1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2021 Free Software Foundation, Inc.
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.
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
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.
30 @c readline appendices use @vindex, @findex and @ftable,
31 @c annotate.texi and gdbmi use @findex.
34 @c !!set GDB manual's edition---not the same as GDB version!
35 @c This is updated by GNU Press.
38 @c !!set GDB edit command default editor
41 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
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
47 * Gdb: (gdb). The GNU debugger.
48 * gdbserver: (gdb) Server. The GNU debugging server.
52 @c man begin COPYRIGHT
53 Copyright @copyright{} 1988-2021 Free Software Foundation, Inc.
55 Permission is granted to copy, distribute and/or modify this document
56 under the terms of the GNU Free Documentation License, Version 1.3 or
57 any later version published by the Free Software Foundation; with the
58 Invariant Sections being ``Free Software'' and ``Free Software Needs
59 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60 and with the Back-Cover Texts as in (a) below.
62 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63 this GNU Manual. Buying copies from GNU Press supports the FSF in
64 developing GNU and promoting software freedom.''
69 This file documents the @sc{gnu} debugger @value{GDBN}.
71 This is the @value{EDITION} Edition, of @cite{Debugging with
72 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73 @ifset VERSION_PACKAGE
74 @value{VERSION_PACKAGE}
76 Version @value{GDBVN}.
82 @title Debugging with @value{GDBN}
83 @subtitle The @sc{gnu} Source-Level Debugger
85 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
86 @ifset VERSION_PACKAGE
88 @subtitle @value{VERSION_PACKAGE}
90 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
94 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
95 \hfill {\it Debugging with @value{GDBN}}\par
96 \hfill \TeX{}info \texinfoversion\par
100 @vskip 0pt plus 1filll
101 Published by the Free Software Foundation @*
102 51 Franklin Street, Fifth Floor,
103 Boston, MA 02110-1301, USA@*
104 ISBN 978-0-9831592-3-0 @*
113 @top Debugging with @value{GDBN}
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
117 This is the @value{EDITION} Edition, for @value{GDBN}
118 @ifset VERSION_PACKAGE
119 @value{VERSION_PACKAGE}
121 Version @value{GDBVN}.
123 Copyright (C) 1988-2021 Free Software Foundation, Inc.
125 This edition of the GDB manual is dedicated to the memory of Fred
126 Fish. Fred was a long-standing contributor to GDB and to Free
127 software in general. We will miss him.
130 * Summary:: Summary of @value{GDBN}
131 * Sample Session:: A sample @value{GDBN} session
133 * Invocation:: Getting in and out of @value{GDBN}
134 * Commands:: @value{GDBN} commands
135 * Running:: Running programs under @value{GDBN}
136 * Stopping:: Stopping and continuing
137 * Reverse Execution:: Running programs backward
138 * Process Record and Replay:: Recording inferior's execution and replaying it
139 * Stack:: Examining the stack
140 * Source:: Examining source files
141 * Data:: Examining data
142 * Optimized Code:: Debugging optimized code
143 * Macros:: Preprocessor Macros
144 * Tracepoints:: Debugging remote targets non-intrusively
145 * Overlays:: Debugging programs that use overlays
147 * Languages:: Using @value{GDBN} with different languages
149 * Symbols:: Examining the symbol table
150 * Altering:: Altering execution
151 * GDB Files:: @value{GDBN} files
152 * Targets:: Specifying a debugging target
153 * Remote Debugging:: Debugging remote programs
154 * Configurations:: Configuration-specific information
155 * Controlling GDB:: Controlling @value{GDBN}
156 * Extending GDB:: Extending @value{GDBN}
157 * Interpreters:: Command Interpreters
158 * TUI:: @value{GDBN} Text User Interface
159 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
160 * GDB/MI:: @value{GDBN}'s Machine Interface.
161 * Annotations:: @value{GDBN}'s annotation interface.
162 * JIT Interface:: Using the JIT debugging interface.
163 * In-Process Agent:: In-Process Agent
165 * GDB Bugs:: Reporting bugs in @value{GDBN}
167 @ifset SYSTEM_READLINE
168 * Command Line Editing: (rluserman). Command Line Editing
169 * Using History Interactively: (history). Using History Interactively
171 @ifclear SYSTEM_READLINE
172 * Command Line Editing:: Command Line Editing
173 * Using History Interactively:: Using History Interactively
175 * In Memoriam:: In Memoriam
176 * Formatting Documentation:: How to format and print @value{GDBN} documentation
177 * Installing GDB:: Installing GDB
178 * Maintenance Commands:: Maintenance Commands
179 * Remote Protocol:: GDB Remote Serial Protocol
180 * Agent Expressions:: The GDB Agent Expression Mechanism
181 * Target Descriptions:: How targets can describe themselves to
183 * Operating System Information:: Getting additional information from
185 * Trace File Format:: GDB trace file format
186 * Index Section Format:: .gdb_index section format
187 * Man Pages:: Manual pages
188 * Copying:: GNU General Public License says
189 how you can copy and share GDB
190 * GNU Free Documentation License:: The license for this documentation
191 * Concept Index:: Index of @value{GDBN} concepts
192 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
201 @unnumbered Summary of @value{GDBN}
203 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204 going on ``inside'' another program while it executes---or what another
205 program was doing at the moment it crashed.
207 @value{GDBN} can do four main kinds of things (plus other things in support of
208 these) to help you catch bugs in the act:
212 Start your program, specifying anything that might affect its behavior.
215 Make your program stop on specified conditions.
218 Examine what has happened, when your program has stopped.
221 Change things in your program, so you can experiment with correcting the
222 effects of one bug and go on to learn about another.
225 You can use @value{GDBN} to debug programs written in C and C@t{++}.
226 For more information, see @ref{Supported Languages,,Supported Languages}.
227 For more information, see @ref{C,,C and C++}.
229 Support for D is partial. For information on D, see
233 Support for Modula-2 is partial. For information on Modula-2, see
234 @ref{Modula-2,,Modula-2}.
236 Support for OpenCL C is partial. For information on OpenCL C, see
237 @ref{OpenCL C,,OpenCL C}.
240 Debugging Pascal programs which use sets, subranges, file variables, or
241 nested functions does not currently work. @value{GDBN} does not support
242 entering expressions, printing values, or similar features using Pascal
246 @value{GDBN} can be used to debug programs written in Fortran, although
247 it may be necessary to refer to some variables with a trailing
250 @value{GDBN} can be used to debug programs written in Objective-C,
251 using either the Apple/NeXT or the GNU Objective-C runtime.
254 * Free Software:: Freely redistributable software
255 * Free Documentation:: Free Software Needs Free Documentation
256 * Contributors:: Contributors to GDB
260 @unnumberedsec Free Software
262 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
263 General Public License
264 (GPL). The GPL gives you the freedom to copy or adapt a licensed
265 program---but every person getting a copy also gets with it the
266 freedom to modify that copy (which means that they must get access to
267 the source code), and the freedom to distribute further copies.
268 Typical software companies use copyrights to limit your freedoms; the
269 Free Software Foundation uses the GPL to preserve these freedoms.
271 Fundamentally, the General Public License is a license which says that
272 you have these freedoms and that you cannot take these freedoms away
275 @node Free Documentation
276 @unnumberedsec Free Software Needs Free Documentation
278 The biggest deficiency in the free software community today is not in
279 the software---it is the lack of good free documentation that we can
280 include with the free software. Many of our most important
281 programs do not come with free reference manuals and free introductory
282 texts. Documentation is an essential part of any software package;
283 when an important free software package does not come with a free
284 manual and a free tutorial, that is a major gap. We have many such
287 Consider Perl, for instance. The tutorial manuals that people
288 normally use are non-free. How did this come about? Because the
289 authors of those manuals published them with restrictive terms---no
290 copying, no modification, source files not available---which exclude
291 them from the free software world.
293 That wasn't the first time this sort of thing happened, and it was far
294 from the last. Many times we have heard a GNU user eagerly describe a
295 manual that he is writing, his intended contribution to the community,
296 only to learn that he had ruined everything by signing a publication
297 contract to make it non-free.
299 Free documentation, like free software, is a matter of freedom, not
300 price. The problem with the non-free manual is not that publishers
301 charge a price for printed copies---that in itself is fine. (The Free
302 Software Foundation sells printed copies of manuals, too.) The
303 problem is the restrictions on the use of the manual. Free manuals
304 are available in source code form, and give you permission to copy and
305 modify. Non-free manuals do not allow this.
307 The criteria of freedom for a free manual are roughly the same as for
308 free software. Redistribution (including the normal kinds of
309 commercial redistribution) must be permitted, so that the manual can
310 accompany every copy of the program, both on-line and on paper.
312 Permission for modification of the technical content is crucial too.
313 When people modify the software, adding or changing features, if they
314 are conscientious they will change the manual too---so they can
315 provide accurate and clear documentation for the modified program. A
316 manual that leaves you no choice but to write a new manual to document
317 a changed version of the program is not really available to our
320 Some kinds of limits on the way modification is handled are
321 acceptable. For example, requirements to preserve the original
322 author's copyright notice, the distribution terms, or the list of
323 authors, are ok. It is also no problem to require modified versions
324 to include notice that they were modified. Even entire sections that
325 may not be deleted or changed are acceptable, as long as they deal
326 with nontechnical topics (like this one). These kinds of restrictions
327 are acceptable because they don't obstruct the community's normal use
330 However, it must be possible to modify all the @emph{technical}
331 content of the manual, and then distribute the result in all the usual
332 media, through all the usual channels. Otherwise, the restrictions
333 obstruct the use of the manual, it is not free, and we need another
334 manual to replace it.
336 Please spread the word about this issue. Our community continues to
337 lose manuals to proprietary publishing. If we spread the word that
338 free software needs free reference manuals and free tutorials, perhaps
339 the next person who wants to contribute by writing documentation will
340 realize, before it is too late, that only free manuals contribute to
341 the free software community.
343 If you are writing documentation, please insist on publishing it under
344 the GNU Free Documentation License or another free documentation
345 license. Remember that this decision requires your approval---you
346 don't have to let the publisher decide. Some commercial publishers
347 will use a free license if you insist, but they will not propose the
348 option; it is up to you to raise the issue and say firmly that this is
349 what you want. If the publisher you are dealing with refuses, please
350 try other publishers. If you're not sure whether a proposed license
351 is free, write to @email{licensing@@gnu.org}.
353 You can encourage commercial publishers to sell more free, copylefted
354 manuals and tutorials by buying them, and particularly by buying
355 copies from the publishers that paid for their writing or for major
356 improvements. Meanwhile, try to avoid buying non-free documentation
357 at all. Check the distribution terms of a manual before you buy it,
358 and insist that whoever seeks your business must respect your freedom.
359 Check the history of the book, and try to reward the publishers that
360 have paid or pay the authors to work on it.
362 The Free Software Foundation maintains a list of free documentation
363 published by other publishers, at
364 @url{http://www.fsf.org/doc/other-free-books.html}.
367 @unnumberedsec Contributors to @value{GDBN}
369 Richard Stallman was the original author of @value{GDBN}, and of many
370 other @sc{gnu} programs. Many others have contributed to its
371 development. This section attempts to credit major contributors. One
372 of the virtues of free software is that everyone is free to contribute
373 to it; with regret, we cannot actually acknowledge everyone here. The
374 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
375 blow-by-blow account.
377 Changes much prior to version 2.0 are lost in the mists of time.
380 @emph{Plea:} Additions to this section are particularly welcome. If you
381 or your friends (or enemies, to be evenhanded) have been unfairly
382 omitted from this list, we would like to add your names!
385 So that they may not regard their many labors as thankless, we
386 particularly thank those who shepherded @value{GDBN} through major
388 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
389 Jim Blandy (release 4.18);
390 Jason Molenda (release 4.17);
391 Stan Shebs (release 4.14);
392 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395 Jim Kingdon (releases 3.5, 3.4, and 3.3);
396 and Randy Smith (releases 3.2, 3.1, and 3.0).
398 Richard Stallman, assisted at various times by Peter TerMaat, Chris
399 Hanson, and Richard Mlynarik, handled releases through 2.8.
401 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402 in @value{GDBN}, with significant additional contributions from Per
403 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405 much general update work leading to release 3.0).
407 @value{GDBN} uses the BFD subroutine library to examine multiple
408 object-file formats; BFD was a joint project of David V.
409 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
411 David Johnson wrote the original COFF support; Pace Willison did
412 the original support for encapsulated COFF.
414 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
416 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
419 Jean-Daniel Fekete contributed Sun 386i support.
420 Chris Hanson improved the HP9000 support.
421 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422 David Johnson contributed Encore Umax support.
423 Jyrki Kuoppala contributed Altos 3068 support.
424 Jeff Law contributed HP PA and SOM support.
425 Keith Packard contributed NS32K support.
426 Doug Rabson contributed Acorn Risc Machine support.
427 Bob Rusk contributed Harris Nighthawk CX-UX support.
428 Chris Smith contributed Convex support (and Fortran debugging).
429 Jonathan Stone contributed Pyramid support.
430 Michael Tiemann contributed SPARC support.
431 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432 Pace Willison contributed Intel 386 support.
433 Jay Vosburgh contributed Symmetry support.
434 Marko Mlinar contributed OpenRISC 1000 support.
436 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
438 Rich Schaefer and Peter Schauer helped with support of SunOS shared
441 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442 about several machine instruction sets.
444 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447 and RDI targets, respectively.
449 Brian Fox is the author of the readline libraries providing
450 command-line editing and command history.
452 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453 Modula-2 support, and contributed the Languages chapter of this manual.
455 Fred Fish wrote most of the support for Unix System Vr4.
456 He also enhanced the command-completion support to cover C@t{++} overloaded
459 Hitachi America (now Renesas America), Ltd. sponsored the support for
460 H8/300, H8/500, and Super-H processors.
462 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
464 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
467 Toshiba sponsored the support for the TX39 Mips processor.
469 Matsushita sponsored the support for the MN10200 and MN10300 processors.
471 Fujitsu sponsored the support for SPARClite and FR30 processors.
473 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
476 Michael Snyder added support for tracepoints.
478 Stu Grossman wrote gdbserver.
480 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
481 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
483 The following people at the Hewlett-Packard Company contributed
484 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
485 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
486 compiler, and the Text User Interface (nee Terminal User Interface):
487 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489 provided HP-specific information in this manual.
491 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492 Robert Hoehne made significant contributions to the DJGPP port.
494 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495 development since 1991. Cygnus engineers who have worked on @value{GDBN}
496 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508 Zuhn have made contributions both large and small.
510 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
513 Jim Blandy added support for preprocessor macros, while working for Red
516 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521 with the migration of old architectures to this new framework.
523 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524 unwinder framework, this consisting of a fresh new design featuring
525 frame IDs, independent frame sniffers, and the sentinel frame. Mark
526 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
528 trad unwinders. The architecture-specific changes, each involving a
529 complete rewrite of the architecture's frame code, were carried out by
530 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
536 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537 Tensilica, Inc.@: contributed support for Xtensa processors. Others
538 who have worked on the Xtensa port of @value{GDBN} in the past include
539 Steve Tjiang, John Newlin, and Scott Foehner.
541 Michael Eager and staff of Xilinx, Inc., contributed support for the
542 Xilinx MicroBlaze architecture.
544 Initial support for the FreeBSD/mips target and native configuration
545 was developed by SRI International and the University of Cambridge
546 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547 ("CTSRD"), as part of the DARPA CRASH research programme.
549 Initial support for the FreeBSD/riscv target and native configuration
550 was developed by SRI International and the University of Cambridge
551 Computer Laboratory (Department of Computer Science and Technology)
552 under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553 SSITH research programme.
555 The original port to the OpenRISC 1000 is believed to be due to
556 Alessandro Forin and Per Bothner. More recent ports have been the work
557 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
560 Weimin Pan, David Faust and Jose E. Marchesi contributed support for
561 the Linux kernel BPF virtual architecture. This work was sponsored by
565 @chapter A Sample @value{GDBN} Session
567 You can use this manual at your leisure to read all about @value{GDBN}.
568 However, a handful of commands are enough to get started using the
569 debugger. This chapter illustrates those commands.
572 In this sample session, we emphasize user input like this: @b{input},
573 to make it easier to pick out from the surrounding output.
576 @c FIXME: this example may not be appropriate for some configs, where
577 @c FIXME...primary interest is in remote use.
579 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
580 processor) exhibits the following bug: sometimes, when we change its
581 quote strings from the default, the commands used to capture one macro
582 definition within another stop working. In the following short @code{m4}
583 session, we define a macro @code{foo} which expands to @code{0000}; we
584 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
585 same thing. However, when we change the open quote string to
586 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
587 procedure fails to define a new synonym @code{baz}:
596 @b{define(bar,defn(`foo'))}
600 @b{changequote(<QUOTE>,<UNQUOTE>)}
602 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
605 m4: End of input: 0: fatal error: EOF in string
609 Let us use @value{GDBN} to try to see what is going on.
612 $ @b{@value{GDBP} m4}
613 @c FIXME: this falsifies the exact text played out, to permit smallbook
614 @c FIXME... format to come out better.
615 @value{GDBN} is free software and you are welcome to distribute copies
616 of it under certain conditions; type "show copying" to see
618 There is absolutely no warranty for @value{GDBN}; type "show warranty"
621 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
626 @value{GDBN} reads only enough symbol data to know where to find the
627 rest when needed; as a result, the first prompt comes up very quickly.
628 We now tell @value{GDBN} to use a narrower display width than usual, so
629 that examples fit in this manual.
632 (@value{GDBP}) @b{set width 70}
636 We need to see how the @code{m4} built-in @code{changequote} works.
637 Having looked at the source, we know the relevant subroutine is
638 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
639 @code{break} command.
642 (@value{GDBP}) @b{break m4_changequote}
643 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
647 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
648 control; as long as control does not reach the @code{m4_changequote}
649 subroutine, the program runs as usual:
652 (@value{GDBP}) @b{run}
653 Starting program: /work/Editorial/gdb/gnu/m4/m4
661 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
662 suspends execution of @code{m4}, displaying information about the
663 context where it stops.
666 @b{changequote(<QUOTE>,<UNQUOTE>)}
668 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
670 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
674 Now we use the command @code{n} (@code{next}) to advance execution to
675 the next line of the current function.
679 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
684 @code{set_quotes} looks like a promising subroutine. We can go into it
685 by using the command @code{s} (@code{step}) instead of @code{next}.
686 @code{step} goes to the next line to be executed in @emph{any}
687 subroutine, so it steps into @code{set_quotes}.
691 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
693 530 if (lquote != def_lquote)
697 The display that shows the subroutine where @code{m4} is now
698 suspended (and its arguments) is called a stack frame display. It
699 shows a summary of the stack. We can use the @code{backtrace}
700 command (which can also be spelled @code{bt}), to see where we are
701 in the stack as a whole: the @code{backtrace} command displays a
702 stack frame for each active subroutine.
705 (@value{GDBP}) @b{bt}
706 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
708 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
710 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
711 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
713 #4 0x79dc in expand_input () at macro.c:40
714 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
718 We step through a few more lines to see what happens. The first two
719 times, we can use @samp{s}; the next two times we use @code{n} to avoid
720 falling into the @code{xstrdup} subroutine.
724 0x3b5c 532 if (rquote != def_rquote)
726 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
727 def_lquote : xstrdup(lq);
729 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
732 538 len_lquote = strlen(rquote);
736 The last line displayed looks a little odd; we can examine the variables
737 @code{lquote} and @code{rquote} to see if they are in fact the new left
738 and right quotes we specified. We use the command @code{p}
739 (@code{print}) to see their values.
742 (@value{GDBP}) @b{p lquote}
743 $1 = 0x35d40 "<QUOTE>"
744 (@value{GDBP}) @b{p rquote}
745 $2 = 0x35d50 "<UNQUOTE>"
749 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
750 To look at some context, we can display ten lines of source
751 surrounding the current line with the @code{l} (@code{list}) command.
757 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
759 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
762 538 len_lquote = strlen(rquote);
763 539 len_rquote = strlen(lquote);
770 Let us step past the two lines that set @code{len_lquote} and
771 @code{len_rquote}, and then examine the values of those variables.
775 539 len_rquote = strlen(lquote);
778 (@value{GDBP}) @b{p len_lquote}
780 (@value{GDBP}) @b{p len_rquote}
785 That certainly looks wrong, assuming @code{len_lquote} and
786 @code{len_rquote} are meant to be the lengths of @code{lquote} and
787 @code{rquote} respectively. We can set them to better values using
788 the @code{p} command, since it can print the value of
789 any expression---and that expression can include subroutine calls and
793 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
795 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
800 Is that enough to fix the problem of using the new quotes with the
801 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
802 executing with the @code{c} (@code{continue}) command, and then try the
803 example that caused trouble initially:
809 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
816 Success! The new quotes now work just as well as the default ones. The
817 problem seems to have been just the two typos defining the wrong
818 lengths. We allow @code{m4} exit by giving it an EOF as input:
822 Program exited normally.
826 The message @samp{Program exited normally.} is from @value{GDBN}; it
827 indicates @code{m4} has finished executing. We can end our @value{GDBN}
828 session with the @value{GDBN} @code{quit} command.
831 (@value{GDBP}) @b{quit}
835 @chapter Getting In and Out of @value{GDBN}
837 This chapter discusses how to start @value{GDBN}, and how to get out of it.
841 type @samp{@value{GDBP}} to start @value{GDBN}.
843 type @kbd{quit} or @kbd{Ctrl-d} to exit.
847 * Invoking GDB:: How to start @value{GDBN}
848 * Quitting GDB:: How to quit @value{GDBN}
849 * Shell Commands:: How to use shell commands inside @value{GDBN}
850 * Logging Output:: How to log @value{GDBN}'s output to a file
854 @section Invoking @value{GDBN}
856 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
857 @value{GDBN} reads commands from the terminal until you tell it to exit.
859 You can also run @code{@value{GDBP}} with a variety of arguments and options,
860 to specify more of your debugging environment at the outset.
862 The command-line options described here are designed
863 to cover a variety of situations; in some environments, some of these
864 options may effectively be unavailable.
866 The most usual way to start @value{GDBN} is with one argument,
867 specifying an executable program:
870 @value{GDBP} @var{program}
874 You can also start with both an executable program and a core file
878 @value{GDBP} @var{program} @var{core}
881 You can, instead, specify a process ID as a second argument or use option
882 @code{-p}, if you want to debug a running process:
885 @value{GDBP} @var{program} 1234
890 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
891 can omit the @var{program} filename.
893 Taking advantage of the second command-line argument requires a fairly
894 complete operating system; when you use @value{GDBN} as a remote
895 debugger attached to a bare board, there may not be any notion of
896 ``process'', and there is often no way to get a core dump. @value{GDBN}
897 will warn you if it is unable to attach or to read core dumps.
899 You can optionally have @code{@value{GDBP}} pass any arguments after the
900 executable file to the inferior using @code{--args}. This option stops
903 @value{GDBP} --args gcc -O2 -c foo.c
905 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
906 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
908 You can run @code{@value{GDBP}} without printing the front material, which describes
909 @value{GDBN}'s non-warranty, by specifying @code{--silent}
910 (or @code{-q}/@code{--quiet}):
913 @value{GDBP} --silent
917 You can further control how @value{GDBN} starts up by using command-line
918 options. @value{GDBN} itself can remind you of the options available.
928 to display all available options and briefly describe their use
929 (@samp{@value{GDBP} -h} is a shorter equivalent).
931 All options and command line arguments you give are processed
932 in sequential order. The order makes a difference when the
933 @samp{-x} option is used.
937 * File Options:: Choosing files
938 * Mode Options:: Choosing modes
939 * Startup:: What @value{GDBN} does during startup
940 * Initialization Files:: Initialization Files
944 @subsection Choosing Files
946 When @value{GDBN} starts, it reads any arguments other than options as
947 specifying an executable file and core file (or process ID). This is
948 the same as if the arguments were specified by the @samp{-se} and
949 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
950 first argument that does not have an associated option flag as
951 equivalent to the @samp{-se} option followed by that argument; and the
952 second argument that does not have an associated option flag, if any, as
953 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
954 If the second argument begins with a decimal digit, @value{GDBN} will
955 first attempt to attach to it as a process, and if that fails, attempt
956 to open it as a corefile. If you have a corefile whose name begins with
957 a digit, you can prevent @value{GDBN} from treating it as a pid by
958 prefixing it with @file{./}, e.g.@: @file{./12345}.
960 If @value{GDBN} has not been configured to included core file support,
961 such as for most embedded targets, then it will complain about a second
962 argument and ignore it.
964 Many options have both long and short forms; both are shown in the
965 following list. @value{GDBN} also recognizes the long forms if you truncate
966 them, so long as enough of the option is present to be unambiguous.
967 (If you prefer, you can flag option arguments with @samp{--} rather
968 than @samp{-}, though we illustrate the more usual convention.)
970 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
971 @c way, both those who look for -foo and --foo in the index, will find
975 @item -symbols @var{file}
977 @cindex @code{--symbols}
979 Read symbol table from file @var{file}.
981 @item -exec @var{file}
983 @cindex @code{--exec}
985 Use file @var{file} as the executable file to execute when appropriate,
986 and for examining pure data in conjunction with a core dump.
990 Read symbol table from file @var{file} and use it as the executable
993 @item -core @var{file}
995 @cindex @code{--core}
997 Use file @var{file} as a core dump to examine.
999 @item -pid @var{number}
1000 @itemx -p @var{number}
1001 @cindex @code{--pid}
1003 Connect to process ID @var{number}, as with the @code{attach} command.
1005 @item -command @var{file}
1006 @itemx -x @var{file}
1007 @cindex @code{--command}
1009 Execute commands from file @var{file}. The contents of this file is
1010 evaluated exactly as the @code{source} command would.
1011 @xref{Command Files,, Command files}.
1013 @item -eval-command @var{command}
1014 @itemx -ex @var{command}
1015 @cindex @code{--eval-command}
1017 Execute a single @value{GDBN} command.
1019 This option may be used multiple times to call multiple commands. It may
1020 also be interleaved with @samp{-command} as required.
1023 @value{GDBP} -ex 'target sim' -ex 'load' \
1024 -x setbreakpoints -ex 'run' a.out
1027 @item -init-command @var{file}
1028 @itemx -ix @var{file}
1029 @cindex @code{--init-command}
1031 Execute commands from file @var{file} before loading the inferior (but
1032 after loading gdbinit files).
1035 @item -init-eval-command @var{command}
1036 @itemx -iex @var{command}
1037 @cindex @code{--init-eval-command}
1039 Execute a single @value{GDBN} command before loading the inferior (but
1040 after loading gdbinit files).
1043 @item -early-init-command @var{file}
1044 @itemx -eix @var{file}
1045 @cindex @code{--early-init-command}
1047 Execute commands from @var{file} very early in the initialization
1048 process, before any output is produced. @xref{Startup}.
1050 @item -early-init-eval-command @var{command}
1051 @itemx -eiex @var{command}
1052 @cindex @code{--early-init-eval-command}
1053 @cindex @code{-eiex}
1054 Execute a single @value{GDBN} command very early in the initialization
1055 process, before any output is produced.
1057 @item -directory @var{directory}
1058 @itemx -d @var{directory}
1059 @cindex @code{--directory}
1061 Add @var{directory} to the path to search for source and script files.
1065 @cindex @code{--readnow}
1067 Read each symbol file's entire symbol table immediately, rather than
1068 the default, which is to read it incrementally as it is needed.
1069 This makes startup slower, but makes future operations faster.
1072 @anchor{--readnever}
1073 @cindex @code{--readnever}, command-line option
1074 Do not read each symbol file's symbolic debug information. This makes
1075 startup faster but at the expense of not being able to perform
1076 symbolic debugging. DWARF unwind information is also not read,
1077 meaning backtraces may become incomplete or inaccurate. One use of
1078 this is when a user simply wants to do the following sequence: attach,
1079 dump core, detach. Loading the debugging information in this case is
1080 an unnecessary cause of delay.
1084 @subsection Choosing Modes
1086 You can run @value{GDBN} in various alternative modes---for example, in
1087 batch mode or quiet mode.
1095 Do not execute commands found in any initialization files
1096 (@pxref{Initialization Files}).
1101 Do not execute commands found in any home directory initialization
1102 file (@pxref{Initialization Files,,Home directory initialization
1103 file}). The system wide and current directory initialization files
1109 @cindex @code{--quiet}
1110 @cindex @code{--silent}
1112 ``Quiet''. Do not print the introductory and copyright messages. These
1113 messages are also suppressed in batch mode.
1116 @cindex @code{--batch}
1117 Run in batch mode. Exit with status @code{0} after processing all the
1118 command files specified with @samp{-x} (and all commands from
1119 initialization files, if not inhibited with @samp{-n}). Exit with
1120 nonzero status if an error occurs in executing the @value{GDBN} commands
1121 in the command files. Batch mode also disables pagination, sets unlimited
1122 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1123 off} were in effect (@pxref{Messages/Warnings}).
1125 Batch mode may be useful for running @value{GDBN} as a filter, for
1126 example to download and run a program on another computer; in order to
1127 make this more useful, the message
1130 Program exited normally.
1134 (which is ordinarily issued whenever a program running under
1135 @value{GDBN} control terminates) is not issued when running in batch
1139 @cindex @code{--batch-silent}
1140 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1141 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1142 unaffected). This is much quieter than @samp{-silent} and would be useless
1143 for an interactive session.
1145 This is particularly useful when using targets that give @samp{Loading section}
1146 messages, for example.
1148 Note that targets that give their output via @value{GDBN}, as opposed to
1149 writing directly to @code{stdout}, will also be made silent.
1151 @item -return-child-result
1152 @cindex @code{--return-child-result}
1153 The return code from @value{GDBN} will be the return code from the child
1154 process (the process being debugged), with the following exceptions:
1158 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1159 internal error. In this case the exit code is the same as it would have been
1160 without @samp{-return-child-result}.
1162 The user quits with an explicit value. E.g., @samp{quit 1}.
1164 The child process never runs, or is not allowed to terminate, in which case
1165 the exit code will be -1.
1168 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1169 when @value{GDBN} is being used as a remote program loader or simulator
1174 @cindex @code{--nowindows}
1176 ``No windows''. If @value{GDBN} comes with a graphical user interface
1177 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1178 interface. If no GUI is available, this option has no effect.
1182 @cindex @code{--windows}
1184 If @value{GDBN} includes a GUI, then this option requires it to be
1187 @item -cd @var{directory}
1189 Run @value{GDBN} using @var{directory} as its working directory,
1190 instead of the current directory.
1192 @item -data-directory @var{directory}
1193 @itemx -D @var{directory}
1194 @cindex @code{--data-directory}
1196 Run @value{GDBN} using @var{directory} as its data directory.
1197 The data directory is where @value{GDBN} searches for its
1198 auxiliary files. @xref{Data Files}.
1202 @cindex @code{--fullname}
1204 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1205 subprocess. It tells @value{GDBN} to output the full file name and line
1206 number in a standard, recognizable fashion each time a stack frame is
1207 displayed (which includes each time your program stops). This
1208 recognizable format looks like two @samp{\032} characters, followed by
1209 the file name, line number and character position separated by colons,
1210 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1211 @samp{\032} characters as a signal to display the source code for the
1214 @item -annotate @var{level}
1215 @cindex @code{--annotate}
1216 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1217 effect is identical to using @samp{set annotate @var{level}}
1218 (@pxref{Annotations}). The annotation @var{level} controls how much
1219 information @value{GDBN} prints together with its prompt, values of
1220 expressions, source lines, and other types of output. Level 0 is the
1221 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1222 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1223 that control @value{GDBN}, and level 2 has been deprecated.
1225 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1229 @cindex @code{--args}
1230 Change interpretation of command line so that arguments following the
1231 executable file are passed as command line arguments to the inferior.
1232 This option stops option processing.
1234 @item -baud @var{bps}
1236 @cindex @code{--baud}
1238 Set the line speed (baud rate or bits per second) of any serial
1239 interface used by @value{GDBN} for remote debugging.
1241 @item -l @var{timeout}
1243 Set the timeout (in seconds) of any communication used by @value{GDBN}
1244 for remote debugging.
1246 @item -tty @var{device}
1247 @itemx -t @var{device}
1248 @cindex @code{--tty}
1250 Run using @var{device} for your program's standard input and output.
1251 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1253 @c resolve the situation of these eventually
1255 @cindex @code{--tui}
1256 Activate the @dfn{Text User Interface} when starting. The Text User
1257 Interface manages several text windows on the terminal, showing
1258 source, assembly, registers and @value{GDBN} command outputs
1259 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1260 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1261 Using @value{GDBN} under @sc{gnu} Emacs}).
1263 @item -interpreter @var{interp}
1264 @cindex @code{--interpreter}
1265 Use the interpreter @var{interp} for interface with the controlling
1266 program or device. This option is meant to be set by programs which
1267 communicate with @value{GDBN} using it as a back end.
1268 @xref{Interpreters, , Command Interpreters}.
1270 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1271 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1272 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1273 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1274 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1275 interfaces are no longer supported.
1278 @cindex @code{--write}
1279 Open the executable and core files for both reading and writing. This
1280 is equivalent to the @samp{set write on} command inside @value{GDBN}
1284 @cindex @code{--statistics}
1285 This option causes @value{GDBN} to print statistics about time and
1286 memory usage after it completes each command and returns to the prompt.
1289 @cindex @code{--version}
1290 This option causes @value{GDBN} to print its version number and
1291 no-warranty blurb, and exit.
1293 @item -configuration
1294 @cindex @code{--configuration}
1295 This option causes @value{GDBN} to print details about its build-time
1296 configuration parameters, and then exit. These details can be
1297 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1302 @subsection What @value{GDBN} Does During Startup
1303 @cindex @value{GDBN} startup
1305 Here's the description of what @value{GDBN} does during session startup:
1310 Performs minimal setup required to initialize basic internal state.
1313 @cindex early initialization file
1314 Reads commands from the early initialization file (if any) in your
1315 home directory. Only a restricted set of commands can be placed into
1316 an early initialization file, see @ref{Initialization Files}, for
1320 Executes commands and command files specified by the @samp{-eiex} and
1321 @samp{-eix} command line options in their specified order. Only a
1322 restricted set of commands can be used with @samp{-eiex} and
1323 @samp{eix}, see @ref{Initialization Files}, for details.
1326 Sets up the command interpreter as specified by the command line
1327 (@pxref{Mode Options, interpreter}).
1331 Reads the system wide initialization file and the files from the
1332 system wide initialization directory, @pxref{System Wide Init Files}.
1335 Reads the initialization file (if any) in your home directory and
1336 executes all the commands in that file, @pxref{Home Directory Init
1339 @anchor{Option -init-eval-command}
1341 Executes commands and command files specified by the @samp{-iex} and
1342 @samp{-ix} options in their specified order. Usually you should use the
1343 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1344 settings before @value{GDBN} init files get executed and before inferior
1348 Processes command line options and operands.
1351 Reads and executes the commands from the initialization file (if any)
1352 in the current working directory as long as @samp{set auto-load
1353 local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1354 Directory}). This is only done if the current directory is different
1355 from your home directory. Thus, you can have more than one init file,
1356 one generic in your home directory, and another, specific to the
1357 program you are debugging, in the directory where you invoke
1358 @value{GDBN}. @xref{Init File in the Current Directory during
1362 If the command line specified a program to debug, or a process to
1363 attach to, or a core file, @value{GDBN} loads any auto-loaded
1364 scripts provided for the program or for its loaded shared libraries.
1365 @xref{Auto-loading}.
1367 If you wish to disable the auto-loading during startup,
1368 you must do something like the following:
1371 $ gdb -iex "set auto-load python-scripts off" myprogram
1374 Option @samp{-ex} does not work because the auto-loading is then turned
1378 Executes commands and command files specified by the @samp{-ex} and
1379 @samp{-x} options in their specified order. @xref{Command Files}, for
1380 more details about @value{GDBN} command files.
1383 Reads the command history recorded in the @dfn{history file}.
1384 @xref{Command History}, for more details about the command history and the
1385 files where @value{GDBN} records it.
1388 @node Initialization Files
1389 @subsection Initialization Files
1390 @cindex init file name
1392 During startup (@pxref{Startup}) @value{GDBN} will execute commands
1393 from several initialization files. These initialization files use the
1394 same syntax as @dfn{command files} (@pxref{Command Files}) and are
1395 processed by @value{GDBN} in the same way.
1397 To display the list of initialization files loaded by @value{GDBN} at
1398 startup, in the order they will be loaded, you can use @kbd{gdb
1401 @cindex early initialization
1402 The @dfn{early initialization} file is loaded very early in
1403 @value{GDBN}'s initialization process, before the interpreter
1404 (@pxref{Interpreters}) has been initialized, and before the default
1405 target (@pxref{Targets}) is initialized. Only @code{set} or
1406 @code{source} commands should be placed into an early initialization
1407 file, and the only @code{set} commands that can be used are those that
1408 control how @value{GDBN} starts up.
1410 Commands that can be placed into an early initialization file will be
1411 documented as such throughout this manual. Any command that is not
1412 documented as being suitable for an early initialization file should
1413 instead be placed into a general initialization file. Command files
1414 passed to @code{--early-init-command} or @code{-eix} are also early
1415 initialization files, with the same command restrictions. Only
1416 commands that can appear in an early initialization file should be
1417 passed to @code{--early-init-eval-command} or @code{-eiex}.
1419 @cindex general initialization
1420 In contrast, the @dfn{general initialization} files are processed
1421 later, after @value{GDBN} has finished its own internal initialization
1422 process, any valid command can be used in these files.
1424 @cindex initialization file
1425 Throughout the rest of this document the term @dfn{initialization
1426 file} refers to one of the general initialization files, not the early
1427 initialization file. Any discussion of the early initialization file
1428 will specifically mention that it is the early initialization file
1431 As the system wide and home directory initialization files are
1432 processed before most command line options, changes to settings
1433 (e.g. @samp{set complaints}) can affect subsequent processing of
1434 command line options and operands.
1436 The following sections describe where @value{GDBN} looks for the early
1437 initialization and initialization files, and the order that the files
1440 @subsubsection Home directory early initialization files
1442 @value{GDBN} initially looks for an early initialization file in the
1443 users home directory@footnote{On DOS/Windows systems, the home
1444 directory is the one pointed to by the @code{HOME} environment
1445 variable.}. There are a number of locations that @value{GDBN} will
1446 search in the home directory, these locations are searched in order
1447 and @value{GDBN} will load the first file that it finds, and
1448 subsequent locations will not be checked.
1450 On non-macOS hosts the locations searched are:
1453 The file @file{gdb/gdbearlyinit} within the directory pointed to by the
1454 environment variable @env{XDG_CONFIG_HOME}, if it is defined.
1456 The file @file{.config/gdb/gdbearlyinit} within the directory pointed to
1457 by the environment variable @env{HOME}, if it is defined.
1459 The file @file{.gdbearlyinit} within the directory pointed to by the
1460 environment variable @env{HOME}, if it is defined.
1463 By contrast, on macOS hosts the locations searched are:
1466 The file @file{Library/Preferences/gdb/gdbearlyinit} within the
1467 directory pointed to by the environment variable @env{HOME}, if it is
1470 The file @file{.gdbearlyinit} within the directory pointed to by the
1471 environment variable @env{HOME}, if it is defined.
1474 It is possible to prevent the home directory early initialization file
1475 from being loaded using the @samp{-nx} or @samp{-nh} command line
1476 options, @pxref{Mode Options,,Choosing Modes}.
1478 @anchor{System Wide Init Files}
1479 @subsubsection System wide initialization files
1481 There are two locations that are searched for system wide
1482 initialization files. Both of these locations are always checked:
1486 @item @file{system.gdbinit}
1487 This is a single system-wide initialization file. Its location is
1488 specified with the @code{--with-system-gdbinit} configure option
1489 (@pxref{System-wide configuration}). It is loaded first when
1490 @value{GDBN} starts, before command line options have been processed.
1492 @item @file{system.gdbinit.d}
1493 This is the system-wide initialization directory. Its location is
1494 specified with the @code{--with-system-gdbinit-dir} configure option
1495 (@pxref{System-wide configuration}). Files in this directory are
1496 loaded in alphabetical order immediately after @file{system.gdbinit}
1497 (if enabled) when @value{GDBN} starts, before command line options
1498 have been processed. Files need to have a recognized scripting
1499 language extension (@file{.py}/@file{.scm}) or be named with a
1500 @file{.gdb} extension to be interpreted as regular @value{GDBN}
1501 commands. @value{GDBN} will not recurse into any subdirectories of
1506 It is possible to prevent the system wide initialization files from
1507 being loaded using the @samp{-nx} command line option, @pxref{Mode
1508 Options,,Choosing Modes}.
1510 @anchor{Home Directory Init File}
1511 @subsubsection Home directory initialization file
1512 @cindex @file{gdbinit}
1513 @cindex @file{.gdbinit}
1514 @cindex @file{gdb.ini}
1516 After loading the system wide initialization files @value{GDBN} will
1517 look for an initialization file in the users home
1518 directory@footnote{On DOS/Windows systems, the home directory is the
1519 one pointed to by the @code{HOME} environment variable.}. There are a
1520 number of locations that @value{GDBN} will search in the home
1521 directory, these locations are searched in order and @value{GDBN} will
1522 load the first file that it finds, and subsequent locations will not
1525 On non-Apple hosts the locations searched are:
1527 @item $XDG_CONFIG_HOME/gdb/gdbinit
1528 @item $HOME/.config/gdb/gdbinit
1529 @item $HOME/.gdbinit
1532 While on Apple hosts the locations searched are:
1534 @item $HOME/Library/Preferences/gdb/gdbinit
1535 @item $HOME/.gdbinit
1538 It is possible to prevent the home directory initialization file from
1539 being loaded using the @samp{-nx} or @samp{-nh} command line options,
1540 @pxref{Mode Options,,Choosing Modes}.
1542 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1543 @file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1544 names imposed by DOS filesystems. The Windows port of @value{GDBN}
1545 uses the standard name, but if it finds a @file{gdb.ini} file in your
1546 home directory, it warns you about that and suggests to rename the
1547 file to the standard name.
1549 @anchor{Init File in the Current Directory during Startup}
1550 @subsubsection Local directory initialization file
1552 @value{GDBN} will check the current directory for a file called
1553 @file{.gdbinit}. It is loaded last, after command line options
1554 other than @samp{-x} and @samp{-ex} have been processed. The command
1555 line options @samp{-x} and @samp{-ex} are processed last, after
1556 @file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1559 If the file in the current directory was already loaded as the home
1560 directory initialization file then it will not be loaded a second
1563 It is possible to prevent the local directory initialization file from
1564 being loaded using the @samp{-nx} command line option, @pxref{Mode
1565 Options,,Choosing Modes}.
1568 @section Quitting @value{GDBN}
1569 @cindex exiting @value{GDBN}
1570 @cindex leaving @value{GDBN}
1573 @kindex quit @r{[}@var{expression}@r{]}
1574 @kindex q @r{(@code{quit})}
1575 @item quit @r{[}@var{expression}@r{]}
1577 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1578 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1579 do not supply @var{expression}, @value{GDBN} will terminate normally;
1580 otherwise it will terminate using the result of @var{expression} as the
1585 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1586 terminates the action of any @value{GDBN} command that is in progress and
1587 returns to @value{GDBN} command level. It is safe to type the interrupt
1588 character at any time because @value{GDBN} does not allow it to take effect
1589 until a time when it is safe.
1591 If you have been using @value{GDBN} to control an attached process or
1592 device, you can release it with the @code{detach} command
1593 (@pxref{Attach, ,Debugging an Already-running Process}).
1595 @node Shell Commands
1596 @section Shell Commands
1598 If you need to execute occasional shell commands during your
1599 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1600 just use the @code{shell} command.
1605 @cindex shell escape
1606 @item shell @var{command-string}
1607 @itemx !@var{command-string}
1608 Invoke a standard shell to execute @var{command-string}.
1609 Note that no space is needed between @code{!} and @var{command-string}.
1610 On GNU and Unix systems, the environment variable @code{SHELL}, if it
1611 exists, determines which shell to run. Otherwise @value{GDBN} uses
1612 the default shell (@file{/bin/sh} on GNU and Unix systems,
1613 @file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1616 The utility @code{make} is often needed in development environments.
1617 You do not have to use the @code{shell} command for this purpose in
1622 @cindex calling make
1623 @item make @var{make-args}
1624 Execute the @code{make} program with the specified
1625 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1631 @cindex send the output of a gdb command to a shell command
1633 @item pipe [@var{command}] | @var{shell_command}
1634 @itemx | [@var{command}] | @var{shell_command}
1635 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1636 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1637 Executes @var{command} and sends its output to @var{shell_command}.
1638 Note that no space is needed around @code{|}.
1639 If no @var{command} is provided, the last command executed is repeated.
1641 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1642 can be used to specify an alternate delimiter string @var{delim} that separates
1643 the @var{command} from the @var{shell_command}.
1676 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1677 this contains a PIPE char
1678 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1679 this contains a PIPE char!
1685 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1686 can be used to examine the exit status of the last shell command launched
1687 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1688 @xref{Convenience Vars,, Convenience Variables}.
1690 @node Logging Output
1691 @section Logging Output
1692 @cindex logging @value{GDBN} output
1693 @cindex save @value{GDBN} output to a file
1695 You may want to save the output of @value{GDBN} commands to a file.
1696 There are several commands to control @value{GDBN}'s logging.
1700 @item set logging on
1702 @item set logging off
1704 @cindex logging file name
1705 @item set logging file @var{file}
1706 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1707 @item set logging overwrite [on|off]
1708 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1709 you want @code{set logging on} to overwrite the logfile instead.
1710 @item set logging redirect [on|off]
1711 By default, @value{GDBN} output will go to both the terminal and the logfile.
1712 Set @code{redirect} if you want output to go only to the log file.
1713 @item set logging debugredirect [on|off]
1714 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1715 Set @code{debugredirect} if you want debug output to go only to the log file.
1716 @kindex show logging
1718 Show the current values of the logging settings.
1721 You can also redirect the output of a @value{GDBN} command to a
1722 shell command. @xref{pipe}.
1724 @chapter @value{GDBN} Commands
1726 You can abbreviate a @value{GDBN} command to the first few letters of the command
1727 name, if that abbreviation is unambiguous; and you can repeat certain
1728 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1729 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1730 show you the alternatives available, if there is more than one possibility).
1733 * Command Syntax:: How to give commands to @value{GDBN}
1734 * Command Settings:: How to change default behavior of commands
1735 * Completion:: Command completion
1736 * Command Options:: Command options
1737 * Help:: How to ask @value{GDBN} for help
1740 @node Command Syntax
1741 @section Command Syntax
1743 A @value{GDBN} command is a single line of input. There is no limit on
1744 how long it can be. It starts with a command name, which is followed by
1745 arguments whose meaning depends on the command name. For example, the
1746 command @code{step} accepts an argument which is the number of times to
1747 step, as in @samp{step 5}. You can also use the @code{step} command
1748 with no arguments. Some commands do not allow any arguments.
1750 @cindex abbreviation
1751 @value{GDBN} command names may always be truncated if that abbreviation is
1752 unambiguous. Other possible command abbreviations are listed in the
1753 documentation for individual commands. In some cases, even ambiguous
1754 abbreviations are allowed; for example, @code{s} is specially defined as
1755 equivalent to @code{step} even though there are other commands whose
1756 names start with @code{s}. You can test abbreviations by using them as
1757 arguments to the @code{help} command.
1759 @cindex repeating commands
1760 @kindex RET @r{(repeat last command)}
1761 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1762 repeat the previous command. Certain commands (for example, @code{run})
1763 will not repeat this way; these are commands whose unintentional
1764 repetition might cause trouble and which you are unlikely to want to
1765 repeat. User-defined commands can disable this feature; see
1766 @ref{Define, dont-repeat}.
1768 The @code{list} and @code{x} commands, when you repeat them with
1769 @key{RET}, construct new arguments rather than repeating
1770 exactly as typed. This permits easy scanning of source or memory.
1772 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1773 output, in a way similar to the common utility @code{more}
1774 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1775 @key{RET} too many in this situation, @value{GDBN} disables command
1776 repetition after any command that generates this sort of display.
1778 @kindex # @r{(a comment)}
1780 Any text from a @kbd{#} to the end of the line is a comment; it does
1781 nothing. This is useful mainly in command files (@pxref{Command
1782 Files,,Command Files}).
1784 @cindex repeating command sequences
1785 @kindex Ctrl-o @r{(operate-and-get-next)}
1786 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1787 commands. This command accepts the current line, like @key{RET}, and
1788 then fetches the next line relative to the current line from the history
1792 @node Command Settings
1793 @section Command Settings
1794 @cindex default behavior of commands, changing
1795 @cindex default settings, changing
1797 Many commands change their behavior according to command-specific
1798 variables or settings. These settings can be changed with the
1799 @code{set} subcommands. For example, the @code{print} command
1800 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1801 settings changeable with the commands @code{set print elements
1802 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1804 You can change these settings to your preference in the gdbinit files
1805 loaded at @value{GDBN} startup. @xref{Startup}.
1807 The settings can also be changed interactively during the debugging
1808 session. For example, to change the limit of array elements to print,
1809 you can do the following:
1811 (@value{GDBN}) set print elements 10
1812 (@value{GDBN}) print some_array
1813 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1816 The above @code{set print elements 10} command changes the number of
1817 elements to print from the default of 200 to 10. If you only intend
1818 this limit of 10 to be used for printing @code{some_array}, then you
1819 must restore the limit back to 200, with @code{set print elements
1822 Some commands allow overriding settings with command options. For
1823 example, the @code{print} command supports a number of options that
1824 allow overriding relevant global print settings as set by @code{set
1825 print} subcommands. @xref{print options}. The example above could be
1828 (@value{GDBN}) print -elements 10 -- some_array
1829 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1832 Alternatively, you can use the @code{with} command to change a setting
1833 temporarily, for the duration of a command invocation.
1836 @kindex with command
1837 @kindex w @r{(@code{with})}
1839 @cindex temporarily change settings
1840 @item with @var{setting} [@var{value}] [-- @var{command}]
1841 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1842 Temporarily set @var{setting} to @var{value} for the duration of
1845 @var{setting} is any setting you can change with the @code{set}
1846 subcommands. @var{value} is the value to assign to @code{setting}
1847 while running @code{command}.
1849 If no @var{command} is provided, the last command executed is
1852 If a @var{command} is provided, it must be preceded by a double dash
1853 (@code{--}) separator. This is required because some settings accept
1854 free-form arguments, such as expressions or filenames.
1856 For example, the command
1858 (@value{GDBN}) with print array on -- print some_array
1861 is equivalent to the following 3 commands:
1863 (@value{GDBN}) set print array on
1864 (@value{GDBN}) print some_array
1865 (@value{GDBN}) set print array off
1868 The @code{with} command is particularly useful when you want to
1869 override a setting while running user-defined commands, or commands
1870 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1873 (@value{GDBN}) with print pretty on -- my_complex_command
1876 To change several settings for the same command, you can nest
1877 @code{with} commands. For example, @code{with language ada -- with
1878 print elements 10} temporarily changes the language to Ada and sets a
1879 limit of 10 elements to print for arrays and strings.
1884 @section Command Completion
1887 @cindex word completion
1888 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1889 only one possibility; it can also show you what the valid possibilities
1890 are for the next word in a command, at any time. This works for @value{GDBN}
1891 commands, @value{GDBN} subcommands, command options, and the names of symbols
1894 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1895 of a word. If there is only one possibility, @value{GDBN} fills in the
1896 word, and waits for you to finish the command (or press @key{RET} to
1897 enter it). For example, if you type
1899 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1900 @c complete accuracy in these examples; space introduced for clarity.
1901 @c If texinfo enhancements make it unnecessary, it would be nice to
1902 @c replace " @key" by "@key" in the following...
1904 (@value{GDBP}) info bre @key{TAB}
1908 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1909 the only @code{info} subcommand beginning with @samp{bre}:
1912 (@value{GDBP}) info breakpoints
1916 You can either press @key{RET} at this point, to run the @code{info
1917 breakpoints} command, or backspace and enter something else, if
1918 @samp{breakpoints} does not look like the command you expected. (If you
1919 were sure you wanted @code{info breakpoints} in the first place, you
1920 might as well just type @key{RET} immediately after @samp{info bre},
1921 to exploit command abbreviations rather than command completion).
1923 If there is more than one possibility for the next word when you press
1924 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1925 characters and try again, or just press @key{TAB} a second time;
1926 @value{GDBN} displays all the possible completions for that word. For
1927 example, you might want to set a breakpoint on a subroutine whose name
1928 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1929 just sounds the bell. Typing @key{TAB} again displays all the
1930 function names in your program that begin with those characters, for
1934 (@value{GDBP}) b make_ @key{TAB}
1935 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1936 make_a_section_from_file make_environ
1937 make_abs_section make_function_type
1938 make_blockvector make_pointer_type
1939 make_cleanup make_reference_type
1940 make_command make_symbol_completion_list
1941 (@value{GDBP}) b make_
1945 After displaying the available possibilities, @value{GDBN} copies your
1946 partial input (@samp{b make_} in the example) so you can finish the
1949 If you just want to see the list of alternatives in the first place, you
1950 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1951 means @kbd{@key{META} ?}. You can type this either by holding down a
1952 key designated as the @key{META} shift on your keyboard (if there is
1953 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1955 If the number of possible completions is large, @value{GDBN} will
1956 print as much of the list as it has collected, as well as a message
1957 indicating that the list may be truncated.
1960 (@value{GDBP}) b m@key{TAB}@key{TAB}
1962 <... the rest of the possible completions ...>
1963 *** List may be truncated, max-completions reached. ***
1968 This behavior can be controlled with the following commands:
1971 @kindex set max-completions
1972 @item set max-completions @var{limit}
1973 @itemx set max-completions unlimited
1974 Set the maximum number of completion candidates. @value{GDBN} will
1975 stop looking for more completions once it collects this many candidates.
1976 This is useful when completing on things like function names as collecting
1977 all the possible candidates can be time consuming.
1978 The default value is 200. A value of zero disables tab-completion.
1979 Note that setting either no limit or a very large limit can make
1981 @kindex show max-completions
1982 @item show max-completions
1983 Show the maximum number of candidates that @value{GDBN} will collect and show
1987 @cindex quotes in commands
1988 @cindex completion of quoted strings
1989 Sometimes the string you need, while logically a ``word'', may contain
1990 parentheses or other characters that @value{GDBN} normally excludes from
1991 its notion of a word. To permit word completion to work in this
1992 situation, you may enclose words in @code{'} (single quote marks) in
1993 @value{GDBN} commands.
1995 A likely situation where you might need this is in typing an
1996 expression that involves a C@t{++} symbol name with template
1997 parameters. This is because when completing expressions, GDB treats
1998 the @samp{<} character as word delimiter, assuming that it's the
1999 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
2002 For example, when you want to call a C@t{++} template function
2003 interactively using the @code{print} or @code{call} commands, you may
2004 need to distinguish whether you mean the version of @code{name} that
2005 was specialized for @code{int}, @code{name<int>()}, or the version
2006 that was specialized for @code{float}, @code{name<float>()}. To use
2007 the word-completion facilities in this situation, type a single quote
2008 @code{'} at the beginning of the function name. This alerts
2009 @value{GDBN} that it may need to consider more information than usual
2010 when you press @key{TAB} or @kbd{M-?} to request word completion:
2013 (@value{GDBP}) p 'func< @kbd{M-?}
2014 func<int>() func<float>()
2015 (@value{GDBP}) p 'func<
2018 When setting breakpoints however (@pxref{Specify Location}), you don't
2019 usually need to type a quote before the function name, because
2020 @value{GDBN} understands that you want to set a breakpoint on a
2024 (@value{GDBP}) b func< @kbd{M-?}
2025 func<int>() func<float>()
2026 (@value{GDBP}) b func<
2029 This is true even in the case of typing the name of C@t{++} overloaded
2030 functions (multiple definitions of the same function, distinguished by
2031 argument type). For example, when you want to set a breakpoint you
2032 don't need to distinguish whether you mean the version of @code{name}
2033 that takes an @code{int} parameter, @code{name(int)}, or the version
2034 that takes a @code{float} parameter, @code{name(float)}.
2037 (@value{GDBP}) b bubble( @kbd{M-?}
2038 bubble(int) bubble(double)
2039 (@value{GDBP}) b bubble(dou @kbd{M-?}
2043 See @ref{quoting names} for a description of other scenarios that
2046 For more information about overloaded functions, see @ref{C Plus Plus
2047 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
2048 overload-resolution off} to disable overload resolution;
2049 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
2051 @cindex completion of structure field names
2052 @cindex structure field name completion
2053 @cindex completion of union field names
2054 @cindex union field name completion
2055 When completing in an expression which looks up a field in a
2056 structure, @value{GDBN} also tries@footnote{The completer can be
2057 confused by certain kinds of invalid expressions. Also, it only
2058 examines the static type of the expression, not the dynamic type.} to
2059 limit completions to the field names available in the type of the
2063 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
2064 magic to_fputs to_rewind
2065 to_data to_isatty to_write
2066 to_delete to_put to_write_async_safe
2071 This is because the @code{gdb_stdout} is a variable of the type
2072 @code{struct ui_file} that is defined in @value{GDBN} sources as
2079 ui_file_flush_ftype *to_flush;
2080 ui_file_write_ftype *to_write;
2081 ui_file_write_async_safe_ftype *to_write_async_safe;
2082 ui_file_fputs_ftype *to_fputs;
2083 ui_file_read_ftype *to_read;
2084 ui_file_delete_ftype *to_delete;
2085 ui_file_isatty_ftype *to_isatty;
2086 ui_file_rewind_ftype *to_rewind;
2087 ui_file_put_ftype *to_put;
2092 @node Command Options
2093 @section Command options
2095 @cindex command options
2096 Some commands accept options starting with a leading dash. For
2097 example, @code{print -pretty}. Similarly to command names, you can
2098 abbreviate a @value{GDBN} option to the first few letters of the
2099 option name, if that abbreviation is unambiguous, and you can also use
2100 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2101 in an option (or to show you the alternatives available, if there is
2102 more than one possibility).
2104 @cindex command options, raw input
2105 Some commands take raw input as argument. For example, the print
2106 command processes arbitrary expressions in any of the languages
2107 supported by @value{GDBN}. With such commands, because raw input may
2108 start with a leading dash that would be confused with an option or any
2109 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2110 -pretty} or printing negative @code{p}?), if you specify any command
2111 option, then you must use a double-dash (@code{--}) delimiter to
2112 indicate the end of options.
2114 @cindex command options, boolean
2116 Some options are described as accepting an argument which can be
2117 either @code{on} or @code{off}. These are known as @dfn{boolean
2118 options}. Similarly to boolean settings commands---@code{on} and
2119 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2120 @code{enable} can also be used as ``true'' value, and any of @code{0},
2121 @code{no} and @code{disable} can also be used as ``false'' value. You
2122 can also omit a ``true'' value, as it is implied by default.
2124 For example, these are equivalent:
2127 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2128 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2131 You can discover the set of options some command accepts by completing
2132 on @code{-} after the command name. For example:
2135 (@value{GDBP}) print -@key{TAB}@key{TAB}
2136 -address -max-depth -raw-values -union
2137 -array -null-stop -repeats -vtbl
2138 -array-indexes -object -static-members
2139 -elements -pretty -symbol
2142 Completion will in some cases guide you with a suggestion of what kind
2143 of argument an option expects. For example:
2146 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2150 Here, the option expects a number (e.g., @code{100}), not literal
2151 @code{NUMBER}. Such metasyntactical arguments are always presented in
2154 (For more on using the @code{print} command, see @ref{Data, ,Examining
2158 @section Getting Help
2159 @cindex online documentation
2162 You can always ask @value{GDBN} itself for information on its commands,
2163 using the command @code{help}.
2166 @kindex h @r{(@code{help})}
2169 You can use @code{help} (abbreviated @code{h}) with no arguments to
2170 display a short list of named classes of commands:
2174 List of classes of commands:
2176 aliases -- User-defined aliases of other commands
2177 breakpoints -- Making program stop at certain points
2178 data -- Examining data
2179 files -- Specifying and examining files
2180 internals -- Maintenance commands
2181 obscure -- Obscure features
2182 running -- Running the program
2183 stack -- Examining the stack
2184 status -- Status inquiries
2185 support -- Support facilities
2186 tracepoints -- Tracing of program execution without
2187 stopping the program
2188 user-defined -- User-defined commands
2190 Type "help" followed by a class name for a list of
2191 commands in that class.
2192 Type "help" followed by command name for full
2194 Command name abbreviations are allowed if unambiguous.
2197 @c the above line break eliminates huge line overfull...
2199 @item help @var{class}
2200 Using one of the general help classes as an argument, you can get a
2201 list of the individual commands in that class. If a command has
2202 aliases, the aliases are given after the command name, separated by
2203 commas. If an alias has default arguments, the full definition of
2204 the alias is given after the first line.
2205 For example, here is the help display for the class @code{status}:
2208 (@value{GDBP}) help status
2213 @c Line break in "show" line falsifies real output, but needed
2214 @c to fit in smallbook page size.
2215 info, inf, i -- Generic command for showing things
2216 about the program being debugged
2217 info address, iamain -- Describe where symbol SYM is stored.
2218 alias iamain = info address main
2219 info all-registers -- List of all registers and their contents,
2220 for selected stack frame.
2222 show, info set -- Generic command for showing things
2225 Type "help" followed by command name for full
2227 Command name abbreviations are allowed if unambiguous.
2231 @item help @var{command}
2232 With a command name as @code{help} argument, @value{GDBN} displays a
2233 short paragraph on how to use that command. If that command has
2234 one or more aliases, @value{GDBN} will display a first line with
2235 the command name and all its aliases separated by commas.
2236 This first line will be followed by the full definition of all aliases
2237 having default arguments.
2240 @item apropos [-v] @var{regexp}
2241 The @code{apropos} command searches through all of the @value{GDBN}
2242 commands, and their documentation, for the regular expression specified in
2243 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2244 which stands for @samp{verbose}, indicates to output the full documentation
2245 of the matching commands and highlight the parts of the documentation
2246 matching @var{regexp}. For example:
2257 alias -- Define a new command that is an alias of an existing command
2258 aliases -- User-defined aliases of other commands
2266 apropos -v cut.*thread apply
2270 results in the below output, where @samp{cut for 'thread apply}
2271 is highlighted if styling is enabled.
2275 taas -- Apply a command to all threads (ignoring errors
2278 shortcut for 'thread apply all -s COMMAND'
2280 tfaas -- Apply a command to all frames of all threads
2281 (ignoring errors and empty output).
2282 Usage: tfaas COMMAND
2283 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2288 @item complete @var{args}
2289 The @code{complete @var{args}} command lists all the possible completions
2290 for the beginning of a command. Use @var{args} to specify the beginning of the
2291 command you want completed. For example:
2297 @noindent results in:
2308 @noindent This is intended for use by @sc{gnu} Emacs.
2311 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2312 and @code{show} to inquire about the state of your program, or the state
2313 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2314 manual introduces each of them in the appropriate context. The listings
2315 under @code{info} and under @code{show} in the Command, Variable, and
2316 Function Index point to all the sub-commands. @xref{Command and Variable
2322 @kindex i @r{(@code{info})}
2324 This command (abbreviated @code{i}) is for describing the state of your
2325 program. For example, you can show the arguments passed to a function
2326 with @code{info args}, list the registers currently in use with @code{info
2327 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2328 You can get a complete list of the @code{info} sub-commands with
2329 @w{@code{help info}}.
2333 You can assign the result of an expression to an environment variable with
2334 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2335 @code{set prompt $}.
2339 In contrast to @code{info}, @code{show} is for describing the state of
2340 @value{GDBN} itself.
2341 You can change most of the things you can @code{show}, by using the
2342 related command @code{set}; for example, you can control what number
2343 system is used for displays with @code{set radix}, or simply inquire
2344 which is currently in use with @code{show radix}.
2347 To display all the settable parameters and their current
2348 values, you can use @code{show} with no arguments; you may also use
2349 @code{info set}. Both commands produce the same display.
2350 @c FIXME: "info set" violates the rule that "info" is for state of
2351 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2352 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2356 Here are several miscellaneous @code{show} subcommands, all of which are
2357 exceptional in lacking corresponding @code{set} commands:
2360 @kindex show version
2361 @cindex @value{GDBN} version number
2363 Show what version of @value{GDBN} is running. You should include this
2364 information in @value{GDBN} bug-reports. If multiple versions of
2365 @value{GDBN} are in use at your site, you may need to determine which
2366 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2367 commands are introduced, and old ones may wither away. Also, many
2368 system vendors ship variant versions of @value{GDBN}, and there are
2369 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2370 The version number is the same as the one announced when you start
2373 @kindex show copying
2374 @kindex info copying
2375 @cindex display @value{GDBN} copyright
2378 Display information about permission for copying @value{GDBN}.
2380 @kindex show warranty
2381 @kindex info warranty
2383 @itemx info warranty
2384 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2385 if your version of @value{GDBN} comes with one.
2387 @kindex show configuration
2388 @item show configuration
2389 Display detailed information about the way @value{GDBN} was configured
2390 when it was built. This displays the optional arguments passed to the
2391 @file{configure} script and also configuration parameters detected
2392 automatically by @command{configure}. When reporting a @value{GDBN}
2393 bug (@pxref{GDB Bugs}), it is important to include this information in
2399 @chapter Running Programs Under @value{GDBN}
2401 When you run a program under @value{GDBN}, you must first generate
2402 debugging information when you compile it.
2404 You may start @value{GDBN} with its arguments, if any, in an environment
2405 of your choice. If you are doing native debugging, you may redirect
2406 your program's input and output, debug an already running process, or
2407 kill a child process.
2410 * Compilation:: Compiling for debugging
2411 * Starting:: Starting your program
2412 * Arguments:: Your program's arguments
2413 * Environment:: Your program's environment
2415 * Working Directory:: Your program's working directory
2416 * Input/Output:: Your program's input and output
2417 * Attach:: Debugging an already-running process
2418 * Kill Process:: Killing the child process
2419 * Inferiors Connections and Programs:: Debugging multiple inferiors
2420 connections and programs
2421 * Threads:: Debugging programs with multiple threads
2422 * Forks:: Debugging forks
2423 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2427 @section Compiling for Debugging
2429 In order to debug a program effectively, you need to generate
2430 debugging information when you compile it. This debugging information
2431 is stored in the object file; it describes the data type of each
2432 variable or function and the correspondence between source line numbers
2433 and addresses in the executable code.
2435 To request debugging information, specify the @samp{-g} option when you run
2438 Programs that are to be shipped to your customers are compiled with
2439 optimizations, using the @samp{-O} compiler option. However, some
2440 compilers are unable to handle the @samp{-g} and @samp{-O} options
2441 together. Using those compilers, you cannot generate optimized
2442 executables containing debugging information.
2444 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2445 without @samp{-O}, making it possible to debug optimized code. We
2446 recommend that you @emph{always} use @samp{-g} whenever you compile a
2447 program. You may think your program is correct, but there is no sense
2448 in pushing your luck. For more information, see @ref{Optimized Code}.
2450 Older versions of the @sc{gnu} C compiler permitted a variant option
2451 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2452 format; if your @sc{gnu} C compiler has this option, do not use it.
2454 @value{GDBN} knows about preprocessor macros and can show you their
2455 expansion (@pxref{Macros}). Most compilers do not include information
2456 about preprocessor macros in the debugging information if you specify
2457 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2458 the @sc{gnu} C compiler, provides macro information if you are using
2459 the DWARF debugging format, and specify the option @option{-g3}.
2461 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2462 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2463 information on @value{NGCC} options affecting debug information.
2465 You will have the best debugging experience if you use the latest
2466 version of the DWARF debugging format that your compiler supports.
2467 DWARF is currently the most expressive and best supported debugging
2468 format in @value{GDBN}.
2472 @section Starting your Program
2478 @kindex r @r{(@code{run})}
2481 Use the @code{run} command to start your program under @value{GDBN}.
2482 You must first specify the program name with an argument to
2483 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2484 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2485 command (@pxref{Files, ,Commands to Specify Files}).
2489 If you are running your program in an execution environment that
2490 supports processes, @code{run} creates an inferior process and makes
2491 that process run your program. In some environments without processes,
2492 @code{run} jumps to the start of your program. Other targets,
2493 like @samp{remote}, are always running. If you get an error
2494 message like this one:
2497 The "remote" target does not support "run".
2498 Try "help target" or "continue".
2502 then use @code{continue} to run your program. You may need @code{load}
2503 first (@pxref{load}).
2505 The execution of a program is affected by certain information it
2506 receives from its superior. @value{GDBN} provides ways to specify this
2507 information, which you must do @emph{before} starting your program. (You
2508 can change it after starting your program, but such changes only affect
2509 your program the next time you start it.) This information may be
2510 divided into four categories:
2513 @item The @emph{arguments.}
2514 Specify the arguments to give your program as the arguments of the
2515 @code{run} command. If a shell is available on your target, the shell
2516 is used to pass the arguments, so that you may use normal conventions
2517 (such as wildcard expansion or variable substitution) in describing
2519 In Unix systems, you can control which shell is used with the
2520 @code{SHELL} environment variable. If you do not define @code{SHELL},
2521 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2522 use of any shell with the @code{set startup-with-shell} command (see
2525 @item The @emph{environment.}
2526 Your program normally inherits its environment from @value{GDBN}, but you can
2527 use the @value{GDBN} commands @code{set environment} and @code{unset
2528 environment} to change parts of the environment that affect
2529 your program. @xref{Environment, ,Your Program's Environment}.
2531 @item The @emph{working directory.}
2532 You can set your program's working directory with the command
2533 @kbd{set cwd}. If you do not set any working directory with this
2534 command, your program will inherit @value{GDBN}'s working directory if
2535 native debugging, or the remote server's working directory if remote
2536 debugging. @xref{Working Directory, ,Your Program's Working
2539 @item The @emph{standard input and output.}
2540 Your program normally uses the same device for standard input and
2541 standard output as @value{GDBN} is using. You can redirect input and output
2542 in the @code{run} command line, or you can use the @code{tty} command to
2543 set a different device for your program.
2544 @xref{Input/Output, ,Your Program's Input and Output}.
2547 @emph{Warning:} While input and output redirection work, you cannot use
2548 pipes to pass the output of the program you are debugging to another
2549 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2553 When you issue the @code{run} command, your program begins to execute
2554 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2555 of how to arrange for your program to stop. Once your program has
2556 stopped, you may call functions in your program, using the @code{print}
2557 or @code{call} commands. @xref{Data, ,Examining Data}.
2559 If the modification time of your symbol file has changed since the last
2560 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2561 table, and reads it again. When it does this, @value{GDBN} tries to retain
2562 your current breakpoints.
2567 @cindex run to main procedure
2568 The name of the main procedure can vary from language to language.
2569 With C or C@t{++}, the main procedure name is always @code{main}, but
2570 other languages such as Ada do not require a specific name for their
2571 main procedure. The debugger provides a convenient way to start the
2572 execution of the program and to stop at the beginning of the main
2573 procedure, depending on the language used.
2575 The @samp{start} command does the equivalent of setting a temporary
2576 breakpoint at the beginning of the main procedure and then invoking
2577 the @samp{run} command.
2579 @cindex elaboration phase
2580 Some programs contain an @dfn{elaboration} phase where some startup code is
2581 executed before the main procedure is called. This depends on the
2582 languages used to write your program. In C@t{++}, for instance,
2583 constructors for static and global objects are executed before
2584 @code{main} is called. It is therefore possible that the debugger stops
2585 before reaching the main procedure. However, the temporary breakpoint
2586 will remain to halt execution.
2588 Specify the arguments to give to your program as arguments to the
2589 @samp{start} command. These arguments will be given verbatim to the
2590 underlying @samp{run} command. Note that the same arguments will be
2591 reused if no argument is provided during subsequent calls to
2592 @samp{start} or @samp{run}.
2594 It is sometimes necessary to debug the program during elaboration. In
2595 these cases, using the @code{start} command would stop the execution
2596 of your program too late, as the program would have already completed
2597 the elaboration phase. Under these circumstances, either insert
2598 breakpoints in your elaboration code before running your program or
2599 use the @code{starti} command.
2603 @cindex run to first instruction
2604 The @samp{starti} command does the equivalent of setting a temporary
2605 breakpoint at the first instruction of a program's execution and then
2606 invoking the @samp{run} command. For programs containing an
2607 elaboration phase, the @code{starti} command will stop execution at
2608 the start of the elaboration phase.
2610 @anchor{set exec-wrapper}
2611 @kindex set exec-wrapper
2612 @item set exec-wrapper @var{wrapper}
2613 @itemx show exec-wrapper
2614 @itemx unset exec-wrapper
2615 When @samp{exec-wrapper} is set, the specified wrapper is used to
2616 launch programs for debugging. @value{GDBN} starts your program
2617 with a shell command of the form @kbd{exec @var{wrapper}
2618 @var{program}}. Quoting is added to @var{program} and its
2619 arguments, but not to @var{wrapper}, so you should add quotes if
2620 appropriate for your shell. The wrapper runs until it executes
2621 your program, and then @value{GDBN} takes control.
2623 You can use any program that eventually calls @code{execve} with
2624 its arguments as a wrapper. Several standard Unix utilities do
2625 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2626 with @code{exec "$@@"} will also work.
2628 For example, you can use @code{env} to pass an environment variable to
2629 the debugged program, without setting the variable in your shell's
2633 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2637 This command is available when debugging locally on most targets, excluding
2638 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2640 @kindex set startup-with-shell
2641 @anchor{set startup-with-shell}
2642 @item set startup-with-shell
2643 @itemx set startup-with-shell on
2644 @itemx set startup-with-shell off
2645 @itemx show startup-with-shell
2646 On Unix systems, by default, if a shell is available on your target,
2647 @value{GDBN}) uses it to start your program. Arguments of the
2648 @code{run} command are passed to the shell, which does variable
2649 substitution, expands wildcard characters and performs redirection of
2650 I/O. In some circumstances, it may be useful to disable such use of a
2651 shell, for example, when debugging the shell itself or diagnosing
2652 startup failures such as:
2656 Starting program: ./a.out
2657 During startup program terminated with signal SIGSEGV, Segmentation fault.
2661 which indicates the shell or the wrapper specified with
2662 @samp{exec-wrapper} crashed, not your program. Most often, this is
2663 caused by something odd in your shell's non-interactive mode
2664 initialization file---such as @file{.cshrc} for C-shell,
2665 $@file{.zshenv} for the Z shell, or the file specified in the
2666 @samp{BASH_ENV} environment variable for BASH.
2668 @anchor{set auto-connect-native-target}
2669 @kindex set auto-connect-native-target
2670 @item set auto-connect-native-target
2671 @itemx set auto-connect-native-target on
2672 @itemx set auto-connect-native-target off
2673 @itemx show auto-connect-native-target
2675 By default, if the current inferior is not connected to any target yet
2676 (e.g., with @code{target remote}), the @code{run} command starts your
2677 program as a native process under @value{GDBN}, on your local machine.
2678 If you're sure you don't want to debug programs on your local machine,
2679 you can tell @value{GDBN} to not connect to the native target
2680 automatically with the @code{set auto-connect-native-target off}
2683 If @code{on}, which is the default, and if the current inferior is not
2684 connected to a target already, the @code{run} command automaticaly
2685 connects to the native target, if one is available.
2687 If @code{off}, and if the current inferior is not connected to a
2688 target already, the @code{run} command fails with an error:
2692 Don't know how to run. Try "help target".
2695 If the current inferior is already connected to a target, @value{GDBN}
2696 always uses it with the @code{run} command.
2698 In any case, you can explicitly connect to the native target with the
2699 @code{target native} command. For example,
2702 (@value{GDBP}) set auto-connect-native-target off
2704 Don't know how to run. Try "help target".
2705 (@value{GDBP}) target native
2707 Starting program: ./a.out
2708 [Inferior 1 (process 10421) exited normally]
2711 In case you connected explicitly to the @code{native} target,
2712 @value{GDBN} remains connected even if all inferiors exit, ready for
2713 the next @code{run} command. Use the @code{disconnect} command to
2716 Examples of other commands that likewise respect the
2717 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2718 proc}, @code{info os}.
2720 @kindex set disable-randomization
2721 @item set disable-randomization
2722 @itemx set disable-randomization on
2723 This option (enabled by default in @value{GDBN}) will turn off the native
2724 randomization of the virtual address space of the started program. This option
2725 is useful for multiple debugging sessions to make the execution better
2726 reproducible and memory addresses reusable across debugging sessions.
2728 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2729 On @sc{gnu}/Linux you can get the same behavior using
2732 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2735 @item set disable-randomization off
2736 Leave the behavior of the started executable unchanged. Some bugs rear their
2737 ugly heads only when the program is loaded at certain addresses. If your bug
2738 disappears when you run the program under @value{GDBN}, that might be because
2739 @value{GDBN} by default disables the address randomization on platforms, such
2740 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2741 disable-randomization off} to try to reproduce such elusive bugs.
2743 On targets where it is available, virtual address space randomization
2744 protects the programs against certain kinds of security attacks. In these
2745 cases the attacker needs to know the exact location of a concrete executable
2746 code. Randomizing its location makes it impossible to inject jumps misusing
2747 a code at its expected addresses.
2749 Prelinking shared libraries provides a startup performance advantage but it
2750 makes addresses in these libraries predictable for privileged processes by
2751 having just unprivileged access at the target system. Reading the shared
2752 library binary gives enough information for assembling the malicious code
2753 misusing it. Still even a prelinked shared library can get loaded at a new
2754 random address just requiring the regular relocation process during the
2755 startup. Shared libraries not already prelinked are always loaded at
2756 a randomly chosen address.
2758 Position independent executables (PIE) contain position independent code
2759 similar to the shared libraries and therefore such executables get loaded at
2760 a randomly chosen address upon startup. PIE executables always load even
2761 already prelinked shared libraries at a random address. You can build such
2762 executable using @command{gcc -fPIE -pie}.
2764 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2765 (as long as the randomization is enabled).
2767 @item show disable-randomization
2768 Show the current setting of the explicit disable of the native randomization of
2769 the virtual address space of the started program.
2774 @section Your Program's Arguments
2776 @cindex arguments (to your program)
2777 The arguments to your program can be specified by the arguments of the
2779 They are passed to a shell, which expands wildcard characters and
2780 performs redirection of I/O, and thence to your program. Your
2781 @code{SHELL} environment variable (if it exists) specifies what shell
2782 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2783 the default shell (@file{/bin/sh} on Unix).
2785 On non-Unix systems, the program is usually invoked directly by
2786 @value{GDBN}, which emulates I/O redirection via the appropriate system
2787 calls, and the wildcard characters are expanded by the startup code of
2788 the program, not by the shell.
2790 @code{run} with no arguments uses the same arguments used by the previous
2791 @code{run}, or those set by the @code{set args} command.
2796 Specify the arguments to be used the next time your program is run. If
2797 @code{set args} has no arguments, @code{run} executes your program
2798 with no arguments. Once you have run your program with arguments,
2799 using @code{set args} before the next @code{run} is the only way to run
2800 it again without arguments.
2804 Show the arguments to give your program when it is started.
2808 @section Your Program's Environment
2810 @cindex environment (of your program)
2811 The @dfn{environment} consists of a set of environment variables and
2812 their values. Environment variables conventionally record such things as
2813 your user name, your home directory, your terminal type, and your search
2814 path for programs to run. Usually you set up environment variables with
2815 the shell and they are inherited by all the other programs you run. When
2816 debugging, it can be useful to try running your program with a modified
2817 environment without having to start @value{GDBN} over again.
2821 @item path @var{directory}
2822 Add @var{directory} to the front of the @code{PATH} environment variable
2823 (the search path for executables) that will be passed to your program.
2824 The value of @code{PATH} used by @value{GDBN} does not change.
2825 You may specify several directory names, separated by whitespace or by a
2826 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2827 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2828 is moved to the front, so it is searched sooner.
2830 You can use the string @samp{$cwd} to refer to whatever is the current
2831 working directory at the time @value{GDBN} searches the path. If you
2832 use @samp{.} instead, it refers to the directory where you executed the
2833 @code{path} command. @value{GDBN} replaces @samp{.} in the
2834 @var{directory} argument (with the current path) before adding
2835 @var{directory} to the search path.
2836 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2837 @c document that, since repeating it would be a no-op.
2841 Display the list of search paths for executables (the @code{PATH}
2842 environment variable).
2844 @kindex show environment
2845 @item show environment @r{[}@var{varname}@r{]}
2846 Print the value of environment variable @var{varname} to be given to
2847 your program when it starts. If you do not supply @var{varname},
2848 print the names and values of all environment variables to be given to
2849 your program. You can abbreviate @code{environment} as @code{env}.
2851 @kindex set environment
2852 @anchor{set environment}
2853 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2854 Set environment variable @var{varname} to @var{value}. The value
2855 changes for your program (and the shell @value{GDBN} uses to launch
2856 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2857 values of environment variables are just strings, and any
2858 interpretation is supplied by your program itself. The @var{value}
2859 parameter is optional; if it is eliminated, the variable is set to a
2861 @c "any string" here does not include leading, trailing
2862 @c blanks. Gnu asks: does anyone care?
2864 For example, this command:
2871 tells the debugged program, when subsequently run, that its user is named
2872 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2873 are not actually required.)
2875 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2876 which also inherits the environment set with @code{set environment}.
2877 If necessary, you can avoid that by using the @samp{env} program as a
2878 wrapper instead of using @code{set environment}. @xref{set
2879 exec-wrapper}, for an example doing just that.
2881 Environment variables that are set by the user are also transmitted to
2882 @command{gdbserver} to be used when starting the remote inferior.
2883 @pxref{QEnvironmentHexEncoded}.
2885 @kindex unset environment
2886 @anchor{unset environment}
2887 @item unset environment @var{varname}
2888 Remove variable @var{varname} from the environment to be passed to your
2889 program. This is different from @samp{set env @var{varname} =};
2890 @code{unset environment} removes the variable from the environment,
2891 rather than assigning it an empty value.
2893 Environment variables that are unset by the user are also unset on
2894 @command{gdbserver} when starting the remote inferior.
2895 @pxref{QEnvironmentUnset}.
2898 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2899 the shell indicated by your @code{SHELL} environment variable if it
2900 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2901 names a shell that runs an initialization file when started
2902 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2903 for the Z shell, or the file specified in the @samp{BASH_ENV}
2904 environment variable for BASH---any variables you set in that file
2905 affect your program. You may wish to move setting of environment
2906 variables to files that are only run when you sign on, such as
2907 @file{.login} or @file{.profile}.
2909 @node Working Directory
2910 @section Your Program's Working Directory
2912 @cindex working directory (of your program)
2913 Each time you start your program with @code{run}, the inferior will be
2914 initialized with the current working directory specified by the
2915 @kbd{set cwd} command. If no directory has been specified by this
2916 command, then the inferior will inherit @value{GDBN}'s current working
2917 directory as its working directory if native debugging, or it will
2918 inherit the remote server's current working directory if remote
2923 @cindex change inferior's working directory
2924 @anchor{set cwd command}
2925 @item set cwd @r{[}@var{directory}@r{]}
2926 Set the inferior's working directory to @var{directory}, which will be
2927 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2928 argument has been specified, the command clears the setting and resets
2929 it to an empty state. This setting has no effect on @value{GDBN}'s
2930 working directory, and it only takes effect the next time you start
2931 the inferior. The @file{~} in @var{directory} is a short for the
2932 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2933 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2934 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2937 You can also change @value{GDBN}'s current working directory by using
2938 the @code{cd} command.
2942 @cindex show inferior's working directory
2944 Show the inferior's working directory. If no directory has been
2945 specified by @kbd{set cwd}, then the default inferior's working
2946 directory is the same as @value{GDBN}'s working directory.
2949 @cindex change @value{GDBN}'s working directory
2951 @item cd @r{[}@var{directory}@r{]}
2952 Set the @value{GDBN} working directory to @var{directory}. If not
2953 given, @var{directory} uses @file{'~'}.
2955 The @value{GDBN} working directory serves as a default for the
2956 commands that specify files for @value{GDBN} to operate on.
2957 @xref{Files, ,Commands to Specify Files}.
2958 @xref{set cwd command}.
2962 Print the @value{GDBN} working directory.
2965 It is generally impossible to find the current working directory of
2966 the process being debugged (since a program can change its directory
2967 during its run). If you work on a system where @value{GDBN} supports
2968 the @code{info proc} command (@pxref{Process Information}), you can
2969 use the @code{info proc} command to find out the
2970 current working directory of the debuggee.
2973 @section Your Program's Input and Output
2978 By default, the program you run under @value{GDBN} does input and output to
2979 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2980 to its own terminal modes to interact with you, but it records the terminal
2981 modes your program was using and switches back to them when you continue
2982 running your program.
2985 @kindex info terminal
2987 Displays information recorded by @value{GDBN} about the terminal modes your
2991 You can redirect your program's input and/or output using shell
2992 redirection with the @code{run} command. For example,
2999 starts your program, diverting its output to the file @file{outfile}.
3002 @cindex controlling terminal
3003 Another way to specify where your program should do input and output is
3004 with the @code{tty} command. This command accepts a file name as
3005 argument, and causes this file to be the default for future @code{run}
3006 commands. It also resets the controlling terminal for the child
3007 process, for future @code{run} commands. For example,
3014 directs that processes started with subsequent @code{run} commands
3015 default to do input and output on the terminal @file{/dev/ttyb} and have
3016 that as their controlling terminal.
3018 An explicit redirection in @code{run} overrides the @code{tty} command's
3019 effect on the input/output device, but not its effect on the controlling
3022 When you use the @code{tty} command or redirect input in the @code{run}
3023 command, only the input @emph{for your program} is affected. The input
3024 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3025 for @code{set inferior-tty}.
3027 @cindex inferior tty
3028 @cindex set inferior controlling terminal
3029 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3030 display the name of the terminal that will be used for future runs of your
3034 @item set inferior-tty [ @var{tty} ]
3035 @kindex set inferior-tty
3036 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3037 restores the default behavior, which is to use the same terminal as
3040 @item show inferior-tty
3041 @kindex show inferior-tty
3042 Show the current tty for the program being debugged.
3046 @section Debugging an Already-running Process
3051 @item attach @var{process-id}
3052 This command attaches to a running process---one that was started
3053 outside @value{GDBN}. (@code{info files} shows your active
3054 targets.) The command takes as argument a process ID. The usual way to
3055 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3056 or with the @samp{jobs -l} shell command.
3058 @code{attach} does not repeat if you press @key{RET} a second time after
3059 executing the command.
3062 To use @code{attach}, your program must be running in an environment
3063 which supports processes; for example, @code{attach} does not work for
3064 programs on bare-board targets that lack an operating system. You must
3065 also have permission to send the process a signal.
3067 When you use @code{attach}, the debugger finds the program running in
3068 the process first by looking in the current working directory, then (if
3069 the program is not found) by using the source file search path
3070 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3071 the @code{file} command to load the program. @xref{Files, ,Commands to
3074 @anchor{set exec-file-mismatch}
3075 If the debugger can determine that the executable file running in the
3076 process it is attaching to does not match the current exec-file loaded
3077 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3078 handle the mismatch. @value{GDBN} tries to compare the files by
3079 comparing their build IDs (@pxref{build ID}), if available.
3082 @kindex exec-file-mismatch
3083 @cindex set exec-file-mismatch
3084 @item set exec-file-mismatch @samp{ask|warn|off}
3086 Whether to detect mismatch between the current executable file loaded
3087 by @value{GDBN} and the executable file used to start the process. If
3088 @samp{ask}, the default, display a warning and ask the user whether to
3089 load the process executable file; if @samp{warn}, just display a
3090 warning; if @samp{off}, don't attempt to detect a mismatch.
3091 If the user confirms loading the process executable file, then its symbols
3092 will be loaded as well.
3094 @cindex show exec-file-mismatch
3095 @item show exec-file-mismatch
3096 Show the current value of @code{exec-file-mismatch}.
3100 The first thing @value{GDBN} does after arranging to debug the specified
3101 process is to stop it. You can examine and modify an attached process
3102 with all the @value{GDBN} commands that are ordinarily available when
3103 you start processes with @code{run}. You can insert breakpoints; you
3104 can step and continue; you can modify storage. If you would rather the
3105 process continue running, you may use the @code{continue} command after
3106 attaching @value{GDBN} to the process.
3111 When you have finished debugging the attached process, you can use the
3112 @code{detach} command to release it from @value{GDBN} control. Detaching
3113 the process continues its execution. After the @code{detach} command,
3114 that process and @value{GDBN} become completely independent once more, and you
3115 are ready to @code{attach} another process or start one with @code{run}.
3116 @code{detach} does not repeat if you press @key{RET} again after
3117 executing the command.
3120 If you exit @value{GDBN} while you have an attached process, you detach
3121 that process. If you use the @code{run} command, you kill that process.
3122 By default, @value{GDBN} asks for confirmation if you try to do either of these
3123 things; you can control whether or not you need to confirm by using the
3124 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3128 @section Killing the Child Process
3133 Kill the child process in which your program is running under @value{GDBN}.
3136 This command is useful if you wish to debug a core dump instead of a
3137 running process. @value{GDBN} ignores any core dump file while your program
3140 On some operating systems, a program cannot be executed outside @value{GDBN}
3141 while you have breakpoints set on it inside @value{GDBN}. You can use the
3142 @code{kill} command in this situation to permit running your program
3143 outside the debugger.
3145 The @code{kill} command is also useful if you wish to recompile and
3146 relink your program, since on many systems it is impossible to modify an
3147 executable file while it is running in a process. In this case, when you
3148 next type @code{run}, @value{GDBN} notices that the file has changed, and
3149 reads the symbol table again (while trying to preserve your current
3150 breakpoint settings).
3152 @node Inferiors Connections and Programs
3153 @section Debugging Multiple Inferiors Connections and Programs
3155 @value{GDBN} lets you run and debug multiple programs in a single
3156 session. In addition, @value{GDBN} on some systems may let you run
3157 several programs simultaneously (otherwise you have to exit from one
3158 before starting another). On some systems @value{GDBN} may even let
3159 you debug several programs simultaneously on different remote systems.
3160 In the most general case, you can have multiple threads of execution
3161 in each of multiple processes, launched from multiple executables,
3162 running on different machines.
3165 @value{GDBN} represents the state of each program execution with an
3166 object called an @dfn{inferior}. An inferior typically corresponds to
3167 a process, but is more general and applies also to targets that do not
3168 have processes. Inferiors may be created before a process runs, and
3169 may be retained after a process exits. Inferiors have unique
3170 identifiers that are different from process ids. Usually each
3171 inferior will also have its own distinct address space, although some
3172 embedded targets may have several inferiors running in different parts
3173 of a single address space. Each inferior may in turn have multiple
3174 threads running in it.
3176 To find out what inferiors exist at any moment, use @w{@code{info
3180 @kindex info inferiors [ @var{id}@dots{} ]
3181 @item info inferiors
3182 Print a list of all inferiors currently being managed by @value{GDBN}.
3183 By default all inferiors are printed, but the argument @var{id}@dots{}
3184 -- a space separated list of inferior numbers -- can be used to limit
3185 the display to just the requested inferiors.
3187 @value{GDBN} displays for each inferior (in this order):
3191 the inferior number assigned by @value{GDBN}
3194 the target system's inferior identifier
3197 the target connection the inferior is bound to, including the unique
3198 connection number assigned by @value{GDBN}, and the protocol used by
3202 the name of the executable the inferior is running.
3207 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3208 indicates the current inferior.
3212 @c end table here to get a little more width for example
3215 (@value{GDBP}) info inferiors
3216 Num Description Connection Executable
3217 * 1 process 3401 1 (native) goodbye
3218 2 process 2307 2 (extended-remote host:10000) hello
3221 To get informations about the current inferior, use @code{inferior}:
3226 Shows information about the current inferior.
3230 @c end table here to get a little more width for example
3233 (@value{GDBP}) inferior
3234 [Current inferior is 1 [process 3401] (helloworld)]
3237 To find out what open target connections exist at any moment, use
3238 @w{@code{info connections}}:
3241 @kindex info connections [ @var{id}@dots{} ]
3242 @item info connections
3243 Print a list of all open target connections currently being managed by
3244 @value{GDBN}. By default all connections are printed, but the
3245 argument @var{id}@dots{} -- a space separated list of connections
3246 numbers -- can be used to limit the display to just the requested
3249 @value{GDBN} displays for each connection (in this order):
3253 the connection number assigned by @value{GDBN}.
3256 the protocol used by the connection.
3259 a textual description of the protocol used by the connection.
3264 An asterisk @samp{*} preceding the connection number indicates the
3265 connection of the current inferior.
3269 @c end table here to get a little more width for example
3272 (@value{GDBP}) info connections
3273 Num What Description
3274 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3275 2 native Native process
3276 3 core Local core dump file
3279 To switch focus between inferiors, use the @code{inferior} command:
3282 @kindex inferior @var{infno}
3283 @item inferior @var{infno}
3284 Make inferior number @var{infno} the current inferior. The argument
3285 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3286 in the first field of the @samp{info inferiors} display.
3289 @vindex $_inferior@r{, convenience variable}
3290 The debugger convenience variable @samp{$_inferior} contains the
3291 number of the current inferior. You may find this useful in writing
3292 breakpoint conditional expressions, command scripts, and so forth.
3293 @xref{Convenience Vars,, Convenience Variables}, for general
3294 information on convenience variables.
3296 You can get multiple executables into a debugging session via the
3297 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3298 systems @value{GDBN} can add inferiors to the debug session
3299 automatically by following calls to @code{fork} and @code{exec}. To
3300 remove inferiors from the debugging session use the
3301 @w{@code{remove-inferiors}} command.
3304 @kindex add-inferior
3305 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3306 Adds @var{n} inferiors to be run using @var{executable} as the
3307 executable; @var{n} defaults to 1. If no executable is specified,
3308 the inferiors begins empty, with no program. You can still assign or
3309 change the program assigned to the inferior at any time by using the
3310 @code{file} command with the executable name as its argument.
3312 By default, the new inferior begins connected to the same target
3313 connection as the current inferior. For example, if the current
3314 inferior was connected to @code{gdbserver} with @code{target remote},
3315 then the new inferior will be connected to the same @code{gdbserver}
3316 instance. The @samp{-no-connection} option starts the new inferior
3317 with no connection yet. You can then for example use the @code{target
3318 remote} command to connect to some other @code{gdbserver} instance,
3319 use @code{run} to spawn a local program, etc.
3321 @kindex clone-inferior
3322 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3323 Adds @var{n} inferiors ready to execute the same program as inferior
3324 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3325 number of the current inferior. This is a convenient command when you
3326 want to run another instance of the inferior you are debugging.
3329 (@value{GDBP}) info inferiors
3330 Num Description Connection Executable
3331 * 1 process 29964 1 (native) helloworld
3332 (@value{GDBP}) clone-inferior
3335 (@value{GDBP}) info inferiors
3336 Num Description Connection Executable
3337 * 1 process 29964 1 (native) helloworld
3338 2 <null> 1 (native) helloworld
3341 You can now simply switch focus to inferior 2 and run it.
3343 @kindex remove-inferiors
3344 @item remove-inferiors @var{infno}@dots{}
3345 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3346 possible to remove an inferior that is running with this command. For
3347 those, use the @code{kill} or @code{detach} command first.
3351 To quit debugging one of the running inferiors that is not the current
3352 inferior, you can either detach from it by using the @w{@code{detach
3353 inferior}} command (allowing it to run independently), or kill it
3354 using the @w{@code{kill inferiors}} command:
3357 @kindex detach inferiors @var{infno}@dots{}
3358 @item detach inferior @var{infno}@dots{}
3359 Detach from the inferior or inferiors identified by @value{GDBN}
3360 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3361 still stays on the list of inferiors shown by @code{info inferiors},
3362 but its Description will show @samp{<null>}.
3364 @kindex kill inferiors @var{infno}@dots{}
3365 @item kill inferiors @var{infno}@dots{}
3366 Kill the inferior or inferiors identified by @value{GDBN} inferior
3367 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3368 stays on the list of inferiors shown by @code{info inferiors}, but its
3369 Description will show @samp{<null>}.
3372 After the successful completion of a command such as @code{detach},
3373 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3374 a normal process exit, the inferior is still valid and listed with
3375 @code{info inferiors}, ready to be restarted.
3378 To be notified when inferiors are started or exit under @value{GDBN}'s
3379 control use @w{@code{set print inferior-events}}:
3382 @kindex set print inferior-events
3383 @cindex print messages on inferior start and exit
3384 @item set print inferior-events
3385 @itemx set print inferior-events on
3386 @itemx set print inferior-events off
3387 The @code{set print inferior-events} command allows you to enable or
3388 disable printing of messages when @value{GDBN} notices that new
3389 inferiors have started or that inferiors have exited or have been
3390 detached. By default, these messages will not be printed.
3392 @kindex show print inferior-events
3393 @item show print inferior-events
3394 Show whether messages will be printed when @value{GDBN} detects that
3395 inferiors have started, exited or have been detached.
3398 Many commands will work the same with multiple programs as with a
3399 single program: e.g., @code{print myglobal} will simply display the
3400 value of @code{myglobal} in the current inferior.
3403 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3404 get more info about the relationship of inferiors, programs, address
3405 spaces in a debug session. You can do that with the @w{@code{maint
3406 info program-spaces}} command.
3409 @kindex maint info program-spaces
3410 @item maint info program-spaces
3411 Print a list of all program spaces currently being managed by
3414 @value{GDBN} displays for each program space (in this order):
3418 the program space number assigned by @value{GDBN}
3421 the name of the executable loaded into the program space, with e.g.,
3422 the @code{file} command.
3427 An asterisk @samp{*} preceding the @value{GDBN} program space number
3428 indicates the current program space.
3430 In addition, below each program space line, @value{GDBN} prints extra
3431 information that isn't suitable to display in tabular form. For
3432 example, the list of inferiors bound to the program space.
3435 (@value{GDBP}) maint info program-spaces
3439 Bound inferiors: ID 1 (process 21561)
3442 Here we can see that no inferior is running the program @code{hello},
3443 while @code{process 21561} is running the program @code{goodbye}. On
3444 some targets, it is possible that multiple inferiors are bound to the
3445 same program space. The most common example is that of debugging both
3446 the parent and child processes of a @code{vfork} call. For example,
3449 (@value{GDBP}) maint info program-spaces
3452 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3455 Here, both inferior 2 and inferior 1 are running in the same program
3456 space as a result of inferior 1 having executed a @code{vfork} call.
3460 @section Debugging Programs with Multiple Threads
3462 @cindex threads of execution
3463 @cindex multiple threads
3464 @cindex switching threads
3465 In some operating systems, such as GNU/Linux and Solaris, a single program
3466 may have more than one @dfn{thread} of execution. The precise semantics
3467 of threads differ from one operating system to another, but in general
3468 the threads of a single program are akin to multiple processes---except
3469 that they share one address space (that is, they can all examine and
3470 modify the same variables). On the other hand, each thread has its own
3471 registers and execution stack, and perhaps private memory.
3473 @value{GDBN} provides these facilities for debugging multi-thread
3477 @item automatic notification of new threads
3478 @item @samp{thread @var{thread-id}}, a command to switch among threads
3479 @item @samp{info threads}, a command to inquire about existing threads
3480 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3481 a command to apply a command to a list of threads
3482 @item thread-specific breakpoints
3483 @item @samp{set print thread-events}, which controls printing of
3484 messages on thread start and exit.
3485 @item @samp{set libthread-db-search-path @var{path}}, which lets
3486 the user specify which @code{libthread_db} to use if the default choice
3487 isn't compatible with the program.
3490 @cindex focus of debugging
3491 @cindex current thread
3492 The @value{GDBN} thread debugging facility allows you to observe all
3493 threads while your program runs---but whenever @value{GDBN} takes
3494 control, one thread in particular is always the focus of debugging.
3495 This thread is called the @dfn{current thread}. Debugging commands show
3496 program information from the perspective of the current thread.
3498 @cindex @code{New} @var{systag} message
3499 @cindex thread identifier (system)
3500 @c FIXME-implementors!! It would be more helpful if the [New...] message
3501 @c included GDB's numeric thread handle, so you could just go to that
3502 @c thread without first checking `info threads'.
3503 Whenever @value{GDBN} detects a new thread in your program, it displays
3504 the target system's identification for the thread with a message in the
3505 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3506 whose form varies depending on the particular system. For example, on
3507 @sc{gnu}/Linux, you might see
3510 [New Thread 0x41e02940 (LWP 25582)]
3514 when @value{GDBN} notices a new thread. In contrast, on other systems,
3515 the @var{systag} is simply something like @samp{process 368}, with no
3518 @c FIXME!! (1) Does the [New...] message appear even for the very first
3519 @c thread of a program, or does it only appear for the
3520 @c second---i.e.@: when it becomes obvious we have a multithread
3522 @c (2) *Is* there necessarily a first thread always? Or do some
3523 @c multithread systems permit starting a program with multiple
3524 @c threads ab initio?
3526 @anchor{thread numbers}
3527 @cindex thread number, per inferior
3528 @cindex thread identifier (GDB)
3529 For debugging purposes, @value{GDBN} associates its own thread number
3530 ---always a single integer---with each thread of an inferior. This
3531 number is unique between all threads of an inferior, but not unique
3532 between threads of different inferiors.
3534 @cindex qualified thread ID
3535 You can refer to a given thread in an inferior using the qualified
3536 @var{inferior-num}.@var{thread-num} syntax, also known as
3537 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3538 number and @var{thread-num} being the thread number of the given
3539 inferior. For example, thread @code{2.3} refers to thread number 3 of
3540 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3541 then @value{GDBN} infers you're referring to a thread of the current
3544 Until you create a second inferior, @value{GDBN} does not show the
3545 @var{inferior-num} part of thread IDs, even though you can always use
3546 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3547 of inferior 1, the initial inferior.
3549 @anchor{thread ID lists}
3550 @cindex thread ID lists
3551 Some commands accept a space-separated @dfn{thread ID list} as
3552 argument. A list element can be:
3556 A thread ID as shown in the first field of the @samp{info threads}
3557 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3561 A range of thread numbers, again with or without an inferior
3562 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3563 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3566 All threads of an inferior, specified with a star wildcard, with or
3567 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3568 @samp{1.*}) or @code{*}. The former refers to all threads of the
3569 given inferior, and the latter form without an inferior qualifier
3570 refers to all threads of the current inferior.
3574 For example, if the current inferior is 1, and inferior 7 has one
3575 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3576 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3577 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3578 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3582 @anchor{global thread numbers}
3583 @cindex global thread number
3584 @cindex global thread identifier (GDB)
3585 In addition to a @emph{per-inferior} number, each thread is also
3586 assigned a unique @emph{global} number, also known as @dfn{global
3587 thread ID}, a single integer. Unlike the thread number component of
3588 the thread ID, no two threads have the same global ID, even when
3589 you're debugging multiple inferiors.
3591 From @value{GDBN}'s perspective, a process always has at least one
3592 thread. In other words, @value{GDBN} assigns a thread number to the
3593 program's ``main thread'' even if the program is not multi-threaded.
3595 @vindex $_thread@r{, convenience variable}
3596 @vindex $_gthread@r{, convenience variable}
3597 The debugger convenience variables @samp{$_thread} and
3598 @samp{$_gthread} contain, respectively, the per-inferior thread number
3599 and the global thread number of the current thread. You may find this
3600 useful in writing breakpoint conditional expressions, command scripts,
3601 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3602 general information on convenience variables.
3604 If @value{GDBN} detects the program is multi-threaded, it augments the
3605 usual message about stopping at a breakpoint with the ID and name of
3606 the thread that hit the breakpoint.
3609 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3612 Likewise when the program receives a signal:
3615 Thread 1 "main" received signal SIGINT, Interrupt.
3619 @kindex info threads
3620 @item info threads @r{[}@var{thread-id-list}@r{]}
3622 Display information about one or more threads. With no arguments
3623 displays information about all threads. You can specify the list of
3624 threads that you want to display using the thread ID list syntax
3625 (@pxref{thread ID lists}).
3627 @value{GDBN} displays for each thread (in this order):
3631 the per-inferior thread number assigned by @value{GDBN}
3634 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3635 option was specified
3638 the target system's thread identifier (@var{systag})
3641 the thread's name, if one is known. A thread can either be named by
3642 the user (see @code{thread name}, below), or, in some cases, by the
3646 the current stack frame summary for that thread
3650 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3651 indicates the current thread.
3655 @c end table here to get a little more width for example
3658 (@value{GDBP}) info threads
3660 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3661 2 process 35 thread 23 0x34e5 in sigpause ()
3662 3 process 35 thread 27 0x34e5 in sigpause ()
3666 If you're debugging multiple inferiors, @value{GDBN} displays thread
3667 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3668 Otherwise, only @var{thread-num} is shown.
3670 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3671 indicating each thread's global thread ID:
3674 (@value{GDBP}) info threads
3675 Id GId Target Id Frame
3676 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3677 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3678 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3679 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3682 On Solaris, you can display more information about user threads with a
3683 Solaris-specific command:
3686 @item maint info sol-threads
3687 @kindex maint info sol-threads
3688 @cindex thread info (Solaris)
3689 Display info on Solaris user threads.
3693 @kindex thread @var{thread-id}
3694 @item thread @var{thread-id}
3695 Make thread ID @var{thread-id} the current thread. The command
3696 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3697 the first field of the @samp{info threads} display, with or without an
3698 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3700 @value{GDBN} responds by displaying the system identifier of the
3701 thread you selected, and its current stack frame summary:
3704 (@value{GDBP}) thread 2
3705 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3706 #0 some_function (ignore=0x0) at example.c:8
3707 8 printf ("hello\n");
3711 As with the @samp{[New @dots{}]} message, the form of the text after
3712 @samp{Switching to} depends on your system's conventions for identifying
3715 @anchor{thread apply all}
3716 @kindex thread apply
3717 @cindex apply command to several threads
3718 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3719 The @code{thread apply} command allows you to apply the named
3720 @var{command} to one or more threads. Specify the threads that you
3721 want affected using the thread ID list syntax (@pxref{thread ID
3722 lists}), or specify @code{all} to apply to all threads. To apply a
3723 command to all threads in descending order, type @kbd{thread apply all
3724 @var{command}}. To apply a command to all threads in ascending order,
3725 type @kbd{thread apply all -ascending @var{command}}.
3727 The @var{flag} arguments control what output to produce and how to handle
3728 errors raised when applying @var{command} to a thread. @var{flag}
3729 must start with a @code{-} directly followed by one letter in
3730 @code{qcs}. If several flags are provided, they must be given
3731 individually, such as @code{-c -q}.
3733 By default, @value{GDBN} displays some thread information before the
3734 output produced by @var{command}, and an error raised during the
3735 execution of a @var{command} will abort @code{thread apply}. The
3736 following flags can be used to fine-tune this behavior:
3740 The flag @code{-c}, which stands for @samp{continue}, causes any
3741 errors in @var{command} to be displayed, and the execution of
3742 @code{thread apply} then continues.
3744 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3745 or empty output produced by a @var{command} to be silently ignored.
3746 That is, the execution continues, but the thread information and errors
3749 The flag @code{-q} (@samp{quiet}) disables printing the thread
3753 Flags @code{-c} and @code{-s} cannot be used together.
3756 @cindex apply command to all threads (ignoring errors and empty output)
3757 @item taas [@var{option}]@dots{} @var{command}
3758 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3759 Applies @var{command} on all threads, ignoring errors and empty output.
3761 The @code{taas} command accepts the same options as the @code{thread
3762 apply all} command. @xref{thread apply all}.
3765 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3766 @item tfaas [@var{option}]@dots{} @var{command}
3767 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3768 Applies @var{command} on all frames of all threads, ignoring errors
3769 and empty output. Note that the flag @code{-s} is specified twice:
3770 The first @code{-s} ensures that @code{thread apply} only shows the thread
3771 information of the threads for which @code{frame apply} produces
3772 some output. The second @code{-s} is needed to ensure that @code{frame
3773 apply} shows the frame information of a frame only if the
3774 @var{command} successfully produced some output.
3776 It can for example be used to print a local variable or a function
3777 argument without knowing the thread or frame where this variable or argument
3780 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3783 The @code{tfaas} command accepts the same options as the @code{frame
3784 apply} command. @xref{Frame Apply,,frame apply}.
3787 @cindex name a thread
3788 @item thread name [@var{name}]
3789 This command assigns a name to the current thread. If no argument is
3790 given, any existing user-specified name is removed. The thread name
3791 appears in the @samp{info threads} display.
3793 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3794 determine the name of the thread as given by the OS. On these
3795 systems, a name specified with @samp{thread name} will override the
3796 system-give name, and removing the user-specified name will cause
3797 @value{GDBN} to once again display the system-specified name.
3800 @cindex search for a thread
3801 @item thread find [@var{regexp}]
3802 Search for and display thread ids whose name or @var{systag}
3803 matches the supplied regular expression.
3805 As well as being the complement to the @samp{thread name} command,
3806 this command also allows you to identify a thread by its target
3807 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3811 (@value{GDBN}) thread find 26688
3812 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3813 (@value{GDBN}) info thread 4
3815 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3818 @kindex set print thread-events
3819 @cindex print messages on thread start and exit
3820 @item set print thread-events
3821 @itemx set print thread-events on
3822 @itemx set print thread-events off
3823 The @code{set print thread-events} command allows you to enable or
3824 disable printing of messages when @value{GDBN} notices that new threads have
3825 started or that threads have exited. By default, these messages will
3826 be printed if detection of these events is supported by the target.
3827 Note that these messages cannot be disabled on all targets.
3829 @kindex show print thread-events
3830 @item show print thread-events
3831 Show whether messages will be printed when @value{GDBN} detects that threads
3832 have started and exited.
3835 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3836 more information about how @value{GDBN} behaves when you stop and start
3837 programs with multiple threads.
3839 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3840 watchpoints in programs with multiple threads.
3842 @anchor{set libthread-db-search-path}
3844 @kindex set libthread-db-search-path
3845 @cindex search path for @code{libthread_db}
3846 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3847 If this variable is set, @var{path} is a colon-separated list of
3848 directories @value{GDBN} will use to search for @code{libthread_db}.
3849 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3850 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3851 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3854 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3855 @code{libthread_db} library to obtain information about threads in the
3856 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3857 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3858 specific thread debugging library loading is enabled
3859 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3861 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3862 refers to the default system directories that are
3863 normally searched for loading shared libraries. The @samp{$sdir} entry
3864 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3865 (@pxref{libthread_db.so.1 file}).
3867 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3868 refers to the directory from which @code{libpthread}
3869 was loaded in the inferior process.
3871 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3872 @value{GDBN} attempts to initialize it with the current inferior process.
3873 If this initialization fails (which could happen because of a version
3874 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3875 will unload @code{libthread_db}, and continue with the next directory.
3876 If none of @code{libthread_db} libraries initialize successfully,
3877 @value{GDBN} will issue a warning and thread debugging will be disabled.
3879 Setting @code{libthread-db-search-path} is currently implemented
3880 only on some platforms.
3882 @kindex show libthread-db-search-path
3883 @item show libthread-db-search-path
3884 Display current libthread_db search path.
3886 @kindex set debug libthread-db
3887 @kindex show debug libthread-db
3888 @cindex debugging @code{libthread_db}
3889 @item set debug libthread-db
3890 @itemx show debug libthread-db
3891 Turns on or off display of @code{libthread_db}-related events.
3892 Use @code{1} to enable, @code{0} to disable.
3896 @section Debugging Forks
3898 @cindex fork, debugging programs which call
3899 @cindex multiple processes
3900 @cindex processes, multiple
3901 On most systems, @value{GDBN} has no special support for debugging
3902 programs which create additional processes using the @code{fork}
3903 function. When a program forks, @value{GDBN} will continue to debug the
3904 parent process and the child process will run unimpeded. If you have
3905 set a breakpoint in any code which the child then executes, the child
3906 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3907 will cause it to terminate.
3909 However, if you want to debug the child process there is a workaround
3910 which isn't too painful. Put a call to @code{sleep} in the code which
3911 the child process executes after the fork. It may be useful to sleep
3912 only if a certain environment variable is set, or a certain file exists,
3913 so that the delay need not occur when you don't want to run @value{GDBN}
3914 on the child. While the child is sleeping, use the @code{ps} program to
3915 get its process ID. Then tell @value{GDBN} (a new invocation of
3916 @value{GDBN} if you are also debugging the parent process) to attach to
3917 the child process (@pxref{Attach}). From that point on you can debug
3918 the child process just like any other process which you attached to.
3920 On some systems, @value{GDBN} provides support for debugging programs
3921 that create additional processes using the @code{fork} or @code{vfork}
3922 functions. On @sc{gnu}/Linux platforms, this feature is supported
3923 with kernel version 2.5.46 and later.
3925 The fork debugging commands are supported in native mode and when
3926 connected to @code{gdbserver} in either @code{target remote} mode or
3927 @code{target extended-remote} mode.
3929 By default, when a program forks, @value{GDBN} will continue to debug
3930 the parent process and the child process will run unimpeded.
3932 If you want to follow the child process instead of the parent process,
3933 use the command @w{@code{set follow-fork-mode}}.
3936 @kindex set follow-fork-mode
3937 @item set follow-fork-mode @var{mode}
3938 Set the debugger response to a program call of @code{fork} or
3939 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3940 process. The @var{mode} argument can be:
3944 The original process is debugged after a fork. The child process runs
3945 unimpeded. This is the default.
3948 The new process is debugged after a fork. The parent process runs
3953 @kindex show follow-fork-mode
3954 @item show follow-fork-mode
3955 Display the current debugger response to a @code{fork} or @code{vfork} call.
3958 @cindex debugging multiple processes
3959 On Linux, if you want to debug both the parent and child processes, use the
3960 command @w{@code{set detach-on-fork}}.
3963 @kindex set detach-on-fork
3964 @item set detach-on-fork @var{mode}
3965 Tells gdb whether to detach one of the processes after a fork, or
3966 retain debugger control over them both.
3970 The child process (or parent process, depending on the value of
3971 @code{follow-fork-mode}) will be detached and allowed to run
3972 independently. This is the default.
3975 Both processes will be held under the control of @value{GDBN}.
3976 One process (child or parent, depending on the value of
3977 @code{follow-fork-mode}) is debugged as usual, while the other
3982 @kindex show detach-on-fork
3983 @item show detach-on-fork
3984 Show whether detach-on-fork mode is on/off.
3987 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3988 will retain control of all forked processes (including nested forks).
3989 You can list the forked processes under the control of @value{GDBN} by
3990 using the @w{@code{info inferiors}} command, and switch from one fork
3991 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3992 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3994 To quit debugging one of the forked processes, you can either detach
3995 from it by using the @w{@code{detach inferiors}} command (allowing it
3996 to run independently), or kill it using the @w{@code{kill inferiors}}
3997 command. @xref{Inferiors Connections and Programs, ,Debugging
3998 Multiple Inferiors Connections and Programs}.
4000 If you ask to debug a child process and a @code{vfork} is followed by an
4001 @code{exec}, @value{GDBN} executes the new target up to the first
4002 breakpoint in the new target. If you have a breakpoint set on
4003 @code{main} in your original program, the breakpoint will also be set on
4004 the child process's @code{main}.
4006 On some systems, when a child process is spawned by @code{vfork}, you
4007 cannot debug the child or parent until an @code{exec} call completes.
4009 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
4010 call executes, the new target restarts. To restart the parent
4011 process, use the @code{file} command with the parent executable name
4012 as its argument. By default, after an @code{exec} call executes,
4013 @value{GDBN} discards the symbols of the previous executable image.
4014 You can change this behaviour with the @w{@code{set follow-exec-mode}}
4018 @kindex set follow-exec-mode
4019 @item set follow-exec-mode @var{mode}
4021 Set debugger response to a program call of @code{exec}. An
4022 @code{exec} call replaces the program image of a process.
4024 @code{follow-exec-mode} can be:
4028 @value{GDBN} creates a new inferior and rebinds the process to this
4029 new inferior. The program the process was running before the
4030 @code{exec} call can be restarted afterwards by restarting the
4036 (@value{GDBP}) info inferiors
4038 Id Description Executable
4041 process 12020 is executing new program: prog2
4042 Program exited normally.
4043 (@value{GDBP}) info inferiors
4044 Id Description Executable
4050 @value{GDBN} keeps the process bound to the same inferior. The new
4051 executable image replaces the previous executable loaded in the
4052 inferior. Restarting the inferior after the @code{exec} call, with
4053 e.g., the @code{run} command, restarts the executable the process was
4054 running after the @code{exec} call. This is the default mode.
4059 (@value{GDBP}) info inferiors
4060 Id Description Executable
4063 process 12020 is executing new program: prog2
4064 Program exited normally.
4065 (@value{GDBP}) info inferiors
4066 Id Description Executable
4073 @code{follow-exec-mode} is supported in native mode and
4074 @code{target extended-remote} mode.
4076 You can use the @code{catch} command to make @value{GDBN} stop whenever
4077 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4078 Catchpoints, ,Setting Catchpoints}.
4080 @node Checkpoint/Restart
4081 @section Setting a @emph{Bookmark} to Return to Later
4086 @cindex snapshot of a process
4087 @cindex rewind program state
4089 On certain operating systems@footnote{Currently, only
4090 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4091 program's state, called a @dfn{checkpoint}, and come back to it
4094 Returning to a checkpoint effectively undoes everything that has
4095 happened in the program since the @code{checkpoint} was saved. This
4096 includes changes in memory, registers, and even (within some limits)
4097 system state. Effectively, it is like going back in time to the
4098 moment when the checkpoint was saved.
4100 Thus, if you're stepping thru a program and you think you're
4101 getting close to the point where things go wrong, you can save
4102 a checkpoint. Then, if you accidentally go too far and miss
4103 the critical statement, instead of having to restart your program
4104 from the beginning, you can just go back to the checkpoint and
4105 start again from there.
4107 This can be especially useful if it takes a lot of time or
4108 steps to reach the point where you think the bug occurs.
4110 To use the @code{checkpoint}/@code{restart} method of debugging:
4115 Save a snapshot of the debugged program's current execution state.
4116 The @code{checkpoint} command takes no arguments, but each checkpoint
4117 is assigned a small integer id, similar to a breakpoint id.
4119 @kindex info checkpoints
4120 @item info checkpoints
4121 List the checkpoints that have been saved in the current debugging
4122 session. For each checkpoint, the following information will be
4129 @item Source line, or label
4132 @kindex restart @var{checkpoint-id}
4133 @item restart @var{checkpoint-id}
4134 Restore the program state that was saved as checkpoint number
4135 @var{checkpoint-id}. All program variables, registers, stack frames
4136 etc.@: will be returned to the values that they had when the checkpoint
4137 was saved. In essence, gdb will ``wind back the clock'' to the point
4138 in time when the checkpoint was saved.
4140 Note that breakpoints, @value{GDBN} variables, command history etc.
4141 are not affected by restoring a checkpoint. In general, a checkpoint
4142 only restores things that reside in the program being debugged, not in
4145 @kindex delete checkpoint @var{checkpoint-id}
4146 @item delete checkpoint @var{checkpoint-id}
4147 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4151 Returning to a previously saved checkpoint will restore the user state
4152 of the program being debugged, plus a significant subset of the system
4153 (OS) state, including file pointers. It won't ``un-write'' data from
4154 a file, but it will rewind the file pointer to the previous location,
4155 so that the previously written data can be overwritten. For files
4156 opened in read mode, the pointer will also be restored so that the
4157 previously read data can be read again.
4159 Of course, characters that have been sent to a printer (or other
4160 external device) cannot be ``snatched back'', and characters received
4161 from eg.@: a serial device can be removed from internal program buffers,
4162 but they cannot be ``pushed back'' into the serial pipeline, ready to
4163 be received again. Similarly, the actual contents of files that have
4164 been changed cannot be restored (at this time).
4166 However, within those constraints, you actually can ``rewind'' your
4167 program to a previously saved point in time, and begin debugging it
4168 again --- and you can change the course of events so as to debug a
4169 different execution path this time.
4171 @cindex checkpoints and process id
4172 Finally, there is one bit of internal program state that will be
4173 different when you return to a checkpoint --- the program's process
4174 id. Each checkpoint will have a unique process id (or @var{pid}),
4175 and each will be different from the program's original @var{pid}.
4176 If your program has saved a local copy of its process id, this could
4177 potentially pose a problem.
4179 @subsection A Non-obvious Benefit of Using Checkpoints
4181 On some systems such as @sc{gnu}/Linux, address space randomization
4182 is performed on new processes for security reasons. This makes it
4183 difficult or impossible to set a breakpoint, or watchpoint, on an
4184 absolute address if you have to restart the program, since the
4185 absolute location of a symbol will change from one execution to the
4188 A checkpoint, however, is an @emph{identical} copy of a process.
4189 Therefore if you create a checkpoint at (eg.@:) the start of main,
4190 and simply return to that checkpoint instead of restarting the
4191 process, you can avoid the effects of address randomization and
4192 your symbols will all stay in the same place.
4195 @chapter Stopping and Continuing
4197 The principal purposes of using a debugger are so that you can stop your
4198 program before it terminates; or so that, if your program runs into
4199 trouble, you can investigate and find out why.
4201 Inside @value{GDBN}, your program may stop for any of several reasons,
4202 such as a signal, a breakpoint, or reaching a new line after a
4203 @value{GDBN} command such as @code{step}. You may then examine and
4204 change variables, set new breakpoints or remove old ones, and then
4205 continue execution. Usually, the messages shown by @value{GDBN} provide
4206 ample explanation of the status of your program---but you can also
4207 explicitly request this information at any time.
4210 @kindex info program
4212 Display information about the status of your program: whether it is
4213 running or not, what process it is, and why it stopped.
4217 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4218 * Continuing and Stepping:: Resuming execution
4219 * Skipping Over Functions and Files::
4220 Skipping over functions and files
4222 * Thread Stops:: Stopping and starting multi-thread programs
4226 @section Breakpoints, Watchpoints, and Catchpoints
4229 A @dfn{breakpoint} makes your program stop whenever a certain point in
4230 the program is reached. For each breakpoint, you can add conditions to
4231 control in finer detail whether your program stops. You can set
4232 breakpoints with the @code{break} command and its variants (@pxref{Set
4233 Breaks, ,Setting Breakpoints}), to specify the place where your program
4234 should stop by line number, function name or exact address in the
4237 On some systems, you can set breakpoints in shared libraries before
4238 the executable is run.
4241 @cindex data breakpoints
4242 @cindex memory tracing
4243 @cindex breakpoint on memory address
4244 @cindex breakpoint on variable modification
4245 A @dfn{watchpoint} is a special breakpoint that stops your program
4246 when the value of an expression changes. The expression may be a value
4247 of a variable, or it could involve values of one or more variables
4248 combined by operators, such as @samp{a + b}. This is sometimes called
4249 @dfn{data breakpoints}. You must use a different command to set
4250 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4251 from that, you can manage a watchpoint like any other breakpoint: you
4252 enable, disable, and delete both breakpoints and watchpoints using the
4255 You can arrange to have values from your program displayed automatically
4256 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4260 @cindex breakpoint on events
4261 A @dfn{catchpoint} is another special breakpoint that stops your program
4262 when a certain kind of event occurs, such as the throwing of a C@t{++}
4263 exception or the loading of a library. As with watchpoints, you use a
4264 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4265 Catchpoints}), but aside from that, you can manage a catchpoint like any
4266 other breakpoint. (To stop when your program receives a signal, use the
4267 @code{handle} command; see @ref{Signals, ,Signals}.)
4269 @cindex breakpoint numbers
4270 @cindex numbers for breakpoints
4271 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4272 catchpoint when you create it; these numbers are successive integers
4273 starting with one. In many of the commands for controlling various
4274 features of breakpoints you use the breakpoint number to say which
4275 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4276 @dfn{disabled}; if disabled, it has no effect on your program until you
4279 @cindex breakpoint ranges
4280 @cindex breakpoint lists
4281 @cindex ranges of breakpoints
4282 @cindex lists of breakpoints
4283 Some @value{GDBN} commands accept a space-separated list of breakpoints
4284 on which to operate. A list element can be either a single breakpoint number,
4285 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4286 When a breakpoint list is given to a command, all breakpoints in that list
4290 * Set Breaks:: Setting breakpoints
4291 * Set Watchpoints:: Setting watchpoints
4292 * Set Catchpoints:: Setting catchpoints
4293 * Delete Breaks:: Deleting breakpoints
4294 * Disabling:: Disabling breakpoints
4295 * Conditions:: Break conditions
4296 * Break Commands:: Breakpoint command lists
4297 * Dynamic Printf:: Dynamic printf
4298 * Save Breakpoints:: How to save breakpoints in a file
4299 * Static Probe Points:: Listing static probe points
4300 * Error in Breakpoints:: ``Cannot insert breakpoints''
4301 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4305 @subsection Setting Breakpoints
4307 @c FIXME LMB what does GDB do if no code on line of breakpt?
4308 @c consider in particular declaration with/without initialization.
4310 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4313 @kindex b @r{(@code{break})}
4314 @vindex $bpnum@r{, convenience variable}
4315 @cindex latest breakpoint
4316 Breakpoints are set with the @code{break} command (abbreviated
4317 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4318 number of the breakpoint you've set most recently; see @ref{Convenience
4319 Vars,, Convenience Variables}, for a discussion of what you can do with
4320 convenience variables.
4323 @item break @var{location}
4324 Set a breakpoint at the given @var{location}, which can specify a
4325 function name, a line number, or an address of an instruction.
4326 (@xref{Specify Location}, for a list of all the possible ways to
4327 specify a @var{location}.) The breakpoint will stop your program just
4328 before it executes any of the code in the specified @var{location}.
4330 When using source languages that permit overloading of symbols, such as
4331 C@t{++}, a function name may refer to more than one possible place to break.
4332 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4335 It is also possible to insert a breakpoint that will stop the program
4336 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4337 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4340 When called without any arguments, @code{break} sets a breakpoint at
4341 the next instruction to be executed in the selected stack frame
4342 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4343 innermost, this makes your program stop as soon as control
4344 returns to that frame. This is similar to the effect of a
4345 @code{finish} command in the frame inside the selected frame---except
4346 that @code{finish} does not leave an active breakpoint. If you use
4347 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4348 the next time it reaches the current location; this may be useful
4351 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4352 least one instruction has been executed. If it did not do this, you
4353 would be unable to proceed past a breakpoint without first disabling the
4354 breakpoint. This rule applies whether or not the breakpoint already
4355 existed when your program stopped.
4357 @item break @dots{} if @var{cond}
4358 Set a breakpoint with condition @var{cond}; evaluate the expression
4359 @var{cond} each time the breakpoint is reached, and stop only if the
4360 value is nonzero---that is, if @var{cond} evaluates as true.
4361 @samp{@dots{}} stands for one of the possible arguments described
4362 above (or no argument) specifying where to break. @xref{Conditions,
4363 ,Break Conditions}, for more information on breakpoint conditions.
4365 The breakpoint may be mapped to multiple locations. If the breakpoint
4366 condition @var{cond} is invalid at some but not all of the locations,
4367 the locations for which the condition is invalid are disabled. For
4368 example, @value{GDBN} reports below that two of the three locations
4372 (@value{GDBP}) break func if a == 10
4373 warning: failed to validate condition at location 0x11ce, disabling:
4374 No symbol "a" in current context.
4375 warning: failed to validate condition at location 0x11b6, disabling:
4376 No symbol "a" in current context.
4377 Breakpoint 1 at 0x11b6: func. (3 locations)
4380 Locations that are disabled because of the condition are denoted by an
4381 uppercase @code{N} in the output of the @code{info breakpoints}
4385 (@value{GDBP}) info breakpoints
4386 Num Type Disp Enb Address What
4387 1 breakpoint keep y <MULTIPLE>
4388 stop only if a == 10
4389 1.1 N* 0x00000000000011b6 in ...
4390 1.2 y 0x00000000000011c2 in ...
4391 1.3 N* 0x00000000000011ce in ...
4392 (*): Breakpoint condition is invalid at this location.
4395 If the breakpoint condition @var{cond} is invalid in the context of
4396 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4397 define the breakpoint. For example, if variable @code{foo} is an
4401 (@value{GDBP}) break func if foo
4402 No symbol "foo" in current context.
4405 @item break @dots{} -force-condition if @var{cond}
4406 There may be cases where the condition @var{cond} is invalid at all
4407 the current locations, but the user knows that it will be valid at a
4408 future location; for example, because of a library load. In such
4409 cases, by using the @code{-force-condition} keyword before @samp{if},
4410 @value{GDBN} can be forced to define the breakpoint with the given
4411 condition expression instead of refusing it.
4414 (@value{GDBP}) break func -force-condition if foo
4415 warning: failed to validate condition at location 1, disabling:
4416 No symbol "foo" in current context.
4417 warning: failed to validate condition at location 2, disabling:
4418 No symbol "foo" in current context.
4419 warning: failed to validate condition at location 3, disabling:
4420 No symbol "foo" in current context.
4421 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4424 This causes all the present locations where the breakpoint would
4425 otherwise be inserted, to be disabled, as seen in the example above.
4426 However, if there exist locations at which the condition is valid, the
4427 @code{-force-condition} keyword has no effect.
4430 @item tbreak @var{args}
4431 Set a breakpoint enabled only for one stop. The @var{args} are the
4432 same as for the @code{break} command, and the breakpoint is set in the same
4433 way, but the breakpoint is automatically deleted after the first time your
4434 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4437 @cindex hardware breakpoints
4438 @item hbreak @var{args}
4439 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4440 @code{break} command and the breakpoint is set in the same way, but the
4441 breakpoint requires hardware support and some target hardware may not
4442 have this support. The main purpose of this is EPROM/ROM code
4443 debugging, so you can set a breakpoint at an instruction without
4444 changing the instruction. This can be used with the new trap-generation
4445 provided by SPARClite DSU and most x86-based targets. These targets
4446 will generate traps when a program accesses some data or instruction
4447 address that is assigned to the debug registers. However the hardware
4448 breakpoint registers can take a limited number of breakpoints. For
4449 example, on the DSU, only two data breakpoints can be set at a time, and
4450 @value{GDBN} will reject this command if more than two are used. Delete
4451 or disable unused hardware breakpoints before setting new ones
4452 (@pxref{Disabling, ,Disabling Breakpoints}).
4453 @xref{Conditions, ,Break Conditions}.
4454 For remote targets, you can restrict the number of hardware
4455 breakpoints @value{GDBN} will use, see @ref{set remote
4456 hardware-breakpoint-limit}.
4459 @item thbreak @var{args}
4460 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4461 are the same as for the @code{hbreak} command and the breakpoint is set in
4462 the same way. However, like the @code{tbreak} command,
4463 the breakpoint is automatically deleted after the
4464 first time your program stops there. Also, like the @code{hbreak}
4465 command, the breakpoint requires hardware support and some target hardware
4466 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4467 See also @ref{Conditions, ,Break Conditions}.
4470 @cindex regular expression
4471 @cindex breakpoints at functions matching a regexp
4472 @cindex set breakpoints in many functions
4473 @item rbreak @var{regex}
4474 Set breakpoints on all functions matching the regular expression
4475 @var{regex}. This command sets an unconditional breakpoint on all
4476 matches, printing a list of all breakpoints it set. Once these
4477 breakpoints are set, they are treated just like the breakpoints set with
4478 the @code{break} command. You can delete them, disable them, or make
4479 them conditional the same way as any other breakpoint.
4481 In programs using different languages, @value{GDBN} chooses the syntax
4482 to print the list of all breakpoints it sets according to the
4483 @samp{set language} value: using @samp{set language auto}
4484 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4485 language of the breakpoint's function, other values mean to use
4486 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4488 The syntax of the regular expression is the standard one used with tools
4489 like @file{grep}. Note that this is different from the syntax used by
4490 shells, so for instance @code{foo*} matches all functions that include
4491 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4492 @code{.*} leading and trailing the regular expression you supply, so to
4493 match only functions that begin with @code{foo}, use @code{^foo}.
4495 @cindex non-member C@t{++} functions, set breakpoint in
4496 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4497 breakpoints on overloaded functions that are not members of any special
4500 @cindex set breakpoints on all functions
4501 The @code{rbreak} command can be used to set breakpoints in
4502 @strong{all} the functions in a program, like this:
4505 (@value{GDBP}) rbreak .
4508 @item rbreak @var{file}:@var{regex}
4509 If @code{rbreak} is called with a filename qualification, it limits
4510 the search for functions matching the given regular expression to the
4511 specified @var{file}. This can be used, for example, to set breakpoints on
4512 every function in a given file:
4515 (@value{GDBP}) rbreak file.c:.
4518 The colon separating the filename qualifier from the regex may
4519 optionally be surrounded by spaces.
4521 @kindex info breakpoints
4522 @cindex @code{$_} and @code{info breakpoints}
4523 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4524 @itemx info break @r{[}@var{list}@dots{}@r{]}
4525 Print a table of all breakpoints, watchpoints, and catchpoints set and
4526 not deleted. Optional argument @var{n} means print information only
4527 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4528 For each breakpoint, following columns are printed:
4531 @item Breakpoint Numbers
4533 Breakpoint, watchpoint, or catchpoint.
4535 Whether the breakpoint is marked to be disabled or deleted when hit.
4536 @item Enabled or Disabled
4537 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4538 that are not enabled.
4540 Where the breakpoint is in your program, as a memory address. For a
4541 pending breakpoint whose address is not yet known, this field will
4542 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4543 library that has the symbol or line referred by breakpoint is loaded.
4544 See below for details. A breakpoint with several locations will
4545 have @samp{<MULTIPLE>} in this field---see below for details.
4547 Where the breakpoint is in the source for your program, as a file and
4548 line number. For a pending breakpoint, the original string passed to
4549 the breakpoint command will be listed as it cannot be resolved until
4550 the appropriate shared library is loaded in the future.
4554 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4555 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4556 @value{GDBN} on the host's side. If it is ``target'', then the condition
4557 is evaluated by the target. The @code{info break} command shows
4558 the condition on the line following the affected breakpoint, together with
4559 its condition evaluation mode in between parentheses.
4561 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4562 allowed to have a condition specified for it. The condition is not parsed for
4563 validity until a shared library is loaded that allows the pending
4564 breakpoint to resolve to a valid location.
4567 @code{info break} with a breakpoint
4568 number @var{n} as argument lists only that breakpoint. The
4569 convenience variable @code{$_} and the default examining-address for
4570 the @code{x} command are set to the address of the last breakpoint
4571 listed (@pxref{Memory, ,Examining Memory}).
4574 @code{info break} displays a count of the number of times the breakpoint
4575 has been hit. This is especially useful in conjunction with the
4576 @code{ignore} command. You can ignore a large number of breakpoint
4577 hits, look at the breakpoint info to see how many times the breakpoint
4578 was hit, and then run again, ignoring one less than that number. This
4579 will get you quickly to the last hit of that breakpoint.
4582 For a breakpoints with an enable count (xref) greater than 1,
4583 @code{info break} also displays that count.
4587 @value{GDBN} allows you to set any number of breakpoints at the same place in
4588 your program. There is nothing silly or meaningless about this. When
4589 the breakpoints are conditional, this is even useful
4590 (@pxref{Conditions, ,Break Conditions}).
4592 @cindex multiple locations, breakpoints
4593 @cindex breakpoints, multiple locations
4594 It is possible that a breakpoint corresponds to several locations
4595 in your program. Examples of this situation are:
4599 Multiple functions in the program may have the same name.
4602 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4603 instances of the function body, used in different cases.
4606 For a C@t{++} template function, a given line in the function can
4607 correspond to any number of instantiations.
4610 For an inlined function, a given source line can correspond to
4611 several places where that function is inlined.
4614 In all those cases, @value{GDBN} will insert a breakpoint at all
4615 the relevant locations.
4617 A breakpoint with multiple locations is displayed in the breakpoint
4618 table using several rows---one header row, followed by one row for
4619 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4620 address column. The rows for individual locations contain the actual
4621 addresses for locations, and show the functions to which those
4622 locations belong. The number column for a location is of the form
4623 @var{breakpoint-number}.@var{location-number}.
4628 Num Type Disp Enb Address What
4629 1 breakpoint keep y <MULTIPLE>
4631 breakpoint already hit 1 time
4632 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4633 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4636 You cannot delete the individual locations from a breakpoint. However,
4637 each location can be individually enabled or disabled by passing
4638 @var{breakpoint-number}.@var{location-number} as argument to the
4639 @code{enable} and @code{disable} commands. It's also possible to
4640 @code{enable} and @code{disable} a range of @var{location-number}
4641 locations using a @var{breakpoint-number} and two @var{location-number}s,
4642 in increasing order, separated by a hyphen, like
4643 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4644 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4645 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4646 all of the locations that belong to that breakpoint.
4648 @cindex pending breakpoints
4649 It's quite common to have a breakpoint inside a shared library.
4650 Shared libraries can be loaded and unloaded explicitly,
4651 and possibly repeatedly, as the program is executed. To support
4652 this use case, @value{GDBN} updates breakpoint locations whenever
4653 any shared library is loaded or unloaded. Typically, you would
4654 set a breakpoint in a shared library at the beginning of your
4655 debugging session, when the library is not loaded, and when the
4656 symbols from the library are not available. When you try to set
4657 breakpoint, @value{GDBN} will ask you if you want to set
4658 a so called @dfn{pending breakpoint}---breakpoint whose address
4659 is not yet resolved.
4661 After the program is run, whenever a new shared library is loaded,
4662 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4663 shared library contains the symbol or line referred to by some
4664 pending breakpoint, that breakpoint is resolved and becomes an
4665 ordinary breakpoint. When a library is unloaded, all breakpoints
4666 that refer to its symbols or source lines become pending again.
4668 This logic works for breakpoints with multiple locations, too. For
4669 example, if you have a breakpoint in a C@t{++} template function, and
4670 a newly loaded shared library has an instantiation of that template,
4671 a new location is added to the list of locations for the breakpoint.
4673 Except for having unresolved address, pending breakpoints do not
4674 differ from regular breakpoints. You can set conditions or commands,
4675 enable and disable them and perform other breakpoint operations.
4677 @value{GDBN} provides some additional commands for controlling what
4678 happens when the @samp{break} command cannot resolve breakpoint
4679 address specification to an address:
4681 @kindex set breakpoint pending
4682 @kindex show breakpoint pending
4684 @item set breakpoint pending auto
4685 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4686 location, it queries you whether a pending breakpoint should be created.
4688 @item set breakpoint pending on
4689 This indicates that an unrecognized breakpoint location should automatically
4690 result in a pending breakpoint being created.
4692 @item set breakpoint pending off
4693 This indicates that pending breakpoints are not to be created. Any
4694 unrecognized breakpoint location results in an error. This setting does
4695 not affect any pending breakpoints previously created.
4697 @item show breakpoint pending
4698 Show the current behavior setting for creating pending breakpoints.
4701 The settings above only affect the @code{break} command and its
4702 variants. Once breakpoint is set, it will be automatically updated
4703 as shared libraries are loaded and unloaded.
4705 @cindex automatic hardware breakpoints
4706 For some targets, @value{GDBN} can automatically decide if hardware or
4707 software breakpoints should be used, depending on whether the
4708 breakpoint address is read-only or read-write. This applies to
4709 breakpoints set with the @code{break} command as well as to internal
4710 breakpoints set by commands like @code{next} and @code{finish}. For
4711 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4714 You can control this automatic behaviour with the following commands:
4716 @kindex set breakpoint auto-hw
4717 @kindex show breakpoint auto-hw
4719 @item set breakpoint auto-hw on
4720 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4721 will try to use the target memory map to decide if software or hardware
4722 breakpoint must be used.
4724 @item set breakpoint auto-hw off
4725 This indicates @value{GDBN} should not automatically select breakpoint
4726 type. If the target provides a memory map, @value{GDBN} will warn when
4727 trying to set software breakpoint at a read-only address.
4730 @value{GDBN} normally implements breakpoints by replacing the program code
4731 at the breakpoint address with a special instruction, which, when
4732 executed, given control to the debugger. By default, the program
4733 code is so modified only when the program is resumed. As soon as
4734 the program stops, @value{GDBN} restores the original instructions. This
4735 behaviour guards against leaving breakpoints inserted in the
4736 target should gdb abrubptly disconnect. However, with slow remote
4737 targets, inserting and removing breakpoint can reduce the performance.
4738 This behavior can be controlled with the following commands::
4740 @kindex set breakpoint always-inserted
4741 @kindex show breakpoint always-inserted
4743 @item set breakpoint always-inserted off
4744 All breakpoints, including newly added by the user, are inserted in
4745 the target only when the target is resumed. All breakpoints are
4746 removed from the target when it stops. This is the default mode.
4748 @item set breakpoint always-inserted on
4749 Causes all breakpoints to be inserted in the target at all times. If
4750 the user adds a new breakpoint, or changes an existing breakpoint, the
4751 breakpoints in the target are updated immediately. A breakpoint is
4752 removed from the target only when breakpoint itself is deleted.
4755 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4756 when a breakpoint breaks. If the condition is true, then the process being
4757 debugged stops, otherwise the process is resumed.
4759 If the target supports evaluating conditions on its end, @value{GDBN} may
4760 download the breakpoint, together with its conditions, to it.
4762 This feature can be controlled via the following commands:
4764 @kindex set breakpoint condition-evaluation
4765 @kindex show breakpoint condition-evaluation
4767 @item set breakpoint condition-evaluation host
4768 This option commands @value{GDBN} to evaluate the breakpoint
4769 conditions on the host's side. Unconditional breakpoints are sent to
4770 the target which in turn receives the triggers and reports them back to GDB
4771 for condition evaluation. This is the standard evaluation mode.
4773 @item set breakpoint condition-evaluation target
4774 This option commands @value{GDBN} to download breakpoint conditions
4775 to the target at the moment of their insertion. The target
4776 is responsible for evaluating the conditional expression and reporting
4777 breakpoint stop events back to @value{GDBN} whenever the condition
4778 is true. Due to limitations of target-side evaluation, some conditions
4779 cannot be evaluated there, e.g., conditions that depend on local data
4780 that is only known to the host. Examples include
4781 conditional expressions involving convenience variables, complex types
4782 that cannot be handled by the agent expression parser and expressions
4783 that are too long to be sent over to the target, specially when the
4784 target is a remote system. In these cases, the conditions will be
4785 evaluated by @value{GDBN}.
4787 @item set breakpoint condition-evaluation auto
4788 This is the default mode. If the target supports evaluating breakpoint
4789 conditions on its end, @value{GDBN} will download breakpoint conditions to
4790 the target (limitations mentioned previously apply). If the target does
4791 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4792 to evaluating all these conditions on the host's side.
4796 @cindex negative breakpoint numbers
4797 @cindex internal @value{GDBN} breakpoints
4798 @value{GDBN} itself sometimes sets breakpoints in your program for
4799 special purposes, such as proper handling of @code{longjmp} (in C
4800 programs). These internal breakpoints are assigned negative numbers,
4801 starting with @code{-1}; @samp{info breakpoints} does not display them.
4802 You can see these breakpoints with the @value{GDBN} maintenance command
4803 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4806 @node Set Watchpoints
4807 @subsection Setting Watchpoints
4809 @cindex setting watchpoints
4810 You can use a watchpoint to stop execution whenever the value of an
4811 expression changes, without having to predict a particular place where
4812 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4813 The expression may be as simple as the value of a single variable, or
4814 as complex as many variables combined by operators. Examples include:
4818 A reference to the value of a single variable.
4821 An address cast to an appropriate data type. For example,
4822 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4823 address (assuming an @code{int} occupies 4 bytes).
4826 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4827 expression can use any operators valid in the program's native
4828 language (@pxref{Languages}).
4831 You can set a watchpoint on an expression even if the expression can
4832 not be evaluated yet. For instance, you can set a watchpoint on
4833 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4834 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4835 the expression produces a valid value. If the expression becomes
4836 valid in some other way than changing a variable (e.g.@: if the memory
4837 pointed to by @samp{*global_ptr} becomes readable as the result of a
4838 @code{malloc} call), @value{GDBN} may not stop until the next time
4839 the expression changes.
4841 @cindex software watchpoints
4842 @cindex hardware watchpoints
4843 Depending on your system, watchpoints may be implemented in software or
4844 hardware. @value{GDBN} does software watchpointing by single-stepping your
4845 program and testing the variable's value each time, which is hundreds of
4846 times slower than normal execution. (But this may still be worth it, to
4847 catch errors where you have no clue what part of your program is the
4850 On some systems, such as most PowerPC or x86-based targets,
4851 @value{GDBN} includes support for hardware watchpoints, which do not
4852 slow down the running of your program.
4856 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4857 Set a watchpoint for an expression. @value{GDBN} will break when the
4858 expression @var{expr} is written into by the program and its value
4859 changes. The simplest (and the most popular) use of this command is
4860 to watch the value of a single variable:
4863 (@value{GDBP}) watch foo
4866 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4867 argument, @value{GDBN} breaks only when the thread identified by
4868 @var{thread-id} changes the value of @var{expr}. If any other threads
4869 change the value of @var{expr}, @value{GDBN} will not break. Note
4870 that watchpoints restricted to a single thread in this way only work
4871 with Hardware Watchpoints.
4873 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4874 (see below). The @code{-location} argument tells @value{GDBN} to
4875 instead watch the memory referred to by @var{expr}. In this case,
4876 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4877 and watch the memory at that address. The type of the result is used
4878 to determine the size of the watched memory. If the expression's
4879 result does not have an address, then @value{GDBN} will print an
4882 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4883 of masked watchpoints, if the current architecture supports this
4884 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4885 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4886 to an address to watch. The mask specifies that some bits of an address
4887 (the bits which are reset in the mask) should be ignored when matching
4888 the address accessed by the inferior against the watchpoint address.
4889 Thus, a masked watchpoint watches many addresses simultaneously---those
4890 addresses whose unmasked bits are identical to the unmasked bits in the
4891 watchpoint address. The @code{mask} argument implies @code{-location}.
4895 (@value{GDBP}) watch foo mask 0xffff00ff
4896 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4900 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4901 Set a watchpoint that will break when the value of @var{expr} is read
4905 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4906 Set a watchpoint that will break when @var{expr} is either read from
4907 or written into by the program.
4909 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4910 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4911 This command prints a list of watchpoints, using the same format as
4912 @code{info break} (@pxref{Set Breaks}).
4915 If you watch for a change in a numerically entered address you need to
4916 dereference it, as the address itself is just a constant number which will
4917 never change. @value{GDBN} refuses to create a watchpoint that watches
4918 a never-changing value:
4921 (@value{GDBP}) watch 0x600850
4922 Cannot watch constant value 0x600850.
4923 (@value{GDBP}) watch *(int *) 0x600850
4924 Watchpoint 1: *(int *) 6293584
4927 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4928 watchpoints execute very quickly, and the debugger reports a change in
4929 value at the exact instruction where the change occurs. If @value{GDBN}
4930 cannot set a hardware watchpoint, it sets a software watchpoint, which
4931 executes more slowly and reports the change in value at the next
4932 @emph{statement}, not the instruction, after the change occurs.
4934 @cindex use only software watchpoints
4935 You can force @value{GDBN} to use only software watchpoints with the
4936 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4937 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4938 the underlying system supports them. (Note that hardware-assisted
4939 watchpoints that were set @emph{before} setting
4940 @code{can-use-hw-watchpoints} to zero will still use the hardware
4941 mechanism of watching expression values.)
4944 @item set can-use-hw-watchpoints
4945 @kindex set can-use-hw-watchpoints
4946 Set whether or not to use hardware watchpoints.
4948 @item show can-use-hw-watchpoints
4949 @kindex show can-use-hw-watchpoints
4950 Show the current mode of using hardware watchpoints.
4953 For remote targets, you can restrict the number of hardware
4954 watchpoints @value{GDBN} will use, see @ref{set remote
4955 hardware-breakpoint-limit}.
4957 When you issue the @code{watch} command, @value{GDBN} reports
4960 Hardware watchpoint @var{num}: @var{expr}
4964 if it was able to set a hardware watchpoint.
4966 Currently, the @code{awatch} and @code{rwatch} commands can only set
4967 hardware watchpoints, because accesses to data that don't change the
4968 value of the watched expression cannot be detected without examining
4969 every instruction as it is being executed, and @value{GDBN} does not do
4970 that currently. If @value{GDBN} finds that it is unable to set a
4971 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4972 will print a message like this:
4975 Expression cannot be implemented with read/access watchpoint.
4978 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4979 data type of the watched expression is wider than what a hardware
4980 watchpoint on the target machine can handle. For example, some systems
4981 can only watch regions that are up to 4 bytes wide; on such systems you
4982 cannot set hardware watchpoints for an expression that yields a
4983 double-precision floating-point number (which is typically 8 bytes
4984 wide). As a work-around, it might be possible to break the large region
4985 into a series of smaller ones and watch them with separate watchpoints.
4987 If you set too many hardware watchpoints, @value{GDBN} might be unable
4988 to insert all of them when you resume the execution of your program.
4989 Since the precise number of active watchpoints is unknown until such
4990 time as the program is about to be resumed, @value{GDBN} might not be
4991 able to warn you about this when you set the watchpoints, and the
4992 warning will be printed only when the program is resumed:
4995 Hardware watchpoint @var{num}: Could not insert watchpoint
4999 If this happens, delete or disable some of the watchpoints.
5001 Watching complex expressions that reference many variables can also
5002 exhaust the resources available for hardware-assisted watchpoints.
5003 That's because @value{GDBN} needs to watch every variable in the
5004 expression with separately allocated resources.
5006 If you call a function interactively using @code{print} or @code{call},
5007 any watchpoints you have set will be inactive until @value{GDBN} reaches another
5008 kind of breakpoint or the call completes.
5010 @value{GDBN} automatically deletes watchpoints that watch local
5011 (automatic) variables, or expressions that involve such variables, when
5012 they go out of scope, that is, when the execution leaves the block in
5013 which these variables were defined. In particular, when the program
5014 being debugged terminates, @emph{all} local variables go out of scope,
5015 and so only watchpoints that watch global variables remain set. If you
5016 rerun the program, you will need to set all such watchpoints again. One
5017 way of doing that would be to set a code breakpoint at the entry to the
5018 @code{main} function and when it breaks, set all the watchpoints.
5020 @cindex watchpoints and threads
5021 @cindex threads and watchpoints
5022 In multi-threaded programs, watchpoints will detect changes to the
5023 watched expression from every thread.
5026 @emph{Warning:} In multi-threaded programs, software watchpoints
5027 have only limited usefulness. If @value{GDBN} creates a software
5028 watchpoint, it can only watch the value of an expression @emph{in a
5029 single thread}. If you are confident that the expression can only
5030 change due to the current thread's activity (and if you are also
5031 confident that no other thread can become current), then you can use
5032 software watchpoints as usual. However, @value{GDBN} may not notice
5033 when a non-current thread's activity changes the expression. (Hardware
5034 watchpoints, in contrast, watch an expression in all threads.)
5037 @xref{set remote hardware-watchpoint-limit}.
5039 @node Set Catchpoints
5040 @subsection Setting Catchpoints
5041 @cindex catchpoints, setting
5042 @cindex exception handlers
5043 @cindex event handling
5045 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5046 kinds of program events, such as C@t{++} exceptions or the loading of a
5047 shared library. Use the @code{catch} command to set a catchpoint.
5051 @item catch @var{event}
5052 Stop when @var{event} occurs. The @var{event} can be any of the following:
5055 @item throw @r{[}@var{regexp}@r{]}
5056 @itemx rethrow @r{[}@var{regexp}@r{]}
5057 @itemx catch @r{[}@var{regexp}@r{]}
5059 @kindex catch rethrow
5061 @cindex stop on C@t{++} exceptions
5062 The throwing, re-throwing, or catching of a C@t{++} exception.
5064 If @var{regexp} is given, then only exceptions whose type matches the
5065 regular expression will be caught.
5067 @vindex $_exception@r{, convenience variable}
5068 The convenience variable @code{$_exception} is available at an
5069 exception-related catchpoint, on some systems. This holds the
5070 exception being thrown.
5072 There are currently some limitations to C@t{++} exception handling in
5077 The support for these commands is system-dependent. Currently, only
5078 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5082 The regular expression feature and the @code{$_exception} convenience
5083 variable rely on the presence of some SDT probes in @code{libstdc++}.
5084 If these probes are not present, then these features cannot be used.
5085 These probes were first available in the GCC 4.8 release, but whether
5086 or not they are available in your GCC also depends on how it was
5090 The @code{$_exception} convenience variable is only valid at the
5091 instruction at which an exception-related catchpoint is set.
5094 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5095 location in the system library which implements runtime exception
5096 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5097 (@pxref{Selection}) to get to your code.
5100 If you call a function interactively, @value{GDBN} normally returns
5101 control to you when the function has finished executing. If the call
5102 raises an exception, however, the call may bypass the mechanism that
5103 returns control to you and cause your program either to abort or to
5104 simply continue running until it hits a breakpoint, catches a signal
5105 that @value{GDBN} is listening for, or exits. This is the case even if
5106 you set a catchpoint for the exception; catchpoints on exceptions are
5107 disabled within interactive calls. @xref{Calling}, for information on
5108 controlling this with @code{set unwind-on-terminating-exception}.
5111 You cannot raise an exception interactively.
5114 You cannot install an exception handler interactively.
5117 @item exception @r{[}@var{name}@r{]}
5118 @kindex catch exception
5119 @cindex Ada exception catching
5120 @cindex catch Ada exceptions
5121 An Ada exception being raised. If an exception name is specified
5122 at the end of the command (eg @code{catch exception Program_Error}),
5123 the debugger will stop only when this specific exception is raised.
5124 Otherwise, the debugger stops execution when any Ada exception is raised.
5126 When inserting an exception catchpoint on a user-defined exception whose
5127 name is identical to one of the exceptions defined by the language, the
5128 fully qualified name must be used as the exception name. Otherwise,
5129 @value{GDBN} will assume that it should stop on the pre-defined exception
5130 rather than the user-defined one. For instance, assuming an exception
5131 called @code{Constraint_Error} is defined in package @code{Pck}, then
5132 the command to use to catch such exceptions is @kbd{catch exception
5133 Pck.Constraint_Error}.
5135 @vindex $_ada_exception@r{, convenience variable}
5136 The convenience variable @code{$_ada_exception} holds the address of
5137 the exception being thrown. This can be useful when setting a
5138 condition for such a catchpoint.
5140 @item exception unhandled
5141 @kindex catch exception unhandled
5142 An exception that was raised but is not handled by the program. The
5143 convenience variable @code{$_ada_exception} is set as for @code{catch
5146 @item handlers @r{[}@var{name}@r{]}
5147 @kindex catch handlers
5148 @cindex Ada exception handlers catching
5149 @cindex catch Ada exceptions when handled
5150 An Ada exception being handled. If an exception name is
5151 specified at the end of the command
5152 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5153 only when this specific exception is handled.
5154 Otherwise, the debugger stops execution when any Ada exception is handled.
5156 When inserting a handlers catchpoint on a user-defined
5157 exception whose name is identical to one of the exceptions
5158 defined by the language, the fully qualified name must be used
5159 as the exception name. Otherwise, @value{GDBN} will assume that it
5160 should stop on the pre-defined exception rather than the
5161 user-defined one. For instance, assuming an exception called
5162 @code{Constraint_Error} is defined in package @code{Pck}, then the
5163 command to use to catch such exceptions handling is
5164 @kbd{catch handlers Pck.Constraint_Error}.
5166 The convenience variable @code{$_ada_exception} is set as for
5167 @code{catch exception}.
5170 @kindex catch assert
5171 A failed Ada assertion. Note that the convenience variable
5172 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5176 @cindex break on fork/exec
5177 A call to @code{exec}.
5179 @anchor{catch syscall}
5181 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5182 @kindex catch syscall
5183 @cindex break on a system call.
5184 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5185 syscall is a mechanism for application programs to request a service
5186 from the operating system (OS) or one of the OS system services.
5187 @value{GDBN} can catch some or all of the syscalls issued by the
5188 debuggee, and show the related information for each syscall. If no
5189 argument is specified, calls to and returns from all system calls
5192 @var{name} can be any system call name that is valid for the
5193 underlying OS. Just what syscalls are valid depends on the OS. On
5194 GNU and Unix systems, you can find the full list of valid syscall
5195 names on @file{/usr/include/asm/unistd.h}.
5197 @c For MS-Windows, the syscall names and the corresponding numbers
5198 @c can be found, e.g., on this URL:
5199 @c http://www.metasploit.com/users/opcode/syscalls.html
5200 @c but we don't support Windows syscalls yet.
5202 Normally, @value{GDBN} knows in advance which syscalls are valid for
5203 each OS, so you can use the @value{GDBN} command-line completion
5204 facilities (@pxref{Completion,, command completion}) to list the
5207 You may also specify the system call numerically. A syscall's
5208 number is the value passed to the OS's syscall dispatcher to
5209 identify the requested service. When you specify the syscall by its
5210 name, @value{GDBN} uses its database of syscalls to convert the name
5211 into the corresponding numeric code, but using the number directly
5212 may be useful if @value{GDBN}'s database does not have the complete
5213 list of syscalls on your system (e.g., because @value{GDBN} lags
5214 behind the OS upgrades).
5216 You may specify a group of related syscalls to be caught at once using
5217 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5218 instance, on some platforms @value{GDBN} allows you to catch all
5219 network related syscalls, by passing the argument @code{group:network}
5220 to @code{catch syscall}. Note that not all syscall groups are
5221 available in every system. You can use the command completion
5222 facilities (@pxref{Completion,, command completion}) to list the
5223 syscall groups available on your environment.
5225 The example below illustrates how this command works if you don't provide
5229 (@value{GDBP}) catch syscall
5230 Catchpoint 1 (syscall)
5232 Starting program: /tmp/catch-syscall
5234 Catchpoint 1 (call to syscall 'close'), \
5235 0xffffe424 in __kernel_vsyscall ()
5239 Catchpoint 1 (returned from syscall 'close'), \
5240 0xffffe424 in __kernel_vsyscall ()
5244 Here is an example of catching a system call by name:
5247 (@value{GDBP}) catch syscall chroot
5248 Catchpoint 1 (syscall 'chroot' [61])
5250 Starting program: /tmp/catch-syscall
5252 Catchpoint 1 (call to syscall 'chroot'), \
5253 0xffffe424 in __kernel_vsyscall ()
5257 Catchpoint 1 (returned from syscall 'chroot'), \
5258 0xffffe424 in __kernel_vsyscall ()
5262 An example of specifying a system call numerically. In the case
5263 below, the syscall number has a corresponding entry in the XML
5264 file, so @value{GDBN} finds its name and prints it:
5267 (@value{GDBP}) catch syscall 252
5268 Catchpoint 1 (syscall(s) 'exit_group')
5270 Starting program: /tmp/catch-syscall
5272 Catchpoint 1 (call to syscall 'exit_group'), \
5273 0xffffe424 in __kernel_vsyscall ()
5277 Program exited normally.
5281 Here is an example of catching a syscall group:
5284 (@value{GDBP}) catch syscall group:process
5285 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5286 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5287 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5289 Starting program: /tmp/catch-syscall
5291 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5292 from /lib64/ld-linux-x86-64.so.2
5298 However, there can be situations when there is no corresponding name
5299 in XML file for that syscall number. In this case, @value{GDBN} prints
5300 a warning message saying that it was not able to find the syscall name,
5301 but the catchpoint will be set anyway. See the example below:
5304 (@value{GDBP}) catch syscall 764
5305 warning: The number '764' does not represent a known syscall.
5306 Catchpoint 2 (syscall 764)
5310 If you configure @value{GDBN} using the @samp{--without-expat} option,
5311 it will not be able to display syscall names. Also, if your
5312 architecture does not have an XML file describing its system calls,
5313 you will not be able to see the syscall names. It is important to
5314 notice that these two features are used for accessing the syscall
5315 name database. In either case, you will see a warning like this:
5318 (@value{GDBP}) catch syscall
5319 warning: Could not open "syscalls/i386-linux.xml"
5320 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5321 GDB will not be able to display syscall names.
5322 Catchpoint 1 (syscall)
5326 Of course, the file name will change depending on your architecture and system.
5328 Still using the example above, you can also try to catch a syscall by its
5329 number. In this case, you would see something like:
5332 (@value{GDBP}) catch syscall 252
5333 Catchpoint 1 (syscall(s) 252)
5336 Again, in this case @value{GDBN} would not be able to display syscall's names.
5340 A call to @code{fork}.
5344 A call to @code{vfork}.
5346 @item load @r{[}@var{regexp}@r{]}
5347 @itemx unload @r{[}@var{regexp}@r{]}
5349 @kindex catch unload
5350 The loading or unloading of a shared library. If @var{regexp} is
5351 given, then the catchpoint will stop only if the regular expression
5352 matches one of the affected libraries.
5354 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5355 @kindex catch signal
5356 The delivery of a signal.
5358 With no arguments, this catchpoint will catch any signal that is not
5359 used internally by @value{GDBN}, specifically, all signals except
5360 @samp{SIGTRAP} and @samp{SIGINT}.
5362 With the argument @samp{all}, all signals, including those used by
5363 @value{GDBN}, will be caught. This argument cannot be used with other
5366 Otherwise, the arguments are a list of signal names as given to
5367 @code{handle} (@pxref{Signals}). Only signals specified in this list
5370 One reason that @code{catch signal} can be more useful than
5371 @code{handle} is that you can attach commands and conditions to the
5374 When a signal is caught by a catchpoint, the signal's @code{stop} and
5375 @code{print} settings, as specified by @code{handle}, are ignored.
5376 However, whether the signal is still delivered to the inferior depends
5377 on the @code{pass} setting; this can be changed in the catchpoint's
5382 @item tcatch @var{event}
5384 Set a catchpoint that is enabled only for one stop. The catchpoint is
5385 automatically deleted after the first time the event is caught.
5389 Use the @code{info break} command to list the current catchpoints.
5393 @subsection Deleting Breakpoints
5395 @cindex clearing breakpoints, watchpoints, catchpoints
5396 @cindex deleting breakpoints, watchpoints, catchpoints
5397 It is often necessary to eliminate a breakpoint, watchpoint, or
5398 catchpoint once it has done its job and you no longer want your program
5399 to stop there. This is called @dfn{deleting} the breakpoint. A
5400 breakpoint that has been deleted no longer exists; it is forgotten.
5402 With the @code{clear} command you can delete breakpoints according to
5403 where they are in your program. With the @code{delete} command you can
5404 delete individual breakpoints, watchpoints, or catchpoints by specifying
5405 their breakpoint numbers.
5407 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5408 automatically ignores breakpoints on the first instruction to be executed
5409 when you continue execution without changing the execution address.
5414 Delete any breakpoints at the next instruction to be executed in the
5415 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5416 the innermost frame is selected, this is a good way to delete a
5417 breakpoint where your program just stopped.
5419 @item clear @var{location}
5420 Delete any breakpoints set at the specified @var{location}.
5421 @xref{Specify Location}, for the various forms of @var{location}; the
5422 most useful ones are listed below:
5425 @item clear @var{function}
5426 @itemx clear @var{filename}:@var{function}
5427 Delete any breakpoints set at entry to the named @var{function}.
5429 @item clear @var{linenum}
5430 @itemx clear @var{filename}:@var{linenum}
5431 Delete any breakpoints set at or within the code of the specified
5432 @var{linenum} of the specified @var{filename}.
5435 @cindex delete breakpoints
5437 @kindex d @r{(@code{delete})}
5438 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5439 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5440 list specified as argument. If no argument is specified, delete all
5441 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5442 confirm off}). You can abbreviate this command as @code{d}.
5446 @subsection Disabling Breakpoints
5448 @cindex enable/disable a breakpoint
5449 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5450 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5451 it had been deleted, but remembers the information on the breakpoint so
5452 that you can @dfn{enable} it again later.
5454 You disable and enable breakpoints, watchpoints, and catchpoints with
5455 the @code{enable} and @code{disable} commands, optionally specifying
5456 one or more breakpoint numbers as arguments. Use @code{info break} to
5457 print a list of all breakpoints, watchpoints, and catchpoints if you
5458 do not know which numbers to use.
5460 Disabling and enabling a breakpoint that has multiple locations
5461 affects all of its locations.
5463 A breakpoint, watchpoint, or catchpoint can have any of several
5464 different states of enablement:
5468 Enabled. The breakpoint stops your program. A breakpoint set
5469 with the @code{break} command starts out in this state.
5471 Disabled. The breakpoint has no effect on your program.
5473 Enabled once. The breakpoint stops your program, but then becomes
5476 Enabled for a count. The breakpoint stops your program for the next
5477 N times, then becomes disabled.
5479 Enabled for deletion. The breakpoint stops your program, but
5480 immediately after it does so it is deleted permanently. A breakpoint
5481 set with the @code{tbreak} command starts out in this state.
5484 You can use the following commands to enable or disable breakpoints,
5485 watchpoints, and catchpoints:
5489 @kindex dis @r{(@code{disable})}
5490 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5491 Disable the specified breakpoints---or all breakpoints, if none are
5492 listed. A disabled breakpoint has no effect but is not forgotten. All
5493 options such as ignore-counts, conditions and commands are remembered in
5494 case the breakpoint is enabled again later. You may abbreviate
5495 @code{disable} as @code{dis}.
5498 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5499 Enable the specified breakpoints (or all defined breakpoints). They
5500 become effective once again in stopping your program.
5502 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5503 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5504 of these breakpoints immediately after stopping your program.
5506 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5507 Enable the specified breakpoints temporarily. @value{GDBN} records
5508 @var{count} with each of the specified breakpoints, and decrements a
5509 breakpoint's count when it is hit. When any count reaches 0,
5510 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5511 count (@pxref{Conditions, ,Break Conditions}), that will be
5512 decremented to 0 before @var{count} is affected.
5514 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5515 Enable the specified breakpoints to work once, then die. @value{GDBN}
5516 deletes any of these breakpoints as soon as your program stops there.
5517 Breakpoints set by the @code{tbreak} command start out in this state.
5520 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5521 @c confusing: tbreak is also initially enabled.
5522 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5523 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5524 subsequently, they become disabled or enabled only when you use one of
5525 the commands above. (The command @code{until} can set and delete a
5526 breakpoint of its own, but it does not change the state of your other
5527 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5531 @subsection Break Conditions
5532 @cindex conditional breakpoints
5533 @cindex breakpoint conditions
5535 @c FIXME what is scope of break condition expr? Context where wanted?
5536 @c in particular for a watchpoint?
5537 The simplest sort of breakpoint breaks every time your program reaches a
5538 specified place. You can also specify a @dfn{condition} for a
5539 breakpoint. A condition is just a Boolean expression in your
5540 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5541 a condition evaluates the expression each time your program reaches it,
5542 and your program stops only if the condition is @emph{true}.
5544 This is the converse of using assertions for program validation; in that
5545 situation, you want to stop when the assertion is violated---that is,
5546 when the condition is false. In C, if you want to test an assertion expressed
5547 by the condition @var{assert}, you should set the condition
5548 @samp{! @var{assert}} on the appropriate breakpoint.
5550 Conditions are also accepted for watchpoints; you may not need them,
5551 since a watchpoint is inspecting the value of an expression anyhow---but
5552 it might be simpler, say, to just set a watchpoint on a variable name,
5553 and specify a condition that tests whether the new value is an interesting
5556 Break conditions can have side effects, and may even call functions in
5557 your program. This can be useful, for example, to activate functions
5558 that log program progress, or to use your own print functions to
5559 format special data structures. The effects are completely predictable
5560 unless there is another enabled breakpoint at the same address. (In
5561 that case, @value{GDBN} might see the other breakpoint first and stop your
5562 program without checking the condition of this one.) Note that
5563 breakpoint commands are usually more convenient and flexible than break
5565 purpose of performing side effects when a breakpoint is reached
5566 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5568 Breakpoint conditions can also be evaluated on the target's side if
5569 the target supports it. Instead of evaluating the conditions locally,
5570 @value{GDBN} encodes the expression into an agent expression
5571 (@pxref{Agent Expressions}) suitable for execution on the target,
5572 independently of @value{GDBN}. Global variables become raw memory
5573 locations, locals become stack accesses, and so forth.
5575 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5576 when its condition evaluates to true. This mechanism may provide faster
5577 response times depending on the performance characteristics of the target
5578 since it does not need to keep @value{GDBN} informed about
5579 every breakpoint trigger, even those with false conditions.
5581 Break conditions can be specified when a breakpoint is set, by using
5582 @samp{if} in the arguments to the @code{break} command. @xref{Set
5583 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5584 with the @code{condition} command.
5586 You can also use the @code{if} keyword with the @code{watch} command.
5587 The @code{catch} command does not recognize the @code{if} keyword;
5588 @code{condition} is the only way to impose a further condition on a
5593 @item condition @var{bnum} @var{expression}
5594 Specify @var{expression} as the break condition for breakpoint,
5595 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5596 breakpoint @var{bnum} stops your program only if the value of
5597 @var{expression} is true (nonzero, in C). When you use
5598 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5599 syntactic correctness, and to determine whether symbols in it have
5600 referents in the context of your breakpoint. If @var{expression} uses
5601 symbols not referenced in the context of the breakpoint, @value{GDBN}
5602 prints an error message:
5605 No symbol "foo" in current context.
5610 not actually evaluate @var{expression} at the time the @code{condition}
5611 command (or a command that sets a breakpoint with a condition, like
5612 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5614 @item condition -force @var{bnum} @var{expression}
5615 When the @code{-force} flag is used, define the condition even if
5616 @var{expression} is invalid at all the current locations of breakpoint
5617 @var{bnum}. This is similar to the @code{-force-condition} option
5618 of the @code{break} command.
5620 @item condition @var{bnum}
5621 Remove the condition from breakpoint number @var{bnum}. It becomes
5622 an ordinary unconditional breakpoint.
5625 @cindex ignore count (of breakpoint)
5626 A special case of a breakpoint condition is to stop only when the
5627 breakpoint has been reached a certain number of times. This is so
5628 useful that there is a special way to do it, using the @dfn{ignore
5629 count} of the breakpoint. Every breakpoint has an ignore count, which
5630 is an integer. Most of the time, the ignore count is zero, and
5631 therefore has no effect. But if your program reaches a breakpoint whose
5632 ignore count is positive, then instead of stopping, it just decrements
5633 the ignore count by one and continues. As a result, if the ignore count
5634 value is @var{n}, the breakpoint does not stop the next @var{n} times
5635 your program reaches it.
5639 @item ignore @var{bnum} @var{count}
5640 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5641 The next @var{count} times the breakpoint is reached, your program's
5642 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5645 To make the breakpoint stop the next time it is reached, specify
5648 When you use @code{continue} to resume execution of your program from a
5649 breakpoint, you can specify an ignore count directly as an argument to
5650 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5651 Stepping,,Continuing and Stepping}.
5653 If a breakpoint has a positive ignore count and a condition, the
5654 condition is not checked. Once the ignore count reaches zero,
5655 @value{GDBN} resumes checking the condition.
5657 You could achieve the effect of the ignore count with a condition such
5658 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5659 is decremented each time. @xref{Convenience Vars, ,Convenience
5663 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5666 @node Break Commands
5667 @subsection Breakpoint Command Lists
5669 @cindex breakpoint commands
5670 You can give any breakpoint (or watchpoint or catchpoint) a series of
5671 commands to execute when your program stops due to that breakpoint. For
5672 example, you might want to print the values of certain expressions, or
5673 enable other breakpoints.
5677 @kindex end@r{ (breakpoint commands)}
5678 @item commands @r{[}@var{list}@dots{}@r{]}
5679 @itemx @dots{} @var{command-list} @dots{}
5681 Specify a list of commands for the given breakpoints. The commands
5682 themselves appear on the following lines. Type a line containing just
5683 @code{end} to terminate the commands.
5685 To remove all commands from a breakpoint, type @code{commands} and
5686 follow it immediately with @code{end}; that is, give no commands.
5688 With no argument, @code{commands} refers to the last breakpoint,
5689 watchpoint, or catchpoint set (not to the breakpoint most recently
5690 encountered). If the most recent breakpoints were set with a single
5691 command, then the @code{commands} will apply to all the breakpoints
5692 set by that command. This applies to breakpoints set by
5693 @code{rbreak}, and also applies when a single @code{break} command
5694 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5698 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5699 disabled within a @var{command-list}.
5701 You can use breakpoint commands to start your program up again. Simply
5702 use the @code{continue} command, or @code{step}, or any other command
5703 that resumes execution.
5705 Any other commands in the command list, after a command that resumes
5706 execution, are ignored. This is because any time you resume execution
5707 (even with a simple @code{next} or @code{step}), you may encounter
5708 another breakpoint---which could have its own command list, leading to
5709 ambiguities about which list to execute.
5712 If the first command you specify in a command list is @code{silent}, the
5713 usual message about stopping at a breakpoint is not printed. This may
5714 be desirable for breakpoints that are to print a specific message and
5715 then continue. If none of the remaining commands print anything, you
5716 see no sign that the breakpoint was reached. @code{silent} is
5717 meaningful only at the beginning of a breakpoint command list.
5719 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5720 print precisely controlled output, and are often useful in silent
5721 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5723 For example, here is how you could use breakpoint commands to print the
5724 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5730 printf "x is %d\n",x
5735 One application for breakpoint commands is to compensate for one bug so
5736 you can test for another. Put a breakpoint just after the erroneous line
5737 of code, give it a condition to detect the case in which something
5738 erroneous has been done, and give it commands to assign correct values
5739 to any variables that need them. End with the @code{continue} command
5740 so that your program does not stop, and start with the @code{silent}
5741 command so that no output is produced. Here is an example:
5752 @node Dynamic Printf
5753 @subsection Dynamic Printf
5755 @cindex dynamic printf
5757 The dynamic printf command @code{dprintf} combines a breakpoint with
5758 formatted printing of your program's data to give you the effect of
5759 inserting @code{printf} calls into your program on-the-fly, without
5760 having to recompile it.
5762 In its most basic form, the output goes to the GDB console. However,
5763 you can set the variable @code{dprintf-style} for alternate handling.
5764 For instance, you can ask to format the output by calling your
5765 program's @code{printf} function. This has the advantage that the
5766 characters go to the program's output device, so they can recorded in
5767 redirects to files and so forth.
5769 If you are doing remote debugging with a stub or agent, you can also
5770 ask to have the printf handled by the remote agent. In addition to
5771 ensuring that the output goes to the remote program's device along
5772 with any other output the program might produce, you can also ask that
5773 the dprintf remain active even after disconnecting from the remote
5774 target. Using the stub/agent is also more efficient, as it can do
5775 everything without needing to communicate with @value{GDBN}.
5779 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5780 Whenever execution reaches @var{location}, print the values of one or
5781 more @var{expressions} under the control of the string @var{template}.
5782 To print several values, separate them with commas.
5784 @item set dprintf-style @var{style}
5785 Set the dprintf output to be handled in one of several different
5786 styles enumerated below. A change of style affects all existing
5787 dynamic printfs immediately. (If you need individual control over the
5788 print commands, simply define normal breakpoints with
5789 explicitly-supplied command lists.)
5793 @kindex dprintf-style gdb
5794 Handle the output using the @value{GDBN} @code{printf} command.
5797 @kindex dprintf-style call
5798 Handle the output by calling a function in your program (normally
5802 @kindex dprintf-style agent
5803 Have the remote debugging agent (such as @code{gdbserver}) handle
5804 the output itself. This style is only available for agents that
5805 support running commands on the target.
5808 @item set dprintf-function @var{function}
5809 Set the function to call if the dprintf style is @code{call}. By
5810 default its value is @code{printf}. You may set it to any expression.
5811 that @value{GDBN} can evaluate to a function, as per the @code{call}
5814 @item set dprintf-channel @var{channel}
5815 Set a ``channel'' for dprintf. If set to a non-empty value,
5816 @value{GDBN} will evaluate it as an expression and pass the result as
5817 a first argument to the @code{dprintf-function}, in the manner of
5818 @code{fprintf} and similar functions. Otherwise, the dprintf format
5819 string will be the first argument, in the manner of @code{printf}.
5821 As an example, if you wanted @code{dprintf} output to go to a logfile
5822 that is a standard I/O stream assigned to the variable @code{mylog},
5823 you could do the following:
5826 (gdb) set dprintf-style call
5827 (gdb) set dprintf-function fprintf
5828 (gdb) set dprintf-channel mylog
5829 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5830 Dprintf 1 at 0x123456: file main.c, line 25.
5832 1 dprintf keep y 0x00123456 in main at main.c:25
5833 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5838 Note that the @code{info break} displays the dynamic printf commands
5839 as normal breakpoint commands; you can thus easily see the effect of
5840 the variable settings.
5842 @item set disconnected-dprintf on
5843 @itemx set disconnected-dprintf off
5844 @kindex set disconnected-dprintf
5845 Choose whether @code{dprintf} commands should continue to run if
5846 @value{GDBN} has disconnected from the target. This only applies
5847 if the @code{dprintf-style} is @code{agent}.
5849 @item show disconnected-dprintf off
5850 @kindex show disconnected-dprintf
5851 Show the current choice for disconnected @code{dprintf}.
5855 @value{GDBN} does not check the validity of function and channel,
5856 relying on you to supply values that are meaningful for the contexts
5857 in which they are being used. For instance, the function and channel
5858 may be the values of local variables, but if that is the case, then
5859 all enabled dynamic prints must be at locations within the scope of
5860 those locals. If evaluation fails, @value{GDBN} will report an error.
5862 @node Save Breakpoints
5863 @subsection How to save breakpoints to a file
5865 To save breakpoint definitions to a file use the @w{@code{save
5866 breakpoints}} command.
5869 @kindex save breakpoints
5870 @cindex save breakpoints to a file for future sessions
5871 @item save breakpoints [@var{filename}]
5872 This command saves all current breakpoint definitions together with
5873 their commands and ignore counts, into a file @file{@var{filename}}
5874 suitable for use in a later debugging session. This includes all
5875 types of breakpoints (breakpoints, watchpoints, catchpoints,
5876 tracepoints). To read the saved breakpoint definitions, use the
5877 @code{source} command (@pxref{Command Files}). Note that watchpoints
5878 with expressions involving local variables may fail to be recreated
5879 because it may not be possible to access the context where the
5880 watchpoint is valid anymore. Because the saved breakpoint definitions
5881 are simply a sequence of @value{GDBN} commands that recreate the
5882 breakpoints, you can edit the file in your favorite editing program,
5883 and remove the breakpoint definitions you're not interested in, or
5884 that can no longer be recreated.
5887 @node Static Probe Points
5888 @subsection Static Probe Points
5890 @cindex static probe point, SystemTap
5891 @cindex static probe point, DTrace
5892 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5893 for Statically Defined Tracing, and the probes are designed to have a tiny
5894 runtime code and data footprint, and no dynamic relocations.
5896 Currently, the following types of probes are supported on
5897 ELF-compatible systems:
5901 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5902 @acronym{SDT} probes@footnote{See
5903 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5904 for more information on how to add @code{SystemTap} @acronym{SDT}
5905 probes in your applications.}. @code{SystemTap} probes are usable
5906 from assembly, C and C@t{++} languages@footnote{See
5907 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5908 for a good reference on how the @acronym{SDT} probes are implemented.}.
5910 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5911 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5915 @cindex semaphores on static probe points
5916 Some @code{SystemTap} probes have an associated semaphore variable;
5917 for instance, this happens automatically if you defined your probe
5918 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5919 @value{GDBN} will automatically enable it when you specify a
5920 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5921 breakpoint at a probe's location by some other method (e.g.,
5922 @code{break file:line}), then @value{GDBN} will not automatically set
5923 the semaphore. @code{DTrace} probes do not support semaphores.
5925 You can examine the available static static probes using @code{info
5926 probes}, with optional arguments:
5930 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5931 If given, @var{type} is either @code{stap} for listing
5932 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5933 probes. If omitted all probes are listed regardless of their types.
5935 If given, @var{provider} is a regular expression used to match against provider
5936 names when selecting which probes to list. If omitted, probes by all
5937 probes from all providers are listed.
5939 If given, @var{name} is a regular expression to match against probe names
5940 when selecting which probes to list. If omitted, probe names are not
5941 considered when deciding whether to display them.
5943 If given, @var{objfile} is a regular expression used to select which
5944 object files (executable or shared libraries) to examine. If not
5945 given, all object files are considered.
5947 @item info probes all
5948 List the available static probes, from all types.
5951 @cindex enabling and disabling probes
5952 Some probe points can be enabled and/or disabled. The effect of
5953 enabling or disabling a probe depends on the type of probe being
5954 handled. Some @code{DTrace} probes can be enabled or
5955 disabled, but @code{SystemTap} probes cannot be disabled.
5957 You can enable (or disable) one or more probes using the following
5958 commands, with optional arguments:
5961 @kindex enable probes
5962 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5963 If given, @var{provider} is a regular expression used to match against
5964 provider names when selecting which probes to enable. If omitted,
5965 all probes from all providers are enabled.
5967 If given, @var{name} is a regular expression to match against probe
5968 names when selecting which probes to enable. If omitted, probe names
5969 are not considered when deciding whether to enable them.
5971 If given, @var{objfile} is a regular expression used to select which
5972 object files (executable or shared libraries) to examine. If not
5973 given, all object files are considered.
5975 @kindex disable probes
5976 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5977 See the @code{enable probes} command above for a description of the
5978 optional arguments accepted by this command.
5981 @vindex $_probe_arg@r{, convenience variable}
5982 A probe may specify up to twelve arguments. These are available at the
5983 point at which the probe is defined---that is, when the current PC is
5984 at the probe's location. The arguments are available using the
5985 convenience variables (@pxref{Convenience Vars})
5986 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5987 probes each probe argument is an integer of the appropriate size;
5988 types are not preserved. In @code{DTrace} probes types are preserved
5989 provided that they are recognized as such by @value{GDBN}; otherwise
5990 the value of the probe argument will be a long integer. The
5991 convenience variable @code{$_probe_argc} holds the number of arguments
5992 at the current probe point.
5994 These variables are always available, but attempts to access them at
5995 any location other than a probe point will cause @value{GDBN} to give
5999 @c @ifclear BARETARGET
6000 @node Error in Breakpoints
6001 @subsection ``Cannot insert breakpoints''
6003 If you request too many active hardware-assisted breakpoints and
6004 watchpoints, you will see this error message:
6006 @c FIXME: the precise wording of this message may change; the relevant
6007 @c source change is not committed yet (Sep 3, 1999).
6009 Stopped; cannot insert breakpoints.
6010 You may have requested too many hardware breakpoints and watchpoints.
6014 This message is printed when you attempt to resume the program, since
6015 only then @value{GDBN} knows exactly how many hardware breakpoints and
6016 watchpoints it needs to insert.
6018 When this message is printed, you need to disable or remove some of the
6019 hardware-assisted breakpoints and watchpoints, and then continue.
6021 @node Breakpoint-related Warnings
6022 @subsection ``Breakpoint address adjusted...''
6023 @cindex breakpoint address adjusted
6025 Some processor architectures place constraints on the addresses at
6026 which breakpoints may be placed. For architectures thus constrained,
6027 @value{GDBN} will attempt to adjust the breakpoint's address to comply
6028 with the constraints dictated by the architecture.
6030 One example of such an architecture is the Fujitsu FR-V. The FR-V is
6031 a VLIW architecture in which a number of RISC-like instructions may be
6032 bundled together for parallel execution. The FR-V architecture
6033 constrains the location of a breakpoint instruction within such a
6034 bundle to the instruction with the lowest address. @value{GDBN}
6035 honors this constraint by adjusting a breakpoint's address to the
6036 first in the bundle.
6038 It is not uncommon for optimized code to have bundles which contain
6039 instructions from different source statements, thus it may happen that
6040 a breakpoint's address will be adjusted from one source statement to
6041 another. Since this adjustment may significantly alter @value{GDBN}'s
6042 breakpoint related behavior from what the user expects, a warning is
6043 printed when the breakpoint is first set and also when the breakpoint
6046 A warning like the one below is printed when setting a breakpoint
6047 that's been subject to address adjustment:
6050 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6053 Such warnings are printed both for user settable and @value{GDBN}'s
6054 internal breakpoints. If you see one of these warnings, you should
6055 verify that a breakpoint set at the adjusted address will have the
6056 desired affect. If not, the breakpoint in question may be removed and
6057 other breakpoints may be set which will have the desired behavior.
6058 E.g., it may be sufficient to place the breakpoint at a later
6059 instruction. A conditional breakpoint may also be useful in some
6060 cases to prevent the breakpoint from triggering too often.
6062 @value{GDBN} will also issue a warning when stopping at one of these
6063 adjusted breakpoints:
6066 warning: Breakpoint 1 address previously adjusted from 0x00010414
6070 When this warning is encountered, it may be too late to take remedial
6071 action except in cases where the breakpoint is hit earlier or more
6072 frequently than expected.
6074 @node Continuing and Stepping
6075 @section Continuing and Stepping
6079 @cindex resuming execution
6080 @dfn{Continuing} means resuming program execution until your program
6081 completes normally. In contrast, @dfn{stepping} means executing just
6082 one more ``step'' of your program, where ``step'' may mean either one
6083 line of source code, or one machine instruction (depending on what
6084 particular command you use). Either when continuing or when stepping,
6085 your program may stop even sooner, due to a breakpoint or a signal. (If
6086 it stops due to a signal, you may want to use @code{handle}, or use
6087 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6088 or you may step into the signal's handler (@pxref{stepping and signal
6093 @kindex c @r{(@code{continue})}
6094 @kindex fg @r{(resume foreground execution)}
6095 @item continue @r{[}@var{ignore-count}@r{]}
6096 @itemx c @r{[}@var{ignore-count}@r{]}
6097 @itemx fg @r{[}@var{ignore-count}@r{]}
6098 Resume program execution, at the address where your program last stopped;
6099 any breakpoints set at that address are bypassed. The optional argument
6100 @var{ignore-count} allows you to specify a further number of times to
6101 ignore a breakpoint at this location; its effect is like that of
6102 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6104 The argument @var{ignore-count} is meaningful only when your program
6105 stopped due to a breakpoint. At other times, the argument to
6106 @code{continue} is ignored.
6108 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6109 debugged program is deemed to be the foreground program) are provided
6110 purely for convenience, and have exactly the same behavior as
6114 To resume execution at a different place, you can use @code{return}
6115 (@pxref{Returning, ,Returning from a Function}) to go back to the
6116 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6117 Different Address}) to go to an arbitrary location in your program.
6119 A typical technique for using stepping is to set a breakpoint
6120 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6121 beginning of the function or the section of your program where a problem
6122 is believed to lie, run your program until it stops at that breakpoint,
6123 and then step through the suspect area, examining the variables that are
6124 interesting, until you see the problem happen.
6128 @kindex s @r{(@code{step})}
6130 Continue running your program until control reaches a different source
6131 line, then stop it and return control to @value{GDBN}. This command is
6132 abbreviated @code{s}.
6135 @c "without debugging information" is imprecise; actually "without line
6136 @c numbers in the debugging information". (gcc -g1 has debugging info but
6137 @c not line numbers). But it seems complex to try to make that
6138 @c distinction here.
6139 @emph{Warning:} If you use the @code{step} command while control is
6140 within a function that was compiled without debugging information,
6141 execution proceeds until control reaches a function that does have
6142 debugging information. Likewise, it will not step into a function which
6143 is compiled without debugging information. To step through functions
6144 without debugging information, use the @code{stepi} command, described
6148 The @code{step} command only stops at the first instruction of a source
6149 line. This prevents the multiple stops that could otherwise occur in
6150 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6151 to stop if a function that has debugging information is called within
6152 the line. In other words, @code{step} @emph{steps inside} any functions
6153 called within the line.
6155 Also, the @code{step} command only enters a function if there is line
6156 number information for the function. Otherwise it acts like the
6157 @code{next} command. This avoids problems when using @code{cc -gl}
6158 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6159 was any debugging information about the routine.
6161 @item step @var{count}
6162 Continue running as in @code{step}, but do so @var{count} times. If a
6163 breakpoint is reached, or a signal not related to stepping occurs before
6164 @var{count} steps, stepping stops right away.
6167 @kindex n @r{(@code{next})}
6168 @item next @r{[}@var{count}@r{]}
6169 Continue to the next source line in the current (innermost) stack frame.
6170 This is similar to @code{step}, but function calls that appear within
6171 the line of code are executed without stopping. Execution stops when
6172 control reaches a different line of code at the original stack level
6173 that was executing when you gave the @code{next} command. This command
6174 is abbreviated @code{n}.
6176 An argument @var{count} is a repeat count, as for @code{step}.
6179 @c FIX ME!! Do we delete this, or is there a way it fits in with
6180 @c the following paragraph? --- Vctoria
6182 @c @code{next} within a function that lacks debugging information acts like
6183 @c @code{step}, but any function calls appearing within the code of the
6184 @c function are executed without stopping.
6186 The @code{next} command only stops at the first instruction of a
6187 source line. This prevents multiple stops that could otherwise occur in
6188 @code{switch} statements, @code{for} loops, etc.
6190 @kindex set step-mode
6192 @cindex functions without line info, and stepping
6193 @cindex stepping into functions with no line info
6194 @itemx set step-mode on
6195 The @code{set step-mode on} command causes the @code{step} command to
6196 stop at the first instruction of a function which contains no debug line
6197 information rather than stepping over it.
6199 This is useful in cases where you may be interested in inspecting the
6200 machine instructions of a function which has no symbolic info and do not
6201 want @value{GDBN} to automatically skip over this function.
6203 @item set step-mode off
6204 Causes the @code{step} command to step over any functions which contains no
6205 debug information. This is the default.
6207 @item show step-mode
6208 Show whether @value{GDBN} will stop in or step over functions without
6209 source line debug information.
6212 @kindex fin @r{(@code{finish})}
6214 Continue running until just after function in the selected stack frame
6215 returns. Print the returned value (if any). This command can be
6216 abbreviated as @code{fin}.
6218 Contrast this with the @code{return} command (@pxref{Returning,
6219 ,Returning from a Function}).
6221 @kindex set print finish
6222 @kindex show print finish
6223 @item set print finish @r{[}on|off@r{]}
6224 @itemx show print finish
6225 By default the @code{finish} command will show the value that is
6226 returned by the function. This can be disabled using @code{set print
6227 finish off}. When disabled, the value is still entered into the value
6228 history (@pxref{Value History}), but not displayed.
6231 @kindex u @r{(@code{until})}
6232 @cindex run until specified location
6235 Continue running until a source line past the current line, in the
6236 current stack frame, is reached. This command is used to avoid single
6237 stepping through a loop more than once. It is like the @code{next}
6238 command, except that when @code{until} encounters a jump, it
6239 automatically continues execution until the program counter is greater
6240 than the address of the jump.
6242 This means that when you reach the end of a loop after single stepping
6243 though it, @code{until} makes your program continue execution until it
6244 exits the loop. In contrast, a @code{next} command at the end of a loop
6245 simply steps back to the beginning of the loop, which forces you to step
6246 through the next iteration.
6248 @code{until} always stops your program if it attempts to exit the current
6251 @code{until} may produce somewhat counterintuitive results if the order
6252 of machine code does not match the order of the source lines. For
6253 example, in the following excerpt from a debugging session, the @code{f}
6254 (@code{frame}) command shows that execution is stopped at line
6255 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6259 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6261 (@value{GDBP}) until
6262 195 for ( ; argc > 0; NEXTARG) @{
6265 This happened because, for execution efficiency, the compiler had
6266 generated code for the loop closure test at the end, rather than the
6267 start, of the loop---even though the test in a C @code{for}-loop is
6268 written before the body of the loop. The @code{until} command appeared
6269 to step back to the beginning of the loop when it advanced to this
6270 expression; however, it has not really gone to an earlier
6271 statement---not in terms of the actual machine code.
6273 @code{until} with no argument works by means of single
6274 instruction stepping, and hence is slower than @code{until} with an
6277 @item until @var{location}
6278 @itemx u @var{location}
6279 Continue running your program until either the specified @var{location} is
6280 reached, or the current stack frame returns. The location is any of
6281 the forms described in @ref{Specify Location}.
6282 This form of the command uses temporary breakpoints, and
6283 hence is quicker than @code{until} without an argument. The specified
6284 location is actually reached only if it is in the current frame. This
6285 implies that @code{until} can be used to skip over recursive function
6286 invocations. For instance in the code below, if the current location is
6287 line @code{96}, issuing @code{until 99} will execute the program up to
6288 line @code{99} in the same invocation of factorial, i.e., after the inner
6289 invocations have returned.
6292 94 int factorial (int value)
6294 96 if (value > 1) @{
6295 97 value *= factorial (value - 1);
6302 @kindex advance @var{location}
6303 @item advance @var{location}
6304 Continue running the program up to the given @var{location}. An argument is
6305 required, which should be of one of the forms described in
6306 @ref{Specify Location}.
6307 Execution will also stop upon exit from the current stack
6308 frame. This command is similar to @code{until}, but @code{advance} will
6309 not skip over recursive function calls, and the target location doesn't
6310 have to be in the same frame as the current one.
6314 @kindex si @r{(@code{stepi})}
6316 @itemx stepi @var{arg}
6318 Execute one machine instruction, then stop and return to the debugger.
6320 It is often useful to do @samp{display/i $pc} when stepping by machine
6321 instructions. This makes @value{GDBN} automatically display the next
6322 instruction to be executed, each time your program stops. @xref{Auto
6323 Display,, Automatic Display}.
6325 An argument is a repeat count, as in @code{step}.
6329 @kindex ni @r{(@code{nexti})}
6331 @itemx nexti @var{arg}
6333 Execute one machine instruction, but if it is a function call,
6334 proceed until the function returns.
6336 An argument is a repeat count, as in @code{next}.
6340 @anchor{range stepping}
6341 @cindex range stepping
6342 @cindex target-assisted range stepping
6343 By default, and if available, @value{GDBN} makes use of
6344 target-assisted @dfn{range stepping}. In other words, whenever you
6345 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6346 tells the target to step the corresponding range of instruction
6347 addresses instead of issuing multiple single-steps. This speeds up
6348 line stepping, particularly for remote targets. Ideally, there should
6349 be no reason you would want to turn range stepping off. However, it's
6350 possible that a bug in the debug info, a bug in the remote stub (for
6351 remote targets), or even a bug in @value{GDBN} could make line
6352 stepping behave incorrectly when target-assisted range stepping is
6353 enabled. You can use the following command to turn off range stepping
6357 @kindex set range-stepping
6358 @kindex show range-stepping
6359 @item set range-stepping
6360 @itemx show range-stepping
6361 Control whether range stepping is enabled.
6363 If @code{on}, and the target supports it, @value{GDBN} tells the
6364 target to step a range of addresses itself, instead of issuing
6365 multiple single-steps. If @code{off}, @value{GDBN} always issues
6366 single-steps, even if range stepping is supported by the target. The
6367 default is @code{on}.
6371 @node Skipping Over Functions and Files
6372 @section Skipping Over Functions and Files
6373 @cindex skipping over functions and files
6375 The program you are debugging may contain some functions which are
6376 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6377 skip a function, all functions in a file or a particular function in
6378 a particular file when stepping.
6380 For example, consider the following C function:
6391 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6392 are not interested in stepping through @code{boring}. If you run @code{step}
6393 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6394 step over both @code{foo} and @code{boring}!
6396 One solution is to @code{step} into @code{boring} and use the @code{finish}
6397 command to immediately exit it. But this can become tedious if @code{boring}
6398 is called from many places.
6400 A more flexible solution is to execute @kbd{skip boring}. This instructs
6401 @value{GDBN} never to step into @code{boring}. Now when you execute
6402 @code{step} at line 103, you'll step over @code{boring} and directly into
6405 Functions may be skipped by providing either a function name, linespec
6406 (@pxref{Specify Location}), regular expression that matches the function's
6407 name, file name or a @code{glob}-style pattern that matches the file name.
6409 On Posix systems the form of the regular expression is
6410 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6411 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6412 expression is whatever is provided by the @code{regcomp} function of
6413 the underlying system.
6414 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6415 description of @code{glob}-style patterns.
6419 @item skip @r{[}@var{options}@r{]}
6420 The basic form of the @code{skip} command takes zero or more options
6421 that specify what to skip.
6422 The @var{options} argument is any useful combination of the following:
6425 @item -file @var{file}
6426 @itemx -fi @var{file}
6427 Functions in @var{file} will be skipped over when stepping.
6429 @item -gfile @var{file-glob-pattern}
6430 @itemx -gfi @var{file-glob-pattern}
6431 @cindex skipping over files via glob-style patterns
6432 Functions in files matching @var{file-glob-pattern} will be skipped
6436 (gdb) skip -gfi utils/*.c
6439 @item -function @var{linespec}
6440 @itemx -fu @var{linespec}
6441 Functions named by @var{linespec} or the function containing the line
6442 named by @var{linespec} will be skipped over when stepping.
6443 @xref{Specify Location}.
6445 @item -rfunction @var{regexp}
6446 @itemx -rfu @var{regexp}
6447 @cindex skipping over functions via regular expressions
6448 Functions whose name matches @var{regexp} will be skipped over when stepping.
6450 This form is useful for complex function names.
6451 For example, there is generally no need to step into C@t{++} @code{std::string}
6452 constructors or destructors. Plus with C@t{++} templates it can be hard to
6453 write out the full name of the function, and often it doesn't matter what
6454 the template arguments are. Specifying the function to be skipped as a
6455 regular expression makes this easier.
6458 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6461 If you want to skip every templated C@t{++} constructor and destructor
6462 in the @code{std} namespace you can do:
6465 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6469 If no options are specified, the function you're currently debugging
6472 @kindex skip function
6473 @item skip function @r{[}@var{linespec}@r{]}
6474 After running this command, the function named by @var{linespec} or the
6475 function containing the line named by @var{linespec} will be skipped over when
6476 stepping. @xref{Specify Location}.
6478 If you do not specify @var{linespec}, the function you're currently debugging
6481 (If you have a function called @code{file} that you want to skip, use
6482 @kbd{skip function file}.)
6485 @item skip file @r{[}@var{filename}@r{]}
6486 After running this command, any function whose source lives in @var{filename}
6487 will be skipped over when stepping.
6490 (gdb) skip file boring.c
6491 File boring.c will be skipped when stepping.
6494 If you do not specify @var{filename}, functions whose source lives in the file
6495 you're currently debugging will be skipped.
6498 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6499 These are the commands for managing your list of skips:
6503 @item info skip @r{[}@var{range}@r{]}
6504 Print details about the specified skip(s). If @var{range} is not specified,
6505 print a table with details about all functions and files marked for skipping.
6506 @code{info skip} prints the following information about each skip:
6510 A number identifying this skip.
6511 @item Enabled or Disabled
6512 Enabled skips are marked with @samp{y}.
6513 Disabled skips are marked with @samp{n}.
6515 If the file name is a @samp{glob} pattern this is @samp{y}.
6516 Otherwise it is @samp{n}.
6518 The name or @samp{glob} pattern of the file to be skipped.
6519 If no file is specified this is @samp{<none>}.
6521 If the function name is a @samp{regular expression} this is @samp{y}.
6522 Otherwise it is @samp{n}.
6524 The name or regular expression of the function to skip.
6525 If no function is specified this is @samp{<none>}.
6529 @item skip delete @r{[}@var{range}@r{]}
6530 Delete the specified skip(s). If @var{range} is not specified, delete all
6534 @item skip enable @r{[}@var{range}@r{]}
6535 Enable the specified skip(s). If @var{range} is not specified, enable all
6538 @kindex skip disable
6539 @item skip disable @r{[}@var{range}@r{]}
6540 Disable the specified skip(s). If @var{range} is not specified, disable all
6543 @kindex set debug skip
6544 @item set debug skip @r{[}on|off@r{]}
6545 Set whether to print the debug output about skipping files and functions.
6547 @kindex show debug skip
6548 @item show debug skip
6549 Show whether the debug output about skipping files and functions is printed.
6557 A signal is an asynchronous event that can happen in a program. The
6558 operating system defines the possible kinds of signals, and gives each
6559 kind a name and a number. For example, in Unix @code{SIGINT} is the
6560 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6561 @code{SIGSEGV} is the signal a program gets from referencing a place in
6562 memory far away from all the areas in use; @code{SIGALRM} occurs when
6563 the alarm clock timer goes off (which happens only if your program has
6564 requested an alarm).
6566 @cindex fatal signals
6567 Some signals, including @code{SIGALRM}, are a normal part of the
6568 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6569 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6570 program has not specified in advance some other way to handle the signal.
6571 @code{SIGINT} does not indicate an error in your program, but it is normally
6572 fatal so it can carry out the purpose of the interrupt: to kill the program.
6574 @value{GDBN} has the ability to detect any occurrence of a signal in your
6575 program. You can tell @value{GDBN} in advance what to do for each kind of
6578 @cindex handling signals
6579 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6580 @code{SIGALRM} be silently passed to your program
6581 (so as not to interfere with their role in the program's functioning)
6582 but to stop your program immediately whenever an error signal happens.
6583 You can change these settings with the @code{handle} command.
6586 @kindex info signals
6590 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6591 handle each one. You can use this to see the signal numbers of all
6592 the defined types of signals.
6594 @item info signals @var{sig}
6595 Similar, but print information only about the specified signal number.
6597 @code{info handle} is an alias for @code{info signals}.
6599 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6600 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6601 for details about this command.
6604 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6605 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6606 can be the number of a signal or its name (with or without the
6607 @samp{SIG} at the beginning); a list of signal numbers of the form
6608 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6609 known signals. Optional arguments @var{keywords}, described below,
6610 say what change to make.
6614 The keywords allowed by the @code{handle} command can be abbreviated.
6615 Their full names are:
6619 @value{GDBN} should not stop your program when this signal happens. It may
6620 still print a message telling you that the signal has come in.
6623 @value{GDBN} should stop your program when this signal happens. This implies
6624 the @code{print} keyword as well.
6627 @value{GDBN} should print a message when this signal happens.
6630 @value{GDBN} should not mention the occurrence of the signal at all. This
6631 implies the @code{nostop} keyword as well.
6635 @value{GDBN} should allow your program to see this signal; your program
6636 can handle the signal, or else it may terminate if the signal is fatal
6637 and not handled. @code{pass} and @code{noignore} are synonyms.
6641 @value{GDBN} should not allow your program to see this signal.
6642 @code{nopass} and @code{ignore} are synonyms.
6646 When a signal stops your program, the signal is not visible to the
6648 continue. Your program sees the signal then, if @code{pass} is in
6649 effect for the signal in question @emph{at that time}. In other words,
6650 after @value{GDBN} reports a signal, you can use the @code{handle}
6651 command with @code{pass} or @code{nopass} to control whether your
6652 program sees that signal when you continue.
6654 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6655 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6656 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6659 You can also use the @code{signal} command to prevent your program from
6660 seeing a signal, or cause it to see a signal it normally would not see,
6661 or to give it any signal at any time. For example, if your program stopped
6662 due to some sort of memory reference error, you might store correct
6663 values into the erroneous variables and continue, hoping to see more
6664 execution; but your program would probably terminate immediately as
6665 a result of the fatal signal once it saw the signal. To prevent this,
6666 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6669 @cindex stepping and signal handlers
6670 @anchor{stepping and signal handlers}
6672 @value{GDBN} optimizes for stepping the mainline code. If a signal
6673 that has @code{handle nostop} and @code{handle pass} set arrives while
6674 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6675 in progress, @value{GDBN} lets the signal handler run and then resumes
6676 stepping the mainline code once the signal handler returns. In other
6677 words, @value{GDBN} steps over the signal handler. This prevents
6678 signals that you've specified as not interesting (with @code{handle
6679 nostop}) from changing the focus of debugging unexpectedly. Note that
6680 the signal handler itself may still hit a breakpoint, stop for another
6681 signal that has @code{handle stop} in effect, or for any other event
6682 that normally results in stopping the stepping command sooner. Also
6683 note that @value{GDBN} still informs you that the program received a
6684 signal if @code{handle print} is set.
6686 @anchor{stepping into signal handlers}
6688 If you set @code{handle pass} for a signal, and your program sets up a
6689 handler for it, then issuing a stepping command, such as @code{step}
6690 or @code{stepi}, when your program is stopped due to the signal will
6691 step @emph{into} the signal handler (if the target supports that).
6693 Likewise, if you use the @code{queue-signal} command to queue a signal
6694 to be delivered to the current thread when execution of the thread
6695 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6696 stepping command will step into the signal handler.
6698 Here's an example, using @code{stepi} to step to the first instruction
6699 of @code{SIGUSR1}'s handler:
6702 (@value{GDBP}) handle SIGUSR1
6703 Signal Stop Print Pass to program Description
6704 SIGUSR1 Yes Yes Yes User defined signal 1
6708 Program received signal SIGUSR1, User defined signal 1.
6709 main () sigusr1.c:28
6712 sigusr1_handler () at sigusr1.c:9
6716 The same, but using @code{queue-signal} instead of waiting for the
6717 program to receive the signal first:
6722 (@value{GDBP}) queue-signal SIGUSR1
6724 sigusr1_handler () at sigusr1.c:9
6729 @cindex extra signal information
6730 @anchor{extra signal information}
6732 On some targets, @value{GDBN} can inspect extra signal information
6733 associated with the intercepted signal, before it is actually
6734 delivered to the program being debugged. This information is exported
6735 by the convenience variable @code{$_siginfo}, and consists of data
6736 that is passed by the kernel to the signal handler at the time of the
6737 receipt of a signal. The data type of the information itself is
6738 target dependent. You can see the data type using the @code{ptype
6739 $_siginfo} command. On Unix systems, it typically corresponds to the
6740 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6743 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6744 referenced address that raised a segmentation fault.
6748 (@value{GDBP}) continue
6749 Program received signal SIGSEGV, Segmentation fault.
6750 0x0000000000400766 in main ()
6752 (@value{GDBP}) ptype $_siginfo
6759 struct @{...@} _kill;
6760 struct @{...@} _timer;
6762 struct @{...@} _sigchld;
6763 struct @{...@} _sigfault;
6764 struct @{...@} _sigpoll;
6767 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6771 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6772 $1 = (void *) 0x7ffff7ff7000
6776 Depending on target support, @code{$_siginfo} may also be writable.
6778 @cindex Intel MPX boundary violations
6779 @cindex boundary violations, Intel MPX
6780 On some targets, a @code{SIGSEGV} can be caused by a boundary
6781 violation, i.e., accessing an address outside of the allowed range.
6782 In those cases @value{GDBN} may displays additional information,
6783 depending on how @value{GDBN} has been told to handle the signal.
6784 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6785 kind: "Upper" or "Lower", the memory address accessed and the
6786 bounds, while with @code{handle nostop SIGSEGV} no additional
6787 information is displayed.
6789 The usual output of a segfault is:
6791 Program received signal SIGSEGV, Segmentation fault
6792 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6793 68 value = *(p + len);
6796 While a bound violation is presented as:
6798 Program received signal SIGSEGV, Segmentation fault
6799 Upper bound violation while accessing address 0x7fffffffc3b3
6800 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6801 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6802 68 value = *(p + len);
6806 @section Stopping and Starting Multi-thread Programs
6808 @cindex stopped threads
6809 @cindex threads, stopped
6811 @cindex continuing threads
6812 @cindex threads, continuing
6814 @value{GDBN} supports debugging programs with multiple threads
6815 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6816 are two modes of controlling execution of your program within the
6817 debugger. In the default mode, referred to as @dfn{all-stop mode},
6818 when any thread in your program stops (for example, at a breakpoint
6819 or while being stepped), all other threads in the program are also stopped by
6820 @value{GDBN}. On some targets, @value{GDBN} also supports
6821 @dfn{non-stop mode}, in which other threads can continue to run freely while
6822 you examine the stopped thread in the debugger.
6825 * All-Stop Mode:: All threads stop when GDB takes control
6826 * Non-Stop Mode:: Other threads continue to execute
6827 * Background Execution:: Running your program asynchronously
6828 * Thread-Specific Breakpoints:: Controlling breakpoints
6829 * Interrupted System Calls:: GDB may interfere with system calls
6830 * Observer Mode:: GDB does not alter program behavior
6834 @subsection All-Stop Mode
6836 @cindex all-stop mode
6838 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6839 @emph{all} threads of execution stop, not just the current thread. This
6840 allows you to examine the overall state of the program, including
6841 switching between threads, without worrying that things may change
6844 Conversely, whenever you restart the program, @emph{all} threads start
6845 executing. @emph{This is true even when single-stepping} with commands
6846 like @code{step} or @code{next}.
6848 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6849 Since thread scheduling is up to your debugging target's operating
6850 system (not controlled by @value{GDBN}), other threads may
6851 execute more than one statement while the current thread completes a
6852 single step. Moreover, in general other threads stop in the middle of a
6853 statement, rather than at a clean statement boundary, when the program
6856 You might even find your program stopped in another thread after
6857 continuing or even single-stepping. This happens whenever some other
6858 thread runs into a breakpoint, a signal, or an exception before the
6859 first thread completes whatever you requested.
6861 @cindex automatic thread selection
6862 @cindex switching threads automatically
6863 @cindex threads, automatic switching
6864 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6865 signal, it automatically selects the thread where that breakpoint or
6866 signal happened. @value{GDBN} alerts you to the context switch with a
6867 message such as @samp{[Switching to Thread @var{n}]} to identify the
6870 On some OSes, you can modify @value{GDBN}'s default behavior by
6871 locking the OS scheduler to allow only a single thread to run.
6874 @item set scheduler-locking @var{mode}
6875 @cindex scheduler locking mode
6876 @cindex lock scheduler
6877 Set the scheduler locking mode. It applies to normal execution,
6878 record mode, and replay mode. If it is @code{off}, then there is no
6879 locking and any thread may run at any time. If @code{on}, then only
6880 the current thread may run when the inferior is resumed. The
6881 @code{step} mode optimizes for single-stepping; it prevents other
6882 threads from preempting the current thread while you are stepping, so
6883 that the focus of debugging does not change unexpectedly. Other
6884 threads never get a chance to run when you step, and they are
6885 completely free to run when you use commands like @samp{continue},
6886 @samp{until}, or @samp{finish}. However, unless another thread hits a
6887 breakpoint during its timeslice, @value{GDBN} does not change the
6888 current thread away from the thread that you are debugging. The
6889 @code{replay} mode behaves like @code{off} in record mode and like
6890 @code{on} in replay mode.
6892 @item show scheduler-locking
6893 Display the current scheduler locking mode.
6896 @cindex resume threads of multiple processes simultaneously
6897 By default, when you issue one of the execution commands such as
6898 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6899 threads of the current inferior to run. For example, if @value{GDBN}
6900 is attached to two inferiors, each with two threads, the
6901 @code{continue} command resumes only the two threads of the current
6902 inferior. This is useful, for example, when you debug a program that
6903 forks and you want to hold the parent stopped (so that, for instance,
6904 it doesn't run to exit), while you debug the child. In other
6905 situations, you may not be interested in inspecting the current state
6906 of any of the processes @value{GDBN} is attached to, and you may want
6907 to resume them all until some breakpoint is hit. In the latter case,
6908 you can instruct @value{GDBN} to allow all threads of all the
6909 inferiors to run with the @w{@code{set schedule-multiple}} command.
6912 @kindex set schedule-multiple
6913 @item set schedule-multiple
6914 Set the mode for allowing threads of multiple processes to be resumed
6915 when an execution command is issued. When @code{on}, all threads of
6916 all processes are allowed to run. When @code{off}, only the threads
6917 of the current process are resumed. The default is @code{off}. The
6918 @code{scheduler-locking} mode takes precedence when set to @code{on},
6919 or while you are stepping and set to @code{step}.
6921 @item show schedule-multiple
6922 Display the current mode for resuming the execution of threads of
6927 @subsection Non-Stop Mode
6929 @cindex non-stop mode
6931 @c This section is really only a place-holder, and needs to be expanded
6932 @c with more details.
6934 For some multi-threaded targets, @value{GDBN} supports an optional
6935 mode of operation in which you can examine stopped program threads in
6936 the debugger while other threads continue to execute freely. This
6937 minimizes intrusion when debugging live systems, such as programs
6938 where some threads have real-time constraints or must continue to
6939 respond to external events. This is referred to as @dfn{non-stop} mode.
6941 In non-stop mode, when a thread stops to report a debugging event,
6942 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6943 threads as well, in contrast to the all-stop mode behavior. Additionally,
6944 execution commands such as @code{continue} and @code{step} apply by default
6945 only to the current thread in non-stop mode, rather than all threads as
6946 in all-stop mode. This allows you to control threads explicitly in
6947 ways that are not possible in all-stop mode --- for example, stepping
6948 one thread while allowing others to run freely, stepping
6949 one thread while holding all others stopped, or stepping several threads
6950 independently and simultaneously.
6952 To enter non-stop mode, use this sequence of commands before you run
6953 or attach to your program:
6956 # If using the CLI, pagination breaks non-stop.
6959 # Finally, turn it on!
6963 You can use these commands to manipulate the non-stop mode setting:
6966 @kindex set non-stop
6967 @item set non-stop on
6968 Enable selection of non-stop mode.
6969 @item set non-stop off
6970 Disable selection of non-stop mode.
6971 @kindex show non-stop
6973 Show the current non-stop enablement setting.
6976 Note these commands only reflect whether non-stop mode is enabled,
6977 not whether the currently-executing program is being run in non-stop mode.
6978 In particular, the @code{set non-stop} preference is only consulted when
6979 @value{GDBN} starts or connects to the target program, and it is generally
6980 not possible to switch modes once debugging has started. Furthermore,
6981 since not all targets support non-stop mode, even when you have enabled
6982 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6985 In non-stop mode, all execution commands apply only to the current thread
6986 by default. That is, @code{continue} only continues one thread.
6987 To continue all threads, issue @code{continue -a} or @code{c -a}.
6989 You can use @value{GDBN}'s background execution commands
6990 (@pxref{Background Execution}) to run some threads in the background
6991 while you continue to examine or step others from @value{GDBN}.
6992 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6993 always executed asynchronously in non-stop mode.
6995 Suspending execution is done with the @code{interrupt} command when
6996 running in the background, or @kbd{Ctrl-c} during foreground execution.
6997 In all-stop mode, this stops the whole process;
6998 but in non-stop mode the interrupt applies only to the current thread.
6999 To stop the whole program, use @code{interrupt -a}.
7001 Other execution commands do not currently support the @code{-a} option.
7003 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
7004 that thread current, as it does in all-stop mode. This is because the
7005 thread stop notifications are asynchronous with respect to @value{GDBN}'s
7006 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
7007 changed to a different thread just as you entered a command to operate on the
7008 previously current thread.
7010 @node Background Execution
7011 @subsection Background Execution
7013 @cindex foreground execution
7014 @cindex background execution
7015 @cindex asynchronous execution
7016 @cindex execution, foreground, background and asynchronous
7018 @value{GDBN}'s execution commands have two variants: the normal
7019 foreground (synchronous) behavior, and a background
7020 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
7021 the program to report that some thread has stopped before prompting for
7022 another command. In background execution, @value{GDBN} immediately gives
7023 a command prompt so that you can issue other commands while your program runs.
7025 If the target doesn't support async mode, @value{GDBN} issues an error
7026 message if you attempt to use the background execution commands.
7028 @cindex @code{&}, background execution of commands
7029 To specify background execution, add a @code{&} to the command. For example,
7030 the background form of the @code{continue} command is @code{continue&}, or
7031 just @code{c&}. The execution commands that accept background execution
7037 @xref{Starting, , Starting your Program}.
7041 @xref{Attach, , Debugging an Already-running Process}.
7045 @xref{Continuing and Stepping, step}.
7049 @xref{Continuing and Stepping, stepi}.
7053 @xref{Continuing and Stepping, next}.
7057 @xref{Continuing and Stepping, nexti}.
7061 @xref{Continuing and Stepping, continue}.
7065 @xref{Continuing and Stepping, finish}.
7069 @xref{Continuing and Stepping, until}.
7073 Background execution is especially useful in conjunction with non-stop
7074 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7075 However, you can also use these commands in the normal all-stop mode with
7076 the restriction that you cannot issue another execution command until the
7077 previous one finishes. Examples of commands that are valid in all-stop
7078 mode while the program is running include @code{help} and @code{info break}.
7080 You can interrupt your program while it is running in the background by
7081 using the @code{interrupt} command.
7088 Suspend execution of the running program. In all-stop mode,
7089 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7090 only the current thread. To stop the whole program in non-stop mode,
7091 use @code{interrupt -a}.
7094 @node Thread-Specific Breakpoints
7095 @subsection Thread-Specific Breakpoints
7097 When your program has multiple threads (@pxref{Threads,, Debugging
7098 Programs with Multiple Threads}), you can choose whether to set
7099 breakpoints on all threads, or on a particular thread.
7102 @cindex breakpoints and threads
7103 @cindex thread breakpoints
7104 @kindex break @dots{} thread @var{thread-id}
7105 @item break @var{location} thread @var{thread-id}
7106 @itemx break @var{location} thread @var{thread-id} if @dots{}
7107 @var{location} specifies source lines; there are several ways of
7108 writing them (@pxref{Specify Location}), but the effect is always to
7109 specify some source line.
7111 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7112 to specify that you only want @value{GDBN} to stop the program when a
7113 particular thread reaches this breakpoint. The @var{thread-id} specifier
7114 is one of the thread identifiers assigned by @value{GDBN}, shown
7115 in the first column of the @samp{info threads} display.
7117 If you do not specify @samp{thread @var{thread-id}} when you set a
7118 breakpoint, the breakpoint applies to @emph{all} threads of your
7121 You can use the @code{thread} qualifier on conditional breakpoints as
7122 well; in this case, place @samp{thread @var{thread-id}} before or
7123 after the breakpoint condition, like this:
7126 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7131 Thread-specific breakpoints are automatically deleted when
7132 @value{GDBN} detects the corresponding thread is no longer in the
7133 thread list. For example:
7137 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7140 There are several ways for a thread to disappear, such as a regular
7141 thread exit, but also when you detach from the process with the
7142 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7143 Process}), or if @value{GDBN} loses the remote connection
7144 (@pxref{Remote Debugging}), etc. Note that with some targets,
7145 @value{GDBN} is only able to detect a thread has exited when the user
7146 explictly asks for the thread list with the @code{info threads}
7149 @node Interrupted System Calls
7150 @subsection Interrupted System Calls
7152 @cindex thread breakpoints and system calls
7153 @cindex system calls and thread breakpoints
7154 @cindex premature return from system calls
7155 There is an unfortunate side effect when using @value{GDBN} to debug
7156 multi-threaded programs. If one thread stops for a
7157 breakpoint, or for some other reason, and another thread is blocked in a
7158 system call, then the system call may return prematurely. This is a
7159 consequence of the interaction between multiple threads and the signals
7160 that @value{GDBN} uses to implement breakpoints and other events that
7163 To handle this problem, your program should check the return value of
7164 each system call and react appropriately. This is good programming
7167 For example, do not write code like this:
7173 The call to @code{sleep} will return early if a different thread stops
7174 at a breakpoint or for some other reason.
7176 Instead, write this:
7181 unslept = sleep (unslept);
7184 A system call is allowed to return early, so the system is still
7185 conforming to its specification. But @value{GDBN} does cause your
7186 multi-threaded program to behave differently than it would without
7189 Also, @value{GDBN} uses internal breakpoints in the thread library to
7190 monitor certain events such as thread creation and thread destruction.
7191 When such an event happens, a system call in another thread may return
7192 prematurely, even though your program does not appear to stop.
7195 @subsection Observer Mode
7197 If you want to build on non-stop mode and observe program behavior
7198 without any chance of disruption by @value{GDBN}, you can set
7199 variables to disable all of the debugger's attempts to modify state,
7200 whether by writing memory, inserting breakpoints, etc. These operate
7201 at a low level, intercepting operations from all commands.
7203 When all of these are set to @code{off}, then @value{GDBN} is said to
7204 be @dfn{observer mode}. As a convenience, the variable
7205 @code{observer} can be set to disable these, plus enable non-stop
7208 Note that @value{GDBN} will not prevent you from making nonsensical
7209 combinations of these settings. For instance, if you have enabled
7210 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7211 then breakpoints that work by writing trap instructions into the code
7212 stream will still not be able to be placed.
7217 @item set observer on
7218 @itemx set observer off
7219 When set to @code{on}, this disables all the permission variables
7220 below (except for @code{insert-fast-tracepoints}), plus enables
7221 non-stop debugging. Setting this to @code{off} switches back to
7222 normal debugging, though remaining in non-stop mode.
7225 Show whether observer mode is on or off.
7227 @kindex may-write-registers
7228 @item set may-write-registers on
7229 @itemx set may-write-registers off
7230 This controls whether @value{GDBN} will attempt to alter the values of
7231 registers, such as with assignment expressions in @code{print}, or the
7232 @code{jump} command. It defaults to @code{on}.
7234 @item show may-write-registers
7235 Show the current permission to write registers.
7237 @kindex may-write-memory
7238 @item set may-write-memory on
7239 @itemx set may-write-memory off
7240 This controls whether @value{GDBN} will attempt to alter the contents
7241 of memory, such as with assignment expressions in @code{print}. It
7242 defaults to @code{on}.
7244 @item show may-write-memory
7245 Show the current permission to write memory.
7247 @kindex may-insert-breakpoints
7248 @item set may-insert-breakpoints on
7249 @itemx set may-insert-breakpoints off
7250 This controls whether @value{GDBN} will attempt to insert breakpoints.
7251 This affects all breakpoints, including internal breakpoints defined
7252 by @value{GDBN}. It defaults to @code{on}.
7254 @item show may-insert-breakpoints
7255 Show the current permission to insert breakpoints.
7257 @kindex may-insert-tracepoints
7258 @item set may-insert-tracepoints on
7259 @itemx set may-insert-tracepoints off
7260 This controls whether @value{GDBN} will attempt to insert (regular)
7261 tracepoints at the beginning of a tracing experiment. It affects only
7262 non-fast tracepoints, fast tracepoints being under the control of
7263 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7265 @item show may-insert-tracepoints
7266 Show the current permission to insert tracepoints.
7268 @kindex may-insert-fast-tracepoints
7269 @item set may-insert-fast-tracepoints on
7270 @itemx set may-insert-fast-tracepoints off
7271 This controls whether @value{GDBN} will attempt to insert fast
7272 tracepoints at the beginning of a tracing experiment. It affects only
7273 fast tracepoints, regular (non-fast) tracepoints being under the
7274 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7276 @item show may-insert-fast-tracepoints
7277 Show the current permission to insert fast tracepoints.
7279 @kindex may-interrupt
7280 @item set may-interrupt on
7281 @itemx set may-interrupt off
7282 This controls whether @value{GDBN} will attempt to interrupt or stop
7283 program execution. When this variable is @code{off}, the
7284 @code{interrupt} command will have no effect, nor will
7285 @kbd{Ctrl-c}. It defaults to @code{on}.
7287 @item show may-interrupt
7288 Show the current permission to interrupt or stop the program.
7292 @node Reverse Execution
7293 @chapter Running programs backward
7294 @cindex reverse execution
7295 @cindex running programs backward
7297 When you are debugging a program, it is not unusual to realize that
7298 you have gone too far, and some event of interest has already happened.
7299 If the target environment supports it, @value{GDBN} can allow you to
7300 ``rewind'' the program by running it backward.
7302 A target environment that supports reverse execution should be able
7303 to ``undo'' the changes in machine state that have taken place as the
7304 program was executing normally. Variables, registers etc.@: should
7305 revert to their previous values. Obviously this requires a great
7306 deal of sophistication on the part of the target environment; not
7307 all target environments can support reverse execution.
7309 When a program is executed in reverse, the instructions that
7310 have most recently been executed are ``un-executed'', in reverse
7311 order. The program counter runs backward, following the previous
7312 thread of execution in reverse. As each instruction is ``un-executed'',
7313 the values of memory and/or registers that were changed by that
7314 instruction are reverted to their previous states. After executing
7315 a piece of source code in reverse, all side effects of that code
7316 should be ``undone'', and all variables should be returned to their
7317 prior values@footnote{
7318 Note that some side effects are easier to undo than others. For instance,
7319 memory and registers are relatively easy, but device I/O is hard. Some
7320 targets may be able undo things like device I/O, and some may not.
7322 The contract between @value{GDBN} and the reverse executing target
7323 requires only that the target do something reasonable when
7324 @value{GDBN} tells it to execute backwards, and then report the
7325 results back to @value{GDBN}. Whatever the target reports back to
7326 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7327 assumes that the memory and registers that the target reports are in a
7328 consistent state, but @value{GDBN} accepts whatever it is given.
7331 On some platforms, @value{GDBN} has built-in support for reverse
7332 execution, activated with the @code{record} or @code{record btrace}
7333 commands. @xref{Process Record and Replay}. Some remote targets,
7334 typically full system emulators, support reverse execution directly
7335 without requiring any special command.
7337 If you are debugging in a target environment that supports
7338 reverse execution, @value{GDBN} provides the following commands.
7341 @kindex reverse-continue
7342 @kindex rc @r{(@code{reverse-continue})}
7343 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7344 @itemx rc @r{[}@var{ignore-count}@r{]}
7345 Beginning at the point where your program last stopped, start executing
7346 in reverse. Reverse execution will stop for breakpoints and synchronous
7347 exceptions (signals), just like normal execution. Behavior of
7348 asynchronous signals depends on the target environment.
7350 @kindex reverse-step
7351 @kindex rs @r{(@code{step})}
7352 @item reverse-step @r{[}@var{count}@r{]}
7353 Run the program backward until control reaches the start of a
7354 different source line; then stop it, and return control to @value{GDBN}.
7356 Like the @code{step} command, @code{reverse-step} will only stop
7357 at the beginning of a source line. It ``un-executes'' the previously
7358 executed source line. If the previous source line included calls to
7359 debuggable functions, @code{reverse-step} will step (backward) into
7360 the called function, stopping at the beginning of the @emph{last}
7361 statement in the called function (typically a return statement).
7363 Also, as with the @code{step} command, if non-debuggable functions are
7364 called, @code{reverse-step} will run thru them backward without stopping.
7366 @kindex reverse-stepi
7367 @kindex rsi @r{(@code{reverse-stepi})}
7368 @item reverse-stepi @r{[}@var{count}@r{]}
7369 Reverse-execute one machine instruction. Note that the instruction
7370 to be reverse-executed is @emph{not} the one pointed to by the program
7371 counter, but the instruction executed prior to that one. For instance,
7372 if the last instruction was a jump, @code{reverse-stepi} will take you
7373 back from the destination of the jump to the jump instruction itself.
7375 @kindex reverse-next
7376 @kindex rn @r{(@code{reverse-next})}
7377 @item reverse-next @r{[}@var{count}@r{]}
7378 Run backward to the beginning of the previous line executed in
7379 the current (innermost) stack frame. If the line contains function
7380 calls, they will be ``un-executed'' without stopping. Starting from
7381 the first line of a function, @code{reverse-next} will take you back
7382 to the caller of that function, @emph{before} the function was called,
7383 just as the normal @code{next} command would take you from the last
7384 line of a function back to its return to its caller
7385 @footnote{Unless the code is too heavily optimized.}.
7387 @kindex reverse-nexti
7388 @kindex rni @r{(@code{reverse-nexti})}
7389 @item reverse-nexti @r{[}@var{count}@r{]}
7390 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7391 in reverse, except that called functions are ``un-executed'' atomically.
7392 That is, if the previously executed instruction was a return from
7393 another function, @code{reverse-nexti} will continue to execute
7394 in reverse until the call to that function (from the current stack
7397 @kindex reverse-finish
7398 @item reverse-finish
7399 Just as the @code{finish} command takes you to the point where the
7400 current function returns, @code{reverse-finish} takes you to the point
7401 where it was called. Instead of ending up at the end of the current
7402 function invocation, you end up at the beginning.
7404 @kindex set exec-direction
7405 @item set exec-direction
7406 Set the direction of target execution.
7407 @item set exec-direction reverse
7408 @cindex execute forward or backward in time
7409 @value{GDBN} will perform all execution commands in reverse, until the
7410 exec-direction mode is changed to ``forward''. Affected commands include
7411 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7412 command cannot be used in reverse mode.
7413 @item set exec-direction forward
7414 @value{GDBN} will perform all execution commands in the normal fashion.
7415 This is the default.
7419 @node Process Record and Replay
7420 @chapter Recording Inferior's Execution and Replaying It
7421 @cindex process record and replay
7422 @cindex recording inferior's execution and replaying it
7424 On some platforms, @value{GDBN} provides a special @dfn{process record
7425 and replay} target that can record a log of the process execution, and
7426 replay it later with both forward and reverse execution commands.
7429 When this target is in use, if the execution log includes the record
7430 for the next instruction, @value{GDBN} will debug in @dfn{replay
7431 mode}. In the replay mode, the inferior does not really execute code
7432 instructions. Instead, all the events that normally happen during
7433 code execution are taken from the execution log. While code is not
7434 really executed in replay mode, the values of registers (including the
7435 program counter register) and the memory of the inferior are still
7436 changed as they normally would. Their contents are taken from the
7440 If the record for the next instruction is not in the execution log,
7441 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7442 inferior executes normally, and @value{GDBN} records the execution log
7445 The process record and replay target supports reverse execution
7446 (@pxref{Reverse Execution}), even if the platform on which the
7447 inferior runs does not. However, the reverse execution is limited in
7448 this case by the range of the instructions recorded in the execution
7449 log. In other words, reverse execution on platforms that don't
7450 support it directly can only be done in the replay mode.
7452 When debugging in the reverse direction, @value{GDBN} will work in
7453 replay mode as long as the execution log includes the record for the
7454 previous instruction; otherwise, it will work in record mode, if the
7455 platform supports reverse execution, or stop if not.
7457 Currently, process record and replay is supported on ARM, Aarch64,
7458 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7459 GNU/Linux. Process record and replay can be used both when native
7460 debugging, and when remote debugging via @code{gdbserver}.
7462 For architecture environments that support process record and replay,
7463 @value{GDBN} provides the following commands:
7466 @kindex target record
7467 @kindex target record-full
7468 @kindex target record-btrace
7471 @kindex record btrace
7472 @kindex record btrace bts
7473 @kindex record btrace pt
7479 @kindex rec btrace bts
7480 @kindex rec btrace pt
7483 @item record @var{method}
7484 This command starts the process record and replay target. The
7485 recording method can be specified as parameter. Without a parameter
7486 the command uses the @code{full} recording method. The following
7487 recording methods are available:
7491 Full record/replay recording using @value{GDBN}'s software record and
7492 replay implementation. This method allows replaying and reverse
7495 @item btrace @var{format}
7496 Hardware-supported instruction recording, supported on Intel
7497 processors. This method does not record data. Further, the data is
7498 collected in a ring buffer so old data will be overwritten when the
7499 buffer is full. It allows limited reverse execution. Variables and
7500 registers are not available during reverse execution. In remote
7501 debugging, recording continues on disconnect. Recorded data can be
7502 inspected after reconnecting. The recording may be stopped using
7505 The recording format can be specified as parameter. Without a parameter
7506 the command chooses the recording format. The following recording
7507 formats are available:
7511 @cindex branch trace store
7512 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7513 this format, the processor stores a from/to record for each executed
7514 branch in the btrace ring buffer.
7517 @cindex Intel Processor Trace
7518 Use the @dfn{Intel Processor Trace} recording format. In this
7519 format, the processor stores the execution trace in a compressed form
7520 that is afterwards decoded by @value{GDBN}.
7522 The trace can be recorded with very low overhead. The compressed
7523 trace format also allows small trace buffers to already contain a big
7524 number of instructions compared to @acronym{BTS}.
7526 Decoding the recorded execution trace, on the other hand, is more
7527 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7528 increased number of instructions to process. You should increase the
7529 buffer-size with care.
7532 Not all recording formats may be available on all processors.
7535 The process record and replay target can only debug a process that is
7536 already running. Therefore, you need first to start the process with
7537 the @kbd{run} or @kbd{start} commands, and then start the recording
7538 with the @kbd{record @var{method}} command.
7540 @cindex displaced stepping, and process record and replay
7541 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7542 will be automatically disabled when process record and replay target
7543 is started. That's because the process record and replay target
7544 doesn't support displaced stepping.
7546 @cindex non-stop mode, and process record and replay
7547 @cindex asynchronous execution, and process record and replay
7548 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7549 the asynchronous execution mode (@pxref{Background Execution}), not
7550 all recording methods are available. The @code{full} recording method
7551 does not support these two modes.
7556 Stop the process record and replay target. When process record and
7557 replay target stops, the entire execution log will be deleted and the
7558 inferior will either be terminated, or will remain in its final state.
7560 When you stop the process record and replay target in record mode (at
7561 the end of the execution log), the inferior will be stopped at the
7562 next instruction that would have been recorded. In other words, if
7563 you record for a while and then stop recording, the inferior process
7564 will be left in the same state as if the recording never happened.
7566 On the other hand, if the process record and replay target is stopped
7567 while in replay mode (that is, not at the end of the execution log,
7568 but at some earlier point), the inferior process will become ``live''
7569 at that earlier state, and it will then be possible to continue the
7570 usual ``live'' debugging of the process from that state.
7572 When the inferior process exits, or @value{GDBN} detaches from it,
7573 process record and replay target will automatically stop itself.
7577 Go to a specific location in the execution log. There are several
7578 ways to specify the location to go to:
7581 @item record goto begin
7582 @itemx record goto start
7583 Go to the beginning of the execution log.
7585 @item record goto end
7586 Go to the end of the execution log.
7588 @item record goto @var{n}
7589 Go to instruction number @var{n} in the execution log.
7593 @item record save @var{filename}
7594 Save the execution log to a file @file{@var{filename}}.
7595 Default filename is @file{gdb_record.@var{process_id}}, where
7596 @var{process_id} is the process ID of the inferior.
7598 This command may not be available for all recording methods.
7600 @kindex record restore
7601 @item record restore @var{filename}
7602 Restore the execution log from a file @file{@var{filename}}.
7603 File must have been created with @code{record save}.
7605 @kindex set record full
7606 @item set record full insn-number-max @var{limit}
7607 @itemx set record full insn-number-max unlimited
7608 Set the limit of instructions to be recorded for the @code{full}
7609 recording method. Default value is 200000.
7611 If @var{limit} is a positive number, then @value{GDBN} will start
7612 deleting instructions from the log once the number of the record
7613 instructions becomes greater than @var{limit}. For every new recorded
7614 instruction, @value{GDBN} will delete the earliest recorded
7615 instruction to keep the number of recorded instructions at the limit.
7616 (Since deleting recorded instructions loses information, @value{GDBN}
7617 lets you control what happens when the limit is reached, by means of
7618 the @code{stop-at-limit} option, described below.)
7620 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7621 delete recorded instructions from the execution log. The number of
7622 recorded instructions is limited only by the available memory.
7624 @kindex show record full
7625 @item show record full insn-number-max
7626 Show the limit of instructions to be recorded with the @code{full}
7629 @item set record full stop-at-limit
7630 Control the behavior of the @code{full} recording method when the
7631 number of recorded instructions reaches the limit. If ON (the
7632 default), @value{GDBN} will stop when the limit is reached for the
7633 first time and ask you whether you want to stop the inferior or
7634 continue running it and recording the execution log. If you decide
7635 to continue recording, each new recorded instruction will cause the
7636 oldest one to be deleted.
7638 If this option is OFF, @value{GDBN} will automatically delete the
7639 oldest record to make room for each new one, without asking.
7641 @item show record full stop-at-limit
7642 Show the current setting of @code{stop-at-limit}.
7644 @item set record full memory-query
7645 Control the behavior when @value{GDBN} is unable to record memory
7646 changes caused by an instruction for the @code{full} recording method.
7647 If ON, @value{GDBN} will query whether to stop the inferior in that
7650 If this option is OFF (the default), @value{GDBN} will automatically
7651 ignore the effect of such instructions on memory. Later, when
7652 @value{GDBN} replays this execution log, it will mark the log of this
7653 instruction as not accessible, and it will not affect the replay
7656 @item show record full memory-query
7657 Show the current setting of @code{memory-query}.
7659 @kindex set record btrace
7660 The @code{btrace} record target does not trace data. As a
7661 convenience, when replaying, @value{GDBN} reads read-only memory off
7662 the live program directly, assuming that the addresses of the
7663 read-only areas don't change. This for example makes it possible to
7664 disassemble code while replaying, but not to print variables.
7665 In some cases, being able to inspect variables might be useful.
7666 You can use the following command for that:
7668 @item set record btrace replay-memory-access
7669 Control the behavior of the @code{btrace} recording method when
7670 accessing memory during replay. If @code{read-only} (the default),
7671 @value{GDBN} will only allow accesses to read-only memory.
7672 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7673 and to read-write memory. Beware that the accessed memory corresponds
7674 to the live target and not necessarily to the current replay
7677 @item set record btrace cpu @var{identifier}
7678 Set the processor to be used for enabling workarounds for processor
7679 errata when decoding the trace.
7681 Processor errata are defects in processor operation, caused by its
7682 design or manufacture. They can cause a trace not to match the
7683 specification. This, in turn, may cause trace decode to fail.
7684 @value{GDBN} can detect erroneous trace packets and correct them, thus
7685 avoiding the decoding failures. These corrections are known as
7686 @dfn{errata workarounds}, and are enabled based on the processor on
7687 which the trace was recorded.
7689 By default, @value{GDBN} attempts to detect the processor
7690 automatically, and apply the necessary workarounds for it. However,
7691 you may need to specify the processor if @value{GDBN} does not yet
7692 support it. This command allows you to do that, and also allows to
7693 disable the workarounds.
7695 The argument @var{identifier} identifies the @sc{cpu} and is of the
7696 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7697 there are two special identifiers, @code{none} and @code{auto}
7700 The following vendor identifiers and corresponding processor
7701 identifiers are currently supported:
7703 @multitable @columnfractions .1 .9
7706 @tab @var{family}/@var{model}[/@var{stepping}]
7710 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7711 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7713 If @var{identifier} is @code{auto}, enable errata workarounds for the
7714 processor on which the trace was recorded. If @var{identifier} is
7715 @code{none}, errata workarounds are disabled.
7717 For example, when using an old @value{GDBN} on a new system, decode
7718 may fail because @value{GDBN} does not support the new processor. It
7719 often suffices to specify an older processor that @value{GDBN}
7724 Active record target: record-btrace
7725 Recording format: Intel Processor Trace.
7727 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7728 (gdb) set record btrace cpu intel:6/158
7730 Active record target: record-btrace
7731 Recording format: Intel Processor Trace.
7733 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7736 @kindex show record btrace
7737 @item show record btrace replay-memory-access
7738 Show the current setting of @code{replay-memory-access}.
7740 @item show record btrace cpu
7741 Show the processor to be used for enabling trace decode errata
7744 @kindex set record btrace bts
7745 @item set record btrace bts buffer-size @var{size}
7746 @itemx set record btrace bts buffer-size unlimited
7747 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7748 format. Default is 64KB.
7750 If @var{size} is a positive number, then @value{GDBN} will try to
7751 allocate a buffer of at least @var{size} bytes for each new thread
7752 that uses the btrace recording method and the @acronym{BTS} format.
7753 The actually obtained buffer size may differ from the requested
7754 @var{size}. Use the @code{info record} command to see the actual
7755 buffer size for each thread that uses the btrace recording method and
7756 the @acronym{BTS} format.
7758 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7759 allocate a buffer of 4MB.
7761 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7762 also need longer to process the branch trace data before it can be used.
7764 @item show record btrace bts buffer-size @var{size}
7765 Show the current setting of the requested ring buffer size for branch
7766 tracing in @acronym{BTS} format.
7768 @kindex set record btrace pt
7769 @item set record btrace pt buffer-size @var{size}
7770 @itemx set record btrace pt buffer-size unlimited
7771 Set the requested ring buffer size for branch tracing in Intel
7772 Processor Trace format. Default is 16KB.
7774 If @var{size} is a positive number, then @value{GDBN} will try to
7775 allocate a buffer of at least @var{size} bytes for each new thread
7776 that uses the btrace recording method and the Intel Processor Trace
7777 format. The actually obtained buffer size may differ from the
7778 requested @var{size}. Use the @code{info record} command to see the
7779 actual buffer size for each thread.
7781 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7782 allocate a buffer of 4MB.
7784 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7785 also need longer to process the branch trace data before it can be used.
7787 @item show record btrace pt buffer-size @var{size}
7788 Show the current setting of the requested ring buffer size for branch
7789 tracing in Intel Processor Trace format.
7793 Show various statistics about the recording depending on the recording
7798 For the @code{full} recording method, it shows the state of process
7799 record and its in-memory execution log buffer, including:
7803 Whether in record mode or replay mode.
7805 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7807 Highest recorded instruction number.
7809 Current instruction about to be replayed (if in replay mode).
7811 Number of instructions contained in the execution log.
7813 Maximum number of instructions that may be contained in the execution log.
7817 For the @code{btrace} recording method, it shows:
7823 Number of instructions that have been recorded.
7825 Number of blocks of sequential control-flow formed by the recorded
7828 Whether in record mode or replay mode.
7831 For the @code{bts} recording format, it also shows:
7834 Size of the perf ring buffer.
7837 For the @code{pt} recording format, it also shows:
7840 Size of the perf ring buffer.
7844 @kindex record delete
7847 When record target runs in replay mode (``in the past''), delete the
7848 subsequent execution log and begin to record a new execution log starting
7849 from the current address. This means you will abandon the previously
7850 recorded ``future'' and begin recording a new ``future''.
7852 @kindex record instruction-history
7853 @kindex rec instruction-history
7854 @item record instruction-history
7855 Disassembles instructions from the recorded execution log. By
7856 default, ten instructions are disassembled. This can be changed using
7857 the @code{set record instruction-history-size} command. Instructions
7858 are printed in execution order.
7860 It can also print mixed source+disassembly if you specify the the
7861 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7862 as well as in symbolic form by specifying the @code{/r} modifier.
7864 The current position marker is printed for the instruction at the
7865 current program counter value. This instruction can appear multiple
7866 times in the trace and the current position marker will be printed
7867 every time. To omit the current position marker, specify the
7870 To better align the printed instructions when the trace contains
7871 instructions from more than one function, the function name may be
7872 omitted by specifying the @code{/f} modifier.
7874 Speculatively executed instructions are prefixed with @samp{?}. This
7875 feature is not available for all recording formats.
7877 There are several ways to specify what part of the execution log to
7881 @item record instruction-history @var{insn}
7882 Disassembles ten instructions starting from instruction number
7885 @item record instruction-history @var{insn}, +/-@var{n}
7886 Disassembles @var{n} instructions around instruction number
7887 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7888 @var{n} instructions after instruction number @var{insn}. If
7889 @var{n} is preceded with @code{-}, disassembles @var{n}
7890 instructions before instruction number @var{insn}.
7892 @item record instruction-history
7893 Disassembles ten more instructions after the last disassembly.
7895 @item record instruction-history -
7896 Disassembles ten more instructions before the last disassembly.
7898 @item record instruction-history @var{begin}, @var{end}
7899 Disassembles instructions beginning with instruction number
7900 @var{begin} until instruction number @var{end}. The instruction
7901 number @var{end} is included.
7904 This command may not be available for all recording methods.
7907 @item set record instruction-history-size @var{size}
7908 @itemx set record instruction-history-size unlimited
7909 Define how many instructions to disassemble in the @code{record
7910 instruction-history} command. The default value is 10.
7911 A @var{size} of @code{unlimited} means unlimited instructions.
7914 @item show record instruction-history-size
7915 Show how many instructions to disassemble in the @code{record
7916 instruction-history} command.
7918 @kindex record function-call-history
7919 @kindex rec function-call-history
7920 @item record function-call-history
7921 Prints the execution history at function granularity. It prints one
7922 line for each sequence of instructions that belong to the same
7923 function giving the name of that function, the source lines
7924 for this instruction sequence (if the @code{/l} modifier is
7925 specified), and the instructions numbers that form the sequence (if
7926 the @code{/i} modifier is specified). The function names are indented
7927 to reflect the call stack depth if the @code{/c} modifier is
7928 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7932 (@value{GDBP}) @b{list 1, 10}
7943 (@value{GDBP}) @b{record function-call-history /ilc}
7944 1 bar inst 1,4 at foo.c:6,8
7945 2 foo inst 5,10 at foo.c:2,3
7946 3 bar inst 11,13 at foo.c:9,10
7949 By default, ten lines are printed. This can be changed using the
7950 @code{set record function-call-history-size} command. Functions are
7951 printed in execution order. There are several ways to specify what
7955 @item record function-call-history @var{func}
7956 Prints ten functions starting from function number @var{func}.
7958 @item record function-call-history @var{func}, +/-@var{n}
7959 Prints @var{n} functions around function number @var{func}. If
7960 @var{n} is preceded with @code{+}, prints @var{n} functions after
7961 function number @var{func}. If @var{n} is preceded with @code{-},
7962 prints @var{n} functions before function number @var{func}.
7964 @item record function-call-history
7965 Prints ten more functions after the last ten-line print.
7967 @item record function-call-history -
7968 Prints ten more functions before the last ten-line print.
7970 @item record function-call-history @var{begin}, @var{end}
7971 Prints functions beginning with function number @var{begin} until
7972 function number @var{end}. The function number @var{end} is included.
7975 This command may not be available for all recording methods.
7977 @item set record function-call-history-size @var{size}
7978 @itemx set record function-call-history-size unlimited
7979 Define how many lines to print in the
7980 @code{record function-call-history} command. The default value is 10.
7981 A size of @code{unlimited} means unlimited lines.
7983 @item show record function-call-history-size
7984 Show how many lines to print in the
7985 @code{record function-call-history} command.
7990 @chapter Examining the Stack
7992 When your program has stopped, the first thing you need to know is where it
7993 stopped and how it got there.
7996 Each time your program performs a function call, information about the call
7998 That information includes the location of the call in your program,
7999 the arguments of the call,
8000 and the local variables of the function being called.
8001 The information is saved in a block of data called a @dfn{stack frame}.
8002 The stack frames are allocated in a region of memory called the @dfn{call
8005 When your program stops, the @value{GDBN} commands for examining the
8006 stack allow you to see all of this information.
8008 @cindex selected frame
8009 One of the stack frames is @dfn{selected} by @value{GDBN} and many
8010 @value{GDBN} commands refer implicitly to the selected frame. In
8011 particular, whenever you ask @value{GDBN} for the value of a variable in
8012 your program, the value is found in the selected frame. There are
8013 special @value{GDBN} commands to select whichever frame you are
8014 interested in. @xref{Selection, ,Selecting a Frame}.
8016 When your program stops, @value{GDBN} automatically selects the
8017 currently executing frame and describes it briefly, similar to the
8018 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
8021 * Frames:: Stack frames
8022 * Backtrace:: Backtraces
8023 * Selection:: Selecting a frame
8024 * Frame Info:: Information on a frame
8025 * Frame Apply:: Applying a command to several frames
8026 * Frame Filter Management:: Managing frame filters
8031 @section Stack Frames
8033 @cindex frame, definition
8035 The call stack is divided up into contiguous pieces called @dfn{stack
8036 frames}, or @dfn{frames} for short; each frame is the data associated
8037 with one call to one function. The frame contains the arguments given
8038 to the function, the function's local variables, and the address at
8039 which the function is executing.
8041 @cindex initial frame
8042 @cindex outermost frame
8043 @cindex innermost frame
8044 When your program is started, the stack has only one frame, that of the
8045 function @code{main}. This is called the @dfn{initial} frame or the
8046 @dfn{outermost} frame. Each time a function is called, a new frame is
8047 made. Each time a function returns, the frame for that function invocation
8048 is eliminated. If a function is recursive, there can be many frames for
8049 the same function. The frame for the function in which execution is
8050 actually occurring is called the @dfn{innermost} frame. This is the most
8051 recently created of all the stack frames that still exist.
8053 @cindex frame pointer
8054 Inside your program, stack frames are identified by their addresses. A
8055 stack frame consists of many bytes, each of which has its own address; each
8056 kind of computer has a convention for choosing one byte whose
8057 address serves as the address of the frame. Usually this address is kept
8058 in a register called the @dfn{frame pointer register}
8059 (@pxref{Registers, $fp}) while execution is going on in that frame.
8062 @cindex frame number
8063 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8064 number that is zero for the innermost frame, one for the frame that
8065 called it, and so on upward. These level numbers give you a way of
8066 designating stack frames in @value{GDBN} commands. The terms
8067 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8068 describe this number.
8070 @c The -fomit-frame-pointer below perennially causes hbox overflow
8071 @c underflow problems.
8072 @cindex frameless execution
8073 Some compilers provide a way to compile functions so that they operate
8074 without stack frames. (For example, the @value{NGCC} option
8076 @samp{-fomit-frame-pointer}
8078 generates functions without a frame.)
8079 This is occasionally done with heavily used library functions to save
8080 the frame setup time. @value{GDBN} has limited facilities for dealing
8081 with these function invocations. If the innermost function invocation
8082 has no stack frame, @value{GDBN} nevertheless regards it as though
8083 it had a separate frame, which is numbered zero as usual, allowing
8084 correct tracing of the function call chain. However, @value{GDBN} has
8085 no provision for frameless functions elsewhere in the stack.
8091 @cindex call stack traces
8092 A backtrace is a summary of how your program got where it is. It shows one
8093 line per frame, for many frames, starting with the currently executing
8094 frame (frame zero), followed by its caller (frame one), and on up the
8097 @anchor{backtrace-command}
8099 @kindex bt @r{(@code{backtrace})}
8100 To print a backtrace of the entire stack, use the @code{backtrace}
8101 command, or its alias @code{bt}. This command will print one line per
8102 frame for frames in the stack. By default, all stack frames are
8103 printed. You can stop the backtrace at any time by typing the system
8104 interrupt character, normally @kbd{Ctrl-c}.
8107 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8108 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8109 Print the backtrace of the entire stack.
8111 The optional @var{count} can be one of the following:
8116 Print only the innermost @var{n} frames, where @var{n} is a positive
8121 Print only the outermost @var{n} frames, where @var{n} is a positive
8129 Print the values of the local variables also. This can be combined
8130 with the optional @var{count} to limit the number of frames shown.
8133 Do not run Python frame filters on this backtrace. @xref{Frame
8134 Filter API}, for more information. Additionally use @ref{disable
8135 frame-filter all} to turn off all frame filters. This is only
8136 relevant when @value{GDBN} has been configured with @code{Python}
8140 A Python frame filter might decide to ``elide'' some frames. Normally
8141 such elided frames are still printed, but they are indented relative
8142 to the filtered frames that cause them to be elided. The @code{-hide}
8143 option causes elided frames to not be printed at all.
8146 The @code{backtrace} command also supports a number of options that
8147 allow overriding relevant global print settings as set by @code{set
8148 backtrace} and @code{set print} subcommands:
8151 @item -past-main [@code{on}|@code{off}]
8152 Set whether backtraces should continue past @code{main}. Related setting:
8153 @ref{set backtrace past-main}.
8155 @item -past-entry [@code{on}|@code{off}]
8156 Set whether backtraces should continue past the entry point of a program.
8157 Related setting: @ref{set backtrace past-entry}.
8159 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8160 Set printing of function arguments at function entry.
8161 Related setting: @ref{set print entry-values}.
8163 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8164 Set printing of non-scalar frame arguments.
8165 Related setting: @ref{set print frame-arguments}.
8167 @item -raw-frame-arguments [@code{on}|@code{off}]
8168 Set whether to print frame arguments in raw form.
8169 Related setting: @ref{set print raw-frame-arguments}.
8171 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8172 Set printing of frame information.
8173 Related setting: @ref{set print frame-info}.
8176 The optional @var{qualifier} is maintained for backward compatibility.
8177 It can be one of the following:
8181 Equivalent to the @code{-full} option.
8184 Equivalent to the @code{-no-filters} option.
8187 Equivalent to the @code{-hide} option.
8194 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8195 are additional aliases for @code{backtrace}.
8197 @cindex multiple threads, backtrace
8198 In a multi-threaded program, @value{GDBN} by default shows the
8199 backtrace only for the current thread. To display the backtrace for
8200 several or all of the threads, use the command @code{thread apply}
8201 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8202 apply all backtrace}, @value{GDBN} will display the backtrace for all
8203 the threads; this is handy when you debug a core dump of a
8204 multi-threaded program.
8206 Each line in the backtrace shows the frame number and the function name.
8207 The program counter value is also shown---unless you use @code{set
8208 print address off}. The backtrace also shows the source file name and
8209 line number, as well as the arguments to the function. The program
8210 counter value is omitted if it is at the beginning of the code for that
8213 Here is an example of a backtrace. It was made with the command
8214 @samp{bt 3}, so it shows the innermost three frames.
8218 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8220 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8221 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8223 (More stack frames follow...)
8228 The display for frame zero does not begin with a program counter
8229 value, indicating that your program has stopped at the beginning of the
8230 code for line @code{993} of @code{builtin.c}.
8233 The value of parameter @code{data} in frame 1 has been replaced by
8234 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8235 only if it is a scalar (integer, pointer, enumeration, etc). See command
8236 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8237 on how to configure the way function parameter values are printed.
8238 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8239 what frame information is printed.
8241 @cindex optimized out, in backtrace
8242 @cindex function call arguments, optimized out
8243 If your program was compiled with optimizations, some compilers will
8244 optimize away arguments passed to functions if those arguments are
8245 never used after the call. Such optimizations generate code that
8246 passes arguments through registers, but doesn't store those arguments
8247 in the stack frame. @value{GDBN} has no way of displaying such
8248 arguments in stack frames other than the innermost one. Here's what
8249 such a backtrace might look like:
8253 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8255 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8256 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8258 (More stack frames follow...)
8263 The values of arguments that were not saved in their stack frames are
8264 shown as @samp{<optimized out>}.
8266 If you need to display the values of such optimized-out arguments,
8267 either deduce that from other variables whose values depend on the one
8268 you are interested in, or recompile without optimizations.
8270 @cindex backtrace beyond @code{main} function
8271 @cindex program entry point
8272 @cindex startup code, and backtrace
8273 Most programs have a standard user entry point---a place where system
8274 libraries and startup code transition into user code. For C this is
8275 @code{main}@footnote{
8276 Note that embedded programs (the so-called ``free-standing''
8277 environment) are not required to have a @code{main} function as the
8278 entry point. They could even have multiple entry points.}.
8279 When @value{GDBN} finds the entry function in a backtrace
8280 it will terminate the backtrace, to avoid tracing into highly
8281 system-specific (and generally uninteresting) code.
8283 If you need to examine the startup code, or limit the number of levels
8284 in a backtrace, you can change this behavior:
8287 @item set backtrace past-main
8288 @itemx set backtrace past-main on
8289 @anchor{set backtrace past-main}
8290 @kindex set backtrace
8291 Backtraces will continue past the user entry point.
8293 @item set backtrace past-main off
8294 Backtraces will stop when they encounter the user entry point. This is the
8297 @item show backtrace past-main
8298 @kindex show backtrace
8299 Display the current user entry point backtrace policy.
8301 @item set backtrace past-entry
8302 @itemx set backtrace past-entry on
8303 @anchor{set backtrace past-entry}
8304 Backtraces will continue past the internal entry point of an application.
8305 This entry point is encoded by the linker when the application is built,
8306 and is likely before the user entry point @code{main} (or equivalent) is called.
8308 @item set backtrace past-entry off
8309 Backtraces will stop when they encounter the internal entry point of an
8310 application. This is the default.
8312 @item show backtrace past-entry
8313 Display the current internal entry point backtrace policy.
8315 @item set backtrace limit @var{n}
8316 @itemx set backtrace limit 0
8317 @itemx set backtrace limit unlimited
8318 @anchor{set backtrace limit}
8319 @cindex backtrace limit
8320 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8321 or zero means unlimited levels.
8323 @item show backtrace limit
8324 Display the current limit on backtrace levels.
8327 You can control how file names are displayed.
8330 @item set filename-display
8331 @itemx set filename-display relative
8332 @cindex filename-display
8333 Display file names relative to the compilation directory. This is the default.
8335 @item set filename-display basename
8336 Display only basename of a filename.
8338 @item set filename-display absolute
8339 Display an absolute filename.
8341 @item show filename-display
8342 Show the current way to display filenames.
8346 @section Selecting a Frame
8348 Most commands for examining the stack and other data in your program work on
8349 whichever stack frame is selected at the moment. Here are the commands for
8350 selecting a stack frame; all of them finish by printing a brief description
8351 of the stack frame just selected.
8354 @kindex frame@r{, selecting}
8355 @kindex f @r{(@code{frame})}
8356 @item frame @r{[} @var{frame-selection-spec} @r{]}
8357 @item f @r{[} @var{frame-selection-spec} @r{]}
8358 The @command{frame} command allows different stack frames to be
8359 selected. The @var{frame-selection-spec} can be any of the following:
8364 @item level @var{num}
8365 Select frame level @var{num}. Recall that frame zero is the innermost
8366 (currently executing) frame, frame one is the frame that called the
8367 innermost one, and so on. The highest level frame is usually the one
8370 As this is the most common method of navigating the frame stack, the
8371 string @command{level} can be omitted. For example, the following two
8372 commands are equivalent:
8375 (@value{GDBP}) frame 3
8376 (@value{GDBP}) frame level 3
8379 @kindex frame address
8380 @item address @var{stack-address}
8381 Select the frame with stack address @var{stack-address}. The
8382 @var{stack-address} for a frame can be seen in the output of
8383 @command{info frame}, for example:
8387 Stack level 1, frame at 0x7fffffffda30:
8388 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8389 tail call frame, caller of frame at 0x7fffffffda30
8390 source language c++.
8391 Arglist at unknown address.
8392 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8395 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8396 indicated by the line:
8399 Stack level 1, frame at 0x7fffffffda30:
8402 @kindex frame function
8403 @item function @var{function-name}
8404 Select the stack frame for function @var{function-name}. If there are
8405 multiple stack frames for function @var{function-name} then the inner
8406 most stack frame is selected.
8409 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8410 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8411 viewed has stack address @var{stack-addr}, and optionally, a program
8412 counter address of @var{pc-addr}.
8414 This is useful mainly if the chaining of stack frames has been
8415 damaged by a bug, making it impossible for @value{GDBN} to assign
8416 numbers properly to all frames. In addition, this can be useful
8417 when your program has multiple stacks and switches between them.
8419 When viewing a frame outside the current backtrace using
8420 @command{frame view} then you can always return to the original
8421 stack using one of the previous stack frame selection instructions,
8422 for example @command{frame level 0}.
8428 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8429 numbers @var{n}, this advances toward the outermost frame, to higher
8430 frame numbers, to frames that have existed longer.
8433 @kindex do @r{(@code{down})}
8435 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8436 positive numbers @var{n}, this advances toward the innermost frame, to
8437 lower frame numbers, to frames that were created more recently.
8438 You may abbreviate @code{down} as @code{do}.
8441 All of these commands end by printing two lines of output describing the
8442 frame. The first line shows the frame number, the function name, the
8443 arguments, and the source file and line number of execution in that
8444 frame. The second line shows the text of that source line.
8452 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8454 10 read_input_file (argv[i]);
8458 After such a printout, the @code{list} command with no arguments
8459 prints ten lines centered on the point of execution in the frame.
8460 You can also edit the program at the point of execution with your favorite
8461 editing program by typing @code{edit}.
8462 @xref{List, ,Printing Source Lines},
8466 @kindex select-frame
8467 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8468 The @code{select-frame} command is a variant of @code{frame} that does
8469 not display the new frame after selecting it. This command is
8470 intended primarily for use in @value{GDBN} command scripts, where the
8471 output might be unnecessary and distracting. The
8472 @var{frame-selection-spec} is as for the @command{frame} command
8473 described in @ref{Selection, ,Selecting a Frame}.
8475 @kindex down-silently
8477 @item up-silently @var{n}
8478 @itemx down-silently @var{n}
8479 These two commands are variants of @code{up} and @code{down},
8480 respectively; they differ in that they do their work silently, without
8481 causing display of the new frame. They are intended primarily for use
8482 in @value{GDBN} command scripts, where the output might be unnecessary and
8487 @section Information About a Frame
8489 There are several other commands to print information about the selected
8495 When used without any argument, this command does not change which
8496 frame is selected, but prints a brief description of the currently
8497 selected stack frame. It can be abbreviated @code{f}. With an
8498 argument, this command is used to select a stack frame.
8499 @xref{Selection, ,Selecting a Frame}.
8502 @kindex info f @r{(@code{info frame})}
8505 This command prints a verbose description of the selected stack frame,
8510 the address of the frame
8512 the address of the next frame down (called by this frame)
8514 the address of the next frame up (caller of this frame)
8516 the language in which the source code corresponding to this frame is written
8518 the address of the frame's arguments
8520 the address of the frame's local variables
8522 the program counter saved in it (the address of execution in the caller frame)
8524 which registers were saved in the frame
8527 @noindent The verbose description is useful when
8528 something has gone wrong that has made the stack format fail to fit
8529 the usual conventions.
8531 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8532 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8533 Print a verbose description of the frame selected by
8534 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8535 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8536 a Frame}). The selected frame remains unchanged by this command.
8539 @item info args [-q]
8540 Print the arguments of the selected frame, each on a separate line.
8542 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8543 printing header information and messages explaining why no argument
8546 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8547 Like @kbd{info args}, but only print the arguments selected
8548 with the provided regexp(s).
8550 If @var{regexp} is provided, print only the arguments whose names
8551 match the regular expression @var{regexp}.
8553 If @var{type_regexp} is provided, print only the arguments whose
8554 types, as printed by the @code{whatis} command, match
8555 the regular expression @var{type_regexp}.
8556 If @var{type_regexp} contains space(s), it should be enclosed in
8557 quote characters. If needed, use backslash to escape the meaning
8558 of special characters or quotes.
8560 If both @var{regexp} and @var{type_regexp} are provided, an argument
8561 is printed only if its name matches @var{regexp} and its type matches
8564 @item info locals [-q]
8566 Print the local variables of the selected frame, each on a separate
8567 line. These are all variables (declared either static or automatic)
8568 accessible at the point of execution of the selected frame.
8570 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8571 printing header information and messages explaining why no local variables
8574 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8575 Like @kbd{info locals}, but only print the local variables selected
8576 with the provided regexp(s).
8578 If @var{regexp} is provided, print only the local variables whose names
8579 match the regular expression @var{regexp}.
8581 If @var{type_regexp} is provided, print only the local variables whose
8582 types, as printed by the @code{whatis} command, match
8583 the regular expression @var{type_regexp}.
8584 If @var{type_regexp} contains space(s), it should be enclosed in
8585 quote characters. If needed, use backslash to escape the meaning
8586 of special characters or quotes.
8588 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8589 is printed only if its name matches @var{regexp} and its type matches
8592 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8593 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8594 For example, your program might use Resource Acquisition Is
8595 Initialization types (RAII) such as @code{lock_something_t}: each
8596 local variable of type @code{lock_something_t} automatically places a
8597 lock that is destroyed when the variable goes out of scope. You can
8598 then list all acquired locks in your program by doing
8600 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8603 or the equivalent shorter form
8605 tfaas i lo -q -t lock_something_t
8611 @section Applying a Command to Several Frames.
8613 @cindex apply command to several frames
8615 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8616 The @code{frame apply} command allows you to apply the named
8617 @var{command} to one or more frames.
8621 Specify @code{all} to apply @var{command} to all frames.
8624 Use @var{count} to apply @var{command} to the innermost @var{count}
8625 frames, where @var{count} is a positive number.
8628 Use @var{-count} to apply @var{command} to the outermost @var{count}
8629 frames, where @var{count} is a positive number.
8632 Use @code{level} to apply @var{command} to the set of frames identified
8633 by the @var{level} list. @var{level} is a frame level or a range of frame
8634 levels as @var{level1}-@var{level2}. The frame level is the number shown
8635 in the first field of the @samp{backtrace} command output.
8636 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8637 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8641 Note that the frames on which @code{frame apply} applies a command are
8642 also influenced by the @code{set backtrace} settings such as @code{set
8643 backtrace past-main} and @code{set backtrace limit N}.
8644 @xref{Backtrace,,Backtraces}.
8646 The @code{frame apply} command also supports a number of options that
8647 allow overriding relevant @code{set backtrace} settings:
8650 @item -past-main [@code{on}|@code{off}]
8651 Whether backtraces should continue past @code{main}.
8652 Related setting: @ref{set backtrace past-main}.
8654 @item -past-entry [@code{on}|@code{off}]
8655 Whether backtraces should continue past the entry point of a program.
8656 Related setting: @ref{set backtrace past-entry}.
8659 By default, @value{GDBN} displays some frame information before the
8660 output produced by @var{command}, and an error raised during the
8661 execution of a @var{command} will abort @code{frame apply}. The
8662 following options can be used to fine-tune these behaviors:
8666 The flag @code{-c}, which stands for @samp{continue}, causes any
8667 errors in @var{command} to be displayed, and the execution of
8668 @code{frame apply} then continues.
8670 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8671 or empty output produced by a @var{command} to be silently ignored.
8672 That is, the execution continues, but the frame information and errors
8675 The flag @code{-q} (@samp{quiet}) disables printing the frame
8679 The following example shows how the flags @code{-c} and @code{-s} are
8680 working when applying the command @code{p j} to all frames, where
8681 variable @code{j} can only be successfully printed in the outermost
8682 @code{#1 main} frame.
8686 (gdb) frame apply all p j
8687 #0 some_function (i=5) at fun.c:4
8688 No symbol "j" in current context.
8689 (gdb) frame apply all -c p j
8690 #0 some_function (i=5) at fun.c:4
8691 No symbol "j" in current context.
8692 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8694 (gdb) frame apply all -s p j
8695 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8701 By default, @samp{frame apply}, prints the frame location
8702 information before the command output:
8706 (gdb) frame apply all p $sp
8707 #0 some_function (i=5) at fun.c:4
8708 $4 = (void *) 0xffffd1e0
8709 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8710 $5 = (void *) 0xffffd1f0
8715 If the flag @code{-q} is given, no frame information is printed:
8718 (gdb) frame apply all -q p $sp
8719 $12 = (void *) 0xffffd1e0
8720 $13 = (void *) 0xffffd1f0
8730 @cindex apply a command to all frames (ignoring errors and empty output)
8731 @item faas @var{command}
8732 Shortcut for @code{frame apply all -s @var{command}}.
8733 Applies @var{command} on all frames, ignoring errors and empty output.
8735 It can for example be used to print a local variable or a function
8736 argument without knowing the frame where this variable or argument
8739 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8742 The @code{faas} command accepts the same options as the @code{frame
8743 apply} command. @xref{Frame Apply,,frame apply}.
8745 Note that the command @code{tfaas @var{command}} applies @var{command}
8746 on all frames of all threads. See @xref{Threads,,Threads}.
8750 @node Frame Filter Management
8751 @section Management of Frame Filters.
8752 @cindex managing frame filters
8754 Frame filters are Python based utilities to manage and decorate the
8755 output of frames. @xref{Frame Filter API}, for further information.
8757 Managing frame filters is performed by several commands available
8758 within @value{GDBN}, detailed here.
8761 @kindex info frame-filter
8762 @item info frame-filter
8763 Print a list of installed frame filters from all dictionaries, showing
8764 their name, priority and enabled status.
8766 @kindex disable frame-filter
8767 @anchor{disable frame-filter all}
8768 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8769 Disable a frame filter in the dictionary matching
8770 @var{filter-dictionary} and @var{filter-name}. The
8771 @var{filter-dictionary} may be @code{all}, @code{global},
8772 @code{progspace}, or the name of the object file where the frame filter
8773 dictionary resides. When @code{all} is specified, all frame filters
8774 across all dictionaries are disabled. The @var{filter-name} is the name
8775 of the frame filter and is used when @code{all} is not the option for
8776 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8777 may be enabled again later.
8779 @kindex enable frame-filter
8780 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8781 Enable a frame filter in the dictionary matching
8782 @var{filter-dictionary} and @var{filter-name}. The
8783 @var{filter-dictionary} may be @code{all}, @code{global},
8784 @code{progspace} or the name of the object file where the frame filter
8785 dictionary resides. When @code{all} is specified, all frame filters across
8786 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8787 filter and is used when @code{all} is not the option for
8788 @var{filter-dictionary}.
8793 (gdb) info frame-filter
8795 global frame-filters:
8796 Priority Enabled Name
8797 1000 No PrimaryFunctionFilter
8800 progspace /build/test frame-filters:
8801 Priority Enabled Name
8802 100 Yes ProgspaceFilter
8804 objfile /build/test frame-filters:
8805 Priority Enabled Name
8806 999 Yes BuildProgramFilter
8808 (gdb) disable frame-filter /build/test BuildProgramFilter
8809 (gdb) info frame-filter
8811 global frame-filters:
8812 Priority Enabled Name
8813 1000 No PrimaryFunctionFilter
8816 progspace /build/test frame-filters:
8817 Priority Enabled Name
8818 100 Yes ProgspaceFilter
8820 objfile /build/test frame-filters:
8821 Priority Enabled Name
8822 999 No BuildProgramFilter
8824 (gdb) enable frame-filter global PrimaryFunctionFilter
8825 (gdb) info frame-filter
8827 global frame-filters:
8828 Priority Enabled Name
8829 1000 Yes PrimaryFunctionFilter
8832 progspace /build/test frame-filters:
8833 Priority Enabled Name
8834 100 Yes ProgspaceFilter
8836 objfile /build/test frame-filters:
8837 Priority Enabled Name
8838 999 No BuildProgramFilter
8841 @kindex set frame-filter priority
8842 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8843 Set the @var{priority} of a frame filter in the dictionary matching
8844 @var{filter-dictionary}, and the frame filter name matching
8845 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8846 @code{progspace} or the name of the object file where the frame filter
8847 dictionary resides. The @var{priority} is an integer.
8849 @kindex show frame-filter priority
8850 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8851 Show the @var{priority} of a frame filter in the dictionary matching
8852 @var{filter-dictionary}, and the frame filter name matching
8853 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8854 @code{progspace} or the name of the object file where the frame filter
8860 (gdb) info frame-filter
8862 global frame-filters:
8863 Priority Enabled Name
8864 1000 Yes PrimaryFunctionFilter
8867 progspace /build/test frame-filters:
8868 Priority Enabled Name
8869 100 Yes ProgspaceFilter
8871 objfile /build/test frame-filters:
8872 Priority Enabled Name
8873 999 No BuildProgramFilter
8875 (gdb) set frame-filter priority global Reverse 50
8876 (gdb) info frame-filter
8878 global frame-filters:
8879 Priority Enabled Name
8880 1000 Yes PrimaryFunctionFilter
8883 progspace /build/test frame-filters:
8884 Priority Enabled Name
8885 100 Yes ProgspaceFilter
8887 objfile /build/test frame-filters:
8888 Priority Enabled Name
8889 999 No BuildProgramFilter
8894 @chapter Examining Source Files
8896 @value{GDBN} can print parts of your program's source, since the debugging
8897 information recorded in the program tells @value{GDBN} what source files were
8898 used to build it. When your program stops, @value{GDBN} spontaneously prints
8899 the line where it stopped. Likewise, when you select a stack frame
8900 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8901 execution in that frame has stopped. You can print other portions of
8902 source files by explicit command.
8904 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8905 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8906 @value{GDBN} under @sc{gnu} Emacs}.
8909 * List:: Printing source lines
8910 * Specify Location:: How to specify code locations
8911 * Edit:: Editing source files
8912 * Search:: Searching source files
8913 * Source Path:: Specifying source directories
8914 * Machine Code:: Source and machine code
8918 @section Printing Source Lines
8921 @kindex l @r{(@code{list})}
8922 To print lines from a source file, use the @code{list} command
8923 (abbreviated @code{l}). By default, ten lines are printed.
8924 There are several ways to specify what part of the file you want to
8925 print; see @ref{Specify Location}, for the full list.
8927 Here are the forms of the @code{list} command most commonly used:
8930 @item list @var{linenum}
8931 Print lines centered around line number @var{linenum} in the
8932 current source file.
8934 @item list @var{function}
8935 Print lines centered around the beginning of function
8939 Print more lines. If the last lines printed were printed with a
8940 @code{list} command, this prints lines following the last lines
8941 printed; however, if the last line printed was a solitary line printed
8942 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8943 Stack}), this prints lines centered around that line.
8946 Print lines just before the lines last printed.
8949 @cindex @code{list}, how many lines to display
8950 By default, @value{GDBN} prints ten source lines with any of these forms of
8951 the @code{list} command. You can change this using @code{set listsize}:
8954 @kindex set listsize
8955 @item set listsize @var{count}
8956 @itemx set listsize unlimited
8957 Make the @code{list} command display @var{count} source lines (unless
8958 the @code{list} argument explicitly specifies some other number).
8959 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8961 @kindex show listsize
8963 Display the number of lines that @code{list} prints.
8966 Repeating a @code{list} command with @key{RET} discards the argument,
8967 so it is equivalent to typing just @code{list}. This is more useful
8968 than listing the same lines again. An exception is made for an
8969 argument of @samp{-}; that argument is preserved in repetition so that
8970 each repetition moves up in the source file.
8972 In general, the @code{list} command expects you to supply zero, one or two
8973 @dfn{locations}. Locations specify source lines; there are several ways
8974 of writing them (@pxref{Specify Location}), but the effect is always
8975 to specify some source line.
8977 Here is a complete description of the possible arguments for @code{list}:
8980 @item list @var{location}
8981 Print lines centered around the line specified by @var{location}.
8983 @item list @var{first},@var{last}
8984 Print lines from @var{first} to @var{last}. Both arguments are
8985 locations. When a @code{list} command has two locations, and the
8986 source file of the second location is omitted, this refers to
8987 the same source file as the first location.
8989 @item list ,@var{last}
8990 Print lines ending with @var{last}.
8992 @item list @var{first},
8993 Print lines starting with @var{first}.
8996 Print lines just after the lines last printed.
8999 Print lines just before the lines last printed.
9002 As described in the preceding table.
9005 @node Specify Location
9006 @section Specifying a Location
9007 @cindex specifying location
9009 @cindex source location
9011 Several @value{GDBN} commands accept arguments that specify a location
9012 of your program's code. Since @value{GDBN} is a source-level
9013 debugger, a location usually specifies some line in the source code.
9014 Locations may be specified using three different formats:
9015 linespec locations, explicit locations, or address locations.
9018 * Linespec Locations:: Linespec locations
9019 * Explicit Locations:: Explicit locations
9020 * Address Locations:: Address locations
9023 @node Linespec Locations
9024 @subsection Linespec Locations
9025 @cindex linespec locations
9027 A @dfn{linespec} is a colon-separated list of source location parameters such
9028 as file name, function name, etc. Here are all the different ways of
9029 specifying a linespec:
9033 Specifies the line number @var{linenum} of the current source file.
9036 @itemx +@var{offset}
9037 Specifies the line @var{offset} lines before or after the @dfn{current
9038 line}. For the @code{list} command, the current line is the last one
9039 printed; for the breakpoint commands, this is the line at which
9040 execution stopped in the currently selected @dfn{stack frame}
9041 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9042 used as the second of the two linespecs in a @code{list} command,
9043 this specifies the line @var{offset} lines up or down from the first
9046 @item @var{filename}:@var{linenum}
9047 Specifies the line @var{linenum} in the source file @var{filename}.
9048 If @var{filename} is a relative file name, then it will match any
9049 source file name with the same trailing components. For example, if
9050 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9051 name of @file{/build/trunk/gcc/expr.c}, but not
9052 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9054 @item @var{function}
9055 Specifies the line that begins the body of the function @var{function}.
9056 For example, in C, this is the line with the open brace.
9058 By default, in C@t{++} and Ada, @var{function} is interpreted as
9059 specifying all functions named @var{function} in all scopes. For
9060 C@t{++}, this means in all namespaces and classes. For Ada, this
9061 means in all packages.
9063 For example, assuming a program with C@t{++} symbols named
9064 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9065 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9067 Commands that accept a linespec let you override this with the
9068 @code{-qualified} option. For example, @w{@kbd{break -qualified
9069 func}} sets a breakpoint on a free-function named @code{func} ignoring
9070 any C@t{++} class methods and namespace functions called @code{func}.
9072 @xref{Explicit Locations}.
9074 @item @var{function}:@var{label}
9075 Specifies the line where @var{label} appears in @var{function}.
9077 @item @var{filename}:@var{function}
9078 Specifies the line that begins the body of the function @var{function}
9079 in the file @var{filename}. You only need the file name with a
9080 function name to avoid ambiguity when there are identically named
9081 functions in different source files.
9084 Specifies the line at which the label named @var{label} appears
9085 in the function corresponding to the currently selected stack frame.
9086 If there is no current selected stack frame (for instance, if the inferior
9087 is not running), then @value{GDBN} will not search for a label.
9089 @cindex breakpoint at static probe point
9090 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9091 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9092 applications to embed static probes. @xref{Static Probe Points}, for more
9093 information on finding and using static probes. This form of linespec
9094 specifies the location of such a static probe.
9096 If @var{objfile} is given, only probes coming from that shared library
9097 or executable matching @var{objfile} as a regular expression are considered.
9098 If @var{provider} is given, then only probes from that provider are considered.
9099 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9100 each one of those probes.
9103 @node Explicit Locations
9104 @subsection Explicit Locations
9105 @cindex explicit locations
9107 @dfn{Explicit locations} allow the user to directly specify the source
9108 location's parameters using option-value pairs.
9110 Explicit locations are useful when several functions, labels, or
9111 file names have the same name (base name for files) in the program's
9112 sources. In these cases, explicit locations point to the source
9113 line you meant more accurately and unambiguously. Also, using
9114 explicit locations might be faster in large programs.
9116 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9117 defined in the file named @file{foo} or the label @code{bar} in a function
9118 named @code{foo}. @value{GDBN} must search either the file system or
9119 the symbol table to know.
9121 The list of valid explicit location options is summarized in the
9125 @item -source @var{filename}
9126 The value specifies the source file name. To differentiate between
9127 files with the same base name, prepend as many directories as is necessary
9128 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9129 @value{GDBN} will use the first file it finds with the given base
9130 name. This option requires the use of either @code{-function} or @code{-line}.
9132 @item -function @var{function}
9133 The value specifies the name of a function. Operations
9134 on function locations unmodified by other options (such as @code{-label}
9135 or @code{-line}) refer to the line that begins the body of the function.
9136 In C, for example, this is the line with the open brace.
9138 By default, in C@t{++} and Ada, @var{function} is interpreted as
9139 specifying all functions named @var{function} in all scopes. For
9140 C@t{++}, this means in all namespaces and classes. For Ada, this
9141 means in all packages.
9143 For example, assuming a program with C@t{++} symbols named
9144 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9145 -function func}} and @w{@kbd{break -function B::func}} set a
9146 breakpoint on both symbols.
9148 You can use the @kbd{-qualified} flag to override this (see below).
9152 This flag makes @value{GDBN} interpret a function name specified with
9153 @kbd{-function} as a complete fully-qualified name.
9155 For example, assuming a C@t{++} program with symbols named
9156 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9157 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9159 (Note: the @kbd{-qualified} option can precede a linespec as well
9160 (@pxref{Linespec Locations}), so the particular example above could be
9161 simplified as @w{@kbd{break -qualified B::func}}.)
9163 @item -label @var{label}
9164 The value specifies the name of a label. When the function
9165 name is not specified, the label is searched in the function of the currently
9166 selected stack frame.
9168 @item -line @var{number}
9169 The value specifies a line offset for the location. The offset may either
9170 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9171 the command. When specified without any other options, the line offset is
9172 relative to the current line.
9175 Explicit location options may be abbreviated by omitting any non-unique
9176 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9178 @node Address Locations
9179 @subsection Address Locations
9180 @cindex address locations
9182 @dfn{Address locations} indicate a specific program address. They have
9183 the generalized form *@var{address}.
9185 For line-oriented commands, such as @code{list} and @code{edit}, this
9186 specifies a source line that contains @var{address}. For @code{break} and
9187 other breakpoint-oriented commands, this can be used to set breakpoints in
9188 parts of your program which do not have debugging information or
9191 Here @var{address} may be any expression valid in the current working
9192 language (@pxref{Languages, working language}) that specifies a code
9193 address. In addition, as a convenience, @value{GDBN} extends the
9194 semantics of expressions used in locations to cover several situations
9195 that frequently occur during debugging. Here are the various forms
9199 @item @var{expression}
9200 Any expression valid in the current working language.
9202 @item @var{funcaddr}
9203 An address of a function or procedure derived from its name. In C,
9204 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9205 simply the function's name @var{function} (and actually a special case
9206 of a valid expression). In Pascal and Modula-2, this is
9207 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9208 (although the Pascal form also works).
9210 This form specifies the address of the function's first instruction,
9211 before the stack frame and arguments have been set up.
9213 @item '@var{filename}':@var{funcaddr}
9214 Like @var{funcaddr} above, but also specifies the name of the source
9215 file explicitly. This is useful if the name of the function does not
9216 specify the function unambiguously, e.g., if there are several
9217 functions with identical names in different source files.
9221 @section Editing Source Files
9222 @cindex editing source files
9225 @kindex e @r{(@code{edit})}
9226 To edit the lines in a source file, use the @code{edit} command.
9227 The editing program of your choice
9228 is invoked with the current line set to
9229 the active line in the program.
9230 Alternatively, there are several ways to specify what part of the file you
9231 want to print if you want to see other parts of the program:
9234 @item edit @var{location}
9235 Edit the source file specified by @code{location}. Editing starts at
9236 that @var{location}, e.g., at the specified source line of the
9237 specified file. @xref{Specify Location}, for all the possible forms
9238 of the @var{location} argument; here are the forms of the @code{edit}
9239 command most commonly used:
9242 @item edit @var{number}
9243 Edit the current source file with @var{number} as the active line number.
9245 @item edit @var{function}
9246 Edit the file containing @var{function} at the beginning of its definition.
9251 @subsection Choosing your Editor
9252 You can customize @value{GDBN} to use any editor you want
9254 The only restriction is that your editor (say @code{ex}), recognizes the
9255 following command-line syntax:
9257 ex +@var{number} file
9259 The optional numeric value +@var{number} specifies the number of the line in
9260 the file where to start editing.}.
9261 By default, it is @file{@value{EDITOR}}, but you can change this
9262 by setting the environment variable @code{EDITOR} before using
9263 @value{GDBN}. For example, to configure @value{GDBN} to use the
9264 @code{vi} editor, you could use these commands with the @code{sh} shell:
9270 or in the @code{csh} shell,
9272 setenv EDITOR /usr/bin/vi
9277 @section Searching Source Files
9278 @cindex searching source files
9280 There are two commands for searching through the current source file for a
9285 @kindex forward-search
9286 @kindex fo @r{(@code{forward-search})}
9287 @item forward-search @var{regexp}
9288 @itemx search @var{regexp}
9289 The command @samp{forward-search @var{regexp}} checks each line,
9290 starting with the one following the last line listed, for a match for
9291 @var{regexp}. It lists the line that is found. You can use the
9292 synonym @samp{search @var{regexp}} or abbreviate the command name as
9295 @kindex reverse-search
9296 @item reverse-search @var{regexp}
9297 The command @samp{reverse-search @var{regexp}} checks each line, starting
9298 with the one before the last line listed and going backward, for a match
9299 for @var{regexp}. It lists the line that is found. You can abbreviate
9300 this command as @code{rev}.
9304 @section Specifying Source Directories
9307 @cindex directories for source files
9308 Executable programs sometimes do not record the directories of the source
9309 files from which they were compiled, just the names. Even when they do,
9310 the directories could be moved between the compilation and your debugging
9311 session. @value{GDBN} has a list of directories to search for source files;
9312 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9313 it tries all the directories in the list, in the order they are present
9314 in the list, until it finds a file with the desired name.
9316 For example, suppose an executable references the file
9317 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9318 directory, and the @dfn{source path} is @file{/mnt/cross}.
9319 @value{GDBN} would look for the source file in the following
9324 @item @file{/usr/src/foo-1.0/lib/foo.c}
9325 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9326 @item @file{/mnt/cross/foo.c}
9330 If the source file is not present at any of the above locations then
9331 an error is printed. @value{GDBN} does not look up the parts of the
9332 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9333 Likewise, the subdirectories of the source path are not searched: if
9334 the source path is @file{/mnt/cross}, and the binary refers to
9335 @file{foo.c}, @value{GDBN} would not find it under
9336 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9338 Plain file names, relative file names with leading directories, file
9339 names containing dots, etc.@: are all treated as described above,
9340 except that non-absolute file names are not looked up literally. If
9341 the @dfn{source path} is @file{/mnt/cross}, the source file is
9342 recorded as @file{../lib/foo.c}, and no compilation directory is
9343 recorded, then @value{GDBN} will search in the following locations:
9347 @item @file{/mnt/cross/../lib/foo.c}
9348 @item @file{/mnt/cross/foo.c}
9354 @vindex $cdir@r{, convenience variable}
9355 @vindex $cwd@r{, convenience variable}
9356 @cindex compilation directory
9357 @cindex current directory
9358 @cindex working directory
9359 @cindex directory, current
9360 @cindex directory, compilation
9361 The @dfn{source path} will always include two special entries
9362 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9363 (if one is recorded) and the current working directory respectively.
9365 @samp{$cdir} causes @value{GDBN} to search within the compilation
9366 directory, if one is recorded in the debug information. If no
9367 compilation directory is recorded in the debug information then
9368 @samp{$cdir} is ignored.
9370 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9371 current working directory as it changes during your @value{GDBN}
9372 session, while the latter is immediately expanded to the current
9373 directory at the time you add an entry to the source path.
9375 If a compilation directory is recorded in the debug information, and
9376 @value{GDBN} has not found the source file after the first search
9377 using @dfn{source path}, then @value{GDBN} will combine the
9378 compilation directory and the filename, and then search for the source
9379 file again using the @dfn{source path}.
9381 For example, if the executable records the source file as
9382 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9383 recorded as @file{/project/build}, and the @dfn{source path} is
9384 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9385 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9386 search for the source file in the following locations:
9390 @item @file{/usr/src/foo-1.0/lib/foo.c}
9391 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9392 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9393 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9394 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9395 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9396 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9397 @item @file{/mnt/cross/foo.c}
9398 @item @file{/project/build/foo.c}
9399 @item @file{/home/user/foo.c}
9403 If the file name in the previous example had been recorded in the
9404 executable as a relative path rather than an absolute path, then the
9405 first look up would not have occurred, but all of the remaining steps
9408 When searching for source files on MS-DOS and MS-Windows, where
9409 absolute paths start with a drive letter (e.g.
9410 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9411 from the file name before appending it to a search directory from
9412 @dfn{source path}; for instance if the executable references the
9413 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9414 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9415 locations for the source file:
9419 @item @file{C:/project/foo.c}
9420 @item @file{D:/mnt/cross/project/foo.c}
9421 @item @file{D:/mnt/cross/foo.c}
9425 Note that the executable search path is @emph{not} used to locate the
9428 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9429 any information it has cached about where source files are found and where
9430 each line is in the file.
9434 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9435 and @samp{$cwd}, in that order.
9436 To add other directories, use the @code{directory} command.
9438 The search path is used to find both program source files and @value{GDBN}
9439 script files (read using the @samp{-command} option and @samp{source} command).
9441 In addition to the source path, @value{GDBN} provides a set of commands
9442 that manage a list of source path substitution rules. A @dfn{substitution
9443 rule} specifies how to rewrite source directories stored in the program's
9444 debug information in case the sources were moved to a different
9445 directory between compilation and debugging. A rule is made of
9446 two strings, the first specifying what needs to be rewritten in
9447 the path, and the second specifying how it should be rewritten.
9448 In @ref{set substitute-path}, we name these two parts @var{from} and
9449 @var{to} respectively. @value{GDBN} does a simple string replacement
9450 of @var{from} with @var{to} at the start of the directory part of the
9451 source file name, and uses that result instead of the original file
9452 name to look up the sources.
9454 Using the previous example, suppose the @file{foo-1.0} tree has been
9455 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9456 @value{GDBN} to replace @file{/usr/src} in all source path names with
9457 @file{/mnt/cross}. The first lookup will then be
9458 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9459 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9460 substitution rule, use the @code{set substitute-path} command
9461 (@pxref{set substitute-path}).
9463 To avoid unexpected substitution results, a rule is applied only if the
9464 @var{from} part of the directory name ends at a directory separator.
9465 For instance, a rule substituting @file{/usr/source} into
9466 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9467 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9468 is applied only at the beginning of the directory name, this rule will
9469 not be applied to @file{/root/usr/source/baz.c} either.
9471 In many cases, you can achieve the same result using the @code{directory}
9472 command. However, @code{set substitute-path} can be more efficient in
9473 the case where the sources are organized in a complex tree with multiple
9474 subdirectories. With the @code{directory} command, you need to add each
9475 subdirectory of your project. If you moved the entire tree while
9476 preserving its internal organization, then @code{set substitute-path}
9477 allows you to direct the debugger to all the sources with one single
9480 @code{set substitute-path} is also more than just a shortcut command.
9481 The source path is only used if the file at the original location no
9482 longer exists. On the other hand, @code{set substitute-path} modifies
9483 the debugger behavior to look at the rewritten location instead. So, if
9484 for any reason a source file that is not relevant to your executable is
9485 located at the original location, a substitution rule is the only
9486 method available to point @value{GDBN} at the new location.
9488 @cindex @samp{--with-relocated-sources}
9489 @cindex default source path substitution
9490 You can configure a default source path substitution rule by
9491 configuring @value{GDBN} with the
9492 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9493 should be the name of a directory under @value{GDBN}'s configured
9494 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9495 directory names in debug information under @var{dir} will be adjusted
9496 automatically if the installed @value{GDBN} is moved to a new
9497 location. This is useful if @value{GDBN}, libraries or executables
9498 with debug information and corresponding source code are being moved
9502 @item directory @var{dirname} @dots{}
9503 @item dir @var{dirname} @dots{}
9504 Add directory @var{dirname} to the front of the source path. Several
9505 directory names may be given to this command, separated by @samp{:}
9506 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9507 part of absolute file names) or
9508 whitespace. You may specify a directory that is already in the source
9509 path; this moves it forward, so @value{GDBN} searches it sooner.
9511 The special strings @samp{$cdir} (to refer to the compilation
9512 directory, if one is recorded), and @samp{$cwd} (to refer to the
9513 current working directory) can also be included in the list of
9514 directories @var{dirname}. Though these will already be in the source
9515 path they will be moved forward in the list so @value{GDBN} searches
9519 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9521 @c RET-repeat for @code{directory} is explicitly disabled, but since
9522 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9524 @item set directories @var{path-list}
9525 @kindex set directories
9526 Set the source path to @var{path-list}.
9527 @samp{$cdir:$cwd} are added if missing.
9529 @item show directories
9530 @kindex show directories
9531 Print the source path: show which directories it contains.
9533 @anchor{set substitute-path}
9534 @item set substitute-path @var{from} @var{to}
9535 @kindex set substitute-path
9536 Define a source path substitution rule, and add it at the end of the
9537 current list of existing substitution rules. If a rule with the same
9538 @var{from} was already defined, then the old rule is also deleted.
9540 For example, if the file @file{/foo/bar/baz.c} was moved to
9541 @file{/mnt/cross/baz.c}, then the command
9544 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9548 will tell @value{GDBN} to replace @samp{/foo/bar} with
9549 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9550 @file{baz.c} even though it was moved.
9552 In the case when more than one substitution rule have been defined,
9553 the rules are evaluated one by one in the order where they have been
9554 defined. The first one matching, if any, is selected to perform
9557 For instance, if we had entered the following commands:
9560 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9561 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9565 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9566 @file{/mnt/include/defs.h} by using the first rule. However, it would
9567 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9568 @file{/mnt/src/lib/foo.c}.
9571 @item unset substitute-path [path]
9572 @kindex unset substitute-path
9573 If a path is specified, search the current list of substitution rules
9574 for a rule that would rewrite that path. Delete that rule if found.
9575 A warning is emitted by the debugger if no rule could be found.
9577 If no path is specified, then all substitution rules are deleted.
9579 @item show substitute-path [path]
9580 @kindex show substitute-path
9581 If a path is specified, then print the source path substitution rule
9582 which would rewrite that path, if any.
9584 If no path is specified, then print all existing source path substitution
9589 If your source path is cluttered with directories that are no longer of
9590 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9591 versions of source. You can correct the situation as follows:
9595 Use @code{directory} with no argument to reset the source path to its default value.
9598 Use @code{directory} with suitable arguments to reinstall the
9599 directories you want in the source path. You can add all the
9600 directories in one command.
9604 @section Source and Machine Code
9605 @cindex source line and its code address
9607 You can use the command @code{info line} to map source lines to program
9608 addresses (and vice versa), and the command @code{disassemble} to display
9609 a range of addresses as machine instructions. You can use the command
9610 @code{set disassemble-next-line} to set whether to disassemble next
9611 source line when execution stops. When run under @sc{gnu} Emacs
9612 mode, the @code{info line} command causes the arrow to point to the
9613 line specified. Also, @code{info line} prints addresses in symbolic form as
9619 @itemx info line @var{location}
9620 Print the starting and ending addresses of the compiled code for
9621 source line @var{location}. You can specify source lines in any of
9622 the ways documented in @ref{Specify Location}. With no @var{location}
9623 information about the current source line is printed.
9626 For example, we can use @code{info line} to discover the location of
9627 the object code for the first line of function
9628 @code{m4_changequote}:
9631 (@value{GDBP}) info line m4_changequote
9632 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9633 ends at 0x6350 <m4_changequote+4>.
9637 @cindex code address and its source line
9638 We can also inquire (using @code{*@var{addr}} as the form for
9639 @var{location}) what source line covers a particular address:
9641 (@value{GDBP}) info line *0x63ff
9642 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9643 ends at 0x6404 <m4_changequote+184>.
9646 @cindex @code{$_} and @code{info line}
9647 @cindex @code{x} command, default address
9648 @kindex x@r{(examine), and} info line
9649 After @code{info line}, the default address for the @code{x} command
9650 is changed to the starting address of the line, so that @samp{x/i} is
9651 sufficient to begin examining the machine code (@pxref{Memory,
9652 ,Examining Memory}). Also, this address is saved as the value of the
9653 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9656 @cindex info line, repeated calls
9657 After @code{info line}, using @code{info line} again without
9658 specifying a location will display information about the next source
9663 @cindex assembly instructions
9664 @cindex instructions, assembly
9665 @cindex machine instructions
9666 @cindex listing machine instructions
9668 @itemx disassemble /m
9669 @itemx disassemble /s
9670 @itemx disassemble /r
9671 This specialized command dumps a range of memory as machine
9672 instructions. It can also print mixed source+disassembly by specifying
9673 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9674 as well as in symbolic form by specifying the @code{/r} modifier.
9675 The default memory range is the function surrounding the
9676 program counter of the selected frame. A single argument to this
9677 command is a program counter value; @value{GDBN} dumps the function
9678 surrounding this value. When two arguments are given, they should
9679 be separated by a comma, possibly surrounded by whitespace. The
9680 arguments specify a range of addresses to dump, in one of two forms:
9683 @item @var{start},@var{end}
9684 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9685 @item @var{start},+@var{length}
9686 the addresses from @var{start} (inclusive) to
9687 @code{@var{start}+@var{length}} (exclusive).
9691 When 2 arguments are specified, the name of the function is also
9692 printed (since there could be several functions in the given range).
9694 The argument(s) can be any expression yielding a numeric value, such as
9695 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9697 If the range of memory being disassembled contains current program counter,
9698 the instruction at that location is shown with a @code{=>} marker.
9701 The following example shows the disassembly of a range of addresses of
9702 HP PA-RISC 2.0 code:
9705 (@value{GDBP}) disas 0x32c4, 0x32e4
9706 Dump of assembler code from 0x32c4 to 0x32e4:
9707 0x32c4 <main+204>: addil 0,dp
9708 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9709 0x32cc <main+212>: ldil 0x3000,r31
9710 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9711 0x32d4 <main+220>: ldo 0(r31),rp
9712 0x32d8 <main+224>: addil -0x800,dp
9713 0x32dc <main+228>: ldo 0x588(r1),r26
9714 0x32e0 <main+232>: ldil 0x3000,r31
9715 End of assembler dump.
9718 Here is an example showing mixed source+assembly for Intel x86
9719 with @code{/m} or @code{/s}, when the program is stopped just after
9720 function prologue in a non-optimized function with no inline code.
9723 (@value{GDBP}) disas /m main
9724 Dump of assembler code for function main:
9726 0x08048330 <+0>: push %ebp
9727 0x08048331 <+1>: mov %esp,%ebp
9728 0x08048333 <+3>: sub $0x8,%esp
9729 0x08048336 <+6>: and $0xfffffff0,%esp
9730 0x08048339 <+9>: sub $0x10,%esp
9732 6 printf ("Hello.\n");
9733 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9734 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9738 0x08048348 <+24>: mov $0x0,%eax
9739 0x0804834d <+29>: leave
9740 0x0804834e <+30>: ret
9742 End of assembler dump.
9745 The @code{/m} option is deprecated as its output is not useful when
9746 there is either inlined code or re-ordered code.
9747 The @code{/s} option is the preferred choice.
9748 Here is an example for AMD x86-64 showing the difference between
9749 @code{/m} output and @code{/s} output.
9750 This example has one inline function defined in a header file,
9751 and the code is compiled with @samp{-O2} optimization.
9752 Note how the @code{/m} output is missing the disassembly of
9753 several instructions that are present in the @code{/s} output.
9783 (@value{GDBP}) disas /m main
9784 Dump of assembler code for function main:
9788 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9789 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9793 0x000000000040041d <+29>: xor %eax,%eax
9794 0x000000000040041f <+31>: retq
9795 0x0000000000400420 <+32>: add %eax,%eax
9796 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9798 End of assembler dump.
9799 (@value{GDBP}) disas /s main
9800 Dump of assembler code for function main:
9804 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9808 0x0000000000400406 <+6>: test %eax,%eax
9809 0x0000000000400408 <+8>: js 0x400420 <main+32>
9814 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9815 0x000000000040040d <+13>: test %eax,%eax
9816 0x000000000040040f <+15>: mov $0x1,%eax
9817 0x0000000000400414 <+20>: cmovne %edx,%eax
9821 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9825 0x000000000040041d <+29>: xor %eax,%eax
9826 0x000000000040041f <+31>: retq
9830 0x0000000000400420 <+32>: add %eax,%eax
9831 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9832 End of assembler dump.
9835 Here is another example showing raw instructions in hex for AMD x86-64,
9838 (gdb) disas /r 0x400281,+10
9839 Dump of assembler code from 0x400281 to 0x40028b:
9840 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9841 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9842 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9843 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9844 End of assembler dump.
9847 Addresses cannot be specified as a location (@pxref{Specify Location}).
9848 So, for example, if you want to disassemble function @code{bar}
9849 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9850 and not @samp{disassemble foo.c:bar}.
9852 Some architectures have more than one commonly-used set of instruction
9853 mnemonics or other syntax.
9855 For programs that were dynamically linked and use shared libraries,
9856 instructions that call functions or branch to locations in the shared
9857 libraries might show a seemingly bogus location---it's actually a
9858 location of the relocation table. On some architectures, @value{GDBN}
9859 might be able to resolve these to actual function names.
9862 @kindex set disassembler-options
9863 @cindex disassembler options
9864 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9865 This command controls the passing of target specific information to
9866 the disassembler. For a list of valid options, please refer to the
9867 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9868 manual and/or the output of @kbd{objdump --help}
9869 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9870 The default value is the empty string.
9872 If it is necessary to specify more than one disassembler option, then
9873 multiple options can be placed together into a comma separated list.
9874 Currently this command is only supported on targets ARM, MIPS, PowerPC
9877 @kindex show disassembler-options
9878 @item show disassembler-options
9879 Show the current setting of the disassembler options.
9883 @kindex set disassembly-flavor
9884 @cindex Intel disassembly flavor
9885 @cindex AT&T disassembly flavor
9886 @item set disassembly-flavor @var{instruction-set}
9887 Select the instruction set to use when disassembling the
9888 program via the @code{disassemble} or @code{x/i} commands.
9890 Currently this command is only defined for the Intel x86 family. You
9891 can set @var{instruction-set} to either @code{intel} or @code{att}.
9892 The default is @code{att}, the AT&T flavor used by default by Unix
9893 assemblers for x86-based targets.
9895 @kindex show disassembly-flavor
9896 @item show disassembly-flavor
9897 Show the current setting of the disassembly flavor.
9901 @kindex set disassemble-next-line
9902 @kindex show disassemble-next-line
9903 @item set disassemble-next-line
9904 @itemx show disassemble-next-line
9905 Control whether or not @value{GDBN} will disassemble the next source
9906 line or instruction when execution stops. If ON, @value{GDBN} will
9907 display disassembly of the next source line when execution of the
9908 program being debugged stops. This is @emph{in addition} to
9909 displaying the source line itself, which @value{GDBN} always does if
9910 possible. If the next source line cannot be displayed for some reason
9911 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9912 info in the debug info), @value{GDBN} will display disassembly of the
9913 next @emph{instruction} instead of showing the next source line. If
9914 AUTO, @value{GDBN} will display disassembly of next instruction only
9915 if the source line cannot be displayed. This setting causes
9916 @value{GDBN} to display some feedback when you step through a function
9917 with no line info or whose source file is unavailable. The default is
9918 OFF, which means never display the disassembly of the next line or
9924 @chapter Examining Data
9926 @cindex printing data
9927 @cindex examining data
9930 The usual way to examine data in your program is with the @code{print}
9931 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9932 evaluates and prints the value of an expression of the language your
9933 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9934 Different Languages}). It may also print the expression using a
9935 Python-based pretty-printer (@pxref{Pretty Printing}).
9938 @item print [[@var{options}] --] @var{expr}
9939 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9940 @var{expr} is an expression (in the source language). By default the
9941 value of @var{expr} is printed in a format appropriate to its data type;
9942 you can choose a different format by specifying @samp{/@var{f}}, where
9943 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9946 @anchor{print options}
9947 The @code{print} command supports a number of options that allow
9948 overriding relevant global print settings as set by @code{set print}
9952 @item -address [@code{on}|@code{off}]
9953 Set printing of addresses.
9954 Related setting: @ref{set print address}.
9956 @item -array [@code{on}|@code{off}]
9957 Pretty formatting of arrays.
9958 Related setting: @ref{set print array}.
9960 @item -array-indexes [@code{on}|@code{off}]
9961 Set printing of array indexes.
9962 Related setting: @ref{set print array-indexes}.
9964 @item -elements @var{number-of-elements}|@code{unlimited}
9965 Set limit on string chars or array elements to print. The value
9966 @code{unlimited} causes there to be no limit. Related setting:
9967 @ref{set print elements}.
9969 @item -max-depth @var{depth}|@code{unlimited}
9970 Set the threshold after which nested structures are replaced with
9971 ellipsis. Related setting: @ref{set print max-depth}.
9973 @item -null-stop [@code{on}|@code{off}]
9974 Set printing of char arrays to stop at first null char. Related
9975 setting: @ref{set print null-stop}.
9977 @item -object [@code{on}|@code{off}]
9978 Set printing C@t{++} virtual function tables. Related setting:
9979 @ref{set print object}.
9981 @item -pretty [@code{on}|@code{off}]
9982 Set pretty formatting of structures. Related setting: @ref{set print
9985 @item -raw-values [@code{on}|@code{off}]
9986 Set whether to print values in raw form, bypassing any
9987 pretty-printers for that value. Related setting: @ref{set print
9990 @item -repeats @var{number-of-repeats}|@code{unlimited}
9991 Set threshold for repeated print elements. @code{unlimited} causes
9992 all elements to be individually printed. Related setting: @ref{set
9995 @item -static-members [@code{on}|@code{off}]
9996 Set printing C@t{++} static members. Related setting: @ref{set print
9999 @item -symbol [@code{on}|@code{off}]
10000 Set printing of symbol names when printing pointers. Related setting:
10001 @ref{set print symbol}.
10003 @item -union [@code{on}|@code{off}]
10004 Set printing of unions interior to structures. Related setting:
10005 @ref{set print union}.
10007 @item -vtbl [@code{on}|@code{off}]
10008 Set printing of C++ virtual function tables. Related setting:
10009 @ref{set print vtbl}.
10012 Because the @code{print} command accepts arbitrary expressions which
10013 may look like options (including abbreviations), if you specify any
10014 command option, then you must use a double dash (@code{--}) to mark
10015 the end of option processing.
10017 For example, this prints the value of the @code{-p} expression:
10020 (@value{GDBP}) print -p
10023 While this repeats the last value in the value history (see below)
10024 with the @code{-pretty} option in effect:
10027 (@value{GDBP}) print -p --
10030 Here is an example including both on option and an expression:
10034 (@value{GDBP}) print -pretty -- *myptr
10046 @item print [@var{options}]
10047 @itemx print [@var{options}] /@var{f}
10048 @cindex reprint the last value
10049 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10050 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10051 conveniently inspect the same value in an alternative format.
10054 If the architecture supports memory tagging, the @code{print} command will
10055 display pointer/memory tag mismatches if what is being printed is a pointer
10056 or reference type. @xref{Memory Tagging}.
10058 A more low-level way of examining data is with the @code{x} command.
10059 It examines data in memory at a specified address and prints it in a
10060 specified format. @xref{Memory, ,Examining Memory}.
10062 If you are interested in information about types, or about how the
10063 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
10064 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10067 @cindex exploring hierarchical data structures
10069 Another way of examining values of expressions and type information is
10070 through the Python extension command @code{explore} (available only if
10071 the @value{GDBN} build is configured with @code{--with-python}). It
10072 offers an interactive way to start at the highest level (or, the most
10073 abstract level) of the data type of an expression (or, the data type
10074 itself) and explore all the way down to leaf scalar values/fields
10075 embedded in the higher level data types.
10078 @item explore @var{arg}
10079 @var{arg} is either an expression (in the source language), or a type
10080 visible in the current context of the program being debugged.
10083 The working of the @code{explore} command can be illustrated with an
10084 example. If a data type @code{struct ComplexStruct} is defined in your
10088 struct SimpleStruct
10094 struct ComplexStruct
10096 struct SimpleStruct *ss_p;
10102 followed by variable declarations as
10105 struct SimpleStruct ss = @{ 10, 1.11 @};
10106 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10110 then, the value of the variable @code{cs} can be explored using the
10111 @code{explore} command as follows.
10115 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10116 the following fields:
10118 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10119 arr = <Enter 1 to explore this field of type `int [10]'>
10121 Enter the field number of choice:
10125 Since the fields of @code{cs} are not scalar values, you are being
10126 prompted to chose the field you want to explore. Let's say you choose
10127 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10128 pointer, you will be asked if it is pointing to a single value. From
10129 the declaration of @code{cs} above, it is indeed pointing to a single
10130 value, hence you enter @code{y}. If you enter @code{n}, then you will
10131 be asked if it were pointing to an array of values, in which case this
10132 field will be explored as if it were an array.
10135 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10136 Continue exploring it as a pointer to a single value [y/n]: y
10137 The value of `*(cs.ss_p)' is a struct/class of type `struct
10138 SimpleStruct' with the following fields:
10140 i = 10 .. (Value of type `int')
10141 d = 1.1100000000000001 .. (Value of type `double')
10143 Press enter to return to parent value:
10147 If the field @code{arr} of @code{cs} was chosen for exploration by
10148 entering @code{1} earlier, then since it is as array, you will be
10149 prompted to enter the index of the element in the array that you want
10153 `cs.arr' is an array of `int'.
10154 Enter the index of the element you want to explore in `cs.arr': 5
10156 `(cs.arr)[5]' is a scalar value of type `int'.
10160 Press enter to return to parent value:
10163 In general, at any stage of exploration, you can go deeper towards the
10164 leaf values by responding to the prompts appropriately, or hit the
10165 return key to return to the enclosing data structure (the @i{higher}
10166 level data structure).
10168 Similar to exploring values, you can use the @code{explore} command to
10169 explore types. Instead of specifying a value (which is typically a
10170 variable name or an expression valid in the current context of the
10171 program being debugged), you specify a type name. If you consider the
10172 same example as above, your can explore the type
10173 @code{struct ComplexStruct} by passing the argument
10174 @code{struct ComplexStruct} to the @code{explore} command.
10177 (gdb) explore struct ComplexStruct
10181 By responding to the prompts appropriately in the subsequent interactive
10182 session, you can explore the type @code{struct ComplexStruct} in a
10183 manner similar to how the value @code{cs} was explored in the above
10186 The @code{explore} command also has two sub-commands,
10187 @code{explore value} and @code{explore type}. The former sub-command is
10188 a way to explicitly specify that value exploration of the argument is
10189 being invoked, while the latter is a way to explicitly specify that type
10190 exploration of the argument is being invoked.
10193 @item explore value @var{expr}
10194 @cindex explore value
10195 This sub-command of @code{explore} explores the value of the
10196 expression @var{expr} (if @var{expr} is an expression valid in the
10197 current context of the program being debugged). The behavior of this
10198 command is identical to that of the behavior of the @code{explore}
10199 command being passed the argument @var{expr}.
10201 @item explore type @var{arg}
10202 @cindex explore type
10203 This sub-command of @code{explore} explores the type of @var{arg} (if
10204 @var{arg} is a type visible in the current context of program being
10205 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10206 is an expression valid in the current context of the program being
10207 debugged). If @var{arg} is a type, then the behavior of this command is
10208 identical to that of the @code{explore} command being passed the
10209 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10210 this command will be identical to that of the @code{explore} command
10211 being passed the type of @var{arg} as the argument.
10215 * Expressions:: Expressions
10216 * Ambiguous Expressions:: Ambiguous Expressions
10217 * Variables:: Program variables
10218 * Arrays:: Artificial arrays
10219 * Output Formats:: Output formats
10220 * Memory:: Examining memory
10221 * Memory Tagging:: Memory Tagging
10222 * Auto Display:: Automatic display
10223 * Print Settings:: Print settings
10224 * Pretty Printing:: Python pretty printing
10225 * Value History:: Value history
10226 * Convenience Vars:: Convenience variables
10227 * Convenience Funs:: Convenience functions
10228 * Registers:: Registers
10229 * Floating Point Hardware:: Floating point hardware
10230 * Vector Unit:: Vector Unit
10231 * OS Information:: Auxiliary data provided by operating system
10232 * Memory Region Attributes:: Memory region attributes
10233 * Dump/Restore Files:: Copy between memory and a file
10234 * Core File Generation:: Cause a program dump its core
10235 * Character Sets:: Debugging programs that use a different
10236 character set than GDB does
10237 * Caching Target Data:: Data caching for targets
10238 * Searching Memory:: Searching memory for a sequence of bytes
10239 * Value Sizes:: Managing memory allocated for values
10243 @section Expressions
10245 @cindex expressions
10246 @code{print} and many other @value{GDBN} commands accept an expression and
10247 compute its value. Any kind of constant, variable or operator defined
10248 by the programming language you are using is valid in an expression in
10249 @value{GDBN}. This includes conditional expressions, function calls,
10250 casts, and string constants. It also includes preprocessor macros, if
10251 you compiled your program to include this information; see
10254 @cindex arrays in expressions
10255 @value{GDBN} supports array constants in expressions input by
10256 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10257 you can use the command @code{print @{1, 2, 3@}} to create an array
10258 of three integers. If you pass an array to a function or assign it
10259 to a program variable, @value{GDBN} copies the array to memory that
10260 is @code{malloc}ed in the target program.
10262 Because C is so widespread, most of the expressions shown in examples in
10263 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10264 Languages}, for information on how to use expressions in other
10267 In this section, we discuss operators that you can use in @value{GDBN}
10268 expressions regardless of your programming language.
10270 @cindex casts, in expressions
10271 Casts are supported in all languages, not just in C, because it is so
10272 useful to cast a number into a pointer in order to examine a structure
10273 at that address in memory.
10274 @c FIXME: casts supported---Mod2 true?
10276 @value{GDBN} supports these operators, in addition to those common
10277 to programming languages:
10281 @samp{@@} is a binary operator for treating parts of memory as arrays.
10282 @xref{Arrays, ,Artificial Arrays}, for more information.
10285 @samp{::} allows you to specify a variable in terms of the file or
10286 function where it is defined. @xref{Variables, ,Program Variables}.
10288 @cindex @{@var{type}@}
10289 @cindex type casting memory
10290 @cindex memory, viewing as typed object
10291 @cindex casts, to view memory
10292 @item @{@var{type}@} @var{addr}
10293 Refers to an object of type @var{type} stored at address @var{addr} in
10294 memory. The address @var{addr} may be any expression whose value is
10295 an integer or pointer (but parentheses are required around binary
10296 operators, just as in a cast). This construct is allowed regardless
10297 of what kind of data is normally supposed to reside at @var{addr}.
10300 @node Ambiguous Expressions
10301 @section Ambiguous Expressions
10302 @cindex ambiguous expressions
10304 Expressions can sometimes contain some ambiguous elements. For instance,
10305 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10306 a single function name to be defined several times, for application in
10307 different contexts. This is called @dfn{overloading}. Another example
10308 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10309 templates and is typically instantiated several times, resulting in
10310 the same function name being defined in different contexts.
10312 In some cases and depending on the language, it is possible to adjust
10313 the expression to remove the ambiguity. For instance in C@t{++}, you
10314 can specify the signature of the function you want to break on, as in
10315 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10316 qualified name of your function often makes the expression unambiguous
10319 When an ambiguity that needs to be resolved is detected, the debugger
10320 has the capability to display a menu of numbered choices for each
10321 possibility, and then waits for the selection with the prompt @samp{>}.
10322 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10323 aborts the current command. If the command in which the expression was
10324 used allows more than one choice to be selected, the next option in the
10325 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10328 For example, the following session excerpt shows an attempt to set a
10329 breakpoint at the overloaded symbol @code{String::after}.
10330 We choose three particular definitions of that function name:
10332 @c FIXME! This is likely to change to show arg type lists, at least
10335 (@value{GDBP}) b String::after
10338 [2] file:String.cc; line number:867
10339 [3] file:String.cc; line number:860
10340 [4] file:String.cc; line number:875
10341 [5] file:String.cc; line number:853
10342 [6] file:String.cc; line number:846
10343 [7] file:String.cc; line number:735
10345 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10346 Breakpoint 2 at 0xb344: file String.cc, line 875.
10347 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10348 Multiple breakpoints were set.
10349 Use the "delete" command to delete unwanted
10356 @kindex set multiple-symbols
10357 @item set multiple-symbols @var{mode}
10358 @cindex multiple-symbols menu
10360 This option allows you to adjust the debugger behavior when an expression
10363 By default, @var{mode} is set to @code{all}. If the command with which
10364 the expression is used allows more than one choice, then @value{GDBN}
10365 automatically selects all possible choices. For instance, inserting
10366 a breakpoint on a function using an ambiguous name results in a breakpoint
10367 inserted on each possible match. However, if a unique choice must be made,
10368 then @value{GDBN} uses the menu to help you disambiguate the expression.
10369 For instance, printing the address of an overloaded function will result
10370 in the use of the menu.
10372 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10373 when an ambiguity is detected.
10375 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10376 an error due to the ambiguity and the command is aborted.
10378 @kindex show multiple-symbols
10379 @item show multiple-symbols
10380 Show the current value of the @code{multiple-symbols} setting.
10384 @section Program Variables
10386 The most common kind of expression to use is the name of a variable
10389 Variables in expressions are understood in the selected stack frame
10390 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10394 global (or file-static)
10401 visible according to the scope rules of the
10402 programming language from the point of execution in that frame
10405 @noindent This means that in the function
10420 you can examine and use the variable @code{a} whenever your program is
10421 executing within the function @code{foo}, but you can only use or
10422 examine the variable @code{b} while your program is executing inside
10423 the block where @code{b} is declared.
10425 @cindex variable name conflict
10426 There is an exception: you can refer to a variable or function whose
10427 scope is a single source file even if the current execution point is not
10428 in this file. But it is possible to have more than one such variable or
10429 function with the same name (in different source files). If that
10430 happens, referring to that name has unpredictable effects. If you wish,
10431 you can specify a static variable in a particular function or file by
10432 using the colon-colon (@code{::}) notation:
10434 @cindex colon-colon, context for variables/functions
10436 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10437 @cindex @code{::}, context for variables/functions
10440 @var{file}::@var{variable}
10441 @var{function}::@var{variable}
10445 Here @var{file} or @var{function} is the name of the context for the
10446 static @var{variable}. In the case of file names, you can use quotes to
10447 make sure @value{GDBN} parses the file name as a single word---for example,
10448 to print a global value of @code{x} defined in @file{f2.c}:
10451 (@value{GDBP}) p 'f2.c'::x
10454 The @code{::} notation is normally used for referring to
10455 static variables, since you typically disambiguate uses of local variables
10456 in functions by selecting the appropriate frame and using the
10457 simple name of the variable. However, you may also use this notation
10458 to refer to local variables in frames enclosing the selected frame:
10467 process (a); /* Stop here */
10478 For example, if there is a breakpoint at the commented line,
10479 here is what you might see
10480 when the program stops after executing the call @code{bar(0)}:
10485 (@value{GDBP}) p bar::a
10487 (@value{GDBP}) up 2
10488 #2 0x080483d0 in foo (a=5) at foobar.c:12
10491 (@value{GDBP}) p bar::a
10495 @cindex C@t{++} scope resolution
10496 These uses of @samp{::} are very rarely in conflict with the very
10497 similar use of the same notation in C@t{++}. When they are in
10498 conflict, the C@t{++} meaning takes precedence; however, this can be
10499 overridden by quoting the file or function name with single quotes.
10501 For example, suppose the program is stopped in a method of a class
10502 that has a field named @code{includefile}, and there is also an
10503 include file named @file{includefile} that defines a variable,
10504 @code{some_global}.
10507 (@value{GDBP}) p includefile
10509 (@value{GDBP}) p includefile::some_global
10510 A syntax error in expression, near `'.
10511 (@value{GDBP}) p 'includefile'::some_global
10515 @cindex wrong values
10516 @cindex variable values, wrong
10517 @cindex function entry/exit, wrong values of variables
10518 @cindex optimized code, wrong values of variables
10520 @emph{Warning:} Occasionally, a local variable may appear to have the
10521 wrong value at certain points in a function---just after entry to a new
10522 scope, and just before exit.
10524 You may see this problem when you are stepping by machine instructions.
10525 This is because, on most machines, it takes more than one instruction to
10526 set up a stack frame (including local variable definitions); if you are
10527 stepping by machine instructions, variables may appear to have the wrong
10528 values until the stack frame is completely built. On exit, it usually
10529 also takes more than one machine instruction to destroy a stack frame;
10530 after you begin stepping through that group of instructions, local
10531 variable definitions may be gone.
10533 This may also happen when the compiler does significant optimizations.
10534 To be sure of always seeing accurate values, turn off all optimization
10537 @cindex ``No symbol "foo" in current context''
10538 Another possible effect of compiler optimizations is to optimize
10539 unused variables out of existence, or assign variables to registers (as
10540 opposed to memory addresses). Depending on the support for such cases
10541 offered by the debug info format used by the compiler, @value{GDBN}
10542 might not be able to display values for such local variables. If that
10543 happens, @value{GDBN} will print a message like this:
10546 No symbol "foo" in current context.
10549 To solve such problems, either recompile without optimizations, or use a
10550 different debug info format, if the compiler supports several such
10551 formats. @xref{Compilation}, for more information on choosing compiler
10552 options. @xref{C, ,C and C@t{++}}, for more information about debug
10553 info formats that are best suited to C@t{++} programs.
10555 If you ask to print an object whose contents are unknown to
10556 @value{GDBN}, e.g., because its data type is not completely specified
10557 by the debug information, @value{GDBN} will say @samp{<incomplete
10558 type>}. @xref{Symbols, incomplete type}, for more about this.
10560 @cindex no debug info variables
10561 If you try to examine or use the value of a (global) variable for
10562 which @value{GDBN} has no type information, e.g., because the program
10563 includes no debug information, @value{GDBN} displays an error message.
10564 @xref{Symbols, unknown type}, for more about unknown types. If you
10565 cast the variable to its declared type, @value{GDBN} gets the
10566 variable's value using the cast-to type as the variable's type. For
10567 example, in a C program:
10570 (@value{GDBP}) p var
10571 'var' has unknown type; cast it to its declared type
10572 (@value{GDBP}) p (float) var
10576 If you append @kbd{@@entry} string to a function parameter name you get its
10577 value at the time the function got called. If the value is not available an
10578 error message is printed. Entry values are available only with some compilers.
10579 Entry values are normally also printed at the function parameter list according
10580 to @ref{set print entry-values}.
10583 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10589 (gdb) print i@@entry
10593 Strings are identified as arrays of @code{char} values without specified
10594 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10595 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10596 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10597 defines literal string type @code{"char"} as @code{char} without a sign.
10602 signed char var1[] = "A";
10605 You get during debugging
10610 $2 = @{65 'A', 0 '\0'@}
10614 @section Artificial Arrays
10616 @cindex artificial array
10618 @kindex @@@r{, referencing memory as an array}
10619 It is often useful to print out several successive objects of the
10620 same type in memory; a section of an array, or an array of
10621 dynamically determined size for which only a pointer exists in the
10624 You can do this by referring to a contiguous span of memory as an
10625 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10626 operand of @samp{@@} should be the first element of the desired array
10627 and be an individual object. The right operand should be the desired length
10628 of the array. The result is an array value whose elements are all of
10629 the type of the left argument. The first element is actually the left
10630 argument; the second element comes from bytes of memory immediately
10631 following those that hold the first element, and so on. Here is an
10632 example. If a program says
10635 int *array = (int *) malloc (len * sizeof (int));
10639 you can print the contents of @code{array} with
10645 The left operand of @samp{@@} must reside in memory. Array values made
10646 with @samp{@@} in this way behave just like other arrays in terms of
10647 subscripting, and are coerced to pointers when used in expressions.
10648 Artificial arrays most often appear in expressions via the value history
10649 (@pxref{Value History, ,Value History}), after printing one out.
10651 Another way to create an artificial array is to use a cast.
10652 This re-interprets a value as if it were an array.
10653 The value need not be in memory:
10655 (@value{GDBP}) p/x (short[2])0x12345678
10656 $1 = @{0x1234, 0x5678@}
10659 As a convenience, if you leave the array length out (as in
10660 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10661 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10663 (@value{GDBP}) p/x (short[])0x12345678
10664 $2 = @{0x1234, 0x5678@}
10667 Sometimes the artificial array mechanism is not quite enough; in
10668 moderately complex data structures, the elements of interest may not
10669 actually be adjacent---for example, if you are interested in the values
10670 of pointers in an array. One useful work-around in this situation is
10671 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10672 Variables}) as a counter in an expression that prints the first
10673 interesting value, and then repeat that expression via @key{RET}. For
10674 instance, suppose you have an array @code{dtab} of pointers to
10675 structures, and you are interested in the values of a field @code{fv}
10676 in each structure. Here is an example of what you might type:
10686 @node Output Formats
10687 @section Output Formats
10689 @cindex formatted output
10690 @cindex output formats
10691 By default, @value{GDBN} prints a value according to its data type. Sometimes
10692 this is not what you want. For example, you might want to print a number
10693 in hex, or a pointer in decimal. Or you might want to view data in memory
10694 at a certain address as a character string or as an instruction. To do
10695 these things, specify an @dfn{output format} when you print a value.
10697 The simplest use of output formats is to say how to print a value
10698 already computed. This is done by starting the arguments of the
10699 @code{print} command with a slash and a format letter. The format
10700 letters supported are:
10704 Regard the bits of the value as an integer, and print the integer in
10708 Print as integer in signed decimal.
10711 Print as integer in unsigned decimal.
10714 Print as integer in octal.
10717 Print as integer in binary. The letter @samp{t} stands for ``two''.
10718 @footnote{@samp{b} cannot be used because these format letters are also
10719 used with the @code{x} command, where @samp{b} stands for ``byte'';
10720 see @ref{Memory,,Examining Memory}.}
10723 @cindex unknown address, locating
10724 @cindex locate address
10725 Print as an address, both absolute in hexadecimal and as an offset from
10726 the nearest preceding symbol. You can use this format used to discover
10727 where (in what function) an unknown address is located:
10730 (@value{GDBP}) p/a 0x54320
10731 $3 = 0x54320 <_initialize_vx+396>
10735 The command @code{info symbol 0x54320} yields similar results.
10736 @xref{Symbols, info symbol}.
10739 Regard as an integer and print it as a character constant. This
10740 prints both the numerical value and its character representation. The
10741 character representation is replaced with the octal escape @samp{\nnn}
10742 for characters outside the 7-bit @sc{ascii} range.
10744 Without this format, @value{GDBN} displays @code{char},
10745 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10746 constants. Single-byte members of vectors are displayed as integer
10750 Regard the bits of the value as a floating point number and print
10751 using typical floating point syntax.
10754 @cindex printing strings
10755 @cindex printing byte arrays
10756 Regard as a string, if possible. With this format, pointers to single-byte
10757 data are displayed as null-terminated strings and arrays of single-byte data
10758 are displayed as fixed-length strings. Other values are displayed in their
10761 Without this format, @value{GDBN} displays pointers to and arrays of
10762 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10763 strings. Single-byte members of a vector are displayed as an integer
10767 Like @samp{x} formatting, the value is treated as an integer and
10768 printed as hexadecimal, but leading zeros are printed to pad the value
10769 to the size of the integer type.
10772 @cindex raw printing
10773 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10774 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10775 Printing}). This typically results in a higher-level display of the
10776 value's contents. The @samp{r} format bypasses any Python
10777 pretty-printer which might exist.
10780 For example, to print the program counter in hex (@pxref{Registers}), type
10787 Note that no space is required before the slash; this is because command
10788 names in @value{GDBN} cannot contain a slash.
10790 To reprint the last value in the value history with a different format,
10791 you can use the @code{print} command with just a format and no
10792 expression. For example, @samp{p/x} reprints the last value in hex.
10795 @section Examining Memory
10797 You can use the command @code{x} (for ``examine'') to examine memory in
10798 any of several formats, independently of your program's data types.
10800 @cindex examining memory
10802 @kindex x @r{(examine memory)}
10803 @item x/@var{nfu} @var{addr}
10804 @itemx x @var{addr}
10806 Use the @code{x} command to examine memory.
10809 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10810 much memory to display and how to format it; @var{addr} is an
10811 expression giving the address where you want to start displaying memory.
10812 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10813 Several commands set convenient defaults for @var{addr}.
10816 @item @var{n}, the repeat count
10817 The repeat count is a decimal integer; the default is 1. It specifies
10818 how much memory (counting by units @var{u}) to display. If a negative
10819 number is specified, memory is examined backward from @var{addr}.
10820 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10823 @item @var{f}, the display format
10824 The display format is one of the formats used by @code{print}
10825 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10826 @samp{f}, @samp{s}), @samp{i} (for machine instructions) and
10827 @samp{m} (for displaying memory tags).
10828 The default is @samp{x} (hexadecimal) initially. The default changes
10829 each time you use either @code{x} or @code{print}.
10831 @item @var{u}, the unit size
10832 The unit size is any of
10838 Halfwords (two bytes).
10840 Words (four bytes). This is the initial default.
10842 Giant words (eight bytes).
10845 Each time you specify a unit size with @code{x}, that size becomes the
10846 default unit the next time you use @code{x}. For the @samp{i} format,
10847 the unit size is ignored and is normally not written. For the @samp{s} format,
10848 the unit size defaults to @samp{b}, unless it is explicitly given.
10849 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10850 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10851 Note that the results depend on the programming language of the
10852 current compilation unit. If the language is C, the @samp{s}
10853 modifier will use the UTF-16 encoding while @samp{w} will use
10854 UTF-32. The encoding is set by the programming language and cannot
10857 @item @var{addr}, starting display address
10858 @var{addr} is the address where you want @value{GDBN} to begin displaying
10859 memory. The expression need not have a pointer value (though it may);
10860 it is always interpreted as an integer address of a byte of memory.
10861 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10862 @var{addr} is usually just after the last address examined---but several
10863 other commands also set the default address: @code{info breakpoints} (to
10864 the address of the last breakpoint listed), @code{info line} (to the
10865 starting address of a line), and @code{print} (if you use it to display
10866 a value from memory).
10869 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10870 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10871 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10872 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10873 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10875 You can also specify a negative repeat count to examine memory backward
10876 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10877 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10879 Since the letters indicating unit sizes are all distinct from the
10880 letters specifying output formats, you do not have to remember whether
10881 unit size or format comes first; either order works. The output
10882 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10883 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10885 Even though the unit size @var{u} is ignored for the formats @samp{s}
10886 and @samp{i}, you might still want to use a count @var{n}; for example,
10887 @samp{3i} specifies that you want to see three machine instructions,
10888 including any operands. For convenience, especially when used with
10889 the @code{display} command, the @samp{i} format also prints branch delay
10890 slot instructions, if any, beyond the count specified, which immediately
10891 follow the last instruction that is within the count. The command
10892 @code{disassemble} gives an alternative way of inspecting machine
10893 instructions; see @ref{Machine Code,,Source and Machine Code}.
10895 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10896 the command displays null-terminated strings or instructions before the given
10897 address as many as the absolute value of the given number. For the @samp{i}
10898 format, we use line number information in the debug info to accurately locate
10899 instruction boundaries while disassembling backward. If line info is not
10900 available, the command stops examining memory with an error message.
10902 All the defaults for the arguments to @code{x} are designed to make it
10903 easy to continue scanning memory with minimal specifications each time
10904 you use @code{x}. For example, after you have inspected three machine
10905 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10906 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10907 the repeat count @var{n} is used again; the other arguments default as
10908 for successive uses of @code{x}.
10910 When examining machine instructions, the instruction at current program
10911 counter is shown with a @code{=>} marker. For example:
10914 (@value{GDBP}) x/5i $pc-6
10915 0x804837f <main+11>: mov %esp,%ebp
10916 0x8048381 <main+13>: push %ecx
10917 0x8048382 <main+14>: sub $0x4,%esp
10918 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10919 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10922 If the architecture supports memory tagging, the tags can be displayed by
10923 using @samp{m}. @xref{Memory Tagging}.
10925 The information will be displayed once per granule size
10926 (the amount of bytes a particular memory tag covers). For example, AArch64
10927 has a granule size of 16 bytes, so it will display a tag every 16 bytes.
10929 Due to the way @value{GDBN} prints information with the @code{x} command (not
10930 aligned to a particular boundary), the tag information will refer to the
10931 initial address displayed on a particular line. If a memory tag boundary
10932 is crossed in the middle of a line displayed by the @code{x} command, it
10933 will be displayed on the next line.
10935 The @samp{m} format doesn't affect any other specified formats that were
10936 passed to the @code{x} command.
10938 @cindex @code{$_}, @code{$__}, and value history
10939 The addresses and contents printed by the @code{x} command are not saved
10940 in the value history because there is often too much of them and they
10941 would get in the way. Instead, @value{GDBN} makes these values available for
10942 subsequent use in expressions as values of the convenience variables
10943 @code{$_} and @code{$__}. After an @code{x} command, the last address
10944 examined is available for use in expressions in the convenience variable
10945 @code{$_}. The contents of that address, as examined, are available in
10946 the convenience variable @code{$__}.
10948 If the @code{x} command has a repeat count, the address and contents saved
10949 are from the last memory unit printed; this is not the same as the last
10950 address printed if several units were printed on the last line of output.
10952 @anchor{addressable memory unit}
10953 @cindex addressable memory unit
10954 Most targets have an addressable memory unit size of 8 bits. This means
10955 that to each memory address are associated 8 bits of data. Some
10956 targets, however, have other addressable memory unit sizes.
10957 Within @value{GDBN} and this document, the term
10958 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10959 when explicitly referring to a chunk of data of that size. The word
10960 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10961 the addressable memory unit size of the target. For most systems,
10962 addressable memory unit is a synonym of byte.
10964 @cindex remote memory comparison
10965 @cindex target memory comparison
10966 @cindex verify remote memory image
10967 @cindex verify target memory image
10968 When you are debugging a program running on a remote target machine
10969 (@pxref{Remote Debugging}), you may wish to verify the program's image
10970 in the remote machine's memory against the executable file you
10971 downloaded to the target. Or, on any target, you may want to check
10972 whether the program has corrupted its own read-only sections. The
10973 @code{compare-sections} command is provided for such situations.
10976 @kindex compare-sections
10977 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10978 Compare the data of a loadable section @var{section-name} in the
10979 executable file of the program being debugged with the same section in
10980 the target machine's memory, and report any mismatches. With no
10981 arguments, compares all loadable sections. With an argument of
10982 @code{-r}, compares all loadable read-only sections.
10984 Note: for remote targets, this command can be accelerated if the
10985 target supports computing the CRC checksum of a block of memory
10986 (@pxref{qCRC packet}).
10989 @node Memory Tagging
10990 @section Memory Tagging
10992 Memory tagging is a memory protection technology that uses a pair of tags to
10993 validate memory accesses through pointers. The tags are integer values
10994 usually comprised of a few bits, depending on the architecture.
10996 There are two types of tags that are used in this setup: logical and
10997 allocation. A logical tag is stored in the pointers themselves, usually at the
10998 higher bits of the pointers. An allocation tag is the tag associated
10999 with particular ranges of memory in the physical address space, against which
11000 the logical tags from pointers are compared.
11002 The pointer tag (logical tag) must match the memory tag (allocation tag)
11003 for the memory access to be valid. If the logical tag does not match the
11004 allocation tag, that will raise a memory violation.
11006 Allocation tags cover multiple contiguous bytes of physical memory. This
11007 range of bytes is called a memory tag granule and is architecture-specific.
11008 For example, AArch64 has a tag granule of 16 bytes, meaning each allocation
11009 tag spans 16 bytes of memory.
11011 If the underlying architecture supports memory tagging, like AArch64 MTE
11012 or SPARC ADI do, @value{GDBN} can make use of it to validate pointers
11013 against memory allocation tags.
11015 The @code{print} (@pxref{Data}) and @code{x} (@pxref{Memory}) commands will
11016 display tag information when appropriate, and a command prefix of
11017 @code{memory-tag} gives access to the various memory tagging commands.
11019 The @code{memory-tag} commands are the following:
11022 @kindex memory-tag print-logical-tag
11023 @item memory-tag print-logical-tag @var{pointer_expression}
11024 Print the logical tag stored in @var{pointer_expression}.
11025 @kindex memory-tag with-logical-tag
11026 @item memory-tag with-logical-tag @var{pointer_expression} @var{tag_bytes}
11027 Print the pointer given by @var{pointer_expression}, augmented with a logical
11028 tag of @var{tag_bytes}.
11029 @kindex memory-tag print-allocation-tag
11030 @item memory-tag print-allocation-tag @var{address_expression}
11031 Print the allocation tag associated with the memory address given by
11032 @var{address_expression}.
11033 @kindex memory-tag setatag
11034 @item memory-tag setatag @var{starting_address} @var{length} @var{tag_bytes}
11035 Set the allocation tag(s) for memory range @r{[}@var{starting_address},
11036 @var{starting_address} + @var{length}@r{)} to @var{tag_bytes}.
11037 @kindex memory-tag check
11038 @item memory-tag check @var{pointer_expression}
11039 Check if the logical tag in the pointer given by @var{pointer_expression}
11040 matches the allocation tag for the memory referenced by the pointer.
11042 This essentially emulates the hardware validation that is done when tagged
11043 memory is accessed through a pointer, but does not cause a memory fault as
11044 it would during hardware validation.
11046 It can be used to inspect potential memory tagging violations in the running
11047 process, before any faults get triggered.
11051 @section Automatic Display
11052 @cindex automatic display
11053 @cindex display of expressions
11055 If you find that you want to print the value of an expression frequently
11056 (to see how it changes), you might want to add it to the @dfn{automatic
11057 display list} so that @value{GDBN} prints its value each time your program stops.
11058 Each expression added to the list is given a number to identify it;
11059 to remove an expression from the list, you specify that number.
11060 The automatic display looks like this:
11064 3: bar[5] = (struct hack *) 0x3804
11068 This display shows item numbers, expressions and their current values. As with
11069 displays you request manually using @code{x} or @code{print}, you can
11070 specify the output format you prefer; in fact, @code{display} decides
11071 whether to use @code{print} or @code{x} depending your format
11072 specification---it uses @code{x} if you specify either the @samp{i}
11073 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
11077 @item display @var{expr}
11078 Add the expression @var{expr} to the list of expressions to display
11079 each time your program stops. @xref{Expressions, ,Expressions}.
11081 @code{display} does not repeat if you press @key{RET} again after using it.
11083 @item display/@var{fmt} @var{expr}
11084 For @var{fmt} specifying only a display format and not a size or
11085 count, add the expression @var{expr} to the auto-display list but
11086 arrange to display it each time in the specified format @var{fmt}.
11087 @xref{Output Formats,,Output Formats}.
11089 @item display/@var{fmt} @var{addr}
11090 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
11091 number of units, add the expression @var{addr} as a memory address to
11092 be examined each time your program stops. Examining means in effect
11093 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
11096 For example, @samp{display/i $pc} can be helpful, to see the machine
11097 instruction about to be executed each time execution stops (@samp{$pc}
11098 is a common name for the program counter; @pxref{Registers, ,Registers}).
11101 @kindex delete display
11103 @item undisplay @var{dnums}@dots{}
11104 @itemx delete display @var{dnums}@dots{}
11105 Remove items from the list of expressions to display. Specify the
11106 numbers of the displays that you want affected with the command
11107 argument @var{dnums}. It can be a single display number, one of the
11108 numbers shown in the first field of the @samp{info display} display;
11109 or it could be a range of display numbers, as in @code{2-4}.
11111 @code{undisplay} does not repeat if you press @key{RET} after using it.
11112 (Otherwise you would just get the error @samp{No display number @dots{}}.)
11114 @kindex disable display
11115 @item disable display @var{dnums}@dots{}
11116 Disable the display of item numbers @var{dnums}. A disabled display
11117 item is not printed automatically, but is not forgotten. It may be
11118 enabled again later. Specify the numbers of the displays that you
11119 want affected with the command argument @var{dnums}. It can be a
11120 single display number, one of the numbers shown in the first field of
11121 the @samp{info display} display; or it could be a range of display
11122 numbers, as in @code{2-4}.
11124 @kindex enable display
11125 @item enable display @var{dnums}@dots{}
11126 Enable display of item numbers @var{dnums}. It becomes effective once
11127 again in auto display of its expression, until you specify otherwise.
11128 Specify the numbers of the displays that you want affected with the
11129 command argument @var{dnums}. It can be a single display number, one
11130 of the numbers shown in the first field of the @samp{info display}
11131 display; or it could be a range of display numbers, as in @code{2-4}.
11134 Display the current values of the expressions on the list, just as is
11135 done when your program stops.
11137 @kindex info display
11139 Print the list of expressions previously set up to display
11140 automatically, each one with its item number, but without showing the
11141 values. This includes disabled expressions, which are marked as such.
11142 It also includes expressions which would not be displayed right now
11143 because they refer to automatic variables not currently available.
11146 @cindex display disabled out of scope
11147 If a display expression refers to local variables, then it does not make
11148 sense outside the lexical context for which it was set up. Such an
11149 expression is disabled when execution enters a context where one of its
11150 variables is not defined. For example, if you give the command
11151 @code{display last_char} while inside a function with an argument
11152 @code{last_char}, @value{GDBN} displays this argument while your program
11153 continues to stop inside that function. When it stops elsewhere---where
11154 there is no variable @code{last_char}---the display is disabled
11155 automatically. The next time your program stops where @code{last_char}
11156 is meaningful, you can enable the display expression once again.
11158 @node Print Settings
11159 @section Print Settings
11161 @cindex format options
11162 @cindex print settings
11163 @value{GDBN} provides the following ways to control how arrays, structures,
11164 and symbols are printed.
11167 These settings are useful for debugging programs in any language:
11171 @anchor{set print address}
11172 @item set print address
11173 @itemx set print address on
11174 @cindex print/don't print memory addresses
11175 @value{GDBN} prints memory addresses showing the location of stack
11176 traces, structure values, pointer values, breakpoints, and so forth,
11177 even when it also displays the contents of those addresses. The default
11178 is @code{on}. For example, this is what a stack frame display looks like with
11179 @code{set print address on}:
11184 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11186 530 if (lquote != def_lquote)
11190 @item set print address off
11191 Do not print addresses when displaying their contents. For example,
11192 this is the same stack frame displayed with @code{set print address off}:
11196 (@value{GDBP}) set print addr off
11198 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11199 530 if (lquote != def_lquote)
11203 You can use @samp{set print address off} to eliminate all machine
11204 dependent displays from the @value{GDBN} interface. For example, with
11205 @code{print address off}, you should get the same text for backtraces on
11206 all machines---whether or not they involve pointer arguments.
11209 @item show print address
11210 Show whether or not addresses are to be printed.
11213 When @value{GDBN} prints a symbolic address, it normally prints the
11214 closest earlier symbol plus an offset. If that symbol does not uniquely
11215 identify the address (for example, it is a name whose scope is a single
11216 source file), you may need to clarify. One way to do this is with
11217 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11218 you can set @value{GDBN} to print the source file and line number when
11219 it prints a symbolic address:
11222 @item set print symbol-filename on
11223 @cindex source file and line of a symbol
11224 @cindex symbol, source file and line
11225 Tell @value{GDBN} to print the source file name and line number of a
11226 symbol in the symbolic form of an address.
11228 @item set print symbol-filename off
11229 Do not print source file name and line number of a symbol. This is the
11232 @item show print symbol-filename
11233 Show whether or not @value{GDBN} will print the source file name and
11234 line number of a symbol in the symbolic form of an address.
11237 Another situation where it is helpful to show symbol filenames and line
11238 numbers is when disassembling code; @value{GDBN} shows you the line
11239 number and source file that corresponds to each instruction.
11241 Also, you may wish to see the symbolic form only if the address being
11242 printed is reasonably close to the closest earlier symbol:
11245 @item set print max-symbolic-offset @var{max-offset}
11246 @itemx set print max-symbolic-offset unlimited
11247 @cindex maximum value for offset of closest symbol
11248 Tell @value{GDBN} to only display the symbolic form of an address if the
11249 offset between the closest earlier symbol and the address is less than
11250 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11251 to always print the symbolic form of an address if any symbol precedes
11252 it. Zero is equivalent to @code{unlimited}.
11254 @item show print max-symbolic-offset
11255 Ask how large the maximum offset is that @value{GDBN} prints in a
11259 @cindex wild pointer, interpreting
11260 @cindex pointer, finding referent
11261 If you have a pointer and you are not sure where it points, try
11262 @samp{set print symbol-filename on}. Then you can determine the name
11263 and source file location of the variable where it points, using
11264 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11265 For example, here @value{GDBN} shows that a variable @code{ptt} points
11266 at another variable @code{t}, defined in @file{hi2.c}:
11269 (@value{GDBP}) set print symbol-filename on
11270 (@value{GDBP}) p/a ptt
11271 $4 = 0xe008 <t in hi2.c>
11275 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11276 does not show the symbol name and filename of the referent, even with
11277 the appropriate @code{set print} options turned on.
11280 You can also enable @samp{/a}-like formatting all the time using
11281 @samp{set print symbol on}:
11283 @anchor{set print symbol}
11285 @item set print symbol on
11286 Tell @value{GDBN} to print the symbol corresponding to an address, if
11289 @item set print symbol off
11290 Tell @value{GDBN} not to print the symbol corresponding to an
11291 address. In this mode, @value{GDBN} will still print the symbol
11292 corresponding to pointers to functions. This is the default.
11294 @item show print symbol
11295 Show whether @value{GDBN} will display the symbol corresponding to an
11299 Other settings control how different kinds of objects are printed:
11302 @anchor{set print array}
11303 @item set print array
11304 @itemx set print array on
11305 @cindex pretty print arrays
11306 Pretty print arrays. This format is more convenient to read,
11307 but uses more space. The default is off.
11309 @item set print array off
11310 Return to compressed format for arrays.
11312 @item show print array
11313 Show whether compressed or pretty format is selected for displaying
11316 @cindex print array indexes
11317 @anchor{set print array-indexes}
11318 @item set print array-indexes
11319 @itemx set print array-indexes on
11320 Print the index of each element when displaying arrays. May be more
11321 convenient to locate a given element in the array or quickly find the
11322 index of a given element in that printed array. The default is off.
11324 @item set print array-indexes off
11325 Stop printing element indexes when displaying arrays.
11327 @item show print array-indexes
11328 Show whether the index of each element is printed when displaying
11331 @anchor{set print elements}
11332 @item set print elements @var{number-of-elements}
11333 @itemx set print elements unlimited
11334 @cindex number of array elements to print
11335 @cindex limit on number of printed array elements
11336 Set a limit on how many elements of an array @value{GDBN} will print.
11337 If @value{GDBN} is printing a large array, it stops printing after it has
11338 printed the number of elements set by the @code{set print elements} command.
11339 This limit also applies to the display of strings.
11340 When @value{GDBN} starts, this limit is set to 200.
11341 Setting @var{number-of-elements} to @code{unlimited} or zero means
11342 that the number of elements to print is unlimited.
11344 @item show print elements
11345 Display the number of elements of a large array that @value{GDBN} will print.
11346 If the number is 0, then the printing is unlimited.
11348 @anchor{set print frame-arguments}
11349 @item set print frame-arguments @var{value}
11350 @kindex set print frame-arguments
11351 @cindex printing frame argument values
11352 @cindex print all frame argument values
11353 @cindex print frame argument values for scalars only
11354 @cindex do not print frame arguments
11355 This command allows to control how the values of arguments are printed
11356 when the debugger prints a frame (@pxref{Frames}). The possible
11361 The values of all arguments are printed.
11364 Print the value of an argument only if it is a scalar. The value of more
11365 complex arguments such as arrays, structures, unions, etc, is replaced
11366 by @code{@dots{}}. This is the default. Here is an example where
11367 only scalar arguments are shown:
11370 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11375 None of the argument values are printed. Instead, the value of each argument
11376 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11379 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11384 Only the presence of arguments is indicated by @code{@dots{}}.
11385 The @code{@dots{}} are not printed for function without any arguments.
11386 None of the argument names and values are printed.
11387 In this case, the example above now becomes:
11390 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11395 By default, only scalar arguments are printed. This command can be used
11396 to configure the debugger to print the value of all arguments, regardless
11397 of their type. However, it is often advantageous to not print the value
11398 of more complex parameters. For instance, it reduces the amount of
11399 information printed in each frame, making the backtrace more readable.
11400 Also, it improves performance when displaying Ada frames, because
11401 the computation of large arguments can sometimes be CPU-intensive,
11402 especially in large applications. Setting @code{print frame-arguments}
11403 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11404 this computation, thus speeding up the display of each Ada frame.
11406 @item show print frame-arguments
11407 Show how the value of arguments should be displayed when printing a frame.
11409 @anchor{set print raw-frame-arguments}
11410 @item set print raw-frame-arguments on
11411 Print frame arguments in raw, non pretty-printed, form.
11413 @item set print raw-frame-arguments off
11414 Print frame arguments in pretty-printed form, if there is a pretty-printer
11415 for the value (@pxref{Pretty Printing}),
11416 otherwise print the value in raw form.
11417 This is the default.
11419 @item show print raw-frame-arguments
11420 Show whether to print frame arguments in raw form.
11422 @anchor{set print entry-values}
11423 @item set print entry-values @var{value}
11424 @kindex set print entry-values
11425 Set printing of frame argument values at function entry. In some cases
11426 @value{GDBN} can determine the value of function argument which was passed by
11427 the function caller, even if the value was modified inside the called function
11428 and therefore is different. With optimized code, the current value could be
11429 unavailable, but the entry value may still be known.
11431 The default value is @code{default} (see below for its description). Older
11432 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11433 this feature will behave in the @code{default} setting the same way as with the
11436 This functionality is currently supported only by DWARF 2 debugging format and
11437 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11438 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11441 The @var{value} parameter can be one of the following:
11445 Print only actual parameter values, never print values from function entry
11449 #0 different (val=6)
11450 #0 lost (val=<optimized out>)
11452 #0 invalid (val=<optimized out>)
11456 Print only parameter values from function entry point. The actual parameter
11457 values are never printed.
11459 #0 equal (val@@entry=5)
11460 #0 different (val@@entry=5)
11461 #0 lost (val@@entry=5)
11462 #0 born (val@@entry=<optimized out>)
11463 #0 invalid (val@@entry=<optimized out>)
11467 Print only parameter values from function entry point. If value from function
11468 entry point is not known while the actual value is known, print the actual
11469 value for such parameter.
11471 #0 equal (val@@entry=5)
11472 #0 different (val@@entry=5)
11473 #0 lost (val@@entry=5)
11475 #0 invalid (val@@entry=<optimized out>)
11479 Print actual parameter values. If actual parameter value is not known while
11480 value from function entry point is known, print the entry point value for such
11484 #0 different (val=6)
11485 #0 lost (val@@entry=5)
11487 #0 invalid (val=<optimized out>)
11491 Always print both the actual parameter value and its value from function entry
11492 point, even if values of one or both are not available due to compiler
11495 #0 equal (val=5, val@@entry=5)
11496 #0 different (val=6, val@@entry=5)
11497 #0 lost (val=<optimized out>, val@@entry=5)
11498 #0 born (val=10, val@@entry=<optimized out>)
11499 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11503 Print the actual parameter value if it is known and also its value from
11504 function entry point if it is known. If neither is known, print for the actual
11505 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11506 values are known and identical, print the shortened
11507 @code{param=param@@entry=VALUE} notation.
11509 #0 equal (val=val@@entry=5)
11510 #0 different (val=6, val@@entry=5)
11511 #0 lost (val@@entry=5)
11513 #0 invalid (val=<optimized out>)
11517 Always print the actual parameter value. Print also its value from function
11518 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11519 if both values are known and identical, print the shortened
11520 @code{param=param@@entry=VALUE} notation.
11522 #0 equal (val=val@@entry=5)
11523 #0 different (val=6, val@@entry=5)
11524 #0 lost (val=<optimized out>, val@@entry=5)
11526 #0 invalid (val=<optimized out>)
11530 For analysis messages on possible failures of frame argument values at function
11531 entry resolution see @ref{set debug entry-values}.
11533 @item show print entry-values
11534 Show the method being used for printing of frame argument values at function
11537 @anchor{set print frame-info}
11538 @item set print frame-info @var{value}
11539 @kindex set print frame-info
11540 @cindex printing frame information
11541 @cindex frame information, printing
11542 This command allows to control the information printed when
11543 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11544 for a general explanation about frames and frame information.
11545 Note that some other settings (such as @code{set print frame-arguments}
11546 and @code{set print address}) are also influencing if and how some frame
11547 information is displayed. In particular, the frame program counter is never
11548 printed if @code{set print address} is off.
11550 The possible values for @code{set print frame-info} are:
11552 @item short-location
11553 Print the frame level, the program counter (if not at the
11554 beginning of the location source line), the function, the function
11557 Same as @code{short-location} but also print the source file and source line
11559 @item location-and-address
11560 Same as @code{location} but print the program counter even if located at the
11561 beginning of the location source line.
11563 Print the program counter (if not at the beginning of the location
11564 source line), the line number and the source line.
11565 @item source-and-location
11566 Print what @code{location} and @code{source-line} are printing.
11568 The information printed for a frame is decided automatically
11569 by the @value{GDBN} command that prints a frame.
11570 For example, @code{frame} prints the information printed by
11571 @code{source-and-location} while @code{stepi} will switch between
11572 @code{source-line} and @code{source-and-location} depending on the program
11574 The default value is @code{auto}.
11577 @anchor{set print repeats}
11578 @item set print repeats @var{number-of-repeats}
11579 @itemx set print repeats unlimited
11580 @cindex repeated array elements
11581 Set the threshold for suppressing display of repeated array
11582 elements. When the number of consecutive identical elements of an
11583 array exceeds the threshold, @value{GDBN} prints the string
11584 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11585 identical repetitions, instead of displaying the identical elements
11586 themselves. Setting the threshold to @code{unlimited} or zero will
11587 cause all elements to be individually printed. The default threshold
11590 @item show print repeats
11591 Display the current threshold for printing repeated identical
11594 @anchor{set print max-depth}
11595 @item set print max-depth @var{depth}
11596 @item set print max-depth unlimited
11597 @cindex printing nested structures
11598 Set the threshold after which nested structures are replaced with
11599 ellipsis, this can make visualising deeply nested structures easier.
11601 For example, given this C code
11604 typedef struct s1 @{ int a; @} s1;
11605 typedef struct s2 @{ s1 b; @} s2;
11606 typedef struct s3 @{ s2 c; @} s3;
11607 typedef struct s4 @{ s3 d; @} s4;
11609 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11612 The following table shows how different values of @var{depth} will
11613 effect how @code{var} is printed by @value{GDBN}:
11615 @multitable @columnfractions .3 .7
11616 @headitem @var{depth} setting @tab Result of @samp{p var}
11618 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11620 @tab @code{$1 = @{...@}}
11622 @tab @code{$1 = @{d = @{...@}@}}
11624 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11626 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11628 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11631 To see the contents of structures that have been hidden the user can
11632 either increase the print max-depth, or they can print the elements of
11633 the structure that are visible, for example
11636 (gdb) set print max-depth 2
11638 $1 = @{d = @{c = @{...@}@}@}
11640 $2 = @{c = @{b = @{...@}@}@}
11642 $3 = @{b = @{a = 3@}@}
11645 The pattern used to replace nested structures varies based on
11646 language, for most languages @code{@{...@}} is used, but Fortran uses
11649 @item show print max-depth
11650 Display the current threshold after which nested structures are
11651 replaces with ellipsis.
11653 @anchor{set print memory-tag-violations}
11654 @cindex printing memory tag violation information
11655 @item set print memory-tag-violations
11656 @itemx set print memory-tag-violations on
11657 Cause @value{GDBN} to display additional information about memory tag violations
11658 when printing pointers and addresses.
11660 @item set print memory-tag-violations off
11661 Stop printing memory tag violation information.
11663 @item show print memory-tag-violations
11664 Show whether memory tag violation information is displayed when printing
11665 pointers and addresses.
11667 @anchor{set print null-stop}
11668 @item set print null-stop
11669 @cindex @sc{null} elements in arrays
11670 Cause @value{GDBN} to stop printing the characters of an array when the first
11671 @sc{null} is encountered. This is useful when large arrays actually
11672 contain only short strings.
11673 The default is off.
11675 @item show print null-stop
11676 Show whether @value{GDBN} stops printing an array on the first
11677 @sc{null} character.
11679 @anchor{set print pretty}
11680 @item set print pretty on
11681 @cindex print structures in indented form
11682 @cindex indentation in structure display
11683 Cause @value{GDBN} to print structures in an indented format with one member
11684 per line, like this:
11699 @item set print pretty off
11700 Cause @value{GDBN} to print structures in a compact format, like this:
11704 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11705 meat = 0x54 "Pork"@}
11710 This is the default format.
11712 @item show print pretty
11713 Show which format @value{GDBN} is using to print structures.
11715 @anchor{set print raw-values}
11716 @item set print raw-values on
11717 Print values in raw form, without applying the pretty
11718 printers for the value.
11720 @item set print raw-values off
11721 Print values in pretty-printed form, if there is a pretty-printer
11722 for the value (@pxref{Pretty Printing}),
11723 otherwise print the value in raw form.
11725 The default setting is ``off''.
11727 @item show print raw-values
11728 Show whether to print values in raw form.
11730 @item set print sevenbit-strings on
11731 @cindex eight-bit characters in strings
11732 @cindex octal escapes in strings
11733 Print using only seven-bit characters; if this option is set,
11734 @value{GDBN} displays any eight-bit characters (in strings or
11735 character values) using the notation @code{\}@var{nnn}. This setting is
11736 best if you are working in English (@sc{ascii}) and you use the
11737 high-order bit of characters as a marker or ``meta'' bit.
11739 @item set print sevenbit-strings off
11740 Print full eight-bit characters. This allows the use of more
11741 international character sets, and is the default.
11743 @item show print sevenbit-strings
11744 Show whether or not @value{GDBN} is printing only seven-bit characters.
11746 @anchor{set print union}
11747 @item set print union on
11748 @cindex unions in structures, printing
11749 Tell @value{GDBN} to print unions which are contained in structures
11750 and other unions. This is the default setting.
11752 @item set print union off
11753 Tell @value{GDBN} not to print unions which are contained in
11754 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11757 @item show print union
11758 Ask @value{GDBN} whether or not it will print unions which are contained in
11759 structures and other unions.
11761 For example, given the declarations
11764 typedef enum @{Tree, Bug@} Species;
11765 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11766 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11777 struct thing foo = @{Tree, @{Acorn@}@};
11781 with @code{set print union on} in effect @samp{p foo} would print
11784 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11788 and with @code{set print union off} in effect it would print
11791 $1 = @{it = Tree, form = @{...@}@}
11795 @code{set print union} affects programs written in C-like languages
11801 These settings are of interest when debugging C@t{++} programs:
11804 @cindex demangling C@t{++} names
11805 @item set print demangle
11806 @itemx set print demangle on
11807 Print C@t{++} names in their source form rather than in the encoded
11808 (``mangled'') form passed to the assembler and linker for type-safe
11809 linkage. The default is on.
11811 @item show print demangle
11812 Show whether C@t{++} names are printed in mangled or demangled form.
11814 @item set print asm-demangle
11815 @itemx set print asm-demangle on
11816 Print C@t{++} names in their source form rather than their mangled form, even
11817 in assembler code printouts such as instruction disassemblies.
11818 The default is off.
11820 @item show print asm-demangle
11821 Show whether C@t{++} names in assembly listings are printed in mangled
11824 @cindex C@t{++} symbol decoding style
11825 @cindex symbol decoding style, C@t{++}
11826 @kindex set demangle-style
11827 @item set demangle-style @var{style}
11828 Choose among several encoding schemes used by different compilers to represent
11829 C@t{++} names. If you omit @var{style}, you will see a list of possible
11830 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11831 decoding style by inspecting your program.
11833 @item show demangle-style
11834 Display the encoding style currently in use for decoding C@t{++} symbols.
11836 @anchor{set print object}
11837 @item set print object
11838 @itemx set print object on
11839 @cindex derived type of an object, printing
11840 @cindex display derived types
11841 When displaying a pointer to an object, identify the @emph{actual}
11842 (derived) type of the object rather than the @emph{declared} type, using
11843 the virtual function table. Note that the virtual function table is
11844 required---this feature can only work for objects that have run-time
11845 type identification; a single virtual method in the object's declared
11846 type is sufficient. Note that this setting is also taken into account when
11847 working with variable objects via MI (@pxref{GDB/MI}).
11849 @item set print object off
11850 Display only the declared type of objects, without reference to the
11851 virtual function table. This is the default setting.
11853 @item show print object
11854 Show whether actual, or declared, object types are displayed.
11856 @anchor{set print static-members}
11857 @item set print static-members
11858 @itemx set print static-members on
11859 @cindex static members of C@t{++} objects
11860 Print static members when displaying a C@t{++} object. The default is on.
11862 @item set print static-members off
11863 Do not print static members when displaying a C@t{++} object.
11865 @item show print static-members
11866 Show whether C@t{++} static members are printed or not.
11868 @item set print pascal_static-members
11869 @itemx set print pascal_static-members on
11870 @cindex static members of Pascal objects
11871 @cindex Pascal objects, static members display
11872 Print static members when displaying a Pascal object. The default is on.
11874 @item set print pascal_static-members off
11875 Do not print static members when displaying a Pascal object.
11877 @item show print pascal_static-members
11878 Show whether Pascal static members are printed or not.
11880 @c These don't work with HP ANSI C++ yet.
11881 @anchor{set print vtbl}
11882 @item set print vtbl
11883 @itemx set print vtbl on
11884 @cindex pretty print C@t{++} virtual function tables
11885 @cindex virtual functions (C@t{++}) display
11886 @cindex VTBL display
11887 Pretty print C@t{++} virtual function tables. The default is off.
11888 (The @code{vtbl} commands do not work on programs compiled with the HP
11889 ANSI C@t{++} compiler (@code{aCC}).)
11891 @item set print vtbl off
11892 Do not pretty print C@t{++} virtual function tables.
11894 @item show print vtbl
11895 Show whether C@t{++} virtual function tables are pretty printed, or not.
11898 @node Pretty Printing
11899 @section Pretty Printing
11901 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11902 Python code. It greatly simplifies the display of complex objects. This
11903 mechanism works for both MI and the CLI.
11906 * Pretty-Printer Introduction:: Introduction to pretty-printers
11907 * Pretty-Printer Example:: An example pretty-printer
11908 * Pretty-Printer Commands:: Pretty-printer commands
11911 @node Pretty-Printer Introduction
11912 @subsection Pretty-Printer Introduction
11914 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11915 registered for the value. If there is then @value{GDBN} invokes the
11916 pretty-printer to print the value. Otherwise the value is printed normally.
11918 Pretty-printers are normally named. This makes them easy to manage.
11919 The @samp{info pretty-printer} command will list all the installed
11920 pretty-printers with their names.
11921 If a pretty-printer can handle multiple data types, then its
11922 @dfn{subprinters} are the printers for the individual data types.
11923 Each such subprinter has its own name.
11924 The format of the name is @var{printer-name};@var{subprinter-name}.
11926 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11927 Typically they are automatically loaded and registered when the corresponding
11928 debug information is loaded, thus making them available without having to
11929 do anything special.
11931 There are three places where a pretty-printer can be registered.
11935 Pretty-printers registered globally are available when debugging
11939 Pretty-printers registered with a program space are available only
11940 when debugging that program.
11941 @xref{Progspaces In Python}, for more details on program spaces in Python.
11944 Pretty-printers registered with an objfile are loaded and unloaded
11945 with the corresponding objfile (e.g., shared library).
11946 @xref{Objfiles In Python}, for more details on objfiles in Python.
11949 @xref{Selecting Pretty-Printers}, for further information on how
11950 pretty-printers are selected,
11952 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11955 @node Pretty-Printer Example
11956 @subsection Pretty-Printer Example
11958 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11961 (@value{GDBP}) print s
11963 static npos = 4294967295,
11965 <std::allocator<char>> = @{
11966 <__gnu_cxx::new_allocator<char>> = @{
11967 <No data fields>@}, <No data fields>
11969 members of std::basic_string<char, std::char_traits<char>,
11970 std::allocator<char> >::_Alloc_hider:
11971 _M_p = 0x804a014 "abcd"
11976 With a pretty-printer for @code{std::string} only the contents are printed:
11979 (@value{GDBP}) print s
11983 @node Pretty-Printer Commands
11984 @subsection Pretty-Printer Commands
11985 @cindex pretty-printer commands
11988 @kindex info pretty-printer
11989 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11990 Print the list of installed pretty-printers.
11991 This includes disabled pretty-printers, which are marked as such.
11993 @var{object-regexp} is a regular expression matching the objects
11994 whose pretty-printers to list.
11995 Objects can be @code{global}, the program space's file
11996 (@pxref{Progspaces In Python}),
11997 and the object files within that program space (@pxref{Objfiles In Python}).
11998 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11999 looks up a printer from these three objects.
12001 @var{name-regexp} is a regular expression matching the name of the printers
12004 @kindex disable pretty-printer
12005 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12006 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12007 A disabled pretty-printer is not forgotten, it may be enabled again later.
12009 @kindex enable pretty-printer
12010 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12011 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12016 Suppose we have three pretty-printers installed: one from library1.so
12017 named @code{foo} that prints objects of type @code{foo}, and
12018 another from library2.so named @code{bar} that prints two types of objects,
12019 @code{bar1} and @code{bar2}.
12022 (gdb) info pretty-printer
12029 (gdb) info pretty-printer library2
12034 (gdb) disable pretty-printer library1
12036 2 of 3 printers enabled
12037 (gdb) info pretty-printer
12044 (gdb) disable pretty-printer library2 bar;bar1
12046 1 of 3 printers enabled
12047 (gdb) info pretty-printer library2
12054 (gdb) disable pretty-printer library2 bar
12056 0 of 3 printers enabled
12057 (gdb) info pretty-printer library2
12066 Note that for @code{bar} the entire printer can be disabled,
12067 as can each individual subprinter.
12069 Printing values and frame arguments is done by default using
12070 the enabled pretty printers.
12072 The print option @code{-raw-values} and @value{GDBN} setting
12073 @code{set print raw-values} (@pxref{set print raw-values}) can be
12074 used to print values without applying the enabled pretty printers.
12076 Similarly, the backtrace option @code{-raw-frame-arguments} and
12077 @value{GDBN} setting @code{set print raw-frame-arguments}
12078 (@pxref{set print raw-frame-arguments}) can be used to ignore the
12079 enabled pretty printers when printing frame argument values.
12081 @node Value History
12082 @section Value History
12084 @cindex value history
12085 @cindex history of values printed by @value{GDBN}
12086 Values printed by the @code{print} command are saved in the @value{GDBN}
12087 @dfn{value history}. This allows you to refer to them in other expressions.
12088 Values are kept until the symbol table is re-read or discarded
12089 (for example with the @code{file} or @code{symbol-file} commands).
12090 When the symbol table changes, the value history is discarded,
12091 since the values may contain pointers back to the types defined in the
12096 @cindex history number
12097 The values printed are given @dfn{history numbers} by which you can
12098 refer to them. These are successive integers starting with one.
12099 @code{print} shows you the history number assigned to a value by
12100 printing @samp{$@var{num} = } before the value; here @var{num} is the
12103 To refer to any previous value, use @samp{$} followed by the value's
12104 history number. The way @code{print} labels its output is designed to
12105 remind you of this. Just @code{$} refers to the most recent value in
12106 the history, and @code{$$} refers to the value before that.
12107 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
12108 is the value just prior to @code{$$}, @code{$$1} is equivalent to
12109 @code{$$}, and @code{$$0} is equivalent to @code{$}.
12111 For example, suppose you have just printed a pointer to a structure and
12112 want to see the contents of the structure. It suffices to type
12118 If you have a chain of structures where the component @code{next} points
12119 to the next one, you can print the contents of the next one with this:
12126 You can print successive links in the chain by repeating this
12127 command---which you can do by just typing @key{RET}.
12129 Note that the history records values, not expressions. If the value of
12130 @code{x} is 4 and you type these commands:
12138 then the value recorded in the value history by the @code{print} command
12139 remains 4 even though the value of @code{x} has changed.
12142 @kindex show values
12144 Print the last ten values in the value history, with their item numbers.
12145 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12146 values} does not change the history.
12148 @item show values @var{n}
12149 Print ten history values centered on history item number @var{n}.
12151 @item show values +
12152 Print ten history values just after the values last printed. If no more
12153 values are available, @code{show values +} produces no display.
12156 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12157 same effect as @samp{show values +}.
12159 @node Convenience Vars
12160 @section Convenience Variables
12162 @cindex convenience variables
12163 @cindex user-defined variables
12164 @value{GDBN} provides @dfn{convenience variables} that you can use within
12165 @value{GDBN} to hold on to a value and refer to it later. These variables
12166 exist entirely within @value{GDBN}; they are not part of your program, and
12167 setting a convenience variable has no direct effect on further execution
12168 of your program. That is why you can use them freely.
12170 Convenience variables are prefixed with @samp{$}. Any name preceded by
12171 @samp{$} can be used for a convenience variable, unless it is one of
12172 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12173 (Value history references, in contrast, are @emph{numbers} preceded
12174 by @samp{$}. @xref{Value History, ,Value History}.)
12176 You can save a value in a convenience variable with an assignment
12177 expression, just as you would set a variable in your program.
12181 set $foo = *object_ptr
12185 would save in @code{$foo} the value contained in the object pointed to by
12188 Using a convenience variable for the first time creates it, but its
12189 value is @code{void} until you assign a new value. You can alter the
12190 value with another assignment at any time.
12192 Convenience variables have no fixed types. You can assign a convenience
12193 variable any type of value, including structures and arrays, even if
12194 that variable already has a value of a different type. The convenience
12195 variable, when used as an expression, has the type of its current value.
12198 @kindex show convenience
12199 @cindex show all user variables and functions
12200 @item show convenience
12201 Print a list of convenience variables used so far, and their values,
12202 as well as a list of the convenience functions.
12203 Abbreviated @code{show conv}.
12205 @kindex init-if-undefined
12206 @cindex convenience variables, initializing
12207 @item init-if-undefined $@var{variable} = @var{expression}
12208 Set a convenience variable if it has not already been set. This is useful
12209 for user-defined commands that keep some state. It is similar, in concept,
12210 to using local static variables with initializers in C (except that
12211 convenience variables are global). It can also be used to allow users to
12212 override default values used in a command script.
12214 If the variable is already defined then the expression is not evaluated so
12215 any side-effects do not occur.
12218 One of the ways to use a convenience variable is as a counter to be
12219 incremented or a pointer to be advanced. For example, to print
12220 a field from successive elements of an array of structures:
12224 print bar[$i++]->contents
12228 Repeat that command by typing @key{RET}.
12230 Some convenience variables are created automatically by @value{GDBN} and given
12231 values likely to be useful.
12234 @vindex $_@r{, convenience variable}
12236 The variable @code{$_} is automatically set by the @code{x} command to
12237 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12238 commands which provide a default address for @code{x} to examine also
12239 set @code{$_} to that address; these commands include @code{info line}
12240 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12241 except when set by the @code{x} command, in which case it is a pointer
12242 to the type of @code{$__}.
12244 @vindex $__@r{, convenience variable}
12246 The variable @code{$__} is automatically set by the @code{x} command
12247 to the value found in the last address examined. Its type is chosen
12248 to match the format in which the data was printed.
12251 @vindex $_exitcode@r{, convenience variable}
12252 When the program being debugged terminates normally, @value{GDBN}
12253 automatically sets this variable to the exit code of the program, and
12254 resets @code{$_exitsignal} to @code{void}.
12257 @vindex $_exitsignal@r{, convenience variable}
12258 When the program being debugged dies due to an uncaught signal,
12259 @value{GDBN} automatically sets this variable to that signal's number,
12260 and resets @code{$_exitcode} to @code{void}.
12262 To distinguish between whether the program being debugged has exited
12263 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12264 @code{$_exitsignal} is not @code{void}), the convenience function
12265 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12266 Functions}). For example, considering the following source code:
12269 #include <signal.h>
12272 main (int argc, char *argv[])
12279 A valid way of telling whether the program being debugged has exited
12280 or signalled would be:
12283 (@value{GDBP}) define has_exited_or_signalled
12284 Type commands for definition of ``has_exited_or_signalled''.
12285 End with a line saying just ``end''.
12286 >if $_isvoid ($_exitsignal)
12287 >echo The program has exited\n
12289 >echo The program has signalled\n
12295 Program terminated with signal SIGALRM, Alarm clock.
12296 The program no longer exists.
12297 (@value{GDBP}) has_exited_or_signalled
12298 The program has signalled
12301 As can be seen, @value{GDBN} correctly informs that the program being
12302 debugged has signalled, since it calls @code{raise} and raises a
12303 @code{SIGALRM} signal. If the program being debugged had not called
12304 @code{raise}, then @value{GDBN} would report a normal exit:
12307 (@value{GDBP}) has_exited_or_signalled
12308 The program has exited
12312 The variable @code{$_exception} is set to the exception object being
12313 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12315 @item $_ada_exception
12316 The variable @code{$_ada_exception} is set to the address of the
12317 exception being caught or thrown at an Ada exception-related
12318 catchpoint. @xref{Set Catchpoints}.
12321 @itemx $_probe_arg0@dots{}$_probe_arg11
12322 Arguments to a static probe. @xref{Static Probe Points}.
12325 @vindex $_sdata@r{, inspect, convenience variable}
12326 The variable @code{$_sdata} contains extra collected static tracepoint
12327 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12328 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12329 if extra static tracepoint data has not been collected.
12332 @vindex $_siginfo@r{, convenience variable}
12333 The variable @code{$_siginfo} contains extra signal information
12334 (@pxref{extra signal information}). Note that @code{$_siginfo}
12335 could be empty, if the application has not yet received any signals.
12336 For example, it will be empty before you execute the @code{run} command.
12339 @vindex $_tlb@r{, convenience variable}
12340 The variable @code{$_tlb} is automatically set when debugging
12341 applications running on MS-Windows in native mode or connected to
12342 gdbserver that supports the @code{qGetTIBAddr} request.
12343 @xref{General Query Packets}.
12344 This variable contains the address of the thread information block.
12347 The number of the current inferior. @xref{Inferiors Connections and
12348 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12351 The thread number of the current thread. @xref{thread numbers}.
12354 The global number of the current thread. @xref{global thread numbers}.
12358 @vindex $_gdb_major@r{, convenience variable}
12359 @vindex $_gdb_minor@r{, convenience variable}
12360 The major and minor version numbers of the running @value{GDBN}.
12361 Development snapshots and pretest versions have their minor version
12362 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12363 the value 12 for @code{$_gdb_minor}. These variables allow you to
12364 write scripts that work with different versions of @value{GDBN}
12365 without errors caused by features unavailable in some of those
12368 @item $_shell_exitcode
12369 @itemx $_shell_exitsignal
12370 @vindex $_shell_exitcode@r{, convenience variable}
12371 @vindex $_shell_exitsignal@r{, convenience variable}
12372 @cindex shell command, exit code
12373 @cindex shell command, exit signal
12374 @cindex exit status of shell commands
12375 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12376 shell commands. When a launched command terminates, @value{GDBN}
12377 automatically maintains the variables @code{$_shell_exitcode}
12378 and @code{$_shell_exitsignal} according to the exit status of the last
12379 launched command. These variables are set and used similarly to
12380 the variables @code{$_exitcode} and @code{$_exitsignal}.
12384 @node Convenience Funs
12385 @section Convenience Functions
12387 @cindex convenience functions
12388 @value{GDBN} also supplies some @dfn{convenience functions}. These
12389 have a syntax similar to convenience variables. A convenience
12390 function can be used in an expression just like an ordinary function;
12391 however, a convenience function is implemented internally to
12394 These functions do not require @value{GDBN} to be configured with
12395 @code{Python} support, which means that they are always available.
12399 @item $_isvoid (@var{expr})
12400 @findex $_isvoid@r{, convenience function}
12401 Return one if the expression @var{expr} is @code{void}. Otherwise it
12404 A @code{void} expression is an expression where the type of the result
12405 is @code{void}. For example, you can examine a convenience variable
12406 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12410 (@value{GDBP}) print $_exitcode
12412 (@value{GDBP}) print $_isvoid ($_exitcode)
12415 Starting program: ./a.out
12416 [Inferior 1 (process 29572) exited normally]
12417 (@value{GDBP}) print $_exitcode
12419 (@value{GDBP}) print $_isvoid ($_exitcode)
12423 In the example above, we used @code{$_isvoid} to check whether
12424 @code{$_exitcode} is @code{void} before and after the execution of the
12425 program being debugged. Before the execution there is no exit code to
12426 be examined, therefore @code{$_exitcode} is @code{void}. After the
12427 execution the program being debugged returned zero, therefore
12428 @code{$_exitcode} is zero, which means that it is not @code{void}
12431 The @code{void} expression can also be a call of a function from the
12432 program being debugged. For example, given the following function:
12441 The result of calling it inside @value{GDBN} is @code{void}:
12444 (@value{GDBP}) print foo ()
12446 (@value{GDBP}) print $_isvoid (foo ())
12448 (@value{GDBP}) set $v = foo ()
12449 (@value{GDBP}) print $v
12451 (@value{GDBP}) print $_isvoid ($v)
12455 @item $_gdb_setting_str (@var{setting})
12456 @findex $_gdb_setting_str@r{, convenience function}
12457 Return the value of the @value{GDBN} @var{setting} as a string.
12458 @var{setting} is any setting that can be used in a @code{set} or
12459 @code{show} command (@pxref{Controlling GDB}).
12462 (@value{GDBP}) show print frame-arguments
12463 Printing of non-scalar frame arguments is "scalars".
12464 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12466 (@value{GDBP}) p $_gdb_setting_str("height")
12471 @item $_gdb_setting (@var{setting})
12472 @findex $_gdb_setting@r{, convenience function}
12473 Return the value of the @value{GDBN} @var{setting}.
12474 The type of the returned value depends on the setting.
12476 The value type for boolean and auto boolean settings is @code{int}.
12477 The boolean values @code{off} and @code{on} are converted to
12478 the integer values @code{0} and @code{1}. The value @code{auto} is
12479 converted to the value @code{-1}.
12481 The value type for integer settings is either @code{unsigned int}
12482 or @code{int}, depending on the setting.
12484 Some integer settings accept an @code{unlimited} value.
12485 Depending on the setting, the @code{set} command also accepts
12486 the value @code{0} or the value @code{@minus{}1} as a synonym for
12488 For example, @code{set height unlimited} is equivalent to
12489 @code{set height 0}.
12491 Some other settings that accept the @code{unlimited} value
12492 use the value @code{0} to literally mean zero.
12493 For example, @code{set history size 0} indicates to not
12494 record any @value{GDBN} commands in the command history.
12495 For such settings, @code{@minus{}1} is the synonym
12496 for @code{unlimited}.
12498 See the documentation of the corresponding @code{set} command for
12499 the numerical value equivalent to @code{unlimited}.
12501 The @code{$_gdb_setting} function converts the unlimited value
12502 to a @code{0} or a @code{@minus{}1} value according to what the
12503 @code{set} command uses.
12507 (@value{GDBP}) p $_gdb_setting_str("height")
12509 (@value{GDBP}) p $_gdb_setting("height")
12511 (@value{GDBP}) set height unlimited
12512 (@value{GDBP}) p $_gdb_setting_str("height")
12514 (@value{GDBP}) p $_gdb_setting("height")
12518 (@value{GDBP}) p $_gdb_setting_str("history size")
12520 (@value{GDBP}) p $_gdb_setting("history size")
12522 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12524 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12530 Other setting types (enum, filename, optional filename, string, string noescape)
12531 are returned as string values.
12534 @item $_gdb_maint_setting_str (@var{setting})
12535 @findex $_gdb_maint_setting_str@r{, convenience function}
12536 Like the @code{$_gdb_setting_str} function, but works with
12537 @code{maintenance set} variables.
12539 @item $_gdb_maint_setting (@var{setting})
12540 @findex $_gdb_maint_setting@r{, convenience function}
12541 Like the @code{$_gdb_setting} function, but works with
12542 @code{maintenance set} variables.
12546 The following functions require @value{GDBN} to be configured with
12547 @code{Python} support.
12551 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12552 @findex $_memeq@r{, convenience function}
12553 Returns one if the @var{length} bytes at the addresses given by
12554 @var{buf1} and @var{buf2} are equal.
12555 Otherwise it returns zero.
12557 @item $_regex(@var{str}, @var{regex})
12558 @findex $_regex@r{, convenience function}
12559 Returns one if the string @var{str} matches the regular expression
12560 @var{regex}. Otherwise it returns zero.
12561 The syntax of the regular expression is that specified by @code{Python}'s
12562 regular expression support.
12564 @item $_streq(@var{str1}, @var{str2})
12565 @findex $_streq@r{, convenience function}
12566 Returns one if the strings @var{str1} and @var{str2} are equal.
12567 Otherwise it returns zero.
12569 @item $_strlen(@var{str})
12570 @findex $_strlen@r{, convenience function}
12571 Returns the length of string @var{str}.
12573 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12574 @findex $_caller_is@r{, convenience function}
12575 Returns one if the calling function's name is equal to @var{name}.
12576 Otherwise it returns zero.
12578 If the optional argument @var{number_of_frames} is provided,
12579 it is the number of frames up in the stack to look.
12587 at testsuite/gdb.python/py-caller-is.c:21
12588 #1 0x00000000004005a0 in middle_func ()
12589 at testsuite/gdb.python/py-caller-is.c:27
12590 #2 0x00000000004005ab in top_func ()
12591 at testsuite/gdb.python/py-caller-is.c:33
12592 #3 0x00000000004005b6 in main ()
12593 at testsuite/gdb.python/py-caller-is.c:39
12594 (gdb) print $_caller_is ("middle_func")
12596 (gdb) print $_caller_is ("top_func", 2)
12600 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12601 @findex $_caller_matches@r{, convenience function}
12602 Returns one if the calling function's name matches the regular expression
12603 @var{regexp}. Otherwise it returns zero.
12605 If the optional argument @var{number_of_frames} is provided,
12606 it is the number of frames up in the stack to look.
12609 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12610 @findex $_any_caller_is@r{, convenience function}
12611 Returns one if any calling function's name is equal to @var{name}.
12612 Otherwise it returns zero.
12614 If the optional argument @var{number_of_frames} is provided,
12615 it is the number of frames up in the stack to look.
12618 This function differs from @code{$_caller_is} in that this function
12619 checks all stack frames from the immediate caller to the frame specified
12620 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12621 frame specified by @var{number_of_frames}.
12623 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12624 @findex $_any_caller_matches@r{, convenience function}
12625 Returns one if any calling function's name matches the regular expression
12626 @var{regexp}. Otherwise it returns zero.
12628 If the optional argument @var{number_of_frames} is provided,
12629 it is the number of frames up in the stack to look.
12632 This function differs from @code{$_caller_matches} in that this function
12633 checks all stack frames from the immediate caller to the frame specified
12634 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12635 frame specified by @var{number_of_frames}.
12637 @item $_as_string(@var{value})
12638 @findex $_as_string@r{, convenience function}
12639 Return the string representation of @var{value}.
12641 This function is useful to obtain the textual label (enumerator) of an
12642 enumeration value. For example, assuming the variable @var{node} is of
12643 an enumerated type:
12646 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12647 Visiting node of type NODE_INTEGER
12650 @item $_cimag(@var{value})
12651 @itemx $_creal(@var{value})
12652 @findex $_cimag@r{, convenience function}
12653 @findex $_creal@r{, convenience function}
12654 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12655 the complex number @var{value}.
12657 The type of the imaginary or real part depends on the type of the
12658 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12659 will return an imaginary part of type @code{float}.
12663 @value{GDBN} provides the ability to list and get help on
12664 convenience functions.
12667 @item help function
12668 @kindex help function
12669 @cindex show all convenience functions
12670 Print a list of all convenience functions.
12677 You can refer to machine register contents, in expressions, as variables
12678 with names starting with @samp{$}. The names of registers are different
12679 for each machine; use @code{info registers} to see the names used on
12683 @kindex info registers
12684 @item info registers
12685 Print the names and values of all registers except floating-point
12686 and vector registers (in the selected stack frame).
12688 @kindex info all-registers
12689 @cindex floating point registers
12690 @item info all-registers
12691 Print the names and values of all registers, including floating-point
12692 and vector registers (in the selected stack frame).
12694 @anchor{info_registers_reggroup}
12695 @item info registers @var{reggroup} @dots{}
12696 Print the name and value of the registers in each of the specified
12697 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12698 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12700 @item info registers @var{regname} @dots{}
12701 Print the @dfn{relativized} value of each specified register @var{regname}.
12702 As discussed in detail below, register values are normally relative to
12703 the selected stack frame. The @var{regname} may be any register name valid on
12704 the machine you are using, with or without the initial @samp{$}.
12707 @anchor{standard registers}
12708 @cindex stack pointer register
12709 @cindex program counter register
12710 @cindex process status register
12711 @cindex frame pointer register
12712 @cindex standard registers
12713 @value{GDBN} has four ``standard'' register names that are available (in
12714 expressions) on most machines---whenever they do not conflict with an
12715 architecture's canonical mnemonics for registers. The register names
12716 @code{$pc} and @code{$sp} are used for the program counter register and
12717 the stack pointer. @code{$fp} is used for a register that contains a
12718 pointer to the current stack frame, and @code{$ps} is used for a
12719 register that contains the processor status. For example,
12720 you could print the program counter in hex with
12727 or print the instruction to be executed next with
12734 or add four to the stack pointer@footnote{This is a way of removing
12735 one word from the stack, on machines where stacks grow downward in
12736 memory (most machines, nowadays). This assumes that the innermost
12737 stack frame is selected; setting @code{$sp} is not allowed when other
12738 stack frames are selected. To pop entire frames off the stack,
12739 regardless of machine architecture, use @code{return};
12740 see @ref{Returning, ,Returning from a Function}.} with
12746 Whenever possible, these four standard register names are available on
12747 your machine even though the machine has different canonical mnemonics,
12748 so long as there is no conflict. The @code{info registers} command
12749 shows the canonical names. For example, on the SPARC, @code{info
12750 registers} displays the processor status register as @code{$psr} but you
12751 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12752 is an alias for the @sc{eflags} register.
12754 @value{GDBN} always considers the contents of an ordinary register as an
12755 integer when the register is examined in this way. Some machines have
12756 special registers which can hold nothing but floating point; these
12757 registers are considered to have floating point values. There is no way
12758 to refer to the contents of an ordinary register as floating point value
12759 (although you can @emph{print} it as a floating point value with
12760 @samp{print/f $@var{regname}}).
12762 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12763 means that the data format in which the register contents are saved by
12764 the operating system is not the same one that your program normally
12765 sees. For example, the registers of the 68881 floating point
12766 coprocessor are always saved in ``extended'' (raw) format, but all C
12767 programs expect to work with ``double'' (virtual) format. In such
12768 cases, @value{GDBN} normally works with the virtual format only (the format
12769 that makes sense for your program), but the @code{info registers} command
12770 prints the data in both formats.
12772 @cindex SSE registers (x86)
12773 @cindex MMX registers (x86)
12774 Some machines have special registers whose contents can be interpreted
12775 in several different ways. For example, modern x86-based machines
12776 have SSE and MMX registers that can hold several values packed
12777 together in several different formats. @value{GDBN} refers to such
12778 registers in @code{struct} notation:
12781 (@value{GDBP}) print $xmm1
12783 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12784 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12785 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12786 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12787 v4_int32 = @{0, 20657912, 11, 13@},
12788 v2_int64 = @{88725056443645952, 55834574859@},
12789 uint128 = 0x0000000d0000000b013b36f800000000
12794 To set values of such registers, you need to tell @value{GDBN} which
12795 view of the register you wish to change, as if you were assigning
12796 value to a @code{struct} member:
12799 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12802 Normally, register values are relative to the selected stack frame
12803 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12804 value that the register would contain if all stack frames farther in
12805 were exited and their saved registers restored. In order to see the
12806 true contents of hardware registers, you must select the innermost
12807 frame (with @samp{frame 0}).
12809 @cindex caller-saved registers
12810 @cindex call-clobbered registers
12811 @cindex volatile registers
12812 @cindex <not saved> values
12813 Usually ABIs reserve some registers as not needed to be saved by the
12814 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12815 registers). It may therefore not be possible for @value{GDBN} to know
12816 the value a register had before the call (in other words, in the outer
12817 frame), if the register value has since been changed by the callee.
12818 @value{GDBN} tries to deduce where the inner frame saved
12819 (``callee-saved'') registers, from the debug info, unwind info, or the
12820 machine code generated by your compiler. If some register is not
12821 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12822 its own knowledge of the ABI, or because the debug/unwind info
12823 explicitly says the register's value is undefined), @value{GDBN}
12824 displays @w{@samp{<not saved>}} as the register's value. With targets
12825 that @value{GDBN} has no knowledge of the register saving convention,
12826 if a register was not saved by the callee, then its value and location
12827 in the outer frame are assumed to be the same of the inner frame.
12828 This is usually harmless, because if the register is call-clobbered,
12829 the caller either does not care what is in the register after the
12830 call, or has code to restore the value that it does care about. Note,
12831 however, that if you change such a register in the outer frame, you
12832 may also be affecting the inner frame. Also, the more ``outer'' the
12833 frame is you're looking at, the more likely a call-clobbered
12834 register's value is to be wrong, in the sense that it doesn't actually
12835 represent the value the register had just before the call.
12837 @node Floating Point Hardware
12838 @section Floating Point Hardware
12839 @cindex floating point
12841 Depending on the configuration, @value{GDBN} may be able to give
12842 you more information about the status of the floating point hardware.
12847 Display hardware-dependent information about the floating
12848 point unit. The exact contents and layout vary depending on the
12849 floating point chip. Currently, @samp{info float} is supported on
12850 the ARM and x86 machines.
12854 @section Vector Unit
12855 @cindex vector unit
12857 Depending on the configuration, @value{GDBN} may be able to give you
12858 more information about the status of the vector unit.
12861 @kindex info vector
12863 Display information about the vector unit. The exact contents and
12864 layout vary depending on the hardware.
12867 @node OS Information
12868 @section Operating System Auxiliary Information
12869 @cindex OS information
12871 @value{GDBN} provides interfaces to useful OS facilities that can help
12872 you debug your program.
12874 @cindex auxiliary vector
12875 @cindex vector, auxiliary
12876 Some operating systems supply an @dfn{auxiliary vector} to programs at
12877 startup. This is akin to the arguments and environment that you
12878 specify for a program, but contains a system-dependent variety of
12879 binary values that tell system libraries important details about the
12880 hardware, operating system, and process. Each value's purpose is
12881 identified by an integer tag; the meanings are well-known but system-specific.
12882 Depending on the configuration and operating system facilities,
12883 @value{GDBN} may be able to show you this information. For remote
12884 targets, this functionality may further depend on the remote stub's
12885 support of the @samp{qXfer:auxv:read} packet, see
12886 @ref{qXfer auxiliary vector read}.
12891 Display the auxiliary vector of the inferior, which can be either a
12892 live process or a core dump file. @value{GDBN} prints each tag value
12893 numerically, and also shows names and text descriptions for recognized
12894 tags. Some values in the vector are numbers, some bit masks, and some
12895 pointers to strings or other data. @value{GDBN} displays each value in the
12896 most appropriate form for a recognized tag, and in hexadecimal for
12897 an unrecognized tag.
12900 On some targets, @value{GDBN} can access operating system-specific
12901 information and show it to you. The types of information available
12902 will differ depending on the type of operating system running on the
12903 target. The mechanism used to fetch the data is described in
12904 @ref{Operating System Information}. For remote targets, this
12905 functionality depends on the remote stub's support of the
12906 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12910 @item info os @var{infotype}
12912 Display OS information of the requested type.
12914 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12916 @anchor{linux info os infotypes}
12918 @kindex info os cpus
12920 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12921 the available fields from /proc/cpuinfo. For each supported architecture
12922 different fields are available. Two common entries are processor which gives
12923 CPU number and bogomips; a system constant that is calculated during
12924 kernel initialization.
12926 @kindex info os files
12928 Display the list of open file descriptors on the target. For each
12929 file descriptor, @value{GDBN} prints the identifier of the process
12930 owning the descriptor, the command of the owning process, the value
12931 of the descriptor, and the target of the descriptor.
12933 @kindex info os modules
12935 Display the list of all loaded kernel modules on the target. For each
12936 module, @value{GDBN} prints the module name, the size of the module in
12937 bytes, the number of times the module is used, the dependencies of the
12938 module, the status of the module, and the address of the loaded module
12941 @kindex info os msg
12943 Display the list of all System V message queues on the target. For each
12944 message queue, @value{GDBN} prints the message queue key, the message
12945 queue identifier, the access permissions, the current number of bytes
12946 on the queue, the current number of messages on the queue, the processes
12947 that last sent and received a message on the queue, the user and group
12948 of the owner and creator of the message queue, the times at which a
12949 message was last sent and received on the queue, and the time at which
12950 the message queue was last changed.
12952 @kindex info os processes
12954 Display the list of processes on the target. For each process,
12955 @value{GDBN} prints the process identifier, the name of the user, the
12956 command corresponding to the process, and the list of processor cores
12957 that the process is currently running on. (To understand what these
12958 properties mean, for this and the following info types, please consult
12959 the general @sc{gnu}/Linux documentation.)
12961 @kindex info os procgroups
12963 Display the list of process groups on the target. For each process,
12964 @value{GDBN} prints the identifier of the process group that it belongs
12965 to, the command corresponding to the process group leader, the process
12966 identifier, and the command line of the process. The list is sorted
12967 first by the process group identifier, then by the process identifier,
12968 so that processes belonging to the same process group are grouped together
12969 and the process group leader is listed first.
12971 @kindex info os semaphores
12973 Display the list of all System V semaphore sets on the target. For each
12974 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12975 set identifier, the access permissions, the number of semaphores in the
12976 set, the user and group of the owner and creator of the semaphore set,
12977 and the times at which the semaphore set was operated upon and changed.
12979 @kindex info os shm
12981 Display the list of all System V shared-memory regions on the target.
12982 For each shared-memory region, @value{GDBN} prints the region key,
12983 the shared-memory identifier, the access permissions, the size of the
12984 region, the process that created the region, the process that last
12985 attached to or detached from the region, the current number of live
12986 attaches to the region, and the times at which the region was last
12987 attached to, detach from, and changed.
12989 @kindex info os sockets
12991 Display the list of Internet-domain sockets on the target. For each
12992 socket, @value{GDBN} prints the address and port of the local and
12993 remote endpoints, the current state of the connection, the creator of
12994 the socket, the IP address family of the socket, and the type of the
12997 @kindex info os threads
12999 Display the list of threads running on the target. For each thread,
13000 @value{GDBN} prints the identifier of the process that the thread
13001 belongs to, the command of the process, the thread identifier, and the
13002 processor core that it is currently running on. The main thread of a
13003 process is not listed.
13007 If @var{infotype} is omitted, then list the possible values for
13008 @var{infotype} and the kind of OS information available for each
13009 @var{infotype}. If the target does not return a list of possible
13010 types, this command will report an error.
13013 @node Memory Region Attributes
13014 @section Memory Region Attributes
13015 @cindex memory region attributes
13017 @dfn{Memory region attributes} allow you to describe special handling
13018 required by regions of your target's memory. @value{GDBN} uses
13019 attributes to determine whether to allow certain types of memory
13020 accesses; whether to use specific width accesses; and whether to cache
13021 target memory. By default the description of memory regions is
13022 fetched from the target (if the current target supports this), but the
13023 user can override the fetched regions.
13025 Defined memory regions can be individually enabled and disabled. When a
13026 memory region is disabled, @value{GDBN} uses the default attributes when
13027 accessing memory in that region. Similarly, if no memory regions have
13028 been defined, @value{GDBN} uses the default attributes when accessing
13031 When a memory region is defined, it is given a number to identify it;
13032 to enable, disable, or remove a memory region, you specify that number.
13036 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
13037 Define a memory region bounded by @var{lower} and @var{upper} with
13038 attributes @var{attributes}@dots{}, and add it to the list of regions
13039 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
13040 case: it is treated as the target's maximum memory address.
13041 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
13044 Discard any user changes to the memory regions and use target-supplied
13045 regions, if available, or no regions if the target does not support.
13048 @item delete mem @var{nums}@dots{}
13049 Remove memory regions @var{nums}@dots{} from the list of regions
13050 monitored by @value{GDBN}.
13052 @kindex disable mem
13053 @item disable mem @var{nums}@dots{}
13054 Disable monitoring of memory regions @var{nums}@dots{}.
13055 A disabled memory region is not forgotten.
13056 It may be enabled again later.
13059 @item enable mem @var{nums}@dots{}
13060 Enable monitoring of memory regions @var{nums}@dots{}.
13064 Print a table of all defined memory regions, with the following columns
13068 @item Memory Region Number
13069 @item Enabled or Disabled.
13070 Enabled memory regions are marked with @samp{y}.
13071 Disabled memory regions are marked with @samp{n}.
13074 The address defining the inclusive lower bound of the memory region.
13077 The address defining the exclusive upper bound of the memory region.
13080 The list of attributes set for this memory region.
13085 @subsection Attributes
13087 @subsubsection Memory Access Mode
13088 The access mode attributes set whether @value{GDBN} may make read or
13089 write accesses to a memory region.
13091 While these attributes prevent @value{GDBN} from performing invalid
13092 memory accesses, they do nothing to prevent the target system, I/O DMA,
13093 etc.@: from accessing memory.
13097 Memory is read only.
13099 Memory is write only.
13101 Memory is read/write. This is the default.
13104 @subsubsection Memory Access Size
13105 The access size attribute tells @value{GDBN} to use specific sized
13106 accesses in the memory region. Often memory mapped device registers
13107 require specific sized accesses. If no access size attribute is
13108 specified, @value{GDBN} may use accesses of any size.
13112 Use 8 bit memory accesses.
13114 Use 16 bit memory accesses.
13116 Use 32 bit memory accesses.
13118 Use 64 bit memory accesses.
13121 @c @subsubsection Hardware/Software Breakpoints
13122 @c The hardware/software breakpoint attributes set whether @value{GDBN}
13123 @c will use hardware or software breakpoints for the internal breakpoints
13124 @c used by the step, next, finish, until, etc. commands.
13128 @c Always use hardware breakpoints
13129 @c @item swbreak (default)
13132 @subsubsection Data Cache
13133 The data cache attributes set whether @value{GDBN} will cache target
13134 memory. While this generally improves performance by reducing debug
13135 protocol overhead, it can lead to incorrect results because @value{GDBN}
13136 does not know about volatile variables or memory mapped device
13141 Enable @value{GDBN} to cache target memory.
13143 Disable @value{GDBN} from caching target memory. This is the default.
13146 @subsection Memory Access Checking
13147 @value{GDBN} can be instructed to refuse accesses to memory that is
13148 not explicitly described. This can be useful if accessing such
13149 regions has undesired effects for a specific target, or to provide
13150 better error checking. The following commands control this behaviour.
13153 @kindex set mem inaccessible-by-default
13154 @item set mem inaccessible-by-default [on|off]
13155 If @code{on} is specified, make @value{GDBN} treat memory not
13156 explicitly described by the memory ranges as non-existent and refuse accesses
13157 to such memory. The checks are only performed if there's at least one
13158 memory range defined. If @code{off} is specified, make @value{GDBN}
13159 treat the memory not explicitly described by the memory ranges as RAM.
13160 The default value is @code{on}.
13161 @kindex show mem inaccessible-by-default
13162 @item show mem inaccessible-by-default
13163 Show the current handling of accesses to unknown memory.
13167 @c @subsubsection Memory Write Verification
13168 @c The memory write verification attributes set whether @value{GDBN}
13169 @c will re-reads data after each write to verify the write was successful.
13173 @c @item noverify (default)
13176 @node Dump/Restore Files
13177 @section Copy Between Memory and a File
13178 @cindex dump/restore files
13179 @cindex append data to a file
13180 @cindex dump data to a file
13181 @cindex restore data from a file
13183 You can use the commands @code{dump}, @code{append}, and
13184 @code{restore} to copy data between target memory and a file. The
13185 @code{dump} and @code{append} commands write data to a file, and the
13186 @code{restore} command reads data from a file back into the inferior's
13187 memory. Files may be in binary, Motorola S-record, Intel hex,
13188 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13189 append to binary files, and cannot read from Verilog Hex files.
13194 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13195 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13196 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13197 or the value of @var{expr}, to @var{filename} in the given format.
13199 The @var{format} parameter may be any one of:
13206 Motorola S-record format.
13208 Tektronix Hex format.
13210 Verilog Hex format.
13213 @value{GDBN} uses the same definitions of these formats as the
13214 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13215 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13219 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13220 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13221 Append the contents of memory from @var{start_addr} to @var{end_addr},
13222 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13223 (@value{GDBN} can only append data to files in raw binary form.)
13226 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13227 Restore the contents of file @var{filename} into memory. The
13228 @code{restore} command can automatically recognize any known @sc{bfd}
13229 file format, except for raw binary. To restore a raw binary file you
13230 must specify the optional keyword @code{binary} after the filename.
13232 If @var{bias} is non-zero, its value will be added to the addresses
13233 contained in the file. Binary files always start at address zero, so
13234 they will be restored at address @var{bias}. Other bfd files have
13235 a built-in location; they will be restored at offset @var{bias}
13236 from that location.
13238 If @var{start} and/or @var{end} are non-zero, then only data between
13239 file offset @var{start} and file offset @var{end} will be restored.
13240 These offsets are relative to the addresses in the file, before
13241 the @var{bias} argument is applied.
13245 @node Core File Generation
13246 @section How to Produce a Core File from Your Program
13247 @cindex dump core from inferior
13249 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13250 image of a running process and its process status (register values
13251 etc.). Its primary use is post-mortem debugging of a program that
13252 crashed while it ran outside a debugger. A program that crashes
13253 automatically produces a core file, unless this feature is disabled by
13254 the user. @xref{Files}, for information on invoking @value{GDBN} in
13255 the post-mortem debugging mode.
13257 Occasionally, you may wish to produce a core file of the program you
13258 are debugging in order to preserve a snapshot of its state.
13259 @value{GDBN} has a special command for that.
13263 @kindex generate-core-file
13264 @item generate-core-file [@var{file}]
13265 @itemx gcore [@var{file}]
13266 Produce a core dump of the inferior process. The optional argument
13267 @var{file} specifies the file name where to put the core dump. If not
13268 specified, the file name defaults to @file{core.@var{pid}}, where
13269 @var{pid} is the inferior process ID.
13271 Note that this command is implemented only for some systems (as of
13272 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13274 On @sc{gnu}/Linux, this command can take into account the value of the
13275 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13276 dump (@pxref{set use-coredump-filter}), and by default honors the
13277 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13278 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13280 @kindex set use-coredump-filter
13281 @anchor{set use-coredump-filter}
13282 @item set use-coredump-filter on
13283 @itemx set use-coredump-filter off
13284 Enable or disable the use of the file
13285 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13286 files. This file is used by the Linux kernel to decide what types of
13287 memory mappings will be dumped or ignored when generating a core dump
13288 file. @var{pid} is the process ID of a currently running process.
13290 To make use of this feature, you have to write in the
13291 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13292 which is a bit mask representing the memory mapping types. If a bit
13293 is set in the bit mask, then the memory mappings of the corresponding
13294 types will be dumped; otherwise, they will be ignored. This
13295 configuration is inherited by child processes. For more information
13296 about the bits that can be set in the
13297 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13298 manpage of @code{core(5)}.
13300 By default, this option is @code{on}. If this option is turned
13301 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13302 and instead uses the same default value as the Linux kernel in order
13303 to decide which pages will be dumped in the core dump file. This
13304 value is currently @code{0x33}, which means that bits @code{0}
13305 (anonymous private mappings), @code{1} (anonymous shared mappings),
13306 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13307 This will cause these memory mappings to be dumped automatically.
13309 @kindex set dump-excluded-mappings
13310 @anchor{set dump-excluded-mappings}
13311 @item set dump-excluded-mappings on
13312 @itemx set dump-excluded-mappings off
13313 If @code{on} is specified, @value{GDBN} will dump memory mappings
13314 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13315 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13317 The default value is @code{off}.
13320 @node Character Sets
13321 @section Character Sets
13322 @cindex character sets
13324 @cindex translating between character sets
13325 @cindex host character set
13326 @cindex target character set
13328 If the program you are debugging uses a different character set to
13329 represent characters and strings than the one @value{GDBN} uses itself,
13330 @value{GDBN} can automatically translate between the character sets for
13331 you. The character set @value{GDBN} uses we call the @dfn{host
13332 character set}; the one the inferior program uses we call the
13333 @dfn{target character set}.
13335 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13336 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13337 remote protocol (@pxref{Remote Debugging}) to debug a program
13338 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13339 then the host character set is Latin-1, and the target character set is
13340 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13341 target-charset EBCDIC-US}, then @value{GDBN} translates between
13342 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13343 character and string literals in expressions.
13345 @value{GDBN} has no way to automatically recognize which character set
13346 the inferior program uses; you must tell it, using the @code{set
13347 target-charset} command, described below.
13349 Here are the commands for controlling @value{GDBN}'s character set
13353 @item set target-charset @var{charset}
13354 @kindex set target-charset
13355 Set the current target character set to @var{charset}. To display the
13356 list of supported target character sets, type
13357 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13359 @item set host-charset @var{charset}
13360 @kindex set host-charset
13361 Set the current host character set to @var{charset}.
13363 By default, @value{GDBN} uses a host character set appropriate to the
13364 system it is running on; you can override that default using the
13365 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13366 automatically determine the appropriate host character set. In this
13367 case, @value{GDBN} uses @samp{UTF-8}.
13369 @value{GDBN} can only use certain character sets as its host character
13370 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13371 @value{GDBN} will list the host character sets it supports.
13373 @item set charset @var{charset}
13374 @kindex set charset
13375 Set the current host and target character sets to @var{charset}. As
13376 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13377 @value{GDBN} will list the names of the character sets that can be used
13378 for both host and target.
13381 @kindex show charset
13382 Show the names of the current host and target character sets.
13384 @item show host-charset
13385 @kindex show host-charset
13386 Show the name of the current host character set.
13388 @item show target-charset
13389 @kindex show target-charset
13390 Show the name of the current target character set.
13392 @item set target-wide-charset @var{charset}
13393 @kindex set target-wide-charset
13394 Set the current target's wide character set to @var{charset}. This is
13395 the character set used by the target's @code{wchar_t} type. To
13396 display the list of supported wide character sets, type
13397 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13399 @item show target-wide-charset
13400 @kindex show target-wide-charset
13401 Show the name of the current target's wide character set.
13404 Here is an example of @value{GDBN}'s character set support in action.
13405 Assume that the following source code has been placed in the file
13406 @file{charset-test.c}:
13412 = @{72, 101, 108, 108, 111, 44, 32, 119,
13413 111, 114, 108, 100, 33, 10, 0@};
13414 char ibm1047_hello[]
13415 = @{200, 133, 147, 147, 150, 107, 64, 166,
13416 150, 153, 147, 132, 90, 37, 0@};
13420 printf ("Hello, world!\n");
13424 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13425 containing the string @samp{Hello, world!} followed by a newline,
13426 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13428 We compile the program, and invoke the debugger on it:
13431 $ gcc -g charset-test.c -o charset-test
13432 $ gdb -nw charset-test
13433 GNU gdb 2001-12-19-cvs
13434 Copyright 2001 Free Software Foundation, Inc.
13439 We can use the @code{show charset} command to see what character sets
13440 @value{GDBN} is currently using to interpret and display characters and
13444 (@value{GDBP}) show charset
13445 The current host and target character set is `ISO-8859-1'.
13449 For the sake of printing this manual, let's use @sc{ascii} as our
13450 initial character set:
13452 (@value{GDBP}) set charset ASCII
13453 (@value{GDBP}) show charset
13454 The current host and target character set is `ASCII'.
13458 Let's assume that @sc{ascii} is indeed the correct character set for our
13459 host system --- in other words, let's assume that if @value{GDBN} prints
13460 characters using the @sc{ascii} character set, our terminal will display
13461 them properly. Since our current target character set is also
13462 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13465 (@value{GDBP}) print ascii_hello
13466 $1 = 0x401698 "Hello, world!\n"
13467 (@value{GDBP}) print ascii_hello[0]
13472 @value{GDBN} uses the target character set for character and string
13473 literals you use in expressions:
13476 (@value{GDBP}) print '+'
13481 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13484 @value{GDBN} relies on the user to tell it which character set the
13485 target program uses. If we print @code{ibm1047_hello} while our target
13486 character set is still @sc{ascii}, we get jibberish:
13489 (@value{GDBP}) print ibm1047_hello
13490 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13491 (@value{GDBP}) print ibm1047_hello[0]
13496 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13497 @value{GDBN} tells us the character sets it supports:
13500 (@value{GDBP}) set target-charset
13501 ASCII EBCDIC-US IBM1047 ISO-8859-1
13502 (@value{GDBP}) set target-charset
13505 We can select @sc{ibm1047} as our target character set, and examine the
13506 program's strings again. Now the @sc{ascii} string is wrong, but
13507 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13508 target character set, @sc{ibm1047}, to the host character set,
13509 @sc{ascii}, and they display correctly:
13512 (@value{GDBP}) set target-charset IBM1047
13513 (@value{GDBP}) show charset
13514 The current host character set is `ASCII'.
13515 The current target character set is `IBM1047'.
13516 (@value{GDBP}) print ascii_hello
13517 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13518 (@value{GDBP}) print ascii_hello[0]
13520 (@value{GDBP}) print ibm1047_hello
13521 $8 = 0x4016a8 "Hello, world!\n"
13522 (@value{GDBP}) print ibm1047_hello[0]
13527 As above, @value{GDBN} uses the target character set for character and
13528 string literals you use in expressions:
13531 (@value{GDBP}) print '+'
13536 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13539 @node Caching Target Data
13540 @section Caching Data of Targets
13541 @cindex caching data of targets
13543 @value{GDBN} caches data exchanged between the debugger and a target.
13544 Each cache is associated with the address space of the inferior.
13545 @xref{Inferiors Connections and Programs}, about inferior and address space.
13546 Such caching generally improves performance in remote debugging
13547 (@pxref{Remote Debugging}), because it reduces the overhead of the
13548 remote protocol by bundling memory reads and writes into large chunks.
13549 Unfortunately, simply caching everything would lead to incorrect results,
13550 since @value{GDBN} does not necessarily know anything about volatile
13551 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13552 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13554 Therefore, by default, @value{GDBN} only caches data
13555 known to be on the stack@footnote{In non-stop mode, it is moderately
13556 rare for a running thread to modify the stack of a stopped thread
13557 in a way that would interfere with a backtrace, and caching of
13558 stack reads provides a significant speed up of remote backtraces.} or
13559 in the code segment.
13560 Other regions of memory can be explicitly marked as
13561 cacheable; @pxref{Memory Region Attributes}.
13564 @kindex set remotecache
13565 @item set remotecache on
13566 @itemx set remotecache off
13567 This option no longer does anything; it exists for compatibility
13570 @kindex show remotecache
13571 @item show remotecache
13572 Show the current state of the obsolete remotecache flag.
13574 @kindex set stack-cache
13575 @item set stack-cache on
13576 @itemx set stack-cache off
13577 Enable or disable caching of stack accesses. When @code{on}, use
13578 caching. By default, this option is @code{on}.
13580 @kindex show stack-cache
13581 @item show stack-cache
13582 Show the current state of data caching for memory accesses.
13584 @kindex set code-cache
13585 @item set code-cache on
13586 @itemx set code-cache off
13587 Enable or disable caching of code segment accesses. When @code{on},
13588 use caching. By default, this option is @code{on}. This improves
13589 performance of disassembly in remote debugging.
13591 @kindex show code-cache
13592 @item show code-cache
13593 Show the current state of target memory cache for code segment
13596 @kindex info dcache
13597 @item info dcache @r{[}line@r{]}
13598 Print the information about the performance of data cache of the
13599 current inferior's address space. The information displayed
13600 includes the dcache width and depth, and for each cache line, its
13601 number, address, and how many times it was referenced. This
13602 command is useful for debugging the data cache operation.
13604 If a line number is specified, the contents of that line will be
13607 @item set dcache size @var{size}
13608 @cindex dcache size
13609 @kindex set dcache size
13610 Set maximum number of entries in dcache (dcache depth above).
13612 @item set dcache line-size @var{line-size}
13613 @cindex dcache line-size
13614 @kindex set dcache line-size
13615 Set number of bytes each dcache entry caches (dcache width above).
13616 Must be a power of 2.
13618 @item show dcache size
13619 @kindex show dcache size
13620 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13622 @item show dcache line-size
13623 @kindex show dcache line-size
13624 Show default size of dcache lines.
13626 @item maint flush dcache
13627 @cindex dcache, flushing
13628 @kindex maint flush dcache
13629 Flush the contents (if any) of the dcache. This maintainer command is
13630 useful when debugging the dcache implementation.
13634 @node Searching Memory
13635 @section Search Memory
13636 @cindex searching memory
13638 Memory can be searched for a particular sequence of bytes with the
13639 @code{find} command.
13643 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13644 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13645 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13646 etc. The search begins at address @var{start_addr} and continues for either
13647 @var{len} bytes or through to @var{end_addr} inclusive.
13650 @var{s} and @var{n} are optional parameters.
13651 They may be specified in either order, apart or together.
13654 @item @var{s}, search query size
13655 The size of each search query value.
13661 halfwords (two bytes)
13665 giant words (eight bytes)
13668 All values are interpreted in the current language.
13669 This means, for example, that if the current source language is C/C@t{++}
13670 then searching for the string ``hello'' includes the trailing '\0'.
13671 The null terminator can be removed from searching by using casts,
13672 e.g.: @samp{@{char[5]@}"hello"}.
13674 If the value size is not specified, it is taken from the
13675 value's type in the current language.
13676 This is useful when one wants to specify the search
13677 pattern as a mixture of types.
13678 Note that this means, for example, that in the case of C-like languages
13679 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13680 which is typically four bytes.
13682 @item @var{n}, maximum number of finds
13683 The maximum number of matches to print. The default is to print all finds.
13686 You can use strings as search values. Quote them with double-quotes
13688 The string value is copied into the search pattern byte by byte,
13689 regardless of the endianness of the target and the size specification.
13691 The address of each match found is printed as well as a count of the
13692 number of matches found.
13694 The address of the last value found is stored in convenience variable
13696 A count of the number of matches is stored in @samp{$numfound}.
13698 For example, if stopped at the @code{printf} in this function:
13704 static char hello[] = "hello-hello";
13705 static struct @{ char c; short s; int i; @}
13706 __attribute__ ((packed)) mixed
13707 = @{ 'c', 0x1234, 0x87654321 @};
13708 printf ("%s\n", hello);
13713 you get during debugging:
13716 (gdb) find &hello[0], +sizeof(hello), "hello"
13717 0x804956d <hello.1620+6>
13719 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13720 0x8049567 <hello.1620>
13721 0x804956d <hello.1620+6>
13723 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13724 0x8049567 <hello.1620>
13725 0x804956d <hello.1620+6>
13727 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13728 0x8049567 <hello.1620>
13730 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13731 0x8049560 <mixed.1625>
13733 (gdb) print $numfound
13736 $2 = (void *) 0x8049560
13740 @section Value Sizes
13742 Whenever @value{GDBN} prints a value memory will be allocated within
13743 @value{GDBN} to hold the contents of the value. It is possible in
13744 some languages with dynamic typing systems, that an invalid program
13745 may indicate a value that is incorrectly large, this in turn may cause
13746 @value{GDBN} to try and allocate an overly large amount of memory.
13749 @kindex set max-value-size
13750 @item set max-value-size @var{bytes}
13751 @itemx set max-value-size unlimited
13752 Set the maximum size of memory that @value{GDBN} will allocate for the
13753 contents of a value to @var{bytes}, trying to display a value that
13754 requires more memory than that will result in an error.
13756 Setting this variable does not effect values that have already been
13757 allocated within @value{GDBN}, only future allocations.
13759 There's a minimum size that @code{max-value-size} can be set to in
13760 order that @value{GDBN} can still operate correctly, this minimum is
13761 currently 16 bytes.
13763 The limit applies to the results of some subexpressions as well as to
13764 complete expressions. For example, an expression denoting a simple
13765 integer component, such as @code{x.y.z}, may fail if the size of
13766 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13767 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13768 @var{A} is an array variable with non-constant size, will generally
13769 succeed regardless of the bounds on @var{A}, as long as the component
13770 size is less than @var{bytes}.
13772 The default value of @code{max-value-size} is currently 64k.
13774 @kindex show max-value-size
13775 @item show max-value-size
13776 Show the maximum size of memory, in bytes, that @value{GDBN} will
13777 allocate for the contents of a value.
13780 @node Optimized Code
13781 @chapter Debugging Optimized Code
13782 @cindex optimized code, debugging
13783 @cindex debugging optimized code
13785 Almost all compilers support optimization. With optimization
13786 disabled, the compiler generates assembly code that corresponds
13787 directly to your source code, in a simplistic way. As the compiler
13788 applies more powerful optimizations, the generated assembly code
13789 diverges from your original source code. With help from debugging
13790 information generated by the compiler, @value{GDBN} can map from
13791 the running program back to constructs from your original source.
13793 @value{GDBN} is more accurate with optimization disabled. If you
13794 can recompile without optimization, it is easier to follow the
13795 progress of your program during debugging. But, there are many cases
13796 where you may need to debug an optimized version.
13798 When you debug a program compiled with @samp{-g -O}, remember that the
13799 optimizer has rearranged your code; the debugger shows you what is
13800 really there. Do not be too surprised when the execution path does not
13801 exactly match your source file! An extreme example: if you define a
13802 variable, but never use it, @value{GDBN} never sees that
13803 variable---because the compiler optimizes it out of existence.
13805 Some things do not work as well with @samp{-g -O} as with just
13806 @samp{-g}, particularly on machines with instruction scheduling. If in
13807 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13808 please report it to us as a bug (including a test case!).
13809 @xref{Variables}, for more information about debugging optimized code.
13812 * Inline Functions:: How @value{GDBN} presents inlining
13813 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13816 @node Inline Functions
13817 @section Inline Functions
13818 @cindex inline functions, debugging
13820 @dfn{Inlining} is an optimization that inserts a copy of the function
13821 body directly at each call site, instead of jumping to a shared
13822 routine. @value{GDBN} displays inlined functions just like
13823 non-inlined functions. They appear in backtraces. You can view their
13824 arguments and local variables, step into them with @code{step}, skip
13825 them with @code{next}, and escape from them with @code{finish}.
13826 You can check whether a function was inlined by using the
13827 @code{info frame} command.
13829 For @value{GDBN} to support inlined functions, the compiler must
13830 record information about inlining in the debug information ---
13831 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13832 other compilers do also. @value{GDBN} only supports inlined functions
13833 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13834 do not emit two required attributes (@samp{DW_AT_call_file} and
13835 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13836 function calls with earlier versions of @value{NGCC}. It instead
13837 displays the arguments and local variables of inlined functions as
13838 local variables in the caller.
13840 The body of an inlined function is directly included at its call site;
13841 unlike a non-inlined function, there are no instructions devoted to
13842 the call. @value{GDBN} still pretends that the call site and the
13843 start of the inlined function are different instructions. Stepping to
13844 the call site shows the call site, and then stepping again shows
13845 the first line of the inlined function, even though no additional
13846 instructions are executed.
13848 This makes source-level debugging much clearer; you can see both the
13849 context of the call and then the effect of the call. Only stepping by
13850 a single instruction using @code{stepi} or @code{nexti} does not do
13851 this; single instruction steps always show the inlined body.
13853 There are some ways that @value{GDBN} does not pretend that inlined
13854 function calls are the same as normal calls:
13858 Setting breakpoints at the call site of an inlined function may not
13859 work, because the call site does not contain any code. @value{GDBN}
13860 may incorrectly move the breakpoint to the next line of the enclosing
13861 function, after the call. This limitation will be removed in a future
13862 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13863 or inside the inlined function instead.
13866 @value{GDBN} cannot locate the return value of inlined calls after
13867 using the @code{finish} command. This is a limitation of compiler-generated
13868 debugging information; after @code{finish}, you can step to the next line
13869 and print a variable where your program stored the return value.
13873 @node Tail Call Frames
13874 @section Tail Call Frames
13875 @cindex tail call frames, debugging
13877 Function @code{B} can call function @code{C} in its very last statement. In
13878 unoptimized compilation the call of @code{C} is immediately followed by return
13879 instruction at the end of @code{B} code. Optimizing compiler may replace the
13880 call and return in function @code{B} into one jump to function @code{C}
13881 instead. Such use of a jump instruction is called @dfn{tail call}.
13883 During execution of function @code{C}, there will be no indication in the
13884 function call stack frames that it was tail-called from @code{B}. If function
13885 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13886 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13887 some cases @value{GDBN} can determine that @code{C} was tail-called from
13888 @code{B}, and it will then create fictitious call frame for that, with the
13889 return address set up as if @code{B} called @code{C} normally.
13891 This functionality is currently supported only by DWARF 2 debugging format and
13892 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13893 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13896 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13897 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13901 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13903 Stack level 1, frame at 0x7fffffffda30:
13904 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13905 tail call frame, caller of frame at 0x7fffffffda30
13906 source language c++.
13907 Arglist at unknown address.
13908 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13911 The detection of all the possible code path executions can find them ambiguous.
13912 There is no execution history stored (possible @ref{Reverse Execution} is never
13913 used for this purpose) and the last known caller could have reached the known
13914 callee by multiple different jump sequences. In such case @value{GDBN} still
13915 tries to show at least all the unambiguous top tail callers and all the
13916 unambiguous bottom tail calees, if any.
13919 @anchor{set debug entry-values}
13920 @item set debug entry-values
13921 @kindex set debug entry-values
13922 When set to on, enables printing of analysis messages for both frame argument
13923 values at function entry and tail calls. It will show all the possible valid
13924 tail calls code paths it has considered. It will also print the intersection
13925 of them with the final unambiguous (possibly partial or even empty) code path
13928 @item show debug entry-values
13929 @kindex show debug entry-values
13930 Show the current state of analysis messages printing for both frame argument
13931 values at function entry and tail calls.
13934 The analysis messages for tail calls can for example show why the virtual tail
13935 call frame for function @code{c} has not been recognized (due to the indirect
13936 reference by variable @code{x}):
13939 static void __attribute__((noinline, noclone)) c (void);
13940 void (*x) (void) = c;
13941 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13942 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13943 int main (void) @{ x (); return 0; @}
13945 Breakpoint 1, DW_OP_entry_value resolving cannot find
13946 DW_TAG_call_site 0x40039a in main
13948 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13951 #1 0x000000000040039a in main () at t.c:5
13954 Another possibility is an ambiguous virtual tail call frames resolution:
13958 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13959 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13960 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13961 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13962 static void __attribute__((noinline, noclone)) b (void)
13963 @{ if (i) c (); else e (); @}
13964 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13965 int main (void) @{ a (); return 0; @}
13967 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13968 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13969 tailcall: reduced: 0x4004d2(a) |
13972 #1 0x00000000004004d2 in a () at t.c:8
13973 #2 0x0000000000400395 in main () at t.c:9
13976 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13977 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13979 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13980 @ifset HAVE_MAKEINFO_CLICK
13981 @set ARROW @click{}
13982 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13983 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13985 @ifclear HAVE_MAKEINFO_CLICK
13987 @set CALLSEQ1B @value{CALLSEQ1A}
13988 @set CALLSEQ2B @value{CALLSEQ2A}
13991 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13992 The code can have possible execution paths @value{CALLSEQ1B} or
13993 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13995 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13996 has found. It then finds another possible calling sequence - that one is
13997 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13998 printed as the @code{reduced:} calling sequence. That one could have many
13999 further @code{compare:} and @code{reduced:} statements as long as there remain
14000 any non-ambiguous sequence entries.
14002 For the frame of function @code{b} in both cases there are different possible
14003 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
14004 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
14005 therefore this one is displayed to the user while the ambiguous frames are
14008 There can be also reasons why printing of frame argument values at function
14013 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
14014 static void __attribute__((noinline, noclone)) a (int i);
14015 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
14016 static void __attribute__((noinline, noclone)) a (int i)
14017 @{ if (i) b (i - 1); else c (0); @}
14018 int main (void) @{ a (5); return 0; @}
14021 #0 c (i=i@@entry=0) at t.c:2
14022 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
14023 function "a" at 0x400420 can call itself via tail calls
14024 i=<optimized out>) at t.c:6
14025 #2 0x000000000040036e in main () at t.c:7
14028 @value{GDBN} cannot find out from the inferior state if and how many times did
14029 function @code{a} call itself (via function @code{b}) as these calls would be
14030 tail calls. Such tail calls would modify the @code{i} variable, therefore
14031 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
14032 prints @code{<optimized out>} instead.
14035 @chapter C Preprocessor Macros
14037 Some languages, such as C and C@t{++}, provide a way to define and invoke
14038 ``preprocessor macros'' which expand into strings of tokens.
14039 @value{GDBN} can evaluate expressions containing macro invocations, show
14040 the result of macro expansion, and show a macro's definition, including
14041 where it was defined.
14043 You may need to compile your program specially to provide @value{GDBN}
14044 with information about preprocessor macros. Most compilers do not
14045 include macros in their debugging information, even when you compile
14046 with the @option{-g} flag. @xref{Compilation}.
14048 A program may define a macro at one point, remove that definition later,
14049 and then provide a different definition after that. Thus, at different
14050 points in the program, a macro may have different definitions, or have
14051 no definition at all. If there is a current stack frame, @value{GDBN}
14052 uses the macros in scope at that frame's source code line. Otherwise,
14053 @value{GDBN} uses the macros in scope at the current listing location;
14056 Whenever @value{GDBN} evaluates an expression, it always expands any
14057 macro invocations present in the expression. @value{GDBN} also provides
14058 the following commands for working with macros explicitly.
14062 @kindex macro expand
14063 @cindex macro expansion, showing the results of preprocessor
14064 @cindex preprocessor macro expansion, showing the results of
14065 @cindex expanding preprocessor macros
14066 @item macro expand @var{expression}
14067 @itemx macro exp @var{expression}
14068 Show the results of expanding all preprocessor macro invocations in
14069 @var{expression}. Since @value{GDBN} simply expands macros, but does
14070 not parse the result, @var{expression} need not be a valid expression;
14071 it can be any string of tokens.
14074 @item macro expand-once @var{expression}
14075 @itemx macro exp1 @var{expression}
14076 @cindex expand macro once
14077 @i{(This command is not yet implemented.)} Show the results of
14078 expanding those preprocessor macro invocations that appear explicitly in
14079 @var{expression}. Macro invocations appearing in that expansion are
14080 left unchanged. This command allows you to see the effect of a
14081 particular macro more clearly, without being confused by further
14082 expansions. Since @value{GDBN} simply expands macros, but does not
14083 parse the result, @var{expression} need not be a valid expression; it
14084 can be any string of tokens.
14087 @cindex macro definition, showing
14088 @cindex definition of a macro, showing
14089 @cindex macros, from debug info
14090 @item info macro [-a|-all] [--] @var{macro}
14091 Show the current definition or all definitions of the named @var{macro},
14092 and describe the source location or compiler command-line where that
14093 definition was established. The optional double dash is to signify the end of
14094 argument processing and the beginning of @var{macro} for non C-like macros where
14095 the macro may begin with a hyphen.
14097 @kindex info macros
14098 @item info macros @var{location}
14099 Show all macro definitions that are in effect at the location specified
14100 by @var{location}, and describe the source location or compiler
14101 command-line where those definitions were established.
14103 @kindex macro define
14104 @cindex user-defined macros
14105 @cindex defining macros interactively
14106 @cindex macros, user-defined
14107 @item macro define @var{macro} @var{replacement-list}
14108 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
14109 Introduce a definition for a preprocessor macro named @var{macro},
14110 invocations of which are replaced by the tokens given in
14111 @var{replacement-list}. The first form of this command defines an
14112 ``object-like'' macro, which takes no arguments; the second form
14113 defines a ``function-like'' macro, which takes the arguments given in
14116 A definition introduced by this command is in scope in every
14117 expression evaluated in @value{GDBN}, until it is removed with the
14118 @code{macro undef} command, described below. The definition overrides
14119 all definitions for @var{macro} present in the program being debugged,
14120 as well as any previous user-supplied definition.
14122 @kindex macro undef
14123 @item macro undef @var{macro}
14124 Remove any user-supplied definition for the macro named @var{macro}.
14125 This command only affects definitions provided with the @code{macro
14126 define} command, described above; it cannot remove definitions present
14127 in the program being debugged.
14131 List all the macros defined using the @code{macro define} command.
14134 @cindex macros, example of debugging with
14135 Here is a transcript showing the above commands in action. First, we
14136 show our source files:
14141 #include "sample.h"
14144 #define ADD(x) (M + x)
14149 printf ("Hello, world!\n");
14151 printf ("We're so creative.\n");
14153 printf ("Goodbye, world!\n");
14160 Now, we compile the program using the @sc{gnu} C compiler,
14161 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14162 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14163 and @option{-gdwarf-4}; we recommend always choosing the most recent
14164 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14165 includes information about preprocessor macros in the debugging
14169 $ gcc -gdwarf-2 -g3 sample.c -o sample
14173 Now, we start @value{GDBN} on our sample program:
14177 GNU gdb 2002-05-06-cvs
14178 Copyright 2002 Free Software Foundation, Inc.
14179 GDB is free software, @dots{}
14183 We can expand macros and examine their definitions, even when the
14184 program is not running. @value{GDBN} uses the current listing position
14185 to decide which macro definitions are in scope:
14188 (@value{GDBP}) list main
14191 5 #define ADD(x) (M + x)
14196 10 printf ("Hello, world!\n");
14198 12 printf ("We're so creative.\n");
14199 (@value{GDBP}) info macro ADD
14200 Defined at /home/jimb/gdb/macros/play/sample.c:5
14201 #define ADD(x) (M + x)
14202 (@value{GDBP}) info macro Q
14203 Defined at /home/jimb/gdb/macros/play/sample.h:1
14204 included at /home/jimb/gdb/macros/play/sample.c:2
14206 (@value{GDBP}) macro expand ADD(1)
14207 expands to: (42 + 1)
14208 (@value{GDBP}) macro expand-once ADD(1)
14209 expands to: once (M + 1)
14213 In the example above, note that @code{macro expand-once} expands only
14214 the macro invocation explicit in the original text --- the invocation of
14215 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14216 which was introduced by @code{ADD}.
14218 Once the program is running, @value{GDBN} uses the macro definitions in
14219 force at the source line of the current stack frame:
14222 (@value{GDBP}) break main
14223 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14225 Starting program: /home/jimb/gdb/macros/play/sample
14227 Breakpoint 1, main () at sample.c:10
14228 10 printf ("Hello, world!\n");
14232 At line 10, the definition of the macro @code{N} at line 9 is in force:
14235 (@value{GDBP}) info macro N
14236 Defined at /home/jimb/gdb/macros/play/sample.c:9
14238 (@value{GDBP}) macro expand N Q M
14239 expands to: 28 < 42
14240 (@value{GDBP}) print N Q M
14245 As we step over directives that remove @code{N}'s definition, and then
14246 give it a new definition, @value{GDBN} finds the definition (or lack
14247 thereof) in force at each point:
14250 (@value{GDBP}) next
14252 12 printf ("We're so creative.\n");
14253 (@value{GDBP}) info macro N
14254 The symbol `N' has no definition as a C/C++ preprocessor macro
14255 at /home/jimb/gdb/macros/play/sample.c:12
14256 (@value{GDBP}) next
14258 14 printf ("Goodbye, world!\n");
14259 (@value{GDBP}) info macro N
14260 Defined at /home/jimb/gdb/macros/play/sample.c:13
14262 (@value{GDBP}) macro expand N Q M
14263 expands to: 1729 < 42
14264 (@value{GDBP}) print N Q M
14269 In addition to source files, macros can be defined on the compilation command
14270 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14271 such a way, @value{GDBN} displays the location of their definition as line zero
14272 of the source file submitted to the compiler.
14275 (@value{GDBP}) info macro __STDC__
14276 Defined at /home/jimb/gdb/macros/play/sample.c:0
14283 @chapter Tracepoints
14284 @c This chapter is based on the documentation written by Michael
14285 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14287 @cindex tracepoints
14288 In some applications, it is not feasible for the debugger to interrupt
14289 the program's execution long enough for the developer to learn
14290 anything helpful about its behavior. If the program's correctness
14291 depends on its real-time behavior, delays introduced by a debugger
14292 might cause the program to change its behavior drastically, or perhaps
14293 fail, even when the code itself is correct. It is useful to be able
14294 to observe the program's behavior without interrupting it.
14296 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14297 specify locations in the program, called @dfn{tracepoints}, and
14298 arbitrary expressions to evaluate when those tracepoints are reached.
14299 Later, using the @code{tfind} command, you can examine the values
14300 those expressions had when the program hit the tracepoints. The
14301 expressions may also denote objects in memory---structures or arrays,
14302 for example---whose values @value{GDBN} should record; while visiting
14303 a particular tracepoint, you may inspect those objects as if they were
14304 in memory at that moment. However, because @value{GDBN} records these
14305 values without interacting with you, it can do so quickly and
14306 unobtrusively, hopefully not disturbing the program's behavior.
14308 The tracepoint facility is currently available only for remote
14309 targets. @xref{Targets}. In addition, your remote target must know
14310 how to collect trace data. This functionality is implemented in the
14311 remote stub; however, none of the stubs distributed with @value{GDBN}
14312 support tracepoints as of this writing. The format of the remote
14313 packets used to implement tracepoints are described in @ref{Tracepoint
14316 It is also possible to get trace data from a file, in a manner reminiscent
14317 of corefiles; you specify the filename, and use @code{tfind} to search
14318 through the file. @xref{Trace Files}, for more details.
14320 This chapter describes the tracepoint commands and features.
14323 * Set Tracepoints::
14324 * Analyze Collected Data::
14325 * Tracepoint Variables::
14329 @node Set Tracepoints
14330 @section Commands to Set Tracepoints
14332 Before running such a @dfn{trace experiment}, an arbitrary number of
14333 tracepoints can be set. A tracepoint is actually a special type of
14334 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14335 standard breakpoint commands. For instance, as with breakpoints,
14336 tracepoint numbers are successive integers starting from one, and many
14337 of the commands associated with tracepoints take the tracepoint number
14338 as their argument, to identify which tracepoint to work on.
14340 For each tracepoint, you can specify, in advance, some arbitrary set
14341 of data that you want the target to collect in the trace buffer when
14342 it hits that tracepoint. The collected data can include registers,
14343 local variables, or global data. Later, you can use @value{GDBN}
14344 commands to examine the values these data had at the time the
14345 tracepoint was hit.
14347 Tracepoints do not support every breakpoint feature. Ignore counts on
14348 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14349 commands when they are hit. Tracepoints may not be thread-specific
14352 @cindex fast tracepoints
14353 Some targets may support @dfn{fast tracepoints}, which are inserted in
14354 a different way (such as with a jump instead of a trap), that is
14355 faster but possibly restricted in where they may be installed.
14357 @cindex static tracepoints
14358 @cindex markers, static tracepoints
14359 @cindex probing markers, static tracepoints
14360 Regular and fast tracepoints are dynamic tracing facilities, meaning
14361 that they can be used to insert tracepoints at (almost) any location
14362 in the target. Some targets may also support controlling @dfn{static
14363 tracepoints} from @value{GDBN}. With static tracing, a set of
14364 instrumentation points, also known as @dfn{markers}, are embedded in
14365 the target program, and can be activated or deactivated by name or
14366 address. These are usually placed at locations which facilitate
14367 investigating what the target is actually doing. @value{GDBN}'s
14368 support for static tracing includes being able to list instrumentation
14369 points, and attach them with @value{GDBN} defined high level
14370 tracepoints that expose the whole range of convenience of
14371 @value{GDBN}'s tracepoints support. Namely, support for collecting
14372 registers values and values of global or local (to the instrumentation
14373 point) variables; tracepoint conditions and trace state variables.
14374 The act of installing a @value{GDBN} static tracepoint on an
14375 instrumentation point, or marker, is referred to as @dfn{probing} a
14376 static tracepoint marker.
14378 @code{gdbserver} supports tracepoints on some target systems.
14379 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14381 This section describes commands to set tracepoints and associated
14382 conditions and actions.
14385 * Create and Delete Tracepoints::
14386 * Enable and Disable Tracepoints::
14387 * Tracepoint Passcounts::
14388 * Tracepoint Conditions::
14389 * Trace State Variables::
14390 * Tracepoint Actions::
14391 * Listing Tracepoints::
14392 * Listing Static Tracepoint Markers::
14393 * Starting and Stopping Trace Experiments::
14394 * Tracepoint Restrictions::
14397 @node Create and Delete Tracepoints
14398 @subsection Create and Delete Tracepoints
14401 @cindex set tracepoint
14403 @item trace @var{location}
14404 The @code{trace} command is very similar to the @code{break} command.
14405 Its argument @var{location} can be any valid location.
14406 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14407 which is a point in the target program where the debugger will briefly stop,
14408 collect some data, and then allow the program to continue. Setting a tracepoint
14409 or changing its actions takes effect immediately if the remote stub
14410 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14412 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14413 these changes don't take effect until the next @code{tstart}
14414 command, and once a trace experiment is running, further changes will
14415 not have any effect until the next trace experiment starts. In addition,
14416 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14417 address is not yet resolved. (This is similar to pending breakpoints.)
14418 Pending tracepoints are not downloaded to the target and not installed
14419 until they are resolved. The resolution of pending tracepoints requires
14420 @value{GDBN} support---when debugging with the remote target, and
14421 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14422 tracing}), pending tracepoints can not be resolved (and downloaded to
14423 the remote stub) while @value{GDBN} is disconnected.
14425 Here are some examples of using the @code{trace} command:
14428 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14430 (@value{GDBP}) @b{trace +2} // 2 lines forward
14432 (@value{GDBP}) @b{trace my_function} // first source line of function
14434 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14436 (@value{GDBP}) @b{trace *0x2117c4} // an address
14440 You can abbreviate @code{trace} as @code{tr}.
14442 @item trace @var{location} if @var{cond}
14443 Set a tracepoint with condition @var{cond}; evaluate the expression
14444 @var{cond} each time the tracepoint is reached, and collect data only
14445 if the value is nonzero---that is, if @var{cond} evaluates as true.
14446 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14447 information on tracepoint conditions.
14449 @item ftrace @var{location} [ if @var{cond} ]
14450 @cindex set fast tracepoint
14451 @cindex fast tracepoints, setting
14453 The @code{ftrace} command sets a fast tracepoint. For targets that
14454 support them, fast tracepoints will use a more efficient but possibly
14455 less general technique to trigger data collection, such as a jump
14456 instruction instead of a trap, or some sort of hardware support. It
14457 may not be possible to create a fast tracepoint at the desired
14458 location, in which case the command will exit with an explanatory
14461 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14464 On 32-bit x86-architecture systems, fast tracepoints normally need to
14465 be placed at an instruction that is 5 bytes or longer, but can be
14466 placed at 4-byte instructions if the low 64K of memory of the target
14467 program is available to install trampolines. Some Unix-type systems,
14468 such as @sc{gnu}/Linux, exclude low addresses from the program's
14469 address space; but for instance with the Linux kernel it is possible
14470 to let @value{GDBN} use this area by doing a @command{sysctl} command
14471 to set the @code{mmap_min_addr} kernel parameter, as in
14474 sudo sysctl -w vm.mmap_min_addr=32768
14478 which sets the low address to 32K, which leaves plenty of room for
14479 trampolines. The minimum address should be set to a page boundary.
14481 @item strace @var{location} [ if @var{cond} ]
14482 @cindex set static tracepoint
14483 @cindex static tracepoints, setting
14484 @cindex probe static tracepoint marker
14486 The @code{strace} command sets a static tracepoint. For targets that
14487 support it, setting a static tracepoint probes a static
14488 instrumentation point, or marker, found at @var{location}. It may not
14489 be possible to set a static tracepoint at the desired location, in
14490 which case the command will exit with an explanatory message.
14492 @value{GDBN} handles arguments to @code{strace} exactly as for
14493 @code{trace}, with the addition that the user can also specify
14494 @code{-m @var{marker}} as @var{location}. This probes the marker
14495 identified by the @var{marker} string identifier. This identifier
14496 depends on the static tracepoint backend library your program is
14497 using. You can find all the marker identifiers in the @samp{ID} field
14498 of the @code{info static-tracepoint-markers} command output.
14499 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14500 Markers}. For example, in the following small program using the UST
14506 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14511 the marker id is composed of joining the first two arguments to the
14512 @code{trace_mark} call with a slash, which translates to:
14515 (@value{GDBP}) info static-tracepoint-markers
14516 Cnt Enb ID Address What
14517 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14523 so you may probe the marker above with:
14526 (@value{GDBP}) strace -m ust/bar33
14529 Static tracepoints accept an extra collect action --- @code{collect
14530 $_sdata}. This collects arbitrary user data passed in the probe point
14531 call to the tracing library. In the UST example above, you'll see
14532 that the third argument to @code{trace_mark} is a printf-like format
14533 string. The user data is then the result of running that formatting
14534 string against the following arguments. Note that @code{info
14535 static-tracepoint-markers} command output lists that format string in
14536 the @samp{Data:} field.
14538 You can inspect this data when analyzing the trace buffer, by printing
14539 the $_sdata variable like any other variable available to
14540 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14543 @cindex last tracepoint number
14544 @cindex recent tracepoint number
14545 @cindex tracepoint number
14546 The convenience variable @code{$tpnum} records the tracepoint number
14547 of the most recently set tracepoint.
14549 @kindex delete tracepoint
14550 @cindex tracepoint deletion
14551 @item delete tracepoint @r{[}@var{num}@r{]}
14552 Permanently delete one or more tracepoints. With no argument, the
14553 default is to delete all tracepoints. Note that the regular
14554 @code{delete} command can remove tracepoints also.
14559 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14561 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14565 You can abbreviate this command as @code{del tr}.
14568 @node Enable and Disable Tracepoints
14569 @subsection Enable and Disable Tracepoints
14571 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14574 @kindex disable tracepoint
14575 @item disable tracepoint @r{[}@var{num}@r{]}
14576 Disable tracepoint @var{num}, or all tracepoints if no argument
14577 @var{num} is given. A disabled tracepoint will have no effect during
14578 a trace experiment, but it is not forgotten. You can re-enable
14579 a disabled tracepoint using the @code{enable tracepoint} command.
14580 If the command is issued during a trace experiment and the debug target
14581 has support for disabling tracepoints during a trace experiment, then the
14582 change will be effective immediately. Otherwise, it will be applied to the
14583 next trace experiment.
14585 @kindex enable tracepoint
14586 @item enable tracepoint @r{[}@var{num}@r{]}
14587 Enable tracepoint @var{num}, or all tracepoints. If this command is
14588 issued during a trace experiment and the debug target supports enabling
14589 tracepoints during a trace experiment, then the enabled tracepoints will
14590 become effective immediately. Otherwise, they will become effective the
14591 next time a trace experiment is run.
14594 @node Tracepoint Passcounts
14595 @subsection Tracepoint Passcounts
14599 @cindex tracepoint pass count
14600 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14601 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14602 automatically stop a trace experiment. If a tracepoint's passcount is
14603 @var{n}, then the trace experiment will be automatically stopped on
14604 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14605 @var{num} is not specified, the @code{passcount} command sets the
14606 passcount of the most recently defined tracepoint. If no passcount is
14607 given, the trace experiment will run until stopped explicitly by the
14613 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14614 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14616 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14617 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14618 (@value{GDBP}) @b{trace foo}
14619 (@value{GDBP}) @b{pass 3}
14620 (@value{GDBP}) @b{trace bar}
14621 (@value{GDBP}) @b{pass 2}
14622 (@value{GDBP}) @b{trace baz}
14623 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14624 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14625 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14626 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14630 @node Tracepoint Conditions
14631 @subsection Tracepoint Conditions
14632 @cindex conditional tracepoints
14633 @cindex tracepoint conditions
14635 The simplest sort of tracepoint collects data every time your program
14636 reaches a specified place. You can also specify a @dfn{condition} for
14637 a tracepoint. A condition is just a Boolean expression in your
14638 programming language (@pxref{Expressions, ,Expressions}). A
14639 tracepoint with a condition evaluates the expression each time your
14640 program reaches it, and data collection happens only if the condition
14643 Tracepoint conditions can be specified when a tracepoint is set, by
14644 using @samp{if} in the arguments to the @code{trace} command.
14645 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14646 also be set or changed at any time with the @code{condition} command,
14647 just as with breakpoints.
14649 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14650 the conditional expression itself. Instead, @value{GDBN} encodes the
14651 expression into an agent expression (@pxref{Agent Expressions})
14652 suitable for execution on the target, independently of @value{GDBN}.
14653 Global variables become raw memory locations, locals become stack
14654 accesses, and so forth.
14656 For instance, suppose you have a function that is usually called
14657 frequently, but should not be called after an error has occurred. You
14658 could use the following tracepoint command to collect data about calls
14659 of that function that happen while the error code is propagating
14660 through the program; an unconditional tracepoint could end up
14661 collecting thousands of useless trace frames that you would have to
14665 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14668 @node Trace State Variables
14669 @subsection Trace State Variables
14670 @cindex trace state variables
14672 A @dfn{trace state variable} is a special type of variable that is
14673 created and managed by target-side code. The syntax is the same as
14674 that for GDB's convenience variables (a string prefixed with ``$''),
14675 but they are stored on the target. They must be created explicitly,
14676 using a @code{tvariable} command. They are always 64-bit signed
14679 Trace state variables are remembered by @value{GDBN}, and downloaded
14680 to the target along with tracepoint information when the trace
14681 experiment starts. There are no intrinsic limits on the number of
14682 trace state variables, beyond memory limitations of the target.
14684 @cindex convenience variables, and trace state variables
14685 Although trace state variables are managed by the target, you can use
14686 them in print commands and expressions as if they were convenience
14687 variables; @value{GDBN} will get the current value from the target
14688 while the trace experiment is running. Trace state variables share
14689 the same namespace as other ``$'' variables, which means that you
14690 cannot have trace state variables with names like @code{$23} or
14691 @code{$pc}, nor can you have a trace state variable and a convenience
14692 variable with the same name.
14696 @item tvariable $@var{name} [ = @var{expression} ]
14698 The @code{tvariable} command creates a new trace state variable named
14699 @code{$@var{name}}, and optionally gives it an initial value of
14700 @var{expression}. The @var{expression} is evaluated when this command is
14701 entered; the result will be converted to an integer if possible,
14702 otherwise @value{GDBN} will report an error. A subsequent
14703 @code{tvariable} command specifying the same name does not create a
14704 variable, but instead assigns the supplied initial value to the
14705 existing variable of that name, overwriting any previous initial
14706 value. The default initial value is 0.
14708 @item info tvariables
14709 @kindex info tvariables
14710 List all the trace state variables along with their initial values.
14711 Their current values may also be displayed, if the trace experiment is
14714 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14715 @kindex delete tvariable
14716 Delete the given trace state variables, or all of them if no arguments
14721 @node Tracepoint Actions
14722 @subsection Tracepoint Action Lists
14726 @cindex tracepoint actions
14727 @item actions @r{[}@var{num}@r{]}
14728 This command will prompt for a list of actions to be taken when the
14729 tracepoint is hit. If the tracepoint number @var{num} is not
14730 specified, this command sets the actions for the one that was most
14731 recently defined (so that you can define a tracepoint and then say
14732 @code{actions} without bothering about its number). You specify the
14733 actions themselves on the following lines, one action at a time, and
14734 terminate the actions list with a line containing just @code{end}. So
14735 far, the only defined actions are @code{collect}, @code{teval}, and
14736 @code{while-stepping}.
14738 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14739 Commands, ,Breakpoint Command Lists}), except that only the defined
14740 actions are allowed; any other @value{GDBN} command is rejected.
14742 @cindex remove actions from a tracepoint
14743 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14744 and follow it immediately with @samp{end}.
14747 (@value{GDBP}) @b{collect @var{data}} // collect some data
14749 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14751 (@value{GDBP}) @b{end} // signals the end of actions.
14754 In the following example, the action list begins with @code{collect}
14755 commands indicating the things to be collected when the tracepoint is
14756 hit. Then, in order to single-step and collect additional data
14757 following the tracepoint, a @code{while-stepping} command is used,
14758 followed by the list of things to be collected after each step in a
14759 sequence of single steps. The @code{while-stepping} command is
14760 terminated by its own separate @code{end} command. Lastly, the action
14761 list is terminated by an @code{end} command.
14764 (@value{GDBP}) @b{trace foo}
14765 (@value{GDBP}) @b{actions}
14766 Enter actions for tracepoint 1, one per line:
14769 > while-stepping 12
14770 > collect $pc, arr[i]
14775 @kindex collect @r{(tracepoints)}
14776 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14777 Collect values of the given expressions when the tracepoint is hit.
14778 This command accepts a comma-separated list of any valid expressions.
14779 In addition to global, static, or local variables, the following
14780 special arguments are supported:
14784 Collect all registers.
14787 Collect all function arguments.
14790 Collect all local variables.
14793 Collect the return address. This is helpful if you want to see more
14796 @emph{Note:} The return address location can not always be reliably
14797 determined up front, and the wrong address / registers may end up
14798 collected instead. On some architectures the reliability is higher
14799 for tracepoints at function entry, while on others it's the opposite.
14800 When this happens, backtracing will stop because the return address is
14801 found unavailable (unless another collect rule happened to match it).
14804 Collects the number of arguments from the static probe at which the
14805 tracepoint is located.
14806 @xref{Static Probe Points}.
14808 @item $_probe_arg@var{n}
14809 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14810 from the static probe at which the tracepoint is located.
14811 @xref{Static Probe Points}.
14814 @vindex $_sdata@r{, collect}
14815 Collect static tracepoint marker specific data. Only available for
14816 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14817 Lists}. On the UST static tracepoints library backend, an
14818 instrumentation point resembles a @code{printf} function call. The
14819 tracing library is able to collect user specified data formatted to a
14820 character string using the format provided by the programmer that
14821 instrumented the program. Other backends have similar mechanisms.
14822 Here's an example of a UST marker call:
14825 const char master_name[] = "$your_name";
14826 trace_mark(channel1, marker1, "hello %s", master_name)
14829 In this case, collecting @code{$_sdata} collects the string
14830 @samp{hello $yourname}. When analyzing the trace buffer, you can
14831 inspect @samp{$_sdata} like any other variable available to
14835 You can give several consecutive @code{collect} commands, each one
14836 with a single argument, or one @code{collect} command with several
14837 arguments separated by commas; the effect is the same.
14839 The optional @var{mods} changes the usual handling of the arguments.
14840 @code{s} requests that pointers to chars be handled as strings, in
14841 particular collecting the contents of the memory being pointed at, up
14842 to the first zero. The upper bound is by default the value of the
14843 @code{print elements} variable; if @code{s} is followed by a decimal
14844 number, that is the upper bound instead. So for instance
14845 @samp{collect/s25 mystr} collects as many as 25 characters at
14848 The command @code{info scope} (@pxref{Symbols, info scope}) is
14849 particularly useful for figuring out what data to collect.
14851 @kindex teval @r{(tracepoints)}
14852 @item teval @var{expr1}, @var{expr2}, @dots{}
14853 Evaluate the given expressions when the tracepoint is hit. This
14854 command accepts a comma-separated list of expressions. The results
14855 are discarded, so this is mainly useful for assigning values to trace
14856 state variables (@pxref{Trace State Variables}) without adding those
14857 values to the trace buffer, as would be the case if the @code{collect}
14860 @kindex while-stepping @r{(tracepoints)}
14861 @item while-stepping @var{n}
14862 Perform @var{n} single-step instruction traces after the tracepoint,
14863 collecting new data after each step. The @code{while-stepping}
14864 command is followed by the list of what to collect while stepping
14865 (followed by its own @code{end} command):
14868 > while-stepping 12
14869 > collect $regs, myglobal
14875 Note that @code{$pc} is not automatically collected by
14876 @code{while-stepping}; you need to explicitly collect that register if
14877 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14880 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14881 @kindex set default-collect
14882 @cindex default collection action
14883 This variable is a list of expressions to collect at each tracepoint
14884 hit. It is effectively an additional @code{collect} action prepended
14885 to every tracepoint action list. The expressions are parsed
14886 individually for each tracepoint, so for instance a variable named
14887 @code{xyz} may be interpreted as a global for one tracepoint, and a
14888 local for another, as appropriate to the tracepoint's location.
14890 @item show default-collect
14891 @kindex show default-collect
14892 Show the list of expressions that are collected by default at each
14897 @node Listing Tracepoints
14898 @subsection Listing Tracepoints
14901 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14902 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14903 @cindex information about tracepoints
14904 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14905 Display information about the tracepoint @var{num}. If you don't
14906 specify a tracepoint number, displays information about all the
14907 tracepoints defined so far. The format is similar to that used for
14908 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14909 command, simply restricting itself to tracepoints.
14911 A tracepoint's listing may include additional information specific to
14916 its passcount as given by the @code{passcount @var{n}} command
14919 the state about installed on target of each location
14923 (@value{GDBP}) @b{info trace}
14924 Num Type Disp Enb Address What
14925 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14927 collect globfoo, $regs
14932 2 tracepoint keep y <MULTIPLE>
14934 2.1 y 0x0804859c in func4 at change-loc.h:35
14935 installed on target
14936 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14937 installed on target
14938 2.3 y <PENDING> set_tracepoint
14939 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14940 not installed on target
14945 This command can be abbreviated @code{info tp}.
14948 @node Listing Static Tracepoint Markers
14949 @subsection Listing Static Tracepoint Markers
14952 @kindex info static-tracepoint-markers
14953 @cindex information about static tracepoint markers
14954 @item info static-tracepoint-markers
14955 Display information about all static tracepoint markers defined in the
14958 For each marker, the following columns are printed:
14962 An incrementing counter, output to help readability. This is not a
14965 The marker ID, as reported by the target.
14966 @item Enabled or Disabled
14967 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14968 that are not enabled.
14970 Where the marker is in your program, as a memory address.
14972 Where the marker is in the source for your program, as a file and line
14973 number. If the debug information included in the program does not
14974 allow @value{GDBN} to locate the source of the marker, this column
14975 will be left blank.
14979 In addition, the following information may be printed for each marker:
14983 User data passed to the tracing library by the marker call. In the
14984 UST backend, this is the format string passed as argument to the
14986 @item Static tracepoints probing the marker
14987 The list of static tracepoints attached to the marker.
14991 (@value{GDBP}) info static-tracepoint-markers
14992 Cnt ID Enb Address What
14993 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14994 Data: number1 %d number2 %d
14995 Probed by static tracepoints: #2
14996 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
15002 @node Starting and Stopping Trace Experiments
15003 @subsection Starting and Stopping Trace Experiments
15006 @kindex tstart [ @var{notes} ]
15007 @cindex start a new trace experiment
15008 @cindex collected data discarded
15010 This command starts the trace experiment, and begins collecting data.
15011 It has the side effect of discarding all the data collected in the
15012 trace buffer during the previous trace experiment. If any arguments
15013 are supplied, they are taken as a note and stored with the trace
15014 experiment's state. The notes may be arbitrary text, and are
15015 especially useful with disconnected tracing in a multi-user context;
15016 the notes can explain what the trace is doing, supply user contact
15017 information, and so forth.
15019 @kindex tstop [ @var{notes} ]
15020 @cindex stop a running trace experiment
15022 This command stops the trace experiment. If any arguments are
15023 supplied, they are recorded with the experiment as a note. This is
15024 useful if you are stopping a trace started by someone else, for
15025 instance if the trace is interfering with the system's behavior and
15026 needs to be stopped quickly.
15028 @strong{Note}: a trace experiment and data collection may stop
15029 automatically if any tracepoint's passcount is reached
15030 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
15033 @cindex status of trace data collection
15034 @cindex trace experiment, status of
15036 This command displays the status of the current trace data
15040 Here is an example of the commands we described so far:
15043 (@value{GDBP}) @b{trace gdb_c_test}
15044 (@value{GDBP}) @b{actions}
15045 Enter actions for tracepoint #1, one per line.
15046 > collect $regs,$locals,$args
15047 > while-stepping 11
15051 (@value{GDBP}) @b{tstart}
15052 [time passes @dots{}]
15053 (@value{GDBP}) @b{tstop}
15056 @anchor{disconnected tracing}
15057 @cindex disconnected tracing
15058 You can choose to continue running the trace experiment even if
15059 @value{GDBN} disconnects from the target, voluntarily or
15060 involuntarily. For commands such as @code{detach}, the debugger will
15061 ask what you want to do with the trace. But for unexpected
15062 terminations (@value{GDBN} crash, network outage), it would be
15063 unfortunate to lose hard-won trace data, so the variable
15064 @code{disconnected-tracing} lets you decide whether the trace should
15065 continue running without @value{GDBN}.
15068 @item set disconnected-tracing on
15069 @itemx set disconnected-tracing off
15070 @kindex set disconnected-tracing
15071 Choose whether a tracing run should continue to run if @value{GDBN}
15072 has disconnected from the target. Note that @code{detach} or
15073 @code{quit} will ask you directly what to do about a running trace no
15074 matter what this variable's setting, so the variable is mainly useful
15075 for handling unexpected situations, such as loss of the network.
15077 @item show disconnected-tracing
15078 @kindex show disconnected-tracing
15079 Show the current choice for disconnected tracing.
15083 When you reconnect to the target, the trace experiment may or may not
15084 still be running; it might have filled the trace buffer in the
15085 meantime, or stopped for one of the other reasons. If it is running,
15086 it will continue after reconnection.
15088 Upon reconnection, the target will upload information about the
15089 tracepoints in effect. @value{GDBN} will then compare that
15090 information to the set of tracepoints currently defined, and attempt
15091 to match them up, allowing for the possibility that the numbers may
15092 have changed due to creation and deletion in the meantime. If one of
15093 the target's tracepoints does not match any in @value{GDBN}, the
15094 debugger will create a new tracepoint, so that you have a number with
15095 which to specify that tracepoint. This matching-up process is
15096 necessarily heuristic, and it may result in useless tracepoints being
15097 created; you may simply delete them if they are of no use.
15099 @cindex circular trace buffer
15100 If your target agent supports a @dfn{circular trace buffer}, then you
15101 can run a trace experiment indefinitely without filling the trace
15102 buffer; when space runs out, the agent deletes already-collected trace
15103 frames, oldest first, until there is enough room to continue
15104 collecting. This is especially useful if your tracepoints are being
15105 hit too often, and your trace gets terminated prematurely because the
15106 buffer is full. To ask for a circular trace buffer, simply set
15107 @samp{circular-trace-buffer} to on. You can set this at any time,
15108 including during tracing; if the agent can do it, it will change
15109 buffer handling on the fly, otherwise it will not take effect until
15113 @item set circular-trace-buffer on
15114 @itemx set circular-trace-buffer off
15115 @kindex set circular-trace-buffer
15116 Choose whether a tracing run should use a linear or circular buffer
15117 for trace data. A linear buffer will not lose any trace data, but may
15118 fill up prematurely, while a circular buffer will discard old trace
15119 data, but it will have always room for the latest tracepoint hits.
15121 @item show circular-trace-buffer
15122 @kindex show circular-trace-buffer
15123 Show the current choice for the trace buffer. Note that this may not
15124 match the agent's current buffer handling, nor is it guaranteed to
15125 match the setting that might have been in effect during a past run,
15126 for instance if you are looking at frames from a trace file.
15131 @item set trace-buffer-size @var{n}
15132 @itemx set trace-buffer-size unlimited
15133 @kindex set trace-buffer-size
15134 Request that the target use a trace buffer of @var{n} bytes. Not all
15135 targets will honor the request; they may have a compiled-in size for
15136 the trace buffer, or some other limitation. Set to a value of
15137 @code{unlimited} or @code{-1} to let the target use whatever size it
15138 likes. This is also the default.
15140 @item show trace-buffer-size
15141 @kindex show trace-buffer-size
15142 Show the current requested size for the trace buffer. Note that this
15143 will only match the actual size if the target supports size-setting,
15144 and was able to handle the requested size. For instance, if the
15145 target can only change buffer size between runs, this variable will
15146 not reflect the change until the next run starts. Use @code{tstatus}
15147 to get a report of the actual buffer size.
15151 @item set trace-user @var{text}
15152 @kindex set trace-user
15154 @item show trace-user
15155 @kindex show trace-user
15157 @item set trace-notes @var{text}
15158 @kindex set trace-notes
15159 Set the trace run's notes.
15161 @item show trace-notes
15162 @kindex show trace-notes
15163 Show the trace run's notes.
15165 @item set trace-stop-notes @var{text}
15166 @kindex set trace-stop-notes
15167 Set the trace run's stop notes. The handling of the note is as for
15168 @code{tstop} arguments; the set command is convenient way to fix a
15169 stop note that is mistaken or incomplete.
15171 @item show trace-stop-notes
15172 @kindex show trace-stop-notes
15173 Show the trace run's stop notes.
15177 @node Tracepoint Restrictions
15178 @subsection Tracepoint Restrictions
15180 @cindex tracepoint restrictions
15181 There are a number of restrictions on the use of tracepoints. As
15182 described above, tracepoint data gathering occurs on the target
15183 without interaction from @value{GDBN}. Thus the full capabilities of
15184 the debugger are not available during data gathering, and then at data
15185 examination time, you will be limited by only having what was
15186 collected. The following items describe some common problems, but it
15187 is not exhaustive, and you may run into additional difficulties not
15193 Tracepoint expressions are intended to gather objects (lvalues). Thus
15194 the full flexibility of GDB's expression evaluator is not available.
15195 You cannot call functions, cast objects to aggregate types, access
15196 convenience variables or modify values (except by assignment to trace
15197 state variables). Some language features may implicitly call
15198 functions (for instance Objective-C fields with accessors), and therefore
15199 cannot be collected either.
15202 Collection of local variables, either individually or in bulk with
15203 @code{$locals} or @code{$args}, during @code{while-stepping} may
15204 behave erratically. The stepping action may enter a new scope (for
15205 instance by stepping into a function), or the location of the variable
15206 may change (for instance it is loaded into a register). The
15207 tracepoint data recorded uses the location information for the
15208 variables that is correct for the tracepoint location. When the
15209 tracepoint is created, it is not possible, in general, to determine
15210 where the steps of a @code{while-stepping} sequence will advance the
15211 program---particularly if a conditional branch is stepped.
15214 Collection of an incompletely-initialized or partially-destroyed object
15215 may result in something that @value{GDBN} cannot display, or displays
15216 in a misleading way.
15219 When @value{GDBN} displays a pointer to character it automatically
15220 dereferences the pointer to also display characters of the string
15221 being pointed to. However, collecting the pointer during tracing does
15222 not automatically collect the string. You need to explicitly
15223 dereference the pointer and provide size information if you want to
15224 collect not only the pointer, but the memory pointed to. For example,
15225 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15229 It is not possible to collect a complete stack backtrace at a
15230 tracepoint. Instead, you may collect the registers and a few hundred
15231 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15232 (adjust to use the name of the actual stack pointer register on your
15233 target architecture, and the amount of stack you wish to capture).
15234 Then the @code{backtrace} command will show a partial backtrace when
15235 using a trace frame. The number of stack frames that can be examined
15236 depends on the sizes of the frames in the collected stack. Note that
15237 if you ask for a block so large that it goes past the bottom of the
15238 stack, the target agent may report an error trying to read from an
15242 If you do not collect registers at a tracepoint, @value{GDBN} can
15243 infer that the value of @code{$pc} must be the same as the address of
15244 the tracepoint and use that when you are looking at a trace frame
15245 for that tracepoint. However, this cannot work if the tracepoint has
15246 multiple locations (for instance if it was set in a function that was
15247 inlined), or if it has a @code{while-stepping} loop. In those cases
15248 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15253 @node Analyze Collected Data
15254 @section Using the Collected Data
15256 After the tracepoint experiment ends, you use @value{GDBN} commands
15257 for examining the trace data. The basic idea is that each tracepoint
15258 collects a trace @dfn{snapshot} every time it is hit and another
15259 snapshot every time it single-steps. All these snapshots are
15260 consecutively numbered from zero and go into a buffer, and you can
15261 examine them later. The way you examine them is to @dfn{focus} on a
15262 specific trace snapshot. When the remote stub is focused on a trace
15263 snapshot, it will respond to all @value{GDBN} requests for memory and
15264 registers by reading from the buffer which belongs to that snapshot,
15265 rather than from @emph{real} memory or registers of the program being
15266 debugged. This means that @strong{all} @value{GDBN} commands
15267 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15268 behave as if we were currently debugging the program state as it was
15269 when the tracepoint occurred. Any requests for data that are not in
15270 the buffer will fail.
15273 * tfind:: How to select a trace snapshot
15274 * tdump:: How to display all data for a snapshot
15275 * save tracepoints:: How to save tracepoints for a future run
15279 @subsection @code{tfind @var{n}}
15282 @cindex select trace snapshot
15283 @cindex find trace snapshot
15284 The basic command for selecting a trace snapshot from the buffer is
15285 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15286 counting from zero. If no argument @var{n} is given, the next
15287 snapshot is selected.
15289 Here are the various forms of using the @code{tfind} command.
15293 Find the first snapshot in the buffer. This is a synonym for
15294 @code{tfind 0} (since 0 is the number of the first snapshot).
15297 Stop debugging trace snapshots, resume @emph{live} debugging.
15300 Same as @samp{tfind none}.
15303 No argument means find the next trace snapshot or find the first
15304 one if no trace snapshot is selected.
15307 Find the previous trace snapshot before the current one. This permits
15308 retracing earlier steps.
15310 @item tfind tracepoint @var{num}
15311 Find the next snapshot associated with tracepoint @var{num}. Search
15312 proceeds forward from the last examined trace snapshot. If no
15313 argument @var{num} is given, it means find the next snapshot collected
15314 for the same tracepoint as the current snapshot.
15316 @item tfind pc @var{addr}
15317 Find the next snapshot associated with the value @var{addr} of the
15318 program counter. Search proceeds forward from the last examined trace
15319 snapshot. If no argument @var{addr} is given, it means find the next
15320 snapshot with the same value of PC as the current snapshot.
15322 @item tfind outside @var{addr1}, @var{addr2}
15323 Find the next snapshot whose PC is outside the given range of
15324 addresses (exclusive).
15326 @item tfind range @var{addr1}, @var{addr2}
15327 Find the next snapshot whose PC is between @var{addr1} and
15328 @var{addr2} (inclusive).
15330 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15331 Find the next snapshot associated with the source line @var{n}. If
15332 the optional argument @var{file} is given, refer to line @var{n} in
15333 that source file. Search proceeds forward from the last examined
15334 trace snapshot. If no argument @var{n} is given, it means find the
15335 next line other than the one currently being examined; thus saying
15336 @code{tfind line} repeatedly can appear to have the same effect as
15337 stepping from line to line in a @emph{live} debugging session.
15340 The default arguments for the @code{tfind} commands are specifically
15341 designed to make it easy to scan through the trace buffer. For
15342 instance, @code{tfind} with no argument selects the next trace
15343 snapshot, and @code{tfind -} with no argument selects the previous
15344 trace snapshot. So, by giving one @code{tfind} command, and then
15345 simply hitting @key{RET} repeatedly you can examine all the trace
15346 snapshots in order. Or, by saying @code{tfind -} and then hitting
15347 @key{RET} repeatedly you can examine the snapshots in reverse order.
15348 The @code{tfind line} command with no argument selects the snapshot
15349 for the next source line executed. The @code{tfind pc} command with
15350 no argument selects the next snapshot with the same program counter
15351 (PC) as the current frame. The @code{tfind tracepoint} command with
15352 no argument selects the next trace snapshot collected by the same
15353 tracepoint as the current one.
15355 In addition to letting you scan through the trace buffer manually,
15356 these commands make it easy to construct @value{GDBN} scripts that
15357 scan through the trace buffer and print out whatever collected data
15358 you are interested in. Thus, if we want to examine the PC, FP, and SP
15359 registers from each trace frame in the buffer, we can say this:
15362 (@value{GDBP}) @b{tfind start}
15363 (@value{GDBP}) @b{while ($trace_frame != -1)}
15364 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15365 $trace_frame, $pc, $sp, $fp
15369 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15370 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15371 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15372 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15373 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15374 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15375 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15376 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15377 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15378 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15379 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15382 Or, if we want to examine the variable @code{X} at each source line in
15386 (@value{GDBP}) @b{tfind start}
15387 (@value{GDBP}) @b{while ($trace_frame != -1)}
15388 > printf "Frame %d, X == %d\n", $trace_frame, X
15398 @subsection @code{tdump}
15400 @cindex dump all data collected at tracepoint
15401 @cindex tracepoint data, display
15403 This command takes no arguments. It prints all the data collected at
15404 the current trace snapshot.
15407 (@value{GDBP}) @b{trace 444}
15408 (@value{GDBP}) @b{actions}
15409 Enter actions for tracepoint #2, one per line:
15410 > collect $regs, $locals, $args, gdb_long_test
15413 (@value{GDBP}) @b{tstart}
15415 (@value{GDBP}) @b{tfind line 444}
15416 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15418 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15420 (@value{GDBP}) @b{tdump}
15421 Data collected at tracepoint 2, trace frame 1:
15422 d0 0xc4aa0085 -995491707
15426 d4 0x71aea3d 119204413
15429 d7 0x380035 3670069
15430 a0 0x19e24a 1696330
15431 a1 0x3000668 50333288
15433 a3 0x322000 3284992
15434 a4 0x3000698 50333336
15435 a5 0x1ad3cc 1758156
15436 fp 0x30bf3c 0x30bf3c
15437 sp 0x30bf34 0x30bf34
15439 pc 0x20b2c8 0x20b2c8
15443 p = 0x20e5b4 "gdb-test"
15450 gdb_long_test = 17 '\021'
15455 @code{tdump} works by scanning the tracepoint's current collection
15456 actions and printing the value of each expression listed. So
15457 @code{tdump} can fail, if after a run, you change the tracepoint's
15458 actions to mention variables that were not collected during the run.
15460 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15461 uses the collected value of @code{$pc} to distinguish between trace
15462 frames that were collected at the tracepoint hit, and frames that were
15463 collected while stepping. This allows it to correctly choose whether
15464 to display the basic list of collections, or the collections from the
15465 body of the while-stepping loop. However, if @code{$pc} was not collected,
15466 then @code{tdump} will always attempt to dump using the basic collection
15467 list, and may fail if a while-stepping frame does not include all the
15468 same data that is collected at the tracepoint hit.
15469 @c This is getting pretty arcane, example would be good.
15471 @node save tracepoints
15472 @subsection @code{save tracepoints @var{filename}}
15473 @kindex save tracepoints
15474 @kindex save-tracepoints
15475 @cindex save tracepoints for future sessions
15477 This command saves all current tracepoint definitions together with
15478 their actions and passcounts, into a file @file{@var{filename}}
15479 suitable for use in a later debugging session. To read the saved
15480 tracepoint definitions, use the @code{source} command (@pxref{Command
15481 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15482 alias for @w{@code{save tracepoints}}
15484 @node Tracepoint Variables
15485 @section Convenience Variables for Tracepoints
15486 @cindex tracepoint variables
15487 @cindex convenience variables for tracepoints
15490 @vindex $trace_frame
15491 @item (int) $trace_frame
15492 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15493 snapshot is selected.
15495 @vindex $tracepoint
15496 @item (int) $tracepoint
15497 The tracepoint for the current trace snapshot.
15499 @vindex $trace_line
15500 @item (int) $trace_line
15501 The line number for the current trace snapshot.
15503 @vindex $trace_file
15504 @item (char []) $trace_file
15505 The source file for the current trace snapshot.
15507 @vindex $trace_func
15508 @item (char []) $trace_func
15509 The name of the function containing @code{$tracepoint}.
15512 Note: @code{$trace_file} is not suitable for use in @code{printf},
15513 use @code{output} instead.
15515 Here's a simple example of using these convenience variables for
15516 stepping through all the trace snapshots and printing some of their
15517 data. Note that these are not the same as trace state variables,
15518 which are managed by the target.
15521 (@value{GDBP}) @b{tfind start}
15523 (@value{GDBP}) @b{while $trace_frame != -1}
15524 > output $trace_file
15525 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15531 @section Using Trace Files
15532 @cindex trace files
15534 In some situations, the target running a trace experiment may no
15535 longer be available; perhaps it crashed, or the hardware was needed
15536 for a different activity. To handle these cases, you can arrange to
15537 dump the trace data into a file, and later use that file as a source
15538 of trace data, via the @code{target tfile} command.
15543 @item tsave [ -r ] @var{filename}
15544 @itemx tsave [-ctf] @var{dirname}
15545 Save the trace data to @var{filename}. By default, this command
15546 assumes that @var{filename} refers to the host filesystem, so if
15547 necessary @value{GDBN} will copy raw trace data up from the target and
15548 then save it. If the target supports it, you can also supply the
15549 optional argument @code{-r} (``remote'') to direct the target to save
15550 the data directly into @var{filename} in its own filesystem, which may be
15551 more efficient if the trace buffer is very large. (Note, however, that
15552 @code{target tfile} can only read from files accessible to the host.)
15553 By default, this command will save trace frame in tfile format.
15554 You can supply the optional argument @code{-ctf} to save data in CTF
15555 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15556 that can be shared by multiple debugging and tracing tools. Please go to
15557 @indicateurl{http://www.efficios.com/ctf} to get more information.
15559 @kindex target tfile
15563 @item target tfile @var{filename}
15564 @itemx target ctf @var{dirname}
15565 Use the file named @var{filename} or directory named @var{dirname} as
15566 a source of trace data. Commands that examine data work as they do with
15567 a live target, but it is not possible to run any new trace experiments.
15568 @code{tstatus} will report the state of the trace run at the moment
15569 the data was saved, as well as the current trace frame you are examining.
15570 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15574 (@value{GDBP}) target ctf ctf.ctf
15575 (@value{GDBP}) tfind
15576 Found trace frame 0, tracepoint 2
15577 39 ++a; /* set tracepoint 1 here */
15578 (@value{GDBP}) tdump
15579 Data collected at tracepoint 2, trace frame 0:
15583 c = @{"123", "456", "789", "123", "456", "789"@}
15584 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15592 @chapter Debugging Programs That Use Overlays
15595 If your program is too large to fit completely in your target system's
15596 memory, you can sometimes use @dfn{overlays} to work around this
15597 problem. @value{GDBN} provides some support for debugging programs that
15601 * How Overlays Work:: A general explanation of overlays.
15602 * Overlay Commands:: Managing overlays in @value{GDBN}.
15603 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15604 mapped by asking the inferior.
15605 * Overlay Sample Program:: A sample program using overlays.
15608 @node How Overlays Work
15609 @section How Overlays Work
15610 @cindex mapped overlays
15611 @cindex unmapped overlays
15612 @cindex load address, overlay's
15613 @cindex mapped address
15614 @cindex overlay area
15616 Suppose you have a computer whose instruction address space is only 64
15617 kilobytes long, but which has much more memory which can be accessed by
15618 other means: special instructions, segment registers, or memory
15619 management hardware, for example. Suppose further that you want to
15620 adapt a program which is larger than 64 kilobytes to run on this system.
15622 One solution is to identify modules of your program which are relatively
15623 independent, and need not call each other directly; call these modules
15624 @dfn{overlays}. Separate the overlays from the main program, and place
15625 their machine code in the larger memory. Place your main program in
15626 instruction memory, but leave at least enough space there to hold the
15627 largest overlay as well.
15629 Now, to call a function located in an overlay, you must first copy that
15630 overlay's machine code from the large memory into the space set aside
15631 for it in the instruction memory, and then jump to its entry point
15634 @c NB: In the below the mapped area's size is greater or equal to the
15635 @c size of all overlays. This is intentional to remind the developer
15636 @c that overlays don't necessarily need to be the same size.
15640 Data Instruction Larger
15641 Address Space Address Space Address Space
15642 +-----------+ +-----------+ +-----------+
15644 +-----------+ +-----------+ +-----------+<-- overlay 1
15645 | program | | main | .----| overlay 1 | load address
15646 | variables | | program | | +-----------+
15647 | and heap | | | | | |
15648 +-----------+ | | | +-----------+<-- overlay 2
15649 | | +-----------+ | | | load address
15650 +-----------+ | | | .-| overlay 2 |
15652 mapped --->+-----------+ | | +-----------+
15653 address | | | | | |
15654 | overlay | <-' | | |
15655 | area | <---' +-----------+<-- overlay 3
15656 | | <---. | | load address
15657 +-----------+ `--| overlay 3 |
15664 @anchor{A code overlay}A code overlay
15668 The diagram (@pxref{A code overlay}) shows a system with separate data
15669 and instruction address spaces. To map an overlay, the program copies
15670 its code from the larger address space to the instruction address space.
15671 Since the overlays shown here all use the same mapped address, only one
15672 may be mapped at a time. For a system with a single address space for
15673 data and instructions, the diagram would be similar, except that the
15674 program variables and heap would share an address space with the main
15675 program and the overlay area.
15677 An overlay loaded into instruction memory and ready for use is called a
15678 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15679 instruction memory. An overlay not present (or only partially present)
15680 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15681 is its address in the larger memory. The mapped address is also called
15682 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15683 called the @dfn{load memory address}, or @dfn{LMA}.
15685 Unfortunately, overlays are not a completely transparent way to adapt a
15686 program to limited instruction memory. They introduce a new set of
15687 global constraints you must keep in mind as you design your program:
15692 Before calling or returning to a function in an overlay, your program
15693 must make sure that overlay is actually mapped. Otherwise, the call or
15694 return will transfer control to the right address, but in the wrong
15695 overlay, and your program will probably crash.
15698 If the process of mapping an overlay is expensive on your system, you
15699 will need to choose your overlays carefully to minimize their effect on
15700 your program's performance.
15703 The executable file you load onto your system must contain each
15704 overlay's instructions, appearing at the overlay's load address, not its
15705 mapped address. However, each overlay's instructions must be relocated
15706 and its symbols defined as if the overlay were at its mapped address.
15707 You can use GNU linker scripts to specify different load and relocation
15708 addresses for pieces of your program; see @ref{Overlay Description,,,
15709 ld.info, Using ld: the GNU linker}.
15712 The procedure for loading executable files onto your system must be able
15713 to load their contents into the larger address space as well as the
15714 instruction and data spaces.
15718 The overlay system described above is rather simple, and could be
15719 improved in many ways:
15724 If your system has suitable bank switch registers or memory management
15725 hardware, you could use those facilities to make an overlay's load area
15726 contents simply appear at their mapped address in instruction space.
15727 This would probably be faster than copying the overlay to its mapped
15728 area in the usual way.
15731 If your overlays are small enough, you could set aside more than one
15732 overlay area, and have more than one overlay mapped at a time.
15735 You can use overlays to manage data, as well as instructions. In
15736 general, data overlays are even less transparent to your design than
15737 code overlays: whereas code overlays only require care when you call or
15738 return to functions, data overlays require care every time you access
15739 the data. Also, if you change the contents of a data overlay, you
15740 must copy its contents back out to its load address before you can copy a
15741 different data overlay into the same mapped area.
15746 @node Overlay Commands
15747 @section Overlay Commands
15749 To use @value{GDBN}'s overlay support, each overlay in your program must
15750 correspond to a separate section of the executable file. The section's
15751 virtual memory address and load memory address must be the overlay's
15752 mapped and load addresses. Identifying overlays with sections allows
15753 @value{GDBN} to determine the appropriate address of a function or
15754 variable, depending on whether the overlay is mapped or not.
15756 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15757 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15762 Disable @value{GDBN}'s overlay support. When overlay support is
15763 disabled, @value{GDBN} assumes that all functions and variables are
15764 always present at their mapped addresses. By default, @value{GDBN}'s
15765 overlay support is disabled.
15767 @item overlay manual
15768 @cindex manual overlay debugging
15769 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15770 relies on you to tell it which overlays are mapped, and which are not,
15771 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15772 commands described below.
15774 @item overlay map-overlay @var{overlay}
15775 @itemx overlay map @var{overlay}
15776 @cindex map an overlay
15777 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15778 be the name of the object file section containing the overlay. When an
15779 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15780 functions and variables at their mapped addresses. @value{GDBN} assumes
15781 that any other overlays whose mapped ranges overlap that of
15782 @var{overlay} are now unmapped.
15784 @item overlay unmap-overlay @var{overlay}
15785 @itemx overlay unmap @var{overlay}
15786 @cindex unmap an overlay
15787 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15788 must be the name of the object file section containing the overlay.
15789 When an overlay is unmapped, @value{GDBN} assumes it can find the
15790 overlay's functions and variables at their load addresses.
15793 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15794 consults a data structure the overlay manager maintains in the inferior
15795 to see which overlays are mapped. For details, see @ref{Automatic
15796 Overlay Debugging}.
15798 @item overlay load-target
15799 @itemx overlay load
15800 @cindex reloading the overlay table
15801 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15802 re-reads the table @value{GDBN} automatically each time the inferior
15803 stops, so this command should only be necessary if you have changed the
15804 overlay mapping yourself using @value{GDBN}. This command is only
15805 useful when using automatic overlay debugging.
15807 @item overlay list-overlays
15808 @itemx overlay list
15809 @cindex listing mapped overlays
15810 Display a list of the overlays currently mapped, along with their mapped
15811 addresses, load addresses, and sizes.
15815 Normally, when @value{GDBN} prints a code address, it includes the name
15816 of the function the address falls in:
15819 (@value{GDBP}) print main
15820 $3 = @{int ()@} 0x11a0 <main>
15823 When overlay debugging is enabled, @value{GDBN} recognizes code in
15824 unmapped overlays, and prints the names of unmapped functions with
15825 asterisks around them. For example, if @code{foo} is a function in an
15826 unmapped overlay, @value{GDBN} prints it this way:
15829 (@value{GDBP}) overlay list
15830 No sections are mapped.
15831 (@value{GDBP}) print foo
15832 $5 = @{int (int)@} 0x100000 <*foo*>
15835 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15839 (@value{GDBP}) overlay list
15840 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15841 mapped at 0x1016 - 0x104a
15842 (@value{GDBP}) print foo
15843 $6 = @{int (int)@} 0x1016 <foo>
15846 When overlay debugging is enabled, @value{GDBN} can find the correct
15847 address for functions and variables in an overlay, whether or not the
15848 overlay is mapped. This allows most @value{GDBN} commands, like
15849 @code{break} and @code{disassemble}, to work normally, even on unmapped
15850 code. However, @value{GDBN}'s breakpoint support has some limitations:
15854 @cindex breakpoints in overlays
15855 @cindex overlays, setting breakpoints in
15856 You can set breakpoints in functions in unmapped overlays, as long as
15857 @value{GDBN} can write to the overlay at its load address.
15859 @value{GDBN} can not set hardware or simulator-based breakpoints in
15860 unmapped overlays. However, if you set a breakpoint at the end of your
15861 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15862 you are using manual overlay management), @value{GDBN} will re-set its
15863 breakpoints properly.
15867 @node Automatic Overlay Debugging
15868 @section Automatic Overlay Debugging
15869 @cindex automatic overlay debugging
15871 @value{GDBN} can automatically track which overlays are mapped and which
15872 are not, given some simple co-operation from the overlay manager in the
15873 inferior. If you enable automatic overlay debugging with the
15874 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15875 looks in the inferior's memory for certain variables describing the
15876 current state of the overlays.
15878 Here are the variables your overlay manager must define to support
15879 @value{GDBN}'s automatic overlay debugging:
15883 @item @code{_ovly_table}:
15884 This variable must be an array of the following structures:
15889 /* The overlay's mapped address. */
15892 /* The size of the overlay, in bytes. */
15893 unsigned long size;
15895 /* The overlay's load address. */
15898 /* Non-zero if the overlay is currently mapped;
15900 unsigned long mapped;
15904 @item @code{_novlys}:
15905 This variable must be a four-byte signed integer, holding the total
15906 number of elements in @code{_ovly_table}.
15910 To decide whether a particular overlay is mapped or not, @value{GDBN}
15911 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15912 @code{lma} members equal the VMA and LMA of the overlay's section in the
15913 executable file. When @value{GDBN} finds a matching entry, it consults
15914 the entry's @code{mapped} member to determine whether the overlay is
15917 In addition, your overlay manager may define a function called
15918 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15919 will silently set a breakpoint there. If the overlay manager then
15920 calls this function whenever it has changed the overlay table, this
15921 will enable @value{GDBN} to accurately keep track of which overlays
15922 are in program memory, and update any breakpoints that may be set
15923 in overlays. This will allow breakpoints to work even if the
15924 overlays are kept in ROM or other non-writable memory while they
15925 are not being executed.
15927 @node Overlay Sample Program
15928 @section Overlay Sample Program
15929 @cindex overlay example program
15931 When linking a program which uses overlays, you must place the overlays
15932 at their load addresses, while relocating them to run at their mapped
15933 addresses. To do this, you must write a linker script (@pxref{Overlay
15934 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15935 since linker scripts are specific to a particular host system, target
15936 architecture, and target memory layout, this manual cannot provide
15937 portable sample code demonstrating @value{GDBN}'s overlay support.
15939 However, the @value{GDBN} source distribution does contain an overlaid
15940 program, with linker scripts for a few systems, as part of its test
15941 suite. The program consists of the following files from
15942 @file{gdb/testsuite/gdb.base}:
15946 The main program file.
15948 A simple overlay manager, used by @file{overlays.c}.
15953 Overlay modules, loaded and used by @file{overlays.c}.
15956 Linker scripts for linking the test program on the @code{d10v-elf}
15957 and @code{m32r-elf} targets.
15960 You can build the test program using the @code{d10v-elf} GCC
15961 cross-compiler like this:
15964 $ d10v-elf-gcc -g -c overlays.c
15965 $ d10v-elf-gcc -g -c ovlymgr.c
15966 $ d10v-elf-gcc -g -c foo.c
15967 $ d10v-elf-gcc -g -c bar.c
15968 $ d10v-elf-gcc -g -c baz.c
15969 $ d10v-elf-gcc -g -c grbx.c
15970 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15971 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15974 The build process is identical for any other architecture, except that
15975 you must substitute the appropriate compiler and linker script for the
15976 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15980 @chapter Using @value{GDBN} with Different Languages
15983 Although programming languages generally have common aspects, they are
15984 rarely expressed in the same manner. For instance, in ANSI C,
15985 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15986 Modula-2, it is accomplished by @code{p^}. Values can also be
15987 represented (and displayed) differently. Hex numbers in C appear as
15988 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15990 @cindex working language
15991 Language-specific information is built into @value{GDBN} for some languages,
15992 allowing you to express operations like the above in your program's
15993 native language, and allowing @value{GDBN} to output values in a manner
15994 consistent with the syntax of your program's native language. The
15995 language you use to build expressions is called the @dfn{working
15999 * Setting:: Switching between source languages
16000 * Show:: Displaying the language
16001 * Checks:: Type and range checks
16002 * Supported Languages:: Supported languages
16003 * Unsupported Languages:: Unsupported languages
16007 @section Switching Between Source Languages
16009 There are two ways to control the working language---either have @value{GDBN}
16010 set it automatically, or select it manually yourself. You can use the
16011 @code{set language} command for either purpose. On startup, @value{GDBN}
16012 defaults to setting the language automatically. The working language is
16013 used to determine how expressions you type are interpreted, how values
16016 In addition to the working language, every source file that
16017 @value{GDBN} knows about has its own working language. For some object
16018 file formats, the compiler might indicate which language a particular
16019 source file is in. However, most of the time @value{GDBN} infers the
16020 language from the name of the file. The language of a source file
16021 controls whether C@t{++} names are demangled---this way @code{backtrace} can
16022 show each frame appropriately for its own language. There is no way to
16023 set the language of a source file from within @value{GDBN}, but you can
16024 set the language associated with a filename extension. @xref{Show, ,
16025 Displaying the Language}.
16027 This is most commonly a problem when you use a program, such
16028 as @code{cfront} or @code{f2c}, that generates C but is written in
16029 another language. In that case, make the
16030 program use @code{#line} directives in its C output; that way
16031 @value{GDBN} will know the correct language of the source code of the original
16032 program, and will display that source code, not the generated C code.
16035 * Filenames:: Filename extensions and languages.
16036 * Manually:: Setting the working language manually
16037 * Automatically:: Having @value{GDBN} infer the source language
16041 @subsection List of Filename Extensions and Languages
16043 If a source file name ends in one of the following extensions, then
16044 @value{GDBN} infers that its language is the one indicated.
16062 C@t{++} source file
16068 Objective-C source file
16072 Fortran source file
16075 Modula-2 source file
16079 Assembler source file. This actually behaves almost like C, but
16080 @value{GDBN} does not skip over function prologues when stepping.
16083 In addition, you may set the language associated with a filename
16084 extension. @xref{Show, , Displaying the Language}.
16087 @subsection Setting the Working Language
16089 If you allow @value{GDBN} to set the language automatically,
16090 expressions are interpreted the same way in your debugging session and
16093 @kindex set language
16094 If you wish, you may set the language manually. To do this, issue the
16095 command @samp{set language @var{lang}}, where @var{lang} is the name of
16096 a language, such as
16097 @code{c} or @code{modula-2}.
16098 For a list of the supported languages, type @samp{set language}.
16100 Setting the language manually prevents @value{GDBN} from updating the working
16101 language automatically. This can lead to confusion if you try
16102 to debug a program when the working language is not the same as the
16103 source language, when an expression is acceptable to both
16104 languages---but means different things. For instance, if the current
16105 source file were written in C, and @value{GDBN} was parsing Modula-2, a
16113 might not have the effect you intended. In C, this means to add
16114 @code{b} and @code{c} and place the result in @code{a}. The result
16115 printed would be the value of @code{a}. In Modula-2, this means to compare
16116 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
16118 @node Automatically
16119 @subsection Having @value{GDBN} Infer the Source Language
16121 To have @value{GDBN} set the working language automatically, use
16122 @samp{set language local} or @samp{set language auto}. @value{GDBN}
16123 then infers the working language. That is, when your program stops in a
16124 frame (usually by encountering a breakpoint), @value{GDBN} sets the
16125 working language to the language recorded for the function in that
16126 frame. If the language for a frame is unknown (that is, if the function
16127 or block corresponding to the frame was defined in a source file that
16128 does not have a recognized extension), the current working language is
16129 not changed, and @value{GDBN} issues a warning.
16131 This may not seem necessary for most programs, which are written
16132 entirely in one source language. However, program modules and libraries
16133 written in one source language can be used by a main program written in
16134 a different source language. Using @samp{set language auto} in this
16135 case frees you from having to set the working language manually.
16138 @section Displaying the Language
16140 The following commands help you find out which language is the
16141 working language, and also what language source files were written in.
16144 @item show language
16145 @anchor{show language}
16146 @kindex show language
16147 Display the current working language. This is the
16148 language you can use with commands such as @code{print} to
16149 build and compute expressions that may involve variables in your program.
16152 @kindex info frame@r{, show the source language}
16153 Display the source language for this frame. This language becomes the
16154 working language if you use an identifier from this frame.
16155 @xref{Frame Info, ,Information about a Frame}, to identify the other
16156 information listed here.
16159 @kindex info source@r{, show the source language}
16160 Display the source language of this source file.
16161 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16162 information listed here.
16165 In unusual circumstances, you may have source files with extensions
16166 not in the standard list. You can then set the extension associated
16167 with a language explicitly:
16170 @item set extension-language @var{ext} @var{language}
16171 @kindex set extension-language
16172 Tell @value{GDBN} that source files with extension @var{ext} are to be
16173 assumed as written in the source language @var{language}.
16175 @item info extensions
16176 @kindex info extensions
16177 List all the filename extensions and the associated languages.
16181 @section Type and Range Checking
16183 Some languages are designed to guard you against making seemingly common
16184 errors through a series of compile- and run-time checks. These include
16185 checking the type of arguments to functions and operators and making
16186 sure mathematical overflows are caught at run time. Checks such as
16187 these help to ensure a program's correctness once it has been compiled
16188 by eliminating type mismatches and providing active checks for range
16189 errors when your program is running.
16191 By default @value{GDBN} checks for these errors according to the
16192 rules of the current source language. Although @value{GDBN} does not check
16193 the statements in your program, it can check expressions entered directly
16194 into @value{GDBN} for evaluation via the @code{print} command, for example.
16197 * Type Checking:: An overview of type checking
16198 * Range Checking:: An overview of range checking
16201 @cindex type checking
16202 @cindex checks, type
16203 @node Type Checking
16204 @subsection An Overview of Type Checking
16206 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16207 arguments to operators and functions have to be of the correct type,
16208 otherwise an error occurs. These checks prevent type mismatch
16209 errors from ever causing any run-time problems. For example,
16212 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16214 (@value{GDBP}) print obj.my_method (0)
16217 (@value{GDBP}) print obj.my_method (0x1234)
16218 Cannot resolve method klass::my_method to any overloaded instance
16221 The second example fails because in C@t{++} the integer constant
16222 @samp{0x1234} is not type-compatible with the pointer parameter type.
16224 For the expressions you use in @value{GDBN} commands, you can tell
16225 @value{GDBN} to not enforce strict type checking or
16226 to treat any mismatches as errors and abandon the expression;
16227 When type checking is disabled, @value{GDBN} successfully evaluates
16228 expressions like the second example above.
16230 Even if type checking is off, there may be other reasons
16231 related to type that prevent @value{GDBN} from evaluating an expression.
16232 For instance, @value{GDBN} does not know how to add an @code{int} and
16233 a @code{struct foo}. These particular type errors have nothing to do
16234 with the language in use and usually arise from expressions which make
16235 little sense to evaluate anyway.
16237 @value{GDBN} provides some additional commands for controlling type checking:
16239 @kindex set check type
16240 @kindex show check type
16242 @item set check type on
16243 @itemx set check type off
16244 Set strict type checking on or off. If any type mismatches occur in
16245 evaluating an expression while type checking is on, @value{GDBN} prints a
16246 message and aborts evaluation of the expression.
16248 @item show check type
16249 Show the current setting of type checking and whether @value{GDBN}
16250 is enforcing strict type checking rules.
16253 @cindex range checking
16254 @cindex checks, range
16255 @node Range Checking
16256 @subsection An Overview of Range Checking
16258 In some languages (such as Modula-2), it is an error to exceed the
16259 bounds of a type; this is enforced with run-time checks. Such range
16260 checking is meant to ensure program correctness by making sure
16261 computations do not overflow, or indices on an array element access do
16262 not exceed the bounds of the array.
16264 For expressions you use in @value{GDBN} commands, you can tell
16265 @value{GDBN} to treat range errors in one of three ways: ignore them,
16266 always treat them as errors and abandon the expression, or issue
16267 warnings but evaluate the expression anyway.
16269 A range error can result from numerical overflow, from exceeding an
16270 array index bound, or when you type a constant that is not a member
16271 of any type. Some languages, however, do not treat overflows as an
16272 error. In many implementations of C, mathematical overflow causes the
16273 result to ``wrap around'' to lower values---for example, if @var{m} is
16274 the largest integer value, and @var{s} is the smallest, then
16277 @var{m} + 1 @result{} @var{s}
16280 This, too, is specific to individual languages, and in some cases
16281 specific to individual compilers or machines. @xref{Supported Languages, ,
16282 Supported Languages}, for further details on specific languages.
16284 @value{GDBN} provides some additional commands for controlling the range checker:
16286 @kindex set check range
16287 @kindex show check range
16289 @item set check range auto
16290 Set range checking on or off based on the current working language.
16291 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16294 @item set check range on
16295 @itemx set check range off
16296 Set range checking on or off, overriding the default setting for the
16297 current working language. A warning is issued if the setting does not
16298 match the language default. If a range error occurs and range checking is on,
16299 then a message is printed and evaluation of the expression is aborted.
16301 @item set check range warn
16302 Output messages when the @value{GDBN} range checker detects a range error,
16303 but attempt to evaluate the expression anyway. Evaluating the
16304 expression may still be impossible for other reasons, such as accessing
16305 memory that the process does not own (a typical example from many Unix
16308 @item show check range
16309 Show the current setting of the range checker, and whether or not it is
16310 being set automatically by @value{GDBN}.
16313 @node Supported Languages
16314 @section Supported Languages
16316 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16317 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16318 @c This is false ...
16319 Some @value{GDBN} features may be used in expressions regardless of the
16320 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16321 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16322 ,Expressions}) can be used with the constructs of any supported
16325 The following sections detail to what degree each source language is
16326 supported by @value{GDBN}. These sections are not meant to be language
16327 tutorials or references, but serve only as a reference guide to what the
16328 @value{GDBN} expression parser accepts, and what input and output
16329 formats should look like for different languages. There are many good
16330 books written on each of these languages; please look to these for a
16331 language reference or tutorial.
16334 * C:: C and C@t{++}
16337 * Objective-C:: Objective-C
16338 * OpenCL C:: OpenCL C
16339 * Fortran:: Fortran
16342 * Modula-2:: Modula-2
16347 @subsection C and C@t{++}
16349 @cindex C and C@t{++}
16350 @cindex expressions in C or C@t{++}
16352 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16353 to both languages. Whenever this is the case, we discuss those languages
16357 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16358 @cindex @sc{gnu} C@t{++}
16359 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16360 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16361 effectively, you must compile your C@t{++} programs with a supported
16362 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16363 compiler (@code{aCC}).
16366 * C Operators:: C and C@t{++} operators
16367 * C Constants:: C and C@t{++} constants
16368 * C Plus Plus Expressions:: C@t{++} expressions
16369 * C Defaults:: Default settings for C and C@t{++}
16370 * C Checks:: C and C@t{++} type and range checks
16371 * Debugging C:: @value{GDBN} and C
16372 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16373 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16377 @subsubsection C and C@t{++} Operators
16379 @cindex C and C@t{++} operators
16381 Operators must be defined on values of specific types. For instance,
16382 @code{+} is defined on numbers, but not on structures. Operators are
16383 often defined on groups of types.
16385 For the purposes of C and C@t{++}, the following definitions hold:
16390 @emph{Integral types} include @code{int} with any of its storage-class
16391 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16394 @emph{Floating-point types} include @code{float}, @code{double}, and
16395 @code{long double} (if supported by the target platform).
16398 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16401 @emph{Scalar types} include all of the above.
16406 The following operators are supported. They are listed here
16407 in order of increasing precedence:
16411 The comma or sequencing operator. Expressions in a comma-separated list
16412 are evaluated from left to right, with the result of the entire
16413 expression being the last expression evaluated.
16416 Assignment. The value of an assignment expression is the value
16417 assigned. Defined on scalar types.
16420 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16421 and translated to @w{@code{@var{a} = @var{a op b}}}.
16422 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16423 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16424 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16427 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16428 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16429 should be of an integral type.
16432 Logical @sc{or}. Defined on integral types.
16435 Logical @sc{and}. Defined on integral types.
16438 Bitwise @sc{or}. Defined on integral types.
16441 Bitwise exclusive-@sc{or}. Defined on integral types.
16444 Bitwise @sc{and}. Defined on integral types.
16447 Equality and inequality. Defined on scalar types. The value of these
16448 expressions is 0 for false and non-zero for true.
16450 @item <@r{, }>@r{, }<=@r{, }>=
16451 Less than, greater than, less than or equal, greater than or equal.
16452 Defined on scalar types. The value of these expressions is 0 for false
16453 and non-zero for true.
16456 left shift, and right shift. Defined on integral types.
16459 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16462 Addition and subtraction. Defined on integral types, floating-point types and
16465 @item *@r{, }/@r{, }%
16466 Multiplication, division, and modulus. Multiplication and division are
16467 defined on integral and floating-point types. Modulus is defined on
16471 Increment and decrement. When appearing before a variable, the
16472 operation is performed before the variable is used in an expression;
16473 when appearing after it, the variable's value is used before the
16474 operation takes place.
16477 Pointer dereferencing. Defined on pointer types. Same precedence as
16481 Address operator. Defined on variables. Same precedence as @code{++}.
16483 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16484 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16485 to examine the address
16486 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16490 Negative. Defined on integral and floating-point types. Same
16491 precedence as @code{++}.
16494 Logical negation. Defined on integral types. Same precedence as
16498 Bitwise complement operator. Defined on integral types. Same precedence as
16503 Structure member, and pointer-to-structure member. For convenience,
16504 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16505 pointer based on the stored type information.
16506 Defined on @code{struct} and @code{union} data.
16509 Dereferences of pointers to members.
16512 Array indexing. @code{@var{a}[@var{i}]} is defined as
16513 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16516 Function parameter list. Same precedence as @code{->}.
16519 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16520 and @code{class} types.
16523 Doubled colons also represent the @value{GDBN} scope operator
16524 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16528 If an operator is redefined in the user code, @value{GDBN} usually
16529 attempts to invoke the redefined version instead of using the operator's
16530 predefined meaning.
16533 @subsubsection C and C@t{++} Constants
16535 @cindex C and C@t{++} constants
16537 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16542 Integer constants are a sequence of digits. Octal constants are
16543 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16544 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16545 @samp{l}, specifying that the constant should be treated as a
16549 Floating point constants are a sequence of digits, followed by a decimal
16550 point, followed by a sequence of digits, and optionally followed by an
16551 exponent. An exponent is of the form:
16552 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16553 sequence of digits. The @samp{+} is optional for positive exponents.
16554 A floating-point constant may also end with a letter @samp{f} or
16555 @samp{F}, specifying that the constant should be treated as being of
16556 the @code{float} (as opposed to the default @code{double}) type; or with
16557 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16561 Enumerated constants consist of enumerated identifiers, or their
16562 integral equivalents.
16565 Character constants are a single character surrounded by single quotes
16566 (@code{'}), or a number---the ordinal value of the corresponding character
16567 (usually its @sc{ascii} value). Within quotes, the single character may
16568 be represented by a letter or by @dfn{escape sequences}, which are of
16569 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16570 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16571 @samp{@var{x}} is a predefined special character---for example,
16572 @samp{\n} for newline.
16574 Wide character constants can be written by prefixing a character
16575 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16576 form of @samp{x}. The target wide character set is used when
16577 computing the value of this constant (@pxref{Character Sets}).
16580 String constants are a sequence of character constants surrounded by
16581 double quotes (@code{"}). Any valid character constant (as described
16582 above) may appear. Double quotes within the string must be preceded by
16583 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16586 Wide string constants can be written by prefixing a string constant
16587 with @samp{L}, as in C. The target wide character set is used when
16588 computing the value of this constant (@pxref{Character Sets}).
16591 Pointer constants are an integral value. You can also write pointers
16592 to constants using the C operator @samp{&}.
16595 Array constants are comma-separated lists surrounded by braces @samp{@{}
16596 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16597 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16598 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16601 @node C Plus Plus Expressions
16602 @subsubsection C@t{++} Expressions
16604 @cindex expressions in C@t{++}
16605 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16607 @cindex debugging C@t{++} programs
16608 @cindex C@t{++} compilers
16609 @cindex debug formats and C@t{++}
16610 @cindex @value{NGCC} and C@t{++}
16612 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16613 the proper compiler and the proper debug format. Currently,
16614 @value{GDBN} works best when debugging C@t{++} code that is compiled
16615 with the most recent version of @value{NGCC} possible. The DWARF
16616 debugging format is preferred; @value{NGCC} defaults to this on most
16617 popular platforms. Other compilers and/or debug formats are likely to
16618 work badly or not at all when using @value{GDBN} to debug C@t{++}
16619 code. @xref{Compilation}.
16624 @cindex member functions
16626 Member function calls are allowed; you can use expressions like
16629 count = aml->GetOriginal(x, y)
16632 @vindex this@r{, inside C@t{++} member functions}
16633 @cindex namespace in C@t{++}
16635 While a member function is active (in the selected stack frame), your
16636 expressions have the same namespace available as the member function;
16637 that is, @value{GDBN} allows implicit references to the class instance
16638 pointer @code{this} following the same rules as C@t{++}. @code{using}
16639 declarations in the current scope are also respected by @value{GDBN}.
16641 @cindex call overloaded functions
16642 @cindex overloaded functions, calling
16643 @cindex type conversions in C@t{++}
16645 You can call overloaded functions; @value{GDBN} resolves the function
16646 call to the right definition, with some restrictions. @value{GDBN} does not
16647 perform overload resolution involving user-defined type conversions,
16648 calls to constructors, or instantiations of templates that do not exist
16649 in the program. It also cannot handle ellipsis argument lists or
16652 It does perform integral conversions and promotions, floating-point
16653 promotions, arithmetic conversions, pointer conversions, conversions of
16654 class objects to base classes, and standard conversions such as those of
16655 functions or arrays to pointers; it requires an exact match on the
16656 number of function arguments.
16658 Overload resolution is always performed, unless you have specified
16659 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16660 ,@value{GDBN} Features for C@t{++}}.
16662 You must specify @code{set overload-resolution off} in order to use an
16663 explicit function signature to call an overloaded function, as in
16665 p 'foo(char,int)'('x', 13)
16668 The @value{GDBN} command-completion facility can simplify this;
16669 see @ref{Completion, ,Command Completion}.
16671 @cindex reference declarations
16673 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16674 references; you can use them in expressions just as you do in C@t{++}
16675 source---they are automatically dereferenced.
16677 In the parameter list shown when @value{GDBN} displays a frame, the values of
16678 reference variables are not displayed (unlike other variables); this
16679 avoids clutter, since references are often used for large structures.
16680 The @emph{address} of a reference variable is always shown, unless
16681 you have specified @samp{set print address off}.
16684 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16685 expressions can use it just as expressions in your program do. Since
16686 one scope may be defined in another, you can use @code{::} repeatedly if
16687 necessary, for example in an expression like
16688 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16689 resolving name scope by reference to source files, in both C and C@t{++}
16690 debugging (@pxref{Variables, ,Program Variables}).
16693 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16698 @subsubsection C and C@t{++} Defaults
16700 @cindex C and C@t{++} defaults
16702 If you allow @value{GDBN} to set range checking automatically, it
16703 defaults to @code{off} whenever the working language changes to
16704 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16705 selects the working language.
16707 If you allow @value{GDBN} to set the language automatically, it
16708 recognizes source files whose names end with @file{.c}, @file{.C}, or
16709 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16710 these files, it sets the working language to C or C@t{++}.
16711 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16712 for further details.
16715 @subsubsection C and C@t{++} Type and Range Checks
16717 @cindex C and C@t{++} checks
16719 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16720 checking is used. However, if you turn type checking off, @value{GDBN}
16721 will allow certain non-standard conversions, such as promoting integer
16722 constants to pointers.
16724 Range checking, if turned on, is done on mathematical operations. Array
16725 indices are not checked, since they are often used to index a pointer
16726 that is not itself an array.
16729 @subsubsection @value{GDBN} and C
16731 The @code{set print union} and @code{show print union} commands apply to
16732 the @code{union} type. When set to @samp{on}, any @code{union} that is
16733 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16734 appears as @samp{@{...@}}.
16736 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16737 with pointers and a memory allocation function. @xref{Expressions,
16740 @node Debugging C Plus Plus
16741 @subsubsection @value{GDBN} Features for C@t{++}
16743 @cindex commands for C@t{++}
16745 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16746 designed specifically for use with C@t{++}. Here is a summary:
16749 @cindex break in overloaded functions
16750 @item @r{breakpoint menus}
16751 When you want a breakpoint in a function whose name is overloaded,
16752 @value{GDBN} has the capability to display a menu of possible breakpoint
16753 locations to help you specify which function definition you want.
16754 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16756 @cindex overloading in C@t{++}
16757 @item rbreak @var{regex}
16758 Setting breakpoints using regular expressions is helpful for setting
16759 breakpoints on overloaded functions that are not members of any special
16761 @xref{Set Breaks, ,Setting Breakpoints}.
16763 @cindex C@t{++} exception handling
16765 @itemx catch rethrow
16767 Debug C@t{++} exception handling using these commands. @xref{Set
16768 Catchpoints, , Setting Catchpoints}.
16770 @cindex inheritance
16771 @item ptype @var{typename}
16772 Print inheritance relationships as well as other information for type
16774 @xref{Symbols, ,Examining the Symbol Table}.
16776 @item info vtbl @var{expression}.
16777 The @code{info vtbl} command can be used to display the virtual
16778 method tables of the object computed by @var{expression}. This shows
16779 one entry per virtual table; there may be multiple virtual tables when
16780 multiple inheritance is in use.
16782 @cindex C@t{++} demangling
16783 @item demangle @var{name}
16784 Demangle @var{name}.
16785 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16787 @cindex C@t{++} symbol display
16788 @item set print demangle
16789 @itemx show print demangle
16790 @itemx set print asm-demangle
16791 @itemx show print asm-demangle
16792 Control whether C@t{++} symbols display in their source form, both when
16793 displaying code as C@t{++} source and when displaying disassemblies.
16794 @xref{Print Settings, ,Print Settings}.
16796 @item set print object
16797 @itemx show print object
16798 Choose whether to print derived (actual) or declared types of objects.
16799 @xref{Print Settings, ,Print Settings}.
16801 @item set print vtbl
16802 @itemx show print vtbl
16803 Control the format for printing virtual function tables.
16804 @xref{Print Settings, ,Print Settings}.
16805 (The @code{vtbl} commands do not work on programs compiled with the HP
16806 ANSI C@t{++} compiler (@code{aCC}).)
16808 @kindex set overload-resolution
16809 @cindex overloaded functions, overload resolution
16810 @item set overload-resolution on
16811 Enable overload resolution for C@t{++} expression evaluation. The default
16812 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16813 and searches for a function whose signature matches the argument types,
16814 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16815 Expressions, ,C@t{++} Expressions}, for details).
16816 If it cannot find a match, it emits a message.
16818 @item set overload-resolution off
16819 Disable overload resolution for C@t{++} expression evaluation. For
16820 overloaded functions that are not class member functions, @value{GDBN}
16821 chooses the first function of the specified name that it finds in the
16822 symbol table, whether or not its arguments are of the correct type. For
16823 overloaded functions that are class member functions, @value{GDBN}
16824 searches for a function whose signature @emph{exactly} matches the
16827 @kindex show overload-resolution
16828 @item show overload-resolution
16829 Show the current setting of overload resolution.
16831 @item @r{Overloaded symbol names}
16832 You can specify a particular definition of an overloaded symbol, using
16833 the same notation that is used to declare such symbols in C@t{++}: type
16834 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16835 also use the @value{GDBN} command-line word completion facilities to list the
16836 available choices, or to finish the type list for you.
16837 @xref{Completion,, Command Completion}, for details on how to do this.
16839 @item @r{Breakpoints in functions with ABI tags}
16841 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16842 correspond to changes in the ABI of a type, function, or variable that
16843 would not otherwise be reflected in a mangled name. See
16844 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16847 The ABI tags are visible in C@t{++} demangled names. For example, a
16848 function that returns a std::string:
16851 std::string function(int);
16855 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16856 tag, and @value{GDBN} displays the symbol like this:
16859 function[abi:cxx11](int)
16862 You can set a breakpoint on such functions simply as if they had no
16866 (gdb) b function(int)
16867 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16868 (gdb) info breakpoints
16869 Num Type Disp Enb Address What
16870 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16874 On the rare occasion you need to disambiguate between different ABI
16875 tags, you can do so by simply including the ABI tag in the function
16879 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16883 @node Decimal Floating Point
16884 @subsubsection Decimal Floating Point format
16885 @cindex decimal floating point format
16887 @value{GDBN} can examine, set and perform computations with numbers in
16888 decimal floating point format, which in the C language correspond to the
16889 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16890 specified by the extension to support decimal floating-point arithmetic.
16892 There are two encodings in use, depending on the architecture: BID (Binary
16893 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16894 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16897 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16898 to manipulate decimal floating point numbers, it is not possible to convert
16899 (using a cast, for example) integers wider than 32-bit to decimal float.
16901 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16902 point computations, error checking in decimal float operations ignores
16903 underflow, overflow and divide by zero exceptions.
16905 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16906 to inspect @code{_Decimal128} values stored in floating point registers.
16907 See @ref{PowerPC,,PowerPC} for more details.
16913 @value{GDBN} can be used to debug programs written in D and compiled with
16914 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16915 specific feature --- dynamic arrays.
16920 @cindex Go (programming language)
16921 @value{GDBN} can be used to debug programs written in Go and compiled with
16922 @file{gccgo} or @file{6g} compilers.
16924 Here is a summary of the Go-specific features and restrictions:
16927 @cindex current Go package
16928 @item The current Go package
16929 The name of the current package does not need to be specified when
16930 specifying global variables and functions.
16932 For example, given the program:
16936 var myglob = "Shall we?"
16942 When stopped inside @code{main} either of these work:
16946 (gdb) p main.myglob
16949 @cindex builtin Go types
16950 @item Builtin Go types
16951 The @code{string} type is recognized by @value{GDBN} and is printed
16954 @cindex builtin Go functions
16955 @item Builtin Go functions
16956 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16957 function and handles it internally.
16959 @cindex restrictions on Go expressions
16960 @item Restrictions on Go expressions
16961 All Go operators are supported except @code{&^}.
16962 The Go @code{_} ``blank identifier'' is not supported.
16963 Automatic dereferencing of pointers is not supported.
16967 @subsection Objective-C
16969 @cindex Objective-C
16970 This section provides information about some commands and command
16971 options that are useful for debugging Objective-C code. See also
16972 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16973 few more commands specific to Objective-C support.
16976 * Method Names in Commands::
16977 * The Print Command with Objective-C::
16980 @node Method Names in Commands
16981 @subsubsection Method Names in Commands
16983 The following commands have been extended to accept Objective-C method
16984 names as line specifications:
16986 @kindex clear@r{, and Objective-C}
16987 @kindex break@r{, and Objective-C}
16988 @kindex info line@r{, and Objective-C}
16989 @kindex jump@r{, and Objective-C}
16990 @kindex list@r{, and Objective-C}
16994 @item @code{info line}
16999 A fully qualified Objective-C method name is specified as
17002 -[@var{Class} @var{methodName}]
17005 where the minus sign is used to indicate an instance method and a
17006 plus sign (not shown) is used to indicate a class method. The class
17007 name @var{Class} and method name @var{methodName} are enclosed in
17008 brackets, similar to the way messages are specified in Objective-C
17009 source code. For example, to set a breakpoint at the @code{create}
17010 instance method of class @code{Fruit} in the program currently being
17014 break -[Fruit create]
17017 To list ten program lines around the @code{initialize} class method,
17021 list +[NSText initialize]
17024 In the current version of @value{GDBN}, the plus or minus sign is
17025 required. In future versions of @value{GDBN}, the plus or minus
17026 sign will be optional, but you can use it to narrow the search. It
17027 is also possible to specify just a method name:
17033 You must specify the complete method name, including any colons. If
17034 your program's source files contain more than one @code{create} method,
17035 you'll be presented with a numbered list of classes that implement that
17036 method. Indicate your choice by number, or type @samp{0} to exit if
17039 As another example, to clear a breakpoint established at the
17040 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
17043 clear -[NSWindow makeKeyAndOrderFront:]
17046 @node The Print Command with Objective-C
17047 @subsubsection The Print Command With Objective-C
17048 @cindex Objective-C, print objects
17049 @kindex print-object
17050 @kindex po @r{(@code{print-object})}
17052 The print command has also been extended to accept methods. For example:
17055 print -[@var{object} hash]
17058 @cindex print an Objective-C object description
17059 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
17061 will tell @value{GDBN} to send the @code{hash} message to @var{object}
17062 and print the result. Also, an additional command has been added,
17063 @code{print-object} or @code{po} for short, which is meant to print
17064 the description of an object. However, this command may only work
17065 with certain Objective-C libraries that have a particular hook
17066 function, @code{_NSPrintForDebugger}, defined.
17069 @subsection OpenCL C
17072 This section provides information about @value{GDBN}s OpenCL C support.
17075 * OpenCL C Datatypes::
17076 * OpenCL C Expressions::
17077 * OpenCL C Operators::
17080 @node OpenCL C Datatypes
17081 @subsubsection OpenCL C Datatypes
17083 @cindex OpenCL C Datatypes
17084 @value{GDBN} supports the builtin scalar and vector datatypes specified
17085 by OpenCL 1.1. In addition the half- and double-precision floating point
17086 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
17087 extensions are also known to @value{GDBN}.
17089 @node OpenCL C Expressions
17090 @subsubsection OpenCL C Expressions
17092 @cindex OpenCL C Expressions
17093 @value{GDBN} supports accesses to vector components including the access as
17094 lvalue where possible. Since OpenCL C is based on C99 most C expressions
17095 supported by @value{GDBN} can be used as well.
17097 @node OpenCL C Operators
17098 @subsubsection OpenCL C Operators
17100 @cindex OpenCL C Operators
17101 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
17105 @subsection Fortran
17106 @cindex Fortran-specific support in @value{GDBN}
17108 @value{GDBN} can be used to debug programs written in Fortran, but it
17109 currently supports only the features of Fortran 77 language.
17111 @cindex trailing underscore, in Fortran symbols
17112 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
17113 among them) append an underscore to the names of variables and
17114 functions. When you debug programs compiled by those compilers, you
17115 will need to refer to variables and functions with a trailing
17119 * Fortran Operators:: Fortran operators and expressions
17120 * Fortran Defaults:: Default settings for Fortran
17121 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
17124 @node Fortran Operators
17125 @subsubsection Fortran Operators and Expressions
17127 @cindex Fortran operators and expressions
17129 Operators must be defined on values of specific types. For instance,
17130 @code{+} is defined on numbers, but not on characters or other non-
17131 arithmetic types. Operators are often defined on groups of types.
17135 The exponentiation operator. It raises the first operand to the power
17139 The range operator. Normally used in the form of array(low:high) to
17140 represent a section of array.
17143 The access component operator. Normally used to access elements in derived
17144 types. Also suitable for unions. As unions aren't part of regular Fortran,
17145 this can only happen when accessing a register that uses a gdbarch-defined
17148 The scope operator. Normally used to access variables in modules or
17149 to set breakpoints on subroutines nested in modules or in other
17150 subroutines (internal subroutines).
17153 @node Fortran Defaults
17154 @subsubsection Fortran Defaults
17156 @cindex Fortran Defaults
17158 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17159 default uses case-insensitive matches for Fortran symbols. You can
17160 change that with the @samp{set case-insensitive} command, see
17161 @ref{Symbols}, for the details.
17163 @node Special Fortran Commands
17164 @subsubsection Special Fortran Commands
17166 @cindex Special Fortran commands
17168 @value{GDBN} has some commands to support Fortran-specific features,
17169 such as displaying common blocks.
17172 @cindex @code{COMMON} blocks, Fortran
17173 @kindex info common
17174 @item info common @r{[}@var{common-name}@r{]}
17175 This command prints the values contained in the Fortran @code{COMMON}
17176 block whose name is @var{common-name}. With no argument, the names of
17177 all @code{COMMON} blocks visible at the current program location are
17179 @cindex arrays slices (Fortran)
17180 @kindex set fortran repack-array-slices
17181 @kindex show fortran repack-array-slices
17182 @item set fortran repack-array-slices [on|off]
17183 @item show fortran repack-array-slices
17184 When taking a slice from an array, a Fortran compiler can choose to
17185 either produce an array descriptor that describes the slice in place,
17186 or it may repack the slice, copying the elements of the slice into a
17187 new region of memory.
17189 When this setting is on, then @value{GDBN} will also repack array
17190 slices in some situations. When this setting is off, then
17191 @value{GDBN} will create array descriptors for slices that reference
17192 the original data in place.
17194 @value{GDBN} will never repack an array slice if the data for the
17195 slice is contiguous within the original array.
17197 @value{GDBN} will always repack string slices if the data for the
17198 slice is non-contiguous within the original string as @value{GDBN}
17199 does not support printing non-contiguous strings.
17201 The default for this setting is @code{off}.
17207 @cindex Pascal support in @value{GDBN}, limitations
17208 Debugging Pascal programs which use sets, subranges, file variables, or
17209 nested functions does not currently work. @value{GDBN} does not support
17210 entering expressions, printing values, or similar features using Pascal
17213 The Pascal-specific command @code{set print pascal_static-members}
17214 controls whether static members of Pascal objects are displayed.
17215 @xref{Print Settings, pascal_static-members}.
17220 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17221 Programming Language}. Type- and value-printing, and expression
17222 parsing, are reasonably complete. However, there are a few
17223 peculiarities and holes to be aware of.
17227 Linespecs (@pxref{Specify Location}) are never relative to the current
17228 crate. Instead, they act as if there were a global namespace of
17229 crates, somewhat similar to the way @code{extern crate} behaves.
17231 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17232 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17233 to set a breakpoint in a function named @samp{f} in a crate named
17236 As a consequence of this approach, linespecs also cannot refer to
17237 items using @samp{self::} or @samp{super::}.
17240 Because @value{GDBN} implements Rust name-lookup semantics in
17241 expressions, it will sometimes prepend the current crate to a name.
17242 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17243 @samp{K}, then @code{print ::x::y} will try to find the symbol
17246 However, since it is useful to be able to refer to other crates when
17247 debugging, @value{GDBN} provides the @code{extern} extension to
17248 circumvent this. To use the extension, just put @code{extern} before
17249 a path expression to refer to the otherwise unavailable ``global''
17252 In the above example, if you wanted to refer to the symbol @samp{y} in
17253 the crate @samp{x}, you would use @code{print extern x::y}.
17256 The Rust expression evaluator does not support ``statement-like''
17257 expressions such as @code{if} or @code{match}, or lambda expressions.
17260 Tuple expressions are not implemented.
17263 The Rust expression evaluator does not currently implement the
17264 @code{Drop} trait. Objects that may be created by the evaluator will
17265 never be destroyed.
17268 @value{GDBN} does not implement type inference for generics. In order
17269 to call generic functions or otherwise refer to generic items, you
17270 will have to specify the type parameters manually.
17273 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17274 cases this does not cause any problems. However, in an expression
17275 context, completing a generic function name will give syntactically
17276 invalid results. This happens because Rust requires the @samp{::}
17277 operator between the function name and its generic arguments. For
17278 example, @value{GDBN} might provide a completion like
17279 @code{crate::f<u32>}, where the parser would require
17280 @code{crate::f::<u32>}.
17283 As of this writing, the Rust compiler (version 1.8) has a few holes in
17284 the debugging information it generates. These holes prevent certain
17285 features from being implemented by @value{GDBN}:
17289 Method calls cannot be made via traits.
17292 Operator overloading is not implemented.
17295 When debugging in a monomorphized function, you cannot use the generic
17299 The type @code{Self} is not available.
17302 @code{use} statements are not available, so some names may not be
17303 available in the crate.
17308 @subsection Modula-2
17310 @cindex Modula-2, @value{GDBN} support
17312 The extensions made to @value{GDBN} to support Modula-2 only support
17313 output from the @sc{gnu} Modula-2 compiler (which is currently being
17314 developed). Other Modula-2 compilers are not currently supported, and
17315 attempting to debug executables produced by them is most likely
17316 to give an error as @value{GDBN} reads in the executable's symbol
17319 @cindex expressions in Modula-2
17321 * M2 Operators:: Built-in operators
17322 * Built-In Func/Proc:: Built-in functions and procedures
17323 * M2 Constants:: Modula-2 constants
17324 * M2 Types:: Modula-2 types
17325 * M2 Defaults:: Default settings for Modula-2
17326 * Deviations:: Deviations from standard Modula-2
17327 * M2 Checks:: Modula-2 type and range checks
17328 * M2 Scope:: The scope operators @code{::} and @code{.}
17329 * GDB/M2:: @value{GDBN} and Modula-2
17333 @subsubsection Operators
17334 @cindex Modula-2 operators
17336 Operators must be defined on values of specific types. For instance,
17337 @code{+} is defined on numbers, but not on structures. Operators are
17338 often defined on groups of types. For the purposes of Modula-2, the
17339 following definitions hold:
17344 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17348 @emph{Character types} consist of @code{CHAR} and its subranges.
17351 @emph{Floating-point types} consist of @code{REAL}.
17354 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17358 @emph{Scalar types} consist of all of the above.
17361 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17364 @emph{Boolean types} consist of @code{BOOLEAN}.
17368 The following operators are supported, and appear in order of
17369 increasing precedence:
17373 Function argument or array index separator.
17376 Assignment. The value of @var{var} @code{:=} @var{value} is
17380 Less than, greater than on integral, floating-point, or enumerated
17384 Less than or equal to, greater than or equal to
17385 on integral, floating-point and enumerated types, or set inclusion on
17386 set types. Same precedence as @code{<}.
17388 @item =@r{, }<>@r{, }#
17389 Equality and two ways of expressing inequality, valid on scalar types.
17390 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17391 available for inequality, since @code{#} conflicts with the script
17395 Set membership. Defined on set types and the types of their members.
17396 Same precedence as @code{<}.
17399 Boolean disjunction. Defined on boolean types.
17402 Boolean conjunction. Defined on boolean types.
17405 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17408 Addition and subtraction on integral and floating-point types, or union
17409 and difference on set types.
17412 Multiplication on integral and floating-point types, or set intersection
17416 Division on floating-point types, or symmetric set difference on set
17417 types. Same precedence as @code{*}.
17420 Integer division and remainder. Defined on integral types. Same
17421 precedence as @code{*}.
17424 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17427 Pointer dereferencing. Defined on pointer types.
17430 Boolean negation. Defined on boolean types. Same precedence as
17434 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17435 precedence as @code{^}.
17438 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17441 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17445 @value{GDBN} and Modula-2 scope operators.
17449 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17450 treats the use of the operator @code{IN}, or the use of operators
17451 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17452 @code{<=}, and @code{>=} on sets as an error.
17456 @node Built-In Func/Proc
17457 @subsubsection Built-in Functions and Procedures
17458 @cindex Modula-2 built-ins
17460 Modula-2 also makes available several built-in procedures and functions.
17461 In describing these, the following metavariables are used:
17466 represents an @code{ARRAY} variable.
17469 represents a @code{CHAR} constant or variable.
17472 represents a variable or constant of integral type.
17475 represents an identifier that belongs to a set. Generally used in the
17476 same function with the metavariable @var{s}. The type of @var{s} should
17477 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17480 represents a variable or constant of integral or floating-point type.
17483 represents a variable or constant of floating-point type.
17489 represents a variable.
17492 represents a variable or constant of one of many types. See the
17493 explanation of the function for details.
17496 All Modula-2 built-in procedures also return a result, described below.
17500 Returns the absolute value of @var{n}.
17503 If @var{c} is a lower case letter, it returns its upper case
17504 equivalent, otherwise it returns its argument.
17507 Returns the character whose ordinal value is @var{i}.
17510 Decrements the value in the variable @var{v} by one. Returns the new value.
17512 @item DEC(@var{v},@var{i})
17513 Decrements the value in the variable @var{v} by @var{i}. Returns the
17516 @item EXCL(@var{m},@var{s})
17517 Removes the element @var{m} from the set @var{s}. Returns the new
17520 @item FLOAT(@var{i})
17521 Returns the floating point equivalent of the integer @var{i}.
17523 @item HIGH(@var{a})
17524 Returns the index of the last member of @var{a}.
17527 Increments the value in the variable @var{v} by one. Returns the new value.
17529 @item INC(@var{v},@var{i})
17530 Increments the value in the variable @var{v} by @var{i}. Returns the
17533 @item INCL(@var{m},@var{s})
17534 Adds the element @var{m} to the set @var{s} if it is not already
17535 there. Returns the new set.
17538 Returns the maximum value of the type @var{t}.
17541 Returns the minimum value of the type @var{t}.
17544 Returns boolean TRUE if @var{i} is an odd number.
17547 Returns the ordinal value of its argument. For example, the ordinal
17548 value of a character is its @sc{ascii} value (on machines supporting
17549 the @sc{ascii} character set). The argument @var{x} must be of an
17550 ordered type, which include integral, character and enumerated types.
17552 @item SIZE(@var{x})
17553 Returns the size of its argument. The argument @var{x} can be a
17554 variable or a type.
17556 @item TRUNC(@var{r})
17557 Returns the integral part of @var{r}.
17559 @item TSIZE(@var{x})
17560 Returns the size of its argument. The argument @var{x} can be a
17561 variable or a type.
17563 @item VAL(@var{t},@var{i})
17564 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17568 @emph{Warning:} Sets and their operations are not yet supported, so
17569 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17573 @cindex Modula-2 constants
17575 @subsubsection Constants
17577 @value{GDBN} allows you to express the constants of Modula-2 in the following
17583 Integer constants are simply a sequence of digits. When used in an
17584 expression, a constant is interpreted to be type-compatible with the
17585 rest of the expression. Hexadecimal integers are specified by a
17586 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17589 Floating point constants appear as a sequence of digits, followed by a
17590 decimal point and another sequence of digits. An optional exponent can
17591 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17592 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17593 digits of the floating point constant must be valid decimal (base 10)
17597 Character constants consist of a single character enclosed by a pair of
17598 like quotes, either single (@code{'}) or double (@code{"}). They may
17599 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17600 followed by a @samp{C}.
17603 String constants consist of a sequence of characters enclosed by a
17604 pair of like quotes, either single (@code{'}) or double (@code{"}).
17605 Escape sequences in the style of C are also allowed. @xref{C
17606 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17610 Enumerated constants consist of an enumerated identifier.
17613 Boolean constants consist of the identifiers @code{TRUE} and
17617 Pointer constants consist of integral values only.
17620 Set constants are not yet supported.
17624 @subsubsection Modula-2 Types
17625 @cindex Modula-2 types
17627 Currently @value{GDBN} can print the following data types in Modula-2
17628 syntax: array types, record types, set types, pointer types, procedure
17629 types, enumerated types, subrange types and base types. You can also
17630 print the contents of variables declared using these type.
17631 This section gives a number of simple source code examples together with
17632 sample @value{GDBN} sessions.
17634 The first example contains the following section of code:
17643 and you can request @value{GDBN} to interrogate the type and value of
17644 @code{r} and @code{s}.
17647 (@value{GDBP}) print s
17649 (@value{GDBP}) ptype s
17651 (@value{GDBP}) print r
17653 (@value{GDBP}) ptype r
17658 Likewise if your source code declares @code{s} as:
17662 s: SET ['A'..'Z'] ;
17666 then you may query the type of @code{s} by:
17669 (@value{GDBP}) ptype s
17670 type = SET ['A'..'Z']
17674 Note that at present you cannot interactively manipulate set
17675 expressions using the debugger.
17677 The following example shows how you might declare an array in Modula-2
17678 and how you can interact with @value{GDBN} to print its type and contents:
17682 s: ARRAY [-10..10] OF CHAR ;
17686 (@value{GDBP}) ptype s
17687 ARRAY [-10..10] OF CHAR
17690 Note that the array handling is not yet complete and although the type
17691 is printed correctly, expression handling still assumes that all
17692 arrays have a lower bound of zero and not @code{-10} as in the example
17695 Here are some more type related Modula-2 examples:
17699 colour = (blue, red, yellow, green) ;
17700 t = [blue..yellow] ;
17708 The @value{GDBN} interaction shows how you can query the data type
17709 and value of a variable.
17712 (@value{GDBP}) print s
17714 (@value{GDBP}) ptype t
17715 type = [blue..yellow]
17719 In this example a Modula-2 array is declared and its contents
17720 displayed. Observe that the contents are written in the same way as
17721 their @code{C} counterparts.
17725 s: ARRAY [1..5] OF CARDINAL ;
17731 (@value{GDBP}) print s
17732 $1 = @{1, 0, 0, 0, 0@}
17733 (@value{GDBP}) ptype s
17734 type = ARRAY [1..5] OF CARDINAL
17737 The Modula-2 language interface to @value{GDBN} also understands
17738 pointer types as shown in this example:
17742 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17749 and you can request that @value{GDBN} describes the type of @code{s}.
17752 (@value{GDBP}) ptype s
17753 type = POINTER TO ARRAY [1..5] OF CARDINAL
17756 @value{GDBN} handles compound types as we can see in this example.
17757 Here we combine array types, record types, pointer types and subrange
17768 myarray = ARRAY myrange OF CARDINAL ;
17769 myrange = [-2..2] ;
17771 s: POINTER TO ARRAY myrange OF foo ;
17775 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17779 (@value{GDBP}) ptype s
17780 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17783 f3 : ARRAY [-2..2] OF CARDINAL;
17788 @subsubsection Modula-2 Defaults
17789 @cindex Modula-2 defaults
17791 If type and range checking are set automatically by @value{GDBN}, they
17792 both default to @code{on} whenever the working language changes to
17793 Modula-2. This happens regardless of whether you or @value{GDBN}
17794 selected the working language.
17796 If you allow @value{GDBN} to set the language automatically, then entering
17797 code compiled from a file whose name ends with @file{.mod} sets the
17798 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17799 Infer the Source Language}, for further details.
17802 @subsubsection Deviations from Standard Modula-2
17803 @cindex Modula-2, deviations from
17805 A few changes have been made to make Modula-2 programs easier to debug.
17806 This is done primarily via loosening its type strictness:
17810 Unlike in standard Modula-2, pointer constants can be formed by
17811 integers. This allows you to modify pointer variables during
17812 debugging. (In standard Modula-2, the actual address contained in a
17813 pointer variable is hidden from you; it can only be modified
17814 through direct assignment to another pointer variable or expression that
17815 returned a pointer.)
17818 C escape sequences can be used in strings and characters to represent
17819 non-printable characters. @value{GDBN} prints out strings with these
17820 escape sequences embedded. Single non-printable characters are
17821 printed using the @samp{CHR(@var{nnn})} format.
17824 The assignment operator (@code{:=}) returns the value of its right-hand
17828 All built-in procedures both modify @emph{and} return their argument.
17832 @subsubsection Modula-2 Type and Range Checks
17833 @cindex Modula-2 checks
17836 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17839 @c FIXME remove warning when type/range checks added
17841 @value{GDBN} considers two Modula-2 variables type equivalent if:
17845 They are of types that have been declared equivalent via a @code{TYPE
17846 @var{t1} = @var{t2}} statement
17849 They have been declared on the same line. (Note: This is true of the
17850 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17853 As long as type checking is enabled, any attempt to combine variables
17854 whose types are not equivalent is an error.
17856 Range checking is done on all mathematical operations, assignment, array
17857 index bounds, and all built-in functions and procedures.
17860 @subsubsection The Scope Operators @code{::} and @code{.}
17862 @cindex @code{.}, Modula-2 scope operator
17863 @cindex colon, doubled as scope operator
17865 @vindex colon-colon@r{, in Modula-2}
17866 @c Info cannot handle :: but TeX can.
17869 @vindex ::@r{, in Modula-2}
17872 There are a few subtle differences between the Modula-2 scope operator
17873 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17878 @var{module} . @var{id}
17879 @var{scope} :: @var{id}
17883 where @var{scope} is the name of a module or a procedure,
17884 @var{module} the name of a module, and @var{id} is any declared
17885 identifier within your program, except another module.
17887 Using the @code{::} operator makes @value{GDBN} search the scope
17888 specified by @var{scope} for the identifier @var{id}. If it is not
17889 found in the specified scope, then @value{GDBN} searches all scopes
17890 enclosing the one specified by @var{scope}.
17892 Using the @code{.} operator makes @value{GDBN} search the current scope for
17893 the identifier specified by @var{id} that was imported from the
17894 definition module specified by @var{module}. With this operator, it is
17895 an error if the identifier @var{id} was not imported from definition
17896 module @var{module}, or if @var{id} is not an identifier in
17900 @subsubsection @value{GDBN} and Modula-2
17902 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17903 Five subcommands of @code{set print} and @code{show print} apply
17904 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17905 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17906 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17907 analogue in Modula-2.
17909 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17910 with any language, is not useful with Modula-2. Its
17911 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17912 created in Modula-2 as they can in C or C@t{++}. However, because an
17913 address can be specified by an integral constant, the construct
17914 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17916 @cindex @code{#} in Modula-2
17917 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17918 interpreted as the beginning of a comment. Use @code{<>} instead.
17924 The extensions made to @value{GDBN} for Ada only support
17925 output from the @sc{gnu} Ada (GNAT) compiler.
17926 Other Ada compilers are not currently supported, and
17927 attempting to debug executables produced by them is most likely
17931 @cindex expressions in Ada
17933 * Ada Mode Intro:: General remarks on the Ada syntax
17934 and semantics supported by Ada mode
17936 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17937 * Additions to Ada:: Extensions of the Ada expression syntax.
17938 * Overloading support for Ada:: Support for expressions involving overloaded
17940 * Stopping Before Main Program:: Debugging the program during elaboration.
17941 * Ada Exceptions:: Ada Exceptions
17942 * Ada Tasks:: Listing and setting breakpoints in tasks.
17943 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17944 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17946 * Ada Settings:: New settable GDB parameters for Ada.
17947 * Ada Glitches:: Known peculiarities of Ada mode.
17950 @node Ada Mode Intro
17951 @subsubsection Introduction
17952 @cindex Ada mode, general
17954 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17955 syntax, with some extensions.
17956 The philosophy behind the design of this subset is
17960 That @value{GDBN} should provide basic literals and access to operations for
17961 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17962 leaving more sophisticated computations to subprograms written into the
17963 program (which therefore may be called from @value{GDBN}).
17966 That type safety and strict adherence to Ada language restrictions
17967 are not particularly important to the @value{GDBN} user.
17970 That brevity is important to the @value{GDBN} user.
17973 Thus, for brevity, the debugger acts as if all names declared in
17974 user-written packages are directly visible, even if they are not visible
17975 according to Ada rules, thus making it unnecessary to fully qualify most
17976 names with their packages, regardless of context. Where this causes
17977 ambiguity, @value{GDBN} asks the user's intent.
17979 The debugger will start in Ada mode if it detects an Ada main program.
17980 As for other languages, it will enter Ada mode when stopped in a program that
17981 was translated from an Ada source file.
17983 While in Ada mode, you may use `@t{--}' for comments. This is useful
17984 mostly for documenting command files. The standard @value{GDBN} comment
17985 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17986 middle (to allow based literals).
17988 @node Omissions from Ada
17989 @subsubsection Omissions from Ada
17990 @cindex Ada, omissions from
17992 Here are the notable omissions from the subset:
17996 Only a subset of the attributes are supported:
18000 @t{'First}, @t{'Last}, and @t{'Length}
18001 on array objects (not on types and subtypes).
18004 @t{'Min} and @t{'Max}.
18007 @t{'Pos} and @t{'Val}.
18013 @t{'Range} on array objects (not subtypes), but only as the right
18014 operand of the membership (@code{in}) operator.
18017 @t{'Access}, @t{'Unchecked_Access}, and
18018 @t{'Unrestricted_Access} (a GNAT extension).
18026 @code{Characters.Latin_1} are not available and
18027 concatenation is not implemented. Thus, escape characters in strings are
18028 not currently available.
18031 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
18032 equality of representations. They will generally work correctly
18033 for strings and arrays whose elements have integer or enumeration types.
18034 They may not work correctly for arrays whose element
18035 types have user-defined equality, for arrays of real values
18036 (in particular, IEEE-conformant floating point, because of negative
18037 zeroes and NaNs), and for arrays whose elements contain unused bits with
18038 indeterminate values.
18041 The other component-by-component array operations (@code{and}, @code{or},
18042 @code{xor}, @code{not}, and relational tests other than equality)
18043 are not implemented.
18046 @cindex array aggregates (Ada)
18047 @cindex record aggregates (Ada)
18048 @cindex aggregates (Ada)
18049 There is limited support for array and record aggregates. They are
18050 permitted only on the right sides of assignments, as in these examples:
18053 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
18054 (@value{GDBP}) set An_Array := (1, others => 0)
18055 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
18056 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
18057 (@value{GDBP}) set A_Record := (1, "Peter", True);
18058 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
18062 discriminant's value by assigning an aggregate has an
18063 undefined effect if that discriminant is used within the record.
18064 However, you can first modify discriminants by directly assigning to
18065 them (which normally would not be allowed in Ada), and then performing an
18066 aggregate assignment. For example, given a variable @code{A_Rec}
18067 declared to have a type such as:
18070 type Rec (Len : Small_Integer := 0) is record
18072 Vals : IntArray (1 .. Len);
18076 you can assign a value with a different size of @code{Vals} with two
18080 (@value{GDBP}) set A_Rec.Len := 4
18081 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
18084 As this example also illustrates, @value{GDBN} is very loose about the usual
18085 rules concerning aggregates. You may leave out some of the
18086 components of an array or record aggregate (such as the @code{Len}
18087 component in the assignment to @code{A_Rec} above); they will retain their
18088 original values upon assignment. You may freely use dynamic values as
18089 indices in component associations. You may even use overlapping or
18090 redundant component associations, although which component values are
18091 assigned in such cases is not defined.
18094 Calls to dispatching subprograms are not implemented.
18097 The overloading algorithm is much more limited (i.e., less selective)
18098 than that of real Ada. It makes only limited use of the context in
18099 which a subexpression appears to resolve its meaning, and it is much
18100 looser in its rules for allowing type matches. As a result, some
18101 function calls will be ambiguous, and the user will be asked to choose
18102 the proper resolution.
18105 The @code{new} operator is not implemented.
18108 Entry calls are not implemented.
18111 Aside from printing, arithmetic operations on the native VAX floating-point
18112 formats are not supported.
18115 It is not possible to slice a packed array.
18118 The names @code{True} and @code{False}, when not part of a qualified name,
18119 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
18121 Should your program
18122 redefine these names in a package or procedure (at best a dubious practice),
18123 you will have to use fully qualified names to access their new definitions.
18126 @node Additions to Ada
18127 @subsubsection Additions to Ada
18128 @cindex Ada, deviations from
18130 As it does for other languages, @value{GDBN} makes certain generic
18131 extensions to Ada (@pxref{Expressions}):
18135 If the expression @var{E} is a variable residing in memory (typically
18136 a local variable or array element) and @var{N} is a positive integer,
18137 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18138 @var{N}-1 adjacent variables following it in memory as an array. In
18139 Ada, this operator is generally not necessary, since its prime use is
18140 in displaying parts of an array, and slicing will usually do this in
18141 Ada. However, there are occasional uses when debugging programs in
18142 which certain debugging information has been optimized away.
18145 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18146 appears in function or file @var{B}.'' When @var{B} is a file name,
18147 you must typically surround it in single quotes.
18150 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18151 @var{type} that appears at address @var{addr}.''
18154 A name starting with @samp{$} is a convenience variable
18155 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18158 In addition, @value{GDBN} provides a few other shortcuts and outright
18159 additions specific to Ada:
18163 The assignment statement is allowed as an expression, returning
18164 its right-hand operand as its value. Thus, you may enter
18167 (@value{GDBP}) set x := y + 3
18168 (@value{GDBP}) print A(tmp := y + 1)
18172 The semicolon is allowed as an ``operator,'' returning as its value
18173 the value of its right-hand operand.
18174 This allows, for example,
18175 complex conditional breaks:
18178 (@value{GDBP}) break f
18179 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18183 Rather than use catenation and symbolic character names to introduce special
18184 characters into strings, one may instead use a special bracket notation,
18185 which is also used to print strings. A sequence of characters of the form
18186 @samp{["@var{XX}"]} within a string or character literal denotes the
18187 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18188 sequence of characters @samp{["""]} also denotes a single quotation mark
18189 in strings. For example,
18191 "One line.["0a"]Next line.["0a"]"
18194 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18198 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18199 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18203 (@value{GDBP}) print 'max(x, y)
18207 When printing arrays, @value{GDBN} uses positional notation when the
18208 array has a lower bound of 1, and uses a modified named notation otherwise.
18209 For example, a one-dimensional array of three integers with a lower bound
18210 of 3 might print as
18217 That is, in contrast to valid Ada, only the first component has a @code{=>}
18221 You may abbreviate attributes in expressions with any unique,
18222 multi-character subsequence of
18223 their names (an exact match gets preference).
18224 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18225 in place of @t{a'length}.
18228 @cindex quoting Ada internal identifiers
18229 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18230 to lower case. The GNAT compiler uses upper-case characters for
18231 some of its internal identifiers, which are normally of no interest to users.
18232 For the rare occasions when you actually have to look at them,
18233 enclose them in angle brackets to avoid the lower-case mapping.
18236 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18240 Printing an object of class-wide type or dereferencing an
18241 access-to-class-wide value will display all the components of the object's
18242 specific type (as indicated by its run-time tag). Likewise, component
18243 selection on such a value will operate on the specific type of the
18248 @node Overloading support for Ada
18249 @subsubsection Overloading support for Ada
18250 @cindex overloading, Ada
18252 The debugger supports limited overloading. Given a subprogram call in which
18253 the function symbol has multiple definitions, it will use the number of
18254 actual parameters and some information about their types to attempt to narrow
18255 the set of definitions. It also makes very limited use of context, preferring
18256 procedures to functions in the context of the @code{call} command, and
18257 functions to procedures elsewhere.
18259 If, after narrowing, the set of matching definitions still contains more than
18260 one definition, @value{GDBN} will display a menu to query which one it should
18264 (@value{GDBP}) print f(1)
18265 Multiple matches for f
18267 [1] foo.f (integer) return boolean at foo.adb:23
18268 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18272 In this case, just select one menu entry either to cancel expression evaluation
18273 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18274 instance (type the corresponding number and press @key{RET}).
18276 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18281 @kindex set ada print-signatures
18282 @item set ada print-signatures
18283 Control whether parameter types and return types are displayed in overloads
18284 selection menus. It is @code{on} by default.
18285 @xref{Overloading support for Ada}.
18287 @kindex show ada print-signatures
18288 @item show ada print-signatures
18289 Show the current setting for displaying parameter types and return types in
18290 overloads selection menu.
18291 @xref{Overloading support for Ada}.
18295 @node Stopping Before Main Program
18296 @subsubsection Stopping at the Very Beginning
18298 @cindex breakpointing Ada elaboration code
18299 It is sometimes necessary to debug the program during elaboration, and
18300 before reaching the main procedure.
18301 As defined in the Ada Reference
18302 Manual, the elaboration code is invoked from a procedure called
18303 @code{adainit}. To run your program up to the beginning of
18304 elaboration, simply use the following two commands:
18305 @code{tbreak adainit} and @code{run}.
18307 @node Ada Exceptions
18308 @subsubsection Ada Exceptions
18310 A command is provided to list all Ada exceptions:
18313 @kindex info exceptions
18314 @item info exceptions
18315 @itemx info exceptions @var{regexp}
18316 The @code{info exceptions} command allows you to list all Ada exceptions
18317 defined within the program being debugged, as well as their addresses.
18318 With a regular expression, @var{regexp}, as argument, only those exceptions
18319 whose names match @var{regexp} are listed.
18322 Below is a small example, showing how the command can be used, first
18323 without argument, and next with a regular expression passed as an
18327 (@value{GDBP}) info exceptions
18328 All defined Ada exceptions:
18329 constraint_error: 0x613da0
18330 program_error: 0x613d20
18331 storage_error: 0x613ce0
18332 tasking_error: 0x613ca0
18333 const.aint_global_e: 0x613b00
18334 (@value{GDBP}) info exceptions const.aint
18335 All Ada exceptions matching regular expression "const.aint":
18336 constraint_error: 0x613da0
18337 const.aint_global_e: 0x613b00
18340 It is also possible to ask @value{GDBN} to stop your program's execution
18341 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18344 @subsubsection Extensions for Ada Tasks
18345 @cindex Ada, tasking
18347 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18348 @value{GDBN} provides the following task-related commands:
18353 This command shows a list of current Ada tasks, as in the following example:
18360 (@value{GDBP}) info tasks
18361 ID TID P-ID Pri State Name
18362 1 8088000 0 15 Child Activation Wait main_task
18363 2 80a4000 1 15 Accept Statement b
18364 3 809a800 1 15 Child Activation Wait a
18365 * 4 80ae800 3 15 Runnable c
18370 In this listing, the asterisk before the last task indicates it to be the
18371 task currently being inspected.
18375 Represents @value{GDBN}'s internal task number.
18381 The parent's task ID (@value{GDBN}'s internal task number).
18384 The base priority of the task.
18387 Current state of the task.
18391 The task has been created but has not been activated. It cannot be
18395 The task is not blocked for any reason known to Ada. (It may be waiting
18396 for a mutex, though.) It is conceptually "executing" in normal mode.
18399 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18400 that were waiting on terminate alternatives have been awakened and have
18401 terminated themselves.
18403 @item Child Activation Wait
18404 The task is waiting for created tasks to complete activation.
18406 @item Accept Statement
18407 The task is waiting on an accept or selective wait statement.
18409 @item Waiting on entry call
18410 The task is waiting on an entry call.
18412 @item Async Select Wait
18413 The task is waiting to start the abortable part of an asynchronous
18417 The task is waiting on a select statement with only a delay
18420 @item Child Termination Wait
18421 The task is sleeping having completed a master within itself, and is
18422 waiting for the tasks dependent on that master to become terminated or
18423 waiting on a terminate Phase.
18425 @item Wait Child in Term Alt
18426 The task is sleeping waiting for tasks on terminate alternatives to
18427 finish terminating.
18429 @item Accepting RV with @var{taskno}
18430 The task is accepting a rendez-vous with the task @var{taskno}.
18434 Name of the task in the program.
18438 @kindex info task @var{taskno}
18439 @item info task @var{taskno}
18440 This command shows detailed informations on the specified task, as in
18441 the following example:
18446 (@value{GDBP}) info tasks
18447 ID TID P-ID Pri State Name
18448 1 8077880 0 15 Child Activation Wait main_task
18449 * 2 807c468 1 15 Runnable task_1
18450 (@value{GDBP}) info task 2
18451 Ada Task: 0x807c468
18455 Parent: 1 ("main_task")
18461 @kindex task@r{ (Ada)}
18462 @cindex current Ada task ID
18463 This command prints the ID and name of the current task.
18469 (@value{GDBP}) info tasks
18470 ID TID P-ID Pri State Name
18471 1 8077870 0 15 Child Activation Wait main_task
18472 * 2 807c458 1 15 Runnable some_task
18473 (@value{GDBP}) task
18474 [Current task is 2 "some_task"]
18477 @item task @var{taskno}
18478 @cindex Ada task switching
18479 This command is like the @code{thread @var{thread-id}}
18480 command (@pxref{Threads}). It switches the context of debugging
18481 from the current task to the given task.
18487 (@value{GDBP}) info tasks
18488 ID TID P-ID Pri State Name
18489 1 8077870 0 15 Child Activation Wait main_task
18490 * 2 807c458 1 15 Runnable some_task
18491 (@value{GDBP}) task 1
18492 [Switching to task 1 "main_task"]
18493 #0 0x8067726 in pthread_cond_wait ()
18495 #0 0x8067726 in pthread_cond_wait ()
18496 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18497 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18498 #3 0x806153e in system.tasking.stages.activate_tasks ()
18499 #4 0x804aacc in un () at un.adb:5
18502 @item break @var{location} task @var{taskno}
18503 @itemx break @var{location} task @var{taskno} if @dots{}
18504 @cindex breakpoints and tasks, in Ada
18505 @cindex task breakpoints, in Ada
18506 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18507 These commands are like the @code{break @dots{} thread @dots{}}
18508 command (@pxref{Thread Stops}). The
18509 @var{location} argument specifies source lines, as described
18510 in @ref{Specify Location}.
18512 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18513 to specify that you only want @value{GDBN} to stop the program when a
18514 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18515 numeric task identifiers assigned by @value{GDBN}, shown in the first
18516 column of the @samp{info tasks} display.
18518 If you do not specify @samp{task @var{taskno}} when you set a
18519 breakpoint, the breakpoint applies to @emph{all} tasks of your
18522 You can use the @code{task} qualifier on conditional breakpoints as
18523 well; in this case, place @samp{task @var{taskno}} before the
18524 breakpoint condition (before the @code{if}).
18532 (@value{GDBP}) info tasks
18533 ID TID P-ID Pri State Name
18534 1 140022020 0 15 Child Activation Wait main_task
18535 2 140045060 1 15 Accept/Select Wait t2
18536 3 140044840 1 15 Runnable t1
18537 * 4 140056040 1 15 Runnable t3
18538 (@value{GDBP}) b 15 task 2
18539 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18540 (@value{GDBP}) cont
18545 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18547 (@value{GDBP}) info tasks
18548 ID TID P-ID Pri State Name
18549 1 140022020 0 15 Child Activation Wait main_task
18550 * 2 140045060 1 15 Runnable t2
18551 3 140044840 1 15 Runnable t1
18552 4 140056040 1 15 Delay Sleep t3
18556 @node Ada Tasks and Core Files
18557 @subsubsection Tasking Support when Debugging Core Files
18558 @cindex Ada tasking and core file debugging
18560 When inspecting a core file, as opposed to debugging a live program,
18561 tasking support may be limited or even unavailable, depending on
18562 the platform being used.
18563 For instance, on x86-linux, the list of tasks is available, but task
18564 switching is not supported.
18566 On certain platforms, the debugger needs to perform some
18567 memory writes in order to provide Ada tasking support. When inspecting
18568 a core file, this means that the core file must be opened with read-write
18569 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18570 Under these circumstances, you should make a backup copy of the core
18571 file before inspecting it with @value{GDBN}.
18573 @node Ravenscar Profile
18574 @subsubsection Tasking Support when using the Ravenscar Profile
18575 @cindex Ravenscar Profile
18577 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18578 specifically designed for systems with safety-critical real-time
18582 @kindex set ravenscar task-switching on
18583 @cindex task switching with program using Ravenscar Profile
18584 @item set ravenscar task-switching on
18585 Allows task switching when debugging a program that uses the Ravenscar
18586 Profile. This is the default.
18588 @kindex set ravenscar task-switching off
18589 @item set ravenscar task-switching off
18590 Turn off task switching when debugging a program that uses the Ravenscar
18591 Profile. This is mostly intended to disable the code that adds support
18592 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18593 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18594 To be effective, this command should be run before the program is started.
18596 @kindex show ravenscar task-switching
18597 @item show ravenscar task-switching
18598 Show whether it is possible to switch from task to task in a program
18599 using the Ravenscar Profile.
18603 @cindex Ravenscar thread
18604 When Ravenscar task-switching is enabled, Ravenscar tasks are
18605 announced by @value{GDBN} as if they were threads:
18609 [New Ravenscar Thread 0x2b8f0]
18612 Both Ravenscar tasks and the underlying CPU threads will show up in
18613 the output of @code{info threads}:
18618 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18619 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18620 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18621 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18622 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18623 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18626 One known limitation of the Ravenscar support in @value{GDBN} is that
18627 it isn't currently possible to single-step through the runtime
18628 initialization sequence. If you need to debug this code, you should
18629 use @code{set ravenscar task-switching off}.
18632 @subsubsection Ada Settings
18633 @cindex Ada settings
18636 @kindex set varsize-limit
18637 @item set varsize-limit @var{size}
18638 Prevent @value{GDBN} from attempting to evaluate objects whose size
18639 is above the given limit (@var{size}) when those sizes are computed
18640 from run-time quantities. This is typically the case when the object
18641 has a variable size, such as an array whose bounds are not known at
18642 compile time for example. Setting @var{size} to @code{unlimited}
18643 removes the size limitation. By default, the limit is about 65KB.
18645 The purpose of having such a limit is to prevent @value{GDBN} from
18646 trying to grab enormous chunks of virtual memory when asked to evaluate
18647 a quantity whose bounds have been corrupted or have not yet been fully
18648 initialized. The limit applies to the results of some subexpressions
18649 as well as to complete expressions. For example, an expression denoting
18650 a simple integer component, such as @code{x.y.z}, may fail if the size of
18651 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18652 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18653 @code{A} is an array variable with non-constant size, will generally
18654 succeed regardless of the bounds on @code{A}, as long as the component
18655 size is less than @var{size}.
18657 @kindex show varsize-limit
18658 @item show varsize-limit
18659 Show the limit on types whose size is determined by run-time quantities.
18663 @subsubsection Known Peculiarities of Ada Mode
18664 @cindex Ada, problems
18666 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18667 we know of several problems with and limitations of Ada mode in
18669 some of which will be fixed with planned future releases of the debugger
18670 and the GNU Ada compiler.
18674 Static constants that the compiler chooses not to materialize as objects in
18675 storage are invisible to the debugger.
18678 Named parameter associations in function argument lists are ignored (the
18679 argument lists are treated as positional).
18682 Many useful library packages are currently invisible to the debugger.
18685 Fixed-point arithmetic, conversions, input, and output is carried out using
18686 floating-point arithmetic, and may give results that only approximate those on
18690 The GNAT compiler never generates the prefix @code{Standard} for any of
18691 the standard symbols defined by the Ada language. @value{GDBN} knows about
18692 this: it will strip the prefix from names when you use it, and will never
18693 look for a name you have so qualified among local symbols, nor match against
18694 symbols in other packages or subprograms. If you have
18695 defined entities anywhere in your program other than parameters and
18696 local variables whose simple names match names in @code{Standard},
18697 GNAT's lack of qualification here can cause confusion. When this happens,
18698 you can usually resolve the confusion
18699 by qualifying the problematic names with package
18700 @code{Standard} explicitly.
18703 Older versions of the compiler sometimes generate erroneous debugging
18704 information, resulting in the debugger incorrectly printing the value
18705 of affected entities. In some cases, the debugger is able to work
18706 around an issue automatically. In other cases, the debugger is able
18707 to work around the issue, but the work-around has to be specifically
18710 @kindex set ada trust-PAD-over-XVS
18711 @kindex show ada trust-PAD-over-XVS
18714 @item set ada trust-PAD-over-XVS on
18715 Configure GDB to strictly follow the GNAT encoding when computing the
18716 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18717 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18718 a complete description of the encoding used by the GNAT compiler).
18719 This is the default.
18721 @item set ada trust-PAD-over-XVS off
18722 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18723 sometimes prints the wrong value for certain entities, changing @code{ada
18724 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18725 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18726 @code{off}, but this incurs a slight performance penalty, so it is
18727 recommended to leave this setting to @code{on} unless necessary.
18731 @cindex GNAT descriptive types
18732 @cindex GNAT encoding
18733 Internally, the debugger also relies on the compiler following a number
18734 of conventions known as the @samp{GNAT Encoding}, all documented in
18735 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18736 how the debugging information should be generated for certain types.
18737 In particular, this convention makes use of @dfn{descriptive types},
18738 which are artificial types generated purely to help the debugger.
18740 These encodings were defined at a time when the debugging information
18741 format used was not powerful enough to describe some of the more complex
18742 types available in Ada. Since DWARF allows us to express nearly all
18743 Ada features, the long-term goal is to slowly replace these descriptive
18744 types by their pure DWARF equivalent. To facilitate that transition,
18745 a new maintenance option is available to force the debugger to ignore
18746 those descriptive types. It allows the user to quickly evaluate how
18747 well @value{GDBN} works without them.
18751 @kindex maint ada set ignore-descriptive-types
18752 @item maintenance ada set ignore-descriptive-types [on|off]
18753 Control whether the debugger should ignore descriptive types.
18754 The default is not to ignore descriptives types (@code{off}).
18756 @kindex maint ada show ignore-descriptive-types
18757 @item maintenance ada show ignore-descriptive-types
18758 Show if descriptive types are ignored by @value{GDBN}.
18762 @node Unsupported Languages
18763 @section Unsupported Languages
18765 @cindex unsupported languages
18766 @cindex minimal language
18767 In addition to the other fully-supported programming languages,
18768 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18769 It does not represent a real programming language, but provides a set
18770 of capabilities close to what the C or assembly languages provide.
18771 This should allow most simple operations to be performed while debugging
18772 an application that uses a language currently not supported by @value{GDBN}.
18774 If the language is set to @code{auto}, @value{GDBN} will automatically
18775 select this language if the current frame corresponds to an unsupported
18779 @chapter Examining the Symbol Table
18781 The commands described in this chapter allow you to inquire about the
18782 symbols (names of variables, functions and types) defined in your
18783 program. This information is inherent in the text of your program and
18784 does not change as your program executes. @value{GDBN} finds it in your
18785 program's symbol table, in the file indicated when you started @value{GDBN}
18786 (@pxref{File Options, ,Choosing Files}), or by one of the
18787 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18789 @cindex symbol names
18790 @cindex names of symbols
18791 @cindex quoting names
18792 @anchor{quoting names}
18793 Occasionally, you may need to refer to symbols that contain unusual
18794 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18795 most frequent case is in referring to static variables in other
18796 source files (@pxref{Variables,,Program Variables}). File names
18797 are recorded in object files as debugging symbols, but @value{GDBN} would
18798 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18799 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18800 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18807 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18810 @cindex case-insensitive symbol names
18811 @cindex case sensitivity in symbol names
18812 @kindex set case-sensitive
18813 @item set case-sensitive on
18814 @itemx set case-sensitive off
18815 @itemx set case-sensitive auto
18816 Normally, when @value{GDBN} looks up symbols, it matches their names
18817 with case sensitivity determined by the current source language.
18818 Occasionally, you may wish to control that. The command @code{set
18819 case-sensitive} lets you do that by specifying @code{on} for
18820 case-sensitive matches or @code{off} for case-insensitive ones. If
18821 you specify @code{auto}, case sensitivity is reset to the default
18822 suitable for the source language. The default is case-sensitive
18823 matches for all languages except for Fortran, for which the default is
18824 case-insensitive matches.
18826 @kindex show case-sensitive
18827 @item show case-sensitive
18828 This command shows the current setting of case sensitivity for symbols
18831 @kindex set print type methods
18832 @item set print type methods
18833 @itemx set print type methods on
18834 @itemx set print type methods off
18835 Normally, when @value{GDBN} prints a class, it displays any methods
18836 declared in that class. You can control this behavior either by
18837 passing the appropriate flag to @code{ptype}, or using @command{set
18838 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18839 display the methods; this is the default. Specifying @code{off} will
18840 cause @value{GDBN} to omit the methods.
18842 @kindex show print type methods
18843 @item show print type methods
18844 This command shows the current setting of method display when printing
18847 @kindex set print type nested-type-limit
18848 @item set print type nested-type-limit @var{limit}
18849 @itemx set print type nested-type-limit unlimited
18850 Set the limit of displayed nested types that the type printer will
18851 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18852 nested definitions. By default, the type printer will not show any nested
18853 types defined in classes.
18855 @kindex show print type nested-type-limit
18856 @item show print type nested-type-limit
18857 This command shows the current display limit of nested types when
18860 @kindex set print type typedefs
18861 @item set print type typedefs
18862 @itemx set print type typedefs on
18863 @itemx set print type typedefs off
18865 Normally, when @value{GDBN} prints a class, it displays any typedefs
18866 defined in that class. You can control this behavior either by
18867 passing the appropriate flag to @code{ptype}, or using @command{set
18868 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18869 display the typedef definitions; this is the default. Specifying
18870 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18871 Note that this controls whether the typedef definition itself is
18872 printed, not whether typedef names are substituted when printing other
18875 @kindex show print type typedefs
18876 @item show print type typedefs
18877 This command shows the current setting of typedef display when
18880 @kindex info address
18881 @cindex address of a symbol
18882 @item info address @var{symbol}
18883 Describe where the data for @var{symbol} is stored. For a register
18884 variable, this says which register it is kept in. For a non-register
18885 local variable, this prints the stack-frame offset at which the variable
18888 Note the contrast with @samp{print &@var{symbol}}, which does not work
18889 at all for a register variable, and for a stack local variable prints
18890 the exact address of the current instantiation of the variable.
18892 @kindex info symbol
18893 @cindex symbol from address
18894 @cindex closest symbol and offset for an address
18895 @item info symbol @var{addr}
18896 Print the name of a symbol which is stored at the address @var{addr}.
18897 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18898 nearest symbol and an offset from it:
18901 (@value{GDBP}) info symbol 0x54320
18902 _initialize_vx + 396 in section .text
18906 This is the opposite of the @code{info address} command. You can use
18907 it to find out the name of a variable or a function given its address.
18909 For dynamically linked executables, the name of executable or shared
18910 library containing the symbol is also printed:
18913 (@value{GDBP}) info symbol 0x400225
18914 _start + 5 in section .text of /tmp/a.out
18915 (@value{GDBP}) info symbol 0x2aaaac2811cf
18916 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18921 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18922 Demangle @var{name}.
18923 If @var{language} is provided it is the name of the language to demangle
18924 @var{name} in. Otherwise @var{name} is demangled in the current language.
18926 The @samp{--} option specifies the end of options,
18927 and is useful when @var{name} begins with a dash.
18929 The parameter @code{demangle-style} specifies how to interpret the kind
18930 of mangling used. @xref{Print Settings}.
18933 @item whatis[/@var{flags}] [@var{arg}]
18934 Print the data type of @var{arg}, which can be either an expression
18935 or a name of a data type. With no argument, print the data type of
18936 @code{$}, the last value in the value history.
18938 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18939 is not actually evaluated, and any side-effecting operations (such as
18940 assignments or function calls) inside it do not take place.
18942 If @var{arg} is a variable or an expression, @code{whatis} prints its
18943 literal type as it is used in the source code. If the type was
18944 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18945 the data type underlying the @code{typedef}. If the type of the
18946 variable or the expression is a compound data type, such as
18947 @code{struct} or @code{class}, @code{whatis} never prints their
18948 fields or methods. It just prints the @code{struct}/@code{class}
18949 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18950 such a compound data type, use @code{ptype}.
18952 If @var{arg} is a type name that was defined using @code{typedef},
18953 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18954 Unrolling means that @code{whatis} will show the underlying type used
18955 in the @code{typedef} declaration of @var{arg}. However, if that
18956 underlying type is also a @code{typedef}, @code{whatis} will not
18959 For C code, the type names may also have the form @samp{class
18960 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18961 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18963 @var{flags} can be used to modify how the type is displayed.
18964 Available flags are:
18968 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18969 parameters and typedefs defined in a class when printing the class'
18970 members. The @code{/r} flag disables this.
18973 Do not print methods defined in the class.
18976 Print methods defined in the class. This is the default, but the flag
18977 exists in case you change the default with @command{set print type methods}.
18980 Do not print typedefs defined in the class. Note that this controls
18981 whether the typedef definition itself is printed, not whether typedef
18982 names are substituted when printing other types.
18985 Print typedefs defined in the class. This is the default, but the flag
18986 exists in case you change the default with @command{set print type typedefs}.
18989 Print the offsets and sizes of fields in a struct, similar to what the
18990 @command{pahole} tool does. This option implies the @code{/tm} flags.
18992 For example, given the following declarations:
19028 Issuing a @kbd{ptype /o struct tuv} command would print:
19031 (@value{GDBP}) ptype /o struct tuv
19032 /* offset | size */ type = struct tuv @{
19033 /* 0 | 4 */ int a1;
19034 /* XXX 4-byte hole */
19035 /* 8 | 8 */ char *a2;
19036 /* 16 | 4 */ int a3;
19038 /* total size (bytes): 24 */
19042 Notice the format of the first column of comments. There, you can
19043 find two parts separated by the @samp{|} character: the @emph{offset},
19044 which indicates where the field is located inside the struct, in
19045 bytes, and the @emph{size} of the field. Another interesting line is
19046 the marker of a @emph{hole} in the struct, indicating that it may be
19047 possible to pack the struct and make it use less space by reorganizing
19050 It is also possible to print offsets inside an union:
19053 (@value{GDBP}) ptype /o union qwe
19054 /* offset | size */ type = union qwe @{
19055 /* 24 */ struct tuv @{
19056 /* 0 | 4 */ int a1;
19057 /* XXX 4-byte hole */
19058 /* 8 | 8 */ char *a2;
19059 /* 16 | 4 */ int a3;
19061 /* total size (bytes): 24 */
19063 /* 40 */ struct xyz @{
19064 /* 0 | 4 */ int f1;
19065 /* 4 | 1 */ char f2;
19066 /* XXX 3-byte hole */
19067 /* 8 | 8 */ void *f3;
19068 /* 16 | 24 */ struct tuv @{
19069 /* 16 | 4 */ int a1;
19070 /* XXX 4-byte hole */
19071 /* 24 | 8 */ char *a2;
19072 /* 32 | 4 */ int a3;
19074 /* total size (bytes): 24 */
19077 /* total size (bytes): 40 */
19080 /* total size (bytes): 40 */
19084 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
19085 same space (because we are dealing with an union), the offset is not
19086 printed for them. However, you can still examine the offset of each
19087 of these structures' fields.
19089 Another useful scenario is printing the offsets of a struct containing
19093 (@value{GDBP}) ptype /o struct tyu
19094 /* offset | size */ type = struct tyu @{
19095 /* 0:31 | 4 */ int a1 : 1;
19096 /* 0:28 | 4 */ int a2 : 3;
19097 /* 0: 5 | 4 */ int a3 : 23;
19098 /* 3: 3 | 1 */ signed char a4 : 2;
19099 /* XXX 3-bit hole */
19100 /* XXX 4-byte hole */
19101 /* 8 | 8 */ int64_t a5;
19102 /* 16: 0 | 4 */ int a6 : 5;
19103 /* 16: 5 | 8 */ int64_t a7 : 3;
19104 "/* XXX 7-byte padding */
19106 /* total size (bytes): 24 */
19110 Note how the offset information is now extended to also include the
19111 first bit of the bitfield.
19115 @item ptype[/@var{flags}] [@var{arg}]
19116 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
19117 detailed description of the type, instead of just the name of the type.
19118 @xref{Expressions, ,Expressions}.
19120 Contrary to @code{whatis}, @code{ptype} always unrolls any
19121 @code{typedef}s in its argument declaration, whether the argument is
19122 a variable, expression, or a data type. This means that @code{ptype}
19123 of a variable or an expression will not print literally its type as
19124 present in the source code---use @code{whatis} for that. @code{typedef}s at
19125 the pointer or reference targets are also unrolled. Only @code{typedef}s of
19126 fields, methods and inner @code{class typedef}s of @code{struct}s,
19127 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
19129 For example, for this variable declaration:
19132 typedef double real_t;
19133 struct complex @{ real_t real; double imag; @};
19134 typedef struct complex complex_t;
19136 real_t *real_pointer_var;
19140 the two commands give this output:
19144 (@value{GDBP}) whatis var
19146 (@value{GDBP}) ptype var
19147 type = struct complex @{
19151 (@value{GDBP}) whatis complex_t
19152 type = struct complex
19153 (@value{GDBP}) whatis struct complex
19154 type = struct complex
19155 (@value{GDBP}) ptype struct complex
19156 type = struct complex @{
19160 (@value{GDBP}) whatis real_pointer_var
19162 (@value{GDBP}) ptype real_pointer_var
19168 As with @code{whatis}, using @code{ptype} without an argument refers to
19169 the type of @code{$}, the last value in the value history.
19171 @cindex incomplete type
19172 Sometimes, programs use opaque data types or incomplete specifications
19173 of complex data structure. If the debug information included in the
19174 program does not allow @value{GDBN} to display a full declaration of
19175 the data type, it will say @samp{<incomplete type>}. For example,
19176 given these declarations:
19180 struct foo *fooptr;
19184 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19187 (@value{GDBP}) ptype foo
19188 $1 = <incomplete type>
19192 ``Incomplete type'' is C terminology for data types that are not
19193 completely specified.
19195 @cindex unknown type
19196 Othertimes, information about a variable's type is completely absent
19197 from the debug information included in the program. This most often
19198 happens when the program or library where the variable is defined
19199 includes no debug information at all. @value{GDBN} knows the variable
19200 exists from inspecting the linker/loader symbol table (e.g., the ELF
19201 dynamic symbol table), but such symbols do not contain type
19202 information. Inspecting the type of a (global) variable for which
19203 @value{GDBN} has no type information shows:
19206 (@value{GDBP}) ptype var
19207 type = <data variable, no debug info>
19210 @xref{Variables, no debug info variables}, for how to print the values
19214 @item info types [-q] [@var{regexp}]
19215 Print a brief description of all types whose names match the regular
19216 expression @var{regexp} (or all types in your program, if you supply
19217 no argument). Each complete typename is matched as though it were a
19218 complete line; thus, @samp{i type value} gives information on all
19219 types in your program whose names include the string @code{value}, but
19220 @samp{i type ^value$} gives information only on types whose complete
19221 name is @code{value}.
19223 In programs using different languages, @value{GDBN} chooses the syntax
19224 to print the type description according to the
19225 @samp{set language} value: using @samp{set language auto}
19226 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19227 language of the type, other values mean to use
19228 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19230 This command differs from @code{ptype} in two ways: first, like
19231 @code{whatis}, it does not print a detailed description; second, it
19232 lists all source files and line numbers where a type is defined.
19234 The output from @samp{into types} is proceeded with a header line
19235 describing what types are being listed. The optional flag @samp{-q},
19236 which stands for @samp{quiet}, disables printing this header
19239 @kindex info type-printers
19240 @item info type-printers
19241 Versions of @value{GDBN} that ship with Python scripting enabled may
19242 have ``type printers'' available. When using @command{ptype} or
19243 @command{whatis}, these printers are consulted when the name of a type
19244 is needed. @xref{Type Printing API}, for more information on writing
19247 @code{info type-printers} displays all the available type printers.
19249 @kindex enable type-printer
19250 @kindex disable type-printer
19251 @item enable type-printer @var{name}@dots{}
19252 @item disable type-printer @var{name}@dots{}
19253 These commands can be used to enable or disable type printers.
19256 @cindex local variables
19257 @item info scope @var{location}
19258 List all the variables local to a particular scope. This command
19259 accepts a @var{location} argument---a function name, a source line, or
19260 an address preceded by a @samp{*}, and prints all the variables local
19261 to the scope defined by that location. (@xref{Specify Location}, for
19262 details about supported forms of @var{location}.) For example:
19265 (@value{GDBP}) @b{info scope command_line_handler}
19266 Scope for command_line_handler:
19267 Symbol rl is an argument at stack/frame offset 8, length 4.
19268 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19269 Symbol linelength is in static storage at address 0x150a1c, length 4.
19270 Symbol p is a local variable in register $esi, length 4.
19271 Symbol p1 is a local variable in register $ebx, length 4.
19272 Symbol nline is a local variable in register $edx, length 4.
19273 Symbol repeat is a local variable at frame offset -8, length 4.
19277 This command is especially useful for determining what data to collect
19278 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19281 @kindex info source
19283 Show information about the current source file---that is, the source file for
19284 the function containing the current point of execution:
19287 the name of the source file, and the directory containing it,
19289 the directory it was compiled in,
19291 its length, in lines,
19293 which programming language it is written in,
19295 if the debug information provides it, the program that compiled the file
19296 (which may include, e.g., the compiler version and command line arguments),
19298 whether the executable includes debugging information for that file, and
19299 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19301 whether the debugging information includes information about
19302 preprocessor macros.
19306 @kindex info sources
19308 Print the names of all source files in your program for which there is
19309 debugging information, organized into two lists: files whose symbols
19310 have already been read, and files whose symbols will be read when needed.
19312 @item info sources [-dirname | -basename] [--] [@var{regexp}]
19313 Like @samp{info sources}, but only print the names of the files
19314 matching the provided @var{regexp}.
19315 By default, the @var{regexp} is used to match anywhere in the filename.
19316 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19317 If @code{-basename}, only files having a basename matching @var{regexp}
19319 The matching is case-sensitive, except on operating systems that
19320 have case-insensitive filesystem (e.g., MS-Windows).
19322 @kindex info functions
19323 @item info functions [-q] [-n]
19324 Print the names and data types of all defined functions.
19325 Similarly to @samp{info types}, this command groups its output by source
19326 files and annotates each function definition with its source line
19329 In programs using different languages, @value{GDBN} chooses the syntax
19330 to print the function name and type according to the
19331 @samp{set language} value: using @samp{set language auto}
19332 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19333 language of the function, other values mean to use
19334 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19336 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19337 results. A non-debugging symbol is a symbol that comes from the
19338 executable's symbol table, not from the debug information (for
19339 example, DWARF) associated with the executable.
19341 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19342 printing header information and messages explaining why no functions
19345 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19346 Like @samp{info functions}, but only print the names and data types
19347 of the functions selected with the provided regexp(s).
19349 If @var{regexp} is provided, print only the functions whose names
19350 match the regular expression @var{regexp}.
19351 Thus, @samp{info fun step} finds all functions whose
19352 names include @code{step}; @samp{info fun ^step} finds those whose names
19353 start with @code{step}. If a function name contains characters that
19354 conflict with the regular expression language (e.g.@:
19355 @samp{operator*()}), they may be quoted with a backslash.
19357 If @var{type_regexp} is provided, print only the functions whose
19358 types, as printed by the @code{whatis} command, match
19359 the regular expression @var{type_regexp}.
19360 If @var{type_regexp} contains space(s), it should be enclosed in
19361 quote characters. If needed, use backslash to escape the meaning
19362 of special characters or quotes.
19363 Thus, @samp{info fun -t '^int ('} finds the functions that return
19364 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19365 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19366 finds the functions whose names start with @code{step} and that return
19369 If both @var{regexp} and @var{type_regexp} are provided, a function
19370 is printed only if its name matches @var{regexp} and its type matches
19374 @kindex info variables
19375 @item info variables [-q] [-n]
19376 Print the names and data types of all variables that are defined
19377 outside of functions (i.e.@: excluding local variables).
19378 The printed variables are grouped by source files and annotated with
19379 their respective source line numbers.
19381 In programs using different languages, @value{GDBN} chooses the syntax
19382 to print the variable name and type according to the
19383 @samp{set language} value: using @samp{set language auto}
19384 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19385 language of the variable, other values mean to use
19386 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19388 The @samp{-n} flag excludes non-debugging symbols from the results.
19390 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19391 printing header information and messages explaining why no variables
19394 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19395 Like @kbd{info variables}, but only print the variables selected
19396 with the provided regexp(s).
19398 If @var{regexp} is provided, print only the variables whose names
19399 match the regular expression @var{regexp}.
19401 If @var{type_regexp} is provided, print only the variables whose
19402 types, as printed by the @code{whatis} command, match
19403 the regular expression @var{type_regexp}.
19404 If @var{type_regexp} contains space(s), it should be enclosed in
19405 quote characters. If needed, use backslash to escape the meaning
19406 of special characters or quotes.
19408 If both @var{regexp} and @var{type_regexp} are provided, an argument
19409 is printed only if its name matches @var{regexp} and its type matches
19412 @kindex info modules
19414 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19415 List all Fortran modules in the program, or all modules matching the
19416 optional regular expression @var{regexp}.
19418 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19419 printing header information and messages explaining why no modules
19422 @kindex info module
19423 @cindex Fortran modules, information about
19424 @cindex functions and variables by Fortran module
19425 @cindex module functions and variables
19426 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19427 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19428 List all functions or variables within all Fortran modules. The set
19429 of functions or variables listed can be limited by providing some or
19430 all of the optional regular expressions. If @var{module-regexp} is
19431 provided, then only Fortran modules matching @var{module-regexp} will
19432 be searched. Only functions or variables whose type matches the
19433 optional regular expression @var{type-regexp} will be listed. And
19434 only functions or variables whose name matches the optional regular
19435 expression @var{regexp} will be listed.
19437 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19438 printing header information and messages explaining why no functions
19439 or variables have been printed.
19441 @kindex info classes
19442 @cindex Objective-C, classes and selectors
19444 @itemx info classes @var{regexp}
19445 Display all Objective-C classes in your program, or
19446 (with the @var{regexp} argument) all those matching a particular regular
19449 @kindex info selectors
19450 @item info selectors
19451 @itemx info selectors @var{regexp}
19452 Display all Objective-C selectors in your program, or
19453 (with the @var{regexp} argument) all those matching a particular regular
19457 This was never implemented.
19458 @kindex info methods
19460 @itemx info methods @var{regexp}
19461 The @code{info methods} command permits the user to examine all defined
19462 methods within C@t{++} program, or (with the @var{regexp} argument) a
19463 specific set of methods found in the various C@t{++} classes. Many
19464 C@t{++} classes provide a large number of methods. Thus, the output
19465 from the @code{ptype} command can be overwhelming and hard to use. The
19466 @code{info-methods} command filters the methods, printing only those
19467 which match the regular-expression @var{regexp}.
19470 @cindex opaque data types
19471 @kindex set opaque-type-resolution
19472 @item set opaque-type-resolution on
19473 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19474 declared as a pointer to a @code{struct}, @code{class}, or
19475 @code{union}---for example, @code{struct MyType *}---that is used in one
19476 source file although the full declaration of @code{struct MyType} is in
19477 another source file. The default is on.
19479 A change in the setting of this subcommand will not take effect until
19480 the next time symbols for a file are loaded.
19482 @item set opaque-type-resolution off
19483 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19484 is printed as follows:
19486 @{<no data fields>@}
19489 @kindex show opaque-type-resolution
19490 @item show opaque-type-resolution
19491 Show whether opaque types are resolved or not.
19493 @kindex set print symbol-loading
19494 @cindex print messages when symbols are loaded
19495 @item set print symbol-loading
19496 @itemx set print symbol-loading full
19497 @itemx set print symbol-loading brief
19498 @itemx set print symbol-loading off
19499 The @code{set print symbol-loading} command allows you to control the
19500 printing of messages when @value{GDBN} loads symbol information.
19501 By default a message is printed for the executable and one for each
19502 shared library, and normally this is what you want. However, when
19503 debugging apps with large numbers of shared libraries these messages
19505 When set to @code{brief} a message is printed for each executable,
19506 and when @value{GDBN} loads a collection of shared libraries at once
19507 it will only print one message regardless of the number of shared
19508 libraries. When set to @code{off} no messages are printed.
19510 @kindex show print symbol-loading
19511 @item show print symbol-loading
19512 Show whether messages will be printed when a @value{GDBN} command
19513 entered from the keyboard causes symbol information to be loaded.
19515 @kindex maint print symbols
19516 @cindex symbol dump
19517 @kindex maint print psymbols
19518 @cindex partial symbol dump
19519 @kindex maint print msymbols
19520 @cindex minimal symbol dump
19521 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19522 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19523 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19524 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19525 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19526 Write a dump of debugging symbol data into the file @var{filename} or
19527 the terminal if @var{filename} is unspecified.
19528 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19530 If @code{-pc @var{address}} is specified, only dump symbols for the file
19531 with code at that address. Note that @var{address} may be a symbol like
19533 If @code{-source @var{source}} is specified, only dump symbols for that
19536 These commands are used to debug the @value{GDBN} symbol-reading code.
19537 These commands do not modify internal @value{GDBN} state, therefore
19538 @samp{maint print symbols} will only print symbols for already expanded symbol
19540 You can use the command @code{info sources} to find out which files these are.
19541 If you use @samp{maint print psymbols} instead, the dump shows information
19542 about symbols that @value{GDBN} only knows partially---that is, symbols
19543 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19544 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19547 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19548 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19550 @kindex maint info symtabs
19551 @kindex maint info psymtabs
19552 @cindex listing @value{GDBN}'s internal symbol tables
19553 @cindex symbol tables, listing @value{GDBN}'s internal
19554 @cindex full symbol tables, listing @value{GDBN}'s internal
19555 @cindex partial symbol tables, listing @value{GDBN}'s internal
19556 @item maint info symtabs @r{[} @var{regexp} @r{]}
19557 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19559 List the @code{struct symtab} or @code{struct partial_symtab}
19560 structures whose names match @var{regexp}. If @var{regexp} is not
19561 given, list them all. The output includes expressions which you can
19562 copy into a @value{GDBN} debugging this one to examine a particular
19563 structure in more detail. For example:
19566 (@value{GDBP}) maint info psymtabs dwarf2read
19567 @{ objfile /home/gnu/build/gdb/gdb
19568 ((struct objfile *) 0x82e69d0)
19569 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19570 ((struct partial_symtab *) 0x8474b10)
19573 text addresses 0x814d3c8 -- 0x8158074
19574 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19575 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19576 dependencies (none)
19579 (@value{GDBP}) maint info symtabs
19583 We see that there is one partial symbol table whose filename contains
19584 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19585 and we see that @value{GDBN} has not read in any symtabs yet at all.
19586 If we set a breakpoint on a function, that will cause @value{GDBN} to
19587 read the symtab for the compilation unit containing that function:
19590 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19591 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19593 (@value{GDBP}) maint info symtabs
19594 @{ objfile /home/gnu/build/gdb/gdb
19595 ((struct objfile *) 0x82e69d0)
19596 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19597 ((struct symtab *) 0x86c1f38)
19600 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19601 linetable ((struct linetable *) 0x8370fa0)
19602 debugformat DWARF 2
19608 @kindex maint info line-table
19609 @cindex listing @value{GDBN}'s internal line tables
19610 @cindex line tables, listing @value{GDBN}'s internal
19611 @item maint info line-table @r{[} @var{regexp} @r{]}
19613 List the @code{struct linetable} from all @code{struct symtab}
19614 instances whose name matches @var{regexp}. If @var{regexp} is not
19615 given, list the @code{struct linetable} from all @code{struct symtab}.
19617 @kindex maint set symbol-cache-size
19618 @cindex symbol cache size
19619 @item maint set symbol-cache-size @var{size}
19620 Set the size of the symbol cache to @var{size}.
19621 The default size is intended to be good enough for debugging
19622 most applications. This option exists to allow for experimenting
19623 with different sizes.
19625 @kindex maint show symbol-cache-size
19626 @item maint show symbol-cache-size
19627 Show the size of the symbol cache.
19629 @kindex maint print symbol-cache
19630 @cindex symbol cache, printing its contents
19631 @item maint print symbol-cache
19632 Print the contents of the symbol cache.
19633 This is useful when debugging symbol cache issues.
19635 @kindex maint print symbol-cache-statistics
19636 @cindex symbol cache, printing usage statistics
19637 @item maint print symbol-cache-statistics
19638 Print symbol cache usage statistics.
19639 This helps determine how well the cache is being utilized.
19641 @kindex maint flush symbol-cache
19642 @kindex maint flush-symbol-cache
19643 @cindex symbol cache, flushing
19644 @item maint flush symbol-cache
19645 @itemx maint flush-symbol-cache
19646 Flush the contents of the symbol cache, all entries are removed. This
19647 command is useful when debugging the symbol cache. It is also useful
19648 when collecting performance data. The command @code{maint
19649 flush-symbol-cache} is deprecated in favor of @code{maint flush
19655 @chapter Altering Execution
19657 Once you think you have found an error in your program, you might want to
19658 find out for certain whether correcting the apparent error would lead to
19659 correct results in the rest of the run. You can find the answer by
19660 experiment, using the @value{GDBN} features for altering execution of the
19663 For example, you can store new values into variables or memory
19664 locations, give your program a signal, restart it at a different
19665 address, or even return prematurely from a function.
19668 * Assignment:: Assignment to variables
19669 * Jumping:: Continuing at a different address
19670 * Signaling:: Giving your program a signal
19671 * Returning:: Returning from a function
19672 * Calling:: Calling your program's functions
19673 * Patching:: Patching your program
19674 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19678 @section Assignment to Variables
19681 @cindex setting variables
19682 To alter the value of a variable, evaluate an assignment expression.
19683 @xref{Expressions, ,Expressions}. For example,
19690 stores the value 4 into the variable @code{x}, and then prints the
19691 value of the assignment expression (which is 4).
19692 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19693 information on operators in supported languages.
19695 @kindex set variable
19696 @cindex variables, setting
19697 If you are not interested in seeing the value of the assignment, use the
19698 @code{set} command instead of the @code{print} command. @code{set} is
19699 really the same as @code{print} except that the expression's value is
19700 not printed and is not put in the value history (@pxref{Value History,
19701 ,Value History}). The expression is evaluated only for its effects.
19703 If the beginning of the argument string of the @code{set} command
19704 appears identical to a @code{set} subcommand, use the @code{set
19705 variable} command instead of just @code{set}. This command is identical
19706 to @code{set} except for its lack of subcommands. For example, if your
19707 program has a variable @code{width}, you get an error if you try to set
19708 a new value with just @samp{set width=13}, because @value{GDBN} has the
19709 command @code{set width}:
19712 (@value{GDBP}) whatis width
19714 (@value{GDBP}) p width
19716 (@value{GDBP}) set width=47
19717 Invalid syntax in expression.
19721 The invalid expression, of course, is @samp{=47}. In
19722 order to actually set the program's variable @code{width}, use
19725 (@value{GDBP}) set var width=47
19728 Because the @code{set} command has many subcommands that can conflict
19729 with the names of program variables, it is a good idea to use the
19730 @code{set variable} command instead of just @code{set}. For example, if
19731 your program has a variable @code{g}, you run into problems if you try
19732 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19733 the command @code{set gnutarget}, abbreviated @code{set g}:
19737 (@value{GDBP}) whatis g
19741 (@value{GDBP}) set g=4
19745 The program being debugged has been started already.
19746 Start it from the beginning? (y or n) y
19747 Starting program: /home/smith/cc_progs/a.out
19748 "/home/smith/cc_progs/a.out": can't open to read symbols:
19749 Invalid bfd target.
19750 (@value{GDBP}) show g
19751 The current BFD target is "=4".
19756 The program variable @code{g} did not change, and you silently set the
19757 @code{gnutarget} to an invalid value. In order to set the variable
19761 (@value{GDBP}) set var g=4
19764 @value{GDBN} allows more implicit conversions in assignments than C; you can
19765 freely store an integer value into a pointer variable or vice versa,
19766 and you can convert any structure to any other structure that is the
19767 same length or shorter.
19768 @comment FIXME: how do structs align/pad in these conversions?
19769 @comment /doc@cygnus.com 18dec1990
19771 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19772 construct to generate a value of specified type at a specified address
19773 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19774 to memory location @code{0x83040} as an integer (which implies a certain size
19775 and representation in memory), and
19778 set @{int@}0x83040 = 4
19782 stores the value 4 into that memory location.
19785 @section Continuing at a Different Address
19787 Ordinarily, when you continue your program, you do so at the place where
19788 it stopped, with the @code{continue} command. You can instead continue at
19789 an address of your own choosing, with the following commands:
19793 @kindex j @r{(@code{jump})}
19794 @item jump @var{location}
19795 @itemx j @var{location}
19796 Resume execution at @var{location}. Execution stops again immediately
19797 if there is a breakpoint there. @xref{Specify Location}, for a description
19798 of the different forms of @var{location}. It is common
19799 practice to use the @code{tbreak} command in conjunction with
19800 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19802 The @code{jump} command does not change the current stack frame, or
19803 the stack pointer, or the contents of any memory location or any
19804 register other than the program counter. If @var{location} is in
19805 a different function from the one currently executing, the results may
19806 be bizarre if the two functions expect different patterns of arguments or
19807 of local variables. For this reason, the @code{jump} command requests
19808 confirmation if the specified line is not in the function currently
19809 executing. However, even bizarre results are predictable if you are
19810 well acquainted with the machine-language code of your program.
19813 On many systems, you can get much the same effect as the @code{jump}
19814 command by storing a new value into the register @code{$pc}. The
19815 difference is that this does not start your program running; it only
19816 changes the address of where it @emph{will} run when you continue. For
19824 makes the next @code{continue} command or stepping command execute at
19825 address @code{0x485}, rather than at the address where your program stopped.
19826 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19828 The most common occasion to use the @code{jump} command is to back
19829 up---perhaps with more breakpoints set---over a portion of a program
19830 that has already executed, in order to examine its execution in more
19835 @section Giving your Program a Signal
19836 @cindex deliver a signal to a program
19840 @item signal @var{signal}
19841 Resume execution where your program is stopped, but immediately give it the
19842 signal @var{signal}. The @var{signal} can be the name or the number of a
19843 signal. For example, on many systems @code{signal 2} and @code{signal
19844 SIGINT} are both ways of sending an interrupt signal.
19846 Alternatively, if @var{signal} is zero, continue execution without
19847 giving a signal. This is useful when your program stopped on account of
19848 a signal and would ordinarily see the signal when resumed with the
19849 @code{continue} command; @samp{signal 0} causes it to resume without a
19852 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19853 delivered to the currently selected thread, not the thread that last
19854 reported a stop. This includes the situation where a thread was
19855 stopped due to a signal. So if you want to continue execution
19856 suppressing the signal that stopped a thread, you should select that
19857 same thread before issuing the @samp{signal 0} command. If you issue
19858 the @samp{signal 0} command with another thread as the selected one,
19859 @value{GDBN} detects that and asks for confirmation.
19861 Invoking the @code{signal} command is not the same as invoking the
19862 @code{kill} utility from the shell. Sending a signal with @code{kill}
19863 causes @value{GDBN} to decide what to do with the signal depending on
19864 the signal handling tables (@pxref{Signals}). The @code{signal} command
19865 passes the signal directly to your program.
19867 @code{signal} does not repeat when you press @key{RET} a second time
19868 after executing the command.
19870 @kindex queue-signal
19871 @item queue-signal @var{signal}
19872 Queue @var{signal} to be delivered immediately to the current thread
19873 when execution of the thread resumes. The @var{signal} can be the name or
19874 the number of a signal. For example, on many systems @code{signal 2} and
19875 @code{signal SIGINT} are both ways of sending an interrupt signal.
19876 The handling of the signal must be set to pass the signal to the program,
19877 otherwise @value{GDBN} will report an error.
19878 You can control the handling of signals from @value{GDBN} with the
19879 @code{handle} command (@pxref{Signals}).
19881 Alternatively, if @var{signal} is zero, any currently queued signal
19882 for the current thread is discarded and when execution resumes no signal
19883 will be delivered. This is useful when your program stopped on account
19884 of a signal and would ordinarily see the signal when resumed with the
19885 @code{continue} command.
19887 This command differs from the @code{signal} command in that the signal
19888 is just queued, execution is not resumed. And @code{queue-signal} cannot
19889 be used to pass a signal whose handling state has been set to @code{nopass}
19894 @xref{stepping into signal handlers}, for information on how stepping
19895 commands behave when the thread has a signal queued.
19898 @section Returning from a Function
19901 @cindex returning from a function
19904 @itemx return @var{expression}
19905 You can cancel execution of a function call with the @code{return}
19906 command. If you give an
19907 @var{expression} argument, its value is used as the function's return
19911 When you use @code{return}, @value{GDBN} discards the selected stack frame
19912 (and all frames within it). You can think of this as making the
19913 discarded frame return prematurely. If you wish to specify a value to
19914 be returned, give that value as the argument to @code{return}.
19916 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19917 Frame}), and any other frames inside of it, leaving its caller as the
19918 innermost remaining frame. That frame becomes selected. The
19919 specified value is stored in the registers used for returning values
19922 The @code{return} command does not resume execution; it leaves the
19923 program stopped in the state that would exist if the function had just
19924 returned. In contrast, the @code{finish} command (@pxref{Continuing
19925 and Stepping, ,Continuing and Stepping}) resumes execution until the
19926 selected stack frame returns naturally.
19928 @value{GDBN} needs to know how the @var{expression} argument should be set for
19929 the inferior. The concrete registers assignment depends on the OS ABI and the
19930 type being returned by the selected stack frame. For example it is common for
19931 OS ABI to return floating point values in FPU registers while integer values in
19932 CPU registers. Still some ABIs return even floating point values in CPU
19933 registers. Larger integer widths (such as @code{long long int}) also have
19934 specific placement rules. @value{GDBN} already knows the OS ABI from its
19935 current target so it needs to find out also the type being returned to make the
19936 assignment into the right register(s).
19938 Normally, the selected stack frame has debug info. @value{GDBN} will always
19939 use the debug info instead of the implicit type of @var{expression} when the
19940 debug info is available. For example, if you type @kbd{return -1}, and the
19941 function in the current stack frame is declared to return a @code{long long
19942 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19943 into a @code{long long int}:
19946 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19948 (@value{GDBP}) return -1
19949 Make func return now? (y or n) y
19950 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19951 43 printf ("result=%lld\n", func ());
19955 However, if the selected stack frame does not have a debug info, e.g., if the
19956 function was compiled without debug info, @value{GDBN} has to find out the type
19957 to return from user. Specifying a different type by mistake may set the value
19958 in different inferior registers than the caller code expects. For example,
19959 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19960 of a @code{long long int} result for a debug info less function (on 32-bit
19961 architectures). Therefore the user is required to specify the return type by
19962 an appropriate cast explicitly:
19965 Breakpoint 2, 0x0040050b in func ()
19966 (@value{GDBP}) return -1
19967 Return value type not available for selected stack frame.
19968 Please use an explicit cast of the value to return.
19969 (@value{GDBP}) return (long long int) -1
19970 Make selected stack frame return now? (y or n) y
19971 #0 0x00400526 in main ()
19976 @section Calling Program Functions
19979 @cindex calling functions
19980 @cindex inferior functions, calling
19981 @item print @var{expr}
19982 Evaluate the expression @var{expr} and display the resulting value.
19983 The expression may include calls to functions in the program being
19987 @item call @var{expr}
19988 Evaluate the expression @var{expr} without displaying @code{void}
19991 You can use this variant of the @code{print} command if you want to
19992 execute a function from your program that does not return anything
19993 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19994 with @code{void} returned values that @value{GDBN} will otherwise
19995 print. If the result is not void, it is printed and saved in the
19999 It is possible for the function you call via the @code{print} or
20000 @code{call} command to generate a signal (e.g., if there's a bug in
20001 the function, or if you passed it incorrect arguments). What happens
20002 in that case is controlled by the @code{set unwindonsignal} command.
20004 Similarly, with a C@t{++} program it is possible for the function you
20005 call via the @code{print} or @code{call} command to generate an
20006 exception that is not handled due to the constraints of the dummy
20007 frame. In this case, any exception that is raised in the frame, but has
20008 an out-of-frame exception handler will not be found. GDB builds a
20009 dummy-frame for the inferior function call, and the unwinder cannot
20010 seek for exception handlers outside of this dummy-frame. What happens
20011 in that case is controlled by the
20012 @code{set unwind-on-terminating-exception} command.
20015 @item set unwindonsignal
20016 @kindex set unwindonsignal
20017 @cindex unwind stack in called functions
20018 @cindex call dummy stack unwinding
20019 Set unwinding of the stack if a signal is received while in a function
20020 that @value{GDBN} called in the program being debugged. If set to on,
20021 @value{GDBN} unwinds the stack it created for the call and restores
20022 the context to what it was before the call. If set to off (the
20023 default), @value{GDBN} stops in the frame where the signal was
20026 @item show unwindonsignal
20027 @kindex show unwindonsignal
20028 Show the current setting of stack unwinding in the functions called by
20031 @item set unwind-on-terminating-exception
20032 @kindex set unwind-on-terminating-exception
20033 @cindex unwind stack in called functions with unhandled exceptions
20034 @cindex call dummy stack unwinding on unhandled exception.
20035 Set unwinding of the stack if a C@t{++} exception is raised, but left
20036 unhandled while in a function that @value{GDBN} called in the program being
20037 debugged. If set to on (the default), @value{GDBN} unwinds the stack
20038 it created for the call and restores the context to what it was before
20039 the call. If set to off, @value{GDBN} the exception is delivered to
20040 the default C@t{++} exception handler and the inferior terminated.
20042 @item show unwind-on-terminating-exception
20043 @kindex show unwind-on-terminating-exception
20044 Show the current setting of stack unwinding in the functions called by
20047 @item set may-call-functions
20048 @kindex set may-call-functions
20049 @cindex disabling calling functions in the program
20050 @cindex calling functions in the program, disabling
20051 Set permission to call functions in the program.
20052 This controls whether @value{GDBN} will attempt to call functions in
20053 the program, such as with expressions in the @code{print} command. It
20054 defaults to @code{on}.
20056 To call a function in the program, @value{GDBN} has to temporarily
20057 modify the state of the inferior. This has potentially undesired side
20058 effects. Also, having @value{GDBN} call nested functions is likely to
20059 be erroneous and may even crash the program being debugged. You can
20060 avoid such hazards by forbidding @value{GDBN} from calling functions
20061 in the program being debugged. If calling functions in the program
20062 is forbidden, GDB will throw an error when a command (such as printing
20063 an expression) starts a function call in the program.
20065 @item show may-call-functions
20066 @kindex show may-call-functions
20067 Show permission to call functions in the program.
20071 @subsection Calling functions with no debug info
20073 @cindex no debug info functions
20074 Sometimes, a function you wish to call is missing debug information.
20075 In such case, @value{GDBN} does not know the type of the function,
20076 including the types of the function's parameters. To avoid calling
20077 the inferior function incorrectly, which could result in the called
20078 function functioning erroneously and even crash, @value{GDBN} refuses
20079 to call the function unless you tell it the type of the function.
20081 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
20082 to do that. The simplest is to cast the call to the function's
20083 declared return type. For example:
20086 (@value{GDBP}) p getenv ("PATH")
20087 'getenv' has unknown return type; cast the call to its declared return type
20088 (@value{GDBP}) p (char *) getenv ("PATH")
20089 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
20092 Casting the return type of a no-debug function is equivalent to
20093 casting the function to a pointer to a prototyped function that has a
20094 prototype that matches the types of the passed-in arguments, and
20095 calling that. I.e., the call above is equivalent to:
20098 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
20102 and given this prototyped C or C++ function with float parameters:
20105 float multiply (float v1, float v2) @{ return v1 * v2; @}
20109 these calls are equivalent:
20112 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
20113 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
20116 If the function you wish to call is declared as unprototyped (i.e.@:
20117 old K&R style), you must use the cast-to-function-pointer syntax, so
20118 that @value{GDBN} knows that it needs to apply default argument
20119 promotions (promote float arguments to double). @xref{ABI, float
20120 promotion}. For example, given this unprototyped C function with
20121 float parameters, and no debug info:
20125 multiply_noproto (v1, v2)
20133 you call it like this:
20136 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20140 @section Patching Programs
20142 @cindex patching binaries
20143 @cindex writing into executables
20144 @cindex writing into corefiles
20146 By default, @value{GDBN} opens the file containing your program's
20147 executable code (or the corefile) read-only. This prevents accidental
20148 alterations to machine code; but it also prevents you from intentionally
20149 patching your program's binary.
20151 If you'd like to be able to patch the binary, you can specify that
20152 explicitly with the @code{set write} command. For example, you might
20153 want to turn on internal debugging flags, or even to make emergency
20159 @itemx set write off
20160 If you specify @samp{set write on}, @value{GDBN} opens executable and
20161 core files for both reading and writing; if you specify @kbd{set write
20162 off} (the default), @value{GDBN} opens them read-only.
20164 If you have already loaded a file, you must load it again (using the
20165 @code{exec-file} or @code{core-file} command) after changing @code{set
20166 write}, for your new setting to take effect.
20170 Display whether executable files and core files are opened for writing
20171 as well as reading.
20174 @node Compiling and Injecting Code
20175 @section Compiling and injecting code in @value{GDBN}
20176 @cindex injecting code
20177 @cindex writing into executables
20178 @cindex compiling code
20180 @value{GDBN} supports on-demand compilation and code injection into
20181 programs running under @value{GDBN}. GCC 5.0 or higher built with
20182 @file{libcc1.so} must be installed for this functionality to be enabled.
20183 This functionality is implemented with the following commands.
20186 @kindex compile code
20187 @item compile code @var{source-code}
20188 @itemx compile code -raw @var{--} @var{source-code}
20189 Compile @var{source-code} with the compiler language found as the current
20190 language in @value{GDBN} (@pxref{Languages}). If compilation and
20191 injection is not supported with the current language specified in
20192 @value{GDBN}, or the compiler does not support this feature, an error
20193 message will be printed. If @var{source-code} compiles and links
20194 successfully, @value{GDBN} will load the object-code emitted,
20195 and execute it within the context of the currently selected inferior.
20196 It is important to note that the compiled code is executed immediately.
20197 After execution, the compiled code is removed from @value{GDBN} and any
20198 new types or variables you have defined will be deleted.
20200 The command allows you to specify @var{source-code} in two ways.
20201 The simplest method is to provide a single line of code to the command.
20205 compile code printf ("hello world\n");
20208 If you specify options on the command line as well as source code, they
20209 may conflict. The @samp{--} delimiter can be used to separate options
20210 from actual source code. E.g.:
20213 compile code -r -- printf ("hello world\n");
20216 Alternatively you can enter source code as multiple lines of text. To
20217 enter this mode, invoke the @samp{compile code} command without any text
20218 following the command. This will start the multiple-line editor and
20219 allow you to type as many lines of source code as required. When you
20220 have completed typing, enter @samp{end} on its own line to exit the
20225 >printf ("hello\n");
20226 >printf ("world\n");
20230 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20231 provided @var{source-code} in a callable scope. In this case, you must
20232 specify the entry point of the code by defining a function named
20233 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20234 inferior. Using @samp{-raw} option may be needed for example when
20235 @var{source-code} requires @samp{#include} lines which may conflict with
20236 inferior symbols otherwise.
20238 @kindex compile file
20239 @item compile file @var{filename}
20240 @itemx compile file -raw @var{filename}
20241 Like @code{compile code}, but take the source code from @var{filename}.
20244 compile file /home/user/example.c
20249 @item compile print [[@var{options}] --] @var{expr}
20250 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
20251 Compile and execute @var{expr} with the compiler language found as the
20252 current language in @value{GDBN} (@pxref{Languages}). By default the
20253 value of @var{expr} is printed in a format appropriate to its data type;
20254 you can choose a different format by specifying @samp{/@var{f}}, where
20255 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
20256 Formats}. The @code{compile print} command accepts the same options
20257 as the @code{print} command; see @ref{print options}.
20259 @item compile print [[@var{options}] --]
20260 @itemx compile print [[@var{options}] --] /@var{f}
20261 @cindex reprint the last value
20262 Alternatively you can enter the expression (source code producing it) as
20263 multiple lines of text. To enter this mode, invoke the @samp{compile print}
20264 command without any text following the command. This will start the
20265 multiple-line editor.
20269 The process of compiling and injecting the code can be inspected using:
20272 @anchor{set debug compile}
20273 @item set debug compile
20274 @cindex compile command debugging info
20275 Turns on or off display of @value{GDBN} process of compiling and
20276 injecting the code. The default is off.
20278 @item show debug compile
20279 Displays the current state of displaying @value{GDBN} process of
20280 compiling and injecting the code.
20282 @anchor{set debug compile-cplus-types}
20283 @item set debug compile-cplus-types
20284 @cindex compile C@t{++} type conversion
20285 Turns on or off the display of C@t{++} type conversion debugging information.
20286 The default is off.
20288 @item show debug compile-cplus-types
20289 Displays the current state of displaying debugging information for
20290 C@t{++} type conversion.
20293 @subsection Compilation options for the @code{compile} command
20295 @value{GDBN} needs to specify the right compilation options for the code
20296 to be injected, in part to make its ABI compatible with the inferior
20297 and in part to make the injected code compatible with @value{GDBN}'s
20301 The options used, in increasing precedence:
20304 @item target architecture and OS options (@code{gdbarch})
20305 These options depend on target processor type and target operating
20306 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20307 (@code{-m64}) compilation option.
20309 @item compilation options recorded in the target
20310 @value{NGCC} (since version 4.7) stores the options used for compilation
20311 into @code{DW_AT_producer} part of DWARF debugging information according
20312 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20313 explicitly specify @code{-g} during inferior compilation otherwise
20314 @value{NGCC} produces no DWARF. This feature is only relevant for
20315 platforms where @code{-g} produces DWARF by default, otherwise one may
20316 try to enforce DWARF by using @code{-gdwarf-4}.
20318 @item compilation options set by @code{set compile-args}
20322 You can override compilation options using the following command:
20325 @item set compile-args
20326 @cindex compile command options override
20327 Set compilation options used for compiling and injecting code with the
20328 @code{compile} commands. These options override any conflicting ones
20329 from the target architecture and/or options stored during inferior
20332 @item show compile-args
20333 Displays the current state of compilation options override.
20334 This does not show all the options actually used during compilation,
20335 use @ref{set debug compile} for that.
20338 @subsection Caveats when using the @code{compile} command
20340 There are a few caveats to keep in mind when using the @code{compile}
20341 command. As the caveats are different per language, the table below
20342 highlights specific issues on a per language basis.
20345 @item C code examples and caveats
20346 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20347 attempt to compile the source code with a @samp{C} compiler. The source
20348 code provided to the @code{compile} command will have much the same
20349 access to variables and types as it normally would if it were part of
20350 the program currently being debugged in @value{GDBN}.
20352 Below is a sample program that forms the basis of the examples that
20353 follow. This program has been compiled and loaded into @value{GDBN},
20354 much like any other normal debugging session.
20357 void function1 (void)
20360 printf ("function 1\n");
20363 void function2 (void)
20378 For the purposes of the examples in this section, the program above has
20379 been compiled, loaded into @value{GDBN}, stopped at the function
20380 @code{main}, and @value{GDBN} is awaiting input from the user.
20382 To access variables and types for any program in @value{GDBN}, the
20383 program must be compiled and packaged with debug information. The
20384 @code{compile} command is not an exception to this rule. Without debug
20385 information, you can still use the @code{compile} command, but you will
20386 be very limited in what variables and types you can access.
20388 So with that in mind, the example above has been compiled with debug
20389 information enabled. The @code{compile} command will have access to
20390 all variables and types (except those that may have been optimized
20391 out). Currently, as @value{GDBN} has stopped the program in the
20392 @code{main} function, the @code{compile} command would have access to
20393 the variable @code{k}. You could invoke the @code{compile} command
20394 and type some source code to set the value of @code{k}. You can also
20395 read it, or do anything with that variable you would normally do in
20396 @code{C}. Be aware that changes to inferior variables in the
20397 @code{compile} command are persistent. In the following example:
20400 compile code k = 3;
20404 the variable @code{k} is now 3. It will retain that value until
20405 something else in the example program changes it, or another
20406 @code{compile} command changes it.
20408 Normal scope and access rules apply to source code compiled and
20409 injected by the @code{compile} command. In the example, the variables
20410 @code{j} and @code{k} are not accessible yet, because the program is
20411 currently stopped in the @code{main} function, where these variables
20412 are not in scope. Therefore, the following command
20415 compile code j = 3;
20419 will result in a compilation error message.
20421 Once the program is continued, execution will bring these variables in
20422 scope, and they will become accessible; then the code you specify via
20423 the @code{compile} command will be able to access them.
20425 You can create variables and types with the @code{compile} command as
20426 part of your source code. Variables and types that are created as part
20427 of the @code{compile} command are not visible to the rest of the program for
20428 the duration of its run. This example is valid:
20431 compile code int ff = 5; printf ("ff is %d\n", ff);
20434 However, if you were to type the following into @value{GDBN} after that
20435 command has completed:
20438 compile code printf ("ff is %d\n'', ff);
20442 a compiler error would be raised as the variable @code{ff} no longer
20443 exists. Object code generated and injected by the @code{compile}
20444 command is removed when its execution ends. Caution is advised
20445 when assigning to program variables values of variables created by the
20446 code submitted to the @code{compile} command. This example is valid:
20449 compile code int ff = 5; k = ff;
20452 The value of the variable @code{ff} is assigned to @code{k}. The variable
20453 @code{k} does not require the existence of @code{ff} to maintain the value
20454 it has been assigned. However, pointers require particular care in
20455 assignment. If the source code compiled with the @code{compile} command
20456 changed the address of a pointer in the example program, perhaps to a
20457 variable created in the @code{compile} command, that pointer would point
20458 to an invalid location when the command exits. The following example
20459 would likely cause issues with your debugged program:
20462 compile code int ff = 5; p = &ff;
20465 In this example, @code{p} would point to @code{ff} when the
20466 @code{compile} command is executing the source code provided to it.
20467 However, as variables in the (example) program persist with their
20468 assigned values, the variable @code{p} would point to an invalid
20469 location when the command exists. A general rule should be followed
20470 in that you should either assign @code{NULL} to any assigned pointers,
20471 or restore a valid location to the pointer before the command exits.
20473 Similar caution must be exercised with any structs, unions, and typedefs
20474 defined in @code{compile} command. Types defined in the @code{compile}
20475 command will no longer be available in the next @code{compile} command.
20476 Therefore, if you cast a variable to a type defined in the
20477 @code{compile} command, care must be taken to ensure that any future
20478 need to resolve the type can be achieved.
20481 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20482 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20483 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20484 Compilation failed.
20485 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20489 Variables that have been optimized away by the compiler are not
20490 accessible to the code submitted to the @code{compile} command.
20491 Access to those variables will generate a compiler error which @value{GDBN}
20492 will print to the console.
20495 @subsection Compiler search for the @code{compile} command
20497 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20498 which may not be obvious for remote targets of different architecture
20499 than where @value{GDBN} is running. Environment variable @code{PATH} on
20500 @value{GDBN} host is searched for @value{NGCC} binary matching the
20501 target architecture and operating system. This search can be overriden
20502 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20503 taken from shell that executed @value{GDBN}, it is not the value set by
20504 @value{GDBN} command @code{set environment}). @xref{Environment}.
20507 Specifically @code{PATH} is searched for binaries matching regular expression
20508 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20509 debugged. @var{arch} is processor name --- multiarch is supported, so for
20510 example both @code{i386} and @code{x86_64} targets look for pattern
20511 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20512 for pattern @code{s390x?}. @var{os} is currently supported only for
20513 pattern @code{linux(-gnu)?}.
20515 On Posix hosts the compiler driver @value{GDBN} needs to find also
20516 shared library @file{libcc1.so} from the compiler. It is searched in
20517 default shared library search path (overridable with usual environment
20518 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20519 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20520 according to the installation of the found compiler --- as possibly
20521 specified by the @code{set compile-gcc} command.
20524 @item set compile-gcc
20525 @cindex compile command driver filename override
20526 Set compilation command used for compiling and injecting code with the
20527 @code{compile} commands. If this option is not set (it is set to
20528 an empty string), the search described above will occur --- that is the
20531 @item show compile-gcc
20532 Displays the current compile command @value{NGCC} driver filename.
20533 If set, it is the main command @command{gcc}, found usually for example
20534 under name @file{x86_64-linux-gnu-gcc}.
20538 @chapter @value{GDBN} Files
20540 @value{GDBN} needs to know the file name of the program to be debugged,
20541 both in order to read its symbol table and in order to start your
20542 program. To debug a core dump of a previous run, you must also tell
20543 @value{GDBN} the name of the core dump file.
20546 * Files:: Commands to specify files
20547 * File Caching:: Information about @value{GDBN}'s file caching
20548 * Separate Debug Files:: Debugging information in separate files
20549 * MiniDebugInfo:: Debugging information in a special section
20550 * Index Files:: Index files speed up GDB
20551 * Symbol Errors:: Errors reading symbol files
20552 * Data Files:: GDB data files
20556 @section Commands to Specify Files
20558 @cindex symbol table
20559 @cindex core dump file
20561 You may want to specify executable and core dump file names. The usual
20562 way to do this is at start-up time, using the arguments to
20563 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20564 Out of @value{GDBN}}).
20566 Occasionally it is necessary to change to a different file during a
20567 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20568 specify a file you want to use. Or you are debugging a remote target
20569 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20570 Program}). In these situations the @value{GDBN} commands to specify
20571 new files are useful.
20574 @cindex executable file
20576 @item file @var{filename}
20577 Use @var{filename} as the program to be debugged. It is read for its
20578 symbols and for the contents of pure memory. It is also the program
20579 executed when you use the @code{run} command. If you do not specify a
20580 directory and the file is not found in the @value{GDBN} working directory,
20581 @value{GDBN} uses the environment variable @code{PATH} as a list of
20582 directories to search, just as the shell does when looking for a program
20583 to run. You can change the value of this variable, for both @value{GDBN}
20584 and your program, using the @code{path} command.
20586 @cindex unlinked object files
20587 @cindex patching object files
20588 You can load unlinked object @file{.o} files into @value{GDBN} using
20589 the @code{file} command. You will not be able to ``run'' an object
20590 file, but you can disassemble functions and inspect variables. Also,
20591 if the underlying BFD functionality supports it, you could use
20592 @kbd{gdb -write} to patch object files using this technique. Note
20593 that @value{GDBN} can neither interpret nor modify relocations in this
20594 case, so branches and some initialized variables will appear to go to
20595 the wrong place. But this feature is still handy from time to time.
20598 @code{file} with no argument makes @value{GDBN} discard any information it
20599 has on both executable file and the symbol table.
20602 @item exec-file @r{[} @var{filename} @r{]}
20603 Specify that the program to be run (but not the symbol table) is found
20604 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20605 if necessary to locate your program. Omitting @var{filename} means to
20606 discard information on the executable file.
20608 @kindex symbol-file
20609 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20610 Read symbol table information from file @var{filename}. @code{PATH} is
20611 searched when necessary. Use the @code{file} command to get both symbol
20612 table and program to run from the same file.
20614 If an optional @var{offset} is specified, it is added to the start
20615 address of each section in the symbol file. This is useful if the
20616 program is relocated at runtime, such as the Linux kernel with kASLR
20619 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20620 program's symbol table.
20622 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20623 some breakpoints and auto-display expressions. This is because they may
20624 contain pointers to the internal data recording symbols and data types,
20625 which are part of the old symbol table data being discarded inside
20628 @code{symbol-file} does not repeat if you press @key{RET} again after
20631 When @value{GDBN} is configured for a particular environment, it
20632 understands debugging information in whatever format is the standard
20633 generated for that environment; you may use either a @sc{gnu} compiler, or
20634 other compilers that adhere to the local conventions.
20635 Best results are usually obtained from @sc{gnu} compilers; for example,
20636 using @code{@value{NGCC}} you can generate debugging information for
20639 For most kinds of object files, with the exception of old SVR3 systems
20640 using COFF, the @code{symbol-file} command does not normally read the
20641 symbol table in full right away. Instead, it scans the symbol table
20642 quickly to find which source files and which symbols are present. The
20643 details are read later, one source file at a time, as they are needed.
20645 The purpose of this two-stage reading strategy is to make @value{GDBN}
20646 start up faster. For the most part, it is invisible except for
20647 occasional pauses while the symbol table details for a particular source
20648 file are being read. (The @code{set verbose} command can turn these
20649 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20650 Warnings and Messages}.)
20652 We have not implemented the two-stage strategy for COFF yet. When the
20653 symbol table is stored in COFF format, @code{symbol-file} reads the
20654 symbol table data in full right away. Note that ``stabs-in-COFF''
20655 still does the two-stage strategy, since the debug info is actually
20659 @cindex reading symbols immediately
20660 @cindex symbols, reading immediately
20661 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20662 @itemx file @r{[} -readnow @r{]} @var{filename}
20663 You can override the @value{GDBN} two-stage strategy for reading symbol
20664 tables by using the @samp{-readnow} option with any of the commands that
20665 load symbol table information, if you want to be sure @value{GDBN} has the
20666 entire symbol table available.
20668 @cindex @code{-readnever}, option for symbol-file command
20669 @cindex never read symbols
20670 @cindex symbols, never read
20671 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20672 @itemx file @r{[} -readnever @r{]} @var{filename}
20673 You can instruct @value{GDBN} to never read the symbolic information
20674 contained in @var{filename} by using the @samp{-readnever} option.
20675 @xref{--readnever}.
20677 @c FIXME: for now no mention of directories, since this seems to be in
20678 @c flux. 13mar1992 status is that in theory GDB would look either in
20679 @c current dir or in same dir as myprog; but issues like competing
20680 @c GDB's, or clutter in system dirs, mean that in practice right now
20681 @c only current dir is used. FFish says maybe a special GDB hierarchy
20682 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20686 @item core-file @r{[}@var{filename}@r{]}
20688 Specify the whereabouts of a core dump file to be used as the ``contents
20689 of memory''. Traditionally, core files contain only some parts of the
20690 address space of the process that generated them; @value{GDBN} can access the
20691 executable file itself for other parts.
20693 @code{core-file} with no argument specifies that no core file is
20696 Note that the core file is ignored when your program is actually running
20697 under @value{GDBN}. So, if you have been running your program and you
20698 wish to debug a core file instead, you must kill the subprocess in which
20699 the program is running. To do this, use the @code{kill} command
20700 (@pxref{Kill Process, ,Killing the Child Process}).
20702 @kindex add-symbol-file
20703 @cindex dynamic linking
20704 @item add-symbol-file @var{filename} @r{[} -readnow @r{|} -readnever @r{]} @r{[} -o @var{offset} @r{]} @r{[} @var{textaddress} @r{]} @r{[} -s @var{section} @var{address} @dots{} @r{]}
20705 The @code{add-symbol-file} command reads additional symbol table
20706 information from the file @var{filename}. You would use this command
20707 when @var{filename} has been dynamically loaded (by some other means)
20708 into the program that is running. The @var{textaddress} parameter gives
20709 the memory address at which the file's text section has been loaded.
20710 You can additionally specify the base address of other sections using
20711 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20712 If a section is omitted, @value{GDBN} will use its default addresses
20713 as found in @var{filename}. Any @var{address} or @var{textaddress}
20714 can be given as an expression.
20716 If an optional @var{offset} is specified, it is added to the start
20717 address of each section, except those for which the address was
20718 specified explicitly.
20720 The symbol table of the file @var{filename} is added to the symbol table
20721 originally read with the @code{symbol-file} command. You can use the
20722 @code{add-symbol-file} command any number of times; the new symbol data
20723 thus read is kept in addition to the old.
20725 Changes can be reverted using the command @code{remove-symbol-file}.
20727 @cindex relocatable object files, reading symbols from
20728 @cindex object files, relocatable, reading symbols from
20729 @cindex reading symbols from relocatable object files
20730 @cindex symbols, reading from relocatable object files
20731 @cindex @file{.o} files, reading symbols from
20732 Although @var{filename} is typically a shared library file, an
20733 executable file, or some other object file which has been fully
20734 relocated for loading into a process, you can also load symbolic
20735 information from relocatable @file{.o} files, as long as:
20739 the file's symbolic information refers only to linker symbols defined in
20740 that file, not to symbols defined by other object files,
20742 every section the file's symbolic information refers to has actually
20743 been loaded into the inferior, as it appears in the file, and
20745 you can determine the address at which every section was loaded, and
20746 provide these to the @code{add-symbol-file} command.
20750 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20751 relocatable files into an already running program; such systems
20752 typically make the requirements above easy to meet. However, it's
20753 important to recognize that many native systems use complex link
20754 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20755 assembly, for example) that make the requirements difficult to meet. In
20756 general, one cannot assume that using @code{add-symbol-file} to read a
20757 relocatable object file's symbolic information will have the same effect
20758 as linking the relocatable object file into the program in the normal
20761 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20763 @kindex remove-symbol-file
20764 @item remove-symbol-file @var{filename}
20765 @item remove-symbol-file -a @var{address}
20766 Remove a symbol file added via the @code{add-symbol-file} command. The
20767 file to remove can be identified by its @var{filename} or by an @var{address}
20768 that lies within the boundaries of this symbol file in memory. Example:
20771 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20772 add symbol table from file "/home/user/gdb/mylib.so" at
20773 .text_addr = 0x7ffff7ff9480
20775 Reading symbols from /home/user/gdb/mylib.so...
20776 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20777 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20782 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20784 @kindex add-symbol-file-from-memory
20785 @cindex @code{syscall DSO}
20786 @cindex load symbols from memory
20787 @item add-symbol-file-from-memory @var{address}
20788 Load symbols from the given @var{address} in a dynamically loaded
20789 object file whose image is mapped directly into the inferior's memory.
20790 For example, the Linux kernel maps a @code{syscall DSO} into each
20791 process's address space; this DSO provides kernel-specific code for
20792 some system calls. The argument can be any expression whose
20793 evaluation yields the address of the file's shared object file header.
20794 For this command to work, you must have used @code{symbol-file} or
20795 @code{exec-file} commands in advance.
20798 @item section @var{section} @var{addr}
20799 The @code{section} command changes the base address of the named
20800 @var{section} of the exec file to @var{addr}. This can be used if the
20801 exec file does not contain section addresses, (such as in the
20802 @code{a.out} format), or when the addresses specified in the file
20803 itself are wrong. Each section must be changed separately. The
20804 @code{info files} command, described below, lists all the sections and
20808 @kindex info target
20811 @code{info files} and @code{info target} are synonymous; both print the
20812 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20813 including the names of the executable and core dump files currently in
20814 use by @value{GDBN}, and the files from which symbols were loaded. The
20815 command @code{help target} lists all possible targets rather than
20818 @kindex maint info sections
20819 @item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
20820 Another command that can give you extra information about program sections
20821 is @code{maint info sections}. In addition to the section information
20822 displayed by @code{info files}, this command displays the flags and file
20823 offset of each section in the executable and core dump files.
20825 When @samp{-all-objects} is passed then sections from all loaded object
20826 files, including shared libraries, are printed.
20828 The optional @var{filter-list} is a space separated list of filter
20829 keywords. Sections that match any one of the filter criteria will be
20830 printed. There are two types of filter:
20833 @item @var{section-name}
20834 Display information about any section named @var{section-name}.
20835 @item @var{section-flag}
20836 Display information for any section with @var{section-flag}. The
20837 section flags that @value{GDBN} currently knows about are:
20840 Section will have space allocated in the process when loaded.
20841 Set for all sections except those containing debug information.
20843 Section will be loaded from the file into the child process memory.
20844 Set for pre-initialized code and data, clear for @code{.bss} sections.
20846 Section needs to be relocated before loading.
20848 Section cannot be modified by the child process.
20850 Section contains executable code only.
20852 Section contains data only (no executable code).
20854 Section will reside in ROM.
20856 Section contains data for constructor/destructor lists.
20858 Section is not empty.
20860 An instruction to the linker to not output the section.
20861 @item COFF_SHARED_LIBRARY
20862 A notification to the linker that the section contains
20863 COFF shared library information.
20865 Section contains common symbols.
20869 @kindex maint info target-sections
20870 @item maint info target-sections
20871 This command prints @value{GDBN}'s internal section table. For each
20872 target @value{GDBN} maintains a table containing the allocatable
20873 sections from all currently mapped objects, along with information
20874 about where the section is mapped.
20876 @kindex set trust-readonly-sections
20877 @cindex read-only sections
20878 @item set trust-readonly-sections on
20879 Tell @value{GDBN} that readonly sections in your object file
20880 really are read-only (i.e.@: that their contents will not change).
20881 In that case, @value{GDBN} can fetch values from these sections
20882 out of the object file, rather than from the target program.
20883 For some targets (notably embedded ones), this can be a significant
20884 enhancement to debugging performance.
20886 The default is off.
20888 @item set trust-readonly-sections off
20889 Tell @value{GDBN} not to trust readonly sections. This means that
20890 the contents of the section might change while the program is running,
20891 and must therefore be fetched from the target when needed.
20893 @item show trust-readonly-sections
20894 Show the current setting of trusting readonly sections.
20897 All file-specifying commands allow both absolute and relative file names
20898 as arguments. @value{GDBN} always converts the file name to an absolute file
20899 name and remembers it that way.
20901 @cindex shared libraries
20902 @anchor{Shared Libraries}
20903 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20904 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20905 DSBT (TIC6X) shared libraries.
20907 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20908 shared libraries. @xref{Expat}.
20910 @value{GDBN} automatically loads symbol definitions from shared libraries
20911 when you use the @code{run} command, or when you examine a core file.
20912 (Before you issue the @code{run} command, @value{GDBN} does not understand
20913 references to a function in a shared library, however---unless you are
20914 debugging a core file).
20916 @c FIXME: some @value{GDBN} release may permit some refs to undef
20917 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20918 @c FIXME...lib; check this from time to time when updating manual
20920 There are times, however, when you may wish to not automatically load
20921 symbol definitions from shared libraries, such as when they are
20922 particularly large or there are many of them.
20924 To control the automatic loading of shared library symbols, use the
20928 @kindex set auto-solib-add
20929 @item set auto-solib-add @var{mode}
20930 If @var{mode} is @code{on}, symbols from all shared object libraries
20931 will be loaded automatically when the inferior begins execution, you
20932 attach to an independently started inferior, or when the dynamic linker
20933 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20934 is @code{off}, symbols must be loaded manually, using the
20935 @code{sharedlibrary} command. The default value is @code{on}.
20937 @cindex memory used for symbol tables
20938 If your program uses lots of shared libraries with debug info that
20939 takes large amounts of memory, you can decrease the @value{GDBN}
20940 memory footprint by preventing it from automatically loading the
20941 symbols from shared libraries. To that end, type @kbd{set
20942 auto-solib-add off} before running the inferior, then load each
20943 library whose debug symbols you do need with @kbd{sharedlibrary
20944 @var{regexp}}, where @var{regexp} is a regular expression that matches
20945 the libraries whose symbols you want to be loaded.
20947 @kindex show auto-solib-add
20948 @item show auto-solib-add
20949 Display the current autoloading mode.
20952 @cindex load shared library
20953 To explicitly load shared library symbols, use the @code{sharedlibrary}
20957 @kindex info sharedlibrary
20959 @item info share @var{regex}
20960 @itemx info sharedlibrary @var{regex}
20961 Print the names of the shared libraries which are currently loaded
20962 that match @var{regex}. If @var{regex} is omitted then print
20963 all shared libraries that are loaded.
20966 @item info dll @var{regex}
20967 This is an alias of @code{info sharedlibrary}.
20969 @kindex sharedlibrary
20971 @item sharedlibrary @var{regex}
20972 @itemx share @var{regex}
20973 Load shared object library symbols for files matching a
20974 Unix regular expression.
20975 As with files loaded automatically, it only loads shared libraries
20976 required by your program for a core file or after typing @code{run}. If
20977 @var{regex} is omitted all shared libraries required by your program are
20980 @item nosharedlibrary
20981 @kindex nosharedlibrary
20982 @cindex unload symbols from shared libraries
20983 Unload all shared object library symbols. This discards all symbols
20984 that have been loaded from all shared libraries. Symbols from shared
20985 libraries that were loaded by explicit user requests are not
20989 Sometimes you may wish that @value{GDBN} stops and gives you control
20990 when any of shared library events happen. The best way to do this is
20991 to use @code{catch load} and @code{catch unload} (@pxref{Set
20994 @value{GDBN} also supports the @code{set stop-on-solib-events}
20995 command for this. This command exists for historical reasons. It is
20996 less useful than setting a catchpoint, because it does not allow for
20997 conditions or commands as a catchpoint does.
21000 @item set stop-on-solib-events
21001 @kindex set stop-on-solib-events
21002 This command controls whether @value{GDBN} should give you control
21003 when the dynamic linker notifies it about some shared library event.
21004 The most common event of interest is loading or unloading of a new
21007 @item show stop-on-solib-events
21008 @kindex show stop-on-solib-events
21009 Show whether @value{GDBN} stops and gives you control when shared
21010 library events happen.
21013 Shared libraries are also supported in many cross or remote debugging
21014 configurations. @value{GDBN} needs to have access to the target's libraries;
21015 this can be accomplished either by providing copies of the libraries
21016 on the host system, or by asking @value{GDBN} to automatically retrieve the
21017 libraries from the target. If copies of the target libraries are
21018 provided, they need to be the same as the target libraries, although the
21019 copies on the target can be stripped as long as the copies on the host are
21022 @cindex where to look for shared libraries
21023 For remote debugging, you need to tell @value{GDBN} where the target
21024 libraries are, so that it can load the correct copies---otherwise, it
21025 may try to load the host's libraries. @value{GDBN} has two variables
21026 to specify the search directories for target libraries.
21029 @cindex prefix for executable and shared library file names
21030 @cindex system root, alternate
21031 @kindex set solib-absolute-prefix
21032 @kindex set sysroot
21033 @item set sysroot @var{path}
21034 Use @var{path} as the system root for the program being debugged. Any
21035 absolute shared library paths will be prefixed with @var{path}; many
21036 runtime loaders store the absolute paths to the shared library in the
21037 target program's memory. When starting processes remotely, and when
21038 attaching to already-running processes (local or remote), their
21039 executable filenames will be prefixed with @var{path} if reported to
21040 @value{GDBN} as absolute by the operating system. If you use
21041 @code{set sysroot} to find executables and shared libraries, they need
21042 to be laid out in the same way that they are on the target, with
21043 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
21046 If @var{path} starts with the sequence @file{target:} and the target
21047 system is remote then @value{GDBN} will retrieve the target binaries
21048 from the remote system. This is only supported when using a remote
21049 target that supports the @code{remote get} command (@pxref{File
21050 Transfer,,Sending files to a remote system}). The part of @var{path}
21051 following the initial @file{target:} (if present) is used as system
21052 root prefix on the remote file system. If @var{path} starts with the
21053 sequence @file{remote:} this is converted to the sequence
21054 @file{target:} by @code{set sysroot}@footnote{Historically the
21055 functionality to retrieve binaries from the remote system was
21056 provided by prefixing @var{path} with @file{remote:}}. If you want
21057 to specify a local system root using a directory that happens to be
21058 named @file{target:} or @file{remote:}, you need to use some
21059 equivalent variant of the name like @file{./target:}.
21061 For targets with an MS-DOS based filesystem, such as MS-Windows,
21062 @value{GDBN} tries prefixing a few variants of the target
21063 absolute file name with @var{path}. But first, on Unix hosts,
21064 @value{GDBN} converts all backslash directory separators into forward
21065 slashes, because the backslash is not a directory separator on Unix:
21068 c:\foo\bar.dll @result{} c:/foo/bar.dll
21071 Then, @value{GDBN} attempts prefixing the target file name with
21072 @var{path}, and looks for the resulting file name in the host file
21076 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
21079 If that does not find the binary, @value{GDBN} tries removing
21080 the @samp{:} character from the drive spec, both for convenience, and,
21081 for the case of the host file system not supporting file names with
21085 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
21088 This makes it possible to have a system root that mirrors a target
21089 with more than one drive. E.g., you may want to setup your local
21090 copies of the target system shared libraries like so (note @samp{c} vs
21094 @file{/path/to/sysroot/c/sys/bin/foo.dll}
21095 @file{/path/to/sysroot/c/sys/bin/bar.dll}
21096 @file{/path/to/sysroot/z/sys/bin/bar.dll}
21100 and point the system root at @file{/path/to/sysroot}, so that
21101 @value{GDBN} can find the correct copies of both
21102 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
21104 If that still does not find the binary, @value{GDBN} tries
21105 removing the whole drive spec from the target file name:
21108 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
21111 This last lookup makes it possible to not care about the drive name,
21112 if you don't want or need to.
21114 The @code{set solib-absolute-prefix} command is an alias for @code{set
21117 @cindex default system root
21118 @cindex @samp{--with-sysroot}
21119 You can set the default system root by using the configure-time
21120 @samp{--with-sysroot} option. If the system root is inside
21121 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21122 @samp{--exec-prefix}), then the default system root will be updated
21123 automatically if the installed @value{GDBN} is moved to a new
21126 @kindex show sysroot
21128 Display the current executable and shared library prefix.
21130 @kindex set solib-search-path
21131 @item set solib-search-path @var{path}
21132 If this variable is set, @var{path} is a colon-separated list of
21133 directories to search for shared libraries. @samp{solib-search-path}
21134 is used after @samp{sysroot} fails to locate the library, or if the
21135 path to the library is relative instead of absolute. If you want to
21136 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
21137 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
21138 finding your host's libraries. @samp{sysroot} is preferred; setting
21139 it to a nonexistent directory may interfere with automatic loading
21140 of shared library symbols.
21142 @kindex show solib-search-path
21143 @item show solib-search-path
21144 Display the current shared library search path.
21146 @cindex DOS file-name semantics of file names.
21147 @kindex set target-file-system-kind (unix|dos-based|auto)
21148 @kindex show target-file-system-kind
21149 @item set target-file-system-kind @var{kind}
21150 Set assumed file system kind for target reported file names.
21152 Shared library file names as reported by the target system may not
21153 make sense as is on the system @value{GDBN} is running on. For
21154 example, when remote debugging a target that has MS-DOS based file
21155 system semantics, from a Unix host, the target may be reporting to
21156 @value{GDBN} a list of loaded shared libraries with file names such as
21157 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21158 drive letters, so the @samp{c:\} prefix is not normally understood as
21159 indicating an absolute file name, and neither is the backslash
21160 normally considered a directory separator character. In that case,
21161 the native file system would interpret this whole absolute file name
21162 as a relative file name with no directory components. This would make
21163 it impossible to point @value{GDBN} at a copy of the remote target's
21164 shared libraries on the host using @code{set sysroot}, and impractical
21165 with @code{set solib-search-path}. Setting
21166 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21167 to interpret such file names similarly to how the target would, and to
21168 map them to file names valid on @value{GDBN}'s native file system
21169 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21170 to one of the supported file system kinds. In that case, @value{GDBN}
21171 tries to determine the appropriate file system variant based on the
21172 current target's operating system (@pxref{ABI, ,Configuring the
21173 Current ABI}). The supported file system settings are:
21177 Instruct @value{GDBN} to assume the target file system is of Unix
21178 kind. Only file names starting the forward slash (@samp{/}) character
21179 are considered absolute, and the directory separator character is also
21183 Instruct @value{GDBN} to assume the target file system is DOS based.
21184 File names starting with either a forward slash, or a drive letter
21185 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21186 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21187 considered directory separators.
21190 Instruct @value{GDBN} to use the file system kind associated with the
21191 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21192 This is the default.
21196 @cindex file name canonicalization
21197 @cindex base name differences
21198 When processing file names provided by the user, @value{GDBN}
21199 frequently needs to compare them to the file names recorded in the
21200 program's debug info. Normally, @value{GDBN} compares just the
21201 @dfn{base names} of the files as strings, which is reasonably fast
21202 even for very large programs. (The base name of a file is the last
21203 portion of its name, after stripping all the leading directories.)
21204 This shortcut in comparison is based upon the assumption that files
21205 cannot have more than one base name. This is usually true, but
21206 references to files that use symlinks or similar filesystem
21207 facilities violate that assumption. If your program records files
21208 using such facilities, or if you provide file names to @value{GDBN}
21209 using symlinks etc., you can set @code{basenames-may-differ} to
21210 @code{true} to instruct @value{GDBN} to completely canonicalize each
21211 pair of file names it needs to compare. This will make file-name
21212 comparisons accurate, but at a price of a significant slowdown.
21215 @item set basenames-may-differ
21216 @kindex set basenames-may-differ
21217 Set whether a source file may have multiple base names.
21219 @item show basenames-may-differ
21220 @kindex show basenames-may-differ
21221 Show whether a source file may have multiple base names.
21225 @section File Caching
21226 @cindex caching of opened files
21227 @cindex caching of bfd objects
21229 To speed up file loading, and reduce memory usage, @value{GDBN} will
21230 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21231 BFD, bfd, The Binary File Descriptor Library}. The following commands
21232 allow visibility and control of the caching behavior.
21235 @kindex maint info bfds
21236 @item maint info bfds
21237 This prints information about each @code{bfd} object that is known to
21240 @kindex maint set bfd-sharing
21241 @kindex maint show bfd-sharing
21242 @kindex bfd caching
21243 @item maint set bfd-sharing
21244 @item maint show bfd-sharing
21245 Control whether @code{bfd} objects can be shared. When sharing is
21246 enabled @value{GDBN} reuses already open @code{bfd} objects rather
21247 than reopening the same file. Turning sharing off does not cause
21248 already shared @code{bfd} objects to be unshared, but all future files
21249 that are opened will create a new @code{bfd} object. Similarly,
21250 re-enabling sharing does not cause multiple existing @code{bfd}
21251 objects to be collapsed into a single shared @code{bfd} object.
21253 @kindex set debug bfd-cache @var{level}
21254 @kindex bfd caching
21255 @item set debug bfd-cache @var{level}
21256 Turns on debugging of the bfd cache, setting the level to @var{level}.
21258 @kindex show debug bfd-cache
21259 @kindex bfd caching
21260 @item show debug bfd-cache
21261 Show the current debugging level of the bfd cache.
21264 @node Separate Debug Files
21265 @section Debugging Information in Separate Files
21266 @cindex separate debugging information files
21267 @cindex debugging information in separate files
21268 @cindex @file{.debug} subdirectories
21269 @cindex debugging information directory, global
21270 @cindex global debugging information directories
21271 @cindex build ID, and separate debugging files
21272 @cindex @file{.build-id} directory
21274 @value{GDBN} allows you to put a program's debugging information in a
21275 file separate from the executable itself, in a way that allows
21276 @value{GDBN} to find and load the debugging information automatically.
21277 Since debugging information can be very large---sometimes larger
21278 than the executable code itself---some systems distribute debugging
21279 information for their executables in separate files, which users can
21280 install only when they need to debug a problem.
21282 @value{GDBN} supports two ways of specifying the separate debug info
21287 The executable contains a @dfn{debug link} that specifies the name of
21288 the separate debug info file. The separate debug file's name is
21289 usually @file{@var{executable}.debug}, where @var{executable} is the
21290 name of the corresponding executable file without leading directories
21291 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
21292 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21293 checksum for the debug file, which @value{GDBN} uses to validate that
21294 the executable and the debug file came from the same build.
21298 The executable contains a @dfn{build ID}, a unique bit string that is
21299 also present in the corresponding debug info file. (This is supported
21300 only on some operating systems, when using the ELF or PE file formats
21301 for binary files and the @sc{gnu} Binutils.) For more details about
21302 this feature, see the description of the @option{--build-id}
21303 command-line option in @ref{Options, , Command Line Options, ld,
21304 The GNU Linker}. The debug info file's name is not specified
21305 explicitly by the build ID, but can be computed from the build ID, see
21309 Depending on the way the debug info file is specified, @value{GDBN}
21310 uses two different methods of looking for the debug file:
21314 For the ``debug link'' method, @value{GDBN} looks up the named file in
21315 the directory of the executable file, then in a subdirectory of that
21316 directory named @file{.debug}, and finally under each one of the
21317 global debug directories, in a subdirectory whose name is identical to
21318 the leading directories of the executable's absolute file name. (On
21319 MS-Windows/MS-DOS, the drive letter of the executable's leading
21320 directories is converted to a one-letter subdirectory, i.e.@:
21321 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21322 filesystems disallow colons in file names.)
21325 For the ``build ID'' method, @value{GDBN} looks in the
21326 @file{.build-id} subdirectory of each one of the global debug directories for
21327 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21328 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21329 are the rest of the bit string. (Real build ID strings are 32 or more
21330 hex characters, not 10.)
21333 So, for example, suppose you ask @value{GDBN} to debug
21334 @file{/usr/bin/ls}, which has a debug link that specifies the
21335 file @file{ls.debug}, and a build ID whose value in hex is
21336 @code{abcdef1234}. If the list of the global debug directories includes
21337 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21338 debug information files, in the indicated order:
21342 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21344 @file{/usr/bin/ls.debug}
21346 @file{/usr/bin/.debug/ls.debug}
21348 @file{/usr/lib/debug/usr/bin/ls.debug}.
21351 @anchor{debug-file-directory}
21352 Global debugging info directories default to what is set by @value{GDBN}
21353 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21354 you can also set the global debugging info directories, and view the list
21355 @value{GDBN} is currently using.
21359 @kindex set debug-file-directory
21360 @item set debug-file-directory @var{directories}
21361 Set the directories which @value{GDBN} searches for separate debugging
21362 information files to @var{directory}. Multiple path components can be set
21363 concatenating them by a path separator.
21365 @kindex show debug-file-directory
21366 @item show debug-file-directory
21367 Show the directories @value{GDBN} searches for separate debugging
21372 @cindex @code{.gnu_debuglink} sections
21373 @cindex debug link sections
21374 A debug link is a special section of the executable file named
21375 @code{.gnu_debuglink}. The section must contain:
21379 A filename, with any leading directory components removed, followed by
21382 zero to three bytes of padding, as needed to reach the next four-byte
21383 boundary within the section, and
21385 a four-byte CRC checksum, stored in the same endianness used for the
21386 executable file itself. The checksum is computed on the debugging
21387 information file's full contents by the function given below, passing
21388 zero as the @var{crc} argument.
21391 Any executable file format can carry a debug link, as long as it can
21392 contain a section named @code{.gnu_debuglink} with the contents
21395 @cindex @code{.note.gnu.build-id} sections
21396 @cindex build ID sections
21397 The build ID is a special section in the executable file (and in other
21398 ELF binary files that @value{GDBN} may consider). This section is
21399 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21400 It contains unique identification for the built files---the ID remains
21401 the same across multiple builds of the same build tree. The default
21402 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21403 content for the build ID string. The same section with an identical
21404 value is present in the original built binary with symbols, in its
21405 stripped variant, and in the separate debugging information file.
21407 The debugging information file itself should be an ordinary
21408 executable, containing a full set of linker symbols, sections, and
21409 debugging information. The sections of the debugging information file
21410 should have the same names, addresses, and sizes as the original file,
21411 but they need not contain any data---much like a @code{.bss} section
21412 in an ordinary executable.
21414 The @sc{gnu} binary utilities (Binutils) package includes the
21415 @samp{objcopy} utility that can produce
21416 the separated executable / debugging information file pairs using the
21417 following commands:
21420 @kbd{objcopy --only-keep-debug foo foo.debug}
21425 These commands remove the debugging
21426 information from the executable file @file{foo} and place it in the file
21427 @file{foo.debug}. You can use the first, second or both methods to link the
21432 The debug link method needs the following additional command to also leave
21433 behind a debug link in @file{foo}:
21436 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21439 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21440 a version of the @code{strip} command such that the command @kbd{strip foo -f
21441 foo.debug} has the same functionality as the two @code{objcopy} commands and
21442 the @code{ln -s} command above, together.
21445 Build ID gets embedded into the main executable using @code{ld --build-id} or
21446 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21447 compatibility fixes for debug files separation are present in @sc{gnu} binary
21448 utilities (Binutils) package since version 2.18.
21453 @cindex CRC algorithm definition
21454 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21455 IEEE 802.3 using the polynomial:
21457 @c TexInfo requires naked braces for multi-digit exponents for Tex
21458 @c output, but this causes HTML output to barf. HTML has to be set using
21459 @c raw commands. So we end up having to specify this equation in 2
21464 <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>
21465 + <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
21471 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21472 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21476 The function is computed byte at a time, taking the least
21477 significant bit of each byte first. The initial pattern
21478 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21479 the final result is inverted to ensure trailing zeros also affect the
21482 @emph{Note:} This is the same CRC polynomial as used in handling the
21483 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21484 However in the case of the Remote Serial Protocol, the CRC is computed
21485 @emph{most} significant bit first, and the result is not inverted, so
21486 trailing zeros have no effect on the CRC value.
21488 To complete the description, we show below the code of the function
21489 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21490 initially supplied @code{crc} argument means that an initial call to
21491 this function passing in zero will start computing the CRC using
21494 @kindex gnu_debuglink_crc32
21497 gnu_debuglink_crc32 (unsigned long crc,
21498 unsigned char *buf, size_t len)
21500 static const unsigned long crc32_table[256] =
21502 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21503 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21504 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21505 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21506 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21507 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21508 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21509 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21510 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21511 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21512 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21513 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21514 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21515 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21516 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21517 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21518 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21519 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21520 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21521 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21522 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21523 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21524 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21525 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21526 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21527 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21528 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21529 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21530 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21531 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21532 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21533 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21534 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21535 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21536 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21537 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21538 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21539 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21540 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21541 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21542 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21543 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21544 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21545 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21546 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21547 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21548 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21549 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21550 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21551 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21552 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21555 unsigned char *end;
21557 crc = ~crc & 0xffffffff;
21558 for (end = buf + len; buf < end; ++buf)
21559 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21560 return ~crc & 0xffffffff;
21565 This computation does not apply to the ``build ID'' method.
21567 @node MiniDebugInfo
21568 @section Debugging information in a special section
21569 @cindex separate debug sections
21570 @cindex @samp{.gnu_debugdata} section
21572 Some systems ship pre-built executables and libraries that have a
21573 special @samp{.gnu_debugdata} section. This feature is called
21574 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21575 is used to supply extra symbols for backtraces.
21577 The intent of this section is to provide extra minimal debugging
21578 information for use in simple backtraces. It is not intended to be a
21579 replacement for full separate debugging information (@pxref{Separate
21580 Debug Files}). The example below shows the intended use; however,
21581 @value{GDBN} does not currently put restrictions on what sort of
21582 debugging information might be included in the section.
21584 @value{GDBN} has support for this extension. If the section exists,
21585 then it is used provided that no other source of debugging information
21586 can be found, and that @value{GDBN} was configured with LZMA support.
21588 This section can be easily created using @command{objcopy} and other
21589 standard utilities:
21592 # Extract the dynamic symbols from the main binary, there is no need
21593 # to also have these in the normal symbol table.
21594 nm -D @var{binary} --format=posix --defined-only \
21595 | awk '@{ print $1 @}' | sort > dynsyms
21597 # Extract all the text (i.e. function) symbols from the debuginfo.
21598 # (Note that we actually also accept "D" symbols, for the benefit
21599 # of platforms like PowerPC64 that use function descriptors.)
21600 nm @var{binary} --format=posix --defined-only \
21601 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21604 # Keep all the function symbols not already in the dynamic symbol
21606 comm -13 dynsyms funcsyms > keep_symbols
21608 # Separate full debug info into debug binary.
21609 objcopy --only-keep-debug @var{binary} debug
21611 # Copy the full debuginfo, keeping only a minimal set of symbols and
21612 # removing some unnecessary sections.
21613 objcopy -S --remove-section .gdb_index --remove-section .comment \
21614 --keep-symbols=keep_symbols debug mini_debuginfo
21616 # Drop the full debug info from the original binary.
21617 strip --strip-all -R .comment @var{binary}
21619 # Inject the compressed data into the .gnu_debugdata section of the
21622 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21626 @section Index Files Speed Up @value{GDBN}
21627 @cindex index files
21628 @cindex @samp{.gdb_index} section
21630 When @value{GDBN} finds a symbol file, it scans the symbols in the
21631 file in order to construct an internal symbol table. This lets most
21632 @value{GDBN} operations work quickly---at the cost of a delay early
21633 on. For large programs, this delay can be quite lengthy, so
21634 @value{GDBN} provides a way to build an index, which speeds up
21637 For convenience, @value{GDBN} comes with a program,
21638 @command{gdb-add-index}, which can be used to add the index to a
21639 symbol file. It takes the symbol file as its only argument:
21642 $ gdb-add-index symfile
21645 @xref{gdb-add-index}.
21647 It is also possible to do the work manually. Here is what
21648 @command{gdb-add-index} does behind the curtains.
21650 The index is stored as a section in the symbol file. @value{GDBN} can
21651 write the index to a file, then you can put it into the symbol file
21652 using @command{objcopy}.
21654 To create an index file, use the @code{save gdb-index} command:
21657 @item save gdb-index [-dwarf-5] @var{directory}
21658 @kindex save gdb-index
21659 Create index files for all symbol files currently known by
21660 @value{GDBN}. For each known @var{symbol-file}, this command by
21661 default creates it produces a single file
21662 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21663 the @option{-dwarf-5} option, it produces 2 files:
21664 @file{@var{symbol-file}.debug_names} and
21665 @file{@var{symbol-file}.debug_str}. The files are created in the
21666 given @var{directory}.
21669 Once you have created an index file you can merge it into your symbol
21670 file, here named @file{symfile}, using @command{objcopy}:
21673 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21674 --set-section-flags .gdb_index=readonly symfile symfile
21677 Or for @code{-dwarf-5}:
21680 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21681 $ cat symfile.debug_str >>symfile.debug_str.new
21682 $ objcopy --add-section .debug_names=symfile.gdb-index \
21683 --set-section-flags .debug_names=readonly \
21684 --update-section .debug_str=symfile.debug_str.new symfile symfile
21687 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21688 sections that have been deprecated. Usually they are deprecated because
21689 they are missing a new feature or have performance issues.
21690 To tell @value{GDBN} to use a deprecated index section anyway
21691 specify @code{set use-deprecated-index-sections on}.
21692 The default is @code{off}.
21693 This can speed up startup, but may result in some functionality being lost.
21694 @xref{Index Section Format}.
21696 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21697 must be done before gdb reads the file. The following will not work:
21700 $ gdb -ex "set use-deprecated-index-sections on" <program>
21703 Instead you must do, for example,
21706 $ gdb -iex "set use-deprecated-index-sections on" <program>
21709 Indices only work when using DWARF debugging information, not stabs.
21711 @subsection Automatic symbol index cache
21713 @cindex automatic symbol index cache
21714 It is possible for @value{GDBN} to automatically save a copy of this index in a
21715 cache on disk and retrieve it from there when loading the same binary in the
21716 future. This feature can be turned on with @kbd{set index-cache on}. The
21717 following commands can be used to tweak the behavior of the index cache.
21721 @kindex set index-cache
21722 @item set index-cache on
21723 @itemx set index-cache off
21724 Enable or disable the use of the symbol index cache.
21726 @item set index-cache directory @var{directory}
21727 @kindex show index-cache
21728 @itemx show index-cache directory
21729 Set/show the directory where index files will be saved.
21731 The default value for this directory depends on the host platform. On
21732 most systems, the index is cached in the @file{gdb} subdirectory of
21733 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21734 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21735 of your home directory. However, on some systems, the default may
21736 differ according to local convention.
21738 There is no limit on the disk space used by index cache. It is perfectly safe
21739 to delete the content of that directory to free up disk space.
21741 @item show index-cache stats
21742 Print the number of cache hits and misses since the launch of @value{GDBN}.
21746 @node Symbol Errors
21747 @section Errors Reading Symbol Files
21749 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21750 such as symbol types it does not recognize, or known bugs in compiler
21751 output. By default, @value{GDBN} does not notify you of such problems, since
21752 they are relatively common and primarily of interest to people
21753 debugging compilers. If you are interested in seeing information
21754 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21755 only one message about each such type of problem, no matter how many
21756 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21757 to see how many times the problems occur, with the @code{set
21758 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21761 The messages currently printed, and their meanings, include:
21764 @item inner block not inside outer block in @var{symbol}
21766 The symbol information shows where symbol scopes begin and end
21767 (such as at the start of a function or a block of statements). This
21768 error indicates that an inner scope block is not fully contained
21769 in its outer scope blocks.
21771 @value{GDBN} circumvents the problem by treating the inner block as if it had
21772 the same scope as the outer block. In the error message, @var{symbol}
21773 may be shown as ``@code{(don't know)}'' if the outer block is not a
21776 @item block at @var{address} out of order
21778 The symbol information for symbol scope blocks should occur in
21779 order of increasing addresses. This error indicates that it does not
21782 @value{GDBN} does not circumvent this problem, and has trouble
21783 locating symbols in the source file whose symbols it is reading. (You
21784 can often determine what source file is affected by specifying
21785 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21788 @item bad block start address patched
21790 The symbol information for a symbol scope block has a start address
21791 smaller than the address of the preceding source line. This is known
21792 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21794 @value{GDBN} circumvents the problem by treating the symbol scope block as
21795 starting on the previous source line.
21797 @item bad string table offset in symbol @var{n}
21800 Symbol number @var{n} contains a pointer into the string table which is
21801 larger than the size of the string table.
21803 @value{GDBN} circumvents the problem by considering the symbol to have the
21804 name @code{foo}, which may cause other problems if many symbols end up
21807 @item unknown symbol type @code{0x@var{nn}}
21809 The symbol information contains new data types that @value{GDBN} does
21810 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21811 uncomprehended information, in hexadecimal.
21813 @value{GDBN} circumvents the error by ignoring this symbol information.
21814 This usually allows you to debug your program, though certain symbols
21815 are not accessible. If you encounter such a problem and feel like
21816 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21817 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21818 and examine @code{*bufp} to see the symbol.
21820 @item stub type has NULL name
21822 @value{GDBN} could not find the full definition for a struct or class.
21824 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21825 The symbol information for a C@t{++} member function is missing some
21826 information that recent versions of the compiler should have output for
21829 @item info mismatch between compiler and debugger
21831 @value{GDBN} could not parse a type specification output by the compiler.
21836 @section GDB Data Files
21838 @cindex prefix for data files
21839 @value{GDBN} will sometimes read an auxiliary data file. These files
21840 are kept in a directory known as the @dfn{data directory}.
21842 You can set the data directory's name, and view the name @value{GDBN}
21843 is currently using.
21846 @kindex set data-directory
21847 @item set data-directory @var{directory}
21848 Set the directory which @value{GDBN} searches for auxiliary data files
21849 to @var{directory}.
21851 @kindex show data-directory
21852 @item show data-directory
21853 Show the directory @value{GDBN} searches for auxiliary data files.
21856 @cindex default data directory
21857 @cindex @samp{--with-gdb-datadir}
21858 You can set the default data directory by using the configure-time
21859 @samp{--with-gdb-datadir} option. If the data directory is inside
21860 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21861 @samp{--exec-prefix}), then the default data directory will be updated
21862 automatically if the installed @value{GDBN} is moved to a new
21865 The data directory may also be specified with the
21866 @code{--data-directory} command line option.
21867 @xref{Mode Options}.
21870 @chapter Specifying a Debugging Target
21872 @cindex debugging target
21873 A @dfn{target} is the execution environment occupied by your program.
21875 Often, @value{GDBN} runs in the same host environment as your program;
21876 in that case, the debugging target is specified as a side effect when
21877 you use the @code{file} or @code{core} commands. When you need more
21878 flexibility---for example, running @value{GDBN} on a physically separate
21879 host, or controlling a standalone system over a serial port or a
21880 realtime system over a TCP/IP connection---you can use the @code{target}
21881 command to specify one of the target types configured for @value{GDBN}
21882 (@pxref{Target Commands, ,Commands for Managing Targets}).
21884 @cindex target architecture
21885 It is possible to build @value{GDBN} for several different @dfn{target
21886 architectures}. When @value{GDBN} is built like that, you can choose
21887 one of the available architectures with the @kbd{set architecture}
21891 @kindex set architecture
21892 @kindex show architecture
21893 @item set architecture @var{arch}
21894 This command sets the current target architecture to @var{arch}. The
21895 value of @var{arch} can be @code{"auto"}, in addition to one of the
21896 supported architectures.
21898 @item show architecture
21899 Show the current target architecture.
21901 @item set processor
21903 @kindex set processor
21904 @kindex show processor
21905 These are alias commands for, respectively, @code{set architecture}
21906 and @code{show architecture}.
21910 * Active Targets:: Active targets
21911 * Target Commands:: Commands for managing targets
21912 * Byte Order:: Choosing target byte order
21915 @node Active Targets
21916 @section Active Targets
21918 @cindex stacking targets
21919 @cindex active targets
21920 @cindex multiple targets
21922 There are multiple classes of targets such as: processes, executable files or
21923 recording sessions. Core files belong to the process class, making core file
21924 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21925 on multiple active targets, one in each class. This allows you to (for
21926 example) start a process and inspect its activity, while still having access to
21927 the executable file after the process finishes. Or if you start process
21928 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21929 presented a virtual layer of the recording target, while the process target
21930 remains stopped at the chronologically last point of the process execution.
21932 Use the @code{core-file} and @code{exec-file} commands to select a new core
21933 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21934 specify as a target a process that is already running, use the @code{attach}
21935 command (@pxref{Attach, ,Debugging an Already-running Process}).
21937 @node Target Commands
21938 @section Commands for Managing Targets
21941 @item target @var{type} @var{parameters}
21942 Connects the @value{GDBN} host environment to a target machine or
21943 process. A target is typically a protocol for talking to debugging
21944 facilities. You use the argument @var{type} to specify the type or
21945 protocol of the target machine.
21947 Further @var{parameters} are interpreted by the target protocol, but
21948 typically include things like device names or host names to connect
21949 with, process numbers, and baud rates.
21951 The @code{target} command does not repeat if you press @key{RET} again
21952 after executing the command.
21954 @kindex help target
21956 Displays the names of all targets available. To display targets
21957 currently selected, use either @code{info target} or @code{info files}
21958 (@pxref{Files, ,Commands to Specify Files}).
21960 @item help target @var{name}
21961 Describe a particular target, including any parameters necessary to
21964 @kindex set gnutarget
21965 @item set gnutarget @var{args}
21966 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21967 knows whether it is reading an @dfn{executable},
21968 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21969 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21970 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21973 @emph{Warning:} To specify a file format with @code{set gnutarget},
21974 you must know the actual BFD name.
21978 @xref{Files, , Commands to Specify Files}.
21980 @kindex show gnutarget
21981 @item show gnutarget
21982 Use the @code{show gnutarget} command to display what file format
21983 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21984 @value{GDBN} will determine the file format for each file automatically,
21985 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21988 @cindex common targets
21989 Here are some common targets (available, or not, depending on the GDB
21994 @item target exec @var{program}
21995 @cindex executable file target
21996 An executable file. @samp{target exec @var{program}} is the same as
21997 @samp{exec-file @var{program}}.
21999 @item target core @var{filename}
22000 @cindex core dump file target
22001 A core dump file. @samp{target core @var{filename}} is the same as
22002 @samp{core-file @var{filename}}.
22004 @item target remote @var{medium}
22005 @cindex remote target
22006 A remote system connected to @value{GDBN} via a serial line or network
22007 connection. This command tells @value{GDBN} to use its own remote
22008 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
22010 For example, if you have a board connected to @file{/dev/ttya} on the
22011 machine running @value{GDBN}, you could say:
22014 target remote /dev/ttya
22017 @code{target remote} supports the @code{load} command. This is only
22018 useful if you have some other way of getting the stub to the target
22019 system, and you can put it somewhere in memory where it won't get
22020 clobbered by the download.
22022 @item target sim @r{[}@var{simargs}@r{]} @dots{}
22023 @cindex built-in simulator target
22024 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
22032 works; however, you cannot assume that a specific memory map, device
22033 drivers, or even basic I/O is available, although some simulators do
22034 provide these. For info about any processor-specific simulator details,
22035 see the appropriate section in @ref{Embedded Processors, ,Embedded
22038 @item target native
22039 @cindex native target
22040 Setup for local/native process debugging. Useful to make the
22041 @code{run} command spawn native processes (likewise @code{attach},
22042 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
22043 (@pxref{set auto-connect-native-target}).
22047 Different targets are available on different configurations of @value{GDBN};
22048 your configuration may have more or fewer targets.
22050 Many remote targets require you to download the executable's code once
22051 you've successfully established a connection. You may wish to control
22052 various aspects of this process.
22057 @kindex set hash@r{, for remote monitors}
22058 @cindex hash mark while downloading
22059 This command controls whether a hash mark @samp{#} is displayed while
22060 downloading a file to the remote monitor. If on, a hash mark is
22061 displayed after each S-record is successfully downloaded to the
22065 @kindex show hash@r{, for remote monitors}
22066 Show the current status of displaying the hash mark.
22068 @item set debug monitor
22069 @kindex set debug monitor
22070 @cindex display remote monitor communications
22071 Enable or disable display of communications messages between
22072 @value{GDBN} and the remote monitor.
22074 @item show debug monitor
22075 @kindex show debug monitor
22076 Show the current status of displaying communications between
22077 @value{GDBN} and the remote monitor.
22082 @kindex load @var{filename} @var{offset}
22083 @item load @var{filename} @var{offset}
22085 Depending on what remote debugging facilities are configured into
22086 @value{GDBN}, the @code{load} command may be available. Where it exists, it
22087 is meant to make @var{filename} (an executable) available for debugging
22088 on the remote system---by downloading, or dynamic linking, for example.
22089 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
22090 the @code{add-symbol-file} command.
22092 If your @value{GDBN} does not have a @code{load} command, attempting to
22093 execute it gets the error message ``@code{You can't do that when your
22094 target is @dots{}}''
22096 The file is loaded at whatever address is specified in the executable.
22097 For some object file formats, you can specify the load address when you
22098 link the program; for other formats, like a.out, the object file format
22099 specifies a fixed address.
22100 @c FIXME! This would be a good place for an xref to the GNU linker doc.
22102 It is also possible to tell @value{GDBN} to load the executable file at a
22103 specific offset described by the optional argument @var{offset}. When
22104 @var{offset} is provided, @var{filename} must also be provided.
22106 Depending on the remote side capabilities, @value{GDBN} may be able to
22107 load programs into flash memory.
22109 @code{load} does not repeat if you press @key{RET} again after using it.
22114 @kindex flash-erase
22116 @anchor{flash-erase}
22118 Erases all known flash memory regions on the target.
22123 @section Choosing Target Byte Order
22125 @cindex choosing target byte order
22126 @cindex target byte order
22128 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
22129 offer the ability to run either big-endian or little-endian byte
22130 orders. Usually the executable or symbol will include a bit to
22131 designate the endian-ness, and you will not need to worry about
22132 which to use. However, you may still find it useful to adjust
22133 @value{GDBN}'s idea of processor endian-ness manually.
22137 @item set endian big
22138 Instruct @value{GDBN} to assume the target is big-endian.
22140 @item set endian little
22141 Instruct @value{GDBN} to assume the target is little-endian.
22143 @item set endian auto
22144 Instruct @value{GDBN} to use the byte order associated with the
22148 Display @value{GDBN}'s current idea of the target byte order.
22152 If the @code{set endian auto} mode is in effect and no executable has
22153 been selected, then the endianness used is the last one chosen either
22154 by one of the @code{set endian big} and @code{set endian little}
22155 commands or by inferring from the last executable used. If no
22156 endianness has been previously chosen, then the default for this mode
22157 is inferred from the target @value{GDBN} has been built for, and is
22158 @code{little} if the name of the target CPU has an @code{el} suffix
22159 and @code{big} otherwise.
22161 Note that these commands merely adjust interpretation of symbolic
22162 data on the host, and that they have absolutely no effect on the
22166 @node Remote Debugging
22167 @chapter Debugging Remote Programs
22168 @cindex remote debugging
22170 If you are trying to debug a program running on a machine that cannot run
22171 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22172 For example, you might use remote debugging on an operating system kernel,
22173 or on a small system which does not have a general purpose operating system
22174 powerful enough to run a full-featured debugger.
22176 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22177 to make this work with particular debugging targets. In addition,
22178 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22179 but not specific to any particular target system) which you can use if you
22180 write the remote stubs---the code that runs on the remote system to
22181 communicate with @value{GDBN}.
22183 Other remote targets may be available in your
22184 configuration of @value{GDBN}; use @code{help target} to list them.
22187 * Connecting:: Connecting to a remote target
22188 * File Transfer:: Sending files to a remote system
22189 * Server:: Using the gdbserver program
22190 * Remote Configuration:: Remote configuration
22191 * Remote Stub:: Implementing a remote stub
22195 @section Connecting to a Remote Target
22196 @cindex remote debugging, connecting
22197 @cindex @code{gdbserver}, connecting
22198 @cindex remote debugging, types of connections
22199 @cindex @code{gdbserver}, types of connections
22200 @cindex @code{gdbserver}, @code{target remote} mode
22201 @cindex @code{gdbserver}, @code{target extended-remote} mode
22203 This section describes how to connect to a remote target, including the
22204 types of connections and their differences, how to set up executable and
22205 symbol files on the host and target, and the commands used for
22206 connecting to and disconnecting from the remote target.
22208 @subsection Types of Remote Connections
22210 @value{GDBN} supports two types of remote connections, @code{target remote}
22211 mode and @code{target extended-remote} mode. Note that many remote targets
22212 support only @code{target remote} mode. There are several major
22213 differences between the two types of connections, enumerated here:
22217 @cindex remote debugging, detach and program exit
22218 @item Result of detach or program exit
22219 @strong{With target remote mode:} When the debugged program exits or you
22220 detach from it, @value{GDBN} disconnects from the target. When using
22221 @code{gdbserver}, @code{gdbserver} will exit.
22223 @strong{With target extended-remote mode:} When the debugged program exits or
22224 you detach from it, @value{GDBN} remains connected to the target, even
22225 though no program is running. You can rerun the program, attach to a
22226 running program, or use @code{monitor} commands specific to the target.
22228 When using @code{gdbserver} in this case, it does not exit unless it was
22229 invoked using the @option{--once} option. If the @option{--once} option
22230 was not used, you can ask @code{gdbserver} to exit using the
22231 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22233 @item Specifying the program to debug
22234 For both connection types you use the @code{file} command to specify the
22235 program on the host system. If you are using @code{gdbserver} there are
22236 some differences in how to specify the location of the program on the
22239 @strong{With target remote mode:} You must either specify the program to debug
22240 on the @code{gdbserver} command line or use the @option{--attach} option
22241 (@pxref{Attaching to a program,,Attaching to a Running Program}).
22243 @cindex @option{--multi}, @code{gdbserver} option
22244 @strong{With target extended-remote mode:} You may specify the program to debug
22245 on the @code{gdbserver} command line, or you can load the program or attach
22246 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22248 @anchor{--multi Option in Types of Remote Connnections}
22249 You can start @code{gdbserver} without supplying an initial command to run
22250 or process ID to attach. To do this, use the @option{--multi} command line
22251 option. Then you can connect using @code{target extended-remote} and start
22252 the program you want to debug (see below for details on using the
22253 @code{run} command in this scenario). Note that the conditions under which
22254 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
22255 (@code{target remote} or @code{target extended-remote}). The
22256 @option{--multi} option to @code{gdbserver} has no influence on that.
22258 @item The @code{run} command
22259 @strong{With target remote mode:} The @code{run} command is not
22260 supported. Once a connection has been established, you can use all
22261 the usual @value{GDBN} commands to examine and change data. The
22262 remote program is already running, so you can use commands like
22263 @kbd{step} and @kbd{continue}.
22265 @strong{With target extended-remote mode:} The @code{run} command is
22266 supported. The @code{run} command uses the value set by
22267 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
22268 the program to run. Command line arguments are supported, except for
22269 wildcard expansion and I/O redirection (@pxref{Arguments}).
22271 If you specify the program to debug on the command line, then the
22272 @code{run} command is not required to start execution, and you can
22273 resume using commands like @kbd{step} and @kbd{continue} as with
22274 @code{target remote} mode.
22276 @anchor{Attaching in Types of Remote Connections}
22278 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22279 not supported. To attach to a running program using @code{gdbserver}, you
22280 must use the @option{--attach} option (@pxref{Running gdbserver}).
22282 @strong{With target extended-remote mode:} To attach to a running program,
22283 you may use the @code{attach} command after the connection has been
22284 established. If you are using @code{gdbserver}, you may also invoke
22285 @code{gdbserver} using the @option{--attach} option
22286 (@pxref{Running gdbserver}).
22288 Some remote targets allow @value{GDBN} to determine the executable file running
22289 in the process the debugger is attaching to. In such a case, @value{GDBN}
22290 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22291 between the executable file name running in the process and the name of the
22292 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22296 @anchor{Host and target files}
22297 @subsection Host and Target Files
22298 @cindex remote debugging, symbol files
22299 @cindex symbol files, remote debugging
22301 @value{GDBN}, running on the host, needs access to symbol and debugging
22302 information for your program running on the target. This requires
22303 access to an unstripped copy of your program, and possibly any associated
22304 symbol files. Note that this section applies equally to both @code{target
22305 remote} mode and @code{target extended-remote} mode.
22307 Some remote targets (@pxref{qXfer executable filename read}, and
22308 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22309 the same connection used to communicate with @value{GDBN}. With such a
22310 target, if the remote program is unstripped, the only command you need is
22311 @code{target remote} (or @code{target extended-remote}).
22313 If the remote program is stripped, or the target does not support remote
22314 program file access, start up @value{GDBN} using the name of the local
22315 unstripped copy of your program as the first argument, or use the
22316 @code{file} command. Use @code{set sysroot} to specify the location (on
22317 the host) of target libraries (unless your @value{GDBN} was compiled with
22318 the correct sysroot using @code{--with-sysroot}). Alternatively, you
22319 may use @code{set solib-search-path} to specify how @value{GDBN} locates
22322 The symbol file and target libraries must exactly match the executable
22323 and libraries on the target, with one exception: the files on the host
22324 system should not be stripped, even if the files on the target system
22325 are. Mismatched or missing files will lead to confusing results
22326 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22327 files may also prevent @code{gdbserver} from debugging multi-threaded
22330 @subsection Remote Connection Commands
22331 @cindex remote connection commands
22332 @value{GDBN} can communicate with the target over a serial line, a
22333 local Unix domain socket, or
22334 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22335 each case, @value{GDBN} uses the same protocol for debugging your
22336 program; only the medium carrying the debugging packets varies. The
22337 @code{target remote} and @code{target extended-remote} commands
22338 establish a connection to the target. Both commands accept the same
22339 arguments, which indicate the medium to use:
22343 @item target remote @var{serial-device}
22344 @itemx target extended-remote @var{serial-device}
22345 @cindex serial line, @code{target remote}
22346 Use @var{serial-device} to communicate with the target. For example,
22347 to use a serial line connected to the device named @file{/dev/ttyb}:
22350 target remote /dev/ttyb
22353 If you're using a serial line, you may want to give @value{GDBN} the
22354 @samp{--baud} option, or use the @code{set serial baud} command
22355 (@pxref{Remote Configuration, set serial baud}) before the
22356 @code{target} command.
22358 @item target remote @var{local-socket}
22359 @itemx target extended-remote @var{local-socket}
22360 @cindex local socket, @code{target remote}
22361 @cindex Unix domain socket
22362 Use @var{local-socket} to communicate with the target. For example,
22363 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22366 target remote /tmp/gdb-socket0
22369 Note that this command has the same form as the command to connect
22370 to a serial line. @value{GDBN} will automatically determine which
22371 kind of file you have specified and will make the appropriate kind
22373 This feature is not available if the host system does not support
22374 Unix domain sockets.
22376 @item target remote @code{@var{host}:@var{port}}
22377 @itemx target remote @code{[@var{host}]:@var{port}}
22378 @itemx target remote @code{tcp:@var{host}:@var{port}}
22379 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22380 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22381 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22382 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22383 @itemx target extended-remote @code{@var{host}:@var{port}}
22384 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22385 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22386 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22387 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22388 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22389 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22390 @cindex @acronym{TCP} port, @code{target remote}
22391 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22392 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22393 address, or a numeric @acronym{IPv6} address (with or without the
22394 square brackets to separate the address from the port); @var{port}
22395 must be a decimal number. The @var{host} could be the target machine
22396 itself, if it is directly connected to the net, or it might be a
22397 terminal server which in turn has a serial line to the target.
22399 For example, to connect to port 2828 on a terminal server named
22403 target remote manyfarms:2828
22406 To connect to port 2828 on a terminal server whose address is
22407 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22408 square bracket syntax:
22411 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22415 or explicitly specify the @acronym{IPv6} protocol:
22418 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22421 This last example may be confusing to the reader, because there is no
22422 visible separation between the hostname and the port number.
22423 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22424 using square brackets for clarity. However, it is important to
22425 mention that for @value{GDBN} there is no ambiguity: the number after
22426 the last colon is considered to be the port number.
22428 If your remote target is actually running on the same machine as your
22429 debugger session (e.g.@: a simulator for your target running on the
22430 same host), you can omit the hostname. For example, to connect to
22431 port 1234 on your local machine:
22434 target remote :1234
22438 Note that the colon is still required here.
22440 @item target remote @code{udp:@var{host}:@var{port}}
22441 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22442 @itemx target remote @code{udp4:@var{host}:@var{port}}
22443 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22444 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22445 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22446 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22447 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22448 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22449 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22450 @cindex @acronym{UDP} port, @code{target remote}
22451 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22452 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22455 target remote udp:manyfarms:2828
22458 When using a @acronym{UDP} connection for remote debugging, you should
22459 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22460 can silently drop packets on busy or unreliable networks, which will
22461 cause havoc with your debugging session.
22463 @item target remote | @var{command}
22464 @itemx target extended-remote | @var{command}
22465 @cindex pipe, @code{target remote} to
22466 Run @var{command} in the background and communicate with it using a
22467 pipe. The @var{command} is a shell command, to be parsed and expanded
22468 by the system's command shell, @code{/bin/sh}; it should expect remote
22469 protocol packets on its standard input, and send replies on its
22470 standard output. You could use this to run a stand-alone simulator
22471 that speaks the remote debugging protocol, to make net connections
22472 using programs like @code{ssh}, or for other similar tricks.
22474 If @var{command} closes its standard output (perhaps by exiting),
22475 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22476 program has already exited, this will have no effect.)
22480 @cindex interrupting remote programs
22481 @cindex remote programs, interrupting
22482 Whenever @value{GDBN} is waiting for the remote program, if you type the
22483 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22484 program. This may or may not succeed, depending in part on the hardware
22485 and the serial drivers the remote system uses. If you type the
22486 interrupt character once again, @value{GDBN} displays this prompt:
22489 Interrupted while waiting for the program.
22490 Give up (and stop debugging it)? (y or n)
22493 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22494 the remote debugging session. (If you decide you want to try again later,
22495 you can use @kbd{target remote} again to connect once more.) If you type
22496 @kbd{n}, @value{GDBN} goes back to waiting.
22498 In @code{target extended-remote} mode, typing @kbd{n} will leave
22499 @value{GDBN} connected to the target.
22502 @kindex detach (remote)
22504 When you have finished debugging the remote program, you can use the
22505 @code{detach} command to release it from @value{GDBN} control.
22506 Detaching from the target normally resumes its execution, but the results
22507 will depend on your particular remote stub. After the @code{detach}
22508 command in @code{target remote} mode, @value{GDBN} is free to connect to
22509 another target. In @code{target extended-remote} mode, @value{GDBN} is
22510 still connected to the target.
22514 The @code{disconnect} command closes the connection to the target, and
22515 the target is generally not resumed. It will wait for @value{GDBN}
22516 (this instance or another one) to connect and continue debugging. After
22517 the @code{disconnect} command, @value{GDBN} is again free to connect to
22520 @cindex send command to remote monitor
22521 @cindex extend @value{GDBN} for remote targets
22522 @cindex add new commands for external monitor
22524 @item monitor @var{cmd}
22525 This command allows you to send arbitrary commands directly to the
22526 remote monitor. Since @value{GDBN} doesn't care about the commands it
22527 sends like this, this command is the way to extend @value{GDBN}---you
22528 can add new commands that only the external monitor will understand
22532 @node File Transfer
22533 @section Sending files to a remote system
22534 @cindex remote target, file transfer
22535 @cindex file transfer
22536 @cindex sending files to remote systems
22538 Some remote targets offer the ability to transfer files over the same
22539 connection used to communicate with @value{GDBN}. This is convenient
22540 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22541 running @code{gdbserver} over a network interface. For other targets,
22542 e.g.@: embedded devices with only a single serial port, this may be
22543 the only way to upload or download files.
22545 Not all remote targets support these commands.
22549 @item remote put @var{hostfile} @var{targetfile}
22550 Copy file @var{hostfile} from the host system (the machine running
22551 @value{GDBN}) to @var{targetfile} on the target system.
22554 @item remote get @var{targetfile} @var{hostfile}
22555 Copy file @var{targetfile} from the target system to @var{hostfile}
22556 on the host system.
22558 @kindex remote delete
22559 @item remote delete @var{targetfile}
22560 Delete @var{targetfile} from the target system.
22565 @section Using the @code{gdbserver} Program
22568 @cindex remote connection without stubs
22569 @code{gdbserver} is a control program for Unix-like systems, which
22570 allows you to connect your program with a remote @value{GDBN} via
22571 @code{target remote} or @code{target extended-remote}---but without
22572 linking in the usual debugging stub.
22574 @code{gdbserver} is not a complete replacement for the debugging stubs,
22575 because it requires essentially the same operating-system facilities
22576 that @value{GDBN} itself does. In fact, a system that can run
22577 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22578 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22579 because it is a much smaller program than @value{GDBN} itself. It is
22580 also easier to port than all of @value{GDBN}, so you may be able to get
22581 started more quickly on a new system by using @code{gdbserver}.
22582 Finally, if you develop code for real-time systems, you may find that
22583 the tradeoffs involved in real-time operation make it more convenient to
22584 do as much development work as possible on another system, for example
22585 by cross-compiling. You can use @code{gdbserver} to make a similar
22586 choice for debugging.
22588 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22589 or a TCP connection, using the standard @value{GDBN} remote serial
22593 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22594 Do not run @code{gdbserver} connected to any public network; a
22595 @value{GDBN} connection to @code{gdbserver} provides access to the
22596 target system with the same privileges as the user running
22600 @anchor{Running gdbserver}
22601 @subsection Running @code{gdbserver}
22602 @cindex arguments, to @code{gdbserver}
22603 @cindex @code{gdbserver}, command-line arguments
22605 Run @code{gdbserver} on the target system. You need a copy of the
22606 program you want to debug, including any libraries it requires.
22607 @code{gdbserver} does not need your program's symbol table, so you can
22608 strip the program if necessary to save space. @value{GDBN} on the host
22609 system does all the symbol handling.
22611 To use the server, you must tell it how to communicate with @value{GDBN};
22612 the name of your program; and the arguments for your program. The usual
22616 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22619 @var{comm} is either a device name (to use a serial line), or a TCP
22620 hostname and portnumber, or @code{-} or @code{stdio} to use
22621 stdin/stdout of @code{gdbserver}.
22622 For example, to debug Emacs with the argument
22623 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22627 target> gdbserver /dev/com1 emacs foo.txt
22630 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22633 To use a TCP connection instead of a serial line:
22636 target> gdbserver host:2345 emacs foo.txt
22639 The only difference from the previous example is the first argument,
22640 specifying that you are communicating with the host @value{GDBN} via
22641 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22642 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22643 (Currently, the @samp{host} part is ignored.) You can choose any number
22644 you want for the port number as long as it does not conflict with any
22645 TCP ports already in use on the target system (for example, @code{23} is
22646 reserved for @code{telnet}).@footnote{If you choose a port number that
22647 conflicts with another service, @code{gdbserver} prints an error message
22648 and exits.} You must use the same port number with the host @value{GDBN}
22649 @code{target remote} command.
22651 The @code{stdio} connection is useful when starting @code{gdbserver}
22655 (gdb) target remote | ssh -T hostname gdbserver - hello
22658 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22659 and we don't want escape-character handling. Ssh does this by default when
22660 a command is provided, the flag is provided to make it explicit.
22661 You could elide it if you want to.
22663 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22664 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22665 display through a pipe connected to gdbserver.
22666 Both @code{stdout} and @code{stderr} use the same pipe.
22668 @anchor{Attaching to a program}
22669 @subsubsection Attaching to a Running Program
22670 @cindex attach to a program, @code{gdbserver}
22671 @cindex @option{--attach}, @code{gdbserver} option
22673 On some targets, @code{gdbserver} can also attach to running programs.
22674 This is accomplished via the @code{--attach} argument. The syntax is:
22677 target> gdbserver --attach @var{comm} @var{pid}
22680 @var{pid} is the process ID of a currently running process. It isn't
22681 necessary to point @code{gdbserver} at a binary for the running process.
22683 In @code{target extended-remote} mode, you can also attach using the
22684 @value{GDBN} attach command
22685 (@pxref{Attaching in Types of Remote Connections}).
22688 You can debug processes by name instead of process ID if your target has the
22689 @code{pidof} utility:
22692 target> gdbserver --attach @var{comm} `pidof @var{program}`
22695 In case more than one copy of @var{program} is running, or @var{program}
22696 has multiple threads, most versions of @code{pidof} support the
22697 @code{-s} option to only return the first process ID.
22699 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22701 This section applies only when @code{gdbserver} is run to listen on a TCP
22704 @code{gdbserver} normally terminates after all of its debugged processes have
22705 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22706 extended-remote}, @code{gdbserver} stays running even with no processes left.
22707 @value{GDBN} normally terminates the spawned debugged process on its exit,
22708 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22709 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22710 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22711 stays running even in the @kbd{target remote} mode.
22713 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22714 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22715 completeness, at most one @value{GDBN} can be connected at a time.
22717 @cindex @option{--once}, @code{gdbserver} option
22718 By default, @code{gdbserver} keeps the listening TCP port open, so that
22719 subsequent connections are possible. However, if you start @code{gdbserver}
22720 with the @option{--once} option, it will stop listening for any further
22721 connection attempts after connecting to the first @value{GDBN} session. This
22722 means no further connections to @code{gdbserver} will be possible after the
22723 first one. It also means @code{gdbserver} will terminate after the first
22724 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22725 connections and even in the @kbd{target extended-remote} mode. The
22726 @option{--once} option allows reusing the same port number for connecting to
22727 multiple instances of @code{gdbserver} running on the same host, since each
22728 instance closes its port after the first connection.
22730 @anchor{Other Command-Line Arguments for gdbserver}
22731 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22733 You can use the @option{--multi} option to start @code{gdbserver} without
22734 specifying a program to debug or a process to attach to. Then you can
22735 attach in @code{target extended-remote} mode and run or attach to a
22736 program. For more information,
22737 @pxref{--multi Option in Types of Remote Connnections}.
22739 @cindex @option{--debug}, @code{gdbserver} option
22740 The @option{--debug} option tells @code{gdbserver} to display extra
22741 status information about the debugging process.
22742 @cindex @option{--remote-debug}, @code{gdbserver} option
22743 The @option{--remote-debug} option tells @code{gdbserver} to display
22744 remote protocol debug output.
22745 @cindex @option{--debug-file}, @code{gdbserver} option
22746 @cindex @code{gdbserver}, send all debug output to a single file
22747 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22748 write any debug output to the given @var{filename}. These options are intended
22749 for @code{gdbserver} development and for bug reports to the developers.
22751 @cindex @option{--debug-format}, @code{gdbserver} option
22752 The @option{--debug-format=option1[,option2,...]} option tells
22753 @code{gdbserver} to include additional information in each output.
22754 Possible options are:
22758 Turn off all extra information in debugging output.
22760 Turn on all extra information in debugging output.
22762 Include a timestamp in each line of debugging output.
22765 Options are processed in order. Thus, for example, if @option{none}
22766 appears last then no additional information is added to debugging output.
22768 @cindex @option{--wrapper}, @code{gdbserver} option
22769 The @option{--wrapper} option specifies a wrapper to launch programs
22770 for debugging. The option should be followed by the name of the
22771 wrapper, then any command-line arguments to pass to the wrapper, then
22772 @kbd{--} indicating the end of the wrapper arguments.
22774 @code{gdbserver} runs the specified wrapper program with a combined
22775 command line including the wrapper arguments, then the name of the
22776 program to debug, then any arguments to the program. The wrapper
22777 runs until it executes your program, and then @value{GDBN} gains control.
22779 You can use any program that eventually calls @code{execve} with
22780 its arguments as a wrapper. Several standard Unix utilities do
22781 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22782 with @code{exec "$@@"} will also work.
22784 For example, you can use @code{env} to pass an environment variable to
22785 the debugged program, without setting the variable in @code{gdbserver}'s
22789 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22792 @cindex @option{--selftest}
22793 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22796 $ gdbserver --selftest
22797 Ran 2 unit tests, 0 failed
22800 These tests are disabled in release.
22801 @subsection Connecting to @code{gdbserver}
22803 The basic procedure for connecting to the remote target is:
22807 Run @value{GDBN} on the host system.
22810 Make sure you have the necessary symbol files
22811 (@pxref{Host and target files}).
22812 Load symbols for your application using the @code{file} command before you
22813 connect. Use @code{set sysroot} to locate target libraries (unless your
22814 @value{GDBN} was compiled with the correct sysroot using
22815 @code{--with-sysroot}).
22818 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22819 For TCP connections, you must start up @code{gdbserver} prior to using
22820 the @code{target} command. Otherwise you may get an error whose
22821 text depends on the host system, but which usually looks something like
22822 @samp{Connection refused}. Don't use the @code{load}
22823 command in @value{GDBN} when using @code{target remote} mode, since the
22824 program is already on the target.
22828 @anchor{Monitor Commands for gdbserver}
22829 @subsection Monitor Commands for @code{gdbserver}
22830 @cindex monitor commands, for @code{gdbserver}
22832 During a @value{GDBN} session using @code{gdbserver}, you can use the
22833 @code{monitor} command to send special requests to @code{gdbserver}.
22834 Here are the available commands.
22838 List the available monitor commands.
22840 @item monitor set debug 0
22841 @itemx monitor set debug 1
22842 Disable or enable general debugging messages.
22844 @item monitor set remote-debug 0
22845 @itemx monitor set remote-debug 1
22846 Disable or enable specific debugging messages associated with the remote
22847 protocol (@pxref{Remote Protocol}).
22849 @item monitor set debug-file filename
22850 @itemx monitor set debug-file
22851 Send any debug output to the given file, or to stderr.
22853 @item monitor set debug-format option1@r{[},option2,...@r{]}
22854 Specify additional text to add to debugging messages.
22855 Possible options are:
22859 Turn off all extra information in debugging output.
22861 Turn on all extra information in debugging output.
22863 Include a timestamp in each line of debugging output.
22866 Options are processed in order. Thus, for example, if @option{none}
22867 appears last then no additional information is added to debugging output.
22869 @item monitor set libthread-db-search-path [PATH]
22870 @cindex gdbserver, search path for @code{libthread_db}
22871 When this command is issued, @var{path} is a colon-separated list of
22872 directories to search for @code{libthread_db} (@pxref{Threads,,set
22873 libthread-db-search-path}). If you omit @var{path},
22874 @samp{libthread-db-search-path} will be reset to its default value.
22876 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22877 not supported in @code{gdbserver}.
22880 Tell gdbserver to exit immediately. This command should be followed by
22881 @code{disconnect} to close the debugging session. @code{gdbserver} will
22882 detach from any attached processes and kill any processes it created.
22883 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22884 of a multi-process mode debug session.
22888 @subsection Tracepoints support in @code{gdbserver}
22889 @cindex tracepoints support in @code{gdbserver}
22891 On some targets, @code{gdbserver} supports tracepoints, fast
22892 tracepoints and static tracepoints.
22894 For fast or static tracepoints to work, a special library called the
22895 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22896 This library is built and distributed as an integral part of
22897 @code{gdbserver}. In addition, support for static tracepoints
22898 requires building the in-process agent library with static tracepoints
22899 support. At present, the UST (LTTng Userspace Tracer,
22900 @url{http://lttng.org/ust}) tracing engine is supported. This support
22901 is automatically available if UST development headers are found in the
22902 standard include path when @code{gdbserver} is built, or if
22903 @code{gdbserver} was explicitly configured using @option{--with-ust}
22904 to point at such headers. You can explicitly disable the support
22905 using @option{--with-ust=no}.
22907 There are several ways to load the in-process agent in your program:
22910 @item Specifying it as dependency at link time
22912 You can link your program dynamically with the in-process agent
22913 library. On most systems, this is accomplished by adding
22914 @code{-linproctrace} to the link command.
22916 @item Using the system's preloading mechanisms
22918 You can force loading the in-process agent at startup time by using
22919 your system's support for preloading shared libraries. Many Unixes
22920 support the concept of preloading user defined libraries. In most
22921 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22922 in the environment. See also the description of @code{gdbserver}'s
22923 @option{--wrapper} command line option.
22925 @item Using @value{GDBN} to force loading the agent at run time
22927 On some systems, you can force the inferior to load a shared library,
22928 by calling a dynamic loader function in the inferior that takes care
22929 of dynamically looking up and loading a shared library. On most Unix
22930 systems, the function is @code{dlopen}. You'll use the @code{call}
22931 command for that. For example:
22934 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22937 Note that on most Unix systems, for the @code{dlopen} function to be
22938 available, the program needs to be linked with @code{-ldl}.
22941 On systems that have a userspace dynamic loader, like most Unix
22942 systems, when you connect to @code{gdbserver} using @code{target
22943 remote}, you'll find that the program is stopped at the dynamic
22944 loader's entry point, and no shared library has been loaded in the
22945 program's address space yet, including the in-process agent. In that
22946 case, before being able to use any of the fast or static tracepoints
22947 features, you need to let the loader run and load the shared
22948 libraries. The simplest way to do that is to run the program to the
22949 main procedure. E.g., if debugging a C or C@t{++} program, start
22950 @code{gdbserver} like so:
22953 $ gdbserver :9999 myprogram
22956 Start GDB and connect to @code{gdbserver} like so, and run to main:
22960 (@value{GDBP}) target remote myhost:9999
22961 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22962 (@value{GDBP}) b main
22963 (@value{GDBP}) continue
22966 The in-process tracing agent library should now be loaded into the
22967 process; you can confirm it with the @code{info sharedlibrary}
22968 command, which will list @file{libinproctrace.so} as loaded in the
22969 process. You are now ready to install fast tracepoints, list static
22970 tracepoint markers, probe static tracepoints markers, and start
22973 @node Remote Configuration
22974 @section Remote Configuration
22977 @kindex show remote
22978 This section documents the configuration options available when
22979 debugging remote programs. For the options related to the File I/O
22980 extensions of the remote protocol, see @ref{system,
22981 system-call-allowed}.
22984 @item set remoteaddresssize @var{bits}
22985 @cindex address size for remote targets
22986 @cindex bits in remote address
22987 Set the maximum size of address in a memory packet to the specified
22988 number of bits. @value{GDBN} will mask off the address bits above
22989 that number, when it passes addresses to the remote target. The
22990 default value is the number of bits in the target's address.
22992 @item show remoteaddresssize
22993 Show the current value of remote address size in bits.
22995 @item set serial baud @var{n}
22996 @cindex baud rate for remote targets
22997 Set the baud rate for the remote serial I/O to @var{n} baud. The
22998 value is used to set the speed of the serial port used for debugging
23001 @item show serial baud
23002 Show the current speed of the remote connection.
23004 @item set serial parity @var{parity}
23005 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
23006 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
23008 @item show serial parity
23009 Show the current parity of the serial port.
23011 @item set remotebreak
23012 @cindex interrupt remote programs
23013 @cindex BREAK signal instead of Ctrl-C
23014 @anchor{set remotebreak}
23015 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
23016 when you type @kbd{Ctrl-c} to interrupt the program running
23017 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
23018 character instead. The default is off, since most remote systems
23019 expect to see @samp{Ctrl-C} as the interrupt signal.
23021 @item show remotebreak
23022 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
23023 interrupt the remote program.
23025 @item set remoteflow on
23026 @itemx set remoteflow off
23027 @kindex set remoteflow
23028 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
23029 on the serial port used to communicate to the remote target.
23031 @item show remoteflow
23032 @kindex show remoteflow
23033 Show the current setting of hardware flow control.
23035 @item set remotelogbase @var{base}
23036 Set the base (a.k.a.@: radix) of logging serial protocol
23037 communications to @var{base}. Supported values of @var{base} are:
23038 @code{ascii}, @code{octal}, and @code{hex}. The default is
23041 @item show remotelogbase
23042 Show the current setting of the radix for logging remote serial
23045 @item set remotelogfile @var{file}
23046 @cindex record serial communications on file
23047 Record remote serial communications on the named @var{file}. The
23048 default is not to record at all.
23050 @item show remotelogfile
23051 Show the current setting of the file name on which to record the
23052 serial communications.
23054 @item set remotetimeout @var{num}
23055 @cindex timeout for serial communications
23056 @cindex remote timeout
23057 Set the timeout limit to wait for the remote target to respond to
23058 @var{num} seconds. The default is 2 seconds.
23060 @item show remotetimeout
23061 Show the current number of seconds to wait for the remote target
23064 @cindex limit hardware breakpoints and watchpoints
23065 @cindex remote target, limit break- and watchpoints
23066 @anchor{set remote hardware-watchpoint-limit}
23067 @anchor{set remote hardware-breakpoint-limit}
23068 @item set remote hardware-watchpoint-limit @var{limit}
23069 @itemx set remote hardware-breakpoint-limit @var{limit}
23070 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
23071 or breakpoints. The @var{limit} can be set to 0 to disable hardware
23072 watchpoints or breakpoints, and @code{unlimited} for unlimited
23073 watchpoints or breakpoints.
23075 @item show remote hardware-watchpoint-limit
23076 @itemx show remote hardware-breakpoint-limit
23077 Show the current limit for the number of hardware watchpoints or
23078 breakpoints that @value{GDBN} can use.
23080 @cindex limit hardware watchpoints length
23081 @cindex remote target, limit watchpoints length
23082 @anchor{set remote hardware-watchpoint-length-limit}
23083 @item set remote hardware-watchpoint-length-limit @var{limit}
23084 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
23085 length of a remote hardware watchpoint. A @var{limit} of 0 disables
23086 hardware watchpoints and @code{unlimited} allows watchpoints of any
23089 @item show remote hardware-watchpoint-length-limit
23090 Show the current limit (in bytes) of the maximum length of
23091 a remote hardware watchpoint.
23093 @item set remote exec-file @var{filename}
23094 @itemx show remote exec-file
23095 @anchor{set remote exec-file}
23096 @cindex executable file, for remote target
23097 Select the file used for @code{run} with @code{target
23098 extended-remote}. This should be set to a filename valid on the
23099 target system. If it is not set, the target will use a default
23100 filename (e.g.@: the last program run).
23102 @item set remote interrupt-sequence
23103 @cindex interrupt remote programs
23104 @cindex select Ctrl-C, BREAK or BREAK-g
23105 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
23106 @samp{BREAK-g} as the
23107 sequence to the remote target in order to interrupt the execution.
23108 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
23109 is high level of serial line for some certain time.
23110 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
23111 It is @code{BREAK} signal followed by character @code{g}.
23113 @item show remote interrupt-sequence
23114 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
23115 is sent by @value{GDBN} to interrupt the remote program.
23116 @code{BREAK-g} is BREAK signal followed by @code{g} and
23117 also known as Magic SysRq g.
23119 @item set remote interrupt-on-connect
23120 @cindex send interrupt-sequence on start
23121 Specify whether interrupt-sequence is sent to remote target when
23122 @value{GDBN} connects to it. This is mostly needed when you debug
23123 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
23124 which is known as Magic SysRq g in order to connect @value{GDBN}.
23126 @item show remote interrupt-on-connect
23127 Show whether interrupt-sequence is sent
23128 to remote target when @value{GDBN} connects to it.
23132 @item set tcp auto-retry on
23133 @cindex auto-retry, for remote TCP target
23134 Enable auto-retry for remote TCP connections. This is useful if the remote
23135 debugging agent is launched in parallel with @value{GDBN}; there is a race
23136 condition because the agent may not become ready to accept the connection
23137 before @value{GDBN} attempts to connect. When auto-retry is
23138 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
23139 to establish the connection using the timeout specified by
23140 @code{set tcp connect-timeout}.
23142 @item set tcp auto-retry off
23143 Do not auto-retry failed TCP connections.
23145 @item show tcp auto-retry
23146 Show the current auto-retry setting.
23148 @item set tcp connect-timeout @var{seconds}
23149 @itemx set tcp connect-timeout unlimited
23150 @cindex connection timeout, for remote TCP target
23151 @cindex timeout, for remote target connection
23152 Set the timeout for establishing a TCP connection to the remote target to
23153 @var{seconds}. The timeout affects both polling to retry failed connections
23154 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23155 that are merely slow to complete, and represents an approximate cumulative
23156 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23157 @value{GDBN} will keep attempting to establish a connection forever,
23158 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23160 @item show tcp connect-timeout
23161 Show the current connection timeout setting.
23164 @cindex remote packets, enabling and disabling
23165 The @value{GDBN} remote protocol autodetects the packets supported by
23166 your debugging stub. If you need to override the autodetection, you
23167 can use these commands to enable or disable individual packets. Each
23168 packet can be set to @samp{on} (the remote target supports this
23169 packet), @samp{off} (the remote target does not support this packet),
23170 or @samp{auto} (detect remote target support for this packet). They
23171 all default to @samp{auto}. For more information about each packet,
23172 see @ref{Remote Protocol}.
23174 During normal use, you should not have to use any of these commands.
23175 If you do, that may be a bug in your remote debugging stub, or a bug
23176 in @value{GDBN}. You may want to report the problem to the
23177 @value{GDBN} developers.
23179 For each packet @var{name}, the command to enable or disable the
23180 packet is @code{set remote @var{name}-packet}. The available settings
23183 @multitable @columnfractions 0.28 0.32 0.25
23186 @tab Related Features
23188 @item @code{fetch-register}
23190 @tab @code{info registers}
23192 @item @code{set-register}
23196 @item @code{binary-download}
23198 @tab @code{load}, @code{set}
23200 @item @code{read-aux-vector}
23201 @tab @code{qXfer:auxv:read}
23202 @tab @code{info auxv}
23204 @item @code{symbol-lookup}
23205 @tab @code{qSymbol}
23206 @tab Detecting multiple threads
23208 @item @code{attach}
23209 @tab @code{vAttach}
23212 @item @code{verbose-resume}
23214 @tab Stepping or resuming multiple threads
23220 @item @code{software-breakpoint}
23224 @item @code{hardware-breakpoint}
23228 @item @code{write-watchpoint}
23232 @item @code{read-watchpoint}
23236 @item @code{access-watchpoint}
23240 @item @code{pid-to-exec-file}
23241 @tab @code{qXfer:exec-file:read}
23242 @tab @code{attach}, @code{run}
23244 @item @code{target-features}
23245 @tab @code{qXfer:features:read}
23246 @tab @code{set architecture}
23248 @item @code{library-info}
23249 @tab @code{qXfer:libraries:read}
23250 @tab @code{info sharedlibrary}
23252 @item @code{memory-map}
23253 @tab @code{qXfer:memory-map:read}
23254 @tab @code{info mem}
23256 @item @code{read-sdata-object}
23257 @tab @code{qXfer:sdata:read}
23258 @tab @code{print $_sdata}
23260 @item @code{read-siginfo-object}
23261 @tab @code{qXfer:siginfo:read}
23262 @tab @code{print $_siginfo}
23264 @item @code{write-siginfo-object}
23265 @tab @code{qXfer:siginfo:write}
23266 @tab @code{set $_siginfo}
23268 @item @code{threads}
23269 @tab @code{qXfer:threads:read}
23270 @tab @code{info threads}
23272 @item @code{get-thread-local-@*storage-address}
23273 @tab @code{qGetTLSAddr}
23274 @tab Displaying @code{__thread} variables
23276 @item @code{get-thread-information-block-address}
23277 @tab @code{qGetTIBAddr}
23278 @tab Display MS-Windows Thread Information Block.
23280 @item @code{search-memory}
23281 @tab @code{qSearch:memory}
23284 @item @code{supported-packets}
23285 @tab @code{qSupported}
23286 @tab Remote communications parameters
23288 @item @code{catch-syscalls}
23289 @tab @code{QCatchSyscalls}
23290 @tab @code{catch syscall}
23292 @item @code{pass-signals}
23293 @tab @code{QPassSignals}
23294 @tab @code{handle @var{signal}}
23296 @item @code{program-signals}
23297 @tab @code{QProgramSignals}
23298 @tab @code{handle @var{signal}}
23300 @item @code{hostio-close-packet}
23301 @tab @code{vFile:close}
23302 @tab @code{remote get}, @code{remote put}
23304 @item @code{hostio-open-packet}
23305 @tab @code{vFile:open}
23306 @tab @code{remote get}, @code{remote put}
23308 @item @code{hostio-pread-packet}
23309 @tab @code{vFile:pread}
23310 @tab @code{remote get}, @code{remote put}
23312 @item @code{hostio-pwrite-packet}
23313 @tab @code{vFile:pwrite}
23314 @tab @code{remote get}, @code{remote put}
23316 @item @code{hostio-unlink-packet}
23317 @tab @code{vFile:unlink}
23318 @tab @code{remote delete}
23320 @item @code{hostio-readlink-packet}
23321 @tab @code{vFile:readlink}
23324 @item @code{hostio-fstat-packet}
23325 @tab @code{vFile:fstat}
23328 @item @code{hostio-setfs-packet}
23329 @tab @code{vFile:setfs}
23332 @item @code{noack-packet}
23333 @tab @code{QStartNoAckMode}
23334 @tab Packet acknowledgment
23336 @item @code{osdata}
23337 @tab @code{qXfer:osdata:read}
23338 @tab @code{info os}
23340 @item @code{query-attached}
23341 @tab @code{qAttached}
23342 @tab Querying remote process attach state.
23344 @item @code{trace-buffer-size}
23345 @tab @code{QTBuffer:size}
23346 @tab @code{set trace-buffer-size}
23348 @item @code{trace-status}
23349 @tab @code{qTStatus}
23350 @tab @code{tstatus}
23352 @item @code{traceframe-info}
23353 @tab @code{qXfer:traceframe-info:read}
23354 @tab Traceframe info
23356 @item @code{install-in-trace}
23357 @tab @code{InstallInTrace}
23358 @tab Install tracepoint in tracing
23360 @item @code{disable-randomization}
23361 @tab @code{QDisableRandomization}
23362 @tab @code{set disable-randomization}
23364 @item @code{startup-with-shell}
23365 @tab @code{QStartupWithShell}
23366 @tab @code{set startup-with-shell}
23368 @item @code{environment-hex-encoded}
23369 @tab @code{QEnvironmentHexEncoded}
23370 @tab @code{set environment}
23372 @item @code{environment-unset}
23373 @tab @code{QEnvironmentUnset}
23374 @tab @code{unset environment}
23376 @item @code{environment-reset}
23377 @tab @code{QEnvironmentReset}
23378 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23380 @item @code{set-working-dir}
23381 @tab @code{QSetWorkingDir}
23382 @tab @code{set cwd}
23384 @item @code{conditional-breakpoints-packet}
23385 @tab @code{Z0 and Z1}
23386 @tab @code{Support for target-side breakpoint condition evaluation}
23388 @item @code{multiprocess-extensions}
23389 @tab @code{multiprocess extensions}
23390 @tab Debug multiple processes and remote process PID awareness
23392 @item @code{swbreak-feature}
23393 @tab @code{swbreak stop reason}
23396 @item @code{hwbreak-feature}
23397 @tab @code{hwbreak stop reason}
23400 @item @code{fork-event-feature}
23401 @tab @code{fork stop reason}
23404 @item @code{vfork-event-feature}
23405 @tab @code{vfork stop reason}
23408 @item @code{exec-event-feature}
23409 @tab @code{exec stop reason}
23412 @item @code{thread-events}
23413 @tab @code{QThreadEvents}
23414 @tab Tracking thread lifetime.
23416 @item @code{no-resumed-stop-reply}
23417 @tab @code{no resumed thread left stop reply}
23418 @tab Tracking thread lifetime.
23423 @section Implementing a Remote Stub
23425 @cindex debugging stub, example
23426 @cindex remote stub, example
23427 @cindex stub example, remote debugging
23428 The stub files provided with @value{GDBN} implement the target side of the
23429 communication protocol, and the @value{GDBN} side is implemented in the
23430 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23431 these subroutines to communicate, and ignore the details. (If you're
23432 implementing your own stub file, you can still ignore the details: start
23433 with one of the existing stub files. @file{sparc-stub.c} is the best
23434 organized, and therefore the easiest to read.)
23436 @cindex remote serial debugging, overview
23437 To debug a program running on another machine (the debugging
23438 @dfn{target} machine), you must first arrange for all the usual
23439 prerequisites for the program to run by itself. For example, for a C
23444 A startup routine to set up the C runtime environment; these usually
23445 have a name like @file{crt0}. The startup routine may be supplied by
23446 your hardware supplier, or you may have to write your own.
23449 A C subroutine library to support your program's
23450 subroutine calls, notably managing input and output.
23453 A way of getting your program to the other machine---for example, a
23454 download program. These are often supplied by the hardware
23455 manufacturer, but you may have to write your own from hardware
23459 The next step is to arrange for your program to use a serial port to
23460 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23461 machine). In general terms, the scheme looks like this:
23465 @value{GDBN} already understands how to use this protocol; when everything
23466 else is set up, you can simply use the @samp{target remote} command
23467 (@pxref{Targets,,Specifying a Debugging Target}).
23469 @item On the target,
23470 you must link with your program a few special-purpose subroutines that
23471 implement the @value{GDBN} remote serial protocol. The file containing these
23472 subroutines is called a @dfn{debugging stub}.
23474 On certain remote targets, you can use an auxiliary program
23475 @code{gdbserver} instead of linking a stub into your program.
23476 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23479 The debugging stub is specific to the architecture of the remote
23480 machine; for example, use @file{sparc-stub.c} to debug programs on
23483 @cindex remote serial stub list
23484 These working remote stubs are distributed with @value{GDBN}:
23489 @cindex @file{i386-stub.c}
23492 For Intel 386 and compatible architectures.
23495 @cindex @file{m68k-stub.c}
23496 @cindex Motorola 680x0
23498 For Motorola 680x0 architectures.
23501 @cindex @file{sh-stub.c}
23504 For Renesas SH architectures.
23507 @cindex @file{sparc-stub.c}
23509 For @sc{sparc} architectures.
23511 @item sparcl-stub.c
23512 @cindex @file{sparcl-stub.c}
23515 For Fujitsu @sc{sparclite} architectures.
23519 The @file{README} file in the @value{GDBN} distribution may list other
23520 recently added stubs.
23523 * Stub Contents:: What the stub can do for you
23524 * Bootstrapping:: What you must do for the stub
23525 * Debug Session:: Putting it all together
23528 @node Stub Contents
23529 @subsection What the Stub Can Do for You
23531 @cindex remote serial stub
23532 The debugging stub for your architecture supplies these three
23536 @item set_debug_traps
23537 @findex set_debug_traps
23538 @cindex remote serial stub, initialization
23539 This routine arranges for @code{handle_exception} to run when your
23540 program stops. You must call this subroutine explicitly in your
23541 program's startup code.
23543 @item handle_exception
23544 @findex handle_exception
23545 @cindex remote serial stub, main routine
23546 This is the central workhorse, but your program never calls it
23547 explicitly---the setup code arranges for @code{handle_exception} to
23548 run when a trap is triggered.
23550 @code{handle_exception} takes control when your program stops during
23551 execution (for example, on a breakpoint), and mediates communications
23552 with @value{GDBN} on the host machine. This is where the communications
23553 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23554 representative on the target machine. It begins by sending summary
23555 information on the state of your program, then continues to execute,
23556 retrieving and transmitting any information @value{GDBN} needs, until you
23557 execute a @value{GDBN} command that makes your program resume; at that point,
23558 @code{handle_exception} returns control to your own code on the target
23562 @cindex @code{breakpoint} subroutine, remote
23563 Use this auxiliary subroutine to make your program contain a
23564 breakpoint. Depending on the particular situation, this may be the only
23565 way for @value{GDBN} to get control. For instance, if your target
23566 machine has some sort of interrupt button, you won't need to call this;
23567 pressing the interrupt button transfers control to
23568 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23569 simply receiving characters on the serial port may also trigger a trap;
23570 again, in that situation, you don't need to call @code{breakpoint} from
23571 your own program---simply running @samp{target remote} from the host
23572 @value{GDBN} session gets control.
23574 Call @code{breakpoint} if none of these is true, or if you simply want
23575 to make certain your program stops at a predetermined point for the
23576 start of your debugging session.
23579 @node Bootstrapping
23580 @subsection What You Must Do for the Stub
23582 @cindex remote stub, support routines
23583 The debugging stubs that come with @value{GDBN} are set up for a particular
23584 chip architecture, but they have no information about the rest of your
23585 debugging target machine.
23587 First of all you need to tell the stub how to communicate with the
23591 @item int getDebugChar()
23592 @findex getDebugChar
23593 Write this subroutine to read a single character from the serial port.
23594 It may be identical to @code{getchar} for your target system; a
23595 different name is used to allow you to distinguish the two if you wish.
23597 @item void putDebugChar(int)
23598 @findex putDebugChar
23599 Write this subroutine to write a single character to the serial port.
23600 It may be identical to @code{putchar} for your target system; a
23601 different name is used to allow you to distinguish the two if you wish.
23604 @cindex control C, and remote debugging
23605 @cindex interrupting remote targets
23606 If you want @value{GDBN} to be able to stop your program while it is
23607 running, you need to use an interrupt-driven serial driver, and arrange
23608 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23609 character). That is the character which @value{GDBN} uses to tell the
23610 remote system to stop.
23612 Getting the debugging target to return the proper status to @value{GDBN}
23613 probably requires changes to the standard stub; one quick and dirty way
23614 is to just execute a breakpoint instruction (the ``dirty'' part is that
23615 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23617 Other routines you need to supply are:
23620 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23621 @findex exceptionHandler
23622 Write this function to install @var{exception_address} in the exception
23623 handling tables. You need to do this because the stub does not have any
23624 way of knowing what the exception handling tables on your target system
23625 are like (for example, the processor's table might be in @sc{rom},
23626 containing entries which point to a table in @sc{ram}).
23627 The @var{exception_number} specifies the exception which should be changed;
23628 its meaning is architecture-dependent (for example, different numbers
23629 might represent divide by zero, misaligned access, etc). When this
23630 exception occurs, control should be transferred directly to
23631 @var{exception_address}, and the processor state (stack, registers,
23632 and so on) should be just as it is when a processor exception occurs. So if
23633 you want to use a jump instruction to reach @var{exception_address}, it
23634 should be a simple jump, not a jump to subroutine.
23636 For the 386, @var{exception_address} should be installed as an interrupt
23637 gate so that interrupts are masked while the handler runs. The gate
23638 should be at privilege level 0 (the most privileged level). The
23639 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23640 help from @code{exceptionHandler}.
23642 @item void flush_i_cache()
23643 @findex flush_i_cache
23644 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23645 instruction cache, if any, on your target machine. If there is no
23646 instruction cache, this subroutine may be a no-op.
23648 On target machines that have instruction caches, @value{GDBN} requires this
23649 function to make certain that the state of your program is stable.
23653 You must also make sure this library routine is available:
23656 @item void *memset(void *, int, int)
23658 This is the standard library function @code{memset} that sets an area of
23659 memory to a known value. If you have one of the free versions of
23660 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23661 either obtain it from your hardware manufacturer, or write your own.
23664 If you do not use the GNU C compiler, you may need other standard
23665 library subroutines as well; this varies from one stub to another,
23666 but in general the stubs are likely to use any of the common library
23667 subroutines which @code{@value{NGCC}} generates as inline code.
23670 @node Debug Session
23671 @subsection Putting it All Together
23673 @cindex remote serial debugging summary
23674 In summary, when your program is ready to debug, you must follow these
23679 Make sure you have defined the supporting low-level routines
23680 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23682 @code{getDebugChar}, @code{putDebugChar},
23683 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23687 Insert these lines in your program's startup code, before the main
23688 procedure is called:
23695 On some machines, when a breakpoint trap is raised, the hardware
23696 automatically makes the PC point to the instruction after the
23697 breakpoint. If your machine doesn't do that, you may need to adjust
23698 @code{handle_exception} to arrange for it to return to the instruction
23699 after the breakpoint on this first invocation, so that your program
23700 doesn't keep hitting the initial breakpoint instead of making
23704 For the 680x0 stub only, you need to provide a variable called
23705 @code{exceptionHook}. Normally you just use:
23708 void (*exceptionHook)() = 0;
23712 but if before calling @code{set_debug_traps}, you set it to point to a
23713 function in your program, that function is called when
23714 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23715 error). The function indicated by @code{exceptionHook} is called with
23716 one parameter: an @code{int} which is the exception number.
23719 Compile and link together: your program, the @value{GDBN} debugging stub for
23720 your target architecture, and the supporting subroutines.
23723 Make sure you have a serial connection between your target machine and
23724 the @value{GDBN} host, and identify the serial port on the host.
23727 @c The "remote" target now provides a `load' command, so we should
23728 @c document that. FIXME.
23729 Download your program to your target machine (or get it there by
23730 whatever means the manufacturer provides), and start it.
23733 Start @value{GDBN} on the host, and connect to the target
23734 (@pxref{Connecting,,Connecting to a Remote Target}).
23738 @node Configurations
23739 @chapter Configuration-Specific Information
23741 While nearly all @value{GDBN} commands are available for all native and
23742 cross versions of the debugger, there are some exceptions. This chapter
23743 describes things that are only available in certain configurations.
23745 There are three major categories of configurations: native
23746 configurations, where the host and target are the same, embedded
23747 operating system configurations, which are usually the same for several
23748 different processor architectures, and bare embedded processors, which
23749 are quite different from each other.
23754 * Embedded Processors::
23761 This section describes details specific to particular native
23765 * BSD libkvm Interface:: Debugging BSD kernel memory images
23766 * Process Information:: Process information
23767 * DJGPP Native:: Features specific to the DJGPP port
23768 * Cygwin Native:: Features specific to the Cygwin port
23769 * Hurd Native:: Features specific to @sc{gnu} Hurd
23770 * Darwin:: Features specific to Darwin
23771 * FreeBSD:: Features specific to FreeBSD
23774 @node BSD libkvm Interface
23775 @subsection BSD libkvm Interface
23778 @cindex kernel memory image
23779 @cindex kernel crash dump
23781 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23782 interface that provides a uniform interface for accessing kernel virtual
23783 memory images, including live systems and crash dumps. @value{GDBN}
23784 uses this interface to allow you to debug live kernels and kernel crash
23785 dumps on many native BSD configurations. This is implemented as a
23786 special @code{kvm} debugging target. For debugging a live system, load
23787 the currently running kernel into @value{GDBN} and connect to the
23791 (@value{GDBP}) @b{target kvm}
23794 For debugging crash dumps, provide the file name of the crash dump as an
23798 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23801 Once connected to the @code{kvm} target, the following commands are
23807 Set current context from the @dfn{Process Control Block} (PCB) address.
23810 Set current context from proc address. This command isn't available on
23811 modern FreeBSD systems.
23814 @node Process Information
23815 @subsection Process Information
23817 @cindex examine process image
23818 @cindex process info via @file{/proc}
23820 Some operating systems provide interfaces to fetch additional
23821 information about running processes beyond memory and per-thread
23822 register state. If @value{GDBN} is configured for an operating system
23823 with a supported interface, the command @code{info proc} is available
23824 to report information about the process running your program, or about
23825 any process running on your system.
23827 One supported interface is a facility called @samp{/proc} that can be
23828 used to examine the image of a running process using file-system
23829 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23832 On FreeBSD and NetBSD systems, system control nodes are used to query
23833 process information.
23835 In addition, some systems may provide additional process information
23836 in core files. Note that a core file may include a subset of the
23837 information available from a live process. Process information is
23838 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23845 @itemx info proc @var{process-id}
23846 Summarize available information about a process. If a
23847 process ID is specified by @var{process-id}, display information about
23848 that process; otherwise display information about the program being
23849 debugged. The summary includes the debugged process ID, the command
23850 line used to invoke it, its current working directory, and its
23851 executable file's absolute file name.
23853 On some systems, @var{process-id} can be of the form
23854 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23855 within a process. If the optional @var{pid} part is missing, it means
23856 a thread from the process being debugged (the leading @samp{/} still
23857 needs to be present, or else @value{GDBN} will interpret the number as
23858 a process ID rather than a thread ID).
23860 @item info proc cmdline
23861 @cindex info proc cmdline
23862 Show the original command line of the process. This command is
23863 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23865 @item info proc cwd
23866 @cindex info proc cwd
23867 Show the current working directory of the process. This command is
23868 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23870 @item info proc exe
23871 @cindex info proc exe
23872 Show the name of executable of the process. This command is supported
23873 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23875 @item info proc files
23876 @cindex info proc files
23877 Show the file descriptors open by the process. For each open file
23878 descriptor, @value{GDBN} shows its number, type (file, directory,
23879 character device, socket), file pointer offset, and the name of the
23880 resource open on the descriptor. The resource name can be a file name
23881 (for files, directories, and devices) or a protocol followed by socket
23882 address (for network connections). This command is supported on
23885 This example shows the open file descriptors for a process using a
23886 tty for standard input and output as well as two network sockets:
23889 (gdb) info proc files 22136
23893 FD Type Offset Flags Name
23894 text file - r-------- /usr/bin/ssh
23895 ctty chr - rw------- /dev/pts/20
23896 cwd dir - r-------- /usr/home/john
23897 root dir - r-------- /
23898 0 chr 0x32933a4 rw------- /dev/pts/20
23899 1 chr 0x32933a4 rw------- /dev/pts/20
23900 2 chr 0x32933a4 rw------- /dev/pts/20
23901 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23902 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23905 @item info proc mappings
23906 @cindex memory address space mappings
23907 Report the memory address space ranges accessible in a process. On
23908 Solaris, FreeBSD and NetBSD systems, each memory range includes information
23909 on whether the process has read, write, or execute access rights to each
23910 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23911 includes the object file which is mapped to that range.
23913 @item info proc stat
23914 @itemx info proc status
23915 @cindex process detailed status information
23916 Show additional process-related information, including the user ID and
23917 group ID; virtual memory usage; the signals that are pending, blocked,
23918 and ignored; its TTY; its consumption of system and user time; its
23919 stack size; its @samp{nice} value; etc. These commands are supported
23920 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23922 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23923 information (type @kbd{man 5 proc} from your shell prompt).
23925 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23926 @code{info proc status}.
23928 @item info proc all
23929 Show all the information about the process described under all of the
23930 above @code{info proc} subcommands.
23933 @comment These sub-options of 'info proc' were not included when
23934 @comment procfs.c was re-written. Keep their descriptions around
23935 @comment against the day when someone finds the time to put them back in.
23936 @kindex info proc times
23937 @item info proc times
23938 Starting time, user CPU time, and system CPU time for your program and
23941 @kindex info proc id
23943 Report on the process IDs related to your program: its own process ID,
23944 the ID of its parent, the process group ID, and the session ID.
23947 @item set procfs-trace
23948 @kindex set procfs-trace
23949 @cindex @code{procfs} API calls
23950 This command enables and disables tracing of @code{procfs} API calls.
23952 @item show procfs-trace
23953 @kindex show procfs-trace
23954 Show the current state of @code{procfs} API call tracing.
23956 @item set procfs-file @var{file}
23957 @kindex set procfs-file
23958 Tell @value{GDBN} to write @code{procfs} API trace to the named
23959 @var{file}. @value{GDBN} appends the trace info to the previous
23960 contents of the file. The default is to display the trace on the
23963 @item show procfs-file
23964 @kindex show procfs-file
23965 Show the file to which @code{procfs} API trace is written.
23967 @item proc-trace-entry
23968 @itemx proc-trace-exit
23969 @itemx proc-untrace-entry
23970 @itemx proc-untrace-exit
23971 @kindex proc-trace-entry
23972 @kindex proc-trace-exit
23973 @kindex proc-untrace-entry
23974 @kindex proc-untrace-exit
23975 These commands enable and disable tracing of entries into and exits
23976 from the @code{syscall} interface.
23979 @kindex info pidlist
23980 @cindex process list, QNX Neutrino
23981 For QNX Neutrino only, this command displays the list of all the
23982 processes and all the threads within each process.
23985 @kindex info meminfo
23986 @cindex mapinfo list, QNX Neutrino
23987 For QNX Neutrino only, this command displays the list of all mapinfos.
23991 @subsection Features for Debugging @sc{djgpp} Programs
23992 @cindex @sc{djgpp} debugging
23993 @cindex native @sc{djgpp} debugging
23994 @cindex MS-DOS-specific commands
23997 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23998 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23999 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
24000 top of real-mode DOS systems and their emulations.
24002 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
24003 defines a few commands specific to the @sc{djgpp} port. This
24004 subsection describes those commands.
24009 This is a prefix of @sc{djgpp}-specific commands which print
24010 information about the target system and important OS structures.
24013 @cindex MS-DOS system info
24014 @cindex free memory information (MS-DOS)
24015 @item info dos sysinfo
24016 This command displays assorted information about the underlying
24017 platform: the CPU type and features, the OS version and flavor, the
24018 DPMI version, and the available conventional and DPMI memory.
24023 @cindex segment descriptor tables
24024 @cindex descriptor tables display
24026 @itemx info dos ldt
24027 @itemx info dos idt
24028 These 3 commands display entries from, respectively, Global, Local,
24029 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
24030 tables are data structures which store a descriptor for each segment
24031 that is currently in use. The segment's selector is an index into a
24032 descriptor table; the table entry for that index holds the
24033 descriptor's base address and limit, and its attributes and access
24036 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
24037 segment (used for both data and the stack), and a DOS segment (which
24038 allows access to DOS/BIOS data structures and absolute addresses in
24039 conventional memory). However, the DPMI host will usually define
24040 additional segments in order to support the DPMI environment.
24042 @cindex garbled pointers
24043 These commands allow to display entries from the descriptor tables.
24044 Without an argument, all entries from the specified table are
24045 displayed. An argument, which should be an integer expression, means
24046 display a single entry whose index is given by the argument. For
24047 example, here's a convenient way to display information about the
24048 debugged program's data segment:
24051 @exdent @code{(@value{GDBP}) info dos ldt $ds}
24052 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
24056 This comes in handy when you want to see whether a pointer is outside
24057 the data segment's limit (i.e.@: @dfn{garbled}).
24059 @cindex page tables display (MS-DOS)
24061 @itemx info dos pte
24062 These two commands display entries from, respectively, the Page
24063 Directory and the Page Tables. Page Directories and Page Tables are
24064 data structures which control how virtual memory addresses are mapped
24065 into physical addresses. A Page Table includes an entry for every
24066 page of memory that is mapped into the program's address space; there
24067 may be several Page Tables, each one holding up to 4096 entries. A
24068 Page Directory has up to 4096 entries, one each for every Page Table
24069 that is currently in use.
24071 Without an argument, @kbd{info dos pde} displays the entire Page
24072 Directory, and @kbd{info dos pte} displays all the entries in all of
24073 the Page Tables. An argument, an integer expression, given to the
24074 @kbd{info dos pde} command means display only that entry from the Page
24075 Directory table. An argument given to the @kbd{info dos pte} command
24076 means display entries from a single Page Table, the one pointed to by
24077 the specified entry in the Page Directory.
24079 @cindex direct memory access (DMA) on MS-DOS
24080 These commands are useful when your program uses @dfn{DMA} (Direct
24081 Memory Access), which needs physical addresses to program the DMA
24084 These commands are supported only with some DPMI servers.
24086 @cindex physical address from linear address
24087 @item info dos address-pte @var{addr}
24088 This command displays the Page Table entry for a specified linear
24089 address. The argument @var{addr} is a linear address which should
24090 already have the appropriate segment's base address added to it,
24091 because this command accepts addresses which may belong to @emph{any}
24092 segment. For example, here's how to display the Page Table entry for
24093 the page where a variable @code{i} is stored:
24096 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
24097 @exdent @code{Page Table entry for address 0x11a00d30:}
24098 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
24102 This says that @code{i} is stored at offset @code{0xd30} from the page
24103 whose physical base address is @code{0x02698000}, and shows all the
24104 attributes of that page.
24106 Note that you must cast the addresses of variables to a @code{char *},
24107 since otherwise the value of @code{__djgpp_base_address}, the base
24108 address of all variables and functions in a @sc{djgpp} program, will
24109 be added using the rules of C pointer arithmetics: if @code{i} is
24110 declared an @code{int}, @value{GDBN} will add 4 times the value of
24111 @code{__djgpp_base_address} to the address of @code{i}.
24113 Here's another example, it displays the Page Table entry for the
24117 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
24118 @exdent @code{Page Table entry for address 0x29110:}
24119 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
24123 (The @code{+ 3} offset is because the transfer buffer's address is the
24124 3rd member of the @code{_go32_info_block} structure.) The output
24125 clearly shows that this DPMI server maps the addresses in conventional
24126 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
24127 linear (@code{0x29110}) addresses are identical.
24129 This command is supported only with some DPMI servers.
24132 @cindex DOS serial data link, remote debugging
24133 In addition to native debugging, the DJGPP port supports remote
24134 debugging via a serial data link. The following commands are specific
24135 to remote serial debugging in the DJGPP port of @value{GDBN}.
24138 @kindex set com1base
24139 @kindex set com1irq
24140 @kindex set com2base
24141 @kindex set com2irq
24142 @kindex set com3base
24143 @kindex set com3irq
24144 @kindex set com4base
24145 @kindex set com4irq
24146 @item set com1base @var{addr}
24147 This command sets the base I/O port address of the @file{COM1} serial
24150 @item set com1irq @var{irq}
24151 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24152 for the @file{COM1} serial port.
24154 There are similar commands @samp{set com2base}, @samp{set com3irq},
24155 etc.@: for setting the port address and the @code{IRQ} lines for the
24158 @kindex show com1base
24159 @kindex show com1irq
24160 @kindex show com2base
24161 @kindex show com2irq
24162 @kindex show com3base
24163 @kindex show com3irq
24164 @kindex show com4base
24165 @kindex show com4irq
24166 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24167 display the current settings of the base address and the @code{IRQ}
24168 lines used by the COM ports.
24171 @kindex info serial
24172 @cindex DOS serial port status
24173 This command prints the status of the 4 DOS serial ports. For each
24174 port, it prints whether it's active or not, its I/O base address and
24175 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24176 counts of various errors encountered so far.
24180 @node Cygwin Native
24181 @subsection Features for Debugging MS Windows PE Executables
24182 @cindex MS Windows debugging
24183 @cindex native Cygwin debugging
24184 @cindex Cygwin-specific commands
24186 @value{GDBN} supports native debugging of MS Windows programs, including
24187 DLLs with and without symbolic debugging information.
24189 @cindex Ctrl-BREAK, MS-Windows
24190 @cindex interrupt debuggee on MS-Windows
24191 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24192 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24193 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24194 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24195 sequence, which can be used to interrupt the debuggee even if it
24198 There are various additional Cygwin-specific commands, described in
24199 this section. Working with DLLs that have no debugging symbols is
24200 described in @ref{Non-debug DLL Symbols}.
24205 This is a prefix of MS Windows-specific commands which print
24206 information about the target system and important OS structures.
24208 @item info w32 selector
24209 This command displays information returned by
24210 the Win32 API @code{GetThreadSelectorEntry} function.
24211 It takes an optional argument that is evaluated to
24212 a long value to give the information about this given selector.
24213 Without argument, this command displays information
24214 about the six segment registers.
24216 @item info w32 thread-information-block
24217 This command displays thread specific information stored in the
24218 Thread Information Block (readable on the X86 CPU family using @code{$fs}
24219 selector for 32-bit programs and @code{$gs} for 64-bit programs).
24221 @kindex signal-event
24222 @item signal-event @var{id}
24223 This command signals an event with user-provided @var{id}. Used to resume
24224 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24226 To use it, create or edit the following keys in
24227 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24228 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24229 (for x86_64 versions):
24233 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
24234 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24235 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
24237 The first @code{%ld} will be replaced by the process ID of the
24238 crashing process, the second @code{%ld} will be replaced by the ID of
24239 the event that blocks the crashing process, waiting for @value{GDBN}
24243 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24244 make the system run debugger specified by the Debugger key
24245 automatically, @code{0} will cause a dialog box with ``OK'' and
24246 ``Cancel'' buttons to appear, which allows the user to either
24247 terminate the crashing process (OK) or debug it (Cancel).
24250 @kindex set cygwin-exceptions
24251 @cindex debugging the Cygwin DLL
24252 @cindex Cygwin DLL, debugging
24253 @item set cygwin-exceptions @var{mode}
24254 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24255 happen inside the Cygwin DLL. If @var{mode} is @code{off},
24256 @value{GDBN} will delay recognition of exceptions, and may ignore some
24257 exceptions which seem to be caused by internal Cygwin DLL
24258 ``bookkeeping''. This option is meant primarily for debugging the
24259 Cygwin DLL itself; the default value is @code{off} to avoid annoying
24260 @value{GDBN} users with false @code{SIGSEGV} signals.
24262 @kindex show cygwin-exceptions
24263 @item show cygwin-exceptions
24264 Displays whether @value{GDBN} will break on exceptions that happen
24265 inside the Cygwin DLL itself.
24267 @kindex set new-console
24268 @item set new-console @var{mode}
24269 If @var{mode} is @code{on} the debuggee will
24270 be started in a new console on next start.
24271 If @var{mode} is @code{off}, the debuggee will
24272 be started in the same console as the debugger.
24274 @kindex show new-console
24275 @item show new-console
24276 Displays whether a new console is used
24277 when the debuggee is started.
24279 @kindex set new-group
24280 @item set new-group @var{mode}
24281 This boolean value controls whether the debuggee should
24282 start a new group or stay in the same group as the debugger.
24283 This affects the way the Windows OS handles
24286 @kindex show new-group
24287 @item show new-group
24288 Displays current value of new-group boolean.
24290 @kindex set debugevents
24291 @item set debugevents
24292 This boolean value adds debug output concerning kernel events related
24293 to the debuggee seen by the debugger. This includes events that
24294 signal thread and process creation and exit, DLL loading and
24295 unloading, console interrupts, and debugging messages produced by the
24296 Windows @code{OutputDebugString} API call.
24298 @kindex set debugexec
24299 @item set debugexec
24300 This boolean value adds debug output concerning execute events
24301 (such as resume thread) seen by the debugger.
24303 @kindex set debugexceptions
24304 @item set debugexceptions
24305 This boolean value adds debug output concerning exceptions in the
24306 debuggee seen by the debugger.
24308 @kindex set debugmemory
24309 @item set debugmemory
24310 This boolean value adds debug output concerning debuggee memory reads
24311 and writes by the debugger.
24315 This boolean values specifies whether the debuggee is called
24316 via a shell or directly (default value is on).
24320 Displays if the debuggee will be started with a shell.
24325 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
24328 @node Non-debug DLL Symbols
24329 @subsubsection Support for DLLs without Debugging Symbols
24330 @cindex DLLs with no debugging symbols
24331 @cindex Minimal symbols and DLLs
24333 Very often on windows, some of the DLLs that your program relies on do
24334 not include symbolic debugging information (for example,
24335 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24336 symbols in a DLL, it relies on the minimal amount of symbolic
24337 information contained in the DLL's export table. This section
24338 describes working with such symbols, known internally to @value{GDBN} as
24339 ``minimal symbols''.
24341 Note that before the debugged program has started execution, no DLLs
24342 will have been loaded. The easiest way around this problem is simply to
24343 start the program --- either by setting a breakpoint or letting the
24344 program run once to completion.
24346 @subsubsection DLL Name Prefixes
24348 In keeping with the naming conventions used by the Microsoft debugging
24349 tools, DLL export symbols are made available with a prefix based on the
24350 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24351 also entered into the symbol table, so @code{CreateFileA} is often
24352 sufficient. In some cases there will be name clashes within a program
24353 (particularly if the executable itself includes full debugging symbols)
24354 necessitating the use of the fully qualified name when referring to the
24355 contents of the DLL. Use single-quotes around the name to avoid the
24356 exclamation mark (``!'') being interpreted as a language operator.
24358 Note that the internal name of the DLL may be all upper-case, even
24359 though the file name of the DLL is lower-case, or vice-versa. Since
24360 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24361 some confusion. If in doubt, try the @code{info functions} and
24362 @code{info variables} commands or even @code{maint print msymbols}
24363 (@pxref{Symbols}). Here's an example:
24366 (@value{GDBP}) info function CreateFileA
24367 All functions matching regular expression "CreateFileA":
24369 Non-debugging symbols:
24370 0x77e885f4 CreateFileA
24371 0x77e885f4 KERNEL32!CreateFileA
24375 (@value{GDBP}) info function !
24376 All functions matching regular expression "!":
24378 Non-debugging symbols:
24379 0x6100114c cygwin1!__assert
24380 0x61004034 cygwin1!_dll_crt0@@0
24381 0x61004240 cygwin1!dll_crt0(per_process *)
24385 @subsubsection Working with Minimal Symbols
24387 Symbols extracted from a DLL's export table do not contain very much
24388 type information. All that @value{GDBN} can do is guess whether a symbol
24389 refers to a function or variable depending on the linker section that
24390 contains the symbol. Also note that the actual contents of the memory
24391 contained in a DLL are not available unless the program is running. This
24392 means that you cannot examine the contents of a variable or disassemble
24393 a function within a DLL without a running program.
24395 Variables are generally treated as pointers and dereferenced
24396 automatically. For this reason, it is often necessary to prefix a
24397 variable name with the address-of operator (``&'') and provide explicit
24398 type information in the command. Here's an example of the type of
24402 (@value{GDBP}) print 'cygwin1!__argv'
24403 'cygwin1!__argv' has unknown type; cast it to its declared type
24407 (@value{GDBP}) x 'cygwin1!__argv'
24408 'cygwin1!__argv' has unknown type; cast it to its declared type
24411 And two possible solutions:
24414 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24415 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24419 (@value{GDBP}) x/2x &'cygwin1!__argv'
24420 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24421 (@value{GDBP}) x/x 0x10021608
24422 0x10021608: 0x0022fd98
24423 (@value{GDBP}) x/s 0x0022fd98
24424 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24427 Setting a break point within a DLL is possible even before the program
24428 starts execution. However, under these circumstances, @value{GDBN} can't
24429 examine the initial instructions of the function in order to skip the
24430 function's frame set-up code. You can work around this by using ``*&''
24431 to set the breakpoint at a raw memory address:
24434 (@value{GDBP}) break *&'python22!PyOS_Readline'
24435 Breakpoint 1 at 0x1e04eff0
24438 The author of these extensions is not entirely convinced that setting a
24439 break point within a shared DLL like @file{kernel32.dll} is completely
24443 @subsection Commands Specific to @sc{gnu} Hurd Systems
24444 @cindex @sc{gnu} Hurd debugging
24446 This subsection describes @value{GDBN} commands specific to the
24447 @sc{gnu} Hurd native debugging.
24452 @kindex set signals@r{, Hurd command}
24453 @kindex set sigs@r{, Hurd command}
24454 This command toggles the state of inferior signal interception by
24455 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24456 affected by this command. @code{sigs} is a shorthand alias for
24461 @kindex show signals@r{, Hurd command}
24462 @kindex show sigs@r{, Hurd command}
24463 Show the current state of intercepting inferior's signals.
24465 @item set signal-thread
24466 @itemx set sigthread
24467 @kindex set signal-thread
24468 @kindex set sigthread
24469 This command tells @value{GDBN} which thread is the @code{libc} signal
24470 thread. That thread is run when a signal is delivered to a running
24471 process. @code{set sigthread} is the shorthand alias of @code{set
24474 @item show signal-thread
24475 @itemx show sigthread
24476 @kindex show signal-thread
24477 @kindex show sigthread
24478 These two commands show which thread will run when the inferior is
24479 delivered a signal.
24482 @kindex set stopped@r{, Hurd command}
24483 This commands tells @value{GDBN} that the inferior process is stopped,
24484 as with the @code{SIGSTOP} signal. The stopped process can be
24485 continued by delivering a signal to it.
24488 @kindex show stopped@r{, Hurd command}
24489 This command shows whether @value{GDBN} thinks the debuggee is
24492 @item set exceptions
24493 @kindex set exceptions@r{, Hurd command}
24494 Use this command to turn off trapping of exceptions in the inferior.
24495 When exception trapping is off, neither breakpoints nor
24496 single-stepping will work. To restore the default, set exception
24499 @item show exceptions
24500 @kindex show exceptions@r{, Hurd command}
24501 Show the current state of trapping exceptions in the inferior.
24503 @item set task pause
24504 @kindex set task@r{, Hurd commands}
24505 @cindex task attributes (@sc{gnu} Hurd)
24506 @cindex pause current task (@sc{gnu} Hurd)
24507 This command toggles task suspension when @value{GDBN} has control.
24508 Setting it to on takes effect immediately, and the task is suspended
24509 whenever @value{GDBN} gets control. Setting it to off will take
24510 effect the next time the inferior is continued. If this option is set
24511 to off, you can use @code{set thread default pause on} or @code{set
24512 thread pause on} (see below) to pause individual threads.
24514 @item show task pause
24515 @kindex show task@r{, Hurd commands}
24516 Show the current state of task suspension.
24518 @item set task detach-suspend-count
24519 @cindex task suspend count
24520 @cindex detach from task, @sc{gnu} Hurd
24521 This command sets the suspend count the task will be left with when
24522 @value{GDBN} detaches from it.
24524 @item show task detach-suspend-count
24525 Show the suspend count the task will be left with when detaching.
24527 @item set task exception-port
24528 @itemx set task excp
24529 @cindex task exception port, @sc{gnu} Hurd
24530 This command sets the task exception port to which @value{GDBN} will
24531 forward exceptions. The argument should be the value of the @dfn{send
24532 rights} of the task. @code{set task excp} is a shorthand alias.
24534 @item set noninvasive
24535 @cindex noninvasive task options
24536 This command switches @value{GDBN} to a mode that is the least
24537 invasive as far as interfering with the inferior is concerned. This
24538 is the same as using @code{set task pause}, @code{set exceptions}, and
24539 @code{set signals} to values opposite to the defaults.
24541 @item info send-rights
24542 @itemx info receive-rights
24543 @itemx info port-rights
24544 @itemx info port-sets
24545 @itemx info dead-names
24548 @cindex send rights, @sc{gnu} Hurd
24549 @cindex receive rights, @sc{gnu} Hurd
24550 @cindex port rights, @sc{gnu} Hurd
24551 @cindex port sets, @sc{gnu} Hurd
24552 @cindex dead names, @sc{gnu} Hurd
24553 These commands display information about, respectively, send rights,
24554 receive rights, port rights, port sets, and dead names of a task.
24555 There are also shorthand aliases: @code{info ports} for @code{info
24556 port-rights} and @code{info psets} for @code{info port-sets}.
24558 @item set thread pause
24559 @kindex set thread@r{, Hurd command}
24560 @cindex thread properties, @sc{gnu} Hurd
24561 @cindex pause current thread (@sc{gnu} Hurd)
24562 This command toggles current thread suspension when @value{GDBN} has
24563 control. Setting it to on takes effect immediately, and the current
24564 thread is suspended whenever @value{GDBN} gets control. Setting it to
24565 off will take effect the next time the inferior is continued.
24566 Normally, this command has no effect, since when @value{GDBN} has
24567 control, the whole task is suspended. However, if you used @code{set
24568 task pause off} (see above), this command comes in handy to suspend
24569 only the current thread.
24571 @item show thread pause
24572 @kindex show thread@r{, Hurd command}
24573 This command shows the state of current thread suspension.
24575 @item set thread run
24576 This command sets whether the current thread is allowed to run.
24578 @item show thread run
24579 Show whether the current thread is allowed to run.
24581 @item set thread detach-suspend-count
24582 @cindex thread suspend count, @sc{gnu} Hurd
24583 @cindex detach from thread, @sc{gnu} Hurd
24584 This command sets the suspend count @value{GDBN} will leave on a
24585 thread when detaching. This number is relative to the suspend count
24586 found by @value{GDBN} when it notices the thread; use @code{set thread
24587 takeover-suspend-count} to force it to an absolute value.
24589 @item show thread detach-suspend-count
24590 Show the suspend count @value{GDBN} will leave on the thread when
24593 @item set thread exception-port
24594 @itemx set thread excp
24595 Set the thread exception port to which to forward exceptions. This
24596 overrides the port set by @code{set task exception-port} (see above).
24597 @code{set thread excp} is the shorthand alias.
24599 @item set thread takeover-suspend-count
24600 Normally, @value{GDBN}'s thread suspend counts are relative to the
24601 value @value{GDBN} finds when it notices each thread. This command
24602 changes the suspend counts to be absolute instead.
24604 @item set thread default
24605 @itemx show thread default
24606 @cindex thread default settings, @sc{gnu} Hurd
24607 Each of the above @code{set thread} commands has a @code{set thread
24608 default} counterpart (e.g., @code{set thread default pause}, @code{set
24609 thread default exception-port}, etc.). The @code{thread default}
24610 variety of commands sets the default thread properties for all
24611 threads; you can then change the properties of individual threads with
24612 the non-default commands.
24619 @value{GDBN} provides the following commands specific to the Darwin target:
24622 @item set debug darwin @var{num}
24623 @kindex set debug darwin
24624 When set to a non zero value, enables debugging messages specific to
24625 the Darwin support. Higher values produce more verbose output.
24627 @item show debug darwin
24628 @kindex show debug darwin
24629 Show the current state of Darwin messages.
24631 @item set debug mach-o @var{num}
24632 @kindex set debug mach-o
24633 When set to a non zero value, enables debugging messages while
24634 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24635 file format used on Darwin for object and executable files.) Higher
24636 values produce more verbose output. This is a command to diagnose
24637 problems internal to @value{GDBN} and should not be needed in normal
24640 @item show debug mach-o
24641 @kindex show debug mach-o
24642 Show the current state of Mach-O file messages.
24644 @item set mach-exceptions on
24645 @itemx set mach-exceptions off
24646 @kindex set mach-exceptions
24647 On Darwin, faults are first reported as a Mach exception and are then
24648 mapped to a Posix signal. Use this command to turn on trapping of
24649 Mach exceptions in the inferior. This might be sometimes useful to
24650 better understand the cause of a fault. The default is off.
24652 @item show mach-exceptions
24653 @kindex show mach-exceptions
24654 Show the current state of exceptions trapping.
24658 @subsection FreeBSD
24661 When the ABI of a system call is changed in the FreeBSD kernel, this
24662 is implemented by leaving a compatibility system call using the old
24663 ABI at the existing number and allocating a new system call number for
24664 the version using the new ABI. As a convenience, when a system call
24665 is caught by name (@pxref{catch syscall}), compatibility system calls
24668 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24669 system call and catching the @code{kevent} system call by name catches
24673 (@value{GDBP}) catch syscall kevent
24674 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24680 @section Embedded Operating Systems
24682 This section describes configurations involving the debugging of
24683 embedded operating systems that are available for several different
24686 @value{GDBN} includes the ability to debug programs running on
24687 various real-time operating systems.
24689 @node Embedded Processors
24690 @section Embedded Processors
24692 This section goes into details specific to particular embedded
24695 @cindex send command to simulator
24696 Whenever a specific embedded processor has a simulator, @value{GDBN}
24697 allows to send an arbitrary command to the simulator.
24700 @item sim @var{command}
24701 @kindex sim@r{, a command}
24702 Send an arbitrary @var{command} string to the simulator. Consult the
24703 documentation for the specific simulator in use for information about
24704 acceptable commands.
24709 * ARC:: Synopsys ARC
24712 * M68K:: Motorola M68K
24713 * MicroBlaze:: Xilinx MicroBlaze
24714 * MIPS Embedded:: MIPS Embedded
24715 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24716 * PowerPC Embedded:: PowerPC Embedded
24719 * Super-H:: Renesas Super-H
24723 @subsection Synopsys ARC
24724 @cindex Synopsys ARC
24725 @cindex ARC specific commands
24731 @value{GDBN} provides the following ARC-specific commands:
24734 @item set debug arc
24735 @kindex set debug arc
24736 Control the level of ARC specific debug messages. Use 0 for no messages (the
24737 default), 1 for debug messages, and 2 for even more debug messages.
24739 @item show debug arc
24740 @kindex show debug arc
24741 Show the level of ARC specific debugging in operation.
24743 @item maint print arc arc-instruction @var{address}
24744 @kindex maint print arc arc-instruction
24745 Print internal disassembler information about instruction at a given address.
24752 @value{GDBN} provides the following ARM-specific commands:
24755 @item set arm disassembler
24757 This commands selects from a list of disassembly styles. The
24758 @code{"std"} style is the standard style.
24760 @item show arm disassembler
24762 Show the current disassembly style.
24764 @item set arm apcs32
24765 @cindex ARM 32-bit mode
24766 This command toggles ARM operation mode between 32-bit and 26-bit.
24768 @item show arm apcs32
24769 Display the current usage of the ARM 32-bit mode.
24771 @item set arm fpu @var{fputype}
24772 This command sets the ARM floating-point unit (FPU) type. The
24773 argument @var{fputype} can be one of these:
24777 Determine the FPU type by querying the OS ABI.
24779 Software FPU, with mixed-endian doubles on little-endian ARM
24782 GCC-compiled FPA co-processor.
24784 Software FPU with pure-endian doubles.
24790 Show the current type of the FPU.
24793 This command forces @value{GDBN} to use the specified ABI.
24796 Show the currently used ABI.
24798 @item set arm fallback-mode (arm|thumb|auto)
24799 @value{GDBN} uses the symbol table, when available, to determine
24800 whether instructions are ARM or Thumb. This command controls
24801 @value{GDBN}'s default behavior when the symbol table is not
24802 available. The default is @samp{auto}, which causes @value{GDBN} to
24803 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24806 @item show arm fallback-mode
24807 Show the current fallback instruction mode.
24809 @item set arm force-mode (arm|thumb|auto)
24810 This command overrides use of the symbol table to determine whether
24811 instructions are ARM or Thumb. The default is @samp{auto}, which
24812 causes @value{GDBN} to use the symbol table and then the setting
24813 of @samp{set arm fallback-mode}.
24815 @item show arm force-mode
24816 Show the current forced instruction mode.
24818 @item set debug arm
24819 Toggle whether to display ARM-specific debugging messages from the ARM
24820 target support subsystem.
24822 @item show debug arm
24823 Show whether ARM-specific debugging messages are enabled.
24827 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24828 The @value{GDBN} ARM simulator accepts the following optional arguments.
24831 @item --swi-support=@var{type}
24832 Tell the simulator which SWI interfaces to support. The argument
24833 @var{type} may be a comma separated list of the following values.
24834 The default value is @code{all}.
24850 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24851 The @value{GDBN} BPF simulator accepts the following optional arguments.
24854 @item --skb-data-offset=@var{offset}
24855 Tell the simulator the offset, measured in bytes, of the
24856 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
24857 This offset is used by some BPF specific-purpose load/store
24858 instructions. Defaults to 0.
24865 The Motorola m68k configuration includes ColdFire support.
24868 @subsection MicroBlaze
24869 @cindex Xilinx MicroBlaze
24870 @cindex XMD, Xilinx Microprocessor Debugger
24872 The MicroBlaze is a soft-core processor supported on various Xilinx
24873 FPGAs, such as Spartan or Virtex series. Boards with these processors
24874 usually have JTAG ports which connect to a host system running the Xilinx
24875 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24876 This host system is used to download the configuration bitstream to
24877 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24878 communicates with the target board using the JTAG interface and
24879 presents a @code{gdbserver} interface to the board. By default
24880 @code{xmd} uses port @code{1234}. (While it is possible to change
24881 this default port, it requires the use of undocumented @code{xmd}
24882 commands. Contact Xilinx support if you need to do this.)
24884 Use these GDB commands to connect to the MicroBlaze target processor.
24887 @item target remote :1234
24888 Use this command to connect to the target if you are running @value{GDBN}
24889 on the same system as @code{xmd}.
24891 @item target remote @var{xmd-host}:1234
24892 Use this command to connect to the target if it is connected to @code{xmd}
24893 running on a different system named @var{xmd-host}.
24896 Use this command to download a program to the MicroBlaze target.
24898 @item set debug microblaze @var{n}
24899 Enable MicroBlaze-specific debugging messages if non-zero.
24901 @item show debug microblaze @var{n}
24902 Show MicroBlaze-specific debugging level.
24905 @node MIPS Embedded
24906 @subsection @acronym{MIPS} Embedded
24909 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24912 @item set mipsfpu double
24913 @itemx set mipsfpu single
24914 @itemx set mipsfpu none
24915 @itemx set mipsfpu auto
24916 @itemx show mipsfpu
24917 @kindex set mipsfpu
24918 @kindex show mipsfpu
24919 @cindex @acronym{MIPS} remote floating point
24920 @cindex floating point, @acronym{MIPS} remote
24921 If your target board does not support the @acronym{MIPS} floating point
24922 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24923 need this, you may wish to put the command in your @value{GDBN} init
24924 file). This tells @value{GDBN} how to find the return value of
24925 functions which return floating point values. It also allows
24926 @value{GDBN} to avoid saving the floating point registers when calling
24927 functions on the board. If you are using a floating point coprocessor
24928 with only single precision floating point support, as on the @sc{r4650}
24929 processor, use the command @samp{set mipsfpu single}. The default
24930 double precision floating point coprocessor may be selected using
24931 @samp{set mipsfpu double}.
24933 In previous versions the only choices were double precision or no
24934 floating point, so @samp{set mipsfpu on} will select double precision
24935 and @samp{set mipsfpu off} will select no floating point.
24937 As usual, you can inquire about the @code{mipsfpu} variable with
24938 @samp{show mipsfpu}.
24941 @node OpenRISC 1000
24942 @subsection OpenRISC 1000
24943 @cindex OpenRISC 1000
24946 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24947 mainly provided as a soft-core which can run on Xilinx, Altera and other
24950 @value{GDBN} for OpenRISC supports the below commands when connecting to
24958 Runs the builtin CPU simulator which can run very basic
24959 programs but does not support most hardware functions like MMU.
24960 For more complex use cases the user is advised to run an external
24961 target, and connect using @samp{target remote}.
24963 Example: @code{target sim}
24965 @item set debug or1k
24966 Toggle whether to display OpenRISC-specific debugging messages from the
24967 OpenRISC target support subsystem.
24969 @item show debug or1k
24970 Show whether OpenRISC-specific debugging messages are enabled.
24973 @node PowerPC Embedded
24974 @subsection PowerPC Embedded
24976 @cindex DVC register
24977 @value{GDBN} supports using the DVC (Data Value Compare) register to
24978 implement in hardware simple hardware watchpoint conditions of the form:
24981 (@value{GDBP}) watch @var{address|variable} \
24982 if @var{address|variable} == @var{constant expression}
24985 The DVC register will be automatically used when @value{GDBN} detects
24986 such pattern in a condition expression, and the created watchpoint uses one
24987 debug register (either the @code{exact-watchpoints} option is on and the
24988 variable is scalar, or the variable has a length of one byte). This feature
24989 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24992 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24993 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24994 in which case watchpoints using only one debug register are created when
24995 watching variables of scalar types.
24997 You can create an artificial array to watch an arbitrary memory
24998 region using one of the following commands (@pxref{Expressions}):
25001 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
25002 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
25005 PowerPC embedded processors support masked watchpoints. See the discussion
25006 about the @code{mask} argument in @ref{Set Watchpoints}.
25008 @cindex ranged breakpoint
25009 PowerPC embedded processors support hardware accelerated
25010 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
25011 the inferior whenever it executes an instruction at any address within
25012 the range it specifies. To set a ranged breakpoint in @value{GDBN},
25013 use the @code{break-range} command.
25015 @value{GDBN} provides the following PowerPC-specific commands:
25018 @kindex break-range
25019 @item break-range @var{start-location}, @var{end-location}
25020 Set a breakpoint for an address range given by
25021 @var{start-location} and @var{end-location}, which can specify a function name,
25022 a line number, an offset of lines from the current line or from the start
25023 location, or an address of an instruction (see @ref{Specify Location},
25024 for a list of all the possible ways to specify a @var{location}.)
25025 The breakpoint will stop execution of the inferior whenever it
25026 executes an instruction at any address within the specified range,
25027 (including @var{start-location} and @var{end-location}.)
25029 @kindex set powerpc
25030 @item set powerpc soft-float
25031 @itemx show powerpc soft-float
25032 Force @value{GDBN} to use (or not use) a software floating point calling
25033 convention. By default, @value{GDBN} selects the calling convention based
25034 on the selected architecture and the provided executable file.
25036 @item set powerpc vector-abi
25037 @itemx show powerpc vector-abi
25038 Force @value{GDBN} to use the specified calling convention for vector
25039 arguments and return values. The valid options are @samp{auto};
25040 @samp{generic}, to avoid vector registers even if they are present;
25041 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
25042 registers. By default, @value{GDBN} selects the calling convention
25043 based on the selected architecture and the provided executable file.
25045 @item set powerpc exact-watchpoints
25046 @itemx show powerpc exact-watchpoints
25047 Allow @value{GDBN} to use only one debug register when watching a variable
25048 of scalar type, thus assuming that the variable is accessed through the
25049 address of its first byte.
25054 @subsection Atmel AVR
25057 When configured for debugging the Atmel AVR, @value{GDBN} supports the
25058 following AVR-specific commands:
25061 @item info io_registers
25062 @kindex info io_registers@r{, AVR}
25063 @cindex I/O registers (Atmel AVR)
25064 This command displays information about the AVR I/O registers. For
25065 each register, @value{GDBN} prints its number and value.
25072 When configured for debugging CRIS, @value{GDBN} provides the
25073 following CRIS-specific commands:
25076 @item set cris-version @var{ver}
25077 @cindex CRIS version
25078 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
25079 The CRIS version affects register names and sizes. This command is useful in
25080 case autodetection of the CRIS version fails.
25082 @item show cris-version
25083 Show the current CRIS version.
25085 @item set cris-dwarf2-cfi
25086 @cindex DWARF-2 CFI and CRIS
25087 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
25088 Change to @samp{off} when using @code{gcc-cris} whose version is below
25091 @item show cris-dwarf2-cfi
25092 Show the current state of using DWARF-2 CFI.
25094 @item set cris-mode @var{mode}
25096 Set the current CRIS mode to @var{mode}. It should only be changed when
25097 debugging in guru mode, in which case it should be set to
25098 @samp{guru} (the default is @samp{normal}).
25100 @item show cris-mode
25101 Show the current CRIS mode.
25105 @subsection Renesas Super-H
25108 For the Renesas Super-H processor, @value{GDBN} provides these
25112 @item set sh calling-convention @var{convention}
25113 @kindex set sh calling-convention
25114 Set the calling-convention used when calling functions from @value{GDBN}.
25115 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
25116 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
25117 convention. If the DWARF-2 information of the called function specifies
25118 that the function follows the Renesas calling convention, the function
25119 is called using the Renesas calling convention. If the calling convention
25120 is set to @samp{renesas}, the Renesas calling convention is always used,
25121 regardless of the DWARF-2 information. This can be used to override the
25122 default of @samp{gcc} if debug information is missing, or the compiler
25123 does not emit the DWARF-2 calling convention entry for a function.
25125 @item show sh calling-convention
25126 @kindex show sh calling-convention
25127 Show the current calling convention setting.
25132 @node Architectures
25133 @section Architectures
25135 This section describes characteristics of architectures that affect
25136 all uses of @value{GDBN} with the architecture, both native and cross.
25143 * HPPA:: HP PA architecture
25151 @subsection AArch64
25152 @cindex AArch64 support
25154 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25155 following special commands:
25158 @item set debug aarch64
25159 @kindex set debug aarch64
25160 This command determines whether AArch64 architecture-specific debugging
25161 messages are to be displayed.
25163 @item show debug aarch64
25164 Show whether AArch64 debugging messages are displayed.
25168 @subsubsection AArch64 SVE.
25169 @cindex AArch64 SVE.
25171 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25172 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25173 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25174 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25175 @code{$vg} will be provided. This is the vector granule for the current thread
25176 and represents the number of 64-bit chunks in an SVE @code{z} register.
25178 If the vector length changes, then the @code{$vg} register will be updated,
25179 but the lengths of the @code{z} and @code{p} registers will not change. This
25180 is a known limitation of @value{GDBN} and does not affect the execution of the
25183 @subsubsection AArch64 Pointer Authentication.
25184 @cindex AArch64 Pointer Authentication.
25186 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25187 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25188 register @code{$lr} is pointing to an PAC function its value will be masked.
25189 When GDB prints a backtrace, any addresses that required unmasking will be
25190 postfixed with the marker [PAC]. When using the MI, this is printed as part
25191 of the @code{addr_flags} field.
25193 @subsubsection AArch64 Memory Tagging Extension.
25194 @cindex AArch64 Memory Tagging Extension.
25196 When @value{GDBN} is debugging the AArch64 architecture, the program is
25197 using the v8.5-A feature Memory Tagging Extension (MTE) and there is support
25198 in the kernel for MTE, @value{GDBN} will make memory tagging functionality
25199 available for inspection and editing of logical and allocation tags.
25200 @xref{Memory Tagging}.
25202 To aid debugging, @value{GDBN} will output additional information when SIGSEGV
25203 signals are generated as a result of memory tag failures.
25205 If the tag violation is synchronous, the following will be shown:
25208 Program received signal SIGSEGV, Segmentation fault
25209 Memory tag violation while accessing address 0x0500fffff7ff8000
25214 If the tag violation is asynchronous, the fault address is not available.
25215 In this case @value{GDBN} will show the following:
25218 Program received signal SIGSEGV, Segmentation fault
25219 Memory tag violation
25220 Fault address unavailable.
25223 A special register, @code{tag_ctl}, is made available through the
25224 @code{org.gnu.gdb.aarch64.mte} feature. This register exposes some
25225 options that can be controlled at runtime and emulates the @code{prctl}
25226 option @code{PR_SET_TAGGED_ADDR_CTRL}. For further information, see the
25227 documentation in the Linux kernel.
25230 @subsection x86 Architecture-specific Issues
25233 @item set struct-convention @var{mode}
25234 @kindex set struct-convention
25235 @cindex struct return convention
25236 @cindex struct/union returned in registers
25237 Set the convention used by the inferior to return @code{struct}s and
25238 @code{union}s from functions to @var{mode}. Possible values of
25239 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25240 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25241 are returned on the stack, while @code{"reg"} means that a
25242 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25243 be returned in a register.
25245 @item show struct-convention
25246 @kindex show struct-convention
25247 Show the current setting of the convention to return @code{struct}s
25252 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25253 @cindex Intel Memory Protection Extensions (MPX).
25255 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25256 @footnote{The register named with capital letters represent the architecture
25257 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25258 which are the lower bound and upper bound. Bounds are effective addresses or
25259 memory locations. The upper bounds are architecturally represented in 1's
25260 complement form. A bound having lower bound = 0, and upper bound = 0
25261 (1's complement of all bits set) will allow access to the entire address space.
25263 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25264 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25265 display the upper bound performing the complement of one operation on the
25266 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25267 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25268 can also be noted that the upper bounds are inclusive.
25270 As an example, assume that the register BND0 holds bounds for a pointer having
25271 access allowed for the range between 0x32 and 0x71. The values present on
25272 bnd0raw and bnd registers are presented as follows:
25275 bnd0raw = @{0x32, 0xffffffff8e@}
25276 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25279 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25280 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25281 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25282 Python, the display includes the memory size, in bits, accessible to
25285 Bounds can also be stored in bounds tables, which are stored in
25286 application memory. These tables store bounds for pointers by specifying
25287 the bounds pointer's value along with its bounds. Evaluating and changing
25288 bounds located in bound tables is therefore interesting while investigating
25289 bugs on MPX context. @value{GDBN} provides commands for this purpose:
25292 @item show mpx bound @var{pointer}
25293 @kindex show mpx bound
25294 Display bounds of the given @var{pointer}.
25296 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25297 @kindex set mpx bound
25298 Set the bounds of a pointer in the bound table.
25299 This command takes three parameters: @var{pointer} is the pointers
25300 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25301 for lower and upper bounds respectively.
25304 When you call an inferior function on an Intel MPX enabled program,
25305 GDB sets the inferior's bound registers to the init (disabled) state
25306 before calling the function. As a consequence, bounds checks for the
25307 pointer arguments passed to the function will always pass.
25309 This is necessary because when you call an inferior function, the
25310 program is usually in the middle of the execution of other function.
25311 Since at that point bound registers are in an arbitrary state, not
25312 clearing them would lead to random bound violations in the called
25315 You can still examine the influence of the bound registers on the
25316 execution of the called function by stopping the execution of the
25317 called function at its prologue, setting bound registers, and
25318 continuing the execution. For example:
25322 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25323 $ print upper (a, b, c, d, 1)
25324 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25326 @{lbound = 0x0, ubound = ffffffff@} : size -1
25329 At this last step the value of bnd0 can be changed for investigation of bound
25330 violations caused along the execution of the call. In order to know how to
25331 set the bound registers or bound table for the call consult the ABI.
25336 See the following section.
25339 @subsection @acronym{MIPS}
25341 @cindex stack on Alpha
25342 @cindex stack on @acronym{MIPS}
25343 @cindex Alpha stack
25344 @cindex @acronym{MIPS} stack
25345 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25346 sometimes requires @value{GDBN} to search backward in the object code to
25347 find the beginning of a function.
25349 @cindex response time, @acronym{MIPS} debugging
25350 To improve response time (especially for embedded applications, where
25351 @value{GDBN} may be restricted to a slow serial line for this search)
25352 you may want to limit the size of this search, using one of these
25356 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25357 @item set heuristic-fence-post @var{limit}
25358 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25359 search for the beginning of a function. A value of @var{0} (the
25360 default) means there is no limit. However, except for @var{0}, the
25361 larger the limit the more bytes @code{heuristic-fence-post} must search
25362 and therefore the longer it takes to run. You should only need to use
25363 this command when debugging a stripped executable.
25365 @item show heuristic-fence-post
25366 Display the current limit.
25370 These commands are available @emph{only} when @value{GDBN} is configured
25371 for debugging programs on Alpha or @acronym{MIPS} processors.
25373 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25377 @item set mips abi @var{arg}
25378 @kindex set mips abi
25379 @cindex set ABI for @acronym{MIPS}
25380 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
25381 values of @var{arg} are:
25385 The default ABI associated with the current binary (this is the
25395 @item show mips abi
25396 @kindex show mips abi
25397 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25399 @item set mips compression @var{arg}
25400 @kindex set mips compression
25401 @cindex code compression, @acronym{MIPS}
25402 Tell @value{GDBN} which @acronym{MIPS} compressed
25403 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25404 inferior. @value{GDBN} uses this for code disassembly and other
25405 internal interpretation purposes. This setting is only referred to
25406 when no executable has been associated with the debugging session or
25407 the executable does not provide information about the encoding it uses.
25408 Otherwise this setting is automatically updated from information
25409 provided by the executable.
25411 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25412 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25413 executables containing @acronym{MIPS16} code frequently are not
25414 identified as such.
25416 This setting is ``sticky''; that is, it retains its value across
25417 debugging sessions until reset either explicitly with this command or
25418 implicitly from an executable.
25420 The compiler and/or assembler typically add symbol table annotations to
25421 identify functions compiled for the @acronym{MIPS16} or
25422 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25423 are present, @value{GDBN} uses them in preference to the global
25424 compressed @acronym{ISA} encoding setting.
25426 @item show mips compression
25427 @kindex show mips compression
25428 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25429 @value{GDBN} to debug the inferior.
25432 @itemx show mipsfpu
25433 @xref{MIPS Embedded, set mipsfpu}.
25435 @item set mips mask-address @var{arg}
25436 @kindex set mips mask-address
25437 @cindex @acronym{MIPS} addresses, masking
25438 This command determines whether the most-significant 32 bits of 64-bit
25439 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25440 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25441 setting, which lets @value{GDBN} determine the correct value.
25443 @item show mips mask-address
25444 @kindex show mips mask-address
25445 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25448 @item set remote-mips64-transfers-32bit-regs
25449 @kindex set remote-mips64-transfers-32bit-regs
25450 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25451 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25452 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25453 and 64 bits for other registers, set this option to @samp{on}.
25455 @item show remote-mips64-transfers-32bit-regs
25456 @kindex show remote-mips64-transfers-32bit-regs
25457 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25459 @item set debug mips
25460 @kindex set debug mips
25461 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25462 target code in @value{GDBN}.
25464 @item show debug mips
25465 @kindex show debug mips
25466 Show the current setting of @acronym{MIPS} debugging messages.
25472 @cindex HPPA support
25474 When @value{GDBN} is debugging the HP PA architecture, it provides the
25475 following special commands:
25478 @item set debug hppa
25479 @kindex set debug hppa
25480 This command determines whether HPPA architecture-specific debugging
25481 messages are to be displayed.
25483 @item show debug hppa
25484 Show whether HPPA debugging messages are displayed.
25486 @item maint print unwind @var{address}
25487 @kindex maint print unwind@r{, HPPA}
25488 This command displays the contents of the unwind table entry at the
25489 given @var{address}.
25495 @subsection PowerPC
25496 @cindex PowerPC architecture
25498 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25499 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25500 numbers stored in the floating point registers. These values must be stored
25501 in two consecutive registers, always starting at an even register like
25502 @code{f0} or @code{f2}.
25504 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25505 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25506 @code{f2} and @code{f3} for @code{$dl1} and so on.
25508 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25509 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25512 @subsection Nios II
25513 @cindex Nios II architecture
25515 When @value{GDBN} is debugging the Nios II architecture,
25516 it provides the following special commands:
25520 @item set debug nios2
25521 @kindex set debug nios2
25522 This command turns on and off debugging messages for the Nios II
25523 target code in @value{GDBN}.
25525 @item show debug nios2
25526 @kindex show debug nios2
25527 Show the current setting of Nios II debugging messages.
25531 @subsection Sparc64
25532 @cindex Sparc64 support
25533 @cindex Application Data Integrity
25534 @subsubsection ADI Support
25536 The M7 processor supports an Application Data Integrity (ADI) feature that
25537 detects invalid data accesses. When software allocates memory and enables
25538 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25539 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25540 the 4-bit version in every cacheline of that data. Hardware saves the latter
25541 in spare bits in the cache and memory hierarchy. On each load and store,
25542 the processor compares the upper 4 VA (virtual address) bits to the
25543 cacheline's version. If there is a mismatch, the processor generates a
25544 version mismatch trap which can be either precise or disrupting. The trap
25545 is an error condition which the kernel delivers to the process as a SIGSEGV
25548 Note that only 64-bit applications can use ADI and need to be built with
25551 Values of the ADI version tags, which are in granularity of a
25552 cacheline (64 bytes), can be viewed or modified.
25556 @kindex adi examine
25557 @item adi (examine | x) [ / @var{n} ] @var{addr}
25559 The @code{adi examine} command displays the value of one ADI version tag per
25562 @var{n} is a decimal integer specifying the number in bytes; the default
25563 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25564 block size, to display.
25566 @var{addr} is the address in user address space where you want @value{GDBN}
25567 to begin displaying the ADI version tags.
25569 Below is an example of displaying ADI versions of variable "shmaddr".
25572 (@value{GDBP}) adi x/100 shmaddr
25573 0xfff800010002c000: 0 0
25577 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25579 The @code{adi assign} command is used to assign new ADI version tag
25582 @var{n} is a decimal integer specifying the number in bytes;
25583 the default is 1. It specifies how much ADI version information, at the
25584 ratio of 1:ADI block size, to modify.
25586 @var{addr} is the address in user address space where you want @value{GDBN}
25587 to begin modifying the ADI version tags.
25589 @var{tag} is the new ADI version tag.
25591 For example, do the following to modify then verify ADI versions of
25592 variable "shmaddr":
25595 (@value{GDBP}) adi a/100 shmaddr = 7
25596 (@value{GDBP}) adi x/100 shmaddr
25597 0xfff800010002c000: 7 7
25604 @cindex S12Z support
25606 When @value{GDBN} is debugging the S12Z architecture,
25607 it provides the following special command:
25610 @item maint info bdccsr
25611 @kindex maint info bdccsr@r{, S12Z}
25612 This command displays the current value of the microprocessor's
25617 @node Controlling GDB
25618 @chapter Controlling @value{GDBN}
25620 You can alter the way @value{GDBN} interacts with you by using the
25621 @code{set} command. For commands controlling how @value{GDBN} displays
25622 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25627 * Editing:: Command editing
25628 * Command History:: Command history
25629 * Screen Size:: Screen size
25630 * Output Styling:: Output styling
25631 * Numbers:: Numbers
25632 * ABI:: Configuring the current ABI
25633 * Auto-loading:: Automatically loading associated files
25634 * Messages/Warnings:: Optional warnings and messages
25635 * Debugging Output:: Optional messages about internal happenings
25636 * Other Misc Settings:: Other Miscellaneous Settings
25644 @value{GDBN} indicates its readiness to read a command by printing a string
25645 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25646 can change the prompt string with the @code{set prompt} command. For
25647 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25648 the prompt in one of the @value{GDBN} sessions so that you can always tell
25649 which one you are talking to.
25651 @emph{Note:} @code{set prompt} does not add a space for you after the
25652 prompt you set. This allows you to set a prompt which ends in a space
25653 or a prompt that does not.
25657 @item set prompt @var{newprompt}
25658 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25660 @kindex show prompt
25662 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25665 Versions of @value{GDBN} that ship with Python scripting enabled have
25666 prompt extensions. The commands for interacting with these extensions
25670 @kindex set extended-prompt
25671 @item set extended-prompt @var{prompt}
25672 Set an extended prompt that allows for substitutions.
25673 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25674 substitution. Any escape sequences specified as part of the prompt
25675 string are replaced with the corresponding strings each time the prompt
25681 set extended-prompt Current working directory: \w (gdb)
25684 Note that when an extended-prompt is set, it takes control of the
25685 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25687 @kindex show extended-prompt
25688 @item show extended-prompt
25689 Prints the extended prompt. Any escape sequences specified as part of
25690 the prompt string with @code{set extended-prompt}, are replaced with the
25691 corresponding strings each time the prompt is displayed.
25695 @section Command Editing
25697 @cindex command line editing
25699 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25700 @sc{gnu} library provides consistent behavior for programs which provide a
25701 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25702 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25703 substitution, and a storage and recall of command history across
25704 debugging sessions.
25706 You may control the behavior of command line editing in @value{GDBN} with the
25707 command @code{set}.
25710 @kindex set editing
25713 @itemx set editing on
25714 Enable command line editing (enabled by default).
25716 @item set editing off
25717 Disable command line editing.
25719 @kindex show editing
25721 Show whether command line editing is enabled.
25724 @ifset SYSTEM_READLINE
25725 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25727 @ifclear SYSTEM_READLINE
25728 @xref{Command Line Editing},
25730 for more details about the Readline
25731 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25732 encouraged to read that chapter.
25734 @cindex Readline application name
25735 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25736 is useful for conditions in @file{.inputrc}.
25738 @cindex operate-and-get-next
25739 @value{GDBN} defines a bindable Readline command,
25740 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25741 This command accepts the current line for execution and fetches the
25742 next line relative to the current line from the history for editing.
25743 Any argument is ignored.
25745 @node Command History
25746 @section Command History
25747 @cindex command history
25749 @value{GDBN} can keep track of the commands you type during your
25750 debugging sessions, so that you can be certain of precisely what
25751 happened. Use these commands to manage the @value{GDBN} command
25754 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25755 package, to provide the history facility.
25756 @ifset SYSTEM_READLINE
25757 @xref{Using History Interactively, , , history, GNU History Library},
25759 @ifclear SYSTEM_READLINE
25760 @xref{Using History Interactively},
25762 for the detailed description of the History library.
25764 To issue a command to @value{GDBN} without affecting certain aspects of
25765 the state which is seen by users, prefix it with @samp{server }
25766 (@pxref{Server Prefix}). This
25767 means that this command will not affect the command history, nor will it
25768 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25769 pressed on a line by itself.
25771 @cindex @code{server}, command prefix
25772 The server prefix does not affect the recording of values into the value
25773 history; to print a value without recording it into the value history,
25774 use the @code{output} command instead of the @code{print} command.
25776 Here is the description of @value{GDBN} commands related to command
25780 @cindex history substitution
25781 @cindex history file
25782 @kindex set history filename
25783 @cindex @env{GDBHISTFILE}, environment variable
25784 @item set history filename @r{[}@var{fname}@r{]}
25785 Set the name of the @value{GDBN} command history file to @var{fname}.
25786 This is the file where @value{GDBN} reads an initial command history
25787 list, and where it writes the command history from this session when it
25788 exits. You can access this list through history expansion or through
25789 the history command editing characters listed below. This file defaults
25790 to the value of the environment variable @code{GDBHISTFILE}, or to
25791 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25794 The @code{GDBHISTFILE} environment variable is read after processing
25795 any @value{GDBN} initialization files (@pxref{Startup}) and after
25796 processing any commands passed using command line options (for
25797 example, @code{-ex}).
25799 If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25800 is the empty string then @value{GDBN} will neither try to load an
25801 existing history file, nor will it try to save the history on exit.
25803 @cindex save command history
25804 @kindex set history save
25805 @item set history save
25806 @itemx set history save on
25807 Record command history in a file, whose name may be specified with the
25808 @code{set history filename} command. By default, this option is
25809 disabled. The command history will be recorded when @value{GDBN}
25810 exits. If @code{set history filename} is set to the empty string then
25811 history saving is disabled, even when @code{set history save} is
25814 @item set history save off
25815 Don't record the command history into the file specified by @code{set
25816 history filename} when @value{GDBN} exits.
25818 @cindex history size
25819 @kindex set history size
25820 @cindex @env{GDBHISTSIZE}, environment variable
25821 @item set history size @var{size}
25822 @itemx set history size unlimited
25823 Set the number of commands which @value{GDBN} keeps in its history list.
25824 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25825 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25826 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25827 either a negative number or the empty string, then the number of commands
25828 @value{GDBN} keeps in the history list is unlimited.
25830 The @code{GDBHISTSIZE} environment variable is read after processing
25831 any @value{GDBN} initialization files (@pxref{Startup}) and after
25832 processing any commands passed using command line options (for
25833 example, @code{-ex}).
25835 @cindex remove duplicate history
25836 @kindex set history remove-duplicates
25837 @item set history remove-duplicates @var{count}
25838 @itemx set history remove-duplicates unlimited
25839 Control the removal of duplicate history entries in the command history list.
25840 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25841 history entries and remove the first entry that is a duplicate of the current
25842 entry being added to the command history list. If @var{count} is
25843 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25844 removal of duplicate history entries is disabled.
25846 Only history entries added during the current session are considered for
25847 removal. This option is set to 0 by default.
25851 History expansion assigns special meaning to the character @kbd{!}.
25852 @ifset SYSTEM_READLINE
25853 @xref{Event Designators, , , history, GNU History Library},
25855 @ifclear SYSTEM_READLINE
25856 @xref{Event Designators},
25860 @cindex history expansion, turn on/off
25861 Since @kbd{!} is also the logical not operator in C, history expansion
25862 is off by default. If you decide to enable history expansion with the
25863 @code{set history expansion on} command, you may sometimes need to
25864 follow @kbd{!} (when it is used as logical not, in an expression) with
25865 a space or a tab to prevent it from being expanded. The readline
25866 history facilities do not attempt substitution on the strings
25867 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25869 The commands to control history expansion are:
25872 @item set history expansion on
25873 @itemx set history expansion
25874 @kindex set history expansion
25875 Enable history expansion. History expansion is off by default.
25877 @item set history expansion off
25878 Disable history expansion.
25881 @kindex show history
25883 @itemx show history filename
25884 @itemx show history save
25885 @itemx show history size
25886 @itemx show history expansion
25887 These commands display the state of the @value{GDBN} history parameters.
25888 @code{show history} by itself displays all four states.
25893 @kindex show commands
25894 @cindex show last commands
25895 @cindex display command history
25896 @item show commands
25897 Display the last ten commands in the command history.
25899 @item show commands @var{n}
25900 Print ten commands centered on command number @var{n}.
25902 @item show commands +
25903 Print ten commands just after the commands last printed.
25907 @section Screen Size
25908 @cindex size of screen
25909 @cindex screen size
25912 @cindex pauses in output
25914 Certain commands to @value{GDBN} may produce large amounts of
25915 information output to the screen. To help you read all of it,
25916 @value{GDBN} pauses and asks you for input at the end of each page of
25917 output. Type @key{RET} when you want to see one more page of output,
25918 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25919 without paging for the rest of the current command. Also, the screen
25920 width setting determines when to wrap lines of output. Depending on
25921 what is being printed, @value{GDBN} tries to break the line at a
25922 readable place, rather than simply letting it overflow onto the
25925 Normally @value{GDBN} knows the size of the screen from the terminal
25926 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25927 together with the value of the @code{TERM} environment variable and the
25928 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25929 you can override it with the @code{set height} and @code{set
25936 @kindex show height
25937 @item set height @var{lpp}
25938 @itemx set height unlimited
25940 @itemx set width @var{cpl}
25941 @itemx set width unlimited
25943 These @code{set} commands specify a screen height of @var{lpp} lines and
25944 a screen width of @var{cpl} characters. The associated @code{show}
25945 commands display the current settings.
25947 If you specify a height of either @code{unlimited} or zero lines,
25948 @value{GDBN} does not pause during output no matter how long the
25949 output is. This is useful if output is to a file or to an editor
25952 Likewise, you can specify @samp{set width unlimited} or @samp{set
25953 width 0} to prevent @value{GDBN} from wrapping its output.
25955 @item set pagination on
25956 @itemx set pagination off
25957 @kindex set pagination
25958 Turn the output pagination on or off; the default is on. Turning
25959 pagination off is the alternative to @code{set height unlimited}. Note that
25960 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25961 Options, -batch}) also automatically disables pagination.
25963 @item show pagination
25964 @kindex show pagination
25965 Show the current pagination mode.
25968 @node Output Styling
25969 @section Output Styling
25975 @value{GDBN} can style its output on a capable terminal. This is
25976 enabled by default on most systems, but disabled by default when in
25977 batch mode (@pxref{Mode Options}). Various style settings are available;
25978 and styles can also be disabled entirely.
25981 @item set style enabled @samp{on|off}
25982 Enable or disable all styling. The default is host-dependent, with
25983 most hosts defaulting to @samp{on}.
25985 @item show style enabled
25986 Show the current state of styling.
25988 @item set style sources @samp{on|off}
25989 Enable or disable source code styling. This affects whether source
25990 code, such as the output of the @code{list} command, is styled. Note
25991 that source styling only works if styling in general is enabled, and
25992 if @value{GDBN} was linked with the GNU Source Highlight library. The
25993 default is @samp{on}.
25995 @item show style sources
25996 Show the current state of source code styling.
25999 Subcommands of @code{set style} control specific forms of styling.
26000 These subcommands all follow the same pattern: each style-able object
26001 can be styled with a foreground color, a background color, and an
26004 For example, the style of file names can be controlled using the
26005 @code{set style filename} group of commands:
26008 @item set style filename background @var{color}
26009 Set the background to @var{color}. Valid colors are @samp{none}
26010 (meaning the terminal's default color), @samp{black}, @samp{red},
26011 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26014 @item set style filename foreground @var{color}
26015 Set the foreground to @var{color}. Valid colors are @samp{none}
26016 (meaning the terminal's default color), @samp{black}, @samp{red},
26017 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26020 @item set style filename intensity @var{value}
26021 Set the intensity to @var{value}. Valid intensities are @samp{normal}
26022 (the default), @samp{bold}, and @samp{dim}.
26025 The @code{show style} command and its subcommands are styling
26026 a style name in their output using its own style.
26027 So, use @command{show style} to see the complete list of styles,
26028 their characteristics and the visual aspect of each style.
26030 The style-able objects are:
26033 Control the styling of file names. By default, this style's
26034 foreground color is green.
26037 Control the styling of function names. These are managed with the
26038 @code{set style function} family of commands. By default, this
26039 style's foreground color is yellow.
26042 Control the styling of variable names. These are managed with the
26043 @code{set style variable} family of commands. By default, this style's
26044 foreground color is cyan.
26047 Control the styling of addresses. These are managed with the
26048 @code{set style address} family of commands. By default, this style's
26049 foreground color is blue.
26052 Control the styling of @value{GDBN}'s version number text. By
26053 default, this style's foreground color is magenta and it has bold
26054 intensity. The version number is displayed in two places, the output
26055 of @command{show version}, and when @value{GDBN} starts up.
26057 In order to control how @value{GDBN} styles the version number at
26058 startup, add the @code{set style version} family of commands to the
26059 early initialization command file (@pxref{Initialization
26063 Control the styling of titles. These are managed with the
26064 @code{set style title} family of commands. By default, this style's
26065 intensity is bold. Commands are using the title style to improve
26066 the readability of large output. For example, the commands
26067 @command{apropos} and @command{help} are using the title style
26068 for the command names.
26071 Control the styling of highlightings. These are managed with the
26072 @code{set style highlight} family of commands. By default, this style's
26073 foreground color is red. Commands are using the highlight style to draw
26074 the user attention to some specific parts of their output. For example,
26075 the command @command{apropos -v REGEXP} uses the highlight style to
26076 mark the documentation parts matching @var{regexp}.
26079 Control the styling of the TUI border. Note that, unlike other
26080 styling options, only the color of the border can be controlled via
26081 @code{set style}. This was done for compatibility reasons, as TUI
26082 controls to set the border's intensity predated the addition of
26083 general styling to @value{GDBN}. @xref{TUI Configuration}.
26085 @item tui-active-border
26086 Control the styling of the active TUI border; that is, the TUI window
26087 that has the focus.
26093 @cindex number representation
26094 @cindex entering numbers
26096 You can always enter numbers in octal, decimal, or hexadecimal in
26097 @value{GDBN} by the usual conventions: octal numbers begin with
26098 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
26099 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
26100 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
26101 10; likewise, the default display for numbers---when no particular
26102 format is specified---is base 10. You can change the default base for
26103 both input and output with the commands described below.
26106 @kindex set input-radix
26107 @item set input-radix @var{base}
26108 Set the default base for numeric input. Supported choices
26109 for @var{base} are decimal 8, 10, or 16. The base must itself be
26110 specified either unambiguously or using the current input radix; for
26114 set input-radix 012
26115 set input-radix 10.
26116 set input-radix 0xa
26120 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
26121 leaves the input radix unchanged, no matter what it was, since
26122 @samp{10}, being without any leading or trailing signs of its base, is
26123 interpreted in the current radix. Thus, if the current radix is 16,
26124 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
26127 @kindex set output-radix
26128 @item set output-radix @var{base}
26129 Set the default base for numeric display. Supported choices
26130 for @var{base} are decimal 8, 10, or 16. The base must itself be
26131 specified either unambiguously or using the current input radix.
26133 @kindex show input-radix
26134 @item show input-radix
26135 Display the current default base for numeric input.
26137 @kindex show output-radix
26138 @item show output-radix
26139 Display the current default base for numeric display.
26141 @item set radix @r{[}@var{base}@r{]}
26145 These commands set and show the default base for both input and output
26146 of numbers. @code{set radix} sets the radix of input and output to
26147 the same base; without an argument, it resets the radix back to its
26148 default value of 10.
26153 @section Configuring the Current ABI
26155 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
26156 application automatically. However, sometimes you need to override its
26157 conclusions. Use these commands to manage @value{GDBN}'s view of the
26163 @cindex Newlib OS ABI and its influence on the longjmp handling
26165 One @value{GDBN} configuration can debug binaries for multiple operating
26166 system targets, either via remote debugging or native emulation.
26167 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
26168 but you can override its conclusion using the @code{set osabi} command.
26169 One example where this is useful is in debugging of binaries which use
26170 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
26171 not have the same identifying marks that the standard C library for your
26174 When @value{GDBN} is debugging the AArch64 architecture, it provides a
26175 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
26176 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
26177 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
26181 Show the OS ABI currently in use.
26184 With no argument, show the list of registered available OS ABI's.
26186 @item set osabi @var{abi}
26187 Set the current OS ABI to @var{abi}.
26190 @cindex float promotion
26192 Generally, the way that an argument of type @code{float} is passed to a
26193 function depends on whether the function is prototyped. For a prototyped
26194 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26195 according to the architecture's convention for @code{float}. For unprototyped
26196 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26197 @code{double} and then passed.
26199 Unfortunately, some forms of debug information do not reliably indicate whether
26200 a function is prototyped. If @value{GDBN} calls a function that is not marked
26201 as prototyped, it consults @kbd{set coerce-float-to-double}.
26204 @kindex set coerce-float-to-double
26205 @item set coerce-float-to-double
26206 @itemx set coerce-float-to-double on
26207 Arguments of type @code{float} will be promoted to @code{double} when passed
26208 to an unprototyped function. This is the default setting.
26210 @item set coerce-float-to-double off
26211 Arguments of type @code{float} will be passed directly to unprototyped
26214 @kindex show coerce-float-to-double
26215 @item show coerce-float-to-double
26216 Show the current setting of promoting @code{float} to @code{double}.
26220 @kindex show cp-abi
26221 @value{GDBN} needs to know the ABI used for your program's C@t{++}
26222 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26223 used to build your application. @value{GDBN} only fully supports
26224 programs with a single C@t{++} ABI; if your program contains code using
26225 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26226 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26227 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26228 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26229 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26230 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26235 Show the C@t{++} ABI currently in use.
26238 With no argument, show the list of supported C@t{++} ABI's.
26240 @item set cp-abi @var{abi}
26241 @itemx set cp-abi auto
26242 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26246 @section Automatically loading associated files
26247 @cindex auto-loading
26249 @value{GDBN} sometimes reads files with commands and settings automatically,
26250 without being explicitly told so by the user. We call this feature
26251 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
26252 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
26253 results or introduce security risks (e.g., if the file comes from untrusted
26256 There are various kinds of files @value{GDBN} can automatically load.
26257 In addition to these files, @value{GDBN} supports auto-loading code written
26258 in various extension languages. @xref{Auto-loading extensions}.
26260 Note that loading of these associated files (including the local @file{.gdbinit}
26261 file) requires accordingly configured @code{auto-load safe-path}
26262 (@pxref{Auto-loading safe path}).
26264 For these reasons, @value{GDBN} includes commands and options to let you
26265 control when to auto-load files and which files should be auto-loaded.
26268 @anchor{set auto-load off}
26269 @kindex set auto-load off
26270 @item set auto-load off
26271 Globally disable loading of all auto-loaded files.
26272 You may want to use this command with the @samp{-iex} option
26273 (@pxref{Option -init-eval-command}) such as:
26275 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26278 Be aware that system init file (@pxref{System-wide configuration})
26279 and init files from your home directory (@pxref{Home Directory Init File})
26280 still get read (as they come from generally trusted directories).
26281 To prevent @value{GDBN} from auto-loading even those init files, use the
26282 @option{-nx} option (@pxref{Mode Options}), in addition to
26283 @code{set auto-load no}.
26285 @anchor{show auto-load}
26286 @kindex show auto-load
26287 @item show auto-load
26288 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26292 (gdb) show auto-load
26293 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26294 libthread-db: Auto-loading of inferior specific libthread_db is on.
26295 local-gdbinit: Auto-loading of .gdbinit script from current directory
26297 python-scripts: Auto-loading of Python scripts is on.
26298 safe-path: List of directories from which it is safe to auto-load files
26299 is $debugdir:$datadir/auto-load.
26300 scripts-directory: List of directories from which to load auto-loaded scripts
26301 is $debugdir:$datadir/auto-load.
26304 @anchor{info auto-load}
26305 @kindex info auto-load
26306 @item info auto-load
26307 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26311 (gdb) info auto-load
26314 Yes /home/user/gdb/gdb-gdb.gdb
26315 libthread-db: No auto-loaded libthread-db.
26316 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26320 Yes /home/user/gdb/gdb-gdb.py
26324 These are @value{GDBN} control commands for the auto-loading:
26326 @multitable @columnfractions .5 .5
26327 @item @xref{set auto-load off}.
26328 @tab Disable auto-loading globally.
26329 @item @xref{show auto-load}.
26330 @tab Show setting of all kinds of files.
26331 @item @xref{info auto-load}.
26332 @tab Show state of all kinds of files.
26333 @item @xref{set auto-load gdb-scripts}.
26334 @tab Control for @value{GDBN} command scripts.
26335 @item @xref{show auto-load gdb-scripts}.
26336 @tab Show setting of @value{GDBN} command scripts.
26337 @item @xref{info auto-load gdb-scripts}.
26338 @tab Show state of @value{GDBN} command scripts.
26339 @item @xref{set auto-load python-scripts}.
26340 @tab Control for @value{GDBN} Python scripts.
26341 @item @xref{show auto-load python-scripts}.
26342 @tab Show setting of @value{GDBN} Python scripts.
26343 @item @xref{info auto-load python-scripts}.
26344 @tab Show state of @value{GDBN} Python scripts.
26345 @item @xref{set auto-load guile-scripts}.
26346 @tab Control for @value{GDBN} Guile scripts.
26347 @item @xref{show auto-load guile-scripts}.
26348 @tab Show setting of @value{GDBN} Guile scripts.
26349 @item @xref{info auto-load guile-scripts}.
26350 @tab Show state of @value{GDBN} Guile scripts.
26351 @item @xref{set auto-load scripts-directory}.
26352 @tab Control for @value{GDBN} auto-loaded scripts location.
26353 @item @xref{show auto-load scripts-directory}.
26354 @tab Show @value{GDBN} auto-loaded scripts location.
26355 @item @xref{add-auto-load-scripts-directory}.
26356 @tab Add directory for auto-loaded scripts location list.
26357 @item @xref{set auto-load local-gdbinit}.
26358 @tab Control for init file in the current directory.
26359 @item @xref{show auto-load local-gdbinit}.
26360 @tab Show setting of init file in the current directory.
26361 @item @xref{info auto-load local-gdbinit}.
26362 @tab Show state of init file in the current directory.
26363 @item @xref{set auto-load libthread-db}.
26364 @tab Control for thread debugging library.
26365 @item @xref{show auto-load libthread-db}.
26366 @tab Show setting of thread debugging library.
26367 @item @xref{info auto-load libthread-db}.
26368 @tab Show state of thread debugging library.
26369 @item @xref{set auto-load safe-path}.
26370 @tab Control directories trusted for automatic loading.
26371 @item @xref{show auto-load safe-path}.
26372 @tab Show directories trusted for automatic loading.
26373 @item @xref{add-auto-load-safe-path}.
26374 @tab Add directory trusted for automatic loading.
26378 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26379 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26381 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26382 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
26385 @node Init File in the Current Directory
26386 @subsection Automatically loading init file in the current directory
26387 @cindex auto-loading init file in the current directory
26389 By default, @value{GDBN} reads and executes the canned sequences of commands
26390 from init file (if any) in the current working directory,
26391 see @ref{Init File in the Current Directory during Startup}.
26393 Note that loading of this local @file{.gdbinit} file also requires accordingly
26394 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26397 @anchor{set auto-load local-gdbinit}
26398 @kindex set auto-load local-gdbinit
26399 @item set auto-load local-gdbinit [on|off]
26400 Enable or disable the auto-loading of canned sequences of commands
26401 (@pxref{Sequences}) found in init file in the current directory.
26403 @anchor{show auto-load local-gdbinit}
26404 @kindex show auto-load local-gdbinit
26405 @item show auto-load local-gdbinit
26406 Show whether auto-loading of canned sequences of commands from init file in the
26407 current directory is enabled or disabled.
26409 @anchor{info auto-load local-gdbinit}
26410 @kindex info auto-load local-gdbinit
26411 @item info auto-load local-gdbinit
26412 Print whether canned sequences of commands from init file in the
26413 current directory have been auto-loaded.
26416 @node libthread_db.so.1 file
26417 @subsection Automatically loading thread debugging library
26418 @cindex auto-loading libthread_db.so.1
26420 This feature is currently present only on @sc{gnu}/Linux native hosts.
26422 @value{GDBN} reads in some cases thread debugging library from places specific
26423 to the inferior (@pxref{set libthread-db-search-path}).
26425 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26426 without checking this @samp{set auto-load libthread-db} switch as system
26427 libraries have to be trusted in general. In all other cases of
26428 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26429 auto-load libthread-db} is enabled before trying to open such thread debugging
26432 Note that loading of this debugging library also requires accordingly configured
26433 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26436 @anchor{set auto-load libthread-db}
26437 @kindex set auto-load libthread-db
26438 @item set auto-load libthread-db [on|off]
26439 Enable or disable the auto-loading of inferior specific thread debugging library.
26441 @anchor{show auto-load libthread-db}
26442 @kindex show auto-load libthread-db
26443 @item show auto-load libthread-db
26444 Show whether auto-loading of inferior specific thread debugging library is
26445 enabled or disabled.
26447 @anchor{info auto-load libthread-db}
26448 @kindex info auto-load libthread-db
26449 @item info auto-load libthread-db
26450 Print the list of all loaded inferior specific thread debugging libraries and
26451 for each such library print list of inferior @var{pid}s using it.
26454 @node Auto-loading safe path
26455 @subsection Security restriction for auto-loading
26456 @cindex auto-loading safe-path
26458 As the files of inferior can come from untrusted source (such as submitted by
26459 an application user) @value{GDBN} does not always load any files automatically.
26460 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26461 directories trusted for loading files not explicitly requested by user.
26462 Each directory can also be a shell wildcard pattern.
26464 If the path is not set properly you will see a warning and the file will not
26469 Reading symbols from /home/user/gdb/gdb...
26470 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26471 declined by your `auto-load safe-path' set
26472 to "$debugdir:$datadir/auto-load".
26473 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26474 declined by your `auto-load safe-path' set
26475 to "$debugdir:$datadir/auto-load".
26479 To instruct @value{GDBN} to go ahead and use the init files anyway,
26480 invoke @value{GDBN} like this:
26483 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26486 The list of trusted directories is controlled by the following commands:
26489 @anchor{set auto-load safe-path}
26490 @kindex set auto-load safe-path
26491 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26492 Set the list of directories (and their subdirectories) trusted for automatic
26493 loading and execution of scripts. You can also enter a specific trusted file.
26494 Each directory can also be a shell wildcard pattern; wildcards do not match
26495 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26496 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26497 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26498 its default value as specified during @value{GDBN} compilation.
26500 The list of directories uses path separator (@samp{:} on GNU and Unix
26501 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26502 to the @env{PATH} environment variable.
26504 @anchor{show auto-load safe-path}
26505 @kindex show auto-load safe-path
26506 @item show auto-load safe-path
26507 Show the list of directories trusted for automatic loading and execution of
26510 @anchor{add-auto-load-safe-path}
26511 @kindex add-auto-load-safe-path
26512 @item add-auto-load-safe-path
26513 Add an entry (or list of entries) to the list of directories trusted for
26514 automatic loading and execution of scripts. Multiple entries may be delimited
26515 by the host platform path separator in use.
26518 This variable defaults to what @code{--with-auto-load-dir} has been configured
26519 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26520 substitution applies the same as for @ref{set auto-load scripts-directory}.
26521 The default @code{set auto-load safe-path} value can be also overriden by
26522 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26524 Setting this variable to @file{/} disables this security protection,
26525 corresponding @value{GDBN} configuration option is
26526 @option{--without-auto-load-safe-path}.
26527 This variable is supposed to be set to the system directories writable by the
26528 system superuser only. Users can add their source directories in init files in
26529 their home directories (@pxref{Home Directory Init File}). See also deprecated
26530 init file in the current directory
26531 (@pxref{Init File in the Current Directory during Startup}).
26533 To force @value{GDBN} to load the files it declined to load in the previous
26534 example, you could use one of the following ways:
26537 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26538 Specify this trusted directory (or a file) as additional component of the list.
26539 You have to specify also any existing directories displayed by
26540 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26542 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26543 Specify this directory as in the previous case but just for a single
26544 @value{GDBN} session.
26546 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26547 Disable auto-loading safety for a single @value{GDBN} session.
26548 This assumes all the files you debug during this @value{GDBN} session will come
26549 from trusted sources.
26551 @item @kbd{./configure --without-auto-load-safe-path}
26552 During compilation of @value{GDBN} you may disable any auto-loading safety.
26553 This assumes all the files you will ever debug with this @value{GDBN} come from
26557 On the other hand you can also explicitly forbid automatic files loading which
26558 also suppresses any such warning messages:
26561 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26562 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26564 @item @file{~/.gdbinit}: @samp{set auto-load no}
26565 Disable auto-loading globally for the user
26566 (@pxref{Home Directory Init File}). While it is improbable, you could also
26567 use system init file instead (@pxref{System-wide configuration}).
26570 This setting applies to the file names as entered by user. If no entry matches
26571 @value{GDBN} tries as a last resort to also resolve all the file names into
26572 their canonical form (typically resolving symbolic links) and compare the
26573 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26574 own before starting the comparison so a canonical form of directories is
26575 recommended to be entered.
26577 @node Auto-loading verbose mode
26578 @subsection Displaying files tried for auto-load
26579 @cindex auto-loading verbose mode
26581 For better visibility of all the file locations where you can place scripts to
26582 be auto-loaded with inferior --- or to protect yourself against accidental
26583 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26584 all the files attempted to be loaded. Both existing and non-existing files may
26587 For example the list of directories from which it is safe to auto-load files
26588 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26589 may not be too obvious while setting it up.
26592 (gdb) set debug auto-load on
26593 (gdb) file ~/src/t/true
26594 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26595 for objfile "/tmp/true".
26596 auto-load: Updating directories of "/usr:/opt".
26597 auto-load: Using directory "/usr".
26598 auto-load: Using directory "/opt".
26599 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26600 by your `auto-load safe-path' set to "/usr:/opt".
26604 @anchor{set debug auto-load}
26605 @kindex set debug auto-load
26606 @item set debug auto-load [on|off]
26607 Set whether to print the filenames attempted to be auto-loaded.
26609 @anchor{show debug auto-load}
26610 @kindex show debug auto-load
26611 @item show debug auto-load
26612 Show whether printing of the filenames attempted to be auto-loaded is turned
26616 @node Messages/Warnings
26617 @section Optional Warnings and Messages
26619 @cindex verbose operation
26620 @cindex optional warnings
26621 By default, @value{GDBN} is silent about its inner workings. If you are
26622 running on a slow machine, you may want to use the @code{set verbose}
26623 command. This makes @value{GDBN} tell you when it does a lengthy
26624 internal operation, so you will not think it has crashed.
26626 Currently, the messages controlled by @code{set verbose} are those
26627 which announce that the symbol table for a source file is being read;
26628 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26631 @kindex set verbose
26632 @item set verbose on
26633 Enables @value{GDBN} output of certain informational messages.
26635 @item set verbose off
26636 Disables @value{GDBN} output of certain informational messages.
26638 @kindex show verbose
26640 Displays whether @code{set verbose} is on or off.
26643 By default, if @value{GDBN} encounters bugs in the symbol table of an
26644 object file, it is silent; but if you are debugging a compiler, you may
26645 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26650 @kindex set complaints
26651 @item set complaints @var{limit}
26652 Permits @value{GDBN} to output @var{limit} complaints about each type of
26653 unusual symbols before becoming silent about the problem. Set
26654 @var{limit} to zero to suppress all complaints; set it to a large number
26655 to prevent complaints from being suppressed.
26657 @kindex show complaints
26658 @item show complaints
26659 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26663 @anchor{confirmation requests}
26664 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26665 lot of stupid questions to confirm certain commands. For example, if
26666 you try to run a program which is already running:
26670 The program being debugged has been started already.
26671 Start it from the beginning? (y or n)
26674 If you are willing to unflinchingly face the consequences of your own
26675 commands, you can disable this ``feature'':
26679 @kindex set confirm
26681 @cindex confirmation
26682 @cindex stupid questions
26683 @item set confirm off
26684 Disables confirmation requests. Note that running @value{GDBN} with
26685 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26686 automatically disables confirmation requests.
26688 @item set confirm on
26689 Enables confirmation requests (the default).
26691 @kindex show confirm
26693 Displays state of confirmation requests.
26697 @cindex command tracing
26698 If you need to debug user-defined commands or sourced files you may find it
26699 useful to enable @dfn{command tracing}. In this mode each command will be
26700 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26701 quantity denoting the call depth of each command.
26704 @kindex set trace-commands
26705 @cindex command scripts, debugging
26706 @item set trace-commands on
26707 Enable command tracing.
26708 @item set trace-commands off
26709 Disable command tracing.
26710 @item show trace-commands
26711 Display the current state of command tracing.
26714 @node Debugging Output
26715 @section Optional Messages about Internal Happenings
26716 @cindex optional debugging messages
26718 @value{GDBN} has commands that enable optional debugging messages from
26719 various @value{GDBN} subsystems; normally these commands are of
26720 interest to @value{GDBN} maintainers, or when reporting a bug. This
26721 section documents those commands.
26724 @kindex set exec-done-display
26725 @item set exec-done-display
26726 Turns on or off the notification of asynchronous commands'
26727 completion. When on, @value{GDBN} will print a message when an
26728 asynchronous command finishes its execution. The default is off.
26729 @kindex show exec-done-display
26730 @item show exec-done-display
26731 Displays the current setting of asynchronous command completion
26735 @cindex ARM AArch64
26736 @item set debug aarch64
26737 Turns on or off display of debugging messages related to ARM AArch64.
26738 The default is off.
26740 @item show debug aarch64
26741 Displays the current state of displaying debugging messages related to
26744 @cindex gdbarch debugging info
26745 @cindex architecture debugging info
26746 @item set debug arch
26747 Turns on or off display of gdbarch debugging info. The default is off
26748 @item show debug arch
26749 Displays the current state of displaying gdbarch debugging info.
26751 @item set debug aix-solib
26752 @cindex AIX shared library debugging
26753 Control display of debugging messages from the AIX shared library
26754 support module. The default is off.
26755 @item show debug aix-solib
26756 Show the current state of displaying AIX shared library debugging messages.
26758 @item set debug aix-thread
26759 @cindex AIX threads
26760 Display debugging messages about inner workings of the AIX thread
26762 @item show debug aix-thread
26763 Show the current state of AIX thread debugging info display.
26765 @item set debug check-physname
26767 Check the results of the ``physname'' computation. When reading DWARF
26768 debugging information for C@t{++}, @value{GDBN} attempts to compute
26769 each entity's name. @value{GDBN} can do this computation in two
26770 different ways, depending on exactly what information is present.
26771 When enabled, this setting causes @value{GDBN} to compute the names
26772 both ways and display any discrepancies.
26773 @item show debug check-physname
26774 Show the current state of ``physname'' checking.
26776 @item set debug coff-pe-read
26777 @cindex COFF/PE exported symbols
26778 Control display of debugging messages related to reading of COFF/PE
26779 exported symbols. The default is off.
26780 @item show debug coff-pe-read
26781 Displays the current state of displaying debugging messages related to
26782 reading of COFF/PE exported symbols.
26784 @item set debug dwarf-die
26786 Dump DWARF DIEs after they are read in.
26787 The value is the number of nesting levels to print.
26788 A value of zero turns off the display.
26789 @item show debug dwarf-die
26790 Show the current state of DWARF DIE debugging.
26792 @item set debug dwarf-line
26793 @cindex DWARF Line Tables
26794 Turns on or off display of debugging messages related to reading
26795 DWARF line tables. The default is 0 (off).
26796 A value of 1 provides basic information.
26797 A value greater than 1 provides more verbose information.
26798 @item show debug dwarf-line
26799 Show the current state of DWARF line table debugging.
26801 @item set debug dwarf-read
26802 @cindex DWARF Reading
26803 Turns on or off display of debugging messages related to reading
26804 DWARF debug info. The default is 0 (off).
26805 A value of 1 provides basic information.
26806 A value greater than 1 provides more verbose information.
26807 @item show debug dwarf-read
26808 Show the current state of DWARF reader debugging.
26810 @item set debug displaced
26811 @cindex displaced stepping debugging info
26812 Turns on or off display of @value{GDBN} debugging info for the
26813 displaced stepping support. The default is off.
26814 @item show debug displaced
26815 Displays the current state of displaying @value{GDBN} debugging info
26816 related to displaced stepping.
26818 @item set debug event
26819 @cindex event debugging info
26820 Turns on or off display of @value{GDBN} event debugging info. The
26822 @item show debug event
26823 Displays the current state of displaying @value{GDBN} event debugging
26826 @item set debug event-loop
26827 @cindex event-loop debugging
26828 Controls output of debugging info about the event loop. The possible
26829 values are @samp{off}, @samp{all} (shows all debugging info) and
26830 @samp{all-except-ui} (shows all debugging info except those about
26831 UI-related events).
26832 @item show debug event-loop
26833 Shows the current state of displaying debugging info about the event
26836 @item set debug expression
26837 @cindex expression debugging info
26838 Turns on or off display of debugging info about @value{GDBN}
26839 expression parsing. The default is off.
26840 @item show debug expression
26841 Displays the current state of displaying debugging info about
26842 @value{GDBN} expression parsing.
26844 @item set debug fbsd-lwp
26845 @cindex FreeBSD LWP debug messages
26846 Turns on or off debugging messages from the FreeBSD LWP debug support.
26847 @item show debug fbsd-lwp
26848 Show the current state of FreeBSD LWP debugging messages.
26850 @item set debug fbsd-nat
26851 @cindex FreeBSD native target debug messages
26852 Turns on or off debugging messages from the FreeBSD native target.
26853 @item show debug fbsd-nat
26854 Show the current state of FreeBSD native target debugging messages.
26856 @item set debug fortran-array-slicing
26857 @cindex fortran array slicing debugging info
26858 Turns on or off display of @value{GDBN} Fortran array slicing
26859 debugging info. The default is off.
26861 @item show debug fortran-array-slicing
26862 Displays the current state of displaying @value{GDBN} Fortran array
26863 slicing debugging info.
26865 @item set debug frame
26866 @cindex frame debugging info
26867 Turns on or off display of @value{GDBN} frame debugging info. The
26869 @item show debug frame
26870 Displays the current state of displaying @value{GDBN} frame debugging
26873 @item set debug gnu-nat
26874 @cindex @sc{gnu}/Hurd debug messages
26875 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26876 @item show debug gnu-nat
26877 Show the current state of @sc{gnu}/Hurd debugging messages.
26879 @item set debug infrun
26880 @cindex inferior debugging info
26881 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26882 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26883 for implementing operations such as single-stepping the inferior.
26884 @item show debug infrun
26885 Displays the current state of @value{GDBN} inferior debugging.
26887 @item set debug jit
26888 @cindex just-in-time compilation, debugging messages
26889 Turn on or off debugging messages from JIT debug support.
26890 @item show debug jit
26891 Displays the current state of @value{GDBN} JIT debugging.
26893 @item set debug lin-lwp
26894 @cindex @sc{gnu}/Linux LWP debug messages
26895 @cindex Linux lightweight processes
26896 Turn on or off debugging messages from the Linux LWP debug support.
26897 @item show debug lin-lwp
26898 Show the current state of Linux LWP debugging messages.
26900 @item set debug linux-namespaces
26901 @cindex @sc{gnu}/Linux namespaces debug messages
26902 Turn on or off debugging messages from the Linux namespaces debug support.
26903 @item show debug linux-namespaces
26904 Show the current state of Linux namespaces debugging messages.
26906 @item set debug mach-o
26907 @cindex Mach-O symbols processing
26908 Control display of debugging messages related to Mach-O symbols
26909 processing. The default is off.
26910 @item show debug mach-o
26911 Displays the current state of displaying debugging messages related to
26912 reading of COFF/PE exported symbols.
26914 @item set debug notification
26915 @cindex remote async notification debugging info
26916 Turn on or off debugging messages about remote async notification.
26917 The default is off.
26918 @item show debug notification
26919 Displays the current state of remote async notification debugging messages.
26921 @item set debug observer
26922 @cindex observer debugging info
26923 Turns on or off display of @value{GDBN} observer debugging. This
26924 includes info such as the notification of observable events.
26925 @item show debug observer
26926 Displays the current state of observer debugging.
26928 @item set debug overload
26929 @cindex C@t{++} overload debugging info
26930 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26931 info. This includes info such as ranking of functions, etc. The default
26933 @item show debug overload
26934 Displays the current state of displaying @value{GDBN} C@t{++} overload
26937 @cindex expression parser, debugging info
26938 @cindex debug expression parser
26939 @item set debug parser
26940 Turns on or off the display of expression parser debugging output.
26941 Internally, this sets the @code{yydebug} variable in the expression
26942 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26943 details. The default is off.
26944 @item show debug parser
26945 Show the current state of expression parser debugging.
26947 @cindex packets, reporting on stdout
26948 @cindex serial connections, debugging
26949 @cindex debug remote protocol
26950 @cindex remote protocol debugging
26951 @cindex display remote packets
26952 @item set debug remote
26953 Turns on or off display of reports on all packets sent back and forth across
26954 the serial line to the remote machine. The info is printed on the
26955 @value{GDBN} standard output stream. The default is off.
26956 @item show debug remote
26957 Displays the state of display of remote packets.
26959 @item set debug remote-packet-max-chars
26960 Sets the maximum number of characters to display for each remote packet when
26961 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26962 displaying lengthy remote packets and polluting the console.
26964 The default value is @code{512}, which means @value{GDBN} will truncate each
26965 remote packet after 512 bytes.
26967 Setting this option to @code{unlimited} will disable truncation and will output
26968 the full length of the remote packets.
26969 @item show debug remote-packet-max-chars
26970 Displays the number of bytes to output for remote packet debugging.
26972 @item set debug separate-debug-file
26973 Turns on or off display of debug output about separate debug file search.
26974 @item show debug separate-debug-file
26975 Displays the state of separate debug file search debug output.
26977 @item set debug serial
26978 Turns on or off display of @value{GDBN} serial debugging info. The
26980 @item show debug serial
26981 Displays the current state of displaying @value{GDBN} serial debugging
26984 @item set debug solib-frv
26985 @cindex FR-V shared-library debugging
26986 Turn on or off debugging messages for FR-V shared-library code.
26987 @item show debug solib-frv
26988 Display the current state of FR-V shared-library code debugging
26991 @item set debug symbol-lookup
26992 @cindex symbol lookup
26993 Turns on or off display of debugging messages related to symbol lookup.
26994 The default is 0 (off).
26995 A value of 1 provides basic information.
26996 A value greater than 1 provides more verbose information.
26997 @item show debug symbol-lookup
26998 Show the current state of symbol lookup debugging messages.
27000 @item set debug symfile
27001 @cindex symbol file functions
27002 Turns on or off display of debugging messages related to symbol file functions.
27003 The default is off. @xref{Files}.
27004 @item show debug symfile
27005 Show the current state of symbol file debugging messages.
27007 @item set debug symtab-create
27008 @cindex symbol table creation
27009 Turns on or off display of debugging messages related to symbol table creation.
27010 The default is 0 (off).
27011 A value of 1 provides basic information.
27012 A value greater than 1 provides more verbose information.
27013 @item show debug symtab-create
27014 Show the current state of symbol table creation debugging.
27016 @item set debug target
27017 @cindex target debugging info
27018 Turns on or off display of @value{GDBN} target debugging info. This info
27019 includes what is going on at the target level of GDB, as it happens. The
27020 default is 0. Set it to 1 to track events, and to 2 to also track the
27021 value of large memory transfers.
27022 @item show debug target
27023 Displays the current state of displaying @value{GDBN} target debugging
27026 @item set debug timestamp
27027 @cindex timestamping debugging info
27028 Turns on or off display of timestamps with @value{GDBN} debugging info.
27029 When enabled, seconds and microseconds are displayed before each debugging
27031 @item show debug timestamp
27032 Displays the current state of displaying timestamps with @value{GDBN}
27035 @item set debug varobj
27036 @cindex variable object debugging info
27037 Turns on or off display of @value{GDBN} variable object debugging
27038 info. The default is off.
27039 @item show debug varobj
27040 Displays the current state of displaying @value{GDBN} variable object
27043 @item set debug xml
27044 @cindex XML parser debugging
27045 Turn on or off debugging messages for built-in XML parsers.
27046 @item show debug xml
27047 Displays the current state of XML debugging messages.
27050 @node Other Misc Settings
27051 @section Other Miscellaneous Settings
27052 @cindex miscellaneous settings
27055 @kindex set interactive-mode
27056 @item set interactive-mode
27057 If @code{on}, forces @value{GDBN} to assume that GDB was started
27058 in a terminal. In practice, this means that @value{GDBN} should wait
27059 for the user to answer queries generated by commands entered at
27060 the command prompt. If @code{off}, forces @value{GDBN} to operate
27061 in the opposite mode, and it uses the default answers to all queries.
27062 If @code{auto} (the default), @value{GDBN} tries to determine whether
27063 its standard input is a terminal, and works in interactive-mode if it
27064 is, non-interactively otherwise.
27066 In the vast majority of cases, the debugger should be able to guess
27067 correctly which mode should be used. But this setting can be useful
27068 in certain specific cases, such as running a MinGW @value{GDBN}
27069 inside a cygwin window.
27071 @kindex show interactive-mode
27072 @item show interactive-mode
27073 Displays whether the debugger is operating in interactive mode or not.
27076 @node Extending GDB
27077 @chapter Extending @value{GDBN}
27078 @cindex extending GDB
27080 @value{GDBN} provides several mechanisms for extension.
27081 @value{GDBN} also provides the ability to automatically load
27082 extensions when it reads a file for debugging. This allows the
27083 user to automatically customize @value{GDBN} for the program
27086 To facilitate the use of extension languages, @value{GDBN} is capable
27087 of evaluating the contents of a file. When doing so, @value{GDBN}
27088 can recognize which extension language is being used by looking at
27089 the filename extension. Files with an unrecognized filename extension
27090 are always treated as a @value{GDBN} Command Files.
27091 @xref{Command Files,, Command files}.
27093 You can control how @value{GDBN} evaluates these files with the following
27097 @kindex set script-extension
27098 @kindex show script-extension
27099 @item set script-extension off
27100 All scripts are always evaluated as @value{GDBN} Command Files.
27102 @item set script-extension soft
27103 The debugger determines the scripting language based on filename
27104 extension. If this scripting language is supported, @value{GDBN}
27105 evaluates the script using that language. Otherwise, it evaluates
27106 the file as a @value{GDBN} Command File.
27108 @item set script-extension strict
27109 The debugger determines the scripting language based on filename
27110 extension, and evaluates the script using that language. If the
27111 language is not supported, then the evaluation fails.
27113 @item show script-extension
27114 Display the current value of the @code{script-extension} option.
27118 @ifset SYSTEM_GDBINIT_DIR
27119 This setting is not used for files in the system-wide gdbinit directory.
27120 Files in that directory must have an extension matching their language,
27121 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
27122 commands. @xref{Startup}.
27126 * Sequences:: Canned Sequences of @value{GDBN} Commands
27127 * Aliases:: Command Aliases
27128 * Python:: Extending @value{GDBN} using Python
27129 * Guile:: Extending @value{GDBN} using Guile
27130 * Auto-loading extensions:: Automatically loading extensions
27131 * Multiple Extension Languages:: Working with multiple extension languages
27135 @section Canned Sequences of Commands
27137 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
27138 Command Lists}), @value{GDBN} provides two ways to store sequences of
27139 commands for execution as a unit: user-defined commands and command
27143 * Define:: How to define your own commands
27144 * Hooks:: Hooks for user-defined commands
27145 * Command Files:: How to write scripts of commands to be stored in a file
27146 * Output:: Commands for controlled output
27147 * Auto-loading sequences:: Controlling auto-loaded command files
27151 @subsection User-defined Commands
27153 @cindex user-defined command
27154 @cindex arguments, to user-defined commands
27155 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
27156 which you assign a new name as a command. This is done with the
27157 @code{define} command. User commands may accept an unlimited number of arguments
27158 separated by whitespace. Arguments are accessed within the user command
27159 via @code{$arg0@dots{}$argN}. A trivial example:
27163 print $arg0 + $arg1 + $arg2
27168 To execute the command use:
27175 This defines the command @code{adder}, which prints the sum of
27176 its three arguments. Note the arguments are text substitutions, so they may
27177 reference variables, use complex expressions, or even perform inferior
27180 @cindex argument count in user-defined commands
27181 @cindex how many arguments (user-defined commands)
27182 In addition, @code{$argc} may be used to find out how many arguments have
27188 print $arg0 + $arg1
27191 print $arg0 + $arg1 + $arg2
27196 Combining with the @code{eval} command (@pxref{eval}) makes it easier
27197 to process a variable number of arguments:
27204 eval "set $sum = $sum + $arg%d", $i
27214 @item define @var{commandname}
27215 Define a command named @var{commandname}. If there is already a command
27216 by that name, you are asked to confirm that you want to redefine it.
27217 The argument @var{commandname} may be a bare command name consisting of letters,
27218 numbers, dashes, dots, and underscores. It may also start with any
27219 predefined or user-defined prefix command.
27220 For example, @samp{define target my-target} creates
27221 a user-defined @samp{target my-target} command.
27223 The definition of the command is made up of other @value{GDBN} command lines,
27224 which are given following the @code{define} command. The end of these
27225 commands is marked by a line containing @code{end}.
27228 @kindex end@r{ (user-defined commands)}
27229 @item document @var{commandname}
27230 Document the user-defined command @var{commandname}, so that it can be
27231 accessed by @code{help}. The command @var{commandname} must already be
27232 defined. This command reads lines of documentation just as @code{define}
27233 reads the lines of the command definition, ending with @code{end}.
27234 After the @code{document} command is finished, @code{help} on command
27235 @var{commandname} displays the documentation you have written.
27237 You may use the @code{document} command again to change the
27238 documentation of a command. Redefining the command with @code{define}
27239 does not change the documentation.
27241 @kindex define-prefix
27242 @item define-prefix @var{commandname}
27243 Define or mark the command @var{commandname} as a user-defined prefix
27244 command. Once marked, @var{commandname} can be used as prefix command
27245 by the @code{define} command.
27246 Note that @code{define-prefix} can be used with a not yet defined
27247 @var{commandname}. In such a case, @var{commandname} is defined as
27248 an empty user-defined command.
27249 In case you redefine a command that was marked as a user-defined
27250 prefix command, the subcommands of the redefined command are kept
27251 (and @value{GDBN} indicates so to the user).
27255 (gdb) define-prefix abc
27256 (gdb) define-prefix abc def
27257 (gdb) define abc def
27258 Type commands for definition of "abc def".
27259 End with a line saying just "end".
27260 >echo command initial def\n
27262 (gdb) define abc def ghi
27263 Type commands for definition of "abc def ghi".
27264 End with a line saying just "end".
27265 >echo command ghi\n
27267 (gdb) define abc def
27268 Keeping subcommands of prefix command "def".
27269 Redefine command "def"? (y or n) y
27270 Type commands for definition of "abc def".
27271 End with a line saying just "end".
27272 >echo command def\n
27281 @kindex dont-repeat
27282 @cindex don't repeat command
27284 Used inside a user-defined command, this tells @value{GDBN} that this
27285 command should not be repeated when the user hits @key{RET}
27286 (@pxref{Command Syntax, repeat last command}).
27288 @kindex help user-defined
27289 @item help user-defined
27290 List all user-defined commands and all python commands defined in class
27291 COMMAND_USER. The first line of the documentation or docstring is
27296 @itemx show user @var{commandname}
27297 Display the @value{GDBN} commands used to define @var{commandname} (but
27298 not its documentation). If no @var{commandname} is given, display the
27299 definitions for all user-defined commands.
27300 This does not work for user-defined python commands.
27302 @cindex infinite recursion in user-defined commands
27303 @kindex show max-user-call-depth
27304 @kindex set max-user-call-depth
27305 @item show max-user-call-depth
27306 @itemx set max-user-call-depth
27307 The value of @code{max-user-call-depth} controls how many recursion
27308 levels are allowed in user-defined commands before @value{GDBN} suspects an
27309 infinite recursion and aborts the command.
27310 This does not apply to user-defined python commands.
27313 In addition to the above commands, user-defined commands frequently
27314 use control flow commands, described in @ref{Command Files}.
27316 When user-defined commands are executed, the
27317 commands of the definition are not printed. An error in any command
27318 stops execution of the user-defined command.
27320 If used interactively, commands that would ask for confirmation proceed
27321 without asking when used inside a user-defined command. Many @value{GDBN}
27322 commands that normally print messages to say what they are doing omit the
27323 messages when used in a user-defined command.
27326 @subsection User-defined Command Hooks
27327 @cindex command hooks
27328 @cindex hooks, for commands
27329 @cindex hooks, pre-command
27332 You may define @dfn{hooks}, which are a special kind of user-defined
27333 command. Whenever you run the command @samp{foo}, if the user-defined
27334 command @samp{hook-foo} exists, it is executed (with no arguments)
27335 before that command.
27337 @cindex hooks, post-command
27339 A hook may also be defined which is run after the command you executed.
27340 Whenever you run the command @samp{foo}, if the user-defined command
27341 @samp{hookpost-foo} exists, it is executed (with no arguments) after
27342 that command. Post-execution hooks may exist simultaneously with
27343 pre-execution hooks, for the same command.
27345 It is valid for a hook to call the command which it hooks. If this
27346 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
27348 @c It would be nice if hookpost could be passed a parameter indicating
27349 @c if the command it hooks executed properly or not. FIXME!
27351 @kindex stop@r{, a pseudo-command}
27352 In addition, a pseudo-command, @samp{stop} exists. Defining
27353 (@samp{hook-stop}) makes the associated commands execute every time
27354 execution stops in your program: before breakpoint commands are run,
27355 displays are printed, or the stack frame is printed.
27357 For example, to ignore @code{SIGALRM} signals while
27358 single-stepping, but treat them normally during normal execution,
27363 handle SIGALRM nopass
27367 handle SIGALRM pass
27370 define hook-continue
27371 handle SIGALRM pass
27375 As a further example, to hook at the beginning and end of the @code{echo}
27376 command, and to add extra text to the beginning and end of the message,
27384 define hookpost-echo
27388 (@value{GDBP}) echo Hello World
27389 <<<---Hello World--->>>
27394 You can define a hook for any single-word command in @value{GDBN}, but
27395 not for command aliases; you should define a hook for the basic command
27396 name, e.g.@: @code{backtrace} rather than @code{bt}.
27397 @c FIXME! So how does Joe User discover whether a command is an alias
27399 You can hook a multi-word command by adding @code{hook-} or
27400 @code{hookpost-} to the last word of the command, e.g.@:
27401 @samp{define target hook-remote} to add a hook to @samp{target remote}.
27403 If an error occurs during the execution of your hook, execution of
27404 @value{GDBN} commands stops and @value{GDBN} issues a prompt
27405 (before the command that you actually typed had a chance to run).
27407 If you try to define a hook which does not match any known command, you
27408 get a warning from the @code{define} command.
27410 @node Command Files
27411 @subsection Command Files
27413 @cindex command files
27414 @cindex scripting commands
27415 A command file for @value{GDBN} is a text file made of lines that are
27416 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27417 also be included. An empty line in a command file does nothing; it
27418 does not mean to repeat the last command, as it would from the
27421 You can request the execution of a command file with the @code{source}
27422 command. Note that the @code{source} command is also used to evaluate
27423 scripts that are not Command Files. The exact behavior can be configured
27424 using the @code{script-extension} setting.
27425 @xref{Extending GDB,, Extending GDB}.
27429 @cindex execute commands from a file
27430 @item source [-s] [-v] @var{filename}
27431 Execute the command file @var{filename}.
27434 The lines in a command file are generally executed sequentially,
27435 unless the order of execution is changed by one of the
27436 @emph{flow-control commands} described below. The commands are not
27437 printed as they are executed. An error in any command terminates
27438 execution of the command file and control is returned to the console.
27440 @value{GDBN} first searches for @var{filename} in the current directory.
27441 If the file is not found there, and @var{filename} does not specify a
27442 directory, then @value{GDBN} also looks for the file on the source search path
27443 (specified with the @samp{directory} command);
27444 except that @file{$cdir} is not searched because the compilation directory
27445 is not relevant to scripts.
27447 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27448 on the search path even if @var{filename} specifies a directory.
27449 The search is done by appending @var{filename} to each element of the
27450 search path. So, for example, if @var{filename} is @file{mylib/myscript}
27451 and the search path contains @file{/home/user} then @value{GDBN} will
27452 look for the script @file{/home/user/mylib/myscript}.
27453 The search is also done if @var{filename} is an absolute path.
27454 For example, if @var{filename} is @file{/tmp/myscript} and
27455 the search path contains @file{/home/user} then @value{GDBN} will
27456 look for the script @file{/home/user/tmp/myscript}.
27457 For DOS-like systems, if @var{filename} contains a drive specification,
27458 it is stripped before concatenation. For example, if @var{filename} is
27459 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27460 will look for the script @file{c:/tmp/myscript}.
27462 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27463 each command as it is executed. The option must be given before
27464 @var{filename}, and is interpreted as part of the filename anywhere else.
27466 Commands that would ask for confirmation if used interactively proceed
27467 without asking when used in a command file. Many @value{GDBN} commands that
27468 normally print messages to say what they are doing omit the messages
27469 when called from command files.
27471 @value{GDBN} also accepts command input from standard input. In this
27472 mode, normal output goes to standard output and error output goes to
27473 standard error. Errors in a command file supplied on standard input do
27474 not terminate execution of the command file---execution continues with
27478 gdb < cmds > log 2>&1
27481 (The syntax above will vary depending on the shell used.) This example
27482 will execute commands from the file @file{cmds}. All output and errors
27483 would be directed to @file{log}.
27485 Since commands stored on command files tend to be more general than
27486 commands typed interactively, they frequently need to deal with
27487 complicated situations, such as different or unexpected values of
27488 variables and symbols, changes in how the program being debugged is
27489 built, etc. @value{GDBN} provides a set of flow-control commands to
27490 deal with these complexities. Using these commands, you can write
27491 complex scripts that loop over data structures, execute commands
27492 conditionally, etc.
27499 This command allows to include in your script conditionally executed
27500 commands. The @code{if} command takes a single argument, which is an
27501 expression to evaluate. It is followed by a series of commands that
27502 are executed only if the expression is true (its value is nonzero).
27503 There can then optionally be an @code{else} line, followed by a series
27504 of commands that are only executed if the expression was false. The
27505 end of the list is marked by a line containing @code{end}.
27509 This command allows to write loops. Its syntax is similar to
27510 @code{if}: the command takes a single argument, which is an expression
27511 to evaluate, and must be followed by the commands to execute, one per
27512 line, terminated by an @code{end}. These commands are called the
27513 @dfn{body} of the loop. The commands in the body of @code{while} are
27514 executed repeatedly as long as the expression evaluates to true.
27518 This command exits the @code{while} loop in whose body it is included.
27519 Execution of the script continues after that @code{while}s @code{end}
27522 @kindex loop_continue
27523 @item loop_continue
27524 This command skips the execution of the rest of the body of commands
27525 in the @code{while} loop in whose body it is included. Execution
27526 branches to the beginning of the @code{while} loop, where it evaluates
27527 the controlling expression.
27529 @kindex end@r{ (if/else/while commands)}
27531 Terminate the block of commands that are the body of @code{if},
27532 @code{else}, or @code{while} flow-control commands.
27537 @subsection Commands for Controlled Output
27539 During the execution of a command file or a user-defined command, normal
27540 @value{GDBN} output is suppressed; the only output that appears is what is
27541 explicitly printed by the commands in the definition. This section
27542 describes three commands useful for generating exactly the output you
27547 @item echo @var{text}
27548 @c I do not consider backslash-space a standard C escape sequence
27549 @c because it is not in ANSI.
27550 Print @var{text}. Nonprinting characters can be included in
27551 @var{text} using C escape sequences, such as @samp{\n} to print a
27552 newline. @strong{No newline is printed unless you specify one.}
27553 In addition to the standard C escape sequences, a backslash followed
27554 by a space stands for a space. This is useful for displaying a
27555 string with spaces at the beginning or the end, since leading and
27556 trailing spaces are otherwise trimmed from all arguments.
27557 To print @samp{@w{ }and foo =@w{ }}, use the command
27558 @samp{echo \@w{ }and foo = \@w{ }}.
27560 A backslash at the end of @var{text} can be used, as in C, to continue
27561 the command onto subsequent lines. For example,
27564 echo This is some text\n\
27565 which is continued\n\
27566 onto several lines.\n
27569 produces the same output as
27572 echo This is some text\n
27573 echo which is continued\n
27574 echo onto several lines.\n
27578 @item output @var{expression}
27579 Print the value of @var{expression} and nothing but that value: no
27580 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27581 value history either. @xref{Expressions, ,Expressions}, for more information
27584 @item output/@var{fmt} @var{expression}
27585 Print the value of @var{expression} in format @var{fmt}. You can use
27586 the same formats as for @code{print}. @xref{Output Formats,,Output
27587 Formats}, for more information.
27590 @item printf @var{template}, @var{expressions}@dots{}
27591 Print the values of one or more @var{expressions} under the control of
27592 the string @var{template}. To print several values, make
27593 @var{expressions} be a comma-separated list of individual expressions,
27594 which may be either numbers or pointers. Their values are printed as
27595 specified by @var{template}, exactly as a C program would do by
27596 executing the code below:
27599 printf (@var{template}, @var{expressions}@dots{});
27602 As in @code{C} @code{printf}, ordinary characters in @var{template}
27603 are printed verbatim, while @dfn{conversion specification} introduced
27604 by the @samp{%} character cause subsequent @var{expressions} to be
27605 evaluated, their values converted and formatted according to type and
27606 style information encoded in the conversion specifications, and then
27609 For example, you can print two values in hex like this:
27612 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27615 @code{printf} supports all the standard @code{C} conversion
27616 specifications, including the flags and modifiers between the @samp{%}
27617 character and the conversion letter, with the following exceptions:
27621 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27624 The modifier @samp{*} is not supported for specifying precision or
27628 The @samp{'} flag (for separation of digits into groups according to
27629 @code{LC_NUMERIC'}) is not supported.
27632 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27636 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27639 The conversion letters @samp{a} and @samp{A} are not supported.
27643 Note that the @samp{ll} type modifier is supported only if the
27644 underlying @code{C} implementation used to build @value{GDBN} supports
27645 the @code{long long int} type, and the @samp{L} type modifier is
27646 supported only if @code{long double} type is available.
27648 As in @code{C}, @code{printf} supports simple backslash-escape
27649 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27650 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27651 single character. Octal and hexadecimal escape sequences are not
27654 Additionally, @code{printf} supports conversion specifications for DFP
27655 (@dfn{Decimal Floating Point}) types using the following length modifiers
27656 together with a floating point specifier.
27661 @samp{H} for printing @code{Decimal32} types.
27664 @samp{D} for printing @code{Decimal64} types.
27667 @samp{DD} for printing @code{Decimal128} types.
27670 If the underlying @code{C} implementation used to build @value{GDBN} has
27671 support for the three length modifiers for DFP types, other modifiers
27672 such as width and precision will also be available for @value{GDBN} to use.
27674 In case there is no such @code{C} support, no additional modifiers will be
27675 available and the value will be printed in the standard way.
27677 Here's an example of printing DFP types using the above conversion letters:
27679 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27684 @item eval @var{template}, @var{expressions}@dots{}
27685 Convert the values of one or more @var{expressions} under the control of
27686 the string @var{template} to a command line, and call it.
27690 @node Auto-loading sequences
27691 @subsection Controlling auto-loading native @value{GDBN} scripts
27692 @cindex native script auto-loading
27694 When a new object file is read (for example, due to the @code{file}
27695 command, or because the inferior has loaded a shared library),
27696 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27697 @xref{Auto-loading extensions}.
27699 Auto-loading can be enabled or disabled,
27700 and the list of auto-loaded scripts can be printed.
27703 @anchor{set auto-load gdb-scripts}
27704 @kindex set auto-load gdb-scripts
27705 @item set auto-load gdb-scripts [on|off]
27706 Enable or disable the auto-loading of canned sequences of commands scripts.
27708 @anchor{show auto-load gdb-scripts}
27709 @kindex show auto-load gdb-scripts
27710 @item show auto-load gdb-scripts
27711 Show whether auto-loading of canned sequences of commands scripts is enabled or
27714 @anchor{info auto-load gdb-scripts}
27715 @kindex info auto-load gdb-scripts
27716 @cindex print list of auto-loaded canned sequences of commands scripts
27717 @item info auto-load gdb-scripts [@var{regexp}]
27718 Print the list of all canned sequences of commands scripts that @value{GDBN}
27722 If @var{regexp} is supplied only canned sequences of commands scripts with
27723 matching names are printed.
27726 @section Command Aliases
27727 @cindex aliases for commands
27729 Aliases allow you to define alternate spellings for existing commands.
27730 For example, if a new @value{GDBN} command defined in Python
27731 (@pxref{Python}) has a long name, it is handy to have an abbreviated
27732 version of it that involves less typing.
27734 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27735 of the @samp{step} command even though it is otherwise an ambiguous
27736 abbreviation of other commands like @samp{set} and @samp{show}.
27738 Aliases are also used to provide shortened or more common versions
27739 of multi-word commands. For example, @value{GDBN} provides the
27740 @samp{tty} alias of the @samp{set inferior-tty} command.
27742 You can define a new alias with the @samp{alias} command.
27747 @item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
27751 @var{alias} specifies the name of the new alias. Each word of
27752 @var{alias} must consist of letters, numbers, dashes and underscores.
27754 @var{command} specifies the name of an existing command
27755 that is being aliased.
27757 @var{command} can also be the name of an existing alias. In this
27758 case, @var{command} cannot be an alias that has default arguments.
27760 The @samp{-a} option specifies that the new alias is an abbreviation
27761 of the command. Abbreviations are not used in command completion.
27763 The @samp{--} option specifies the end of options,
27764 and is useful when @var{alias} begins with a dash.
27766 You can specify @var{default-args} for your alias. These
27767 @var{default-args} will be automatically added before the alias
27768 arguments typed explicitly on the command line.
27770 For example, the below defines an alias @code{btfullall} that shows all local
27771 variables and all frame arguments:
27773 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27776 For more information about @var{default-args}, see @ref{Command
27777 aliases default args, ,Default Arguments}.
27779 Here is a simple example showing how to make an abbreviation of a
27780 command so that there is less to type. Suppose you were tired of
27781 typing @samp{disas}, the current shortest unambiguous abbreviation of
27782 the @samp{disassemble} command and you wanted an even shorter version
27783 named @samp{di}. The following will accomplish this.
27786 (gdb) alias -a di = disas
27789 Note that aliases are different from user-defined commands. With a
27790 user-defined command, you also need to write documentation for it with
27791 the @samp{document} command. An alias automatically picks up the
27792 documentation of the existing command.
27794 Here is an example where we make @samp{elms} an abbreviation of
27795 @samp{elements} in the @samp{set print elements} command.
27796 This is to show that you can make an abbreviation of any part
27800 (gdb) alias -a set print elms = set print elements
27801 (gdb) alias -a show print elms = show print elements
27802 (gdb) set p elms 20
27804 Limit on string chars or array elements to print is 200.
27807 Note that if you are defining an alias of a @samp{set} command,
27808 and you want to have an alias for the corresponding @samp{show}
27809 command, then you need to define the latter separately.
27811 Unambiguously abbreviated commands are allowed in @var{command} and
27812 @var{alias}, just as they are normally.
27815 (gdb) alias -a set pr elms = set p ele
27818 Finally, here is an example showing the creation of a one word
27819 alias for a more complex command.
27820 This creates alias @samp{spe} of the command @samp{set print elements}.
27823 (gdb) alias spe = set print elements
27828 * Command aliases default args:: Default arguments for aliases
27831 @node Command aliases default args
27832 @subsection Default Arguments
27833 @cindex aliases for commands, default arguments
27835 You can tell @value{GDBN} to always prepend some default arguments to
27836 the list of arguments provided explicitly by the user when using a
27837 user-defined alias.
27839 If you repeatedly use the same arguments or options for a command, you
27840 can define an alias for this command and tell @value{GDBN} to
27841 automatically prepend these arguments or options to the list of
27842 arguments you type explicitly when using the alias@footnote{@value{GDBN}
27843 could easily accept default arguments for pre-defined commands and aliases,
27844 but it was deemed this would be confusing, and so is not allowed.}.
27846 For example, if you often use the command @code{thread apply all}
27847 specifying to work on the threads in ascending order and to continue in case it
27848 encounters an error, you can tell @value{GDBN} to automatically preprend
27849 the @code{-ascending} and @code{-c} options by using:
27852 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
27855 Once you have defined this alias with its default args, any time you type
27856 the @code{thread apply asc-all} followed by @code{some arguments},
27857 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
27859 To have even less to type, you can also define a one word alias:
27861 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
27864 As usual, unambiguous abbreviations can be used for @var{alias}
27865 and @var{default-args}.
27867 The different aliases of a command do not share their default args.
27868 For example, you define a new alias @code{bt_ALL} showing all possible
27869 information and another alias @code{bt_SMALL} showing very limited information
27872 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
27873 -past-main -past-entry -full
27874 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
27875 -past-main off -past-entry off
27878 (For more on using the @code{alias} command, see @ref{Aliases}.)
27880 Default args are not limited to the arguments and options of @var{command},
27881 but can specify nested commands if @var{command} accepts such a nested command
27883 For example, the below defines @code{faalocalsoftype} that lists the
27884 frames having locals of a certain type, together with the matching
27887 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
27888 (@value{GDBP}) faalocalsoftype int
27889 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
27894 This is also very useful to define an alias for a set of nested @code{with}
27895 commands to have a particular combination of temporary settings. For example,
27896 the below defines the alias @code{pp10} that pretty prints an expression
27897 argument, with a maximum of 10 elements if the expression is a string or
27900 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
27902 This defines the alias @code{pp10} as being a sequence of 3 commands.
27903 The first part @code{with print pretty --} temporarily activates the setting
27904 @code{set print pretty}, then launches the command that follows the separator
27906 The command following the first part is also a @code{with} command that
27907 temporarily changes the setting @code{set print elements} to 10, then
27908 launches the command that follows the second separator @code{--}.
27909 The third part @code{print} is the command the @code{pp10} alias will launch,
27910 using the temporary values of the settings and the arguments explicitly given
27912 For more information about the @code{with} command usage,
27913 see @ref{Command Settings}.
27915 @c Python docs live in a separate file.
27916 @include python.texi
27918 @c Guile docs live in a separate file.
27919 @include guile.texi
27921 @node Auto-loading extensions
27922 @section Auto-loading extensions
27923 @cindex auto-loading extensions
27925 @value{GDBN} provides two mechanisms for automatically loading
27926 extensions when a new object file is read (for example, due to the
27927 @code{file} command, or because the inferior has loaded a shared
27928 library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
27929 file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
27930 @code{.debug_gdb_scripts} section of modern file formats like ELF
27931 (@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
27932 section}). For a discussion of the differences between these two
27933 approaches see @ref{Which flavor to choose?}.
27935 The auto-loading feature is useful for supplying application-specific
27936 debugging commands and features.
27938 Auto-loading can be enabled or disabled,
27939 and the list of auto-loaded scripts can be printed.
27940 See the @samp{auto-loading} section of each extension language
27941 for more information.
27942 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27943 For Python files see @ref{Python Auto-loading}.
27945 Note that loading of this script file also requires accordingly configured
27946 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27949 * objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
27950 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
27951 * Which flavor to choose?:: Choosing between these approaches
27954 @node objfile-gdbdotext file
27955 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27956 @cindex @file{@var{objfile}-gdb.gdb}
27957 @cindex @file{@var{objfile}-gdb.py}
27958 @cindex @file{@var{objfile}-gdb.scm}
27960 When a new object file is read, @value{GDBN} looks for a file named
27961 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27962 where @var{objfile} is the object file's name and
27963 where @var{ext} is the file extension for the extension language:
27966 @item @file{@var{objfile}-gdb.gdb}
27967 GDB's own command language
27968 @item @file{@var{objfile}-gdb.py}
27970 @item @file{@var{objfile}-gdb.scm}
27974 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27975 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27976 components, and appending the @file{-gdb.@var{ext}} suffix.
27977 If this file exists and is readable, @value{GDBN} will evaluate it as a
27978 script in the specified extension language.
27980 If this file does not exist, then @value{GDBN} will look for
27981 @var{script-name} file in all of the directories as specified below.
27982 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
27983 directories is converted to a one-letter subdirectory, i.e.@:
27984 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27985 filesystems disallow colons in file names.)
27987 Note that loading of these files requires an accordingly configured
27988 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27990 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27991 scripts normally according to its @file{.exe} filename. But if no scripts are
27992 found @value{GDBN} also tries script filenames matching the object file without
27993 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27994 is attempted on any platform. This makes the script filenames compatible
27995 between Unix and MS-Windows hosts.
27998 @anchor{set auto-load scripts-directory}
27999 @kindex set auto-load scripts-directory
28000 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
28001 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
28002 may be delimited by the host platform path separator in use
28003 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
28005 Each entry here needs to be covered also by the security setting
28006 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
28008 @anchor{with-auto-load-dir}
28009 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
28010 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
28011 configuration option @option{--with-auto-load-dir}.
28013 Any reference to @file{$debugdir} will get replaced by
28014 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
28015 reference to @file{$datadir} will get replaced by @var{data-directory} which is
28016 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
28017 @file{$datadir} must be placed as a directory component --- either alone or
28018 delimited by @file{/} or @file{\} directory separators, depending on the host
28021 The list of directories uses path separator (@samp{:} on GNU and Unix
28022 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
28023 to the @env{PATH} environment variable.
28025 @anchor{show auto-load scripts-directory}
28026 @kindex show auto-load scripts-directory
28027 @item show auto-load scripts-directory
28028 Show @value{GDBN} auto-loaded scripts location.
28030 @anchor{add-auto-load-scripts-directory}
28031 @kindex add-auto-load-scripts-directory
28032 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
28033 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
28034 Multiple entries may be delimited by the host platform path separator in use.
28037 @value{GDBN} does not track which files it has already auto-loaded this way.
28038 @value{GDBN} will load the associated script every time the corresponding
28039 @var{objfile} is opened.
28040 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
28041 is evaluated more than once.
28043 @node dotdebug_gdb_scripts section
28044 @subsection The @code{.debug_gdb_scripts} section
28045 @cindex @code{.debug_gdb_scripts} section
28047 For systems using file formats like ELF and COFF,
28048 when @value{GDBN} loads a new object file
28049 it will look for a special section named @code{.debug_gdb_scripts}.
28050 If this section exists, its contents is a list of null-terminated entries
28051 specifying scripts to load. Each entry begins with a non-null prefix byte that
28052 specifies the kind of entry, typically the extension language and whether the
28053 script is in a file or inlined in @code{.debug_gdb_scripts}.
28055 The following entries are supported:
28058 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
28059 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
28060 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
28061 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
28064 @subsubsection Script File Entries
28066 If the entry specifies a file, @value{GDBN} will look for the file first
28067 in the current directory and then along the source search path
28068 (@pxref{Source Path, ,Specifying Source Directories}),
28069 except that @file{$cdir} is not searched, since the compilation
28070 directory is not relevant to scripts.
28072 File entries can be placed in section @code{.debug_gdb_scripts} with,
28073 for example, this GCC macro for Python scripts.
28076 /* Note: The "MS" section flags are to remove duplicates. */
28077 #define DEFINE_GDB_PY_SCRIPT(script_name) \
28079 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
28080 .byte 1 /* Python */\n\
28081 .asciz \"" script_name "\"\n\
28087 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
28088 Then one can reference the macro in a header or source file like this:
28091 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
28094 The script name may include directories if desired.
28096 Note that loading of this script file also requires accordingly configured
28097 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28099 If the macro invocation is put in a header, any application or library
28100 using this header will get a reference to the specified script,
28101 and with the use of @code{"MS"} attributes on the section, the linker
28102 will remove duplicates.
28104 @subsubsection Script Text Entries
28106 Script text entries allow to put the executable script in the entry
28107 itself instead of loading it from a file.
28108 The first line of the entry, everything after the prefix byte and up to
28109 the first newline (@code{0xa}) character, is the script name, and must not
28110 contain any kind of space character, e.g., spaces or tabs.
28111 The rest of the entry, up to the trailing null byte, is the script to
28112 execute in the specified language. The name needs to be unique among
28113 all script names, as @value{GDBN} executes each script only once based
28116 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
28120 #include "symcat.h"
28121 #include "gdb/section-scripts.h"
28123 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
28124 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
28125 ".ascii \"gdb.inlined-script\\n\"\n"
28126 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
28127 ".ascii \" def __init__ (self):\\n\"\n"
28128 ".ascii \" super (test_cmd, self).__init__ ("
28129 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
28130 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
28131 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
28132 ".ascii \"test_cmd ()\\n\"\n"
28138 Loading of inlined scripts requires a properly configured
28139 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28140 The path to specify in @code{auto-load safe-path} is the path of the file
28141 containing the @code{.debug_gdb_scripts} section.
28143 @node Which flavor to choose?
28144 @subsection Which flavor to choose?
28146 Given the multiple ways of auto-loading extensions, it might not always
28147 be clear which one to choose. This section provides some guidance.
28150 Benefits of the @file{-gdb.@var{ext}} way:
28154 Can be used with file formats that don't support multiple sections.
28157 Ease of finding scripts for public libraries.
28159 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
28160 in the source search path.
28161 For publicly installed libraries, e.g., @file{libstdc++}, there typically
28162 isn't a source directory in which to find the script.
28165 Doesn't require source code additions.
28169 Benefits of the @code{.debug_gdb_scripts} way:
28173 Works with static linking.
28175 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
28176 trigger their loading. When an application is statically linked the only
28177 objfile available is the executable, and it is cumbersome to attach all the
28178 scripts from all the input libraries to the executable's
28179 @file{-gdb.@var{ext}} script.
28182 Works with classes that are entirely inlined.
28184 Some classes can be entirely inlined, and thus there may not be an associated
28185 shared library to attach a @file{-gdb.@var{ext}} script to.
28188 Scripts needn't be copied out of the source tree.
28190 In some circumstances, apps can be built out of large collections of internal
28191 libraries, and the build infrastructure necessary to install the
28192 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
28193 cumbersome. It may be easier to specify the scripts in the
28194 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
28195 top of the source tree to the source search path.
28198 @node Multiple Extension Languages
28199 @section Multiple Extension Languages
28201 The Guile and Python extension languages do not share any state,
28202 and generally do not interfere with each other.
28203 There are some things to be aware of, however.
28205 @subsection Python comes first
28207 Python was @value{GDBN}'s first extension language, and to avoid breaking
28208 existing behaviour Python comes first. This is generally solved by the
28209 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
28210 extension languages, and when it makes a call to an extension language,
28211 (say to pretty-print a value), it tries each in turn until an extension
28212 language indicates it has performed the request (e.g., has returned the
28213 pretty-printed form of a value).
28214 This extends to errors while performing such requests: If an error happens
28215 while, for example, trying to pretty-print an object then the error is
28216 reported and any following extension languages are not tried.
28219 @chapter Command Interpreters
28220 @cindex command interpreters
28222 @value{GDBN} supports multiple command interpreters, and some command
28223 infrastructure to allow users or user interface writers to switch
28224 between interpreters or run commands in other interpreters.
28226 @value{GDBN} currently supports two command interpreters, the console
28227 interpreter (sometimes called the command-line interpreter or @sc{cli})
28228 and the machine interface interpreter (or @sc{gdb/mi}). This manual
28229 describes both of these interfaces in great detail.
28231 By default, @value{GDBN} will start with the console interpreter.
28232 However, the user may choose to start @value{GDBN} with another
28233 interpreter by specifying the @option{-i} or @option{--interpreter}
28234 startup options. Defined interpreters include:
28238 @cindex console interpreter
28239 The traditional console or command-line interpreter. This is the most often
28240 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
28241 @value{GDBN} will use this interpreter.
28244 @cindex mi interpreter
28245 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
28246 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
28247 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
28251 @cindex mi3 interpreter
28252 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
28255 @cindex mi2 interpreter
28256 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
28259 @cindex mi1 interpreter
28260 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
28264 @cindex invoke another interpreter
28266 @kindex interpreter-exec
28267 You may execute commands in any interpreter from the current
28268 interpreter using the appropriate command. If you are running the
28269 console interpreter, simply use the @code{interpreter-exec} command:
28272 interpreter-exec mi "-data-list-register-names"
28275 @sc{gdb/mi} has a similar command, although it is only available in versions of
28276 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28278 Note that @code{interpreter-exec} only changes the interpreter for the
28279 duration of the specified command. It does not change the interpreter
28282 @cindex start a new independent interpreter
28284 Although you may only choose a single interpreter at startup, it is
28285 possible to run an independent interpreter on a specified input/output
28286 device (usually a tty).
28288 For example, consider a debugger GUI or IDE that wants to provide a
28289 @value{GDBN} console view. It may do so by embedding a terminal
28290 emulator widget in its GUI, starting @value{GDBN} in the traditional
28291 command-line mode with stdin/stdout/stderr redirected to that
28292 terminal, and then creating an MI interpreter running on a specified
28293 input/output device. The console interpreter created by @value{GDBN}
28294 at startup handles commands the user types in the terminal widget,
28295 while the GUI controls and synchronizes state with @value{GDBN} using
28296 the separate MI interpreter.
28298 To start a new secondary @dfn{user interface} running MI, use the
28299 @code{new-ui} command:
28302 @cindex new user interface
28304 new-ui @var{interpreter} @var{tty}
28307 The @var{interpreter} parameter specifies the interpreter to run.
28308 This accepts the same values as the @code{interpreter-exec} command.
28309 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28310 @var{tty} parameter specifies the name of the bidirectional file the
28311 interpreter uses for input/output, usually the name of a
28312 pseudoterminal slave on Unix systems. For example:
28315 (@value{GDBP}) new-ui mi /dev/pts/9
28319 runs an MI interpreter on @file{/dev/pts/9}.
28322 @chapter @value{GDBN} Text User Interface
28324 @cindex Text User Interface
28326 The @value{GDBN} Text User Interface (TUI) is a terminal
28327 interface which uses the @code{curses} library to show the source
28328 file, the assembly output, the program registers and @value{GDBN}
28329 commands in separate text windows. The TUI mode is supported only
28330 on platforms where a suitable version of the @code{curses} library
28333 The TUI mode is enabled by default when you invoke @value{GDBN} as
28334 @samp{@value{GDBP} -tui}.
28335 You can also switch in and out of TUI mode while @value{GDBN} runs by
28336 using various TUI commands and key bindings, such as @command{tui
28337 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
28338 @ref{TUI Keys, ,TUI Key Bindings}.
28341 * TUI Overview:: TUI overview
28342 * TUI Keys:: TUI key bindings
28343 * TUI Single Key Mode:: TUI single key mode
28344 * TUI Commands:: TUI-specific commands
28345 * TUI Configuration:: TUI configuration variables
28349 @section TUI Overview
28351 In TUI mode, @value{GDBN} can display several text windows:
28355 This window is the @value{GDBN} command window with the @value{GDBN}
28356 prompt and the @value{GDBN} output. The @value{GDBN} input is still
28357 managed using readline.
28360 The source window shows the source file of the program. The current
28361 line and active breakpoints are displayed in this window.
28364 The assembly window shows the disassembly output of the program.
28367 This window shows the processor registers. Registers are highlighted
28368 when their values change.
28371 The source and assembly windows show the current program position
28372 by highlighting the current line and marking it with a @samp{>} marker.
28373 Breakpoints are indicated with two markers. The first marker
28374 indicates the breakpoint type:
28378 Breakpoint which was hit at least once.
28381 Breakpoint which was never hit.
28384 Hardware breakpoint which was hit at least once.
28387 Hardware breakpoint which was never hit.
28390 The second marker indicates whether the breakpoint is enabled or not:
28394 Breakpoint is enabled.
28397 Breakpoint is disabled.
28400 The source, assembly and register windows are updated when the current
28401 thread changes, when the frame changes, or when the program counter
28404 These windows are not all visible at the same time. The command
28405 window is always visible. The others can be arranged in several
28416 source and assembly,
28419 source and registers, or
28422 assembly and registers.
28425 These are the standard layouts, but other layouts can be defined.
28427 A status line above the command window shows the following information:
28431 Indicates the current @value{GDBN} target.
28432 (@pxref{Targets, ,Specifying a Debugging Target}).
28435 Gives the current process or thread number.
28436 When no process is being debugged, this field is set to @code{No process}.
28439 Gives the current function name for the selected frame.
28440 The name is demangled if demangling is turned on (@pxref{Print Settings}).
28441 When there is no symbol corresponding to the current program counter,
28442 the string @code{??} is displayed.
28445 Indicates the current line number for the selected frame.
28446 When the current line number is not known, the string @code{??} is displayed.
28449 Indicates the current program counter address.
28453 @section TUI Key Bindings
28454 @cindex TUI key bindings
28456 The TUI installs several key bindings in the readline keymaps
28457 @ifset SYSTEM_READLINE
28458 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28460 @ifclear SYSTEM_READLINE
28461 (@pxref{Command Line Editing}).
28463 The following key bindings are installed for both TUI mode and the
28464 @value{GDBN} standard mode.
28473 Enter or leave the TUI mode. When leaving the TUI mode,
28474 the curses window management stops and @value{GDBN} operates using
28475 its standard mode, writing on the terminal directly. When reentering
28476 the TUI mode, control is given back to the curses windows.
28477 The screen is then refreshed.
28479 This key binding uses the bindable Readline function
28480 @code{tui-switch-mode}.
28484 Use a TUI layout with only one window. The layout will
28485 either be @samp{source} or @samp{assembly}. When the TUI mode
28486 is not active, it will switch to the TUI mode.
28488 Think of this key binding as the Emacs @kbd{C-x 1} binding.
28490 This key binding uses the bindable Readline function
28491 @code{tui-delete-other-windows}.
28495 Use a TUI layout with at least two windows. When the current
28496 layout already has two windows, the next layout with two windows is used.
28497 When a new layout is chosen, one window will always be common to the
28498 previous layout and the new one.
28500 Think of it as the Emacs @kbd{C-x 2} binding.
28502 This key binding uses the bindable Readline function
28503 @code{tui-change-windows}.
28507 Change the active window. The TUI associates several key bindings
28508 (like scrolling and arrow keys) with the active window. This command
28509 gives the focus to the next TUI window.
28511 Think of it as the Emacs @kbd{C-x o} binding.
28513 This key binding uses the bindable Readline function
28514 @code{tui-other-window}.
28518 Switch in and out of the TUI SingleKey mode that binds single
28519 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
28521 This key binding uses the bindable Readline function
28522 @code{next-keymap}.
28525 The following key bindings only work in the TUI mode:
28530 Scroll the active window one page up.
28534 Scroll the active window one page down.
28538 Scroll the active window one line up.
28542 Scroll the active window one line down.
28546 Scroll the active window one column left.
28550 Scroll the active window one column right.
28554 Refresh the screen.
28557 Because the arrow keys scroll the active window in the TUI mode, they
28558 are not available for their normal use by readline unless the command
28559 window has the focus. When another window is active, you must use
28560 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28561 and @kbd{C-f} to control the command window.
28563 @node TUI Single Key Mode
28564 @section TUI Single Key Mode
28565 @cindex TUI single key mode
28567 The TUI also provides a @dfn{SingleKey} mode, which binds several
28568 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28569 switch into this mode, where the following key bindings are used:
28572 @kindex c @r{(SingleKey TUI key)}
28576 @kindex d @r{(SingleKey TUI key)}
28580 @kindex f @r{(SingleKey TUI key)}
28584 @kindex n @r{(SingleKey TUI key)}
28588 @kindex o @r{(SingleKey TUI key)}
28590 nexti. The shortcut letter @samp{o} stands for ``step Over''.
28592 @kindex q @r{(SingleKey TUI key)}
28594 exit the SingleKey mode.
28596 @kindex r @r{(SingleKey TUI key)}
28600 @kindex s @r{(SingleKey TUI key)}
28604 @kindex i @r{(SingleKey TUI key)}
28606 stepi. The shortcut letter @samp{i} stands for ``step Into''.
28608 @kindex u @r{(SingleKey TUI key)}
28612 @kindex v @r{(SingleKey TUI key)}
28616 @kindex w @r{(SingleKey TUI key)}
28621 Other keys temporarily switch to the @value{GDBN} command prompt.
28622 The key that was pressed is inserted in the editing buffer so that
28623 it is possible to type most @value{GDBN} commands without interaction
28624 with the TUI SingleKey mode. Once the command is entered the TUI
28625 SingleKey mode is restored. The only way to permanently leave
28626 this mode is by typing @kbd{q} or @kbd{C-x s}.
28628 @cindex SingleKey keymap name
28629 If @value{GDBN} was built with Readline 8.0 or later, the TUI
28630 SingleKey keymap will be named @samp{SingleKey}. This can be used in
28631 @file{.inputrc} to add additional bindings to this keymap.
28634 @section TUI-specific Commands
28635 @cindex TUI commands
28637 The TUI has specific commands to control the text windows.
28638 These commands are always available, even when @value{GDBN} is not in
28639 the TUI mode. When @value{GDBN} is in the standard mode, most
28640 of these commands will automatically switch to the TUI mode.
28642 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28643 terminal, or @value{GDBN} has been started with the machine interface
28644 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28645 these commands will fail with an error, because it would not be
28646 possible or desirable to enable curses window management.
28651 Activate TUI mode. The last active TUI window layout will be used if
28652 TUI mode has previously been used in the current debugging session,
28653 otherwise a default layout is used.
28656 @kindex tui disable
28657 Disable TUI mode, returning to the console interpreter.
28661 List and give the size of all displayed windows.
28663 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28664 @kindex tui new-layout
28665 Create a new TUI layout. The new layout will be named @var{name}, and
28666 can be accessed using the @code{layout} command (see below).
28668 Each @var{window} parameter is either the name of a window to display,
28669 or a window description. The windows will be displayed from top to
28670 bottom in the order listed.
28672 The names of the windows are the same as the ones given to the
28673 @code{focus} command (see below); additional, the @code{status}
28674 window can be specified. Note that, because it is of fixed height,
28675 the weight assigned to the status window is of no importance. It is
28676 conventional to use @samp{0} here.
28678 A window description looks a bit like an invocation of @code{tui
28679 new-layout}, and is of the form
28680 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28682 This specifies a sub-layout. If @code{-horizontal} is given, the
28683 windows in this description will be arranged side-by-side, rather than
28686 Each @var{weight} is an integer. It is the weight of this window
28687 relative to all the other windows in the layout. These numbers are
28688 used to calculate how much of the screen is given to each window.
28693 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28696 Here, the new layout is called @samp{example}. It shows the source
28697 and register windows, followed by the status window, and then finally
28698 the command window. The non-status windows all have the same weight,
28699 so the terminal will be split into three roughly equal sections.
28701 Here is a more complex example, showing a horizontal layout:
28704 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28707 This will result in side-by-side source and assembly windows; with the
28708 status and command window being beneath these, filling the entire
28709 width of the terminal. Because they have weight 2, the source and
28710 assembly windows will be twice the height of the command window.
28712 @item layout @var{name}
28714 Changes which TUI windows are displayed. The @var{name} parameter
28715 controls which layout is shown. It can be either one of the built-in
28716 layout names, or the name of a layout defined by the user using
28717 @code{tui new-layout}.
28719 The built-in layouts are as follows:
28723 Display the next layout.
28726 Display the previous layout.
28729 Display the source and command windows.
28732 Display the assembly and command windows.
28735 Display the source, assembly, and command windows.
28738 When in @code{src} layout display the register, source, and command
28739 windows. When in @code{asm} or @code{split} layout display the
28740 register, assembler, and command windows.
28743 @item focus @var{name}
28745 Changes which TUI window is currently active for scrolling. The
28746 @var{name} parameter can be any of the following:
28750 Make the next window active for scrolling.
28753 Make the previous window active for scrolling.
28756 Make the source window active for scrolling.
28759 Make the assembly window active for scrolling.
28762 Make the register window active for scrolling.
28765 Make the command window active for scrolling.
28770 Refresh the screen. This is similar to typing @kbd{C-L}.
28772 @item tui reg @var{group}
28774 Changes the register group displayed in the tui register window to
28775 @var{group}. If the register window is not currently displayed this
28776 command will cause the register window to be displayed. The list of
28777 register groups, as well as their order is target specific. The
28778 following groups are available on most targets:
28781 Repeatedly selecting this group will cause the display to cycle
28782 through all of the available register groups.
28785 Repeatedly selecting this group will cause the display to cycle
28786 through all of the available register groups in the reverse order to
28790 Display the general registers.
28792 Display the floating point registers.
28794 Display the system registers.
28796 Display the vector registers.
28798 Display all registers.
28803 Update the source window and the current execution point.
28805 @item winheight @var{name} +@var{count}
28806 @itemx winheight @var{name} -@var{count}
28808 Change the height of the window @var{name} by @var{count}
28809 lines. Positive counts increase the height, while negative counts
28810 decrease it. The @var{name} parameter can be one of @code{src} (the
28811 source window), @code{cmd} (the command window), @code{asm} (the
28812 disassembly window), or @code{regs} (the register display window).
28815 @node TUI Configuration
28816 @section TUI Configuration Variables
28817 @cindex TUI configuration variables
28819 Several configuration variables control the appearance of TUI windows.
28822 @item set tui border-kind @var{kind}
28823 @kindex set tui border-kind
28824 Select the border appearance for the source, assembly and register windows.
28825 The possible values are the following:
28828 Use a space character to draw the border.
28831 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28834 Use the Alternate Character Set to draw the border. The border is
28835 drawn using character line graphics if the terminal supports them.
28838 @item set tui border-mode @var{mode}
28839 @kindex set tui border-mode
28840 @itemx set tui active-border-mode @var{mode}
28841 @kindex set tui active-border-mode
28842 Select the display attributes for the borders of the inactive windows
28843 or the active window. The @var{mode} can be one of the following:
28846 Use normal attributes to display the border.
28852 Use reverse video mode.
28855 Use half bright mode.
28857 @item half-standout
28858 Use half bright and standout mode.
28861 Use extra bright or bold mode.
28863 @item bold-standout
28864 Use extra bright or bold and standout mode.
28867 @item set tui tab-width @var{nchars}
28868 @kindex set tui tab-width
28870 Set the width of tab stops to be @var{nchars} characters. This
28871 setting affects the display of TAB characters in the source and
28874 @item set tui compact-source @r{[}on@r{|}off@r{]}
28875 @kindex set tui compact-source
28876 Set whether the TUI source window is displayed in ``compact'' form.
28877 The default display uses more space for line numbers and starts the
28878 source text at the next tab stop; the compact display uses only as
28879 much space as is needed for the line numbers in the current file, and
28880 only a single space to separate the line numbers from the source.
28883 Note that the colors of the TUI borders can be controlled using the
28884 appropriate @code{set style} commands. @xref{Output Styling}.
28887 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28890 @cindex @sc{gnu} Emacs
28891 A special interface allows you to use @sc{gnu} Emacs to view (and
28892 edit) the source files for the program you are debugging with
28895 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28896 executable file you want to debug as an argument. This command starts
28897 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28898 created Emacs buffer.
28899 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28901 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28906 All ``terminal'' input and output goes through an Emacs buffer, called
28909 This applies both to @value{GDBN} commands and their output, and to the input
28910 and output done by the program you are debugging.
28912 This is useful because it means that you can copy the text of previous
28913 commands and input them again; you can even use parts of the output
28916 All the facilities of Emacs' Shell mode are available for interacting
28917 with your program. In particular, you can send signals the usual
28918 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28922 @value{GDBN} displays source code through Emacs.
28924 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28925 source file for that frame and puts an arrow (@samp{=>}) at the
28926 left margin of the current line. Emacs uses a separate buffer for
28927 source display, and splits the screen to show both your @value{GDBN} session
28930 Explicit @value{GDBN} @code{list} or search commands still produce output as
28931 usual, but you probably have no reason to use them from Emacs.
28934 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28935 a graphical mode, enabled by default, which provides further buffers
28936 that can control the execution and describe the state of your program.
28937 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28939 If you specify an absolute file name when prompted for the @kbd{M-x
28940 gdb} argument, then Emacs sets your current working directory to where
28941 your program resides. If you only specify the file name, then Emacs
28942 sets your current working directory to the directory associated
28943 with the previous buffer. In this case, @value{GDBN} may find your
28944 program by searching your environment's @code{PATH} variable, but on
28945 some operating systems it might not find the source. So, although the
28946 @value{GDBN} input and output session proceeds normally, the auxiliary
28947 buffer does not display the current source and line of execution.
28949 The initial working directory of @value{GDBN} is printed on the top
28950 line of the GUD buffer and this serves as a default for the commands
28951 that specify files for @value{GDBN} to operate on. @xref{Files,
28952 ,Commands to Specify Files}.
28954 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28955 need to call @value{GDBN} by a different name (for example, if you
28956 keep several configurations around, with different names) you can
28957 customize the Emacs variable @code{gud-gdb-command-name} to run the
28960 In the GUD buffer, you can use these special Emacs commands in
28961 addition to the standard Shell mode commands:
28965 Describe the features of Emacs' GUD Mode.
28968 Execute to another source line, like the @value{GDBN} @code{step} command; also
28969 update the display window to show the current file and location.
28972 Execute to next source line in this function, skipping all function
28973 calls, like the @value{GDBN} @code{next} command. Then update the display window
28974 to show the current file and location.
28977 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28978 display window accordingly.
28981 Execute until exit from the selected stack frame, like the @value{GDBN}
28982 @code{finish} command.
28985 Continue execution of your program, like the @value{GDBN} @code{continue}
28989 Go up the number of frames indicated by the numeric argument
28990 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28991 like the @value{GDBN} @code{up} command.
28994 Go down the number of frames indicated by the numeric argument, like the
28995 @value{GDBN} @code{down} command.
28998 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28999 tells @value{GDBN} to set a breakpoint on the source line point is on.
29001 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
29002 separate frame which shows a backtrace when the GUD buffer is current.
29003 Move point to any frame in the stack and type @key{RET} to make it
29004 become the current frame and display the associated source in the
29005 source buffer. Alternatively, click @kbd{Mouse-2} to make the
29006 selected frame become the current one. In graphical mode, the
29007 speedbar displays watch expressions.
29009 If you accidentally delete the source-display buffer, an easy way to get
29010 it back is to type the command @code{f} in the @value{GDBN} buffer, to
29011 request a frame display; when you run under Emacs, this recreates
29012 the source buffer if necessary to show you the context of the current
29015 The source files displayed in Emacs are in ordinary Emacs buffers
29016 which are visiting the source files in the usual way. You can edit
29017 the files with these buffers if you wish; but keep in mind that @value{GDBN}
29018 communicates with Emacs in terms of line numbers. If you add or
29019 delete lines from the text, the line numbers that @value{GDBN} knows cease
29020 to correspond properly with the code.
29022 A more detailed description of Emacs' interaction with @value{GDBN} is
29023 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
29027 @chapter The @sc{gdb/mi} Interface
29029 @unnumberedsec Function and Purpose
29031 @cindex @sc{gdb/mi}, its purpose
29032 @sc{gdb/mi} is a line based machine oriented text interface to
29033 @value{GDBN} and is activated by specifying using the
29034 @option{--interpreter} command line option (@pxref{Mode Options}). It
29035 is specifically intended to support the development of systems which
29036 use the debugger as just one small component of a larger system.
29038 This chapter is a specification of the @sc{gdb/mi} interface. It is written
29039 in the form of a reference manual.
29041 Note that @sc{gdb/mi} is still under construction, so some of the
29042 features described below are incomplete and subject to change
29043 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
29045 @unnumberedsec Notation and Terminology
29047 @cindex notational conventions, for @sc{gdb/mi}
29048 This chapter uses the following notation:
29052 @code{|} separates two alternatives.
29055 @code{[ @var{something} ]} indicates that @var{something} is optional:
29056 it may or may not be given.
29059 @code{( @var{group} )*} means that @var{group} inside the parentheses
29060 may repeat zero or more times.
29063 @code{( @var{group} )+} means that @var{group} inside the parentheses
29064 may repeat one or more times.
29067 @code{"@var{string}"} means a literal @var{string}.
29071 @heading Dependencies
29075 * GDB/MI General Design::
29076 * GDB/MI Command Syntax::
29077 * GDB/MI Compatibility with CLI::
29078 * GDB/MI Development and Front Ends::
29079 * GDB/MI Output Records::
29080 * GDB/MI Simple Examples::
29081 * GDB/MI Command Description Format::
29082 * GDB/MI Breakpoint Commands::
29083 * GDB/MI Catchpoint Commands::
29084 * GDB/MI Program Context::
29085 * GDB/MI Thread Commands::
29086 * GDB/MI Ada Tasking Commands::
29087 * GDB/MI Program Execution::
29088 * GDB/MI Stack Manipulation::
29089 * GDB/MI Variable Objects::
29090 * GDB/MI Data Manipulation::
29091 * GDB/MI Tracepoint Commands::
29092 * GDB/MI Symbol Query::
29093 * GDB/MI File Commands::
29095 * GDB/MI Kod Commands::
29096 * GDB/MI Memory Overlay Commands::
29097 * GDB/MI Signal Handling Commands::
29099 * GDB/MI Target Manipulation::
29100 * GDB/MI File Transfer Commands::
29101 * GDB/MI Ada Exceptions Commands::
29102 * GDB/MI Support Commands::
29103 * GDB/MI Miscellaneous Commands::
29106 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29107 @node GDB/MI General Design
29108 @section @sc{gdb/mi} General Design
29109 @cindex GDB/MI General Design
29111 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
29112 parts---commands sent to @value{GDBN}, responses to those commands
29113 and notifications. Each command results in exactly one response,
29114 indicating either successful completion of the command, or an error.
29115 For the commands that do not resume the target, the response contains the
29116 requested information. For the commands that resume the target, the
29117 response only indicates whether the target was successfully resumed.
29118 Notifications is the mechanism for reporting changes in the state of the
29119 target, or in @value{GDBN} state, that cannot conveniently be associated with
29120 a command and reported as part of that command response.
29122 The important examples of notifications are:
29126 Exec notifications. These are used to report changes in
29127 target state---when a target is resumed, or stopped. It would not
29128 be feasible to include this information in response of resuming
29129 commands, because one resume commands can result in multiple events in
29130 different threads. Also, quite some time may pass before any event
29131 happens in the target, while a frontend needs to know whether the resuming
29132 command itself was successfully executed.
29135 Console output, and status notifications. Console output
29136 notifications are used to report output of CLI commands, as well as
29137 diagnostics for other commands. Status notifications are used to
29138 report the progress of a long-running operation. Naturally, including
29139 this information in command response would mean no output is produced
29140 until the command is finished, which is undesirable.
29143 General notifications. Commands may have various side effects on
29144 the @value{GDBN} or target state beyond their official purpose. For example,
29145 a command may change the selected thread. Although such changes can
29146 be included in command response, using notification allows for more
29147 orthogonal frontend design.
29151 There's no guarantee that whenever an MI command reports an error,
29152 @value{GDBN} or the target are in any specific state, and especially,
29153 the state is not reverted to the state before the MI command was
29154 processed. Therefore, whenever an MI command results in an error,
29155 we recommend that the frontend refreshes all the information shown in
29156 the user interface.
29160 * Context management::
29161 * Asynchronous and non-stop modes::
29165 @node Context management
29166 @subsection Context management
29168 @subsubsection Threads and Frames
29170 In most cases when @value{GDBN} accesses the target, this access is
29171 done in context of a specific thread and frame (@pxref{Frames}).
29172 Often, even when accessing global data, the target requires that a thread
29173 be specified. The CLI interface maintains the selected thread and frame,
29174 and supplies them to target on each command. This is convenient,
29175 because a command line user would not want to specify that information
29176 explicitly on each command, and because user interacts with
29177 @value{GDBN} via a single terminal, so no confusion is possible as
29178 to what thread and frame are the current ones.
29180 In the case of MI, the concept of selected thread and frame is less
29181 useful. First, a frontend can easily remember this information
29182 itself. Second, a graphical frontend can have more than one window,
29183 each one used for debugging a different thread, and the frontend might
29184 want to access additional threads for internal purposes. This
29185 increases the risk that by relying on implicitly selected thread, the
29186 frontend may be operating on a wrong one. Therefore, each MI command
29187 should explicitly specify which thread and frame to operate on. To
29188 make it possible, each MI command accepts the @samp{--thread} and
29189 @samp{--frame} options, the value to each is @value{GDBN} global
29190 identifier for thread and frame to operate on.
29192 Usually, each top-level window in a frontend allows the user to select
29193 a thread and a frame, and remembers the user selection for further
29194 operations. However, in some cases @value{GDBN} may suggest that the
29195 current thread or frame be changed. For example, when stopping on a
29196 breakpoint it is reasonable to switch to the thread where breakpoint is
29197 hit. For another example, if the user issues the CLI @samp{thread} or
29198 @samp{frame} commands via the frontend, it is desirable to change the
29199 frontend's selection to the one specified by user. @value{GDBN}
29200 communicates the suggestion to change current thread and frame using the
29201 @samp{=thread-selected} notification.
29203 Note that historically, MI shares the selected thread with CLI, so
29204 frontends used the @code{-thread-select} to execute commands in the
29205 right context. However, getting this to work right is cumbersome. The
29206 simplest way is for frontend to emit @code{-thread-select} command
29207 before every command. This doubles the number of commands that need
29208 to be sent. The alternative approach is to suppress @code{-thread-select}
29209 if the selected thread in @value{GDBN} is supposed to be identical to the
29210 thread the frontend wants to operate on. However, getting this
29211 optimization right can be tricky. In particular, if the frontend
29212 sends several commands to @value{GDBN}, and one of the commands changes the
29213 selected thread, then the behaviour of subsequent commands will
29214 change. So, a frontend should either wait for response from such
29215 problematic commands, or explicitly add @code{-thread-select} for
29216 all subsequent commands. No frontend is known to do this exactly
29217 right, so it is suggested to just always pass the @samp{--thread} and
29218 @samp{--frame} options.
29220 @subsubsection Language
29222 The execution of several commands depends on which language is selected.
29223 By default, the current language (@pxref{show language}) is used.
29224 But for commands known to be language-sensitive, it is recommended
29225 to use the @samp{--language} option. This option takes one argument,
29226 which is the name of the language to use while executing the command.
29230 -data-evaluate-expression --language c "sizeof (void*)"
29235 The valid language names are the same names accepted by the
29236 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
29237 @samp{local} or @samp{unknown}.
29239 @node Asynchronous and non-stop modes
29240 @subsection Asynchronous command execution and non-stop mode
29242 On some targets, @value{GDBN} is capable of processing MI commands
29243 even while the target is running. This is called @dfn{asynchronous
29244 command execution} (@pxref{Background Execution}). The frontend may
29245 specify a preference for asynchronous execution using the
29246 @code{-gdb-set mi-async 1} command, which should be emitted before
29247 either running the executable or attaching to the target. After the
29248 frontend has started the executable or attached to the target, it can
29249 find if asynchronous execution is enabled using the
29250 @code{-list-target-features} command.
29253 @item -gdb-set mi-async on
29254 @item -gdb-set mi-async off
29255 Set whether MI is in asynchronous mode.
29257 When @code{off}, which is the default, MI execution commands (e.g.,
29258 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
29259 for the program to stop before processing further commands.
29261 When @code{on}, MI execution commands are background execution
29262 commands (e.g., @code{-exec-continue} becomes the equivalent of the
29263 @code{c&} CLI command), and so @value{GDBN} is capable of processing
29264 MI commands even while the target is running.
29266 @item -gdb-show mi-async
29267 Show whether MI asynchronous mode is enabled.
29270 Note: In @value{GDBN} version 7.7 and earlier, this option was called
29271 @code{target-async} instead of @code{mi-async}, and it had the effect
29272 of both putting MI in asynchronous mode and making CLI background
29273 commands possible. CLI background commands are now always possible
29274 ``out of the box'' if the target supports them. The old spelling is
29275 kept as a deprecated alias for backwards compatibility.
29277 Even if @value{GDBN} can accept a command while target is running,
29278 many commands that access the target do not work when the target is
29279 running. Therefore, asynchronous command execution is most useful
29280 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29281 it is possible to examine the state of one thread, while other threads
29284 When a given thread is running, MI commands that try to access the
29285 target in the context of that thread may not work, or may work only on
29286 some targets. In particular, commands that try to operate on thread's
29287 stack will not work, on any target. Commands that read memory, or
29288 modify breakpoints, may work or not work, depending on the target. Note
29289 that even commands that operate on global state, such as @code{print},
29290 @code{set}, and breakpoint commands, still access the target in the
29291 context of a specific thread, so frontend should try to find a
29292 stopped thread and perform the operation on that thread (using the
29293 @samp{--thread} option).
29295 Which commands will work in the context of a running thread is
29296 highly target dependent. However, the two commands
29297 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29298 to find the state of a thread, will always work.
29300 @node Thread groups
29301 @subsection Thread groups
29302 @value{GDBN} may be used to debug several processes at the same time.
29303 On some platforms, @value{GDBN} may support debugging of several
29304 hardware systems, each one having several cores with several different
29305 processes running on each core. This section describes the MI
29306 mechanism to support such debugging scenarios.
29308 The key observation is that regardless of the structure of the
29309 target, MI can have a global list of threads, because most commands that
29310 accept the @samp{--thread} option do not need to know what process that
29311 thread belongs to. Therefore, it is not necessary to introduce
29312 neither additional @samp{--process} option, nor an notion of the
29313 current process in the MI interface. The only strictly new feature
29314 that is required is the ability to find how the threads are grouped
29317 To allow the user to discover such grouping, and to support arbitrary
29318 hierarchy of machines/cores/processes, MI introduces the concept of a
29319 @dfn{thread group}. Thread group is a collection of threads and other
29320 thread groups. A thread group always has a string identifier, a type,
29321 and may have additional attributes specific to the type. A new
29322 command, @code{-list-thread-groups}, returns the list of top-level
29323 thread groups, which correspond to processes that @value{GDBN} is
29324 debugging at the moment. By passing an identifier of a thread group
29325 to the @code{-list-thread-groups} command, it is possible to obtain
29326 the members of specific thread group.
29328 To allow the user to easily discover processes, and other objects, he
29329 wishes to debug, a concept of @dfn{available thread group} is
29330 introduced. Available thread group is an thread group that
29331 @value{GDBN} is not debugging, but that can be attached to, using the
29332 @code{-target-attach} command. The list of available top-level thread
29333 groups can be obtained using @samp{-list-thread-groups --available}.
29334 In general, the content of a thread group may be only retrieved only
29335 after attaching to that thread group.
29337 Thread groups are related to inferiors (@pxref{Inferiors Connections and
29338 Programs}). Each inferior corresponds to a thread group of a special
29339 type @samp{process}, and some additional operations are permitted on
29340 such thread groups.
29342 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29343 @node GDB/MI Command Syntax
29344 @section @sc{gdb/mi} Command Syntax
29347 * GDB/MI Input Syntax::
29348 * GDB/MI Output Syntax::
29351 @node GDB/MI Input Syntax
29352 @subsection @sc{gdb/mi} Input Syntax
29354 @cindex input syntax for @sc{gdb/mi}
29355 @cindex @sc{gdb/mi}, input syntax
29357 @item @var{command} @expansion{}
29358 @code{@var{cli-command} | @var{mi-command}}
29360 @item @var{cli-command} @expansion{}
29361 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29362 @var{cli-command} is any existing @value{GDBN} CLI command.
29364 @item @var{mi-command} @expansion{}
29365 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29366 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29368 @item @var{token} @expansion{}
29369 "any sequence of digits"
29371 @item @var{option} @expansion{}
29372 @code{"-" @var{parameter} [ " " @var{parameter} ]}
29374 @item @var{parameter} @expansion{}
29375 @code{@var{non-blank-sequence} | @var{c-string}}
29377 @item @var{operation} @expansion{}
29378 @emph{any of the operations described in this chapter}
29380 @item @var{non-blank-sequence} @expansion{}
29381 @emph{anything, provided it doesn't contain special characters such as
29382 "-", @var{nl}, """ and of course " "}
29384 @item @var{c-string} @expansion{}
29385 @code{""" @var{seven-bit-iso-c-string-content} """}
29387 @item @var{nl} @expansion{}
29396 The CLI commands are still handled by the @sc{mi} interpreter; their
29397 output is described below.
29400 The @code{@var{token}}, when present, is passed back when the command
29404 Some @sc{mi} commands accept optional arguments as part of the parameter
29405 list. Each option is identified by a leading @samp{-} (dash) and may be
29406 followed by an optional argument parameter. Options occur first in the
29407 parameter list and can be delimited from normal parameters using
29408 @samp{--} (this is useful when some parameters begin with a dash).
29415 We want easy access to the existing CLI syntax (for debugging).
29418 We want it to be easy to spot a @sc{mi} operation.
29421 @node GDB/MI Output Syntax
29422 @subsection @sc{gdb/mi} Output Syntax
29424 @cindex output syntax of @sc{gdb/mi}
29425 @cindex @sc{gdb/mi}, output syntax
29426 The output from @sc{gdb/mi} consists of zero or more out-of-band records
29427 followed, optionally, by a single result record. This result record
29428 is for the most recent command. The sequence of output records is
29429 terminated by @samp{(gdb)}.
29431 If an input command was prefixed with a @code{@var{token}} then the
29432 corresponding output for that command will also be prefixed by that same
29436 @item @var{output} @expansion{}
29437 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
29439 @item @var{result-record} @expansion{}
29440 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29442 @item @var{out-of-band-record} @expansion{}
29443 @code{@var{async-record} | @var{stream-record}}
29445 @item @var{async-record} @expansion{}
29446 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29448 @item @var{exec-async-output} @expansion{}
29449 @code{[ @var{token} ] "*" @var{async-output nl}}
29451 @item @var{status-async-output} @expansion{}
29452 @code{[ @var{token} ] "+" @var{async-output nl}}
29454 @item @var{notify-async-output} @expansion{}
29455 @code{[ @var{token} ] "=" @var{async-output nl}}
29457 @item @var{async-output} @expansion{}
29458 @code{@var{async-class} ( "," @var{result} )*}
29460 @item @var{result-class} @expansion{}
29461 @code{"done" | "running" | "connected" | "error" | "exit"}
29463 @item @var{async-class} @expansion{}
29464 @code{"stopped" | @var{others}} (where @var{others} will be added
29465 depending on the needs---this is still in development).
29467 @item @var{result} @expansion{}
29468 @code{ @var{variable} "=" @var{value}}
29470 @item @var{variable} @expansion{}
29471 @code{ @var{string} }
29473 @item @var{value} @expansion{}
29474 @code{ @var{const} | @var{tuple} | @var{list} }
29476 @item @var{const} @expansion{}
29477 @code{@var{c-string}}
29479 @item @var{tuple} @expansion{}
29480 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29482 @item @var{list} @expansion{}
29483 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29484 @var{result} ( "," @var{result} )* "]" }
29486 @item @var{stream-record} @expansion{}
29487 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29489 @item @var{console-stream-output} @expansion{}
29490 @code{"~" @var{c-string nl}}
29492 @item @var{target-stream-output} @expansion{}
29493 @code{"@@" @var{c-string nl}}
29495 @item @var{log-stream-output} @expansion{}
29496 @code{"&" @var{c-string nl}}
29498 @item @var{nl} @expansion{}
29501 @item @var{token} @expansion{}
29502 @emph{any sequence of digits}.
29510 All output sequences end in a single line containing a period.
29513 The @code{@var{token}} is from the corresponding request. Note that
29514 for all async output, while the token is allowed by the grammar and
29515 may be output by future versions of @value{GDBN} for select async
29516 output messages, it is generally omitted. Frontends should treat
29517 all async output as reporting general changes in the state of the
29518 target and there should be no need to associate async output to any
29522 @cindex status output in @sc{gdb/mi}
29523 @var{status-async-output} contains on-going status information about the
29524 progress of a slow operation. It can be discarded. All status output is
29525 prefixed by @samp{+}.
29528 @cindex async output in @sc{gdb/mi}
29529 @var{exec-async-output} contains asynchronous state change on the target
29530 (stopped, started, disappeared). All async output is prefixed by
29534 @cindex notify output in @sc{gdb/mi}
29535 @var{notify-async-output} contains supplementary information that the
29536 client should handle (e.g., a new breakpoint information). All notify
29537 output is prefixed by @samp{=}.
29540 @cindex console output in @sc{gdb/mi}
29541 @var{console-stream-output} is output that should be displayed as is in the
29542 console. It is the textual response to a CLI command. All the console
29543 output is prefixed by @samp{~}.
29546 @cindex target output in @sc{gdb/mi}
29547 @var{target-stream-output} is the output produced by the target program.
29548 All the target output is prefixed by @samp{@@}.
29551 @cindex log output in @sc{gdb/mi}
29552 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29553 instance messages that should be displayed as part of an error log. All
29554 the log output is prefixed by @samp{&}.
29557 @cindex list output in @sc{gdb/mi}
29558 New @sc{gdb/mi} commands should only output @var{lists} containing
29564 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29565 details about the various output records.
29567 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29568 @node GDB/MI Compatibility with CLI
29569 @section @sc{gdb/mi} Compatibility with CLI
29571 @cindex compatibility, @sc{gdb/mi} and CLI
29572 @cindex @sc{gdb/mi}, compatibility with CLI
29574 For the developers convenience CLI commands can be entered directly,
29575 but there may be some unexpected behaviour. For example, commands
29576 that query the user will behave as if the user replied yes, breakpoint
29577 command lists are not executed and some CLI commands, such as
29578 @code{if}, @code{when} and @code{define}, prompt for further input with
29579 @samp{>}, which is not valid MI output.
29581 This feature may be removed at some stage in the future and it is
29582 recommended that front ends use the @code{-interpreter-exec} command
29583 (@pxref{-interpreter-exec}).
29585 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29586 @node GDB/MI Development and Front Ends
29587 @section @sc{gdb/mi} Development and Front Ends
29588 @cindex @sc{gdb/mi} development
29590 The application which takes the MI output and presents the state of the
29591 program being debugged to the user is called a @dfn{front end}.
29593 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29594 to the MI interface may break existing usage. This section describes how the
29595 protocol changes and how to request previous version of the protocol when it
29598 Some changes in MI need not break a carefully designed front end, and
29599 for these the MI version will remain unchanged. The following is a
29600 list of changes that may occur within one level, so front ends should
29601 parse MI output in a way that can handle them:
29605 New MI commands may be added.
29608 New fields may be added to the output of any MI command.
29611 The range of values for fields with specified values, e.g.,
29612 @code{in_scope} (@pxref{-var-update}) may be extended.
29614 @c The format of field's content e.g type prefix, may change so parse it
29615 @c at your own risk. Yes, in general?
29617 @c The order of fields may change? Shouldn't really matter but it might
29618 @c resolve inconsistencies.
29621 If the changes are likely to break front ends, the MI version level
29622 will be increased by one. The new versions of the MI protocol are not compatible
29623 with the old versions. Old versions of MI remain available, allowing front ends
29624 to keep using them until they are modified to use the latest MI version.
29626 Since @code{--interpreter=mi} always points to the latest MI version, it is
29627 recommended that front ends request a specific version of MI when launching
29628 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29629 interpreter with the MI version they expect.
29631 The following table gives a summary of the released versions of the MI
29632 interface: the version number, the version of GDB in which it first appeared
29633 and the breaking changes compared to the previous version.
29635 @multitable @columnfractions .05 .05 .9
29636 @headitem MI version @tab GDB version @tab Breaking changes
29653 The @code{-environment-pwd}, @code{-environment-directory} and
29654 @code{-environment-path} commands now returns values using the MI output
29655 syntax, rather than CLI output syntax.
29658 @code{-var-list-children}'s @code{children} result field is now a list, rather
29662 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29674 The output of information about multi-location breakpoints has changed in the
29675 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29676 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29677 The multiple locations are now placed in a @code{locations} field, whose value
29683 If your front end cannot yet migrate to a more recent version of the
29684 MI protocol, you can nevertheless selectively enable specific features
29685 available in those recent MI versions, using the following commands:
29689 @item -fix-multi-location-breakpoint-output
29690 Use the output for multi-location breakpoints which was introduced by
29691 MI 3, even when using MI versions 2 or 1. This command has no
29692 effect when using MI version 3 or later.
29696 The best way to avoid unexpected changes in MI that might break your front
29697 end is to make your project known to @value{GDBN} developers and
29698 follow development on @email{gdb@@sourceware.org} and
29699 @email{gdb-patches@@sourceware.org}.
29700 @cindex mailing lists
29702 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29703 @node GDB/MI Output Records
29704 @section @sc{gdb/mi} Output Records
29707 * GDB/MI Result Records::
29708 * GDB/MI Stream Records::
29709 * GDB/MI Async Records::
29710 * GDB/MI Breakpoint Information::
29711 * GDB/MI Frame Information::
29712 * GDB/MI Thread Information::
29713 * GDB/MI Ada Exception Information::
29716 @node GDB/MI Result Records
29717 @subsection @sc{gdb/mi} Result Records
29719 @cindex result records in @sc{gdb/mi}
29720 @cindex @sc{gdb/mi}, result records
29721 In addition to a number of out-of-band notifications, the response to a
29722 @sc{gdb/mi} command includes one of the following result indications:
29726 @item "^done" [ "," @var{results} ]
29727 The synchronous operation was successful, @code{@var{results}} are the return
29732 This result record is equivalent to @samp{^done}. Historically, it
29733 was output instead of @samp{^done} if the command has resumed the
29734 target. This behaviour is maintained for backward compatibility, but
29735 all frontends should treat @samp{^done} and @samp{^running}
29736 identically and rely on the @samp{*running} output record to determine
29737 which threads are resumed.
29741 @value{GDBN} has connected to a remote target.
29743 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29745 The operation failed. The @code{msg=@var{c-string}} variable contains
29746 the corresponding error message.
29748 If present, the @code{code=@var{c-string}} variable provides an error
29749 code on which consumers can rely on to detect the corresponding
29750 error condition. At present, only one error code is defined:
29753 @item "undefined-command"
29754 Indicates that the command causing the error does not exist.
29759 @value{GDBN} has terminated.
29763 @node GDB/MI Stream Records
29764 @subsection @sc{gdb/mi} Stream Records
29766 @cindex @sc{gdb/mi}, stream records
29767 @cindex stream records in @sc{gdb/mi}
29768 @value{GDBN} internally maintains a number of output streams: the console, the
29769 target, and the log. The output intended for each of these streams is
29770 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29772 Each stream record begins with a unique @dfn{prefix character} which
29773 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29774 Syntax}). In addition to the prefix, each stream record contains a
29775 @code{@var{string-output}}. This is either raw text (with an implicit new
29776 line) or a quoted C string (which does not contain an implicit newline).
29779 @item "~" @var{string-output}
29780 The console output stream contains text that should be displayed in the
29781 CLI console window. It contains the textual responses to CLI commands.
29783 @item "@@" @var{string-output}
29784 The target output stream contains any textual output from the running
29785 target. This is only present when GDB's event loop is truly
29786 asynchronous, which is currently only the case for remote targets.
29788 @item "&" @var{string-output}
29789 The log stream contains debugging messages being produced by @value{GDBN}'s
29793 @node GDB/MI Async Records
29794 @subsection @sc{gdb/mi} Async Records
29796 @cindex async records in @sc{gdb/mi}
29797 @cindex @sc{gdb/mi}, async records
29798 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29799 additional changes that have occurred. Those changes can either be a
29800 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29801 target activity (e.g., target stopped).
29803 The following is the list of possible async records:
29807 @item *running,thread-id="@var{thread}"
29808 The target is now running. The @var{thread} field can be the global
29809 thread ID of the thread that is now running, and it can be
29810 @samp{all} if all threads are running. The frontend should assume
29811 that no interaction with a running thread is possible after this
29812 notification is produced. The frontend should not assume that this
29813 notification is output only once for any command. @value{GDBN} may
29814 emit this notification several times, either for different threads,
29815 because it cannot resume all threads together, or even for a single
29816 thread, if the thread must be stepped though some code before letting
29819 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29820 The target has stopped. The @var{reason} field can have one of the
29824 @item breakpoint-hit
29825 A breakpoint was reached.
29826 @item watchpoint-trigger
29827 A watchpoint was triggered.
29828 @item read-watchpoint-trigger
29829 A read watchpoint was triggered.
29830 @item access-watchpoint-trigger
29831 An access watchpoint was triggered.
29832 @item function-finished
29833 An -exec-finish or similar CLI command was accomplished.
29834 @item location-reached
29835 An -exec-until or similar CLI command was accomplished.
29836 @item watchpoint-scope
29837 A watchpoint has gone out of scope.
29838 @item end-stepping-range
29839 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29840 similar CLI command was accomplished.
29841 @item exited-signalled
29842 The inferior exited because of a signal.
29844 The inferior exited.
29845 @item exited-normally
29846 The inferior exited normally.
29847 @item signal-received
29848 A signal was received by the inferior.
29850 The inferior has stopped due to a library being loaded or unloaded.
29851 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29852 set or when a @code{catch load} or @code{catch unload} catchpoint is
29853 in use (@pxref{Set Catchpoints}).
29855 The inferior has forked. This is reported when @code{catch fork}
29856 (@pxref{Set Catchpoints}) has been used.
29858 The inferior has vforked. This is reported in when @code{catch vfork}
29859 (@pxref{Set Catchpoints}) has been used.
29860 @item syscall-entry
29861 The inferior entered a system call. This is reported when @code{catch
29862 syscall} (@pxref{Set Catchpoints}) has been used.
29863 @item syscall-return
29864 The inferior returned from a system call. This is reported when
29865 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29867 The inferior called @code{exec}. This is reported when @code{catch exec}
29868 (@pxref{Set Catchpoints}) has been used.
29871 The @var{id} field identifies the global thread ID of the thread
29872 that directly caused the stop -- for example by hitting a breakpoint.
29873 Depending on whether all-stop
29874 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29875 stop all threads, or only the thread that directly triggered the stop.
29876 If all threads are stopped, the @var{stopped} field will have the
29877 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29878 field will be a list of thread identifiers. Presently, this list will
29879 always include a single thread, but frontend should be prepared to see
29880 several threads in the list. The @var{core} field reports the
29881 processor core on which the stop event has happened. This field may be absent
29882 if such information is not available.
29884 @item =thread-group-added,id="@var{id}"
29885 @itemx =thread-group-removed,id="@var{id}"
29886 A thread group was either added or removed. The @var{id} field
29887 contains the @value{GDBN} identifier of the thread group. When a thread
29888 group is added, it generally might not be associated with a running
29889 process. When a thread group is removed, its id becomes invalid and
29890 cannot be used in any way.
29892 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29893 A thread group became associated with a running program,
29894 either because the program was just started or the thread group
29895 was attached to a program. The @var{id} field contains the
29896 @value{GDBN} identifier of the thread group. The @var{pid} field
29897 contains process identifier, specific to the operating system.
29899 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29900 A thread group is no longer associated with a running program,
29901 either because the program has exited, or because it was detached
29902 from. The @var{id} field contains the @value{GDBN} identifier of the
29903 thread group. The @var{code} field is the exit code of the inferior; it exists
29904 only when the inferior exited with some code.
29906 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29907 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29908 A thread either was created, or has exited. The @var{id} field
29909 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29910 field identifies the thread group this thread belongs to.
29912 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29913 Informs that the selected thread or frame were changed. This notification
29914 is not emitted as result of the @code{-thread-select} or
29915 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29916 that is not documented to change the selected thread and frame actually
29917 changes them. In particular, invoking, directly or indirectly
29918 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29919 will generate this notification. Changing the thread or frame from another
29920 user interface (see @ref{Interpreters}) will also generate this notification.
29922 The @var{frame} field is only present if the newly selected thread is
29923 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29925 We suggest that in response to this notification, front ends
29926 highlight the selected thread and cause subsequent commands to apply to
29929 @item =library-loaded,...
29930 Reports that a new library file was loaded by the program. This
29931 notification has 5 fields---@var{id}, @var{target-name},
29932 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29933 opaque identifier of the library. For remote debugging case,
29934 @var{target-name} and @var{host-name} fields give the name of the
29935 library file on the target, and on the host respectively. For native
29936 debugging, both those fields have the same value. The
29937 @var{symbols-loaded} field is emitted only for backward compatibility
29938 and should not be relied on to convey any useful information. The
29939 @var{thread-group} field, if present, specifies the id of the thread
29940 group in whose context the library was loaded. If the field is
29941 absent, it means the library was loaded in the context of all present
29942 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29945 @item =library-unloaded,...
29946 Reports that a library was unloaded by the program. This notification
29947 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29948 the same meaning as for the @code{=library-loaded} notification.
29949 The @var{thread-group} field, if present, specifies the id of the
29950 thread group in whose context the library was unloaded. If the field is
29951 absent, it means the library was unloaded in the context of all present
29954 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29955 @itemx =traceframe-changed,end
29956 Reports that the trace frame was changed and its new number is
29957 @var{tfnum}. The number of the tracepoint associated with this trace
29958 frame is @var{tpnum}.
29960 @item =tsv-created,name=@var{name},initial=@var{initial}
29961 Reports that the new trace state variable @var{name} is created with
29962 initial value @var{initial}.
29964 @item =tsv-deleted,name=@var{name}
29965 @itemx =tsv-deleted
29966 Reports that the trace state variable @var{name} is deleted or all
29967 trace state variables are deleted.
29969 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29970 Reports that the trace state variable @var{name} is modified with
29971 the initial value @var{initial}. The current value @var{current} of
29972 trace state variable is optional and is reported if the current
29973 value of trace state variable is known.
29975 @item =breakpoint-created,bkpt=@{...@}
29976 @itemx =breakpoint-modified,bkpt=@{...@}
29977 @itemx =breakpoint-deleted,id=@var{number}
29978 Reports that a breakpoint was created, modified, or deleted,
29979 respectively. Only user-visible breakpoints are reported to the MI
29982 The @var{bkpt} argument is of the same form as returned by the various
29983 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29984 @var{number} is the ordinal number of the breakpoint.
29986 Note that if a breakpoint is emitted in the result record of a
29987 command, then it will not also be emitted in an async record.
29989 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29990 @itemx =record-stopped,thread-group="@var{id}"
29991 Execution log recording was either started or stopped on an
29992 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29993 group corresponding to the affected inferior.
29995 The @var{method} field indicates the method used to record execution. If the
29996 method in use supports multiple recording formats, @var{format} will be present
29997 and contain the currently used format. @xref{Process Record and Replay},
29998 for existing method and format values.
30000 @item =cmd-param-changed,param=@var{param},value=@var{value}
30001 Reports that a parameter of the command @code{set @var{param}} is
30002 changed to @var{value}. In the multi-word @code{set} command,
30003 the @var{param} is the whole parameter list to @code{set} command.
30004 For example, In command @code{set check type on}, @var{param}
30005 is @code{check type} and @var{value} is @code{on}.
30007 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
30008 Reports that bytes from @var{addr} to @var{data} + @var{len} were
30009 written in an inferior. The @var{id} is the identifier of the
30010 thread group corresponding to the affected inferior. The optional
30011 @code{type="code"} part is reported if the memory written to holds
30015 @node GDB/MI Breakpoint Information
30016 @subsection @sc{gdb/mi} Breakpoint Information
30018 When @value{GDBN} reports information about a breakpoint, a
30019 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
30024 The breakpoint number.
30027 The type of the breakpoint. For ordinary breakpoints this will be
30028 @samp{breakpoint}, but many values are possible.
30031 If the type of the breakpoint is @samp{catchpoint}, then this
30032 indicates the exact type of catchpoint.
30035 This is the breakpoint disposition---either @samp{del}, meaning that
30036 the breakpoint will be deleted at the next stop, or @samp{keep},
30037 meaning that the breakpoint will not be deleted.
30040 This indicates whether the breakpoint is enabled, in which case the
30041 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30042 Note that this is not the same as the field @code{enable}.
30045 The address of the breakpoint. This may be a hexidecimal number,
30046 giving the address; or the string @samp{<PENDING>}, for a pending
30047 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
30048 multiple locations. This field will not be present if no address can
30049 be determined. For example, a watchpoint does not have an address.
30052 Optional field containing any flags related to the address. These flags are
30053 architecture-dependent; see @ref{Architectures} for their meaning for a
30057 If known, the function in which the breakpoint appears.
30058 If not known, this field is not present.
30061 The name of the source file which contains this function, if known.
30062 If not known, this field is not present.
30065 The full file name of the source file which contains this function, if
30066 known. If not known, this field is not present.
30069 The line number at which this breakpoint appears, if known.
30070 If not known, this field is not present.
30073 If the source file is not known, this field may be provided. If
30074 provided, this holds the address of the breakpoint, possibly followed
30078 If this breakpoint is pending, this field is present and holds the
30079 text used to set the breakpoint, as entered by the user.
30082 Where this breakpoint's condition is evaluated, either @samp{host} or
30086 If this is a thread-specific breakpoint, then this identifies the
30087 thread in which the breakpoint can trigger.
30090 If this breakpoint is restricted to a particular Ada task, then this
30091 field will hold the task identifier.
30094 If the breakpoint is conditional, this is the condition expression.
30097 The ignore count of the breakpoint.
30100 The enable count of the breakpoint.
30102 @item traceframe-usage
30105 @item static-tracepoint-marker-string-id
30106 For a static tracepoint, the name of the static tracepoint marker.
30109 For a masked watchpoint, this is the mask.
30112 A tracepoint's pass count.
30114 @item original-location
30115 The location of the breakpoint as originally specified by the user.
30116 This field is optional.
30119 The number of times the breakpoint has been hit.
30122 This field is only given for tracepoints. This is either @samp{y},
30123 meaning that the tracepoint is installed, or @samp{n}, meaning that it
30127 Some extra data, the exact contents of which are type-dependent.
30130 This field is present if the breakpoint has multiple locations. It is also
30131 exceptionally present if the breakpoint is enabled and has a single, disabled
30134 The value is a list of locations. The format of a location is described below.
30138 A location in a multi-location breakpoint is represented as a tuple with the
30144 The location number as a dotted pair, like @samp{1.2}. The first digit is the
30145 number of the parent breakpoint. The second digit is the number of the
30146 location within that breakpoint.
30149 This indicates whether the location is enabled, in which case the
30150 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30151 Note that this is not the same as the field @code{enable}.
30154 The address of this location as an hexidecimal number.
30157 Optional field containing any flags related to the address. These flags are
30158 architecture-dependent; see @ref{Architectures} for their meaning for a
30162 If known, the function in which the location appears.
30163 If not known, this field is not present.
30166 The name of the source file which contains this location, if known.
30167 If not known, this field is not present.
30170 The full file name of the source file which contains this location, if
30171 known. If not known, this field is not present.
30174 The line number at which this location appears, if known.
30175 If not known, this field is not present.
30177 @item thread-groups
30178 The thread groups this location is in.
30182 For example, here is what the output of @code{-break-insert}
30183 (@pxref{GDB/MI Breakpoint Commands}) might be:
30186 -> -break-insert main
30187 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30188 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30189 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30194 @node GDB/MI Frame Information
30195 @subsection @sc{gdb/mi} Frame Information
30197 Response from many MI commands includes an information about stack
30198 frame. This information is a tuple that may have the following
30203 The level of the stack frame. The innermost frame has the level of
30204 zero. This field is always present.
30207 The name of the function corresponding to the frame. This field may
30208 be absent if @value{GDBN} is unable to determine the function name.
30211 The code address for the frame. This field is always present.
30214 Optional field containing any flags related to the address. These flags are
30215 architecture-dependent; see @ref{Architectures} for their meaning for a
30219 The name of the source files that correspond to the frame's code
30220 address. This field may be absent.
30223 The source line corresponding to the frames' code address. This field
30227 The name of the binary file (either executable or shared library) the
30228 corresponds to the frame's code address. This field may be absent.
30232 @node GDB/MI Thread Information
30233 @subsection @sc{gdb/mi} Thread Information
30235 Whenever @value{GDBN} has to report an information about a thread, it
30236 uses a tuple with the following fields. The fields are always present unless
30241 The global numeric id assigned to the thread by @value{GDBN}.
30244 The target-specific string identifying the thread.
30247 Additional information about the thread provided by the target.
30248 It is supposed to be human-readable and not interpreted by the
30249 frontend. This field is optional.
30252 The name of the thread. If the user specified a name using the
30253 @code{thread name} command, then this name is given. Otherwise, if
30254 @value{GDBN} can extract the thread name from the target, then that
30255 name is given. If @value{GDBN} cannot find the thread name, then this
30259 The execution state of the thread, either @samp{stopped} or @samp{running},
30260 depending on whether the thread is presently running.
30263 The stack frame currently executing in the thread. This field is only present
30264 if the thread is stopped. Its format is documented in
30265 @ref{GDB/MI Frame Information}.
30268 The value of this field is an integer number of the processor core the
30269 thread was last seen on. This field is optional.
30272 @node GDB/MI Ada Exception Information
30273 @subsection @sc{gdb/mi} Ada Exception Information
30275 Whenever a @code{*stopped} record is emitted because the program
30276 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30277 @value{GDBN} provides the name of the exception that was raised via
30278 the @code{exception-name} field. Also, for exceptions that were raised
30279 with an exception message, @value{GDBN} provides that message via
30280 the @code{exception-message} field.
30282 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30283 @node GDB/MI Simple Examples
30284 @section Simple Examples of @sc{gdb/mi} Interaction
30285 @cindex @sc{gdb/mi}, simple examples
30287 This subsection presents several simple examples of interaction using
30288 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30289 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30290 the output received from @sc{gdb/mi}.
30292 Note the line breaks shown in the examples are here only for
30293 readability, they don't appear in the real output.
30295 @subheading Setting a Breakpoint
30297 Setting a breakpoint generates synchronous output which contains detailed
30298 information of the breakpoint.
30301 -> -break-insert main
30302 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30303 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30304 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30309 @subheading Program Execution
30311 Program execution generates asynchronous records and MI gives the
30312 reason that execution stopped.
30318 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
30319 frame=@{addr="0x08048564",func="main",
30320 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
30321 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30322 arch="i386:x86_64"@}
30327 <- *stopped,reason="exited-normally"
30331 @subheading Quitting @value{GDBN}
30333 Quitting @value{GDBN} just prints the result class @samp{^exit}.
30341 Please note that @samp{^exit} is printed immediately, but it might
30342 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30343 performs necessary cleanups, including killing programs being debugged
30344 or disconnecting from debug hardware, so the frontend should wait till
30345 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30346 fails to exit in reasonable time.
30348 @subheading A Bad Command
30350 Here's what happens if you pass a non-existent command:
30354 <- ^error,msg="Undefined MI command: rubbish"
30359 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30360 @node GDB/MI Command Description Format
30361 @section @sc{gdb/mi} Command Description Format
30363 The remaining sections describe blocks of commands. Each block of
30364 commands is laid out in a fashion similar to this section.
30366 @subheading Motivation
30368 The motivation for this collection of commands.
30370 @subheading Introduction
30372 A brief introduction to this collection of commands as a whole.
30374 @subheading Commands
30376 For each command in the block, the following is described:
30378 @subsubheading Synopsis
30381 -command @var{args}@dots{}
30384 @subsubheading Result
30386 @subsubheading @value{GDBN} Command
30388 The corresponding @value{GDBN} CLI command(s), if any.
30390 @subsubheading Example
30392 Example(s) formatted for readability. Some of the described commands have
30393 not been implemented yet and these are labeled N.A.@: (not available).
30396 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30397 @node GDB/MI Breakpoint Commands
30398 @section @sc{gdb/mi} Breakpoint Commands
30400 @cindex breakpoint commands for @sc{gdb/mi}
30401 @cindex @sc{gdb/mi}, breakpoint commands
30402 This section documents @sc{gdb/mi} commands for manipulating
30405 @subheading The @code{-break-after} Command
30406 @findex -break-after
30408 @subsubheading Synopsis
30411 -break-after @var{number} @var{count}
30414 The breakpoint number @var{number} is not in effect until it has been
30415 hit @var{count} times. To see how this is reflected in the output of
30416 the @samp{-break-list} command, see the description of the
30417 @samp{-break-list} command below.
30419 @subsubheading @value{GDBN} Command
30421 The corresponding @value{GDBN} command is @samp{ignore}.
30423 @subsubheading Example
30428 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30429 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30430 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30438 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30439 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30440 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30441 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30442 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30443 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30444 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30445 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30446 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30447 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
30452 @subheading The @code{-break-catch} Command
30453 @findex -break-catch
30456 @subheading The @code{-break-commands} Command
30457 @findex -break-commands
30459 @subsubheading Synopsis
30462 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30465 Specifies the CLI commands that should be executed when breakpoint
30466 @var{number} is hit. The parameters @var{command1} to @var{commandN}
30467 are the commands. If no command is specified, any previously-set
30468 commands are cleared. @xref{Break Commands}. Typical use of this
30469 functionality is tracing a program, that is, printing of values of
30470 some variables whenever breakpoint is hit and then continuing.
30472 @subsubheading @value{GDBN} Command
30474 The corresponding @value{GDBN} command is @samp{commands}.
30476 @subsubheading Example
30481 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30482 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30483 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30486 -break-commands 1 "print v" "continue"
30491 @subheading The @code{-break-condition} Command
30492 @findex -break-condition
30494 @subsubheading Synopsis
30497 -break-condition @var{number} @var{expr}
30500 Breakpoint @var{number} will stop the program only if the condition in
30501 @var{expr} is true. The condition becomes part of the
30502 @samp{-break-list} output (see the description of the @samp{-break-list}
30505 @subsubheading @value{GDBN} Command
30507 The corresponding @value{GDBN} command is @samp{condition}.
30509 @subsubheading Example
30513 -break-condition 1 1
30517 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30518 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30519 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30520 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30521 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30522 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30523 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30524 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30525 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30526 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
30530 @subheading The @code{-break-delete} Command
30531 @findex -break-delete
30533 @subsubheading Synopsis
30536 -break-delete ( @var{breakpoint} )+
30539 Delete the breakpoint(s) whose number(s) are specified in the argument
30540 list. This is obviously reflected in the breakpoint list.
30542 @subsubheading @value{GDBN} Command
30544 The corresponding @value{GDBN} command is @samp{delete}.
30546 @subsubheading Example
30554 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30555 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30556 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30557 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30558 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30559 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30560 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30565 @subheading The @code{-break-disable} Command
30566 @findex -break-disable
30568 @subsubheading Synopsis
30571 -break-disable ( @var{breakpoint} )+
30574 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30575 break list is now set to @samp{n} for the named @var{breakpoint}(s).
30577 @subsubheading @value{GDBN} Command
30579 The corresponding @value{GDBN} command is @samp{disable}.
30581 @subsubheading Example
30589 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30590 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30591 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30592 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30593 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30594 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30595 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30596 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30597 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30598 line="5",thread-groups=["i1"],times="0"@}]@}
30602 @subheading The @code{-break-enable} Command
30603 @findex -break-enable
30605 @subsubheading Synopsis
30608 -break-enable ( @var{breakpoint} )+
30611 Enable (previously disabled) @var{breakpoint}(s).
30613 @subsubheading @value{GDBN} Command
30615 The corresponding @value{GDBN} command is @samp{enable}.
30617 @subsubheading Example
30625 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30626 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30627 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30628 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30629 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30630 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30631 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30632 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30633 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30634 line="5",thread-groups=["i1"],times="0"@}]@}
30638 @subheading The @code{-break-info} Command
30639 @findex -break-info
30641 @subsubheading Synopsis
30644 -break-info @var{breakpoint}
30648 Get information about a single breakpoint.
30650 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30651 Information}, for details on the format of each breakpoint in the
30654 @subsubheading @value{GDBN} Command
30656 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30658 @subsubheading Example
30661 @subheading The @code{-break-insert} Command
30662 @findex -break-insert
30663 @anchor{-break-insert}
30665 @subsubheading Synopsis
30668 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
30669 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30670 [ -p @var{thread-id} ] [ @var{location} ]
30674 If specified, @var{location}, can be one of:
30677 @item linespec location
30678 A linespec location. @xref{Linespec Locations}.
30680 @item explicit location
30681 An explicit location. @sc{gdb/mi} explicit locations are
30682 analogous to the CLI's explicit locations using the option names
30683 listed below. @xref{Explicit Locations}.
30686 @item --source @var{filename}
30687 The source file name of the location. This option requires the use
30688 of either @samp{--function} or @samp{--line}.
30690 @item --function @var{function}
30691 The name of a function or method.
30693 @item --label @var{label}
30694 The name of a label.
30696 @item --line @var{lineoffset}
30697 An absolute or relative line offset from the start of the location.
30700 @item address location
30701 An address location, *@var{address}. @xref{Address Locations}.
30705 The possible optional parameters of this command are:
30709 Insert a temporary breakpoint.
30711 Insert a hardware breakpoint.
30713 If @var{location} cannot be parsed (for example if it
30714 refers to unknown files or functions), create a pending
30715 breakpoint. Without this flag, @value{GDBN} will report
30716 an error, and won't create a breakpoint, if @var{location}
30719 Create a disabled breakpoint.
30721 Create a tracepoint. @xref{Tracepoints}. When this parameter
30722 is used together with @samp{-h}, a fast tracepoint is created.
30723 @item -c @var{condition}
30724 Make the breakpoint conditional on @var{condition}.
30725 @item -i @var{ignore-count}
30726 Initialize the @var{ignore-count}.
30727 @item -p @var{thread-id}
30728 Restrict the breakpoint to the thread with the specified global
30731 This option makes @value{GDBN} interpret a function name specified as
30732 a complete fully-qualified name.
30735 @subsubheading Result
30737 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30738 resulting breakpoint.
30740 Note: this format is open to change.
30741 @c An out-of-band breakpoint instead of part of the result?
30743 @subsubheading @value{GDBN} Command
30745 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30746 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30748 @subsubheading Example
30753 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30754 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30757 -break-insert -t foo
30758 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30759 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30763 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30764 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30765 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30766 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30767 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30768 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30769 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30770 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30771 addr="0x0001072c", func="main",file="recursive2.c",
30772 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30774 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30775 addr="0x00010774",func="foo",file="recursive2.c",
30776 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30779 @c -break-insert -r foo.*
30780 @c ~int foo(int, int);
30781 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30782 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30787 @subheading The @code{-dprintf-insert} Command
30788 @findex -dprintf-insert
30790 @subsubheading Synopsis
30793 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
30794 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30795 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30800 If supplied, @var{location} and @code{--qualified} may be specified
30801 the same way as for the @code{-break-insert} command.
30802 @xref{-break-insert}.
30804 The possible optional parameters of this command are:
30808 Insert a temporary breakpoint.
30810 If @var{location} cannot be parsed (for example, if it
30811 refers to unknown files or functions), create a pending
30812 breakpoint. Without this flag, @value{GDBN} will report
30813 an error, and won't create a breakpoint, if @var{location}
30816 Create a disabled breakpoint.
30817 @item -c @var{condition}
30818 Make the breakpoint conditional on @var{condition}.
30819 @item -i @var{ignore-count}
30820 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30821 to @var{ignore-count}.
30822 @item -p @var{thread-id}
30823 Restrict the breakpoint to the thread with the specified global
30827 @subsubheading Result
30829 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30830 resulting breakpoint.
30832 @c An out-of-band breakpoint instead of part of the result?
30834 @subsubheading @value{GDBN} Command
30836 The corresponding @value{GDBN} command is @samp{dprintf}.
30838 @subsubheading Example
30842 4-dprintf-insert foo "At foo entry\n"
30843 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30844 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30845 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30846 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30847 original-location="foo"@}
30849 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30850 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30851 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30852 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30853 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30854 original-location="mi-dprintf.c:26"@}
30858 @subheading The @code{-break-list} Command
30859 @findex -break-list
30861 @subsubheading Synopsis
30867 Displays the list of inserted breakpoints, showing the following fields:
30871 number of the breakpoint
30873 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30875 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30878 is the breakpoint enabled or no: @samp{y} or @samp{n}
30880 memory location at which the breakpoint is set
30882 logical location of the breakpoint, expressed by function name, file
30884 @item Thread-groups
30885 list of thread groups to which this breakpoint applies
30887 number of times the breakpoint has been hit
30890 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30891 @code{body} field is an empty list.
30893 @subsubheading @value{GDBN} Command
30895 The corresponding @value{GDBN} command is @samp{info break}.
30897 @subsubheading Example
30902 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30903 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30904 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30905 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30906 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30907 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30908 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30909 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30910 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30912 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30913 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30914 line="13",thread-groups=["i1"],times="0"@}]@}
30918 Here's an example of the result when there are no breakpoints:
30923 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30924 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30925 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30926 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30927 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30928 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30929 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30934 @subheading The @code{-break-passcount} Command
30935 @findex -break-passcount
30937 @subsubheading Synopsis
30940 -break-passcount @var{tracepoint-number} @var{passcount}
30943 Set the passcount for tracepoint @var{tracepoint-number} to
30944 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30945 is not a tracepoint, error is emitted. This corresponds to CLI
30946 command @samp{passcount}.
30948 @subheading The @code{-break-watch} Command
30949 @findex -break-watch
30951 @subsubheading Synopsis
30954 -break-watch [ -a | -r ]
30957 Create a watchpoint. With the @samp{-a} option it will create an
30958 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30959 read from or on a write to the memory location. With the @samp{-r}
30960 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30961 trigger only when the memory location is accessed for reading. Without
30962 either of the options, the watchpoint created is a regular watchpoint,
30963 i.e., it will trigger when the memory location is accessed for writing.
30964 @xref{Set Watchpoints, , Setting Watchpoints}.
30966 Note that @samp{-break-list} will report a single list of watchpoints and
30967 breakpoints inserted.
30969 @subsubheading @value{GDBN} Command
30971 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30974 @subsubheading Example
30976 Setting a watchpoint on a variable in the @code{main} function:
30981 ^done,wpt=@{number="2",exp="x"@}
30986 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30987 value=@{old="-268439212",new="55"@},
30988 frame=@{func="main",args=[],file="recursive2.c",
30989 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30993 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30994 the program execution twice: first for the variable changing value, then
30995 for the watchpoint going out of scope.
31000 ^done,wpt=@{number="5",exp="C"@}
31005 *stopped,reason="watchpoint-trigger",
31006 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
31007 frame=@{func="callee4",args=[],
31008 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31009 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31010 arch="i386:x86_64"@}
31015 *stopped,reason="watchpoint-scope",wpnum="5",
31016 frame=@{func="callee3",args=[@{name="strarg",
31017 value="0x11940 \"A string argument.\""@}],
31018 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31019 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31020 arch="i386:x86_64"@}
31024 Listing breakpoints and watchpoints, at different points in the program
31025 execution. Note that once the watchpoint goes out of scope, it is
31031 ^done,wpt=@{number="2",exp="C"@}
31034 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31035 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31036 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31037 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31038 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31039 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31040 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31041 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31042 addr="0x00010734",func="callee4",
31043 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31044 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
31046 bkpt=@{number="2",type="watchpoint",disp="keep",
31047 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
31052 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
31053 value=@{old="-276895068",new="3"@},
31054 frame=@{func="callee4",args=[],
31055 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31056 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31057 arch="i386:x86_64"@}
31060 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31061 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31062 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31063 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31064 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31065 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31066 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31067 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31068 addr="0x00010734",func="callee4",
31069 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31070 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
31072 bkpt=@{number="2",type="watchpoint",disp="keep",
31073 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
31077 ^done,reason="watchpoint-scope",wpnum="2",
31078 frame=@{func="callee3",args=[@{name="strarg",
31079 value="0x11940 \"A string argument.\""@}],
31080 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31081 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31082 arch="i386:x86_64"@}
31085 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31086 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31087 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31088 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31089 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31090 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31091 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31092 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31093 addr="0x00010734",func="callee4",
31094 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31095 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31096 thread-groups=["i1"],times="1"@}]@}
31101 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31102 @node GDB/MI Catchpoint Commands
31103 @section @sc{gdb/mi} Catchpoint Commands
31105 This section documents @sc{gdb/mi} commands for manipulating
31109 * Shared Library GDB/MI Catchpoint Commands::
31110 * Ada Exception GDB/MI Catchpoint Commands::
31111 * C++ Exception GDB/MI Catchpoint Commands::
31114 @node Shared Library GDB/MI Catchpoint Commands
31115 @subsection Shared Library @sc{gdb/mi} Catchpoints
31117 @subheading The @code{-catch-load} Command
31118 @findex -catch-load
31120 @subsubheading Synopsis
31123 -catch-load [ -t ] [ -d ] @var{regexp}
31126 Add a catchpoint for library load events. If the @samp{-t} option is used,
31127 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31128 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
31129 in a disabled state. The @samp{regexp} argument is a regular
31130 expression used to match the name of the loaded library.
31133 @subsubheading @value{GDBN} Command
31135 The corresponding @value{GDBN} command is @samp{catch load}.
31137 @subsubheading Example
31140 -catch-load -t foo.so
31141 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
31142 what="load of library matching foo.so",catch-type="load",times="0"@}
31147 @subheading The @code{-catch-unload} Command
31148 @findex -catch-unload
31150 @subsubheading Synopsis
31153 -catch-unload [ -t ] [ -d ] @var{regexp}
31156 Add a catchpoint for library unload events. If the @samp{-t} option is
31157 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31158 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
31159 created in a disabled state. The @samp{regexp} argument is a regular
31160 expression used to match the name of the unloaded library.
31162 @subsubheading @value{GDBN} Command
31164 The corresponding @value{GDBN} command is @samp{catch unload}.
31166 @subsubheading Example
31169 -catch-unload -d bar.so
31170 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
31171 what="load of library matching bar.so",catch-type="unload",times="0"@}
31175 @node Ada Exception GDB/MI Catchpoint Commands
31176 @subsection Ada Exception @sc{gdb/mi} Catchpoints
31178 The following @sc{gdb/mi} commands can be used to create catchpoints
31179 that stop the execution when Ada exceptions are being raised.
31181 @subheading The @code{-catch-assert} Command
31182 @findex -catch-assert
31184 @subsubheading Synopsis
31187 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
31190 Add a catchpoint for failed Ada assertions.
31192 The possible optional parameters for this command are:
31195 @item -c @var{condition}
31196 Make the catchpoint conditional on @var{condition}.
31198 Create a disabled catchpoint.
31200 Create a temporary catchpoint.
31203 @subsubheading @value{GDBN} Command
31205 The corresponding @value{GDBN} command is @samp{catch assert}.
31207 @subsubheading Example
31211 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
31212 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
31213 thread-groups=["i1"],times="0",
31214 original-location="__gnat_debug_raise_assert_failure"@}
31218 @subheading The @code{-catch-exception} Command
31219 @findex -catch-exception
31221 @subsubheading Synopsis
31224 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31228 Add a catchpoint stopping when Ada exceptions are raised.
31229 By default, the command stops the program when any Ada exception
31230 gets raised. But it is also possible, by using some of the
31231 optional parameters described below, to create more selective
31234 The possible optional parameters for this command are:
31237 @item -c @var{condition}
31238 Make the catchpoint conditional on @var{condition}.
31240 Create a disabled catchpoint.
31241 @item -e @var{exception-name}
31242 Only stop when @var{exception-name} is raised. This option cannot
31243 be used combined with @samp{-u}.
31245 Create a temporary catchpoint.
31247 Stop only when an unhandled exception gets raised. This option
31248 cannot be used combined with @samp{-e}.
31251 @subsubheading @value{GDBN} Command
31253 The corresponding @value{GDBN} commands are @samp{catch exception}
31254 and @samp{catch exception unhandled}.
31256 @subsubheading Example
31259 -catch-exception -e Program_Error
31260 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31261 enabled="y",addr="0x0000000000404874",
31262 what="`Program_Error' Ada exception", thread-groups=["i1"],
31263 times="0",original-location="__gnat_debug_raise_exception"@}
31267 @subheading The @code{-catch-handlers} Command
31268 @findex -catch-handlers
31270 @subsubheading Synopsis
31273 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31277 Add a catchpoint stopping when Ada exceptions are handled.
31278 By default, the command stops the program when any Ada exception
31279 gets handled. But it is also possible, by using some of the
31280 optional parameters described below, to create more selective
31283 The possible optional parameters for this command are:
31286 @item -c @var{condition}
31287 Make the catchpoint conditional on @var{condition}.
31289 Create a disabled catchpoint.
31290 @item -e @var{exception-name}
31291 Only stop when @var{exception-name} is handled.
31293 Create a temporary catchpoint.
31296 @subsubheading @value{GDBN} Command
31298 The corresponding @value{GDBN} command is @samp{catch handlers}.
31300 @subsubheading Example
31303 -catch-handlers -e Constraint_Error
31304 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31305 enabled="y",addr="0x0000000000402f68",
31306 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31307 times="0",original-location="__gnat_begin_handler"@}
31311 @node C++ Exception GDB/MI Catchpoint Commands
31312 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31314 The following @sc{gdb/mi} commands can be used to create catchpoints
31315 that stop the execution when C@t{++} exceptions are being throw, rethrown,
31318 @subheading The @code{-catch-throw} Command
31319 @findex -catch-throw
31321 @subsubheading Synopsis
31324 -catch-throw [ -t ] [ -r @var{regexp}]
31327 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31328 given, then only exceptions whose type matches the regular expression
31331 If @samp{-t} is given, then the catchpoint is enabled only for one
31332 stop, the catchpoint is automatically deleted after stopping once for
31335 @subsubheading @value{GDBN} Command
31337 The corresponding @value{GDBN} commands are @samp{catch throw}
31338 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31340 @subsubheading Example
31343 -catch-throw -r exception_type
31344 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31345 what="exception throw",catch-type="throw",
31346 thread-groups=["i1"],
31347 regexp="exception_type",times="0"@}
31353 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31354 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31355 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31356 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31357 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31358 thread-id="1",stopped-threads="all",core="6"
31362 @subheading The @code{-catch-rethrow} Command
31363 @findex -catch-rethrow
31365 @subsubheading Synopsis
31368 -catch-rethrow [ -t ] [ -r @var{regexp}]
31371 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31372 then only exceptions whose type matches the regular expression will be
31375 If @samp{-t} is given, then the catchpoint is enabled only for one
31376 stop, the catchpoint is automatically deleted after the first event is
31379 @subsubheading @value{GDBN} Command
31381 The corresponding @value{GDBN} commands are @samp{catch rethrow}
31382 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31384 @subsubheading Example
31387 -catch-rethrow -r exception_type
31388 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31389 what="exception rethrow",catch-type="rethrow",
31390 thread-groups=["i1"],
31391 regexp="exception_type",times="0"@}
31397 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31398 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31399 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31400 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31401 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31402 thread-id="1",stopped-threads="all",core="6"
31406 @subheading The @code{-catch-catch} Command
31407 @findex -catch-catch
31409 @subsubheading Synopsis
31412 -catch-catch [ -t ] [ -r @var{regexp}]
31415 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31416 is given, then only exceptions whose type matches the regular
31417 expression will be caught.
31419 If @samp{-t} is given, then the catchpoint is enabled only for one
31420 stop, the catchpoint is automatically deleted after the first event is
31423 @subsubheading @value{GDBN} Command
31425 The corresponding @value{GDBN} commands are @samp{catch catch}
31426 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31428 @subsubheading Example
31431 -catch-catch -r exception_type
31432 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31433 what="exception catch",catch-type="catch",
31434 thread-groups=["i1"],
31435 regexp="exception_type",times="0"@}
31441 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31442 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31443 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31444 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31445 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31446 thread-id="1",stopped-threads="all",core="6"
31450 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31451 @node GDB/MI Program Context
31452 @section @sc{gdb/mi} Program Context
31454 @subheading The @code{-exec-arguments} Command
31455 @findex -exec-arguments
31458 @subsubheading Synopsis
31461 -exec-arguments @var{args}
31464 Set the inferior program arguments, to be used in the next
31467 @subsubheading @value{GDBN} Command
31469 The corresponding @value{GDBN} command is @samp{set args}.
31471 @subsubheading Example
31475 -exec-arguments -v word
31482 @subheading The @code{-exec-show-arguments} Command
31483 @findex -exec-show-arguments
31485 @subsubheading Synopsis
31488 -exec-show-arguments
31491 Print the arguments of the program.
31493 @subsubheading @value{GDBN} Command
31495 The corresponding @value{GDBN} command is @samp{show args}.
31497 @subsubheading Example
31502 @subheading The @code{-environment-cd} Command
31503 @findex -environment-cd
31505 @subsubheading Synopsis
31508 -environment-cd @var{pathdir}
31511 Set @value{GDBN}'s working directory.
31513 @subsubheading @value{GDBN} Command
31515 The corresponding @value{GDBN} command is @samp{cd}.
31517 @subsubheading Example
31521 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31527 @subheading The @code{-environment-directory} Command
31528 @findex -environment-directory
31530 @subsubheading Synopsis
31533 -environment-directory [ -r ] [ @var{pathdir} ]+
31536 Add directories @var{pathdir} to beginning of search path for source files.
31537 If the @samp{-r} option is used, the search path is reset to the default
31538 search path. If directories @var{pathdir} are supplied in addition to the
31539 @samp{-r} option, the search path is first reset and then addition
31541 Multiple directories may be specified, separated by blanks. Specifying
31542 multiple directories in a single command
31543 results in the directories added to the beginning of the
31544 search path in the same order they were presented in the command.
31545 If blanks are needed as
31546 part of a directory name, double-quotes should be used around
31547 the name. In the command output, the path will show up separated
31548 by the system directory-separator character. The directory-separator
31549 character must not be used
31550 in any directory name.
31551 If no directories are specified, the current search path is displayed.
31553 @subsubheading @value{GDBN} Command
31555 The corresponding @value{GDBN} command is @samp{dir}.
31557 @subsubheading Example
31561 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31562 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31564 -environment-directory ""
31565 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31567 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
31568 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31570 -environment-directory -r
31571 ^done,source-path="$cdir:$cwd"
31576 @subheading The @code{-environment-path} Command
31577 @findex -environment-path
31579 @subsubheading Synopsis
31582 -environment-path [ -r ] [ @var{pathdir} ]+
31585 Add directories @var{pathdir} to beginning of search path for object files.
31586 If the @samp{-r} option is used, the search path is reset to the original
31587 search path that existed at gdb start-up. If directories @var{pathdir} are
31588 supplied in addition to the
31589 @samp{-r} option, the search path is first reset and then addition
31591 Multiple directories may be specified, separated by blanks. Specifying
31592 multiple directories in a single command
31593 results in the directories added to the beginning of the
31594 search path in the same order they were presented in the command.
31595 If blanks are needed as
31596 part of a directory name, double-quotes should be used around
31597 the name. In the command output, the path will show up separated
31598 by the system directory-separator character. The directory-separator
31599 character must not be used
31600 in any directory name.
31601 If no directories are specified, the current path is displayed.
31604 @subsubheading @value{GDBN} Command
31606 The corresponding @value{GDBN} command is @samp{path}.
31608 @subsubheading Example
31613 ^done,path="/usr/bin"
31615 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31616 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31618 -environment-path -r /usr/local/bin
31619 ^done,path="/usr/local/bin:/usr/bin"
31624 @subheading The @code{-environment-pwd} Command
31625 @findex -environment-pwd
31627 @subsubheading Synopsis
31633 Show the current working directory.
31635 @subsubheading @value{GDBN} Command
31637 The corresponding @value{GDBN} command is @samp{pwd}.
31639 @subsubheading Example
31644 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31648 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31649 @node GDB/MI Thread Commands
31650 @section @sc{gdb/mi} Thread Commands
31653 @subheading The @code{-thread-info} Command
31654 @findex -thread-info
31656 @subsubheading Synopsis
31659 -thread-info [ @var{thread-id} ]
31662 Reports information about either a specific thread, if the
31663 @var{thread-id} parameter is present, or about all threads.
31664 @var{thread-id} is the thread's global thread ID. When printing
31665 information about all threads, also reports the global ID of the
31668 @subsubheading @value{GDBN} Command
31670 The @samp{info thread} command prints the same information
31673 @subsubheading Result
31675 The result contains the following attributes:
31679 A list of threads. The format of the elements of the list is described in
31680 @ref{GDB/MI Thread Information}.
31682 @item current-thread-id
31683 The global id of the currently selected thread. This field is omitted if there
31684 is no selected thread (for example, when the selected inferior is not running,
31685 and therefore has no threads) or if a @var{thread-id} argument was passed to
31690 @subsubheading Example
31695 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31696 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31697 args=[]@},state="running"@},
31698 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31699 frame=@{level="0",addr="0x0804891f",func="foo",
31700 args=[@{name="i",value="10"@}],
31701 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31702 state="running"@}],
31703 current-thread-id="1"
31707 @subheading The @code{-thread-list-ids} Command
31708 @findex -thread-list-ids
31710 @subsubheading Synopsis
31716 Produces a list of the currently known global @value{GDBN} thread ids.
31717 At the end of the list it also prints the total number of such
31720 This command is retained for historical reasons, the
31721 @code{-thread-info} command should be used instead.
31723 @subsubheading @value{GDBN} Command
31725 Part of @samp{info threads} supplies the same information.
31727 @subsubheading Example
31732 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31733 current-thread-id="1",number-of-threads="3"
31738 @subheading The @code{-thread-select} Command
31739 @findex -thread-select
31741 @subsubheading Synopsis
31744 -thread-select @var{thread-id}
31747 Make thread with global thread number @var{thread-id} the current
31748 thread. It prints the number of the new current thread, and the
31749 topmost frame for that thread.
31751 This command is deprecated in favor of explicitly using the
31752 @samp{--thread} option to each command.
31754 @subsubheading @value{GDBN} Command
31756 The corresponding @value{GDBN} command is @samp{thread}.
31758 @subsubheading Example
31765 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31766 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31770 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31771 number-of-threads="3"
31774 ^done,new-thread-id="3",
31775 frame=@{level="0",func="vprintf",
31776 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31777 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31781 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31782 @node GDB/MI Ada Tasking Commands
31783 @section @sc{gdb/mi} Ada Tasking Commands
31785 @subheading The @code{-ada-task-info} Command
31786 @findex -ada-task-info
31788 @subsubheading Synopsis
31791 -ada-task-info [ @var{task-id} ]
31794 Reports information about either a specific Ada task, if the
31795 @var{task-id} parameter is present, or about all Ada tasks.
31797 @subsubheading @value{GDBN} Command
31799 The @samp{info tasks} command prints the same information
31800 about all Ada tasks (@pxref{Ada Tasks}).
31802 @subsubheading Result
31804 The result is a table of Ada tasks. The following columns are
31805 defined for each Ada task:
31809 This field exists only for the current thread. It has the value @samp{*}.
31812 The identifier that @value{GDBN} uses to refer to the Ada task.
31815 The identifier that the target uses to refer to the Ada task.
31818 The global thread identifier of the thread corresponding to the Ada
31821 This field should always exist, as Ada tasks are always implemented
31822 on top of a thread. But if @value{GDBN} cannot find this corresponding
31823 thread for any reason, the field is omitted.
31826 This field exists only when the task was created by another task.
31827 In this case, it provides the ID of the parent task.
31830 The base priority of the task.
31833 The current state of the task. For a detailed description of the
31834 possible states, see @ref{Ada Tasks}.
31837 The name of the task.
31841 @subsubheading Example
31845 ^done,tasks=@{nr_rows="3",nr_cols="8",
31846 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31847 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31848 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31849 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31850 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31851 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31852 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31853 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31854 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31855 state="Child Termination Wait",name="main_task"@}]@}
31859 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31860 @node GDB/MI Program Execution
31861 @section @sc{gdb/mi} Program Execution
31863 These are the asynchronous commands which generate the out-of-band
31864 record @samp{*stopped}. Currently @value{GDBN} only really executes
31865 asynchronously with remote targets and this interaction is mimicked in
31868 @subheading The @code{-exec-continue} Command
31869 @findex -exec-continue
31871 @subsubheading Synopsis
31874 -exec-continue [--reverse] [--all|--thread-group N]
31877 Resumes the execution of the inferior program, which will continue
31878 to execute until it reaches a debugger stop event. If the
31879 @samp{--reverse} option is specified, execution resumes in reverse until
31880 it reaches a stop event. Stop events may include
31883 breakpoints or watchpoints
31885 signals or exceptions
31887 the end of the process (or its beginning under @samp{--reverse})
31889 the end or beginning of a replay log if one is being used.
31891 In all-stop mode (@pxref{All-Stop
31892 Mode}), may resume only one thread, or all threads, depending on the
31893 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31894 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31895 ignored in all-stop mode. If the @samp{--thread-group} options is
31896 specified, then all threads in that thread group are resumed.
31898 @subsubheading @value{GDBN} Command
31900 The corresponding @value{GDBN} corresponding is @samp{continue}.
31902 @subsubheading Example
31909 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31910 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31911 line="13",arch="i386:x86_64"@}
31916 @subheading The @code{-exec-finish} Command
31917 @findex -exec-finish
31919 @subsubheading Synopsis
31922 -exec-finish [--reverse]
31925 Resumes the execution of the inferior program until the current
31926 function is exited. Displays the results returned by the function.
31927 If the @samp{--reverse} option is specified, resumes the reverse
31928 execution of the inferior program until the point where current
31929 function was called.
31931 @subsubheading @value{GDBN} Command
31933 The corresponding @value{GDBN} command is @samp{finish}.
31935 @subsubheading Example
31937 Function returning @code{void}.
31944 *stopped,reason="function-finished",frame=@{func="main",args=[],
31945 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31949 Function returning other than @code{void}. The name of the internal
31950 @value{GDBN} variable storing the result is printed, together with the
31957 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31958 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31959 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31960 arch="i386:x86_64"@},
31961 gdb-result-var="$1",return-value="0"
31966 @subheading The @code{-exec-interrupt} Command
31967 @findex -exec-interrupt
31969 @subsubheading Synopsis
31972 -exec-interrupt [--all|--thread-group N]
31975 Interrupts the background execution of the target. Note how the token
31976 associated with the stop message is the one for the execution command
31977 that has been interrupted. The token for the interrupt itself only
31978 appears in the @samp{^done} output. If the user is trying to
31979 interrupt a non-running program, an error message will be printed.
31981 Note that when asynchronous execution is enabled, this command is
31982 asynchronous just like other execution commands. That is, first the
31983 @samp{^done} response will be printed, and the target stop will be
31984 reported after that using the @samp{*stopped} notification.
31986 In non-stop mode, only the context thread is interrupted by default.
31987 All threads (in all inferiors) will be interrupted if the
31988 @samp{--all} option is specified. If the @samp{--thread-group}
31989 option is specified, all threads in that group will be interrupted.
31991 @subsubheading @value{GDBN} Command
31993 The corresponding @value{GDBN} command is @samp{interrupt}.
31995 @subsubheading Example
32006 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
32007 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
32008 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
32013 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
32017 @subheading The @code{-exec-jump} Command
32020 @subsubheading Synopsis
32023 -exec-jump @var{location}
32026 Resumes execution of the inferior program at the location specified by
32027 parameter. @xref{Specify Location}, for a description of the
32028 different forms of @var{location}.
32030 @subsubheading @value{GDBN} Command
32032 The corresponding @value{GDBN} command is @samp{jump}.
32034 @subsubheading Example
32037 -exec-jump foo.c:10
32038 *running,thread-id="all"
32043 @subheading The @code{-exec-next} Command
32046 @subsubheading Synopsis
32049 -exec-next [--reverse]
32052 Resumes execution of the inferior program, stopping when the beginning
32053 of the next source line is reached.
32055 If the @samp{--reverse} option is specified, resumes reverse execution
32056 of the inferior program, stopping at the beginning of the previous
32057 source line. If you issue this command on the first line of a
32058 function, it will take you back to the caller of that function, to the
32059 source line where the function was called.
32062 @subsubheading @value{GDBN} Command
32064 The corresponding @value{GDBN} command is @samp{next}.
32066 @subsubheading Example
32072 *stopped,reason="end-stepping-range",line="8",file="hello.c"
32077 @subheading The @code{-exec-next-instruction} Command
32078 @findex -exec-next-instruction
32080 @subsubheading Synopsis
32083 -exec-next-instruction [--reverse]
32086 Executes one machine instruction. If the instruction is a function
32087 call, continues until the function returns. If the program stops at an
32088 instruction in the middle of a source line, the address will be
32091 If the @samp{--reverse} option is specified, resumes reverse execution
32092 of the inferior program, stopping at the previous instruction. If the
32093 previously executed instruction was a return from another function,
32094 it will continue to execute in reverse until the call to that function
32095 (from the current stack frame) is reached.
32097 @subsubheading @value{GDBN} Command
32099 The corresponding @value{GDBN} command is @samp{nexti}.
32101 @subsubheading Example
32105 -exec-next-instruction
32109 *stopped,reason="end-stepping-range",
32110 addr="0x000100d4",line="5",file="hello.c"
32115 @subheading The @code{-exec-return} Command
32116 @findex -exec-return
32118 @subsubheading Synopsis
32124 Makes current function return immediately. Doesn't execute the inferior.
32125 Displays the new current frame.
32127 @subsubheading @value{GDBN} Command
32129 The corresponding @value{GDBN} command is @samp{return}.
32131 @subsubheading Example
32135 200-break-insert callee4
32136 200^done,bkpt=@{number="1",addr="0x00010734",
32137 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
32142 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32143 frame=@{func="callee4",args=[],
32144 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32145 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32146 arch="i386:x86_64"@}
32152 111^done,frame=@{level="0",func="callee3",
32153 args=[@{name="strarg",
32154 value="0x11940 \"A string argument.\""@}],
32155 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32156 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32157 arch="i386:x86_64"@}
32162 @subheading The @code{-exec-run} Command
32165 @subsubheading Synopsis
32168 -exec-run [ --all | --thread-group N ] [ --start ]
32171 Starts execution of the inferior from the beginning. The inferior
32172 executes until either a breakpoint is encountered or the program
32173 exits. In the latter case the output will include an exit code, if
32174 the program has exited exceptionally.
32176 When neither the @samp{--all} nor the @samp{--thread-group} option
32177 is specified, the current inferior is started. If the
32178 @samp{--thread-group} option is specified, it should refer to a thread
32179 group of type @samp{process}, and that thread group will be started.
32180 If the @samp{--all} option is specified, then all inferiors will be started.
32182 Using the @samp{--start} option instructs the debugger to stop
32183 the execution at the start of the inferior's main subprogram,
32184 following the same behavior as the @code{start} command
32185 (@pxref{Starting}).
32187 @subsubheading @value{GDBN} Command
32189 The corresponding @value{GDBN} command is @samp{run}.
32191 @subsubheading Examples
32196 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
32201 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32202 frame=@{func="main",args=[],file="recursive2.c",
32203 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
32208 Program exited normally:
32216 *stopped,reason="exited-normally"
32221 Program exited exceptionally:
32229 *stopped,reason="exited",exit-code="01"
32233 Another way the program can terminate is if it receives a signal such as
32234 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
32238 *stopped,reason="exited-signalled",signal-name="SIGINT",
32239 signal-meaning="Interrupt"
32243 @c @subheading -exec-signal
32246 @subheading The @code{-exec-step} Command
32249 @subsubheading Synopsis
32252 -exec-step [--reverse]
32255 Resumes execution of the inferior program, stopping when the beginning
32256 of the next source line is reached, if the next source line is not a
32257 function call. If it is, stop at the first instruction of the called
32258 function. If the @samp{--reverse} option is specified, resumes reverse
32259 execution of the inferior program, stopping at the beginning of the
32260 previously executed source line.
32262 @subsubheading @value{GDBN} Command
32264 The corresponding @value{GDBN} command is @samp{step}.
32266 @subsubheading Example
32268 Stepping into a function:
32274 *stopped,reason="end-stepping-range",
32275 frame=@{func="foo",args=[@{name="a",value="10"@},
32276 @{name="b",value="0"@}],file="recursive2.c",
32277 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
32287 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
32292 @subheading The @code{-exec-step-instruction} Command
32293 @findex -exec-step-instruction
32295 @subsubheading Synopsis
32298 -exec-step-instruction [--reverse]
32301 Resumes the inferior which executes one machine instruction. If the
32302 @samp{--reverse} option is specified, resumes reverse execution of the
32303 inferior program, stopping at the previously executed instruction.
32304 The output, once @value{GDBN} has stopped, will vary depending on
32305 whether we have stopped in the middle of a source line or not. In the
32306 former case, the address at which the program stopped will be printed
32309 @subsubheading @value{GDBN} Command
32311 The corresponding @value{GDBN} command is @samp{stepi}.
32313 @subsubheading Example
32317 -exec-step-instruction
32321 *stopped,reason="end-stepping-range",
32322 frame=@{func="foo",args=[],file="try.c",
32323 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32325 -exec-step-instruction
32329 *stopped,reason="end-stepping-range",
32330 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
32331 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32336 @subheading The @code{-exec-until} Command
32337 @findex -exec-until
32339 @subsubheading Synopsis
32342 -exec-until [ @var{location} ]
32345 Executes the inferior until the @var{location} specified in the
32346 argument is reached. If there is no argument, the inferior executes
32347 until a source line greater than the current one is reached. The
32348 reason for stopping in this case will be @samp{location-reached}.
32350 @subsubheading @value{GDBN} Command
32352 The corresponding @value{GDBN} command is @samp{until}.
32354 @subsubheading Example
32358 -exec-until recursive2.c:6
32362 *stopped,reason="location-reached",frame=@{func="main",args=[],
32363 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32364 arch="i386:x86_64"@}
32369 @subheading -file-clear
32370 Is this going away????
32373 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32374 @node GDB/MI Stack Manipulation
32375 @section @sc{gdb/mi} Stack Manipulation Commands
32377 @subheading The @code{-enable-frame-filters} Command
32378 @findex -enable-frame-filters
32381 -enable-frame-filters
32384 @value{GDBN} allows Python-based frame filters to affect the output of
32385 the MI commands relating to stack traces. As there is no way to
32386 implement this in a fully backward-compatible way, a front end must
32387 request that this functionality be enabled.
32389 Once enabled, this feature cannot be disabled.
32391 Note that if Python support has not been compiled into @value{GDBN},
32392 this command will still succeed (and do nothing).
32394 @subheading The @code{-stack-info-frame} Command
32395 @findex -stack-info-frame
32397 @subsubheading Synopsis
32403 Get info on the selected frame.
32405 @subsubheading @value{GDBN} Command
32407 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32408 (without arguments).
32410 @subsubheading Example
32415 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32416 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32417 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32418 arch="i386:x86_64"@}
32422 @subheading The @code{-stack-info-depth} Command
32423 @findex -stack-info-depth
32425 @subsubheading Synopsis
32428 -stack-info-depth [ @var{max-depth} ]
32431 Return the depth of the stack. If the integer argument @var{max-depth}
32432 is specified, do not count beyond @var{max-depth} frames.
32434 @subsubheading @value{GDBN} Command
32436 There's no equivalent @value{GDBN} command.
32438 @subsubheading Example
32440 For a stack with frame levels 0 through 11:
32447 -stack-info-depth 4
32450 -stack-info-depth 12
32453 -stack-info-depth 11
32456 -stack-info-depth 13
32461 @anchor{-stack-list-arguments}
32462 @subheading The @code{-stack-list-arguments} Command
32463 @findex -stack-list-arguments
32465 @subsubheading Synopsis
32468 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32469 [ @var{low-frame} @var{high-frame} ]
32472 Display a list of the arguments for the frames between @var{low-frame}
32473 and @var{high-frame} (inclusive). If @var{low-frame} and
32474 @var{high-frame} are not provided, list the arguments for the whole
32475 call stack. If the two arguments are equal, show the single frame
32476 at the corresponding level. It is an error if @var{low-frame} is
32477 larger than the actual number of frames. On the other hand,
32478 @var{high-frame} may be larger than the actual number of frames, in
32479 which case only existing frames will be returned.
32481 If @var{print-values} is 0 or @code{--no-values}, print only the names of
32482 the variables; if it is 1 or @code{--all-values}, print also their
32483 values; and if it is 2 or @code{--simple-values}, print the name,
32484 type and value for simple data types, and the name and type for arrays,
32485 structures and unions. If the option @code{--no-frame-filters} is
32486 supplied, then Python frame filters will not be executed.
32488 If the @code{--skip-unavailable} option is specified, arguments that
32489 are not available are not listed. Partially available arguments
32490 are still displayed, however.
32492 Use of this command to obtain arguments in a single frame is
32493 deprecated in favor of the @samp{-stack-list-variables} command.
32495 @subsubheading @value{GDBN} Command
32497 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32498 @samp{gdb_get_args} command which partially overlaps with the
32499 functionality of @samp{-stack-list-arguments}.
32501 @subsubheading Example
32508 frame=@{level="0",addr="0x00010734",func="callee4",
32509 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32510 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32511 arch="i386:x86_64"@},
32512 frame=@{level="1",addr="0x0001076c",func="callee3",
32513 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32514 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32515 arch="i386:x86_64"@},
32516 frame=@{level="2",addr="0x0001078c",func="callee2",
32517 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32518 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32519 arch="i386:x86_64"@},
32520 frame=@{level="3",addr="0x000107b4",func="callee1",
32521 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32522 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32523 arch="i386:x86_64"@},
32524 frame=@{level="4",addr="0x000107e0",func="main",
32525 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32526 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32527 arch="i386:x86_64"@}]
32529 -stack-list-arguments 0
32532 frame=@{level="0",args=[]@},
32533 frame=@{level="1",args=[name="strarg"]@},
32534 frame=@{level="2",args=[name="intarg",name="strarg"]@},
32535 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32536 frame=@{level="4",args=[]@}]
32538 -stack-list-arguments 1
32541 frame=@{level="0",args=[]@},
32543 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32544 frame=@{level="2",args=[
32545 @{name="intarg",value="2"@},
32546 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32547 @{frame=@{level="3",args=[
32548 @{name="intarg",value="2"@},
32549 @{name="strarg",value="0x11940 \"A string argument.\""@},
32550 @{name="fltarg",value="3.5"@}]@},
32551 frame=@{level="4",args=[]@}]
32553 -stack-list-arguments 0 2 2
32554 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32556 -stack-list-arguments 1 2 2
32557 ^done,stack-args=[frame=@{level="2",
32558 args=[@{name="intarg",value="2"@},
32559 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32563 @c @subheading -stack-list-exception-handlers
32566 @anchor{-stack-list-frames}
32567 @subheading The @code{-stack-list-frames} Command
32568 @findex -stack-list-frames
32570 @subsubheading Synopsis
32573 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32576 List the frames currently on the stack. For each frame it displays the
32581 The frame number, 0 being the topmost frame, i.e., the innermost function.
32583 The @code{$pc} value for that frame.
32587 File name of the source file where the function lives.
32588 @item @var{fullname}
32589 The full file name of the source file where the function lives.
32591 Line number corresponding to the @code{$pc}.
32593 The shared library where this function is defined. This is only given
32594 if the frame's function is not known.
32596 Frame's architecture.
32599 If invoked without arguments, this command prints a backtrace for the
32600 whole stack. If given two integer arguments, it shows the frames whose
32601 levels are between the two arguments (inclusive). If the two arguments
32602 are equal, it shows the single frame at the corresponding level. It is
32603 an error if @var{low-frame} is larger than the actual number of
32604 frames. On the other hand, @var{high-frame} may be larger than the
32605 actual number of frames, in which case only existing frames will be
32606 returned. If the option @code{--no-frame-filters} is supplied, then
32607 Python frame filters will not be executed.
32609 @subsubheading @value{GDBN} Command
32611 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32613 @subsubheading Example
32615 Full stack backtrace:
32621 [frame=@{level="0",addr="0x0001076c",func="foo",
32622 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32623 arch="i386:x86_64"@},
32624 frame=@{level="1",addr="0x000107a4",func="foo",
32625 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32626 arch="i386:x86_64"@},
32627 frame=@{level="2",addr="0x000107a4",func="foo",
32628 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32629 arch="i386:x86_64"@},
32630 frame=@{level="3",addr="0x000107a4",func="foo",
32631 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32632 arch="i386:x86_64"@},
32633 frame=@{level="4",addr="0x000107a4",func="foo",
32634 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32635 arch="i386:x86_64"@},
32636 frame=@{level="5",addr="0x000107a4",func="foo",
32637 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32638 arch="i386:x86_64"@},
32639 frame=@{level="6",addr="0x000107a4",func="foo",
32640 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32641 arch="i386:x86_64"@},
32642 frame=@{level="7",addr="0x000107a4",func="foo",
32643 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32644 arch="i386:x86_64"@},
32645 frame=@{level="8",addr="0x000107a4",func="foo",
32646 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32647 arch="i386:x86_64"@},
32648 frame=@{level="9",addr="0x000107a4",func="foo",
32649 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32650 arch="i386:x86_64"@},
32651 frame=@{level="10",addr="0x000107a4",func="foo",
32652 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32653 arch="i386:x86_64"@},
32654 frame=@{level="11",addr="0x00010738",func="main",
32655 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32656 arch="i386:x86_64"@}]
32660 Show frames between @var{low_frame} and @var{high_frame}:
32664 -stack-list-frames 3 5
32666 [frame=@{level="3",addr="0x000107a4",func="foo",
32667 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32668 arch="i386:x86_64"@},
32669 frame=@{level="4",addr="0x000107a4",func="foo",
32670 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32671 arch="i386:x86_64"@},
32672 frame=@{level="5",addr="0x000107a4",func="foo",
32673 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32674 arch="i386:x86_64"@}]
32678 Show a single frame:
32682 -stack-list-frames 3 3
32684 [frame=@{level="3",addr="0x000107a4",func="foo",
32685 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32686 arch="i386:x86_64"@}]
32691 @subheading The @code{-stack-list-locals} Command
32692 @findex -stack-list-locals
32693 @anchor{-stack-list-locals}
32695 @subsubheading Synopsis
32698 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32701 Display the local variable names for the selected frame. If
32702 @var{print-values} is 0 or @code{--no-values}, print only the names of
32703 the variables; if it is 1 or @code{--all-values}, print also their
32704 values; and if it is 2 or @code{--simple-values}, print the name,
32705 type and value for simple data types, and the name and type for arrays,
32706 structures and unions. In this last case, a frontend can immediately
32707 display the value of simple data types and create variable objects for
32708 other data types when the user wishes to explore their values in
32709 more detail. If the option @code{--no-frame-filters} is supplied, then
32710 Python frame filters will not be executed.
32712 If the @code{--skip-unavailable} option is specified, local variables
32713 that are not available are not listed. Partially available local
32714 variables are still displayed, however.
32716 This command is deprecated in favor of the
32717 @samp{-stack-list-variables} command.
32719 @subsubheading @value{GDBN} Command
32721 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32723 @subsubheading Example
32727 -stack-list-locals 0
32728 ^done,locals=[name="A",name="B",name="C"]
32730 -stack-list-locals --all-values
32731 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32732 @{name="C",value="@{1, 2, 3@}"@}]
32733 -stack-list-locals --simple-values
32734 ^done,locals=[@{name="A",type="int",value="1"@},
32735 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32739 @anchor{-stack-list-variables}
32740 @subheading The @code{-stack-list-variables} Command
32741 @findex -stack-list-variables
32743 @subsubheading Synopsis
32746 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32749 Display the names of local variables and function arguments for the selected frame. If
32750 @var{print-values} is 0 or @code{--no-values}, print only the names of
32751 the variables; if it is 1 or @code{--all-values}, print also their
32752 values; and if it is 2 or @code{--simple-values}, print the name,
32753 type and value for simple data types, and the name and type for arrays,
32754 structures and unions. If the option @code{--no-frame-filters} is
32755 supplied, then Python frame filters will not be executed.
32757 If the @code{--skip-unavailable} option is specified, local variables
32758 and arguments that are not available are not listed. Partially
32759 available arguments and local variables are still displayed, however.
32761 @subsubheading Example
32765 -stack-list-variables --thread 1 --frame 0 --all-values
32766 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32771 @subheading The @code{-stack-select-frame} Command
32772 @findex -stack-select-frame
32774 @subsubheading Synopsis
32777 -stack-select-frame @var{framenum}
32780 Change the selected frame. Select a different frame @var{framenum} on
32783 This command in deprecated in favor of passing the @samp{--frame}
32784 option to every command.
32786 @subsubheading @value{GDBN} Command
32788 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32789 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32791 @subsubheading Example
32795 -stack-select-frame 2
32800 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32801 @node GDB/MI Variable Objects
32802 @section @sc{gdb/mi} Variable Objects
32806 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32808 For the implementation of a variable debugger window (locals, watched
32809 expressions, etc.), we are proposing the adaptation of the existing code
32810 used by @code{Insight}.
32812 The two main reasons for that are:
32816 It has been proven in practice (it is already on its second generation).
32819 It will shorten development time (needless to say how important it is
32823 The original interface was designed to be used by Tcl code, so it was
32824 slightly changed so it could be used through @sc{gdb/mi}. This section
32825 describes the @sc{gdb/mi} operations that will be available and gives some
32826 hints about their use.
32828 @emph{Note}: In addition to the set of operations described here, we
32829 expect the @sc{gui} implementation of a variable window to require, at
32830 least, the following operations:
32833 @item @code{-gdb-show} @code{output-radix}
32834 @item @code{-stack-list-arguments}
32835 @item @code{-stack-list-locals}
32836 @item @code{-stack-select-frame}
32841 @subheading Introduction to Variable Objects
32843 @cindex variable objects in @sc{gdb/mi}
32845 Variable objects are "object-oriented" MI interface for examining and
32846 changing values of expressions. Unlike some other MI interfaces that
32847 work with expressions, variable objects are specifically designed for
32848 simple and efficient presentation in the frontend. A variable object
32849 is identified by string name. When a variable object is created, the
32850 frontend specifies the expression for that variable object. The
32851 expression can be a simple variable, or it can be an arbitrary complex
32852 expression, and can even involve CPU registers. After creating a
32853 variable object, the frontend can invoke other variable object
32854 operations---for example to obtain or change the value of a variable
32855 object, or to change display format.
32857 Variable objects have hierarchical tree structure. Any variable object
32858 that corresponds to a composite type, such as structure in C, has
32859 a number of child variable objects, for example corresponding to each
32860 element of a structure. A child variable object can itself have
32861 children, recursively. Recursion ends when we reach
32862 leaf variable objects, which always have built-in types. Child variable
32863 objects are created only by explicit request, so if a frontend
32864 is not interested in the children of a particular variable object, no
32865 child will be created.
32867 For a leaf variable object it is possible to obtain its value as a
32868 string, or set the value from a string. String value can be also
32869 obtained for a non-leaf variable object, but it's generally a string
32870 that only indicates the type of the object, and does not list its
32871 contents. Assignment to a non-leaf variable object is not allowed.
32873 A frontend does not need to read the values of all variable objects each time
32874 the program stops. Instead, MI provides an update command that lists all
32875 variable objects whose values has changed since the last update
32876 operation. This considerably reduces the amount of data that must
32877 be transferred to the frontend. As noted above, children variable
32878 objects are created on demand, and only leaf variable objects have a
32879 real value. As result, gdb will read target memory only for leaf
32880 variables that frontend has created.
32882 The automatic update is not always desirable. For example, a frontend
32883 might want to keep a value of some expression for future reference,
32884 and never update it. For another example, fetching memory is
32885 relatively slow for embedded targets, so a frontend might want
32886 to disable automatic update for the variables that are either not
32887 visible on the screen, or ``closed''. This is possible using so
32888 called ``frozen variable objects''. Such variable objects are never
32889 implicitly updated.
32891 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32892 fixed variable object, the expression is parsed when the variable
32893 object is created, including associating identifiers to specific
32894 variables. The meaning of expression never changes. For a floating
32895 variable object the values of variables whose names appear in the
32896 expressions are re-evaluated every time in the context of the current
32897 frame. Consider this example:
32902 struct work_state state;
32909 If a fixed variable object for the @code{state} variable is created in
32910 this function, and we enter the recursive call, the variable
32911 object will report the value of @code{state} in the top-level
32912 @code{do_work} invocation. On the other hand, a floating variable
32913 object will report the value of @code{state} in the current frame.
32915 If an expression specified when creating a fixed variable object
32916 refers to a local variable, the variable object becomes bound to the
32917 thread and frame in which the variable object is created. When such
32918 variable object is updated, @value{GDBN} makes sure that the
32919 thread/frame combination the variable object is bound to still exists,
32920 and re-evaluates the variable object in context of that thread/frame.
32922 The following is the complete set of @sc{gdb/mi} operations defined to
32923 access this functionality:
32925 @multitable @columnfractions .4 .6
32926 @item @strong{Operation}
32927 @tab @strong{Description}
32929 @item @code{-enable-pretty-printing}
32930 @tab enable Python-based pretty-printing
32931 @item @code{-var-create}
32932 @tab create a variable object
32933 @item @code{-var-delete}
32934 @tab delete the variable object and/or its children
32935 @item @code{-var-set-format}
32936 @tab set the display format of this variable
32937 @item @code{-var-show-format}
32938 @tab show the display format of this variable
32939 @item @code{-var-info-num-children}
32940 @tab tells how many children this object has
32941 @item @code{-var-list-children}
32942 @tab return a list of the object's children
32943 @item @code{-var-info-type}
32944 @tab show the type of this variable object
32945 @item @code{-var-info-expression}
32946 @tab print parent-relative expression that this variable object represents
32947 @item @code{-var-info-path-expression}
32948 @tab print full expression that this variable object represents
32949 @item @code{-var-show-attributes}
32950 @tab is this variable editable? does it exist here?
32951 @item @code{-var-evaluate-expression}
32952 @tab get the value of this variable
32953 @item @code{-var-assign}
32954 @tab set the value of this variable
32955 @item @code{-var-update}
32956 @tab update the variable and its children
32957 @item @code{-var-set-frozen}
32958 @tab set frozenness attribute
32959 @item @code{-var-set-update-range}
32960 @tab set range of children to display on update
32963 In the next subsection we describe each operation in detail and suggest
32964 how it can be used.
32966 @subheading Description And Use of Operations on Variable Objects
32968 @subheading The @code{-enable-pretty-printing} Command
32969 @findex -enable-pretty-printing
32972 -enable-pretty-printing
32975 @value{GDBN} allows Python-based visualizers to affect the output of the
32976 MI variable object commands. However, because there was no way to
32977 implement this in a fully backward-compatible way, a front end must
32978 request that this functionality be enabled.
32980 Once enabled, this feature cannot be disabled.
32982 Note that if Python support has not been compiled into @value{GDBN},
32983 this command will still succeed (and do nothing).
32985 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32986 may work differently in future versions of @value{GDBN}.
32988 @subheading The @code{-var-create} Command
32989 @findex -var-create
32991 @subsubheading Synopsis
32994 -var-create @{@var{name} | "-"@}
32995 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32998 This operation creates a variable object, which allows the monitoring of
32999 a variable, the result of an expression, a memory cell or a CPU
33002 The @var{name} parameter is the string by which the object can be
33003 referenced. It must be unique. If @samp{-} is specified, the varobj
33004 system will generate a string ``varNNNNNN'' automatically. It will be
33005 unique provided that one does not specify @var{name} of that format.
33006 The command fails if a duplicate name is found.
33008 The frame under which the expression should be evaluated can be
33009 specified by @var{frame-addr}. A @samp{*} indicates that the current
33010 frame should be used. A @samp{@@} indicates that a floating variable
33011 object must be created.
33013 @var{expression} is any expression valid on the current language set (must not
33014 begin with a @samp{*}), or one of the following:
33018 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
33021 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
33024 @samp{$@var{regname}} --- a CPU register name
33027 @cindex dynamic varobj
33028 A varobj's contents may be provided by a Python-based pretty-printer. In this
33029 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
33030 have slightly different semantics in some cases. If the
33031 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
33032 will never create a dynamic varobj. This ensures backward
33033 compatibility for existing clients.
33035 @subsubheading Result
33037 This operation returns attributes of the newly-created varobj. These
33042 The name of the varobj.
33045 The number of children of the varobj. This number is not necessarily
33046 reliable for a dynamic varobj. Instead, you must examine the
33047 @samp{has_more} attribute.
33050 The varobj's scalar value. For a varobj whose type is some sort of
33051 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
33052 will not be interesting.
33055 The varobj's type. This is a string representation of the type, as
33056 would be printed by the @value{GDBN} CLI. If @samp{print object}
33057 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33058 @emph{actual} (derived) type of the object is shown rather than the
33059 @emph{declared} one.
33062 If a variable object is bound to a specific thread, then this is the
33063 thread's global identifier.
33066 For a dynamic varobj, this indicates whether there appear to be any
33067 children available. For a non-dynamic varobj, this will be 0.
33070 This attribute will be present and have the value @samp{1} if the
33071 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33072 then this attribute will not be present.
33075 A dynamic varobj can supply a display hint to the front end. The
33076 value comes directly from the Python pretty-printer object's
33077 @code{display_hint} method. @xref{Pretty Printing API}.
33080 Typical output will look like this:
33083 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
33084 has_more="@var{has_more}"
33088 @subheading The @code{-var-delete} Command
33089 @findex -var-delete
33091 @subsubheading Synopsis
33094 -var-delete [ -c ] @var{name}
33097 Deletes a previously created variable object and all of its children.
33098 With the @samp{-c} option, just deletes the children.
33100 Returns an error if the object @var{name} is not found.
33103 @subheading The @code{-var-set-format} Command
33104 @findex -var-set-format
33106 @subsubheading Synopsis
33109 -var-set-format @var{name} @var{format-spec}
33112 Sets the output format for the value of the object @var{name} to be
33115 @anchor{-var-set-format}
33116 The syntax for the @var{format-spec} is as follows:
33119 @var{format-spec} @expansion{}
33120 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
33123 The natural format is the default format choosen automatically
33124 based on the variable type (like decimal for an @code{int}, hex
33125 for pointers, etc.).
33127 The zero-hexadecimal format has a representation similar to hexadecimal
33128 but with padding zeroes to the left of the value. For example, a 32-bit
33129 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
33130 zero-hexadecimal format.
33132 For a variable with children, the format is set only on the
33133 variable itself, and the children are not affected.
33135 @subheading The @code{-var-show-format} Command
33136 @findex -var-show-format
33138 @subsubheading Synopsis
33141 -var-show-format @var{name}
33144 Returns the format used to display the value of the object @var{name}.
33147 @var{format} @expansion{}
33152 @subheading The @code{-var-info-num-children} Command
33153 @findex -var-info-num-children
33155 @subsubheading Synopsis
33158 -var-info-num-children @var{name}
33161 Returns the number of children of a variable object @var{name}:
33167 Note that this number is not completely reliable for a dynamic varobj.
33168 It will return the current number of children, but more children may
33172 @subheading The @code{-var-list-children} Command
33173 @findex -var-list-children
33175 @subsubheading Synopsis
33178 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
33180 @anchor{-var-list-children}
33182 Return a list of the children of the specified variable object and
33183 create variable objects for them, if they do not already exist. With
33184 a single argument or if @var{print-values} has a value of 0 or
33185 @code{--no-values}, print only the names of the variables; if
33186 @var{print-values} is 1 or @code{--all-values}, also print their
33187 values; and if it is 2 or @code{--simple-values} print the name and
33188 value for simple data types and just the name for arrays, structures
33191 @var{from} and @var{to}, if specified, indicate the range of children
33192 to report. If @var{from} or @var{to} is less than zero, the range is
33193 reset and all children will be reported. Otherwise, children starting
33194 at @var{from} (zero-based) and up to and excluding @var{to} will be
33197 If a child range is requested, it will only affect the current call to
33198 @code{-var-list-children}, but not future calls to @code{-var-update}.
33199 For this, you must instead use @code{-var-set-update-range}. The
33200 intent of this approach is to enable a front end to implement any
33201 update approach it likes; for example, scrolling a view may cause the
33202 front end to request more children with @code{-var-list-children}, and
33203 then the front end could call @code{-var-set-update-range} with a
33204 different range to ensure that future updates are restricted to just
33207 For each child the following results are returned:
33212 Name of the variable object created for this child.
33215 The expression to be shown to the user by the front end to designate this child.
33216 For example this may be the name of a structure member.
33218 For a dynamic varobj, this value cannot be used to form an
33219 expression. There is no way to do this at all with a dynamic varobj.
33221 For C/C@t{++} structures there are several pseudo children returned to
33222 designate access qualifiers. For these pseudo children @var{exp} is
33223 @samp{public}, @samp{private}, or @samp{protected}. In this case the
33224 type and value are not present.
33226 A dynamic varobj will not report the access qualifying
33227 pseudo-children, regardless of the language. This information is not
33228 available at all with a dynamic varobj.
33231 Number of children this child has. For a dynamic varobj, this will be
33235 The type of the child. If @samp{print object}
33236 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33237 @emph{actual} (derived) type of the object is shown rather than the
33238 @emph{declared} one.
33241 If values were requested, this is the value.
33244 If this variable object is associated with a thread, this is the
33245 thread's global thread id. Otherwise this result is not present.
33248 If the variable object is frozen, this variable will be present with a value of 1.
33251 A dynamic varobj can supply a display hint to the front end. The
33252 value comes directly from the Python pretty-printer object's
33253 @code{display_hint} method. @xref{Pretty Printing API}.
33256 This attribute will be present and have the value @samp{1} if the
33257 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33258 then this attribute will not be present.
33262 The result may have its own attributes:
33266 A dynamic varobj can supply a display hint to the front end. The
33267 value comes directly from the Python pretty-printer object's
33268 @code{display_hint} method. @xref{Pretty Printing API}.
33271 This is an integer attribute which is nonzero if there are children
33272 remaining after the end of the selected range.
33275 @subsubheading Example
33279 -var-list-children n
33280 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33281 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
33283 -var-list-children --all-values n
33284 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33285 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
33289 @subheading The @code{-var-info-type} Command
33290 @findex -var-info-type
33292 @subsubheading Synopsis
33295 -var-info-type @var{name}
33298 Returns the type of the specified variable @var{name}. The type is
33299 returned as a string in the same format as it is output by the
33303 type=@var{typename}
33307 @subheading The @code{-var-info-expression} Command
33308 @findex -var-info-expression
33310 @subsubheading Synopsis
33313 -var-info-expression @var{name}
33316 Returns a string that is suitable for presenting this
33317 variable object in user interface. The string is generally
33318 not valid expression in the current language, and cannot be evaluated.
33320 For example, if @code{a} is an array, and variable object
33321 @code{A} was created for @code{a}, then we'll get this output:
33324 (gdb) -var-info-expression A.1
33325 ^done,lang="C",exp="1"
33329 Here, the value of @code{lang} is the language name, which can be
33330 found in @ref{Supported Languages}.
33332 Note that the output of the @code{-var-list-children} command also
33333 includes those expressions, so the @code{-var-info-expression} command
33336 @subheading The @code{-var-info-path-expression} Command
33337 @findex -var-info-path-expression
33339 @subsubheading Synopsis
33342 -var-info-path-expression @var{name}
33345 Returns an expression that can be evaluated in the current
33346 context and will yield the same value that a variable object has.
33347 Compare this with the @code{-var-info-expression} command, which
33348 result can be used only for UI presentation. Typical use of
33349 the @code{-var-info-path-expression} command is creating a
33350 watchpoint from a variable object.
33352 This command is currently not valid for children of a dynamic varobj,
33353 and will give an error when invoked on one.
33355 For example, suppose @code{C} is a C@t{++} class, derived from class
33356 @code{Base}, and that the @code{Base} class has a member called
33357 @code{m_size}. Assume a variable @code{c} is has the type of
33358 @code{C} and a variable object @code{C} was created for variable
33359 @code{c}. Then, we'll get this output:
33361 (gdb) -var-info-path-expression C.Base.public.m_size
33362 ^done,path_expr=((Base)c).m_size)
33365 @subheading The @code{-var-show-attributes} Command
33366 @findex -var-show-attributes
33368 @subsubheading Synopsis
33371 -var-show-attributes @var{name}
33374 List attributes of the specified variable object @var{name}:
33377 status=@var{attr} [ ( ,@var{attr} )* ]
33381 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33383 @subheading The @code{-var-evaluate-expression} Command
33384 @findex -var-evaluate-expression
33386 @subsubheading Synopsis
33389 -var-evaluate-expression [-f @var{format-spec}] @var{name}
33392 Evaluates the expression that is represented by the specified variable
33393 object and returns its value as a string. The format of the string
33394 can be specified with the @samp{-f} option. The possible values of
33395 this option are the same as for @code{-var-set-format}
33396 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33397 the current display format will be used. The current display format
33398 can be changed using the @code{-var-set-format} command.
33404 Note that one must invoke @code{-var-list-children} for a variable
33405 before the value of a child variable can be evaluated.
33407 @subheading The @code{-var-assign} Command
33408 @findex -var-assign
33410 @subsubheading Synopsis
33413 -var-assign @var{name} @var{expression}
33416 Assigns the value of @var{expression} to the variable object specified
33417 by @var{name}. The object must be @samp{editable}. If the variable's
33418 value is altered by the assign, the variable will show up in any
33419 subsequent @code{-var-update} list.
33421 @subsubheading Example
33429 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
33433 @subheading The @code{-var-update} Command
33434 @findex -var-update
33436 @subsubheading Synopsis
33439 -var-update [@var{print-values}] @{@var{name} | "*"@}
33442 Reevaluate the expressions corresponding to the variable object
33443 @var{name} and all its direct and indirect children, and return the
33444 list of variable objects whose values have changed; @var{name} must
33445 be a root variable object. Here, ``changed'' means that the result of
33446 @code{-var-evaluate-expression} before and after the
33447 @code{-var-update} is different. If @samp{*} is used as the variable
33448 object names, all existing variable objects are updated, except
33449 for frozen ones (@pxref{-var-set-frozen}). The option
33450 @var{print-values} determines whether both names and values, or just
33451 names are printed. The possible values of this option are the same
33452 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33453 recommended to use the @samp{--all-values} option, to reduce the
33454 number of MI commands needed on each program stop.
33456 With the @samp{*} parameter, if a variable object is bound to a
33457 currently running thread, it will not be updated, without any
33460 If @code{-var-set-update-range} was previously used on a varobj, then
33461 only the selected range of children will be reported.
33463 @code{-var-update} reports all the changed varobjs in a tuple named
33466 Each item in the change list is itself a tuple holding:
33470 The name of the varobj.
33473 If values were requested for this update, then this field will be
33474 present and will hold the value of the varobj.
33477 @anchor{-var-update}
33478 This field is a string which may take one of three values:
33482 The variable object's current value is valid.
33485 The variable object does not currently hold a valid value but it may
33486 hold one in the future if its associated expression comes back into
33490 The variable object no longer holds a valid value.
33491 This can occur when the executable file being debugged has changed,
33492 either through recompilation or by using the @value{GDBN} @code{file}
33493 command. The front end should normally choose to delete these variable
33497 In the future new values may be added to this list so the front should
33498 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33501 This is only present if the varobj is still valid. If the type
33502 changed, then this will be the string @samp{true}; otherwise it will
33505 When a varobj's type changes, its children are also likely to have
33506 become incorrect. Therefore, the varobj's children are automatically
33507 deleted when this attribute is @samp{true}. Also, the varobj's update
33508 range, when set using the @code{-var-set-update-range} command, is
33512 If the varobj's type changed, then this field will be present and will
33515 @item new_num_children
33516 For a dynamic varobj, if the number of children changed, or if the
33517 type changed, this will be the new number of children.
33519 The @samp{numchild} field in other varobj responses is generally not
33520 valid for a dynamic varobj -- it will show the number of children that
33521 @value{GDBN} knows about, but because dynamic varobjs lazily
33522 instantiate their children, this will not reflect the number of
33523 children which may be available.
33525 The @samp{new_num_children} attribute only reports changes to the
33526 number of children known by @value{GDBN}. This is the only way to
33527 detect whether an update has removed children (which necessarily can
33528 only happen at the end of the update range).
33531 The display hint, if any.
33534 This is an integer value, which will be 1 if there are more children
33535 available outside the varobj's update range.
33538 This attribute will be present and have the value @samp{1} if the
33539 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33540 then this attribute will not be present.
33543 If new children were added to a dynamic varobj within the selected
33544 update range (as set by @code{-var-set-update-range}), then they will
33545 be listed in this attribute.
33548 @subsubheading Example
33555 -var-update --all-values var1
33556 ^done,changelist=[@{name="var1",value="3",in_scope="true",
33557 type_changed="false"@}]
33561 @subheading The @code{-var-set-frozen} Command
33562 @findex -var-set-frozen
33563 @anchor{-var-set-frozen}
33565 @subsubheading Synopsis
33568 -var-set-frozen @var{name} @var{flag}
33571 Set the frozenness flag on the variable object @var{name}. The
33572 @var{flag} parameter should be either @samp{1} to make the variable
33573 frozen or @samp{0} to make it unfrozen. If a variable object is
33574 frozen, then neither itself, nor any of its children, are
33575 implicitly updated by @code{-var-update} of
33576 a parent variable or by @code{-var-update *}. Only
33577 @code{-var-update} of the variable itself will update its value and
33578 values of its children. After a variable object is unfrozen, it is
33579 implicitly updated by all subsequent @code{-var-update} operations.
33580 Unfreezing a variable does not update it, only subsequent
33581 @code{-var-update} does.
33583 @subsubheading Example
33587 -var-set-frozen V 1
33592 @subheading The @code{-var-set-update-range} command
33593 @findex -var-set-update-range
33594 @anchor{-var-set-update-range}
33596 @subsubheading Synopsis
33599 -var-set-update-range @var{name} @var{from} @var{to}
33602 Set the range of children to be returned by future invocations of
33603 @code{-var-update}.
33605 @var{from} and @var{to} indicate the range of children to report. If
33606 @var{from} or @var{to} is less than zero, the range is reset and all
33607 children will be reported. Otherwise, children starting at @var{from}
33608 (zero-based) and up to and excluding @var{to} will be reported.
33610 @subsubheading Example
33614 -var-set-update-range V 1 2
33618 @subheading The @code{-var-set-visualizer} command
33619 @findex -var-set-visualizer
33620 @anchor{-var-set-visualizer}
33622 @subsubheading Synopsis
33625 -var-set-visualizer @var{name} @var{visualizer}
33628 Set a visualizer for the variable object @var{name}.
33630 @var{visualizer} is the visualizer to use. The special value
33631 @samp{None} means to disable any visualizer in use.
33633 If not @samp{None}, @var{visualizer} must be a Python expression.
33634 This expression must evaluate to a callable object which accepts a
33635 single argument. @value{GDBN} will call this object with the value of
33636 the varobj @var{name} as an argument (this is done so that the same
33637 Python pretty-printing code can be used for both the CLI and MI).
33638 When called, this object must return an object which conforms to the
33639 pretty-printing interface (@pxref{Pretty Printing API}).
33641 The pre-defined function @code{gdb.default_visualizer} may be used to
33642 select a visualizer by following the built-in process
33643 (@pxref{Selecting Pretty-Printers}). This is done automatically when
33644 a varobj is created, and so ordinarily is not needed.
33646 This feature is only available if Python support is enabled. The MI
33647 command @code{-list-features} (@pxref{GDB/MI Support Commands})
33648 can be used to check this.
33650 @subsubheading Example
33652 Resetting the visualizer:
33656 -var-set-visualizer V None
33660 Reselecting the default (type-based) visualizer:
33664 -var-set-visualizer V gdb.default_visualizer
33668 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33669 can be used to instantiate this class for a varobj:
33673 -var-set-visualizer V "lambda val: SomeClass()"
33677 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33678 @node GDB/MI Data Manipulation
33679 @section @sc{gdb/mi} Data Manipulation
33681 @cindex data manipulation, in @sc{gdb/mi}
33682 @cindex @sc{gdb/mi}, data manipulation
33683 This section describes the @sc{gdb/mi} commands that manipulate data:
33684 examine memory and registers, evaluate expressions, etc.
33686 For details about what an addressable memory unit is,
33687 @pxref{addressable memory unit}.
33689 @c REMOVED FROM THE INTERFACE.
33690 @c @subheading -data-assign
33691 @c Change the value of a program variable. Plenty of side effects.
33692 @c @subsubheading GDB Command
33694 @c @subsubheading Example
33697 @subheading The @code{-data-disassemble} Command
33698 @findex -data-disassemble
33700 @subsubheading Synopsis
33704 [ -s @var{start-addr} -e @var{end-addr} ]
33705 | [ -a @var{addr} ]
33706 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33714 @item @var{start-addr}
33715 is the beginning address (or @code{$pc})
33716 @item @var{end-addr}
33719 is an address anywhere within (or the name of) the function to
33720 disassemble. If an address is specified, the whole function
33721 surrounding that address will be disassembled. If a name is
33722 specified, the whole function with that name will be disassembled.
33723 @item @var{filename}
33724 is the name of the file to disassemble
33725 @item @var{linenum}
33726 is the line number to disassemble around
33728 is the number of disassembly lines to be produced. If it is -1,
33729 the whole function will be disassembled, in case no @var{end-addr} is
33730 specified. If @var{end-addr} is specified as a non-zero value, and
33731 @var{lines} is lower than the number of disassembly lines between
33732 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
33733 displayed; if @var{lines} is higher than the number of lines between
33734 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33739 @item 0 disassembly only
33740 @item 1 mixed source and disassembly (deprecated)
33741 @item 2 disassembly with raw opcodes
33742 @item 3 mixed source and disassembly with raw opcodes (deprecated)
33743 @item 4 mixed source and disassembly
33744 @item 5 mixed source and disassembly with raw opcodes
33747 Modes 1 and 3 are deprecated. The output is ``source centric''
33748 which hasn't proved useful in practice.
33749 @xref{Machine Code}, for a discussion of the difference between
33750 @code{/m} and @code{/s} output of the @code{disassemble} command.
33753 @subsubheading Result
33755 The result of the @code{-data-disassemble} command will be a list named
33756 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33757 used with the @code{-data-disassemble} command.
33759 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33764 The address at which this instruction was disassembled.
33767 The name of the function this instruction is within.
33770 The decimal offset in bytes from the start of @samp{func-name}.
33773 The text disassembly for this @samp{address}.
33776 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33777 bytes for the @samp{inst} field.
33781 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33782 @samp{src_and_asm_line}, each of which has the following fields:
33786 The line number within @samp{file}.
33789 The file name from the compilation unit. This might be an absolute
33790 file name or a relative file name depending on the compile command
33794 Absolute file name of @samp{file}. It is converted to a canonical form
33795 using the source file search path
33796 (@pxref{Source Path, ,Specifying Source Directories})
33797 and after resolving all the symbolic links.
33799 If the source file is not found this field will contain the path as
33800 present in the debug information.
33802 @item line_asm_insn
33803 This is a list of tuples containing the disassembly for @samp{line} in
33804 @samp{file}. The fields of each tuple are the same as for
33805 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33806 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33811 Note that whatever included in the @samp{inst} field, is not
33812 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33815 @subsubheading @value{GDBN} Command
33817 The corresponding @value{GDBN} command is @samp{disassemble}.
33819 @subsubheading Example
33821 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33825 -data-disassemble -s $pc -e "$pc + 20" -- 0
33828 @{address="0x000107c0",func-name="main",offset="4",
33829 inst="mov 2, %o0"@},
33830 @{address="0x000107c4",func-name="main",offset="8",
33831 inst="sethi %hi(0x11800), %o2"@},
33832 @{address="0x000107c8",func-name="main",offset="12",
33833 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33834 @{address="0x000107cc",func-name="main",offset="16",
33835 inst="sethi %hi(0x11800), %o2"@},
33836 @{address="0x000107d0",func-name="main",offset="20",
33837 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33841 Disassemble the whole @code{main} function. Line 32 is part of
33845 -data-disassemble -f basics.c -l 32 -- 0
33847 @{address="0x000107bc",func-name="main",offset="0",
33848 inst="save %sp, -112, %sp"@},
33849 @{address="0x000107c0",func-name="main",offset="4",
33850 inst="mov 2, %o0"@},
33851 @{address="0x000107c4",func-name="main",offset="8",
33852 inst="sethi %hi(0x11800), %o2"@},
33854 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33855 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33859 Disassemble 3 instructions from the start of @code{main}:
33863 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33865 @{address="0x000107bc",func-name="main",offset="0",
33866 inst="save %sp, -112, %sp"@},
33867 @{address="0x000107c0",func-name="main",offset="4",
33868 inst="mov 2, %o0"@},
33869 @{address="0x000107c4",func-name="main",offset="8",
33870 inst="sethi %hi(0x11800), %o2"@}]
33874 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33878 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33880 src_and_asm_line=@{line="31",
33881 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33882 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33883 line_asm_insn=[@{address="0x000107bc",
33884 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33885 src_and_asm_line=@{line="32",
33886 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33887 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33888 line_asm_insn=[@{address="0x000107c0",
33889 func-name="main",offset="4",inst="mov 2, %o0"@},
33890 @{address="0x000107c4",func-name="main",offset="8",
33891 inst="sethi %hi(0x11800), %o2"@}]@}]
33896 @subheading The @code{-data-evaluate-expression} Command
33897 @findex -data-evaluate-expression
33899 @subsubheading Synopsis
33902 -data-evaluate-expression @var{expr}
33905 Evaluate @var{expr} as an expression. The expression could contain an
33906 inferior function call. The function call will execute synchronously.
33907 If the expression contains spaces, it must be enclosed in double quotes.
33909 @subsubheading @value{GDBN} Command
33911 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33912 @samp{call}. In @code{gdbtk} only, there's a corresponding
33913 @samp{gdb_eval} command.
33915 @subsubheading Example
33917 In the following example, the numbers that precede the commands are the
33918 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33919 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33923 211-data-evaluate-expression A
33926 311-data-evaluate-expression &A
33927 311^done,value="0xefffeb7c"
33929 411-data-evaluate-expression A+3
33932 511-data-evaluate-expression "A + 3"
33938 @subheading The @code{-data-list-changed-registers} Command
33939 @findex -data-list-changed-registers
33941 @subsubheading Synopsis
33944 -data-list-changed-registers
33947 Display a list of the registers that have changed.
33949 @subsubheading @value{GDBN} Command
33951 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33952 has the corresponding command @samp{gdb_changed_register_list}.
33954 @subsubheading Example
33956 On a PPC MBX board:
33964 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33965 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33966 line="5",arch="powerpc"@}
33968 -data-list-changed-registers
33969 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33970 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33971 "24","25","26","27","28","30","31","64","65","66","67","69"]
33976 @subheading The @code{-data-list-register-names} Command
33977 @findex -data-list-register-names
33979 @subsubheading Synopsis
33982 -data-list-register-names [ ( @var{regno} )+ ]
33985 Show a list of register names for the current target. If no arguments
33986 are given, it shows a list of the names of all the registers. If
33987 integer numbers are given as arguments, it will print a list of the
33988 names of the registers corresponding to the arguments. To ensure
33989 consistency between a register name and its number, the output list may
33990 include empty register names.
33992 @subsubheading @value{GDBN} Command
33994 @value{GDBN} does not have a command which corresponds to
33995 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33996 corresponding command @samp{gdb_regnames}.
33998 @subsubheading Example
34000 For the PPC MBX board:
34003 -data-list-register-names
34004 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
34005 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
34006 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
34007 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
34008 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
34009 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
34010 "", "pc","ps","cr","lr","ctr","xer"]
34012 -data-list-register-names 1 2 3
34013 ^done,register-names=["r1","r2","r3"]
34017 @subheading The @code{-data-list-register-values} Command
34018 @findex -data-list-register-values
34020 @subsubheading Synopsis
34023 -data-list-register-values
34024 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
34027 Display the registers' contents. The format according to which the
34028 registers' contents are to be returned is given by @var{fmt}, followed
34029 by an optional list of numbers specifying the registers to display. A
34030 missing list of numbers indicates that the contents of all the
34031 registers must be returned. The @code{--skip-unavailable} option
34032 indicates that only the available registers are to be returned.
34034 Allowed formats for @var{fmt} are:
34051 @subsubheading @value{GDBN} Command
34053 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
34054 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
34056 @subsubheading Example
34058 For a PPC MBX board (note: line breaks are for readability only, they
34059 don't appear in the actual output):
34063 -data-list-register-values r 64 65
34064 ^done,register-values=[@{number="64",value="0xfe00a300"@},
34065 @{number="65",value="0x00029002"@}]
34067 -data-list-register-values x
34068 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
34069 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
34070 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
34071 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
34072 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
34073 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
34074 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
34075 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
34076 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
34077 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
34078 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
34079 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
34080 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
34081 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
34082 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
34083 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
34084 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
34085 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
34086 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
34087 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
34088 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
34089 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
34090 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
34091 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
34092 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
34093 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
34094 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
34095 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
34096 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
34097 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
34098 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
34099 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
34100 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
34101 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
34102 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
34103 @{number="69",value="0x20002b03"@}]
34108 @subheading The @code{-data-read-memory} Command
34109 @findex -data-read-memory
34111 This command is deprecated, use @code{-data-read-memory-bytes} instead.
34113 @subsubheading Synopsis
34116 -data-read-memory [ -o @var{byte-offset} ]
34117 @var{address} @var{word-format} @var{word-size}
34118 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
34125 @item @var{address}
34126 An expression specifying the address of the first memory word to be
34127 read. Complex expressions containing embedded white space should be
34128 quoted using the C convention.
34130 @item @var{word-format}
34131 The format to be used to print the memory words. The notation is the
34132 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
34135 @item @var{word-size}
34136 The size of each memory word in bytes.
34138 @item @var{nr-rows}
34139 The number of rows in the output table.
34141 @item @var{nr-cols}
34142 The number of columns in the output table.
34145 If present, indicates that each row should include an @sc{ascii} dump. The
34146 value of @var{aschar} is used as a padding character when a byte is not a
34147 member of the printable @sc{ascii} character set (printable @sc{ascii}
34148 characters are those whose code is between 32 and 126, inclusively).
34150 @item @var{byte-offset}
34151 An offset to add to the @var{address} before fetching memory.
34154 This command displays memory contents as a table of @var{nr-rows} by
34155 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
34156 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
34157 (returned as @samp{total-bytes}). Should less than the requested number
34158 of bytes be returned by the target, the missing words are identified
34159 using @samp{N/A}. The number of bytes read from the target is returned
34160 in @samp{nr-bytes} and the starting address used to read memory in
34163 The address of the next/previous row or page is available in
34164 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
34167 @subsubheading @value{GDBN} Command
34169 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
34170 @samp{gdb_get_mem} memory read command.
34172 @subsubheading Example
34174 Read six bytes of memory starting at @code{bytes+6} but then offset by
34175 @code{-6} bytes. Format as three rows of two columns. One byte per
34176 word. Display each word in hex.
34180 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
34181 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
34182 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
34183 prev-page="0x0000138a",memory=[
34184 @{addr="0x00001390",data=["0x00","0x01"]@},
34185 @{addr="0x00001392",data=["0x02","0x03"]@},
34186 @{addr="0x00001394",data=["0x04","0x05"]@}]
34190 Read two bytes of memory starting at address @code{shorts + 64} and
34191 display as a single word formatted in decimal.
34195 5-data-read-memory shorts+64 d 2 1 1
34196 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
34197 next-row="0x00001512",prev-row="0x0000150e",
34198 next-page="0x00001512",prev-page="0x0000150e",memory=[
34199 @{addr="0x00001510",data=["128"]@}]
34203 Read thirty two bytes of memory starting at @code{bytes+16} and format
34204 as eight rows of four columns. Include a string encoding with @samp{x}
34205 used as the non-printable character.
34209 4-data-read-memory bytes+16 x 1 8 4 x
34210 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
34211 next-row="0x000013c0",prev-row="0x0000139c",
34212 next-page="0x000013c0",prev-page="0x00001380",memory=[
34213 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
34214 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
34215 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
34216 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
34217 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
34218 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
34219 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
34220 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
34224 @subheading The @code{-data-read-memory-bytes} Command
34225 @findex -data-read-memory-bytes
34227 @subsubheading Synopsis
34230 -data-read-memory-bytes [ -o @var{offset} ]
34231 @var{address} @var{count}
34238 @item @var{address}
34239 An expression specifying the address of the first addressable memory unit
34240 to be read. Complex expressions containing embedded white space should be
34241 quoted using the C convention.
34244 The number of addressable memory units to read. This should be an integer
34248 The offset relative to @var{address} at which to start reading. This
34249 should be an integer literal. This option is provided so that a frontend
34250 is not required to first evaluate address and then perform address
34251 arithmetics itself.
34255 This command attempts to read all accessible memory regions in the
34256 specified range. First, all regions marked as unreadable in the memory
34257 map (if one is defined) will be skipped. @xref{Memory Region
34258 Attributes}. Second, @value{GDBN} will attempt to read the remaining
34259 regions. For each one, if reading full region results in an errors,
34260 @value{GDBN} will try to read a subset of the region.
34262 In general, every single memory unit in the region may be readable or not,
34263 and the only way to read every readable unit is to try a read at
34264 every address, which is not practical. Therefore, @value{GDBN} will
34265 attempt to read all accessible memory units at either beginning or the end
34266 of the region, using a binary division scheme. This heuristic works
34267 well for reading across a memory map boundary. Note that if a region
34268 has a readable range that is neither at the beginning or the end,
34269 @value{GDBN} will not read it.
34271 The result record (@pxref{GDB/MI Result Records}) that is output of
34272 the command includes a field named @samp{memory} whose content is a
34273 list of tuples. Each tuple represent a successfully read memory block
34274 and has the following fields:
34278 The start address of the memory block, as hexadecimal literal.
34281 The end address of the memory block, as hexadecimal literal.
34284 The offset of the memory block, as hexadecimal literal, relative to
34285 the start address passed to @code{-data-read-memory-bytes}.
34288 The contents of the memory block, in hex.
34294 @subsubheading @value{GDBN} Command
34296 The corresponding @value{GDBN} command is @samp{x}.
34298 @subsubheading Example
34302 -data-read-memory-bytes &a 10
34303 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34305 contents="01000000020000000300"@}]
34310 @subheading The @code{-data-write-memory-bytes} Command
34311 @findex -data-write-memory-bytes
34313 @subsubheading Synopsis
34316 -data-write-memory-bytes @var{address} @var{contents}
34317 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
34324 @item @var{address}
34325 An expression specifying the address of the first addressable memory unit
34326 to be written. Complex expressions containing embedded white space should
34327 be quoted using the C convention.
34329 @item @var{contents}
34330 The hex-encoded data to write. It is an error if @var{contents} does
34331 not represent an integral number of addressable memory units.
34334 Optional argument indicating the number of addressable memory units to be
34335 written. If @var{count} is greater than @var{contents}' length,
34336 @value{GDBN} will repeatedly write @var{contents} until it fills
34337 @var{count} memory units.
34341 @subsubheading @value{GDBN} Command
34343 There's no corresponding @value{GDBN} command.
34345 @subsubheading Example
34349 -data-write-memory-bytes &a "aabbccdd"
34356 -data-write-memory-bytes &a "aabbccdd" 16e
34361 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34362 @node GDB/MI Tracepoint Commands
34363 @section @sc{gdb/mi} Tracepoint Commands
34365 The commands defined in this section implement MI support for
34366 tracepoints. For detailed introduction, see @ref{Tracepoints}.
34368 @subheading The @code{-trace-find} Command
34369 @findex -trace-find
34371 @subsubheading Synopsis
34374 -trace-find @var{mode} [@var{parameters}@dots{}]
34377 Find a trace frame using criteria defined by @var{mode} and
34378 @var{parameters}. The following table lists permissible
34379 modes and their parameters. For details of operation, see @ref{tfind}.
34384 No parameters are required. Stops examining trace frames.
34387 An integer is required as parameter. Selects tracepoint frame with
34390 @item tracepoint-number
34391 An integer is required as parameter. Finds next
34392 trace frame that corresponds to tracepoint with the specified number.
34395 An address is required as parameter. Finds
34396 next trace frame that corresponds to any tracepoint at the specified
34399 @item pc-inside-range
34400 Two addresses are required as parameters. Finds next trace
34401 frame that corresponds to a tracepoint at an address inside the
34402 specified range. Both bounds are considered to be inside the range.
34404 @item pc-outside-range
34405 Two addresses are required as parameters. Finds
34406 next trace frame that corresponds to a tracepoint at an address outside
34407 the specified range. Both bounds are considered to be inside the range.
34410 Line specification is required as parameter. @xref{Specify Location}.
34411 Finds next trace frame that corresponds to a tracepoint at
34412 the specified location.
34416 If @samp{none} was passed as @var{mode}, the response does not
34417 have fields. Otherwise, the response may have the following fields:
34421 This field has either @samp{0} or @samp{1} as the value, depending
34422 on whether a matching tracepoint was found.
34425 The index of the found traceframe. This field is present iff
34426 the @samp{found} field has value of @samp{1}.
34429 The index of the found tracepoint. This field is present iff
34430 the @samp{found} field has value of @samp{1}.
34433 The information about the frame corresponding to the found trace
34434 frame. This field is present only if a trace frame was found.
34435 @xref{GDB/MI Frame Information}, for description of this field.
34439 @subsubheading @value{GDBN} Command
34441 The corresponding @value{GDBN} command is @samp{tfind}.
34443 @subheading -trace-define-variable
34444 @findex -trace-define-variable
34446 @subsubheading Synopsis
34449 -trace-define-variable @var{name} [ @var{value} ]
34452 Create trace variable @var{name} if it does not exist. If
34453 @var{value} is specified, sets the initial value of the specified
34454 trace variable to that value. Note that the @var{name} should start
34455 with the @samp{$} character.
34457 @subsubheading @value{GDBN} Command
34459 The corresponding @value{GDBN} command is @samp{tvariable}.
34461 @subheading The @code{-trace-frame-collected} Command
34462 @findex -trace-frame-collected
34464 @subsubheading Synopsis
34467 -trace-frame-collected
34468 [--var-print-values @var{var_pval}]
34469 [--comp-print-values @var{comp_pval}]
34470 [--registers-format @var{regformat}]
34471 [--memory-contents]
34474 This command returns the set of collected objects, register names,
34475 trace state variable names, memory ranges and computed expressions
34476 that have been collected at a particular trace frame. The optional
34477 parameters to the command affect the output format in different ways.
34478 See the output description table below for more details.
34480 The reported names can be used in the normal manner to create
34481 varobjs and inspect the objects themselves. The items returned by
34482 this command are categorized so that it is clear which is a variable,
34483 which is a register, which is a trace state variable, which is a
34484 memory range and which is a computed expression.
34486 For instance, if the actions were
34488 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34489 collect *(int*)0xaf02bef0@@40
34493 the object collected in its entirety would be @code{myVar}. The
34494 object @code{myArray} would be partially collected, because only the
34495 element at index @code{myIndex} would be collected. The remaining
34496 objects would be computed expressions.
34498 An example output would be:
34502 -trace-frame-collected
34504 explicit-variables=[@{name="myVar",value="1"@}],
34505 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34506 @{name="myObj.field",value="0"@},
34507 @{name="myPtr->field",value="1"@},
34508 @{name="myCount + 2",value="3"@},
34509 @{name="$tvar1 + 1",value="43970027"@}],
34510 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34511 @{number="1",value="0x0"@},
34512 @{number="2",value="0x4"@},
34514 @{number="125",value="0x0"@}],
34515 tvars=[@{name="$tvar1",current="43970026"@}],
34516 memory=[@{address="0x0000000000602264",length="4"@},
34517 @{address="0x0000000000615bc0",length="4"@}]
34524 @item explicit-variables
34525 The set of objects that have been collected in their entirety (as
34526 opposed to collecting just a few elements of an array or a few struct
34527 members). For each object, its name and value are printed.
34528 The @code{--var-print-values} option affects how or whether the value
34529 field is output. If @var{var_pval} is 0, then print only the names;
34530 if it is 1, print also their values; and if it is 2, print the name,
34531 type and value for simple data types, and the name and type for
34532 arrays, structures and unions.
34534 @item computed-expressions
34535 The set of computed expressions that have been collected at the
34536 current trace frame. The @code{--comp-print-values} option affects
34537 this set like the @code{--var-print-values} option affects the
34538 @code{explicit-variables} set. See above.
34541 The registers that have been collected at the current trace frame.
34542 For each register collected, the name and current value are returned.
34543 The value is formatted according to the @code{--registers-format}
34544 option. See the @command{-data-list-register-values} command for a
34545 list of the allowed formats. The default is @samp{x}.
34548 The trace state variables that have been collected at the current
34549 trace frame. For each trace state variable collected, the name and
34550 current value are returned.
34553 The set of memory ranges that have been collected at the current trace
34554 frame. Its content is a list of tuples. Each tuple represents a
34555 collected memory range and has the following fields:
34559 The start address of the memory range, as hexadecimal literal.
34562 The length of the memory range, as decimal literal.
34565 The contents of the memory block, in hex. This field is only present
34566 if the @code{--memory-contents} option is specified.
34572 @subsubheading @value{GDBN} Command
34574 There is no corresponding @value{GDBN} command.
34576 @subsubheading Example
34578 @subheading -trace-list-variables
34579 @findex -trace-list-variables
34581 @subsubheading Synopsis
34584 -trace-list-variables
34587 Return a table of all defined trace variables. Each element of the
34588 table has the following fields:
34592 The name of the trace variable. This field is always present.
34595 The initial value. This is a 64-bit signed integer. This
34596 field is always present.
34599 The value the trace variable has at the moment. This is a 64-bit
34600 signed integer. This field is absent iff current value is
34601 not defined, for example if the trace was never run, or is
34606 @subsubheading @value{GDBN} Command
34608 The corresponding @value{GDBN} command is @samp{tvariables}.
34610 @subsubheading Example
34614 -trace-list-variables
34615 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
34616 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34617 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34618 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34619 body=[variable=@{name="$trace_timestamp",initial="0"@}
34620 variable=@{name="$foo",initial="10",current="15"@}]@}
34624 @subheading -trace-save
34625 @findex -trace-save
34627 @subsubheading Synopsis
34630 -trace-save [ -r ] [ -ctf ] @var{filename}
34633 Saves the collected trace data to @var{filename}. Without the
34634 @samp{-r} option, the data is downloaded from the target and saved
34635 in a local file. With the @samp{-r} option the target is asked
34636 to perform the save.
34638 By default, this command will save the trace in the tfile format. You can
34639 supply the optional @samp{-ctf} argument to save it the CTF format. See
34640 @ref{Trace Files} for more information about CTF.
34642 @subsubheading @value{GDBN} Command
34644 The corresponding @value{GDBN} command is @samp{tsave}.
34647 @subheading -trace-start
34648 @findex -trace-start
34650 @subsubheading Synopsis
34656 Starts a tracing experiment. The result of this command does not
34659 @subsubheading @value{GDBN} Command
34661 The corresponding @value{GDBN} command is @samp{tstart}.
34663 @subheading -trace-status
34664 @findex -trace-status
34666 @subsubheading Synopsis
34672 Obtains the status of a tracing experiment. The result may include
34673 the following fields:
34678 May have a value of either @samp{0}, when no tracing operations are
34679 supported, @samp{1}, when all tracing operations are supported, or
34680 @samp{file} when examining trace file. In the latter case, examining
34681 of trace frame is possible but new tracing experiement cannot be
34682 started. This field is always present.
34685 May have a value of either @samp{0} or @samp{1} depending on whether
34686 tracing experiement is in progress on target. This field is present
34687 if @samp{supported} field is not @samp{0}.
34690 Report the reason why the tracing was stopped last time. This field
34691 may be absent iff tracing was never stopped on target yet. The
34692 value of @samp{request} means the tracing was stopped as result of
34693 the @code{-trace-stop} command. The value of @samp{overflow} means
34694 the tracing buffer is full. The value of @samp{disconnection} means
34695 tracing was automatically stopped when @value{GDBN} has disconnected.
34696 The value of @samp{passcount} means tracing was stopped when a
34697 tracepoint was passed a maximal number of times for that tracepoint.
34698 This field is present if @samp{supported} field is not @samp{0}.
34700 @item stopping-tracepoint
34701 The number of tracepoint whose passcount as exceeded. This field is
34702 present iff the @samp{stop-reason} field has the value of
34706 @itemx frames-created
34707 The @samp{frames} field is a count of the total number of trace frames
34708 in the trace buffer, while @samp{frames-created} is the total created
34709 during the run, including ones that were discarded, such as when a
34710 circular trace buffer filled up. Both fields are optional.
34714 These fields tell the current size of the tracing buffer and the
34715 remaining space. These fields are optional.
34718 The value of the circular trace buffer flag. @code{1} means that the
34719 trace buffer is circular and old trace frames will be discarded if
34720 necessary to make room, @code{0} means that the trace buffer is linear
34724 The value of the disconnected tracing flag. @code{1} means that
34725 tracing will continue after @value{GDBN} disconnects, @code{0} means
34726 that the trace run will stop.
34729 The filename of the trace file being examined. This field is
34730 optional, and only present when examining a trace file.
34734 @subsubheading @value{GDBN} Command
34736 The corresponding @value{GDBN} command is @samp{tstatus}.
34738 @subheading -trace-stop
34739 @findex -trace-stop
34741 @subsubheading Synopsis
34747 Stops a tracing experiment. The result of this command has the same
34748 fields as @code{-trace-status}, except that the @samp{supported} and
34749 @samp{running} fields are not output.
34751 @subsubheading @value{GDBN} Command
34753 The corresponding @value{GDBN} command is @samp{tstop}.
34756 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34757 @node GDB/MI Symbol Query
34758 @section @sc{gdb/mi} Symbol Query Commands
34762 @subheading The @code{-symbol-info-address} Command
34763 @findex -symbol-info-address
34765 @subsubheading Synopsis
34768 -symbol-info-address @var{symbol}
34771 Describe where @var{symbol} is stored.
34773 @subsubheading @value{GDBN} Command
34775 The corresponding @value{GDBN} command is @samp{info address}.
34777 @subsubheading Example
34781 @subheading The @code{-symbol-info-file} Command
34782 @findex -symbol-info-file
34784 @subsubheading Synopsis
34790 Show the file for the symbol.
34792 @subsubheading @value{GDBN} Command
34794 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34795 @samp{gdb_find_file}.
34797 @subsubheading Example
34801 @subheading The @code{-symbol-info-functions} Command
34802 @findex -symbol-info-functions
34803 @anchor{-symbol-info-functions}
34805 @subsubheading Synopsis
34808 -symbol-info-functions [--include-nondebug]
34809 [--type @var{type_regexp}]
34810 [--name @var{name_regexp}]
34811 [--max-results @var{limit}]
34815 Return a list containing the names and types for all global functions
34816 taken from the debug information. The functions are grouped by source
34817 file, and shown with the line number on which each function is
34820 The @code{--include-nondebug} option causes the output to include
34821 code symbols from the symbol table.
34823 The options @code{--type} and @code{--name} allow the symbols returned
34824 to be filtered based on either the name of the function, or the type
34825 signature of the function.
34827 The option @code{--max-results} restricts the command to return no
34828 more than @var{limit} results. If exactly @var{limit} results are
34829 returned then there might be additional results available if a higher
34832 @subsubheading @value{GDBN} Command
34834 The corresponding @value{GDBN} command is @samp{info functions}.
34836 @subsubheading Example
34840 -symbol-info-functions
34843 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34844 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34845 symbols=[@{line="36", name="f4", type="void (int *)",
34846 description="void f4(int *);"@},
34847 @{line="42", name="main", type="int ()",
34848 description="int main();"@},
34849 @{line="30", name="f1", type="my_int_t (int, int)",
34850 description="static my_int_t f1(int, int);"@}]@},
34851 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34852 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34853 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34854 description="float f2(another_float_t);"@},
34855 @{line="39", name="f3", type="int (another_int_t)",
34856 description="int f3(another_int_t);"@},
34857 @{line="27", name="f1", type="another_float_t (int)",
34858 description="static another_float_t f1(int);"@}]@}]@}
34862 -symbol-info-functions --name f1
34865 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34866 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34867 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34868 description="static my_int_t f1(int, int);"@}]@},
34869 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34870 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34871 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34872 description="static another_float_t f1(int);"@}]@}]@}
34876 -symbol-info-functions --type void
34879 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34880 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34881 symbols=[@{line="36", name="f4", type="void (int *)",
34882 description="void f4(int *);"@}]@}]@}
34886 -symbol-info-functions --include-nondebug
34889 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34890 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34891 symbols=[@{line="36", name="f4", type="void (int *)",
34892 description="void f4(int *);"@},
34893 @{line="42", name="main", type="int ()",
34894 description="int main();"@},
34895 @{line="30", name="f1", type="my_int_t (int, int)",
34896 description="static my_int_t f1(int, int);"@}]@},
34897 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34898 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34899 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34900 description="float f2(another_float_t);"@},
34901 @{line="39", name="f3", type="int (another_int_t)",
34902 description="int f3(another_int_t);"@},
34903 @{line="27", name="f1", type="another_float_t (int)",
34904 description="static another_float_t f1(int);"@}]@}],
34906 [@{address="0x0000000000400398",name="_init"@},
34907 @{address="0x00000000004003b0",name="_start"@},
34913 @subheading The @code{-symbol-info-module-functions} Command
34914 @findex -symbol-info-module-functions
34915 @anchor{-symbol-info-module-functions}
34917 @subsubheading Synopsis
34920 -symbol-info-module-functions [--module @var{module_regexp}]
34921 [--name @var{name_regexp}]
34922 [--type @var{type_regexp}]
34926 Return a list containing the names of all known functions within all
34927 know Fortran modules. The functions are grouped by source file and
34928 containing module, and shown with the line number on which each
34929 function is defined.
34931 The option @code{--module} only returns results for modules matching
34932 @var{module_regexp}. The option @code{--name} only returns functions
34933 whose name matches @var{name_regexp}, and @code{--type} only returns
34934 functions whose type matches @var{type_regexp}.
34936 @subsubheading @value{GDBN} Command
34938 The corresponding @value{GDBN} command is @samp{info module functions}.
34940 @subsubheading Example
34945 -symbol-info-module-functions
34948 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34949 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34950 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34951 description="void mod1::check_all(void);"@}]@}]@},
34953 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34954 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34955 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34956 description="void mod2::check_var_i(void);"@}]@}]@},
34958 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34959 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34960 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34961 description="void mod3::check_all(void);"@},
34962 @{line="27",name="mod3::check_mod2",type="void (void)",
34963 description="void mod3::check_mod2(void);"@}]@}]@},
34964 @{module="modmany",
34965 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34966 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34967 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34968 description="void modmany::check_some(void);"@}]@}]@},
34970 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34971 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34972 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34973 description="void moduse::check_all(void);"@},
34974 @{line="49",name="moduse::check_var_x",type="void (void)",
34975 description="void moduse::check_var_x(void);"@}]@}]@}]
34979 @subheading The @code{-symbol-info-module-variables} Command
34980 @findex -symbol-info-module-variables
34981 @anchor{-symbol-info-module-variables}
34983 @subsubheading Synopsis
34986 -symbol-info-module-variables [--module @var{module_regexp}]
34987 [--name @var{name_regexp}]
34988 [--type @var{type_regexp}]
34992 Return a list containing the names of all known variables within all
34993 know Fortran modules. The variables are grouped by source file and
34994 containing module, and shown with the line number on which each
34995 variable is defined.
34997 The option @code{--module} only returns results for modules matching
34998 @var{module_regexp}. The option @code{--name} only returns variables
34999 whose name matches @var{name_regexp}, and @code{--type} only returns
35000 variables whose type matches @var{type_regexp}.
35002 @subsubheading @value{GDBN} Command
35004 The corresponding @value{GDBN} command is @samp{info module variables}.
35006 @subsubheading Example
35011 -symbol-info-module-variables
35014 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35015 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35016 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
35017 description="integer(kind=4) mod1::var_const;"@},
35018 @{line="17",name="mod1::var_i",type="integer(kind=4)",
35019 description="integer(kind=4) mod1::var_i;"@}]@}]@},
35021 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35022 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35023 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
35024 description="integer(kind=4) mod2::var_i;"@}]@}]@},
35026 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35027 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35028 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
35029 description="integer(kind=4) mod3::mod1;"@},
35030 @{line="17",name="mod3::mod2",type="integer(kind=4)",
35031 description="integer(kind=4) mod3::mod2;"@},
35032 @{line="19",name="mod3::var_i",type="integer(kind=4)",
35033 description="integer(kind=4) mod3::var_i;"@}]@}]@},
35034 @{module="modmany",
35035 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35036 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35037 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
35038 description="integer(kind=4) modmany::var_a;"@},
35039 @{line="33",name="modmany::var_b",type="integer(kind=4)",
35040 description="integer(kind=4) modmany::var_b;"@},
35041 @{line="33",name="modmany::var_c",type="integer(kind=4)",
35042 description="integer(kind=4) modmany::var_c;"@},
35043 @{line="33",name="modmany::var_i",type="integer(kind=4)",
35044 description="integer(kind=4) modmany::var_i;"@}]@}]@},
35046 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35047 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35048 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
35049 description="integer(kind=4) moduse::var_x;"@},
35050 @{line="42",name="moduse::var_y",type="integer(kind=4)",
35051 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
35055 @subheading The @code{-symbol-info-modules} Command
35056 @findex -symbol-info-modules
35057 @anchor{-symbol-info-modules}
35059 @subsubheading Synopsis
35062 -symbol-info-modules [--name @var{name_regexp}]
35063 [--max-results @var{limit}]
35068 Return a list containing the names of all known Fortran modules. The
35069 modules are grouped by source file, and shown with the line number on
35070 which each modules is defined.
35072 The option @code{--name} allows the modules returned to be filtered
35073 based the name of the module.
35075 The option @code{--max-results} restricts the command to return no
35076 more than @var{limit} results. If exactly @var{limit} results are
35077 returned then there might be additional results available if a higher
35080 @subsubheading @value{GDBN} Command
35082 The corresponding @value{GDBN} command is @samp{info modules}.
35084 @subsubheading Example
35088 -symbol-info-modules
35091 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35092 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35093 symbols=[@{line="16",name="mod1"@},
35094 @{line="22",name="mod2"@}]@},
35095 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35096 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35097 symbols=[@{line="16",name="mod3"@},
35098 @{line="22",name="modmany"@},
35099 @{line="26",name="moduse"@}]@}]@}
35103 -symbol-info-modules --name mod[123]
35106 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35107 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35108 symbols=[@{line="16",name="mod1"@},
35109 @{line="22",name="mod2"@}]@},
35110 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35111 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35112 symbols=[@{line="16",name="mod3"@}]@}]@}
35116 @subheading The @code{-symbol-info-types} Command
35117 @findex -symbol-info-types
35118 @anchor{-symbol-info-types}
35120 @subsubheading Synopsis
35123 -symbol-info-types [--name @var{name_regexp}]
35124 [--max-results @var{limit}]
35129 Return a list of all defined types. The types are grouped by source
35130 file, and shown with the line number on which each user defined type
35131 is defined. Some base types are not defined in the source code but
35132 are added to the debug information by the compiler, for example
35133 @code{int}, @code{float}, etc.; these types do not have an associated
35136 The option @code{--name} allows the list of types returned to be
35139 The option @code{--max-results} restricts the command to return no
35140 more than @var{limit} results. If exactly @var{limit} results are
35141 returned then there might be additional results available if a higher
35144 @subsubheading @value{GDBN} Command
35146 The corresponding @value{GDBN} command is @samp{info types}.
35148 @subsubheading Example
35155 [@{filename="gdb.mi/mi-sym-info-1.c",
35156 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35157 symbols=[@{name="float"@},
35159 @{line="27",name="typedef int my_int_t;"@}]@},
35160 @{filename="gdb.mi/mi-sym-info-2.c",
35161 fullname="/project/gdb.mi/mi-sym-info-2.c",
35162 symbols=[@{line="24",name="typedef float another_float_t;"@},
35163 @{line="23",name="typedef int another_int_t;"@},
35165 @{name="int"@}]@}]@}
35169 -symbol-info-types --name _int_
35172 [@{filename="gdb.mi/mi-sym-info-1.c",
35173 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35174 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
35175 @{filename="gdb.mi/mi-sym-info-2.c",
35176 fullname="/project/gdb.mi/mi-sym-info-2.c",
35177 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
35181 @subheading The @code{-symbol-info-variables} Command
35182 @findex -symbol-info-variables
35183 @anchor{-symbol-info-variables}
35185 @subsubheading Synopsis
35188 -symbol-info-variables [--include-nondebug]
35189 [--type @var{type_regexp}]
35190 [--name @var{name_regexp}]
35191 [--max-results @var{limit}]
35196 Return a list containing the names and types for all global variables
35197 taken from the debug information. The variables are grouped by source
35198 file, and shown with the line number on which each variable is
35201 The @code{--include-nondebug} option causes the output to include
35202 data symbols from the symbol table.
35204 The options @code{--type} and @code{--name} allow the symbols returned
35205 to be filtered based on either the name of the variable, or the type
35208 The option @code{--max-results} restricts the command to return no
35209 more than @var{limit} results. If exactly @var{limit} results are
35210 returned then there might be additional results available if a higher
35213 @subsubheading @value{GDBN} Command
35215 The corresponding @value{GDBN} command is @samp{info variables}.
35217 @subsubheading Example
35221 -symbol-info-variables
35224 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35225 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35226 symbols=[@{line="25",name="global_f1",type="float",
35227 description="static float global_f1;"@},
35228 @{line="24",name="global_i1",type="int",
35229 description="static int global_i1;"@}]@},
35230 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35231 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35232 symbols=[@{line="21",name="global_f2",type="int",
35233 description="int global_f2;"@},
35234 @{line="20",name="global_i2",type="int",
35235 description="int global_i2;"@},
35236 @{line="19",name="global_f1",type="float",
35237 description="static float global_f1;"@},
35238 @{line="18",name="global_i1",type="int",
35239 description="static int global_i1;"@}]@}]@}
35243 -symbol-info-variables --name f1
35246 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35247 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35248 symbols=[@{line="25",name="global_f1",type="float",
35249 description="static float global_f1;"@}]@},
35250 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35251 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35252 symbols=[@{line="19",name="global_f1",type="float",
35253 description="static float global_f1;"@}]@}]@}
35257 -symbol-info-variables --type float
35260 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35261 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35262 symbols=[@{line="25",name="global_f1",type="float",
35263 description="static float global_f1;"@}]@},
35264 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35265 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35266 symbols=[@{line="19",name="global_f1",type="float",
35267 description="static float global_f1;"@}]@}]@}
35271 -symbol-info-variables --include-nondebug
35274 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35275 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35276 symbols=[@{line="25",name="global_f1",type="float",
35277 description="static float global_f1;"@},
35278 @{line="24",name="global_i1",type="int",
35279 description="static int global_i1;"@}]@},
35280 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35281 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35282 symbols=[@{line="21",name="global_f2",type="int",
35283 description="int global_f2;"@},
35284 @{line="20",name="global_i2",type="int",
35285 description="int global_i2;"@},
35286 @{line="19",name="global_f1",type="float",
35287 description="static float global_f1;"@},
35288 @{line="18",name="global_i1",type="int",
35289 description="static int global_i1;"@}]@}],
35291 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35292 @{address="0x00000000004005d8",name="__dso_handle"@}
35299 @subheading The @code{-symbol-info-line} Command
35300 @findex -symbol-info-line
35302 @subsubheading Synopsis
35308 Show the core addresses of the code for a source line.
35310 @subsubheading @value{GDBN} Command
35312 The corresponding @value{GDBN} command is @samp{info line}.
35313 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
35315 @subsubheading Example
35319 @subheading The @code{-symbol-info-symbol} Command
35320 @findex -symbol-info-symbol
35322 @subsubheading Synopsis
35325 -symbol-info-symbol @var{addr}
35328 Describe what symbol is at location @var{addr}.
35330 @subsubheading @value{GDBN} Command
35332 The corresponding @value{GDBN} command is @samp{info symbol}.
35334 @subsubheading Example
35338 @subheading The @code{-symbol-list-functions} Command
35339 @findex -symbol-list-functions
35341 @subsubheading Synopsis
35344 -symbol-list-functions
35347 List the functions in the executable.
35349 @subsubheading @value{GDBN} Command
35351 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35352 @samp{gdb_search} in @code{gdbtk}.
35354 @subsubheading Example
35359 @subheading The @code{-symbol-list-lines} Command
35360 @findex -symbol-list-lines
35362 @subsubheading Synopsis
35365 -symbol-list-lines @var{filename}
35368 Print the list of lines that contain code and their associated program
35369 addresses for the given source filename. The entries are sorted in
35370 ascending PC order.
35372 @subsubheading @value{GDBN} Command
35374 There is no corresponding @value{GDBN} command.
35376 @subsubheading Example
35379 -symbol-list-lines basics.c
35380 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
35386 @subheading The @code{-symbol-list-types} Command
35387 @findex -symbol-list-types
35389 @subsubheading Synopsis
35395 List all the type names.
35397 @subsubheading @value{GDBN} Command
35399 The corresponding commands are @samp{info types} in @value{GDBN},
35400 @samp{gdb_search} in @code{gdbtk}.
35402 @subsubheading Example
35406 @subheading The @code{-symbol-list-variables} Command
35407 @findex -symbol-list-variables
35409 @subsubheading Synopsis
35412 -symbol-list-variables
35415 List all the global and static variable names.
35417 @subsubheading @value{GDBN} Command
35419 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
35421 @subsubheading Example
35425 @subheading The @code{-symbol-locate} Command
35426 @findex -symbol-locate
35428 @subsubheading Synopsis
35434 @subsubheading @value{GDBN} Command
35436 @samp{gdb_loc} in @code{gdbtk}.
35438 @subsubheading Example
35442 @subheading The @code{-symbol-type} Command
35443 @findex -symbol-type
35445 @subsubheading Synopsis
35448 -symbol-type @var{variable}
35451 Show type of @var{variable}.
35453 @subsubheading @value{GDBN} Command
35455 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35456 @samp{gdb_obj_variable}.
35458 @subsubheading Example
35463 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35464 @node GDB/MI File Commands
35465 @section @sc{gdb/mi} File Commands
35467 This section describes the GDB/MI commands to specify executable file names
35468 and to read in and obtain symbol table information.
35470 @subheading The @code{-file-exec-and-symbols} Command
35471 @findex -file-exec-and-symbols
35473 @subsubheading Synopsis
35476 -file-exec-and-symbols @var{file}
35479 Specify the executable file to be debugged. This file is the one from
35480 which the symbol table is also read. If no file is specified, the
35481 command clears the executable and symbol information. If breakpoints
35482 are set when using this command with no arguments, @value{GDBN} will produce
35483 error messages. Otherwise, no output is produced, except a completion
35486 @subsubheading @value{GDBN} Command
35488 The corresponding @value{GDBN} command is @samp{file}.
35490 @subsubheading Example
35494 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35500 @subheading The @code{-file-exec-file} Command
35501 @findex -file-exec-file
35503 @subsubheading Synopsis
35506 -file-exec-file @var{file}
35509 Specify the executable file to be debugged. Unlike
35510 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35511 from this file. If used without argument, @value{GDBN} clears the information
35512 about the executable file. No output is produced, except a completion
35515 @subsubheading @value{GDBN} Command
35517 The corresponding @value{GDBN} command is @samp{exec-file}.
35519 @subsubheading Example
35523 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35530 @subheading The @code{-file-list-exec-sections} Command
35531 @findex -file-list-exec-sections
35533 @subsubheading Synopsis
35536 -file-list-exec-sections
35539 List the sections of the current executable file.
35541 @subsubheading @value{GDBN} Command
35543 The @value{GDBN} command @samp{info file} shows, among the rest, the same
35544 information as this command. @code{gdbtk} has a corresponding command
35545 @samp{gdb_load_info}.
35547 @subsubheading Example
35552 @subheading The @code{-file-list-exec-source-file} Command
35553 @findex -file-list-exec-source-file
35555 @subsubheading Synopsis
35558 -file-list-exec-source-file
35561 List the line number, the current source file, and the absolute path
35562 to the current source file for the current executable. The macro
35563 information field has a value of @samp{1} or @samp{0} depending on
35564 whether or not the file includes preprocessor macro information.
35566 @subsubheading @value{GDBN} Command
35568 The @value{GDBN} equivalent is @samp{info source}
35570 @subsubheading Example
35574 123-file-list-exec-source-file
35575 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35580 @subheading The @code{-file-list-exec-source-files} Command
35581 @findex -file-list-exec-source-files
35583 @subsubheading Synopsis
35586 -file-list-exec-source-files
35589 List the source files for the current executable.
35591 It will always output both the filename and fullname (absolute file
35592 name) of a source file.
35594 @subsubheading @value{GDBN} Command
35596 The @value{GDBN} equivalent is @samp{info sources}.
35597 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35599 @subsubheading Example
35602 -file-list-exec-source-files
35604 @{file=foo.c,fullname=/home/foo.c@},
35605 @{file=/home/bar.c,fullname=/home/bar.c@},
35606 @{file=gdb_could_not_find_fullpath.c@}]
35610 @subheading The @code{-file-list-shared-libraries} Command
35611 @findex -file-list-shared-libraries
35613 @subsubheading Synopsis
35616 -file-list-shared-libraries [ @var{regexp} ]
35619 List the shared libraries in the program.
35620 With a regular expression @var{regexp}, only those libraries whose
35621 names match @var{regexp} are listed.
35623 @subsubheading @value{GDBN} Command
35625 The corresponding @value{GDBN} command is @samp{info shared}. The fields
35626 have a similar meaning to the @code{=library-loaded} notification.
35627 The @code{ranges} field specifies the multiple segments belonging to this
35628 library. Each range has the following fields:
35632 The address defining the inclusive lower bound of the segment.
35634 The address defining the exclusive upper bound of the segment.
35637 @subsubheading Example
35640 -file-list-exec-source-files
35641 ^done,shared-libraries=[
35642 @{id="/lib/libfoo.so",target-name="/lib/libfoo.so",host-name="/lib/libfoo.so",symbols-loaded="1",thread-group="i1",ranges=[@{from="0x72815989",to="0x728162c0"@}]@},
35643 @{id="/lib/libbar.so",target-name="/lib/libbar.so",host-name="/lib/libbar.so",symbols-loaded="1",thread-group="i1",ranges=[@{from="0x76ee48c0",to="0x76ee9160"@}]@}]
35649 @subheading The @code{-file-list-symbol-files} Command
35650 @findex -file-list-symbol-files
35652 @subsubheading Synopsis
35655 -file-list-symbol-files
35660 @subsubheading @value{GDBN} Command
35662 The corresponding @value{GDBN} command is @samp{info file} (part of it).
35664 @subsubheading Example
35669 @subheading The @code{-file-symbol-file} Command
35670 @findex -file-symbol-file
35672 @subsubheading Synopsis
35675 -file-symbol-file @var{file}
35678 Read symbol table info from the specified @var{file} argument. When
35679 used without arguments, clears @value{GDBN}'s symbol table info. No output is
35680 produced, except for a completion notification.
35682 @subsubheading @value{GDBN} Command
35684 The corresponding @value{GDBN} command is @samp{symbol-file}.
35686 @subsubheading Example
35690 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35696 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35697 @node GDB/MI Memory Overlay Commands
35698 @section @sc{gdb/mi} Memory Overlay Commands
35700 The memory overlay commands are not implemented.
35702 @c @subheading -overlay-auto
35704 @c @subheading -overlay-list-mapping-state
35706 @c @subheading -overlay-list-overlays
35708 @c @subheading -overlay-map
35710 @c @subheading -overlay-off
35712 @c @subheading -overlay-on
35714 @c @subheading -overlay-unmap
35716 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35717 @node GDB/MI Signal Handling Commands
35718 @section @sc{gdb/mi} Signal Handling Commands
35720 Signal handling commands are not implemented.
35722 @c @subheading -signal-handle
35724 @c @subheading -signal-list-handle-actions
35726 @c @subheading -signal-list-signal-types
35730 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35731 @node GDB/MI Target Manipulation
35732 @section @sc{gdb/mi} Target Manipulation Commands
35735 @subheading The @code{-target-attach} Command
35736 @findex -target-attach
35738 @subsubheading Synopsis
35741 -target-attach @var{pid} | @var{gid} | @var{file}
35744 Attach to a process @var{pid} or a file @var{file} outside of
35745 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35746 group, the id previously returned by
35747 @samp{-list-thread-groups --available} must be used.
35749 @subsubheading @value{GDBN} Command
35751 The corresponding @value{GDBN} command is @samp{attach}.
35753 @subsubheading Example
35757 =thread-created,id="1"
35758 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35764 @subheading The @code{-target-compare-sections} Command
35765 @findex -target-compare-sections
35767 @subsubheading Synopsis
35770 -target-compare-sections [ @var{section} ]
35773 Compare data of section @var{section} on target to the exec file.
35774 Without the argument, all sections are compared.
35776 @subsubheading @value{GDBN} Command
35778 The @value{GDBN} equivalent is @samp{compare-sections}.
35780 @subsubheading Example
35785 @subheading The @code{-target-detach} Command
35786 @findex -target-detach
35788 @subsubheading Synopsis
35791 -target-detach [ @var{pid} | @var{gid} ]
35794 Detach from the remote target which normally resumes its execution.
35795 If either @var{pid} or @var{gid} is specified, detaches from either
35796 the specified process, or specified thread group. There's no output.
35798 @subsubheading @value{GDBN} Command
35800 The corresponding @value{GDBN} command is @samp{detach}.
35802 @subsubheading Example
35812 @subheading The @code{-target-disconnect} Command
35813 @findex -target-disconnect
35815 @subsubheading Synopsis
35821 Disconnect from the remote target. There's no output and the target is
35822 generally not resumed.
35824 @subsubheading @value{GDBN} Command
35826 The corresponding @value{GDBN} command is @samp{disconnect}.
35828 @subsubheading Example
35838 @subheading The @code{-target-download} Command
35839 @findex -target-download
35841 @subsubheading Synopsis
35847 Loads the executable onto the remote target.
35848 It prints out an update message every half second, which includes the fields:
35852 The name of the section.
35854 The size of what has been sent so far for that section.
35856 The size of the section.
35858 The total size of what was sent so far (the current and the previous sections).
35860 The size of the overall executable to download.
35864 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35865 @sc{gdb/mi} Output Syntax}).
35867 In addition, it prints the name and size of the sections, as they are
35868 downloaded. These messages include the following fields:
35872 The name of the section.
35874 The size of the section.
35876 The size of the overall executable to download.
35880 At the end, a summary is printed.
35882 @subsubheading @value{GDBN} Command
35884 The corresponding @value{GDBN} command is @samp{load}.
35886 @subsubheading Example
35888 Note: each status message appears on a single line. Here the messages
35889 have been broken down so that they can fit onto a page.
35894 +download,@{section=".text",section-size="6668",total-size="9880"@}
35895 +download,@{section=".text",section-sent="512",section-size="6668",
35896 total-sent="512",total-size="9880"@}
35897 +download,@{section=".text",section-sent="1024",section-size="6668",
35898 total-sent="1024",total-size="9880"@}
35899 +download,@{section=".text",section-sent="1536",section-size="6668",
35900 total-sent="1536",total-size="9880"@}
35901 +download,@{section=".text",section-sent="2048",section-size="6668",
35902 total-sent="2048",total-size="9880"@}
35903 +download,@{section=".text",section-sent="2560",section-size="6668",
35904 total-sent="2560",total-size="9880"@}
35905 +download,@{section=".text",section-sent="3072",section-size="6668",
35906 total-sent="3072",total-size="9880"@}
35907 +download,@{section=".text",section-sent="3584",section-size="6668",
35908 total-sent="3584",total-size="9880"@}
35909 +download,@{section=".text",section-sent="4096",section-size="6668",
35910 total-sent="4096",total-size="9880"@}
35911 +download,@{section=".text",section-sent="4608",section-size="6668",
35912 total-sent="4608",total-size="9880"@}
35913 +download,@{section=".text",section-sent="5120",section-size="6668",
35914 total-sent="5120",total-size="9880"@}
35915 +download,@{section=".text",section-sent="5632",section-size="6668",
35916 total-sent="5632",total-size="9880"@}
35917 +download,@{section=".text",section-sent="6144",section-size="6668",
35918 total-sent="6144",total-size="9880"@}
35919 +download,@{section=".text",section-sent="6656",section-size="6668",
35920 total-sent="6656",total-size="9880"@}
35921 +download,@{section=".init",section-size="28",total-size="9880"@}
35922 +download,@{section=".fini",section-size="28",total-size="9880"@}
35923 +download,@{section=".data",section-size="3156",total-size="9880"@}
35924 +download,@{section=".data",section-sent="512",section-size="3156",
35925 total-sent="7236",total-size="9880"@}
35926 +download,@{section=".data",section-sent="1024",section-size="3156",
35927 total-sent="7748",total-size="9880"@}
35928 +download,@{section=".data",section-sent="1536",section-size="3156",
35929 total-sent="8260",total-size="9880"@}
35930 +download,@{section=".data",section-sent="2048",section-size="3156",
35931 total-sent="8772",total-size="9880"@}
35932 +download,@{section=".data",section-sent="2560",section-size="3156",
35933 total-sent="9284",total-size="9880"@}
35934 +download,@{section=".data",section-sent="3072",section-size="3156",
35935 total-sent="9796",total-size="9880"@}
35936 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35943 @subheading The @code{-target-exec-status} Command
35944 @findex -target-exec-status
35946 @subsubheading Synopsis
35949 -target-exec-status
35952 Provide information on the state of the target (whether it is running or
35953 not, for instance).
35955 @subsubheading @value{GDBN} Command
35957 There's no equivalent @value{GDBN} command.
35959 @subsubheading Example
35963 @subheading The @code{-target-list-available-targets} Command
35964 @findex -target-list-available-targets
35966 @subsubheading Synopsis
35969 -target-list-available-targets
35972 List the possible targets to connect to.
35974 @subsubheading @value{GDBN} Command
35976 The corresponding @value{GDBN} command is @samp{help target}.
35978 @subsubheading Example
35982 @subheading The @code{-target-list-current-targets} Command
35983 @findex -target-list-current-targets
35985 @subsubheading Synopsis
35988 -target-list-current-targets
35991 Describe the current target.
35993 @subsubheading @value{GDBN} Command
35995 The corresponding information is printed by @samp{info file} (among
35998 @subsubheading Example
36002 @subheading The @code{-target-list-parameters} Command
36003 @findex -target-list-parameters
36005 @subsubheading Synopsis
36008 -target-list-parameters
36014 @subsubheading @value{GDBN} Command
36018 @subsubheading Example
36021 @subheading The @code{-target-flash-erase} Command
36022 @findex -target-flash-erase
36024 @subsubheading Synopsis
36027 -target-flash-erase
36030 Erases all known flash memory regions on the target.
36032 The corresponding @value{GDBN} command is @samp{flash-erase}.
36034 The output is a list of flash regions that have been erased, with starting
36035 addresses and memory region sizes.
36039 -target-flash-erase
36040 ^done,erased-regions=@{address="0x0",size="0x40000"@}
36044 @subheading The @code{-target-select} Command
36045 @findex -target-select
36047 @subsubheading Synopsis
36050 -target-select @var{type} @var{parameters @dots{}}
36053 Connect @value{GDBN} to the remote target. This command takes two args:
36057 The type of target, for instance @samp{remote}, etc.
36058 @item @var{parameters}
36059 Device names, host names and the like. @xref{Target Commands, ,
36060 Commands for Managing Targets}, for more details.
36063 The output is a connection notification, followed by the address at
36064 which the target program is, in the following form:
36067 ^connected,addr="@var{address}",func="@var{function name}",
36068 args=[@var{arg list}]
36071 @subsubheading @value{GDBN} Command
36073 The corresponding @value{GDBN} command is @samp{target}.
36075 @subsubheading Example
36079 -target-select remote /dev/ttya
36080 ^connected,addr="0xfe00a300",func="??",args=[]
36084 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36085 @node GDB/MI File Transfer Commands
36086 @section @sc{gdb/mi} File Transfer Commands
36089 @subheading The @code{-target-file-put} Command
36090 @findex -target-file-put
36092 @subsubheading Synopsis
36095 -target-file-put @var{hostfile} @var{targetfile}
36098 Copy file @var{hostfile} from the host system (the machine running
36099 @value{GDBN}) to @var{targetfile} on the target system.
36101 @subsubheading @value{GDBN} Command
36103 The corresponding @value{GDBN} command is @samp{remote put}.
36105 @subsubheading Example
36109 -target-file-put localfile remotefile
36115 @subheading The @code{-target-file-get} Command
36116 @findex -target-file-get
36118 @subsubheading Synopsis
36121 -target-file-get @var{targetfile} @var{hostfile}
36124 Copy file @var{targetfile} from the target system to @var{hostfile}
36125 on the host system.
36127 @subsubheading @value{GDBN} Command
36129 The corresponding @value{GDBN} command is @samp{remote get}.
36131 @subsubheading Example
36135 -target-file-get remotefile localfile
36141 @subheading The @code{-target-file-delete} Command
36142 @findex -target-file-delete
36144 @subsubheading Synopsis
36147 -target-file-delete @var{targetfile}
36150 Delete @var{targetfile} from the target system.
36152 @subsubheading @value{GDBN} Command
36154 The corresponding @value{GDBN} command is @samp{remote delete}.
36156 @subsubheading Example
36160 -target-file-delete remotefile
36166 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36167 @node GDB/MI Ada Exceptions Commands
36168 @section Ada Exceptions @sc{gdb/mi} Commands
36170 @subheading The @code{-info-ada-exceptions} Command
36171 @findex -info-ada-exceptions
36173 @subsubheading Synopsis
36176 -info-ada-exceptions [ @var{regexp}]
36179 List all Ada exceptions defined within the program being debugged.
36180 With a regular expression @var{regexp}, only those exceptions whose
36181 names match @var{regexp} are listed.
36183 @subsubheading @value{GDBN} Command
36185 The corresponding @value{GDBN} command is @samp{info exceptions}.
36187 @subsubheading Result
36189 The result is a table of Ada exceptions. The following columns are
36190 defined for each exception:
36194 The name of the exception.
36197 The address of the exception.
36201 @subsubheading Example
36204 -info-ada-exceptions aint
36205 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
36206 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
36207 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
36208 body=[@{name="constraint_error",address="0x0000000000613da0"@},
36209 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
36212 @subheading Catching Ada Exceptions
36214 The commands describing how to ask @value{GDBN} to stop when a program
36215 raises an exception are described at @ref{Ada Exception GDB/MI
36216 Catchpoint Commands}.
36219 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36220 @node GDB/MI Support Commands
36221 @section @sc{gdb/mi} Support Commands
36223 Since new commands and features get regularly added to @sc{gdb/mi},
36224 some commands are available to help front-ends query the debugger
36225 about support for these capabilities. Similarly, it is also possible
36226 to query @value{GDBN} about target support of certain features.
36228 @subheading The @code{-info-gdb-mi-command} Command
36229 @cindex @code{-info-gdb-mi-command}
36230 @findex -info-gdb-mi-command
36232 @subsubheading Synopsis
36235 -info-gdb-mi-command @var{cmd_name}
36238 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
36240 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
36241 is technically not part of the command name (@pxref{GDB/MI Input
36242 Syntax}), and thus should be omitted in @var{cmd_name}. However,
36243 for ease of use, this command also accepts the form with the leading
36246 @subsubheading @value{GDBN} Command
36248 There is no corresponding @value{GDBN} command.
36250 @subsubheading Result
36252 The result is a tuple. There is currently only one field:
36256 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
36257 @code{"false"} otherwise.
36261 @subsubheading Example
36263 Here is an example where the @sc{gdb/mi} command does not exist:
36266 -info-gdb-mi-command unsupported-command
36267 ^done,command=@{exists="false"@}
36271 And here is an example where the @sc{gdb/mi} command is known
36275 -info-gdb-mi-command symbol-list-lines
36276 ^done,command=@{exists="true"@}
36279 @subheading The @code{-list-features} Command
36280 @findex -list-features
36281 @cindex supported @sc{gdb/mi} features, list
36283 Returns a list of particular features of the MI protocol that
36284 this version of gdb implements. A feature can be a command,
36285 or a new field in an output of some command, or even an
36286 important bugfix. While a frontend can sometimes detect presence
36287 of a feature at runtime, it is easier to perform detection at debugger
36290 The command returns a list of strings, with each string naming an
36291 available feature. Each returned string is just a name, it does not
36292 have any internal structure. The list of possible feature names
36298 (gdb) -list-features
36299 ^done,result=["feature1","feature2"]
36302 The current list of features is:
36305 @item frozen-varobjs
36306 Indicates support for the @code{-var-set-frozen} command, as well
36307 as possible presence of the @code{frozen} field in the output
36308 of @code{-varobj-create}.
36309 @item pending-breakpoints
36310 Indicates support for the @option{-f} option to the @code{-break-insert}
36313 Indicates Python scripting support, Python-based
36314 pretty-printing commands, and possible presence of the
36315 @samp{display_hint} field in the output of @code{-var-list-children}
36317 Indicates support for the @code{-thread-info} command.
36318 @item data-read-memory-bytes
36319 Indicates support for the @code{-data-read-memory-bytes} and the
36320 @code{-data-write-memory-bytes} commands.
36321 @item breakpoint-notifications
36322 Indicates that changes to breakpoints and breakpoints created via the
36323 CLI will be announced via async records.
36324 @item ada-task-info
36325 Indicates support for the @code{-ada-task-info} command.
36326 @item language-option
36327 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36328 option (@pxref{Context management}).
36329 @item info-gdb-mi-command
36330 Indicates support for the @code{-info-gdb-mi-command} command.
36331 @item undefined-command-error-code
36332 Indicates support for the "undefined-command" error code in error result
36333 records, produced when trying to execute an undefined @sc{gdb/mi} command
36334 (@pxref{GDB/MI Result Records}).
36335 @item exec-run-start-option
36336 Indicates that the @code{-exec-run} command supports the @option{--start}
36337 option (@pxref{GDB/MI Program Execution}).
36338 @item data-disassemble-a-option
36339 Indicates that the @code{-data-disassemble} command supports the @option{-a}
36340 option (@pxref{GDB/MI Data Manipulation}).
36343 @subheading The @code{-list-target-features} Command
36344 @findex -list-target-features
36346 Returns a list of particular features that are supported by the
36347 target. Those features affect the permitted MI commands, but
36348 unlike the features reported by the @code{-list-features} command, the
36349 features depend on which target GDB is using at the moment. Whenever
36350 a target can change, due to commands such as @code{-target-select},
36351 @code{-target-attach} or @code{-exec-run}, the list of target features
36352 may change, and the frontend should obtain it again.
36356 (gdb) -list-target-features
36357 ^done,result=["async"]
36360 The current list of features is:
36364 Indicates that the target is capable of asynchronous command
36365 execution, which means that @value{GDBN} will accept further commands
36366 while the target is running.
36369 Indicates that the target is capable of reverse execution.
36370 @xref{Reverse Execution}, for more information.
36374 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36375 @node GDB/MI Miscellaneous Commands
36376 @section Miscellaneous @sc{gdb/mi} Commands
36378 @c @subheading -gdb-complete
36380 @subheading The @code{-gdb-exit} Command
36383 @subsubheading Synopsis
36389 Exit @value{GDBN} immediately.
36391 @subsubheading @value{GDBN} Command
36393 Approximately corresponds to @samp{quit}.
36395 @subsubheading Example
36405 @subheading The @code{-exec-abort} Command
36406 @findex -exec-abort
36408 @subsubheading Synopsis
36414 Kill the inferior running program.
36416 @subsubheading @value{GDBN} Command
36418 The corresponding @value{GDBN} command is @samp{kill}.
36420 @subsubheading Example
36425 @subheading The @code{-gdb-set} Command
36428 @subsubheading Synopsis
36434 Set an internal @value{GDBN} variable.
36435 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36437 @subsubheading @value{GDBN} Command
36439 The corresponding @value{GDBN} command is @samp{set}.
36441 @subsubheading Example
36451 @subheading The @code{-gdb-show} Command
36454 @subsubheading Synopsis
36460 Show the current value of a @value{GDBN} variable.
36462 @subsubheading @value{GDBN} Command
36464 The corresponding @value{GDBN} command is @samp{show}.
36466 @subsubheading Example
36475 @c @subheading -gdb-source
36478 @subheading The @code{-gdb-version} Command
36479 @findex -gdb-version
36481 @subsubheading Synopsis
36487 Show version information for @value{GDBN}. Used mostly in testing.
36489 @subsubheading @value{GDBN} Command
36491 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36492 default shows this information when you start an interactive session.
36494 @subsubheading Example
36496 @c This example modifies the actual output from GDB to avoid overfull
36502 ~Copyright 2000 Free Software Foundation, Inc.
36503 ~GDB is free software, covered by the GNU General Public License, and
36504 ~you are welcome to change it and/or distribute copies of it under
36505 ~ certain conditions.
36506 ~Type "show copying" to see the conditions.
36507 ~There is absolutely no warranty for GDB. Type "show warranty" for
36509 ~This GDB was configured as
36510 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36515 @subheading The @code{-list-thread-groups} Command
36516 @findex -list-thread-groups
36518 @subheading Synopsis
36521 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
36524 Lists thread groups (@pxref{Thread groups}). When a single thread
36525 group is passed as the argument, lists the children of that group.
36526 When several thread group are passed, lists information about those
36527 thread groups. Without any parameters, lists information about all
36528 top-level thread groups.
36530 Normally, thread groups that are being debugged are reported.
36531 With the @samp{--available} option, @value{GDBN} reports thread groups
36532 available on the target.
36534 The output of this command may have either a @samp{threads} result or
36535 a @samp{groups} result. The @samp{thread} result has a list of tuples
36536 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36537 Information}). The @samp{groups} result has a list of tuples as value,
36538 each tuple describing a thread group. If top-level groups are
36539 requested (that is, no parameter is passed), or when several groups
36540 are passed, the output always has a @samp{groups} result. The format
36541 of the @samp{group} result is described below.
36543 To reduce the number of roundtrips it's possible to list thread groups
36544 together with their children, by passing the @samp{--recurse} option
36545 and the recursion depth. Presently, only recursion depth of 1 is
36546 permitted. If this option is present, then every reported thread group
36547 will also include its children, either as @samp{group} or
36548 @samp{threads} field.
36550 In general, any combination of option and parameters is permitted, with
36551 the following caveats:
36555 When a single thread group is passed, the output will typically
36556 be the @samp{threads} result. Because threads may not contain
36557 anything, the @samp{recurse} option will be ignored.
36560 When the @samp{--available} option is passed, limited information may
36561 be available. In particular, the list of threads of a process might
36562 be inaccessible. Further, specifying specific thread groups might
36563 not give any performance advantage over listing all thread groups.
36564 The frontend should assume that @samp{-list-thread-groups --available}
36565 is always an expensive operation and cache the results.
36569 The @samp{groups} result is a list of tuples, where each tuple may
36570 have the following fields:
36574 Identifier of the thread group. This field is always present.
36575 The identifier is an opaque string; frontends should not try to
36576 convert it to an integer, even though it might look like one.
36579 The type of the thread group. At present, only @samp{process} is a
36583 The target-specific process identifier. This field is only present
36584 for thread groups of type @samp{process} and only if the process exists.
36587 The exit code of this group's last exited thread, formatted in octal.
36588 This field is only present for thread groups of type @samp{process} and
36589 only if the process is not running.
36592 The number of children this thread group has. This field may be
36593 absent for an available thread group.
36596 This field has a list of tuples as value, each tuple describing a
36597 thread. It may be present if the @samp{--recurse} option is
36598 specified, and it's actually possible to obtain the threads.
36601 This field is a list of integers, each identifying a core that one
36602 thread of the group is running on. This field may be absent if
36603 such information is not available.
36606 The name of the executable file that corresponds to this thread group.
36607 The field is only present for thread groups of type @samp{process},
36608 and only if there is a corresponding executable file.
36612 @subheading Example
36616 -list-thread-groups
36617 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36618 -list-thread-groups 17
36619 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36620 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36621 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36622 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
36623 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
36624 -list-thread-groups --available
36625 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36626 -list-thread-groups --available --recurse 1
36627 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36628 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36629 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36630 -list-thread-groups --available --recurse 1 17 18
36631 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36632 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36633 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
36636 @subheading The @code{-info-os} Command
36639 @subsubheading Synopsis
36642 -info-os [ @var{type} ]
36645 If no argument is supplied, the command returns a table of available
36646 operating-system-specific information types. If one of these types is
36647 supplied as an argument @var{type}, then the command returns a table
36648 of data of that type.
36650 The types of information available depend on the target operating
36653 @subsubheading @value{GDBN} Command
36655 The corresponding @value{GDBN} command is @samp{info os}.
36657 @subsubheading Example
36659 When run on a @sc{gnu}/Linux system, the output will look something
36665 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36666 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36667 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36668 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36669 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36671 item=@{col0="files",col1="Listing of all file descriptors",
36672 col2="File descriptors"@},
36673 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36674 col2="Kernel modules"@},
36675 item=@{col0="msg",col1="Listing of all message queues",
36676 col2="Message queues"@},
36677 item=@{col0="processes",col1="Listing of all processes",
36678 col2="Processes"@},
36679 item=@{col0="procgroups",col1="Listing of all process groups",
36680 col2="Process groups"@},
36681 item=@{col0="semaphores",col1="Listing of all semaphores",
36682 col2="Semaphores"@},
36683 item=@{col0="shm",col1="Listing of all shared-memory regions",
36684 col2="Shared-memory regions"@},
36685 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36687 item=@{col0="threads",col1="Listing of all threads",
36691 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36692 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36693 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36694 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36695 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36696 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36697 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36698 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36700 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36701 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36705 (Note that the MI output here includes a @code{"Title"} column that
36706 does not appear in command-line @code{info os}; this column is useful
36707 for MI clients that want to enumerate the types of data, such as in a
36708 popup menu, but is needless clutter on the command line, and
36709 @code{info os} omits it.)
36711 @subheading The @code{-add-inferior} Command
36712 @findex -add-inferior
36714 @subheading Synopsis
36720 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
36721 inferior is not associated with any executable. Such association may
36722 be established with the @samp{-file-exec-and-symbols} command
36723 (@pxref{GDB/MI File Commands}). The command response has a single
36724 field, @samp{inferior}, whose value is the identifier of the
36725 thread group corresponding to the new inferior.
36727 @subheading Example
36732 ^done,inferior="i3"
36735 @subheading The @code{-interpreter-exec} Command
36736 @findex -interpreter-exec
36738 @subheading Synopsis
36741 -interpreter-exec @var{interpreter} @var{command}
36743 @anchor{-interpreter-exec}
36745 Execute the specified @var{command} in the given @var{interpreter}.
36747 @subheading @value{GDBN} Command
36749 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36751 @subheading Example
36755 -interpreter-exec console "break main"
36756 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36757 &"During symbol reading, bad structure-type format.\n"
36758 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36763 @subheading The @code{-inferior-tty-set} Command
36764 @findex -inferior-tty-set
36766 @subheading Synopsis
36769 -inferior-tty-set /dev/pts/1
36772 Set terminal for future runs of the program being debugged.
36774 @subheading @value{GDBN} Command
36776 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36778 @subheading Example
36782 -inferior-tty-set /dev/pts/1
36787 @subheading The @code{-inferior-tty-show} Command
36788 @findex -inferior-tty-show
36790 @subheading Synopsis
36796 Show terminal for future runs of program being debugged.
36798 @subheading @value{GDBN} Command
36800 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36802 @subheading Example
36806 -inferior-tty-set /dev/pts/1
36810 ^done,inferior_tty_terminal="/dev/pts/1"
36814 @subheading The @code{-enable-timings} Command
36815 @findex -enable-timings
36817 @subheading Synopsis
36820 -enable-timings [yes | no]
36823 Toggle the printing of the wallclock, user and system times for an MI
36824 command as a field in its output. This command is to help frontend
36825 developers optimize the performance of their code. No argument is
36826 equivalent to @samp{yes}.
36828 @subheading @value{GDBN} Command
36832 @subheading Example
36840 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36841 addr="0x080484ed",func="main",file="myprog.c",
36842 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36844 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36852 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36853 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36854 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36855 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36859 @subheading The @code{-complete} Command
36862 @subheading Synopsis
36865 -complete @var{command}
36868 Show a list of completions for partially typed CLI @var{command}.
36870 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36871 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36872 because @value{GDBN} is used remotely via a SSH connection.
36876 The result consists of two or three fields:
36880 This field contains the completed @var{command}. If @var{command}
36881 has no known completions, this field is omitted.
36884 This field contains a (possibly empty) array of matches. It is always present.
36886 @item max_completions_reached
36887 This field contains @code{1} if number of known completions is above
36888 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36889 @code{0}. It is always present.
36893 @subheading @value{GDBN} Command
36895 The corresponding @value{GDBN} command is @samp{complete}.
36897 @subheading Example
36902 ^done,completion="break",
36903 matches=["break","break-range"],
36904 max_completions_reached="0"
36907 ^done,completion="b ma",
36908 matches=["b madvise","b main"],max_completions_reached="0"
36910 -complete "b push_b"
36911 ^done,completion="b push_back(",
36913 "b A::push_back(void*)",
36914 "b std::string::push_back(char)",
36915 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36916 max_completions_reached="0"
36918 -complete "nonexist"
36919 ^done,matches=[],max_completions_reached="0"
36925 @chapter @value{GDBN} Annotations
36927 This chapter describes annotations in @value{GDBN}. Annotations were
36928 designed to interface @value{GDBN} to graphical user interfaces or other
36929 similar programs which want to interact with @value{GDBN} at a
36930 relatively high level.
36932 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36936 This is Edition @value{EDITION}, @value{DATE}.
36940 * Annotations Overview:: What annotations are; the general syntax.
36941 * Server Prefix:: Issuing a command without affecting user state.
36942 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36943 * Errors:: Annotations for error messages.
36944 * Invalidation:: Some annotations describe things now invalid.
36945 * Annotations for Running::
36946 Whether the program is running, how it stopped, etc.
36947 * Source Annotations:: Annotations describing source code.
36950 @node Annotations Overview
36951 @section What is an Annotation?
36952 @cindex annotations
36954 Annotations start with a newline character, two @samp{control-z}
36955 characters, and the name of the annotation. If there is no additional
36956 information associated with this annotation, the name of the annotation
36957 is followed immediately by a newline. If there is additional
36958 information, the name of the annotation is followed by a space, the
36959 additional information, and a newline. The additional information
36960 cannot contain newline characters.
36962 Any output not beginning with a newline and two @samp{control-z}
36963 characters denotes literal output from @value{GDBN}. Currently there is
36964 no need for @value{GDBN} to output a newline followed by two
36965 @samp{control-z} characters, but if there was such a need, the
36966 annotations could be extended with an @samp{escape} annotation which
36967 means those three characters as output.
36969 The annotation @var{level}, which is specified using the
36970 @option{--annotate} command line option (@pxref{Mode Options}), controls
36971 how much information @value{GDBN} prints together with its prompt,
36972 values of expressions, source lines, and other types of output. Level 0
36973 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36974 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36975 for programs that control @value{GDBN}, and level 2 annotations have
36976 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36977 Interface, annotate, GDB's Obsolete Annotations}).
36980 @kindex set annotate
36981 @item set annotate @var{level}
36982 The @value{GDBN} command @code{set annotate} sets the level of
36983 annotations to the specified @var{level}.
36985 @item show annotate
36986 @kindex show annotate
36987 Show the current annotation level.
36990 This chapter describes level 3 annotations.
36992 A simple example of starting up @value{GDBN} with annotations is:
36995 $ @kbd{gdb --annotate=3}
36997 Copyright 2003 Free Software Foundation, Inc.
36998 GDB is free software, covered by the GNU General Public License,
36999 and you are welcome to change it and/or distribute copies of it
37000 under certain conditions.
37001 Type "show copying" to see the conditions.
37002 There is absolutely no warranty for GDB. Type "show warranty"
37004 This GDB was configured as "i386-pc-linux-gnu"
37015 Here @samp{quit} is input to @value{GDBN}; the rest is output from
37016 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
37017 denotes a @samp{control-z} character) are annotations; the rest is
37018 output from @value{GDBN}.
37020 @node Server Prefix
37021 @section The Server Prefix
37022 @cindex server prefix
37024 If you prefix a command with @samp{server } then it will not affect
37025 the command history, nor will it affect @value{GDBN}'s notion of which
37026 command to repeat if @key{RET} is pressed on a line by itself. This
37027 means that commands can be run behind a user's back by a front-end in
37028 a transparent manner.
37030 The @code{server } prefix does not affect the recording of values into
37031 the value history; to print a value without recording it into the
37032 value history, use the @code{output} command instead of the
37033 @code{print} command.
37035 Using this prefix also disables confirmation requests
37036 (@pxref{confirmation requests}).
37039 @section Annotation for @value{GDBN} Input
37041 @cindex annotations for prompts
37042 When @value{GDBN} prompts for input, it annotates this fact so it is possible
37043 to know when to send output, when the output from a given command is
37046 Different kinds of input each have a different @dfn{input type}. Each
37047 input type has three annotations: a @code{pre-} annotation, which
37048 denotes the beginning of any prompt which is being output, a plain
37049 annotation, which denotes the end of the prompt, and then a @code{post-}
37050 annotation which denotes the end of any echo which may (or may not) be
37051 associated with the input. For example, the @code{prompt} input type
37052 features the following annotations:
37060 The input types are
37063 @findex pre-prompt annotation
37064 @findex prompt annotation
37065 @findex post-prompt annotation
37067 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
37069 @findex pre-commands annotation
37070 @findex commands annotation
37071 @findex post-commands annotation
37073 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
37074 command. The annotations are repeated for each command which is input.
37076 @findex pre-overload-choice annotation
37077 @findex overload-choice annotation
37078 @findex post-overload-choice annotation
37079 @item overload-choice
37080 When @value{GDBN} wants the user to select between various overloaded functions.
37082 @findex pre-query annotation
37083 @findex query annotation
37084 @findex post-query annotation
37086 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
37088 @findex pre-prompt-for-continue annotation
37089 @findex prompt-for-continue annotation
37090 @findex post-prompt-for-continue annotation
37091 @item prompt-for-continue
37092 When @value{GDBN} is asking the user to press return to continue. Note: Don't
37093 expect this to work well; instead use @code{set height 0} to disable
37094 prompting. This is because the counting of lines is buggy in the
37095 presence of annotations.
37100 @cindex annotations for errors, warnings and interrupts
37102 @findex quit annotation
37107 This annotation occurs right before @value{GDBN} responds to an interrupt.
37109 @findex error annotation
37114 This annotation occurs right before @value{GDBN} responds to an error.
37116 Quit and error annotations indicate that any annotations which @value{GDBN} was
37117 in the middle of may end abruptly. For example, if a
37118 @code{value-history-begin} annotation is followed by a @code{error}, one
37119 cannot expect to receive the matching @code{value-history-end}. One
37120 cannot expect not to receive it either, however; an error annotation
37121 does not necessarily mean that @value{GDBN} is immediately returning all the way
37124 @findex error-begin annotation
37125 A quit or error annotation may be preceded by
37131 Any output between that and the quit or error annotation is the error
37134 Warning messages are not yet annotated.
37135 @c If we want to change that, need to fix warning(), type_error(),
37136 @c range_error(), and possibly other places.
37139 @section Invalidation Notices
37141 @cindex annotations for invalidation messages
37142 The following annotations say that certain pieces of state may have
37146 @findex frames-invalid annotation
37147 @item ^Z^Zframes-invalid
37149 The frames (for example, output from the @code{backtrace} command) may
37152 @findex breakpoints-invalid annotation
37153 @item ^Z^Zbreakpoints-invalid
37155 The breakpoints may have changed. For example, the user just added or
37156 deleted a breakpoint.
37159 @node Annotations for Running
37160 @section Running the Program
37161 @cindex annotations for running programs
37163 @findex starting annotation
37164 @findex stopping annotation
37165 When the program starts executing due to a @value{GDBN} command such as
37166 @code{step} or @code{continue},
37172 is output. When the program stops,
37178 is output. Before the @code{stopped} annotation, a variety of
37179 annotations describe how the program stopped.
37182 @findex exited annotation
37183 @item ^Z^Zexited @var{exit-status}
37184 The program exited, and @var{exit-status} is the exit status (zero for
37185 successful exit, otherwise nonzero).
37187 @findex signalled annotation
37188 @findex signal-name annotation
37189 @findex signal-name-end annotation
37190 @findex signal-string annotation
37191 @findex signal-string-end annotation
37192 @item ^Z^Zsignalled
37193 The program exited with a signal. After the @code{^Z^Zsignalled}, the
37194 annotation continues:
37200 ^Z^Zsignal-name-end
37204 ^Z^Zsignal-string-end
37209 where @var{name} is the name of the signal, such as @code{SIGILL} or
37210 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
37211 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
37212 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
37213 user's benefit and have no particular format.
37215 @findex signal annotation
37217 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
37218 just saying that the program received the signal, not that it was
37219 terminated with it.
37221 @findex breakpoint annotation
37222 @item ^Z^Zbreakpoint @var{number}
37223 The program hit breakpoint number @var{number}.
37225 @findex watchpoint annotation
37226 @item ^Z^Zwatchpoint @var{number}
37227 The program hit watchpoint number @var{number}.
37230 @node Source Annotations
37231 @section Displaying Source
37232 @cindex annotations for source display
37234 @findex source annotation
37235 The following annotation is used instead of displaying source code:
37238 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
37241 where @var{filename} is an absolute file name indicating which source
37242 file, @var{line} is the line number within that file (where 1 is the
37243 first line in the file), @var{character} is the character position
37244 within the file (where 0 is the first character in the file) (for most
37245 debug formats this will necessarily point to the beginning of a line),
37246 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
37247 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
37248 @var{addr} is the address in the target program associated with the
37249 source which is being displayed. The @var{addr} is in the form @samp{0x}
37250 followed by one or more lowercase hex digits (note that this does not
37251 depend on the language).
37253 @node JIT Interface
37254 @chapter JIT Compilation Interface
37255 @cindex just-in-time compilation
37256 @cindex JIT compilation interface
37258 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
37259 interface. A JIT compiler is a program or library that generates native
37260 executable code at runtime and executes it, usually in order to achieve good
37261 performance while maintaining platform independence.
37263 Programs that use JIT compilation are normally difficult to debug because
37264 portions of their code are generated at runtime, instead of being loaded from
37265 object files, which is where @value{GDBN} normally finds the program's symbols
37266 and debug information. In order to debug programs that use JIT compilation,
37267 @value{GDBN} has an interface that allows the program to register in-memory
37268 symbol files with @value{GDBN} at runtime.
37270 If you are using @value{GDBN} to debug a program that uses this interface, then
37271 it should work transparently so long as you have not stripped the binary. If
37272 you are developing a JIT compiler, then the interface is documented in the rest
37273 of this chapter. At this time, the only known client of this interface is the
37276 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37277 JIT compiler communicates with @value{GDBN} by writing data into a global
37278 variable and calling a function at a well-known symbol. When @value{GDBN}
37279 attaches, it reads a linked list of symbol files from the global variable to
37280 find existing code, and puts a breakpoint in the function so that it can find
37281 out about additional code.
37284 * Declarations:: Relevant C struct declarations
37285 * Registering Code:: Steps to register code
37286 * Unregistering Code:: Steps to unregister code
37287 * Custom Debug Info:: Emit debug information in a custom format
37291 @section JIT Declarations
37293 These are the relevant struct declarations that a C program should include to
37294 implement the interface:
37304 struct jit_code_entry
37306 struct jit_code_entry *next_entry;
37307 struct jit_code_entry *prev_entry;
37308 const char *symfile_addr;
37309 uint64_t symfile_size;
37312 struct jit_descriptor
37315 /* This type should be jit_actions_t, but we use uint32_t
37316 to be explicit about the bitwidth. */
37317 uint32_t action_flag;
37318 struct jit_code_entry *relevant_entry;
37319 struct jit_code_entry *first_entry;
37322 /* GDB puts a breakpoint in this function. */
37323 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37325 /* Make sure to specify the version statically, because the
37326 debugger may check the version before we can set it. */
37327 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37330 If the JIT is multi-threaded, then it is important that the JIT synchronize any
37331 modifications to this global data properly, which can easily be done by putting
37332 a global mutex around modifications to these structures.
37334 @node Registering Code
37335 @section Registering Code
37337 To register code with @value{GDBN}, the JIT should follow this protocol:
37341 Generate an object file in memory with symbols and other desired debug
37342 information. The file must include the virtual addresses of the sections.
37345 Create a code entry for the file, which gives the start and size of the symbol
37349 Add it to the linked list in the JIT descriptor.
37352 Point the relevant_entry field of the descriptor at the entry.
37355 Set @code{action_flag} to @code{JIT_REGISTER} and call
37356 @code{__jit_debug_register_code}.
37359 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37360 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
37361 new code. However, the linked list must still be maintained in order to allow
37362 @value{GDBN} to attach to a running process and still find the symbol files.
37364 @node Unregistering Code
37365 @section Unregistering Code
37367 If code is freed, then the JIT should use the following protocol:
37371 Remove the code entry corresponding to the code from the linked list.
37374 Point the @code{relevant_entry} field of the descriptor at the code entry.
37377 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37378 @code{__jit_debug_register_code}.
37381 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37382 and the JIT will leak the memory used for the associated symbol files.
37384 @node Custom Debug Info
37385 @section Custom Debug Info
37386 @cindex custom JIT debug info
37387 @cindex JIT debug info reader
37389 Generating debug information in platform-native file formats (like ELF
37390 or COFF) may be an overkill for JIT compilers; especially if all the
37391 debug info is used for is displaying a meaningful backtrace. The
37392 issue can be resolved by having the JIT writers decide on a debug info
37393 format and also provide a reader that parses the debug info generated
37394 by the JIT compiler. This section gives a brief overview on writing
37395 such a parser. More specific details can be found in the source file
37396 @file{gdb/jit-reader.in}, which is also installed as a header at
37397 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37399 The reader is implemented as a shared object (so this functionality is
37400 not available on platforms which don't allow loading shared objects at
37401 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37402 @code{jit-reader-unload} are provided, to be used to load and unload
37403 the readers from a preconfigured directory. Once loaded, the shared
37404 object is used the parse the debug information emitted by the JIT
37408 * Using JIT Debug Info Readers:: How to use supplied readers correctly
37409 * Writing JIT Debug Info Readers:: Creating a debug-info reader
37412 @node Using JIT Debug Info Readers
37413 @subsection Using JIT Debug Info Readers
37414 @kindex jit-reader-load
37415 @kindex jit-reader-unload
37417 Readers can be loaded and unloaded using the @code{jit-reader-load}
37418 and @code{jit-reader-unload} commands.
37421 @item jit-reader-load @var{reader}
37422 Load the JIT reader named @var{reader}, which is a shared
37423 object specified as either an absolute or a relative file name. In
37424 the latter case, @value{GDBN} will try to load the reader from a
37425 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37426 system (here @var{libdir} is the system library directory, often
37427 @file{/usr/local/lib}).
37429 Only one reader can be active at a time; trying to load a second
37430 reader when one is already loaded will result in @value{GDBN}
37431 reporting an error. A new JIT reader can be loaded by first unloading
37432 the current one using @code{jit-reader-unload} and then invoking
37433 @code{jit-reader-load}.
37435 @item jit-reader-unload
37436 Unload the currently loaded JIT reader.
37440 @node Writing JIT Debug Info Readers
37441 @subsection Writing JIT Debug Info Readers
37442 @cindex writing JIT debug info readers
37444 As mentioned, a reader is essentially a shared object conforming to a
37445 certain ABI. This ABI is described in @file{jit-reader.h}.
37447 @file{jit-reader.h} defines the structures, macros and functions
37448 required to write a reader. It is installed (along with
37449 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37450 the system include directory.
37452 Readers need to be released under a GPL compatible license. A reader
37453 can be declared as released under such a license by placing the macro
37454 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37456 The entry point for readers is the symbol @code{gdb_init_reader},
37457 which is expected to be a function with the prototype
37459 @findex gdb_init_reader
37461 extern struct gdb_reader_funcs *gdb_init_reader (void);
37464 @cindex @code{struct gdb_reader_funcs}
37466 @code{struct gdb_reader_funcs} contains a set of pointers to callback
37467 functions. These functions are executed to read the debug info
37468 generated by the JIT compiler (@code{read}), to unwind stack frames
37469 (@code{unwind}) and to create canonical frame IDs
37470 (@code{get_frame_id}). It also has a callback that is called when the
37471 reader is being unloaded (@code{destroy}). The struct looks like this
37474 struct gdb_reader_funcs
37476 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37477 int reader_version;
37479 /* For use by the reader. */
37482 gdb_read_debug_info *read;
37483 gdb_unwind_frame *unwind;
37484 gdb_get_frame_id *get_frame_id;
37485 gdb_destroy_reader *destroy;
37489 @cindex @code{struct gdb_symbol_callbacks}
37490 @cindex @code{struct gdb_unwind_callbacks}
37492 The callbacks are provided with another set of callbacks by
37493 @value{GDBN} to do their job. For @code{read}, these callbacks are
37494 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37495 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37496 @code{struct gdb_symbol_callbacks} has callbacks to create new object
37497 files and new symbol tables inside those object files. @code{struct
37498 gdb_unwind_callbacks} has callbacks to read registers off the current
37499 frame and to write out the values of the registers in the previous
37500 frame. Both have a callback (@code{target_read}) to read bytes off the
37501 target's address space.
37503 @node In-Process Agent
37504 @chapter In-Process Agent
37505 @cindex debugging agent
37506 The traditional debugging model is conceptually low-speed, but works fine,
37507 because most bugs can be reproduced in debugging-mode execution. However,
37508 as multi-core or many-core processors are becoming mainstream, and
37509 multi-threaded programs become more and more popular, there should be more
37510 and more bugs that only manifest themselves at normal-mode execution, for
37511 example, thread races, because debugger's interference with the program's
37512 timing may conceal the bugs. On the other hand, in some applications,
37513 it is not feasible for the debugger to interrupt the program's execution
37514 long enough for the developer to learn anything helpful about its behavior.
37515 If the program's correctness depends on its real-time behavior, delays
37516 introduced by a debugger might cause the program to fail, even when the
37517 code itself is correct. It is useful to be able to observe the program's
37518 behavior without interrupting it.
37520 Therefore, traditional debugging model is too intrusive to reproduce
37521 some bugs. In order to reduce the interference with the program, we can
37522 reduce the number of operations performed by debugger. The
37523 @dfn{In-Process Agent}, a shared library, is running within the same
37524 process with inferior, and is able to perform some debugging operations
37525 itself. As a result, debugger is only involved when necessary, and
37526 performance of debugging can be improved accordingly. Note that
37527 interference with program can be reduced but can't be removed completely,
37528 because the in-process agent will still stop or slow down the program.
37530 The in-process agent can interpret and execute Agent Expressions
37531 (@pxref{Agent Expressions}) during performing debugging operations. The
37532 agent expressions can be used for different purposes, such as collecting
37533 data in tracepoints, and condition evaluation in breakpoints.
37535 @anchor{Control Agent}
37536 You can control whether the in-process agent is used as an aid for
37537 debugging with the following commands:
37540 @kindex set agent on
37542 Causes the in-process agent to perform some operations on behalf of the
37543 debugger. Just which operations requested by the user will be done
37544 by the in-process agent depends on the its capabilities. For example,
37545 if you request to evaluate breakpoint conditions in the in-process agent,
37546 and the in-process agent has such capability as well, then breakpoint
37547 conditions will be evaluated in the in-process agent.
37549 @kindex set agent off
37550 @item set agent off
37551 Disables execution of debugging operations by the in-process agent. All
37552 of the operations will be performed by @value{GDBN}.
37556 Display the current setting of execution of debugging operations by
37557 the in-process agent.
37561 * In-Process Agent Protocol::
37564 @node In-Process Agent Protocol
37565 @section In-Process Agent Protocol
37566 @cindex in-process agent protocol
37568 The in-process agent is able to communicate with both @value{GDBN} and
37569 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37570 used for communications between @value{GDBN} or GDBserver and the IPA.
37571 In general, @value{GDBN} or GDBserver sends commands
37572 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37573 in-process agent replies back with the return result of the command, or
37574 some other information. The data sent to in-process agent is composed
37575 of primitive data types, such as 4-byte or 8-byte type, and composite
37576 types, which are called objects (@pxref{IPA Protocol Objects}).
37579 * IPA Protocol Objects::
37580 * IPA Protocol Commands::
37583 @node IPA Protocol Objects
37584 @subsection IPA Protocol Objects
37585 @cindex ipa protocol objects
37587 The commands sent to and results received from agent may contain some
37588 complex data types called @dfn{objects}.
37590 The in-process agent is running on the same machine with @value{GDBN}
37591 or GDBserver, so it doesn't have to handle as much differences between
37592 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37593 However, there are still some differences of two ends in two processes:
37597 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37598 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37600 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37601 GDBserver is compiled with one, and in-process agent is compiled with
37605 Here are the IPA Protocol Objects:
37609 agent expression object. It represents an agent expression
37610 (@pxref{Agent Expressions}).
37611 @anchor{agent expression object}
37613 tracepoint action object. It represents a tracepoint action
37614 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37615 memory, static trace data and to evaluate expression.
37616 @anchor{tracepoint action object}
37618 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37619 @anchor{tracepoint object}
37623 The following table describes important attributes of each IPA protocol
37626 @multitable @columnfractions .30 .20 .50
37627 @headitem Name @tab Size @tab Description
37628 @item @emph{agent expression object} @tab @tab
37629 @item length @tab 4 @tab length of bytes code
37630 @item byte code @tab @var{length} @tab contents of byte code
37631 @item @emph{tracepoint action for collecting memory} @tab @tab
37632 @item 'M' @tab 1 @tab type of tracepoint action
37633 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37634 address of the lowest byte to collect, otherwise @var{addr} is the offset
37635 of @var{basereg} for memory collecting.
37636 @item len @tab 8 @tab length of memory for collecting
37637 @item basereg @tab 4 @tab the register number containing the starting
37638 memory address for collecting.
37639 @item @emph{tracepoint action for collecting registers} @tab @tab
37640 @item 'R' @tab 1 @tab type of tracepoint action
37641 @item @emph{tracepoint action for collecting static trace data} @tab @tab
37642 @item 'L' @tab 1 @tab type of tracepoint action
37643 @item @emph{tracepoint action for expression evaluation} @tab @tab
37644 @item 'X' @tab 1 @tab type of tracepoint action
37645 @item agent expression @tab length of @tab @ref{agent expression object}
37646 @item @emph{tracepoint object} @tab @tab
37647 @item number @tab 4 @tab number of tracepoint
37648 @item address @tab 8 @tab address of tracepoint inserted on
37649 @item type @tab 4 @tab type of tracepoint
37650 @item enabled @tab 1 @tab enable or disable of tracepoint
37651 @item step_count @tab 8 @tab step
37652 @item pass_count @tab 8 @tab pass
37653 @item numactions @tab 4 @tab number of tracepoint actions
37654 @item hit count @tab 8 @tab hit count
37655 @item trace frame usage @tab 8 @tab trace frame usage
37656 @item compiled_cond @tab 8 @tab compiled condition
37657 @item orig_size @tab 8 @tab orig size
37658 @item condition @tab 4 if condition is NULL otherwise length of
37659 @ref{agent expression object}
37660 @tab zero if condition is NULL, otherwise is
37661 @ref{agent expression object}
37662 @item actions @tab variable
37663 @tab numactions number of @ref{tracepoint action object}
37666 @node IPA Protocol Commands
37667 @subsection IPA Protocol Commands
37668 @cindex ipa protocol commands
37670 The spaces in each command are delimiters to ease reading this commands
37671 specification. They don't exist in real commands.
37675 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37676 Installs a new fast tracepoint described by @var{tracepoint_object}
37677 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
37678 head of @dfn{jumppad}, which is used to jump to data collection routine
37683 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37684 @var{target_address} is address of tracepoint in the inferior.
37685 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
37686 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37687 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37688 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37695 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37696 is about to kill inferiors.
37704 @item probe_marker_at:@var{address}
37705 Asks in-process agent to probe the marker at @var{address}.
37712 @item unprobe_marker_at:@var{address}
37713 Asks in-process agent to unprobe the marker at @var{address}.
37717 @chapter Reporting Bugs in @value{GDBN}
37718 @cindex bugs in @value{GDBN}
37719 @cindex reporting bugs in @value{GDBN}
37721 Your bug reports play an essential role in making @value{GDBN} reliable.
37723 Reporting a bug may help you by bringing a solution to your problem, or it
37724 may not. But in any case the principal function of a bug report is to help
37725 the entire community by making the next version of @value{GDBN} work better. Bug
37726 reports are your contribution to the maintenance of @value{GDBN}.
37728 In order for a bug report to serve its purpose, you must include the
37729 information that enables us to fix the bug.
37732 * Bug Criteria:: Have you found a bug?
37733 * Bug Reporting:: How to report bugs
37737 @section Have You Found a Bug?
37738 @cindex bug criteria
37740 If you are not sure whether you have found a bug, here are some guidelines:
37743 @cindex fatal signal
37744 @cindex debugger crash
37745 @cindex crash of debugger
37747 If the debugger gets a fatal signal, for any input whatever, that is a
37748 @value{GDBN} bug. Reliable debuggers never crash.
37750 @cindex error on valid input
37752 If @value{GDBN} produces an error message for valid input, that is a
37753 bug. (Note that if you're cross debugging, the problem may also be
37754 somewhere in the connection to the target.)
37756 @cindex invalid input
37758 If @value{GDBN} does not produce an error message for invalid input,
37759 that is a bug. However, you should note that your idea of
37760 ``invalid input'' might be our idea of ``an extension'' or ``support
37761 for traditional practice''.
37764 If you are an experienced user of debugging tools, your suggestions
37765 for improvement of @value{GDBN} are welcome in any case.
37768 @node Bug Reporting
37769 @section How to Report Bugs
37770 @cindex bug reports
37771 @cindex @value{GDBN} bugs, reporting
37773 A number of companies and individuals offer support for @sc{gnu} products.
37774 If you obtained @value{GDBN} from a support organization, we recommend you
37775 contact that organization first.
37777 You can find contact information for many support companies and
37778 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37780 @c should add a web page ref...
37783 @ifset BUGURL_DEFAULT
37784 In any event, we also recommend that you submit bug reports for
37785 @value{GDBN}. The preferred method is to submit them directly using
37786 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37787 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37790 @strong{Do not send bug reports to @samp{info-gdb}, or to
37791 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37792 not want to receive bug reports. Those that do have arranged to receive
37795 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37796 serves as a repeater. The mailing list and the newsgroup carry exactly
37797 the same messages. Often people think of posting bug reports to the
37798 newsgroup instead of mailing them. This appears to work, but it has one
37799 problem which can be crucial: a newsgroup posting often lacks a mail
37800 path back to the sender. Thus, if we need to ask for more information,
37801 we may be unable to reach you. For this reason, it is better to send
37802 bug reports to the mailing list.
37804 @ifclear BUGURL_DEFAULT
37805 In any event, we also recommend that you submit bug reports for
37806 @value{GDBN} to @value{BUGURL}.
37810 The fundamental principle of reporting bugs usefully is this:
37811 @strong{report all the facts}. If you are not sure whether to state a
37812 fact or leave it out, state it!
37814 Often people omit facts because they think they know what causes the
37815 problem and assume that some details do not matter. Thus, you might
37816 assume that the name of the variable you use in an example does not matter.
37817 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37818 stray memory reference which happens to fetch from the location where that
37819 name is stored in memory; perhaps, if the name were different, the contents
37820 of that location would fool the debugger into doing the right thing despite
37821 the bug. Play it safe and give a specific, complete example. That is the
37822 easiest thing for you to do, and the most helpful.
37824 Keep in mind that the purpose of a bug report is to enable us to fix the
37825 bug. It may be that the bug has been reported previously, but neither
37826 you nor we can know that unless your bug report is complete and
37829 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37830 bell?'' Those bug reports are useless, and we urge everyone to
37831 @emph{refuse to respond to them} except to chide the sender to report
37834 To enable us to fix the bug, you should include all these things:
37838 The version of @value{GDBN}. @value{GDBN} announces it if you start
37839 with no arguments; you can also print it at any time using @code{show
37842 Without this, we will not know whether there is any point in looking for
37843 the bug in the current version of @value{GDBN}.
37846 The type of machine you are using, and the operating system name and
37850 The details of the @value{GDBN} build-time configuration.
37851 @value{GDBN} shows these details if you invoke it with the
37852 @option{--configuration} command-line option, or if you type
37853 @code{show configuration} at @value{GDBN}'s prompt.
37856 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37857 ``@value{GCC}--2.8.1''.
37860 What compiler (and its version) was used to compile the program you are
37861 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37862 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37863 to get this information; for other compilers, see the documentation for
37867 The command arguments you gave the compiler to compile your example and
37868 observe the bug. For example, did you use @samp{-O}? To guarantee
37869 you will not omit something important, list them all. A copy of the
37870 Makefile (or the output from make) is sufficient.
37872 If we were to try to guess the arguments, we would probably guess wrong
37873 and then we might not encounter the bug.
37876 A complete input script, and all necessary source files, that will
37880 A description of what behavior you observe that you believe is
37881 incorrect. For example, ``It gets a fatal signal.''
37883 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37884 will certainly notice it. But if the bug is incorrect output, we might
37885 not notice unless it is glaringly wrong. You might as well not give us
37886 a chance to make a mistake.
37888 Even if the problem you experience is a fatal signal, you should still
37889 say so explicitly. Suppose something strange is going on, such as, your
37890 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37891 the C library on your system. (This has happened!) Your copy might
37892 crash and ours would not. If you told us to expect a crash, then when
37893 ours fails to crash, we would know that the bug was not happening for
37894 us. If you had not told us to expect a crash, then we would not be able
37895 to draw any conclusion from our observations.
37898 @cindex recording a session script
37899 To collect all this information, you can use a session recording program
37900 such as @command{script}, which is available on many Unix systems.
37901 Just run your @value{GDBN} session inside @command{script} and then
37902 include the @file{typescript} file with your bug report.
37904 Another way to record a @value{GDBN} session is to run @value{GDBN}
37905 inside Emacs and then save the entire buffer to a file.
37908 If you wish to suggest changes to the @value{GDBN} source, send us context
37909 diffs. If you even discuss something in the @value{GDBN} source, refer to
37910 it by context, not by line number.
37912 The line numbers in our development sources will not match those in your
37913 sources. Your line numbers would convey no useful information to us.
37917 Here are some things that are not necessary:
37921 A description of the envelope of the bug.
37923 Often people who encounter a bug spend a lot of time investigating
37924 which changes to the input file will make the bug go away and which
37925 changes will not affect it.
37927 This is often time consuming and not very useful, because the way we
37928 will find the bug is by running a single example under the debugger
37929 with breakpoints, not by pure deduction from a series of examples.
37930 We recommend that you save your time for something else.
37932 Of course, if you can find a simpler example to report @emph{instead}
37933 of the original one, that is a convenience for us. Errors in the
37934 output will be easier to spot, running under the debugger will take
37935 less time, and so on.
37937 However, simplification is not vital; if you do not want to do this,
37938 report the bug anyway and send us the entire test case you used.
37941 A patch for the bug.
37943 A patch for the bug does help us if it is a good one. But do not omit
37944 the necessary information, such as the test case, on the assumption that
37945 a patch is all we need. We might see problems with your patch and decide
37946 to fix the problem another way, or we might not understand it at all.
37948 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37949 construct an example that will make the program follow a certain path
37950 through the code. If you do not send us the example, we will not be able
37951 to construct one, so we will not be able to verify that the bug is fixed.
37953 And if we cannot understand what bug you are trying to fix, or why your
37954 patch should be an improvement, we will not install it. A test case will
37955 help us to understand.
37958 A guess about what the bug is or what it depends on.
37960 Such guesses are usually wrong. Even we cannot guess right about such
37961 things without first using the debugger to find the facts.
37964 @c The readline documentation is distributed with the readline code
37965 @c and consists of the two following files:
37968 @c Use -I with makeinfo to point to the appropriate directory,
37969 @c environment var TEXINPUTS with TeX.
37970 @ifclear SYSTEM_READLINE
37971 @include rluser.texi
37972 @include hsuser.texi
37976 @appendix In Memoriam
37978 The @value{GDBN} project mourns the loss of the following long-time
37983 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37984 to Free Software in general. Outside of @value{GDBN}, he was known in
37985 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37987 @item Michael Snyder
37988 Michael was one of the Global Maintainers of the @value{GDBN} project,
37989 with contributions recorded as early as 1996, until 2011. In addition
37990 to his day to day participation, he was a large driving force behind
37991 adding Reverse Debugging to @value{GDBN}.
37994 Beyond their technical contributions to the project, they were also
37995 enjoyable members of the Free Software Community. We will miss them.
37997 @node Formatting Documentation
37998 @appendix Formatting Documentation
38000 @cindex @value{GDBN} reference card
38001 @cindex reference card
38002 The @value{GDBN} 4 release includes an already-formatted reference card, ready
38003 for printing with PostScript or Ghostscript, in the @file{gdb}
38004 subdirectory of the main source directory@footnote{In
38005 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
38006 release.}. If you can use PostScript or Ghostscript with your printer,
38007 you can print the reference card immediately with @file{refcard.ps}.
38009 The release also includes the source for the reference card. You
38010 can format it, using @TeX{}, by typing:
38016 The @value{GDBN} reference card is designed to print in @dfn{landscape}
38017 mode on US ``letter'' size paper;
38018 that is, on a sheet 11 inches wide by 8.5 inches
38019 high. You will need to specify this form of printing as an option to
38020 your @sc{dvi} output program.
38022 @cindex documentation
38024 All the documentation for @value{GDBN} comes as part of the machine-readable
38025 distribution. The documentation is written in Texinfo format, which is
38026 a documentation system that uses a single source file to produce both
38027 on-line information and a printed manual. You can use one of the Info
38028 formatting commands to create the on-line version of the documentation
38029 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
38031 @value{GDBN} includes an already formatted copy of the on-line Info
38032 version of this manual in the @file{gdb} subdirectory. The main Info
38033 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
38034 subordinate files matching @samp{gdb.info*} in the same directory. If
38035 necessary, you can print out these files, or read them with any editor;
38036 but they are easier to read using the @code{info} subsystem in @sc{gnu}
38037 Emacs or the standalone @code{info} program, available as part of the
38038 @sc{gnu} Texinfo distribution.
38040 If you want to format these Info files yourself, you need one of the
38041 Info formatting programs, such as @code{texinfo-format-buffer} or
38044 If you have @code{makeinfo} installed, and are in the top level
38045 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
38046 version @value{GDBVN}), you can make the Info file by typing:
38053 If you want to typeset and print copies of this manual, you need @TeX{},
38054 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
38055 Texinfo definitions file.
38057 @TeX{} is a typesetting program; it does not print files directly, but
38058 produces output files called @sc{dvi} files. To print a typeset
38059 document, you need a program to print @sc{dvi} files. If your system
38060 has @TeX{} installed, chances are it has such a program. The precise
38061 command to use depends on your system; @kbd{lpr -d} is common; another
38062 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
38063 require a file name without any extension or a @samp{.dvi} extension.
38065 @TeX{} also requires a macro definitions file called
38066 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
38067 written in Texinfo format. On its own, @TeX{} cannot either read or
38068 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
38069 and is located in the @file{gdb-@var{version-number}/texinfo}
38072 If you have @TeX{} and a @sc{dvi} printer program installed, you can
38073 typeset and print this manual. First switch to the @file{gdb}
38074 subdirectory of the main source directory (for example, to
38075 @file{gdb-@value{GDBVN}/gdb}) and type:
38081 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
38083 @node Installing GDB
38084 @appendix Installing @value{GDBN}
38085 @cindex installation
38088 * Requirements:: Requirements for building @value{GDBN}
38089 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
38090 * Separate Objdir:: Compiling @value{GDBN} in another directory
38091 * Config Names:: Specifying names for hosts and targets
38092 * Configure Options:: Summary of options for configure
38093 * System-wide configuration:: Having a system-wide init file
38097 @section Requirements for Building @value{GDBN}
38098 @cindex building @value{GDBN}, requirements for
38100 Building @value{GDBN} requires various tools and packages to be available.
38101 Other packages will be used only if they are found.
38103 @heading Tools/Packages Necessary for Building @value{GDBN}
38105 @item C@t{++}11 compiler
38106 @value{GDBN} is written in C@t{++}11. It should be buildable with any
38107 recent C@t{++}11 compiler, e.g.@: GCC.
38110 @value{GDBN}'s build system relies on features only found in the GNU
38111 make program. Other variants of @code{make} will not work.
38113 @item GMP (The GNU Multiple Precision Arithmetic Library)
38114 @value{GDBN} now uses GMP to perform some of its arithmetics.
38115 This library may be included with your operating system distribution;
38116 if it is not, you can get the latest version from
38117 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
38118 you can use the @option{--with-libgmp-prefix} option to specify
38123 @heading Tools/Packages Optional for Building @value{GDBN}
38127 @value{GDBN} can use the Expat XML parsing library. This library may be
38128 included with your operating system distribution; if it is not, you
38129 can get the latest version from @url{http://expat.sourceforge.net}.
38130 The @file{configure} script will search for this library in several
38131 standard locations; if it is installed in an unusual path, you can
38132 use the @option{--with-libexpat-prefix} option to specify its location.
38138 Remote protocol memory maps (@pxref{Memory Map Format})
38140 Target descriptions (@pxref{Target Descriptions})
38142 Remote shared library lists (@xref{Library List Format},
38143 or alternatively @pxref{Library List Format for SVR4 Targets})
38145 MS-Windows shared libraries (@pxref{Shared Libraries})
38147 Traceframe info (@pxref{Traceframe Info Format})
38149 Branch trace (@pxref{Branch Trace Format},
38150 @pxref{Branch Trace Configuration Format})
38154 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
38155 default, @value{GDBN} will be compiled if the Guile libraries are
38156 installed and are found by @file{configure}. You can use the
38157 @code{--with-guile} option to request Guile, and pass either the Guile
38158 version number or the file name of the relevant @code{pkg-config}
38159 program to choose a particular version of Guile.
38162 @value{GDBN}'s features related to character sets (@pxref{Character
38163 Sets}) require a functioning @code{iconv} implementation. If you are
38164 on a GNU system, then this is provided by the GNU C Library. Some
38165 other systems also provide a working @code{iconv}.
38167 If @value{GDBN} is using the @code{iconv} program which is installed
38168 in a non-standard place, you will need to tell @value{GDBN} where to
38169 find it. This is done with @option{--with-iconv-bin} which specifies
38170 the directory that contains the @code{iconv} program. This program is
38171 run in order to make a list of the available character sets.
38173 On systems without @code{iconv}, you can install GNU Libiconv. If
38174 Libiconv is installed in a standard place, @value{GDBN} will
38175 automatically use it if it is needed. If you have previously
38176 installed Libiconv in a non-standard place, you can use the
38177 @option{--with-libiconv-prefix} option to @file{configure}.
38179 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
38180 arrange to build Libiconv if a directory named @file{libiconv} appears
38181 in the top-most source directory. If Libiconv is built this way, and
38182 if the operating system does not provide a suitable @code{iconv}
38183 implementation, then the just-built library will automatically be used
38184 by @value{GDBN}. One easy way to set this up is to download GNU
38185 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
38186 source tree, and then rename the directory holding the Libiconv source
38187 code to @samp{libiconv}.
38190 @value{GDBN} can support debugging sections that are compressed with
38191 the LZMA library. @xref{MiniDebugInfo}. If this library is not
38192 included with your operating system, you can find it in the xz package
38193 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
38194 the usual place, then the @file{configure} script will use it
38195 automatically. If it is installed in an unusual path, you can use the
38196 @option{--with-lzma-prefix} option to specify its location.
38200 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
38201 library. This library may be included with your operating system
38202 distribution; if it is not, you can get the latest version from
38203 @url{http://www.mpfr.org}. The @file{configure} script will search
38204 for this library in several standard locations; if it is installed
38205 in an unusual path, you can use the @option{--with-libmpfr-prefix}
38206 option to specify its location.
38208 GNU MPFR is used to emulate target floating-point arithmetic during
38209 expression evaluation when the target uses different floating-point
38210 formats than the host. If GNU MPFR it is not available, @value{GDBN}
38211 will fall back to using host floating-point arithmetic.
38214 @value{GDBN} can be scripted using Python language. @xref{Python}.
38215 By default, @value{GDBN} will be compiled if the Python libraries are
38216 installed and are found by @file{configure}. You can use the
38217 @code{--with-python} option to request Python, and pass either the
38218 file name of the relevant @code{python} executable, or the name of the
38219 directory in which Python is installed, to choose a particular
38220 installation of Python.
38223 @cindex compressed debug sections
38224 @value{GDBN} will use the @samp{zlib} library, if available, to read
38225 compressed debug sections. Some linkers, such as GNU gold, are capable
38226 of producing binaries with compressed debug sections. If @value{GDBN}
38227 is compiled with @samp{zlib}, it will be able to read the debug
38228 information in such binaries.
38230 The @samp{zlib} library is likely included with your operating system
38231 distribution; if it is not, you can get the latest version from
38232 @url{http://zlib.net}.
38235 @node Running Configure
38236 @section Invoking the @value{GDBN} @file{configure} Script
38237 @cindex configuring @value{GDBN}
38238 @value{GDBN} comes with a @file{configure} script that automates the process
38239 of preparing @value{GDBN} for installation; you can then use @code{make} to
38240 build the @code{gdb} program.
38242 @c irrelevant in info file; it's as current as the code it lives with.
38243 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
38244 look at the @file{README} file in the sources; we may have improved the
38245 installation procedures since publishing this manual.}
38248 The @value{GDBN} distribution includes all the source code you need for
38249 @value{GDBN} in a single directory, whose name is usually composed by
38250 appending the version number to @samp{gdb}.
38252 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
38253 @file{gdb-@value{GDBVN}} directory. That directory contains:
38256 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
38257 script for configuring @value{GDBN} and all its supporting libraries
38259 @item gdb-@value{GDBVN}/gdb
38260 the source specific to @value{GDBN} itself
38262 @item gdb-@value{GDBVN}/bfd
38263 source for the Binary File Descriptor library
38265 @item gdb-@value{GDBVN}/include
38266 @sc{gnu} include files
38268 @item gdb-@value{GDBVN}/libiberty
38269 source for the @samp{-liberty} free software library
38271 @item gdb-@value{GDBVN}/opcodes
38272 source for the library of opcode tables and disassemblers
38274 @item gdb-@value{GDBVN}/readline
38275 source for the @sc{gnu} command-line interface
38278 There may be other subdirectories as well.
38280 The simplest way to configure and build @value{GDBN} is to run @file{configure}
38281 from the @file{gdb-@var{version-number}} source directory, which in
38282 this example is the @file{gdb-@value{GDBVN}} directory.
38284 First switch to the @file{gdb-@var{version-number}} source directory
38285 if you are not already in it; then run @file{configure}. Pass the
38286 identifier for the platform on which @value{GDBN} will run as an
38292 cd gdb-@value{GDBVN}
38297 Running @samp{configure} and then running @code{make} builds the
38298 included supporting libraries, then @code{gdb} itself. The configured
38299 source files, and the binaries, are left in the corresponding source
38303 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
38304 system does not recognize this automatically when you run a different
38305 shell, you may need to run @code{sh} on it explicitly:
38311 You should run the @file{configure} script from the top directory in the
38312 source tree, the @file{gdb-@var{version-number}} directory. If you run
38313 @file{configure} from one of the subdirectories, you will configure only
38314 that subdirectory. That is usually not what you want. In particular,
38315 if you run the first @file{configure} from the @file{gdb} subdirectory
38316 of the @file{gdb-@var{version-number}} directory, you will omit the
38317 configuration of @file{bfd}, @file{readline}, and other sibling
38318 directories of the @file{gdb} subdirectory. This leads to build errors
38319 about missing include files such as @file{bfd/bfd.h}.
38321 You can install @code{@value{GDBN}} anywhere. The best way to do this
38322 is to pass the @code{--prefix} option to @code{configure}, and then
38323 install it with @code{make install}.
38325 @node Separate Objdir
38326 @section Compiling @value{GDBN} in Another Directory
38328 If you want to run @value{GDBN} versions for several host or target machines,
38329 you need a different @code{gdb} compiled for each combination of
38330 host and target. @file{configure} is designed to make this easy by
38331 allowing you to generate each configuration in a separate subdirectory,
38332 rather than in the source directory. If your @code{make} program
38333 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38334 @code{make} in each of these directories builds the @code{gdb}
38335 program specified there.
38337 To build @code{gdb} in a separate directory, run @file{configure}
38338 with the @samp{--srcdir} option to specify where to find the source.
38339 (You also need to specify a path to find @file{configure}
38340 itself from your working directory. If the path to @file{configure}
38341 would be the same as the argument to @samp{--srcdir}, you can leave out
38342 the @samp{--srcdir} option; it is assumed.)
38344 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38345 separate directory for a Sun 4 like this:
38349 cd gdb-@value{GDBVN}
38352 ../gdb-@value{GDBVN}/configure
38357 When @file{configure} builds a configuration using a remote source
38358 directory, it creates a tree for the binaries with the same structure
38359 (and using the same names) as the tree under the source directory. In
38360 the example, you'd find the Sun 4 library @file{libiberty.a} in the
38361 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38362 @file{gdb-sun4/gdb}.
38364 Make sure that your path to the @file{configure} script has just one
38365 instance of @file{gdb} in it. If your path to @file{configure} looks
38366 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38367 one subdirectory of @value{GDBN}, not the whole package. This leads to
38368 build errors about missing include files such as @file{bfd/bfd.h}.
38370 One popular reason to build several @value{GDBN} configurations in separate
38371 directories is to configure @value{GDBN} for cross-compiling (where
38372 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
38373 programs that run on another machine---the @dfn{target}).
38374 You specify a cross-debugging target by
38375 giving the @samp{--target=@var{target}} option to @file{configure}.
38377 When you run @code{make} to build a program or library, you must run
38378 it in a configured directory---whatever directory you were in when you
38379 called @file{configure} (or one of its subdirectories).
38381 The @code{Makefile} that @file{configure} generates in each source
38382 directory also runs recursively. If you type @code{make} in a source
38383 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38384 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38385 will build all the required libraries, and then build GDB.
38387 When you have multiple hosts or targets configured in separate
38388 directories, you can run @code{make} on them in parallel (for example,
38389 if they are NFS-mounted on each of the hosts); they will not interfere
38393 @section Specifying Names for Hosts and Targets
38395 The specifications used for hosts and targets in the @file{configure}
38396 script are based on a three-part naming scheme, but some short predefined
38397 aliases are also supported. The full naming scheme encodes three pieces
38398 of information in the following pattern:
38401 @var{architecture}-@var{vendor}-@var{os}
38404 For example, you can use the alias @code{sun4} as a @var{host} argument,
38405 or as the value for @var{target} in a @code{--target=@var{target}}
38406 option. The equivalent full name is @samp{sparc-sun-sunos4}.
38408 The @file{configure} script accompanying @value{GDBN} does not provide
38409 any query facility to list all supported host and target names or
38410 aliases. @file{configure} calls the Bourne shell script
38411 @code{config.sub} to map abbreviations to full names; you can read the
38412 script, if you wish, or you can use it to test your guesses on
38413 abbreviations---for example:
38416 % sh config.sub i386-linux
38418 % sh config.sub alpha-linux
38419 alpha-unknown-linux-gnu
38420 % sh config.sub hp9k700
38422 % sh config.sub sun4
38423 sparc-sun-sunos4.1.1
38424 % sh config.sub sun3
38425 m68k-sun-sunos4.1.1
38426 % sh config.sub i986v
38427 Invalid configuration `i986v': machine `i986v' not recognized
38431 @code{config.sub} is also distributed in the @value{GDBN} source
38432 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
38434 @node Configure Options
38435 @section @file{configure} Options
38437 Here is a summary of the @file{configure} options and arguments that
38438 are most often useful for building @value{GDBN}. @file{configure}
38439 also has several other options not listed here. @inforef{Running
38440 configure scripts,,autoconf.info}, for a full
38441 explanation of @file{configure}.
38444 configure @r{[}--help@r{]}
38445 @r{[}--prefix=@var{dir}@r{]}
38446 @r{[}--exec-prefix=@var{dir}@r{]}
38447 @r{[}--srcdir=@var{dirname}@r{]}
38448 @r{[}--target=@var{target}@r{]}
38452 You may introduce options with a single @samp{-} rather than
38453 @samp{--} if you prefer; but you may abbreviate option names if you use
38458 Display a quick summary of how to invoke @file{configure}.
38460 @item --prefix=@var{dir}
38461 Configure the source to install programs and files under directory
38464 @item --exec-prefix=@var{dir}
38465 Configure the source to install programs under directory
38468 @c avoid splitting the warning from the explanation:
38470 @item --srcdir=@var{dirname}
38471 Use this option to make configurations in directories separate from the
38472 @value{GDBN} source directories. Among other things, you can use this to
38473 build (or maintain) several configurations simultaneously, in separate
38474 directories. @file{configure} writes configuration-specific files in
38475 the current directory, but arranges for them to use the source in the
38476 directory @var{dirname}. @file{configure} creates directories under
38477 the working directory in parallel to the source directories below
38480 @item --target=@var{target}
38481 Configure @value{GDBN} for cross-debugging programs running on the specified
38482 @var{target}. Without this option, @value{GDBN} is configured to debug
38483 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
38485 There is no convenient way to generate a list of all available
38486 targets. Also see the @code{--enable-targets} option, below.
38489 There are many other options that are specific to @value{GDBN}. This
38490 lists just the most common ones; there are some very specialized
38491 options not described here.
38494 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38495 @itemx --enable-targets=all
38496 Configure @value{GDBN} for cross-debugging programs running on the
38497 specified list of targets. The special value @samp{all} configures
38498 @value{GDBN} for debugging programs running on any target it supports.
38500 @item --with-gdb-datadir=@var{path}
38501 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38502 here for certain supporting files or scripts. This defaults to the
38503 @file{gdb} subdirectory of @samp{datadir} (which can be set using
38506 @item --with-relocated-sources=@var{dir}
38507 Sets up the default source path substitution rule so that directory
38508 names recorded in debug information will be automatically adjusted for
38509 any directory under @var{dir}. @var{dir} should be a subdirectory of
38510 @value{GDBN}'s configured prefix, the one mentioned in the
38511 @code{--prefix} or @code{--exec-prefix} options to configure. This
38512 option is useful if GDB is supposed to be moved to a different place
38515 @item --enable-64-bit-bfd
38516 Enable 64-bit support in BFD on 32-bit hosts.
38518 @item --disable-gdbmi
38519 Build @value{GDBN} without the GDB/MI machine interface
38523 Build @value{GDBN} with the text-mode full-screen user interface
38524 (TUI). Requires a curses library (ncurses and cursesX are also
38527 @item --with-curses
38528 Use the curses library instead of the termcap library, for text-mode
38529 terminal operations.
38531 @item --with-debuginfod
38532 Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38533 Used to automatically fetch source files and separate debug files from
38534 debuginfod servers using the associated executable's build ID. Enabled
38535 by default if libdebuginfod is installed and found at configure time.
38536 debuginfod is packaged with elfutils, starting with version 0.178. You
38537 can get the latest version from `https://sourceware.org/elfutils/'.
38539 @item --with-libunwind-ia64
38540 Use the libunwind library for unwinding function call stack on ia64
38541 target platforms. See http://www.nongnu.org/libunwind/index.html for
38544 @item --with-system-readline
38545 Use the readline library installed on the host, rather than the
38546 library supplied as part of @value{GDBN}. Readline 7 or newer is
38547 required; this is enforced by the build system.
38549 @item --with-system-zlib
38550 Use the zlib library installed on the host, rather than the library
38551 supplied as part of @value{GDBN}.
38554 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38555 default if libexpat is installed and found at configure time.) This
38556 library is used to read XML files supplied with @value{GDBN}. If it
38557 is unavailable, some features, such as remote protocol memory maps,
38558 target descriptions, and shared library lists, that are based on XML
38559 files, will not be available in @value{GDBN}. If your host does not
38560 have libexpat installed, you can get the latest version from
38561 `http://expat.sourceforge.net'.
38563 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38565 Build @value{GDBN} with GNU libiconv, a character set encoding
38566 conversion library. This is not done by default, as on GNU systems
38567 the @code{iconv} that is built in to the C library is sufficient. If
38568 your host does not have a working @code{iconv}, you can get the latest
38569 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38571 @value{GDBN}'s build system also supports building GNU libiconv as
38572 part of the overall build. @xref{Requirements}.
38575 Build @value{GDBN} with LZMA, a compression library. (Done by default
38576 if liblzma is installed and found at configure time.) LZMA is used by
38577 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
38578 platforms using the ELF object file format. If your host does not
38579 have liblzma installed, you can get the latest version from
38580 `https://tukaani.org/xz/'.
38583 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38584 floating-point computation with correct rounding. (Done by default if
38585 GNU MPFR is installed and found at configure time.) This library is
38586 used to emulate target floating-point arithmetic during expression
38587 evaluation when the target uses different floating-point formats than
38588 the host. If GNU MPFR is not available, @value{GDBN} will fall back
38589 to using host floating-point arithmetic. If your host does not have
38590 GNU MPFR installed, you can get the latest version from
38591 `http://www.mpfr.org'.
38593 @item --with-python@r{[}=@var{python}@r{]}
38594 Build @value{GDBN} with Python scripting support. (Done by default if
38595 libpython is present and found at configure time.) Python makes
38596 @value{GDBN} scripting much more powerful than the restricted CLI
38597 scripting language. If your host does not have Python installed, you
38598 can find it on `http://www.python.org/download/'. The oldest version
38599 of Python supported by GDB is 2.6. The optional argument @var{python}
38600 is used to find the Python headers and libraries. It can be either
38601 the name of a Python executable, or the name of the directory in which
38602 Python is installed.
38604 @item --with-guile[=GUILE]'
38605 Build @value{GDBN} with GNU Guile scripting support. (Done by default
38606 if libguile is present and found at configure time.) If your host
38607 does not have Guile installed, you can find it at
38608 `https://www.gnu.org/software/guile/'. The optional argument GUILE
38609 can be a version number, which will cause @code{configure} to try to
38610 use that version of Guile; or the file name of a @code{pkg-config}
38611 executable, which will be queried to find the information needed to
38612 compile and link against Guile.
38614 @item --without-included-regex
38615 Don't use the regex library included with @value{GDBN} (as part of the
38616 libiberty library). This is the default on hosts with version 2 of
38619 @item --with-sysroot=@var{dir}
38620 Use @var{dir} as the default system root directory for libraries whose
38621 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38622 @var{dir} can be modified at run time by using the @command{set
38623 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38624 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38625 default system root will be automatically adjusted if and when
38626 @value{GDBN} is moved to a different location.
38628 @item --with-system-gdbinit=@var{file}
38629 Configure @value{GDBN} to automatically load a system-wide init file.
38630 @var{file} should be an absolute file name. If @var{file} is in a
38631 directory under the configured prefix, and @value{GDBN} is moved to
38632 another location after being built, the location of the system-wide
38633 init file will be adjusted accordingly.
38635 @item --with-system-gdbinit-dir=@var{directory}
38636 Configure @value{GDBN} to automatically load init files from a
38637 system-wide directory. @var{directory} should be an absolute directory
38638 name. If @var{directory} is in a directory under the configured
38639 prefix, and @value{GDBN} is moved to another location after being
38640 built, the location of the system-wide init directory will be
38641 adjusted accordingly.
38643 @item --enable-build-warnings
38644 When building the @value{GDBN} sources, ask the compiler to warn about
38645 any code which looks even vaguely suspicious. It passes many
38646 different warning flags, depending on the exact version of the
38647 compiler you are using.
38649 @item --enable-werror
38650 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38651 to the compiler, which will fail the compilation if the compiler
38652 outputs any warning messages.
38654 @item --enable-ubsan
38655 Enable the GCC undefined behavior sanitizer. This is disabled by
38656 default, but passing @code{--enable-ubsan=yes} or
38657 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
38658 undefined behavior sanitizer checks for C@t{++} undefined behavior.
38659 It has a performance cost, so if you are looking at @value{GDBN}'s
38660 performance, you should disable it. The undefined behavior sanitizer
38661 was first introduced in GCC 4.9.
38664 @node System-wide configuration
38665 @section System-wide configuration and settings
38666 @cindex system-wide init file
38668 @value{GDBN} can be configured to have a system-wide init file and a
38669 system-wide init file directory; this file and files in that directory
38670 (if they have a recognized file extension) will be read and executed at
38671 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38673 Here are the corresponding configure options:
38676 @item --with-system-gdbinit=@var{file}
38677 Specify that the default location of the system-wide init file is
38679 @item --with-system-gdbinit-dir=@var{directory}
38680 Specify that the default location of the system-wide init file directory
38681 is @var{directory}.
38684 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38685 they may be subject to relocation. Two possible cases:
38689 If the default location of this init file/directory contains @file{$prefix},
38690 it will be subject to relocation. Suppose that the configure options
38691 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38692 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38693 init file is looked for as @file{$install/etc/gdbinit} instead of
38694 @file{$prefix/etc/gdbinit}.
38697 By contrast, if the default location does not contain the prefix,
38698 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38699 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38700 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38701 wherever @value{GDBN} is installed.
38704 If the configured location of the system-wide init file (as given by the
38705 @option{--with-system-gdbinit} option at configure time) is in the
38706 data-directory (as specified by @option{--with-gdb-datadir} at configure
38707 time) or in one of its subdirectories, then @value{GDBN} will look for the
38708 system-wide init file in the directory specified by the
38709 @option{--data-directory} command-line option.
38710 Note that the system-wide init file is only read once, during @value{GDBN}
38711 initialization. If the data-directory is changed after @value{GDBN} has
38712 started with the @code{set data-directory} command, the file will not be
38715 This applies similarly to the system-wide directory specified in
38716 @option{--with-system-gdbinit-dir}.
38718 Any supported scripting language can be used for these init files, as long
38719 as the file extension matches the scripting language. To be interpreted
38720 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38724 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38727 @node System-wide Configuration Scripts
38728 @subsection Installed System-wide Configuration Scripts
38729 @cindex system-wide configuration scripts
38731 The @file{system-gdbinit} directory, located inside the data-directory
38732 (as specified by @option{--with-gdb-datadir} at configure time) contains
38733 a number of scripts which can be used as system-wide init files. To
38734 automatically source those scripts at startup, @value{GDBN} should be
38735 configured with @option{--with-system-gdbinit}. Otherwise, any user
38736 should be able to source them by hand as needed.
38738 The following scripts are currently available:
38741 @item @file{elinos.py}
38743 @cindex ELinOS system-wide configuration script
38744 This script is useful when debugging a program on an ELinOS target.
38745 It takes advantage of the environment variables defined in a standard
38746 ELinOS environment in order to determine the location of the system
38747 shared libraries, and then sets the @samp{solib-absolute-prefix}
38748 and @samp{solib-search-path} variables appropriately.
38750 @item @file{wrs-linux.py}
38751 @pindex wrs-linux.py
38752 @cindex Wind River Linux system-wide configuration script
38753 This script is useful when debugging a program on a target running
38754 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38755 the host-side sysroot used by the target system.
38759 @node Maintenance Commands
38760 @appendix Maintenance Commands
38761 @cindex maintenance commands
38762 @cindex internal commands
38764 In addition to commands intended for @value{GDBN} users, @value{GDBN}
38765 includes a number of commands intended for @value{GDBN} developers,
38766 that are not documented elsewhere in this manual. These commands are
38767 provided here for reference. (For commands that turn on debugging
38768 messages, see @ref{Debugging Output}.)
38771 @kindex maint agent
38772 @kindex maint agent-eval
38773 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38774 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38775 Translate the given @var{expression} into remote agent bytecodes.
38776 This command is useful for debugging the Agent Expression mechanism
38777 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38778 expression useful for data collection, such as by tracepoints, while
38779 @samp{maint agent-eval} produces an expression that evaluates directly
38780 to a result. For instance, a collection expression for @code{globa +
38781 globb} will include bytecodes to record four bytes of memory at each
38782 of the addresses of @code{globa} and @code{globb}, while discarding
38783 the result of the addition, while an evaluation expression will do the
38784 addition and return the sum.
38785 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38786 If not, generate remote agent bytecode for current frame PC address.
38788 @kindex maint agent-printf
38789 @item maint agent-printf @var{format},@var{expr},...
38790 Translate the given format string and list of argument expressions
38791 into remote agent bytecodes and display them as a disassembled list.
38792 This command is useful for debugging the agent version of dynamic
38793 printf (@pxref{Dynamic Printf}).
38795 @kindex maint info breakpoints
38796 @item @anchor{maint info breakpoints}maint info breakpoints
38797 Using the same format as @samp{info breakpoints}, display both the
38798 breakpoints you've set explicitly, and those @value{GDBN} is using for
38799 internal purposes. Internal breakpoints are shown with negative
38800 breakpoint numbers. The type column identifies what kind of breakpoint
38805 Normal, explicitly set breakpoint.
38808 Normal, explicitly set watchpoint.
38811 Internal breakpoint, used to handle correctly stepping through
38812 @code{longjmp} calls.
38814 @item longjmp resume
38815 Internal breakpoint at the target of a @code{longjmp}.
38818 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38821 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38824 Shared library events.
38828 @kindex maint info btrace
38829 @item maint info btrace
38830 Pint information about raw branch tracing data.
38832 @kindex maint btrace packet-history
38833 @item maint btrace packet-history
38834 Print the raw branch trace packets that are used to compute the
38835 execution history for the @samp{record btrace} command. Both the
38836 information and the format in which it is printed depend on the btrace
38841 For the BTS recording format, print a list of blocks of sequential
38842 code. For each block, the following information is printed:
38846 Newer blocks have higher numbers. The oldest block has number zero.
38847 @item Lowest @samp{PC}
38848 @item Highest @samp{PC}
38852 For the Intel Processor Trace recording format, print a list of
38853 Intel Processor Trace packets. For each packet, the following
38854 information is printed:
38857 @item Packet number
38858 Newer packets have higher numbers. The oldest packet has number zero.
38860 The packet's offset in the trace stream.
38861 @item Packet opcode and payload
38865 @kindex maint btrace clear-packet-history
38866 @item maint btrace clear-packet-history
38867 Discards the cached packet history printed by the @samp{maint btrace
38868 packet-history} command. The history will be computed again when
38871 @kindex maint btrace clear
38872 @item maint btrace clear
38873 Discard the branch trace data. The data will be fetched anew and the
38874 branch trace will be recomputed when needed.
38876 This implicitly truncates the branch trace to a single branch trace
38877 buffer. When updating branch trace incrementally, the branch trace
38878 available to @value{GDBN} may be bigger than a single branch trace
38881 @kindex maint set btrace pt skip-pad
38882 @item maint set btrace pt skip-pad
38883 @kindex maint show btrace pt skip-pad
38884 @item maint show btrace pt skip-pad
38885 Control whether @value{GDBN} will skip PAD packets when computing the
38888 @kindex set displaced-stepping
38889 @kindex show displaced-stepping
38890 @cindex displaced stepping support
38891 @cindex out-of-line single-stepping
38892 @item set displaced-stepping
38893 @itemx show displaced-stepping
38894 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38895 if the target supports it. Displaced stepping is a way to single-step
38896 over breakpoints without removing them from the inferior, by executing
38897 an out-of-line copy of the instruction that was originally at the
38898 breakpoint location. It is also known as out-of-line single-stepping.
38901 @item set displaced-stepping on
38902 If the target architecture supports it, @value{GDBN} will use
38903 displaced stepping to step over breakpoints.
38905 @item set displaced-stepping off
38906 @value{GDBN} will not use displaced stepping to step over breakpoints,
38907 even if such is supported by the target architecture.
38909 @cindex non-stop mode, and @samp{set displaced-stepping}
38910 @item set displaced-stepping auto
38911 This is the default mode. @value{GDBN} will use displaced stepping
38912 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38913 architecture supports displaced stepping.
38916 @kindex maint check-psymtabs
38917 @item maint check-psymtabs
38918 Check the consistency of currently expanded psymtabs versus symtabs.
38919 Use this to check, for example, whether a symbol is in one but not the other.
38921 @kindex maint check-symtabs
38922 @item maint check-symtabs
38923 Check the consistency of currently expanded symtabs.
38925 @kindex maint expand-symtabs
38926 @item maint expand-symtabs [@var{regexp}]
38927 Expand symbol tables.
38928 If @var{regexp} is specified, only expand symbol tables for file
38929 names matching @var{regexp}.
38931 @kindex maint set catch-demangler-crashes
38932 @kindex maint show catch-demangler-crashes
38933 @cindex demangler crashes
38934 @item maint set catch-demangler-crashes [on|off]
38935 @itemx maint show catch-demangler-crashes
38936 Control whether @value{GDBN} should attempt to catch crashes in the
38937 symbol name demangler. The default is to attempt to catch crashes.
38938 If enabled, the first time a crash is caught, a core file is created,
38939 the offending symbol is displayed and the user is presented with the
38940 option to terminate the current session.
38942 @kindex maint cplus first_component
38943 @item maint cplus first_component @var{name}
38944 Print the first C@t{++} class/namespace component of @var{name}.
38946 @kindex maint cplus namespace
38947 @item maint cplus namespace
38948 Print the list of possible C@t{++} namespaces.
38950 @kindex maint deprecate
38951 @kindex maint undeprecate
38952 @cindex deprecated commands
38953 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38954 @itemx maint undeprecate @var{command}
38955 Deprecate or undeprecate the named @var{command}. Deprecated commands
38956 cause @value{GDBN} to issue a warning when you use them. The optional
38957 argument @var{replacement} says which newer command should be used in
38958 favor of the deprecated one; if it is given, @value{GDBN} will mention
38959 the replacement as part of the warning.
38961 @kindex maint dump-me
38962 @item maint dump-me
38963 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38964 Cause a fatal signal in the debugger and force it to dump its core.
38965 This is supported only on systems which support aborting a program
38966 with the @code{SIGQUIT} signal.
38968 @kindex maint internal-error
38969 @kindex maint internal-warning
38970 @kindex maint demangler-warning
38971 @cindex demangler crashes
38972 @item maint internal-error @r{[}@var{message-text}@r{]}
38973 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38974 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38976 Cause @value{GDBN} to call the internal function @code{internal_error},
38977 @code{internal_warning} or @code{demangler_warning} and hence behave
38978 as though an internal problem has been detected. In addition to
38979 reporting the internal problem, these functions give the user the
38980 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38981 and @code{internal_warning}) create a core file of the current
38982 @value{GDBN} session.
38984 These commands take an optional parameter @var{message-text} that is
38985 used as the text of the error or warning message.
38987 Here's an example of using @code{internal-error}:
38990 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38991 @dots{}/maint.c:121: internal-error: testing, 1, 2
38992 A problem internal to GDB has been detected. Further
38993 debugging may prove unreliable.
38994 Quit this debugging session? (y or n) @kbd{n}
38995 Create a core file? (y or n) @kbd{n}
38999 @cindex @value{GDBN} internal error
39000 @cindex internal errors, control of @value{GDBN} behavior
39001 @cindex demangler crashes
39003 @kindex maint set internal-error
39004 @kindex maint show internal-error
39005 @kindex maint set internal-warning
39006 @kindex maint show internal-warning
39007 @kindex maint set demangler-warning
39008 @kindex maint show demangler-warning
39009 @item maint set internal-error @var{action} [ask|yes|no]
39010 @itemx maint show internal-error @var{action}
39011 @itemx maint set internal-warning @var{action} [ask|yes|no]
39012 @itemx maint show internal-warning @var{action}
39013 @itemx maint set demangler-warning @var{action} [ask|yes|no]
39014 @itemx maint show demangler-warning @var{action}
39015 When @value{GDBN} reports an internal problem (error or warning) it
39016 gives the user the opportunity to both quit @value{GDBN} and create a
39017 core file of the current @value{GDBN} session. These commands let you
39018 override the default behaviour for each particular @var{action},
39019 described in the table below.
39023 You can specify that @value{GDBN} should always (yes) or never (no)
39024 quit. The default is to ask the user what to do.
39027 You can specify that @value{GDBN} should always (yes) or never (no)
39028 create a core file. The default is to ask the user what to do. Note
39029 that there is no @code{corefile} option for @code{demangler-warning}:
39030 demangler warnings always create a core file and this cannot be
39034 @kindex maint packet
39035 @item maint packet @var{text}
39036 If @value{GDBN} is talking to an inferior via the serial protocol,
39037 then this command sends the string @var{text} to the inferior, and
39038 displays the response packet. @value{GDBN} supplies the initial
39039 @samp{$} character, the terminating @samp{#} character, and the
39042 @kindex maint print architecture
39043 @item maint print architecture @r{[}@var{file}@r{]}
39044 Print the entire architecture configuration. The optional argument
39045 @var{file} names the file where the output goes.
39047 @kindex maint print c-tdesc
39048 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
39049 Print the target description (@pxref{Target Descriptions}) as
39050 a C source file. By default, the target description is for the current
39051 target, but if the optional argument @var{file} is provided, that file
39052 is used to produce the description. The @var{file} should be an XML
39053 document, of the form described in @ref{Target Description Format}.
39054 The created source file is built into @value{GDBN} when @value{GDBN} is
39055 built again. This command is used by developers after they add or
39056 modify XML target descriptions.
39058 When the optional flag @samp{-single-feature} is provided then the
39059 target description being processed (either the default, or from
39060 @var{file}) must only contain a single feature. The source file
39061 produced is different in this case.
39063 @kindex maint print xml-tdesc
39064 @item maint print xml-tdesc @r{[}@var{file}@r{]}
39065 Print the target description (@pxref{Target Descriptions}) as an XML
39066 file. By default print the target description for the current target,
39067 but if the optional argument @var{file} is provided, then that file is
39068 read in by GDB and then used to produce the description. The
39069 @var{file} should be an XML document, of the form described in
39070 @ref{Target Description Format}.
39072 @kindex maint check xml-descriptions
39073 @item maint check xml-descriptions @var{dir}
39074 Check that the target descriptions dynamically created by @value{GDBN}
39075 equal the descriptions created from XML files found in @var{dir}.
39077 @anchor{maint check libthread-db}
39078 @kindex maint check libthread-db
39079 @item maint check libthread-db
39080 Run integrity checks on the current inferior's thread debugging
39081 library. This exercises all @code{libthread_db} functionality used by
39082 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
39083 @code{proc_service} functions provided by @value{GDBN} that
39084 @code{libthread_db} uses. Note that parts of the test may be skipped
39085 on some platforms when debugging core files.
39087 @kindex maint print core-file-backed-mappings
39088 @cindex memory address space mappings
39089 @item maint print core-file-backed-mappings
39090 Print the file-backed mappings which were loaded from a core file note.
39091 This output represents state internal to @value{GDBN} and should be
39092 similar to the mappings displayed by the @code{info proc mappings}
39095 @kindex maint print dummy-frames
39096 @item maint print dummy-frames
39097 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
39100 (@value{GDBP}) @kbd{b add}
39102 (@value{GDBP}) @kbd{print add(2,3)}
39103 Breakpoint 2, add (a=2, b=3) at @dots{}
39105 The program being debugged stopped while in a function called from GDB.
39107 (@value{GDBP}) @kbd{maint print dummy-frames}
39108 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
39112 Takes an optional file parameter.
39114 @kindex maint print registers
39115 @kindex maint print raw-registers
39116 @kindex maint print cooked-registers
39117 @kindex maint print register-groups
39118 @kindex maint print remote-registers
39119 @item maint print registers @r{[}@var{file}@r{]}
39120 @itemx maint print raw-registers @r{[}@var{file}@r{]}
39121 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
39122 @itemx maint print register-groups @r{[}@var{file}@r{]}
39123 @itemx maint print remote-registers @r{[}@var{file}@r{]}
39124 Print @value{GDBN}'s internal register data structures.
39126 The command @code{maint print raw-registers} includes the contents of
39127 the raw register cache; the command @code{maint print
39128 cooked-registers} includes the (cooked) value of all registers,
39129 including registers which aren't available on the target nor visible
39130 to user; the command @code{maint print register-groups} includes the
39131 groups that each register is a member of; and the command @code{maint
39132 print remote-registers} includes the remote target's register numbers
39133 and offsets in the `G' packets.
39135 These commands take an optional parameter, a file name to which to
39136 write the information.
39138 @kindex maint print reggroups
39139 @item maint print reggroups @r{[}@var{file}@r{]}
39140 Print @value{GDBN}'s internal register group data structures. The
39141 optional argument @var{file} tells to what file to write the
39144 The register groups info looks like this:
39147 (@value{GDBP}) @kbd{maint print reggroups}
39158 @kindex maint flush register-cache
39160 @cindex register cache, flushing
39161 @item maint flush register-cache
39163 Flush the contents of the register cache and as a consequence the
39164 frame cache. This command is useful when debugging issues related to
39165 register fetching, or frame unwinding. The command @code{flushregs}
39166 is deprecated in favor of @code{maint flush register-cache}.
39168 @kindex maint print objfiles
39169 @cindex info for known object files
39170 @item maint print objfiles @r{[}@var{regexp}@r{]}
39171 Print a dump of all known object files.
39172 If @var{regexp} is specified, only print object files whose names
39173 match @var{regexp}. For each object file, this command prints its name,
39174 address in memory, and all of its psymtabs and symtabs.
39176 @kindex maint print user-registers
39177 @cindex user registers
39178 @item maint print user-registers
39179 List all currently available @dfn{user registers}. User registers
39180 typically provide alternate names for actual hardware registers. They
39181 include the four ``standard'' registers @code{$fp}, @code{$pc},
39182 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
39183 registers can be used in expressions in the same way as the canonical
39184 register names, but only the latter are listed by the @code{info
39185 registers} and @code{maint print registers} commands.
39187 @kindex maint print section-scripts
39188 @cindex info for known .debug_gdb_scripts-loaded scripts
39189 @item maint print section-scripts [@var{regexp}]
39190 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
39191 If @var{regexp} is specified, only print scripts loaded by object files
39192 matching @var{regexp}.
39193 For each script, this command prints its name as specified in the objfile,
39194 and the full path if known.
39195 @xref{dotdebug_gdb_scripts section}.
39197 @kindex maint print statistics
39198 @cindex bcache statistics
39199 @item maint print statistics
39200 This command prints, for each object file in the program, various data
39201 about that object file followed by the byte cache (@dfn{bcache})
39202 statistics for the object file. The objfile data includes the number
39203 of minimal, partial, full, and stabs symbols, the number of types
39204 defined by the objfile, the number of as yet unexpanded psym tables,
39205 the number of line tables and string tables, and the amount of memory
39206 used by the various tables. The bcache statistics include the counts,
39207 sizes, and counts of duplicates of all and unique objects, max,
39208 average, and median entry size, total memory used and its overhead and
39209 savings, and various measures of the hash table size and chain
39212 @kindex maint print target-stack
39213 @cindex target stack description
39214 @item maint print target-stack
39215 A @dfn{target} is an interface between the debugger and a particular
39216 kind of file or process. Targets can be stacked in @dfn{strata},
39217 so that more than one target can potentially respond to a request.
39218 In particular, memory accesses will walk down the stack of targets
39219 until they find a target that is interested in handling that particular
39222 This command prints a short description of each layer that was pushed on
39223 the @dfn{target stack}, starting from the top layer down to the bottom one.
39225 @kindex maint print type
39226 @cindex type chain of a data type
39227 @item maint print type @var{expr}
39228 Print the type chain for a type specified by @var{expr}. The argument
39229 can be either a type name or a symbol. If it is a symbol, the type of
39230 that symbol is described. The type chain produced by this command is
39231 a recursive definition of the data type as stored in @value{GDBN}'s
39232 data structures, including its flags and contained types.
39234 @kindex maint selftest
39236 @item maint selftest @r{[}@var{filter}@r{]}
39237 Run any self tests that were compiled in to @value{GDBN}. This will
39238 print a message showing how many tests were run, and how many failed.
39239 If a @var{filter} is passed, only the tests with @var{filter} in their
39242 @kindex maint info selftests
39244 @item maint info selftests
39245 List the selftests compiled in to @value{GDBN}.
39247 @kindex maint set dwarf always-disassemble
39248 @kindex maint show dwarf always-disassemble
39249 @item maint set dwarf always-disassemble
39250 @item maint show dwarf always-disassemble
39251 Control the behavior of @code{info address} when using DWARF debugging
39254 The default is @code{off}, which means that @value{GDBN} should try to
39255 describe a variable's location in an easily readable format. When
39256 @code{on}, @value{GDBN} will instead display the DWARF location
39257 expression in an assembly-like format. Note that some locations are
39258 too complex for @value{GDBN} to describe simply; in this case you will
39259 always see the disassembly form.
39261 Here is an example of the resulting disassembly:
39264 (gdb) info addr argc
39265 Symbol "argc" is a complex DWARF expression:
39269 For more information on these expressions, see
39270 @uref{http://www.dwarfstd.org/, the DWARF standard}.
39272 @kindex maint set dwarf max-cache-age
39273 @kindex maint show dwarf max-cache-age
39274 @item maint set dwarf max-cache-age
39275 @itemx maint show dwarf max-cache-age
39276 Control the DWARF compilation unit cache.
39278 @cindex DWARF compilation units cache
39279 In object files with inter-compilation-unit references, such as those
39280 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
39281 reader needs to frequently refer to previously read compilation units.
39282 This setting controls how long a compilation unit will remain in the
39283 cache if it is not referenced. A higher limit means that cached
39284 compilation units will be stored in memory longer, and more total
39285 memory will be used. Setting it to zero disables caching, which will
39286 slow down @value{GDBN} startup, but reduce memory consumption.
39288 @kindex maint set dwarf unwinders
39289 @kindex maint show dwarf unwinders
39290 @item maint set dwarf unwinders
39291 @itemx maint show dwarf unwinders
39292 Control use of the DWARF frame unwinders.
39294 @cindex DWARF frame unwinders
39295 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39296 frame unwinders to build the backtrace. Many of these targets will
39297 also have a second mechanism for building the backtrace for use in
39298 cases where DWARF information is not available, this second mechanism
39299 is often an analysis of a function's prologue.
39301 In order to extend testing coverage of the second level stack
39302 unwinding mechanisms it is helpful to be able to disable the DWARF
39303 stack unwinders, this can be done with this switch.
39305 In normal use of @value{GDBN} disabling the DWARF unwinders is not
39306 advisable, there are cases that are better handled through DWARF than
39307 prologue analysis, and the debug experience is likely to be better
39308 with the DWARF frame unwinders enabled.
39310 If DWARF frame unwinders are not supported for a particular target
39311 architecture, then enabling this flag does not cause them to be used.
39313 @kindex maint set worker-threads
39314 @kindex maint show worker-threads
39315 @item maint set worker-threads
39316 @item maint show worker-threads
39317 Control the number of worker threads that may be used by @value{GDBN}.
39318 On capable hosts, @value{GDBN} may use multiple threads to speed up
39319 certain CPU-intensive operations, such as demangling symbol names.
39320 While the number of threads used by @value{GDBN} may vary, this
39321 command can be used to set an upper bound on this number. The default
39322 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39323 number. Note that this only controls worker threads started by
39324 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
39327 @kindex maint set profile
39328 @kindex maint show profile
39329 @cindex profiling GDB
39330 @item maint set profile
39331 @itemx maint show profile
39332 Control profiling of @value{GDBN}.
39334 Profiling will be disabled until you use the @samp{maint set profile}
39335 command to enable it. When you enable profiling, the system will begin
39336 collecting timing and execution count data; when you disable profiling or
39337 exit @value{GDBN}, the results will be written to a log file. Remember that
39338 if you use profiling, @value{GDBN} will overwrite the profiling log file
39339 (often called @file{gmon.out}). If you have a record of important profiling
39340 data in a @file{gmon.out} file, be sure to move it to a safe location.
39342 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
39343 compiled with the @samp{-pg} compiler option.
39345 @kindex maint set show-debug-regs
39346 @kindex maint show show-debug-regs
39347 @cindex hardware debug registers
39348 @item maint set show-debug-regs
39349 @itemx maint show show-debug-regs
39350 Control whether to show variables that mirror the hardware debug
39351 registers. Use @code{on} to enable, @code{off} to disable. If
39352 enabled, the debug registers values are shown when @value{GDBN} inserts or
39353 removes a hardware breakpoint or watchpoint, and when the inferior
39354 triggers a hardware-assisted breakpoint or watchpoint.
39356 @kindex maint set show-all-tib
39357 @kindex maint show show-all-tib
39358 @item maint set show-all-tib
39359 @itemx maint show show-all-tib
39360 Control whether to show all non zero areas within a 1k block starting
39361 at thread local base, when using the @samp{info w32 thread-information-block}
39364 @kindex maint set target-async
39365 @kindex maint show target-async
39366 @item maint set target-async
39367 @itemx maint show target-async
39368 This controls whether @value{GDBN} targets operate in synchronous or
39369 asynchronous mode (@pxref{Background Execution}). Normally the
39370 default is asynchronous, if it is available; but this can be changed
39371 to more easily debug problems occurring only in synchronous mode.
39373 @kindex maint set target-non-stop @var{mode} [on|off|auto]
39374 @kindex maint show target-non-stop
39375 @item maint set target-non-stop
39376 @itemx maint show target-non-stop
39378 This controls whether @value{GDBN} targets always operate in non-stop
39379 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39380 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39381 if supported by the target.
39384 @item maint set target-non-stop auto
39385 This is the default mode. @value{GDBN} controls the target in
39386 non-stop mode if the target supports it.
39388 @item maint set target-non-stop on
39389 @value{GDBN} controls the target in non-stop mode even if the target
39390 does not indicate support.
39392 @item maint set target-non-stop off
39393 @value{GDBN} does not control the target in non-stop mode even if the
39394 target supports it.
39397 @kindex maint set tui-resize-message
39398 @kindex maint show tui-resize-message
39399 @item maint set tui-resize-message
39400 @item maint show tui-resize-message
39401 Control whether @value{GDBN} displays a message each time the terminal
39402 is resized when in TUI mode. The default is @code{off}, which means
39403 that @value{GDBN} is silent during resizes. When @code{on},
39404 @value{GDBN} will display a message after a resize is completed; the
39405 message will include a number indicating how many times the terminal
39406 has been resized. This setting is intended for use by the test suite,
39407 where it would otherwise be difficult to determine when a resize and
39408 refresh has been completed.
39410 @kindex maint set per-command
39411 @kindex maint show per-command
39412 @item maint set per-command
39413 @itemx maint show per-command
39414 @cindex resources used by commands
39416 @value{GDBN} can display the resources used by each command.
39417 This is useful in debugging performance problems.
39420 @item maint set per-command space [on|off]
39421 @itemx maint show per-command space
39422 Enable or disable the printing of the memory used by GDB for each command.
39423 If enabled, @value{GDBN} will display how much memory each command
39424 took, following the command's own output.
39425 This can also be requested by invoking @value{GDBN} with the
39426 @option{--statistics} command-line switch (@pxref{Mode Options}).
39428 @item maint set per-command time [on|off]
39429 @itemx maint show per-command time
39430 Enable or disable the printing of the execution time of @value{GDBN}
39432 If enabled, @value{GDBN} will display how much time it
39433 took to execute each command, following the command's own output.
39434 Both CPU time and wallclock time are printed.
39435 Printing both is useful when trying to determine whether the cost is
39436 CPU or, e.g., disk/network latency.
39437 Note that the CPU time printed is for @value{GDBN} only, it does not include
39438 the execution time of the inferior because there's no mechanism currently
39439 to compute how much time was spent by @value{GDBN} and how much time was
39440 spent by the program been debugged.
39441 This can also be requested by invoking @value{GDBN} with the
39442 @option{--statistics} command-line switch (@pxref{Mode Options}).
39444 @item maint set per-command symtab [on|off]
39445 @itemx maint show per-command symtab
39446 Enable or disable the printing of basic symbol table statistics
39448 If enabled, @value{GDBN} will display the following information:
39452 number of symbol tables
39454 number of primary symbol tables
39456 number of blocks in the blockvector
39460 @kindex maint set check-libthread-db
39461 @kindex maint show check-libthread-db
39462 @item maint set check-libthread-db [on|off]
39463 @itemx maint show check-libthread-db
39464 Control whether @value{GDBN} should run integrity checks on inferior
39465 specific thread debugging libraries as they are loaded. The default
39466 is not to perform such checks. If any check fails @value{GDBN} will
39467 unload the library and continue searching for a suitable candidate as
39468 described in @ref{set libthread-db-search-path}. For more information
39469 about the tests, see @ref{maint check libthread-db}.
39471 @kindex maint space
39472 @cindex memory used by commands
39473 @item maint space @var{value}
39474 An alias for @code{maint set per-command space}.
39475 A non-zero value enables it, zero disables it.
39478 @cindex time of command execution
39479 @item maint time @var{value}
39480 An alias for @code{maint set per-command time}.
39481 A non-zero value enables it, zero disables it.
39483 @kindex maint translate-address
39484 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39485 Find the symbol stored at the location specified by the address
39486 @var{addr} and an optional section name @var{section}. If found,
39487 @value{GDBN} prints the name of the closest symbol and an offset from
39488 the symbol's location to the specified address. This is similar to
39489 the @code{info address} command (@pxref{Symbols}), except that this
39490 command also allows to find symbols in other sections.
39492 If section was not specified, the section in which the symbol was found
39493 is also printed. For dynamically linked executables, the name of
39494 executable or shared library containing the symbol is printed as well.
39496 @kindex maint test-options
39497 @item maint test-options require-delimiter
39498 @itemx maint test-options unknown-is-error
39499 @itemx maint test-options unknown-is-operand
39500 These commands are used by the testsuite to validate the command
39501 options framework. The @code{require-delimiter} variant requires a
39502 double-dash delimiter to indicate end of options. The
39503 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
39504 @code{unknown-is-error} variant throws an error on unknown option,
39505 while @code{unknown-is-operand} treats unknown options as the start of
39506 the command's operands. When run, the commands output the result of
39507 the processed options. When completed, the commands store the
39508 internal result of completion in a variable exposed by the @code{maint
39509 show test-options-completion-result} command.
39511 @kindex maint show test-options-completion-result
39512 @item maint show test-options-completion-result
39513 Shows the result of completing the @code{maint test-options}
39514 subcommands. This is used by the testsuite to validate completion
39515 support in the command options framework.
39517 @kindex maint set test-settings
39518 @kindex maint show test-settings
39519 @item maint set test-settings @var{kind}
39520 @itemx maint show test-settings @var{kind}
39521 These are representative commands for each @var{kind} of setting type
39522 @value{GDBN} supports. They are used by the testsuite for exercising
39523 the settings infrastructure.
39526 @item maint with @var{setting} [@var{value}] [-- @var{command}]
39527 Like the @code{with} command, but works with @code{maintenance set}
39528 variables. This is used by the testsuite to exercise the @code{with}
39529 command's infrastructure.
39533 The following command is useful for non-interactive invocations of
39534 @value{GDBN}, such as in the test suite.
39537 @item set watchdog @var{nsec}
39538 @kindex set watchdog
39539 @cindex watchdog timer
39540 @cindex timeout for commands
39541 Set the maximum number of seconds @value{GDBN} will wait for the
39542 target operation to finish. If this time expires, @value{GDBN}
39543 reports and error and the command is aborted.
39545 @item show watchdog
39546 Show the current setting of the target wait timeout.
39549 @node Remote Protocol
39550 @appendix @value{GDBN} Remote Serial Protocol
39555 * Stop Reply Packets::
39556 * General Query Packets::
39557 * Architecture-Specific Protocol Details::
39558 * Tracepoint Packets::
39559 * Host I/O Packets::
39561 * Notification Packets::
39562 * Remote Non-Stop::
39563 * Packet Acknowledgment::
39565 * File-I/O Remote Protocol Extension::
39566 * Library List Format::
39567 * Library List Format for SVR4 Targets::
39568 * Memory Map Format::
39569 * Thread List Format::
39570 * Traceframe Info Format::
39571 * Branch Trace Format::
39572 * Branch Trace Configuration Format::
39578 There may be occasions when you need to know something about the
39579 protocol---for example, if there is only one serial port to your target
39580 machine, you might want your program to do something special if it
39581 recognizes a packet meant for @value{GDBN}.
39583 In the examples below, @samp{->} and @samp{<-} are used to indicate
39584 transmitted and received data, respectively.
39586 @cindex protocol, @value{GDBN} remote serial
39587 @cindex serial protocol, @value{GDBN} remote
39588 @cindex remote serial protocol
39589 All @value{GDBN} commands and responses (other than acknowledgments
39590 and notifications, see @ref{Notification Packets}) are sent as a
39591 @var{packet}. A @var{packet} is introduced with the character
39592 @samp{$}, the actual @var{packet-data}, and the terminating character
39593 @samp{#} followed by a two-digit @var{checksum}:
39596 @code{$}@var{packet-data}@code{#}@var{checksum}
39600 @cindex checksum, for @value{GDBN} remote
39602 The two-digit @var{checksum} is computed as the modulo 256 sum of all
39603 characters between the leading @samp{$} and the trailing @samp{#} (an
39604 eight bit unsigned checksum).
39606 Implementors should note that prior to @value{GDBN} 5.0 the protocol
39607 specification also included an optional two-digit @var{sequence-id}:
39610 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
39613 @cindex sequence-id, for @value{GDBN} remote
39615 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39616 has never output @var{sequence-id}s. Stubs that handle packets added
39617 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
39619 When either the host or the target machine receives a packet, the first
39620 response expected is an acknowledgment: either @samp{+} (to indicate
39621 the package was received correctly) or @samp{-} (to request
39625 -> @code{$}@var{packet-data}@code{#}@var{checksum}
39630 The @samp{+}/@samp{-} acknowledgments can be disabled
39631 once a connection is established.
39632 @xref{Packet Acknowledgment}, for details.
39634 The host (@value{GDBN}) sends @var{command}s, and the target (the
39635 debugging stub incorporated in your program) sends a @var{response}. In
39636 the case of step and continue @var{command}s, the response is only sent
39637 when the operation has completed, and the target has again stopped all
39638 threads in all attached processes. This is the default all-stop mode
39639 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39640 execution mode; see @ref{Remote Non-Stop}, for details.
39642 @var{packet-data} consists of a sequence of characters with the
39643 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39646 @cindex remote protocol, field separator
39647 Fields within the packet should be separated using @samp{,} @samp{;} or
39648 @samp{:}. Except where otherwise noted all numbers are represented in
39649 @sc{hex} with leading zeros suppressed.
39651 Implementors should note that prior to @value{GDBN} 5.0, the character
39652 @samp{:} could not appear as the third character in a packet (as it
39653 would potentially conflict with the @var{sequence-id}).
39655 @cindex remote protocol, binary data
39656 @anchor{Binary Data}
39657 Binary data in most packets is encoded either as two hexadecimal
39658 digits per byte of binary data. This allowed the traditional remote
39659 protocol to work over connections which were only seven-bit clean.
39660 Some packets designed more recently assume an eight-bit clean
39661 connection, and use a more efficient encoding to send and receive
39664 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39665 as an escape character. Any escaped byte is transmitted as the escape
39666 character followed by the original character XORed with @code{0x20}.
39667 For example, the byte @code{0x7d} would be transmitted as the two
39668 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39669 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39670 @samp{@}}) must always be escaped. Responses sent by the stub
39671 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39672 is not interpreted as the start of a run-length encoded sequence
39675 Response @var{data} can be run-length encoded to save space.
39676 Run-length encoding replaces runs of identical characters with one
39677 instance of the repeated character, followed by a @samp{*} and a
39678 repeat count. The repeat count is itself sent encoded, to avoid
39679 binary characters in @var{data}: a value of @var{n} is sent as
39680 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
39681 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39682 code 32) for a repeat count of 3. (This is because run-length
39683 encoding starts to win for counts 3 or more.) Thus, for example,
39684 @samp{0* } is a run-length encoding of ``0000'': the space character
39685 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
39688 The printable characters @samp{#} and @samp{$} or with a numeric value
39689 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39690 seven repeats (@samp{$}) can be expanded using a repeat count of only
39691 five (@samp{"}). For example, @samp{00000000} can be encoded as
39694 The error response returned for some packets includes a two character
39695 error number. That number is not well defined.
39697 @cindex empty response, for unsupported packets
39698 For any @var{command} not supported by the stub, an empty response
39699 (@samp{$#00}) should be returned. That way it is possible to extend the
39700 protocol. A newer @value{GDBN} can tell if a packet is supported based
39703 At a minimum, a stub is required to support the @samp{?} command to
39704 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
39705 commands for register access, and the @samp{m} and @samp{M} commands
39706 for memory access. Stubs that only control single-threaded targets
39707 can implement run control with the @samp{c} (continue) command, and if
39708 the target architecture supports hardware-assisted single-stepping,
39709 the @samp{s} (step) command. Stubs that support multi-threading
39710 targets should support the @samp{vCont} command. All other commands
39716 The following table provides a complete list of all currently defined
39717 @var{command}s and their corresponding response @var{data}.
39718 @xref{File-I/O Remote Protocol Extension}, for details about the File
39719 I/O extension of the remote protocol.
39721 Each packet's description has a template showing the packet's overall
39722 syntax, followed by an explanation of the packet's meaning. We
39723 include spaces in some of the templates for clarity; these are not
39724 part of the packet's syntax. No @value{GDBN} packet uses spaces to
39725 separate its components. For example, a template like @samp{foo
39726 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
39727 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39728 @var{baz}. @value{GDBN} does not transmit a space character between the
39729 @samp{foo} and the @var{bar}, or between the @var{bar} and the
39732 @cindex @var{thread-id}, in remote protocol
39733 @anchor{thread-id syntax}
39734 Several packets and replies include a @var{thread-id} field to identify
39735 a thread. Normally these are positive numbers with a target-specific
39736 interpretation, formatted as big-endian hex strings. A @var{thread-id}
39737 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39740 In addition, the remote protocol supports a multiprocess feature in
39741 which the @var{thread-id} syntax is extended to optionally include both
39742 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39743 The @var{pid} (process) and @var{tid} (thread) components each have the
39744 format described above: a positive number with target-specific
39745 interpretation formatted as a big-endian hex string, literal @samp{-1}
39746 to indicate all processes or threads (respectively), or @samp{0} to
39747 indicate an arbitrary process or thread. Specifying just a process, as
39748 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39749 error to specify all processes but a specific thread, such as
39750 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39751 for those packets and replies explicitly documented to include a process
39752 ID, rather than a @var{thread-id}.
39754 The multiprocess @var{thread-id} syntax extensions are only used if both
39755 @value{GDBN} and the stub report support for the @samp{multiprocess}
39756 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39759 Note that all packet forms beginning with an upper- or lower-case
39760 letter, other than those described here, are reserved for future use.
39762 Here are the packet descriptions.
39767 @cindex @samp{!} packet
39768 @anchor{extended mode}
39769 Enable extended mode. In extended mode, the remote server is made
39770 persistent. The @samp{R} packet is used to restart the program being
39776 The remote target both supports and has enabled extended mode.
39780 @cindex @samp{?} packet
39782 This is sent when connection is first established to query the reason
39783 the target halted. The reply is the same as for step and continue.
39784 This packet has a special interpretation when the target is in
39785 non-stop mode; see @ref{Remote Non-Stop}.
39788 @xref{Stop Reply Packets}, for the reply specifications.
39790 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
39791 @cindex @samp{A} packet
39792 Initialized @code{argv[]} array passed into program. @var{arglen}
39793 specifies the number of bytes in the hex encoded byte stream
39794 @var{arg}. See @code{gdbserver} for more details.
39799 The arguments were set.
39805 @cindex @samp{b} packet
39806 (Don't use this packet; its behavior is not well-defined.)
39807 Change the serial line speed to @var{baud}.
39809 JTC: @emph{When does the transport layer state change? When it's
39810 received, or after the ACK is transmitted. In either case, there are
39811 problems if the command or the acknowledgment packet is dropped.}
39813 Stan: @emph{If people really wanted to add something like this, and get
39814 it working for the first time, they ought to modify ser-unix.c to send
39815 some kind of out-of-band message to a specially-setup stub and have the
39816 switch happen "in between" packets, so that from remote protocol's point
39817 of view, nothing actually happened.}
39819 @item B @var{addr},@var{mode}
39820 @cindex @samp{B} packet
39821 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39822 breakpoint at @var{addr}.
39824 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39825 (@pxref{insert breakpoint or watchpoint packet}).
39827 @cindex @samp{bc} packet
39830 Backward continue. Execute the target system in reverse. No parameter.
39831 @xref{Reverse Execution}, for more information.
39834 @xref{Stop Reply Packets}, for the reply specifications.
39836 @cindex @samp{bs} packet
39839 Backward single step. Execute one instruction in reverse. No parameter.
39840 @xref{Reverse Execution}, for more information.
39843 @xref{Stop Reply Packets}, for the reply specifications.
39845 @item c @r{[}@var{addr}@r{]}
39846 @cindex @samp{c} packet
39847 Continue at @var{addr}, which is the address to resume. If @var{addr}
39848 is omitted, resume at current address.
39850 This packet is deprecated for multi-threading support. @xref{vCont
39854 @xref{Stop Reply Packets}, for the reply specifications.
39856 @item C @var{sig}@r{[};@var{addr}@r{]}
39857 @cindex @samp{C} packet
39858 Continue with signal @var{sig} (hex signal number). If
39859 @samp{;@var{addr}} is omitted, resume at same address.
39861 This packet is deprecated for multi-threading support. @xref{vCont
39865 @xref{Stop Reply Packets}, for the reply specifications.
39868 @cindex @samp{d} packet
39871 Don't use this packet; instead, define a general set packet
39872 (@pxref{General Query Packets}).
39876 @cindex @samp{D} packet
39877 The first form of the packet is used to detach @value{GDBN} from the
39878 remote system. It is sent to the remote target
39879 before @value{GDBN} disconnects via the @code{detach} command.
39881 The second form, including a process ID, is used when multiprocess
39882 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39883 detach only a specific process. The @var{pid} is specified as a
39884 big-endian hex string.
39894 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39895 @cindex @samp{F} packet
39896 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39897 This is part of the File-I/O protocol extension. @xref{File-I/O
39898 Remote Protocol Extension}, for the specification.
39901 @anchor{read registers packet}
39902 @cindex @samp{g} packet
39903 Read general registers.
39907 @item @var{XX@dots{}}
39908 Each byte of register data is described by two hex digits. The bytes
39909 with the register are transmitted in target byte order. The size of
39910 each register and their position within the @samp{g} packet are
39911 determined by the @value{GDBN} internal gdbarch functions
39912 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39914 When reading registers from a trace frame (@pxref{Analyze Collected
39915 Data,,Using the Collected Data}), the stub may also return a string of
39916 literal @samp{x}'s in place of the register data digits, to indicate
39917 that the corresponding register has not been collected, thus its value
39918 is unavailable. For example, for an architecture with 4 registers of
39919 4 bytes each, the following reply indicates to @value{GDBN} that
39920 registers 0 and 2 have not been collected, while registers 1 and 3
39921 have been collected, and both have zero value:
39925 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39932 @item G @var{XX@dots{}}
39933 @cindex @samp{G} packet
39934 Write general registers. @xref{read registers packet}, for a
39935 description of the @var{XX@dots{}} data.
39945 @item H @var{op} @var{thread-id}
39946 @cindex @samp{H} packet
39947 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39948 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39949 should be @samp{c} for step and continue operations (note that this
39950 is deprecated, supporting the @samp{vCont} command is a better
39951 option), and @samp{g} for other operations. The thread designator
39952 @var{thread-id} has the format and interpretation described in
39953 @ref{thread-id syntax}.
39964 @c 'H': How restrictive (or permissive) is the thread model. If a
39965 @c thread is selected and stopped, are other threads allowed
39966 @c to continue to execute? As I mentioned above, I think the
39967 @c semantics of each command when a thread is selected must be
39968 @c described. For example:
39970 @c 'g': If the stub supports threads and a specific thread is
39971 @c selected, returns the register block from that thread;
39972 @c otherwise returns current registers.
39974 @c 'G' If the stub supports threads and a specific thread is
39975 @c selected, sets the registers of the register block of
39976 @c that thread; otherwise sets current registers.
39978 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39979 @anchor{cycle step packet}
39980 @cindex @samp{i} packet
39981 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39982 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39983 step starting at that address.
39986 @cindex @samp{I} packet
39987 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39991 @cindex @samp{k} packet
39994 The exact effect of this packet is not specified.
39996 For a bare-metal target, it may power cycle or reset the target
39997 system. For that reason, the @samp{k} packet has no reply.
39999 For a single-process target, it may kill that process if possible.
40001 A multiple-process target may choose to kill just one process, or all
40002 that are under @value{GDBN}'s control. For more precise control, use
40003 the vKill packet (@pxref{vKill packet}).
40005 If the target system immediately closes the connection in response to
40006 @samp{k}, @value{GDBN} does not consider the lack of packet
40007 acknowledgment to be an error, and assumes the kill was successful.
40009 If connected using @kbd{target extended-remote}, and the target does
40010 not close the connection in response to a kill request, @value{GDBN}
40011 probes the target state as if a new connection was opened
40012 (@pxref{? packet}).
40014 @item m @var{addr},@var{length}
40015 @cindex @samp{m} packet
40016 Read @var{length} addressable memory units starting at address @var{addr}
40017 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
40018 any particular boundary.
40020 The stub need not use any particular size or alignment when gathering
40021 data from memory for the response; even if @var{addr} is word-aligned
40022 and @var{length} is a multiple of the word size, the stub is free to
40023 use byte accesses, or not. For this reason, this packet may not be
40024 suitable for accessing memory-mapped I/O devices.
40025 @cindex alignment of remote memory accesses
40026 @cindex size of remote memory accesses
40027 @cindex memory, alignment and size of remote accesses
40031 @item @var{XX@dots{}}
40032 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
40033 The reply may contain fewer addressable memory units than requested if the
40034 server was able to read only part of the region of memory.
40039 @item M @var{addr},@var{length}:@var{XX@dots{}}
40040 @cindex @samp{M} packet
40041 Write @var{length} addressable memory units starting at address @var{addr}
40042 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
40043 byte is transmitted as a two-digit hexadecimal number.
40050 for an error (this includes the case where only part of the data was
40055 @cindex @samp{p} packet
40056 Read the value of register @var{n}; @var{n} is in hex.
40057 @xref{read registers packet}, for a description of how the returned
40058 register value is encoded.
40062 @item @var{XX@dots{}}
40063 the register's value
40067 Indicating an unrecognized @var{query}.
40070 @item P @var{n@dots{}}=@var{r@dots{}}
40071 @anchor{write register packet}
40072 @cindex @samp{P} packet
40073 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
40074 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
40075 digits for each byte in the register (target byte order).
40085 @item q @var{name} @var{params}@dots{}
40086 @itemx Q @var{name} @var{params}@dots{}
40087 @cindex @samp{q} packet
40088 @cindex @samp{Q} packet
40089 General query (@samp{q}) and set (@samp{Q}). These packets are
40090 described fully in @ref{General Query Packets}.
40093 @cindex @samp{r} packet
40094 Reset the entire system.
40096 Don't use this packet; use the @samp{R} packet instead.
40099 @cindex @samp{R} packet
40100 Restart the program being debugged. The @var{XX}, while needed, is ignored.
40101 This packet is only available in extended mode (@pxref{extended mode}).
40103 The @samp{R} packet has no reply.
40105 @item s @r{[}@var{addr}@r{]}
40106 @cindex @samp{s} packet
40107 Single step, resuming at @var{addr}. If
40108 @var{addr} is omitted, resume at same address.
40110 This packet is deprecated for multi-threading support. @xref{vCont
40114 @xref{Stop Reply Packets}, for the reply specifications.
40116 @item S @var{sig}@r{[};@var{addr}@r{]}
40117 @anchor{step with signal packet}
40118 @cindex @samp{S} packet
40119 Step with signal. This is analogous to the @samp{C} packet, but
40120 requests a single-step, rather than a normal resumption of execution.
40122 This packet is deprecated for multi-threading support. @xref{vCont
40126 @xref{Stop Reply Packets}, for the reply specifications.
40128 @item t @var{addr}:@var{PP},@var{MM}
40129 @cindex @samp{t} packet
40130 Search backwards starting at address @var{addr} for a match with pattern
40131 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
40132 There must be at least 3 digits in @var{addr}.
40134 @item T @var{thread-id}
40135 @cindex @samp{T} packet
40136 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
40141 thread is still alive
40147 Packets starting with @samp{v} are identified by a multi-letter name,
40148 up to the first @samp{;} or @samp{?} (or the end of the packet).
40150 @item vAttach;@var{pid}
40151 @cindex @samp{vAttach} packet
40152 Attach to a new process with the specified process ID @var{pid}.
40153 The process ID is a
40154 hexadecimal integer identifying the process. In all-stop mode, all
40155 threads in the attached process are stopped; in non-stop mode, it may be
40156 attached without being stopped if that is supported by the target.
40158 @c In non-stop mode, on a successful vAttach, the stub should set the
40159 @c current thread to a thread of the newly-attached process. After
40160 @c attaching, GDB queries for the attached process's thread ID with qC.
40161 @c Also note that, from a user perspective, whether or not the
40162 @c target is stopped on attach in non-stop mode depends on whether you
40163 @c use the foreground or background version of the attach command, not
40164 @c on what vAttach does; GDB does the right thing with respect to either
40165 @c stopping or restarting threads.
40167 This packet is only available in extended mode (@pxref{extended mode}).
40173 @item @r{Any stop packet}
40174 for success in all-stop mode (@pxref{Stop Reply Packets})
40176 for success in non-stop mode (@pxref{Remote Non-Stop})
40179 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
40180 @cindex @samp{vCont} packet
40181 @anchor{vCont packet}
40182 Resume the inferior, specifying different actions for each thread.
40184 For each inferior thread, the leftmost action with a matching
40185 @var{thread-id} is applied. Threads that don't match any action
40186 remain in their current state. Thread IDs are specified using the
40187 syntax described in @ref{thread-id syntax}. If multiprocess
40188 extensions (@pxref{multiprocess extensions}) are supported, actions
40189 can be specified to match all threads in a process by using the
40190 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
40191 @var{thread-id} matches all threads. Specifying no actions is an
40194 Currently supported actions are:
40200 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
40204 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
40207 @item r @var{start},@var{end}
40208 Step once, and then keep stepping as long as the thread stops at
40209 addresses between @var{start} (inclusive) and @var{end} (exclusive).
40210 The remote stub reports a stop reply when either the thread goes out
40211 of the range or is stopped due to an unrelated reason, such as hitting
40212 a breakpoint. @xref{range stepping}.
40214 If the range is empty (@var{start} == @var{end}), then the action
40215 becomes equivalent to the @samp{s} action. In other words,
40216 single-step once, and report the stop (even if the stepped instruction
40217 jumps to @var{start}).
40219 (A stop reply may be sent at any point even if the PC is still within
40220 the stepping range; for example, it is valid to implement this packet
40221 in a degenerate way as a single instruction step operation.)
40225 The optional argument @var{addr} normally associated with the
40226 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
40227 not supported in @samp{vCont}.
40229 The @samp{t} action is only relevant in non-stop mode
40230 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
40231 A stop reply should be generated for any affected thread not already stopped.
40232 When a thread is stopped by means of a @samp{t} action,
40233 the corresponding stop reply should indicate that the thread has stopped with
40234 signal @samp{0}, regardless of whether the target uses some other signal
40235 as an implementation detail.
40237 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
40238 @samp{r} actions for threads that are already running. Conversely,
40239 the server must ignore @samp{t} actions for threads that are already
40242 @emph{Note:} In non-stop mode, a thread is considered running until
40243 @value{GDBN} acknowledges an asynchronous stop notification for it with
40244 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
40246 The stub must support @samp{vCont} if it reports support for
40247 multiprocess extensions (@pxref{multiprocess extensions}).
40250 @xref{Stop Reply Packets}, for the reply specifications.
40253 @cindex @samp{vCont?} packet
40254 Request a list of actions supported by the @samp{vCont} packet.
40258 @item vCont@r{[};@var{action}@dots{}@r{]}
40259 The @samp{vCont} packet is supported. Each @var{action} is a supported
40260 command in the @samp{vCont} packet.
40262 The @samp{vCont} packet is not supported.
40265 @anchor{vCtrlC packet}
40267 @cindex @samp{vCtrlC} packet
40268 Interrupt remote target as if a control-C was pressed on the remote
40269 terminal. This is the equivalent to reacting to the @code{^C}
40270 (@samp{\003}, the control-C character) character in all-stop mode
40271 while the target is running, except this works in non-stop mode.
40272 @xref{interrupting remote targets}, for more info on the all-stop
40283 @item vFile:@var{operation}:@var{parameter}@dots{}
40284 @cindex @samp{vFile} packet
40285 Perform a file operation on the target system. For details,
40286 see @ref{Host I/O Packets}.
40288 @item vFlashErase:@var{addr},@var{length}
40289 @cindex @samp{vFlashErase} packet
40290 Direct the stub to erase @var{length} bytes of flash starting at
40291 @var{addr}. The region may enclose any number of flash blocks, but
40292 its start and end must fall on block boundaries, as indicated by the
40293 flash block size appearing in the memory map (@pxref{Memory Map
40294 Format}). @value{GDBN} groups flash memory programming operations
40295 together, and sends a @samp{vFlashDone} request after each group; the
40296 stub is allowed to delay erase operation until the @samp{vFlashDone}
40297 packet is received.
40307 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
40308 @cindex @samp{vFlashWrite} packet
40309 Direct the stub to write data to flash address @var{addr}. The data
40310 is passed in binary form using the same encoding as for the @samp{X}
40311 packet (@pxref{Binary Data}). The memory ranges specified by
40312 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40313 not overlap, and must appear in order of increasing addresses
40314 (although @samp{vFlashErase} packets for higher addresses may already
40315 have been received; the ordering is guaranteed only between
40316 @samp{vFlashWrite} packets). If a packet writes to an address that was
40317 neither erased by a preceding @samp{vFlashErase} packet nor by some other
40318 target-specific method, the results are unpredictable.
40326 for vFlashWrite addressing non-flash memory
40332 @cindex @samp{vFlashDone} packet
40333 Indicate to the stub that flash programming operation is finished.
40334 The stub is permitted to delay or batch the effects of a group of
40335 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
40336 @samp{vFlashDone} packet is received. The contents of the affected
40337 regions of flash memory are unpredictable until the @samp{vFlashDone}
40338 request is completed.
40340 @item vKill;@var{pid}
40341 @cindex @samp{vKill} packet
40342 @anchor{vKill packet}
40343 Kill the process with the specified process ID @var{pid}, which is a
40344 hexadecimal integer identifying the process. This packet is used in
40345 preference to @samp{k} when multiprocess protocol extensions are
40346 supported; see @ref{multiprocess extensions}.
40356 @item vMustReplyEmpty
40357 @cindex @samp{vMustReplyEmpty} packet
40358 The correct reply to an unknown @samp{v} packet is to return the empty
40359 string, however, some older versions of @command{gdbserver} would
40360 incorrectly return @samp{OK} for unknown @samp{v} packets.
40362 The @samp{vMustReplyEmpty} is used as a feature test to check how
40363 @command{gdbserver} handles unknown packets, it is important that this
40364 packet be handled in the same way as other unknown @samp{v} packets.
40365 If this packet is handled differently to other unknown @samp{v}
40366 packets then it is possible that @value{GDBN} may run into problems in
40367 other areas, specifically around use of @samp{vFile:setfs:}.
40369 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40370 @cindex @samp{vRun} packet
40371 Run the program @var{filename}, passing it each @var{argument} on its
40372 command line. The file and arguments are hex-encoded strings. If
40373 @var{filename} is an empty string, the stub may use a default program
40374 (e.g.@: the last program run). The program is created in the stopped
40377 @c FIXME: What about non-stop mode?
40379 This packet is only available in extended mode (@pxref{extended mode}).
40385 @item @r{Any stop packet}
40386 for success (@pxref{Stop Reply Packets})
40390 @cindex @samp{vStopped} packet
40391 @xref{Notification Packets}.
40393 @item X @var{addr},@var{length}:@var{XX@dots{}}
40395 @cindex @samp{X} packet
40396 Write data to memory, where the data is transmitted in binary.
40397 Memory is specified by its address @var{addr} and number of addressable memory
40398 units @var{length} (@pxref{addressable memory unit});
40399 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
40409 @item z @var{type},@var{addr},@var{kind}
40410 @itemx Z @var{type},@var{addr},@var{kind}
40411 @anchor{insert breakpoint or watchpoint packet}
40412 @cindex @samp{z} packet
40413 @cindex @samp{Z} packets
40414 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
40415 watchpoint starting at address @var{address} of kind @var{kind}.
40417 Each breakpoint and watchpoint packet @var{type} is documented
40420 @emph{Implementation notes: A remote target shall return an empty string
40421 for an unrecognized breakpoint or watchpoint packet @var{type}. A
40422 remote target shall support either both or neither of a given
40423 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
40424 avoid potential problems with duplicate packets, the operations should
40425 be implemented in an idempotent way.}
40427 @item z0,@var{addr},@var{kind}
40428 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40429 @cindex @samp{z0} packet
40430 @cindex @samp{Z0} packet
40431 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
40432 @var{addr} of type @var{kind}.
40434 A software breakpoint is implemented by replacing the instruction at
40435 @var{addr} with a software breakpoint or trap instruction. The
40436 @var{kind} is target-specific and typically indicates the size of the
40437 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40438 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40439 architectures have additional meanings for @var{kind}
40440 (@pxref{Architecture-Specific Protocol Details}); if no
40441 architecture-specific value is being used, it should be @samp{0}.
40442 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
40443 conditional expressions in bytecode form that should be evaluated on
40444 the target's side. These are the conditions that should be taken into
40445 consideration when deciding if the breakpoint trigger should be
40446 reported back to @value{GDBN}.
40448 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
40449 for how to best report a software breakpoint event to @value{GDBN}.
40451 The @var{cond_list} parameter is comprised of a series of expressions,
40452 concatenated without separators. Each expression has the following form:
40456 @item X @var{len},@var{expr}
40457 @var{len} is the length of the bytecode expression and @var{expr} is the
40458 actual conditional expression in bytecode form.
40462 The optional @var{cmd_list} parameter introduces commands that may be
40463 run on the target, rather than being reported back to @value{GDBN}.
40464 The parameter starts with a numeric flag @var{persist}; if the flag is
40465 nonzero, then the breakpoint may remain active and the commands
40466 continue to be run even when @value{GDBN} disconnects from the target.
40467 Following this flag is a series of expressions concatenated with no
40468 separators. Each expression has the following form:
40472 @item X @var{len},@var{expr}
40473 @var{len} is the length of the bytecode expression and @var{expr} is the
40474 actual commands expression in bytecode form.
40478 @emph{Implementation note: It is possible for a target to copy or move
40479 code that contains software breakpoints (e.g., when implementing
40480 overlays). The behavior of this packet, in the presence of such a
40481 target, is not defined.}
40493 @item z1,@var{addr},@var{kind}
40494 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40495 @cindex @samp{z1} packet
40496 @cindex @samp{Z1} packet
40497 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
40498 address @var{addr}.
40500 A hardware breakpoint is implemented using a mechanism that is not
40501 dependent on being able to modify the target's memory. The
40502 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40503 same meaning as in @samp{Z0} packets.
40505 @emph{Implementation note: A hardware breakpoint is not affected by code
40518 @item z2,@var{addr},@var{kind}
40519 @itemx Z2,@var{addr},@var{kind}
40520 @cindex @samp{z2} packet
40521 @cindex @samp{Z2} packet
40522 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
40523 The number of bytes to watch is specified by @var{kind}.
40535 @item z3,@var{addr},@var{kind}
40536 @itemx Z3,@var{addr},@var{kind}
40537 @cindex @samp{z3} packet
40538 @cindex @samp{Z3} packet
40539 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
40540 The number of bytes to watch is specified by @var{kind}.
40552 @item z4,@var{addr},@var{kind}
40553 @itemx Z4,@var{addr},@var{kind}
40554 @cindex @samp{z4} packet
40555 @cindex @samp{Z4} packet
40556 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
40557 The number of bytes to watch is specified by @var{kind}.
40571 @node Stop Reply Packets
40572 @section Stop Reply Packets
40573 @cindex stop reply packets
40575 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40576 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40577 receive any of the below as a reply. Except for @samp{?}
40578 and @samp{vStopped}, that reply is only returned
40579 when the target halts. In the below the exact meaning of @dfn{signal
40580 number} is defined by the header @file{include/gdb/signals.h} in the
40581 @value{GDBN} source code.
40583 In non-stop mode, the server will simply reply @samp{OK} to commands
40584 such as @samp{vCont}; any stop will be the subject of a future
40585 notification. @xref{Remote Non-Stop}.
40587 As in the description of request packets, we include spaces in the
40588 reply templates for clarity; these are not part of the reply packet's
40589 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40595 The program received signal number @var{AA} (a two-digit hexadecimal
40596 number). This is equivalent to a @samp{T} response with no
40597 @var{n}:@var{r} pairs.
40599 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40600 @cindex @samp{T} packet reply
40601 The program received signal number @var{AA} (a two-digit hexadecimal
40602 number). This is equivalent to an @samp{S} response, except that the
40603 @samp{@var{n}:@var{r}} pairs can carry values of important registers
40604 and other information directly in the stop reply packet, reducing
40605 round-trip latency. Single-step and breakpoint traps are reported
40606 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
40610 If @var{n} is a hexadecimal number, it is a register number, and the
40611 corresponding @var{r} gives that register's value. The data @var{r} is a
40612 series of bytes in target byte order, with each byte given by a
40613 two-digit hex number.
40616 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40617 the stopped thread, as specified in @ref{thread-id syntax}.
40620 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40621 the core on which the stop event was detected.
40624 If @var{n} is a recognized @dfn{stop reason}, it describes a more
40625 specific event that stopped the target. The currently defined stop
40626 reasons are listed below. The @var{aa} should be @samp{05}, the trap
40627 signal. At most one stop reason should be present.
40630 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40631 and go on to the next; this allows us to extend the protocol in the
40635 The currently defined stop reasons are:
40641 The packet indicates a watchpoint hit, and @var{r} is the data address, in
40644 @item syscall_entry
40645 @itemx syscall_return
40646 The packet indicates a syscall entry or return, and @var{r} is the
40647 syscall number, in hex.
40649 @cindex shared library events, remote reply
40651 The packet indicates that the loaded libraries have changed.
40652 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
40653 list of loaded libraries. The @var{r} part is ignored.
40655 @cindex replay log events, remote reply
40657 The packet indicates that the target cannot continue replaying
40658 logged execution events, because it has reached the end (or the
40659 beginning when executing backward) of the log. The value of @var{r}
40660 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40661 for more information.
40664 @anchor{swbreak stop reason}
40665 The packet indicates a software breakpoint instruction was executed,
40666 irrespective of whether it was @value{GDBN} that planted the
40667 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40668 part must be left empty.
40670 On some architectures, such as x86, at the architecture level, when a
40671 breakpoint instruction executes the program counter points at the
40672 breakpoint address plus an offset. On such targets, the stub is
40673 responsible for adjusting the PC to point back at the breakpoint
40676 This packet should not be sent by default; older @value{GDBN} versions
40677 did not support it. @value{GDBN} requests it, by supplying an
40678 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40679 remote stub must also supply the appropriate @samp{qSupported} feature
40680 indicating support.
40682 This packet is required for correct non-stop mode operation.
40685 The packet indicates the target stopped for a hardware breakpoint.
40686 The @var{r} part must be left empty.
40688 The same remarks about @samp{qSupported} and non-stop mode above
40691 @cindex fork events, remote reply
40693 The packet indicates that @code{fork} was called, and @var{r}
40694 is the thread ID of the new child process. Refer to
40695 @ref{thread-id syntax} for the format of the @var{thread-id}
40696 field. This packet is only applicable to targets that support
40699 This packet should not be sent by default; older @value{GDBN} versions
40700 did not support it. @value{GDBN} requests it, by supplying an
40701 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40702 remote stub must also supply the appropriate @samp{qSupported} feature
40703 indicating support.
40705 @cindex vfork events, remote reply
40707 The packet indicates that @code{vfork} was called, and @var{r}
40708 is the thread ID of the new child process. Refer to
40709 @ref{thread-id syntax} for the format of the @var{thread-id}
40710 field. This packet is only applicable to targets that support
40713 This packet should not be sent by default; older @value{GDBN} versions
40714 did not support it. @value{GDBN} requests it, by supplying an
40715 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40716 remote stub must also supply the appropriate @samp{qSupported} feature
40717 indicating support.
40719 @cindex vforkdone events, remote reply
40721 The packet indicates that a child process created by a vfork
40722 has either called @code{exec} or terminated, so that the
40723 address spaces of the parent and child process are no longer
40724 shared. The @var{r} part is ignored. This packet is only
40725 applicable to targets that support vforkdone events.
40727 This packet should not be sent by default; older @value{GDBN} versions
40728 did not support it. @value{GDBN} requests it, by supplying an
40729 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40730 remote stub must also supply the appropriate @samp{qSupported} feature
40731 indicating support.
40733 @cindex exec events, remote reply
40735 The packet indicates that @code{execve} was called, and @var{r}
40736 is the absolute pathname of the file that was executed, in hex.
40737 This packet is only applicable to targets that support exec events.
40739 This packet should not be sent by default; older @value{GDBN} versions
40740 did not support it. @value{GDBN} requests it, by supplying an
40741 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40742 remote stub must also supply the appropriate @samp{qSupported} feature
40743 indicating support.
40745 @cindex thread create event, remote reply
40746 @anchor{thread create event}
40748 The packet indicates that the thread was just created. The new thread
40749 is stopped until @value{GDBN} sets it running with a resumption packet
40750 (@pxref{vCont packet}). This packet should not be sent by default;
40751 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
40752 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40753 @var{r} part is ignored.
40758 @itemx W @var{AA} ; process:@var{pid}
40759 The process exited, and @var{AA} is the exit status. This is only
40760 applicable to certain targets.
40762 The second form of the response, including the process ID of the
40763 exited process, can be used only when @value{GDBN} has reported
40764 support for multiprocess protocol extensions; see @ref{multiprocess
40765 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40769 @itemx X @var{AA} ; process:@var{pid}
40770 The process terminated with signal @var{AA}.
40772 The second form of the response, including the process ID of the
40773 terminated process, can be used only when @value{GDBN} has reported
40774 support for multiprocess protocol extensions; see @ref{multiprocess
40775 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40778 @anchor{thread exit event}
40779 @cindex thread exit event, remote reply
40780 @item w @var{AA} ; @var{tid}
40782 The thread exited, and @var{AA} is the exit status. This response
40783 should not be sent by default; @value{GDBN} requests it with the
40784 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
40785 @var{AA} is formatted as a big-endian hex string.
40788 There are no resumed threads left in the target. In other words, even
40789 though the process is alive, the last resumed thread has exited. For
40790 example, say the target process has two threads: thread 1 and thread
40791 2. The client leaves thread 1 stopped, and resumes thread 2, which
40792 subsequently exits. At this point, even though the process is still
40793 alive, and thus no @samp{W} stop reply is sent, no thread is actually
40794 executing either. The @samp{N} stop reply thus informs the client
40795 that it can stop waiting for stop replies. This packet should not be
40796 sent by default; older @value{GDBN} versions did not support it.
40797 @value{GDBN} requests it, by supplying an appropriate
40798 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40799 also supply the appropriate @samp{qSupported} feature indicating
40802 @item O @var{XX}@dots{}
40803 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40804 written as the program's console output. This can happen at any time
40805 while the program is running and the debugger should continue to wait
40806 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40808 @item F @var{call-id},@var{parameter}@dots{}
40809 @var{call-id} is the identifier which says which host system call should
40810 be called. This is just the name of the function. Translation into the
40811 correct system call is only applicable as it's defined in @value{GDBN}.
40812 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40815 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40816 this very system call.
40818 The target replies with this packet when it expects @value{GDBN} to
40819 call a host system call on behalf of the target. @value{GDBN} replies
40820 with an appropriate @samp{F} packet and keeps up waiting for the next
40821 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40822 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40823 Protocol Extension}, for more details.
40827 @node General Query Packets
40828 @section General Query Packets
40829 @cindex remote query requests
40831 Packets starting with @samp{q} are @dfn{general query packets};
40832 packets starting with @samp{Q} are @dfn{general set packets}. General
40833 query and set packets are a semi-unified form for retrieving and
40834 sending information to and from the stub.
40836 The initial letter of a query or set packet is followed by a name
40837 indicating what sort of thing the packet applies to. For example,
40838 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40839 definitions with the stub. These packet names follow some
40844 The name must not contain commas, colons or semicolons.
40846 Most @value{GDBN} query and set packets have a leading upper case
40849 The names of custom vendor packets should use a company prefix, in
40850 lower case, followed by a period. For example, packets designed at
40851 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40852 foos) or @samp{Qacme.bar} (for setting bars).
40855 The name of a query or set packet should be separated from any
40856 parameters by a @samp{:}; the parameters themselves should be
40857 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40858 full packet name, and check for a separator or the end of the packet,
40859 in case two packet names share a common prefix. New packets should not begin
40860 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40861 packets predate these conventions, and have arguments without any terminator
40862 for the packet name; we suspect they are in widespread use in places that
40863 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40864 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40867 Like the descriptions of the other packets, each description here
40868 has a template showing the packet's overall syntax, followed by an
40869 explanation of the packet's meaning. We include spaces in some of the
40870 templates for clarity; these are not part of the packet's syntax. No
40871 @value{GDBN} packet uses spaces to separate its components.
40873 Here are the currently defined query and set packets:
40879 Turn on or off the agent as a helper to perform some debugging operations
40880 delegated from @value{GDBN} (@pxref{Control Agent}).
40882 @item QAllow:@var{op}:@var{val}@dots{}
40883 @cindex @samp{QAllow} packet
40884 Specify which operations @value{GDBN} expects to request of the
40885 target, as a semicolon-separated list of operation name and value
40886 pairs. Possible values for @var{op} include @samp{WriteReg},
40887 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40888 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40889 indicating that @value{GDBN} will not request the operation, or 1,
40890 indicating that it may. (The target can then use this to set up its
40891 own internals optimally, for instance if the debugger never expects to
40892 insert breakpoints, it may not need to install its own trap handler.)
40895 @cindex current thread, remote request
40896 @cindex @samp{qC} packet
40897 Return the current thread ID.
40901 @item QC @var{thread-id}
40902 Where @var{thread-id} is a thread ID as documented in
40903 @ref{thread-id syntax}.
40904 @item @r{(anything else)}
40905 Any other reply implies the old thread ID.
40908 @item qCRC:@var{addr},@var{length}
40909 @cindex CRC of memory block, remote request
40910 @cindex @samp{qCRC} packet
40911 @anchor{qCRC packet}
40912 Compute the CRC checksum of a block of memory using CRC-32 defined in
40913 IEEE 802.3. The CRC is computed byte at a time, taking the most
40914 significant bit of each byte first. The initial pattern code
40915 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40917 @emph{Note:} This is the same CRC used in validating separate debug
40918 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40919 Files}). However the algorithm is slightly different. When validating
40920 separate debug files, the CRC is computed taking the @emph{least}
40921 significant bit of each byte first, and the final result is inverted to
40922 detect trailing zeros.
40927 An error (such as memory fault)
40928 @item C @var{crc32}
40929 The specified memory region's checksum is @var{crc32}.
40932 @item QDisableRandomization:@var{value}
40933 @cindex disable address space randomization, remote request
40934 @cindex @samp{QDisableRandomization} packet
40935 Some target operating systems will randomize the virtual address space
40936 of the inferior process as a security feature, but provide a feature
40937 to disable such randomization, e.g.@: to allow for a more deterministic
40938 debugging experience. On such systems, this packet with a @var{value}
40939 of 1 directs the target to disable address space randomization for
40940 processes subsequently started via @samp{vRun} packets, while a packet
40941 with a @var{value} of 0 tells the target to enable address space
40944 This packet is only available in extended mode (@pxref{extended mode}).
40949 The request succeeded.
40952 An error occurred. The error number @var{nn} is given as hex digits.
40955 An empty reply indicates that @samp{QDisableRandomization} is not supported
40959 This packet is not probed by default; the remote stub must request it,
40960 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40961 This should only be done on targets that actually support disabling
40962 address space randomization.
40964 @item QStartupWithShell:@var{value}
40965 @cindex startup with shell, remote request
40966 @cindex @samp{QStartupWithShell} packet
40967 On UNIX-like targets, it is possible to start the inferior using a
40968 shell program. This is the default behavior on both @value{GDBN} and
40969 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40970 used to inform @command{gdbserver} whether it should start the
40971 inferior using a shell or not.
40973 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40974 to start the inferior. If @var{value} is @samp{1},
40975 @command{gdbserver} will use a shell to start the inferior. All other
40976 values are considered an error.
40978 This packet is only available in extended mode (@pxref{extended
40984 The request succeeded.
40987 An error occurred. The error number @var{nn} is given as hex digits.
40990 This packet is not probed by default; the remote stub must request it,
40991 by supplying an appropriate @samp{qSupported} response
40992 (@pxref{qSupported}). This should only be done on targets that
40993 actually support starting the inferior using a shell.
40995 Use of this packet is controlled by the @code{set startup-with-shell}
40996 command; @pxref{set startup-with-shell}.
40998 @item QEnvironmentHexEncoded:@var{hex-value}
40999 @anchor{QEnvironmentHexEncoded}
41000 @cindex set environment variable, remote request
41001 @cindex @samp{QEnvironmentHexEncoded} packet
41002 On UNIX-like targets, it is possible to set environment variables that
41003 will be passed to the inferior during the startup process. This
41004 packet is used to inform @command{gdbserver} of an environment
41005 variable that has been defined by the user on @value{GDBN} (@pxref{set
41008 The packet is composed by @var{hex-value}, an hex encoded
41009 representation of the @var{name=value} format representing an
41010 environment variable. The name of the environment variable is
41011 represented by @var{name}, and the value to be assigned to the
41012 environment variable is represented by @var{value}. If the variable
41013 has no value (i.e., the value is @code{null}), then @var{value} will
41016 This packet is only available in extended mode (@pxref{extended
41022 The request succeeded.
41025 This packet is not probed by default; the remote stub must request it,
41026 by supplying an appropriate @samp{qSupported} response
41027 (@pxref{qSupported}). This should only be done on targets that
41028 actually support passing environment variables to the starting
41031 This packet is related to the @code{set environment} command;
41032 @pxref{set environment}.
41034 @item QEnvironmentUnset:@var{hex-value}
41035 @anchor{QEnvironmentUnset}
41036 @cindex unset environment variable, remote request
41037 @cindex @samp{QEnvironmentUnset} packet
41038 On UNIX-like targets, it is possible to unset environment variables
41039 before starting the inferior in the remote target. This packet is
41040 used to inform @command{gdbserver} of an environment variable that has
41041 been unset by the user on @value{GDBN} (@pxref{unset environment}).
41043 The packet is composed by @var{hex-value}, an hex encoded
41044 representation of the name of the environment variable to be unset.
41046 This packet is only available in extended mode (@pxref{extended
41052 The request succeeded.
41055 This packet is not probed by default; the remote stub must request it,
41056 by supplying an appropriate @samp{qSupported} response
41057 (@pxref{qSupported}). This should only be done on targets that
41058 actually support passing environment variables to the starting
41061 This packet is related to the @code{unset environment} command;
41062 @pxref{unset environment}.
41064 @item QEnvironmentReset
41065 @anchor{QEnvironmentReset}
41066 @cindex reset environment, remote request
41067 @cindex @samp{QEnvironmentReset} packet
41068 On UNIX-like targets, this packet is used to reset the state of
41069 environment variables in the remote target before starting the
41070 inferior. In this context, reset means unsetting all environment
41071 variables that were previously set by the user (i.e., were not
41072 initially present in the environment). It is sent to
41073 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
41074 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
41075 (@pxref{QEnvironmentUnset}) packets.
41077 This packet is only available in extended mode (@pxref{extended
41083 The request succeeded.
41086 This packet is not probed by default; the remote stub must request it,
41087 by supplying an appropriate @samp{qSupported} response
41088 (@pxref{qSupported}). This should only be done on targets that
41089 actually support passing environment variables to the starting
41092 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
41093 @anchor{QSetWorkingDir packet}
41094 @cindex set working directory, remote request
41095 @cindex @samp{QSetWorkingDir} packet
41096 This packet is used to inform the remote server of the intended
41097 current working directory for programs that are going to be executed.
41099 The packet is composed by @var{directory}, an hex encoded
41100 representation of the directory that the remote inferior will use as
41101 its current working directory. If @var{directory} is an empty string,
41102 the remote server should reset the inferior's current working
41103 directory to its original, empty value.
41105 This packet is only available in extended mode (@pxref{extended
41111 The request succeeded.
41115 @itemx qsThreadInfo
41116 @cindex list active threads, remote request
41117 @cindex @samp{qfThreadInfo} packet
41118 @cindex @samp{qsThreadInfo} packet
41119 Obtain a list of all active thread IDs from the target (OS). Since there
41120 may be too many active threads to fit into one reply packet, this query
41121 works iteratively: it may require more than one query/reply sequence to
41122 obtain the entire list of threads. The first query of the sequence will
41123 be the @samp{qfThreadInfo} query; subsequent queries in the
41124 sequence will be the @samp{qsThreadInfo} query.
41126 NOTE: This packet replaces the @samp{qL} query (see below).
41130 @item m @var{thread-id}
41132 @item m @var{thread-id},@var{thread-id}@dots{}
41133 a comma-separated list of thread IDs
41135 (lower case letter @samp{L}) denotes end of list.
41138 In response to each query, the target will reply with a list of one or
41139 more thread IDs, separated by commas.
41140 @value{GDBN} will respond to each reply with a request for more thread
41141 ids (using the @samp{qs} form of the query), until the target responds
41142 with @samp{l} (lower-case ell, for @dfn{last}).
41143 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
41146 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
41147 initial connection with the remote target, and the very first thread ID
41148 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
41149 message. Therefore, the stub should ensure that the first thread ID in
41150 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
41152 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
41153 @cindex get thread-local storage address, remote request
41154 @cindex @samp{qGetTLSAddr} packet
41155 Fetch the address associated with thread local storage specified
41156 by @var{thread-id}, @var{offset}, and @var{lm}.
41158 @var{thread-id} is the thread ID associated with the
41159 thread for which to fetch the TLS address. @xref{thread-id syntax}.
41161 @var{offset} is the (big endian, hex encoded) offset associated with the
41162 thread local variable. (This offset is obtained from the debug
41163 information associated with the variable.)
41165 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
41166 load module associated with the thread local storage. For example,
41167 a @sc{gnu}/Linux system will pass the link map address of the shared
41168 object associated with the thread local storage under consideration.
41169 Other operating environments may choose to represent the load module
41170 differently, so the precise meaning of this parameter will vary.
41174 @item @var{XX}@dots{}
41175 Hex encoded (big endian) bytes representing the address of the thread
41176 local storage requested.
41179 An error occurred. The error number @var{nn} is given as hex digits.
41182 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
41185 @item qGetTIBAddr:@var{thread-id}
41186 @cindex get thread information block address
41187 @cindex @samp{qGetTIBAddr} packet
41188 Fetch address of the Windows OS specific Thread Information Block.
41190 @var{thread-id} is the thread ID associated with the thread.
41194 @item @var{XX}@dots{}
41195 Hex encoded (big endian) bytes representing the linear address of the
41196 thread information block.
41199 An error occured. This means that either the thread was not found, or the
41200 address could not be retrieved.
41203 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
41206 @item qL @var{startflag} @var{threadcount} @var{nextthread}
41207 Obtain thread information from RTOS. Where: @var{startflag} (one hex
41208 digit) is one to indicate the first query and zero to indicate a
41209 subsequent query; @var{threadcount} (two hex digits) is the maximum
41210 number of threads the response packet can contain; and @var{nextthread}
41211 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
41212 returned in the response as @var{argthread}.
41214 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
41218 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
41219 Where: @var{count} (two hex digits) is the number of threads being
41220 returned; @var{done} (one hex digit) is zero to indicate more threads
41221 and one indicates no further threads; @var{argthreadid} (eight hex
41222 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
41223 is a sequence of thread IDs, @var{threadid} (eight hex
41224 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
41227 @item qMemTags:@var{start address},@var{length}:@var{type}
41229 @cindex fetch memory tags
41230 @cindex @samp{qMemTags} packet
41231 Fetch memory tags of type @var{type} from the address range
41232 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41233 target is responsible for calculating how many tags will be returned, as this
41234 is architecture-specific.
41236 @var{start address} is the starting address of the memory range.
41238 @var{length} is the length, in bytes, of the memory range.
41240 @var{type} is the type of tag the request wants to fetch. The type is a signed
41245 @item @var{mxx}@dots{}
41246 Hex encoded sequence of uninterpreted bytes, @var{xx}@dots{}, representing the
41247 tags found in the requested memory range.
41250 An error occured. This means that fetching of memory tags failed for some
41254 An empty reply indicates that @samp{qMemTags} is not supported by the stub,
41255 although this should not happen given @value{GDBN} will only send this packet
41256 if the stub has advertised support for memory tagging via @samp{qSupported}.
41259 @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes}
41261 @cindex store memory tags
41262 @cindex @samp{QMemTags} packet
41263 Store memory tags of type @var{type} to the address range
41264 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41265 target is responsible for interpreting the type, the tag bytes and modifying
41266 the memory tag granules accordingly, given this is architecture-specific.
41268 The interpretation of how many tags (@var{nt}) should be written to how many
41269 memory tag granules (@var{ng}) is also architecture-specific. The behavior is
41270 implementation-specific, but the following is suggested.
41272 If the number of memory tags, @var{nt}, is greater than or equal to the
41273 number of memory tag granules, @var{ng}, only @var{ng} tags will be
41276 If @var{nt} is less than @var{ng}, the behavior is that of a fill operation,
41277 and the tag bytes will be used as a pattern that will get repeated until
41278 @var{ng} tags are stored.
41280 @var{start address} is the starting address of the memory range. The address
41281 does not have any restriction on alignment or size.
41283 @var{length} is the length, in bytes, of the memory range.
41285 @var{type} is the type of tag the request wants to fetch. The type is a signed
41288 @var{tag bytes} is a sequence of hex encoded uninterpreted bytes which will be
41289 interpreted by the target. Each pair of hex digits is interpreted as a
41295 The request was successful and the memory tag granules were modified
41299 An error occured. This means that modifying the memory tag granules failed
41303 An empty reply indicates that @samp{QMemTags} is not supported by the stub,
41304 although this should not happen given @value{GDBN} will only send this packet
41305 if the stub has advertised support for memory tagging via @samp{qSupported}.
41309 @cindex section offsets, remote request
41310 @cindex @samp{qOffsets} packet
41311 Get section offsets that the target used when relocating the downloaded
41316 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
41317 Relocate the @code{Text} section by @var{xxx} from its original address.
41318 Relocate the @code{Data} section by @var{yyy} from its original address.
41319 If the object file format provides segment information (e.g.@: @sc{elf}
41320 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
41321 segments by the supplied offsets.
41323 @emph{Note: while a @code{Bss} offset may be included in the response,
41324 @value{GDBN} ignores this and instead applies the @code{Data} offset
41325 to the @code{Bss} section.}
41327 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
41328 Relocate the first segment of the object file, which conventionally
41329 contains program code, to a starting address of @var{xxx}. If
41330 @samp{DataSeg} is specified, relocate the second segment, which
41331 conventionally contains modifiable data, to a starting address of
41332 @var{yyy}. @value{GDBN} will report an error if the object file
41333 does not contain segment information, or does not contain at least
41334 as many segments as mentioned in the reply. Extra segments are
41335 kept at fixed offsets relative to the last relocated segment.
41338 @item qP @var{mode} @var{thread-id}
41339 @cindex thread information, remote request
41340 @cindex @samp{qP} packet
41341 Returns information on @var{thread-id}. Where: @var{mode} is a hex
41342 encoded 32 bit mode; @var{thread-id} is a thread ID
41343 (@pxref{thread-id syntax}).
41345 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
41348 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
41352 @cindex non-stop mode, remote request
41353 @cindex @samp{QNonStop} packet
41355 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
41356 @xref{Remote Non-Stop}, for more information.
41361 The request succeeded.
41364 An error occurred. The error number @var{nn} is given as hex digits.
41367 An empty reply indicates that @samp{QNonStop} is not supported by
41371 This packet is not probed by default; the remote stub must request it,
41372 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41373 Use of this packet is controlled by the @code{set non-stop} command;
41374 @pxref{Non-Stop Mode}.
41376 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41377 @itemx QCatchSyscalls:0
41378 @cindex catch syscalls from inferior, remote request
41379 @cindex @samp{QCatchSyscalls} packet
41380 @anchor{QCatchSyscalls}
41381 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41382 catching syscalls from the inferior process.
41384 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41385 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41386 is listed, every system call should be reported.
41388 Note that if a syscall not in the list is reported, @value{GDBN} will
41389 still filter the event according to its own list from all corresponding
41390 @code{catch syscall} commands. However, it is more efficient to only
41391 report the requested syscalls.
41393 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41394 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
41396 If the inferior process execs, the state of @samp{QCatchSyscalls} is
41397 kept for the new process too. On targets where exec may affect syscall
41398 numbers, for example with exec between 32 and 64-bit processes, the
41399 client should send a new packet with the new syscall list.
41404 The request succeeded.
41407 An error occurred. @var{nn} are hex digits.
41410 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41414 Use of this packet is controlled by the @code{set remote catch-syscalls}
41415 command (@pxref{Remote Configuration, set remote catch-syscalls}).
41416 This packet is not probed by default; the remote stub must request it,
41417 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41419 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41420 @cindex pass signals to inferior, remote request
41421 @cindex @samp{QPassSignals} packet
41422 @anchor{QPassSignals}
41423 Each listed @var{signal} should be passed directly to the inferior process.
41424 Signals are numbered identically to continue packets and stop replies
41425 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41426 strictly greater than the previous item. These signals do not need to stop
41427 the inferior, or be reported to @value{GDBN}. All other signals should be
41428 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41429 combine; any earlier @samp{QPassSignals} list is completely replaced by the
41430 new list. This packet improves performance when using @samp{handle
41431 @var{signal} nostop noprint pass}.
41436 The request succeeded.
41439 An error occurred. The error number @var{nn} is given as hex digits.
41442 An empty reply indicates that @samp{QPassSignals} is not supported by
41446 Use of this packet is controlled by the @code{set remote pass-signals}
41447 command (@pxref{Remote Configuration, set remote pass-signals}).
41448 This packet is not probed by default; the remote stub must request it,
41449 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41451 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41452 @cindex signals the inferior may see, remote request
41453 @cindex @samp{QProgramSignals} packet
41454 @anchor{QProgramSignals}
41455 Each listed @var{signal} may be delivered to the inferior process.
41456 Others should be silently discarded.
41458 In some cases, the remote stub may need to decide whether to deliver a
41459 signal to the program or not without @value{GDBN} involvement. One
41460 example of that is while detaching --- the program's threads may have
41461 stopped for signals that haven't yet had a chance of being reported to
41462 @value{GDBN}, and so the remote stub can use the signal list specified
41463 by this packet to know whether to deliver or ignore those pending
41466 This does not influence whether to deliver a signal as requested by a
41467 resumption packet (@pxref{vCont packet}).
41469 Signals are numbered identically to continue packets and stop replies
41470 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41471 strictly greater than the previous item. Multiple
41472 @samp{QProgramSignals} packets do not combine; any earlier
41473 @samp{QProgramSignals} list is completely replaced by the new list.
41478 The request succeeded.
41481 An error occurred. The error number @var{nn} is given as hex digits.
41484 An empty reply indicates that @samp{QProgramSignals} is not supported
41488 Use of this packet is controlled by the @code{set remote program-signals}
41489 command (@pxref{Remote Configuration, set remote program-signals}).
41490 This packet is not probed by default; the remote stub must request it,
41491 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41493 @anchor{QThreadEvents}
41494 @item QThreadEvents:1
41495 @itemx QThreadEvents:0
41496 @cindex thread create/exit events, remote request
41497 @cindex @samp{QThreadEvents} packet
41499 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41500 reporting of thread create and exit events. @xref{thread create
41501 event}, for the reply specifications. For example, this is used in
41502 non-stop mode when @value{GDBN} stops a set of threads and
41503 synchronously waits for the their corresponding stop replies. Without
41504 exit events, if one of the threads exits, @value{GDBN} would hang
41505 forever not knowing that it should no longer expect a stop for that
41506 same thread. @value{GDBN} does not enable this feature unless the
41507 stub reports that it supports it by including @samp{QThreadEvents+} in
41508 its @samp{qSupported} reply.
41513 The request succeeded.
41516 An error occurred. The error number @var{nn} is given as hex digits.
41519 An empty reply indicates that @samp{QThreadEvents} is not supported by
41523 Use of this packet is controlled by the @code{set remote thread-events}
41524 command (@pxref{Remote Configuration, set remote thread-events}).
41526 @item qRcmd,@var{command}
41527 @cindex execute remote command, remote request
41528 @cindex @samp{qRcmd} packet
41529 @var{command} (hex encoded) is passed to the local interpreter for
41530 execution. Invalid commands should be reported using the output
41531 string. Before the final result packet, the target may also respond
41532 with a number of intermediate @samp{O@var{output}} console output
41533 packets. @emph{Implementors should note that providing access to a
41534 stubs's interpreter may have security implications}.
41539 A command response with no output.
41541 A command response with the hex encoded output string @var{OUTPUT}.
41543 Indicate a badly formed request.
41545 An empty reply indicates that @samp{qRcmd} is not recognized.
41548 (Note that the @code{qRcmd} packet's name is separated from the
41549 command by a @samp{,}, not a @samp{:}, contrary to the naming
41550 conventions above. Please don't use this packet as a model for new
41553 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
41554 @cindex searching memory, in remote debugging
41556 @cindex @samp{qSearch:memory} packet
41558 @cindex @samp{qSearch memory} packet
41559 @anchor{qSearch memory}
41560 Search @var{length} bytes at @var{address} for @var{search-pattern}.
41561 Both @var{address} and @var{length} are encoded in hex;
41562 @var{search-pattern} is a sequence of bytes, also hex encoded.
41567 The pattern was not found.
41569 The pattern was found at @var{address}.
41571 A badly formed request or an error was encountered while searching memory.
41573 An empty reply indicates that @samp{qSearch:memory} is not recognized.
41576 @item QStartNoAckMode
41577 @cindex @samp{QStartNoAckMode} packet
41578 @anchor{QStartNoAckMode}
41579 Request that the remote stub disable the normal @samp{+}/@samp{-}
41580 protocol acknowledgments (@pxref{Packet Acknowledgment}).
41585 The stub has switched to no-acknowledgment mode.
41586 @value{GDBN} acknowledges this response,
41587 but neither the stub nor @value{GDBN} shall send or expect further
41588 @samp{+}/@samp{-} acknowledgments in the current connection.
41590 An empty reply indicates that the stub does not support no-acknowledgment mode.
41593 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41594 @cindex supported packets, remote query
41595 @cindex features of the remote protocol
41596 @cindex @samp{qSupported} packet
41597 @anchor{qSupported}
41598 Tell the remote stub about features supported by @value{GDBN}, and
41599 query the stub for features it supports. This packet allows
41600 @value{GDBN} and the remote stub to take advantage of each others'
41601 features. @samp{qSupported} also consolidates multiple feature probes
41602 at startup, to improve @value{GDBN} performance---a single larger
41603 packet performs better than multiple smaller probe packets on
41604 high-latency links. Some features may enable behavior which must not
41605 be on by default, e.g.@: because it would confuse older clients or
41606 stubs. Other features may describe packets which could be
41607 automatically probed for, but are not. These features must be
41608 reported before @value{GDBN} will use them. This ``default
41609 unsupported'' behavior is not appropriate for all packets, but it
41610 helps to keep the initial connection time under control with new
41611 versions of @value{GDBN} which support increasing numbers of packets.
41615 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41616 The stub supports or does not support each returned @var{stubfeature},
41617 depending on the form of each @var{stubfeature} (see below for the
41620 An empty reply indicates that @samp{qSupported} is not recognized,
41621 or that no features needed to be reported to @value{GDBN}.
41624 The allowed forms for each feature (either a @var{gdbfeature} in the
41625 @samp{qSupported} packet, or a @var{stubfeature} in the response)
41629 @item @var{name}=@var{value}
41630 The remote protocol feature @var{name} is supported, and associated
41631 with the specified @var{value}. The format of @var{value} depends
41632 on the feature, but it must not include a semicolon.
41634 The remote protocol feature @var{name} is supported, and does not
41635 need an associated value.
41637 The remote protocol feature @var{name} is not supported.
41639 The remote protocol feature @var{name} may be supported, and
41640 @value{GDBN} should auto-detect support in some other way when it is
41641 needed. This form will not be used for @var{gdbfeature} notifications,
41642 but may be used for @var{stubfeature} responses.
41645 Whenever the stub receives a @samp{qSupported} request, the
41646 supplied set of @value{GDBN} features should override any previous
41647 request. This allows @value{GDBN} to put the stub in a known
41648 state, even if the stub had previously been communicating with
41649 a different version of @value{GDBN}.
41651 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41656 This feature indicates whether @value{GDBN} supports multiprocess
41657 extensions to the remote protocol. @value{GDBN} does not use such
41658 extensions unless the stub also reports that it supports them by
41659 including @samp{multiprocess+} in its @samp{qSupported} reply.
41660 @xref{multiprocess extensions}, for details.
41663 This feature indicates that @value{GDBN} supports the XML target
41664 description. If the stub sees @samp{xmlRegisters=} with target
41665 specific strings separated by a comma, it will report register
41669 This feature indicates whether @value{GDBN} supports the
41670 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41671 instruction reply packet}).
41674 This feature indicates whether @value{GDBN} supports the swbreak stop
41675 reason in stop replies. @xref{swbreak stop reason}, for details.
41678 This feature indicates whether @value{GDBN} supports the hwbreak stop
41679 reason in stop replies. @xref{swbreak stop reason}, for details.
41682 This feature indicates whether @value{GDBN} supports fork event
41683 extensions to the remote protocol. @value{GDBN} does not use such
41684 extensions unless the stub also reports that it supports them by
41685 including @samp{fork-events+} in its @samp{qSupported} reply.
41688 This feature indicates whether @value{GDBN} supports vfork event
41689 extensions to the remote protocol. @value{GDBN} does not use such
41690 extensions unless the stub also reports that it supports them by
41691 including @samp{vfork-events+} in its @samp{qSupported} reply.
41694 This feature indicates whether @value{GDBN} supports exec event
41695 extensions to the remote protocol. @value{GDBN} does not use such
41696 extensions unless the stub also reports that it supports them by
41697 including @samp{exec-events+} in its @samp{qSupported} reply.
41699 @item vContSupported
41700 This feature indicates whether @value{GDBN} wants to know the
41701 supported actions in the reply to @samp{vCont?} packet.
41704 Stubs should ignore any unknown values for
41705 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41706 packet supports receiving packets of unlimited length (earlier
41707 versions of @value{GDBN} may reject overly long responses). Additional values
41708 for @var{gdbfeature} may be defined in the future to let the stub take
41709 advantage of new features in @value{GDBN}, e.g.@: incompatible
41710 improvements in the remote protocol---the @samp{multiprocess} feature is
41711 an example of such a feature. The stub's reply should be independent
41712 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41713 describes all the features it supports, and then the stub replies with
41714 all the features it supports.
41716 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41717 responses, as long as each response uses one of the standard forms.
41719 Some features are flags. A stub which supports a flag feature
41720 should respond with a @samp{+} form response. Other features
41721 require values, and the stub should respond with an @samp{=}
41724 Each feature has a default value, which @value{GDBN} will use if
41725 @samp{qSupported} is not available or if the feature is not mentioned
41726 in the @samp{qSupported} response. The default values are fixed; a
41727 stub is free to omit any feature responses that match the defaults.
41729 Not all features can be probed, but for those which can, the probing
41730 mechanism is useful: in some cases, a stub's internal
41731 architecture may not allow the protocol layer to know some information
41732 about the underlying target in advance. This is especially common in
41733 stubs which may be configured for multiple targets.
41735 These are the currently defined stub features and their properties:
41737 @multitable @columnfractions 0.35 0.2 0.12 0.2
41738 @c NOTE: The first row should be @headitem, but we do not yet require
41739 @c a new enough version of Texinfo (4.7) to use @headitem.
41741 @tab Value Required
41745 @item @samp{PacketSize}
41750 @item @samp{qXfer:auxv:read}
41755 @item @samp{qXfer:btrace:read}
41760 @item @samp{qXfer:btrace-conf:read}
41765 @item @samp{qXfer:exec-file:read}
41770 @item @samp{qXfer:features:read}
41775 @item @samp{qXfer:libraries:read}
41780 @item @samp{qXfer:libraries-svr4:read}
41785 @item @samp{augmented-libraries-svr4-read}
41790 @item @samp{qXfer:memory-map:read}
41795 @item @samp{qXfer:sdata:read}
41800 @item @samp{qXfer:siginfo:read}
41805 @item @samp{qXfer:siginfo:write}
41810 @item @samp{qXfer:threads:read}
41815 @item @samp{qXfer:traceframe-info:read}
41820 @item @samp{qXfer:uib:read}
41825 @item @samp{qXfer:fdpic:read}
41830 @item @samp{Qbtrace:off}
41835 @item @samp{Qbtrace:bts}
41840 @item @samp{Qbtrace:pt}
41845 @item @samp{Qbtrace-conf:bts:size}
41850 @item @samp{Qbtrace-conf:pt:size}
41855 @item @samp{QNonStop}
41860 @item @samp{QCatchSyscalls}
41865 @item @samp{QPassSignals}
41870 @item @samp{QStartNoAckMode}
41875 @item @samp{multiprocess}
41880 @item @samp{ConditionalBreakpoints}
41885 @item @samp{ConditionalTracepoints}
41890 @item @samp{ReverseContinue}
41895 @item @samp{ReverseStep}
41900 @item @samp{TracepointSource}
41905 @item @samp{QAgent}
41910 @item @samp{QAllow}
41915 @item @samp{QDisableRandomization}
41920 @item @samp{EnableDisableTracepoints}
41925 @item @samp{QTBuffer:size}
41930 @item @samp{tracenz}
41935 @item @samp{BreakpointCommands}
41940 @item @samp{swbreak}
41945 @item @samp{hwbreak}
41950 @item @samp{fork-events}
41955 @item @samp{vfork-events}
41960 @item @samp{exec-events}
41965 @item @samp{QThreadEvents}
41970 @item @samp{no-resumed}
41975 @item @samp{memory-tagging}
41982 These are the currently defined stub features, in more detail:
41985 @cindex packet size, remote protocol
41986 @item PacketSize=@var{bytes}
41987 The remote stub can accept packets up to at least @var{bytes} in
41988 length. @value{GDBN} will send packets up to this size for bulk
41989 transfers, and will never send larger packets. This is a limit on the
41990 data characters in the packet, including the frame and checksum.
41991 There is no trailing NUL byte in a remote protocol packet; if the stub
41992 stores packets in a NUL-terminated format, it should allow an extra
41993 byte in its buffer for the NUL. If this stub feature is not supported,
41994 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41996 @item qXfer:auxv:read
41997 The remote stub understands the @samp{qXfer:auxv:read} packet
41998 (@pxref{qXfer auxiliary vector read}).
42000 @item qXfer:btrace:read
42001 The remote stub understands the @samp{qXfer:btrace:read}
42002 packet (@pxref{qXfer btrace read}).
42004 @item qXfer:btrace-conf:read
42005 The remote stub understands the @samp{qXfer:btrace-conf:read}
42006 packet (@pxref{qXfer btrace-conf read}).
42008 @item qXfer:exec-file:read
42009 The remote stub understands the @samp{qXfer:exec-file:read} packet
42010 (@pxref{qXfer executable filename read}).
42012 @item qXfer:features:read
42013 The remote stub understands the @samp{qXfer:features:read} packet
42014 (@pxref{qXfer target description read}).
42016 @item qXfer:libraries:read
42017 The remote stub understands the @samp{qXfer:libraries:read} packet
42018 (@pxref{qXfer library list read}).
42020 @item qXfer:libraries-svr4:read
42021 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
42022 (@pxref{qXfer svr4 library list read}).
42024 @item augmented-libraries-svr4-read
42025 The remote stub understands the augmented form of the
42026 @samp{qXfer:libraries-svr4:read} packet
42027 (@pxref{qXfer svr4 library list read}).
42029 @item qXfer:memory-map:read
42030 The remote stub understands the @samp{qXfer:memory-map:read} packet
42031 (@pxref{qXfer memory map read}).
42033 @item qXfer:sdata:read
42034 The remote stub understands the @samp{qXfer:sdata:read} packet
42035 (@pxref{qXfer sdata read}).
42037 @item qXfer:siginfo:read
42038 The remote stub understands the @samp{qXfer:siginfo:read} packet
42039 (@pxref{qXfer siginfo read}).
42041 @item qXfer:siginfo:write
42042 The remote stub understands the @samp{qXfer:siginfo:write} packet
42043 (@pxref{qXfer siginfo write}).
42045 @item qXfer:threads:read
42046 The remote stub understands the @samp{qXfer:threads:read} packet
42047 (@pxref{qXfer threads read}).
42049 @item qXfer:traceframe-info:read
42050 The remote stub understands the @samp{qXfer:traceframe-info:read}
42051 packet (@pxref{qXfer traceframe info read}).
42053 @item qXfer:uib:read
42054 The remote stub understands the @samp{qXfer:uib:read}
42055 packet (@pxref{qXfer unwind info block}).
42057 @item qXfer:fdpic:read
42058 The remote stub understands the @samp{qXfer:fdpic:read}
42059 packet (@pxref{qXfer fdpic loadmap read}).
42062 The remote stub understands the @samp{QNonStop} packet
42063 (@pxref{QNonStop}).
42065 @item QCatchSyscalls
42066 The remote stub understands the @samp{QCatchSyscalls} packet
42067 (@pxref{QCatchSyscalls}).
42070 The remote stub understands the @samp{QPassSignals} packet
42071 (@pxref{QPassSignals}).
42073 @item QStartNoAckMode
42074 The remote stub understands the @samp{QStartNoAckMode} packet and
42075 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
42078 @anchor{multiprocess extensions}
42079 @cindex multiprocess extensions, in remote protocol
42080 The remote stub understands the multiprocess extensions to the remote
42081 protocol syntax. The multiprocess extensions affect the syntax of
42082 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
42083 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
42084 replies. Note that reporting this feature indicates support for the
42085 syntactic extensions only, not that the stub necessarily supports
42086 debugging of more than one process at a time. The stub must not use
42087 multiprocess extensions in packet replies unless @value{GDBN} has also
42088 indicated it supports them in its @samp{qSupported} request.
42090 @item qXfer:osdata:read
42091 The remote stub understands the @samp{qXfer:osdata:read} packet
42092 ((@pxref{qXfer osdata read}).
42094 @item ConditionalBreakpoints
42095 The target accepts and implements evaluation of conditional expressions
42096 defined for breakpoints. The target will only report breakpoint triggers
42097 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
42099 @item ConditionalTracepoints
42100 The remote stub accepts and implements conditional expressions defined
42101 for tracepoints (@pxref{Tracepoint Conditions}).
42103 @item ReverseContinue
42104 The remote stub accepts and implements the reverse continue packet
42108 The remote stub accepts and implements the reverse step packet
42111 @item TracepointSource
42112 The remote stub understands the @samp{QTDPsrc} packet that supplies
42113 the source form of tracepoint definitions.
42116 The remote stub understands the @samp{QAgent} packet.
42119 The remote stub understands the @samp{QAllow} packet.
42121 @item QDisableRandomization
42122 The remote stub understands the @samp{QDisableRandomization} packet.
42124 @item StaticTracepoint
42125 @cindex static tracepoints, in remote protocol
42126 The remote stub supports static tracepoints.
42128 @item InstallInTrace
42129 @anchor{install tracepoint in tracing}
42130 The remote stub supports installing tracepoint in tracing.
42132 @item EnableDisableTracepoints
42133 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
42134 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
42135 to be enabled and disabled while a trace experiment is running.
42137 @item QTBuffer:size
42138 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
42139 packet that allows to change the size of the trace buffer.
42142 @cindex string tracing, in remote protocol
42143 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
42144 See @ref{Bytecode Descriptions} for details about the bytecode.
42146 @item BreakpointCommands
42147 @cindex breakpoint commands, in remote protocol
42148 The remote stub supports running a breakpoint's command list itself,
42149 rather than reporting the hit to @value{GDBN}.
42152 The remote stub understands the @samp{Qbtrace:off} packet.
42155 The remote stub understands the @samp{Qbtrace:bts} packet.
42158 The remote stub understands the @samp{Qbtrace:pt} packet.
42160 @item Qbtrace-conf:bts:size
42161 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
42163 @item Qbtrace-conf:pt:size
42164 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
42167 The remote stub reports the @samp{swbreak} stop reason for memory
42171 The remote stub reports the @samp{hwbreak} stop reason for hardware
42175 The remote stub reports the @samp{fork} stop reason for fork events.
42178 The remote stub reports the @samp{vfork} stop reason for vfork events
42179 and vforkdone events.
42182 The remote stub reports the @samp{exec} stop reason for exec events.
42184 @item vContSupported
42185 The remote stub reports the supported actions in the reply to
42186 @samp{vCont?} packet.
42188 @item QThreadEvents
42189 The remote stub understands the @samp{QThreadEvents} packet.
42192 The remote stub reports the @samp{N} stop reply.
42195 @item memory-tagging
42196 The remote stub supports and implements the required memory tagging
42197 functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and
42198 @samp{QMemTags} (@pxref{QMemTags}) packets.
42200 For AArch64 GNU/Linux systems, this feature also requires access to the
42201 @file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected.
42202 This is done via the @samp{vFile} requests.
42207 @cindex symbol lookup, remote request
42208 @cindex @samp{qSymbol} packet
42209 Notify the target that @value{GDBN} is prepared to serve symbol lookup
42210 requests. Accept requests from the target for the values of symbols.
42215 The target does not need to look up any (more) symbols.
42216 @item qSymbol:@var{sym_name}
42217 The target requests the value of symbol @var{sym_name} (hex encoded).
42218 @value{GDBN} may provide the value by using the
42219 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
42223 @item qSymbol:@var{sym_value}:@var{sym_name}
42224 Set the value of @var{sym_name} to @var{sym_value}.
42226 @var{sym_name} (hex encoded) is the name of a symbol whose value the
42227 target has previously requested.
42229 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
42230 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
42236 The target does not need to look up any (more) symbols.
42237 @item qSymbol:@var{sym_name}
42238 The target requests the value of a new symbol @var{sym_name} (hex
42239 encoded). @value{GDBN} will continue to supply the values of symbols
42240 (if available), until the target ceases to request them.
42245 @itemx QTDisconnected
42252 @itemx qTMinFTPILen
42254 @xref{Tracepoint Packets}.
42256 @item qThreadExtraInfo,@var{thread-id}
42257 @cindex thread attributes info, remote request
42258 @cindex @samp{qThreadExtraInfo} packet
42259 Obtain from the target OS a printable string description of thread
42260 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
42261 for the forms of @var{thread-id}. This
42262 string may contain anything that the target OS thinks is interesting
42263 for @value{GDBN} to tell the user about the thread. The string is
42264 displayed in @value{GDBN}'s @code{info threads} display. Some
42265 examples of possible thread extra info strings are @samp{Runnable}, or
42266 @samp{Blocked on Mutex}.
42270 @item @var{XX}@dots{}
42271 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
42272 comprising the printable string containing the extra information about
42273 the thread's attributes.
42276 (Note that the @code{qThreadExtraInfo} packet's name is separated from
42277 the command by a @samp{,}, not a @samp{:}, contrary to the naming
42278 conventions above. Please don't use this packet as a model for new
42297 @xref{Tracepoint Packets}.
42299 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
42300 @cindex read special object, remote request
42301 @cindex @samp{qXfer} packet
42302 @anchor{qXfer read}
42303 Read uninterpreted bytes from the target's special data area
42304 identified by the keyword @var{object}. Request @var{length} bytes
42305 starting at @var{offset} bytes into the data. The content and
42306 encoding of @var{annex} is specific to @var{object}; it can supply
42307 additional details about what data to access.
42312 Data @var{data} (@pxref{Binary Data}) has been read from the
42313 target. There may be more data at a higher address (although
42314 it is permitted to return @samp{m} even for the last valid
42315 block of data, as long as at least one byte of data was read).
42316 It is possible for @var{data} to have fewer bytes than the @var{length} in the
42320 Data @var{data} (@pxref{Binary Data}) has been read from the target.
42321 There is no more data to be read. It is possible for @var{data} to
42322 have fewer bytes than the @var{length} in the request.
42325 The @var{offset} in the request is at the end of the data.
42326 There is no more data to be read.
42329 The request was malformed, or @var{annex} was invalid.
42332 The offset was invalid, or there was an error encountered reading the data.
42333 The @var{nn} part is a hex-encoded @code{errno} value.
42336 An empty reply indicates the @var{object} string was not recognized by
42337 the stub, or that the object does not support reading.
42340 Here are the specific requests of this form defined so far. All the
42341 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
42342 formats, listed above.
42345 @item qXfer:auxv:read::@var{offset},@var{length}
42346 @anchor{qXfer auxiliary vector read}
42347 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
42348 auxiliary vector}. Note @var{annex} must be empty.
42350 This packet is not probed by default; the remote stub must request it,
42351 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42353 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
42354 @anchor{qXfer btrace read}
42356 Return a description of the current branch trace.
42357 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
42358 packet may have one of the following values:
42362 Returns all available branch trace.
42365 Returns all available branch trace if the branch trace changed since
42366 the last read request.
42369 Returns the new branch trace since the last read request. Adds a new
42370 block to the end of the trace that begins at zero and ends at the source
42371 location of the first branch in the trace buffer. This extra block is
42372 used to stitch traces together.
42374 If the trace buffer overflowed, returns an error indicating the overflow.
42377 This packet is not probed by default; the remote stub must request it
42378 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42380 @item qXfer:btrace-conf:read::@var{offset},@var{length}
42381 @anchor{qXfer btrace-conf read}
42383 Return a description of the current branch trace configuration.
42384 @xref{Branch Trace Configuration Format}.
42386 This packet is not probed by default; the remote stub must request it
42387 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42389 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42390 @anchor{qXfer executable filename read}
42391 Return the full absolute name of the file that was executed to create
42392 a process running on the remote system. The annex specifies the
42393 numeric process ID of the process to query, encoded as a hexadecimal
42394 number. If the annex part is empty the remote stub should return the
42395 filename corresponding to the currently executing process.
42397 This packet is not probed by default; the remote stub must request it,
42398 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42400 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42401 @anchor{qXfer target description read}
42402 Access the @dfn{target description}. @xref{Target Descriptions}. The
42403 annex specifies which XML document to access. The main description is
42404 always loaded from the @samp{target.xml} annex.
42406 This packet is not probed by default; the remote stub must request it,
42407 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42409 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42410 @anchor{qXfer library list read}
42411 Access the target's list of loaded libraries. @xref{Library List Format}.
42412 The annex part of the generic @samp{qXfer} packet must be empty
42413 (@pxref{qXfer read}).
42415 Targets which maintain a list of libraries in the program's memory do
42416 not need to implement this packet; it is designed for platforms where
42417 the operating system manages the list of loaded libraries.
42419 This packet is not probed by default; the remote stub must request it,
42420 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42422 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42423 @anchor{qXfer svr4 library list read}
42424 Access the target's list of loaded libraries when the target is an SVR4
42425 platform. @xref{Library List Format for SVR4 Targets}. The annex part
42426 of the generic @samp{qXfer} packet must be empty unless the remote
42427 stub indicated it supports the augmented form of this packet
42428 by supplying an appropriate @samp{qSupported} response
42429 (@pxref{qXfer read}, @ref{qSupported}).
42431 This packet is optional for better performance on SVR4 targets.
42432 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42434 This packet is not probed by default; the remote stub must request it,
42435 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42437 If the remote stub indicates it supports the augmented form of this
42438 packet then the annex part of the generic @samp{qXfer} packet may
42439 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42440 arguments. The currently supported arguments are:
42443 @item start=@var{address}
42444 A hexadecimal number specifying the address of the @samp{struct
42445 link_map} to start reading the library list from. If unset or zero
42446 then the first @samp{struct link_map} in the library list will be
42447 chosen as the starting point.
42449 @item prev=@var{address}
42450 A hexadecimal number specifying the address of the @samp{struct
42451 link_map} immediately preceding the @samp{struct link_map}
42452 specified by the @samp{start} argument. If unset or zero then
42453 the remote stub will expect that no @samp{struct link_map}
42454 exists prior to the starting point.
42458 Arguments that are not understood by the remote stub will be silently
42461 @item qXfer:memory-map:read::@var{offset},@var{length}
42462 @anchor{qXfer memory map read}
42463 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
42464 annex part of the generic @samp{qXfer} packet must be empty
42465 (@pxref{qXfer read}).
42467 This packet is not probed by default; the remote stub must request it,
42468 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42470 @item qXfer:sdata:read::@var{offset},@var{length}
42471 @anchor{qXfer sdata read}
42473 Read contents of the extra collected static tracepoint marker
42474 information. The annex part of the generic @samp{qXfer} packet must
42475 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42478 This packet is not probed by default; the remote stub must request it,
42479 by supplying an appropriate @samp{qSupported} response
42480 (@pxref{qSupported}).
42482 @item qXfer:siginfo:read::@var{offset},@var{length}
42483 @anchor{qXfer siginfo read}
42484 Read contents of the extra signal information on the target
42485 system. The annex part of the generic @samp{qXfer} packet must be
42486 empty (@pxref{qXfer read}).
42488 This packet is not probed by default; the remote stub must request it,
42489 by supplying an appropriate @samp{qSupported} response
42490 (@pxref{qSupported}).
42492 @item qXfer:threads:read::@var{offset},@var{length}
42493 @anchor{qXfer threads read}
42494 Access the list of threads on target. @xref{Thread List Format}. The
42495 annex part of the generic @samp{qXfer} packet must be empty
42496 (@pxref{qXfer read}).
42498 This packet is not probed by default; the remote stub must request it,
42499 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42501 @item qXfer:traceframe-info:read::@var{offset},@var{length}
42502 @anchor{qXfer traceframe info read}
42504 Return a description of the current traceframe's contents.
42505 @xref{Traceframe Info Format}. The annex part of the generic
42506 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
42508 This packet is not probed by default; the remote stub must request it,
42509 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42511 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
42512 @anchor{qXfer unwind info block}
42514 Return the unwind information block for @var{pc}. This packet is used
42515 on OpenVMS/ia64 to ask the kernel unwind information.
42517 This packet is not probed by default.
42519 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
42520 @anchor{qXfer fdpic loadmap read}
42521 Read contents of @code{loadmap}s on the target system. The
42522 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
42523 executable @code{loadmap} or interpreter @code{loadmap} to read.
42525 This packet is not probed by default; the remote stub must request it,
42526 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42528 @item qXfer:osdata:read::@var{offset},@var{length}
42529 @anchor{qXfer osdata read}
42530 Access the target's @dfn{operating system information}.
42531 @xref{Operating System Information}.
42535 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
42536 @cindex write data into object, remote request
42537 @anchor{qXfer write}
42538 Write uninterpreted bytes into the target's special data area
42539 identified by the keyword @var{object}, starting at @var{offset} bytes
42540 into the data. The binary-encoded data (@pxref{Binary Data}) to be
42541 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
42542 is specific to @var{object}; it can supply additional details about what data
42548 @var{nn} (hex encoded) is the number of bytes written.
42549 This may be fewer bytes than supplied in the request.
42552 The request was malformed, or @var{annex} was invalid.
42555 The offset was invalid, or there was an error encountered writing the data.
42556 The @var{nn} part is a hex-encoded @code{errno} value.
42559 An empty reply indicates the @var{object} string was not
42560 recognized by the stub, or that the object does not support writing.
42563 Here are the specific requests of this form defined so far. All the
42564 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
42565 formats, listed above.
42568 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
42569 @anchor{qXfer siginfo write}
42570 Write @var{data} to the extra signal information on the target system.
42571 The annex part of the generic @samp{qXfer} packet must be
42572 empty (@pxref{qXfer write}).
42574 This packet is not probed by default; the remote stub must request it,
42575 by supplying an appropriate @samp{qSupported} response
42576 (@pxref{qSupported}).
42579 @item qXfer:@var{object}:@var{operation}:@dots{}
42580 Requests of this form may be added in the future. When a stub does
42581 not recognize the @var{object} keyword, or its support for
42582 @var{object} does not recognize the @var{operation} keyword, the stub
42583 must respond with an empty packet.
42585 @item qAttached:@var{pid}
42586 @cindex query attached, remote request
42587 @cindex @samp{qAttached} packet
42588 Return an indication of whether the remote server attached to an
42589 existing process or created a new process. When the multiprocess
42590 protocol extensions are supported (@pxref{multiprocess extensions}),
42591 @var{pid} is an integer in hexadecimal format identifying the target
42592 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
42593 the query packet will be simplified as @samp{qAttached}.
42595 This query is used, for example, to know whether the remote process
42596 should be detached or killed when a @value{GDBN} session is ended with
42597 the @code{quit} command.
42602 The remote server attached to an existing process.
42604 The remote server created a new process.
42606 A badly formed request or an error was encountered.
42610 Enable branch tracing for the current thread using Branch Trace Store.
42615 Branch tracing has been enabled.
42617 A badly formed request or an error was encountered.
42621 Enable branch tracing for the current thread using Intel Processor Trace.
42626 Branch tracing has been enabled.
42628 A badly formed request or an error was encountered.
42632 Disable branch tracing for the current thread.
42637 Branch tracing has been disabled.
42639 A badly formed request or an error was encountered.
42642 @item Qbtrace-conf:bts:size=@var{value}
42643 Set the requested ring buffer size for new threads that use the
42644 btrace recording method in bts format.
42649 The ring buffer size has been set.
42651 A badly formed request or an error was encountered.
42654 @item Qbtrace-conf:pt:size=@var{value}
42655 Set the requested ring buffer size for new threads that use the
42656 btrace recording method in pt format.
42661 The ring buffer size has been set.
42663 A badly formed request or an error was encountered.
42668 @node Architecture-Specific Protocol Details
42669 @section Architecture-Specific Protocol Details
42671 This section describes how the remote protocol is applied to specific
42672 target architectures. Also see @ref{Standard Target Features}, for
42673 details of XML target descriptions for each architecture.
42676 * ARM-Specific Protocol Details::
42677 * MIPS-Specific Protocol Details::
42680 @node ARM-Specific Protocol Details
42681 @subsection @acronym{ARM}-specific Protocol Details
42684 * ARM Breakpoint Kinds::
42685 * ARM Memory Tag Types::
42688 @node ARM Breakpoint Kinds
42689 @subsubsection @acronym{ARM} Breakpoint Kinds
42690 @cindex breakpoint kinds, @acronym{ARM}
42692 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42697 16-bit Thumb mode breakpoint.
42700 32-bit Thumb mode (Thumb-2) breakpoint.
42703 32-bit @acronym{ARM} mode breakpoint.
42707 @node ARM Memory Tag Types
42708 @subsubsection @acronym{ARM} Memory Tag Types
42709 @cindex memory tag types, @acronym{ARM}
42711 These memory tag types are defined for the @samp{qMemTag} and @samp{QMemTag}
42724 @node MIPS-Specific Protocol Details
42725 @subsection @acronym{MIPS}-specific Protocol Details
42728 * MIPS Register packet Format::
42729 * MIPS Breakpoint Kinds::
42732 @node MIPS Register packet Format
42733 @subsubsection @acronym{MIPS} Register Packet Format
42734 @cindex register packet format, @acronym{MIPS}
42736 The following @code{g}/@code{G} packets have previously been defined.
42737 In the below, some thirty-two bit registers are transferred as
42738 sixty-four bits. Those registers should be zero/sign extended (which?)
42739 to fill the space allocated. Register bytes are transferred in target
42740 byte order. The two nibbles within a register byte are transferred
42741 most-significant -- least-significant.
42746 All registers are transferred as thirty-two bit quantities in the order:
42747 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42748 registers; fsr; fir; fp.
42751 All registers are transferred as sixty-four bit quantities (including
42752 thirty-two bit registers such as @code{sr}). The ordering is the same
42757 @node MIPS Breakpoint Kinds
42758 @subsubsection @acronym{MIPS} Breakpoint Kinds
42759 @cindex breakpoint kinds, @acronym{MIPS}
42761 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42766 16-bit @acronym{MIPS16} mode breakpoint.
42769 16-bit @acronym{microMIPS} mode breakpoint.
42772 32-bit standard @acronym{MIPS} mode breakpoint.
42775 32-bit @acronym{microMIPS} mode breakpoint.
42779 @node Tracepoint Packets
42780 @section Tracepoint Packets
42781 @cindex tracepoint packets
42782 @cindex packets, tracepoint
42784 Here we describe the packets @value{GDBN} uses to implement
42785 tracepoints (@pxref{Tracepoints}).
42789 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
42790 @cindex @samp{QTDP} packet
42791 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42792 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
42793 the tracepoint is disabled. The @var{step} gives the tracepoint's step
42794 count, and @var{pass} gives its pass count. If an @samp{F} is present,
42795 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42796 the number of bytes that the target should copy elsewhere to make room
42797 for the tracepoint. If an @samp{X} is present, it introduces a
42798 tracepoint condition, which consists of a hexadecimal length, followed
42799 by a comma and hex-encoded bytes, in a manner similar to action
42800 encodings as described below. If the trailing @samp{-} is present,
42801 further @samp{QTDP} packets will follow to specify this tracepoint's
42807 The packet was understood and carried out.
42809 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42811 The packet was not recognized.
42814 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42815 Define actions to be taken when a tracepoint is hit. The @var{n} and
42816 @var{addr} must be the same as in the initial @samp{QTDP} packet for
42817 this tracepoint. This packet may only be sent immediately after
42818 another @samp{QTDP} packet that ended with a @samp{-}. If the
42819 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42820 specifying more actions for this tracepoint.
42822 In the series of action packets for a given tracepoint, at most one
42823 can have an @samp{S} before its first @var{action}. If such a packet
42824 is sent, it and the following packets define ``while-stepping''
42825 actions. Any prior packets define ordinary actions --- that is, those
42826 taken when the tracepoint is first hit. If no action packet has an
42827 @samp{S}, then all the packets in the series specify ordinary
42828 tracepoint actions.
42830 The @samp{@var{action}@dots{}} portion of the packet is a series of
42831 actions, concatenated without separators. Each action has one of the
42837 Collect the registers whose bits are set in @var{mask},
42838 a hexadecimal number whose @var{i}'th bit is set if register number
42839 @var{i} should be collected. (The least significant bit is numbered
42840 zero.) Note that @var{mask} may be any number of digits long; it may
42841 not fit in a 32-bit word.
42843 @item M @var{basereg},@var{offset},@var{len}
42844 Collect @var{len} bytes of memory starting at the address in register
42845 number @var{basereg}, plus @var{offset}. If @var{basereg} is
42846 @samp{-1}, then the range has a fixed address: @var{offset} is the
42847 address of the lowest byte to collect. The @var{basereg},
42848 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
42849 values (the @samp{-1} value for @var{basereg} is a special case).
42851 @item X @var{len},@var{expr}
42852 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42853 it directs. The agent expression @var{expr} is as described in
42854 @ref{Agent Expressions}. Each byte of the expression is encoded as a
42855 two-digit hex number in the packet; @var{len} is the number of bytes
42856 in the expression (and thus one-half the number of hex digits in the
42861 Any number of actions may be packed together in a single @samp{QTDP}
42862 packet, as long as the packet does not exceed the maximum packet
42863 length (400 bytes, for many stubs). There may be only one @samp{R}
42864 action per tracepoint, and it must precede any @samp{M} or @samp{X}
42865 actions. Any registers referred to by @samp{M} and @samp{X} actions
42866 must be collected by a preceding @samp{R} action. (The
42867 ``while-stepping'' actions are treated as if they were attached to a
42868 separate tracepoint, as far as these restrictions are concerned.)
42873 The packet was understood and carried out.
42875 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42877 The packet was not recognized.
42880 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42881 @cindex @samp{QTDPsrc} packet
42882 Specify a source string of tracepoint @var{n} at address @var{addr}.
42883 This is useful to get accurate reproduction of the tracepoints
42884 originally downloaded at the beginning of the trace run. The @var{type}
42885 is the name of the tracepoint part, such as @samp{cond} for the
42886 tracepoint's conditional expression (see below for a list of types), while
42887 @var{bytes} is the string, encoded in hexadecimal.
42889 @var{start} is the offset of the @var{bytes} within the overall source
42890 string, while @var{slen} is the total length of the source string.
42891 This is intended for handling source strings that are longer than will
42892 fit in a single packet.
42893 @c Add detailed example when this info is moved into a dedicated
42894 @c tracepoint descriptions section.
42896 The available string types are @samp{at} for the location,
42897 @samp{cond} for the conditional, and @samp{cmd} for an action command.
42898 @value{GDBN} sends a separate packet for each command in the action
42899 list, in the same order in which the commands are stored in the list.
42901 The target does not need to do anything with source strings except
42902 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42905 Although this packet is optional, and @value{GDBN} will only send it
42906 if the target replies with @samp{TracepointSource} @xref{General
42907 Query Packets}, it makes both disconnected tracing and trace files
42908 much easier to use. Otherwise the user must be careful that the
42909 tracepoints in effect while looking at trace frames are identical to
42910 the ones in effect during the trace run; even a small discrepancy
42911 could cause @samp{tdump} not to work, or a particular trace frame not
42914 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42915 @cindex define trace state variable, remote request
42916 @cindex @samp{QTDV} packet
42917 Create a new trace state variable, number @var{n}, with an initial
42918 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42919 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42920 the option of not using this packet for initial values of zero; the
42921 target should simply create the trace state variables as they are
42922 mentioned in expressions. The value @var{builtin} should be 1 (one)
42923 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42924 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42925 @samp{qTsV} packet had it set. The contents of @var{name} is the
42926 hex-encoded name (without the leading @samp{$}) of the trace state
42929 @item QTFrame:@var{n}
42930 @cindex @samp{QTFrame} packet
42931 Select the @var{n}'th tracepoint frame from the buffer, and use the
42932 register and memory contents recorded there to answer subsequent
42933 request packets from @value{GDBN}.
42935 A successful reply from the stub indicates that the stub has found the
42936 requested frame. The response is a series of parts, concatenated
42937 without separators, describing the frame we selected. Each part has
42938 one of the following forms:
42942 The selected frame is number @var{n} in the trace frame buffer;
42943 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42944 was no frame matching the criteria in the request packet.
42947 The selected trace frame records a hit of tracepoint number @var{t};
42948 @var{t} is a hexadecimal number.
42952 @item QTFrame:pc:@var{addr}
42953 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42954 currently selected frame whose PC is @var{addr};
42955 @var{addr} is a hexadecimal number.
42957 @item QTFrame:tdp:@var{t}
42958 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42959 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42960 is a hexadecimal number.
42962 @item QTFrame:range:@var{start}:@var{end}
42963 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42964 currently selected frame whose PC is between @var{start} (inclusive)
42965 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42968 @item QTFrame:outside:@var{start}:@var{end}
42969 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42970 frame @emph{outside} the given range of addresses (exclusive).
42973 @cindex @samp{qTMinFTPILen} packet
42974 This packet requests the minimum length of instruction at which a fast
42975 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42976 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42977 it depends on the target system being able to create trampolines in
42978 the first 64K of memory, which might or might not be possible for that
42979 system. So the reply to this packet will be 4 if it is able to
42986 The minimum instruction length is currently unknown.
42988 The minimum instruction length is @var{length}, where @var{length}
42989 is a hexadecimal number greater or equal to 1. A reply
42990 of 1 means that a fast tracepoint may be placed on any instruction
42991 regardless of size.
42993 An error has occurred.
42995 An empty reply indicates that the request is not supported by the stub.
42999 @cindex @samp{QTStart} packet
43000 Begin the tracepoint experiment. Begin collecting data from
43001 tracepoint hits in the trace frame buffer. This packet supports the
43002 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
43003 instruction reply packet}).
43006 @cindex @samp{QTStop} packet
43007 End the tracepoint experiment. Stop collecting trace frames.
43009 @item QTEnable:@var{n}:@var{addr}
43011 @cindex @samp{QTEnable} packet
43012 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
43013 experiment. If the tracepoint was previously disabled, then collection
43014 of data from it will resume.
43016 @item QTDisable:@var{n}:@var{addr}
43018 @cindex @samp{QTDisable} packet
43019 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
43020 experiment. No more data will be collected from the tracepoint unless
43021 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
43024 @cindex @samp{QTinit} packet
43025 Clear the table of tracepoints, and empty the trace frame buffer.
43027 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
43028 @cindex @samp{QTro} packet
43029 Establish the given ranges of memory as ``transparent''. The stub
43030 will answer requests for these ranges from memory's current contents,
43031 if they were not collected as part of the tracepoint hit.
43033 @value{GDBN} uses this to mark read-only regions of memory, like those
43034 containing program code. Since these areas never change, they should
43035 still have the same contents they did when the tracepoint was hit, so
43036 there's no reason for the stub to refuse to provide their contents.
43038 @item QTDisconnected:@var{value}
43039 @cindex @samp{QTDisconnected} packet
43040 Set the choice to what to do with the tracing run when @value{GDBN}
43041 disconnects from the target. A @var{value} of 1 directs the target to
43042 continue the tracing run, while 0 tells the target to stop tracing if
43043 @value{GDBN} is no longer in the picture.
43046 @cindex @samp{qTStatus} packet
43047 Ask the stub if there is a trace experiment running right now.
43049 The reply has the form:
43053 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
43054 @var{running} is a single digit @code{1} if the trace is presently
43055 running, or @code{0} if not. It is followed by semicolon-separated
43056 optional fields that an agent may use to report additional status.
43060 If the trace is not running, the agent may report any of several
43061 explanations as one of the optional fields:
43066 No trace has been run yet.
43068 @item tstop[:@var{text}]:0
43069 The trace was stopped by a user-originated stop command. The optional
43070 @var{text} field is a user-supplied string supplied as part of the
43071 stop command (for instance, an explanation of why the trace was
43072 stopped manually). It is hex-encoded.
43075 The trace stopped because the trace buffer filled up.
43077 @item tdisconnected:0
43078 The trace stopped because @value{GDBN} disconnected from the target.
43080 @item tpasscount:@var{tpnum}
43081 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
43083 @item terror:@var{text}:@var{tpnum}
43084 The trace stopped because tracepoint @var{tpnum} had an error. The
43085 string @var{text} is available to describe the nature of the error
43086 (for instance, a divide by zero in the condition expression); it
43090 The trace stopped for some other reason.
43094 Additional optional fields supply statistical and other information.
43095 Although not required, they are extremely useful for users monitoring
43096 the progress of a trace run. If a trace has stopped, and these
43097 numbers are reported, they must reflect the state of the just-stopped
43102 @item tframes:@var{n}
43103 The number of trace frames in the buffer.
43105 @item tcreated:@var{n}
43106 The total number of trace frames created during the run. This may
43107 be larger than the trace frame count, if the buffer is circular.
43109 @item tsize:@var{n}
43110 The total size of the trace buffer, in bytes.
43112 @item tfree:@var{n}
43113 The number of bytes still unused in the buffer.
43115 @item circular:@var{n}
43116 The value of the circular trace buffer flag. @code{1} means that the
43117 trace buffer is circular and old trace frames will be discarded if
43118 necessary to make room, @code{0} means that the trace buffer is linear
43121 @item disconn:@var{n}
43122 The value of the disconnected tracing flag. @code{1} means that
43123 tracing will continue after @value{GDBN} disconnects, @code{0} means
43124 that the trace run will stop.
43128 @item qTP:@var{tp}:@var{addr}
43129 @cindex tracepoint status, remote request
43130 @cindex @samp{qTP} packet
43131 Ask the stub for the current state of tracepoint number @var{tp} at
43132 address @var{addr}.
43136 @item V@var{hits}:@var{usage}
43137 The tracepoint has been hit @var{hits} times so far during the trace
43138 run, and accounts for @var{usage} in the trace buffer. Note that
43139 @code{while-stepping} steps are not counted as separate hits, but the
43140 steps' space consumption is added into the usage number.
43144 @item qTV:@var{var}
43145 @cindex trace state variable value, remote request
43146 @cindex @samp{qTV} packet
43147 Ask the stub for the value of the trace state variable number @var{var}.
43152 The value of the variable is @var{value}. This will be the current
43153 value of the variable if the user is examining a running target, or a
43154 saved value if the variable was collected in the trace frame that the
43155 user is looking at. Note that multiple requests may result in
43156 different reply values, such as when requesting values while the
43157 program is running.
43160 The value of the variable is unknown. This would occur, for example,
43161 if the user is examining a trace frame in which the requested variable
43166 @cindex @samp{qTfP} packet
43168 @cindex @samp{qTsP} packet
43169 These packets request data about tracepoints that are being used by
43170 the target. @value{GDBN} sends @code{qTfP} to get the first piece
43171 of data, and multiple @code{qTsP} to get additional pieces. Replies
43172 to these packets generally take the form of the @code{QTDP} packets
43173 that define tracepoints. (FIXME add detailed syntax)
43176 @cindex @samp{qTfV} packet
43178 @cindex @samp{qTsV} packet
43179 These packets request data about trace state variables that are on the
43180 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
43181 and multiple @code{qTsV} to get additional variables. Replies to
43182 these packets follow the syntax of the @code{QTDV} packets that define
43183 trace state variables.
43189 @cindex @samp{qTfSTM} packet
43190 @cindex @samp{qTsSTM} packet
43191 These packets request data about static tracepoint markers that exist
43192 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
43193 first piece of data, and multiple @code{qTsSTM} to get additional
43194 pieces. Replies to these packets take the following form:
43198 @item m @var{address}:@var{id}:@var{extra}
43200 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
43201 a comma-separated list of markers
43203 (lower case letter @samp{L}) denotes end of list.
43205 An error occurred. The error number @var{nn} is given as hex digits.
43207 An empty reply indicates that the request is not supported by the
43211 The @var{address} is encoded in hex;
43212 @var{id} and @var{extra} are strings encoded in hex.
43214 In response to each query, the target will reply with a list of one or
43215 more markers, separated by commas. @value{GDBN} will respond to each
43216 reply with a request for more markers (using the @samp{qs} form of the
43217 query), until the target responds with @samp{l} (lower-case ell, for
43220 @item qTSTMat:@var{address}
43222 @cindex @samp{qTSTMat} packet
43223 This packets requests data about static tracepoint markers in the
43224 target program at @var{address}. Replies to this packet follow the
43225 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
43226 tracepoint markers.
43228 @item QTSave:@var{filename}
43229 @cindex @samp{QTSave} packet
43230 This packet directs the target to save trace data to the file name
43231 @var{filename} in the target's filesystem. The @var{filename} is encoded
43232 as a hex string; the interpretation of the file name (relative vs
43233 absolute, wild cards, etc) is up to the target.
43235 @item qTBuffer:@var{offset},@var{len}
43236 @cindex @samp{qTBuffer} packet
43237 Return up to @var{len} bytes of the current contents of trace buffer,
43238 starting at @var{offset}. The trace buffer is treated as if it were
43239 a contiguous collection of traceframes, as per the trace file format.
43240 The reply consists as many hex-encoded bytes as the target can deliver
43241 in a packet; it is not an error to return fewer than were asked for.
43242 A reply consisting of just @code{l} indicates that no bytes are
43245 @item QTBuffer:circular:@var{value}
43246 This packet directs the target to use a circular trace buffer if
43247 @var{value} is 1, or a linear buffer if the value is 0.
43249 @item QTBuffer:size:@var{size}
43250 @anchor{QTBuffer-size}
43251 @cindex @samp{QTBuffer size} packet
43252 This packet directs the target to make the trace buffer be of size
43253 @var{size} if possible. A value of @code{-1} tells the target to
43254 use whatever size it prefers.
43256 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
43257 @cindex @samp{QTNotes} packet
43258 This packet adds optional textual notes to the trace run. Allowable
43259 types include @code{user}, @code{notes}, and @code{tstop}, the
43260 @var{text} fields are arbitrary strings, hex-encoded.
43264 @subsection Relocate instruction reply packet
43265 When installing fast tracepoints in memory, the target may need to
43266 relocate the instruction currently at the tracepoint address to a
43267 different address in memory. For most instructions, a simple copy is
43268 enough, but, for example, call instructions that implicitly push the
43269 return address on the stack, and relative branches or other
43270 PC-relative instructions require offset adjustment, so that the effect
43271 of executing the instruction at a different address is the same as if
43272 it had executed in the original location.
43274 In response to several of the tracepoint packets, the target may also
43275 respond with a number of intermediate @samp{qRelocInsn} request
43276 packets before the final result packet, to have @value{GDBN} handle
43277 this relocation operation. If a packet supports this mechanism, its
43278 documentation will explicitly say so. See for example the above
43279 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
43280 format of the request is:
43283 @item qRelocInsn:@var{from};@var{to}
43285 This requests @value{GDBN} to copy instruction at address @var{from}
43286 to address @var{to}, possibly adjusted so that executing the
43287 instruction at @var{to} has the same effect as executing it at
43288 @var{from}. @value{GDBN} writes the adjusted instruction to target
43289 memory starting at @var{to}.
43294 @item qRelocInsn:@var{adjusted_size}
43295 Informs the stub the relocation is complete. The @var{adjusted_size} is
43296 the length in bytes of resulting relocated instruction sequence.
43298 A badly formed request was detected, or an error was encountered while
43299 relocating the instruction.
43302 @node Host I/O Packets
43303 @section Host I/O Packets
43304 @cindex Host I/O, remote protocol
43305 @cindex file transfer, remote protocol
43307 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
43308 operations on the far side of a remote link. For example, Host I/O is
43309 used to upload and download files to a remote target with its own
43310 filesystem. Host I/O uses the same constant values and data structure
43311 layout as the target-initiated File-I/O protocol. However, the
43312 Host I/O packets are structured differently. The target-initiated
43313 protocol relies on target memory to store parameters and buffers.
43314 Host I/O requests are initiated by @value{GDBN}, and the
43315 target's memory is not involved. @xref{File-I/O Remote Protocol
43316 Extension}, for more details on the target-initiated protocol.
43318 The Host I/O request packets all encode a single operation along with
43319 its arguments. They have this format:
43323 @item vFile:@var{operation}: @var{parameter}@dots{}
43324 @var{operation} is the name of the particular request; the target
43325 should compare the entire packet name up to the second colon when checking
43326 for a supported operation. The format of @var{parameter} depends on
43327 the operation. Numbers are always passed in hexadecimal. Negative
43328 numbers have an explicit minus sign (i.e.@: two's complement is not
43329 used). Strings (e.g.@: filenames) are encoded as a series of
43330 hexadecimal bytes. The last argument to a system call may be a
43331 buffer of escaped binary data (@pxref{Binary Data}).
43335 The valid responses to Host I/O packets are:
43339 @item F @var{result} [, @var{errno}] [; @var{attachment}]
43340 @var{result} is the integer value returned by this operation, usually
43341 non-negative for success and -1 for errors. If an error has occured,
43342 @var{errno} will be included in the result specifying a
43343 value defined by the File-I/O protocol (@pxref{Errno Values}). For
43344 operations which return data, @var{attachment} supplies the data as a
43345 binary buffer. Binary buffers in response packets are escaped in the
43346 normal way (@pxref{Binary Data}). See the individual packet
43347 documentation for the interpretation of @var{result} and
43351 An empty response indicates that this operation is not recognized.
43355 These are the supported Host I/O operations:
43358 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
43359 Open a file at @var{filename} and return a file descriptor for it, or
43360 return -1 if an error occurs. The @var{filename} is a string,
43361 @var{flags} is an integer indicating a mask of open flags
43362 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
43363 of mode bits to use if the file is created (@pxref{mode_t Values}).
43364 @xref{open}, for details of the open flags and mode values.
43366 @item vFile:close: @var{fd}
43367 Close the open file corresponding to @var{fd} and return 0, or
43368 -1 if an error occurs.
43370 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
43371 Read data from the open file corresponding to @var{fd}. Up to
43372 @var{count} bytes will be read from the file, starting at @var{offset}
43373 relative to the start of the file. The target may read fewer bytes;
43374 common reasons include packet size limits and an end-of-file
43375 condition. The number of bytes read is returned. Zero should only be
43376 returned for a successful read at the end of the file, or if
43377 @var{count} was zero.
43379 The data read should be returned as a binary attachment on success.
43380 If zero bytes were read, the response should include an empty binary
43381 attachment (i.e.@: a trailing semicolon). The return value is the
43382 number of target bytes read; the binary attachment may be longer if
43383 some characters were escaped.
43385 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
43386 Write @var{data} (a binary buffer) to the open file corresponding
43387 to @var{fd}. Start the write at @var{offset} from the start of the
43388 file. Unlike many @code{write} system calls, there is no
43389 separate @var{count} argument; the length of @var{data} in the
43390 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
43391 which may be shorter than the length of @var{data}, or -1 if an
43394 @item vFile:fstat: @var{fd}
43395 Get information about the open file corresponding to @var{fd}.
43396 On success the information is returned as a binary attachment
43397 and the return value is the size of this attachment in bytes.
43398 If an error occurs the return value is -1. The format of the
43399 returned binary attachment is as described in @ref{struct stat}.
43401 @item vFile:unlink: @var{filename}
43402 Delete the file at @var{filename} on the target. Return 0,
43403 or -1 if an error occurs. The @var{filename} is a string.
43405 @item vFile:readlink: @var{filename}
43406 Read value of symbolic link @var{filename} on the target. Return
43407 the number of bytes read, or -1 if an error occurs.
43409 The data read should be returned as a binary attachment on success.
43410 If zero bytes were read, the response should include an empty binary
43411 attachment (i.e.@: a trailing semicolon). The return value is the
43412 number of target bytes read; the binary attachment may be longer if
43413 some characters were escaped.
43415 @item vFile:setfs: @var{pid}
43416 Select the filesystem on which @code{vFile} operations with
43417 @var{filename} arguments will operate. This is required for
43418 @value{GDBN} to be able to access files on remote targets where
43419 the remote stub does not share a common filesystem with the
43422 If @var{pid} is nonzero, select the filesystem as seen by process
43423 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
43424 the remote stub. Return 0 on success, or -1 if an error occurs.
43425 If @code{vFile:setfs:} indicates success, the selected filesystem
43426 remains selected until the next successful @code{vFile:setfs:}
43432 @section Interrupts
43433 @cindex interrupts (remote protocol)
43434 @anchor{interrupting remote targets}
43436 In all-stop mode, when a program on the remote target is running,
43437 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43438 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43439 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
43441 The precise meaning of @code{BREAK} is defined by the transport
43442 mechanism and may, in fact, be undefined. @value{GDBN} does not
43443 currently define a @code{BREAK} mechanism for any of the network
43444 interfaces except for TCP, in which case @value{GDBN} sends the
43445 @code{telnet} BREAK sequence.
43447 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
43448 transport mechanisms. It is represented by sending the single byte
43449 @code{0x03} without any of the usual packet overhead described in
43450 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43451 transmitted as part of a packet, it is considered to be packet data
43452 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
43453 (@pxref{X packet}), used for binary downloads, may include an unescaped
43454 @code{0x03} as part of its packet.
43456 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43457 When Linux kernel receives this sequence from serial port,
43458 it stops execution and connects to gdb.
43460 In non-stop mode, because packet resumptions are asynchronous
43461 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43462 command to the remote stub, even when the target is running. For that
43463 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43464 packet}) with the usual packet framing instead of the single byte
43467 Stubs are not required to recognize these interrupt mechanisms and the
43468 precise meaning associated with receipt of the interrupt is
43469 implementation defined. If the target supports debugging of multiple
43470 threads and/or processes, it should attempt to interrupt all
43471 currently-executing threads and processes.
43472 If the stub is successful at interrupting the
43473 running program, it should send one of the stop
43474 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43475 of successfully stopping the program in all-stop mode, and a stop reply
43476 for each stopped thread in non-stop mode.
43477 Interrupts received while the
43478 program is stopped are queued and the program will be interrupted when
43479 it is resumed next time.
43481 @node Notification Packets
43482 @section Notification Packets
43483 @cindex notification packets
43484 @cindex packets, notification
43486 The @value{GDBN} remote serial protocol includes @dfn{notifications},
43487 packets that require no acknowledgment. Both the GDB and the stub
43488 may send notifications (although the only notifications defined at
43489 present are sent by the stub). Notifications carry information
43490 without incurring the round-trip latency of an acknowledgment, and so
43491 are useful for low-impact communications where occasional packet loss
43494 A notification packet has the form @samp{% @var{data} #
43495 @var{checksum}}, where @var{data} is the content of the notification,
43496 and @var{checksum} is a checksum of @var{data}, computed and formatted
43497 as for ordinary @value{GDBN} packets. A notification's @var{data}
43498 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43499 receiving a notification, the recipient sends no @samp{+} or @samp{-}
43500 to acknowledge the notification's receipt or to report its corruption.
43502 Every notification's @var{data} begins with a name, which contains no
43503 colon characters, followed by a colon character.
43505 Recipients should silently ignore corrupted notifications and
43506 notifications they do not understand. Recipients should restart
43507 timeout periods on receipt of a well-formed notification, whether or
43508 not they understand it.
43510 Senders should only send the notifications described here when this
43511 protocol description specifies that they are permitted. In the
43512 future, we may extend the protocol to permit existing notifications in
43513 new contexts; this rule helps older senders avoid confusing newer
43516 (Older versions of @value{GDBN} ignore bytes received until they see
43517 the @samp{$} byte that begins an ordinary packet, so new stubs may
43518 transmit notifications without fear of confusing older clients. There
43519 are no notifications defined for @value{GDBN} to send at the moment, but we
43520 assume that most older stubs would ignore them, as well.)
43522 Each notification is comprised of three parts:
43524 @item @var{name}:@var{event}
43525 The notification packet is sent by the side that initiates the
43526 exchange (currently, only the stub does that), with @var{event}
43527 carrying the specific information about the notification, and
43528 @var{name} specifying the name of the notification.
43530 The acknowledge sent by the other side, usually @value{GDBN}, to
43531 acknowledge the exchange and request the event.
43534 The purpose of an asynchronous notification mechanism is to report to
43535 @value{GDBN} that something interesting happened in the remote stub.
43537 The remote stub may send notification @var{name}:@var{event}
43538 at any time, but @value{GDBN} acknowledges the notification when
43539 appropriate. The notification event is pending before @value{GDBN}
43540 acknowledges. Only one notification at a time may be pending; if
43541 additional events occur before @value{GDBN} has acknowledged the
43542 previous notification, they must be queued by the stub for later
43543 synchronous transmission in response to @var{ack} packets from
43544 @value{GDBN}. Because the notification mechanism is unreliable,
43545 the stub is permitted to resend a notification if it believes
43546 @value{GDBN} may not have received it.
43548 Specifically, notifications may appear when @value{GDBN} is not
43549 otherwise reading input from the stub, or when @value{GDBN} is
43550 expecting to read a normal synchronous response or a
43551 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
43552 Notification packets are distinct from any other communication from
43553 the stub so there is no ambiguity.
43555 After receiving a notification, @value{GDBN} shall acknowledge it by
43556 sending a @var{ack} packet as a regular, synchronous request to the
43557 stub. Such acknowledgment is not required to happen immediately, as
43558 @value{GDBN} is permitted to send other, unrelated packets to the
43559 stub first, which the stub should process normally.
43561 Upon receiving a @var{ack} packet, if the stub has other queued
43562 events to report to @value{GDBN}, it shall respond by sending a
43563 normal @var{event}. @value{GDBN} shall then send another @var{ack}
43564 packet to solicit further responses; again, it is permitted to send
43565 other, unrelated packets as well which the stub should process
43568 If the stub receives a @var{ack} packet and there are no additional
43569 @var{event} to report, the stub shall return an @samp{OK} response.
43570 At this point, @value{GDBN} has finished processing a notification
43571 and the stub has completed sending any queued events. @value{GDBN}
43572 won't accept any new notifications until the final @samp{OK} is
43573 received . If further notification events occur, the stub shall send
43574 a new notification, @value{GDBN} shall accept the notification, and
43575 the process shall be repeated.
43577 The process of asynchronous notification can be illustrated by the
43580 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
43583 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
43585 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
43590 The following notifications are defined:
43591 @multitable @columnfractions 0.12 0.12 0.38 0.38
43600 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
43601 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
43602 for information on how these notifications are acknowledged by
43604 @tab Report an asynchronous stop event in non-stop mode.
43608 @node Remote Non-Stop
43609 @section Remote Protocol Support for Non-Stop Mode
43611 @value{GDBN}'s remote protocol supports non-stop debugging of
43612 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
43613 supports non-stop mode, it should report that to @value{GDBN} by including
43614 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
43616 @value{GDBN} typically sends a @samp{QNonStop} packet only when
43617 establishing a new connection with the stub. Entering non-stop mode
43618 does not alter the state of any currently-running threads, but targets
43619 must stop all threads in any already-attached processes when entering
43620 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
43621 probe the target state after a mode change.
43623 In non-stop mode, when an attached process encounters an event that
43624 would otherwise be reported with a stop reply, it uses the
43625 asynchronous notification mechanism (@pxref{Notification Packets}) to
43626 inform @value{GDBN}. In contrast to all-stop mode, where all threads
43627 in all processes are stopped when a stop reply is sent, in non-stop
43628 mode only the thread reporting the stop event is stopped. That is,
43629 when reporting a @samp{S} or @samp{T} response to indicate completion
43630 of a step operation, hitting a breakpoint, or a fault, only the
43631 affected thread is stopped; any other still-running threads continue
43632 to run. When reporting a @samp{W} or @samp{X} response, all running
43633 threads belonging to other attached processes continue to run.
43635 In non-stop mode, the target shall respond to the @samp{?} packet as
43636 follows. First, any incomplete stop reply notification/@samp{vStopped}
43637 sequence in progress is abandoned. The target must begin a new
43638 sequence reporting stop events for all stopped threads, whether or not
43639 it has previously reported those events to @value{GDBN}. The first
43640 stop reply is sent as a synchronous reply to the @samp{?} packet, and
43641 subsequent stop replies are sent as responses to @samp{vStopped} packets
43642 using the mechanism described above. The target must not send
43643 asynchronous stop reply notifications until the sequence is complete.
43644 If all threads are running when the target receives the @samp{?} packet,
43645 or if the target is not attached to any process, it shall respond
43648 If the stub supports non-stop mode, it should also support the
43649 @samp{swbreak} stop reason if software breakpoints are supported, and
43650 the @samp{hwbreak} stop reason if hardware breakpoints are supported
43651 (@pxref{swbreak stop reason}). This is because given the asynchronous
43652 nature of non-stop mode, between the time a thread hits a breakpoint
43653 and the time the event is finally processed by @value{GDBN}, the
43654 breakpoint may have already been removed from the target. Due to
43655 this, @value{GDBN} needs to be able to tell whether a trap stop was
43656 caused by a delayed breakpoint event, which should be ignored, as
43657 opposed to a random trap signal, which should be reported to the user.
43658 Note the @samp{swbreak} feature implies that the target is responsible
43659 for adjusting the PC when a software breakpoint triggers, if
43660 necessary, such as on the x86 architecture.
43662 @node Packet Acknowledgment
43663 @section Packet Acknowledgment
43665 @cindex acknowledgment, for @value{GDBN} remote
43666 @cindex packet acknowledgment, for @value{GDBN} remote
43667 By default, when either the host or the target machine receives a packet,
43668 the first response expected is an acknowledgment: either @samp{+} (to indicate
43669 the package was received correctly) or @samp{-} (to request retransmission).
43670 This mechanism allows the @value{GDBN} remote protocol to operate over
43671 unreliable transport mechanisms, such as a serial line.
43673 In cases where the transport mechanism is itself reliable (such as a pipe or
43674 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43675 It may be desirable to disable them in that case to reduce communication
43676 overhead, or for other reasons. This can be accomplished by means of the
43677 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43679 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43680 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43681 and response format still includes the normal checksum, as described in
43682 @ref{Overview}, but the checksum may be ignored by the receiver.
43684 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43685 no-acknowledgment mode, it should report that to @value{GDBN}
43686 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43687 @pxref{qSupported}.
43688 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43689 disabled via the @code{set remote noack-packet off} command
43690 (@pxref{Remote Configuration}),
43691 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43692 Only then may the stub actually turn off packet acknowledgments.
43693 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43694 response, which can be safely ignored by the stub.
43696 Note that @code{set remote noack-packet} command only affects negotiation
43697 between @value{GDBN} and the stub when subsequent connections are made;
43698 it does not affect the protocol acknowledgment state for any current
43700 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43701 new connection is established,
43702 there is also no protocol request to re-enable the acknowledgments
43703 for the current connection, once disabled.
43708 Example sequence of a target being re-started. Notice how the restart
43709 does not get any direct output:
43714 @emph{target restarts}
43717 <- @code{T001:1234123412341234}
43721 Example sequence of a target being stepped by a single instruction:
43724 -> @code{G1445@dots{}}
43729 <- @code{T001:1234123412341234}
43733 <- @code{1455@dots{}}
43737 @node File-I/O Remote Protocol Extension
43738 @section File-I/O Remote Protocol Extension
43739 @cindex File-I/O remote protocol extension
43742 * File-I/O Overview::
43743 * Protocol Basics::
43744 * The F Request Packet::
43745 * The F Reply Packet::
43746 * The Ctrl-C Message::
43748 * List of Supported Calls::
43749 * Protocol-specific Representation of Datatypes::
43751 * File-I/O Examples::
43754 @node File-I/O Overview
43755 @subsection File-I/O Overview
43756 @cindex file-i/o overview
43758 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
43759 target to use the host's file system and console I/O to perform various
43760 system calls. System calls on the target system are translated into a
43761 remote protocol packet to the host system, which then performs the needed
43762 actions and returns a response packet to the target system.
43763 This simulates file system operations even on targets that lack file systems.
43765 The protocol is defined to be independent of both the host and target systems.
43766 It uses its own internal representation of datatypes and values. Both
43767 @value{GDBN} and the target's @value{GDBN} stub are responsible for
43768 translating the system-dependent value representations into the internal
43769 protocol representations when data is transmitted.
43771 The communication is synchronous. A system call is possible only when
43772 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43773 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
43774 the target is stopped to allow deterministic access to the target's
43775 memory. Therefore File-I/O is not interruptible by target signals. On
43776 the other hand, it is possible to interrupt File-I/O by a user interrupt
43777 (@samp{Ctrl-C}) within @value{GDBN}.
43779 The target's request to perform a host system call does not finish
43780 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43781 after finishing the system call, the target returns to continuing the
43782 previous activity (continue, step). No additional continue or step
43783 request from @value{GDBN} is required.
43786 (@value{GDBP}) continue
43787 <- target requests 'system call X'
43788 target is stopped, @value{GDBN} executes system call
43789 -> @value{GDBN} returns result
43790 ... target continues, @value{GDBN} returns to wait for the target
43791 <- target hits breakpoint and sends a Txx packet
43794 The protocol only supports I/O on the console and to regular files on
43795 the host file system. Character or block special devices, pipes,
43796 named pipes, sockets or any other communication method on the host
43797 system are not supported by this protocol.
43799 File I/O is not supported in non-stop mode.
43801 @node Protocol Basics
43802 @subsection Protocol Basics
43803 @cindex protocol basics, file-i/o
43805 The File-I/O protocol uses the @code{F} packet as the request as well
43806 as reply packet. Since a File-I/O system call can only occur when
43807 @value{GDBN} is waiting for a response from the continuing or stepping target,
43808 the File-I/O request is a reply that @value{GDBN} has to expect as a result
43809 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43810 This @code{F} packet contains all information needed to allow @value{GDBN}
43811 to call the appropriate host system call:
43815 A unique identifier for the requested system call.
43818 All parameters to the system call. Pointers are given as addresses
43819 in the target memory address space. Pointers to strings are given as
43820 pointer/length pair. Numerical values are given as they are.
43821 Numerical control flags are given in a protocol-specific representation.
43825 At this point, @value{GDBN} has to perform the following actions.
43829 If the parameters include pointer values to data needed as input to a
43830 system call, @value{GDBN} requests this data from the target with a
43831 standard @code{m} packet request. This additional communication has to be
43832 expected by the target implementation and is handled as any other @code{m}
43836 @value{GDBN} translates all value from protocol representation to host
43837 representation as needed. Datatypes are coerced into the host types.
43840 @value{GDBN} calls the system call.
43843 It then coerces datatypes back to protocol representation.
43846 If the system call is expected to return data in buffer space specified
43847 by pointer parameters to the call, the data is transmitted to the
43848 target using a @code{M} or @code{X} packet. This packet has to be expected
43849 by the target implementation and is handled as any other @code{M} or @code{X}
43854 Eventually @value{GDBN} replies with another @code{F} packet which contains all
43855 necessary information for the target to continue. This at least contains
43862 @code{errno}, if has been changed by the system call.
43869 After having done the needed type and value coercion, the target continues
43870 the latest continue or step action.
43872 @node The F Request Packet
43873 @subsection The @code{F} Request Packet
43874 @cindex file-i/o request packet
43875 @cindex @code{F} request packet
43877 The @code{F} request packet has the following format:
43880 @item F@var{call-id},@var{parameter@dots{}}
43882 @var{call-id} is the identifier to indicate the host system call to be called.
43883 This is just the name of the function.
43885 @var{parameter@dots{}} are the parameters to the system call.
43886 Parameters are hexadecimal integer values, either the actual values in case
43887 of scalar datatypes, pointers to target buffer space in case of compound
43888 datatypes and unspecified memory areas, or pointer/length pairs in case
43889 of string parameters. These are appended to the @var{call-id} as a
43890 comma-delimited list. All values are transmitted in ASCII
43891 string representation, pointer/length pairs separated by a slash.
43897 @node The F Reply Packet
43898 @subsection The @code{F} Reply Packet
43899 @cindex file-i/o reply packet
43900 @cindex @code{F} reply packet
43902 The @code{F} reply packet has the following format:
43906 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43908 @var{retcode} is the return code of the system call as hexadecimal value.
43910 @var{errno} is the @code{errno} set by the call, in protocol-specific
43912 This parameter can be omitted if the call was successful.
43914 @var{Ctrl-C flag} is only sent if the user requested a break. In this
43915 case, @var{errno} must be sent as well, even if the call was successful.
43916 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43923 or, if the call was interrupted before the host call has been performed:
43930 assuming 4 is the protocol-specific representation of @code{EINTR}.
43935 @node The Ctrl-C Message
43936 @subsection The @samp{Ctrl-C} Message
43937 @cindex ctrl-c message, in file-i/o protocol
43939 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43940 reply packet (@pxref{The F Reply Packet}),
43941 the target should behave as if it had
43942 gotten a break message. The meaning for the target is ``system call
43943 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43944 (as with a break message) and return to @value{GDBN} with a @code{T02}
43947 It's important for the target to know in which
43948 state the system call was interrupted. There are two possible cases:
43952 The system call hasn't been performed on the host yet.
43955 The system call on the host has been finished.
43959 These two states can be distinguished by the target by the value of the
43960 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43961 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43962 on POSIX systems. In any other case, the target may presume that the
43963 system call has been finished --- successfully or not --- and should behave
43964 as if the break message arrived right after the system call.
43966 @value{GDBN} must behave reliably. If the system call has not been called
43967 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43968 @code{errno} in the packet. If the system call on the host has been finished
43969 before the user requests a break, the full action must be finished by
43970 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43971 The @code{F} packet may only be sent when either nothing has happened
43972 or the full action has been completed.
43975 @subsection Console I/O
43976 @cindex console i/o as part of file-i/o
43978 By default and if not explicitly closed by the target system, the file
43979 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43980 on the @value{GDBN} console is handled as any other file output operation
43981 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43982 by @value{GDBN} so that after the target read request from file descriptor
43983 0 all following typing is buffered until either one of the following
43988 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43990 system call is treated as finished.
43993 The user presses @key{RET}. This is treated as end of input with a trailing
43997 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43998 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
44002 If the user has typed more characters than fit in the buffer given to
44003 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
44004 either another @code{read(0, @dots{})} is requested by the target, or debugging
44005 is stopped at the user's request.
44008 @node List of Supported Calls
44009 @subsection List of Supported Calls
44010 @cindex list of supported file-i/o calls
44027 @unnumberedsubsubsec open
44028 @cindex open, file-i/o system call
44033 int open(const char *pathname, int flags);
44034 int open(const char *pathname, int flags, mode_t mode);
44038 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
44041 @var{flags} is the bitwise @code{OR} of the following values:
44045 If the file does not exist it will be created. The host
44046 rules apply as far as file ownership and time stamps
44050 When used with @code{O_CREAT}, if the file already exists it is
44051 an error and open() fails.
44054 If the file already exists and the open mode allows
44055 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
44056 truncated to zero length.
44059 The file is opened in append mode.
44062 The file is opened for reading only.
44065 The file is opened for writing only.
44068 The file is opened for reading and writing.
44072 Other bits are silently ignored.
44076 @var{mode} is the bitwise @code{OR} of the following values:
44080 User has read permission.
44083 User has write permission.
44086 Group has read permission.
44089 Group has write permission.
44092 Others have read permission.
44095 Others have write permission.
44099 Other bits are silently ignored.
44102 @item Return value:
44103 @code{open} returns the new file descriptor or -1 if an error
44110 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
44113 @var{pathname} refers to a directory.
44116 The requested access is not allowed.
44119 @var{pathname} was too long.
44122 A directory component in @var{pathname} does not exist.
44125 @var{pathname} refers to a device, pipe, named pipe or socket.
44128 @var{pathname} refers to a file on a read-only filesystem and
44129 write access was requested.
44132 @var{pathname} is an invalid pointer value.
44135 No space on device to create the file.
44138 The process already has the maximum number of files open.
44141 The limit on the total number of files open on the system
44145 The call was interrupted by the user.
44151 @unnumberedsubsubsec close
44152 @cindex close, file-i/o system call
44161 @samp{Fclose,@var{fd}}
44163 @item Return value:
44164 @code{close} returns zero on success, or -1 if an error occurred.
44170 @var{fd} isn't a valid open file descriptor.
44173 The call was interrupted by the user.
44179 @unnumberedsubsubsec read
44180 @cindex read, file-i/o system call
44185 int read(int fd, void *buf, unsigned int count);
44189 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
44191 @item Return value:
44192 On success, the number of bytes read is returned.
44193 Zero indicates end of file. If count is zero, read
44194 returns zero as well. On error, -1 is returned.
44200 @var{fd} is not a valid file descriptor or is not open for
44204 @var{bufptr} is an invalid pointer value.
44207 The call was interrupted by the user.
44213 @unnumberedsubsubsec write
44214 @cindex write, file-i/o system call
44219 int write(int fd, const void *buf, unsigned int count);
44223 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
44225 @item Return value:
44226 On success, the number of bytes written are returned.
44227 Zero indicates nothing was written. On error, -1
44234 @var{fd} is not a valid file descriptor or is not open for
44238 @var{bufptr} is an invalid pointer value.
44241 An attempt was made to write a file that exceeds the
44242 host-specific maximum file size allowed.
44245 No space on device to write the data.
44248 The call was interrupted by the user.
44254 @unnumberedsubsubsec lseek
44255 @cindex lseek, file-i/o system call
44260 long lseek (int fd, long offset, int flag);
44264 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
44266 @var{flag} is one of:
44270 The offset is set to @var{offset} bytes.
44273 The offset is set to its current location plus @var{offset}
44277 The offset is set to the size of the file plus @var{offset}
44281 @item Return value:
44282 On success, the resulting unsigned offset in bytes from
44283 the beginning of the file is returned. Otherwise, a
44284 value of -1 is returned.
44290 @var{fd} is not a valid open file descriptor.
44293 @var{fd} is associated with the @value{GDBN} console.
44296 @var{flag} is not a proper value.
44299 The call was interrupted by the user.
44305 @unnumberedsubsubsec rename
44306 @cindex rename, file-i/o system call
44311 int rename(const char *oldpath, const char *newpath);
44315 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
44317 @item Return value:
44318 On success, zero is returned. On error, -1 is returned.
44324 @var{newpath} is an existing directory, but @var{oldpath} is not a
44328 @var{newpath} is a non-empty directory.
44331 @var{oldpath} or @var{newpath} is a directory that is in use by some
44335 An attempt was made to make a directory a subdirectory
44339 A component used as a directory in @var{oldpath} or new
44340 path is not a directory. Or @var{oldpath} is a directory
44341 and @var{newpath} exists but is not a directory.
44344 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
44347 No access to the file or the path of the file.
44351 @var{oldpath} or @var{newpath} was too long.
44354 A directory component in @var{oldpath} or @var{newpath} does not exist.
44357 The file is on a read-only filesystem.
44360 The device containing the file has no room for the new
44364 The call was interrupted by the user.
44370 @unnumberedsubsubsec unlink
44371 @cindex unlink, file-i/o system call
44376 int unlink(const char *pathname);
44380 @samp{Funlink,@var{pathnameptr}/@var{len}}
44382 @item Return value:
44383 On success, zero is returned. On error, -1 is returned.
44389 No access to the file or the path of the file.
44392 The system does not allow unlinking of directories.
44395 The file @var{pathname} cannot be unlinked because it's
44396 being used by another process.
44399 @var{pathnameptr} is an invalid pointer value.
44402 @var{pathname} was too long.
44405 A directory component in @var{pathname} does not exist.
44408 A component of the path is not a directory.
44411 The file is on a read-only filesystem.
44414 The call was interrupted by the user.
44420 @unnumberedsubsubsec stat/fstat
44421 @cindex fstat, file-i/o system call
44422 @cindex stat, file-i/o system call
44427 int stat(const char *pathname, struct stat *buf);
44428 int fstat(int fd, struct stat *buf);
44432 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44433 @samp{Ffstat,@var{fd},@var{bufptr}}
44435 @item Return value:
44436 On success, zero is returned. On error, -1 is returned.
44442 @var{fd} is not a valid open file.
44445 A directory component in @var{pathname} does not exist or the
44446 path is an empty string.
44449 A component of the path is not a directory.
44452 @var{pathnameptr} is an invalid pointer value.
44455 No access to the file or the path of the file.
44458 @var{pathname} was too long.
44461 The call was interrupted by the user.
44467 @unnumberedsubsubsec gettimeofday
44468 @cindex gettimeofday, file-i/o system call
44473 int gettimeofday(struct timeval *tv, void *tz);
44477 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
44479 @item Return value:
44480 On success, 0 is returned, -1 otherwise.
44486 @var{tz} is a non-NULL pointer.
44489 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44495 @unnumberedsubsubsec isatty
44496 @cindex isatty, file-i/o system call
44501 int isatty(int fd);
44505 @samp{Fisatty,@var{fd}}
44507 @item Return value:
44508 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
44514 The call was interrupted by the user.
44519 Note that the @code{isatty} call is treated as a special case: it returns
44520 1 to the target if the file descriptor is attached
44521 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
44522 would require implementing @code{ioctl} and would be more complex than
44527 @unnumberedsubsubsec system
44528 @cindex system, file-i/o system call
44533 int system(const char *command);
44537 @samp{Fsystem,@var{commandptr}/@var{len}}
44539 @item Return value:
44540 If @var{len} is zero, the return value indicates whether a shell is
44541 available. A zero return value indicates a shell is not available.
44542 For non-zero @var{len}, the value returned is -1 on error and the
44543 return status of the command otherwise. Only the exit status of the
44544 command is returned, which is extracted from the host's @code{system}
44545 return value by calling @code{WEXITSTATUS(retval)}. In case
44546 @file{/bin/sh} could not be executed, 127 is returned.
44552 The call was interrupted by the user.
44557 @value{GDBN} takes over the full task of calling the necessary host calls
44558 to perform the @code{system} call. The return value of @code{system} on
44559 the host is simplified before it's returned
44560 to the target. Any termination signal information from the child process
44561 is discarded, and the return value consists
44562 entirely of the exit status of the called command.
44564 Due to security concerns, the @code{system} call is by default refused
44565 by @value{GDBN}. The user has to allow this call explicitly with the
44566 @code{set remote system-call-allowed 1} command.
44569 @item set remote system-call-allowed
44570 @kindex set remote system-call-allowed
44571 Control whether to allow the @code{system} calls in the File I/O
44572 protocol for the remote target. The default is zero (disabled).
44574 @item show remote system-call-allowed
44575 @kindex show remote system-call-allowed
44576 Show whether the @code{system} calls are allowed in the File I/O
44580 @node Protocol-specific Representation of Datatypes
44581 @subsection Protocol-specific Representation of Datatypes
44582 @cindex protocol-specific representation of datatypes, in file-i/o protocol
44585 * Integral Datatypes::
44587 * Memory Transfer::
44592 @node Integral Datatypes
44593 @unnumberedsubsubsec Integral Datatypes
44594 @cindex integral datatypes, in file-i/o protocol
44596 The integral datatypes used in the system calls are @code{int},
44597 @code{unsigned int}, @code{long}, @code{unsigned long},
44598 @code{mode_t}, and @code{time_t}.
44600 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
44601 implemented as 32 bit values in this protocol.
44603 @code{long} and @code{unsigned long} are implemented as 64 bit types.
44605 @xref{Limits}, for corresponding MIN and MAX values (similar to those
44606 in @file{limits.h}) to allow range checking on host and target.
44608 @code{time_t} datatypes are defined as seconds since the Epoch.
44610 All integral datatypes transferred as part of a memory read or write of a
44611 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
44614 @node Pointer Values
44615 @unnumberedsubsubsec Pointer Values
44616 @cindex pointer values, in file-i/o protocol
44618 Pointers to target data are transmitted as they are. An exception
44619 is made for pointers to buffers for which the length isn't
44620 transmitted as part of the function call, namely strings. Strings
44621 are transmitted as a pointer/length pair, both as hex values, e.g.@:
44628 which is a pointer to data of length 18 bytes at position 0x1aaf.
44629 The length is defined as the full string length in bytes, including
44630 the trailing null byte. For example, the string @code{"hello world"}
44631 at address 0x123456 is transmitted as
44637 @node Memory Transfer
44638 @unnumberedsubsubsec Memory Transfer
44639 @cindex memory transfer, in file-i/o protocol
44641 Structured data which is transferred using a memory read or write (for
44642 example, a @code{struct stat}) is expected to be in a protocol-specific format
44643 with all scalar multibyte datatypes being big endian. Translation to
44644 this representation needs to be done both by the target before the @code{F}
44645 packet is sent, and by @value{GDBN} before
44646 it transfers memory to the target. Transferred pointers to structured
44647 data should point to the already-coerced data at any time.
44651 @unnumberedsubsubsec struct stat
44652 @cindex struct stat, in file-i/o protocol
44654 The buffer of type @code{struct stat} used by the target and @value{GDBN}
44655 is defined as follows:
44659 unsigned int st_dev; /* device */
44660 unsigned int st_ino; /* inode */
44661 mode_t st_mode; /* protection */
44662 unsigned int st_nlink; /* number of hard links */
44663 unsigned int st_uid; /* user ID of owner */
44664 unsigned int st_gid; /* group ID of owner */
44665 unsigned int st_rdev; /* device type (if inode device) */
44666 unsigned long st_size; /* total size, in bytes */
44667 unsigned long st_blksize; /* blocksize for filesystem I/O */
44668 unsigned long st_blocks; /* number of blocks allocated */
44669 time_t st_atime; /* time of last access */
44670 time_t st_mtime; /* time of last modification */
44671 time_t st_ctime; /* time of last change */
44675 The integral datatypes conform to the definitions given in the
44676 appropriate section (see @ref{Integral Datatypes}, for details) so this
44677 structure is of size 64 bytes.
44679 The values of several fields have a restricted meaning and/or
44685 A value of 0 represents a file, 1 the console.
44688 No valid meaning for the target. Transmitted unchanged.
44691 Valid mode bits are described in @ref{Constants}. Any other
44692 bits have currently no meaning for the target.
44697 No valid meaning for the target. Transmitted unchanged.
44702 These values have a host and file system dependent
44703 accuracy. Especially on Windows hosts, the file system may not
44704 support exact timing values.
44707 The target gets a @code{struct stat} of the above representation and is
44708 responsible for coercing it to the target representation before
44711 Note that due to size differences between the host, target, and protocol
44712 representations of @code{struct stat} members, these members could eventually
44713 get truncated on the target.
44715 @node struct timeval
44716 @unnumberedsubsubsec struct timeval
44717 @cindex struct timeval, in file-i/o protocol
44719 The buffer of type @code{struct timeval} used by the File-I/O protocol
44720 is defined as follows:
44724 time_t tv_sec; /* second */
44725 long tv_usec; /* microsecond */
44729 The integral datatypes conform to the definitions given in the
44730 appropriate section (see @ref{Integral Datatypes}, for details) so this
44731 structure is of size 8 bytes.
44734 @subsection Constants
44735 @cindex constants, in file-i/o protocol
44737 The following values are used for the constants inside of the
44738 protocol. @value{GDBN} and target are responsible for translating these
44739 values before and after the call as needed.
44750 @unnumberedsubsubsec Open Flags
44751 @cindex open flags, in file-i/o protocol
44753 All values are given in hexadecimal representation.
44765 @node mode_t Values
44766 @unnumberedsubsubsec mode_t Values
44767 @cindex mode_t values, in file-i/o protocol
44769 All values are given in octal representation.
44786 @unnumberedsubsubsec Errno Values
44787 @cindex errno values, in file-i/o protocol
44789 All values are given in decimal representation.
44814 @code{EUNKNOWN} is used as a fallback error value if a host system returns
44815 any error value not in the list of supported error numbers.
44818 @unnumberedsubsubsec Lseek Flags
44819 @cindex lseek flags, in file-i/o protocol
44828 @unnumberedsubsubsec Limits
44829 @cindex limits, in file-i/o protocol
44831 All values are given in decimal representation.
44834 INT_MIN -2147483648
44836 UINT_MAX 4294967295
44837 LONG_MIN -9223372036854775808
44838 LONG_MAX 9223372036854775807
44839 ULONG_MAX 18446744073709551615
44842 @node File-I/O Examples
44843 @subsection File-I/O Examples
44844 @cindex file-i/o examples
44846 Example sequence of a write call, file descriptor 3, buffer is at target
44847 address 0x1234, 6 bytes should be written:
44850 <- @code{Fwrite,3,1234,6}
44851 @emph{request memory read from target}
44854 @emph{return "6 bytes written"}
44858 Example sequence of a read call, file descriptor 3, buffer is at target
44859 address 0x1234, 6 bytes should be read:
44862 <- @code{Fread,3,1234,6}
44863 @emph{request memory write to target}
44864 -> @code{X1234,6:XXXXXX}
44865 @emph{return "6 bytes read"}
44869 Example sequence of a read call, call fails on the host due to invalid
44870 file descriptor (@code{EBADF}):
44873 <- @code{Fread,3,1234,6}
44877 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44881 <- @code{Fread,3,1234,6}
44886 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44890 <- @code{Fread,3,1234,6}
44891 -> @code{X1234,6:XXXXXX}
44895 @node Library List Format
44896 @section Library List Format
44897 @cindex library list format, remote protocol
44899 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44900 same process as your application to manage libraries. In this case,
44901 @value{GDBN} can use the loader's symbol table and normal memory
44902 operations to maintain a list of shared libraries. On other
44903 platforms, the operating system manages loaded libraries.
44904 @value{GDBN} can not retrieve the list of currently loaded libraries
44905 through memory operations, so it uses the @samp{qXfer:libraries:read}
44906 packet (@pxref{qXfer library list read}) instead. The remote stub
44907 queries the target's operating system and reports which libraries
44910 The @samp{qXfer:libraries:read} packet returns an XML document which
44911 lists loaded libraries and their offsets. Each library has an
44912 associated name and one or more segment or section base addresses,
44913 which report where the library was loaded in memory.
44915 For the common case of libraries that are fully linked binaries, the
44916 library should have a list of segments. If the target supports
44917 dynamic linking of a relocatable object file, its library XML element
44918 should instead include a list of allocated sections. The segment or
44919 section bases are start addresses, not relocation offsets; they do not
44920 depend on the library's link-time base addresses.
44922 @value{GDBN} must be linked with the Expat library to support XML
44923 library lists. @xref{Expat}.
44925 A simple memory map, with one loaded library relocated by a single
44926 offset, looks like this:
44930 <library name="/lib/libc.so.6">
44931 <segment address="0x10000000"/>
44936 Another simple memory map, with one loaded library with three
44937 allocated sections (.text, .data, .bss), looks like this:
44941 <library name="sharedlib.o">
44942 <section address="0x10000000"/>
44943 <section address="0x20000000"/>
44944 <section address="0x30000000"/>
44949 The format of a library list is described by this DTD:
44952 <!-- library-list: Root element with versioning -->
44953 <!ELEMENT library-list (library)*>
44954 <!ATTLIST library-list version CDATA #FIXED "1.0">
44955 <!ELEMENT library (segment*, section*)>
44956 <!ATTLIST library name CDATA #REQUIRED>
44957 <!ELEMENT segment EMPTY>
44958 <!ATTLIST segment address CDATA #REQUIRED>
44959 <!ELEMENT section EMPTY>
44960 <!ATTLIST section address CDATA #REQUIRED>
44963 In addition, segments and section descriptors cannot be mixed within a
44964 single library element, and you must supply at least one segment or
44965 section for each library.
44967 @node Library List Format for SVR4 Targets
44968 @section Library List Format for SVR4 Targets
44969 @cindex library list format, remote protocol
44971 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44972 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44973 shared libraries. Still a special library list provided by this packet is
44974 more efficient for the @value{GDBN} remote protocol.
44976 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44977 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44978 target, the following parameters are reported:
44982 @code{name}, the absolute file name from the @code{l_name} field of
44983 @code{struct link_map}.
44985 @code{lm} with address of @code{struct link_map} used for TLS
44986 (Thread Local Storage) access.
44988 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44989 @code{struct link_map}. For prelinked libraries this is not an absolute
44990 memory address. It is a displacement of absolute memory address against
44991 address the file was prelinked to during the library load.
44993 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44996 Additionally the single @code{main-lm} attribute specifies address of
44997 @code{struct link_map} used for the main executable. This parameter is used
44998 for TLS access and its presence is optional.
45000 @value{GDBN} must be linked with the Expat library to support XML
45001 SVR4 library lists. @xref{Expat}.
45003 A simple memory map, with two loaded libraries (which do not use prelink),
45007 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
45008 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
45010 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
45012 </library-list-svr>
45015 The format of an SVR4 library list is described by this DTD:
45018 <!-- library-list-svr4: Root element with versioning -->
45019 <!ELEMENT library-list-svr4 (library)*>
45020 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
45021 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
45022 <!ELEMENT library EMPTY>
45023 <!ATTLIST library name CDATA #REQUIRED>
45024 <!ATTLIST library lm CDATA #REQUIRED>
45025 <!ATTLIST library l_addr CDATA #REQUIRED>
45026 <!ATTLIST library l_ld CDATA #REQUIRED>
45029 @node Memory Map Format
45030 @section Memory Map Format
45031 @cindex memory map format
45033 To be able to write into flash memory, @value{GDBN} needs to obtain a
45034 memory map from the target. This section describes the format of the
45037 The memory map is obtained using the @samp{qXfer:memory-map:read}
45038 (@pxref{qXfer memory map read}) packet and is an XML document that
45039 lists memory regions.
45041 @value{GDBN} must be linked with the Expat library to support XML
45042 memory maps. @xref{Expat}.
45044 The top-level structure of the document is shown below:
45047 <?xml version="1.0"?>
45048 <!DOCTYPE memory-map
45049 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45050 "http://sourceware.org/gdb/gdb-memory-map.dtd">
45056 Each region can be either:
45061 A region of RAM starting at @var{addr} and extending for @var{length}
45065 <memory type="ram" start="@var{addr}" length="@var{length}"/>
45070 A region of read-only memory:
45073 <memory type="rom" start="@var{addr}" length="@var{length}"/>
45078 A region of flash memory, with erasure blocks @var{blocksize}
45082 <memory type="flash" start="@var{addr}" length="@var{length}">
45083 <property name="blocksize">@var{blocksize}</property>
45089 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
45090 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
45091 packets to write to addresses in such ranges.
45093 The formal DTD for memory map format is given below:
45096 <!-- ................................................... -->
45097 <!-- Memory Map XML DTD ................................ -->
45098 <!-- File: memory-map.dtd .............................. -->
45099 <!-- .................................... .............. -->
45100 <!-- memory-map.dtd -->
45101 <!-- memory-map: Root element with versioning -->
45102 <!ELEMENT memory-map (memory)*>
45103 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
45104 <!ELEMENT memory (property)*>
45105 <!-- memory: Specifies a memory region,
45106 and its type, or device. -->
45107 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
45108 start CDATA #REQUIRED
45109 length CDATA #REQUIRED>
45110 <!-- property: Generic attribute tag -->
45111 <!ELEMENT property (#PCDATA | property)*>
45112 <!ATTLIST property name (blocksize) #REQUIRED>
45115 @node Thread List Format
45116 @section Thread List Format
45117 @cindex thread list format
45119 To efficiently update the list of threads and their attributes,
45120 @value{GDBN} issues the @samp{qXfer:threads:read} packet
45121 (@pxref{qXfer threads read}) and obtains the XML document with
45122 the following structure:
45125 <?xml version="1.0"?>
45127 <thread id="id" core="0" name="name">
45128 ... description ...
45133 Each @samp{thread} element must have the @samp{id} attribute that
45134 identifies the thread (@pxref{thread-id syntax}). The
45135 @samp{core} attribute, if present, specifies which processor core
45136 the thread was last executing on. The @samp{name} attribute, if
45137 present, specifies the human-readable name of the thread. The content
45138 of the of @samp{thread} element is interpreted as human-readable
45139 auxiliary information. The @samp{handle} attribute, if present,
45140 is a hex encoded representation of the thread handle.
45143 @node Traceframe Info Format
45144 @section Traceframe Info Format
45145 @cindex traceframe info format
45147 To be able to know which objects in the inferior can be examined when
45148 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
45149 memory ranges, registers and trace state variables that have been
45150 collected in a traceframe.
45152 This list is obtained using the @samp{qXfer:traceframe-info:read}
45153 (@pxref{qXfer traceframe info read}) packet and is an XML document.
45155 @value{GDBN} must be linked with the Expat library to support XML
45156 traceframe info discovery. @xref{Expat}.
45158 The top-level structure of the document is shown below:
45161 <?xml version="1.0"?>
45162 <!DOCTYPE traceframe-info
45163 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45164 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
45170 Each traceframe block can be either:
45175 A region of collected memory starting at @var{addr} and extending for
45176 @var{length} bytes from there:
45179 <memory start="@var{addr}" length="@var{length}"/>
45183 A block indicating trace state variable numbered @var{number} has been
45187 <tvar id="@var{number}"/>
45192 The formal DTD for the traceframe info format is given below:
45195 <!ELEMENT traceframe-info (memory | tvar)* >
45196 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
45198 <!ELEMENT memory EMPTY>
45199 <!ATTLIST memory start CDATA #REQUIRED
45200 length CDATA #REQUIRED>
45202 <!ATTLIST tvar id CDATA #REQUIRED>
45205 @node Branch Trace Format
45206 @section Branch Trace Format
45207 @cindex branch trace format
45209 In order to display the branch trace of an inferior thread,
45210 @value{GDBN} needs to obtain the list of branches. This list is
45211 represented as list of sequential code blocks that are connected via
45212 branches. The code in each block has been executed sequentially.
45214 This list is obtained using the @samp{qXfer:btrace:read}
45215 (@pxref{qXfer btrace read}) packet and is an XML document.
45217 @value{GDBN} must be linked with the Expat library to support XML
45218 traceframe info discovery. @xref{Expat}.
45220 The top-level structure of the document is shown below:
45223 <?xml version="1.0"?>
45225 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
45226 "http://sourceware.org/gdb/gdb-btrace.dtd">
45235 A block of sequentially executed instructions starting at @var{begin}
45236 and ending at @var{end}:
45239 <block begin="@var{begin}" end="@var{end}"/>
45244 The formal DTD for the branch trace format is given below:
45247 <!ELEMENT btrace (block* | pt) >
45248 <!ATTLIST btrace version CDATA #FIXED "1.0">
45250 <!ELEMENT block EMPTY>
45251 <!ATTLIST block begin CDATA #REQUIRED
45252 end CDATA #REQUIRED>
45254 <!ELEMENT pt (pt-config?, raw?)>
45256 <!ELEMENT pt-config (cpu?)>
45258 <!ELEMENT cpu EMPTY>
45259 <!ATTLIST cpu vendor CDATA #REQUIRED
45260 family CDATA #REQUIRED
45261 model CDATA #REQUIRED
45262 stepping CDATA #REQUIRED>
45264 <!ELEMENT raw (#PCDATA)>
45267 @node Branch Trace Configuration Format
45268 @section Branch Trace Configuration Format
45269 @cindex branch trace configuration format
45271 For each inferior thread, @value{GDBN} can obtain the branch trace
45272 configuration using the @samp{qXfer:btrace-conf:read}
45273 (@pxref{qXfer btrace-conf read}) packet.
45275 The configuration describes the branch trace format and configuration
45276 settings for that format. The following information is described:
45280 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
45283 The size of the @acronym{BTS} ring buffer in bytes.
45286 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
45290 The size of the @acronym{Intel PT} ring buffer in bytes.
45294 @value{GDBN} must be linked with the Expat library to support XML
45295 branch trace configuration discovery. @xref{Expat}.
45297 The formal DTD for the branch trace configuration format is given below:
45300 <!ELEMENT btrace-conf (bts?, pt?)>
45301 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
45303 <!ELEMENT bts EMPTY>
45304 <!ATTLIST bts size CDATA #IMPLIED>
45306 <!ELEMENT pt EMPTY>
45307 <!ATTLIST pt size CDATA #IMPLIED>
45310 @include agentexpr.texi
45312 @node Target Descriptions
45313 @appendix Target Descriptions
45314 @cindex target descriptions
45316 One of the challenges of using @value{GDBN} to debug embedded systems
45317 is that there are so many minor variants of each processor
45318 architecture in use. It is common practice for vendors to start with
45319 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
45320 and then make changes to adapt it to a particular market niche. Some
45321 architectures have hundreds of variants, available from dozens of
45322 vendors. This leads to a number of problems:
45326 With so many different customized processors, it is difficult for
45327 the @value{GDBN} maintainers to keep up with the changes.
45329 Since individual variants may have short lifetimes or limited
45330 audiences, it may not be worthwhile to carry information about every
45331 variant in the @value{GDBN} source tree.
45333 When @value{GDBN} does support the architecture of the embedded system
45334 at hand, the task of finding the correct architecture name to give the
45335 @command{set architecture} command can be error-prone.
45338 To address these problems, the @value{GDBN} remote protocol allows a
45339 target system to not only identify itself to @value{GDBN}, but to
45340 actually describe its own features. This lets @value{GDBN} support
45341 processor variants it has never seen before --- to the extent that the
45342 descriptions are accurate, and that @value{GDBN} understands them.
45344 @value{GDBN} must be linked with the Expat library to support XML
45345 target descriptions. @xref{Expat}.
45348 * Retrieving Descriptions:: How descriptions are fetched from a target.
45349 * Target Description Format:: The contents of a target description.
45350 * Predefined Target Types:: Standard types available for target
45352 * Enum Target Types:: How to define enum target types.
45353 * Standard Target Features:: Features @value{GDBN} knows about.
45356 @node Retrieving Descriptions
45357 @section Retrieving Descriptions
45359 Target descriptions can be read from the target automatically, or
45360 specified by the user manually. The default behavior is to read the
45361 description from the target. @value{GDBN} retrieves it via the remote
45362 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
45363 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
45364 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
45365 XML document, of the form described in @ref{Target Description
45368 Alternatively, you can specify a file to read for the target description.
45369 If a file is set, the target will not be queried. The commands to
45370 specify a file are:
45373 @cindex set tdesc filename
45374 @item set tdesc filename @var{path}
45375 Read the target description from @var{path}.
45377 @cindex unset tdesc filename
45378 @item unset tdesc filename
45379 Do not read the XML target description from a file. @value{GDBN}
45380 will use the description supplied by the current target.
45382 @cindex show tdesc filename
45383 @item show tdesc filename
45384 Show the filename to read for a target description, if any.
45388 @node Target Description Format
45389 @section Target Description Format
45390 @cindex target descriptions, XML format
45392 A target description annex is an @uref{http://www.w3.org/XML/, XML}
45393 document which complies with the Document Type Definition provided in
45394 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45395 means you can use generally available tools like @command{xmllint} to
45396 check that your feature descriptions are well-formed and valid.
45397 However, to help people unfamiliar with XML write descriptions for
45398 their targets, we also describe the grammar here.
45400 Target descriptions can identify the architecture of the remote target
45401 and (for some architectures) provide information about custom register
45402 sets. They can also identify the OS ABI of the remote target.
45403 @value{GDBN} can use this information to autoconfigure for your
45404 target, or to warn you if you connect to an unsupported target.
45406 Here is a simple target description:
45409 <target version="1.0">
45410 <architecture>i386:x86-64</architecture>
45415 This minimal description only says that the target uses
45416 the x86-64 architecture.
45418 A target description has the following overall form, with [ ] marking
45419 optional elements and @dots{} marking repeatable elements. The elements
45420 are explained further below.
45423 <?xml version="1.0"?>
45424 <!DOCTYPE target SYSTEM "gdb-target.dtd">
45425 <target version="1.0">
45426 @r{[}@var{architecture}@r{]}
45427 @r{[}@var{osabi}@r{]}
45428 @r{[}@var{compatible}@r{]}
45429 @r{[}@var{feature}@dots{}@r{]}
45434 The description is generally insensitive to whitespace and line
45435 breaks, under the usual common-sense rules. The XML version
45436 declaration and document type declaration can generally be omitted
45437 (@value{GDBN} does not require them), but specifying them may be
45438 useful for XML validation tools. The @samp{version} attribute for
45439 @samp{<target>} may also be omitted, but we recommend
45440 including it; if future versions of @value{GDBN} use an incompatible
45441 revision of @file{gdb-target.dtd}, they will detect and report
45442 the version mismatch.
45444 @subsection Inclusion
45445 @cindex target descriptions, inclusion
45448 @cindex <xi:include>
45451 It can sometimes be valuable to split a target description up into
45452 several different annexes, either for organizational purposes, or to
45453 share files between different possible target descriptions. You can
45454 divide a description into multiple files by replacing any element of
45455 the target description with an inclusion directive of the form:
45458 <xi:include href="@var{document}"/>
45462 When @value{GDBN} encounters an element of this form, it will retrieve
45463 the named XML @var{document}, and replace the inclusion directive with
45464 the contents of that document. If the current description was read
45465 using @samp{qXfer}, then so will be the included document;
45466 @var{document} will be interpreted as the name of an annex. If the
45467 current description was read from a file, @value{GDBN} will look for
45468 @var{document} as a file in the same directory where it found the
45469 original description.
45471 @subsection Architecture
45472 @cindex <architecture>
45474 An @samp{<architecture>} element has this form:
45477 <architecture>@var{arch}</architecture>
45480 @var{arch} is one of the architectures from the set accepted by
45481 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45484 @cindex @code{<osabi>}
45486 This optional field was introduced in @value{GDBN} version 7.0.
45487 Previous versions of @value{GDBN} ignore it.
45489 An @samp{<osabi>} element has this form:
45492 <osabi>@var{abi-name}</osabi>
45495 @var{abi-name} is an OS ABI name from the same selection accepted by
45496 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45498 @subsection Compatible Architecture
45499 @cindex @code{<compatible>}
45501 This optional field was introduced in @value{GDBN} version 7.0.
45502 Previous versions of @value{GDBN} ignore it.
45504 A @samp{<compatible>} element has this form:
45507 <compatible>@var{arch}</compatible>
45510 @var{arch} is one of the architectures from the set accepted by
45511 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45513 A @samp{<compatible>} element is used to specify that the target
45514 is able to run binaries in some other than the main target architecture
45515 given by the @samp{<architecture>} element. For example, on the
45516 Cell Broadband Engine, the main architecture is @code{powerpc:common}
45517 or @code{powerpc:common64}, but the system is able to run binaries
45518 in the @code{spu} architecture as well. The way to describe this
45519 capability with @samp{<compatible>} is as follows:
45522 <architecture>powerpc:common</architecture>
45523 <compatible>spu</compatible>
45526 @subsection Features
45529 Each @samp{<feature>} describes some logical portion of the target
45530 system. Features are currently used to describe available CPU
45531 registers and the types of their contents. A @samp{<feature>} element
45535 <feature name="@var{name}">
45536 @r{[}@var{type}@dots{}@r{]}
45542 Each feature's name should be unique within the description. The name
45543 of a feature does not matter unless @value{GDBN} has some special
45544 knowledge of the contents of that feature; if it does, the feature
45545 should have its standard name. @xref{Standard Target Features}.
45549 Any register's value is a collection of bits which @value{GDBN} must
45550 interpret. The default interpretation is a two's complement integer,
45551 but other types can be requested by name in the register description.
45552 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
45553 Target Types}), and the description can define additional composite
45556 Each type element must have an @samp{id} attribute, which gives
45557 a unique (within the containing @samp{<feature>}) name to the type.
45558 Types must be defined before they are used.
45561 Some targets offer vector registers, which can be treated as arrays
45562 of scalar elements. These types are written as @samp{<vector>} elements,
45563 specifying the array element type, @var{type}, and the number of elements,
45567 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
45571 If a register's value is usefully viewed in multiple ways, define it
45572 with a union type containing the useful representations. The
45573 @samp{<union>} element contains one or more @samp{<field>} elements,
45574 each of which has a @var{name} and a @var{type}:
45577 <union id="@var{id}">
45578 <field name="@var{name}" type="@var{type}"/>
45585 If a register's value is composed from several separate values, define
45586 it with either a structure type or a flags type.
45587 A flags type may only contain bitfields.
45588 A structure type may either contain only bitfields or contain no bitfields.
45589 If the value contains only bitfields, its total size in bytes must be
45592 Non-bitfield values have a @var{name} and @var{type}.
45595 <struct id="@var{id}">
45596 <field name="@var{name}" type="@var{type}"/>
45601 Both @var{name} and @var{type} values are required.
45602 No implicit padding is added.
45604 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
45607 <struct id="@var{id}" size="@var{size}">
45608 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45614 <flags id="@var{id}" size="@var{size}">
45615 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45620 The @var{name} value is required.
45621 Bitfield values may be named with the empty string, @samp{""},
45622 in which case the field is ``filler'' and its value is not printed.
45623 Not all bits need to be specified, so ``filler'' fields are optional.
45625 The @var{start} and @var{end} values are required, and @var{type}
45627 The field's @var{start} must be less than or equal to its @var{end},
45628 and zero represents the least significant bit.
45630 The default value of @var{type} is @code{bool} for single bit fields,
45631 and an unsigned integer otherwise.
45633 Which to choose? Structures or flags?
45635 Registers defined with @samp{flags} have these advantages over
45636 defining them with @samp{struct}:
45640 Arithmetic may be performed on them as if they were integers.
45642 They are printed in a more readable fashion.
45645 Registers defined with @samp{struct} have one advantage over
45646 defining them with @samp{flags}:
45650 One can fetch individual fields like in @samp{C}.
45653 (gdb) print $my_struct_reg.field3
45659 @subsection Registers
45662 Each register is represented as an element with this form:
45665 <reg name="@var{name}"
45666 bitsize="@var{size}"
45667 @r{[}regnum="@var{num}"@r{]}
45668 @r{[}save-restore="@var{save-restore}"@r{]}
45669 @r{[}type="@var{type}"@r{]}
45670 @r{[}group="@var{group}"@r{]}/>
45674 The components are as follows:
45679 The register's name; it must be unique within the target description.
45682 The register's size, in bits.
45685 The register's number. If omitted, a register's number is one greater
45686 than that of the previous register (either in the current feature or in
45687 a preceding feature); the first register in the target description
45688 defaults to zero. This register number is used to read or write
45689 the register; e.g.@: it is used in the remote @code{p} and @code{P}
45690 packets, and registers appear in the @code{g} and @code{G} packets
45691 in order of increasing register number.
45694 Whether the register should be preserved across inferior function
45695 calls; this must be either @code{yes} or @code{no}. The default is
45696 @code{yes}, which is appropriate for most registers except for
45697 some system control registers; this is not related to the target's
45701 The type of the register. It may be a predefined type, a type
45702 defined in the current feature, or one of the special types @code{int}
45703 and @code{float}. @code{int} is an integer type of the correct size
45704 for @var{bitsize}, and @code{float} is a floating point type (in the
45705 architecture's normal floating point format) of the correct size for
45706 @var{bitsize}. The default is @code{int}.
45709 The register group to which this register belongs. It can be one of the
45710 standard register groups @code{general}, @code{float}, @code{vector} or an
45711 arbitrary string. Group names should be limited to alphanumeric characters.
45712 If a group name is made up of multiple words the words may be separated by
45713 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45714 @var{group} is specified, @value{GDBN} will not display the register in
45715 @code{info registers}.
45719 @node Predefined Target Types
45720 @section Predefined Target Types
45721 @cindex target descriptions, predefined types
45723 Type definitions in the self-description can build up composite types
45724 from basic building blocks, but can not define fundamental types. Instead,
45725 standard identifiers are provided by @value{GDBN} for the fundamental
45726 types. The currently supported types are:
45731 Boolean type, occupying a single bit.
45739 Signed integer types holding the specified number of bits.
45747 Unsigned integer types holding the specified number of bits.
45751 Pointers to unspecified code and data. The program counter and
45752 any dedicated return address register may be marked as code
45753 pointers; printing a code pointer converts it into a symbolic
45754 address. The stack pointer and any dedicated address registers
45755 may be marked as data pointers.
45758 Single precision IEEE floating point.
45761 Double precision IEEE floating point.
45764 The 12-byte extended precision format used by ARM FPA registers.
45767 The 10-byte extended precision format used by x87 registers.
45770 32bit @sc{eflags} register used by x86.
45773 32bit @sc{mxcsr} register used by x86.
45777 @node Enum Target Types
45778 @section Enum Target Types
45779 @cindex target descriptions, enum types
45781 Enum target types are useful in @samp{struct} and @samp{flags}
45782 register descriptions. @xref{Target Description Format}.
45784 Enum types have a name, size and a list of name/value pairs.
45787 <enum id="@var{id}" size="@var{size}">
45788 <evalue name="@var{name}" value="@var{value}"/>
45793 Enums must be defined before they are used.
45796 <enum id="levels_type" size="4">
45797 <evalue name="low" value="0"/>
45798 <evalue name="high" value="1"/>
45800 <flags id="flags_type" size="4">
45801 <field name="X" start="0"/>
45802 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45804 <reg name="flags" bitsize="32" type="flags_type"/>
45807 Given that description, a value of 3 for the @samp{flags} register
45808 would be printed as:
45811 (gdb) info register flags
45812 flags 0x3 [ X LEVEL=high ]
45815 @node Standard Target Features
45816 @section Standard Target Features
45817 @cindex target descriptions, standard features
45819 A target description must contain either no registers or all the
45820 target's registers. If the description contains no registers, then
45821 @value{GDBN} will assume a default register layout, selected based on
45822 the architecture. If the description contains any registers, the
45823 default layout will not be used; the standard registers must be
45824 described in the target description, in such a way that @value{GDBN}
45825 can recognize them.
45827 This is accomplished by giving specific names to feature elements
45828 which contain standard registers. @value{GDBN} will look for features
45829 with those names and verify that they contain the expected registers;
45830 if any known feature is missing required registers, or if any required
45831 feature is missing, @value{GDBN} will reject the target
45832 description. You can add additional registers to any of the
45833 standard features --- @value{GDBN} will display them just as if
45834 they were added to an unrecognized feature.
45836 This section lists the known features and their expected contents.
45837 Sample XML documents for these features are included in the
45838 @value{GDBN} source tree, in the directory @file{gdb/features}.
45840 Names recognized by @value{GDBN} should include the name of the
45841 company or organization which selected the name, and the overall
45842 architecture to which the feature applies; so e.g.@: the feature
45843 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45845 The names of registers are not case sensitive for the purpose
45846 of recognizing standard features, but @value{GDBN} will only display
45847 registers using the capitalization used in the description.
45850 * AArch64 Features::
45854 * MicroBlaze Features::
45858 * Nios II Features::
45859 * OpenRISC 1000 Features::
45860 * PowerPC Features::
45861 * RISC-V Features::
45863 * S/390 and System z Features::
45869 @node AArch64 Features
45870 @subsection AArch64 Features
45871 @cindex target descriptions, AArch64 features
45873 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45874 targets. It should contain registers @samp{x0} through @samp{x30},
45875 @samp{sp}, @samp{pc}, and @samp{cpsr}.
45877 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45878 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45881 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45882 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45883 through @samp{p15}, @samp{ffr} and @samp{vg}.
45885 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45886 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45889 @subsection ARC Features
45890 @cindex target descriptions, ARC Features
45892 ARC processors are so configurable that even core registers and their numbers
45893 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45894 registers, which are important to @value{GDBN}, are not ``core'' registers in
45895 ARC. Therefore, there are two features that their presence is mandatory:
45896 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45898 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45903 @samp{r0} through @samp{r25} for normal register file targets.
45905 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45906 register file targets.
45908 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45909 @samp{blink}, @samp{lp_count}, @samp{pcl}.
45912 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45913 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45914 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45915 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45916 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45917 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45918 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45919 because of their inaccessibility during user space debugging sessions.
45921 Extension core registers @samp{r32} through @samp{r59} are optional and their
45922 existence depends on the configuration. When debugging GNU/Linux applications,
45923 i.e.@: user space debugging, these core registers are not available.
45925 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
45926 is the list of registers pertinent to this feature:
45930 mandatory: @samp{pc} and @samp{status32}.
45932 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45936 @subsection ARM Features
45937 @cindex target descriptions, ARM features
45939 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45941 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45942 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45944 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45945 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45946 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45949 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45950 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45952 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45953 it should contain at least registers @samp{wR0} through @samp{wR15} and
45954 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45955 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45957 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45958 should contain at least registers @samp{d0} through @samp{d15}. If
45959 they are present, @samp{d16} through @samp{d31} should also be included.
45960 @value{GDBN} will synthesize the single-precision registers from
45961 halves of the double-precision registers.
45963 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45964 need to contain registers; it instructs @value{GDBN} to display the
45965 VFP double-precision registers as vectors and to synthesize the
45966 quad-precision registers from pairs of double-precision registers.
45967 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45968 be present and include 32 double-precision registers.
45970 @node i386 Features
45971 @subsection i386 Features
45972 @cindex target descriptions, i386 features
45974 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45975 targets. It should describe the following registers:
45979 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45981 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45983 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45984 @samp{fs}, @samp{gs}
45986 @samp{st0} through @samp{st7}
45988 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45989 @samp{foseg}, @samp{fooff} and @samp{fop}
45992 The register sets may be different, depending on the target.
45994 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45995 describe registers:
45999 @samp{xmm0} through @samp{xmm7} for i386
46001 @samp{xmm0} through @samp{xmm15} for amd64
46006 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
46007 @samp{org.gnu.gdb.i386.sse} feature. It should
46008 describe the upper 128 bits of @sc{ymm} registers:
46012 @samp{ymm0h} through @samp{ymm7h} for i386
46014 @samp{ymm0h} through @samp{ymm15h} for amd64
46017 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
46018 Memory Protection Extension (MPX). It should describe the following registers:
46022 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
46024 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
46027 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
46028 describe a single register, @samp{orig_eax}.
46030 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
46031 describe two system registers: @samp{fs_base} and @samp{gs_base}.
46033 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
46034 @samp{org.gnu.gdb.i386.avx} feature. It should
46035 describe additional @sc{xmm} registers:
46039 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
46042 It should describe the upper 128 bits of additional @sc{ymm} registers:
46046 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
46050 describe the upper 256 bits of @sc{zmm} registers:
46054 @samp{zmm0h} through @samp{zmm7h} for i386.
46056 @samp{zmm0h} through @samp{zmm15h} for amd64.
46060 describe the additional @sc{zmm} registers:
46064 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
46067 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
46068 describe a single register, @samp{pkru}. It is a 32-bit register
46069 valid for i386 and amd64.
46071 @node MicroBlaze Features
46072 @subsection MicroBlaze Features
46073 @cindex target descriptions, MicroBlaze features
46075 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
46076 targets. It should contain registers @samp{r0} through @samp{r31},
46077 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
46078 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
46079 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
46081 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
46082 If present, it should contain registers @samp{rshr} and @samp{rslr}
46084 @node MIPS Features
46085 @subsection @acronym{MIPS} Features
46086 @cindex target descriptions, @acronym{MIPS} features
46088 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
46089 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
46090 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
46093 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
46094 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
46095 registers. They may be 32-bit or 64-bit depending on the target.
46097 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
46098 it may be optional in a future version of @value{GDBN}. It should
46099 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
46100 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
46102 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
46103 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
46104 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
46105 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
46107 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
46108 contain a single register, @samp{restart}, which is used by the
46109 Linux kernel to control restartable syscalls.
46111 @node M68K Features
46112 @subsection M68K Features
46113 @cindex target descriptions, M68K features
46116 @item @samp{org.gnu.gdb.m68k.core}
46117 @itemx @samp{org.gnu.gdb.coldfire.core}
46118 @itemx @samp{org.gnu.gdb.fido.core}
46119 One of those features must be always present.
46120 The feature that is present determines which flavor of m68k is
46121 used. The feature that is present should contain registers
46122 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
46123 @samp{sp}, @samp{ps} and @samp{pc}.
46125 @item @samp{org.gnu.gdb.coldfire.fp}
46126 This feature is optional. If present, it should contain registers
46127 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
46130 Note that, despite the fact that this feature's name says
46131 @samp{coldfire}, it is used to describe any floating point registers.
46132 The size of the registers must match the main m68k flavor; so, for
46133 example, if the primary feature is reported as @samp{coldfire}, then
46134 64-bit floating point registers are required.
46137 @node NDS32 Features
46138 @subsection NDS32 Features
46139 @cindex target descriptions, NDS32 features
46141 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
46142 targets. It should contain at least registers @samp{r0} through
46143 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
46146 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
46147 it should contain 64-bit double-precision floating-point registers
46148 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
46149 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
46151 @emph{Note:} The first sixteen 64-bit double-precision floating-point
46152 registers are overlapped with the thirty-two 32-bit single-precision
46153 floating-point registers. The 32-bit single-precision registers, if
46154 not being listed explicitly, will be synthesized from halves of the
46155 overlapping 64-bit double-precision registers. Listing 32-bit
46156 single-precision registers explicitly is deprecated, and the
46157 support to it could be totally removed some day.
46159 @node Nios II Features
46160 @subsection Nios II Features
46161 @cindex target descriptions, Nios II features
46163 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
46164 targets. It should contain the 32 core registers (@samp{zero},
46165 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
46166 @samp{pc}, and the 16 control registers (@samp{status} through
46169 @node OpenRISC 1000 Features
46170 @subsection Openrisc 1000 Features
46171 @cindex target descriptions, OpenRISC 1000 features
46173 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
46174 targets. It should contain the 32 general purpose registers (@samp{r0}
46175 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
46177 @node PowerPC Features
46178 @subsection PowerPC Features
46179 @cindex target descriptions, PowerPC features
46181 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
46182 targets. It should contain registers @samp{r0} through @samp{r31},
46183 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
46184 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
46186 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
46187 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
46189 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
46190 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
46191 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
46192 through @samp{v31} as aliases for the corresponding @samp{vrX}
46195 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
46196 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
46197 combine these registers with the floating point registers (@samp{f0}
46198 through @samp{f31}) and the altivec registers (@samp{vr0} through
46199 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
46200 @samp{vs63}, the set of vector-scalar registers for POWER7.
46201 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
46202 @samp{org.gnu.gdb.power.altivec}.
46204 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
46205 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
46206 @samp{spefscr}. SPE targets should provide 32-bit registers in
46207 @samp{org.gnu.gdb.power.core} and provide the upper halves in
46208 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
46209 these to present registers @samp{ev0} through @samp{ev31} to the
46212 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
46213 contain the 64-bit register @samp{ppr}.
46215 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
46216 contain the 64-bit register @samp{dscr}.
46218 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
46219 contain the 64-bit register @samp{tar}.
46221 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
46222 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
46225 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
46226 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
46227 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
46228 server PMU registers provided by @sc{gnu}/Linux.
46230 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
46231 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
46234 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
46235 contain the checkpointed general-purpose registers @samp{cr0} through
46236 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
46237 @samp{cctr}. These registers may all be either 32-bit or 64-bit
46238 depending on the target. It should also contain the checkpointed
46239 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
46242 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
46243 contain the checkpointed 64-bit floating-point registers @samp{cf0}
46244 through @samp{cf31}, as well as the checkpointed 64-bit register
46247 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
46248 should contain the checkpointed altivec registers @samp{cvr0} through
46249 @samp{cvr31}, all 128-bit wide. It should also contain the
46250 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
46253 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
46254 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
46255 will combine these registers with the checkpointed floating point
46256 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
46257 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
46258 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
46259 @samp{cvs63}. Therefore, this feature requires both
46260 @samp{org.gnu.gdb.power.htm.altivec} and
46261 @samp{org.gnu.gdb.power.htm.fpu}.
46263 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
46264 contain the 64-bit checkpointed register @samp{cppr}.
46266 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
46267 contain the 64-bit checkpointed register @samp{cdscr}.
46269 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
46270 contain the 64-bit checkpointed register @samp{ctar}.
46273 @node RISC-V Features
46274 @subsection RISC-V Features
46275 @cindex target descriptions, RISC-V Features
46277 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
46278 targets. It should contain the registers @samp{x0} through
46279 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
46280 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
46283 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
46284 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
46285 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
46286 architectural register names, or the ABI names can be used.
46288 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
46289 it should contain registers that are not backed by real registers on
46290 the target, but are instead virtual, where the register value is
46291 derived from other target state. In many ways these are like
46292 @value{GDBN}s pseudo-registers, except implemented by the target.
46293 Currently the only register expected in this set is the one byte
46294 @samp{priv} register that contains the target's privilege level in the
46295 least significant two bits.
46297 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
46298 should contain all of the target's standard CSRs. Standard CSRs are
46299 those defined in the RISC-V specification documents. There is some
46300 overlap between this feature and the fpu feature; the @samp{fflags},
46301 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
46302 expectation is that these registers will be in the fpu feature if the
46303 target has floating point hardware, but can be moved into the csr
46304 feature if the target has the floating point control registers, but no
46305 other floating point hardware.
46308 @subsection RX Features
46309 @cindex target descriptions, RX Features
46311 The @samp{org.gnu.gdb.rx.core} feature is required for RX
46312 targets. It should contain the registers @samp{r0} through
46313 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
46314 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
46316 @node S/390 and System z Features
46317 @subsection S/390 and System z Features
46318 @cindex target descriptions, S/390 features
46319 @cindex target descriptions, System z features
46321 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
46322 System z targets. It should contain the PSW and the 16 general
46323 registers. In particular, System z targets should provide the 64-bit
46324 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
46325 S/390 targets should provide the 32-bit versions of these registers.
46326 A System z target that runs in 31-bit addressing mode should provide
46327 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
46328 register's upper halves @samp{r0h} through @samp{r15h}, and their
46329 lower halves @samp{r0l} through @samp{r15l}.
46331 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
46332 contain the 64-bit registers @samp{f0} through @samp{f15}, and
46335 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
46336 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
46338 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
46339 contain the register @samp{orig_r2}, which is 64-bit wide on System z
46340 targets and 32-bit otherwise. In addition, the feature may contain
46341 the @samp{last_break} register, whose width depends on the addressing
46342 mode, as well as the @samp{system_call} register, which is always
46345 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
46346 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
46347 @samp{atia}, and @samp{tr0} through @samp{tr15}.
46349 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
46350 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
46351 combined by @value{GDBN} with the floating point registers @samp{f0}
46352 through @samp{f15} to present the 128-bit wide vector registers
46353 @samp{v0} through @samp{v15}. In addition, this feature should
46354 contain the 128-bit wide vector registers @samp{v16} through
46357 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
46358 the 64-bit wide guarded-storage-control registers @samp{gsd},
46359 @samp{gssm}, and @samp{gsepla}.
46361 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
46362 the 64-bit wide guarded-storage broadcast control registers
46363 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
46365 @node Sparc Features
46366 @subsection Sparc Features
46367 @cindex target descriptions, sparc32 features
46368 @cindex target descriptions, sparc64 features
46369 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
46370 targets. It should describe the following registers:
46374 @samp{g0} through @samp{g7}
46376 @samp{o0} through @samp{o7}
46378 @samp{l0} through @samp{l7}
46380 @samp{i0} through @samp{i7}
46383 They may be 32-bit or 64-bit depending on the target.
46385 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
46386 targets. It should describe the following registers:
46390 @samp{f0} through @samp{f31}
46392 @samp{f32} through @samp{f62} for sparc64
46395 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46396 targets. It should describe the following registers:
46400 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46401 @samp{fsr}, and @samp{csr} for sparc32
46403 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46407 @node TIC6x Features
46408 @subsection TMS320C6x Features
46409 @cindex target descriptions, TIC6x features
46410 @cindex target descriptions, TMS320C6x features
46411 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46412 targets. It should contain registers @samp{A0} through @samp{A15},
46413 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46415 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46416 contain registers @samp{A16} through @samp{A31} and @samp{B16}
46417 through @samp{B31}.
46419 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46420 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46422 @node Operating System Information
46423 @appendix Operating System Information
46424 @cindex operating system information
46426 Users of @value{GDBN} often wish to obtain information about the state of
46427 the operating system running on the target---for example the list of
46428 processes, or the list of open files. This section describes the
46429 mechanism that makes it possible. This mechanism is similar to the
46430 target features mechanism (@pxref{Target Descriptions}), but focuses
46431 on a different aspect of target.
46433 Operating system information is retrieved from the target via the
46434 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46435 read}). The object name in the request should be @samp{osdata}, and
46436 the @var{annex} identifies the data to be fetched.
46443 @appendixsection Process list
46444 @cindex operating system information, process list
46446 When requesting the process list, the @var{annex} field in the
46447 @samp{qXfer} request should be @samp{processes}. The returned data is
46448 an XML document. The formal syntax of this document is defined in
46449 @file{gdb/features/osdata.dtd}.
46451 An example document is:
46454 <?xml version="1.0"?>
46455 <!DOCTYPE target SYSTEM "osdata.dtd">
46456 <osdata type="processes">
46458 <column name="pid">1</column>
46459 <column name="user">root</column>
46460 <column name="command">/sbin/init</column>
46461 <column name="cores">1,2,3</column>
46466 Each item should include a column whose name is @samp{pid}. The value
46467 of that column should identify the process on the target. The
46468 @samp{user} and @samp{command} columns are optional, and will be
46469 displayed by @value{GDBN}. The @samp{cores} column, if present,
46470 should contain a comma-separated list of cores that this process
46471 is running on. Target may provide additional columns,
46472 which @value{GDBN} currently ignores.
46474 @node Trace File Format
46475 @appendix Trace File Format
46476 @cindex trace file format
46478 The trace file comes in three parts: a header, a textual description
46479 section, and a trace frame section with binary data.
46481 The header has the form @code{\x7fTRACE0\n}. The first byte is
46482 @code{0x7f} so as to indicate that the file contains binary data,
46483 while the @code{0} is a version number that may have different values
46486 The description section consists of multiple lines of @sc{ascii} text
46487 separated by newline characters (@code{0xa}). The lines may include a
46488 variety of optional descriptive or context-setting information, such
46489 as tracepoint definitions or register set size. @value{GDBN} will
46490 ignore any line that it does not recognize. An empty line marks the end
46495 Specifies the size of a register block in bytes. This is equal to the
46496 size of a @code{g} packet payload in the remote protocol. @var{size}
46497 is an ascii decimal number. There should be only one such line in
46498 a single trace file.
46500 @item status @var{status}
46501 Trace status. @var{status} has the same format as a @code{qTStatus}
46502 remote packet reply. There should be only one such line in a single trace
46505 @item tp @var{payload}
46506 Tracepoint definition. The @var{payload} has the same format as
46507 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
46508 may take multiple lines of definition, corresponding to the multiple
46511 @item tsv @var{payload}
46512 Trace state variable definition. The @var{payload} has the same format as
46513 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
46514 may take multiple lines of definition, corresponding to the multiple
46517 @item tdesc @var{payload}
46518 Target description in XML format. The @var{payload} is a single line of
46519 the XML file. All such lines should be concatenated together to get
46520 the original XML file. This file is in the same format as @code{qXfer}
46521 @code{features} payload, and corresponds to the main @code{target.xml}
46522 file. Includes are not allowed.
46526 The trace frame section consists of a number of consecutive frames.
46527 Each frame begins with a two-byte tracepoint number, followed by a
46528 four-byte size giving the amount of data in the frame. The data in
46529 the frame consists of a number of blocks, each introduced by a
46530 character indicating its type (at least register, memory, and trace
46531 state variable). The data in this section is raw binary, not a
46532 hexadecimal or other encoding; its endianness matches the target's
46535 @c FIXME bi-arch may require endianness/arch info in description section
46538 @item R @var{bytes}
46539 Register block. The number and ordering of bytes matches that of a
46540 @code{g} packet in the remote protocol. Note that these are the
46541 actual bytes, in target order, not a hexadecimal encoding.
46543 @item M @var{address} @var{length} @var{bytes}...
46544 Memory block. This is a contiguous block of memory, at the 8-byte
46545 address @var{address}, with a 2-byte length @var{length}, followed by
46546 @var{length} bytes.
46548 @item V @var{number} @var{value}
46549 Trace state variable block. This records the 8-byte signed value
46550 @var{value} of trace state variable numbered @var{number}.
46554 Future enhancements of the trace file format may include additional types
46557 @node Index Section Format
46558 @appendix @code{.gdb_index} section format
46559 @cindex .gdb_index section format
46560 @cindex index section format
46562 This section documents the index section that is created by @code{save
46563 gdb-index} (@pxref{Index Files}). The index section is
46564 DWARF-specific; some knowledge of DWARF is assumed in this
46567 The mapped index file format is designed to be directly
46568 @code{mmap}able on any architecture. In most cases, a datum is
46569 represented using a little-endian 32-bit integer value, called an
46570 @code{offset_type}. Big endian machines must byte-swap the values
46571 before using them. Exceptions to this rule are noted. The data is
46572 laid out such that alignment is always respected.
46574 A mapped index consists of several areas, laid out in order.
46578 The file header. This is a sequence of values, of @code{offset_type}
46579 unless otherwise noted:
46583 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
46584 Version 4 uses a different hashing function from versions 5 and 6.
46585 Version 6 includes symbols for inlined functions, whereas versions 4
46586 and 5 do not. Version 7 adds attributes to the CU indices in the
46587 symbol table. Version 8 specifies that symbols from DWARF type units
46588 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
46589 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
46591 @value{GDBN} will only read version 4, 5, or 6 indices
46592 by specifying @code{set use-deprecated-index-sections on}.
46593 GDB has a workaround for potentially broken version 7 indices so it is
46594 currently not flagged as deprecated.
46597 The offset, from the start of the file, of the CU list.
46600 The offset, from the start of the file, of the types CU list. Note
46601 that this area can be empty, in which case this offset will be equal
46602 to the next offset.
46605 The offset, from the start of the file, of the address area.
46608 The offset, from the start of the file, of the symbol table.
46611 The offset, from the start of the file, of the constant pool.
46615 The CU list. This is a sequence of pairs of 64-bit little-endian
46616 values, sorted by the CU offset. The first element in each pair is
46617 the offset of a CU in the @code{.debug_info} section. The second
46618 element in each pair is the length of that CU. References to a CU
46619 elsewhere in the map are done using a CU index, which is just the
46620 0-based index into this table. Note that if there are type CUs, then
46621 conceptually CUs and type CUs form a single list for the purposes of
46625 The types CU list. This is a sequence of triplets of 64-bit
46626 little-endian values. In a triplet, the first value is the CU offset,
46627 the second value is the type offset in the CU, and the third value is
46628 the type signature. The types CU list is not sorted.
46631 The address area. The address area consists of a sequence of address
46632 entries. Each address entry has three elements:
46636 The low address. This is a 64-bit little-endian value.
46639 The high address. This is a 64-bit little-endian value. Like
46640 @code{DW_AT_high_pc}, the value is one byte beyond the end.
46643 The CU index. This is an @code{offset_type} value.
46647 The symbol table. This is an open-addressed hash table. The size of
46648 the hash table is always a power of 2.
46650 Each slot in the hash table consists of a pair of @code{offset_type}
46651 values. The first value is the offset of the symbol's name in the
46652 constant pool. The second value is the offset of the CU vector in the
46655 If both values are 0, then this slot in the hash table is empty. This
46656 is ok because while 0 is a valid constant pool index, it cannot be a
46657 valid index for both a string and a CU vector.
46659 The hash value for a table entry is computed by applying an
46660 iterative hash function to the symbol's name. Starting with an
46661 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
46662 the string is incorporated into the hash using the formula depending on the
46667 The formula is @code{r = r * 67 + c - 113}.
46669 @item Versions 5 to 7
46670 The formula is @code{r = r * 67 + tolower (c) - 113}.
46673 The terminating @samp{\0} is not incorporated into the hash.
46675 The step size used in the hash table is computed via
46676 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46677 value, and @samp{size} is the size of the hash table. The step size
46678 is used to find the next candidate slot when handling a hash
46681 The names of C@t{++} symbols in the hash table are canonicalized. We
46682 don't currently have a simple description of the canonicalization
46683 algorithm; if you intend to create new index sections, you must read
46687 The constant pool. This is simply a bunch of bytes. It is organized
46688 so that alignment is correct: CU vectors are stored first, followed by
46691 A CU vector in the constant pool is a sequence of @code{offset_type}
46692 values. The first value is the number of CU indices in the vector.
46693 Each subsequent value is the index and symbol attributes of a CU in
46694 the CU list. This element in the hash table is used to indicate which
46695 CUs define the symbol and how the symbol is used.
46696 See below for the format of each CU index+attributes entry.
46698 A string in the constant pool is zero-terminated.
46701 Attributes were added to CU index values in @code{.gdb_index} version 7.
46702 If a symbol has multiple uses within a CU then there is one
46703 CU index+attributes value for each use.
46705 The format of each CU index+attributes entry is as follows
46711 This is the index of the CU in the CU list.
46713 These bits are reserved for future purposes and must be zero.
46715 The kind of the symbol in the CU.
46719 This value is reserved and should not be used.
46720 By reserving zero the full @code{offset_type} value is backwards compatible
46721 with previous versions of the index.
46723 The symbol is a type.
46725 The symbol is a variable or an enum value.
46727 The symbol is a function.
46729 Any other kind of symbol.
46731 These values are reserved.
46735 This bit is zero if the value is global and one if it is static.
46737 The determination of whether a symbol is global or static is complicated.
46738 The authorative reference is the file @file{dwarf2read.c} in
46739 @value{GDBN} sources.
46743 This pseudo-code describes the computation of a symbol's kind and
46744 global/static attributes in the index.
46747 is_external = get_attribute (die, DW_AT_external);
46748 language = get_attribute (cu_die, DW_AT_language);
46751 case DW_TAG_typedef:
46752 case DW_TAG_base_type:
46753 case DW_TAG_subrange_type:
46757 case DW_TAG_enumerator:
46759 is_static = language != CPLUS;
46761 case DW_TAG_subprogram:
46763 is_static = ! (is_external || language == ADA);
46765 case DW_TAG_constant:
46767 is_static = ! is_external;
46769 case DW_TAG_variable:
46771 is_static = ! is_external;
46773 case DW_TAG_namespace:
46777 case DW_TAG_class_type:
46778 case DW_TAG_interface_type:
46779 case DW_TAG_structure_type:
46780 case DW_TAG_union_type:
46781 case DW_TAG_enumeration_type:
46783 is_static = language != CPLUS;
46791 @appendix Manual pages
46795 * gdb man:: The GNU Debugger man page
46796 * gdbserver man:: Remote Server for the GNU Debugger man page
46797 * gcore man:: Generate a core file of a running program
46798 * gdbinit man:: gdbinit scripts
46799 * gdb-add-index man:: Add index files to speed up GDB
46805 @c man title gdb The GNU Debugger
46807 @c man begin SYNOPSIS gdb
46808 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46809 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46810 [@option{-b}@w{ }@var{bps}]
46811 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46812 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46813 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46814 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46815 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46818 @c man begin DESCRIPTION gdb
46819 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46820 going on ``inside'' another program while it executes -- or what another
46821 program was doing at the moment it crashed.
46823 @value{GDBN} can do four main kinds of things (plus other things in support of
46824 these) to help you catch bugs in the act:
46828 Start your program, specifying anything that might affect its behavior.
46831 Make your program stop on specified conditions.
46834 Examine what has happened, when your program has stopped.
46837 Change things in your program, so you can experiment with correcting the
46838 effects of one bug and go on to learn about another.
46841 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46844 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46845 commands from the terminal until you tell it to exit with the @value{GDBN}
46846 command @code{quit}. You can get online help from @value{GDBN} itself
46847 by using the command @code{help}.
46849 You can run @code{gdb} with no arguments or options; but the most
46850 usual way to start @value{GDBN} is with one argument or two, specifying an
46851 executable program as the argument:
46857 You can also start with both an executable program and a core file specified:
46863 You can, instead, specify a process ID as a second argument or use option
46864 @code{-p}, if you want to debug a running process:
46872 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46873 can omit the @var{program} filename.
46875 Here are some of the most frequently needed @value{GDBN} commands:
46877 @c pod2man highlights the right hand side of the @item lines.
46879 @item break [@var{file}:]@var{function}
46880 Set a breakpoint at @var{function} (in @var{file}).
46882 @item run [@var{arglist}]
46883 Start your program (with @var{arglist}, if specified).
46886 Backtrace: display the program stack.
46888 @item print @var{expr}
46889 Display the value of an expression.
46892 Continue running your program (after stopping, e.g. at a breakpoint).
46895 Execute next program line (after stopping); step @emph{over} any
46896 function calls in the line.
46898 @item edit [@var{file}:]@var{function}
46899 look at the program line where it is presently stopped.
46901 @item list [@var{file}:]@var{function}
46902 type the text of the program in the vicinity of where it is presently stopped.
46905 Execute next program line (after stopping); step @emph{into} any
46906 function calls in the line.
46908 @item help [@var{name}]
46909 Show information about @value{GDBN} command @var{name}, or general information
46910 about using @value{GDBN}.
46913 Exit from @value{GDBN}.
46917 For full details on @value{GDBN},
46918 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46919 by Richard M. Stallman and Roland H. Pesch. The same text is available online
46920 as the @code{gdb} entry in the @code{info} program.
46924 @c man begin OPTIONS gdb
46925 Any arguments other than options specify an executable
46926 file and core file (or process ID); that is, the first argument
46927 encountered with no
46928 associated option flag is equivalent to a @option{-se} option, and the second,
46929 if any, is equivalent to a @option{-c} option if it's the name of a file.
46931 both long and short forms; both are shown here. The long forms are also
46932 recognized if you truncate them, so long as enough of the option is
46933 present to be unambiguous. (If you prefer, you can flag option
46934 arguments with @option{+} rather than @option{-}, though we illustrate the
46935 more usual convention.)
46937 All the options and command line arguments you give are processed
46938 in sequential order. The order makes a difference when the @option{-x}
46944 List all options, with brief explanations.
46946 @item -symbols=@var{file}
46947 @itemx -s @var{file}
46948 Read symbol table from file @var{file}.
46951 Enable writing into executable and core files.
46953 @item -exec=@var{file}
46954 @itemx -e @var{file}
46955 Use file @var{file} as the executable file to execute when
46956 appropriate, and for examining pure data in conjunction with a core
46959 @item -se=@var{file}
46960 Read symbol table from file @var{file} and use it as the executable
46963 @item -core=@var{file}
46964 @itemx -c @var{file}
46965 Use file @var{file} as a core dump to examine.
46967 @item -command=@var{file}
46968 @itemx -x @var{file}
46969 Execute @value{GDBN} commands from file @var{file}.
46971 @item -ex @var{command}
46972 Execute given @value{GDBN} @var{command}.
46974 @item -directory=@var{directory}
46975 @itemx -d @var{directory}
46976 Add @var{directory} to the path to search for source files.
46979 Do not execute commands from @file{~/.config/gdb/gdbinit},
46980 @file{~/.gdbinit}, @file{~/.config/gdb/gdbearlyinit}, or
46981 @file{~/.gdbearlyinit}
46985 Do not execute commands from any @file{.gdbinit} or
46986 @file{.gdbearlyinit} initialization files.
46990 ``Quiet''. Do not print the introductory and copyright messages. These
46991 messages are also suppressed in batch mode.
46994 Run in batch mode. Exit with status @code{0} after processing all the command
46995 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46996 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46997 commands in the command files.
46999 Batch mode may be useful for running @value{GDBN} as a filter, for example to
47000 download and run a program on another computer; in order to make this
47001 more useful, the message
47004 Program exited normally.
47008 (which is ordinarily issued whenever a program running under @value{GDBN} control
47009 terminates) is not issued when running in batch mode.
47011 @item -cd=@var{directory}
47012 Run @value{GDBN} using @var{directory} as its working directory,
47013 instead of the current directory.
47017 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
47018 @value{GDBN} to output the full file name and line number in a standard,
47019 recognizable fashion each time a stack frame is displayed (which
47020 includes each time the program stops). This recognizable format looks
47021 like two @samp{\032} characters, followed by the file name, line number
47022 and character position separated by colons, and a newline. The
47023 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
47024 characters as a signal to display the source code for the frame.
47027 Set the line speed (baud rate or bits per second) of any serial
47028 interface used by @value{GDBN} for remote debugging.
47030 @item -tty=@var{device}
47031 Run using @var{device} for your program's standard input and output.
47035 @c man begin SEEALSO gdb
47037 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47038 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47039 documentation are properly installed at your site, the command
47046 should give you access to the complete manual.
47048 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47049 Richard M. Stallman and Roland H. Pesch, July 1991.
47053 @node gdbserver man
47054 @heading gdbserver man
47056 @c man title gdbserver Remote Server for the GNU Debugger
47058 @c man begin SYNOPSIS gdbserver
47059 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47061 gdbserver --attach @var{comm} @var{pid}
47063 gdbserver --multi @var{comm}
47067 @c man begin DESCRIPTION gdbserver
47068 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
47069 than the one which is running the program being debugged.
47072 @subheading Usage (server (target) side)
47075 Usage (server (target) side):
47078 First, you need to have a copy of the program you want to debug put onto
47079 the target system. The program can be stripped to save space if needed, as
47080 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
47081 the @value{GDBN} running on the host system.
47083 To use the server, you log on to the target system, and run the @command{gdbserver}
47084 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
47085 your program, and (c) its arguments. The general syntax is:
47088 target> gdbserver @var{comm} @var{program} [@var{args} ...]
47091 For example, using a serial port, you might say:
47095 @c @file would wrap it as F</dev/com1>.
47096 target> gdbserver /dev/com1 emacs foo.txt
47099 target> gdbserver @file{/dev/com1} emacs foo.txt
47103 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
47104 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
47105 waits patiently for the host @value{GDBN} to communicate with it.
47107 To use a TCP connection, you could say:
47110 target> gdbserver host:2345 emacs foo.txt
47113 This says pretty much the same thing as the last example, except that we are
47114 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
47115 that we are expecting to see a TCP connection from @code{host} to local TCP port
47116 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
47117 want for the port number as long as it does not conflict with any existing TCP
47118 ports on the target system. This same port number must be used in the host
47119 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
47120 you chose a port number that conflicts with another service, @command{gdbserver} will
47121 print an error message and exit.
47123 @command{gdbserver} can also attach to running programs.
47124 This is accomplished via the @option{--attach} argument. The syntax is:
47127 target> gdbserver --attach @var{comm} @var{pid}
47130 @var{pid} is the process ID of a currently running process. It isn't
47131 necessary to point @command{gdbserver} at a binary for the running process.
47133 To start @code{gdbserver} without supplying an initial command to run
47134 or process ID to attach, use the @option{--multi} command line option.
47135 In such case you should connect using @kbd{target extended-remote} to start
47136 the program you want to debug.
47139 target> gdbserver --multi @var{comm}
47143 @subheading Usage (host side)
47149 You need an unstripped copy of the target program on your host system, since
47150 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
47151 would, with the target program as the first argument. (You may need to use the
47152 @option{--baud} option if the serial line is running at anything except 9600 baud.)
47153 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
47154 new command you need to know about is @code{target remote}
47155 (or @code{target extended-remote}). Its argument is either
47156 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
47157 descriptor. For example:
47161 @c @file would wrap it as F</dev/ttyb>.
47162 (gdb) target remote /dev/ttyb
47165 (gdb) target remote @file{/dev/ttyb}
47170 communicates with the server via serial line @file{/dev/ttyb}, and:
47173 (gdb) target remote the-target:2345
47177 communicates via a TCP connection to port 2345 on host `the-target', where
47178 you previously started up @command{gdbserver} with the same port number. Note that for
47179 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
47180 command, otherwise you may get an error that looks something like
47181 `Connection refused'.
47183 @command{gdbserver} can also debug multiple inferiors at once,
47186 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
47187 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
47190 @ref{Inferiors Connections and Programs}.
47192 In such case use the @code{extended-remote} @value{GDBN} command variant:
47195 (gdb) target extended-remote the-target:2345
47198 The @command{gdbserver} option @option{--multi} may or may not be used in such
47202 @c man begin OPTIONS gdbserver
47203 There are three different modes for invoking @command{gdbserver}:
47208 Debug a specific program specified by its program name:
47211 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47214 The @var{comm} parameter specifies how should the server communicate
47215 with @value{GDBN}; it is either a device name (to use a serial line),
47216 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
47217 stdin/stdout of @code{gdbserver}. Specify the name of the program to
47218 debug in @var{prog}. Any remaining arguments will be passed to the
47219 program verbatim. When the program exits, @value{GDBN} will close the
47220 connection, and @code{gdbserver} will exit.
47223 Debug a specific program by specifying the process ID of a running
47227 gdbserver --attach @var{comm} @var{pid}
47230 The @var{comm} parameter is as described above. Supply the process ID
47231 of a running program in @var{pid}; @value{GDBN} will do everything
47232 else. Like with the previous mode, when the process @var{pid} exits,
47233 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
47236 Multi-process mode -- debug more than one program/process:
47239 gdbserver --multi @var{comm}
47242 In this mode, @value{GDBN} can instruct @command{gdbserver} which
47243 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
47244 close the connection when a process being debugged exits, so you can
47245 debug several processes in the same session.
47248 In each of the modes you may specify these options:
47253 List all options, with brief explanations.
47256 This option causes @command{gdbserver} to print its version number and exit.
47259 @command{gdbserver} will attach to a running program. The syntax is:
47262 target> gdbserver --attach @var{comm} @var{pid}
47265 @var{pid} is the process ID of a currently running process. It isn't
47266 necessary to point @command{gdbserver} at a binary for the running process.
47269 To start @code{gdbserver} without supplying an initial command to run
47270 or process ID to attach, use this command line option.
47271 Then you can connect using @kbd{target extended-remote} and start
47272 the program you want to debug. The syntax is:
47275 target> gdbserver --multi @var{comm}
47279 Instruct @code{gdbserver} to display extra status information about the debugging
47281 This option is intended for @code{gdbserver} development and for bug reports to
47284 @item --remote-debug
47285 Instruct @code{gdbserver} to display remote protocol debug output.
47286 This option is intended for @code{gdbserver} development and for bug reports to
47289 @item --debug-file=@var{filename}
47290 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
47291 This option is intended for @code{gdbserver} development and for bug reports to
47294 @item --debug-format=option1@r{[},option2,...@r{]}
47295 Instruct @code{gdbserver} to include extra information in each line
47296 of debugging output.
47297 @xref{Other Command-Line Arguments for gdbserver}.
47300 Specify a wrapper to launch programs
47301 for debugging. The option should be followed by the name of the
47302 wrapper, then any command-line arguments to pass to the wrapper, then
47303 @kbd{--} indicating the end of the wrapper arguments.
47306 By default, @command{gdbserver} keeps the listening TCP port open, so that
47307 additional connections are possible. However, if you start @code{gdbserver}
47308 with the @option{--once} option, it will stop listening for any further
47309 connection attempts after connecting to the first @value{GDBN} session.
47311 @c --disable-packet is not documented for users.
47313 @c --disable-randomization and --no-disable-randomization are superseded by
47314 @c QDisableRandomization.
47319 @c man begin SEEALSO gdbserver
47321 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47322 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47323 documentation are properly installed at your site, the command
47329 should give you access to the complete manual.
47331 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47332 Richard M. Stallman and Roland H. Pesch, July 1991.
47339 @c man title gcore Generate a core file of a running program
47342 @c man begin SYNOPSIS gcore
47343 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
47347 @c man begin DESCRIPTION gcore
47348 Generate core dumps of one or more running programs with process IDs
47349 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
47350 is equivalent to one produced by the kernel when the process crashes
47351 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
47352 limit). However, unlike after a crash, after @command{gcore} finishes
47353 its job the program remains running without any change.
47356 @c man begin OPTIONS gcore
47359 Dump all memory mappings. The actual effect of this option depends on
47360 the Operating System. On @sc{gnu}/Linux, it will disable
47361 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
47362 enable @code{dump-excluded-mappings} (@pxref{set
47363 dump-excluded-mappings}).
47365 @item -o @var{prefix}
47366 The optional argument @var{prefix} specifies the prefix to be used
47367 when composing the file names of the core dumps. The file name is
47368 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
47369 process ID of the running program being analyzed by @command{gcore}.
47370 If not specified, @var{prefix} defaults to @var{gcore}.
47374 @c man begin SEEALSO gcore
47376 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47377 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47378 documentation are properly installed at your site, the command
47385 should give you access to the complete manual.
47387 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47388 Richard M. Stallman and Roland H. Pesch, July 1991.
47395 @c man title gdbinit GDB initialization scripts
47398 @c man begin SYNOPSIS gdbinit
47399 @ifset SYSTEM_GDBINIT
47400 @value{SYSTEM_GDBINIT}
47403 @ifset SYSTEM_GDBINIT_DIR
47404 @value{SYSTEM_GDBINIT_DIR}/*
47407 ~/.config/gdb/gdbinit
47415 @c man begin DESCRIPTION gdbinit
47416 These files contain @value{GDBN} commands to automatically execute during
47417 @value{GDBN} startup. The lines of contents are canned sequences of commands,
47420 the @value{GDBN} manual in node @code{Sequences}
47421 -- shell command @code{info -f gdb -n Sequences}.
47427 Please read more in
47429 the @value{GDBN} manual in node @code{Startup}
47430 -- shell command @code{info -f gdb -n Startup}.
47437 @ifset SYSTEM_GDBINIT
47438 @item @value{SYSTEM_GDBINIT}
47440 @ifclear SYSTEM_GDBINIT
47441 @item (not enabled with @code{--with-system-gdbinit} during compilation)
47443 System-wide initialization file. It is executed unless user specified
47444 @value{GDBN} option @code{-nx} or @code{-n}.
47447 the @value{GDBN} manual in node @code{System-wide configuration}
47448 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47450 @ifset SYSTEM_GDBINIT_DIR
47451 @item @value{SYSTEM_GDBINIT_DIR}
47453 @ifclear SYSTEM_GDBINIT_DIR
47454 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
47456 System-wide initialization directory. All files in this directory are
47457 executed on startup unless user specified @value{GDBN} option @code{-nx} or
47458 @code{-n}, as long as they have a recognized file extension.
47461 the @value{GDBN} manual in node @code{System-wide configuration}
47462 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47465 @ref{System-wide configuration}.
47468 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
47469 User initialization file. It is executed unless user specified
47470 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
47472 @item @file{.gdbinit}
47473 Initialization file for current directory. It may need to be enabled with
47474 @value{GDBN} security command @code{set auto-load local-gdbinit}.
47477 the @value{GDBN} manual in node @code{Init File in the Current Directory}
47478 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
47481 @ref{Init File in the Current Directory}.
47486 @c man begin SEEALSO gdbinit
47488 gdb(1), @code{info -f gdb -n Startup}
47490 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47491 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47492 documentation are properly installed at your site, the command
47498 should give you access to the complete manual.
47500 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47501 Richard M. Stallman and Roland H. Pesch, July 1991.
47505 @node gdb-add-index man
47506 @heading gdb-add-index
47507 @pindex gdb-add-index
47508 @anchor{gdb-add-index}
47510 @c man title gdb-add-index Add index files to speed up GDB
47512 @c man begin SYNOPSIS gdb-add-index
47513 gdb-add-index @var{filename}
47516 @c man begin DESCRIPTION gdb-add-index
47517 When @value{GDBN} finds a symbol file, it scans the symbols in the
47518 file in order to construct an internal symbol table. This lets most
47519 @value{GDBN} operations work quickly--at the cost of a delay early on.
47520 For large programs, this delay can be quite lengthy, so @value{GDBN}
47521 provides a way to build an index, which speeds up startup.
47523 To determine whether a file contains such an index, use the command
47524 @kbd{readelf -S filename}: the index is stored in a section named
47525 @code{.gdb_index}. The index file can only be produced on systems
47526 which use ELF binaries and DWARF debug information (i.e., sections
47527 named @code{.debug_*}).
47529 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
47530 in the @env{PATH} environment variable. If you want to use different
47531 versions of these programs, you can specify them through the
47532 @env{GDB} and @env{OBJDUMP} environment variables.
47536 the @value{GDBN} manual in node @code{Index Files}
47537 -- shell command @kbd{info -f gdb -n "Index Files"}.
47544 @c man begin SEEALSO gdb-add-index
47546 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47547 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47548 documentation are properly installed at your site, the command
47554 should give you access to the complete manual.
47556 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47557 Richard M. Stallman and Roland H. Pesch, July 1991.
47563 @node GNU Free Documentation License
47564 @appendix GNU Free Documentation License
47567 @node Concept Index
47568 @unnumbered Concept Index
47572 @node Command and Variable Index
47573 @unnumbered Command, Variable, and Function Index
47578 % I think something like @@colophon should be in texinfo. In the
47580 \long\def\colophon{\hbox to0pt{}\vfill
47581 \centerline{The body of this manual is set in}
47582 \centerline{\fontname\tenrm,}
47583 \centerline{with headings in {\bf\fontname\tenbf}}
47584 \centerline{and examples in {\tt\fontname\tentt}.}
47585 \centerline{{\it\fontname\tenit\/},}
47586 \centerline{{\bf\fontname\tenbf}, and}
47587 \centerline{{\sl\fontname\tensl\/}}
47588 \centerline{are used for emphasis.}\vfill}
47590 % Blame: doc@@cygnus.com, 1991.