Update the 'g' packet documentation
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2023 Free Software Foundation, Inc.
3 @c
4 @c %**start of header
5 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6 @c of @set vars. However, you can override filename with makeinfo -o.
7 @setfilename gdb.info
8 @c
9 @c man begin INCLUDE
10 @include gdb-cfg.texi
11 @c man end
12 @c
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
15 @c %**end of header
16
17 @iftex
18 @c @smallbook
19 @c @cropmarks
20 @end iftex
21
22 @finalout
23 @c To avoid file-name clashes between index.html and Index.html, when
24 @c the manual is produced on a Posix host and then moved to a
25 @c case-insensitive filesystem (e.g., MS-Windows), we separate the
26 @c indices into two: Concept Index and all the rest.
27 @syncodeindex ky fn
28 @syncodeindex tp fn
29
30 @c readline appendices use @vindex, @findex and @ftable,
31 @c annotate.texi and gdbmi use @findex.
32 @syncodeindex vr fn
33
34 @c !!set GDB manual's edition---not the same as GDB version!
35 @c This is updated by GNU Press.
36 @set EDITION Tenth
37
38 @c !!set GDB edit command default editor
39 @set EDITOR /bin/ex
40
41 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
42
43 @c This is a dir.info fragment to support semi-automated addition of
44 @c manuals to an info tree.
45 @dircategory Software development
46 @direntry
47 * Gdb: (gdb). The GNU debugger.
48 * gdbserver: (gdb) Server. The GNU debugging server.
49 @end direntry
50
51 @copying
52 @c man begin COPYRIGHT
53 Copyright @copyright{} 1988-2023 Free Software Foundation, Inc.
54
55 Permission is granted to copy, distribute and/or modify this document
56 under the terms of the GNU Free Documentation License, Version 1.3 or
57 any later version published by the Free Software Foundation; with the
58 Invariant Sections being ``Free Software'' and ``Free Software Needs
59 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60 and with the Back-Cover Texts as in (a) below.
61
62 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63 this GNU Manual. Buying copies from GNU Press supports the FSF in
64 developing GNU and promoting software freedom.''
65 @c man end
66 @end copying
67
68 @ifnottex
69 This file documents the @sc{gnu} debugger @value{GDBN}.
70
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}
75 @end ifset
76 Version @value{GDBVN}.
77
78 @insertcopying
79 @end ifnottex
80
81 @titlepage
82 @title Debugging with @value{GDBN}
83 @subtitle The @sc{gnu} Source-Level Debugger
84 @sp 1
85 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
86 @ifset VERSION_PACKAGE
87 @sp 1
88 @subtitle @value{VERSION_PACKAGE}
89 @end ifset
90 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
91 @page
92 @tex
93 {\parskip=0pt
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
97 }
98 @end tex
99
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 @*
105
106 @insertcopying
107 @end titlepage
108 @page
109
110 @ifnottex
111 @node Top, Summary
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, for @value{GDBN}
118 @ifset VERSION_PACKAGE
119 @value{VERSION_PACKAGE}
120 @end ifset
121 Version @value{GDBVN}.
122
123 Copyright (C) 1988-2023 Free Software Foundation, Inc.
124
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.
128
129 @menu
130 * Summary:: Summary of @value{GDBN}
131 * Sample Session:: A sample @value{GDBN} session
132
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
146
147 * Languages:: Using @value{GDBN} with different languages
148
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
164
165 * GDB Bugs:: Reporting bugs in @value{GDBN}
166
167 @ifset SYSTEM_READLINE
168 * Command Line Editing: (rluserman). Command Line Editing
169 * Using History Interactively: (history). Using History Interactively
170 @end ifset
171 @ifclear SYSTEM_READLINE
172 * Command Line Editing:: Command Line Editing
173 * Using History Interactively:: Using History Interactively
174 @end ifclear
175 * In Memoriam:: In Memoriam
176 * Formatting Documentation:: How to format and print @value{GDBN} documentation
177 * Installing GDB:: Installing @value{GDBN}
178 * Maintenance Commands:: Maintenance Commands
179 * Remote Protocol:: GDB Remote Serial Protocol
180 * Agent Expressions:: The @value{GDBN} Agent Expression Mechanism
181 * Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
183 * Operating System Information:: Getting additional information from
184 the operating system
185 * Trace File Format:: @value{GDBN} trace file format
186 * Index Section Format:: .gdb_index section format
187 * Debuginfod:: Download debugging resources with @code{debuginfod}
188 * Man Pages:: Manual pages
189 * Copying:: GNU General Public License says
190 how you can copy and share @value{GDBN}
191 * GNU Free Documentation License:: The license for this documentation
192 * Concept Index:: Index of @value{GDBN} concepts
193 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
194 functions, and Python data types
195 @end menu
196
197 @end ifnottex
198
199 @contents
200
201 @node Summary
202 @unnumbered Summary of @value{GDBN}
203
204 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
205 going on ``inside'' another program while it executes---or what another
206 program was doing at the moment it crashed.
207
208 @value{GDBN} can do four main kinds of things (plus other things in support of
209 these) to help you catch bugs in the act:
210
211 @itemize @bullet
212 @item
213 Start your program, specifying anything that might affect its behavior.
214
215 @item
216 Make your program stop on specified conditions.
217
218 @item
219 Examine what has happened, when your program has stopped.
220
221 @item
222 Change things in your program, so you can experiment with correcting the
223 effects of one bug and go on to learn about another.
224 @end itemize
225
226 You can use @value{GDBN} to debug programs written in C and C@t{++}.
227 For more information, see @ref{Supported Languages,,Supported Languages}.
228 For more information, see @ref{C,,C and C++}.
229
230 Support for D is partial. For information on D, see
231 @ref{D,,D}.
232
233 @cindex Modula-2
234 Support for Modula-2 is partial. For information on Modula-2, see
235 @ref{Modula-2,,Modula-2}.
236
237 Support for OpenCL C is partial. For information on OpenCL C, see
238 @ref{OpenCL C,,OpenCL C}.
239
240 @cindex Pascal
241 Debugging Pascal programs which use sets, subranges, file variables, or
242 nested functions does not currently work. @value{GDBN} does not support
243 entering expressions, printing values, or similar features using Pascal
244 syntax.
245
246 @cindex Fortran
247 @value{GDBN} can be used to debug programs written in Fortran, although
248 it may be necessary to refer to some variables with a trailing
249 underscore.
250
251 @value{GDBN} can be used to debug programs written in Objective-C,
252 using either the Apple/NeXT or the GNU Objective-C runtime.
253
254 @menu
255 * Free Software:: Freely redistributable software
256 * Free Documentation:: Free Software Needs Free Documentation
257 * Contributors:: Contributors to GDB
258 @end menu
259
260 @node Free Software
261 @unnumberedsec Free Software
262
263 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
264 General Public License
265 (GPL). The GPL gives you the freedom to copy or adapt a licensed
266 program---but every person getting a copy also gets with it the
267 freedom to modify that copy (which means that they must get access to
268 the source code), and the freedom to distribute further copies.
269 Typical software companies use copyrights to limit your freedoms; the
270 Free Software Foundation uses the GPL to preserve these freedoms.
271
272 Fundamentally, the General Public License is a license which says that
273 you have these freedoms and that you cannot take these freedoms away
274 from anyone else.
275
276 @node Free Documentation
277 @unnumberedsec Free Software Needs Free Documentation
278
279 The biggest deficiency in the free software community today is not in
280 the software---it is the lack of good free documentation that we can
281 include with the free software. Many of our most important
282 programs do not come with free reference manuals and free introductory
283 texts. Documentation is an essential part of any software package;
284 when an important free software package does not come with a free
285 manual and a free tutorial, that is a major gap. We have many such
286 gaps today.
287
288 Consider Perl, for instance. The tutorial manuals that people
289 normally use are non-free. How did this come about? Because the
290 authors of those manuals published them with restrictive terms---no
291 copying, no modification, source files not available---which exclude
292 them from the free software world.
293
294 That wasn't the first time this sort of thing happened, and it was far
295 from the last. Many times we have heard a GNU user eagerly describe a
296 manual that he is writing, his intended contribution to the community,
297 only to learn that he had ruined everything by signing a publication
298 contract to make it non-free.
299
300 Free documentation, like free software, is a matter of freedom, not
301 price. The problem with the non-free manual is not that publishers
302 charge a price for printed copies---that in itself is fine. (The Free
303 Software Foundation sells printed copies of manuals, too.) The
304 problem is the restrictions on the use of the manual. Free manuals
305 are available in source code form, and give you permission to copy and
306 modify. Non-free manuals do not allow this.
307
308 The criteria of freedom for a free manual are roughly the same as for
309 free software. Redistribution (including the normal kinds of
310 commercial redistribution) must be permitted, so that the manual can
311 accompany every copy of the program, both on-line and on paper.
312
313 Permission for modification of the technical content is crucial too.
314 When people modify the software, adding or changing features, if they
315 are conscientious they will change the manual too---so they can
316 provide accurate and clear documentation for the modified program. A
317 manual that leaves you no choice but to write a new manual to document
318 a changed version of the program is not really available to our
319 community.
320
321 Some kinds of limits on the way modification is handled are
322 acceptable. For example, requirements to preserve the original
323 author's copyright notice, the distribution terms, or the list of
324 authors, are ok. It is also no problem to require modified versions
325 to include notice that they were modified. Even entire sections that
326 may not be deleted or changed are acceptable, as long as they deal
327 with nontechnical topics (like this one). These kinds of restrictions
328 are acceptable because they don't obstruct the community's normal use
329 of the manual.
330
331 However, it must be possible to modify all the @emph{technical}
332 content of the manual, and then distribute the result in all the usual
333 media, through all the usual channels. Otherwise, the restrictions
334 obstruct the use of the manual, it is not free, and we need another
335 manual to replace it.
336
337 Please spread the word about this issue. Our community continues to
338 lose manuals to proprietary publishing. If we spread the word that
339 free software needs free reference manuals and free tutorials, perhaps
340 the next person who wants to contribute by writing documentation will
341 realize, before it is too late, that only free manuals contribute to
342 the free software community.
343
344 If you are writing documentation, please insist on publishing it under
345 the GNU Free Documentation License or another free documentation
346 license. Remember that this decision requires your approval---you
347 don't have to let the publisher decide. Some commercial publishers
348 will use a free license if you insist, but they will not propose the
349 option; it is up to you to raise the issue and say firmly that this is
350 what you want. If the publisher you are dealing with refuses, please
351 try other publishers. If you're not sure whether a proposed license
352 is free, write to @email{licensing@@gnu.org}.
353
354 You can encourage commercial publishers to sell more free, copylefted
355 manuals and tutorials by buying them, and particularly by buying
356 copies from the publishers that paid for their writing or for major
357 improvements. Meanwhile, try to avoid buying non-free documentation
358 at all. Check the distribution terms of a manual before you buy it,
359 and insist that whoever seeks your business must respect your freedom.
360 Check the history of the book, and try to reward the publishers that
361 have paid or pay the authors to work on it.
362
363 The Free Software Foundation maintains a list of free documentation
364 published by other publishers, at
365 @url{http://www.fsf.org/doc/other-free-books.html}.
366
367 @node Contributors
368 @unnumberedsec Contributors to @value{GDBN}
369
370 Richard Stallman was the original author of @value{GDBN}, and of many
371 other @sc{gnu} programs. Many others have contributed to its
372 development. This section attempts to credit major contributors. One
373 of the virtues of free software is that everyone is free to contribute
374 to it; with regret, we cannot actually acknowledge everyone here. The
375 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
376 blow-by-blow account.
377
378 Changes much prior to version 2.0 are lost in the mists of time.
379
380 @quotation
381 @emph{Plea:} Additions to this section are particularly welcome. If you
382 or your friends (or enemies, to be evenhanded) have been unfairly
383 omitted from this list, we would like to add your names!
384 @end quotation
385
386 So that they may not regard their many labors as thankless, we
387 particularly thank those who shepherded @value{GDBN} through major
388 releases:
389 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
390 Jim Blandy (release 4.18);
391 Jason Molenda (release 4.17);
392 Stan Shebs (release 4.14);
393 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
394 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
395 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
396 Jim Kingdon (releases 3.5, 3.4, and 3.3);
397 and Randy Smith (releases 3.2, 3.1, and 3.0).
398
399 Richard Stallman, assisted at various times by Peter TerMaat, Chris
400 Hanson, and Richard Mlynarik, handled releases through 2.8.
401
402 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
403 in @value{GDBN}, with significant additional contributions from Per
404 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
405 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
406 much general update work leading to release 3.0).
407
408 @value{GDBN} uses the BFD subroutine library to examine multiple
409 object-file formats; BFD was a joint project of David V.
410 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
411
412 David Johnson wrote the original COFF support; Pace Willison did
413 the original support for encapsulated COFF.
414
415 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
416
417 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
418 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
419 support.
420 Jean-Daniel Fekete contributed Sun 386i support.
421 Chris Hanson improved the HP9000 support.
422 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
423 David Johnson contributed Encore Umax support.
424 Jyrki Kuoppala contributed Altos 3068 support.
425 Jeff Law contributed HP PA and SOM support.
426 Keith Packard contributed NS32K support.
427 Doug Rabson contributed Acorn Risc Machine support.
428 Bob Rusk contributed Harris Nighthawk CX-UX support.
429 Chris Smith contributed Convex support (and Fortran debugging).
430 Jonathan Stone contributed Pyramid support.
431 Michael Tiemann contributed SPARC support.
432 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
433 Pace Willison contributed Intel 386 support.
434 Jay Vosburgh contributed Symmetry support.
435 Marko Mlinar contributed OpenRISC 1000 support.
436
437 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
438
439 Rich Schaefer and Peter Schauer helped with support of SunOS shared
440 libraries.
441
442 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
443 about several machine instruction sets.
444
445 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
446 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
447 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
448 and RDI targets, respectively.
449
450 Brian Fox is the author of the readline libraries providing
451 command-line editing and command history.
452
453 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
454 Modula-2 support, and contributed the Languages chapter of this manual.
455
456 Fred Fish wrote most of the support for Unix System Vr4.
457 He also enhanced the command-completion support to cover C@t{++} overloaded
458 symbols.
459
460 Hitachi America (now Renesas America), Ltd. sponsored the support for
461 H8/300, H8/500, and Super-H processors.
462
463 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
464
465 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
466 processors.
467
468 Toshiba sponsored the support for the TX39 Mips processor.
469
470 Matsushita sponsored the support for the MN10200 and MN10300 processors.
471
472 Fujitsu sponsored the support for SPARClite and FR30 processors.
473
474 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
475 watchpoints.
476
477 Michael Snyder added support for tracepoints.
478
479 Stu Grossman wrote gdbserver.
480
481 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
482 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
483
484 The following people at the Hewlett-Packard Company contributed
485 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
486 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
487 compiler, and the Text User Interface (nee Terminal User Interface):
488 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
489 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
490 provided HP-specific information in this manual.
491
492 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
493 Robert Hoehne made significant contributions to the DJGPP port.
494
495 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
496 development since 1991. Cygnus engineers who have worked on @value{GDBN}
497 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
498 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
499 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
500 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
501 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
502 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
503 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
504 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
505 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
506 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
507 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
508 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
509 Zuhn have made contributions both large and small.
510
511 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
512 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
513
514 Jim Blandy added support for preprocessor macros, while working for Red
515 Hat.
516
517 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
518 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
519 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
520 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
521 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
522 with the migration of old architectures to this new framework.
523
524 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
525 unwinder framework, this consisting of a fresh new design featuring
526 frame IDs, independent frame sniffers, and the sentinel frame. Mark
527 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
528 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
529 trad unwinders. The architecture-specific changes, each involving a
530 complete rewrite of the architecture's frame code, were carried out by
531 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
532 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
533 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
534 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
535 Weigand.
536
537 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
538 Tensilica, Inc.@: contributed support for Xtensa processors. Others
539 who have worked on the Xtensa port of @value{GDBN} in the past include
540 Steve Tjiang, John Newlin, and Scott Foehner.
541
542 Michael Eager and staff of Xilinx, Inc., contributed support for the
543 Xilinx MicroBlaze architecture.
544
545 Initial support for the FreeBSD/mips target and native configuration
546 was developed by SRI International and the University of Cambridge
547 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
548 ("CTSRD"), as part of the DARPA CRASH research programme.
549
550 Initial support for the FreeBSD/riscv target and native configuration
551 was developed by SRI International and the University of Cambridge
552 Computer Laboratory (Department of Computer Science and Technology)
553 under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
554 SSITH research programme.
555
556 The original port to the OpenRISC 1000 is believed to be due to
557 Alessandro Forin and Per Bothner. More recent ports have been the work
558 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
559 Stafford Horne.
560
561 Weimin Pan, David Faust and Jose E. Marchesi contributed support for
562 the Linux kernel BPF virtual architecture. This work was sponsored by
563 Oracle.
564
565 @node Sample Session
566 @chapter A Sample @value{GDBN} Session
567
568 You can use this manual at your leisure to read all about @value{GDBN}.
569 However, a handful of commands are enough to get started using the
570 debugger. This chapter illustrates those commands.
571
572 @iftex
573 In this sample session, we emphasize user input like this: @b{input},
574 to make it easier to pick out from the surrounding output.
575 @end iftex
576
577 @c FIXME: this example may not be appropriate for some configs, where
578 @c FIXME...primary interest is in remote use.
579
580 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
581 processor) exhibits the following bug: sometimes, when we change its
582 quote strings from the default, the commands used to capture one macro
583 definition within another stop working. In the following short @code{m4}
584 session, we define a macro @code{foo} which expands to @code{0000}; we
585 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
586 same thing. However, when we change the open quote string to
587 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
588 procedure fails to define a new synonym @code{baz}:
589
590 @smallexample
591 $ @b{cd gnu/m4}
592 $ @b{./m4}
593 @b{define(foo,0000)}
594
595 @b{foo}
596 0000
597 @b{define(bar,defn(`foo'))}
598
599 @b{bar}
600 0000
601 @b{changequote(<QUOTE>,<UNQUOTE>)}
602
603 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
604 @b{baz}
605 @b{Ctrl-d}
606 m4: End of input: 0: fatal error: EOF in string
607 @end smallexample
608
609 @noindent
610 Let us use @value{GDBN} to try to see what is going on.
611
612 @smallexample
613 $ @b{@value{GDBP} m4}
614 @c FIXME: this falsifies the exact text played out, to permit smallbook
615 @c FIXME... format to come out better.
616 @value{GDBN} is free software and you are welcome to distribute copies
617 of it under certain conditions; type "show copying" to see
618 the conditions.
619 There is absolutely no warranty for @value{GDBN}; type "show warranty"
620 for details.
621
622 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
623 (@value{GDBP})
624 @end smallexample
625
626 @noindent
627 @value{GDBN} reads only enough symbol data to know where to find the
628 rest when needed; as a result, the first prompt comes up very quickly.
629 We now tell @value{GDBN} to use a narrower display width than usual, so
630 that examples fit in this manual.
631
632 @smallexample
633 (@value{GDBP}) @b{set width 70}
634 @end smallexample
635
636 @noindent
637 We need to see how the @code{m4} built-in @code{changequote} works.
638 Having looked at the source, we know the relevant subroutine is
639 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
640 @code{break} command.
641
642 @smallexample
643 (@value{GDBP}) @b{break m4_changequote}
644 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
645 @end smallexample
646
647 @noindent
648 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
649 control; as long as control does not reach the @code{m4_changequote}
650 subroutine, the program runs as usual:
651
652 @smallexample
653 (@value{GDBP}) @b{run}
654 Starting program: /work/Editorial/gdb/gnu/m4/m4
655 @b{define(foo,0000)}
656
657 @b{foo}
658 0000
659 @end smallexample
660
661 @noindent
662 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
663 suspends execution of @code{m4}, displaying information about the
664 context where it stops.
665
666 @smallexample
667 @b{changequote(<QUOTE>,<UNQUOTE>)}
668
669 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
670 at builtin.c:879
671 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
672 @end smallexample
673
674 @noindent
675 Now we use the command @code{n} (@code{next}) to advance execution to
676 the next line of the current function.
677
678 @smallexample
679 (@value{GDBP}) @b{n}
680 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
681 : nil,
682 @end smallexample
683
684 @noindent
685 @code{set_quotes} looks like a promising subroutine. We can go into it
686 by using the command @code{s} (@code{step}) instead of @code{next}.
687 @code{step} goes to the next line to be executed in @emph{any}
688 subroutine, so it steps into @code{set_quotes}.
689
690 @smallexample
691 (@value{GDBP}) @b{s}
692 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
693 at input.c:530
694 530 if (lquote != def_lquote)
695 @end smallexample
696
697 @noindent
698 The display that shows the subroutine where @code{m4} is now
699 suspended (and its arguments) is called a stack frame display. It
700 shows a summary of the stack. We can use the @code{backtrace}
701 command (which can also be spelled @code{bt}), to see where we are
702 in the stack as a whole: the @code{backtrace} command displays a
703 stack frame for each active subroutine.
704
705 @smallexample
706 (@value{GDBP}) @b{bt}
707 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
708 at input.c:530
709 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
710 at builtin.c:882
711 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
712 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
713 at macro.c:71
714 #4 0x79dc in expand_input () at macro.c:40
715 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
716 @end smallexample
717
718 @noindent
719 We step through a few more lines to see what happens. The first two
720 times, we can use @samp{s}; the next two times we use @code{n} to avoid
721 falling into the @code{xstrdup} subroutine.
722
723 @smallexample
724 (@value{GDBP}) @b{s}
725 0x3b5c 532 if (rquote != def_rquote)
726 (@value{GDBP}) @b{s}
727 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
728 def_lquote : xstrdup(lq);
729 (@value{GDBP}) @b{n}
730 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
731 : xstrdup(rq);
732 (@value{GDBP}) @b{n}
733 538 len_lquote = strlen(rquote);
734 @end smallexample
735
736 @noindent
737 The last line displayed looks a little odd; we can examine the variables
738 @code{lquote} and @code{rquote} to see if they are in fact the new left
739 and right quotes we specified. We use the command @code{p}
740 (@code{print}) to see their values.
741
742 @smallexample
743 (@value{GDBP}) @b{p lquote}
744 $1 = 0x35d40 "<QUOTE>"
745 (@value{GDBP}) @b{p rquote}
746 $2 = 0x35d50 "<UNQUOTE>"
747 @end smallexample
748
749 @noindent
750 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
751 To look at some context, we can display ten lines of source
752 surrounding the current line with the @code{l} (@code{list}) command.
753
754 @smallexample
755 (@value{GDBP}) @b{l}
756 533 xfree(rquote);
757 534
758 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
759 : xstrdup (lq);
760 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
761 : xstrdup (rq);
762 537
763 538 len_lquote = strlen(rquote);
764 539 len_rquote = strlen(lquote);
765 540 @}
766 541
767 542 void
768 @end smallexample
769
770 @noindent
771 Let us step past the two lines that set @code{len_lquote} and
772 @code{len_rquote}, and then examine the values of those variables.
773
774 @smallexample
775 (@value{GDBP}) @b{n}
776 539 len_rquote = strlen(lquote);
777 (@value{GDBP}) @b{n}
778 540 @}
779 (@value{GDBP}) @b{p len_lquote}
780 $3 = 9
781 (@value{GDBP}) @b{p len_rquote}
782 $4 = 7
783 @end smallexample
784
785 @noindent
786 That certainly looks wrong, assuming @code{len_lquote} and
787 @code{len_rquote} are meant to be the lengths of @code{lquote} and
788 @code{rquote} respectively. We can set them to better values using
789 the @code{p} command, since it can print the value of
790 any expression---and that expression can include subroutine calls and
791 assignments.
792
793 @smallexample
794 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
795 $5 = 7
796 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
797 $6 = 9
798 @end smallexample
799
800 @noindent
801 Is that enough to fix the problem of using the new quotes with the
802 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
803 executing with the @code{c} (@code{continue}) command, and then try the
804 example that caused trouble initially:
805
806 @smallexample
807 (@value{GDBP}) @b{c}
808 Continuing.
809
810 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
811
812 baz
813 0000
814 @end smallexample
815
816 @noindent
817 Success! The new quotes now work just as well as the default ones. The
818 problem seems to have been just the two typos defining the wrong
819 lengths. We allow @code{m4} exit by giving it an EOF as input:
820
821 @smallexample
822 @b{Ctrl-d}
823 Program exited normally.
824 @end smallexample
825
826 @noindent
827 The message @samp{Program exited normally.} is from @value{GDBN}; it
828 indicates @code{m4} has finished executing. We can end our @value{GDBN}
829 session with the @value{GDBN} @code{quit} command.
830
831 @smallexample
832 (@value{GDBP}) @b{quit}
833 @end smallexample
834
835 @node Invocation
836 @chapter Getting In and Out of @value{GDBN}
837
838 This chapter discusses how to start @value{GDBN}, and how to get out of it.
839 The essentials are:
840 @itemize @bullet
841 @item
842 type @samp{@value{GDBP}} to start @value{GDBN}.
843 @item
844 type @kbd{quit}, @kbd{exit} or @kbd{Ctrl-d} to exit.
845 @end itemize
846
847 @menu
848 * Invoking GDB:: How to start @value{GDBN}
849 * Quitting GDB:: How to quit @value{GDBN}
850 * Shell Commands:: How to use shell commands inside @value{GDBN}
851 * Logging Output:: How to log @value{GDBN}'s output to a file
852 @end menu
853
854 @node Invoking GDB
855 @section Invoking @value{GDBN}
856
857 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
858 @value{GDBN} reads commands from the terminal until you tell it to exit.
859
860 You can also run @code{@value{GDBP}} with a variety of arguments and options,
861 to specify more of your debugging environment at the outset.
862
863 The command-line options described here are designed
864 to cover a variety of situations; in some environments, some of these
865 options may effectively be unavailable.
866
867 The most usual way to start @value{GDBN} is with one argument,
868 specifying an executable program:
869
870 @smallexample
871 @value{GDBP} @var{program}
872 @end smallexample
873
874 @noindent
875 You can also start with both an executable program and a core file
876 specified:
877
878 @smallexample
879 @value{GDBP} @var{program} @var{core}
880 @end smallexample
881
882 You can, instead, specify a process ID as a second argument or use option
883 @code{-p}, if you want to debug a running process:
884
885 @smallexample
886 @value{GDBP} @var{program} 1234
887 @value{GDBP} -p 1234
888 @end smallexample
889
890 @noindent
891 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
892 can omit the @var{program} filename.
893
894 Taking advantage of the second command-line argument requires a fairly
895 complete operating system; when you use @value{GDBN} as a remote
896 debugger attached to a bare board, there may not be any notion of
897 ``process'', and there is often no way to get a core dump. @value{GDBN}
898 will warn you if it is unable to attach or to read core dumps.
899
900 You can optionally have @code{@value{GDBP}} pass any arguments after the
901 executable file to the inferior using @code{--args}. This option stops
902 option processing.
903 @smallexample
904 @value{GDBP} --args gcc -O2 -c foo.c
905 @end smallexample
906 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
907 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
908
909 You can run @code{@value{GDBP}} without printing the front material, which describes
910 @value{GDBN}'s non-warranty, by specifying @code{--silent}
911 (or @code{-q}/@code{--quiet}):
912
913 @smallexample
914 @value{GDBP} --silent
915 @end smallexample
916
917 @noindent
918 You can further control how @value{GDBN} starts up by using command-line
919 options. @value{GDBN} itself can remind you of the options available.
920
921 @noindent
922 Type
923
924 @smallexample
925 @value{GDBP} -help
926 @end smallexample
927
928 @noindent
929 to display all available options and briefly describe their use
930 (@samp{@value{GDBP} -h} is a shorter equivalent).
931
932 All options and command line arguments you give are processed
933 in sequential order. The order makes a difference when the
934 @samp{-x} option is used.
935
936
937 @menu
938 * File Options:: Choosing files
939 * Mode Options:: Choosing modes
940 * Startup:: What @value{GDBN} does during startup
941 * Initialization Files:: Initialization Files
942 @end menu
943
944 @node File Options
945 @subsection Choosing Files
946
947 When @value{GDBN} starts, it reads any arguments other than options as
948 specifying an executable file and core file (or process ID). This is
949 the same as if the arguments were specified by the @samp{-se} and
950 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
951 first argument that does not have an associated option flag as
952 equivalent to the @samp{-se} option followed by that argument; and the
953 second argument that does not have an associated option flag, if any, as
954 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
955 If the second argument begins with a decimal digit, @value{GDBN} will
956 first attempt to attach to it as a process, and if that fails, attempt
957 to open it as a corefile. If you have a corefile whose name begins with
958 a digit, you can prevent @value{GDBN} from treating it as a pid by
959 prefixing it with @file{./}, e.g.@: @file{./12345}.
960
961 If @value{GDBN} has not been configured to included core file support,
962 such as for most embedded targets, then it will complain about a second
963 argument and ignore it.
964
965 For the @samp{-s}, @samp{-e}, and @samp{-se} options, and their long
966 form equivalents, the method used to search the file system for the
967 symbol and/or executable file is the same as that used by the
968 @code{file} command. @xref{Files, ,file}.
969
970 Many options have both long and short forms; both are shown in the
971 following list. @value{GDBN} also recognizes the long forms if you truncate
972 them, so long as enough of the option is present to be unambiguous.
973 (If you prefer, you can flag option arguments with @samp{--} rather
974 than @samp{-}, though we illustrate the more usual convention.)
975
976 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
977 @c way, both those who look for -foo and --foo in the index, will find
978 @c it.
979
980 @table @code
981 @item -symbols @var{file}
982 @itemx -s @var{file}
983 @cindex @code{--symbols}
984 @cindex @code{-s}
985 Read symbol table from file @var{file}.
986
987 @item -exec @var{file}
988 @itemx -e @var{file}
989 @cindex @code{--exec}
990 @cindex @code{-e}
991 Use file @var{file} as the executable file to execute when appropriate,
992 and for examining pure data in conjunction with a core dump.
993
994 @item -se @var{file}
995 @cindex @code{--se}
996 Read symbol table from file @var{file} and use it as the executable
997 file.
998
999 @item -core @var{file}
1000 @itemx -c @var{file}
1001 @cindex @code{--core}
1002 @cindex @code{-c}
1003 Use file @var{file} as a core dump to examine.
1004
1005 @item -pid @var{number}
1006 @itemx -p @var{number}
1007 @cindex @code{--pid}
1008 @cindex @code{-p}
1009 Connect to process ID @var{number}, as with the @code{attach} command.
1010
1011 @item -command @var{file}
1012 @itemx -x @var{file}
1013 @cindex @code{--command}
1014 @cindex @code{-x}
1015 Execute commands from file @var{file}. The contents of this file is
1016 evaluated exactly as the @code{source} command would.
1017 @xref{Command Files,, Command files}.
1018
1019 @item -eval-command @var{command}
1020 @itemx -ex @var{command}
1021 @cindex @code{--eval-command}
1022 @cindex @code{-ex}
1023 Execute a single @value{GDBN} command.
1024
1025 This option may be used multiple times to call multiple commands. It may
1026 also be interleaved with @samp{-command} as required.
1027
1028 @smallexample
1029 @value{GDBP} -ex 'target sim' -ex 'load' \
1030 -x setbreakpoints -ex 'run' a.out
1031 @end smallexample
1032
1033 @item -init-command @var{file}
1034 @itemx -ix @var{file}
1035 @cindex @code{--init-command}
1036 @cindex @code{-ix}
1037 Execute commands from file @var{file} before loading the inferior (but
1038 after loading gdbinit files).
1039 @xref{Startup}.
1040
1041 @item -init-eval-command @var{command}
1042 @itemx -iex @var{command}
1043 @cindex @code{--init-eval-command}
1044 @cindex @code{-iex}
1045 Execute a single @value{GDBN} command before loading the inferior (but
1046 after loading gdbinit files).
1047 @xref{Startup}.
1048
1049 @item -early-init-command @var{file}
1050 @itemx -eix @var{file}
1051 @cindex @code{--early-init-command}
1052 @cindex @code{-eix}
1053 Execute commands from @var{file} very early in the initialization
1054 process, before any output is produced. @xref{Startup}.
1055
1056 @item -early-init-eval-command @var{command}
1057 @itemx -eiex @var{command}
1058 @cindex @code{--early-init-eval-command}
1059 @cindex @code{-eiex}
1060 Execute a single @value{GDBN} command very early in the initialization
1061 process, before any output is produced.
1062
1063 @item -directory @var{directory}
1064 @itemx -d @var{directory}
1065 @cindex @code{--directory}
1066 @cindex @code{-d}
1067 Add @var{directory} to the path to search for source and script files.
1068
1069 @item -r
1070 @itemx -readnow
1071 @cindex @code{--readnow}
1072 @cindex @code{-r}
1073 Read each symbol file's entire symbol table immediately, rather than
1074 the default, which is to read it incrementally as it is needed.
1075 This makes startup slower, but makes future operations faster.
1076
1077 @item --readnever
1078 @anchor{--readnever}
1079 @cindex @code{--readnever}, command-line option
1080 Do not read each symbol file's symbolic debug information. This makes
1081 startup faster but at the expense of not being able to perform
1082 symbolic debugging. DWARF unwind information is also not read,
1083 meaning backtraces may become incomplete or inaccurate. One use of
1084 this is when a user simply wants to do the following sequence: attach,
1085 dump core, detach. Loading the debugging information in this case is
1086 an unnecessary cause of delay.
1087 @end table
1088
1089 @node Mode Options
1090 @subsection Choosing Modes
1091
1092 You can run @value{GDBN} in various alternative modes---for example, in
1093 batch mode or quiet mode.
1094
1095 @table @code
1096 @anchor{-nx}
1097 @item -nx
1098 @itemx -n
1099 @cindex @code{--nx}
1100 @cindex @code{-n}
1101 Do not execute commands found in any initialization files
1102 (@pxref{Initialization Files}).
1103
1104 @anchor{-nh}
1105 @item -nh
1106 @cindex @code{--nh}
1107 Do not execute commands found in any home directory initialization
1108 file (@pxref{Initialization Files,,Home directory initialization
1109 file}). The system wide and current directory initialization files
1110 are still loaded.
1111
1112 @item -quiet
1113 @itemx -silent
1114 @itemx -q
1115 @cindex @code{--quiet}
1116 @cindex @code{--silent}
1117 @cindex @code{-q}
1118 ``Quiet''. Do not print the introductory and copyright messages. These
1119 messages are also suppressed in batch mode.
1120
1121 @kindex set startup-quietly
1122 @kindex show startup-quietly
1123 This can also be enabled using @code{set startup-quietly on}. The
1124 default is @code{off}. Use @code{show startup-quietly} to see the
1125 current setting. Place @code{set startup-quietly on} into your early
1126 initialization file (@pxref{Initialization Files,,Initialization
1127 Files}) to have future @value{GDBN} sessions startup quietly.
1128
1129 @item -batch
1130 @cindex @code{--batch}
1131 Run in batch mode. Exit with status @code{0} after processing all the
1132 command files specified with @samp{-x} (and all commands from
1133 initialization files, if not inhibited with @samp{-n}). Exit with
1134 nonzero status if an error occurs in executing the @value{GDBN} commands
1135 in the command files. Batch mode also disables pagination, sets unlimited
1136 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1137 off} were in effect (@pxref{Messages/Warnings}).
1138
1139 Batch mode may be useful for running @value{GDBN} as a filter, for
1140 example to download and run a program on another computer; in order to
1141 make this more useful, the message
1142
1143 @smallexample
1144 Program exited normally.
1145 @end smallexample
1146
1147 @noindent
1148 (which is ordinarily issued whenever a program running under
1149 @value{GDBN} control terminates) is not issued when running in batch
1150 mode.
1151
1152 @item -batch-silent
1153 @cindex @code{--batch-silent}
1154 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1155 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1156 unaffected). This is much quieter than @samp{-silent} and would be useless
1157 for an interactive session.
1158
1159 This is particularly useful when using targets that give @samp{Loading section}
1160 messages, for example.
1161
1162 Note that targets that give their output via @value{GDBN}, as opposed to
1163 writing directly to @code{stdout}, will also be made silent.
1164
1165 @item -return-child-result
1166 @cindex @code{--return-child-result}
1167 The return code from @value{GDBN} will be the return code from the child
1168 process (the process being debugged), with the following exceptions:
1169
1170 @itemize @bullet
1171 @item
1172 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1173 internal error. In this case the exit code is the same as it would have been
1174 without @samp{-return-child-result}.
1175 @item
1176 The user quits with an explicit value. E.g., @samp{quit 1}.
1177 @item
1178 The child process never runs, or is not allowed to terminate, in which case
1179 the exit code will be -1.
1180 @end itemize
1181
1182 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1183 when @value{GDBN} is being used as a remote program loader or simulator
1184 interface.
1185
1186 @item -nowindows
1187 @itemx -nw
1188 @cindex @code{--nowindows}
1189 @cindex @code{-nw}
1190 ``No windows''. If @value{GDBN} comes with a graphical user interface
1191 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1192 interface. If no GUI is available, this option has no effect.
1193
1194 @item -windows
1195 @itemx -w
1196 @cindex @code{--windows}
1197 @cindex @code{-w}
1198 If @value{GDBN} includes a GUI, then this option requires it to be
1199 used if possible.
1200
1201 @item -cd @var{directory}
1202 @cindex @code{--cd}
1203 Run @value{GDBN} using @var{directory} as its working directory,
1204 instead of the current directory.
1205
1206 @item -data-directory @var{directory}
1207 @itemx -D @var{directory}
1208 @cindex @code{--data-directory}
1209 @cindex @code{-D}
1210 Run @value{GDBN} using @var{directory} as its data directory.
1211 The data directory is where @value{GDBN} searches for its
1212 auxiliary files. @xref{Data Files}.
1213
1214 @item -fullname
1215 @itemx -f
1216 @cindex @code{--fullname}
1217 @cindex @code{-f}
1218 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1219 subprocess. It tells @value{GDBN} to output the full file name and line
1220 number in a standard, recognizable fashion each time a stack frame is
1221 displayed (which includes each time your program stops). This
1222 recognizable format looks like two @samp{\032} characters, followed by
1223 the file name, line number and character position separated by colons,
1224 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1225 @samp{\032} characters as a signal to display the source code for the
1226 frame.
1227
1228 @item -annotate @var{level}
1229 @cindex @code{--annotate}
1230 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1231 effect is identical to using @samp{set annotate @var{level}}
1232 (@pxref{Annotations}). The annotation @var{level} controls how much
1233 information @value{GDBN} prints together with its prompt, values of
1234 expressions, source lines, and other types of output. Level 0 is the
1235 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1236 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1237 that control @value{GDBN}, and level 2 has been deprecated.
1238
1239 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1240 (@pxref{GDB/MI}).
1241
1242 @item --args
1243 @cindex @code{--args}
1244 Change interpretation of command line so that arguments following the
1245 executable file are passed as command line arguments to the inferior.
1246 This option stops option processing.
1247
1248 @item -baud @var{bps}
1249 @itemx -b @var{bps}
1250 @cindex @code{--baud}
1251 @cindex @code{-b}
1252 Set the line speed (baud rate or bits per second) of any serial
1253 interface used by @value{GDBN} for remote debugging.
1254
1255 @item -l @var{timeout}
1256 @cindex @code{-l}
1257 Set the timeout (in seconds) of any communication used by @value{GDBN}
1258 for remote debugging.
1259
1260 @item -tty @var{device}
1261 @itemx -t @var{device}
1262 @cindex @code{--tty}
1263 @cindex @code{-t}
1264 Run using @var{device} for your program's standard input and output.
1265 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1266
1267 @c resolve the situation of these eventually
1268 @item -tui
1269 @cindex @code{--tui}
1270 Activate the @dfn{Text User Interface} when starting. The Text User
1271 Interface manages several text windows on the terminal, showing
1272 source, assembly, registers and @value{GDBN} command outputs
1273 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1274 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1275 Using @value{GDBN} under @sc{gnu} Emacs}).
1276
1277 @item -interpreter @var{interp}
1278 @cindex @code{--interpreter}
1279 Use the interpreter @var{interp} for interface with the controlling
1280 program or device. This option is meant to be set by programs which
1281 communicate with @value{GDBN} using it as a back end.
1282 @xref{Interpreters, , Command Interpreters}.
1283
1284 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1285 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1286 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1287 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1288 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1289 interfaces are no longer supported.
1290
1291 @item -write
1292 @cindex @code{--write}
1293 Open the executable and core files for both reading and writing. This
1294 is equivalent to the @samp{set write on} command inside @value{GDBN}
1295 (@pxref{Patching}).
1296
1297 @item -statistics
1298 @cindex @code{--statistics}
1299 This option causes @value{GDBN} to print statistics about time and
1300 memory usage after it completes each command and returns to the prompt.
1301
1302 @item -version
1303 @cindex @code{--version}
1304 This option causes @value{GDBN} to print its version number and
1305 no-warranty blurb, and exit.
1306
1307 @item -configuration
1308 @cindex @code{--configuration}
1309 This option causes @value{GDBN} to print details about its build-time
1310 configuration parameters, and then exit. These details can be
1311 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1312
1313 @end table
1314
1315 @node Startup
1316 @subsection What @value{GDBN} Does During Startup
1317 @cindex @value{GDBN} startup
1318
1319 Here's the description of what @value{GDBN} does during session startup:
1320
1321 @enumerate
1322
1323 @item
1324 Performs minimal setup required to initialize basic internal state.
1325
1326 @item
1327 @cindex early initialization file
1328 Reads commands from the early initialization file (if any) in your
1329 home directory. Only a restricted set of commands can be placed into
1330 an early initialization file, see @ref{Initialization Files}, for
1331 details.
1332
1333 @item
1334 Executes commands and command files specified by the @samp{-eiex} and
1335 @samp{-eix} command line options in their specified order. Only a
1336 restricted set of commands can be used with @samp{-eiex} and
1337 @samp{eix}, see @ref{Initialization Files}, for details.
1338
1339 @item
1340 Sets up the command interpreter as specified by the command line
1341 (@pxref{Mode Options, interpreter}).
1342
1343 @item
1344 @cindex init file
1345 Reads the system wide initialization file and the files from the
1346 system wide initialization directory, @pxref{System Wide Init Files}.
1347
1348 @item
1349 Reads the initialization file (if any) in your home directory and
1350 executes all the commands in that file, @pxref{Home Directory Init
1351 File}.
1352
1353 @anchor{Option -init-eval-command}
1354 @item
1355 Executes commands and command files specified by the @samp{-iex} and
1356 @samp{-ix} options in their specified order. Usually you should use the
1357 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1358 settings before @value{GDBN} init files get executed and before inferior
1359 gets loaded.
1360
1361 @item
1362 Processes command line options and operands.
1363
1364 @item
1365 Reads and executes the commands from the initialization file (if any)
1366 in the current working directory as long as @samp{set auto-load
1367 local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1368 Directory}). This is only done if the current directory is different
1369 from your home directory. Thus, you can have more than one init file,
1370 one generic in your home directory, and another, specific to the
1371 program you are debugging, in the directory where you invoke
1372 @value{GDBN}. @xref{Init File in the Current Directory during
1373 Startup}.
1374
1375 @item
1376 If the command line specified a program to debug, or a process to
1377 attach to, or a core file, @value{GDBN} loads any auto-loaded
1378 scripts provided for the program or for its loaded shared libraries.
1379 @xref{Auto-loading}.
1380
1381 If you wish to disable the auto-loading during startup,
1382 you must do something like the following:
1383
1384 @smallexample
1385 $ gdb -iex "set auto-load python-scripts off" myprogram
1386 @end smallexample
1387
1388 Option @samp{-ex} does not work because the auto-loading is then turned
1389 off too late.
1390
1391 @item
1392 Executes commands and command files specified by the @samp{-ex} and
1393 @samp{-x} options in their specified order. @xref{Command Files}, for
1394 more details about @value{GDBN} command files.
1395
1396 @item
1397 Reads the command history recorded in the @dfn{history file}.
1398 @xref{Command History}, for more details about the command history and the
1399 files where @value{GDBN} records it.
1400 @end enumerate
1401
1402 @node Initialization Files
1403 @subsection Initialization Files
1404 @cindex init file name
1405
1406 During startup (@pxref{Startup}) @value{GDBN} will execute commands
1407 from several initialization files. These initialization files use the
1408 same syntax as @dfn{command files} (@pxref{Command Files}) and are
1409 processed by @value{GDBN} in the same way.
1410
1411 To display the list of initialization files loaded by @value{GDBN} at
1412 startup, in the order they will be loaded, you can use @kbd{gdb
1413 --help}.
1414
1415 @cindex early initialization
1416 The @dfn{early initialization} file is loaded very early in
1417 @value{GDBN}'s initialization process, before the interpreter
1418 (@pxref{Interpreters}) has been initialized, and before the default
1419 target (@pxref{Targets}) is initialized. Only @code{set} or
1420 @code{source} commands should be placed into an early initialization
1421 file, and the only @code{set} commands that can be used are those that
1422 control how @value{GDBN} starts up.
1423
1424 Commands that can be placed into an early initialization file will be
1425 documented as such throughout this manual. Any command that is not
1426 documented as being suitable for an early initialization file should
1427 instead be placed into a general initialization file. Command files
1428 passed to @code{--early-init-command} or @code{-eix} are also early
1429 initialization files, with the same command restrictions. Only
1430 commands that can appear in an early initialization file should be
1431 passed to @code{--early-init-eval-command} or @code{-eiex}.
1432
1433 @cindex general initialization
1434 In contrast, the @dfn{general initialization} files are processed
1435 later, after @value{GDBN} has finished its own internal initialization
1436 process, any valid command can be used in these files.
1437
1438 @cindex initialization file
1439 Throughout the rest of this document the term @dfn{initialization
1440 file} refers to one of the general initialization files, not the early
1441 initialization file. Any discussion of the early initialization file
1442 will specifically mention that it is the early initialization file
1443 being discussed.
1444
1445 As the system wide and home directory initialization files are
1446 processed before most command line options, changes to settings
1447 (e.g.@: @samp{set complaints}) can affect subsequent processing of
1448 command line options and operands.
1449
1450 The following sections describe where @value{GDBN} looks for the early
1451 initialization and initialization files, and the order that the files
1452 are searched for.
1453
1454 @subsubsection Home directory early initialization files
1455
1456 @value{GDBN} initially looks for an early initialization file in the
1457 users home directory@footnote{On DOS/Windows systems, the home
1458 directory is the one pointed to by the @env{HOME} environment
1459 variable.}. There are a number of locations that @value{GDBN} will
1460 search in the home directory, these locations are searched in order
1461 and @value{GDBN} will load the first file that it finds, and
1462 subsequent locations will not be checked.
1463
1464 On non-macOS hosts the locations searched are:
1465 @itemize
1466 @item
1467 The file @file{gdb/gdbearlyinit} within the directory pointed to by the
1468 environment variable @env{XDG_CONFIG_HOME}, if it is defined.
1469 @item
1470 The file @file{.config/gdb/gdbearlyinit} within the directory pointed to
1471 by the environment variable @env{HOME}, if it is defined.
1472 @item
1473 The file @file{.gdbearlyinit} within the directory pointed to by the
1474 environment variable @env{HOME}, if it is defined.
1475 @end itemize
1476
1477 By contrast, on macOS hosts the locations searched are:
1478 @itemize
1479 @item
1480 The file @file{Library/Preferences/gdb/gdbearlyinit} within the
1481 directory pointed to by the environment variable @env{HOME}, if it is
1482 defined.
1483 @item
1484 The file @file{.gdbearlyinit} within the directory pointed to by the
1485 environment variable @env{HOME}, if it is defined.
1486 @end itemize
1487
1488 It is possible to prevent the home directory early initialization file
1489 from being loaded using the @samp{-nx} or @samp{-nh} command line
1490 options, @pxref{Mode Options,,Choosing Modes}.
1491
1492 @anchor{System Wide Init Files}
1493 @subsubsection System wide initialization files
1494
1495 There are two locations that are searched for system wide
1496 initialization files. Both of these locations are always checked:
1497
1498 @table @code
1499
1500 @item @file{system.gdbinit}
1501 This is a single system-wide initialization file. Its location is
1502 specified with the @code{--with-system-gdbinit} configure option
1503 (@pxref{System-wide configuration}). It is loaded first when
1504 @value{GDBN} starts, before command line options have been processed.
1505
1506 @item @file{system.gdbinit.d}
1507 This is the system-wide initialization directory. Its location is
1508 specified with the @code{--with-system-gdbinit-dir} configure option
1509 (@pxref{System-wide configuration}). Files in this directory are
1510 loaded in alphabetical order immediately after @file{system.gdbinit}
1511 (if enabled) when @value{GDBN} starts, before command line options
1512 have been processed. Files need to have a recognized scripting
1513 language extension (@file{.py}/@file{.scm}) or be named with a
1514 @file{.gdb} extension to be interpreted as regular @value{GDBN}
1515 commands. @value{GDBN} will not recurse into any subdirectories of
1516 this directory.
1517
1518 @end table
1519
1520 It is possible to prevent the system wide initialization files from
1521 being loaded using the @samp{-nx} command line option, @pxref{Mode
1522 Options,,Choosing Modes}.
1523
1524 @anchor{Home Directory Init File}
1525 @subsubsection Home directory initialization file
1526 @cindex @file{gdbinit}
1527 @cindex @file{.gdbinit}
1528 @cindex @file{gdb.ini}
1529
1530 After loading the system wide initialization files @value{GDBN} will
1531 look for an initialization file in the users home
1532 directory@footnote{On DOS/Windows systems, the home directory is the
1533 one pointed to by the @env{HOME} environment variable.}. There are a
1534 number of locations that @value{GDBN} will search in the home
1535 directory, these locations are searched in order and @value{GDBN} will
1536 load the first file that it finds, and subsequent locations will not
1537 be checked.
1538
1539 On non-Apple hosts the locations searched are:
1540 @table @file
1541 @item $XDG_CONFIG_HOME/gdb/gdbinit
1542 @item $HOME/.config/gdb/gdbinit
1543 @item $HOME/.gdbinit
1544 @end table
1545
1546 While on Apple hosts the locations searched are:
1547 @table @file
1548 @item $HOME/Library/Preferences/gdb/gdbinit
1549 @item $HOME/.gdbinit
1550 @end table
1551
1552 It is possible to prevent the home directory initialization file from
1553 being loaded using the @samp{-nx} or @samp{-nh} command line options,
1554 @pxref{Mode Options,,Choosing Modes}.
1555
1556 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1557 @file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1558 names imposed by DOS filesystems. The Windows port of @value{GDBN}
1559 uses the standard name, but if it finds a @file{gdb.ini} file in your
1560 home directory, it warns you about that and suggests to rename the
1561 file to the standard name.
1562
1563 @anchor{Init File in the Current Directory during Startup}
1564 @subsubsection Local directory initialization file
1565
1566 @value{GDBN} will check the current directory for a file called
1567 @file{.gdbinit}. It is loaded last, after command line options
1568 other than @samp{-x} and @samp{-ex} have been processed. The command
1569 line options @samp{-x} and @samp{-ex} are processed last, after
1570 @file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1571 Files}.
1572
1573 If the file in the current directory was already loaded as the home
1574 directory initialization file then it will not be loaded a second
1575 time.
1576
1577 It is possible to prevent the local directory initialization file from
1578 being loaded using the @samp{-nx} command line option, @pxref{Mode
1579 Options,,Choosing Modes}.
1580
1581 @node Quitting GDB
1582 @section Quitting @value{GDBN}
1583 @cindex exiting @value{GDBN}
1584 @cindex leaving @value{GDBN}
1585
1586 @table @code
1587 @kindex quit @r{[}@var{expression}@r{]}
1588 @kindex exit @r{[}@var{expression}@r{]}
1589 @kindex q @r{(@code{quit})}
1590 @item quit @r{[}@var{expression}@r{]}
1591 @itemx exit @r{[}@var{expression}@r{]}
1592 @itemx q
1593 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1594 @code{q}), the @code{exit} command, or type an end-of-file
1595 character (usually @kbd{Ctrl-d}). If you do not supply @var{expression},
1596 @value{GDBN} will terminate normally; otherwise it will terminate using
1597 the result of @var{expression} as the error code.
1598 @end table
1599
1600 @cindex interrupt
1601 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1602 terminates the action of any @value{GDBN} command that is in progress and
1603 returns to @value{GDBN} command level. It is safe to type the interrupt
1604 character at any time because @value{GDBN} does not allow it to take effect
1605 until a time when it is safe.
1606
1607 If you have been using @value{GDBN} to control an attached process or
1608 device, you can release it with the @code{detach} command
1609 (@pxref{Attach, ,Debugging an Already-running Process}).
1610
1611 @node Shell Commands
1612 @section Shell Commands
1613
1614 If you need to execute occasional shell commands during your
1615 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1616 just use the @code{shell} command.
1617
1618 @table @code
1619 @kindex shell
1620 @kindex !
1621 @cindex shell escape
1622 @item shell @var{command-string}
1623 @itemx !@var{command-string}
1624 Invoke a shell to execute @var{command-string}.
1625 Note that no space is needed between @code{!} and @var{command-string}.
1626 On GNU and Unix systems, the environment variable @env{SHELL}, if it
1627 exists, determines which shell to run. Otherwise @value{GDBN} uses
1628 the default shell (@file{/bin/sh} on GNU and Unix systems,
1629 @file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1630 @end table
1631
1632 You may also invoke shell commands from expressions, using the
1633 @code{$_shell} convenience function. @xref{$_shell convenience
1634 function}.
1635
1636 The utility @code{make} is often needed in development environments.
1637 You do not have to use the @code{shell} command for this purpose in
1638 @value{GDBN}:
1639
1640 @table @code
1641 @kindex make
1642 @cindex calling make
1643 @item make @var{make-args}
1644 Execute the @code{make} program with the specified
1645 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1646 @end table
1647
1648 @table @code
1649 @kindex pipe
1650 @kindex |
1651 @cindex send the output of a gdb command to a shell command
1652 @anchor{pipe}
1653 @item pipe [@var{command}] | @var{shell_command}
1654 @itemx | [@var{command}] | @var{shell_command}
1655 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1656 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1657 Executes @var{command} and sends its output to @var{shell_command}.
1658 Note that no space is needed around @code{|}.
1659 If no @var{command} is provided, the last command executed is repeated.
1660
1661 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1662 can be used to specify an alternate delimiter string @var{delim} that separates
1663 the @var{command} from the @var{shell_command}.
1664
1665 Example:
1666 @smallexample
1667 @group
1668 (@value{GDBP}) p var
1669 $1 = @{
1670 black = 144,
1671 red = 233,
1672 green = 377,
1673 blue = 610,
1674 white = 987
1675 @}
1676 @end group
1677 @group
1678 (@value{GDBP}) pipe p var|wc
1679 7 19 80
1680 (@value{GDBP}) |p var|wc -l
1681 7
1682 @end group
1683 @group
1684 (@value{GDBP}) p /x var
1685 $4 = @{
1686 black = 0x90,
1687 red = 0xe9,
1688 green = 0x179,
1689 blue = 0x262,
1690 white = 0x3db
1691 @}
1692 (@value{GDBP}) ||grep red
1693 red => 0xe9,
1694 @end group
1695 @group
1696 (@value{GDBP}) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1697 this contains a PIPE char
1698 (@value{GDBP}) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1699 this contains a PIPE char!
1700 (@value{GDBP})
1701 @end group
1702 @end smallexample
1703 @end table
1704
1705 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1706 can be used to examine the exit status of the last shell command launched
1707 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1708 @xref{Convenience Vars,, Convenience Variables}.
1709
1710 @node Logging Output
1711 @section Logging Output
1712 @cindex logging @value{GDBN} output
1713 @cindex save @value{GDBN} output to a file
1714
1715 You may want to save the output of @value{GDBN} commands to a file.
1716 There are several commands to control @value{GDBN}'s logging.
1717
1718 @table @code
1719 @kindex set logging enabled
1720 @item set logging enabled [on|off]
1721 Enable or disable logging.
1722 @cindex logging file name
1723 @item set logging file @var{file}
1724 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1725 @item set logging overwrite [on|off]
1726 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1727 you want @code{set logging enabled on} to overwrite the logfile instead.
1728 @item set logging redirect [on|off]
1729 By default, @value{GDBN} output will go to both the terminal and the logfile.
1730 Set @code{redirect} if you want output to go only to the log file.
1731 @item set logging debugredirect [on|off]
1732 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1733 Set @code{debugredirect} if you want debug output to go only to the log file.
1734 @kindex show logging
1735 @item show logging
1736 Show the current values of the logging settings.
1737 @end table
1738
1739 You can also redirect the output of a @value{GDBN} command to a
1740 shell command. @xref{pipe}.
1741 @node Commands
1742 @chapter @value{GDBN} Commands
1743
1744 You can abbreviate a @value{GDBN} command to the first few letters of the command
1745 name, if that abbreviation is unambiguous; and you can repeat certain
1746 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1747 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1748 show you the alternatives available, if there is more than one possibility).
1749
1750 @menu
1751 * Command Syntax:: How to give commands to @value{GDBN}
1752 * Command Settings:: How to change default behavior of commands
1753 * Completion:: Command completion
1754 * Command Options:: Command options
1755 * Help:: How to ask @value{GDBN} for help
1756 @end menu
1757
1758 @node Command Syntax
1759 @section Command Syntax
1760
1761 A @value{GDBN} command is a single line of input. There is no limit on
1762 how long it can be. It starts with a command name, which is followed by
1763 arguments whose meaning depends on the command name. For example, the
1764 command @code{step} accepts an argument which is the number of times to
1765 step, as in @samp{step 5}. You can also use the @code{step} command
1766 with no arguments. Some commands do not allow any arguments.
1767
1768 @cindex abbreviation
1769 @value{GDBN} command names may always be truncated if that abbreviation is
1770 unambiguous. Other possible command abbreviations are listed in the
1771 documentation for individual commands. In some cases, even ambiguous
1772 abbreviations are allowed; for example, @code{s} is specially defined as
1773 equivalent to @code{step} even though there are other commands whose
1774 names start with @code{s}. You can test abbreviations by using them as
1775 arguments to the @code{help} command.
1776
1777 @cindex repeating commands
1778 @kindex RET @r{(repeat last command)}
1779 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1780 repeat the previous command. Certain commands (for example, @code{run})
1781 will not repeat this way; these are commands whose unintentional
1782 repetition might cause trouble and which you are unlikely to want to
1783 repeat. User-defined commands can disable this feature; see
1784 @ref{Define, dont-repeat}.
1785
1786 The @code{list} and @code{x} commands, when you repeat them with
1787 @key{RET}, construct new arguments rather than repeating
1788 exactly as typed. This permits easy scanning of source or memory.
1789
1790 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1791 output, in a way similar to the common utility @code{more}
1792 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1793 @key{RET} too many in this situation, @value{GDBN} disables command
1794 repetition after any command that generates this sort of display.
1795
1796 @kindex # @r{(a comment)}
1797 @cindex comment
1798 Any text from a @kbd{#} to the end of the line is a comment; it does
1799 nothing. This is useful mainly in command files (@pxref{Command
1800 Files,,Command Files}).
1801
1802 @cindex repeating command sequences
1803 @kindex Ctrl-o @r{(operate-and-get-next)}
1804 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1805 commands. This command accepts the current line, like @key{RET}, and
1806 then fetches the next line relative to the current line from the history
1807 for editing.
1808
1809
1810 @node Command Settings
1811 @section Command Settings
1812 @cindex default behavior of commands, changing
1813 @cindex default settings, changing
1814
1815 Many commands change their behavior according to command-specific
1816 variables or settings. These settings can be changed with the
1817 @code{set} subcommands. For example, the @code{print} command
1818 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1819 settings changeable with the commands @code{set print elements
1820 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1821
1822 You can change these settings to your preference in the gdbinit files
1823 loaded at @value{GDBN} startup. @xref{Startup}.
1824
1825 The settings can also be changed interactively during the debugging
1826 session. For example, to change the limit of array elements to print,
1827 you can do the following:
1828 @smallexample
1829 (@value{GDBP}) set print elements 10
1830 (@value{GDBP}) print some_array
1831 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1832 @end smallexample
1833
1834 The above @code{set print elements 10} command changes the number of
1835 elements to print from the default of 200 to 10. If you only intend
1836 this limit of 10 to be used for printing @code{some_array}, then you
1837 must restore the limit back to 200, with @code{set print elements
1838 200}.
1839
1840 Some commands allow overriding settings with command options. For
1841 example, the @code{print} command supports a number of options that
1842 allow overriding relevant global print settings as set by @code{set
1843 print} subcommands. @xref{print options}. The example above could be
1844 rewritten as:
1845 @smallexample
1846 (@value{GDBP}) print -elements 10 -- some_array
1847 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1848 @end smallexample
1849
1850 Alternatively, you can use the @code{with} command to change a setting
1851 temporarily, for the duration of a command invocation.
1852
1853 @table @code
1854 @kindex with command
1855 @kindex w @r{(@code{with})}
1856 @cindex settings
1857 @cindex temporarily change settings
1858 @item with @var{setting} [@var{value}] [-- @var{command}]
1859 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1860 Temporarily set @var{setting} to @var{value} for the duration of
1861 @var{command}.
1862
1863 @var{setting} is any setting you can change with the @code{set}
1864 subcommands. @var{value} is the value to assign to @code{setting}
1865 while running @code{command}.
1866
1867 If no @var{command} is provided, the last command executed is
1868 repeated.
1869
1870 If a @var{command} is provided, it must be preceded by a double dash
1871 (@code{--}) separator. This is required because some settings accept
1872 free-form arguments, such as expressions or filenames.
1873
1874 For example, the command
1875 @smallexample
1876 (@value{GDBP}) with print array on -- print some_array
1877 @end smallexample
1878 @noindent
1879 is equivalent to the following 3 commands:
1880 @smallexample
1881 (@value{GDBP}) set print array on
1882 (@value{GDBP}) print some_array
1883 (@value{GDBP}) set print array off
1884 @end smallexample
1885
1886 The @code{with} command is particularly useful when you want to
1887 override a setting while running user-defined commands, or commands
1888 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1889
1890 @smallexample
1891 (@value{GDBP}) with print pretty on -- my_complex_command
1892 @end smallexample
1893
1894 To change several settings for the same command, you can nest
1895 @code{with} commands. For example, @code{with language ada -- with
1896 print elements 10} temporarily changes the language to Ada and sets a
1897 limit of 10 elements to print for arrays and strings.
1898
1899 @end table
1900
1901 @node Completion
1902 @section Command Completion
1903
1904 @cindex completion
1905 @cindex word completion
1906 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1907 only one possibility; it can also show you what the valid possibilities
1908 are for the next word in a command, at any time. This works for @value{GDBN}
1909 commands, @value{GDBN} subcommands, command options, and the names of symbols
1910 in your program.
1911
1912 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1913 of a word. If there is only one possibility, @value{GDBN} fills in the
1914 word, and waits for you to finish the command (or press @key{RET} to
1915 enter it). For example, if you type
1916
1917 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1918 @c complete accuracy in these examples; space introduced for clarity.
1919 @c If texinfo enhancements make it unnecessary, it would be nice to
1920 @c replace " @key" by "@key" in the following...
1921 @smallexample
1922 (@value{GDBP}) info bre@key{TAB}
1923 @end smallexample
1924
1925 @noindent
1926 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1927 the only @code{info} subcommand beginning with @samp{bre}:
1928
1929 @smallexample
1930 (@value{GDBP}) info breakpoints
1931 @end smallexample
1932
1933 @noindent
1934 You can either press @key{RET} at this point, to run the @code{info
1935 breakpoints} command, or backspace and enter something else, if
1936 @samp{breakpoints} does not look like the command you expected. (If you
1937 were sure you wanted @code{info breakpoints} in the first place, you
1938 might as well just type @key{RET} immediately after @samp{info bre},
1939 to exploit command abbreviations rather than command completion).
1940
1941 If there is more than one possibility for the next word when you press
1942 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1943 characters and try again, or just press @key{TAB} a second time;
1944 @value{GDBN} displays all the possible completions for that word. For
1945 example, you might want to set a breakpoint on a subroutine whose name
1946 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1947 just sounds the bell. Typing @key{TAB} again displays all the
1948 function names in your program that begin with those characters, for
1949 example:
1950
1951 @smallexample
1952 (@value{GDBP}) b make_@key{TAB}
1953 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1954 make_a_section_from_file make_environ
1955 make_abs_section make_function_type
1956 make_blockvector make_pointer_type
1957 make_cleanup make_reference_type
1958 make_command make_symbol_completion_list
1959 (@value{GDBP}) b make_
1960 @end smallexample
1961
1962 @noindent
1963 After displaying the available possibilities, @value{GDBN} copies your
1964 partial input (@samp{b make_} in the example) so you can finish the
1965 command.
1966
1967 If the command you are trying to complete expects either a keyword or a
1968 number to follow, then @samp{NUMBER} will be shown among the available
1969 completions, for example:
1970
1971 @smallexample
1972 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
1973 NUMBER unlimited
1974 (@value{GDBP}) print -elements@tie{}
1975 @end smallexample
1976
1977 @noindent
1978 Here, the option expects a number (e.g., @code{100}), not literal
1979 @code{NUMBER}. Such metasyntactical arguments are always presented in
1980 uppercase.
1981
1982 If you just want to see the list of alternatives in the first place, you
1983 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1984 means @kbd{@key{META} ?}. You can type this either by holding down a
1985 key designated as the @key{META} shift on your keyboard (if there is
1986 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1987
1988 If the number of possible completions is large, @value{GDBN} will
1989 print as much of the list as it has collected, as well as a message
1990 indicating that the list may be truncated.
1991
1992 @smallexample
1993 (@value{GDBP}) b m@key{TAB}@key{TAB}
1994 main
1995 <... the rest of the possible completions ...>
1996 *** List may be truncated, max-completions reached. ***
1997 (@value{GDBP}) b m
1998 @end smallexample
1999
2000 @noindent
2001 This behavior can be controlled with the following commands:
2002
2003 @table @code
2004 @kindex set max-completions
2005 @item set max-completions @var{limit}
2006 @itemx set max-completions unlimited
2007 Set the maximum number of completion candidates. @value{GDBN} will
2008 stop looking for more completions once it collects this many candidates.
2009 This is useful when completing on things like function names as collecting
2010 all the possible candidates can be time consuming.
2011 The default value is 200. A value of zero disables tab-completion.
2012 Note that setting either no limit or a very large limit can make
2013 completion slow.
2014 @kindex show max-completions
2015 @item show max-completions
2016 Show the maximum number of candidates that @value{GDBN} will collect and show
2017 during completion.
2018 @end table
2019
2020 @cindex quotes in commands
2021 @cindex completion of quoted strings
2022 Sometimes the string you need, while logically a ``word'', may contain
2023 parentheses or other characters that @value{GDBN} normally excludes from
2024 its notion of a word. To permit word completion to work in this
2025 situation, you may enclose words in @code{'} (single quote marks) in
2026 @value{GDBN} commands.
2027
2028 A likely situation where you might need this is in typing an
2029 expression that involves a C@t{++} symbol name with template
2030 parameters. This is because when completing expressions, GDB treats
2031 the @samp{<} character as word delimiter, assuming that it's the
2032 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
2033 Operators}).
2034
2035 For example, when you want to call a C@t{++} template function
2036 interactively using the @code{print} or @code{call} commands, you may
2037 need to distinguish whether you mean the version of @code{name} that
2038 was specialized for @code{int}, @code{name<int>()}, or the version
2039 that was specialized for @code{float}, @code{name<float>()}. To use
2040 the word-completion facilities in this situation, type a single quote
2041 @code{'} at the beginning of the function name. This alerts
2042 @value{GDBN} that it may need to consider more information than usual
2043 when you press @key{TAB} or @kbd{M-?} to request word completion:
2044
2045 @smallexample
2046 (@value{GDBP}) p 'func<@kbd{M-?}
2047 func<int>() func<float>()
2048 (@value{GDBP}) p 'func<
2049 @end smallexample
2050
2051 When setting breakpoints however (@pxref{Location Specifications}), you don't
2052 usually need to type a quote before the function name, because
2053 @value{GDBN} understands that you want to set a breakpoint on a
2054 function:
2055
2056 @smallexample
2057 (@value{GDBP}) b func<@kbd{M-?}
2058 func<int>() func<float>()
2059 (@value{GDBP}) b func<
2060 @end smallexample
2061
2062 This is true even in the case of typing the name of C@t{++} overloaded
2063 functions (multiple definitions of the same function, distinguished by
2064 argument type). For example, when you want to set a breakpoint you
2065 don't need to distinguish whether you mean the version of @code{name}
2066 that takes an @code{int} parameter, @code{name(int)}, or the version
2067 that takes a @code{float} parameter, @code{name(float)}.
2068
2069 @smallexample
2070 (@value{GDBP}) b bubble(@kbd{M-?}
2071 bubble(int) bubble(double)
2072 (@value{GDBP}) b bubble(dou@kbd{M-?}
2073 bubble(double)
2074 @end smallexample
2075
2076 See @ref{quoting names} for a description of other scenarios that
2077 require quoting.
2078
2079 For more information about overloaded functions, see @ref{C Plus Plus
2080 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
2081 overload-resolution off} to disable overload resolution;
2082 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
2083
2084 @cindex completion of structure field names
2085 @cindex structure field name completion
2086 @cindex completion of union field names
2087 @cindex union field name completion
2088 When completing in an expression which looks up a field in a
2089 structure, @value{GDBN} also tries@footnote{The completer can be
2090 confused by certain kinds of invalid expressions. Also, it only
2091 examines the static type of the expression, not the dynamic type.} to
2092 limit completions to the field names available in the type of the
2093 left-hand-side:
2094
2095 @smallexample
2096 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
2097 magic to_fputs to_rewind
2098 to_data to_isatty to_write
2099 to_delete to_put to_write_async_safe
2100 to_flush to_read
2101 @end smallexample
2102
2103 @noindent
2104 This is because the @code{gdb_stdout} is a variable of the type
2105 @code{struct ui_file} that is defined in @value{GDBN} sources as
2106 follows:
2107
2108 @smallexample
2109 struct ui_file
2110 @{
2111 int *magic;
2112 ui_file_flush_ftype *to_flush;
2113 ui_file_write_ftype *to_write;
2114 ui_file_write_async_safe_ftype *to_write_async_safe;
2115 ui_file_fputs_ftype *to_fputs;
2116 ui_file_read_ftype *to_read;
2117 ui_file_delete_ftype *to_delete;
2118 ui_file_isatty_ftype *to_isatty;
2119 ui_file_rewind_ftype *to_rewind;
2120 ui_file_put_ftype *to_put;
2121 void *to_data;
2122 @}
2123 @end smallexample
2124
2125 @node Command Options
2126 @section Command options
2127
2128 @cindex command options
2129 Some commands accept options starting with a leading dash. For
2130 example, @code{print -pretty}. Similarly to command names, you can
2131 abbreviate a @value{GDBN} option to the first few letters of the
2132 option name, if that abbreviation is unambiguous, and you can also use
2133 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2134 in an option (or to show you the alternatives available, if there is
2135 more than one possibility).
2136
2137 @cindex command options, raw input
2138 Some commands take raw input as argument. For example, the print
2139 command processes arbitrary expressions in any of the languages
2140 supported by @value{GDBN}. With such commands, because raw input may
2141 start with a leading dash that would be confused with an option or any
2142 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2143 -pretty} or printing negative @code{p}?), if you specify any command
2144 option, then you must use a double-dash (@code{--}) delimiter to
2145 indicate the end of options.
2146
2147 @cindex command options, boolean
2148
2149 Some options are described as accepting an argument which can be
2150 either @code{on} or @code{off}. These are known as @dfn{boolean
2151 options}. Similarly to boolean settings commands---@code{on} and
2152 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2153 @code{enable} can also be used as ``true'' value, and any of @code{0},
2154 @code{no} and @code{disable} can also be used as ``false'' value. You
2155 can also omit a ``true'' value, as it is implied by default.
2156
2157 For example, these are equivalent:
2158
2159 @smallexample
2160 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2161 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2162 @end smallexample
2163
2164 You can discover the set of options some command accepts by completing
2165 on @code{-} after the command name. For example:
2166
2167 @smallexample
2168 (@value{GDBP}) print -@key{TAB}@key{TAB}
2169 -address -max-depth -object -static-members
2170 -array -memory-tag-violations -pretty -symbol
2171 -array-indexes -nibbles -raw-values -union
2172 -elements -null-stop -repeats -vtbl
2173 @end smallexample
2174
2175 Completion will in some cases guide you with a suggestion of what kind
2176 of argument an option expects. For example:
2177
2178 @smallexample
2179 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2180 NUMBER unlimited
2181 @end smallexample
2182
2183 @noindent
2184 Here, the option expects a number (e.g., @code{100}), not literal
2185 @code{NUMBER}. Such metasyntactical arguments are always presented in
2186 uppercase.
2187
2188 (For more on using the @code{print} command, see @ref{Data, ,Examining
2189 Data}.)
2190
2191 @node Help
2192 @section Getting Help
2193 @cindex online documentation
2194 @kindex help
2195
2196 You can always ask @value{GDBN} itself for information on its commands,
2197 using the command @code{help}.
2198
2199 @table @code
2200 @kindex h @r{(@code{help})}
2201 @item help
2202 @itemx h
2203 You can use @code{help} (abbreviated @code{h}) with no arguments to
2204 display a short list of named classes of commands:
2205
2206 @smallexample
2207 (@value{GDBP}) help
2208 List of classes of commands:
2209
2210 aliases -- User-defined aliases of other commands
2211 breakpoints -- Making program stop at certain points
2212 data -- Examining data
2213 files -- Specifying and examining files
2214 internals -- Maintenance commands
2215 obscure -- Obscure features
2216 running -- Running the program
2217 stack -- Examining the stack
2218 status -- Status inquiries
2219 support -- Support facilities
2220 tracepoints -- Tracing of program execution without
2221 stopping the program
2222 user-defined -- User-defined commands
2223
2224 Type "help" followed by a class name for a list of
2225 commands in that class.
2226 Type "help" followed by command name for full
2227 documentation.
2228 Command name abbreviations are allowed if unambiguous.
2229 (@value{GDBP})
2230 @end smallexample
2231 @c the above line break eliminates huge line overfull...
2232
2233 @item help @var{class}
2234 Using one of the general help classes as an argument, you can get a
2235 list of the individual commands in that class. If a command has
2236 aliases, the aliases are given after the command name, separated by
2237 commas. If an alias has default arguments, the full definition of
2238 the alias is given after the first line.
2239 For example, here is the help display for the class @code{status}:
2240
2241 @smallexample
2242 (@value{GDBP}) help status
2243 Status inquiries.
2244
2245 List of commands:
2246
2247 @c Line break in "show" line falsifies real output, but needed
2248 @c to fit in smallbook page size.
2249 info, inf, i -- Generic command for showing things
2250 about the program being debugged
2251 info address, iamain -- Describe where symbol SYM is stored.
2252 alias iamain = info address main
2253 info all-registers -- List of all registers and their contents,
2254 for selected stack frame.
2255 ...
2256 show, info set -- Generic command for showing things
2257 about the debugger
2258
2259 Type "help" followed by command name for full
2260 documentation.
2261 Command name abbreviations are allowed if unambiguous.
2262 (@value{GDBP})
2263 @end smallexample
2264
2265 @item help @var{command}
2266 With a command name as @code{help} argument, @value{GDBN} displays a
2267 short paragraph on how to use that command. If that command has
2268 one or more aliases, @value{GDBN} will display a first line with
2269 the command name and all its aliases separated by commas.
2270 This first line will be followed by the full definition of all aliases
2271 having default arguments.
2272 When asking the help for an alias, the documentation for the aliased
2273 command is shown.
2274
2275 A user-defined alias can optionally be documented using the
2276 @code{document} command (@pxref{Define, document}). @value{GDBN} then
2277 considers this alias as different from the aliased command: this alias
2278 is not listed in the aliased command help output, and asking help for
2279 this alias will show the documentation provided for the alias instead of
2280 the documentation of the aliased command.
2281
2282 @kindex apropos
2283 @item apropos [-v] @var{regexp}
2284 The @code{apropos} command searches through all of the @value{GDBN}
2285 commands and aliases, and their documentation, for the regular expression specified in
2286 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2287 which stands for @samp{verbose}, indicates to output the full documentation
2288 of the matching commands and highlight the parts of the documentation
2289 matching @var{regexp}. For example:
2290
2291 @smallexample
2292 apropos alias
2293 @end smallexample
2294
2295 @noindent
2296 results in:
2297
2298 @smallexample
2299 @group
2300 alias -- Define a new command that is an alias of an existing command
2301 aliases -- User-defined aliases of other commands
2302 @end group
2303 @end smallexample
2304
2305 @noindent
2306 while
2307
2308 @smallexample
2309 apropos -v cut.*thread apply
2310 @end smallexample
2311
2312 @noindent
2313 results in the below output, where @samp{cut for 'thread apply}
2314 is highlighted if styling is enabled.
2315
2316 @smallexample
2317 @group
2318 taas -- Apply a command to all threads (ignoring errors
2319 and empty output).
2320 Usage: taas COMMAND
2321 shortcut for 'thread apply all -s COMMAND'
2322
2323 tfaas -- Apply a command to all frames of all threads
2324 (ignoring errors and empty output).
2325 Usage: tfaas COMMAND
2326 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2327 @end group
2328 @end smallexample
2329
2330 @kindex complete
2331 @item complete @var{args}
2332 The @code{complete @var{args}} command lists all the possible completions
2333 for the beginning of a command. Use @var{args} to specify the beginning of the
2334 command you want completed. For example:
2335
2336 @smallexample
2337 complete i
2338 @end smallexample
2339
2340 @noindent results in:
2341
2342 @smallexample
2343 @group
2344 if
2345 ignore
2346 info
2347 inspect
2348 @end group
2349 @end smallexample
2350
2351 @noindent This is intended for use by @sc{gnu} Emacs.
2352 @end table
2353
2354 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2355 and @code{show} to inquire about the state of your program, or the state
2356 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2357 manual introduces each of them in the appropriate context. The listings
2358 under @code{info} and under @code{show} in the Command, Variable, and
2359 Function Index point to all the sub-commands. @xref{Command and Variable
2360 Index}.
2361
2362 @c @group
2363 @table @code
2364 @kindex info
2365 @kindex i @r{(@code{info})}
2366 @item info
2367 This command (abbreviated @code{i}) is for describing the state of your
2368 program. For example, you can show the arguments passed to a function
2369 with @code{info args}, list the registers currently in use with @code{info
2370 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2371 You can get a complete list of the @code{info} sub-commands with
2372 @w{@code{help info}}.
2373
2374 @kindex set
2375 @item set
2376 You can assign the result of an expression to an environment variable with
2377 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2378 @code{set prompt $}.
2379
2380 @kindex show
2381 @item show
2382 In contrast to @code{info}, @code{show} is for describing the state of
2383 @value{GDBN} itself.
2384 You can change most of the things you can @code{show}, by using the
2385 related command @code{set}; for example, you can control what number
2386 system is used for displays with @code{set radix}, or simply inquire
2387 which is currently in use with @code{show radix}.
2388
2389 @kindex info set
2390 To display all the settable parameters and their current
2391 values, you can use @code{show} with no arguments; you may also use
2392 @code{info set}. Both commands produce the same display.
2393 @c FIXME: "info set" violates the rule that "info" is for state of
2394 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2395 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2396 @end table
2397 @c @end group
2398
2399 Here are several miscellaneous @code{show} subcommands, all of which are
2400 exceptional in lacking corresponding @code{set} commands:
2401
2402 @table @code
2403 @kindex show version
2404 @cindex @value{GDBN} version number
2405 @item show version
2406 Show what version of @value{GDBN} is running. You should include this
2407 information in @value{GDBN} bug-reports. If multiple versions of
2408 @value{GDBN} are in use at your site, you may need to determine which
2409 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2410 commands are introduced, and old ones may wither away. Also, many
2411 system vendors ship variant versions of @value{GDBN}, and there are
2412 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2413 The version number is the same as the one announced when you start
2414 @value{GDBN}.
2415
2416 @kindex show copying
2417 @kindex info copying
2418 @cindex display @value{GDBN} copyright
2419 @item show copying
2420 @itemx info copying
2421 Display information about permission for copying @value{GDBN}.
2422
2423 @kindex show warranty
2424 @kindex info warranty
2425 @item show warranty
2426 @itemx info warranty
2427 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2428 if your version of @value{GDBN} comes with one.
2429
2430 @kindex show configuration
2431 @item show configuration
2432 Display detailed information about the way @value{GDBN} was configured
2433 when it was built. This displays the optional arguments passed to the
2434 @file{configure} script and also configuration parameters detected
2435 automatically by @command{configure}. When reporting a @value{GDBN}
2436 bug (@pxref{GDB Bugs}), it is important to include this information in
2437 your report.
2438
2439 @end table
2440
2441 @node Running
2442 @chapter Running Programs Under @value{GDBN}
2443
2444 When you run a program under @value{GDBN}, you must first generate
2445 debugging information when you compile it.
2446
2447 You may start @value{GDBN} with its arguments, if any, in an environment
2448 of your choice. If you are doing native debugging, you may redirect
2449 your program's input and output, debug an already running process, or
2450 kill a child process.
2451
2452 @menu
2453 * Compilation:: Compiling for debugging
2454 * Starting:: Starting your program
2455 * Arguments:: Your program's arguments
2456 * Environment:: Your program's environment
2457
2458 * Working Directory:: Your program's working directory
2459 * Input/Output:: Your program's input and output
2460 * Attach:: Debugging an already-running process
2461 * Kill Process:: Killing the child process
2462 * Inferiors Connections and Programs:: Debugging multiple inferiors
2463 connections and programs
2464 * Threads:: Debugging programs with multiple threads
2465 * Forks:: Debugging forks
2466 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2467 @end menu
2468
2469 @node Compilation
2470 @section Compiling for Debugging
2471
2472 In order to debug a program effectively, you need to generate
2473 debugging information when you compile it. This debugging information
2474 is stored in the object file; it describes the data type of each
2475 variable or function and the correspondence between source line numbers
2476 and addresses in the executable code.
2477
2478 To request debugging information, specify the @samp{-g} option when you run
2479 the compiler.
2480
2481 Programs that are to be shipped to your customers are compiled with
2482 optimizations, using the @samp{-O} compiler option. However, some
2483 compilers are unable to handle the @samp{-g} and @samp{-O} options
2484 together. Using those compilers, you cannot generate optimized
2485 executables containing debugging information.
2486
2487 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2488 without @samp{-O}, making it possible to debug optimized code. We
2489 recommend that you @emph{always} use @samp{-g} whenever you compile a
2490 program. You may think your program is correct, but there is no sense
2491 in pushing your luck. For more information, see @ref{Optimized Code}.
2492
2493 Older versions of the @sc{gnu} C compiler permitted a variant option
2494 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2495 format; if your @sc{gnu} C compiler has this option, do not use it.
2496
2497 @value{GDBN} knows about preprocessor macros and can show you their
2498 expansion (@pxref{Macros}). Most compilers do not include information
2499 about preprocessor macros in the debugging information if you specify
2500 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2501 the @sc{gnu} C compiler, provides macro information if you are using
2502 the DWARF debugging format, and specify the option @option{-g3}.
2503
2504 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2505 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2506 information on @value{NGCC} options affecting debug information.
2507
2508 You will have the best debugging experience if you use the latest
2509 version of the DWARF debugging format that your compiler supports.
2510 DWARF is currently the most expressive and best supported debugging
2511 format in @value{GDBN}.
2512
2513 @need 2000
2514 @node Starting
2515 @section Starting your Program
2516 @cindex starting
2517 @cindex running
2518
2519 @table @code
2520 @kindex run
2521 @kindex r @r{(@code{run})}
2522 @item run
2523 @itemx r
2524 Use the @code{run} command to start your program under @value{GDBN}.
2525 You must first specify the program name with an argument to
2526 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2527 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2528 command (@pxref{Files, ,Commands to Specify Files}).
2529
2530 @end table
2531
2532 If you are running your program in an execution environment that
2533 supports processes, @code{run} creates an inferior process and makes
2534 that process run your program. In some environments without processes,
2535 @code{run} jumps to the start of your program. Other targets,
2536 like @samp{remote}, are always running. If you get an error
2537 message like this one:
2538
2539 @smallexample
2540 The "remote" target does not support "run".
2541 Try "help target" or "continue".
2542 @end smallexample
2543
2544 @noindent
2545 then use @code{continue} to run your program. You may need @code{load}
2546 first (@pxref{load}).
2547
2548 The execution of a program is affected by certain information it
2549 receives from its superior. @value{GDBN} provides ways to specify this
2550 information, which you must do @emph{before} starting your program. (You
2551 can change it after starting your program, but such changes only affect
2552 your program the next time you start it.) This information may be
2553 divided into four categories:
2554
2555 @table @asis
2556 @item The @emph{arguments.}
2557 Specify the arguments to give your program as the arguments of the
2558 @code{run} command. If a shell is available on your target, the shell
2559 is used to pass the arguments, so that you may use normal conventions
2560 (such as wildcard expansion or variable substitution) in describing
2561 the arguments.
2562 In Unix systems, you can control which shell is used with the
2563 @env{SHELL} environment variable. If you do not define @env{SHELL},
2564 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2565 use of any shell with the @code{set startup-with-shell} command (see
2566 below for details).
2567
2568 @item The @emph{environment.}
2569 Your program normally inherits its environment from @value{GDBN}, but you can
2570 use the @value{GDBN} commands @code{set environment} and @code{unset
2571 environment} to change parts of the environment that affect
2572 your program. @xref{Environment, ,Your Program's Environment}.
2573
2574 @item The @emph{working directory.}
2575 You can set your program's working directory with the command
2576 @kbd{set cwd}. If you do not set any working directory with this
2577 command, your program will inherit @value{GDBN}'s working directory if
2578 native debugging, or the remote server's working directory if remote
2579 debugging. @xref{Working Directory, ,Your Program's Working
2580 Directory}.
2581
2582 @item The @emph{standard input and output.}
2583 Your program normally uses the same device for standard input and
2584 standard output as @value{GDBN} is using. You can redirect input and output
2585 in the @code{run} command line, or you can use the @code{tty} command to
2586 set a different device for your program.
2587 @xref{Input/Output, ,Your Program's Input and Output}.
2588
2589 @cindex pipes
2590 @emph{Warning:} While input and output redirection work, you cannot use
2591 pipes to pass the output of the program you are debugging to another
2592 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2593 wrong program.
2594 @end table
2595
2596 When you issue the @code{run} command, your program begins to execute
2597 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2598 of how to arrange for your program to stop. Once your program has
2599 stopped, you may call functions in your program, using the @code{print}
2600 or @code{call} commands. @xref{Data, ,Examining Data}.
2601
2602 If the modification time of your symbol file has changed since the last
2603 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2604 table, and reads it again. When it does this, @value{GDBN} tries to retain
2605 your current breakpoints.
2606
2607 @table @code
2608 @kindex start
2609 @item start
2610 @cindex run to main procedure
2611 The name of the main procedure can vary from language to language.
2612 With C or C@t{++}, the main procedure name is always @code{main}, but
2613 other languages such as Ada do not require a specific name for their
2614 main procedure. The debugger provides a convenient way to start the
2615 execution of the program and to stop at the beginning of the main
2616 procedure, depending on the language used.
2617
2618 The @samp{start} command does the equivalent of setting a temporary
2619 breakpoint at the beginning of the main procedure and then invoking
2620 the @samp{run} command.
2621
2622 @cindex elaboration phase
2623 Some programs contain an @dfn{elaboration} phase where some startup code is
2624 executed before the main procedure is called. This depends on the
2625 languages used to write your program. In C@t{++}, for instance,
2626 constructors for static and global objects are executed before
2627 @code{main} is called. It is therefore possible that the debugger stops
2628 before reaching the main procedure. However, the temporary breakpoint
2629 will remain to halt execution.
2630
2631 Specify the arguments to give to your program as arguments to the
2632 @samp{start} command. These arguments will be given verbatim to the
2633 underlying @samp{run} command. Note that the same arguments will be
2634 reused if no argument is provided during subsequent calls to
2635 @samp{start} or @samp{run}.
2636
2637 It is sometimes necessary to debug the program during elaboration. In
2638 these cases, using the @code{start} command would stop the execution
2639 of your program too late, as the program would have already completed
2640 the elaboration phase. Under these circumstances, either insert
2641 breakpoints in your elaboration code before running your program or
2642 use the @code{starti} command.
2643
2644 @kindex starti
2645 @item starti
2646 @cindex run to first instruction
2647 The @samp{starti} command does the equivalent of setting a temporary
2648 breakpoint at the first instruction of a program's execution and then
2649 invoking the @samp{run} command. For programs containing an
2650 elaboration phase, the @code{starti} command will stop execution at
2651 the start of the elaboration phase.
2652
2653 @anchor{set exec-wrapper}
2654 @kindex set exec-wrapper
2655 @item set exec-wrapper @var{wrapper}
2656 @itemx show exec-wrapper
2657 @itemx unset exec-wrapper
2658 When @samp{exec-wrapper} is set, the specified wrapper is used to
2659 launch programs for debugging. @value{GDBN} starts your program
2660 with a shell command of the form @kbd{exec @var{wrapper}
2661 @var{program}}. Quoting is added to @var{program} and its
2662 arguments, but not to @var{wrapper}, so you should add quotes if
2663 appropriate for your shell. The wrapper runs until it executes
2664 your program, and then @value{GDBN} takes control.
2665
2666 You can use any program that eventually calls @code{execve} with
2667 its arguments as a wrapper. Several standard Unix utilities do
2668 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2669 with @code{exec "$@@"} will also work.
2670
2671 For example, you can use @code{env} to pass an environment variable to
2672 the debugged program, without setting the variable in your shell's
2673 environment:
2674
2675 @smallexample
2676 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2677 (@value{GDBP}) run
2678 @end smallexample
2679
2680 This command is available when debugging locally on most targets, excluding
2681 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2682
2683 @kindex set startup-with-shell
2684 @anchor{set startup-with-shell}
2685 @item set startup-with-shell
2686 @itemx set startup-with-shell on
2687 @itemx set startup-with-shell off
2688 @itemx show startup-with-shell
2689 On Unix systems, by default, if a shell is available on your target,
2690 @value{GDBN}) uses it to start your program. Arguments of the
2691 @code{run} command are passed to the shell, which does variable
2692 substitution, expands wildcard characters and performs redirection of
2693 I/O. In some circumstances, it may be useful to disable such use of a
2694 shell, for example, when debugging the shell itself or diagnosing
2695 startup failures such as:
2696
2697 @smallexample
2698 (@value{GDBP}) run
2699 Starting program: ./a.out
2700 During startup program terminated with signal SIGSEGV, Segmentation fault.
2701 @end smallexample
2702
2703 @noindent
2704 which indicates the shell or the wrapper specified with
2705 @samp{exec-wrapper} crashed, not your program. Most often, this is
2706 caused by something odd in your shell's non-interactive mode
2707 initialization file---such as @file{.cshrc} for C-shell,
2708 $@file{.zshenv} for the Z shell, or the file specified in the
2709 @env{BASH_ENV} environment variable for BASH.
2710
2711 @anchor{set auto-connect-native-target}
2712 @kindex set auto-connect-native-target
2713 @item set auto-connect-native-target
2714 @itemx set auto-connect-native-target on
2715 @itemx set auto-connect-native-target off
2716 @itemx show auto-connect-native-target
2717
2718 By default, if the current inferior is not connected to any target yet
2719 (e.g., with @code{target remote}), the @code{run} command starts your
2720 program as a native process under @value{GDBN}, on your local machine.
2721 If you're sure you don't want to debug programs on your local machine,
2722 you can tell @value{GDBN} to not connect to the native target
2723 automatically with the @code{set auto-connect-native-target off}
2724 command.
2725
2726 If @code{on}, which is the default, and if the current inferior is not
2727 connected to a target already, the @code{run} command automaticaly
2728 connects to the native target, if one is available.
2729
2730 If @code{off}, and if the current inferior is not connected to a
2731 target already, the @code{run} command fails with an error:
2732
2733 @smallexample
2734 (@value{GDBP}) run
2735 Don't know how to run. Try "help target".
2736 @end smallexample
2737
2738 If the current inferior is already connected to a target, @value{GDBN}
2739 always uses it with the @code{run} command.
2740
2741 In any case, you can explicitly connect to the native target with the
2742 @code{target native} command. For example,
2743
2744 @smallexample
2745 (@value{GDBP}) set auto-connect-native-target off
2746 (@value{GDBP}) run
2747 Don't know how to run. Try "help target".
2748 (@value{GDBP}) target native
2749 (@value{GDBP}) run
2750 Starting program: ./a.out
2751 [Inferior 1 (process 10421) exited normally]
2752 @end smallexample
2753
2754 In case you connected explicitly to the @code{native} target,
2755 @value{GDBN} remains connected even if all inferiors exit, ready for
2756 the next @code{run} command. Use the @code{disconnect} command to
2757 disconnect.
2758
2759 Examples of other commands that likewise respect the
2760 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2761 proc}, @code{info os}.
2762
2763 @kindex set disable-randomization
2764 @item set disable-randomization
2765 @itemx set disable-randomization on
2766 This option (enabled by default in @value{GDBN}) will turn off the native
2767 randomization of the virtual address space of the started program. This option
2768 is useful for multiple debugging sessions to make the execution better
2769 reproducible and memory addresses reusable across debugging sessions.
2770
2771 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2772 On @sc{gnu}/Linux you can get the same behavior using
2773
2774 @smallexample
2775 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2776 @end smallexample
2777
2778 @item set disable-randomization off
2779 Leave the behavior of the started executable unchanged. Some bugs rear their
2780 ugly heads only when the program is loaded at certain addresses. If your bug
2781 disappears when you run the program under @value{GDBN}, that might be because
2782 @value{GDBN} by default disables the address randomization on platforms, such
2783 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2784 disable-randomization off} to try to reproduce such elusive bugs.
2785
2786 On targets where it is available, virtual address space randomization
2787 protects the programs against certain kinds of security attacks. In these
2788 cases the attacker needs to know the exact location of a concrete executable
2789 code. Randomizing its location makes it impossible to inject jumps misusing
2790 a code at its expected addresses.
2791
2792 Prelinking shared libraries provides a startup performance advantage but it
2793 makes addresses in these libraries predictable for privileged processes by
2794 having just unprivileged access at the target system. Reading the shared
2795 library binary gives enough information for assembling the malicious code
2796 misusing it. Still even a prelinked shared library can get loaded at a new
2797 random address just requiring the regular relocation process during the
2798 startup. Shared libraries not already prelinked are always loaded at
2799 a randomly chosen address.
2800
2801 Position independent executables (PIE) contain position independent code
2802 similar to the shared libraries and therefore such executables get loaded at
2803 a randomly chosen address upon startup. PIE executables always load even
2804 already prelinked shared libraries at a random address. You can build such
2805 executable using @command{gcc -fPIE -pie}.
2806
2807 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2808 (as long as the randomization is enabled).
2809
2810 @item show disable-randomization
2811 Show the current setting of the explicit disable of the native randomization of
2812 the virtual address space of the started program.
2813
2814 @end table
2815
2816 @node Arguments
2817 @section Your Program's Arguments
2818
2819 @cindex arguments (to your program)
2820 The arguments to your program can be specified by the arguments of the
2821 @code{run} command.
2822 They are passed to a shell, which expands wildcard characters and
2823 performs redirection of I/O, and thence to your program. Your
2824 @env{SHELL} environment variable (if it exists) specifies what shell
2825 @value{GDBN} uses. If you do not define @env{SHELL}, @value{GDBN} uses
2826 the default shell (@file{/bin/sh} on Unix).
2827
2828 On non-Unix systems, the program is usually invoked directly by
2829 @value{GDBN}, which emulates I/O redirection via the appropriate system
2830 calls, and the wildcard characters are expanded by the startup code of
2831 the program, not by the shell.
2832
2833 @code{run} with no arguments uses the same arguments used by the previous
2834 @code{run}, or those set by the @code{set args} command.
2835
2836 @table @code
2837 @kindex set args
2838 @item set args
2839 Specify the arguments to be used the next time your program is run. If
2840 @code{set args} has no arguments, @code{run} executes your program
2841 with no arguments. Once you have run your program with arguments,
2842 using @code{set args} before the next @code{run} is the only way to run
2843 it again without arguments.
2844
2845 @kindex show args
2846 @item show args
2847 Show the arguments to give your program when it is started.
2848 @end table
2849
2850 @node Environment
2851 @section Your Program's Environment
2852
2853 @cindex environment (of your program)
2854 The @dfn{environment} consists of a set of environment variables and
2855 their values. Environment variables conventionally record such things as
2856 your user name, your home directory, your terminal type, and your search
2857 path for programs to run. Usually you set up environment variables with
2858 the shell and they are inherited by all the other programs you run. When
2859 debugging, it can be useful to try running your program with a modified
2860 environment without having to start @value{GDBN} over again.
2861
2862 @table @code
2863 @kindex path
2864 @item path @var{directory}
2865 Add @var{directory} to the front of the @env{PATH} environment variable
2866 (the search path for executables) that will be passed to your program.
2867 The value of @env{PATH} used by @value{GDBN} does not change.
2868 You may specify several directory names, separated by whitespace or by a
2869 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2870 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2871 is moved to the front, so it is searched sooner.
2872
2873 You can use the string @samp{$cwd} to refer to whatever is the current
2874 working directory at the time @value{GDBN} searches the path. If you
2875 use @samp{.} instead, it refers to the directory where you executed the
2876 @code{path} command. @value{GDBN} replaces @samp{.} in the
2877 @var{directory} argument (with the current path) before adding
2878 @var{directory} to the search path.
2879 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2880 @c document that, since repeating it would be a no-op.
2881
2882 @kindex show paths
2883 @item show paths
2884 Display the list of search paths for executables (the @env{PATH}
2885 environment variable).
2886
2887 @kindex show environment
2888 @item show environment @r{[}@var{varname}@r{]}
2889 Print the value of environment variable @var{varname} to be given to
2890 your program when it starts. If you do not supply @var{varname},
2891 print the names and values of all environment variables to be given to
2892 your program. You can abbreviate @code{environment} as @code{env}.
2893
2894 @kindex set environment
2895 @anchor{set environment}
2896 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2897 Set environment variable @var{varname} to @var{value}. The value
2898 changes for your program (and the shell @value{GDBN} uses to launch
2899 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2900 values of environment variables are just strings, and any
2901 interpretation is supplied by your program itself. The @var{value}
2902 parameter is optional; if it is eliminated, the variable is set to a
2903 null value.
2904 @c "any string" here does not include leading, trailing
2905 @c blanks. Gnu asks: does anyone care?
2906
2907 For example, this command:
2908
2909 @smallexample
2910 set env USER = foo
2911 @end smallexample
2912
2913 @noindent
2914 tells the debugged program, when subsequently run, that its user is named
2915 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2916 are not actually required.)
2917
2918 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2919 which also inherits the environment set with @code{set environment}.
2920 If necessary, you can avoid that by using the @samp{env} program as a
2921 wrapper instead of using @code{set environment}. @xref{set
2922 exec-wrapper}, for an example doing just that.
2923
2924 Environment variables that are set by the user are also transmitted to
2925 @command{gdbserver} to be used when starting the remote inferior.
2926 @pxref{QEnvironmentHexEncoded}.
2927
2928 @kindex unset environment
2929 @anchor{unset environment}
2930 @item unset environment @var{varname}
2931 Remove variable @var{varname} from the environment to be passed to your
2932 program. This is different from @samp{set env @var{varname} =};
2933 @code{unset environment} removes the variable from the environment,
2934 rather than assigning it an empty value.
2935
2936 Environment variables that are unset by the user are also unset on
2937 @command{gdbserver} when starting the remote inferior.
2938 @pxref{QEnvironmentUnset}.
2939 @end table
2940
2941 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2942 the shell indicated by your @env{SHELL} environment variable if it
2943 exists (or @code{/bin/sh} if not). If your @env{SHELL} variable
2944 names a shell that runs an initialization file when started
2945 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2946 for the Z shell, or the file specified in the @env{BASH_ENV}
2947 environment variable for BASH---any variables you set in that file
2948 affect your program. You may wish to move setting of environment
2949 variables to files that are only run when you sign on, such as
2950 @file{.login} or @file{.profile}.
2951
2952 @node Working Directory
2953 @section Your Program's Working Directory
2954
2955 @cindex working directory (of your program)
2956 Each time you start your program with @code{run}, the inferior will be
2957 initialized with the current working directory specified by the
2958 @kbd{set cwd} command. If no directory has been specified by this
2959 command, then the inferior will inherit @value{GDBN}'s current working
2960 directory as its working directory if native debugging, or it will
2961 inherit the remote server's current working directory if remote
2962 debugging.
2963
2964 @table @code
2965 @kindex set cwd
2966 @cindex change inferior's working directory
2967 @anchor{set cwd command}
2968 @item set cwd @r{[}@var{directory}@r{]}
2969 Set the inferior's working directory to @var{directory}, which will be
2970 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2971 argument has been specified, the command clears the setting and resets
2972 it to an empty state. This setting has no effect on @value{GDBN}'s
2973 working directory, and it only takes effect the next time you start
2974 the inferior. The @file{~} in @var{directory} is a short for the
2975 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2976 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2977 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2978 fallback.
2979
2980 You can also change @value{GDBN}'s current working directory by using
2981 the @code{cd} command.
2982 @xref{cd command}.
2983
2984 @kindex show cwd
2985 @cindex show inferior's working directory
2986 @item show cwd
2987 Show the inferior's working directory. If no directory has been
2988 specified by @kbd{set cwd}, then the default inferior's working
2989 directory is the same as @value{GDBN}'s working directory.
2990
2991 @kindex cd
2992 @cindex change @value{GDBN}'s working directory
2993 @anchor{cd command}
2994 @item cd @r{[}@var{directory}@r{]}
2995 Set the @value{GDBN} working directory to @var{directory}. If not
2996 given, @var{directory} uses @file{'~'}.
2997
2998 The @value{GDBN} working directory serves as a default for the
2999 commands that specify files for @value{GDBN} to operate on.
3000 @xref{Files, ,Commands to Specify Files}.
3001 @xref{set cwd command}.
3002
3003 @kindex pwd
3004 @item pwd
3005 Print the @value{GDBN} working directory.
3006 @end table
3007
3008 It is generally impossible to find the current working directory of
3009 the process being debugged (since a program can change its directory
3010 during its run). If you work on a system where @value{GDBN} supports
3011 the @code{info proc} command (@pxref{Process Information}), you can
3012 use the @code{info proc} command to find out the
3013 current working directory of the debuggee.
3014
3015 @node Input/Output
3016 @section Your Program's Input and Output
3017
3018 @cindex redirection
3019 @cindex i/o
3020 @cindex terminal
3021 By default, the program you run under @value{GDBN} does input and output to
3022 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
3023 to its own terminal modes to interact with you, but it records the terminal
3024 modes your program was using and switches back to them when you continue
3025 running your program.
3026
3027 @table @code
3028 @kindex info terminal
3029 @item info terminal
3030 Displays information recorded by @value{GDBN} about the terminal modes your
3031 program is using.
3032 @end table
3033
3034 You can redirect your program's input and/or output using shell
3035 redirection with the @code{run} command. For example,
3036
3037 @smallexample
3038 run > outfile
3039 @end smallexample
3040
3041 @noindent
3042 starts your program, diverting its output to the file @file{outfile}.
3043
3044 @kindex tty
3045 @cindex controlling terminal
3046 Another way to specify where your program should do input and output is
3047 with the @code{tty} command. This command accepts a file name as
3048 argument, and causes this file to be the default for future @code{run}
3049 commands. It also resets the controlling terminal for the child
3050 process, for future @code{run} commands. For example,
3051
3052 @smallexample
3053 tty /dev/ttyb
3054 @end smallexample
3055
3056 @noindent
3057 directs that processes started with subsequent @code{run} commands
3058 default to do input and output on the terminal @file{/dev/ttyb} and have
3059 that as their controlling terminal.
3060
3061 An explicit redirection in @code{run} overrides the @code{tty} command's
3062 effect on the input/output device, but not its effect on the controlling
3063 terminal.
3064
3065 When you use the @code{tty} command or redirect input in the @code{run}
3066 command, only the input @emph{for your program} is affected. The input
3067 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3068 for @code{set inferior-tty}.
3069
3070 @cindex inferior tty
3071 @cindex set inferior controlling terminal
3072 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3073 display the name of the terminal that will be used for future runs of your
3074 program.
3075
3076 @table @code
3077 @item set inferior-tty [ @var{tty} ]
3078 @kindex set inferior-tty
3079 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3080 restores the default behavior, which is to use the same terminal as
3081 @value{GDBN}.
3082
3083 @item show inferior-tty
3084 @kindex show inferior-tty
3085 Show the current tty for the program being debugged.
3086 @end table
3087
3088 @node Attach
3089 @section Debugging an Already-running Process
3090 @kindex attach
3091 @cindex attach
3092
3093 @table @code
3094 @item attach @var{process-id}
3095 This command attaches to a running process---one that was started
3096 outside @value{GDBN}. (@code{info files} shows your active
3097 targets.) The command takes as argument a process ID. The usual way to
3098 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3099 or with the @samp{jobs -l} shell command.
3100
3101 @code{attach} does not repeat if you press @key{RET} a second time after
3102 executing the command.
3103 @end table
3104
3105 To use @code{attach}, your program must be running in an environment
3106 which supports processes; for example, @code{attach} does not work for
3107 programs on bare-board targets that lack an operating system. You must
3108 also have permission to send the process a signal.
3109
3110 When you use @code{attach}, the debugger finds the program running in
3111 the process first by looking in the current working directory, then (if
3112 the program is not found) by using the source file search path
3113 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3114 the @code{file} command to load the program. @xref{Files, ,Commands to
3115 Specify Files}.
3116
3117 @anchor{set exec-file-mismatch}
3118 If the debugger can determine that the executable file running in the
3119 process it is attaching to does not match the current exec-file loaded
3120 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3121 handle the mismatch. @value{GDBN} tries to compare the files by
3122 comparing their build IDs (@pxref{build ID}), if available.
3123
3124 @table @code
3125 @kindex exec-file-mismatch
3126 @cindex set exec-file-mismatch
3127 @item set exec-file-mismatch @samp{ask|warn|off}
3128
3129 Whether to detect mismatch between the current executable file loaded
3130 by @value{GDBN} and the executable file used to start the process. If
3131 @samp{ask}, the default, display a warning and ask the user whether to
3132 load the process executable file; if @samp{warn}, just display a
3133 warning; if @samp{off}, don't attempt to detect a mismatch.
3134 If the user confirms loading the process executable file, then its symbols
3135 will be loaded as well.
3136
3137 @cindex show exec-file-mismatch
3138 @item show exec-file-mismatch
3139 Show the current value of @code{exec-file-mismatch}.
3140
3141 @end table
3142
3143 The first thing @value{GDBN} does after arranging to debug the specified
3144 process is to stop it. You can examine and modify an attached process
3145 with all the @value{GDBN} commands that are ordinarily available when
3146 you start processes with @code{run}. You can insert breakpoints; you
3147 can step and continue; you can modify storage. If you would rather the
3148 process continue running, you may use the @code{continue} command after
3149 attaching @value{GDBN} to the process.
3150
3151 @table @code
3152 @kindex detach
3153 @item detach
3154 When you have finished debugging the attached process, you can use the
3155 @code{detach} command to release it from @value{GDBN} control. Detaching
3156 the process continues its execution. After the @code{detach} command,
3157 that process and @value{GDBN} become completely independent once more, and you
3158 are ready to @code{attach} another process or start one with @code{run}.
3159 @code{detach} does not repeat if you press @key{RET} again after
3160 executing the command.
3161 @end table
3162
3163 If you exit @value{GDBN} while you have an attached process, you detach
3164 that process. If you use the @code{run} command, you kill that process.
3165 By default, @value{GDBN} asks for confirmation if you try to do either of these
3166 things; you can control whether or not you need to confirm by using the
3167 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3168 Messages}).
3169
3170 @node Kill Process
3171 @section Killing the Child Process
3172
3173 @table @code
3174 @kindex kill
3175 @item kill
3176 Kill the child process in which your program is running under @value{GDBN}.
3177 @end table
3178
3179 This command is useful if you wish to debug a core dump instead of a
3180 running process. @value{GDBN} ignores any core dump file while your program
3181 is running.
3182
3183 On some operating systems, a program cannot be executed outside @value{GDBN}
3184 while you have breakpoints set on it inside @value{GDBN}. You can use the
3185 @code{kill} command in this situation to permit running your program
3186 outside the debugger.
3187
3188 The @code{kill} command is also useful if you wish to recompile and
3189 relink your program, since on many systems it is impossible to modify an
3190 executable file while it is running in a process. In this case, when you
3191 next type @code{run}, @value{GDBN} notices that the file has changed, and
3192 reads the symbol table again (while trying to preserve your current
3193 breakpoint settings).
3194
3195 @node Inferiors Connections and Programs
3196 @section Debugging Multiple Inferiors Connections and Programs
3197
3198 @value{GDBN} lets you run and debug multiple programs in a single
3199 session. In addition, @value{GDBN} on some systems may let you run
3200 several programs simultaneously (otherwise you have to exit from one
3201 before starting another). On some systems @value{GDBN} may even let
3202 you debug several programs simultaneously on different remote systems.
3203 In the most general case, you can have multiple threads of execution
3204 in each of multiple processes, launched from multiple executables,
3205 running on different machines.
3206
3207 @cindex inferior
3208 @value{GDBN} represents the state of each program execution with an
3209 object called an @dfn{inferior}. An inferior typically corresponds to
3210 a process, but is more general and applies also to targets that do not
3211 have processes. Inferiors may be created before a process runs, and
3212 may be retained after a process exits. Inferiors have unique
3213 identifiers that are different from process ids. Usually each
3214 inferior will also have its own distinct address space, although some
3215 embedded targets may have several inferiors running in different parts
3216 of a single address space. Each inferior may in turn have multiple
3217 threads running in it.
3218
3219 To find out what inferiors exist at any moment, use @w{@code{info
3220 inferiors}}:
3221
3222 @table @code
3223 @kindex info inferiors [ @var{id}@dots{} ]
3224 @item info inferiors
3225 Print a list of all inferiors currently being managed by @value{GDBN}.
3226 By default all inferiors are printed, but the argument @var{id}@dots{}
3227 -- a space separated list of inferior numbers -- can be used to limit
3228 the display to just the requested inferiors.
3229
3230 @value{GDBN} displays for each inferior (in this order):
3231
3232 @enumerate
3233 @item
3234 the inferior number assigned by @value{GDBN}
3235
3236 @item
3237 the target system's inferior identifier
3238
3239 @item
3240 the target connection the inferior is bound to, including the unique
3241 connection number assigned by @value{GDBN}, and the protocol used by
3242 the connection.
3243
3244 @item
3245 the name of the executable the inferior is running.
3246
3247 @end enumerate
3248
3249 @noindent
3250 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3251 indicates the current inferior.
3252
3253 For example,
3254 @end table
3255 @c end table here to get a little more width for example
3256
3257 @smallexample
3258 (@value{GDBP}) info inferiors
3259 Num Description Connection Executable
3260 * 1 process 3401 1 (native) goodbye
3261 2 process 2307 2 (extended-remote host:10000) hello
3262 @end smallexample
3263
3264 To get informations about the current inferior, use @code{inferior}:
3265
3266 @table @code
3267 @kindex inferior
3268 @item inferior
3269 Shows information about the current inferior.
3270
3271 For example,
3272 @end table
3273 @c end table here to get a little more width for example
3274
3275 @smallexample
3276 (@value{GDBP}) inferior
3277 [Current inferior is 1 [process 3401] (helloworld)]
3278 @end smallexample
3279
3280 To find out what open target connections exist at any moment, use
3281 @w{@code{info connections}}:
3282
3283 @table @code
3284 @kindex info connections [ @var{id}@dots{} ]
3285 @item info connections
3286 Print a list of all open target connections currently being managed by
3287 @value{GDBN}. By default all connections are printed, but the
3288 argument @var{id}@dots{} -- a space separated list of connections
3289 numbers -- can be used to limit the display to just the requested
3290 connections.
3291
3292 @value{GDBN} displays for each connection (in this order):
3293
3294 @enumerate
3295 @item
3296 the connection number assigned by @value{GDBN}.
3297
3298 @item
3299 the protocol used by the connection.
3300
3301 @item
3302 a textual description of the protocol used by the connection.
3303
3304 @end enumerate
3305
3306 @noindent
3307 An asterisk @samp{*} preceding the connection number indicates the
3308 connection of the current inferior.
3309
3310 For example,
3311 @end table
3312 @c end table here to get a little more width for example
3313
3314 @smallexample
3315 (@value{GDBP}) info connections
3316 Num What Description
3317 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3318 2 native Native process
3319 3 core Local core dump file
3320 @end smallexample
3321
3322 To switch focus between inferiors, use the @code{inferior} command:
3323
3324 @table @code
3325 @kindex inferior @var{infno}
3326 @item inferior @var{infno}
3327 Make inferior number @var{infno} the current inferior. The argument
3328 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3329 in the first field of the @samp{info inferiors} display.
3330 @end table
3331
3332 @vindex $_inferior@r{, convenience variable}
3333 The debugger convenience variable @samp{$_inferior} contains the
3334 number of the current inferior. You may find this useful in writing
3335 breakpoint conditional expressions, command scripts, and so forth.
3336 @xref{Convenience Vars,, Convenience Variables}, for general
3337 information on convenience variables.
3338
3339 You can get multiple executables into a debugging session via the
3340 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3341 systems @value{GDBN} can add inferiors to the debug session
3342 automatically by following calls to @code{fork} and @code{exec}. To
3343 remove inferiors from the debugging session use the
3344 @w{@code{remove-inferiors}} command.
3345
3346 @table @code
3347 @anchor{add_inferior_cli}
3348 @kindex add-inferior
3349 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3350 Adds @var{n} inferiors to be run using @var{executable} as the
3351 executable; @var{n} defaults to 1. If no executable is specified,
3352 the inferiors begins empty, with no program. You can still assign or
3353 change the program assigned to the inferior at any time by using the
3354 @code{file} command with the executable name as its argument.
3355
3356 By default, the new inferior begins connected to the same target
3357 connection as the current inferior. For example, if the current
3358 inferior was connected to @code{gdbserver} with @code{target remote},
3359 then the new inferior will be connected to the same @code{gdbserver}
3360 instance. The @samp{-no-connection} option starts the new inferior
3361 with no connection yet. You can then for example use the @code{target
3362 remote} command to connect to some other @code{gdbserver} instance,
3363 use @code{run} to spawn a local program, etc.
3364
3365 @kindex clone-inferior
3366 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3367 Adds @var{n} inferiors ready to execute the same program as inferior
3368 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3369 number of the current inferior. This command copies the values of the
3370 @var{args}, @w{@var{inferior-tty}} and @var{cwd} properties from the
3371 current inferior to the new one. It also propagates changes the user
3372 made to environment variables using the @w{@code{set environment}} and
3373 @w{@code{unset environment}} commands. This is a convenient command
3374 when you want to run another instance of the inferior you are debugging.
3375
3376 @smallexample
3377 (@value{GDBP}) info inferiors
3378 Num Description Connection Executable
3379 * 1 process 29964 1 (native) helloworld
3380 (@value{GDBP}) clone-inferior
3381 Added inferior 2.
3382 1 inferiors added.
3383 (@value{GDBP}) info inferiors
3384 Num Description Connection Executable
3385 * 1 process 29964 1 (native) helloworld
3386 2 <null> 1 (native) helloworld
3387 @end smallexample
3388
3389 You can now simply switch focus to inferior 2 and run it.
3390
3391 @anchor{remove_inferiors_cli}
3392 @kindex remove-inferiors
3393 @item remove-inferiors @var{infno}@dots{}
3394 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3395 possible to remove an inferior that is running with this command. For
3396 those, use the @code{kill} or @code{detach} command first.
3397
3398 @end table
3399
3400 To quit debugging one of the running inferiors that is not the current
3401 inferior, you can either detach from it by using the @w{@code{detach
3402 inferior}} command (allowing it to run independently), or kill it
3403 using the @w{@code{kill inferiors}} command:
3404
3405 @table @code
3406 @kindex detach inferiors @var{infno}@dots{}
3407 @item detach inferior @var{infno}@dots{}
3408 Detach from the inferior or inferiors identified by @value{GDBN}
3409 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3410 still stays on the list of inferiors shown by @code{info inferiors},
3411 but its Description will show @samp{<null>}.
3412
3413 @kindex kill inferiors @var{infno}@dots{}
3414 @item kill inferiors @var{infno}@dots{}
3415 Kill the inferior or inferiors identified by @value{GDBN} inferior
3416 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3417 stays on the list of inferiors shown by @code{info inferiors}, but its
3418 Description will show @samp{<null>}.
3419 @end table
3420
3421 After the successful completion of a command such as @code{detach},
3422 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3423 a normal process exit, the inferior is still valid and listed with
3424 @code{info inferiors}, ready to be restarted.
3425
3426
3427 To be notified when inferiors are started or exit under @value{GDBN}'s
3428 control use @w{@code{set print inferior-events}}:
3429
3430 @table @code
3431 @kindex set print inferior-events
3432 @cindex print messages on inferior start and exit
3433 @item set print inferior-events
3434 @itemx set print inferior-events on
3435 @itemx set print inferior-events off
3436 The @code{set print inferior-events} command allows you to enable or
3437 disable printing of messages when @value{GDBN} notices that new
3438 inferiors have started or that inferiors have exited or have been
3439 detached. By default, these messages will be printed.
3440
3441 @kindex show print inferior-events
3442 @item show print inferior-events
3443 Show whether messages will be printed when @value{GDBN} detects that
3444 inferiors have started, exited or have been detached.
3445 @end table
3446
3447 Many commands will work the same with multiple programs as with a
3448 single program: e.g., @code{print myglobal} will simply display the
3449 value of @code{myglobal} in the current inferior.
3450
3451
3452 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3453 get more info about the relationship of inferiors, programs, address
3454 spaces in a debug session. You can do that with the @w{@code{maint
3455 info program-spaces}} command.
3456
3457 @table @code
3458 @kindex maint info program-spaces
3459 @item maint info program-spaces
3460 Print a list of all program spaces currently being managed by
3461 @value{GDBN}.
3462
3463 @value{GDBN} displays for each program space (in this order):
3464
3465 @enumerate
3466 @item
3467 the program space number assigned by @value{GDBN}
3468
3469 @item
3470 the name of the executable loaded into the program space, with e.g.,
3471 the @code{file} command.
3472
3473 @item
3474 the name of the core file loaded into the program space, with e.g.,
3475 the @code{core-file} command.
3476
3477 @end enumerate
3478
3479 @noindent
3480 An asterisk @samp{*} preceding the @value{GDBN} program space number
3481 indicates the current program space.
3482
3483 In addition, below each program space line, @value{GDBN} prints extra
3484 information that isn't suitable to display in tabular form. For
3485 example, the list of inferiors bound to the program space.
3486
3487 @smallexample
3488 (@value{GDBP}) maint info program-spaces
3489 Id Executable Core File
3490 * 1 hello
3491 2 goodbye
3492 Bound inferiors: ID 1 (process 21561)
3493 @end smallexample
3494
3495 Here we can see that no inferior is running the program @code{hello},
3496 while @code{process 21561} is running the program @code{goodbye}. On
3497 some targets, it is possible that multiple inferiors are bound to the
3498 same program space. The most common example is that of debugging both
3499 the parent and child processes of a @code{vfork} call. For example,
3500
3501 @smallexample
3502 (@value{GDBP}) maint info program-spaces
3503 Id Executable Core File
3504 * 1 vfork-test
3505 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3506 @end smallexample
3507
3508 Here, both inferior 2 and inferior 1 are running in the same program
3509 space as a result of inferior 1 having executed a @code{vfork} call.
3510 @end table
3511
3512 @node Threads
3513 @section Debugging Programs with Multiple Threads
3514
3515 @cindex threads of execution
3516 @cindex multiple threads
3517 @cindex switching threads
3518 In some operating systems, such as GNU/Linux and Solaris, a single program
3519 may have more than one @dfn{thread} of execution. The precise semantics
3520 of threads differ from one operating system to another, but in general
3521 the threads of a single program are akin to multiple processes---except
3522 that they share one address space (that is, they can all examine and
3523 modify the same variables). On the other hand, each thread has its own
3524 registers and execution stack, and perhaps private memory.
3525
3526 @value{GDBN} provides these facilities for debugging multi-thread
3527 programs:
3528
3529 @itemize @bullet
3530 @item automatic notification of new threads
3531 @item @samp{thread @var{thread-id}}, a command to switch among threads
3532 @item @samp{info threads}, a command to inquire about existing threads
3533 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3534 a command to apply a command to a list of threads
3535 @item thread-specific breakpoints
3536 @item @samp{set print thread-events}, which controls printing of
3537 messages on thread start and exit.
3538 @item @samp{set libthread-db-search-path @var{path}}, which lets
3539 the user specify which @code{libthread_db} to use if the default choice
3540 isn't compatible with the program.
3541 @end itemize
3542
3543 @cindex focus of debugging
3544 @cindex current thread
3545 The @value{GDBN} thread debugging facility allows you to observe all
3546 threads while your program runs---but whenever @value{GDBN} takes
3547 control, one thread in particular is always the focus of debugging.
3548 This thread is called the @dfn{current thread}. Debugging commands show
3549 program information from the perspective of the current thread.
3550
3551 @cindex @code{New} @var{systag} message
3552 @cindex thread identifier (system)
3553 @c FIXME-implementors!! It would be more helpful if the [New...] message
3554 @c included GDB's numeric thread handle, so you could just go to that
3555 @c thread without first checking `info threads'.
3556 Whenever @value{GDBN} detects a new thread in your program, it displays
3557 the target system's identification for the thread with a message in the
3558 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3559 whose form varies depending on the particular system. For example, on
3560 @sc{gnu}/Linux, you might see
3561
3562 @smallexample
3563 [New Thread 0x41e02940 (LWP 25582)]
3564 @end smallexample
3565
3566 @noindent
3567 when @value{GDBN} notices a new thread. In contrast, on other systems,
3568 the @var{systag} is simply something like @samp{process 368}, with no
3569 further qualifier.
3570
3571 @c FIXME!! (1) Does the [New...] message appear even for the very first
3572 @c thread of a program, or does it only appear for the
3573 @c second---i.e.@: when it becomes obvious we have a multithread
3574 @c program?
3575 @c (2) *Is* there necessarily a first thread always? Or do some
3576 @c multithread systems permit starting a program with multiple
3577 @c threads ab initio?
3578
3579 @anchor{thread numbers}
3580 @cindex thread number, per inferior
3581 @cindex thread identifier (GDB)
3582 For debugging purposes, @value{GDBN} associates its own thread number
3583 ---always a single integer---with each thread of an inferior. This
3584 number is unique between all threads of an inferior, but not unique
3585 between threads of different inferiors.
3586
3587 @cindex qualified thread ID
3588 You can refer to a given thread in an inferior using the qualified
3589 @var{inferior-num}.@var{thread-num} syntax, also known as
3590 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3591 number and @var{thread-num} being the thread number of the given
3592 inferior. For example, thread @code{2.3} refers to thread number 3 of
3593 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3594 then @value{GDBN} infers you're referring to a thread of the current
3595 inferior.
3596
3597 Until you create a second inferior, @value{GDBN} does not show the
3598 @var{inferior-num} part of thread IDs, even though you can always use
3599 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3600 of inferior 1, the initial inferior.
3601
3602 @anchor{thread ID lists}
3603 @cindex thread ID lists
3604 Some commands accept a space-separated @dfn{thread ID list} as
3605 argument. A list element can be:
3606
3607 @enumerate
3608 @item
3609 A thread ID as shown in the first field of the @samp{info threads}
3610 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3611 @samp{1}.
3612
3613 @item
3614 A range of thread numbers, again with or without an inferior
3615 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3616 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3617
3618 @item
3619 All threads of an inferior, specified with a star wildcard, with or
3620 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3621 @samp{1.*}) or @code{*}. The former refers to all threads of the
3622 given inferior, and the latter form without an inferior qualifier
3623 refers to all threads of the current inferior.
3624
3625 @end enumerate
3626
3627 For example, if the current inferior is 1, and inferior 7 has one
3628 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3629 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3630 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3631 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3632 7.1}.
3633
3634
3635 @anchor{global thread numbers}
3636 @cindex global thread number
3637 @cindex global thread identifier (GDB)
3638 In addition to a @emph{per-inferior} number, each thread is also
3639 assigned a unique @emph{global} number, also known as @dfn{global
3640 thread ID}, a single integer. Unlike the thread number component of
3641 the thread ID, no two threads have the same global ID, even when
3642 you're debugging multiple inferiors.
3643
3644 From @value{GDBN}'s perspective, a process always has at least one
3645 thread. In other words, @value{GDBN} assigns a thread number to the
3646 program's ``main thread'' even if the program is not multi-threaded.
3647
3648 @vindex $_thread@r{, convenience variable}
3649 @vindex $_gthread@r{, convenience variable}
3650 The debugger convenience variables @samp{$_thread} and
3651 @samp{$_gthread} contain, respectively, the per-inferior thread number
3652 and the global thread number of the current thread. You may find this
3653 useful in writing breakpoint conditional expressions, command scripts,
3654 and so forth. The convenience variable @samp{$_inferior_thread_count}
3655 contains the number of live threads in the current inferior.
3656 @xref{Convenience Vars,, Convenience Variables}, for general
3657 information on convenience variables.
3658
3659 When running in non-stop mode (@pxref{Non-Stop Mode}), where new
3660 threads can be created, and existing threads exit, at any time,
3661 @samp{$_inferior_thread_count} could return a different value each
3662 time it is evaluated.
3663
3664 If @value{GDBN} detects the program is multi-threaded, it augments the
3665 usual message about stopping at a breakpoint with the ID and name of
3666 the thread that hit the breakpoint.
3667
3668 @smallexample
3669 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3670 @end smallexample
3671
3672 Likewise when the program receives a signal:
3673
3674 @smallexample
3675 Thread 1 "main" received signal SIGINT, Interrupt.
3676 @end smallexample
3677
3678 @table @code
3679 @anchor{info_threads}
3680 @kindex info threads
3681 @item info threads @r{[}@var{thread-id-list}@r{]}
3682
3683 Display information about one or more threads. With no arguments
3684 displays information about all threads. You can specify the list of
3685 threads that you want to display using the thread ID list syntax
3686 (@pxref{thread ID lists}).
3687
3688 @value{GDBN} displays for each thread (in this order):
3689
3690 @enumerate
3691 @item
3692 the per-inferior thread number assigned by @value{GDBN}
3693
3694 @item
3695 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3696 option was specified
3697
3698 @item
3699 the target system's thread identifier (@var{systag})
3700
3701 @item
3702 the thread's name, if one is known. A thread can either be named by
3703 the user (see @code{thread name}, below), or, in some cases, by the
3704 program itself.
3705
3706 @item
3707 the current stack frame summary for that thread
3708 @end enumerate
3709
3710 @noindent
3711 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3712 indicates the current thread.
3713
3714 For example,
3715 @end table
3716 @c end table here to get a little more width for example
3717
3718 @smallexample
3719 (@value{GDBP}) info threads
3720 Id Target Id Frame
3721 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3722 2 process 35 thread 23 0x34e5 in sigpause ()
3723 3 process 35 thread 27 0x34e5 in sigpause ()
3724 at threadtest.c:68
3725 @end smallexample
3726
3727 If you're debugging multiple inferiors, @value{GDBN} displays thread
3728 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3729 Otherwise, only @var{thread-num} is shown.
3730
3731 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3732 indicating each thread's global thread ID:
3733
3734 @smallexample
3735 (@value{GDBP}) info threads
3736 Id GId Target Id Frame
3737 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3738 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3739 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3740 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3741 @end smallexample
3742
3743 On Solaris, you can display more information about user threads with a
3744 Solaris-specific command:
3745
3746 @table @code
3747 @item maint info sol-threads
3748 @kindex maint info sol-threads
3749 @cindex thread info (Solaris)
3750 Display info on Solaris user threads.
3751 @end table
3752
3753 @table @code
3754 @kindex thread @var{thread-id}
3755 @item thread @var{thread-id}
3756 Make thread ID @var{thread-id} the current thread. The command
3757 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3758 the first field of the @samp{info threads} display, with or without an
3759 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3760
3761 @value{GDBN} responds by displaying the system identifier of the
3762 thread you selected, and its current stack frame summary:
3763
3764 @smallexample
3765 (@value{GDBP}) thread 2
3766 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3767 #0 some_function (ignore=0x0) at example.c:8
3768 8 printf ("hello\n");
3769 @end smallexample
3770
3771 @noindent
3772 As with the @samp{[New @dots{}]} message, the form of the text after
3773 @samp{Switching to} depends on your system's conventions for identifying
3774 threads.
3775
3776 @anchor{thread apply all}
3777 @kindex thread apply
3778 @cindex apply command to several threads
3779 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3780 The @code{thread apply} command allows you to apply the named
3781 @var{command} to one or more threads. Specify the threads that you
3782 want affected using the thread ID list syntax (@pxref{thread ID
3783 lists}), or specify @code{all} to apply to all threads. To apply a
3784 command to all threads in descending order, type @kbd{thread apply all
3785 @var{command}}. To apply a command to all threads in ascending order,
3786 type @kbd{thread apply all -ascending @var{command}}.
3787
3788 The @var{flag} arguments control what output to produce and how to handle
3789 errors raised when applying @var{command} to a thread. @var{flag}
3790 must start with a @code{-} directly followed by one letter in
3791 @code{qcs}. If several flags are provided, they must be given
3792 individually, such as @code{-c -q}.
3793
3794 By default, @value{GDBN} displays some thread information before the
3795 output produced by @var{command}, and an error raised during the
3796 execution of a @var{command} will abort @code{thread apply}. The
3797 following flags can be used to fine-tune this behavior:
3798
3799 @table @code
3800 @item -c
3801 The flag @code{-c}, which stands for @samp{continue}, causes any
3802 errors in @var{command} to be displayed, and the execution of
3803 @code{thread apply} then continues.
3804 @item -s
3805 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3806 or empty output produced by a @var{command} to be silently ignored.
3807 That is, the execution continues, but the thread information and errors
3808 are not printed.
3809 @item -q
3810 The flag @code{-q} (@samp{quiet}) disables printing the thread
3811 information.
3812 @end table
3813
3814 Flags @code{-c} and @code{-s} cannot be used together.
3815
3816 @kindex taas
3817 @cindex apply command to all threads (ignoring errors and empty output)
3818 @item taas [@var{option}]@dots{} @var{command}
3819 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3820 Applies @var{command} on all threads, ignoring errors and empty output.
3821
3822 The @code{taas} command accepts the same options as the @code{thread
3823 apply all} command. @xref{thread apply all}.
3824
3825 @kindex tfaas
3826 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3827 @item tfaas [@var{option}]@dots{} @var{command}
3828 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3829 Applies @var{command} on all frames of all threads, ignoring errors
3830 and empty output. Note that the flag @code{-s} is specified twice:
3831 The first @code{-s} ensures that @code{thread apply} only shows the thread
3832 information of the threads for which @code{frame apply} produces
3833 some output. The second @code{-s} is needed to ensure that @code{frame
3834 apply} shows the frame information of a frame only if the
3835 @var{command} successfully produced some output.
3836
3837 It can for example be used to print a local variable or a function
3838 argument without knowing the thread or frame where this variable or argument
3839 is, using:
3840 @smallexample
3841 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3842 @end smallexample
3843
3844 The @code{tfaas} command accepts the same options as the @code{frame
3845 apply} command. @xref{Frame Apply,,frame apply}.
3846
3847 @kindex thread name
3848 @cindex name a thread
3849 @item thread name [@var{name}]
3850 This command assigns a name to the current thread. If no argument is
3851 given, any existing user-specified name is removed. The thread name
3852 appears in the @samp{info threads} display.
3853
3854 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3855 determine the name of the thread as given by the OS. On these
3856 systems, a name specified with @samp{thread name} will override the
3857 system-give name, and removing the user-specified name will cause
3858 @value{GDBN} to once again display the system-specified name.
3859
3860 @kindex thread find
3861 @cindex search for a thread
3862 @item thread find [@var{regexp}]
3863 Search for and display thread ids whose name or @var{systag}
3864 matches the supplied regular expression.
3865
3866 As well as being the complement to the @samp{thread name} command,
3867 this command also allows you to identify a thread by its target
3868 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3869 is the LWP id.
3870
3871 @smallexample
3872 (@value{GDBP}) thread find 26688
3873 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3874 (@value{GDBP}) info thread 4
3875 Id Target Id Frame
3876 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3877 @end smallexample
3878
3879 @kindex set print thread-events
3880 @cindex print messages on thread start and exit
3881 @item set print thread-events
3882 @itemx set print thread-events on
3883 @itemx set print thread-events off
3884 The @code{set print thread-events} command allows you to enable or
3885 disable printing of messages when @value{GDBN} notices that new threads have
3886 started or that threads have exited. By default, these messages will
3887 be printed if detection of these events is supported by the target.
3888 Note that these messages cannot be disabled on all targets.
3889
3890 @kindex show print thread-events
3891 @item show print thread-events
3892 Show whether messages will be printed when @value{GDBN} detects that threads
3893 have started and exited.
3894 @end table
3895
3896 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3897 more information about how @value{GDBN} behaves when you stop and start
3898 programs with multiple threads.
3899
3900 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3901 watchpoints in programs with multiple threads.
3902
3903 @anchor{set libthread-db-search-path}
3904 @table @code
3905 @kindex set libthread-db-search-path
3906 @cindex search path for @code{libthread_db}
3907 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3908 If this variable is set, @var{path} is a colon-separated list of
3909 directories @value{GDBN} will use to search for @code{libthread_db}.
3910 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3911 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3912 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3913 macro.
3914
3915 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3916 @code{libthread_db} library to obtain information about threads in the
3917 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3918 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3919 specific thread debugging library loading is enabled
3920 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3921
3922 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3923 refers to the default system directories that are
3924 normally searched for loading shared libraries. The @samp{$sdir} entry
3925 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3926 (@pxref{libthread_db.so.1 file}).
3927
3928 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3929 refers to the directory from which @code{libpthread}
3930 was loaded in the inferior process.
3931
3932 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3933 @value{GDBN} attempts to initialize it with the current inferior process.
3934 If this initialization fails (which could happen because of a version
3935 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3936 will unload @code{libthread_db}, and continue with the next directory.
3937 If none of @code{libthread_db} libraries initialize successfully,
3938 @value{GDBN} will issue a warning and thread debugging will be disabled.
3939
3940 Setting @code{libthread-db-search-path} is currently implemented
3941 only on some platforms.
3942
3943 @kindex show libthread-db-search-path
3944 @item show libthread-db-search-path
3945 Display current libthread_db search path.
3946
3947 @kindex set debug libthread-db
3948 @kindex show debug libthread-db
3949 @cindex debugging @code{libthread_db}
3950 @item set debug libthread-db
3951 @itemx show debug libthread-db
3952 Turns on or off display of @code{libthread_db}-related events.
3953 Use @code{1} to enable, @code{0} to disable.
3954
3955 @kindex set debug threads
3956 @kindex show debug threads
3957 @cindex debugging @code{threads}
3958 @item set debug threads @r{[}on@r{|}off@r{]}
3959 @itemx show debug threads
3960 When @samp{on} @value{GDBN} will print additional messages when
3961 threads are created and deleted.
3962 @end table
3963
3964 @node Forks
3965 @section Debugging Forks
3966
3967 @cindex fork, debugging programs which call
3968 @cindex multiple processes
3969 @cindex processes, multiple
3970 On most systems, @value{GDBN} has no special support for debugging
3971 programs which create additional processes using the @code{fork}
3972 function. When a program forks, @value{GDBN} will continue to debug the
3973 parent process and the child process will run unimpeded. If you have
3974 set a breakpoint in any code which the child then executes, the child
3975 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3976 will cause it to terminate.
3977
3978 However, if you want to debug the child process there is a workaround
3979 which isn't too painful. Put a call to @code{sleep} in the code which
3980 the child process executes after the fork. It may be useful to sleep
3981 only if a certain environment variable is set, or a certain file exists,
3982 so that the delay need not occur when you don't want to run @value{GDBN}
3983 on the child. While the child is sleeping, use the @code{ps} program to
3984 get its process ID. Then tell @value{GDBN} (a new invocation of
3985 @value{GDBN} if you are also debugging the parent process) to attach to
3986 the child process (@pxref{Attach}). From that point on you can debug
3987 the child process just like any other process which you attached to.
3988
3989 On some systems, @value{GDBN} provides support for debugging programs
3990 that create additional processes using the @code{fork} or @code{vfork}
3991 functions. On @sc{gnu}/Linux platforms, this feature is supported
3992 with kernel version 2.5.46 and later.
3993
3994 The fork debugging commands are supported in native mode and when
3995 connected to @code{gdbserver} in either @code{target remote} mode or
3996 @code{target extended-remote} mode.
3997
3998 By default, when a program forks, @value{GDBN} will continue to debug
3999 the parent process and the child process will run unimpeded.
4000
4001 If you want to follow the child process instead of the parent process,
4002 use the command @w{@code{set follow-fork-mode}}.
4003
4004 @table @code
4005 @kindex set follow-fork-mode
4006 @item set follow-fork-mode @var{mode}
4007 Set the debugger response to a program call of @code{fork} or
4008 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
4009 process. The @var{mode} argument can be:
4010
4011 @table @code
4012 @item parent
4013 The original process is debugged after a fork. The child process runs
4014 unimpeded. This is the default.
4015
4016 @item child
4017 The new process is debugged after a fork. The parent process runs
4018 unimpeded.
4019
4020 @end table
4021
4022 @kindex show follow-fork-mode
4023 @item show follow-fork-mode
4024 Display the current debugger response to a @code{fork} or @code{vfork} call.
4025 @end table
4026
4027 @cindex debugging multiple processes
4028 On Linux, if you want to debug both the parent and child processes, use the
4029 command @w{@code{set detach-on-fork}}.
4030
4031 @table @code
4032 @kindex set detach-on-fork
4033 @item set detach-on-fork @var{mode}
4034 Tells gdb whether to detach one of the processes after a fork, or
4035 retain debugger control over them both.
4036
4037 @table @code
4038 @item on
4039 The child process (or parent process, depending on the value of
4040 @code{follow-fork-mode}) will be detached and allowed to run
4041 independently. This is the default.
4042
4043 @item off
4044 Both processes will be held under the control of @value{GDBN}.
4045 One process (child or parent, depending on the value of
4046 @code{follow-fork-mode}) is debugged as usual, while the other
4047 is held suspended.
4048
4049 @end table
4050
4051 @kindex show detach-on-fork
4052 @item show detach-on-fork
4053 Show whether detach-on-fork mode is on/off.
4054 @end table
4055
4056 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
4057 will retain control of all forked processes (including nested forks).
4058 You can list the forked processes under the control of @value{GDBN} by
4059 using the @w{@code{info inferiors}} command, and switch from one fork
4060 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
4061 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
4062
4063 To quit debugging one of the forked processes, you can either detach
4064 from it by using the @w{@code{detach inferiors}} command (allowing it
4065 to run independently), or kill it using the @w{@code{kill inferiors}}
4066 command. @xref{Inferiors Connections and Programs, ,Debugging
4067 Multiple Inferiors Connections and Programs}.
4068
4069 If you ask to debug a child process and a @code{vfork} is followed by an
4070 @code{exec}, @value{GDBN} executes the new target up to the first
4071 breakpoint in the new target. If you have a breakpoint set on
4072 @code{main} in your original program, the breakpoint will also be set on
4073 the child process's @code{main}.
4074
4075 On some systems, when a child process is spawned by @code{vfork}, you
4076 cannot debug the child or parent until an @code{exec} call completes.
4077
4078 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
4079 call executes, the new target restarts. To restart the parent
4080 process, use the @code{file} command with the parent executable name
4081 as its argument. By default, after an @code{exec} call executes,
4082 @value{GDBN} discards the symbols of the previous executable image.
4083 You can change this behaviour with the @w{@code{set follow-exec-mode}}
4084 command.
4085
4086 @table @code
4087 @kindex set follow-exec-mode
4088 @item set follow-exec-mode @var{mode}
4089
4090 Set debugger response to a program call of @code{exec}. An
4091 @code{exec} call replaces the program image of a process.
4092
4093 @code{follow-exec-mode} can be:
4094
4095 @table @code
4096 @item new
4097 @value{GDBN} creates a new inferior and rebinds the process to this
4098 new inferior. The program the process was running before the
4099 @code{exec} call can be restarted afterwards by restarting the
4100 original inferior.
4101
4102 For example:
4103
4104 @smallexample
4105 (@value{GDBP}) info inferiors
4106 (@value{GDBP}) info inferior
4107 Id Description Executable
4108 * 1 <null> prog1
4109 (@value{GDBP}) run
4110 process 12020 is executing new program: prog2
4111 Program exited normally.
4112 (@value{GDBP}) info inferiors
4113 Id Description Executable
4114 1 <null> prog1
4115 * 2 <null> prog2
4116 @end smallexample
4117
4118 @item same
4119 @value{GDBN} keeps the process bound to the same inferior. The new
4120 executable image replaces the previous executable loaded in the
4121 inferior. Restarting the inferior after the @code{exec} call, with
4122 e.g., the @code{run} command, restarts the executable the process was
4123 running after the @code{exec} call. This is the default mode.
4124
4125 For example:
4126
4127 @smallexample
4128 (@value{GDBP}) info inferiors
4129 Id Description Executable
4130 * 1 <null> prog1
4131 (@value{GDBP}) run
4132 process 12020 is executing new program: prog2
4133 Program exited normally.
4134 (@value{GDBP}) info inferiors
4135 Id Description Executable
4136 * 1 <null> prog2
4137 @end smallexample
4138
4139 @end table
4140 @end table
4141
4142 @code{follow-exec-mode} is supported in native mode and
4143 @code{target extended-remote} mode.
4144
4145 You can use the @code{catch} command to make @value{GDBN} stop whenever
4146 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4147 Catchpoints, ,Setting Catchpoints}.
4148
4149 @node Checkpoint/Restart
4150 @section Setting a @emph{Bookmark} to Return to Later
4151
4152 @cindex checkpoint
4153 @cindex restart
4154 @cindex bookmark
4155 @cindex snapshot of a process
4156 @cindex rewind program state
4157
4158 On certain operating systems@footnote{Currently, only
4159 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4160 program's state, called a @dfn{checkpoint}, and come back to it
4161 later.
4162
4163 Returning to a checkpoint effectively undoes everything that has
4164 happened in the program since the @code{checkpoint} was saved. This
4165 includes changes in memory, registers, and even (within some limits)
4166 system state. Effectively, it is like going back in time to the
4167 moment when the checkpoint was saved.
4168
4169 Thus, if you're stepping thru a program and you think you're
4170 getting close to the point where things go wrong, you can save
4171 a checkpoint. Then, if you accidentally go too far and miss
4172 the critical statement, instead of having to restart your program
4173 from the beginning, you can just go back to the checkpoint and
4174 start again from there.
4175
4176 This can be especially useful if it takes a lot of time or
4177 steps to reach the point where you think the bug occurs.
4178
4179 To use the @code{checkpoint}/@code{restart} method of debugging:
4180
4181 @table @code
4182 @kindex checkpoint
4183 @item checkpoint
4184 Save a snapshot of the debugged program's current execution state.
4185 The @code{checkpoint} command takes no arguments, but each checkpoint
4186 is assigned a small integer id, similar to a breakpoint id.
4187
4188 @kindex info checkpoints
4189 @item info checkpoints
4190 List the checkpoints that have been saved in the current debugging
4191 session. For each checkpoint, the following information will be
4192 listed:
4193
4194 @table @code
4195 @item Checkpoint ID
4196 @item Process ID
4197 @item Code Address
4198 @item Source line, or label
4199 @end table
4200
4201 @kindex restart @var{checkpoint-id}
4202 @item restart @var{checkpoint-id}
4203 Restore the program state that was saved as checkpoint number
4204 @var{checkpoint-id}. All program variables, registers, stack frames
4205 etc.@: will be returned to the values that they had when the checkpoint
4206 was saved. In essence, gdb will ``wind back the clock'' to the point
4207 in time when the checkpoint was saved.
4208
4209 Note that breakpoints, @value{GDBN} variables, command history etc.
4210 are not affected by restoring a checkpoint. In general, a checkpoint
4211 only restores things that reside in the program being debugged, not in
4212 the debugger.
4213
4214 @kindex delete checkpoint @var{checkpoint-id}
4215 @item delete checkpoint @var{checkpoint-id}
4216 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4217
4218 @end table
4219
4220 Returning to a previously saved checkpoint will restore the user state
4221 of the program being debugged, plus a significant subset of the system
4222 (OS) state, including file pointers. It won't ``un-write'' data from
4223 a file, but it will rewind the file pointer to the previous location,
4224 so that the previously written data can be overwritten. For files
4225 opened in read mode, the pointer will also be restored so that the
4226 previously read data can be read again.
4227
4228 Of course, characters that have been sent to a printer (or other
4229 external device) cannot be ``snatched back'', and characters received
4230 from eg.@: a serial device can be removed from internal program buffers,
4231 but they cannot be ``pushed back'' into the serial pipeline, ready to
4232 be received again. Similarly, the actual contents of files that have
4233 been changed cannot be restored (at this time).
4234
4235 However, within those constraints, you actually can ``rewind'' your
4236 program to a previously saved point in time, and begin debugging it
4237 again --- and you can change the course of events so as to debug a
4238 different execution path this time.
4239
4240 @cindex checkpoints and process id
4241 Finally, there is one bit of internal program state that will be
4242 different when you return to a checkpoint --- the program's process
4243 id. Each checkpoint will have a unique process id (or @var{pid}),
4244 and each will be different from the program's original @var{pid}.
4245 If your program has saved a local copy of its process id, this could
4246 potentially pose a problem.
4247
4248 @subsection A Non-obvious Benefit of Using Checkpoints
4249
4250 On some systems such as @sc{gnu}/Linux, address space randomization
4251 is performed on new processes for security reasons. This makes it
4252 difficult or impossible to set a breakpoint, or watchpoint, on an
4253 absolute address if you have to restart the program, since the
4254 absolute location of a symbol will change from one execution to the
4255 next.
4256
4257 A checkpoint, however, is an @emph{identical} copy of a process.
4258 Therefore if you create a checkpoint at (eg.@:) the start of main,
4259 and simply return to that checkpoint instead of restarting the
4260 process, you can avoid the effects of address randomization and
4261 your symbols will all stay in the same place.
4262
4263 @node Stopping
4264 @chapter Stopping and Continuing
4265
4266 The principal purposes of using a debugger are so that you can stop your
4267 program before it terminates; or so that, if your program runs into
4268 trouble, you can investigate and find out why.
4269
4270 Inside @value{GDBN}, your program may stop for any of several reasons,
4271 such as a signal, a breakpoint, or reaching a new line after a
4272 @value{GDBN} command such as @code{step}. You may then examine and
4273 change variables, set new breakpoints or remove old ones, and then
4274 continue execution. Usually, the messages shown by @value{GDBN} provide
4275 ample explanation of the status of your program---but you can also
4276 explicitly request this information at any time.
4277
4278 @table @code
4279 @kindex info program
4280 @item info program
4281 Display information about the status of your program: whether it is
4282 running or not, what process it is, and why it stopped.
4283 @end table
4284
4285 @menu
4286 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4287 * Continuing and Stepping:: Resuming execution
4288 * Skipping Over Functions and Files::
4289 Skipping over functions and files
4290 * Signals:: Signals
4291 * Thread Stops:: Stopping and starting multi-thread programs
4292 @end menu
4293
4294 @node Breakpoints
4295 @section Breakpoints, Watchpoints, and Catchpoints
4296
4297 @cindex breakpoints
4298 A @dfn{breakpoint} makes your program stop whenever a certain point in
4299 the program is reached. For each breakpoint, you can add conditions to
4300 control in finer detail whether your program stops. You can set
4301 breakpoints with the @code{break} command and its variants (@pxref{Set
4302 Breaks, ,Setting Breakpoints}), to specify the place where your program
4303 should stop by line number, function name or exact address in the
4304 program.
4305
4306 On some systems, you can set breakpoints in shared libraries before
4307 the executable is run.
4308
4309 @cindex watchpoints
4310 @cindex data breakpoints
4311 @cindex memory tracing
4312 @cindex breakpoint on memory address
4313 @cindex breakpoint on variable modification
4314 A @dfn{watchpoint} is a special breakpoint that stops your program
4315 when the value of an expression changes. The expression may be a value
4316 of a variable, or it could involve values of one or more variables
4317 combined by operators, such as @samp{a + b}. This is sometimes called
4318 @dfn{data breakpoints}. You must use a different command to set
4319 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4320 from that, you can manage a watchpoint like any other breakpoint: you
4321 enable, disable, and delete both breakpoints and watchpoints using the
4322 same commands.
4323
4324 You can arrange to have values from your program displayed automatically
4325 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4326 Automatic Display}.
4327
4328 @cindex catchpoints
4329 @cindex breakpoint on events
4330 A @dfn{catchpoint} is another special breakpoint that stops your program
4331 when a certain kind of event occurs, such as the throwing of a C@t{++}
4332 exception or the loading of a library. As with watchpoints, you use a
4333 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4334 Catchpoints}), but aside from that, you can manage a catchpoint like any
4335 other breakpoint. (To stop when your program receives a signal, use the
4336 @code{handle} command; see @ref{Signals, ,Signals}.)
4337
4338 @cindex breakpoint numbers
4339 @cindex numbers for breakpoints
4340 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4341 catchpoint when you create it; these numbers are successive integers
4342 starting with one. In many of the commands for controlling various
4343 features of breakpoints you use the breakpoint number to say which
4344 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4345 @dfn{disabled}; if disabled, it has no effect on your program until you
4346 enable it again.
4347
4348 @cindex breakpoint ranges
4349 @cindex breakpoint lists
4350 @cindex ranges of breakpoints
4351 @cindex lists of breakpoints
4352 Some @value{GDBN} commands accept a space-separated list of breakpoints
4353 on which to operate. A list element can be either a single breakpoint number,
4354 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4355 When a breakpoint list is given to a command, all breakpoints in that list
4356 are operated on.
4357
4358 @menu
4359 * Set Breaks:: Setting breakpoints
4360 * Set Watchpoints:: Setting watchpoints
4361 * Set Catchpoints:: Setting catchpoints
4362 * Delete Breaks:: Deleting breakpoints
4363 * Disabling:: Disabling breakpoints
4364 * Conditions:: Break conditions
4365 * Break Commands:: Breakpoint command lists
4366 * Dynamic Printf:: Dynamic printf
4367 * Save Breakpoints:: How to save breakpoints in a file
4368 * Static Probe Points:: Listing static probe points
4369 * Error in Breakpoints:: ``Cannot insert breakpoints''
4370 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4371 @end menu
4372
4373 @node Set Breaks
4374 @subsection Setting Breakpoints
4375
4376 @c FIXME LMB what does GDB do if no code on line of breakpt?
4377 @c consider in particular declaration with/without initialization.
4378 @c
4379 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4380
4381 @kindex break
4382 @kindex b @r{(@code{break})}
4383 @vindex $bpnum@r{, convenience variable}
4384 @cindex latest breakpoint
4385 Breakpoints are set with the @code{break} command (abbreviated
4386 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4387 number of the breakpoint you've set most recently:
4388 @smallexample
4389 (gdb) b main
4390 Breakpoint 1 at 0x11c6: file zeoes.c, line 24.
4391 (gdb) p $bpnum
4392 $1 = 1
4393 @end smallexample
4394
4395 A breakpoint may be mapped to multiple code locations for example with
4396 inlined functions, Ada generics, C@t{++} templates or overloaded function names.
4397 @value{GDBN} then indicates the number of code locations in the breakpoint
4398 command output:
4399 @smallexample
4400 (gdb) b some_func
4401 Breakpoint 2 at 0x1179: some_func. (3 locations)
4402 (gdb) p $bpnum
4403 $2 = 2
4404 (gdb)
4405 @end smallexample
4406
4407 @vindex $_hit_bpnum@r{, convenience variable}
4408 @vindex $_hit_locno@r{, convenience variable}
4409 When your program stops on a breakpoint, the convenience variables
4410 @samp{$_hit_bpnum} and @samp{$_hit_locno} are respectively set to the number of
4411 the encountered breakpoint and the number of the breakpoint's code location:
4412 @smallexample
4413 Thread 1 "zeoes" hit Breakpoint 2.1, some_func () at zeoes.c:8
4414 8 printf("some func\n");
4415 (gdb) p $_hit_bpnum
4416 $5 = 2
4417 (gdb) p $_hit_locno
4418 $6 = 1
4419 (gdb)
4420 @end smallexample
4421
4422 Note that @samp{$_hit_bpnum} and @samp{$bpnum} are not equivalent:
4423 @samp{$_hit_bpnum} is set to the breakpoint number @b{last hit}, while
4424 @samp{$bpnum} is set to the breakpoint number @b{last set}.
4425
4426
4427 If the encountered breakpoint has only one code location, @samp{$_hit_locno}
4428 is set to 1:
4429 @smallexample
4430 Breakpoint 1, main (argc=1, argv=0x7fffffffe018) at zeoes.c:24
4431 24 if (argc > 1)
4432 (gdb) p $_hit_bpnum
4433 $3 = 1
4434 (gdb) p $_hit_locno
4435 $4 = 1
4436 (gdb)
4437 @end smallexample
4438
4439 The @samp{$_hit_bpnum} and @samp{$_hit_locno} variables can typically be used
4440 in a breakpoint command list.
4441 (@pxref{Break Commands, ,Breakpoint Command Lists}). For example, as
4442 part of the breakpoint command list, you can disable completely the
4443 encountered breakpoint using @kbd{disable $_hit_bpnum} or disable the
4444 specific encountered breakpoint location using
4445 @kbd{disable $_hit_bpnum.$_hit_locno}.
4446 If a breakpoint has only one location, @samp{$_hit_locno} is set to 1
4447 and the commands @kbd{disable $_hit_bpnum} and
4448 @kbd{disable $_hit_bpnum.$_hit_locno} both disable the breakpoint.
4449
4450 You can also define aliases to easily disable the last hit location or
4451 last hit breakpoint:
4452 @smallexample
4453 (gdb) alias lld = disable $_hit_bpnum.$_hit_locno
4454 (gdb) alias lbd = disable $_hit_bpnum
4455 @end smallexample
4456
4457 @table @code
4458 @item break @var{locspec}
4459 Set a breakpoint at all the code locations in your program that result
4460 from resolving the given @var{locspec}. @var{locspec} can specify a
4461 function name, a line number, an address of an instruction, and more.
4462 @xref{Location Specifications}, for the various forms of
4463 @var{locspec}. The breakpoint will stop your program just before it
4464 executes the instruction at the address of any of the breakpoint's
4465 code locations.
4466
4467 When using source languages that permit overloading of symbols, such
4468 as C@t{++}, a function name may refer to more than one symbol, and
4469 thus more than one place to break. @xref{Ambiguous
4470 Expressions,,Ambiguous Expressions}, for a discussion of that
4471 situation.
4472
4473 It is also possible to insert a breakpoint that will stop the program
4474 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4475 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4476
4477 @item break
4478 When called without any arguments, @code{break} sets a breakpoint at
4479 the next instruction to be executed in the selected stack frame
4480 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4481 innermost, this makes your program stop as soon as control
4482 returns to that frame. This is similar to the effect of a
4483 @code{finish} command in the frame inside the selected frame---except
4484 that @code{finish} does not leave an active breakpoint. If you use
4485 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4486 the next time it reaches the current location; this may be useful
4487 inside loops.
4488
4489 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4490 least one instruction has been executed. If it did not do this, you
4491 would be unable to proceed past a breakpoint without first disabling the
4492 breakpoint. This rule applies whether or not the breakpoint already
4493 existed when your program stopped.
4494
4495 @item break @dots{} if @var{cond}
4496 Set a breakpoint with condition @var{cond}; evaluate the expression
4497 @var{cond} each time the breakpoint is reached, and stop only if the
4498 value is nonzero---that is, if @var{cond} evaluates as true.
4499 @samp{@dots{}} stands for one of the possible arguments described
4500 above (or no argument) specifying where to break. @xref{Conditions,
4501 ,Break Conditions}, for more information on breakpoint conditions.
4502
4503 The breakpoint may be mapped to multiple locations. If the breakpoint
4504 condition @var{cond} is invalid at some but not all of the locations,
4505 the locations for which the condition is invalid are disabled. For
4506 example, @value{GDBN} reports below that two of the three locations
4507 are disabled.
4508
4509 @smallexample
4510 (@value{GDBP}) break func if a == 10
4511 warning: failed to validate condition at location 0x11ce, disabling:
4512 No symbol "a" in current context.
4513 warning: failed to validate condition at location 0x11b6, disabling:
4514 No symbol "a" in current context.
4515 Breakpoint 1 at 0x11b6: func. (3 locations)
4516 @end smallexample
4517
4518 Locations that are disabled because of the condition are denoted by an
4519 uppercase @code{N} in the output of the @code{info breakpoints}
4520 command:
4521
4522 @smallexample
4523 (@value{GDBP}) info breakpoints
4524 Num Type Disp Enb Address What
4525 1 breakpoint keep y <MULTIPLE>
4526 stop only if a == 10
4527 1.1 N* 0x00000000000011b6 in ...
4528 1.2 y 0x00000000000011c2 in ...
4529 1.3 N* 0x00000000000011ce in ...
4530 (*): Breakpoint condition is invalid at this location.
4531 @end smallexample
4532
4533 If the breakpoint condition @var{cond} is invalid in the context of
4534 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4535 define the breakpoint. For example, if variable @code{foo} is an
4536 undefined variable:
4537
4538 @smallexample
4539 (@value{GDBP}) break func if foo
4540 No symbol "foo" in current context.
4541 @end smallexample
4542
4543 @item break @dots{} -force-condition if @var{cond}
4544 There may be cases where the condition @var{cond} is invalid at all
4545 the current locations, but the user knows that it will be valid at a
4546 future location; for example, because of a library load. In such
4547 cases, by using the @code{-force-condition} keyword before @samp{if},
4548 @value{GDBN} can be forced to define the breakpoint with the given
4549 condition expression instead of refusing it.
4550
4551 @smallexample
4552 (@value{GDBP}) break func -force-condition if foo
4553 warning: failed to validate condition at location 1, disabling:
4554 No symbol "foo" in current context.
4555 warning: failed to validate condition at location 2, disabling:
4556 No symbol "foo" in current context.
4557 warning: failed to validate condition at location 3, disabling:
4558 No symbol "foo" in current context.
4559 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4560 @end smallexample
4561
4562 This causes all the present locations where the breakpoint would
4563 otherwise be inserted, to be disabled, as seen in the example above.
4564 However, if there exist locations at which the condition is valid, the
4565 @code{-force-condition} keyword has no effect.
4566
4567 @kindex tbreak
4568 @item tbreak @var{args}
4569 Set a breakpoint enabled only for one stop. The @var{args} are the
4570 same as for the @code{break} command, and the breakpoint is set in the same
4571 way, but the breakpoint is automatically deleted after the first time your
4572 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4573
4574 @kindex hbreak
4575 @cindex hardware breakpoints
4576 @item hbreak @var{args}
4577 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4578 @code{break} command and the breakpoint is set in the same way, but the
4579 breakpoint requires hardware support and some target hardware may not
4580 have this support. The main purpose of this is EPROM/ROM code
4581 debugging, so you can set a breakpoint at an instruction without
4582 changing the instruction. This can be used with the new trap-generation
4583 provided by SPARClite DSU and most x86-based targets. These targets
4584 will generate traps when a program accesses some data or instruction
4585 address that is assigned to the debug registers. However the hardware
4586 breakpoint registers can take a limited number of breakpoints. For
4587 example, on the DSU, only two data breakpoints can be set at a time, and
4588 @value{GDBN} will reject this command if more than two are used. Delete
4589 or disable unused hardware breakpoints before setting new ones
4590 (@pxref{Disabling, ,Disabling Breakpoints}).
4591 @xref{Conditions, ,Break Conditions}.
4592 For remote targets, you can restrict the number of hardware
4593 breakpoints @value{GDBN} will use, see @ref{set remote
4594 hardware-breakpoint-limit}.
4595
4596 @kindex thbreak
4597 @item thbreak @var{args}
4598 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4599 are the same as for the @code{hbreak} command and the breakpoint is set in
4600 the same way. However, like the @code{tbreak} command,
4601 the breakpoint is automatically deleted after the
4602 first time your program stops there. Also, like the @code{hbreak}
4603 command, the breakpoint requires hardware support and some target hardware
4604 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4605 See also @ref{Conditions, ,Break Conditions}.
4606
4607 @kindex rbreak
4608 @cindex regular expression
4609 @cindex breakpoints at functions matching a regexp
4610 @cindex set breakpoints in many functions
4611 @item rbreak @var{regex}
4612 Set breakpoints on all functions matching the regular expression
4613 @var{regex}. This command sets an unconditional breakpoint on all
4614 matches, printing a list of all breakpoints it set. Once these
4615 breakpoints are set, they are treated just like the breakpoints set with
4616 the @code{break} command. You can delete them, disable them, or make
4617 them conditional the same way as any other breakpoint.
4618
4619 In programs using different languages, @value{GDBN} chooses the syntax
4620 to print the list of all breakpoints it sets according to the
4621 @samp{set language} value: using @samp{set language auto}
4622 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4623 language of the breakpoint's function, other values mean to use
4624 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4625
4626 The syntax of the regular expression is the standard one used with tools
4627 like @file{grep}. Note that this is different from the syntax used by
4628 shells, so for instance @code{foo*} matches all functions that include
4629 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4630 @code{.*} leading and trailing the regular expression you supply, so to
4631 match only functions that begin with @code{foo}, use @code{^foo}.
4632
4633 @cindex non-member C@t{++} functions, set breakpoint in
4634 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4635 breakpoints on overloaded functions that are not members of any special
4636 classes.
4637
4638 @cindex set breakpoints on all functions
4639 The @code{rbreak} command can be used to set breakpoints in
4640 @strong{all} the functions in a program, like this:
4641
4642 @smallexample
4643 (@value{GDBP}) rbreak .
4644 @end smallexample
4645
4646 @item rbreak @var{file}:@var{regex}
4647 If @code{rbreak} is called with a filename qualification, it limits
4648 the search for functions matching the given regular expression to the
4649 specified @var{file}. This can be used, for example, to set breakpoints on
4650 every function in a given file:
4651
4652 @smallexample
4653 (@value{GDBP}) rbreak file.c:.
4654 @end smallexample
4655
4656 The colon separating the filename qualifier from the regex may
4657 optionally be surrounded by spaces.
4658
4659 @kindex info breakpoints
4660 @cindex @code{$_} and @code{info breakpoints}
4661 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4662 @itemx info break @r{[}@var{list}@dots{}@r{]}
4663 Print a table of all breakpoints, watchpoints, and catchpoints set and
4664 not deleted. Optional argument @var{n} means print information only
4665 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4666 For each breakpoint, following columns are printed:
4667
4668 @table @emph
4669 @item Breakpoint Numbers
4670 @item Type
4671 Breakpoint, watchpoint, or catchpoint.
4672 @item Disposition
4673 Whether the breakpoint is marked to be disabled or deleted when hit.
4674 @item Enabled or Disabled
4675 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4676 that are not enabled.
4677 @item Address
4678 Where the breakpoint is in your program, as a memory address. For a
4679 pending breakpoint whose address is not yet known, this field will
4680 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4681 library that has the symbol or line referred by breakpoint is loaded.
4682 See below for details. A breakpoint with several locations will
4683 have @samp{<MULTIPLE>} in this field---see below for details.
4684 @item What
4685 Where the breakpoint is in the source for your program, as a file and
4686 line number. For a pending breakpoint, the original string passed to
4687 the breakpoint command will be listed as it cannot be resolved until
4688 the appropriate shared library is loaded in the future.
4689 @end table
4690
4691 @noindent
4692 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4693 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4694 @value{GDBN} on the host's side. If it is ``target'', then the condition
4695 is evaluated by the target. The @code{info break} command shows
4696 the condition on the line following the affected breakpoint, together with
4697 its condition evaluation mode in between parentheses.
4698
4699 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4700 allowed to have a condition specified for it. The condition is not parsed for
4701 validity until a shared library is loaded that allows the pending
4702 breakpoint to resolve to a valid location.
4703
4704 @noindent
4705 @code{info break} with a breakpoint
4706 number @var{n} as argument lists only that breakpoint. The
4707 convenience variable @code{$_} and the default examining-address for
4708 the @code{x} command are set to the address of the last breakpoint
4709 listed (@pxref{Memory, ,Examining Memory}).
4710
4711 @noindent
4712 @code{info break} displays a count of the number of times the breakpoint
4713 has been hit. This is especially useful in conjunction with the
4714 @code{ignore} command. You can ignore a large number of breakpoint
4715 hits, look at the breakpoint info to see how many times the breakpoint
4716 was hit, and then run again, ignoring one less than that number. This
4717 will get you quickly to the last hit of that breakpoint.
4718
4719 @noindent
4720 For a breakpoints with an enable count (xref) greater than 1,
4721 @code{info break} also displays that count.
4722
4723 @end table
4724
4725 @value{GDBN} allows you to set any number of breakpoints at the same place in
4726 your program. There is nothing silly or meaningless about this. When
4727 the breakpoints are conditional, this is even useful
4728 (@pxref{Conditions, ,Break Conditions}).
4729
4730 @cindex multiple locations, breakpoints
4731 @cindex breakpoints, multiple locations
4732 It is possible that a single logical breakpoint is set at several code
4733 locations in your program. @xref{Location Specifications}, for
4734 examples.
4735
4736 A breakpoint with multiple code locations is displayed in the
4737 breakpoint table using several rows---one header row, followed by one
4738 row for each code location. The header row has @samp{<MULTIPLE>} in
4739 the address column. Each code location row contains the actual
4740 address, source file, source line and function of its code location.
4741 The number column for a code location is of the form
4742 @var{breakpoint-number}.@var{location-number}.
4743
4744 For example:
4745
4746 @smallexample
4747 Num Type Disp Enb Address What
4748 1 breakpoint keep y <MULTIPLE>
4749 stop only if i==1
4750 breakpoint already hit 1 time
4751 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4752 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4753 @end smallexample
4754
4755 You cannot delete the individual locations from a breakpoint. However,
4756 each location can be individually enabled or disabled by passing
4757 @var{breakpoint-number}.@var{location-number} as argument to the
4758 @code{enable} and @code{disable} commands. It's also possible to
4759 @code{enable} and @code{disable} a range of @var{location-number}
4760 locations using a @var{breakpoint-number} and two @var{location-number}s,
4761 in increasing order, separated by a hyphen, like
4762 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4763 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4764 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4765 all of the locations that belong to that breakpoint.
4766
4767 Locations that are enabled while their parent breakpoint is disabled
4768 won't trigger a break, and are denoted by @code{y-} in the @code{Enb}
4769 column. For example:
4770
4771 @smallexample
4772 (@value{GDBP}) info breakpoints
4773 Num Type Disp Enb Address What
4774 1 breakpoint keep n <MULTIPLE>
4775 1.1 y- 0x00000000000011b6 in ...
4776 1.2 y- 0x00000000000011c2 in ...
4777 1.3 n 0x00000000000011ce in ...
4778 @end smallexample
4779
4780 @cindex pending breakpoints
4781 It's quite common to have a breakpoint inside a shared library.
4782 Shared libraries can be loaded and unloaded explicitly,
4783 and possibly repeatedly, as the program is executed. To support
4784 this use case, @value{GDBN} updates breakpoint locations whenever
4785 any shared library is loaded or unloaded. Typically, you would
4786 set a breakpoint in a shared library at the beginning of your
4787 debugging session, when the library is not loaded, and when the
4788 symbols from the library are not available. When you try to set
4789 breakpoint, @value{GDBN} will ask you if you want to set
4790 a so called @dfn{pending breakpoint}---breakpoint whose address
4791 is not yet resolved.
4792
4793 After the program is run, whenever a new shared library is loaded,
4794 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4795 shared library contains the symbol or line referred to by some
4796 pending breakpoint, that breakpoint is resolved and becomes an
4797 ordinary breakpoint. When a library is unloaded, all breakpoints
4798 that refer to its symbols or source lines become pending again.
4799
4800 This logic works for breakpoints with multiple locations, too. For
4801 example, if you have a breakpoint in a C@t{++} template function, and
4802 a newly loaded shared library has an instantiation of that template,
4803 a new location is added to the list of locations for the breakpoint.
4804
4805 Except for having unresolved address, pending breakpoints do not
4806 differ from regular breakpoints. You can set conditions or commands,
4807 enable and disable them and perform other breakpoint operations.
4808
4809 @value{GDBN} provides some additional commands for controlling what
4810 happens when the @samp{break} command cannot resolve the location spec
4811 to any code location in your program (@pxref{Location
4812 Specifications}):
4813
4814 @kindex set breakpoint pending
4815 @kindex show breakpoint pending
4816 @table @code
4817 @item set breakpoint pending auto
4818 This is the default behavior. When @value{GDBN} cannot resolve the
4819 location spec, it queries you whether a pending breakpoint should be
4820 created.
4821
4822 @item set breakpoint pending on
4823 This indicates that when @value{GDBN} cannot resolve the location
4824 spec, it should create a pending breakpoint without confirmation.
4825
4826 @item set breakpoint pending off
4827 This indicates that pending breakpoints are not to be created. If
4828 @value{GDBN} cannot resolve the location spec, it aborts the
4829 breakpoint creation with an error. This setting does not affect any
4830 pending breakpoints previously created.
4831
4832 @item show breakpoint pending
4833 Show the current behavior setting for creating pending breakpoints.
4834 @end table
4835
4836 The settings above only affect the @code{break} command and its
4837 variants. Once a breakpoint is set, it will be automatically updated
4838 as shared libraries are loaded and unloaded.
4839
4840 @cindex automatic hardware breakpoints
4841 For some targets, @value{GDBN} can automatically decide if hardware or
4842 software breakpoints should be used, depending on whether the
4843 breakpoint address is read-only or read-write. This applies to
4844 breakpoints set with the @code{break} command as well as to internal
4845 breakpoints set by commands like @code{next} and @code{finish}. For
4846 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4847 breakpoints.
4848
4849 You can control this automatic behaviour with the following commands:
4850
4851 @kindex set breakpoint auto-hw
4852 @kindex show breakpoint auto-hw
4853 @table @code
4854 @item set breakpoint auto-hw on
4855 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4856 will try to use the target memory map to decide if software or hardware
4857 breakpoint must be used.
4858
4859 @item set breakpoint auto-hw off
4860 This indicates @value{GDBN} should not automatically select breakpoint
4861 type. If the target provides a memory map, @value{GDBN} will warn when
4862 trying to set software breakpoint at a read-only address.
4863 @end table
4864
4865 @value{GDBN} normally implements breakpoints by replacing the program code
4866 at the breakpoint address with a special instruction, which, when
4867 executed, given control to the debugger. By default, the program
4868 code is so modified only when the program is resumed. As soon as
4869 the program stops, @value{GDBN} restores the original instructions. This
4870 behaviour guards against leaving breakpoints inserted in the
4871 target should gdb abrubptly disconnect. However, with slow remote
4872 targets, inserting and removing breakpoint can reduce the performance.
4873 This behavior can be controlled with the following commands::
4874
4875 @kindex set breakpoint always-inserted
4876 @kindex show breakpoint always-inserted
4877 @table @code
4878 @item set breakpoint always-inserted off
4879 All breakpoints, including newly added by the user, are inserted in
4880 the target only when the target is resumed. All breakpoints are
4881 removed from the target when it stops. This is the default mode.
4882
4883 @item set breakpoint always-inserted on
4884 Causes all breakpoints to be inserted in the target at all times. If
4885 the user adds a new breakpoint, or changes an existing breakpoint, the
4886 breakpoints in the target are updated immediately. A breakpoint is
4887 removed from the target only when breakpoint itself is deleted.
4888 @end table
4889
4890 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4891 when a breakpoint breaks. If the condition is true, then the process being
4892 debugged stops, otherwise the process is resumed.
4893
4894 If the target supports evaluating conditions on its end, @value{GDBN} may
4895 download the breakpoint, together with its conditions, to it.
4896
4897 This feature can be controlled via the following commands:
4898
4899 @kindex set breakpoint condition-evaluation
4900 @kindex show breakpoint condition-evaluation
4901 @table @code
4902 @item set breakpoint condition-evaluation host
4903 This option commands @value{GDBN} to evaluate the breakpoint
4904 conditions on the host's side. Unconditional breakpoints are sent to
4905 the target which in turn receives the triggers and reports them back to GDB
4906 for condition evaluation. This is the standard evaluation mode.
4907
4908 @item set breakpoint condition-evaluation target
4909 This option commands @value{GDBN} to download breakpoint conditions
4910 to the target at the moment of their insertion. The target
4911 is responsible for evaluating the conditional expression and reporting
4912 breakpoint stop events back to @value{GDBN} whenever the condition
4913 is true. Due to limitations of target-side evaluation, some conditions
4914 cannot be evaluated there, e.g., conditions that depend on local data
4915 that is only known to the host. Examples include
4916 conditional expressions involving convenience variables, complex types
4917 that cannot be handled by the agent expression parser and expressions
4918 that are too long to be sent over to the target, specially when the
4919 target is a remote system. In these cases, the conditions will be
4920 evaluated by @value{GDBN}.
4921
4922 @item set breakpoint condition-evaluation auto
4923 This is the default mode. If the target supports evaluating breakpoint
4924 conditions on its end, @value{GDBN} will download breakpoint conditions to
4925 the target (limitations mentioned previously apply). If the target does
4926 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4927 to evaluating all these conditions on the host's side.
4928 @end table
4929
4930
4931 @cindex negative breakpoint numbers
4932 @cindex internal @value{GDBN} breakpoints
4933 @value{GDBN} itself sometimes sets breakpoints in your program for
4934 special purposes, such as proper handling of @code{longjmp} (in C
4935 programs). These internal breakpoints are assigned negative numbers,
4936 starting with @code{-1}; @samp{info breakpoints} does not display them.
4937 You can see these breakpoints with the @value{GDBN} maintenance command
4938 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4939
4940
4941 @node Set Watchpoints
4942 @subsection Setting Watchpoints
4943
4944 @cindex setting watchpoints
4945 You can use a watchpoint to stop execution whenever the value of an
4946 expression changes, without having to predict a particular place where
4947 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4948 The expression may be as simple as the value of a single variable, or
4949 as complex as many variables combined by operators. Examples include:
4950
4951 @itemize @bullet
4952 @item
4953 A reference to the value of a single variable.
4954
4955 @item
4956 An address cast to an appropriate data type. For example,
4957 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4958 address (assuming an @code{int} occupies 4 bytes).
4959
4960 @item
4961 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4962 expression can use any operators valid in the program's native
4963 language (@pxref{Languages}).
4964 @end itemize
4965
4966 You can set a watchpoint on an expression even if the expression can
4967 not be evaluated yet. For instance, you can set a watchpoint on
4968 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4969 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4970 the expression produces a valid value. If the expression becomes
4971 valid in some other way than changing a variable (e.g.@: if the memory
4972 pointed to by @samp{*global_ptr} becomes readable as the result of a
4973 @code{malloc} call), @value{GDBN} may not stop until the next time
4974 the expression changes.
4975
4976 @cindex software watchpoints
4977 @cindex hardware watchpoints
4978 Depending on your system, watchpoints may be implemented in software or
4979 hardware. @value{GDBN} does software watchpointing by single-stepping your
4980 program and testing the variable's value each time, which is hundreds of
4981 times slower than normal execution. (But this may still be worth it, to
4982 catch errors where you have no clue what part of your program is the
4983 culprit.)
4984
4985 On some systems, such as most PowerPC or x86-based targets,
4986 @value{GDBN} includes support for hardware watchpoints, which do not
4987 slow down the running of your program.
4988
4989 @table @code
4990 @kindex watch
4991 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]} @r{[}task @var{task-id}@r{]}
4992 Set a watchpoint for an expression. @value{GDBN} will break when the
4993 expression @var{expr} is written into by the program and its value
4994 changes. The simplest (and the most popular) use of this command is
4995 to watch the value of a single variable:
4996
4997 @smallexample
4998 (@value{GDBP}) watch foo
4999 @end smallexample
5000
5001 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
5002 argument, @value{GDBN} breaks only when the thread identified by
5003 @var{thread-id} changes the value of @var{expr}. If any other threads
5004 change the value of @var{expr}, @value{GDBN} will not break. Note
5005 that watchpoints restricted to a single thread in this way only work
5006 with Hardware Watchpoints.
5007
5008 Similarly, if the @code{task} argument is given, then the watchpoint
5009 will be specific to the indicated Ada task (@pxref{Ada Tasks}).
5010
5011 Ordinarily a watchpoint respects the scope of variables in @var{expr}
5012 (see below). The @code{-location} argument tells @value{GDBN} to
5013 instead watch the memory referred to by @var{expr}. In this case,
5014 @value{GDBN} will evaluate @var{expr}, take the address of the result,
5015 and watch the memory at that address. The type of the result is used
5016 to determine the size of the watched memory. If the expression's
5017 result does not have an address, then @value{GDBN} will print an
5018 error.
5019
5020 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
5021 of masked watchpoints, if the current architecture supports this
5022 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
5023 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
5024 to an address to watch. The mask specifies that some bits of an address
5025 (the bits which are reset in the mask) should be ignored when matching
5026 the address accessed by the inferior against the watchpoint address.
5027 Thus, a masked watchpoint watches many addresses simultaneously---those
5028 addresses whose unmasked bits are identical to the unmasked bits in the
5029 watchpoint address. The @code{mask} argument implies @code{-location}.
5030 Examples:
5031
5032 @smallexample
5033 (@value{GDBP}) watch foo mask 0xffff00ff
5034 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
5035 @end smallexample
5036
5037 @kindex rwatch
5038 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
5039 Set a watchpoint that will break when the value of @var{expr} is read
5040 by the program.
5041
5042 @kindex awatch
5043 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
5044 Set a watchpoint that will break when @var{expr} is either read from
5045 or written into by the program.
5046
5047 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
5048 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
5049 This command prints a list of watchpoints, using the same format as
5050 @code{info break} (@pxref{Set Breaks}).
5051 @end table
5052
5053 If you watch for a change in a numerically entered address you need to
5054 dereference it, as the address itself is just a constant number which will
5055 never change. @value{GDBN} refuses to create a watchpoint that watches
5056 a never-changing value:
5057
5058 @smallexample
5059 (@value{GDBP}) watch 0x600850
5060 Cannot watch constant value 0x600850.
5061 (@value{GDBP}) watch *(int *) 0x600850
5062 Watchpoint 1: *(int *) 6293584
5063 @end smallexample
5064
5065 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
5066 watchpoints execute very quickly, and the debugger reports a change in
5067 value at the exact instruction where the change occurs. If @value{GDBN}
5068 cannot set a hardware watchpoint, it sets a software watchpoint, which
5069 executes more slowly and reports the change in value at the next
5070 @emph{statement}, not the instruction, after the change occurs.
5071
5072 @cindex use only software watchpoints
5073 You can force @value{GDBN} to use only software watchpoints with the
5074 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
5075 zero, @value{GDBN} will never try to use hardware watchpoints, even if
5076 the underlying system supports them. (Note that hardware-assisted
5077 watchpoints that were set @emph{before} setting
5078 @code{can-use-hw-watchpoints} to zero will still use the hardware
5079 mechanism of watching expression values.)
5080
5081 @table @code
5082 @item set can-use-hw-watchpoints
5083 @kindex set can-use-hw-watchpoints
5084 Set whether or not to use hardware watchpoints.
5085
5086 @item show can-use-hw-watchpoints
5087 @kindex show can-use-hw-watchpoints
5088 Show the current mode of using hardware watchpoints.
5089 @end table
5090
5091 For remote targets, you can restrict the number of hardware
5092 watchpoints @value{GDBN} will use, see @ref{set remote
5093 hardware-breakpoint-limit}.
5094
5095 When you issue the @code{watch} command, @value{GDBN} reports
5096
5097 @smallexample
5098 Hardware watchpoint @var{num}: @var{expr}
5099 @end smallexample
5100
5101 @noindent
5102 if it was able to set a hardware watchpoint.
5103
5104 Currently, the @code{awatch} and @code{rwatch} commands can only set
5105 hardware watchpoints, because accesses to data that don't change the
5106 value of the watched expression cannot be detected without examining
5107 every instruction as it is being executed, and @value{GDBN} does not do
5108 that currently. If @value{GDBN} finds that it is unable to set a
5109 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
5110 will print a message like this:
5111
5112 @smallexample
5113 Expression cannot be implemented with read/access watchpoint.
5114 @end smallexample
5115
5116 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
5117 data type of the watched expression is wider than what a hardware
5118 watchpoint on the target machine can handle. For example, some systems
5119 can only watch regions that are up to 4 bytes wide; on such systems you
5120 cannot set hardware watchpoints for an expression that yields a
5121 double-precision floating-point number (which is typically 8 bytes
5122 wide). As a work-around, it might be possible to break the large region
5123 into a series of smaller ones and watch them with separate watchpoints.
5124
5125 If you set too many hardware watchpoints, @value{GDBN} might be unable
5126 to insert all of them when you resume the execution of your program.
5127 Since the precise number of active watchpoints is unknown until such
5128 time as the program is about to be resumed, @value{GDBN} might not be
5129 able to warn you about this when you set the watchpoints, and the
5130 warning will be printed only when the program is resumed:
5131
5132 @smallexample
5133 Hardware watchpoint @var{num}: Could not insert watchpoint
5134 @end smallexample
5135
5136 @noindent
5137 If this happens, delete or disable some of the watchpoints.
5138
5139 Watching complex expressions that reference many variables can also
5140 exhaust the resources available for hardware-assisted watchpoints.
5141 That's because @value{GDBN} needs to watch every variable in the
5142 expression with separately allocated resources.
5143
5144 If you call a function interactively using @code{print} or @code{call},
5145 any watchpoints you have set will be inactive until @value{GDBN} reaches another
5146 kind of breakpoint or the call completes.
5147
5148 @value{GDBN} automatically deletes watchpoints that watch local
5149 (automatic) variables, or expressions that involve such variables, when
5150 they go out of scope, that is, when the execution leaves the block in
5151 which these variables were defined. In particular, when the program
5152 being debugged terminates, @emph{all} local variables go out of scope,
5153 and so only watchpoints that watch global variables remain set. If you
5154 rerun the program, you will need to set all such watchpoints again. One
5155 way of doing that would be to set a code breakpoint at the entry to the
5156 @code{main} function and when it breaks, set all the watchpoints.
5157
5158 @cindex watchpoints and threads
5159 @cindex threads and watchpoints
5160 In multi-threaded programs, watchpoints will detect changes to the
5161 watched expression from every thread.
5162
5163 @quotation
5164 @emph{Warning:} In multi-threaded programs, software watchpoints
5165 have only limited usefulness. If @value{GDBN} creates a software
5166 watchpoint, it can only watch the value of an expression @emph{in a
5167 single thread}. If you are confident that the expression can only
5168 change due to the current thread's activity (and if you are also
5169 confident that no other thread can become current), then you can use
5170 software watchpoints as usual. However, @value{GDBN} may not notice
5171 when a non-current thread's activity changes the expression. (Hardware
5172 watchpoints, in contrast, watch an expression in all threads.)
5173 @end quotation
5174
5175 @xref{set remote hardware-watchpoint-limit}.
5176
5177 @node Set Catchpoints
5178 @subsection Setting Catchpoints
5179 @cindex catchpoints, setting
5180 @cindex exception handlers
5181 @cindex event handling
5182
5183 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5184 kinds of program events, such as C@t{++} exceptions or the loading of a
5185 shared library. Use the @code{catch} command to set a catchpoint.
5186
5187 @table @code
5188 @kindex catch
5189 @item catch @var{event}
5190 Stop when @var{event} occurs. The @var{event} can be any of the following:
5191
5192 @table @code
5193 @item throw @r{[}@var{regexp}@r{]}
5194 @itemx rethrow @r{[}@var{regexp}@r{]}
5195 @itemx catch @r{[}@var{regexp}@r{]}
5196 @kindex catch throw
5197 @kindex catch rethrow
5198 @kindex catch catch
5199 @cindex stop on C@t{++} exceptions
5200 The throwing, re-throwing, or catching of a C@t{++} exception.
5201
5202 If @var{regexp} is given, then only exceptions whose type matches the
5203 regular expression will be caught.
5204
5205 @vindex $_exception@r{, convenience variable}
5206 The convenience variable @code{$_exception} is available at an
5207 exception-related catchpoint, on some systems. This holds the
5208 exception being thrown.
5209
5210 There are currently some limitations to C@t{++} exception handling in
5211 @value{GDBN}:
5212
5213 @itemize @bullet
5214 @item
5215 The support for these commands is system-dependent. Currently, only
5216 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5217 supported.
5218
5219 @item
5220 The regular expression feature and the @code{$_exception} convenience
5221 variable rely on the presence of some SDT probes in @code{libstdc++}.
5222 If these probes are not present, then these features cannot be used.
5223 These probes were first available in the GCC 4.8 release, but whether
5224 or not they are available in your GCC also depends on how it was
5225 built.
5226
5227 @item
5228 The @code{$_exception} convenience variable is only valid at the
5229 instruction at which an exception-related catchpoint is set.
5230
5231 @item
5232 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5233 location in the system library which implements runtime exception
5234 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5235 (@pxref{Selection}) to get to your code.
5236
5237 @item
5238 If you call a function interactively, @value{GDBN} normally returns
5239 control to you when the function has finished executing. If the call
5240 raises an exception, however, the call may bypass the mechanism that
5241 returns control to you and cause your program either to abort or to
5242 simply continue running until it hits a breakpoint, catches a signal
5243 that @value{GDBN} is listening for, or exits. This is the case even if
5244 you set a catchpoint for the exception; catchpoints on exceptions are
5245 disabled within interactive calls. @xref{Calling}, for information on
5246 controlling this with @code{set unwind-on-terminating-exception}.
5247
5248 @item
5249 You cannot raise an exception interactively.
5250
5251 @item
5252 You cannot install an exception handler interactively.
5253 @end itemize
5254
5255 @item exception @r{[}@var{name}@r{]}
5256 @kindex catch exception
5257 @cindex Ada exception catching
5258 @cindex catch Ada exceptions
5259 An Ada exception being raised. If an exception name is specified
5260 at the end of the command (eg @code{catch exception Program_Error}),
5261 the debugger will stop only when this specific exception is raised.
5262 Otherwise, the debugger stops execution when any Ada exception is raised.
5263
5264 When inserting an exception catchpoint on a user-defined exception whose
5265 name is identical to one of the exceptions defined by the language, the
5266 fully qualified name must be used as the exception name. Otherwise,
5267 @value{GDBN} will assume that it should stop on the pre-defined exception
5268 rather than the user-defined one. For instance, assuming an exception
5269 called @code{Constraint_Error} is defined in package @code{Pck}, then
5270 the command to use to catch such exceptions is @kbd{catch exception
5271 Pck.Constraint_Error}.
5272
5273 @vindex $_ada_exception@r{, convenience variable}
5274 The convenience variable @code{$_ada_exception} holds the address of
5275 the exception being thrown. This can be useful when setting a
5276 condition for such a catchpoint.
5277
5278 @item exception unhandled
5279 @kindex catch exception unhandled
5280 An exception that was raised but is not handled by the program. The
5281 convenience variable @code{$_ada_exception} is set as for @code{catch
5282 exception}.
5283
5284 @item handlers @r{[}@var{name}@r{]}
5285 @kindex catch handlers
5286 @cindex Ada exception handlers catching
5287 @cindex catch Ada exceptions when handled
5288 An Ada exception being handled. If an exception name is
5289 specified at the end of the command
5290 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5291 only when this specific exception is handled.
5292 Otherwise, the debugger stops execution when any Ada exception is handled.
5293
5294 When inserting a handlers catchpoint on a user-defined
5295 exception whose name is identical to one of the exceptions
5296 defined by the language, the fully qualified name must be used
5297 as the exception name. Otherwise, @value{GDBN} will assume that it
5298 should stop on the pre-defined exception rather than the
5299 user-defined one. For instance, assuming an exception called
5300 @code{Constraint_Error} is defined in package @code{Pck}, then the
5301 command to use to catch such exceptions handling is
5302 @kbd{catch handlers Pck.Constraint_Error}.
5303
5304 The convenience variable @code{$_ada_exception} is set as for
5305 @code{catch exception}.
5306
5307 @item assert
5308 @kindex catch assert
5309 A failed Ada assertion. Note that the convenience variable
5310 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5311
5312 @item exec
5313 @kindex catch exec
5314 @cindex break on fork/exec
5315 A call to @code{exec}.
5316
5317 @anchor{catch syscall}
5318 @item syscall
5319 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5320 @kindex catch syscall
5321 @cindex break on a system call.
5322 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5323 syscall is a mechanism for application programs to request a service
5324 from the operating system (OS) or one of the OS system services.
5325 @value{GDBN} can catch some or all of the syscalls issued by the
5326 debuggee, and show the related information for each syscall. If no
5327 argument is specified, calls to and returns from all system calls
5328 will be caught.
5329
5330 @var{name} can be any system call name that is valid for the
5331 underlying OS. Just what syscalls are valid depends on the OS. On
5332 GNU and Unix systems, you can find the full list of valid syscall
5333 names on @file{/usr/include/asm/unistd.h}.
5334
5335 @c For MS-Windows, the syscall names and the corresponding numbers
5336 @c can be found, e.g., on this URL:
5337 @c http://www.metasploit.com/users/opcode/syscalls.html
5338 @c but we don't support Windows syscalls yet.
5339
5340 Normally, @value{GDBN} knows in advance which syscalls are valid for
5341 each OS, so you can use the @value{GDBN} command-line completion
5342 facilities (@pxref{Completion,, command completion}) to list the
5343 available choices.
5344
5345 You may also specify the system call numerically. A syscall's
5346 number is the value passed to the OS's syscall dispatcher to
5347 identify the requested service. When you specify the syscall by its
5348 name, @value{GDBN} uses its database of syscalls to convert the name
5349 into the corresponding numeric code, but using the number directly
5350 may be useful if @value{GDBN}'s database does not have the complete
5351 list of syscalls on your system (e.g., because @value{GDBN} lags
5352 behind the OS upgrades).
5353
5354 You may specify a group of related syscalls to be caught at once using
5355 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5356 instance, on some platforms @value{GDBN} allows you to catch all
5357 network related syscalls, by passing the argument @code{group:network}
5358 to @code{catch syscall}. Note that not all syscall groups are
5359 available in every system. You can use the command completion
5360 facilities (@pxref{Completion,, command completion}) to list the
5361 syscall groups available on your environment.
5362
5363 The example below illustrates how this command works if you don't provide
5364 arguments to it:
5365
5366 @smallexample
5367 (@value{GDBP}) catch syscall
5368 Catchpoint 1 (syscall)
5369 (@value{GDBP}) r
5370 Starting program: /tmp/catch-syscall
5371
5372 Catchpoint 1 (call to syscall 'close'), \
5373 0xffffe424 in __kernel_vsyscall ()
5374 (@value{GDBP}) c
5375 Continuing.
5376
5377 Catchpoint 1 (returned from syscall 'close'), \
5378 0xffffe424 in __kernel_vsyscall ()
5379 (@value{GDBP})
5380 @end smallexample
5381
5382 Here is an example of catching a system call by name:
5383
5384 @smallexample
5385 (@value{GDBP}) catch syscall chroot
5386 Catchpoint 1 (syscall 'chroot' [61])
5387 (@value{GDBP}) r
5388 Starting program: /tmp/catch-syscall
5389
5390 Catchpoint 1 (call to syscall 'chroot'), \
5391 0xffffe424 in __kernel_vsyscall ()
5392 (@value{GDBP}) c
5393 Continuing.
5394
5395 Catchpoint 1 (returned from syscall 'chroot'), \
5396 0xffffe424 in __kernel_vsyscall ()
5397 (@value{GDBP})
5398 @end smallexample
5399
5400 An example of specifying a system call numerically. In the case
5401 below, the syscall number has a corresponding entry in the XML
5402 file, so @value{GDBN} finds its name and prints it:
5403
5404 @smallexample
5405 (@value{GDBP}) catch syscall 252
5406 Catchpoint 1 (syscall(s) 'exit_group')
5407 (@value{GDBP}) r
5408 Starting program: /tmp/catch-syscall
5409
5410 Catchpoint 1 (call to syscall 'exit_group'), \
5411 0xffffe424 in __kernel_vsyscall ()
5412 (@value{GDBP}) c
5413 Continuing.
5414
5415 Program exited normally.
5416 (@value{GDBP})
5417 @end smallexample
5418
5419 Here is an example of catching a syscall group:
5420
5421 @smallexample
5422 (@value{GDBP}) catch syscall group:process
5423 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5424 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5425 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5426 (@value{GDBP}) r
5427 Starting program: /tmp/catch-syscall
5428
5429 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5430 from /lib64/ld-linux-x86-64.so.2
5431
5432 (@value{GDBP}) c
5433 Continuing.
5434 @end smallexample
5435
5436 However, there can be situations when there is no corresponding name
5437 in XML file for that syscall number. In this case, @value{GDBN} prints
5438 a warning message saying that it was not able to find the syscall name,
5439 but the catchpoint will be set anyway. See the example below:
5440
5441 @smallexample
5442 (@value{GDBP}) catch syscall 764
5443 warning: The number '764' does not represent a known syscall.
5444 Catchpoint 2 (syscall 764)
5445 (@value{GDBP})
5446 @end smallexample
5447
5448 If you configure @value{GDBN} using the @samp{--without-expat} option,
5449 it will not be able to display syscall names. Also, if your
5450 architecture does not have an XML file describing its system calls,
5451 you will not be able to see the syscall names. It is important to
5452 notice that these two features are used for accessing the syscall
5453 name database. In either case, you will see a warning like this:
5454
5455 @smallexample
5456 (@value{GDBP}) catch syscall
5457 warning: Could not open "syscalls/i386-linux.xml"
5458 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5459 GDB will not be able to display syscall names.
5460 Catchpoint 1 (syscall)
5461 (@value{GDBP})
5462 @end smallexample
5463
5464 Of course, the file name will change depending on your architecture and system.
5465
5466 Still using the example above, you can also try to catch a syscall by its
5467 number. In this case, you would see something like:
5468
5469 @smallexample
5470 (@value{GDBP}) catch syscall 252
5471 Catchpoint 1 (syscall(s) 252)
5472 @end smallexample
5473
5474 Again, in this case @value{GDBN} would not be able to display syscall's names.
5475
5476 @item fork
5477 @kindex catch fork
5478 A call to @code{fork}.
5479
5480 @item vfork
5481 @kindex catch vfork
5482 A call to @code{vfork}.
5483
5484 @item load @r{[}@var{regexp}@r{]}
5485 @itemx unload @r{[}@var{regexp}@r{]}
5486 @kindex catch load
5487 @kindex catch unload
5488 The loading or unloading of a shared library. If @var{regexp} is
5489 given, then the catchpoint will stop only if the regular expression
5490 matches one of the affected libraries.
5491
5492 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5493 @kindex catch signal
5494 The delivery of a signal.
5495
5496 With no arguments, this catchpoint will catch any signal that is not
5497 used internally by @value{GDBN}, specifically, all signals except
5498 @samp{SIGTRAP} and @samp{SIGINT}.
5499
5500 With the argument @samp{all}, all signals, including those used by
5501 @value{GDBN}, will be caught. This argument cannot be used with other
5502 signal names.
5503
5504 Otherwise, the arguments are a list of signal names as given to
5505 @code{handle} (@pxref{Signals}). Only signals specified in this list
5506 will be caught.
5507
5508 One reason that @code{catch signal} can be more useful than
5509 @code{handle} is that you can attach commands and conditions to the
5510 catchpoint.
5511
5512 When a signal is caught by a catchpoint, the signal's @code{stop} and
5513 @code{print} settings, as specified by @code{handle}, are ignored.
5514 However, whether the signal is still delivered to the inferior depends
5515 on the @code{pass} setting; this can be changed in the catchpoint's
5516 commands.
5517
5518 @end table
5519
5520 @item tcatch @var{event}
5521 @kindex tcatch
5522 Set a catchpoint that is enabled only for one stop. The catchpoint is
5523 automatically deleted after the first time the event is caught.
5524
5525 @end table
5526
5527 Use the @code{info break} command to list the current catchpoints.
5528
5529
5530 @node Delete Breaks
5531 @subsection Deleting Breakpoints
5532
5533 @cindex clearing breakpoints, watchpoints, catchpoints
5534 @cindex deleting breakpoints, watchpoints, catchpoints
5535 It is often necessary to eliminate a breakpoint, watchpoint, or
5536 catchpoint once it has done its job and you no longer want your program
5537 to stop there. This is called @dfn{deleting} the breakpoint. A
5538 breakpoint that has been deleted no longer exists; it is forgotten.
5539
5540 With the @code{clear} command you can delete breakpoints according to
5541 where they are in your program. With the @code{delete} command you can
5542 delete individual breakpoints, watchpoints, or catchpoints by specifying
5543 their breakpoint numbers.
5544
5545 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5546 automatically ignores breakpoints on the first instruction to be executed
5547 when you continue execution without changing the execution address.
5548
5549 @table @code
5550 @kindex clear
5551 @item clear
5552 Delete any breakpoints at the next instruction to be executed in the
5553 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5554 the innermost frame is selected, this is a good way to delete a
5555 breakpoint where your program just stopped.
5556
5557 @item clear @var{locspec}
5558 Delete any breakpoint with a code location that corresponds to
5559 @var{locspec}. @xref{Location Specifications}, for the various forms
5560 of @var{locspec}. Which code locations correspond to @var{locspec}
5561 depends on the form used in the location specification @var{locspec}:
5562
5563 @table @code
5564 @item @var{linenum}
5565 @itemx @var{filename}:@var{linenum}
5566 @itemx -line @var{linenum}
5567 @itemx -source @var{filename} -line @var{linenum}
5568 If @var{locspec} specifies a line number, with or without a file name,
5569 the command deletes any breakpoint with a code location that is at or
5570 within the specified line @var{linenum} in files that match the
5571 specified @var{filename}. If @var{filename} is omitted, it defaults
5572 to the current source file.
5573
5574 @item *@var{address}
5575 If @var{locspec} specifies an address, the command deletes any
5576 breakpoint with a code location that is at the given @var{address}.
5577
5578 @item @var{function}
5579 @itemx -function @var{function}
5580 If @var{locspec} specifies a function, the command deletes any
5581 breakpoint with a code location that is at the entry to any function
5582 whose name matches @var{function}.
5583 @end table
5584
5585 Ambiguity in names of files and functions can be resolved as described
5586 in @ref{Location Specifications}.
5587
5588 @cindex delete breakpoints
5589 @kindex delete
5590 @kindex d @r{(@code{delete})}
5591 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5592 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5593 list specified as argument. If no argument is specified, delete all
5594 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5595 confirm off}). You can abbreviate this command as @code{d}.
5596 @end table
5597
5598 @node Disabling
5599 @subsection Disabling Breakpoints
5600
5601 @cindex enable/disable a breakpoint
5602 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5603 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5604 it had been deleted, but remembers the information on the breakpoint so
5605 that you can @dfn{enable} it again later.
5606
5607 You disable and enable breakpoints, watchpoints, and catchpoints with
5608 the @code{enable} and @code{disable} commands, optionally specifying
5609 one or more breakpoint numbers as arguments. Use @code{info break} to
5610 print a list of all breakpoints, watchpoints, and catchpoints if you
5611 do not know which numbers to use.
5612
5613 Disabling and enabling a breakpoint that has multiple locations
5614 affects all of its locations.
5615
5616 A breakpoint, watchpoint, or catchpoint can have any of several
5617 different states of enablement:
5618
5619 @itemize @bullet
5620 @item
5621 Enabled. The breakpoint stops your program. A breakpoint set
5622 with the @code{break} command starts out in this state.
5623 @item
5624 Disabled. The breakpoint has no effect on your program.
5625 @item
5626 Enabled once. The breakpoint stops your program, but then becomes
5627 disabled.
5628 @item
5629 Enabled for a count. The breakpoint stops your program for the next
5630 N times, then becomes disabled.
5631 @item
5632 Enabled for deletion. The breakpoint stops your program, but
5633 immediately after it does so it is deleted permanently. A breakpoint
5634 set with the @code{tbreak} command starts out in this state.
5635 @end itemize
5636
5637 You can use the following commands to enable or disable breakpoints,
5638 watchpoints, and catchpoints:
5639
5640 @table @code
5641 @kindex disable
5642 @kindex dis @r{(@code{disable})}
5643 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5644 Disable the specified breakpoints---or all breakpoints, if none are
5645 listed. A disabled breakpoint has no effect but is not forgotten. All
5646 options such as ignore-counts, conditions and commands are remembered in
5647 case the breakpoint is enabled again later. You may abbreviate
5648 @code{disable} as @code{dis}.
5649
5650 @kindex enable
5651 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5652 Enable the specified breakpoints (or all defined breakpoints). They
5653 become effective once again in stopping your program.
5654
5655 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5656 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5657 of these breakpoints immediately after stopping your program.
5658
5659 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5660 Enable the specified breakpoints temporarily. @value{GDBN} records
5661 @var{count} with each of the specified breakpoints, and decrements a
5662 breakpoint's count when it is hit. When any count reaches 0,
5663 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5664 count (@pxref{Conditions, ,Break Conditions}), that will be
5665 decremented to 0 before @var{count} is affected.
5666
5667 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5668 Enable the specified breakpoints to work once, then die. @value{GDBN}
5669 deletes any of these breakpoints as soon as your program stops there.
5670 Breakpoints set by the @code{tbreak} command start out in this state.
5671 @end table
5672
5673 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5674 @c confusing: tbreak is also initially enabled.
5675 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5676 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5677 subsequently, they become disabled or enabled only when you use one of
5678 the commands above. (The command @code{until} can set and delete a
5679 breakpoint of its own, but it does not change the state of your other
5680 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5681 Stepping}.)
5682
5683 @node Conditions
5684 @subsection Break Conditions
5685 @cindex conditional breakpoints
5686 @cindex breakpoint conditions
5687
5688 @c FIXME what is scope of break condition expr? Context where wanted?
5689 @c in particular for a watchpoint?
5690 The simplest sort of breakpoint breaks every time your program reaches a
5691 specified place. You can also specify a @dfn{condition} for a
5692 breakpoint. A condition is just a Boolean expression in your
5693 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5694 a condition evaluates the expression each time your program reaches it,
5695 and your program stops only if the condition is @emph{true}.
5696
5697 This is the converse of using assertions for program validation; in that
5698 situation, you want to stop when the assertion is violated---that is,
5699 when the condition is false. In C, if you want to test an assertion expressed
5700 by the condition @var{assert}, you should set the condition
5701 @samp{! @var{assert}} on the appropriate breakpoint.
5702
5703 Conditions are also accepted for watchpoints; you may not need them,
5704 since a watchpoint is inspecting the value of an expression anyhow---but
5705 it might be simpler, say, to just set a watchpoint on a variable name,
5706 and specify a condition that tests whether the new value is an interesting
5707 one.
5708
5709 Break conditions can have side effects, and may even call functions in
5710 your program. This can be useful, for example, to activate functions
5711 that log program progress, or to use your own print functions to
5712 format special data structures. The effects are completely predictable
5713 unless there is another enabled breakpoint at the same address. (In
5714 that case, @value{GDBN} might see the other breakpoint first and stop your
5715 program without checking the condition of this one.) Note that
5716 breakpoint commands are usually more convenient and flexible than break
5717 conditions for the
5718 purpose of performing side effects when a breakpoint is reached
5719 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5720
5721 Breakpoint conditions can also be evaluated on the target's side if
5722 the target supports it. Instead of evaluating the conditions locally,
5723 @value{GDBN} encodes the expression into an agent expression
5724 (@pxref{Agent Expressions}) suitable for execution on the target,
5725 independently of @value{GDBN}. Global variables become raw memory
5726 locations, locals become stack accesses, and so forth.
5727
5728 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5729 when its condition evaluates to true. This mechanism may provide faster
5730 response times depending on the performance characteristics of the target
5731 since it does not need to keep @value{GDBN} informed about
5732 every breakpoint trigger, even those with false conditions.
5733
5734 Break conditions can be specified when a breakpoint is set, by using
5735 @samp{if} in the arguments to the @code{break} command. @xref{Set
5736 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5737 with the @code{condition} command.
5738
5739 You can also use the @code{if} keyword with the @code{watch} command.
5740 The @code{catch} command does not recognize the @code{if} keyword;
5741 @code{condition} is the only way to impose a further condition on a
5742 catchpoint.
5743
5744 @table @code
5745 @kindex condition
5746 @item condition @var{bnum} @var{expression}
5747 Specify @var{expression} as the break condition for breakpoint,
5748 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5749 breakpoint @var{bnum} stops your program only if the value of
5750 @var{expression} is true (nonzero, in C). When you use
5751 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5752 syntactic correctness, and to determine whether symbols in it have
5753 referents in the context of your breakpoint. If @var{expression} uses
5754 symbols not referenced in the context of the breakpoint, @value{GDBN}
5755 prints an error message:
5756
5757 @smallexample
5758 No symbol "foo" in current context.
5759 @end smallexample
5760
5761 @noindent
5762 @value{GDBN} does
5763 not actually evaluate @var{expression} at the time the @code{condition}
5764 command (or a command that sets a breakpoint with a condition, like
5765 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5766
5767 @item condition -force @var{bnum} @var{expression}
5768 When the @code{-force} flag is used, define the condition even if
5769 @var{expression} is invalid at all the current locations of breakpoint
5770 @var{bnum}. This is similar to the @code{-force-condition} option
5771 of the @code{break} command.
5772
5773 @item condition @var{bnum}
5774 Remove the condition from breakpoint number @var{bnum}. It becomes
5775 an ordinary unconditional breakpoint.
5776 @end table
5777
5778 @cindex ignore count (of breakpoint)
5779 A special case of a breakpoint condition is to stop only when the
5780 breakpoint has been reached a certain number of times. This is so
5781 useful that there is a special way to do it, using the @dfn{ignore
5782 count} of the breakpoint. Every breakpoint has an ignore count, which
5783 is an integer. Most of the time, the ignore count is zero, and
5784 therefore has no effect. But if your program reaches a breakpoint whose
5785 ignore count is positive, then instead of stopping, it just decrements
5786 the ignore count by one and continues. As a result, if the ignore count
5787 value is @var{n}, the breakpoint does not stop the next @var{n} times
5788 your program reaches it.
5789
5790 @table @code
5791 @kindex ignore
5792 @item ignore @var{bnum} @var{count}
5793 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5794 The next @var{count} times the breakpoint is reached, your program's
5795 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5796 takes no action.
5797
5798 To make the breakpoint stop the next time it is reached, specify
5799 a count of zero.
5800
5801 When you use @code{continue} to resume execution of your program from a
5802 breakpoint, you can specify an ignore count directly as an argument to
5803 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5804 Stepping,,Continuing and Stepping}.
5805
5806 If a breakpoint has a positive ignore count and a condition, the
5807 condition is not checked. Once the ignore count reaches zero,
5808 @value{GDBN} resumes checking the condition.
5809
5810 You could achieve the effect of the ignore count with a condition such
5811 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5812 is decremented each time. @xref{Convenience Vars, ,Convenience
5813 Variables}.
5814 @end table
5815
5816 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5817
5818
5819 @node Break Commands
5820 @subsection Breakpoint Command Lists
5821
5822 @cindex breakpoint commands
5823 You can give any breakpoint (or watchpoint or catchpoint) a series of
5824 commands to execute when your program stops due to that breakpoint. For
5825 example, you might want to print the values of certain expressions, or
5826 enable other breakpoints.
5827
5828 @table @code
5829 @kindex commands
5830 @kindex end@r{ (breakpoint commands)}
5831 @item commands @r{[}@var{list}@dots{}@r{]}
5832 @itemx @dots{} @var{command-list} @dots{}
5833 @itemx end
5834 Specify a list of commands for the given breakpoints. The commands
5835 themselves appear on the following lines. Type a line containing just
5836 @code{end} to terminate the commands.
5837
5838 To remove all commands from a breakpoint, type @code{commands} and
5839 follow it immediately with @code{end}; that is, give no commands.
5840
5841 With no argument, @code{commands} refers to the last breakpoint,
5842 watchpoint, or catchpoint set (not to the breakpoint most recently
5843 encountered). If the most recent breakpoints were set with a single
5844 command, then the @code{commands} will apply to all the breakpoints
5845 set by that command. This applies to breakpoints set by
5846 @code{rbreak}, and also applies when a single @code{break} command
5847 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5848 Expressions}).
5849 @end table
5850
5851 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5852 disabled within a @var{command-list}.
5853
5854 Inside a command list, you can use the command
5855 @kbd{disable $_hit_bpnum} to disable the encountered breakpoint.
5856
5857 If your breakpoint has several code locations, the command
5858 @kbd{disable $_hit_bpnum.$_hit_locno} will disable the specific breakpoint
5859 code location encountered. If the breakpoint has only one location,
5860 this command will disable the encountered breakpoint.
5861
5862 You can use breakpoint commands to start your program up again. Simply
5863 use the @code{continue} command, or @code{step}, or any other command
5864 that resumes execution.
5865
5866 Any other commands in the command list, after a command that resumes
5867 execution, are ignored. This is because any time you resume execution
5868 (even with a simple @code{next} or @code{step}), you may encounter
5869 another breakpoint---which could have its own command list, leading to
5870 ambiguities about which list to execute.
5871
5872 @kindex silent
5873 If the first command you specify in a command list is @code{silent}, the
5874 usual message about stopping at a breakpoint is not printed. This may
5875 be desirable for breakpoints that are to print a specific message and
5876 then continue. If none of the remaining commands print anything, you
5877 see no sign that the breakpoint was reached. @code{silent} is
5878 meaningful only at the beginning of a breakpoint command list.
5879
5880 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5881 print precisely controlled output, and are often useful in silent
5882 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5883
5884 For example, here is how you could use breakpoint commands to print the
5885 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5886
5887 @smallexample
5888 break foo if x>0
5889 commands
5890 silent
5891 printf "x is %d\n",x
5892 cont
5893 end
5894 @end smallexample
5895
5896 One application for breakpoint commands is to compensate for one bug so
5897 you can test for another. Put a breakpoint just after the erroneous line
5898 of code, give it a condition to detect the case in which something
5899 erroneous has been done, and give it commands to assign correct values
5900 to any variables that need them. End with the @code{continue} command
5901 so that your program does not stop, and start with the @code{silent}
5902 command so that no output is produced. Here is an example:
5903
5904 @smallexample
5905 break 403
5906 commands
5907 silent
5908 set x = y + 4
5909 cont
5910 end
5911 @end smallexample
5912
5913 @node Dynamic Printf
5914 @subsection Dynamic Printf
5915
5916 @cindex dynamic printf
5917 @cindex dprintf
5918 The dynamic printf command @code{dprintf} combines a breakpoint with
5919 formatted printing of your program's data to give you the effect of
5920 inserting @code{printf} calls into your program on-the-fly, without
5921 having to recompile it.
5922
5923 In its most basic form, the output goes to the GDB console. However,
5924 you can set the variable @code{dprintf-style} for alternate handling.
5925 For instance, you can ask to format the output by calling your
5926 program's @code{printf} function. This has the advantage that the
5927 characters go to the program's output device, so they can recorded in
5928 redirects to files and so forth.
5929
5930 If you are doing remote debugging with a stub or agent, you can also
5931 ask to have the printf handled by the remote agent. In addition to
5932 ensuring that the output goes to the remote program's device along
5933 with any other output the program might produce, you can also ask that
5934 the dprintf remain active even after disconnecting from the remote
5935 target. Using the stub/agent is also more efficient, as it can do
5936 everything without needing to communicate with @value{GDBN}.
5937
5938 @table @code
5939 @kindex dprintf
5940 @item dprintf @var{locspec},@var{template},@var{expression}[,@var{expression}@dots{}]
5941 Whenever execution reaches a code location that results from resolving
5942 @var{locspec}, print the values of one or more @var{expressions} under
5943 the control of the string @var{template}. To print several values,
5944 separate them with commas.
5945
5946 @item set dprintf-style @var{style}
5947 Set the dprintf output to be handled in one of several different
5948 styles enumerated below. A change of style affects all existing
5949 dynamic printfs immediately. (If you need individual control over the
5950 print commands, simply define normal breakpoints with
5951 explicitly-supplied command lists.)
5952
5953 @table @code
5954 @item gdb
5955 @kindex dprintf-style gdb
5956 Handle the output using the @value{GDBN} @code{printf} command.
5957
5958 @item call
5959 @kindex dprintf-style call
5960 Handle the output by calling a function in your program (normally
5961 @code{printf}).
5962
5963 @item agent
5964 @kindex dprintf-style agent
5965 Have the remote debugging agent (such as @code{gdbserver}) handle
5966 the output itself. This style is only available for agents that
5967 support running commands on the target.
5968 @end table
5969
5970 @item set dprintf-function @var{function}
5971 Set the function to call if the dprintf style is @code{call}. By
5972 default its value is @code{printf}. You may set it to any expression.
5973 that @value{GDBN} can evaluate to a function, as per the @code{call}
5974 command.
5975
5976 @item set dprintf-channel @var{channel}
5977 Set a ``channel'' for dprintf. If set to a non-empty value,
5978 @value{GDBN} will evaluate it as an expression and pass the result as
5979 a first argument to the @code{dprintf-function}, in the manner of
5980 @code{fprintf} and similar functions. Otherwise, the dprintf format
5981 string will be the first argument, in the manner of @code{printf}.
5982
5983 As an example, if you wanted @code{dprintf} output to go to a logfile
5984 that is a standard I/O stream assigned to the variable @code{mylog},
5985 you could do the following:
5986
5987 @example
5988 (@value{GDBP}) set dprintf-style call
5989 (@value{GDBP}) set dprintf-function fprintf
5990 (@value{GDBP}) set dprintf-channel mylog
5991 (@value{GDBP}) dprintf 25,"at line 25, glob=%d\n",glob
5992 Dprintf 1 at 0x123456: file main.c, line 25.
5993 (@value{GDBP}) info break
5994 1 dprintf keep y 0x00123456 in main at main.c:25
5995 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5996 continue
5997 (@value{GDBP})
5998 @end example
5999
6000 Note that the @code{info break} displays the dynamic printf commands
6001 as normal breakpoint commands; you can thus easily see the effect of
6002 the variable settings.
6003
6004 @item set disconnected-dprintf on
6005 @itemx set disconnected-dprintf off
6006 @kindex set disconnected-dprintf
6007 Choose whether @code{dprintf} commands should continue to run if
6008 @value{GDBN} has disconnected from the target. This only applies
6009 if the @code{dprintf-style} is @code{agent}.
6010
6011 @item show disconnected-dprintf off
6012 @kindex show disconnected-dprintf
6013 Show the current choice for disconnected @code{dprintf}.
6014
6015 @end table
6016
6017 @value{GDBN} does not check the validity of function and channel,
6018 relying on you to supply values that are meaningful for the contexts
6019 in which they are being used. For instance, the function and channel
6020 may be the values of local variables, but if that is the case, then
6021 all enabled dynamic prints must be at locations within the scope of
6022 those locals. If evaluation fails, @value{GDBN} will report an error.
6023
6024 @node Save Breakpoints
6025 @subsection How to save breakpoints to a file
6026
6027 To save breakpoint definitions to a file use the @w{@code{save
6028 breakpoints}} command.
6029
6030 @table @code
6031 @kindex save breakpoints
6032 @cindex save breakpoints to a file for future sessions
6033 @item save breakpoints [@var{filename}]
6034 This command saves all current breakpoint definitions together with
6035 their commands and ignore counts, into a file @file{@var{filename}}
6036 suitable for use in a later debugging session. This includes all
6037 types of breakpoints (breakpoints, watchpoints, catchpoints,
6038 tracepoints). To read the saved breakpoint definitions, use the
6039 @code{source} command (@pxref{Command Files}). Note that watchpoints
6040 with expressions involving local variables may fail to be recreated
6041 because it may not be possible to access the context where the
6042 watchpoint is valid anymore. Because the saved breakpoint definitions
6043 are simply a sequence of @value{GDBN} commands that recreate the
6044 breakpoints, you can edit the file in your favorite editing program,
6045 and remove the breakpoint definitions you're not interested in, or
6046 that can no longer be recreated.
6047 @end table
6048
6049 @node Static Probe Points
6050 @subsection Static Probe Points
6051
6052 @cindex static probe point, SystemTap
6053 @cindex static probe point, DTrace
6054 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
6055 for Statically Defined Tracing, and the probes are designed to have a tiny
6056 runtime code and data footprint, and no dynamic relocations.
6057
6058 Currently, the following types of probes are supported on
6059 ELF-compatible systems:
6060
6061 @itemize @bullet
6062
6063 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
6064 @acronym{SDT} probes@footnote{See
6065 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
6066 for more information on how to add @code{SystemTap} @acronym{SDT}
6067 probes in your applications.}. @code{SystemTap} probes are usable
6068 from assembly, C and C@t{++} languages@footnote{See
6069 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
6070 for a good reference on how the @acronym{SDT} probes are implemented.}.
6071
6072 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
6073 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
6074 C@t{++} languages.
6075 @end itemize
6076
6077 @cindex semaphores on static probe points
6078 Some @code{SystemTap} probes have an associated semaphore variable;
6079 for instance, this happens automatically if you defined your probe
6080 using a DTrace-style @file{.d} file. If your probe has a semaphore,
6081 @value{GDBN} will automatically enable it when you specify a
6082 breakpoint using the @samp{-probe-stap} notation. But, if you put a
6083 breakpoint at a probe's location by some other method (e.g.,
6084 @code{break file:line}), then @value{GDBN} will not automatically set
6085 the semaphore. @code{DTrace} probes do not support semaphores.
6086
6087 You can examine the available static static probes using @code{info
6088 probes}, with optional arguments:
6089
6090 @table @code
6091 @kindex info probes
6092 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6093 If given, @var{type} is either @code{stap} for listing
6094 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
6095 probes. If omitted all probes are listed regardless of their types.
6096
6097 If given, @var{provider} is a regular expression used to match against provider
6098 names when selecting which probes to list. If omitted, probes by all
6099 probes from all providers are listed.
6100
6101 If given, @var{name} is a regular expression to match against probe names
6102 when selecting which probes to list. If omitted, probe names are not
6103 considered when deciding whether to display them.
6104
6105 If given, @var{objfile} is a regular expression used to select which
6106 object files (executable or shared libraries) to examine. If not
6107 given, all object files are considered.
6108
6109 @item info probes all
6110 List the available static probes, from all types.
6111 @end table
6112
6113 @cindex enabling and disabling probes
6114 Some probe points can be enabled and/or disabled. The effect of
6115 enabling or disabling a probe depends on the type of probe being
6116 handled. Some @code{DTrace} probes can be enabled or
6117 disabled, but @code{SystemTap} probes cannot be disabled.
6118
6119 You can enable (or disable) one or more probes using the following
6120 commands, with optional arguments:
6121
6122 @anchor{enable probes}
6123 @table @code
6124 @kindex enable probes
6125 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6126 If given, @var{provider} is a regular expression used to match against
6127 provider names when selecting which probes to enable. If omitted,
6128 all probes from all providers are enabled.
6129
6130 If given, @var{name} is a regular expression to match against probe
6131 names when selecting which probes to enable. If omitted, probe names
6132 are not considered when deciding whether to enable them.
6133
6134 If given, @var{objfile} is a regular expression used to select which
6135 object files (executable or shared libraries) to examine. If not
6136 given, all object files are considered.
6137
6138 @kindex disable probes
6139 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6140 See the @code{enable probes} command above for a description of the
6141 optional arguments accepted by this command.
6142 @end table
6143
6144 @vindex $_probe_arg@r{, convenience variable}
6145 A probe may specify up to twelve arguments. These are available at the
6146 point at which the probe is defined---that is, when the current PC is
6147 at the probe's location. The arguments are available using the
6148 convenience variables (@pxref{Convenience Vars})
6149 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
6150 probes each probe argument is an integer of the appropriate size;
6151 types are not preserved. In @code{DTrace} probes types are preserved
6152 provided that they are recognized as such by @value{GDBN}; otherwise
6153 the value of the probe argument will be a long integer. The
6154 convenience variable @code{$_probe_argc} holds the number of arguments
6155 at the current probe point.
6156
6157 These variables are always available, but attempts to access them at
6158 any location other than a probe point will cause @value{GDBN} to give
6159 an error message.
6160
6161
6162 @c @ifclear BARETARGET
6163 @node Error in Breakpoints
6164 @subsection ``Cannot insert breakpoints''
6165
6166 If you request too many active hardware-assisted breakpoints and
6167 watchpoints, you will see this error message:
6168
6169 @c FIXME: the precise wording of this message may change; the relevant
6170 @c source change is not committed yet (Sep 3, 1999).
6171 @smallexample
6172 Stopped; cannot insert breakpoints.
6173 You may have requested too many hardware breakpoints and watchpoints.
6174 @end smallexample
6175
6176 @noindent
6177 This message is printed when you attempt to resume the program, since
6178 only then @value{GDBN} knows exactly how many hardware breakpoints and
6179 watchpoints it needs to insert.
6180
6181 When this message is printed, you need to disable or remove some of the
6182 hardware-assisted breakpoints and watchpoints, and then continue.
6183
6184 @node Breakpoint-related Warnings
6185 @subsection ``Breakpoint address adjusted...''
6186 @cindex breakpoint address adjusted
6187
6188 Some processor architectures place constraints on the addresses at
6189 which breakpoints may be placed. For architectures thus constrained,
6190 @value{GDBN} will attempt to adjust the breakpoint's address to comply
6191 with the constraints dictated by the architecture.
6192
6193 One example of such an architecture is the Fujitsu FR-V. The FR-V is
6194 a VLIW architecture in which a number of RISC-like instructions may be
6195 bundled together for parallel execution. The FR-V architecture
6196 constrains the location of a breakpoint instruction within such a
6197 bundle to the instruction with the lowest address. @value{GDBN}
6198 honors this constraint by adjusting a breakpoint's address to the
6199 first in the bundle.
6200
6201 It is not uncommon for optimized code to have bundles which contain
6202 instructions from different source statements, thus it may happen that
6203 a breakpoint's address will be adjusted from one source statement to
6204 another. Since this adjustment may significantly alter @value{GDBN}'s
6205 breakpoint related behavior from what the user expects, a warning is
6206 printed when the breakpoint is first set and also when the breakpoint
6207 is hit.
6208
6209 A warning like the one below is printed when setting a breakpoint
6210 that's been subject to address adjustment:
6211
6212 @smallexample
6213 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6214 @end smallexample
6215
6216 Such warnings are printed both for user settable and @value{GDBN}'s
6217 internal breakpoints. If you see one of these warnings, you should
6218 verify that a breakpoint set at the adjusted address will have the
6219 desired affect. If not, the breakpoint in question may be removed and
6220 other breakpoints may be set which will have the desired behavior.
6221 E.g., it may be sufficient to place the breakpoint at a later
6222 instruction. A conditional breakpoint may also be useful in some
6223 cases to prevent the breakpoint from triggering too often.
6224
6225 @value{GDBN} will also issue a warning when stopping at one of these
6226 adjusted breakpoints:
6227
6228 @smallexample
6229 warning: Breakpoint 1 address previously adjusted from 0x00010414
6230 to 0x00010410.
6231 @end smallexample
6232
6233 When this warning is encountered, it may be too late to take remedial
6234 action except in cases where the breakpoint is hit earlier or more
6235 frequently than expected.
6236
6237 @node Continuing and Stepping
6238 @section Continuing and Stepping
6239
6240 @cindex stepping
6241 @cindex continuing
6242 @cindex resuming execution
6243 @dfn{Continuing} means resuming program execution until your program
6244 completes normally. In contrast, @dfn{stepping} means executing just
6245 one more ``step'' of your program, where ``step'' may mean either one
6246 line of source code, or one machine instruction (depending on what
6247 particular command you use). Either when continuing or when stepping,
6248 your program may stop even sooner, due to a breakpoint or a signal. (If
6249 it stops due to a signal, you may want to use @code{handle}, or use
6250 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6251 or you may step into the signal's handler (@pxref{stepping and signal
6252 handlers}).)
6253
6254 @table @code
6255 @kindex continue
6256 @kindex c @r{(@code{continue})}
6257 @kindex fg @r{(resume foreground execution)}
6258 @item continue @r{[}@var{ignore-count}@r{]}
6259 @itemx c @r{[}@var{ignore-count}@r{]}
6260 @itemx fg @r{[}@var{ignore-count}@r{]}
6261 Resume program execution, at the address where your program last stopped;
6262 any breakpoints set at that address are bypassed. The optional argument
6263 @var{ignore-count} allows you to specify a further number of times to
6264 ignore a breakpoint at this location; its effect is like that of
6265 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6266
6267 The argument @var{ignore-count} is meaningful only when your program
6268 stopped due to a breakpoint. At other times, the argument to
6269 @code{continue} is ignored.
6270
6271 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6272 debugged program is deemed to be the foreground program) are provided
6273 purely for convenience, and have exactly the same behavior as
6274 @code{continue}.
6275 @end table
6276
6277 To resume execution at a different place, you can use @code{return}
6278 (@pxref{Returning, ,Returning from a Function}) to go back to the
6279 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6280 Different Address}) to go to an arbitrary location in your program.
6281
6282 A typical technique for using stepping is to set a breakpoint
6283 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6284 beginning of the function or the section of your program where a problem
6285 is believed to lie, run your program until it stops at that breakpoint,
6286 and then step through the suspect area, examining the variables that are
6287 interesting, until you see the problem happen.
6288
6289 @table @code
6290 @kindex step
6291 @kindex s @r{(@code{step})}
6292 @item step
6293 Continue running your program until control reaches a different source
6294 line, then stop it and return control to @value{GDBN}. This command is
6295 abbreviated @code{s}.
6296
6297 @quotation
6298 @c "without debugging information" is imprecise; actually "without line
6299 @c numbers in the debugging information". (gcc -g1 has debugging info but
6300 @c not line numbers). But it seems complex to try to make that
6301 @c distinction here.
6302 @emph{Warning:} If you use the @code{step} command while control is
6303 within a function that was compiled without debugging information,
6304 execution proceeds until control reaches a function that does have
6305 debugging information. Likewise, it will not step into a function which
6306 is compiled without debugging information. To step through functions
6307 without debugging information, use the @code{stepi} command, described
6308 below.
6309 @end quotation
6310
6311 The @code{step} command only stops at the first instruction of a source
6312 line. This prevents the multiple stops that could otherwise occur in
6313 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6314 to stop if a function that has debugging information is called within
6315 the line. In other words, @code{step} @emph{steps inside} any functions
6316 called within the line.
6317
6318 Also, the @code{step} command only enters a function if there is line
6319 number information for the function. Otherwise it acts like the
6320 @code{next} command. This avoids problems when using @code{cc -gl}
6321 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6322 was any debugging information about the routine.
6323
6324 @item step @var{count}
6325 Continue running as in @code{step}, but do so @var{count} times. If a
6326 breakpoint is reached, or a signal not related to stepping occurs before
6327 @var{count} steps, stepping stops right away.
6328
6329 @kindex next
6330 @kindex n @r{(@code{next})}
6331 @item next @r{[}@var{count}@r{]}
6332 Continue to the next source line in the current (innermost) stack frame.
6333 This is similar to @code{step}, but function calls that appear within
6334 the line of code are executed without stopping. Execution stops when
6335 control reaches a different line of code at the original stack level
6336 that was executing when you gave the @code{next} command. This command
6337 is abbreviated @code{n}.
6338
6339 An argument @var{count} is a repeat count, as for @code{step}.
6340
6341
6342 @c FIX ME!! Do we delete this, or is there a way it fits in with
6343 @c the following paragraph? --- Vctoria
6344 @c
6345 @c @code{next} within a function that lacks debugging information acts like
6346 @c @code{step}, but any function calls appearing within the code of the
6347 @c function are executed without stopping.
6348
6349 The @code{next} command only stops at the first instruction of a
6350 source line. This prevents multiple stops that could otherwise occur in
6351 @code{switch} statements, @code{for} loops, etc.
6352
6353 @kindex set step-mode
6354 @item set step-mode
6355 @cindex functions without line info, and stepping
6356 @cindex stepping into functions with no line info
6357 @itemx set step-mode on
6358 The @code{set step-mode on} command causes the @code{step} command to
6359 stop at the first instruction of a function which contains no debug line
6360 information rather than stepping over it.
6361
6362 This is useful in cases where you may be interested in inspecting the
6363 machine instructions of a function which has no symbolic info and do not
6364 want @value{GDBN} to automatically skip over this function.
6365
6366 @item set step-mode off
6367 Causes the @code{step} command to step over any functions which contains no
6368 debug information. This is the default.
6369
6370 @item show step-mode
6371 Show whether @value{GDBN} will stop in or step over functions without
6372 source line debug information.
6373
6374 @kindex finish
6375 @kindex fin @r{(@code{finish})}
6376 @item finish
6377 Continue running until just after function in the selected stack frame
6378 returns. Print the returned value (if any). This command can be
6379 abbreviated as @code{fin}.
6380
6381 Contrast this with the @code{return} command (@pxref{Returning,
6382 ,Returning from a Function}).
6383
6384 @kindex set print finish
6385 @kindex show print finish
6386 @item set print finish @r{[}on|off@r{]}
6387 @itemx show print finish
6388 By default the @code{finish} command will show the value that is
6389 returned by the function. This can be disabled using @code{set print
6390 finish off}. When disabled, the value is still entered into the value
6391 history (@pxref{Value History}), but not displayed.
6392
6393 @kindex until
6394 @kindex u @r{(@code{until})}
6395 @cindex run until specified location
6396 @item until
6397 @itemx u
6398 Continue running until a source line past the current line, in the
6399 current stack frame, is reached. This command is used to avoid single
6400 stepping through a loop more than once. It is like the @code{next}
6401 command, except that when @code{until} encounters a jump, it
6402 automatically continues execution until the program counter is greater
6403 than the address of the jump.
6404
6405 This means that when you reach the end of a loop after single stepping
6406 though it, @code{until} makes your program continue execution until it
6407 exits the loop. In contrast, a @code{next} command at the end of a loop
6408 simply steps back to the beginning of the loop, which forces you to step
6409 through the next iteration.
6410
6411 @code{until} always stops your program if it attempts to exit the current
6412 stack frame.
6413
6414 @code{until} may produce somewhat counterintuitive results if the order
6415 of machine code does not match the order of the source lines. For
6416 example, in the following excerpt from a debugging session, the @code{f}
6417 (@code{frame}) command shows that execution is stopped at line
6418 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6419
6420 @smallexample
6421 (@value{GDBP}) f
6422 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6423 206 expand_input();
6424 (@value{GDBP}) until
6425 195 for ( ; argc > 0; NEXTARG) @{
6426 @end smallexample
6427
6428 This happened because, for execution efficiency, the compiler had
6429 generated code for the loop closure test at the end, rather than the
6430 start, of the loop---even though the test in a C @code{for}-loop is
6431 written before the body of the loop. The @code{until} command appeared
6432 to step back to the beginning of the loop when it advanced to this
6433 expression; however, it has not really gone to an earlier
6434 statement---not in terms of the actual machine code.
6435
6436 @code{until} with no argument works by means of single
6437 instruction stepping, and hence is slower than @code{until} with an
6438 argument.
6439
6440 @item until @var{locspec}
6441 @itemx u @var{locspec}
6442 Continue running your program until either it reaches a code location
6443 that results from resolving @var{locspec}, or the current stack frame
6444 returns. @var{locspec} is any of the forms described in @ref{Location
6445 Specifications}.
6446 This form of the command uses temporary breakpoints, and
6447 hence is quicker than @code{until} without an argument. The specified
6448 location is actually reached only if it is in the current frame. This
6449 implies that @code{until} can be used to skip over recursive function
6450 invocations. For instance in the code below, if the current location is
6451 line @code{96}, issuing @code{until 99} will execute the program up to
6452 line @code{99} in the same invocation of factorial, i.e., after the inner
6453 invocations have returned.
6454
6455 @smallexample
6456 94 int factorial (int value)
6457 95 @{
6458 96 if (value > 1) @{
6459 97 value *= factorial (value - 1);
6460 98 @}
6461 99 return (value);
6462 100 @}
6463 @end smallexample
6464
6465
6466 @kindex advance @var{locspec}
6467 @item advance @var{locspec}
6468 Continue running your program until either it reaches a code location
6469 that results from resolving @var{locspec}, or the current stack frame
6470 returns. @var{locspec} is any of the forms described in @ref{Location
6471 Specifications}. This command is similar to @code{until}, but
6472 @code{advance} will not skip over recursive function calls, and the
6473 target code location doesn't have to be in the same frame as the
6474 current one.
6475
6476
6477 @kindex stepi
6478 @kindex si @r{(@code{stepi})}
6479 @item stepi
6480 @itemx stepi @var{arg}
6481 @itemx si
6482 Execute one machine instruction, then stop and return to the debugger.
6483
6484 It is often useful to do @samp{display/i $pc} when stepping by machine
6485 instructions. This makes @value{GDBN} automatically display the next
6486 instruction to be executed, each time your program stops. @xref{Auto
6487 Display,, Automatic Display}.
6488
6489 An argument is a repeat count, as in @code{step}.
6490
6491 @need 750
6492 @kindex nexti
6493 @kindex ni @r{(@code{nexti})}
6494 @item nexti
6495 @itemx nexti @var{arg}
6496 @itemx ni
6497 Execute one machine instruction, but if it is a function call,
6498 proceed until the function returns.
6499
6500 An argument is a repeat count, as in @code{next}.
6501
6502 @end table
6503
6504 @anchor{range stepping}
6505 @cindex range stepping
6506 @cindex target-assisted range stepping
6507 By default, and if available, @value{GDBN} makes use of
6508 target-assisted @dfn{range stepping}. In other words, whenever you
6509 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6510 tells the target to step the corresponding range of instruction
6511 addresses instead of issuing multiple single-steps. This speeds up
6512 line stepping, particularly for remote targets. Ideally, there should
6513 be no reason you would want to turn range stepping off. However, it's
6514 possible that a bug in the debug info, a bug in the remote stub (for
6515 remote targets), or even a bug in @value{GDBN} could make line
6516 stepping behave incorrectly when target-assisted range stepping is
6517 enabled. You can use the following command to turn off range stepping
6518 if necessary:
6519
6520 @table @code
6521 @kindex set range-stepping
6522 @kindex show range-stepping
6523 @item set range-stepping
6524 @itemx show range-stepping
6525 Control whether range stepping is enabled.
6526
6527 If @code{on}, and the target supports it, @value{GDBN} tells the
6528 target to step a range of addresses itself, instead of issuing
6529 multiple single-steps. If @code{off}, @value{GDBN} always issues
6530 single-steps, even if range stepping is supported by the target. The
6531 default is @code{on}.
6532
6533 @end table
6534
6535 @node Skipping Over Functions and Files
6536 @section Skipping Over Functions and Files
6537 @cindex skipping over functions and files
6538
6539 The program you are debugging may contain some functions which are
6540 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6541 skip a function, all functions in a file or a particular function in
6542 a particular file when stepping.
6543
6544 For example, consider the following C function:
6545
6546 @smallexample
6547 101 int func()
6548 102 @{
6549 103 foo(boring());
6550 104 bar(boring());
6551 105 @}
6552 @end smallexample
6553
6554 @noindent
6555 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6556 are not interested in stepping through @code{boring}. If you run @code{step}
6557 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6558 step over both @code{foo} and @code{boring}!
6559
6560 One solution is to @code{step} into @code{boring} and use the @code{finish}
6561 command to immediately exit it. But this can become tedious if @code{boring}
6562 is called from many places.
6563
6564 A more flexible solution is to execute @kbd{skip boring}. This instructs
6565 @value{GDBN} never to step into @code{boring}. Now when you execute
6566 @code{step} at line 103, you'll step over @code{boring} and directly into
6567 @code{foo}.
6568
6569 Functions may be skipped by providing either a function name, linespec
6570 (@pxref{Location Specifications}), regular expression that matches the function's
6571 name, file name or a @code{glob}-style pattern that matches the file name.
6572
6573 On Posix systems the form of the regular expression is
6574 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6575 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6576 expression is whatever is provided by the @code{regcomp} function of
6577 the underlying system.
6578 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6579 description of @code{glob}-style patterns.
6580
6581 @table @code
6582 @kindex skip
6583 @item skip @r{[}@var{options}@r{]}
6584 The basic form of the @code{skip} command takes zero or more options
6585 that specify what to skip.
6586 The @var{options} argument is any useful combination of the following:
6587
6588 @table @code
6589 @item -file @var{file}
6590 @itemx -fi @var{file}
6591 Functions in @var{file} will be skipped over when stepping.
6592
6593 @item -gfile @var{file-glob-pattern}
6594 @itemx -gfi @var{file-glob-pattern}
6595 @cindex skipping over files via glob-style patterns
6596 Functions in files matching @var{file-glob-pattern} will be skipped
6597 over when stepping.
6598
6599 @smallexample
6600 (@value{GDBP}) skip -gfi utils/*.c
6601 @end smallexample
6602
6603 @item -function @var{linespec}
6604 @itemx -fu @var{linespec}
6605 Functions named by @var{linespec} or the function containing the line
6606 named by @var{linespec} will be skipped over when stepping.
6607 @xref{Location Specifications}.
6608
6609 @item -rfunction @var{regexp}
6610 @itemx -rfu @var{regexp}
6611 @cindex skipping over functions via regular expressions
6612 Functions whose name matches @var{regexp} will be skipped over when stepping.
6613
6614 This form is useful for complex function names.
6615 For example, there is generally no need to step into C@t{++} @code{std::string}
6616 constructors or destructors. Plus with C@t{++} templates it can be hard to
6617 write out the full name of the function, and often it doesn't matter what
6618 the template arguments are. Specifying the function to be skipped as a
6619 regular expression makes this easier.
6620
6621 @smallexample
6622 (@value{GDBP}) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6623 @end smallexample
6624
6625 If you want to skip every templated C@t{++} constructor and destructor
6626 in the @code{std} namespace you can do:
6627
6628 @smallexample
6629 (@value{GDBP}) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6630 @end smallexample
6631 @end table
6632
6633 If no options are specified, the function you're currently debugging
6634 will be skipped.
6635
6636 @kindex skip function
6637 @item skip function @r{[}@var{linespec}@r{]}
6638 After running this command, the function named by @var{linespec} or the
6639 function containing the line named by @var{linespec} will be skipped over when
6640 stepping. @xref{Location Specifications}.
6641
6642 If you do not specify @var{linespec}, the function you're currently debugging
6643 will be skipped.
6644
6645 (If you have a function called @code{file} that you want to skip, use
6646 @kbd{skip function file}.)
6647
6648 @kindex skip file
6649 @item skip file @r{[}@var{filename}@r{]}
6650 After running this command, any function whose source lives in @var{filename}
6651 will be skipped over when stepping.
6652
6653 @smallexample
6654 (@value{GDBP}) skip file boring.c
6655 File boring.c will be skipped when stepping.
6656 @end smallexample
6657
6658 If you do not specify @var{filename}, functions whose source lives in the file
6659 you're currently debugging will be skipped.
6660 @end table
6661
6662 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6663 These are the commands for managing your list of skips:
6664
6665 @table @code
6666 @kindex info skip
6667 @item info skip @r{[}@var{range}@r{]}
6668 Print details about the specified skip(s). If @var{range} is not specified,
6669 print a table with details about all functions and files marked for skipping.
6670 @code{info skip} prints the following information about each skip:
6671
6672 @table @emph
6673 @item Identifier
6674 A number identifying this skip.
6675 @item Enabled or Disabled
6676 Enabled skips are marked with @samp{y}.
6677 Disabled skips are marked with @samp{n}.
6678 @item Glob
6679 If the file name is a @samp{glob} pattern this is @samp{y}.
6680 Otherwise it is @samp{n}.
6681 @item File
6682 The name or @samp{glob} pattern of the file to be skipped.
6683 If no file is specified this is @samp{<none>}.
6684 @item RE
6685 If the function name is a @samp{regular expression} this is @samp{y}.
6686 Otherwise it is @samp{n}.
6687 @item Function
6688 The name or regular expression of the function to skip.
6689 If no function is specified this is @samp{<none>}.
6690 @end table
6691
6692 @kindex skip delete
6693 @item skip delete @r{[}@var{range}@r{]}
6694 Delete the specified skip(s). If @var{range} is not specified, delete all
6695 skips.
6696
6697 @kindex skip enable
6698 @item skip enable @r{[}@var{range}@r{]}
6699 Enable the specified skip(s). If @var{range} is not specified, enable all
6700 skips.
6701
6702 @kindex skip disable
6703 @item skip disable @r{[}@var{range}@r{]}
6704 Disable the specified skip(s). If @var{range} is not specified, disable all
6705 skips.
6706
6707 @kindex set debug skip
6708 @item set debug skip @r{[}on|off@r{]}
6709 Set whether to print the debug output about skipping files and functions.
6710
6711 @kindex show debug skip
6712 @item show debug skip
6713 Show whether the debug output about skipping files and functions is printed.
6714
6715 @end table
6716
6717 @node Signals
6718 @section Signals
6719 @cindex signals
6720
6721 A signal is an asynchronous event that can happen in a program. The
6722 operating system defines the possible kinds of signals, and gives each
6723 kind a name and a number. For example, in Unix @code{SIGINT} is the
6724 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6725 @code{SIGSEGV} is the signal a program gets from referencing a place in
6726 memory far away from all the areas in use; @code{SIGALRM} occurs when
6727 the alarm clock timer goes off (which happens only if your program has
6728 requested an alarm).
6729
6730 @cindex fatal signals
6731 Some signals, including @code{SIGALRM}, are a normal part of the
6732 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6733 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6734 program has not specified in advance some other way to handle the signal.
6735 @code{SIGINT} does not indicate an error in your program, but it is normally
6736 fatal so it can carry out the purpose of the interrupt: to kill the program.
6737
6738 @value{GDBN} has the ability to detect any occurrence of a signal in your
6739 program. You can tell @value{GDBN} in advance what to do for each kind of
6740 signal.
6741
6742 @cindex handling signals
6743 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6744 @code{SIGALRM} be silently passed to your program
6745 (so as not to interfere with their role in the program's functioning)
6746 but to stop your program immediately whenever an error signal happens.
6747 You can change these settings with the @code{handle} command.
6748
6749 @table @code
6750 @kindex info signals
6751 @kindex info handle
6752 @item info signals
6753 @itemx info handle
6754 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6755 handle each one. You can use this to see the signal numbers of all
6756 the defined types of signals.
6757
6758 @item info signals @var{sig}
6759 Similar, but print information only about the specified signal number.
6760
6761 @code{info handle} is an alias for @code{info signals}.
6762
6763 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6764 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6765 for details about this command.
6766
6767 @kindex handle
6768 @item handle @var{signal} @r{[} @var{signal} @dots{} @r{]} @r{[}@var{keywords}@dots{}@r{]}
6769 Change the way @value{GDBN} handles each @var{signal}. Each
6770 @var{signal} can be the number of a signal or its name (with or
6771 without the @samp{SIG} at the beginning); a list of signal numbers of
6772 the form @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning
6773 all the known signals, except @code{SIGINT} and @code{SIGTRAP}, which
6774 are used by @value{GDBN}. Optional argument @var{keywords}, described
6775 below, say what changes to make to all of the specified signals.
6776 @end table
6777
6778 @c @group
6779 The keywords allowed by the @code{handle} command can be abbreviated.
6780 Their full names are:
6781
6782 @table @code
6783 @item nostop
6784 @value{GDBN} should not stop your program when this signal happens. It may
6785 still print a message telling you that the signal has come in.
6786
6787 @item stop
6788 @value{GDBN} should stop your program when this signal happens. This implies
6789 the @code{print} keyword as well.
6790
6791 @item print
6792 @value{GDBN} should print a message when this signal happens.
6793
6794 @item noprint
6795 @value{GDBN} should not mention the occurrence of the signal at all. This
6796 implies the @code{nostop} keyword as well.
6797
6798 @item pass
6799 @itemx noignore
6800 @value{GDBN} should allow your program to see this signal; your program
6801 can handle the signal, or else it may terminate if the signal is fatal
6802 and not handled. @code{pass} and @code{noignore} are synonyms.
6803
6804 @item nopass
6805 @itemx ignore
6806 @value{GDBN} should not allow your program to see this signal.
6807 @code{nopass} and @code{ignore} are synonyms.
6808 @end table
6809 @c @end group
6810
6811 When a signal stops your program, the signal is not visible to the
6812 program until you
6813 continue. Your program sees the signal then, if @code{pass} is in
6814 effect for the signal in question @emph{at that time}. In other words,
6815 after @value{GDBN} reports a signal, you can use the @code{handle}
6816 command with @code{pass} or @code{nopass} to control whether your
6817 program sees that signal when you continue.
6818
6819 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6820 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6821 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6822 erroneous signals.
6823
6824 You can also use the @code{signal} command to prevent your program from
6825 seeing a signal, or cause it to see a signal it normally would not see,
6826 or to give it any signal at any time. For example, if your program stopped
6827 due to some sort of memory reference error, you might store correct
6828 values into the erroneous variables and continue, hoping to see more
6829 execution; but your program would probably terminate immediately as
6830 a result of the fatal signal once it saw the signal. To prevent this,
6831 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6832 Program a Signal}.
6833
6834 @cindex stepping and signal handlers
6835 @anchor{stepping and signal handlers}
6836
6837 @value{GDBN} optimizes for stepping the mainline code. If a signal
6838 that has @code{handle nostop} and @code{handle pass} set arrives while
6839 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6840 in progress, @value{GDBN} lets the signal handler run and then resumes
6841 stepping the mainline code once the signal handler returns. In other
6842 words, @value{GDBN} steps over the signal handler. This prevents
6843 signals that you've specified as not interesting (with @code{handle
6844 nostop}) from changing the focus of debugging unexpectedly. Note that
6845 the signal handler itself may still hit a breakpoint, stop for another
6846 signal that has @code{handle stop} in effect, or for any other event
6847 that normally results in stopping the stepping command sooner. Also
6848 note that @value{GDBN} still informs you that the program received a
6849 signal if @code{handle print} is set.
6850
6851 @anchor{stepping into signal handlers}
6852
6853 If you set @code{handle pass} for a signal, and your program sets up a
6854 handler for it, then issuing a stepping command, such as @code{step}
6855 or @code{stepi}, when your program is stopped due to the signal will
6856 step @emph{into} the signal handler (if the target supports that).
6857
6858 Likewise, if you use the @code{queue-signal} command to queue a signal
6859 to be delivered to the current thread when execution of the thread
6860 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6861 stepping command will step into the signal handler.
6862
6863 Here's an example, using @code{stepi} to step to the first instruction
6864 of @code{SIGUSR1}'s handler:
6865
6866 @smallexample
6867 (@value{GDBP}) handle SIGUSR1
6868 Signal Stop Print Pass to program Description
6869 SIGUSR1 Yes Yes Yes User defined signal 1
6870 (@value{GDBP}) c
6871 Continuing.
6872
6873 Program received signal SIGUSR1, User defined signal 1.
6874 main () sigusr1.c:28
6875 28 p = 0;
6876 (@value{GDBP}) si
6877 sigusr1_handler () at sigusr1.c:9
6878 9 @{
6879 @end smallexample
6880
6881 The same, but using @code{queue-signal} instead of waiting for the
6882 program to receive the signal first:
6883
6884 @smallexample
6885 (@value{GDBP}) n
6886 28 p = 0;
6887 (@value{GDBP}) queue-signal SIGUSR1
6888 (@value{GDBP}) si
6889 sigusr1_handler () at sigusr1.c:9
6890 9 @{
6891 (@value{GDBP})
6892 @end smallexample
6893
6894 @cindex extra signal information
6895 @anchor{extra signal information}
6896
6897 On some targets, @value{GDBN} can inspect extra signal information
6898 associated with the intercepted signal, before it is actually
6899 delivered to the program being debugged. This information is exported
6900 by the convenience variable @code{$_siginfo}, and consists of data
6901 that is passed by the kernel to the signal handler at the time of the
6902 receipt of a signal. The data type of the information itself is
6903 target dependent. You can see the data type using the @code{ptype
6904 $_siginfo} command. On Unix systems, it typically corresponds to the
6905 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6906 system header.
6907
6908 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6909 referenced address that raised a segmentation fault.
6910
6911 @smallexample
6912 @group
6913 (@value{GDBP}) continue
6914 Program received signal SIGSEGV, Segmentation fault.
6915 0x0000000000400766 in main ()
6916 69 *(int *)p = 0;
6917 (@value{GDBP}) ptype $_siginfo
6918 type = struct @{
6919 int si_signo;
6920 int si_errno;
6921 int si_code;
6922 union @{
6923 int _pad[28];
6924 struct @{...@} _kill;
6925 struct @{...@} _timer;
6926 struct @{...@} _rt;
6927 struct @{...@} _sigchld;
6928 struct @{...@} _sigfault;
6929 struct @{...@} _sigpoll;
6930 @} _sifields;
6931 @}
6932 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6933 type = struct @{
6934 void *si_addr;
6935 @}
6936 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6937 $1 = (void *) 0x7ffff7ff7000
6938 @end group
6939 @end smallexample
6940
6941 Depending on target support, @code{$_siginfo} may also be writable.
6942
6943 @cindex Intel MPX boundary violations
6944 @cindex boundary violations, Intel MPX
6945 On some targets, a @code{SIGSEGV} can be caused by a boundary
6946 violation, i.e., accessing an address outside of the allowed range.
6947 In those cases @value{GDBN} may displays additional information,
6948 depending on how @value{GDBN} has been told to handle the signal.
6949 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6950 kind: "Upper" or "Lower", the memory address accessed and the
6951 bounds, while with @code{handle nostop SIGSEGV} no additional
6952 information is displayed.
6953
6954 The usual output of a segfault is:
6955 @smallexample
6956 Program received signal SIGSEGV, Segmentation fault
6957 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6958 68 value = *(p + len);
6959 @end smallexample
6960
6961 While a bound violation is presented as:
6962 @smallexample
6963 Program received signal SIGSEGV, Segmentation fault
6964 Upper bound violation while accessing address 0x7fffffffc3b3
6965 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6966 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6967 68 value = *(p + len);
6968 @end smallexample
6969
6970 @node Thread Stops
6971 @section Stopping and Starting Multi-thread Programs
6972
6973 @cindex stopped threads
6974 @cindex threads, stopped
6975
6976 @cindex continuing threads
6977 @cindex threads, continuing
6978
6979 @value{GDBN} supports debugging programs with multiple threads
6980 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6981 are two modes of controlling execution of your program within the
6982 debugger. In the default mode, referred to as @dfn{all-stop mode},
6983 when any thread in your program stops (for example, at a breakpoint
6984 or while being stepped), all other threads in the program are also stopped by
6985 @value{GDBN}. On some targets, @value{GDBN} also supports
6986 @dfn{non-stop mode}, in which other threads can continue to run freely while
6987 you examine the stopped thread in the debugger.
6988
6989 @menu
6990 * All-Stop Mode:: All threads stop when GDB takes control
6991 * Non-Stop Mode:: Other threads continue to execute
6992 * Background Execution:: Running your program asynchronously
6993 * Thread-Specific Breakpoints:: Controlling breakpoints
6994 * Interrupted System Calls:: GDB may interfere with system calls
6995 * Observer Mode:: GDB does not alter program behavior
6996 @end menu
6997
6998 @node All-Stop Mode
6999 @subsection All-Stop Mode
7000
7001 @cindex all-stop mode
7002
7003 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
7004 @emph{all} threads of execution stop, not just the current thread. This
7005 allows you to examine the overall state of the program, including
7006 switching between threads, without worrying that things may change
7007 underfoot.
7008
7009 Conversely, whenever you restart the program, @emph{all} threads start
7010 executing. @emph{This is true even when single-stepping} with commands
7011 like @code{step} or @code{next}.
7012
7013 In particular, @value{GDBN} cannot single-step all threads in lockstep.
7014 Since thread scheduling is up to your debugging target's operating
7015 system (not controlled by @value{GDBN}), other threads may
7016 execute more than one statement while the current thread completes a
7017 single step. Moreover, in general other threads stop in the middle of a
7018 statement, rather than at a clean statement boundary, when the program
7019 stops.
7020
7021 You might even find your program stopped in another thread after
7022 continuing or even single-stepping. This happens whenever some other
7023 thread runs into a breakpoint, a signal, or an exception before the
7024 first thread completes whatever you requested.
7025
7026 @cindex automatic thread selection
7027 @cindex switching threads automatically
7028 @cindex threads, automatic switching
7029 Whenever @value{GDBN} stops your program, due to a breakpoint or a
7030 signal, it automatically selects the thread where that breakpoint or
7031 signal happened. @value{GDBN} alerts you to the context switch with a
7032 message such as @samp{[Switching to Thread @var{n}]} to identify the
7033 thread.
7034
7035 @anchor{set scheduler-locking}
7036
7037 On some OSes, you can modify @value{GDBN}'s default behavior by
7038 locking the OS scheduler to allow only a single thread to run.
7039
7040 @table @code
7041 @item set scheduler-locking @var{mode}
7042 @cindex scheduler locking mode
7043 @cindex lock scheduler
7044 Set the scheduler locking mode. It applies to normal execution,
7045 record mode, and replay mode. @var{mode} can be one of
7046 the following:
7047
7048 @table @code
7049 @item off
7050 There is no locking and any thread may run at any time.
7051
7052 @item on
7053 Only the current thread may run when the inferior is resumed.
7054
7055 @item step
7056 Behaves like @code{on} when stepping, and @code{off} otherwise.
7057 Threads other than the current never get a chance to run when you
7058 step, and they are completely free to run when you use commands like
7059 @samp{continue}, @samp{until}, or @samp{finish}.
7060
7061 This mode optimizes for single-stepping; it prevents other threads
7062 from preempting the current thread while you are stepping, so that the
7063 focus of debugging does not change unexpectedly. However, unless
7064 another thread hits a breakpoint during its timeslice, @value{GDBN}
7065 does not change the current thread away from the thread that you are
7066 debugging.
7067
7068 @item replay
7069 Behaves like @code{on} in replay mode, and @code{off} in either record
7070 mode or during normal execution. This is the default mode.
7071 @end table
7072
7073 @item show scheduler-locking
7074 Display the current scheduler locking mode.
7075 @end table
7076
7077 @cindex resume threads of multiple processes simultaneously
7078 By default, when you issue one of the execution commands such as
7079 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
7080 threads of the current inferior to run. For example, if @value{GDBN}
7081 is attached to two inferiors, each with two threads, the
7082 @code{continue} command resumes only the two threads of the current
7083 inferior. This is useful, for example, when you debug a program that
7084 forks and you want to hold the parent stopped (so that, for instance,
7085 it doesn't run to exit), while you debug the child. In other
7086 situations, you may not be interested in inspecting the current state
7087 of any of the processes @value{GDBN} is attached to, and you may want
7088 to resume them all until some breakpoint is hit. In the latter case,
7089 you can instruct @value{GDBN} to allow all threads of all the
7090 inferiors to run with the @w{@code{set schedule-multiple}} command.
7091
7092 @table @code
7093 @kindex set schedule-multiple
7094 @item set schedule-multiple
7095 Set the mode for allowing threads of multiple processes to be resumed
7096 when an execution command is issued. When @code{on}, all threads of
7097 all processes are allowed to run. When @code{off}, only the threads
7098 of the current process are resumed. The default is @code{off}. The
7099 @code{scheduler-locking} mode takes precedence when set to @code{on},
7100 or while you are stepping and set to @code{step}.
7101
7102 @item show schedule-multiple
7103 Display the current mode for resuming the execution of threads of
7104 multiple processes.
7105 @end table
7106
7107 @node Non-Stop Mode
7108 @subsection Non-Stop Mode
7109
7110 @cindex non-stop mode
7111
7112 @c This section is really only a place-holder, and needs to be expanded
7113 @c with more details.
7114
7115 For some multi-threaded targets, @value{GDBN} supports an optional
7116 mode of operation in which you can examine stopped program threads in
7117 the debugger while other threads continue to execute freely. This
7118 minimizes intrusion when debugging live systems, such as programs
7119 where some threads have real-time constraints or must continue to
7120 respond to external events. This is referred to as @dfn{non-stop} mode.
7121
7122 In non-stop mode, when a thread stops to report a debugging event,
7123 @emph{only} that thread is stopped; @value{GDBN} does not stop other
7124 threads as well, in contrast to the all-stop mode behavior. Additionally,
7125 execution commands such as @code{continue} and @code{step} apply by default
7126 only to the current thread in non-stop mode, rather than all threads as
7127 in all-stop mode. This allows you to control threads explicitly in
7128 ways that are not possible in all-stop mode --- for example, stepping
7129 one thread while allowing others to run freely, stepping
7130 one thread while holding all others stopped, or stepping several threads
7131 independently and simultaneously.
7132
7133 To enter non-stop mode, use this sequence of commands before you run
7134 or attach to your program:
7135
7136 @smallexample
7137 # If using the CLI, pagination breaks non-stop.
7138 set pagination off
7139
7140 # Finally, turn it on!
7141 set non-stop on
7142 @end smallexample
7143
7144 You can use these commands to manipulate the non-stop mode setting:
7145
7146 @table @code
7147 @kindex set non-stop
7148 @item set non-stop on
7149 Enable selection of non-stop mode.
7150 @item set non-stop off
7151 Disable selection of non-stop mode.
7152 @kindex show non-stop
7153 @item show non-stop
7154 Show the current non-stop enablement setting.
7155 @end table
7156
7157 Note these commands only reflect whether non-stop mode is enabled,
7158 not whether the currently-executing program is being run in non-stop mode.
7159 In particular, the @code{set non-stop} preference is only consulted when
7160 @value{GDBN} starts or connects to the target program, and it is generally
7161 not possible to switch modes once debugging has started. Furthermore,
7162 since not all targets support non-stop mode, even when you have enabled
7163 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
7164 default.
7165
7166 In non-stop mode, all execution commands apply only to the current thread
7167 by default. That is, @code{continue} only continues one thread.
7168 To continue all threads, issue @code{continue -a} or @code{c -a}.
7169
7170 You can use @value{GDBN}'s background execution commands
7171 (@pxref{Background Execution}) to run some threads in the background
7172 while you continue to examine or step others from @value{GDBN}.
7173 The MI execution commands (@pxref{GDB/MI Program Execution}) are
7174 always executed asynchronously in non-stop mode.
7175
7176 Suspending execution is done with the @code{interrupt} command when
7177 running in the background, or @kbd{Ctrl-c} during foreground execution.
7178 In all-stop mode, this stops the whole process;
7179 but in non-stop mode the interrupt applies only to the current thread.
7180 To stop the whole program, use @code{interrupt -a}.
7181
7182 Other execution commands do not currently support the @code{-a} option.
7183
7184 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
7185 that thread current, as it does in all-stop mode. This is because the
7186 thread stop notifications are asynchronous with respect to @value{GDBN}'s
7187 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
7188 changed to a different thread just as you entered a command to operate on the
7189 previously current thread.
7190
7191 @node Background Execution
7192 @subsection Background Execution
7193
7194 @cindex foreground execution
7195 @cindex background execution
7196 @cindex asynchronous execution
7197 @cindex execution, foreground, background and asynchronous
7198
7199 @value{GDBN}'s execution commands have two variants: the normal
7200 foreground (synchronous) behavior, and a background
7201 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
7202 the program to report that some thread has stopped before prompting for
7203 another command. In background execution, @value{GDBN} immediately gives
7204 a command prompt so that you can issue other commands while your program runs.
7205
7206 If the target doesn't support async mode, @value{GDBN} issues an error
7207 message if you attempt to use the background execution commands.
7208
7209 @cindex @code{&}, background execution of commands
7210 To specify background execution, add a @code{&} to the command. For example,
7211 the background form of the @code{continue} command is @code{continue&}, or
7212 just @code{c&}. The execution commands that accept background execution
7213 are:
7214
7215 @table @code
7216 @kindex run&
7217 @item run
7218 @xref{Starting, , Starting your Program}.
7219
7220 @item attach
7221 @kindex attach&
7222 @xref{Attach, , Debugging an Already-running Process}.
7223
7224 @item step
7225 @kindex step&
7226 @xref{Continuing and Stepping, step}.
7227
7228 @item stepi
7229 @kindex stepi&
7230 @xref{Continuing and Stepping, stepi}.
7231
7232 @item next
7233 @kindex next&
7234 @xref{Continuing and Stepping, next}.
7235
7236 @item nexti
7237 @kindex nexti&
7238 @xref{Continuing and Stepping, nexti}.
7239
7240 @item continue
7241 @kindex continue&
7242 @xref{Continuing and Stepping, continue}.
7243
7244 @item finish
7245 @kindex finish&
7246 @xref{Continuing and Stepping, finish}.
7247
7248 @item until
7249 @kindex until&
7250 @xref{Continuing and Stepping, until}.
7251
7252 @end table
7253
7254 Background execution is especially useful in conjunction with non-stop
7255 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7256 However, you can also use these commands in the normal all-stop mode with
7257 the restriction that you cannot issue another execution command until the
7258 previous one finishes. Examples of commands that are valid in all-stop
7259 mode while the program is running include @code{help} and @code{info break}.
7260
7261 You can interrupt your program while it is running in the background by
7262 using the @code{interrupt} command.
7263
7264 @table @code
7265 @kindex interrupt
7266 @item interrupt
7267 @itemx interrupt -a
7268
7269 Suspend execution of the running program. In all-stop mode,
7270 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7271 only the current thread. To stop the whole program in non-stop mode,
7272 use @code{interrupt -a}.
7273 @end table
7274
7275 @node Thread-Specific Breakpoints
7276 @subsection Thread-Specific Breakpoints
7277
7278 When your program has multiple threads (@pxref{Threads,, Debugging
7279 Programs with Multiple Threads}), you can choose whether to set
7280 breakpoints on all threads, or on a particular thread.
7281
7282 @table @code
7283 @cindex breakpoints and threads
7284 @cindex thread breakpoints
7285 @kindex break @dots{} thread @var{thread-id}
7286 @item break @var{locspec} thread @var{thread-id}
7287 @itemx break @var{locspec} thread @var{thread-id} if @dots{}
7288 @var{locspec} specifies a code location or locations in your program.
7289 @xref{Location Specifications}, for details.
7290
7291 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7292 to specify that you only want @value{GDBN} to stop the program when a
7293 particular thread reaches this breakpoint. The @var{thread-id} specifier
7294 is one of the thread identifiers assigned by @value{GDBN}, shown
7295 in the first column of the @samp{info threads} display.
7296
7297 If you do not specify @samp{thread @var{thread-id}} when you set a
7298 breakpoint, the breakpoint applies to @emph{all} threads of your
7299 program.
7300
7301 You can use the @code{thread} qualifier on conditional breakpoints as
7302 well; in this case, place @samp{thread @var{thread-id}} before or
7303 after the breakpoint condition, like this:
7304
7305 @smallexample
7306 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7307 @end smallexample
7308
7309 @end table
7310
7311 Thread-specific breakpoints are automatically deleted when
7312 @value{GDBN} detects the corresponding thread is no longer in the
7313 thread list. For example:
7314
7315 @smallexample
7316 (@value{GDBP}) c
7317 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7318 @end smallexample
7319
7320 There are several ways for a thread to disappear, such as a regular
7321 thread exit, but also when you detach from the process with the
7322 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7323 Process}), or if @value{GDBN} loses the remote connection
7324 (@pxref{Remote Debugging}), etc. Note that with some targets,
7325 @value{GDBN} is only able to detect a thread has exited when the user
7326 explictly asks for the thread list with the @code{info threads}
7327 command.
7328
7329 @node Interrupted System Calls
7330 @subsection Interrupted System Calls
7331
7332 @cindex thread breakpoints and system calls
7333 @cindex system calls and thread breakpoints
7334 @cindex premature return from system calls
7335 There is an unfortunate side effect when using @value{GDBN} to debug
7336 multi-threaded programs. If one thread stops for a
7337 breakpoint, or for some other reason, and another thread is blocked in a
7338 system call, then the system call may return prematurely. This is a
7339 consequence of the interaction between multiple threads and the signals
7340 that @value{GDBN} uses to implement breakpoints and other events that
7341 stop execution.
7342
7343 To handle this problem, your program should check the return value of
7344 each system call and react appropriately. This is good programming
7345 style anyways.
7346
7347 For example, do not write code like this:
7348
7349 @smallexample
7350 sleep (10);
7351 @end smallexample
7352
7353 The call to @code{sleep} will return early if a different thread stops
7354 at a breakpoint or for some other reason.
7355
7356 Instead, write this:
7357
7358 @smallexample
7359 int unslept = 10;
7360 while (unslept > 0)
7361 unslept = sleep (unslept);
7362 @end smallexample
7363
7364 A system call is allowed to return early, so the system is still
7365 conforming to its specification. But @value{GDBN} does cause your
7366 multi-threaded program to behave differently than it would without
7367 @value{GDBN}.
7368
7369 Also, @value{GDBN} uses internal breakpoints in the thread library to
7370 monitor certain events such as thread creation and thread destruction.
7371 When such an event happens, a system call in another thread may return
7372 prematurely, even though your program does not appear to stop.
7373
7374 @node Observer Mode
7375 @subsection Observer Mode
7376
7377 If you want to build on non-stop mode and observe program behavior
7378 without any chance of disruption by @value{GDBN}, you can set
7379 variables to disable all of the debugger's attempts to modify state,
7380 whether by writing memory, inserting breakpoints, etc. These operate
7381 at a low level, intercepting operations from all commands.
7382
7383 When all of these are set to @code{off}, then @value{GDBN} is said to
7384 be @dfn{observer mode}. As a convenience, the variable
7385 @code{observer} can be set to disable these, plus enable non-stop
7386 mode.
7387
7388 Note that @value{GDBN} will not prevent you from making nonsensical
7389 combinations of these settings. For instance, if you have enabled
7390 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7391 then breakpoints that work by writing trap instructions into the code
7392 stream will still not be able to be placed.
7393
7394 @table @code
7395
7396 @kindex observer
7397 @item set observer on
7398 @itemx set observer off
7399 When set to @code{on}, this disables all the permission variables
7400 below (except for @code{insert-fast-tracepoints}), plus enables
7401 non-stop debugging. Setting this to @code{off} switches back to
7402 normal debugging, though remaining in non-stop mode.
7403
7404 @item show observer
7405 Show whether observer mode is on or off.
7406
7407 @kindex may-write-registers
7408 @item set may-write-registers on
7409 @itemx set may-write-registers off
7410 This controls whether @value{GDBN} will attempt to alter the values of
7411 registers, such as with assignment expressions in @code{print}, or the
7412 @code{jump} command. It defaults to @code{on}.
7413
7414 @item show may-write-registers
7415 Show the current permission to write registers.
7416
7417 @kindex may-write-memory
7418 @item set may-write-memory on
7419 @itemx set may-write-memory off
7420 This controls whether @value{GDBN} will attempt to alter the contents
7421 of memory, such as with assignment expressions in @code{print}. It
7422 defaults to @code{on}.
7423
7424 @item show may-write-memory
7425 Show the current permission to write memory.
7426
7427 @kindex may-insert-breakpoints
7428 @item set may-insert-breakpoints on
7429 @itemx set may-insert-breakpoints off
7430 This controls whether @value{GDBN} will attempt to insert breakpoints.
7431 This affects all breakpoints, including internal breakpoints defined
7432 by @value{GDBN}. It defaults to @code{on}.
7433
7434 @item show may-insert-breakpoints
7435 Show the current permission to insert breakpoints.
7436
7437 @kindex may-insert-tracepoints
7438 @item set may-insert-tracepoints on
7439 @itemx set may-insert-tracepoints off
7440 This controls whether @value{GDBN} will attempt to insert (regular)
7441 tracepoints at the beginning of a tracing experiment. It affects only
7442 non-fast tracepoints, fast tracepoints being under the control of
7443 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7444
7445 @item show may-insert-tracepoints
7446 Show the current permission to insert tracepoints.
7447
7448 @kindex may-insert-fast-tracepoints
7449 @item set may-insert-fast-tracepoints on
7450 @itemx set may-insert-fast-tracepoints off
7451 This controls whether @value{GDBN} will attempt to insert fast
7452 tracepoints at the beginning of a tracing experiment. It affects only
7453 fast tracepoints, regular (non-fast) tracepoints being under the
7454 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7455
7456 @item show may-insert-fast-tracepoints
7457 Show the current permission to insert fast tracepoints.
7458
7459 @kindex may-interrupt
7460 @item set may-interrupt on
7461 @itemx set may-interrupt off
7462 This controls whether @value{GDBN} will attempt to interrupt or stop
7463 program execution. When this variable is @code{off}, the
7464 @code{interrupt} command will have no effect, nor will
7465 @kbd{Ctrl-c}. It defaults to @code{on}.
7466
7467 @item show may-interrupt
7468 Show the current permission to interrupt or stop the program.
7469
7470 @end table
7471
7472 @node Reverse Execution
7473 @chapter Running programs backward
7474 @cindex reverse execution
7475 @cindex running programs backward
7476
7477 When you are debugging a program, it is not unusual to realize that
7478 you have gone too far, and some event of interest has already happened.
7479 If the target environment supports it, @value{GDBN} can allow you to
7480 ``rewind'' the program by running it backward.
7481
7482 A target environment that supports reverse execution should be able
7483 to ``undo'' the changes in machine state that have taken place as the
7484 program was executing normally. Variables, registers etc.@: should
7485 revert to their previous values. Obviously this requires a great
7486 deal of sophistication on the part of the target environment; not
7487 all target environments can support reverse execution.
7488
7489 When a program is executed in reverse, the instructions that
7490 have most recently been executed are ``un-executed'', in reverse
7491 order. The program counter runs backward, following the previous
7492 thread of execution in reverse. As each instruction is ``un-executed'',
7493 the values of memory and/or registers that were changed by that
7494 instruction are reverted to their previous states. After executing
7495 a piece of source code in reverse, all side effects of that code
7496 should be ``undone'', and all variables should be returned to their
7497 prior values@footnote{
7498 Note that some side effects are easier to undo than others. For instance,
7499 memory and registers are relatively easy, but device I/O is hard. Some
7500 targets may be able undo things like device I/O, and some may not.
7501
7502 The contract between @value{GDBN} and the reverse executing target
7503 requires only that the target do something reasonable when
7504 @value{GDBN} tells it to execute backwards, and then report the
7505 results back to @value{GDBN}. Whatever the target reports back to
7506 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7507 assumes that the memory and registers that the target reports are in a
7508 consistent state, but @value{GDBN} accepts whatever it is given.
7509 }.
7510
7511 On some platforms, @value{GDBN} has built-in support for reverse
7512 execution, activated with the @code{record} or @code{record btrace}
7513 commands. @xref{Process Record and Replay}. Some remote targets,
7514 typically full system emulators, support reverse execution directly
7515 without requiring any special command.
7516
7517 If you are debugging in a target environment that supports
7518 reverse execution, @value{GDBN} provides the following commands.
7519
7520 @table @code
7521 @kindex reverse-continue
7522 @kindex rc @r{(@code{reverse-continue})}
7523 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7524 @itemx rc @r{[}@var{ignore-count}@r{]}
7525 Beginning at the point where your program last stopped, start executing
7526 in reverse. Reverse execution will stop for breakpoints and synchronous
7527 exceptions (signals), just like normal execution. Behavior of
7528 asynchronous signals depends on the target environment.
7529
7530 @kindex reverse-step
7531 @kindex rs @r{(@code{step})}
7532 @item reverse-step @r{[}@var{count}@r{]}
7533 Run the program backward until control reaches the start of a
7534 different source line; then stop it, and return control to @value{GDBN}.
7535
7536 Like the @code{step} command, @code{reverse-step} will only stop
7537 at the beginning of a source line. It ``un-executes'' the previously
7538 executed source line. If the previous source line included calls to
7539 debuggable functions, @code{reverse-step} will step (backward) into
7540 the called function, stopping at the beginning of the @emph{last}
7541 statement in the called function (typically a return statement).
7542
7543 Also, as with the @code{step} command, if non-debuggable functions are
7544 called, @code{reverse-step} will run thru them backward without stopping.
7545
7546 @kindex reverse-stepi
7547 @kindex rsi @r{(@code{reverse-stepi})}
7548 @item reverse-stepi @r{[}@var{count}@r{]}
7549 Reverse-execute one machine instruction. Note that the instruction
7550 to be reverse-executed is @emph{not} the one pointed to by the program
7551 counter, but the instruction executed prior to that one. For instance,
7552 if the last instruction was a jump, @code{reverse-stepi} will take you
7553 back from the destination of the jump to the jump instruction itself.
7554
7555 @kindex reverse-next
7556 @kindex rn @r{(@code{reverse-next})}
7557 @item reverse-next @r{[}@var{count}@r{]}
7558 Run backward to the beginning of the previous line executed in
7559 the current (innermost) stack frame. If the line contains function
7560 calls, they will be ``un-executed'' without stopping. Starting from
7561 the first line of a function, @code{reverse-next} will take you back
7562 to the caller of that function, @emph{before} the function was called,
7563 just as the normal @code{next} command would take you from the last
7564 line of a function back to its return to its caller
7565 @footnote{Unless the code is too heavily optimized.}.
7566
7567 @kindex reverse-nexti
7568 @kindex rni @r{(@code{reverse-nexti})}
7569 @item reverse-nexti @r{[}@var{count}@r{]}
7570 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7571 in reverse, except that called functions are ``un-executed'' atomically.
7572 That is, if the previously executed instruction was a return from
7573 another function, @code{reverse-nexti} will continue to execute
7574 in reverse until the call to that function (from the current stack
7575 frame) is reached.
7576
7577 @kindex reverse-finish
7578 @item reverse-finish
7579 Just as the @code{finish} command takes you to the point where the
7580 current function returns, @code{reverse-finish} takes you to the point
7581 where it was called. Instead of ending up at the end of the current
7582 function invocation, you end up at the beginning.
7583
7584 @kindex set exec-direction
7585 @item set exec-direction
7586 Set the direction of target execution.
7587 @item set exec-direction reverse
7588 @cindex execute forward or backward in time
7589 @value{GDBN} will perform all execution commands in reverse, until the
7590 exec-direction mode is changed to ``forward''. Affected commands include
7591 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7592 command cannot be used in reverse mode.
7593 @item set exec-direction forward
7594 @value{GDBN} will perform all execution commands in the normal fashion.
7595 This is the default.
7596 @end table
7597
7598
7599 @node Process Record and Replay
7600 @chapter Recording Inferior's Execution and Replaying It
7601 @cindex process record and replay
7602 @cindex recording inferior's execution and replaying it
7603
7604 On some platforms, @value{GDBN} provides a special @dfn{process record
7605 and replay} target that can record a log of the process execution, and
7606 replay it later with both forward and reverse execution commands.
7607
7608 @cindex replay mode
7609 When this target is in use, if the execution log includes the record
7610 for the next instruction, @value{GDBN} will debug in @dfn{replay
7611 mode}. In the replay mode, the inferior does not really execute code
7612 instructions. Instead, all the events that normally happen during
7613 code execution are taken from the execution log. While code is not
7614 really executed in replay mode, the values of registers (including the
7615 program counter register) and the memory of the inferior are still
7616 changed as they normally would. Their contents are taken from the
7617 execution log.
7618
7619 @cindex record mode
7620 If the record for the next instruction is not in the execution log,
7621 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7622 inferior executes normally, and @value{GDBN} records the execution log
7623 for future replay.
7624
7625 The process record and replay target supports reverse execution
7626 (@pxref{Reverse Execution}), even if the platform on which the
7627 inferior runs does not. However, the reverse execution is limited in
7628 this case by the range of the instructions recorded in the execution
7629 log. In other words, reverse execution on platforms that don't
7630 support it directly can only be done in the replay mode.
7631
7632 When debugging in the reverse direction, @value{GDBN} will work in
7633 replay mode as long as the execution log includes the record for the
7634 previous instruction; otherwise, it will work in record mode, if the
7635 platform supports reverse execution, or stop if not.
7636
7637 Currently, process record and replay is supported on ARM, Aarch64,
7638 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7639 GNU/Linux. Process record and replay can be used both when native
7640 debugging, and when remote debugging via @code{gdbserver}.
7641
7642 For architecture environments that support process record and replay,
7643 @value{GDBN} provides the following commands:
7644
7645 @table @code
7646 @kindex target record
7647 @kindex target record-full
7648 @kindex target record-btrace
7649 @kindex record
7650 @kindex record full
7651 @kindex record btrace
7652 @kindex record btrace bts
7653 @kindex record btrace pt
7654 @kindex record bts
7655 @kindex record pt
7656 @kindex rec
7657 @kindex rec full
7658 @kindex rec btrace
7659 @kindex rec btrace bts
7660 @kindex rec btrace pt
7661 @kindex rec bts
7662 @kindex rec pt
7663 @item record @var{method}
7664 This command starts the process record and replay target. The
7665 recording method can be specified as parameter. Without a parameter
7666 the command uses the @code{full} recording method. The following
7667 recording methods are available:
7668
7669 @table @code
7670 @item full
7671 Full record/replay recording using @value{GDBN}'s software record and
7672 replay implementation. This method allows replaying and reverse
7673 execution.
7674
7675 @item btrace @var{format}
7676 Hardware-supported instruction recording, supported on Intel
7677 processors. This method does not record data. Further, the data is
7678 collected in a ring buffer so old data will be overwritten when the
7679 buffer is full. It allows limited reverse execution. Variables and
7680 registers are not available during reverse execution. In remote
7681 debugging, recording continues on disconnect. Recorded data can be
7682 inspected after reconnecting. The recording may be stopped using
7683 @code{record stop}.
7684
7685 The recording format can be specified as parameter. Without a parameter
7686 the command chooses the recording format. The following recording
7687 formats are available:
7688
7689 @table @code
7690 @item bts
7691 @cindex branch trace store
7692 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7693 this format, the processor stores a from/to record for each executed
7694 branch in the btrace ring buffer.
7695
7696 @item pt
7697 @cindex Intel Processor Trace
7698 Use the @dfn{Intel Processor Trace} recording format. In this
7699 format, the processor stores the execution trace in a compressed form
7700 that is afterwards decoded by @value{GDBN}.
7701
7702 The trace can be recorded with very low overhead. The compressed
7703 trace format also allows small trace buffers to already contain a big
7704 number of instructions compared to @acronym{BTS}.
7705
7706 Decoding the recorded execution trace, on the other hand, is more
7707 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7708 increased number of instructions to process. You should increase the
7709 buffer-size with care.
7710 @end table
7711
7712 Not all recording formats may be available on all processors.
7713 @end table
7714
7715 The process record and replay target can only debug a process that is
7716 already running. Therefore, you need first to start the process with
7717 the @kbd{run} or @kbd{start} commands, and then start the recording
7718 with the @kbd{record @var{method}} command.
7719
7720 @cindex displaced stepping, and process record and replay
7721 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7722 will be automatically disabled when process record and replay target
7723 is started. That's because the process record and replay target
7724 doesn't support displaced stepping.
7725
7726 @cindex non-stop mode, and process record and replay
7727 @cindex asynchronous execution, and process record and replay
7728 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7729 the asynchronous execution mode (@pxref{Background Execution}), not
7730 all recording methods are available. The @code{full} recording method
7731 does not support these two modes.
7732
7733 @kindex record stop
7734 @kindex rec s
7735 @item record stop
7736 Stop the process record and replay target. When process record and
7737 replay target stops, the entire execution log will be deleted and the
7738 inferior will either be terminated, or will remain in its final state.
7739
7740 When you stop the process record and replay target in record mode (at
7741 the end of the execution log), the inferior will be stopped at the
7742 next instruction that would have been recorded. In other words, if
7743 you record for a while and then stop recording, the inferior process
7744 will be left in the same state as if the recording never happened.
7745
7746 On the other hand, if the process record and replay target is stopped
7747 while in replay mode (that is, not at the end of the execution log,
7748 but at some earlier point), the inferior process will become ``live''
7749 at that earlier state, and it will then be possible to continue the
7750 usual ``live'' debugging of the process from that state.
7751
7752 When the inferior process exits, or @value{GDBN} detaches from it,
7753 process record and replay target will automatically stop itself.
7754
7755 @kindex record goto
7756 @item record goto
7757 Go to a specific location in the execution log. There are several
7758 ways to specify the location to go to:
7759
7760 @table @code
7761 @item record goto begin
7762 @itemx record goto start
7763 Go to the beginning of the execution log.
7764
7765 @item record goto end
7766 Go to the end of the execution log.
7767
7768 @item record goto @var{n}
7769 Go to instruction number @var{n} in the execution log.
7770 @end table
7771
7772 @kindex record save
7773 @item record save @var{filename}
7774 Save the execution log to a file @file{@var{filename}}.
7775 Default filename is @file{gdb_record.@var{process_id}}, where
7776 @var{process_id} is the process ID of the inferior.
7777
7778 This command may not be available for all recording methods.
7779
7780 @kindex record restore
7781 @item record restore @var{filename}
7782 Restore the execution log from a file @file{@var{filename}}.
7783 File must have been created with @code{record save}.
7784
7785 @kindex set record full
7786 @item set record full insn-number-max @var{limit}
7787 @itemx set record full insn-number-max unlimited
7788 Set the limit of instructions to be recorded for the @code{full}
7789 recording method. Default value is 200000.
7790
7791 If @var{limit} is a positive number, then @value{GDBN} will start
7792 deleting instructions from the log once the number of the record
7793 instructions becomes greater than @var{limit}. For every new recorded
7794 instruction, @value{GDBN} will delete the earliest recorded
7795 instruction to keep the number of recorded instructions at the limit.
7796 (Since deleting recorded instructions loses information, @value{GDBN}
7797 lets you control what happens when the limit is reached, by means of
7798 the @code{stop-at-limit} option, described below.)
7799
7800 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7801 delete recorded instructions from the execution log. The number of
7802 recorded instructions is limited only by the available memory.
7803
7804 @kindex show record full
7805 @item show record full insn-number-max
7806 Show the limit of instructions to be recorded with the @code{full}
7807 recording method.
7808
7809 @item set record full stop-at-limit
7810 Control the behavior of the @code{full} recording method when the
7811 number of recorded instructions reaches the limit. If ON (the
7812 default), @value{GDBN} will stop when the limit is reached for the
7813 first time and ask you whether you want to stop the inferior or
7814 continue running it and recording the execution log. If you decide
7815 to continue recording, each new recorded instruction will cause the
7816 oldest one to be deleted.
7817
7818 If this option is OFF, @value{GDBN} will automatically delete the
7819 oldest record to make room for each new one, without asking.
7820
7821 @item show record full stop-at-limit
7822 Show the current setting of @code{stop-at-limit}.
7823
7824 @item set record full memory-query
7825 Control the behavior when @value{GDBN} is unable to record memory
7826 changes caused by an instruction for the @code{full} recording method.
7827 If ON, @value{GDBN} will query whether to stop the inferior in that
7828 case.
7829
7830 If this option is OFF (the default), @value{GDBN} will automatically
7831 ignore the effect of such instructions on memory. Later, when
7832 @value{GDBN} replays this execution log, it will mark the log of this
7833 instruction as not accessible, and it will not affect the replay
7834 results.
7835
7836 @item show record full memory-query
7837 Show the current setting of @code{memory-query}.
7838
7839 @kindex set record btrace
7840 The @code{btrace} record target does not trace data. As a
7841 convenience, when replaying, @value{GDBN} reads read-only memory off
7842 the live program directly, assuming that the addresses of the
7843 read-only areas don't change. This for example makes it possible to
7844 disassemble code while replaying, but not to print variables.
7845 In some cases, being able to inspect variables might be useful.
7846 You can use the following command for that:
7847
7848 @item set record btrace replay-memory-access
7849 Control the behavior of the @code{btrace} recording method when
7850 accessing memory during replay. If @code{read-only} (the default),
7851 @value{GDBN} will only allow accesses to read-only memory.
7852 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7853 and to read-write memory. Beware that the accessed memory corresponds
7854 to the live target and not necessarily to the current replay
7855 position.
7856
7857 @item set record btrace cpu @var{identifier}
7858 Set the processor to be used for enabling workarounds for processor
7859 errata when decoding the trace.
7860
7861 Processor errata are defects in processor operation, caused by its
7862 design or manufacture. They can cause a trace not to match the
7863 specification. This, in turn, may cause trace decode to fail.
7864 @value{GDBN} can detect erroneous trace packets and correct them, thus
7865 avoiding the decoding failures. These corrections are known as
7866 @dfn{errata workarounds}, and are enabled based on the processor on
7867 which the trace was recorded.
7868
7869 By default, @value{GDBN} attempts to detect the processor
7870 automatically, and apply the necessary workarounds for it. However,
7871 you may need to specify the processor if @value{GDBN} does not yet
7872 support it. This command allows you to do that, and also allows to
7873 disable the workarounds.
7874
7875 The argument @var{identifier} identifies the @sc{cpu} and is of the
7876 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7877 there are two special identifiers, @code{none} and @code{auto}
7878 (default).
7879
7880 The following vendor identifiers and corresponding processor
7881 identifiers are currently supported:
7882
7883 @multitable @columnfractions .1 .9
7884
7885 @item @code{intel}
7886 @tab @var{family}/@var{model}[/@var{stepping}]
7887
7888 @end multitable
7889
7890 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7891 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7892
7893 If @var{identifier} is @code{auto}, enable errata workarounds for the
7894 processor on which the trace was recorded. If @var{identifier} is
7895 @code{none}, errata workarounds are disabled.
7896
7897 For example, when using an old @value{GDBN} on a new system, decode
7898 may fail because @value{GDBN} does not support the new processor. It
7899 often suffices to specify an older processor that @value{GDBN}
7900 supports.
7901
7902 @smallexample
7903 (@value{GDBP}) info record
7904 Active record target: record-btrace
7905 Recording format: Intel Processor Trace.
7906 Buffer size: 16kB.
7907 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7908 (@value{GDBP}) set record btrace cpu intel:6/158
7909 (@value{GDBP}) info record
7910 Active record target: record-btrace
7911 Recording format: Intel Processor Trace.
7912 Buffer size: 16kB.
7913 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7914 @end smallexample
7915
7916 @kindex show record btrace
7917 @item show record btrace replay-memory-access
7918 Show the current setting of @code{replay-memory-access}.
7919
7920 @item show record btrace cpu
7921 Show the processor to be used for enabling trace decode errata
7922 workarounds.
7923
7924 @kindex set record btrace bts
7925 @item set record btrace bts buffer-size @var{size}
7926 @itemx set record btrace bts buffer-size unlimited
7927 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7928 format. Default is 64KB.
7929
7930 If @var{size} is a positive number, then @value{GDBN} will try to
7931 allocate a buffer of at least @var{size} bytes for each new thread
7932 that uses the btrace recording method and the @acronym{BTS} format.
7933 The actually obtained buffer size may differ from the requested
7934 @var{size}. Use the @code{info record} command to see the actual
7935 buffer size for each thread that uses the btrace recording method and
7936 the @acronym{BTS} format.
7937
7938 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7939 allocate a buffer of 4MB.
7940
7941 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7942 also need longer to process the branch trace data before it can be used.
7943
7944 @item show record btrace bts buffer-size @var{size}
7945 Show the current setting of the requested ring buffer size for branch
7946 tracing in @acronym{BTS} format.
7947
7948 @kindex set record btrace pt
7949 @item set record btrace pt buffer-size @var{size}
7950 @itemx set record btrace pt buffer-size unlimited
7951 Set the requested ring buffer size for branch tracing in Intel
7952 Processor Trace format. Default is 16KB.
7953
7954 If @var{size} is a positive number, then @value{GDBN} will try to
7955 allocate a buffer of at least @var{size} bytes for each new thread
7956 that uses the btrace recording method and the Intel Processor Trace
7957 format. The actually obtained buffer size may differ from the
7958 requested @var{size}. Use the @code{info record} command to see the
7959 actual buffer size for each thread.
7960
7961 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7962 allocate a buffer of 4MB.
7963
7964 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7965 also need longer to process the branch trace data before it can be used.
7966
7967 @item show record btrace pt buffer-size @var{size}
7968 Show the current setting of the requested ring buffer size for branch
7969 tracing in Intel Processor Trace format.
7970
7971 @kindex info record
7972 @item info record
7973 Show various statistics about the recording depending on the recording
7974 method:
7975
7976 @table @code
7977 @item full
7978 For the @code{full} recording method, it shows the state of process
7979 record and its in-memory execution log buffer, including:
7980
7981 @itemize @bullet
7982 @item
7983 Whether in record mode or replay mode.
7984 @item
7985 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7986 @item
7987 Highest recorded instruction number.
7988 @item
7989 Current instruction about to be replayed (if in replay mode).
7990 @item
7991 Number of instructions contained in the execution log.
7992 @item
7993 Maximum number of instructions that may be contained in the execution log.
7994 @end itemize
7995
7996 @item btrace
7997 For the @code{btrace} recording method, it shows:
7998
7999 @itemize @bullet
8000 @item
8001 Recording format.
8002 @item
8003 Number of instructions that have been recorded.
8004 @item
8005 Number of blocks of sequential control-flow formed by the recorded
8006 instructions.
8007 @item
8008 Whether in record mode or replay mode.
8009 @end itemize
8010
8011 For the @code{bts} recording format, it also shows:
8012 @itemize @bullet
8013 @item
8014 Size of the perf ring buffer.
8015 @end itemize
8016
8017 For the @code{pt} recording format, it also shows:
8018 @itemize @bullet
8019 @item
8020 Size of the perf ring buffer.
8021 @end itemize
8022 @end table
8023
8024 @kindex record delete
8025 @kindex rec del
8026 @item record delete
8027 When record target runs in replay mode (``in the past''), delete the
8028 subsequent execution log and begin to record a new execution log starting
8029 from the current address. This means you will abandon the previously
8030 recorded ``future'' and begin recording a new ``future''.
8031
8032 @kindex record instruction-history
8033 @kindex rec instruction-history
8034 @item record instruction-history
8035 Disassembles instructions from the recorded execution log. By
8036 default, ten instructions are disassembled. This can be changed using
8037 the @code{set record instruction-history-size} command. Instructions
8038 are printed in execution order.
8039
8040 It can also print mixed source+disassembly if you specify the the
8041 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
8042 as well as in symbolic form by specifying the @code{/r} or @code{/b}
8043 modifier. The behaviour of the @code{/m}, @code{/s}, @code{/r}, and
8044 @code{/b} modifiers are the same as for the @kbd{disassemble} command
8045 (@pxref{disassemble,,@kbd{disassemble}}).
8046
8047 The current position marker is printed for the instruction at the
8048 current program counter value. This instruction can appear multiple
8049 times in the trace and the current position marker will be printed
8050 every time. To omit the current position marker, specify the
8051 @code{/p} modifier.
8052
8053 To better align the printed instructions when the trace contains
8054 instructions from more than one function, the function name may be
8055 omitted by specifying the @code{/f} modifier.
8056
8057 Speculatively executed instructions are prefixed with @samp{?}. This
8058 feature is not available for all recording formats.
8059
8060 There are several ways to specify what part of the execution log to
8061 disassemble:
8062
8063 @table @code
8064 @item record instruction-history @var{insn}
8065 Disassembles ten instructions starting from instruction number
8066 @var{insn}.
8067
8068 @item record instruction-history @var{insn}, +/-@var{n}
8069 Disassembles @var{n} instructions around instruction number
8070 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
8071 @var{n} instructions after instruction number @var{insn}. If
8072 @var{n} is preceded with @code{-}, disassembles @var{n}
8073 instructions before instruction number @var{insn}.
8074
8075 @item record instruction-history
8076 Disassembles ten more instructions after the last disassembly.
8077
8078 @item record instruction-history -
8079 Disassembles ten more instructions before the last disassembly.
8080
8081 @item record instruction-history @var{begin}, @var{end}
8082 Disassembles instructions beginning with instruction number
8083 @var{begin} until instruction number @var{end}. The instruction
8084 number @var{end} is included.
8085 @end table
8086
8087 This command may not be available for all recording methods.
8088
8089 @kindex set record
8090 @item set record instruction-history-size @var{size}
8091 @itemx set record instruction-history-size unlimited
8092 Define how many instructions to disassemble in the @code{record
8093 instruction-history} command. The default value is 10.
8094 A @var{size} of @code{unlimited} means unlimited instructions.
8095
8096 @kindex show record
8097 @item show record instruction-history-size
8098 Show how many instructions to disassemble in the @code{record
8099 instruction-history} command.
8100
8101 @kindex record function-call-history
8102 @kindex rec function-call-history
8103 @item record function-call-history
8104 Prints the execution history at function granularity. For each sequence
8105 of instructions that belong to the same function, it prints the name of
8106 that function, the source lines for this instruction sequence (if the
8107 @code{/l} modifier is specified), and the instructions numbers that form
8108 the sequence (if the @code{/i} modifier is specified). The function names
8109 are indented to reflect the call stack depth if the @code{/c} modifier is
8110 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be given
8111 together.
8112
8113 @smallexample
8114 (@value{GDBP}) @b{list 1, 10}
8115 1 void foo (void)
8116 2 @{
8117 3 @}
8118 4
8119 5 void bar (void)
8120 6 @{
8121 7 ...
8122 8 foo ();
8123 9 ...
8124 10 @}
8125 (@value{GDBP}) @b{record function-call-history /ilc}
8126 1 bar inst 1,4 at foo.c:6,8
8127 2 foo inst 5,10 at foo.c:2,3
8128 3 bar inst 11,13 at foo.c:9,10
8129 @end smallexample
8130
8131 By default, ten functions are printed. This can be changed using the
8132 @code{set record function-call-history-size} command. Functions are
8133 printed in execution order. There are several ways to specify what
8134 to print:
8135
8136 @table @code
8137 @item record function-call-history @var{func}
8138 Prints ten functions starting from function number @var{func}.
8139
8140 @item record function-call-history @var{func}, +/-@var{n}
8141 Prints @var{n} functions around function number @var{func}. If
8142 @var{n} is preceded with @code{+}, prints @var{n} functions after
8143 function number @var{func}. If @var{n} is preceded with @code{-},
8144 prints @var{n} functions before function number @var{func}.
8145
8146 @item record function-call-history
8147 Prints ten more functions after the last ten-function print.
8148
8149 @item record function-call-history -
8150 Prints ten more functions before the last ten-function print.
8151
8152 @item record function-call-history @var{begin}, @var{end}
8153 Prints functions beginning with function number @var{begin} until
8154 function number @var{end}. The function number @var{end} is included.
8155 @end table
8156
8157 This command may not be available for all recording methods.
8158
8159 @item set record function-call-history-size @var{size}
8160 @itemx set record function-call-history-size unlimited
8161 Define how many functions to print in the
8162 @code{record function-call-history} command. The default value is 10.
8163 A size of @code{unlimited} means unlimited functions.
8164
8165 @item show record function-call-history-size
8166 Show how many functions to print in the
8167 @code{record function-call-history} command.
8168 @end table
8169
8170
8171 @node Stack
8172 @chapter Examining the Stack
8173
8174 When your program has stopped, the first thing you need to know is where it
8175 stopped and how it got there.
8176
8177 @cindex call stack
8178 Each time your program performs a function call, information about the call
8179 is generated.
8180 That information includes the location of the call in your program,
8181 the arguments of the call,
8182 and the local variables of the function being called.
8183 The information is saved in a block of data called a @dfn{stack frame}.
8184 The stack frames are allocated in a region of memory called the @dfn{call
8185 stack}.
8186
8187 When your program stops, the @value{GDBN} commands for examining the
8188 stack allow you to see all of this information.
8189
8190 @cindex selected frame
8191 One of the stack frames is @dfn{selected} by @value{GDBN} and many
8192 @value{GDBN} commands refer implicitly to the selected frame. In
8193 particular, whenever you ask @value{GDBN} for the value of a variable in
8194 your program, the value is found in the selected frame. There are
8195 special @value{GDBN} commands to select whichever frame you are
8196 interested in. @xref{Selection, ,Selecting a Frame}.
8197
8198 When your program stops, @value{GDBN} automatically selects the
8199 currently executing frame and describes it briefly, similar to the
8200 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
8201
8202 @menu
8203 * Frames:: Stack frames
8204 * Backtrace:: Backtraces
8205 * Selection:: Selecting a frame
8206 * Frame Info:: Information on a frame
8207 * Frame Apply:: Applying a command to several frames
8208 * Frame Filter Management:: Managing frame filters
8209
8210 @end menu
8211
8212 @node Frames
8213 @section Stack Frames
8214
8215 @cindex frame, definition
8216 @cindex stack frame
8217 The call stack is divided up into contiguous pieces called @dfn{stack
8218 frames}, or @dfn{frames} for short; each frame is the data associated
8219 with one call to one function. The frame contains the arguments given
8220 to the function, the function's local variables, and the address at
8221 which the function is executing.
8222
8223 @cindex initial frame
8224 @cindex outermost frame
8225 @cindex innermost frame
8226 When your program is started, the stack has only one frame, that of the
8227 function @code{main}. This is called the @dfn{initial} frame or the
8228 @dfn{outermost} frame. Each time a function is called, a new frame is
8229 made. Each time a function returns, the frame for that function invocation
8230 is eliminated. If a function is recursive, there can be many frames for
8231 the same function. The frame for the function in which execution is
8232 actually occurring is called the @dfn{innermost} frame. This is the most
8233 recently created of all the stack frames that still exist.
8234
8235 @cindex frame pointer
8236 Inside your program, stack frames are identified by their addresses. A
8237 stack frame consists of many bytes, each of which has its own address; each
8238 kind of computer has a convention for choosing one byte whose
8239 address serves as the address of the frame. Usually this address is kept
8240 in a register called the @dfn{frame pointer register}
8241 (@pxref{Registers, $fp}) while execution is going on in that frame.
8242
8243 @cindex frame level
8244 @cindex frame number
8245 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8246 number that is zero for the innermost frame, one for the frame that
8247 called it, and so on upward. These level numbers give you a way of
8248 designating stack frames in @value{GDBN} commands. The terms
8249 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8250 describe this number.
8251
8252 @c The -fomit-frame-pointer below perennially causes hbox overflow
8253 @c underflow problems.
8254 @cindex frameless execution
8255 Some compilers provide a way to compile functions so that they operate
8256 without stack frames. (For example, the @value{NGCC} option
8257 @smallexample
8258 @samp{-fomit-frame-pointer}
8259 @end smallexample
8260 generates functions without a frame.)
8261 This is occasionally done with heavily used library functions to save
8262 the frame setup time. @value{GDBN} has limited facilities for dealing
8263 with these function invocations. If the innermost function invocation
8264 has no stack frame, @value{GDBN} nevertheless regards it as though
8265 it had a separate frame, which is numbered zero as usual, allowing
8266 correct tracing of the function call chain. However, @value{GDBN} has
8267 no provision for frameless functions elsewhere in the stack.
8268
8269 @node Backtrace
8270 @section Backtraces
8271
8272 @cindex traceback
8273 @cindex call stack traces
8274 A backtrace is a summary of how your program got where it is. It shows one
8275 line per frame, for many frames, starting with the currently executing
8276 frame (frame zero), followed by its caller (frame one), and on up the
8277 stack.
8278
8279 @anchor{backtrace-command}
8280 @kindex backtrace
8281 @kindex bt @r{(@code{backtrace})}
8282 To print a backtrace of the entire stack, use the @code{backtrace}
8283 command, or its alias @code{bt}. This command will print one line per
8284 frame for frames in the stack. By default, all stack frames are
8285 printed. You can stop the backtrace at any time by typing the system
8286 interrupt character, normally @kbd{Ctrl-c}.
8287
8288 @table @code
8289 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8290 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8291 Print the backtrace of the entire stack.
8292
8293 The optional @var{count} can be one of the following:
8294
8295 @table @code
8296 @item @var{n}
8297 @itemx @var{n}
8298 Print only the innermost @var{n} frames, where @var{n} is a positive
8299 number.
8300
8301 @item -@var{n}
8302 @itemx -@var{n}
8303 Print only the outermost @var{n} frames, where @var{n} is a positive
8304 number.
8305 @end table
8306
8307 Options:
8308
8309 @table @code
8310 @item -full
8311 Print the values of the local variables also. This can be combined
8312 with the optional @var{count} to limit the number of frames shown.
8313
8314 @item -no-filters
8315 Do not run Python frame filters on this backtrace. @xref{Frame
8316 Filter API}, for more information. Additionally use @ref{disable
8317 frame-filter all} to turn off all frame filters. This is only
8318 relevant when @value{GDBN} has been configured with @code{Python}
8319 support.
8320
8321 @item -hide
8322 A Python frame filter might decide to ``elide'' some frames. Normally
8323 such elided frames are still printed, but they are indented relative
8324 to the filtered frames that cause them to be elided. The @code{-hide}
8325 option causes elided frames to not be printed at all.
8326 @end table
8327
8328 The @code{backtrace} command also supports a number of options that
8329 allow overriding relevant global print settings as set by @code{set
8330 backtrace} and @code{set print} subcommands:
8331
8332 @table @code
8333 @item -past-main [@code{on}|@code{off}]
8334 Set whether backtraces should continue past @code{main}. Related setting:
8335 @ref{set backtrace past-main}.
8336
8337 @item -past-entry [@code{on}|@code{off}]
8338 Set whether backtraces should continue past the entry point of a program.
8339 Related setting: @ref{set backtrace past-entry}.
8340
8341 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8342 Set printing of function arguments at function entry.
8343 Related setting: @ref{set print entry-values}.
8344
8345 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8346 Set printing of non-scalar frame arguments.
8347 Related setting: @ref{set print frame-arguments}.
8348
8349 @item -raw-frame-arguments [@code{on}|@code{off}]
8350 Set whether to print frame arguments in raw form.
8351 Related setting: @ref{set print raw-frame-arguments}.
8352
8353 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8354 Set printing of frame information.
8355 Related setting: @ref{set print frame-info}.
8356 @end table
8357
8358 The optional @var{qualifier} is maintained for backward compatibility.
8359 It can be one of the following:
8360
8361 @table @code
8362 @item full
8363 Equivalent to the @code{-full} option.
8364
8365 @item no-filters
8366 Equivalent to the @code{-no-filters} option.
8367
8368 @item hide
8369 Equivalent to the @code{-hide} option.
8370 @end table
8371
8372 @end table
8373
8374 @kindex where
8375 @kindex info stack
8376 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8377 are additional aliases for @code{backtrace}.
8378
8379 @cindex multiple threads, backtrace
8380 In a multi-threaded program, @value{GDBN} by default shows the
8381 backtrace only for the current thread. To display the backtrace for
8382 several or all of the threads, use the command @code{thread apply}
8383 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8384 apply all backtrace}, @value{GDBN} will display the backtrace for all
8385 the threads; this is handy when you debug a core dump of a
8386 multi-threaded program.
8387
8388 Each line in the backtrace shows the frame number and the function name.
8389 The program counter value is also shown---unless you use @code{set
8390 print address off}. The backtrace also shows the source file name and
8391 line number, as well as the arguments to the function. The program
8392 counter value is omitted if it is at the beginning of the code for that
8393 line number.
8394
8395 Here is an example of a backtrace. It was made with the command
8396 @samp{bt 3}, so it shows the innermost three frames.
8397
8398 @smallexample
8399 @group
8400 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8401 at builtin.c:993
8402 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8403 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8404 at macro.c:71
8405 (More stack frames follow...)
8406 @end group
8407 @end smallexample
8408
8409 @noindent
8410 The display for frame zero does not begin with a program counter
8411 value, indicating that your program has stopped at the beginning of the
8412 code for line @code{993} of @code{builtin.c}.
8413
8414 @noindent
8415 The value of parameter @code{data} in frame 1 has been replaced by
8416 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8417 only if it is a scalar (integer, pointer, enumeration, etc). See command
8418 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8419 on how to configure the way function parameter values are printed.
8420 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8421 what frame information is printed.
8422
8423 @cindex optimized out, in backtrace
8424 @cindex function call arguments, optimized out
8425 If your program was compiled with optimizations, some compilers will
8426 optimize away arguments passed to functions if those arguments are
8427 never used after the call. Such optimizations generate code that
8428 passes arguments through registers, but doesn't store those arguments
8429 in the stack frame. @value{GDBN} has no way of displaying such
8430 arguments in stack frames other than the innermost one. Here's what
8431 such a backtrace might look like:
8432
8433 @smallexample
8434 @group
8435 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8436 at builtin.c:993
8437 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8438 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8439 at macro.c:71
8440 (More stack frames follow...)
8441 @end group
8442 @end smallexample
8443
8444 @noindent
8445 The values of arguments that were not saved in their stack frames are
8446 shown as @samp{<optimized out>}.
8447
8448 If you need to display the values of such optimized-out arguments,
8449 either deduce that from other variables whose values depend on the one
8450 you are interested in, or recompile without optimizations.
8451
8452 @cindex backtrace beyond @code{main} function
8453 @cindex program entry point
8454 @cindex startup code, and backtrace
8455 Most programs have a standard user entry point---a place where system
8456 libraries and startup code transition into user code. For C this is
8457 @code{main}@footnote{
8458 Note that embedded programs (the so-called ``free-standing''
8459 environment) are not required to have a @code{main} function as the
8460 entry point. They could even have multiple entry points.}.
8461 When @value{GDBN} finds the entry function in a backtrace
8462 it will terminate the backtrace, to avoid tracing into highly
8463 system-specific (and generally uninteresting) code.
8464
8465 If you need to examine the startup code, or limit the number of levels
8466 in a backtrace, you can change this behavior:
8467
8468 @table @code
8469 @item set backtrace past-main
8470 @itemx set backtrace past-main on
8471 @anchor{set backtrace past-main}
8472 @kindex set backtrace
8473 Backtraces will continue past the user entry point.
8474
8475 @item set backtrace past-main off
8476 Backtraces will stop when they encounter the user entry point. This is the
8477 default.
8478
8479 @item show backtrace past-main
8480 @kindex show backtrace
8481 Display the current user entry point backtrace policy.
8482
8483 @item set backtrace past-entry
8484 @itemx set backtrace past-entry on
8485 @anchor{set backtrace past-entry}
8486 Backtraces will continue past the internal entry point of an application.
8487 This entry point is encoded by the linker when the application is built,
8488 and is likely before the user entry point @code{main} (or equivalent) is called.
8489
8490 @item set backtrace past-entry off
8491 Backtraces will stop when they encounter the internal entry point of an
8492 application. This is the default.
8493
8494 @item show backtrace past-entry
8495 Display the current internal entry point backtrace policy.
8496
8497 @item set backtrace limit @var{n}
8498 @itemx set backtrace limit 0
8499 @itemx set backtrace limit unlimited
8500 @anchor{set backtrace limit}
8501 @cindex backtrace limit
8502 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8503 or zero means unlimited levels.
8504
8505 @item show backtrace limit
8506 Display the current limit on backtrace levels.
8507 @end table
8508
8509 You can control how file names are displayed.
8510
8511 @table @code
8512 @item set filename-display
8513 @itemx set filename-display relative
8514 @cindex filename-display
8515 Display file names relative to the compilation directory. This is the default.
8516
8517 @item set filename-display basename
8518 Display only basename of a filename.
8519
8520 @item set filename-display absolute
8521 Display an absolute filename.
8522
8523 @item show filename-display
8524 Show the current way to display filenames.
8525 @end table
8526
8527 @node Selection
8528 @section Selecting a Frame
8529
8530 Most commands for examining the stack and other data in your program work on
8531 whichever stack frame is selected at the moment. Here are the commands for
8532 selecting a stack frame; all of them finish by printing a brief description
8533 of the stack frame just selected.
8534
8535 @table @code
8536 @kindex frame@r{, selecting}
8537 @kindex f @r{(@code{frame})}
8538 @item frame @r{[} @var{frame-selection-spec} @r{]}
8539 @item f @r{[} @var{frame-selection-spec} @r{]}
8540 The @command{frame} command allows different stack frames to be
8541 selected. The @var{frame-selection-spec} can be any of the following:
8542
8543 @table @code
8544 @kindex frame level
8545 @item @var{num}
8546 @item level @var{num}
8547 Select frame level @var{num}. Recall that frame zero is the innermost
8548 (currently executing) frame, frame one is the frame that called the
8549 innermost one, and so on. The highest level frame is usually the one
8550 for @code{main}.
8551
8552 As this is the most common method of navigating the frame stack, the
8553 string @command{level} can be omitted. For example, the following two
8554 commands are equivalent:
8555
8556 @smallexample
8557 (@value{GDBP}) frame 3
8558 (@value{GDBP}) frame level 3
8559 @end smallexample
8560
8561 @kindex frame address
8562 @item address @var{stack-address}
8563 Select the frame with stack address @var{stack-address}. The
8564 @var{stack-address} for a frame can be seen in the output of
8565 @command{info frame}, for example:
8566
8567 @smallexample
8568 (@value{GDBP}) info frame
8569 Stack level 1, frame at 0x7fffffffda30:
8570 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8571 tail call frame, caller of frame at 0x7fffffffda30
8572 source language c++.
8573 Arglist at unknown address.
8574 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8575 @end smallexample
8576
8577 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8578 indicated by the line:
8579
8580 @smallexample
8581 Stack level 1, frame at 0x7fffffffda30:
8582 @end smallexample
8583
8584 @kindex frame function
8585 @item function @var{function-name}
8586 Select the stack frame for function @var{function-name}. If there are
8587 multiple stack frames for function @var{function-name} then the inner
8588 most stack frame is selected.
8589
8590 @kindex frame view
8591 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8592 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8593 viewed has stack address @var{stack-addr}, and optionally, a program
8594 counter address of @var{pc-addr}.
8595
8596 This is useful mainly if the chaining of stack frames has been
8597 damaged by a bug, making it impossible for @value{GDBN} to assign
8598 numbers properly to all frames. In addition, this can be useful
8599 when your program has multiple stacks and switches between them.
8600
8601 When viewing a frame outside the current backtrace using
8602 @command{frame view} then you can always return to the original
8603 stack using one of the previous stack frame selection instructions,
8604 for example @command{frame level 0}.
8605
8606 @end table
8607
8608 @kindex up
8609 @item up @var{n}
8610 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8611 numbers @var{n}, this advances toward the outermost frame, to higher
8612 frame numbers, to frames that have existed longer.
8613
8614 @kindex down
8615 @kindex do @r{(@code{down})}
8616 @item down @var{n}
8617 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8618 positive numbers @var{n}, this advances toward the innermost frame, to
8619 lower frame numbers, to frames that were created more recently.
8620 You may abbreviate @code{down} as @code{do}.
8621 @end table
8622
8623 All of these commands end by printing two lines of output describing the
8624 frame. The first line shows the frame number, the function name, the
8625 arguments, and the source file and line number of execution in that
8626 frame. The second line shows the text of that source line.
8627
8628 @need 1000
8629 For example:
8630
8631 @smallexample
8632 @group
8633 (@value{GDBP}) up
8634 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8635 at env.c:10
8636 10 read_input_file (argv[i]);
8637 @end group
8638 @end smallexample
8639
8640 After such a printout, the @code{list} command with no arguments
8641 prints ten lines centered on the point of execution in the frame.
8642 You can also edit the program at the point of execution with your favorite
8643 editing program by typing @code{edit}.
8644 @xref{List, ,Printing Source Lines},
8645 for details.
8646
8647 @table @code
8648 @kindex select-frame
8649 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8650 The @code{select-frame} command is a variant of @code{frame} that does
8651 not display the new frame after selecting it. This command is
8652 intended primarily for use in @value{GDBN} command scripts, where the
8653 output might be unnecessary and distracting. The
8654 @var{frame-selection-spec} is as for the @command{frame} command
8655 described in @ref{Selection, ,Selecting a Frame}.
8656
8657 @kindex down-silently
8658 @kindex up-silently
8659 @item up-silently @var{n}
8660 @itemx down-silently @var{n}
8661 These two commands are variants of @code{up} and @code{down},
8662 respectively; they differ in that they do their work silently, without
8663 causing display of the new frame. They are intended primarily for use
8664 in @value{GDBN} command scripts, where the output might be unnecessary and
8665 distracting.
8666 @end table
8667
8668 @node Frame Info
8669 @section Information About a Frame
8670
8671 There are several other commands to print information about the selected
8672 stack frame.
8673
8674 @table @code
8675 @item frame
8676 @itemx f
8677 When used without any argument, this command does not change which
8678 frame is selected, but prints a brief description of the currently
8679 selected stack frame. It can be abbreviated @code{f}. With an
8680 argument, this command is used to select a stack frame.
8681 @xref{Selection, ,Selecting a Frame}.
8682
8683 @kindex info frame
8684 @kindex info f @r{(@code{info frame})}
8685 @item info frame
8686 @itemx info f
8687 This command prints a verbose description of the selected stack frame,
8688 including:
8689
8690 @itemize @bullet
8691 @item
8692 the address of the frame
8693 @item
8694 the address of the next frame down (called by this frame)
8695 @item
8696 the address of the next frame up (caller of this frame)
8697 @item
8698 the language in which the source code corresponding to this frame is written
8699 @item
8700 the address of the frame's arguments
8701 @item
8702 the address of the frame's local variables
8703 @item
8704 the program counter saved in it (the address of execution in the caller frame)
8705 @item
8706 which registers were saved in the frame
8707 @end itemize
8708
8709 @noindent The verbose description is useful when
8710 something has gone wrong that has made the stack format fail to fit
8711 the usual conventions.
8712
8713 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8714 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8715 Print a verbose description of the frame selected by
8716 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8717 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8718 a Frame}). The selected frame remains unchanged by this command.
8719
8720 @kindex info args
8721 @item info args [-q]
8722 Print the arguments of the selected frame, each on a separate line.
8723
8724 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8725 printing header information and messages explaining why no argument
8726 have been printed.
8727
8728 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8729 Like @kbd{info args}, but only print the arguments selected
8730 with the provided regexp(s).
8731
8732 If @var{regexp} is provided, print only the arguments whose names
8733 match the regular expression @var{regexp}.
8734
8735 If @var{type_regexp} is provided, print only the arguments whose
8736 types, as printed by the @code{whatis} command, match
8737 the regular expression @var{type_regexp}.
8738 If @var{type_regexp} contains space(s), it should be enclosed in
8739 quote characters. If needed, use backslash to escape the meaning
8740 of special characters or quotes.
8741
8742 If both @var{regexp} and @var{type_regexp} are provided, an argument
8743 is printed only if its name matches @var{regexp} and its type matches
8744 @var{type_regexp}.
8745
8746 @item info locals [-q]
8747 @kindex info locals
8748 Print the local variables of the selected frame, each on a separate
8749 line. These are all variables (declared either static or automatic)
8750 accessible at the point of execution of the selected frame.
8751
8752 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8753 printing header information and messages explaining why no local variables
8754 have been printed.
8755
8756 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8757 Like @kbd{info locals}, but only print the local variables selected
8758 with the provided regexp(s).
8759
8760 If @var{regexp} is provided, print only the local variables whose names
8761 match the regular expression @var{regexp}.
8762
8763 If @var{type_regexp} is provided, print only the local variables whose
8764 types, as printed by the @code{whatis} command, match
8765 the regular expression @var{type_regexp}.
8766 If @var{type_regexp} contains space(s), it should be enclosed in
8767 quote characters. If needed, use backslash to escape the meaning
8768 of special characters or quotes.
8769
8770 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8771 is printed only if its name matches @var{regexp} and its type matches
8772 @var{type_regexp}.
8773
8774 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8775 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8776 For example, your program might use Resource Acquisition Is
8777 Initialization types (RAII) such as @code{lock_something_t}: each
8778 local variable of type @code{lock_something_t} automatically places a
8779 lock that is destroyed when the variable goes out of scope. You can
8780 then list all acquired locks in your program by doing
8781 @smallexample
8782 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8783 @end smallexample
8784 @noindent
8785 or the equivalent shorter form
8786 @smallexample
8787 tfaas i lo -q -t lock_something_t
8788 @end smallexample
8789
8790 @end table
8791
8792 @node Frame Apply
8793 @section Applying a Command to Several Frames.
8794 @kindex frame apply
8795 @cindex apply command to several frames
8796 @table @code
8797 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8798 The @code{frame apply} command allows you to apply the named
8799 @var{command} to one or more frames.
8800
8801 @table @code
8802 @item @code{all}
8803 Specify @code{all} to apply @var{command} to all frames.
8804
8805 @item @var{count}
8806 Use @var{count} to apply @var{command} to the innermost @var{count}
8807 frames, where @var{count} is a positive number.
8808
8809 @item @var{-count}
8810 Use @var{-count} to apply @var{command} to the outermost @var{count}
8811 frames, where @var{count} is a positive number.
8812
8813 @item @code{level}
8814 Use @code{level} to apply @var{command} to the set of frames identified
8815 by the @var{level} list. @var{level} is a frame level or a range of frame
8816 levels as @var{level1}-@var{level2}. The frame level is the number shown
8817 in the first field of the @samp{backtrace} command output.
8818 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8819 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8820
8821 @end table
8822
8823 Note that the frames on which @code{frame apply} applies a command are
8824 also influenced by the @code{set backtrace} settings such as @code{set
8825 backtrace past-main} and @code{set backtrace limit N}.
8826 @xref{Backtrace,,Backtraces}.
8827
8828 The @code{frame apply} command also supports a number of options that
8829 allow overriding relevant @code{set backtrace} settings:
8830
8831 @table @code
8832 @item -past-main [@code{on}|@code{off}]
8833 Whether backtraces should continue past @code{main}.
8834 Related setting: @ref{set backtrace past-main}.
8835
8836 @item -past-entry [@code{on}|@code{off}]
8837 Whether backtraces should continue past the entry point of a program.
8838 Related setting: @ref{set backtrace past-entry}.
8839 @end table
8840
8841 By default, @value{GDBN} displays some frame information before the
8842 output produced by @var{command}, and an error raised during the
8843 execution of a @var{command} will abort @code{frame apply}. The
8844 following options can be used to fine-tune these behaviors:
8845
8846 @table @code
8847 @item -c
8848 The flag @code{-c}, which stands for @samp{continue}, causes any
8849 errors in @var{command} to be displayed, and the execution of
8850 @code{frame apply} then continues.
8851 @item -s
8852 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8853 or empty output produced by a @var{command} to be silently ignored.
8854 That is, the execution continues, but the frame information and errors
8855 are not printed.
8856 @item -q
8857 The flag @code{-q} (@samp{quiet}) disables printing the frame
8858 information.
8859 @end table
8860
8861 The following example shows how the flags @code{-c} and @code{-s} are
8862 working when applying the command @code{p j} to all frames, where
8863 variable @code{j} can only be successfully printed in the outermost
8864 @code{#1 main} frame.
8865
8866 @smallexample
8867 @group
8868 (@value{GDBP}) frame apply all p j
8869 #0 some_function (i=5) at fun.c:4
8870 No symbol "j" in current context.
8871 (@value{GDBP}) frame apply all -c p j
8872 #0 some_function (i=5) at fun.c:4
8873 No symbol "j" in current context.
8874 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8875 $1 = 5
8876 (@value{GDBP}) frame apply all -s p j
8877 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8878 $2 = 5
8879 (@value{GDBP})
8880 @end group
8881 @end smallexample
8882
8883 By default, @samp{frame apply}, prints the frame location
8884 information before the command output:
8885
8886 @smallexample
8887 @group
8888 (@value{GDBP}) frame apply all p $sp
8889 #0 some_function (i=5) at fun.c:4
8890 $4 = (void *) 0xffffd1e0
8891 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8892 $5 = (void *) 0xffffd1f0
8893 (@value{GDBP})
8894 @end group
8895 @end smallexample
8896
8897 If the flag @code{-q} is given, no frame information is printed:
8898 @smallexample
8899 @group
8900 (@value{GDBP}) frame apply all -q p $sp
8901 $12 = (void *) 0xffffd1e0
8902 $13 = (void *) 0xffffd1f0
8903 (@value{GDBP})
8904 @end group
8905 @end smallexample
8906
8907 @end table
8908
8909 @table @code
8910
8911 @kindex faas
8912 @cindex apply a command to all frames (ignoring errors and empty output)
8913 @item faas @var{command}
8914 Shortcut for @code{frame apply all -s @var{command}}.
8915 Applies @var{command} on all frames, ignoring errors and empty output.
8916
8917 It can for example be used to print a local variable or a function
8918 argument without knowing the frame where this variable or argument
8919 is, using:
8920 @smallexample
8921 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8922 @end smallexample
8923
8924 The @code{faas} command accepts the same options as the @code{frame
8925 apply} command. @xref{Frame Apply,,frame apply}.
8926
8927 Note that the command @code{tfaas @var{command}} applies @var{command}
8928 on all frames of all threads. See @xref{Threads,,Threads}.
8929 @end table
8930
8931
8932 @node Frame Filter Management
8933 @section Management of Frame Filters.
8934 @cindex managing frame filters
8935
8936 Frame filters are Python based utilities to manage and decorate the
8937 output of frames. @xref{Frame Filter API}, for further information.
8938
8939 Managing frame filters is performed by several commands available
8940 within @value{GDBN}, detailed here.
8941
8942 @table @code
8943 @kindex info frame-filter
8944 @item info frame-filter
8945 Print a list of installed frame filters from all dictionaries, showing
8946 their name, priority and enabled status.
8947
8948 @kindex disable frame-filter
8949 @anchor{disable frame-filter all}
8950 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8951 Disable a frame filter in the dictionary matching
8952 @var{filter-dictionary} and @var{filter-name}. The
8953 @var{filter-dictionary} may be @code{all}, @code{global},
8954 @code{progspace}, or the name of the object file where the frame filter
8955 dictionary resides. When @code{all} is specified, all frame filters
8956 across all dictionaries are disabled. The @var{filter-name} is the name
8957 of the frame filter and is used when @code{all} is not the option for
8958 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8959 may be enabled again later.
8960
8961 @kindex enable frame-filter
8962 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8963 Enable a frame filter in the dictionary matching
8964 @var{filter-dictionary} and @var{filter-name}. The
8965 @var{filter-dictionary} may be @code{all}, @code{global},
8966 @code{progspace} or the name of the object file where the frame filter
8967 dictionary resides. When @code{all} is specified, all frame filters across
8968 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8969 filter and is used when @code{all} is not the option for
8970 @var{filter-dictionary}.
8971
8972 Example:
8973
8974 @smallexample
8975 (@value{GDBP}) info frame-filter
8976
8977 global frame-filters:
8978 Priority Enabled Name
8979 1000 No PrimaryFunctionFilter
8980 100 Yes Reverse
8981
8982 progspace /build/test frame-filters:
8983 Priority Enabled Name
8984 100 Yes ProgspaceFilter
8985
8986 objfile /build/test frame-filters:
8987 Priority Enabled Name
8988 999 Yes BuildProgramFilter
8989
8990 (@value{GDBP}) disable frame-filter /build/test BuildProgramFilter
8991 (@value{GDBP}) info frame-filter
8992
8993 global frame-filters:
8994 Priority Enabled Name
8995 1000 No PrimaryFunctionFilter
8996 100 Yes Reverse
8997
8998 progspace /build/test frame-filters:
8999 Priority Enabled Name
9000 100 Yes ProgspaceFilter
9001
9002 objfile /build/test frame-filters:
9003 Priority Enabled Name
9004 999 No BuildProgramFilter
9005
9006 (@value{GDBP}) enable frame-filter global PrimaryFunctionFilter
9007 (@value{GDBP}) info frame-filter
9008
9009 global frame-filters:
9010 Priority Enabled Name
9011 1000 Yes PrimaryFunctionFilter
9012 100 Yes Reverse
9013
9014 progspace /build/test frame-filters:
9015 Priority Enabled Name
9016 100 Yes ProgspaceFilter
9017
9018 objfile /build/test frame-filters:
9019 Priority Enabled Name
9020 999 No BuildProgramFilter
9021 @end smallexample
9022
9023 @kindex set frame-filter priority
9024 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
9025 Set the @var{priority} of a frame filter in the dictionary matching
9026 @var{filter-dictionary}, and the frame filter name matching
9027 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
9028 @code{progspace} or the name of the object file where the frame filter
9029 dictionary resides. The @var{priority} is an integer.
9030
9031 @kindex show frame-filter priority
9032 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
9033 Show the @var{priority} of a frame filter in the dictionary matching
9034 @var{filter-dictionary}, and the frame filter name matching
9035 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
9036 @code{progspace} or the name of the object file where the frame filter
9037 dictionary resides.
9038
9039 Example:
9040
9041 @smallexample
9042 (@value{GDBP}) info frame-filter
9043
9044 global frame-filters:
9045 Priority Enabled Name
9046 1000 Yes PrimaryFunctionFilter
9047 100 Yes Reverse
9048
9049 progspace /build/test frame-filters:
9050 Priority Enabled Name
9051 100 Yes ProgspaceFilter
9052
9053 objfile /build/test frame-filters:
9054 Priority Enabled Name
9055 999 No BuildProgramFilter
9056
9057 (@value{GDBP}) set frame-filter priority global Reverse 50
9058 (@value{GDBP}) info frame-filter
9059
9060 global frame-filters:
9061 Priority Enabled Name
9062 1000 Yes PrimaryFunctionFilter
9063 50 Yes Reverse
9064
9065 progspace /build/test frame-filters:
9066 Priority Enabled Name
9067 100 Yes ProgspaceFilter
9068
9069 objfile /build/test frame-filters:
9070 Priority Enabled Name
9071 999 No BuildProgramFilter
9072 @end smallexample
9073 @end table
9074
9075 @node Source
9076 @chapter Examining Source Files
9077
9078 @value{GDBN} can print parts of your program's source, since the debugging
9079 information recorded in the program tells @value{GDBN} what source files were
9080 used to build it. When your program stops, @value{GDBN} spontaneously prints
9081 the line where it stopped. Likewise, when you select a stack frame
9082 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
9083 execution in that frame has stopped. You can print other portions of
9084 source files by explicit command.
9085
9086 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
9087 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
9088 @value{GDBN} under @sc{gnu} Emacs}.
9089
9090 @menu
9091 * List:: Printing source lines
9092 * Location Specifications:: How to specify code locations
9093 * Edit:: Editing source files
9094 * Search:: Searching source files
9095 * Source Path:: Specifying source directories
9096 * Machine Code:: Source and machine code
9097 * Disable Reading Source:: Disable Reading Source Code
9098 @end menu
9099
9100 @node List
9101 @section Printing Source Lines
9102
9103 @kindex list
9104 @kindex l @r{(@code{list})}
9105 To print lines from a source file, use the @code{list} command
9106 (abbreviated @code{l}). By default, ten lines are printed.
9107 There are several ways to specify what part of the file you want to
9108 print; see @ref{Location Specifications}, for the full list.
9109
9110 Here are the forms of the @code{list} command most commonly used:
9111
9112 @table @code
9113 @item list @var{linenum}
9114 Print lines centered around line number @var{linenum} in the
9115 current source file.
9116
9117 @item list @var{function}
9118 Print lines centered around the beginning of function
9119 @var{function}.
9120
9121 @item list
9122 Print more lines. If the last lines printed were printed with a
9123 @code{list} command, this prints lines following the last lines
9124 printed; however, if the last line printed was a solitary line printed
9125 as part of displaying a stack frame (@pxref{Stack, ,Examining the
9126 Stack}), this prints lines centered around that line.
9127
9128 @item list -
9129 Print lines just before the lines last printed.
9130 @end table
9131
9132 @cindex @code{list}, how many lines to display
9133 By default, @value{GDBN} prints ten source lines with any of these forms of
9134 the @code{list} command. You can change this using @code{set listsize}:
9135
9136 @table @code
9137 @kindex set listsize
9138 @item set listsize @var{count}
9139 @itemx set listsize unlimited
9140 Make the @code{list} command display @var{count} source lines (unless
9141 the @code{list} argument explicitly specifies some other number).
9142 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
9143
9144 @kindex show listsize
9145 @item show listsize
9146 Display the number of lines that @code{list} prints.
9147 @end table
9148
9149 Repeating a @code{list} command with @key{RET} discards the argument,
9150 so it is equivalent to typing just @code{list}. This is more useful
9151 than listing the same lines again. An exception is made for an
9152 argument of @samp{-}; that argument is preserved in repetition so that
9153 each repetition moves up in the source file.
9154
9155 In general, the @code{list} command expects you to supply zero, one or
9156 two location specs. These location specs are interpreted to resolve
9157 to source code lines; there are several ways of writing them
9158 (@pxref{Location Specifications}), but the effect is always to resolve
9159 to some source lines to display.
9160
9161 Here is a complete description of the possible arguments for @code{list}:
9162
9163 @table @code
9164 @item list @var{locspec}
9165 Print lines centered around the line or lines of all the code
9166 locations that result from resolving @var{locspec}.
9167
9168 @item list @var{first},@var{last}
9169 Print lines from @var{first} to @var{last}. Both arguments are
9170 location specs. When a @code{list} command has two location specs,
9171 and the source file of the second location spec is omitted, this
9172 refers to the same source file as the first location spec. If either
9173 @var{first} or @var{last} resolve to more than one source line in the
9174 program, then the list command shows the list of resolved source
9175 lines and does not proceed with the source code listing.
9176
9177 @item list ,@var{last}
9178 Print lines ending with @var{last}.
9179
9180 Likewise, if @var{last} resolves to more than one source line in the
9181 program, then the list command prints the list of resolved source
9182 lines and does not proceed with the source code listing.
9183
9184 @item list @var{first},
9185 Print lines starting with @var{first}.
9186
9187 @item list +
9188 Print lines just after the lines last printed.
9189
9190 @item list -
9191 Print lines just before the lines last printed.
9192
9193 @item list
9194 As described in the preceding table.
9195 @end table
9196
9197 @node Location Specifications
9198 @section Location Specifications
9199 @cindex specifying location
9200 @cindex locspec
9201 @cindex source location
9202 @cindex code location
9203
9204 @cindex location spec
9205 Several @value{GDBN} commands accept arguments that specify a location
9206 or locations of your program's code. Many times locations are
9207 specified using a source line number, but they can also be specified
9208 by a function name, an address, a label, etc. The different
9209 forms of specifying a location that @value{GDBN} recognizes are
9210 collectively known as forms of @dfn{location specification}, or
9211 @dfn{location spec}. This section documents the forms of specifying
9212 locations that @value{GDBN} recognizes.
9213
9214 @cindex location resolution
9215 @cindex resolution of location spec
9216 When you specify a location, @value{GDBN} needs to find the place in
9217 your program, known as @dfn{code location}, that corresponds to the
9218 given location spec. We call this process of finding actual code
9219 locations corresponding to a location spec @dfn{location resolution}.
9220
9221 A concrete code location in your program is uniquely identifiable by a
9222 set of several attributes: its source line number, the name of its
9223 source file, the fully-qualified and prototyped function in which it
9224 is defined, and an instruction address. Because each inferior has its
9225 own address space, the inferior number is also a necessary part of
9226 these attributes.
9227
9228 By contrast, location specs you type will many times omit some of
9229 these attributes. For example, it is customary to specify just the
9230 source line number to mean a line in the current source file, or
9231 specify just the basename of the file, omitting its directories. In
9232 other words, a location spec is usually incomplete, a kind of
9233 blueprint, and @value{GDBN} needs to complete the missing attributes
9234 by using the implied defaults, and by considering the source code and
9235 the debug information available to it. This is what location
9236 resolution is about.
9237
9238 The resolution of an incomplete location spec can produce more than a
9239 single code location, if the spec doesn't allow distinguishing between
9240 them. Here are some examples of situations that result in a location
9241 spec matching multiple code locations in your program:
9242
9243 @itemize @bullet
9244 @item
9245 The location spec specifies a function name, and there are several
9246 functions in the program which have that name. (To distinguish
9247 between them, you can specify a fully-qualified and prototyped
9248 function name, such as @code{A::func(int)} instead of just
9249 @code{func}.)
9250
9251 @item
9252 The location spec specifies a source file name, and there are several
9253 source files in the program that share the same name, for example
9254 several files with the same basename in different subdirectories. (To
9255 distinguish between them, specify enough leading directories with the
9256 file name.)
9257
9258 @item
9259 For a C@t{++} constructor, the @value{NGCC} compiler generates several
9260 instances of the function body, used in different cases, but their
9261 source-level names are identical.
9262
9263 @item
9264 For a C@t{++} template function, a given line in the function can
9265 correspond to any number of instantiations.
9266
9267 @item
9268 For an inlined function, a given source line can correspond to several
9269 actual code locations with that function's inlined code.
9270 @end itemize
9271
9272 Resolution of a location spec can also fail to produce a complete code
9273 location, or even fail to produce any code location. Here are some
9274 examples of such situations:
9275
9276 @itemize @bullet
9277 @item
9278 Some parts of the program lack detailed enough debug info, so the
9279 resolved code location lacks some attributes, like source file name
9280 and line number, leaving just the instruction address and perhaps also
9281 a function name. Such an incomplete code location is only usable in
9282 contexts that work with addresses and/or function names. Some
9283 commands can only work with complete code locations.
9284
9285 @item
9286 The location spec specifies a function name, and there are no
9287 functions in the program by that name, or they only exist in a
9288 yet-unloaded shared library.
9289
9290 @item
9291 The location spec specifies a source file name, and there are no
9292 source files in the program by that name, or they only exist in a
9293 yet-unloaded shared library.
9294
9295 @item
9296 The location spec specifies both a source file name and a source line
9297 number, and even though there are source files in the program that
9298 match the file name, none of those files has the specified line
9299 number.
9300 @end itemize
9301
9302 Locations may be specified using three different formats: linespec
9303 locations, explicit locations, or address locations. The following
9304 subsections describe these formats.
9305
9306 @menu
9307 * Linespec Locations:: Linespec locations
9308 * Explicit Locations:: Explicit locations
9309 * Address Locations:: Address locations
9310 @end menu
9311
9312 @node Linespec Locations
9313 @subsection Linespec Locations
9314 @cindex linespec locations
9315
9316 A @dfn{linespec} is a colon-separated list of source location parameters such
9317 as file name, function name, etc. Here are all the different ways of
9318 specifying a linespec:
9319
9320 @table @code
9321 @item @var{linenum}
9322 Specifies the line number @var{linenum} of the current source file.
9323
9324 @item -@var{offset}
9325 @itemx +@var{offset}
9326 Specifies the line @var{offset} lines before or after the @dfn{current
9327 line}. For the @code{list} command, the current line is the last one
9328 printed; for the breakpoint commands, this is the line at which
9329 execution stopped in the currently selected @dfn{stack frame}
9330 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9331 used as the second of the two linespecs in a @code{list} command,
9332 this specifies the line @var{offset} lines up or down from the first
9333 linespec.
9334
9335 @item @var{filename}:@var{linenum}
9336 Specifies the line @var{linenum} in the source file @var{filename}.
9337 If @var{filename} is a relative file name, then it will match any
9338 source file name with the same trailing components. For example, if
9339 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9340 name of @file{/build/trunk/gcc/expr.c}, but not
9341 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9342
9343 @item @var{function}
9344 Specifies the line that begins the body of the function @var{function}.
9345 For example, in C, this is the line with the open brace.
9346
9347 By default, in C@t{++} and Ada, @var{function} is interpreted as
9348 specifying all functions named @var{function} in all scopes. For
9349 C@t{++}, this means in all namespaces and classes. For Ada, this
9350 means in all packages.
9351
9352 For example, assuming a program with C@t{++} symbols named
9353 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9354 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9355
9356 Commands that accept a linespec let you override this with the
9357 @code{-qualified} option. For example, @w{@kbd{break -qualified
9358 func}} sets a breakpoint on a free-function named @code{func} ignoring
9359 any C@t{++} class methods and namespace functions called @code{func}.
9360
9361 @xref{Explicit Locations}.
9362
9363 @item @var{function}:@var{label}
9364 Specifies the line where @var{label} appears in @var{function}.
9365
9366 @item @var{filename}:@var{function}
9367 Specifies the line that begins the body of the function @var{function}
9368 in the file @var{filename}. You only need the file name with a
9369 function name to avoid ambiguity when there are identically named
9370 functions in different source files.
9371
9372 @item @var{label}
9373 Specifies the line at which the label named @var{label} appears
9374 in the function corresponding to the currently selected stack frame.
9375 If there is no current selected stack frame (for instance, if the inferior
9376 is not running), then @value{GDBN} will not search for a label.
9377
9378 @cindex breakpoint at static probe point
9379 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9380 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9381 applications to embed static probes. @xref{Static Probe Points}, for more
9382 information on finding and using static probes. This form of linespec
9383 specifies the location of such a static probe.
9384
9385 If @var{objfile} is given, only probes coming from that shared library
9386 or executable matching @var{objfile} as a regular expression are considered.
9387 If @var{provider} is given, then only probes from that provider are considered.
9388 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9389 each one of those probes.
9390 @end table
9391
9392 @node Explicit Locations
9393 @subsection Explicit Locations
9394 @cindex explicit locations
9395
9396 @dfn{Explicit locations} allow the user to directly specify the source
9397 location's parameters using option-value pairs.
9398
9399 Explicit locations are useful when several functions, labels, or
9400 file names have the same name (base name for files) in the program's
9401 sources. In these cases, explicit locations point to the source
9402 line you meant more accurately and unambiguously. Also, using
9403 explicit locations might be faster in large programs.
9404
9405 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9406 defined in the file named @file{foo} or the label @code{bar} in a function
9407 named @code{foo}. @value{GDBN} must search either the file system or
9408 the symbol table to know.
9409
9410 The list of valid explicit location options is summarized in the
9411 following table:
9412
9413 @table @code
9414 @item -source @var{filename}
9415 The value specifies the source file name. To differentiate between
9416 files with the same base name, prepend as many directories as is necessary
9417 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9418 @value{GDBN} will use the first file it finds with the given base
9419 name. This option requires the use of either @code{-function} or @code{-line}.
9420
9421 @item -function @var{function}
9422 The value specifies the name of a function. Operations
9423 on function locations unmodified by other options (such as @code{-label}
9424 or @code{-line}) refer to the line that begins the body of the function.
9425 In C, for example, this is the line with the open brace.
9426
9427 By default, in C@t{++} and Ada, @var{function} is interpreted as
9428 specifying all functions named @var{function} in all scopes. For
9429 C@t{++}, this means in all namespaces and classes. For Ada, this
9430 means in all packages.
9431
9432 For example, assuming a program with C@t{++} symbols named
9433 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9434 -function func}} and @w{@kbd{break -function B::func}} set a
9435 breakpoint on both symbols.
9436
9437 You can use the @kbd{-qualified} flag to override this (see below).
9438
9439 @item -qualified
9440
9441 This flag makes @value{GDBN} interpret a function name specified with
9442 @kbd{-function} as a complete fully-qualified name.
9443
9444 For example, assuming a C@t{++} program with symbols named
9445 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9446 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9447
9448 (Note: the @kbd{-qualified} option can precede a linespec as well
9449 (@pxref{Linespec Locations}), so the particular example above could be
9450 simplified as @w{@kbd{break -qualified B::func}}.)
9451
9452 @item -label @var{label}
9453 The value specifies the name of a label. When the function
9454 name is not specified, the label is searched in the function of the currently
9455 selected stack frame.
9456
9457 @item -line @var{number}
9458 The value specifies a line offset for the location. The offset may either
9459 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9460 the command. When specified without any other options, the line offset is
9461 relative to the current line.
9462 @end table
9463
9464 Explicit location options may be abbreviated by omitting any non-unique
9465 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9466
9467 @node Address Locations
9468 @subsection Address Locations
9469 @cindex address locations
9470
9471 @dfn{Address locations} indicate a specific program address. They have
9472 the generalized form *@var{address}.
9473
9474 For line-oriented commands, such as @code{list} and @code{edit}, this
9475 specifies a source line that contains @var{address}. For @code{break} and
9476 other breakpoint-oriented commands, this can be used to set breakpoints in
9477 parts of your program which do not have debugging information or
9478 source files.
9479
9480 Here @var{address} may be any expression valid in the current working
9481 language (@pxref{Languages, working language}) that specifies a code
9482 address. In addition, as a convenience, @value{GDBN} extends the
9483 semantics of expressions used in locations to cover several situations
9484 that frequently occur during debugging. Here are the various forms
9485 of @var{address}:
9486
9487 @table @code
9488 @item @var{expression}
9489 Any expression valid in the current working language.
9490
9491 @item @var{funcaddr}
9492 An address of a function or procedure derived from its name. In C,
9493 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9494 simply the function's name @var{function} (and actually a special case
9495 of a valid expression). In Pascal and Modula-2, this is
9496 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9497 (although the Pascal form also works).
9498
9499 This form specifies the address of the function's first instruction,
9500 before the stack frame and arguments have been set up.
9501
9502 @item '@var{filename}':@var{funcaddr}
9503 Like @var{funcaddr} above, but also specifies the name of the source
9504 file explicitly. This is useful if the name of the function does not
9505 specify the function unambiguously, e.g., if there are several
9506 functions with identical names in different source files.
9507 @end table
9508
9509 @node Edit
9510 @section Editing Source Files
9511 @cindex editing source files
9512
9513 @kindex edit
9514 @kindex e @r{(@code{edit})}
9515 To edit the lines in a source file, use the @code{edit} command.
9516 The editing program of your choice
9517 is invoked with the current line set to
9518 the active line in the program.
9519 Alternatively, there are several ways to specify what part of the file you
9520 want to print if you want to see other parts of the program:
9521
9522 @table @code
9523 @item edit @var{locspec}
9524 Edit the source file of the code location that results from resolving
9525 @code{locspec}. Editing starts at the source file and source line
9526 @code{locspec} resolves to.
9527 @xref{Location Specifications}, for all the possible forms of the
9528 @var{locspec} argument.
9529
9530 If @code{locspec} resolves to more than one source line in your
9531 program, then the command prints the list of resolved source lines and
9532 does not proceed with the editing.
9533
9534 Here are the forms of the @code{edit} command most commonly used:
9535
9536 @table @code
9537 @item edit @var{number}
9538 Edit the current source file with @var{number} as the active line number.
9539
9540 @item edit @var{function}
9541 Edit the file containing @var{function} at the beginning of its definition.
9542 @end table
9543
9544 @end table
9545
9546 @subsection Choosing your Editor
9547 You can customize @value{GDBN} to use any editor you want
9548 @footnote{
9549 The only restriction is that your editor (say @code{ex}), recognizes the
9550 following command-line syntax:
9551 @smallexample
9552 ex +@var{number} file
9553 @end smallexample
9554 The optional numeric value +@var{number} specifies the number of the line in
9555 the file where to start editing.}.
9556 By default, it is @file{@value{EDITOR}}, but you can change this
9557 by setting the environment variable @env{EDITOR} before using
9558 @value{GDBN}. For example, to configure @value{GDBN} to use the
9559 @code{vi} editor, you could use these commands with the @code{sh} shell:
9560 @smallexample
9561 EDITOR=/usr/bin/vi
9562 export EDITOR
9563 gdb @dots{}
9564 @end smallexample
9565 or in the @code{csh} shell,
9566 @smallexample
9567 setenv EDITOR /usr/bin/vi
9568 gdb @dots{}
9569 @end smallexample
9570
9571 @node Search
9572 @section Searching Source Files
9573 @cindex searching source files
9574
9575 There are two commands for searching through the current source file for a
9576 regular expression.
9577
9578 @table @code
9579 @kindex search
9580 @kindex forward-search
9581 @kindex fo @r{(@code{forward-search})}
9582 @item forward-search @var{regexp}
9583 @itemx search @var{regexp}
9584 The command @samp{forward-search @var{regexp}} checks each line,
9585 starting with the one following the last line listed, for a match for
9586 @var{regexp}. It lists the line that is found. You can use the
9587 synonym @samp{search @var{regexp}} or abbreviate the command name as
9588 @code{fo}.
9589
9590 @kindex reverse-search
9591 @item reverse-search @var{regexp}
9592 The command @samp{reverse-search @var{regexp}} checks each line, starting
9593 with the one before the last line listed and going backward, for a match
9594 for @var{regexp}. It lists the line that is found. You can abbreviate
9595 this command as @code{rev}.
9596 @end table
9597
9598 @node Source Path
9599 @section Specifying Source Directories
9600
9601 @cindex source path
9602 @cindex directories for source files
9603 Executable programs sometimes do not record the directories of the source
9604 files from which they were compiled, just the names. Even when they do,
9605 the directories could be moved between the compilation and your debugging
9606 session. @value{GDBN} has a list of directories to search for source files;
9607 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9608 it tries all the directories in the list, in the order they are present
9609 in the list, until it finds a file with the desired name.
9610
9611 For example, suppose an executable references the file
9612 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9613 directory, and the @dfn{source path} is @file{/mnt/cross}.
9614 @value{GDBN} would look for the source file in the following
9615 locations:
9616
9617 @enumerate
9618
9619 @item @file{/usr/src/foo-1.0/lib/foo.c}
9620 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9621 @item @file{/mnt/cross/foo.c}
9622
9623 @end enumerate
9624
9625 If the source file is not present at any of the above locations then
9626 an error is printed. @value{GDBN} does not look up the parts of the
9627 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9628 Likewise, the subdirectories of the source path are not searched: if
9629 the source path is @file{/mnt/cross}, and the binary refers to
9630 @file{foo.c}, @value{GDBN} would not find it under
9631 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9632
9633 Plain file names, relative file names with leading directories, file
9634 names containing dots, etc.@: are all treated as described above,
9635 except that non-absolute file names are not looked up literally. If
9636 the @dfn{source path} is @file{/mnt/cross}, the source file is
9637 recorded as @file{../lib/foo.c}, and no compilation directory is
9638 recorded, then @value{GDBN} will search in the following locations:
9639
9640 @enumerate
9641
9642 @item @file{/mnt/cross/../lib/foo.c}
9643 @item @file{/mnt/cross/foo.c}
9644
9645 @end enumerate
9646
9647 @kindex cdir
9648 @kindex cwd
9649 @vindex $cdir@r{, convenience variable}
9650 @vindex $cwd@r{, convenience variable}
9651 @cindex compilation directory
9652 @cindex current directory
9653 @cindex working directory
9654 @cindex directory, current
9655 @cindex directory, compilation
9656 The @dfn{source path} will always include two special entries
9657 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9658 (if one is recorded) and the current working directory respectively.
9659
9660 @samp{$cdir} causes @value{GDBN} to search within the compilation
9661 directory, if one is recorded in the debug information. If no
9662 compilation directory is recorded in the debug information then
9663 @samp{$cdir} is ignored.
9664
9665 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9666 current working directory as it changes during your @value{GDBN}
9667 session, while the latter is immediately expanded to the current
9668 directory at the time you add an entry to the source path.
9669
9670 If a compilation directory is recorded in the debug information, and
9671 @value{GDBN} has not found the source file after the first search
9672 using @dfn{source path}, then @value{GDBN} will combine the
9673 compilation directory and the filename, and then search for the source
9674 file again using the @dfn{source path}.
9675
9676 For example, if the executable records the source file as
9677 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9678 recorded as @file{/project/build}, and the @dfn{source path} is
9679 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9680 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9681 search for the source file in the following locations:
9682
9683 @enumerate
9684
9685 @item @file{/usr/src/foo-1.0/lib/foo.c}
9686 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9687 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9688 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9689 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9690 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9691 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9692 @item @file{/mnt/cross/foo.c}
9693 @item @file{/project/build/foo.c}
9694 @item @file{/home/user/foo.c}
9695
9696 @end enumerate
9697
9698 If the file name in the previous example had been recorded in the
9699 executable as a relative path rather than an absolute path, then the
9700 first look up would not have occurred, but all of the remaining steps
9701 would be similar.
9702
9703 When searching for source files on MS-DOS and MS-Windows, where
9704 absolute paths start with a drive letter (e.g.@:
9705 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9706 from the file name before appending it to a search directory from
9707 @dfn{source path}; for instance if the executable references the
9708 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9709 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9710 locations for the source file:
9711
9712 @enumerate
9713
9714 @item @file{C:/project/foo.c}
9715 @item @file{D:/mnt/cross/project/foo.c}
9716 @item @file{D:/mnt/cross/foo.c}
9717
9718 @end enumerate
9719
9720 Note that the executable search path is @emph{not} used to locate the
9721 source files.
9722
9723 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9724 any information it has cached about where source files are found and where
9725 each line is in the file.
9726
9727 @kindex directory
9728 @kindex dir
9729 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9730 and @samp{$cwd}, in that order.
9731 To add other directories, use the @code{directory} command.
9732
9733 The search path is used to find both program source files and @value{GDBN}
9734 script files (read using the @samp{-command} option and @samp{source} command).
9735
9736 In addition to the source path, @value{GDBN} provides a set of commands
9737 that manage a list of source path substitution rules. A @dfn{substitution
9738 rule} specifies how to rewrite source directories stored in the program's
9739 debug information in case the sources were moved to a different
9740 directory between compilation and debugging. A rule is made of
9741 two strings, the first specifying what needs to be rewritten in
9742 the path, and the second specifying how it should be rewritten.
9743 In @ref{set substitute-path}, we name these two parts @var{from} and
9744 @var{to} respectively. @value{GDBN} does a simple string replacement
9745 of @var{from} with @var{to} at the start of the directory part of the
9746 source file name, and uses that result instead of the original file
9747 name to look up the sources.
9748
9749 Using the previous example, suppose the @file{foo-1.0} tree has been
9750 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9751 @value{GDBN} to replace @file{/usr/src} in all source path names with
9752 @file{/mnt/cross}. The first lookup will then be
9753 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9754 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9755 substitution rule, use the @code{set substitute-path} command
9756 (@pxref{set substitute-path}).
9757
9758 To avoid unexpected substitution results, a rule is applied only if the
9759 @var{from} part of the directory name ends at a directory separator.
9760 For instance, a rule substituting @file{/usr/source} into
9761 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9762 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9763 is applied only at the beginning of the directory name, this rule will
9764 not be applied to @file{/root/usr/source/baz.c} either.
9765
9766 In many cases, you can achieve the same result using the @code{directory}
9767 command. However, @code{set substitute-path} can be more efficient in
9768 the case where the sources are organized in a complex tree with multiple
9769 subdirectories. With the @code{directory} command, you need to add each
9770 subdirectory of your project. If you moved the entire tree while
9771 preserving its internal organization, then @code{set substitute-path}
9772 allows you to direct the debugger to all the sources with one single
9773 command.
9774
9775 @code{set substitute-path} is also more than just a shortcut command.
9776 The source path is only used if the file at the original location no
9777 longer exists. On the other hand, @code{set substitute-path} modifies
9778 the debugger behavior to look at the rewritten location instead. So, if
9779 for any reason a source file that is not relevant to your executable is
9780 located at the original location, a substitution rule is the only
9781 method available to point @value{GDBN} at the new location.
9782
9783 @cindex @samp{--with-relocated-sources}
9784 @cindex default source path substitution
9785 You can configure a default source path substitution rule by
9786 configuring @value{GDBN} with the
9787 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9788 should be the name of a directory under @value{GDBN}'s configured
9789 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9790 directory names in debug information under @var{dir} will be adjusted
9791 automatically if the installed @value{GDBN} is moved to a new
9792 location. This is useful if @value{GDBN}, libraries or executables
9793 with debug information and corresponding source code are being moved
9794 together.
9795
9796 @table @code
9797 @item directory @var{dirname} @dots{}
9798 @item dir @var{dirname} @dots{}
9799 Add directory @var{dirname} to the front of the source path. Several
9800 directory names may be given to this command, separated by @samp{:}
9801 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9802 part of absolute file names) or
9803 whitespace. You may specify a directory that is already in the source
9804 path; this moves it forward, so @value{GDBN} searches it sooner.
9805
9806 The special strings @samp{$cdir} (to refer to the compilation
9807 directory, if one is recorded), and @samp{$cwd} (to refer to the
9808 current working directory) can also be included in the list of
9809 directories @var{dirname}. Though these will already be in the source
9810 path they will be moved forward in the list so @value{GDBN} searches
9811 them sooner.
9812
9813 @item directory
9814 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9815
9816 @c RET-repeat for @code{directory} is explicitly disabled, but since
9817 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9818
9819 @item set directories @var{path-list}
9820 @kindex set directories
9821 Set the source path to @var{path-list}.
9822 @samp{$cdir:$cwd} are added if missing.
9823
9824 @item show directories
9825 @kindex show directories
9826 Print the source path: show which directories it contains.
9827
9828 @anchor{set substitute-path}
9829 @item set substitute-path @var{from} @var{to}
9830 @kindex set substitute-path
9831 Define a source path substitution rule, and add it at the end of the
9832 current list of existing substitution rules. If a rule with the same
9833 @var{from} was already defined, then the old rule is also deleted.
9834
9835 For example, if the file @file{/foo/bar/baz.c} was moved to
9836 @file{/mnt/cross/baz.c}, then the command
9837
9838 @smallexample
9839 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9840 @end smallexample
9841
9842 @noindent
9843 will tell @value{GDBN} to replace @samp{/foo/bar} with
9844 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9845 @file{baz.c} even though it was moved.
9846
9847 In the case when more than one substitution rule have been defined,
9848 the rules are evaluated one by one in the order where they have been
9849 defined. The first one matching, if any, is selected to perform
9850 the substitution.
9851
9852 For instance, if we had entered the following commands:
9853
9854 @smallexample
9855 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9856 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9857 @end smallexample
9858
9859 @noindent
9860 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9861 @file{/mnt/include/defs.h} by using the first rule. However, it would
9862 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9863 @file{/mnt/src/lib/foo.c}.
9864
9865
9866 @item unset substitute-path [path]
9867 @kindex unset substitute-path
9868 If a path is specified, search the current list of substitution rules
9869 for a rule that would rewrite that path. Delete that rule if found.
9870 A warning is emitted by the debugger if no rule could be found.
9871
9872 If no path is specified, then all substitution rules are deleted.
9873
9874 @item show substitute-path [path]
9875 @kindex show substitute-path
9876 If a path is specified, then print the source path substitution rule
9877 which would rewrite that path, if any.
9878
9879 If no path is specified, then print all existing source path substitution
9880 rules.
9881
9882 @end table
9883
9884 If your source path is cluttered with directories that are no longer of
9885 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9886 versions of source. You can correct the situation as follows:
9887
9888 @enumerate
9889 @item
9890 Use @code{directory} with no argument to reset the source path to its default value.
9891
9892 @item
9893 Use @code{directory} with suitable arguments to reinstall the
9894 directories you want in the source path. You can add all the
9895 directories in one command.
9896 @end enumerate
9897
9898 @node Machine Code
9899 @section Source and Machine Code
9900 @cindex source line and its code address
9901
9902 You can use the command @code{info line} to map source lines to program
9903 addresses (and vice versa), and the command @code{disassemble} to display
9904 a range of addresses as machine instructions. You can use the command
9905 @code{set disassemble-next-line} to set whether to disassemble next
9906 source line when execution stops. When run under @sc{gnu} Emacs
9907 mode, the @code{info line} command causes the arrow to point to the
9908 line specified. Also, @code{info line} prints addresses in symbolic form as
9909 well as hex.
9910
9911 @table @code
9912 @kindex info line
9913 @item info line
9914 @itemx info line @var{locspec}
9915 Print the starting and ending addresses of the compiled code for the
9916 source lines of the code locations that result from resolving
9917 @var{locspec}. @xref{Location Specifications}, for the various forms
9918 of @var{locspec}.
9919 With no @var{locspec}, information about the current source line is
9920 printed.
9921 @end table
9922
9923 For example, we can use @code{info line} to discover the location of
9924 the object code for the first line of function
9925 @code{m4_changequote}:
9926
9927 @smallexample
9928 (@value{GDBP}) info line m4_changequote
9929 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9930 ends at 0x6350 <m4_changequote+4>.
9931 @end smallexample
9932
9933 @noindent
9934 @cindex code address and its source line
9935 We can also inquire, using @code{*@var{addr}} as the form for
9936 @var{locspec}, what source line covers a particular address
9937 @var{addr}:
9938 @smallexample
9939 (@value{GDBP}) info line *0x63ff
9940 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9941 ends at 0x6404 <m4_changequote+184>.
9942 @end smallexample
9943
9944 @cindex @code{$_} and @code{info line}
9945 @cindex @code{x} command, default address
9946 @kindex x@r{(examine), and} info line
9947 After @code{info line}, the default address for the @code{x} command
9948 is changed to the starting address of the line, so that @samp{x/i} is
9949 sufficient to begin examining the machine code (@pxref{Memory,
9950 ,Examining Memory}). Also, this address is saved as the value of the
9951 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9952 Variables}).
9953
9954 @cindex info line, repeated calls
9955 After @code{info line}, using @code{info line} again without
9956 specifying a location will display information about the next source
9957 line.
9958
9959 @anchor{disassemble}
9960 @table @code
9961 @kindex disassemble
9962 @cindex assembly instructions
9963 @cindex instructions, assembly
9964 @cindex machine instructions
9965 @cindex listing machine instructions
9966 @item disassemble
9967 @itemx disassemble /m
9968 @itemx disassemble /s
9969 @itemx disassemble /r
9970 @itemx disassemble /b
9971 This specialized command dumps a range of memory as machine
9972 instructions. It can also print mixed source+disassembly by specifying
9973 the @code{/m} or @code{/s} modifier and print the raw instructions in
9974 hex as well as in symbolic form by specifying the @code{/r} or @code{/b}
9975 modifier. The default memory range is the function surrounding the
9976 program counter of the selected frame. A single argument to this
9977 command is a program counter value; @value{GDBN} dumps the function
9978 surrounding this value. When two arguments are given, they should be
9979 separated by a comma, possibly surrounded by whitespace. The arguments
9980 specify a range of addresses to dump, in one of two forms:
9981
9982 @table @code
9983 @item @var{start},@var{end}
9984 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9985 @item @var{start},+@var{length}
9986 the addresses from @var{start} (inclusive) to
9987 @code{@var{start}+@var{length}} (exclusive).
9988 @end table
9989
9990 @noindent
9991 When 2 arguments are specified, the name of the function is also
9992 printed (since there could be several functions in the given range).
9993
9994 The argument(s) can be any expression yielding a numeric value, such as
9995 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9996
9997 If the range of memory being disassembled contains current program counter,
9998 the instruction at that location is shown with a @code{=>} marker.
9999 @end table
10000
10001 The following example shows the disassembly of a range of addresses of
10002 HP PA-RISC 2.0 code:
10003
10004 @smallexample
10005 (@value{GDBP}) disas 0x32c4, 0x32e4
10006 Dump of assembler code from 0x32c4 to 0x32e4:
10007 0x32c4 <main+204>: addil 0,dp
10008 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
10009 0x32cc <main+212>: ldil 0x3000,r31
10010 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
10011 0x32d4 <main+220>: ldo 0(r31),rp
10012 0x32d8 <main+224>: addil -0x800,dp
10013 0x32dc <main+228>: ldo 0x588(r1),r26
10014 0x32e0 <main+232>: ldil 0x3000,r31
10015 End of assembler dump.
10016 @end smallexample
10017
10018 The following two examples are for RISC-V, and demonstrates the
10019 difference between the @code{/r} and @code{/b} modifiers. First with
10020 @code{/b}, the bytes of the instruction are printed, in hex, in memory
10021 order:
10022
10023 @smallexample
10024 (@value{GDBP}) disassemble /b 0x00010150,0x0001015c
10025 Dump of assembler code from 0x10150 to 0x1015c:
10026 0x00010150 <call_me+4>: 22 dc sw s0,56(sp)
10027 0x00010152 <call_me+6>: 80 00 addi s0,sp,64
10028 0x00010154 <call_me+8>: 23 26 a4 fe sw a0,-20(s0)
10029 0x00010158 <call_me+12>: 23 24 b4 fe sw a1,-24(s0)
10030 End of assembler dump.
10031 @end smallexample
10032
10033 In contrast, with @code{/r} the bytes of the instruction are displayed
10034 in the instruction order, for RISC-V this means that the bytes have been
10035 swapped to little-endian order:
10036
10037 @smallexample
10038 (@value{GDBP}) disassemble /r 0x00010150,0x0001015c
10039 Dump of assembler code from 0x10150 to 0x1015c:
10040 0x00010150 <call_me+4>: dc22 sw s0,56(sp)
10041 0x00010152 <call_me+6>: 0080 addi s0,sp,64
10042 0x00010154 <call_me+8>: fea42623 sw a0,-20(s0)
10043 0x00010158 <call_me+12>: feb42423 sw a1,-24(s0)
10044 End of assembler dump.
10045 @end smallexample
10046
10047 Here is an example showing mixed source+assembly for Intel x86
10048 with @code{/m} or @code{/s}, when the program is stopped just after
10049 function prologue in a non-optimized function with no inline code.
10050
10051 @smallexample
10052 (@value{GDBP}) disas /m main
10053 Dump of assembler code for function main:
10054 5 @{
10055 0x08048330 <+0>: push %ebp
10056 0x08048331 <+1>: mov %esp,%ebp
10057 0x08048333 <+3>: sub $0x8,%esp
10058 0x08048336 <+6>: and $0xfffffff0,%esp
10059 0x08048339 <+9>: sub $0x10,%esp
10060
10061 6 printf ("Hello.\n");
10062 => 0x0804833c <+12>: movl $0x8048440,(%esp)
10063 0x08048343 <+19>: call 0x8048284 <puts@@plt>
10064
10065 7 return 0;
10066 8 @}
10067 0x08048348 <+24>: mov $0x0,%eax
10068 0x0804834d <+29>: leave
10069 0x0804834e <+30>: ret
10070
10071 End of assembler dump.
10072 @end smallexample
10073
10074 The @code{/m} option is deprecated as its output is not useful when
10075 there is either inlined code or re-ordered code.
10076 The @code{/s} option is the preferred choice.
10077 Here is an example for AMD x86-64 showing the difference between
10078 @code{/m} output and @code{/s} output.
10079 This example has one inline function defined in a header file,
10080 and the code is compiled with @samp{-O2} optimization.
10081 Note how the @code{/m} output is missing the disassembly of
10082 several instructions that are present in the @code{/s} output.
10083
10084 @file{foo.h}:
10085
10086 @smallexample
10087 int
10088 foo (int a)
10089 @{
10090 if (a < 0)
10091 return a * 2;
10092 if (a == 0)
10093 return 1;
10094 return a + 10;
10095 @}
10096 @end smallexample
10097
10098 @file{foo.c}:
10099
10100 @smallexample
10101 #include "foo.h"
10102 volatile int x, y;
10103 int
10104 main ()
10105 @{
10106 x = foo (y);
10107 return 0;
10108 @}
10109 @end smallexample
10110
10111 @smallexample
10112 (@value{GDBP}) disas /m main
10113 Dump of assembler code for function main:
10114 5 @{
10115
10116 6 x = foo (y);
10117 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
10118 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
10119
10120 7 return 0;
10121 8 @}
10122 0x000000000040041d <+29>: xor %eax,%eax
10123 0x000000000040041f <+31>: retq
10124 0x0000000000400420 <+32>: add %eax,%eax
10125 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
10126
10127 End of assembler dump.
10128 (@value{GDBP}) disas /s main
10129 Dump of assembler code for function main:
10130 foo.c:
10131 5 @{
10132 6 x = foo (y);
10133 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
10134
10135 foo.h:
10136 4 if (a < 0)
10137 0x0000000000400406 <+6>: test %eax,%eax
10138 0x0000000000400408 <+8>: js 0x400420 <main+32>
10139
10140 6 if (a == 0)
10141 7 return 1;
10142 8 return a + 10;
10143 0x000000000040040a <+10>: lea 0xa(%rax),%edx
10144 0x000000000040040d <+13>: test %eax,%eax
10145 0x000000000040040f <+15>: mov $0x1,%eax
10146 0x0000000000400414 <+20>: cmovne %edx,%eax
10147
10148 foo.c:
10149 6 x = foo (y);
10150 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
10151
10152 7 return 0;
10153 8 @}
10154 0x000000000040041d <+29>: xor %eax,%eax
10155 0x000000000040041f <+31>: retq
10156
10157 foo.h:
10158 5 return a * 2;
10159 0x0000000000400420 <+32>: add %eax,%eax
10160 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
10161 End of assembler dump.
10162 @end smallexample
10163
10164 Here is another example showing raw instructions in hex for AMD x86-64,
10165
10166 @smallexample
10167 (@value{GDBP}) disas /r 0x400281,+10
10168 Dump of assembler code from 0x400281 to 0x40028b:
10169 0x0000000000400281: 38 36 cmp %dh,(%rsi)
10170 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
10171 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
10172 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
10173 End of assembler dump.
10174 @end smallexample
10175
10176 Note that the @samp{disassemble} command's address arguments are
10177 specified using expressions in your programming language
10178 (@pxref{Expressions, ,Expressions}), not location specs
10179 (@pxref{Location Specifications}). So, for example, if you want to
10180 disassemble function @code{bar} in file @file{foo.c}, you must type
10181 @samp{disassemble 'foo.c'::bar} and not @samp{disassemble foo.c:bar}.
10182
10183 Some architectures have more than one commonly-used set of instruction
10184 mnemonics or other syntax.
10185
10186 For programs that were dynamically linked and use shared libraries,
10187 instructions that call functions or branch to locations in the shared
10188 libraries might show a seemingly bogus location---it's actually a
10189 location of the relocation table. On some architectures, @value{GDBN}
10190 might be able to resolve these to actual function names.
10191
10192 @table @code
10193 @kindex set disassembler-options
10194 @cindex disassembler options
10195 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
10196 This command controls the passing of target specific information to
10197 the disassembler. For a list of valid options, please refer to the
10198 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
10199 manual and/or the output of @kbd{objdump --help}
10200 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
10201 The default value is the empty string.
10202
10203 If it is necessary to specify more than one disassembler option, then
10204 multiple options can be placed together into a comma separated list.
10205 Currently this command is only supported on targets ARC, ARM, MIPS,
10206 PowerPC and S/390.
10207
10208 @kindex show disassembler-options
10209 @item show disassembler-options
10210 Show the current setting of the disassembler options.
10211 @end table
10212
10213 @table @code
10214 @kindex set disassembly-flavor
10215 @cindex Intel disassembly flavor
10216 @cindex AT&T disassembly flavor
10217 @item set disassembly-flavor @var{instruction-set}
10218 Select the instruction set to use when disassembling the
10219 program via the @code{disassemble} or @code{x/i} commands.
10220
10221 Currently this command is only defined for the Intel x86 family. You
10222 can set @var{instruction-set} to either @code{intel} or @code{att}.
10223 The default is @code{att}, the AT&T flavor used by default by Unix
10224 assemblers for x86-based targets.
10225
10226 @kindex show disassembly-flavor
10227 @item show disassembly-flavor
10228 Show the current setting of the disassembly flavor.
10229 @end table
10230
10231 @table @code
10232 @kindex set disassemble-next-line
10233 @kindex show disassemble-next-line
10234 @item set disassemble-next-line
10235 @itemx show disassemble-next-line
10236 Control whether or not @value{GDBN} will disassemble the next source
10237 line or instruction when execution stops. If ON, @value{GDBN} will
10238 display disassembly of the next source line when execution of the
10239 program being debugged stops. This is @emph{in addition} to
10240 displaying the source line itself, which @value{GDBN} always does if
10241 possible. If the next source line cannot be displayed for some reason
10242 (e.g., if @value{GDBN} cannot find the source file, or there's no line
10243 info in the debug info), @value{GDBN} will display disassembly of the
10244 next @emph{instruction} instead of showing the next source line. If
10245 AUTO, @value{GDBN} will display disassembly of next instruction only
10246 if the source line cannot be displayed. This setting causes
10247 @value{GDBN} to display some feedback when you step through a function
10248 with no line info or whose source file is unavailable. The default is
10249 OFF, which means never display the disassembly of the next line or
10250 instruction.
10251 @end table
10252
10253 @node Disable Reading Source
10254 @section Disable Reading Source Code
10255 @cindex source code, disable access
10256
10257 In some cases it can be desirable to prevent @value{GDBN} from
10258 accessing source code files. One case where this might be desirable
10259 is if the source code files are located over a slow network
10260 connection.
10261
10262 The following command can be used to control whether @value{GDBN}
10263 should access source code files or not:
10264
10265 @table @code
10266 @kindex set source open
10267 @kindex show source open
10268 @item set source open @r{[}on@r{|}off@r{]}
10269 @itemx show source open
10270 When this option is @code{on}, which is the default, @value{GDBN} will
10271 access source code files when needed, for example to print source
10272 lines when @value{GDBN} stops, or in response to the @code{list}
10273 command.
10274
10275 When this option is @code{off}, @value{GDBN} will not access source
10276 code files.
10277 @end table
10278
10279 @node Data
10280 @chapter Examining Data
10281
10282 @cindex printing data
10283 @cindex examining data
10284 @kindex print
10285 @kindex inspect
10286 The usual way to examine data in your program is with the @code{print}
10287 command (abbreviated @code{p}), or its synonym @code{inspect}. It
10288 evaluates and prints the value of an expression of the language your
10289 program is written in (@pxref{Languages, ,Using @value{GDBN} with
10290 Different Languages}). It may also print the expression using a
10291 Python-based pretty-printer (@pxref{Pretty Printing}).
10292
10293 @table @code
10294 @item print [[@var{options}] --] @var{expr}
10295 @itemx print [[@var{options}] --] /@var{f} @var{expr}
10296 @var{expr} is an expression (in the source language). By default the
10297 value of @var{expr} is printed in a format appropriate to its data type;
10298 you can choose a different format by specifying @samp{/@var{f}}, where
10299 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
10300 Formats}.
10301
10302 @anchor{print options}
10303 The @code{print} command supports a number of options that allow
10304 overriding relevant global print settings as set by @code{set print}
10305 subcommands:
10306
10307 @table @code
10308 @item -address [@code{on}|@code{off}]
10309 Set printing of addresses.
10310 Related setting: @ref{set print address}.
10311
10312 @item -array [@code{on}|@code{off}]
10313 Pretty formatting of arrays.
10314 Related setting: @ref{set print array}.
10315
10316 @item -array-indexes [@code{on}|@code{off}]
10317 Set printing of array indexes.
10318 Related setting: @ref{set print array-indexes}.
10319
10320 @item -characters @var{number-of-characters}|@code{elements}|@code{unlimited}
10321 Set limit on string characters to print. The value @code{elements}
10322 causes the limit on array elements to print to be used. The value
10323 @code{unlimited} causes there to be no limit. Related setting:
10324 @ref{set print characters}.
10325
10326 @item -elements @var{number-of-elements}|@code{unlimited}
10327 Set limit on array elements and optionally string characters to print.
10328 See @ref{set print characters}, and the @code{-characters} option above
10329 for when this option applies to strings. The value @code{unlimited}
10330 causes there to be no limit. @xref{set print elements}, for a related
10331 CLI command.
10332
10333 @item -max-depth @var{depth}|@code{unlimited}
10334 Set the threshold after which nested structures are replaced with
10335 ellipsis. Related setting: @ref{set print max-depth}.
10336
10337 @item -nibbles [@code{on}|@code{off}]
10338 Set whether to print binary values in groups of four bits, known
10339 as ``nibbles''. @xref{set print nibbles}.
10340
10341 @item -memory-tag-violations [@code{on}|@code{off}]
10342 Set printing of additional information about memory tag violations.
10343 @xref{set print memory-tag-violations}.
10344
10345 @item -null-stop [@code{on}|@code{off}]
10346 Set printing of char arrays to stop at first null char. Related
10347 setting: @ref{set print null-stop}.
10348
10349 @item -object [@code{on}|@code{off}]
10350 Set printing C@t{++} virtual function tables. Related setting:
10351 @ref{set print object}.
10352
10353 @item -pretty [@code{on}|@code{off}]
10354 Set pretty formatting of structures. Related setting: @ref{set print
10355 pretty}.
10356
10357 @item -raw-values [@code{on}|@code{off}]
10358 Set whether to print values in raw form, bypassing any
10359 pretty-printers for that value. Related setting: @ref{set print
10360 raw-values}.
10361
10362 @item -repeats @var{number-of-repeats}|@code{unlimited}
10363 Set threshold for repeated print elements. @code{unlimited} causes
10364 all elements to be individually printed. Related setting: @ref{set
10365 print repeats}.
10366
10367 @item -static-members [@code{on}|@code{off}]
10368 Set printing C@t{++} static members. Related setting: @ref{set print
10369 static-members}.
10370
10371 @item -symbol [@code{on}|@code{off}]
10372 Set printing of symbol names when printing pointers. Related setting:
10373 @ref{set print symbol}.
10374
10375 @item -union [@code{on}|@code{off}]
10376 Set printing of unions interior to structures. Related setting:
10377 @ref{set print union}.
10378
10379 @item -vtbl [@code{on}|@code{off}]
10380 Set printing of C++ virtual function tables. Related setting:
10381 @ref{set print vtbl}.
10382 @end table
10383
10384 Because the @code{print} command accepts arbitrary expressions which
10385 may look like options (including abbreviations), if you specify any
10386 command option, then you must use a double dash (@code{--}) to mark
10387 the end of option processing.
10388
10389 For example, this prints the value of the @code{-p} expression:
10390
10391 @smallexample
10392 (@value{GDBP}) print -p
10393 @end smallexample
10394
10395 While this repeats the last value in the value history (see below)
10396 with the @code{-pretty} option in effect:
10397
10398 @smallexample
10399 (@value{GDBP}) print -p --
10400 @end smallexample
10401
10402 Here is an example including both on option and an expression:
10403
10404 @smallexample
10405 @group
10406 (@value{GDBP}) print -pretty -- *myptr
10407 $1 = @{
10408 next = 0x0,
10409 flags = @{
10410 sweet = 1,
10411 sour = 1
10412 @},
10413 meat = 0x54 "Pork"
10414 @}
10415 @end group
10416 @end smallexample
10417
10418 @item print [@var{options}]
10419 @itemx print [@var{options}] /@var{f}
10420 @cindex reprint the last value
10421 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10422 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10423 conveniently inspect the same value in an alternative format.
10424 @end table
10425
10426 If the architecture supports memory tagging, the @code{print} command will
10427 display pointer/memory tag mismatches if what is being printed is a pointer
10428 or reference type. @xref{Memory Tagging}.
10429
10430 A more low-level way of examining data is with the @code{x} command.
10431 It examines data in memory at a specified address and prints it in a
10432 specified format. @xref{Memory, ,Examining Memory}.
10433
10434 If you are interested in information about types, or about how the
10435 fields of a struct or a class are declared, use the @code{ptype @var{expr}}
10436 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10437 Table}.
10438
10439 @cindex exploring hierarchical data structures
10440 @kindex explore
10441 Another way of examining values of expressions and type information is
10442 through the Python extension command @code{explore} (available only if
10443 the @value{GDBN} build is configured with @code{--with-python}). It
10444 offers an interactive way to start at the highest level (or, the most
10445 abstract level) of the data type of an expression (or, the data type
10446 itself) and explore all the way down to leaf scalar values/fields
10447 embedded in the higher level data types.
10448
10449 @table @code
10450 @item explore @var{arg}
10451 @var{arg} is either an expression (in the source language), or a type
10452 visible in the current context of the program being debugged.
10453 @end table
10454
10455 The working of the @code{explore} command can be illustrated with an
10456 example. If a data type @code{struct ComplexStruct} is defined in your
10457 C program as
10458
10459 @smallexample
10460 struct SimpleStruct
10461 @{
10462 int i;
10463 double d;
10464 @};
10465
10466 struct ComplexStruct
10467 @{
10468 struct SimpleStruct *ss_p;
10469 int arr[10];
10470 @};
10471 @end smallexample
10472
10473 @noindent
10474 followed by variable declarations as
10475
10476 @smallexample
10477 struct SimpleStruct ss = @{ 10, 1.11 @};
10478 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10479 @end smallexample
10480
10481 @noindent
10482 then, the value of the variable @code{cs} can be explored using the
10483 @code{explore} command as follows.
10484
10485 @smallexample
10486 (@value{GDBP}) explore cs
10487 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10488 the following fields:
10489
10490 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10491 arr = <Enter 1 to explore this field of type `int [10]'>
10492
10493 Enter the field number of choice:
10494 @end smallexample
10495
10496 @noindent
10497 Since the fields of @code{cs} are not scalar values, you are being
10498 prompted to chose the field you want to explore. Let's say you choose
10499 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10500 pointer, you will be asked if it is pointing to a single value. From
10501 the declaration of @code{cs} above, it is indeed pointing to a single
10502 value, hence you enter @code{y}. If you enter @code{n}, then you will
10503 be asked if it were pointing to an array of values, in which case this
10504 field will be explored as if it were an array.
10505
10506 @smallexample
10507 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10508 Continue exploring it as a pointer to a single value [y/n]: y
10509 The value of `*(cs.ss_p)' is a struct/class of type `struct
10510 SimpleStruct' with the following fields:
10511
10512 i = 10 .. (Value of type `int')
10513 d = 1.1100000000000001 .. (Value of type `double')
10514
10515 Press enter to return to parent value:
10516 @end smallexample
10517
10518 @noindent
10519 If the field @code{arr} of @code{cs} was chosen for exploration by
10520 entering @code{1} earlier, then since it is as array, you will be
10521 prompted to enter the index of the element in the array that you want
10522 to explore.
10523
10524 @smallexample
10525 `cs.arr' is an array of `int'.
10526 Enter the index of the element you want to explore in `cs.arr': 5
10527
10528 `(cs.arr)[5]' is a scalar value of type `int'.
10529
10530 (cs.arr)[5] = 4
10531
10532 Press enter to return to parent value:
10533 @end smallexample
10534
10535 In general, at any stage of exploration, you can go deeper towards the
10536 leaf values by responding to the prompts appropriately, or hit the
10537 return key to return to the enclosing data structure (the @i{higher}
10538 level data structure).
10539
10540 Similar to exploring values, you can use the @code{explore} command to
10541 explore types. Instead of specifying a value (which is typically a
10542 variable name or an expression valid in the current context of the
10543 program being debugged), you specify a type name. If you consider the
10544 same example as above, your can explore the type
10545 @code{struct ComplexStruct} by passing the argument
10546 @code{struct ComplexStruct} to the @code{explore} command.
10547
10548 @smallexample
10549 (@value{GDBP}) explore struct ComplexStruct
10550 @end smallexample
10551
10552 @noindent
10553 By responding to the prompts appropriately in the subsequent interactive
10554 session, you can explore the type @code{struct ComplexStruct} in a
10555 manner similar to how the value @code{cs} was explored in the above
10556 example.
10557
10558 The @code{explore} command also has two sub-commands,
10559 @code{explore value} and @code{explore type}. The former sub-command is
10560 a way to explicitly specify that value exploration of the argument is
10561 being invoked, while the latter is a way to explicitly specify that type
10562 exploration of the argument is being invoked.
10563
10564 @table @code
10565 @item explore value @var{expr}
10566 @cindex explore value
10567 This sub-command of @code{explore} explores the value of the
10568 expression @var{expr} (if @var{expr} is an expression valid in the
10569 current context of the program being debugged). The behavior of this
10570 command is identical to that of the behavior of the @code{explore}
10571 command being passed the argument @var{expr}.
10572
10573 @item explore type @var{arg}
10574 @cindex explore type
10575 This sub-command of @code{explore} explores the type of @var{arg} (if
10576 @var{arg} is a type visible in the current context of program being
10577 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10578 is an expression valid in the current context of the program being
10579 debugged). If @var{arg} is a type, then the behavior of this command is
10580 identical to that of the @code{explore} command being passed the
10581 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10582 this command will be identical to that of the @code{explore} command
10583 being passed the type of @var{arg} as the argument.
10584 @end table
10585
10586 @menu
10587 * Expressions:: Expressions
10588 * Ambiguous Expressions:: Ambiguous Expressions
10589 * Variables:: Program variables
10590 * Arrays:: Artificial arrays
10591 * Output Formats:: Output formats
10592 * Memory:: Examining memory
10593 * Memory Tagging:: Memory Tagging
10594 * Auto Display:: Automatic display
10595 * Print Settings:: Print settings
10596 * Pretty Printing:: Python pretty printing
10597 * Value History:: Value history
10598 * Convenience Vars:: Convenience variables
10599 * Convenience Funs:: Convenience functions
10600 * Registers:: Registers
10601 * Floating Point Hardware:: Floating point hardware
10602 * Vector Unit:: Vector Unit
10603 * OS Information:: Auxiliary data provided by operating system
10604 * Memory Region Attributes:: Memory region attributes
10605 * Dump/Restore Files:: Copy between memory and a file
10606 * Core File Generation:: Cause a program dump its core
10607 * Character Sets:: Debugging programs that use a different
10608 character set than GDB does
10609 * Caching Target Data:: Data caching for targets
10610 * Searching Memory:: Searching memory for a sequence of bytes
10611 * Value Sizes:: Managing memory allocated for values
10612 @end menu
10613
10614 @node Expressions
10615 @section Expressions
10616
10617 @cindex expressions
10618 @code{print} and many other @value{GDBN} commands accept an expression and
10619 compute its value. Any kind of constant, variable or operator defined
10620 by the programming language you are using is valid in an expression in
10621 @value{GDBN}. This includes conditional expressions, function calls,
10622 casts, and string constants. It also includes preprocessor macros, if
10623 you compiled your program to include this information; see
10624 @ref{Compilation}.
10625
10626 @cindex arrays in expressions
10627 @value{GDBN} supports array constants in expressions input by
10628 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10629 you can use the command @code{print @{1, 2, 3@}} to create an array
10630 of three integers. If you pass an array to a function or assign it
10631 to a program variable, @value{GDBN} copies the array to memory that
10632 is @code{malloc}ed in the target program.
10633
10634 Because C is so widespread, most of the expressions shown in examples in
10635 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10636 Languages}, for information on how to use expressions in other
10637 languages.
10638
10639 In this section, we discuss operators that you can use in @value{GDBN}
10640 expressions regardless of your programming language.
10641
10642 @cindex casts, in expressions
10643 Casts are supported in all languages, not just in C, because it is so
10644 useful to cast a number into a pointer in order to examine a structure
10645 at that address in memory.
10646 @c FIXME: casts supported---Mod2 true?
10647
10648 @value{GDBN} supports these operators, in addition to those common
10649 to programming languages:
10650
10651 @table @code
10652 @item @@
10653 @samp{@@} is a binary operator for treating parts of memory as arrays.
10654 @xref{Arrays, ,Artificial Arrays}, for more information.
10655
10656 @item ::
10657 @samp{::} allows you to specify a variable in terms of the file or
10658 function where it is defined. @xref{Variables, ,Program Variables}.
10659
10660 @cindex @{@var{type}@}
10661 @cindex type casting memory
10662 @cindex memory, viewing as typed object
10663 @cindex casts, to view memory
10664 @item @{@var{type}@} @var{addr}
10665 Refers to an object of type @var{type} stored at address @var{addr} in
10666 memory. The address @var{addr} may be any expression whose value is
10667 an integer or pointer (but parentheses are required around binary
10668 operators, just as in a cast). This construct is allowed regardless
10669 of what kind of data is normally supposed to reside at @var{addr}.
10670 @end table
10671
10672 @node Ambiguous Expressions
10673 @section Ambiguous Expressions
10674 @cindex ambiguous expressions
10675
10676 Expressions can sometimes contain some ambiguous elements. For instance,
10677 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10678 a single function name to be defined several times, for application in
10679 different contexts. This is called @dfn{overloading}. Another example
10680 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10681 templates and is typically instantiated several times, resulting in
10682 the same function name being defined in different contexts.
10683
10684 In some cases and depending on the language, it is possible to adjust
10685 the expression to remove the ambiguity. For instance in C@t{++}, you
10686 can specify the signature of the function you want to break on, as in
10687 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10688 qualified name of your function often makes the expression unambiguous
10689 as well.
10690
10691 When an ambiguity that needs to be resolved is detected, the debugger
10692 has the capability to display a menu of numbered choices for each
10693 possibility, and then waits for the selection with the prompt @samp{>}.
10694 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10695 aborts the current command. If the command in which the expression was
10696 used allows more than one choice to be selected, the next option in the
10697 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10698 choices.
10699
10700 For example, the following session excerpt shows an attempt to set a
10701 breakpoint at the overloaded symbol @code{String::after}.
10702 We choose three particular definitions of that function name:
10703
10704 @c FIXME! This is likely to change to show arg type lists, at least
10705 @smallexample
10706 @group
10707 (@value{GDBP}) b String::after
10708 [0] cancel
10709 [1] all
10710 [2] file:String.cc; line number:867
10711 [3] file:String.cc; line number:860
10712 [4] file:String.cc; line number:875
10713 [5] file:String.cc; line number:853
10714 [6] file:String.cc; line number:846
10715 [7] file:String.cc; line number:735
10716 > 2 4 6
10717 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10718 Breakpoint 2 at 0xb344: file String.cc, line 875.
10719 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10720 Multiple breakpoints were set.
10721 Use the "delete" command to delete unwanted
10722 breakpoints.
10723 (@value{GDBP})
10724 @end group
10725 @end smallexample
10726
10727 @table @code
10728 @kindex set multiple-symbols
10729 @item set multiple-symbols @var{mode}
10730 @cindex multiple-symbols menu
10731
10732 This option allows you to adjust the debugger behavior when an expression
10733 is ambiguous.
10734
10735 By default, @var{mode} is set to @code{all}. If the command with which
10736 the expression is used allows more than one choice, then @value{GDBN}
10737 automatically selects all possible choices. For instance, inserting
10738 a breakpoint on a function using an ambiguous name results in a breakpoint
10739 inserted on each possible match. However, if a unique choice must be made,
10740 then @value{GDBN} uses the menu to help you disambiguate the expression.
10741 For instance, printing the address of an overloaded function will result
10742 in the use of the menu.
10743
10744 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10745 when an ambiguity is detected.
10746
10747 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10748 an error due to the ambiguity and the command is aborted.
10749
10750 @kindex show multiple-symbols
10751 @item show multiple-symbols
10752 Show the current value of the @code{multiple-symbols} setting.
10753 @end table
10754
10755 @node Variables
10756 @section Program Variables
10757
10758 The most common kind of expression to use is the name of a variable
10759 in your program.
10760
10761 Variables in expressions are understood in the selected stack frame
10762 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10763
10764 @itemize @bullet
10765 @item
10766 global (or file-static)
10767 @end itemize
10768
10769 @noindent or
10770
10771 @itemize @bullet
10772 @item
10773 visible according to the scope rules of the
10774 programming language from the point of execution in that frame
10775 @end itemize
10776
10777 @noindent This means that in the function
10778
10779 @smallexample
10780 foo (a)
10781 int a;
10782 @{
10783 bar (a);
10784 @{
10785 int b = test ();
10786 bar (b);
10787 @}
10788 @}
10789 @end smallexample
10790
10791 @noindent
10792 you can examine and use the variable @code{a} whenever your program is
10793 executing within the function @code{foo}, but you can only use or
10794 examine the variable @code{b} while your program is executing inside
10795 the block where @code{b} is declared.
10796
10797 @cindex variable name conflict
10798 There is an exception: you can refer to a variable or function whose
10799 scope is a single source file even if the current execution point is not
10800 in this file. But it is possible to have more than one such variable or
10801 function with the same name (in different source files). If that
10802 happens, referring to that name has unpredictable effects. If you wish,
10803 you can specify a static variable in a particular function or file by
10804 using the colon-colon (@code{::}) notation:
10805
10806 @cindex colon-colon, context for variables/functions
10807 @ifnotinfo
10808 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10809 @cindex @code{::}, context for variables/functions
10810 @end ifnotinfo
10811 @smallexample
10812 @var{file}::@var{variable}
10813 @var{function}::@var{variable}
10814 @end smallexample
10815
10816 @noindent
10817 Here @var{file} or @var{function} is the name of the context for the
10818 static @var{variable}. In the case of file names, you can use quotes to
10819 make sure @value{GDBN} parses the file name as a single word---for example,
10820 to print a global value of @code{x} defined in @file{f2.c}:
10821
10822 @smallexample
10823 (@value{GDBP}) p 'f2.c'::x
10824 @end smallexample
10825
10826 The @code{::} notation is normally used for referring to
10827 static variables, since you typically disambiguate uses of local variables
10828 in functions by selecting the appropriate frame and using the
10829 simple name of the variable. However, you may also use this notation
10830 to refer to local variables in frames enclosing the selected frame:
10831
10832 @smallexample
10833 void
10834 foo (int a)
10835 @{
10836 if (a < 10)
10837 bar (a);
10838 else
10839 process (a); /* Stop here */
10840 @}
10841
10842 int
10843 bar (int a)
10844 @{
10845 foo (a + 5);
10846 @}
10847 @end smallexample
10848
10849 @noindent
10850 For example, if there is a breakpoint at the commented line,
10851 here is what you might see
10852 when the program stops after executing the call @code{bar(0)}:
10853
10854 @smallexample
10855 (@value{GDBP}) p a
10856 $1 = 10
10857 (@value{GDBP}) p bar::a
10858 $2 = 5
10859 (@value{GDBP}) up 2
10860 #2 0x080483d0 in foo (a=5) at foobar.c:12
10861 (@value{GDBP}) p a
10862 $3 = 5
10863 (@value{GDBP}) p bar::a
10864 $4 = 0
10865 @end smallexample
10866
10867 @cindex C@t{++} scope resolution
10868 These uses of @samp{::} are very rarely in conflict with the very
10869 similar use of the same notation in C@t{++}. When they are in
10870 conflict, the C@t{++} meaning takes precedence; however, this can be
10871 overridden by quoting the file or function name with single quotes.
10872
10873 For example, suppose the program is stopped in a method of a class
10874 that has a field named @code{includefile}, and there is also an
10875 include file named @file{includefile} that defines a variable,
10876 @code{some_global}.
10877
10878 @smallexample
10879 (@value{GDBP}) p includefile
10880 $1 = 23
10881 (@value{GDBP}) p includefile::some_global
10882 A syntax error in expression, near `'.
10883 (@value{GDBP}) p 'includefile'::some_global
10884 $2 = 27
10885 @end smallexample
10886
10887 @cindex wrong values
10888 @cindex variable values, wrong
10889 @cindex function entry/exit, wrong values of variables
10890 @cindex optimized code, wrong values of variables
10891 @quotation
10892 @emph{Warning:} Occasionally, a local variable may appear to have the
10893 wrong value at certain points in a function---just after entry to a new
10894 scope, and just before exit.
10895 @end quotation
10896 You may see this problem when you are stepping by machine instructions.
10897 This is because, on most machines, it takes more than one instruction to
10898 set up a stack frame (including local variable definitions); if you are
10899 stepping by machine instructions, variables may appear to have the wrong
10900 values until the stack frame is completely built. On exit, it usually
10901 also takes more than one machine instruction to destroy a stack frame;
10902 after you begin stepping through that group of instructions, local
10903 variable definitions may be gone.
10904
10905 This may also happen when the compiler does significant optimizations.
10906 To be sure of always seeing accurate values, turn off all optimization
10907 when compiling.
10908
10909 @cindex ``No symbol "foo" in current context''
10910 Another possible effect of compiler optimizations is to optimize
10911 unused variables out of existence, or assign variables to registers (as
10912 opposed to memory addresses). Depending on the support for such cases
10913 offered by the debug info format used by the compiler, @value{GDBN}
10914 might not be able to display values for such local variables. If that
10915 happens, @value{GDBN} will print a message like this:
10916
10917 @smallexample
10918 No symbol "foo" in current context.
10919 @end smallexample
10920
10921 To solve such problems, either recompile without optimizations, or use a
10922 different debug info format, if the compiler supports several such
10923 formats. @xref{Compilation}, for more information on choosing compiler
10924 options. @xref{C, ,C and C@t{++}}, for more information about debug
10925 info formats that are best suited to C@t{++} programs.
10926
10927 If you ask to print an object whose contents are unknown to
10928 @value{GDBN}, e.g., because its data type is not completely specified
10929 by the debug information, @value{GDBN} will say @samp{<incomplete
10930 type>}. @xref{Symbols, incomplete type}, for more about this.
10931
10932 @cindex no debug info variables
10933 If you try to examine or use the value of a (global) variable for
10934 which @value{GDBN} has no type information, e.g., because the program
10935 includes no debug information, @value{GDBN} displays an error message.
10936 @xref{Symbols, unknown type}, for more about unknown types. If you
10937 cast the variable to its declared type, @value{GDBN} gets the
10938 variable's value using the cast-to type as the variable's type. For
10939 example, in a C program:
10940
10941 @smallexample
10942 (@value{GDBP}) p var
10943 'var' has unknown type; cast it to its declared type
10944 (@value{GDBP}) p (float) var
10945 $1 = 3.14
10946 @end smallexample
10947
10948 If you append @kbd{@@entry} string to a function parameter name you get its
10949 value at the time the function got called. If the value is not available an
10950 error message is printed. Entry values are available only with some compilers.
10951 Entry values are normally also printed at the function parameter list according
10952 to @ref{set print entry-values}.
10953
10954 @smallexample
10955 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10956 29 i++;
10957 (@value{GDBP}) next
10958 30 e (i);
10959 (@value{GDBP}) print i
10960 $1 = 31
10961 (@value{GDBP}) print i@@entry
10962 $2 = 30
10963 @end smallexample
10964
10965 Strings are identified as arrays of @code{char} values without specified
10966 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10967 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10968 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10969 defines literal string type @code{"char"} as @code{char} without a sign.
10970 For program code
10971
10972 @smallexample
10973 char var0[] = "A";
10974 signed char var1[] = "A";
10975 @end smallexample
10976
10977 You get during debugging
10978 @smallexample
10979 (@value{GDBP}) print var0
10980 $1 = "A"
10981 (@value{GDBP}) print var1
10982 $2 = @{65 'A', 0 '\0'@}
10983 @end smallexample
10984
10985 @node Arrays
10986 @section Artificial Arrays
10987
10988 @cindex artificial array
10989 @cindex arrays
10990 @kindex @@@r{, referencing memory as an array}
10991 It is often useful to print out several successive objects of the
10992 same type in memory; a section of an array, or an array of
10993 dynamically determined size for which only a pointer exists in the
10994 program.
10995
10996 You can do this by referring to a contiguous span of memory as an
10997 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10998 operand of @samp{@@} should be the first element of the desired array
10999 and be an individual object. The right operand should be the desired length
11000 of the array. The result is an array value whose elements are all of
11001 the type of the left argument. The first element is actually the left
11002 argument; the second element comes from bytes of memory immediately
11003 following those that hold the first element, and so on. Here is an
11004 example. If a program says
11005
11006 @smallexample
11007 int *array = (int *) malloc (len * sizeof (int));
11008 @end smallexample
11009
11010 @noindent
11011 you can print the contents of @code{array} with
11012
11013 @smallexample
11014 p *array@@len
11015 @end smallexample
11016
11017 The left operand of @samp{@@} must reside in memory. Array values made
11018 with @samp{@@} in this way behave just like other arrays in terms of
11019 subscripting, and are coerced to pointers when used in expressions.
11020 Artificial arrays most often appear in expressions via the value history
11021 (@pxref{Value History, ,Value History}), after printing one out.
11022
11023 Another way to create an artificial array is to use a cast.
11024 This re-interprets a value as if it were an array.
11025 The value need not be in memory:
11026 @smallexample
11027 (@value{GDBP}) p/x (short[2])0x12345678
11028 $1 = @{0x1234, 0x5678@}
11029 @end smallexample
11030
11031 As a convenience, if you leave the array length out (as in
11032 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
11033 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
11034 @smallexample
11035 (@value{GDBP}) p/x (short[])0x12345678
11036 $2 = @{0x1234, 0x5678@}
11037 @end smallexample
11038
11039 Sometimes the artificial array mechanism is not quite enough; in
11040 moderately complex data structures, the elements of interest may not
11041 actually be adjacent---for example, if you are interested in the values
11042 of pointers in an array. One useful work-around in this situation is
11043 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
11044 Variables}) as a counter in an expression that prints the first
11045 interesting value, and then repeat that expression via @key{RET}. For
11046 instance, suppose you have an array @code{dtab} of pointers to
11047 structures, and you are interested in the values of a field @code{fv}
11048 in each structure. Here is an example of what you might type:
11049
11050 @smallexample
11051 set $i = 0
11052 p dtab[$i++]->fv
11053 @key{RET}
11054 @key{RET}
11055 @dots{}
11056 @end smallexample
11057
11058 @node Output Formats
11059 @section Output Formats
11060
11061 @cindex formatted output
11062 @cindex output formats
11063 By default, @value{GDBN} prints a value according to its data type. Sometimes
11064 this is not what you want. For example, you might want to print a number
11065 in hex, or a pointer in decimal. Or you might want to view data in memory
11066 at a certain address as a character string or as an instruction. To do
11067 these things, specify an @dfn{output format} when you print a value.
11068
11069 The simplest use of output formats is to say how to print a value
11070 already computed. This is done by starting the arguments of the
11071 @code{print} command with a slash and a format letter. The format
11072 letters supported are:
11073
11074 @table @code
11075 @item x
11076 Print the binary representation of the value in hexadecimal.
11077
11078 @item d
11079 Print the binary representation of the value in decimal.
11080
11081 @item u
11082 Print the binary representation of the value as an decimal, as if it
11083 were unsigned.
11084
11085 @item o
11086 Print the binary representation of the value in octal.
11087
11088 @item t
11089 Print the binary representation of the value in binary. The letter
11090 @samp{t} stands for ``two''. @footnote{@samp{b} cannot be used
11091 because these format letters are also used with the @code{x} command,
11092 where @samp{b} stands for ``byte''; see @ref{Memory,,Examining
11093 Memory}.}
11094
11095 @item a
11096 @cindex unknown address, locating
11097 @cindex locate address
11098 Print as an address, both absolute in hexadecimal and as an offset from
11099 the nearest preceding symbol. You can use this format used to discover
11100 where (in what function) an unknown address is located:
11101
11102 @smallexample
11103 (@value{GDBP}) p/a 0x54320
11104 $3 = 0x54320 <_initialize_vx+396>
11105 @end smallexample
11106
11107 @noindent
11108 The command @code{info symbol 0x54320} yields similar results.
11109 @xref{Symbols, info symbol}.
11110
11111 @item c
11112 Cast the value to an integer (unlike other formats, this does not just
11113 reinterpret the underlying bits) and print it as a character constant.
11114 This prints both the numerical value and its character representation.
11115 The character representation is replaced with the octal escape
11116 @samp{\nnn} for characters outside the 7-bit @sc{ascii} range.
11117
11118 Without this format, @value{GDBN} displays @code{char},
11119 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
11120 constants. Single-byte members of vectors are displayed as integer
11121 data.
11122
11123 @item f
11124 Regard the bits of the value as a floating point number and print
11125 using typical floating point syntax.
11126
11127 @item s
11128 @cindex printing strings
11129 @cindex printing byte arrays
11130 Regard as a string, if possible. With this format, pointers to single-byte
11131 data are displayed as null-terminated strings and arrays of single-byte data
11132 are displayed as fixed-length strings. Other values are displayed in their
11133 natural types.
11134
11135 Without this format, @value{GDBN} displays pointers to and arrays of
11136 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
11137 strings. Single-byte members of a vector are displayed as an integer
11138 array.
11139
11140 @item z
11141 Like @samp{x} formatting, the value is treated as an integer and
11142 printed as hexadecimal, but leading zeros are printed to pad the value
11143 to the size of the integer type.
11144
11145 @item r
11146 @cindex raw printing
11147 Print using the @samp{raw} formatting. By default, @value{GDBN} will
11148 use a Python-based pretty-printer, if one is available (@pxref{Pretty
11149 Printing}). This typically results in a higher-level display of the
11150 value's contents. The @samp{r} format bypasses any Python
11151 pretty-printer which might exist.
11152 @end table
11153
11154 For example, to print the program counter in hex (@pxref{Registers}), type
11155
11156 @smallexample
11157 p/x $pc
11158 @end smallexample
11159
11160 @noindent
11161 Note that no space is required before the slash; this is because command
11162 names in @value{GDBN} cannot contain a slash.
11163
11164 To reprint the last value in the value history with a different format,
11165 you can use the @code{print} command with just a format and no
11166 expression. For example, @samp{p/x} reprints the last value in hex.
11167
11168 @node Memory
11169 @section Examining Memory
11170
11171 You can use the command @code{x} (for ``examine'') to examine memory in
11172 any of several formats, independently of your program's data types.
11173
11174 @cindex examining memory
11175 @table @code
11176 @kindex x @r{(examine memory)}
11177 @item x/@var{nfu} @var{addr}
11178 @itemx x @var{addr}
11179 @itemx x
11180 Use the @code{x} command to examine memory.
11181 @end table
11182
11183 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
11184 much memory to display and how to format it; @var{addr} is an
11185 expression giving the address where you want to start displaying memory.
11186 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
11187 Several commands set convenient defaults for @var{addr}.
11188
11189 @table @r
11190 @item @var{n}, the repeat count
11191 The repeat count is a decimal integer; the default is 1. It specifies
11192 how much memory (counting by units @var{u}) to display. If a negative
11193 number is specified, memory is examined backward from @var{addr}.
11194 @c This really is **decimal**; unaffected by 'set radix' as of GDB
11195 @c 4.1.2.
11196
11197 @item @var{f}, the display format
11198 The display format is one of the formats used by @code{print}
11199 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
11200 @samp{f}, @samp{s}), @samp{i} (for machine instructions) and
11201 @samp{m} (for displaying memory tags).
11202 The default is @samp{x} (hexadecimal) initially. The default changes
11203 each time you use either @code{x} or @code{print}.
11204
11205 @item @var{u}, the unit size
11206 The unit size is any of
11207
11208 @table @code
11209 @item b
11210 Bytes.
11211 @item h
11212 Halfwords (two bytes).
11213 @item w
11214 Words (four bytes). This is the initial default.
11215 @item g
11216 Giant words (eight bytes).
11217 @end table
11218
11219 Each time you specify a unit size with @code{x}, that size becomes the
11220 default unit the next time you use @code{x}. For the @samp{i} format,
11221 the unit size is ignored and is normally not written. For the @samp{s} format,
11222 the unit size defaults to @samp{b}, unless it is explicitly given.
11223 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
11224 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
11225 Note that the results depend on the programming language of the
11226 current compilation unit. If the language is C, the @samp{s}
11227 modifier will use the UTF-16 encoding while @samp{w} will use
11228 UTF-32. The encoding is set by the programming language and cannot
11229 be altered.
11230
11231 @item @var{addr}, starting display address
11232 @var{addr} is the address where you want @value{GDBN} to begin displaying
11233 memory. The expression need not have a pointer value (though it may);
11234 it is always interpreted as an integer address of a byte of memory.
11235 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
11236 @var{addr} is usually just after the last address examined---but several
11237 other commands also set the default address: @code{info breakpoints} (to
11238 the address of the last breakpoint listed), @code{info line} (to the
11239 starting address of a line), and @code{print} (if you use it to display
11240 a value from memory).
11241 @end table
11242
11243 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
11244 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
11245 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
11246 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
11247 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
11248
11249 You can also specify a negative repeat count to examine memory backward
11250 from the given address. For example, @samp{x/-3uh 0x54320} prints three
11251 halfwords (@code{h}) at @code{0x5431a}, @code{0x5431c}, and @code{0x5431e}.
11252
11253 Since the letters indicating unit sizes are all distinct from the
11254 letters specifying output formats, you do not have to remember whether
11255 unit size or format comes first; either order works. The output
11256 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
11257 (However, the count @var{n} must come first; @samp{wx4} does not work.)
11258
11259 Even though the unit size @var{u} is ignored for the formats @samp{s}
11260 and @samp{i}, you might still want to use a count @var{n}; for example,
11261 @samp{3i} specifies that you want to see three machine instructions,
11262 including any operands. For convenience, especially when used with
11263 the @code{display} command, the @samp{i} format also prints branch delay
11264 slot instructions, if any, beyond the count specified, which immediately
11265 follow the last instruction that is within the count. The command
11266 @code{disassemble} gives an alternative way of inspecting machine
11267 instructions; see @ref{Machine Code,,Source and Machine Code}.
11268
11269 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
11270 the command displays null-terminated strings or instructions before the given
11271 address as many as the absolute value of the given number. For the @samp{i}
11272 format, we use line number information in the debug info to accurately locate
11273 instruction boundaries while disassembling backward. If line info is not
11274 available, the command stops examining memory with an error message.
11275
11276 All the defaults for the arguments to @code{x} are designed to make it
11277 easy to continue scanning memory with minimal specifications each time
11278 you use @code{x}. For example, after you have inspected three machine
11279 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
11280 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
11281 the repeat count @var{n} is used again; the other arguments default as
11282 for successive uses of @code{x}.
11283
11284 When examining machine instructions, the instruction at current program
11285 counter is shown with a @code{=>} marker. For example:
11286
11287 @smallexample
11288 (@value{GDBP}) x/5i $pc-6
11289 0x804837f <main+11>: mov %esp,%ebp
11290 0x8048381 <main+13>: push %ecx
11291 0x8048382 <main+14>: sub $0x4,%esp
11292 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
11293 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
11294 @end smallexample
11295
11296 If the architecture supports memory tagging, the tags can be displayed by
11297 using @samp{m}. @xref{Memory Tagging}.
11298
11299 The information will be displayed once per granule size
11300 (the amount of bytes a particular memory tag covers). For example, AArch64
11301 has a granule size of 16 bytes, so it will display a tag every 16 bytes.
11302
11303 Due to the way @value{GDBN} prints information with the @code{x} command (not
11304 aligned to a particular boundary), the tag information will refer to the
11305 initial address displayed on a particular line. If a memory tag boundary
11306 is crossed in the middle of a line displayed by the @code{x} command, it
11307 will be displayed on the next line.
11308
11309 The @samp{m} format doesn't affect any other specified formats that were
11310 passed to the @code{x} command.
11311
11312 @cindex @code{$_}, @code{$__}, and value history
11313 The addresses and contents printed by the @code{x} command are not saved
11314 in the value history because there is often too much of them and they
11315 would get in the way. Instead, @value{GDBN} makes these values available for
11316 subsequent use in expressions as values of the convenience variables
11317 @code{$_} and @code{$__}. After an @code{x} command, the last address
11318 examined is available for use in expressions in the convenience variable
11319 @code{$_}. The contents of that address, as examined, are available in
11320 the convenience variable @code{$__}.
11321
11322 If the @code{x} command has a repeat count, the address and contents saved
11323 are from the last memory unit printed; this is not the same as the last
11324 address printed if several units were printed on the last line of output.
11325
11326 @anchor{addressable memory unit}
11327 @cindex addressable memory unit
11328 Most targets have an addressable memory unit size of 8 bits. This means
11329 that to each memory address are associated 8 bits of data. Some
11330 targets, however, have other addressable memory unit sizes.
11331 Within @value{GDBN} and this document, the term
11332 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
11333 when explicitly referring to a chunk of data of that size. The word
11334 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
11335 the addressable memory unit size of the target. For most systems,
11336 addressable memory unit is a synonym of byte.
11337
11338 @cindex remote memory comparison
11339 @cindex target memory comparison
11340 @cindex verify remote memory image
11341 @cindex verify target memory image
11342 When you are debugging a program running on a remote target machine
11343 (@pxref{Remote Debugging}), you may wish to verify the program's image
11344 in the remote machine's memory against the executable file you
11345 downloaded to the target. Or, on any target, you may want to check
11346 whether the program has corrupted its own read-only sections. The
11347 @code{compare-sections} command is provided for such situations.
11348
11349 @table @code
11350 @kindex compare-sections
11351 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
11352 Compare the data of a loadable section @var{section-name} in the
11353 executable file of the program being debugged with the same section in
11354 the target machine's memory, and report any mismatches. With no
11355 arguments, compares all loadable sections. With an argument of
11356 @code{-r}, compares all loadable read-only sections.
11357
11358 Note: for remote targets, this command can be accelerated if the
11359 target supports computing the CRC checksum of a block of memory
11360 (@pxref{qCRC packet}).
11361 @end table
11362
11363 @node Memory Tagging
11364 @section Memory Tagging
11365
11366 Memory tagging is a memory protection technology that uses a pair of tags to
11367 validate memory accesses through pointers. The tags are integer values
11368 usually comprised of a few bits, depending on the architecture.
11369
11370 There are two types of tags that are used in this setup: logical and
11371 allocation. A logical tag is stored in the pointers themselves, usually at the
11372 higher bits of the pointers. An allocation tag is the tag associated
11373 with particular ranges of memory in the physical address space, against which
11374 the logical tags from pointers are compared.
11375
11376 The pointer tag (logical tag) must match the memory tag (allocation tag)
11377 for the memory access to be valid. If the logical tag does not match the
11378 allocation tag, that will raise a memory violation.
11379
11380 Allocation tags cover multiple contiguous bytes of physical memory. This
11381 range of bytes is called a memory tag granule and is architecture-specific.
11382 For example, AArch64 has a tag granule of 16 bytes, meaning each allocation
11383 tag spans 16 bytes of memory.
11384
11385 If the underlying architecture supports memory tagging, like AArch64 MTE
11386 or SPARC ADI do, @value{GDBN} can make use of it to validate pointers
11387 against memory allocation tags.
11388
11389 The @code{print} (@pxref{Data}) and @code{x} (@pxref{Memory}) commands will
11390 display tag information when appropriate, and a command prefix of
11391 @code{memory-tag} gives access to the various memory tagging commands.
11392
11393 The @code{memory-tag} commands are the following:
11394
11395 @table @code
11396 @kindex memory-tag print-logical-tag
11397 @item memory-tag print-logical-tag @var{pointer_expression}
11398 Print the logical tag stored in @var{pointer_expression}.
11399 @kindex memory-tag with-logical-tag
11400 @item memory-tag with-logical-tag @var{pointer_expression} @var{tag_bytes}
11401 Print the pointer given by @var{pointer_expression}, augmented with a logical
11402 tag of @var{tag_bytes}.
11403 @kindex memory-tag print-allocation-tag
11404 @item memory-tag print-allocation-tag @var{address_expression}
11405 Print the allocation tag associated with the memory address given by
11406 @var{address_expression}.
11407 @kindex memory-tag setatag
11408 @item memory-tag setatag @var{starting_address} @var{length} @var{tag_bytes}
11409 Set the allocation tag(s) for memory range @r{[}@var{starting_address},
11410 @var{starting_address} + @var{length}@r{)} to @var{tag_bytes}.
11411 @kindex memory-tag check
11412 @item memory-tag check @var{pointer_expression}
11413 Check if the logical tag in the pointer given by @var{pointer_expression}
11414 matches the allocation tag for the memory referenced by the pointer.
11415
11416 This essentially emulates the hardware validation that is done when tagged
11417 memory is accessed through a pointer, but does not cause a memory fault as
11418 it would during hardware validation.
11419
11420 It can be used to inspect potential memory tagging violations in the running
11421 process, before any faults get triggered.
11422 @end table
11423
11424 @node Auto Display
11425 @section Automatic Display
11426 @cindex automatic display
11427 @cindex display of expressions
11428
11429 If you find that you want to print the value of an expression frequently
11430 (to see how it changes), you might want to add it to the @dfn{automatic
11431 display list} so that @value{GDBN} prints its value each time your program stops.
11432 Each expression added to the list is given a number to identify it;
11433 to remove an expression from the list, you specify that number.
11434 The automatic display looks like this:
11435
11436 @smallexample
11437 2: foo = 38
11438 3: bar[5] = (struct hack *) 0x3804
11439 @end smallexample
11440
11441 @noindent
11442 This display shows item numbers, expressions and their current values. As with
11443 displays you request manually using @code{x} or @code{print}, you can
11444 specify the output format you prefer; in fact, @code{display} decides
11445 whether to use @code{print} or @code{x} depending your format
11446 specification---it uses @code{x} if you specify either the @samp{i}
11447 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
11448
11449 @table @code
11450 @kindex display
11451 @item display @var{expr}
11452 Add the expression @var{expr} to the list of expressions to display
11453 each time your program stops. @xref{Expressions, ,Expressions}.
11454
11455 @code{display} does not repeat if you press @key{RET} again after using it.
11456
11457 @item display/@var{fmt} @var{expr}
11458 For @var{fmt} specifying only a display format and not a size or
11459 count, add the expression @var{expr} to the auto-display list but
11460 arrange to display it each time in the specified format @var{fmt}.
11461 @xref{Output Formats,,Output Formats}.
11462
11463 @item display/@var{fmt} @var{addr}
11464 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
11465 number of units, add the expression @var{addr} as a memory address to
11466 be examined each time your program stops. Examining means in effect
11467 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
11468 @end table
11469
11470 For example, @samp{display/i $pc} can be helpful, to see the machine
11471 instruction about to be executed each time execution stops (@samp{$pc}
11472 is a common name for the program counter; @pxref{Registers, ,Registers}).
11473
11474 @table @code
11475 @kindex delete display
11476 @kindex undisplay
11477 @item undisplay @var{dnums}@dots{}
11478 @itemx delete display @var{dnums}@dots{}
11479 Remove items from the list of expressions to display. Specify the
11480 numbers of the displays that you want affected with the command
11481 argument @var{dnums}. It can be a single display number, one of the
11482 numbers shown in the first field of the @samp{info display} display;
11483 or it could be a range of display numbers, as in @code{2-4}.
11484
11485 @code{undisplay} does not repeat if you press @key{RET} after using it.
11486 (Otherwise you would just get the error @samp{No display number @dots{}}.)
11487
11488 @kindex disable display
11489 @item disable display @var{dnums}@dots{}
11490 Disable the display of item numbers @var{dnums}. A disabled display
11491 item is not printed automatically, but is not forgotten. It may be
11492 enabled again later. Specify the numbers of the displays that you
11493 want affected with the command argument @var{dnums}. It can be a
11494 single display number, one of the numbers shown in the first field of
11495 the @samp{info display} display; or it could be a range of display
11496 numbers, as in @code{2-4}.
11497
11498 @kindex enable display
11499 @item enable display @var{dnums}@dots{}
11500 Enable display of item numbers @var{dnums}. It becomes effective once
11501 again in auto display of its expression, until you specify otherwise.
11502 Specify the numbers of the displays that you want affected with the
11503 command argument @var{dnums}. It can be a single display number, one
11504 of the numbers shown in the first field of the @samp{info display}
11505 display; or it could be a range of display numbers, as in @code{2-4}.
11506
11507 @item display
11508 Display the current values of the expressions on the list, just as is
11509 done when your program stops.
11510
11511 @kindex info display
11512 @item info display
11513 Print the list of expressions previously set up to display
11514 automatically, each one with its item number, but without showing the
11515 values. This includes disabled expressions, which are marked as such.
11516 It also includes expressions which would not be displayed right now
11517 because they refer to automatic variables not currently available.
11518 @end table
11519
11520 @cindex display disabled out of scope
11521 If a display expression refers to local variables, then it does not make
11522 sense outside the lexical context for which it was set up. Such an
11523 expression is disabled when execution enters a context where one of its
11524 variables is not defined. For example, if you give the command
11525 @code{display last_char} while inside a function with an argument
11526 @code{last_char}, @value{GDBN} displays this argument while your program
11527 continues to stop inside that function. When it stops elsewhere---where
11528 there is no variable @code{last_char}---the display is disabled
11529 automatically. The next time your program stops where @code{last_char}
11530 is meaningful, you can enable the display expression once again.
11531
11532 @node Print Settings
11533 @section Print Settings
11534
11535 @cindex format options
11536 @cindex print settings
11537 @value{GDBN} provides the following ways to control how arrays, structures,
11538 and symbols are printed.
11539
11540 @noindent
11541 These settings are useful for debugging programs in any language:
11542
11543 @table @code
11544 @kindex set print
11545 @anchor{set print address}
11546 @item set print address
11547 @itemx set print address on
11548 @cindex print/don't print memory addresses
11549 @value{GDBN} prints memory addresses showing the location of stack
11550 traces, structure values, pointer values, breakpoints, and so forth,
11551 even when it also displays the contents of those addresses. The default
11552 is @code{on}. For example, this is what a stack frame display looks like with
11553 @code{set print address on}:
11554
11555 @smallexample
11556 @group
11557 (@value{GDBP}) f
11558 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11559 at input.c:530
11560 530 if (lquote != def_lquote)
11561 @end group
11562 @end smallexample
11563
11564 @item set print address off
11565 Do not print addresses when displaying their contents. For example,
11566 this is the same stack frame displayed with @code{set print address off}:
11567
11568 @smallexample
11569 @group
11570 (@value{GDBP}) set print addr off
11571 (@value{GDBP}) f
11572 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11573 530 if (lquote != def_lquote)
11574 @end group
11575 @end smallexample
11576
11577 You can use @samp{set print address off} to eliminate all machine
11578 dependent displays from the @value{GDBN} interface. For example, with
11579 @code{print address off}, you should get the same text for backtraces on
11580 all machines---whether or not they involve pointer arguments.
11581
11582 @kindex show print
11583 @item show print address
11584 Show whether or not addresses are to be printed.
11585 @end table
11586
11587 When @value{GDBN} prints a symbolic address, it normally prints the
11588 closest earlier symbol plus an offset. If that symbol does not uniquely
11589 identify the address (for example, it is a name whose scope is a single
11590 source file), you may need to clarify. One way to do this is with
11591 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11592 you can set @value{GDBN} to print the source file and line number when
11593 it prints a symbolic address:
11594
11595 @table @code
11596 @item set print symbol-filename on
11597 @cindex source file and line of a symbol
11598 @cindex symbol, source file and line
11599 Tell @value{GDBN} to print the source file name and line number of a
11600 symbol in the symbolic form of an address.
11601
11602 @item set print symbol-filename off
11603 Do not print source file name and line number of a symbol. This is the
11604 default.
11605
11606 @item show print symbol-filename
11607 Show whether or not @value{GDBN} will print the source file name and
11608 line number of a symbol in the symbolic form of an address.
11609 @end table
11610
11611 Another situation where it is helpful to show symbol filenames and line
11612 numbers is when disassembling code; @value{GDBN} shows you the line
11613 number and source file that corresponds to each instruction.
11614
11615 Also, you may wish to see the symbolic form only if the address being
11616 printed is reasonably close to the closest earlier symbol:
11617
11618 @table @code
11619 @item set print max-symbolic-offset @var{max-offset}
11620 @itemx set print max-symbolic-offset unlimited
11621 @cindex maximum value for offset of closest symbol
11622 Tell @value{GDBN} to only display the symbolic form of an address if the
11623 offset between the closest earlier symbol and the address is less than
11624 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11625 to always print the symbolic form of an address if any symbol precedes
11626 it. Zero is equivalent to @code{unlimited}.
11627
11628 @item show print max-symbolic-offset
11629 Ask how large the maximum offset is that @value{GDBN} prints in a
11630 symbolic address.
11631 @end table
11632
11633 @cindex wild pointer, interpreting
11634 @cindex pointer, finding referent
11635 If you have a pointer and you are not sure where it points, try
11636 @samp{set print symbol-filename on}. Then you can determine the name
11637 and source file location of the variable where it points, using
11638 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11639 For example, here @value{GDBN} shows that a variable @code{ptt} points
11640 at another variable @code{t}, defined in @file{hi2.c}:
11641
11642 @smallexample
11643 (@value{GDBP}) set print symbol-filename on
11644 (@value{GDBP}) p/a ptt
11645 $4 = 0xe008 <t in hi2.c>
11646 @end smallexample
11647
11648 @quotation
11649 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11650 does not show the symbol name and filename of the referent, even with
11651 the appropriate @code{set print} options turned on.
11652 @end quotation
11653
11654 You can also enable @samp{/a}-like formatting all the time using
11655 @samp{set print symbol on}:
11656
11657 @anchor{set print symbol}
11658 @table @code
11659 @item set print symbol on
11660 Tell @value{GDBN} to print the symbol corresponding to an address, if
11661 one exists.
11662
11663 @item set print symbol off
11664 Tell @value{GDBN} not to print the symbol corresponding to an
11665 address. In this mode, @value{GDBN} will still print the symbol
11666 corresponding to pointers to functions. This is the default.
11667
11668 @item show print symbol
11669 Show whether @value{GDBN} will display the symbol corresponding to an
11670 address.
11671 @end table
11672
11673 Other settings control how different kinds of objects are printed:
11674
11675 @table @code
11676 @anchor{set print array}
11677 @item set print array
11678 @itemx set print array on
11679 @cindex pretty print arrays
11680 Pretty print arrays. This format is more convenient to read,
11681 but uses more space. The default is off.
11682
11683 @item set print array off
11684 Return to compressed format for arrays.
11685
11686 @item show print array
11687 Show whether compressed or pretty format is selected for displaying
11688 arrays.
11689
11690 @cindex print array indexes
11691 @anchor{set print array-indexes}
11692 @item set print array-indexes
11693 @itemx set print array-indexes on
11694 Print the index of each element when displaying arrays. May be more
11695 convenient to locate a given element in the array or quickly find the
11696 index of a given element in that printed array. The default is off.
11697
11698 @item set print array-indexes off
11699 Stop printing element indexes when displaying arrays.
11700
11701 @item show print array-indexes
11702 Show whether the index of each element is printed when displaying
11703 arrays.
11704
11705 @anchor{set print nibbles}
11706 @item set print nibbles
11707 @itemx set print nibbles on
11708 @cindex print binary values in groups of four bits
11709 Print binary values in groups of four bits, known as @dfn{nibbles},
11710 when using the print command of @value{GDBN} with the option @samp{/t}.
11711 For example, this is what it looks like with @code{set print nibbles on}:
11712
11713 @smallexample
11714 @group
11715 (@value{GDBP}) print val_flags
11716 $1 = 1230
11717 (@value{GDBP}) print/t val_flags
11718 $2 = 0100 1100 1110
11719 @end group
11720 @end smallexample
11721
11722 @item set print nibbles off
11723 Don't printing binary values in groups. This is the default.
11724
11725 @item show print nibbles
11726 Show whether to print binary values in groups of four bits.
11727
11728 @anchor{set print characters}
11729 @item set print characters @var{number-of-characters}
11730 @itemx set print characters elements
11731 @itemx set print characters unlimited
11732 @cindex number of string characters to print
11733 @cindex limit on number of printed string characters
11734 Set a limit on how many characters of a string @value{GDBN} will print.
11735 If @value{GDBN} is printing a large string, it stops printing after it
11736 has printed the number of characters set by the @code{set print
11737 characters} command. This equally applies to multi-byte and wide
11738 character strings, that is for strings whose character type is
11739 @code{wchar_t}, @code{char16_t}, or @code{char32_t} it is the number of
11740 actual characters rather than underlying bytes the encoding uses that
11741 this setting controls.
11742 Setting @var{number-of-characters} to @code{elements} means that the
11743 limit on the number of characters to print follows one for array
11744 elements; see @ref{set print elements}.
11745 Setting @var{number-of-characters} to @code{unlimited} means that the
11746 number of characters to print is unlimited.
11747 When @value{GDBN} starts, this limit is set to @code{elements}.
11748
11749 @item show print characters
11750 Display the number of characters of a large string that @value{GDBN}
11751 will print.
11752
11753 @anchor{set print elements}
11754 @item set print elements @var{number-of-elements}
11755 @itemx set print elements unlimited
11756 @cindex number of array elements to print
11757 @cindex limit on number of printed array elements
11758 Set a limit on how many elements of an array @value{GDBN} will print.
11759 If @value{GDBN} is printing a large array, it stops printing after it has
11760 printed the number of elements set by the @code{set print elements} command.
11761 By default this limit also applies to the display of strings; see
11762 @ref{set print characters}.
11763 When @value{GDBN} starts, this limit is set to 200.
11764 Setting @var{number-of-elements} to @code{unlimited} or zero means
11765 that the number of elements to print is unlimited.
11766
11767 When printing very large arrays, whose size is greater than
11768 @code{max-value-size} (@pxref{set max-value-size,,max-value-size}),
11769 if the @code{print elements} is set such that the size of the elements
11770 being printed is less than or equal to @code{max-value-size}, then
11771 @value{GDBN} will print the array (up to the @code{print elements} limit),
11772 and only @code{max-value-size} worth of data will be added into the value
11773 history (@pxref{Value History, ,Value History}).
11774
11775 @item show print elements
11776 Display the number of elements of a large array that @value{GDBN} will print.
11777
11778 @anchor{set print frame-arguments}
11779 @item set print frame-arguments @var{value}
11780 @kindex set print frame-arguments
11781 @cindex printing frame argument values
11782 @cindex print all frame argument values
11783 @cindex print frame argument values for scalars only
11784 @cindex do not print frame arguments
11785 This command allows to control how the values of arguments are printed
11786 when the debugger prints a frame (@pxref{Frames}). The possible
11787 values are:
11788
11789 @table @code
11790 @item all
11791 The values of all arguments are printed.
11792
11793 @item scalars
11794 Print the value of an argument only if it is a scalar. The value of more
11795 complex arguments such as arrays, structures, unions, etc, is replaced
11796 by @code{@dots{}}. This is the default. Here is an example where
11797 only scalar arguments are shown:
11798
11799 @smallexample
11800 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11801 at frame-args.c:23
11802 @end smallexample
11803
11804 @item none
11805 None of the argument values are printed. Instead, the value of each argument
11806 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11807
11808 @smallexample
11809 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11810 at frame-args.c:23
11811 @end smallexample
11812
11813 @item presence
11814 Only the presence of arguments is indicated by @code{@dots{}}.
11815 The @code{@dots{}} are not printed for function without any arguments.
11816 None of the argument names and values are printed.
11817 In this case, the example above now becomes:
11818
11819 @smallexample
11820 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11821 @end smallexample
11822
11823 @end table
11824
11825 By default, only scalar arguments are printed. This command can be used
11826 to configure the debugger to print the value of all arguments, regardless
11827 of their type. However, it is often advantageous to not print the value
11828 of more complex parameters. For instance, it reduces the amount of
11829 information printed in each frame, making the backtrace more readable.
11830 Also, it improves performance when displaying Ada frames, because
11831 the computation of large arguments can sometimes be CPU-intensive,
11832 especially in large applications. Setting @code{print frame-arguments}
11833 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11834 this computation, thus speeding up the display of each Ada frame.
11835
11836 @item show print frame-arguments
11837 Show how the value of arguments should be displayed when printing a frame.
11838
11839 @anchor{set print raw-frame-arguments}
11840 @item set print raw-frame-arguments on
11841 Print frame arguments in raw, non pretty-printed, form.
11842
11843 @item set print raw-frame-arguments off
11844 Print frame arguments in pretty-printed form, if there is a pretty-printer
11845 for the value (@pxref{Pretty Printing}),
11846 otherwise print the value in raw form.
11847 This is the default.
11848
11849 @item show print raw-frame-arguments
11850 Show whether to print frame arguments in raw form.
11851
11852 @anchor{set print entry-values}
11853 @item set print entry-values @var{value}
11854 @kindex set print entry-values
11855 Set printing of frame argument values at function entry. In some cases
11856 @value{GDBN} can determine the value of function argument which was passed by
11857 the function caller, even if the value was modified inside the called function
11858 and therefore is different. With optimized code, the current value could be
11859 unavailable, but the entry value may still be known.
11860
11861 The default value is @code{default} (see below for its description). Older
11862 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11863 this feature will behave in the @code{default} setting the same way as with the
11864 @code{no} setting.
11865
11866 This functionality is currently supported only by DWARF 2 debugging format and
11867 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11868 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11869 this information.
11870
11871 The @var{value} parameter can be one of the following:
11872
11873 @table @code
11874 @item no
11875 Print only actual parameter values, never print values from function entry
11876 point.
11877 @smallexample
11878 #0 equal (val=5)
11879 #0 different (val=6)
11880 #0 lost (val=<optimized out>)
11881 #0 born (val=10)
11882 #0 invalid (val=<optimized out>)
11883 @end smallexample
11884
11885 @item only
11886 Print only parameter values from function entry point. The actual parameter
11887 values are never printed.
11888 @smallexample
11889 #0 equal (val@@entry=5)
11890 #0 different (val@@entry=5)
11891 #0 lost (val@@entry=5)
11892 #0 born (val@@entry=<optimized out>)
11893 #0 invalid (val@@entry=<optimized out>)
11894 @end smallexample
11895
11896 @item preferred
11897 Print only parameter values from function entry point. If value from function
11898 entry point is not known while the actual value is known, print the actual
11899 value for such parameter.
11900 @smallexample
11901 #0 equal (val@@entry=5)
11902 #0 different (val@@entry=5)
11903 #0 lost (val@@entry=5)
11904 #0 born (val=10)
11905 #0 invalid (val@@entry=<optimized out>)
11906 @end smallexample
11907
11908 @item if-needed
11909 Print actual parameter values. If actual parameter value is not known while
11910 value from function entry point is known, print the entry point value for such
11911 parameter.
11912 @smallexample
11913 #0 equal (val=5)
11914 #0 different (val=6)
11915 #0 lost (val@@entry=5)
11916 #0 born (val=10)
11917 #0 invalid (val=<optimized out>)
11918 @end smallexample
11919
11920 @item both
11921 Always print both the actual parameter value and its value from function entry
11922 point, even if values of one or both are not available due to compiler
11923 optimizations.
11924 @smallexample
11925 #0 equal (val=5, val@@entry=5)
11926 #0 different (val=6, val@@entry=5)
11927 #0 lost (val=<optimized out>, val@@entry=5)
11928 #0 born (val=10, val@@entry=<optimized out>)
11929 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11930 @end smallexample
11931
11932 @item compact
11933 Print the actual parameter value if it is known and also its value from
11934 function entry point if it is known. If neither is known, print for the actual
11935 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11936 values are known and identical, print the shortened
11937 @code{param=param@@entry=VALUE} notation.
11938 @smallexample
11939 #0 equal (val=val@@entry=5)
11940 #0 different (val=6, val@@entry=5)
11941 #0 lost (val@@entry=5)
11942 #0 born (val=10)
11943 #0 invalid (val=<optimized out>)
11944 @end smallexample
11945
11946 @item default
11947 Always print the actual parameter value. Print also its value from function
11948 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11949 if both values are known and identical, print the shortened
11950 @code{param=param@@entry=VALUE} notation.
11951 @smallexample
11952 #0 equal (val=val@@entry=5)
11953 #0 different (val=6, val@@entry=5)
11954 #0 lost (val=<optimized out>, val@@entry=5)
11955 #0 born (val=10)
11956 #0 invalid (val=<optimized out>)
11957 @end smallexample
11958 @end table
11959
11960 For analysis messages on possible failures of frame argument values at function
11961 entry resolution see @ref{set debug entry-values}.
11962
11963 @item show print entry-values
11964 Show the method being used for printing of frame argument values at function
11965 entry.
11966
11967 @anchor{set print frame-info}
11968 @item set print frame-info @var{value}
11969 @kindex set print frame-info
11970 @cindex printing frame information
11971 @cindex frame information, printing
11972 This command allows to control the information printed when
11973 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11974 for a general explanation about frames and frame information.
11975 Note that some other settings (such as @code{set print frame-arguments}
11976 and @code{set print address}) are also influencing if and how some frame
11977 information is displayed. In particular, the frame program counter is never
11978 printed if @code{set print address} is off.
11979
11980 The possible values for @code{set print frame-info} are:
11981 @table @code
11982 @item short-location
11983 Print the frame level, the program counter (if not at the
11984 beginning of the location source line), the function, the function
11985 arguments.
11986 @item location
11987 Same as @code{short-location} but also print the source file and source line
11988 number.
11989 @item location-and-address
11990 Same as @code{location} but print the program counter even if located at the
11991 beginning of the location source line.
11992 @item source-line
11993 Print the program counter (if not at the beginning of the location
11994 source line), the line number and the source line.
11995 @item source-and-location
11996 Print what @code{location} and @code{source-line} are printing.
11997 @item auto
11998 The information printed for a frame is decided automatically
11999 by the @value{GDBN} command that prints a frame.
12000 For example, @code{frame} prints the information printed by
12001 @code{source-and-location} while @code{stepi} will switch between
12002 @code{source-line} and @code{source-and-location} depending on the program
12003 counter.
12004 The default value is @code{auto}.
12005 @end table
12006
12007 @anchor{set print repeats}
12008 @item set print repeats @var{number-of-repeats}
12009 @itemx set print repeats unlimited
12010 @cindex repeated array elements
12011 Set the threshold for suppressing display of repeated array
12012 elements. When the number of consecutive identical elements of an
12013 array exceeds the threshold, @value{GDBN} prints the string
12014 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
12015 identical repetitions, instead of displaying the identical elements
12016 themselves. Setting the threshold to @code{unlimited} or zero will
12017 cause all elements to be individually printed. The default threshold
12018 is 10.
12019
12020 @item show print repeats
12021 Display the current threshold for printing repeated identical
12022 elements.
12023
12024 @anchor{set print max-depth}
12025 @item set print max-depth @var{depth}
12026 @item set print max-depth unlimited
12027 @cindex printing nested structures
12028 Set the threshold after which nested structures are replaced with
12029 ellipsis, this can make visualising deeply nested structures easier.
12030
12031 For example, given this C code
12032
12033 @smallexample
12034 typedef struct s1 @{ int a; @} s1;
12035 typedef struct s2 @{ s1 b; @} s2;
12036 typedef struct s3 @{ s2 c; @} s3;
12037 typedef struct s4 @{ s3 d; @} s4;
12038
12039 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
12040 @end smallexample
12041
12042 The following table shows how different values of @var{depth} will
12043 effect how @code{var} is printed by @value{GDBN}:
12044
12045 @multitable @columnfractions .3 .7
12046 @headitem @var{depth} setting @tab Result of @samp{p var}
12047 @item unlimited
12048 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
12049 @item @code{0}
12050 @tab @code{$1 = @{...@}}
12051 @item @code{1}
12052 @tab @code{$1 = @{d = @{...@}@}}
12053 @item @code{2}
12054 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
12055 @item @code{3}
12056 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
12057 @item @code{4}
12058 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
12059 @end multitable
12060
12061 To see the contents of structures that have been hidden the user can
12062 either increase the print max-depth, or they can print the elements of
12063 the structure that are visible, for example
12064
12065 @smallexample
12066 (@value{GDBP}) set print max-depth 2
12067 (@value{GDBP}) p var
12068 $1 = @{d = @{c = @{...@}@}@}
12069 (@value{GDBP}) p var.d
12070 $2 = @{c = @{b = @{...@}@}@}
12071 (@value{GDBP}) p var.d.c
12072 $3 = @{b = @{a = 3@}@}
12073 @end smallexample
12074
12075 The pattern used to replace nested structures varies based on
12076 language, for most languages @code{@{...@}} is used, but Fortran uses
12077 @code{(...)}.
12078
12079 @item show print max-depth
12080 Display the current threshold after which nested structures are
12081 replaces with ellipsis.
12082
12083 @anchor{set print memory-tag-violations}
12084 @cindex printing memory tag violation information
12085 @item set print memory-tag-violations
12086 @itemx set print memory-tag-violations on
12087 Cause @value{GDBN} to display additional information about memory tag violations
12088 when printing pointers and addresses.
12089
12090 @item set print memory-tag-violations off
12091 Stop printing memory tag violation information.
12092
12093 @item show print memory-tag-violations
12094 Show whether memory tag violation information is displayed when printing
12095 pointers and addresses.
12096
12097 @anchor{set print null-stop}
12098 @item set print null-stop
12099 @cindex @sc{null} elements in arrays
12100 Cause @value{GDBN} to stop printing the characters of an array when the first
12101 @sc{null} is encountered. This is useful when large arrays actually
12102 contain only short strings.
12103 The default is off.
12104
12105 @item show print null-stop
12106 Show whether @value{GDBN} stops printing an array on the first
12107 @sc{null} character.
12108
12109 @anchor{set print pretty}
12110 @item set print pretty on
12111 @cindex print structures in indented form
12112 @cindex indentation in structure display
12113 Cause @value{GDBN} to print structures in an indented format with one member
12114 per line, like this:
12115
12116 @smallexample
12117 @group
12118 $1 = @{
12119 next = 0x0,
12120 flags = @{
12121 sweet = 1,
12122 sour = 1
12123 @},
12124 meat = 0x54 "Pork"
12125 @}
12126 @end group
12127 @end smallexample
12128
12129 @item set print pretty off
12130 Cause @value{GDBN} to print structures in a compact format, like this:
12131
12132 @smallexample
12133 @group
12134 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
12135 meat = 0x54 "Pork"@}
12136 @end group
12137 @end smallexample
12138
12139 @noindent
12140 This is the default format.
12141
12142 @item show print pretty
12143 Show which format @value{GDBN} is using to print structures.
12144
12145 @anchor{set print raw-values}
12146 @item set print raw-values on
12147 Print values in raw form, without applying the pretty
12148 printers for the value.
12149
12150 @item set print raw-values off
12151 Print values in pretty-printed form, if there is a pretty-printer
12152 for the value (@pxref{Pretty Printing}),
12153 otherwise print the value in raw form.
12154
12155 The default setting is ``off''.
12156
12157 @item show print raw-values
12158 Show whether to print values in raw form.
12159
12160 @item set print sevenbit-strings on
12161 @cindex eight-bit characters in strings
12162 @cindex octal escapes in strings
12163 Print using only seven-bit characters; if this option is set,
12164 @value{GDBN} displays any eight-bit characters (in strings or
12165 character values) using the notation @code{\}@var{nnn}. This setting is
12166 best if you are working in English (@sc{ascii}) and you use the
12167 high-order bit of characters as a marker or ``meta'' bit.
12168
12169 @item set print sevenbit-strings off
12170 Print full eight-bit characters. This allows the use of more
12171 international character sets, and is the default.
12172
12173 @item show print sevenbit-strings
12174 Show whether or not @value{GDBN} is printing only seven-bit characters.
12175
12176 @anchor{set print union}
12177 @item set print union on
12178 @cindex unions in structures, printing
12179 Tell @value{GDBN} to print unions which are contained in structures
12180 and other unions. This is the default setting.
12181
12182 @item set print union off
12183 Tell @value{GDBN} not to print unions which are contained in
12184 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
12185 instead.
12186
12187 @item show print union
12188 Ask @value{GDBN} whether or not it will print unions which are contained in
12189 structures and other unions.
12190
12191 For example, given the declarations
12192
12193 @smallexample
12194 typedef enum @{Tree, Bug@} Species;
12195 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
12196 typedef enum @{Caterpillar, Cocoon, Butterfly@}
12197 Bug_forms;
12198
12199 struct thing @{
12200 Species it;
12201 union @{
12202 Tree_forms tree;
12203 Bug_forms bug;
12204 @} form;
12205 @};
12206
12207 struct thing foo = @{Tree, @{Acorn@}@};
12208 @end smallexample
12209
12210 @noindent
12211 with @code{set print union on} in effect @samp{p foo} would print
12212
12213 @smallexample
12214 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
12215 @end smallexample
12216
12217 @noindent
12218 and with @code{set print union off} in effect it would print
12219
12220 @smallexample
12221 $1 = @{it = Tree, form = @{...@}@}
12222 @end smallexample
12223
12224 @noindent
12225 @code{set print union} affects programs written in C-like languages
12226 and in Pascal.
12227 @end table
12228
12229 @need 1000
12230 @noindent
12231 These settings are of interest when debugging C@t{++} programs:
12232
12233 @table @code
12234 @cindex demangling C@t{++} names
12235 @item set print demangle
12236 @itemx set print demangle on
12237 Print C@t{++} names in their source form rather than in the encoded
12238 (``mangled'') form passed to the assembler and linker for type-safe
12239 linkage. The default is on.
12240
12241 @item show print demangle
12242 Show whether C@t{++} names are printed in mangled or demangled form.
12243
12244 @item set print asm-demangle
12245 @itemx set print asm-demangle on
12246 Print C@t{++} names in their source form rather than their mangled form, even
12247 in assembler code printouts such as instruction disassemblies.
12248 The default is off.
12249
12250 @item show print asm-demangle
12251 Show whether C@t{++} names in assembly listings are printed in mangled
12252 or demangled form.
12253
12254 @cindex C@t{++} symbol decoding style
12255 @cindex symbol decoding style, C@t{++}
12256 @kindex set demangle-style
12257 @item set demangle-style @var{style}
12258 Choose among several encoding schemes used by different compilers to represent
12259 C@t{++} names. If you omit @var{style}, you will see a list of possible
12260 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
12261 decoding style by inspecting your program.
12262
12263 @item show demangle-style
12264 Display the encoding style currently in use for decoding C@t{++} symbols.
12265
12266 @anchor{set print object}
12267 @item set print object
12268 @itemx set print object on
12269 @cindex derived type of an object, printing
12270 @cindex display derived types
12271 When displaying a pointer to an object, identify the @emph{actual}
12272 (derived) type of the object rather than the @emph{declared} type, using
12273 the virtual function table. Note that the virtual function table is
12274 required---this feature can only work for objects that have run-time
12275 type identification; a single virtual method in the object's declared
12276 type is sufficient. Note that this setting is also taken into account when
12277 working with variable objects via MI (@pxref{GDB/MI}).
12278
12279 @item set print object off
12280 Display only the declared type of objects, without reference to the
12281 virtual function table. This is the default setting.
12282
12283 @item show print object
12284 Show whether actual, or declared, object types are displayed.
12285
12286 @anchor{set print static-members}
12287 @item set print static-members
12288 @itemx set print static-members on
12289 @cindex static members of C@t{++} objects
12290 Print static members when displaying a C@t{++} object. The default is on.
12291
12292 @item set print static-members off
12293 Do not print static members when displaying a C@t{++} object.
12294
12295 @item show print static-members
12296 Show whether C@t{++} static members are printed or not.
12297
12298 @item set print pascal_static-members
12299 @itemx set print pascal_static-members on
12300 @cindex static members of Pascal objects
12301 @cindex Pascal objects, static members display
12302 Print static members when displaying a Pascal object. The default is on.
12303
12304 @item set print pascal_static-members off
12305 Do not print static members when displaying a Pascal object.
12306
12307 @item show print pascal_static-members
12308 Show whether Pascal static members are printed or not.
12309
12310 @c These don't work with HP ANSI C++ yet.
12311 @anchor{set print vtbl}
12312 @item set print vtbl
12313 @itemx set print vtbl on
12314 @cindex pretty print C@t{++} virtual function tables
12315 @cindex virtual functions (C@t{++}) display
12316 @cindex VTBL display
12317 Pretty print C@t{++} virtual function tables. The default is off.
12318 (The @code{vtbl} commands do not work on programs compiled with the HP
12319 ANSI C@t{++} compiler (@code{aCC}).)
12320
12321 @item set print vtbl off
12322 Do not pretty print C@t{++} virtual function tables.
12323
12324 @item show print vtbl
12325 Show whether C@t{++} virtual function tables are pretty printed, or not.
12326 @end table
12327
12328 @node Pretty Printing
12329 @section Pretty Printing
12330
12331 @value{GDBN} provides a mechanism to allow pretty-printing of values using
12332 Python code. It greatly simplifies the display of complex objects. This
12333 mechanism works for both MI and the CLI.
12334
12335 @menu
12336 * Pretty-Printer Introduction:: Introduction to pretty-printers
12337 * Pretty-Printer Example:: An example pretty-printer
12338 * Pretty-Printer Commands:: Pretty-printer commands
12339 @end menu
12340
12341 @node Pretty-Printer Introduction
12342 @subsection Pretty-Printer Introduction
12343
12344 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
12345 registered for the value. If there is then @value{GDBN} invokes the
12346 pretty-printer to print the value. Otherwise the value is printed normally.
12347
12348 Pretty-printers are normally named. This makes them easy to manage.
12349 The @samp{info pretty-printer} command will list all the installed
12350 pretty-printers with their names.
12351 If a pretty-printer can handle multiple data types, then its
12352 @dfn{subprinters} are the printers for the individual data types.
12353 Each such subprinter has its own name.
12354 The format of the name is @var{printer-name};@var{subprinter-name}.
12355
12356 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
12357 Typically they are automatically loaded and registered when the corresponding
12358 debug information is loaded, thus making them available without having to
12359 do anything special.
12360
12361 There are three places where a pretty-printer can be registered.
12362
12363 @itemize @bullet
12364 @item
12365 Pretty-printers registered globally are available when debugging
12366 all inferiors.
12367
12368 @item
12369 Pretty-printers registered with a program space are available only
12370 when debugging that program.
12371 @xref{Progspaces In Python}, for more details on program spaces in Python.
12372
12373 @item
12374 Pretty-printers registered with an objfile are loaded and unloaded
12375 with the corresponding objfile (e.g., shared library).
12376 @xref{Objfiles In Python}, for more details on objfiles in Python.
12377 @end itemize
12378
12379 @xref{Selecting Pretty-Printers}, for further information on how
12380 pretty-printers are selected,
12381
12382 @xref{Writing a Pretty-Printer}, for implementing pretty printers
12383 for new types.
12384
12385 @node Pretty-Printer Example
12386 @subsection Pretty-Printer Example
12387
12388 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
12389
12390 @smallexample
12391 (@value{GDBP}) print s
12392 $1 = @{
12393 static npos = 4294967295,
12394 _M_dataplus = @{
12395 <std::allocator<char>> = @{
12396 <__gnu_cxx::new_allocator<char>> = @{
12397 <No data fields>@}, <No data fields>
12398 @},
12399 members of std::basic_string<char, std::char_traits<char>,
12400 std::allocator<char> >::_Alloc_hider:
12401 _M_p = 0x804a014 "abcd"
12402 @}
12403 @}
12404 @end smallexample
12405
12406 With a pretty-printer for @code{std::string} only the contents are printed:
12407
12408 @smallexample
12409 (@value{GDBP}) print s
12410 $2 = "abcd"
12411 @end smallexample
12412
12413 @node Pretty-Printer Commands
12414 @subsection Pretty-Printer Commands
12415 @cindex pretty-printer commands
12416
12417 @table @code
12418 @kindex info pretty-printer
12419 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12420 Print the list of installed pretty-printers.
12421 This includes disabled pretty-printers, which are marked as such.
12422
12423 @var{object-regexp} is a regular expression matching the objects
12424 whose pretty-printers to list.
12425 Objects can be @code{global}, the program space's file
12426 (@pxref{Progspaces In Python}),
12427 and the object files within that program space (@pxref{Objfiles In Python}).
12428 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
12429 looks up a printer from these three objects.
12430
12431 @var{name-regexp} is a regular expression matching the name of the printers
12432 to list.
12433
12434 @kindex disable pretty-printer
12435 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12436 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12437 A disabled pretty-printer is not forgotten, it may be enabled again later.
12438
12439 @kindex enable pretty-printer
12440 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12441 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12442 @end table
12443
12444 Example:
12445
12446 Suppose we have three pretty-printers installed: one from library1.so
12447 named @code{foo} that prints objects of type @code{foo}, and
12448 another from library2.so named @code{bar} that prints two types of objects,
12449 @code{bar1} and @code{bar2}.
12450
12451 @smallexample
12452 @group
12453 (@value{GDBP}) info pretty-printer
12454 library1.so:
12455 foo
12456 library2.so:
12457 bar
12458 bar1
12459 bar2
12460 @end group
12461 @group
12462 (@value{GDBP}) info pretty-printer library2
12463 library2.so:
12464 bar
12465 bar1
12466 bar2
12467 @end group
12468 @group
12469 (@value{GDBP}) disable pretty-printer library1
12470 1 printer disabled
12471 2 of 3 printers enabled
12472 (@value{GDBP}) info pretty-printer
12473 library1.so:
12474 foo [disabled]
12475 library2.so:
12476 bar
12477 bar1
12478 bar2
12479 @end group
12480 @group
12481 (@value{GDBP}) disable pretty-printer library2 bar;bar1
12482 1 printer disabled
12483 1 of 3 printers enabled
12484 (@value{GDBP}) info pretty-printer library2
12485 library2.so:
12486 bar
12487 bar1 [disabled]
12488 bar2
12489 @end group
12490 @group
12491 (@value{GDBP}) disable pretty-printer library2 bar
12492 1 printer disabled
12493 0 of 3 printers enabled
12494 (@value{GDBP}) info pretty-printer
12495 library1.so:
12496 foo [disabled]
12497 library2.so:
12498 bar [disabled]
12499 bar1 [disabled]
12500 bar2
12501 @end group
12502 @end smallexample
12503
12504 Note that for @code{bar} the entire printer can be disabled,
12505 as can each individual subprinter.
12506
12507 Printing values and frame arguments is done by default using
12508 the enabled pretty printers.
12509
12510 The print option @code{-raw-values} and @value{GDBN} setting
12511 @code{set print raw-values} (@pxref{set print raw-values}) can be
12512 used to print values without applying the enabled pretty printers.
12513
12514 Similarly, the backtrace option @code{-raw-frame-arguments} and
12515 @value{GDBN} setting @code{set print raw-frame-arguments}
12516 (@pxref{set print raw-frame-arguments}) can be used to ignore the
12517 enabled pretty printers when printing frame argument values.
12518
12519 @node Value History
12520 @section Value History
12521
12522 @cindex value history
12523 @cindex history of values printed by @value{GDBN}
12524 Values printed by the @code{print} command are saved in the @value{GDBN}
12525 @dfn{value history}. This allows you to refer to them in other expressions.
12526 Values are kept until the symbol table is re-read or discarded
12527 (for example with the @code{file} or @code{symbol-file} commands).
12528 When the symbol table changes, the value history is discarded,
12529 since the values may contain pointers back to the types defined in the
12530 symbol table.
12531
12532 @cindex @code{$}
12533 @cindex @code{$$}
12534 @cindex history number
12535 The values printed are given @dfn{history numbers} by which you can
12536 refer to them. These are successive integers starting with one.
12537 @code{print} shows you the history number assigned to a value by
12538 printing @samp{$@var{num} = } before the value; here @var{num} is the
12539 history number.
12540
12541 To refer to any previous value, use @samp{$} followed by the value's
12542 history number. The way @code{print} labels its output is designed to
12543 remind you of this. Just @code{$} refers to the most recent value in
12544 the history, and @code{$$} refers to the value before that.
12545 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
12546 is the value just prior to @code{$$}, @code{$$1} is equivalent to
12547 @code{$$}, and @code{$$0} is equivalent to @code{$}.
12548
12549 For example, suppose you have just printed a pointer to a structure and
12550 want to see the contents of the structure. It suffices to type
12551
12552 @smallexample
12553 p *$
12554 @end smallexample
12555
12556 If you have a chain of structures where the component @code{next} points
12557 to the next one, you can print the contents of the next one with this:
12558
12559 @smallexample
12560 p *$.next
12561 @end smallexample
12562
12563 @noindent
12564 You can print successive links in the chain by repeating this
12565 command---which you can do by just typing @key{RET}.
12566
12567 Note that the history records values, not expressions. If the value of
12568 @code{x} is 4 and you type these commands:
12569
12570 @smallexample
12571 print x
12572 set x=5
12573 @end smallexample
12574
12575 @noindent
12576 then the value recorded in the value history by the @code{print} command
12577 remains 4 even though the value of @code{x} has changed.
12578
12579 @table @code
12580 @kindex show values
12581 @item show values
12582 Print the last ten values in the value history, with their item numbers.
12583 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12584 values} does not change the history.
12585
12586 @item show values @var{n}
12587 Print ten history values centered on history item number @var{n}.
12588
12589 @item show values +
12590 Print ten history values just after the values last printed. If no more
12591 values are available, @code{show values +} produces no display.
12592 @end table
12593
12594 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12595 same effect as @samp{show values +}.
12596
12597 @node Convenience Vars
12598 @section Convenience Variables
12599
12600 @cindex convenience variables
12601 @cindex user-defined variables
12602 @value{GDBN} provides @dfn{convenience variables} that you can use within
12603 @value{GDBN} to hold on to a value and refer to it later. These variables
12604 exist entirely within @value{GDBN}; they are not part of your program, and
12605 setting a convenience variable has no direct effect on further execution
12606 of your program. That is why you can use them freely.
12607
12608 Convenience variables are prefixed with @samp{$}. Any name preceded by
12609 @samp{$} can be used for a convenience variable, unless it is one of
12610 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12611 (Value history references, in contrast, are @emph{numbers} preceded
12612 by @samp{$}. @xref{Value History, ,Value History}.)
12613
12614 You can save a value in a convenience variable with an assignment
12615 expression, just as you would set a variable in your program.
12616 For example:
12617
12618 @smallexample
12619 set $foo = *object_ptr
12620 @end smallexample
12621
12622 @noindent
12623 would save in @code{$foo} the value contained in the object pointed to by
12624 @code{object_ptr}.
12625
12626 Using a convenience variable for the first time creates it, but its
12627 value is @code{void} until you assign a new value. You can alter the
12628 value with another assignment at any time.
12629
12630 Convenience variables have no fixed types. You can assign a convenience
12631 variable any type of value, including structures and arrays, even if
12632 that variable already has a value of a different type. The convenience
12633 variable, when used as an expression, has the type of its current value.
12634
12635 @table @code
12636 @kindex show convenience
12637 @cindex show all user variables and functions
12638 @item show convenience
12639 Print a list of convenience variables used so far, and their values,
12640 as well as a list of the convenience functions.
12641 Abbreviated @code{show conv}.
12642
12643 @kindex init-if-undefined
12644 @cindex convenience variables, initializing
12645 @item init-if-undefined $@var{variable} = @var{expression}
12646 Set a convenience variable if it has not already been set. This is useful
12647 for user-defined commands that keep some state. It is similar, in concept,
12648 to using local static variables with initializers in C (except that
12649 convenience variables are global). It can also be used to allow users to
12650 override default values used in a command script.
12651
12652 If the variable is already defined then the expression is not evaluated so
12653 any side-effects do not occur.
12654 @end table
12655
12656 One of the ways to use a convenience variable is as a counter to be
12657 incremented or a pointer to be advanced. For example, to print
12658 a field from successive elements of an array of structures:
12659
12660 @smallexample
12661 set $i = 0
12662 print bar[$i++]->contents
12663 @end smallexample
12664
12665 @noindent
12666 Repeat that command by typing @key{RET}.
12667
12668 Some convenience variables are created automatically by @value{GDBN} and given
12669 values likely to be useful.
12670
12671 @table @code
12672 @vindex $_@r{, convenience variable}
12673 @item $_
12674 The variable @code{$_} is automatically set by the @code{x} command to
12675 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12676 commands which provide a default address for @code{x} to examine also
12677 set @code{$_} to that address; these commands include @code{info line}
12678 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12679 except when set by the @code{x} command, in which case it is a pointer
12680 to the type of @code{$__}.
12681
12682 @vindex $__@r{, convenience variable}
12683 @item $__
12684 The variable @code{$__} is automatically set by the @code{x} command
12685 to the value found in the last address examined. Its type is chosen
12686 to match the format in which the data was printed.
12687
12688 @item $_exitcode
12689 @vindex $_exitcode@r{, convenience variable}
12690 When the program being debugged terminates normally, @value{GDBN}
12691 automatically sets this variable to the exit code of the program, and
12692 resets @code{$_exitsignal} to @code{void}.
12693
12694 @item $_exitsignal
12695 @vindex $_exitsignal@r{, convenience variable}
12696 When the program being debugged dies due to an uncaught signal,
12697 @value{GDBN} automatically sets this variable to that signal's number,
12698 and resets @code{$_exitcode} to @code{void}.
12699
12700 To distinguish between whether the program being debugged has exited
12701 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12702 @code{$_exitsignal} is not @code{void}), the convenience function
12703 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12704 Functions}). For example, considering the following source code:
12705
12706 @smallexample
12707 #include <signal.h>
12708
12709 int
12710 main (int argc, char *argv[])
12711 @{
12712 raise (SIGALRM);
12713 return 0;
12714 @}
12715 @end smallexample
12716
12717 A valid way of telling whether the program being debugged has exited
12718 or signalled would be:
12719
12720 @smallexample
12721 (@value{GDBP}) define has_exited_or_signalled
12722 Type commands for definition of ``has_exited_or_signalled''.
12723 End with a line saying just ``end''.
12724 >if $_isvoid ($_exitsignal)
12725 >echo The program has exited\n
12726 >else
12727 >echo The program has signalled\n
12728 >end
12729 >end
12730 (@value{GDBP}) run
12731 Starting program:
12732
12733 Program terminated with signal SIGALRM, Alarm clock.
12734 The program no longer exists.
12735 (@value{GDBP}) has_exited_or_signalled
12736 The program has signalled
12737 @end smallexample
12738
12739 As can be seen, @value{GDBN} correctly informs that the program being
12740 debugged has signalled, since it calls @code{raise} and raises a
12741 @code{SIGALRM} signal. If the program being debugged had not called
12742 @code{raise}, then @value{GDBN} would report a normal exit:
12743
12744 @smallexample
12745 (@value{GDBP}) has_exited_or_signalled
12746 The program has exited
12747 @end smallexample
12748
12749 @item $_exception
12750 The variable @code{$_exception} is set to the exception object being
12751 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12752
12753 @item $_ada_exception
12754 The variable @code{$_ada_exception} is set to the address of the
12755 exception being caught or thrown at an Ada exception-related
12756 catchpoint. @xref{Set Catchpoints}.
12757
12758 @item $_probe_argc
12759 @itemx $_probe_arg0@dots{}$_probe_arg11
12760 Arguments to a static probe. @xref{Static Probe Points}.
12761
12762 @item $_sdata
12763 @vindex $_sdata@r{, inspect, convenience variable}
12764 The variable @code{$_sdata} contains extra collected static tracepoint
12765 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12766 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12767 if extra static tracepoint data has not been collected.
12768
12769 @item $_siginfo
12770 @vindex $_siginfo@r{, convenience variable}
12771 The variable @code{$_siginfo} contains extra signal information
12772 (@pxref{extra signal information}). Note that @code{$_siginfo}
12773 could be empty, if the application has not yet received any signals.
12774 For example, it will be empty before you execute the @code{run} command.
12775
12776 @item $_tlb
12777 @vindex $_tlb@r{, convenience variable}
12778 The variable @code{$_tlb} is automatically set when debugging
12779 applications running on MS-Windows in native mode or connected to
12780 gdbserver that supports the @code{qGetTIBAddr} request.
12781 @xref{General Query Packets}.
12782 This variable contains the address of the thread information block.
12783
12784 @item $_inferior
12785 The number of the current inferior. @xref{Inferiors Connections and
12786 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12787
12788 @item $_thread
12789 The thread number of the current thread. @xref{thread numbers}.
12790
12791 @item $_gthread
12792 The global number of the current thread. @xref{global thread numbers}.
12793
12794 @item $_inferior_thread_count
12795 The number of live threads in the current inferior. @xref{Threads}.
12796
12797 @item $_gdb_major
12798 @itemx $_gdb_minor
12799 @vindex $_gdb_major@r{, convenience variable}
12800 @vindex $_gdb_minor@r{, convenience variable}
12801 The major and minor version numbers of the running @value{GDBN}.
12802 Development snapshots and pretest versions have their minor version
12803 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12804 the value 12 for @code{$_gdb_minor}. These variables allow you to
12805 write scripts that work with different versions of @value{GDBN}
12806 without errors caused by features unavailable in some of those
12807 versions.
12808
12809 @item $_shell_exitcode
12810 @itemx $_shell_exitsignal
12811 @vindex $_shell_exitcode@r{, convenience variable}
12812 @vindex $_shell_exitsignal@r{, convenience variable}
12813 @cindex shell command, exit code
12814 @cindex shell command, exit signal
12815 @cindex exit status of shell commands
12816 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12817 shell commands. When a launched command terminates, @value{GDBN}
12818 automatically maintains the variables @code{$_shell_exitcode}
12819 and @code{$_shell_exitsignal} according to the exit status of the last
12820 launched command. These variables are set and used similarly to
12821 the variables @code{$_exitcode} and @code{$_exitsignal}.
12822
12823 @end table
12824
12825 @node Convenience Funs
12826 @section Convenience Functions
12827
12828 @cindex convenience functions
12829 @value{GDBN} also supplies some @dfn{convenience functions}. These
12830 have a syntax similar to convenience variables. A convenience
12831 function can be used in an expression just like an ordinary function;
12832 however, a convenience function is implemented internally to
12833 @value{GDBN}.
12834
12835 These functions do not require @value{GDBN} to be configured with
12836 @code{Python} support, which means that they are always available.
12837
12838 @table @code
12839
12840 @findex $_isvoid@r{, convenience function}
12841 @item $_isvoid (@var{expr})
12842 Return one if the expression @var{expr} is @code{void}. Otherwise it
12843 returns zero.
12844
12845 A @code{void} expression is an expression where the type of the result
12846 is @code{void}. For example, you can examine a convenience variable
12847 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12848 it is @code{void}:
12849
12850 @smallexample
12851 (@value{GDBP}) print $_exitcode
12852 $1 = void
12853 (@value{GDBP}) print $_isvoid ($_exitcode)
12854 $2 = 1
12855 (@value{GDBP}) run
12856 Starting program: ./a.out
12857 [Inferior 1 (process 29572) exited normally]
12858 (@value{GDBP}) print $_exitcode
12859 $3 = 0
12860 (@value{GDBP}) print $_isvoid ($_exitcode)
12861 $4 = 0
12862 @end smallexample
12863
12864 In the example above, we used @code{$_isvoid} to check whether
12865 @code{$_exitcode} is @code{void} before and after the execution of the
12866 program being debugged. Before the execution there is no exit code to
12867 be examined, therefore @code{$_exitcode} is @code{void}. After the
12868 execution the program being debugged returned zero, therefore
12869 @code{$_exitcode} is zero, which means that it is not @code{void}
12870 anymore.
12871
12872 The @code{void} expression can also be a call of a function from the
12873 program being debugged. For example, given the following function:
12874
12875 @smallexample
12876 void
12877 foo (void)
12878 @{
12879 @}
12880 @end smallexample
12881
12882 The result of calling it inside @value{GDBN} is @code{void}:
12883
12884 @smallexample
12885 (@value{GDBP}) print foo ()
12886 $1 = void
12887 (@value{GDBP}) print $_isvoid (foo ())
12888 $2 = 1
12889 (@value{GDBP}) set $v = foo ()
12890 (@value{GDBP}) print $v
12891 $3 = void
12892 (@value{GDBP}) print $_isvoid ($v)
12893 $4 = 1
12894 @end smallexample
12895
12896 @findex $_gdb_setting_str@r{, convenience function}
12897 @item $_gdb_setting_str (@var{setting})
12898 Return the value of the @value{GDBN} @var{setting} as a string.
12899 @var{setting} is any setting that can be used in a @code{set} or
12900 @code{show} command (@pxref{Controlling GDB}).
12901
12902 @smallexample
12903 (@value{GDBP}) show print frame-arguments
12904 Printing of non-scalar frame arguments is "scalars".
12905 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12906 $1 = "scalars"
12907 (@value{GDBP}) p $_gdb_setting_str("height")
12908 $2 = "30"
12909 (@value{GDBP})
12910 @end smallexample
12911
12912 @findex $_gdb_setting@r{, convenience function}
12913 @item $_gdb_setting (@var{setting})
12914 Return the value of the @value{GDBN} @var{setting}.
12915 The type of the returned value depends on the setting.
12916
12917 The value type for boolean and auto boolean settings is @code{int}.
12918 The boolean values @code{off} and @code{on} are converted to
12919 the integer values @code{0} and @code{1}. The value @code{auto} is
12920 converted to the value @code{-1}.
12921
12922 The value type for integer settings is either @code{unsigned int}
12923 or @code{int}, depending on the setting.
12924
12925 Some integer settings accept an @code{unlimited} value.
12926 Depending on the setting, the @code{set} command also accepts
12927 the value @code{0} or the value @code{@minus{}1} as a synonym for
12928 @code{unlimited}.
12929 For example, @code{set height unlimited} is equivalent to
12930 @code{set height 0}.
12931
12932 Some other settings that accept the @code{unlimited} value
12933 use the value @code{0} to literally mean zero.
12934 For example, @code{set history size 0} indicates to not
12935 record any @value{GDBN} commands in the command history.
12936 For such settings, @code{@minus{}1} is the synonym
12937 for @code{unlimited}.
12938
12939 See the documentation of the corresponding @code{set} command for
12940 the numerical value equivalent to @code{unlimited}.
12941
12942 The @code{$_gdb_setting} function converts the unlimited value
12943 to a @code{0} or a @code{@minus{}1} value according to what the
12944 @code{set} command uses.
12945
12946 @smallexample
12947 @group
12948 (@value{GDBP}) p $_gdb_setting_str("height")
12949 $1 = "30"
12950 (@value{GDBP}) p $_gdb_setting("height")
12951 $2 = 30
12952 (@value{GDBP}) set height unlimited
12953 (@value{GDBP}) p $_gdb_setting_str("height")
12954 $3 = "unlimited"
12955 (@value{GDBP}) p $_gdb_setting("height")
12956 $4 = 0
12957 @end group
12958 @group
12959 (@value{GDBP}) p $_gdb_setting_str("history size")
12960 $5 = "unlimited"
12961 (@value{GDBP}) p $_gdb_setting("history size")
12962 $6 = -1
12963 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12964 $7 = "auto"
12965 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12966 $8 = -1
12967 (@value{GDBP})
12968 @end group
12969 @end smallexample
12970
12971 Other setting types (enum, filename, optional filename, string, string noescape)
12972 are returned as string values.
12973
12974
12975 @findex $_gdb_maint_setting_str@r{, convenience function}
12976 @item $_gdb_maint_setting_str (@var{setting})
12977 Like the @code{$_gdb_setting_str} function, but works with
12978 @code{maintenance set} variables.
12979
12980 @findex $_gdb_maint_setting@r{, convenience function}
12981 @item $_gdb_maint_setting (@var{setting})
12982 Like the @code{$_gdb_setting} function, but works with
12983 @code{maintenance set} variables.
12984
12985 @anchor{$_shell convenience function}
12986 @findex $_shell@r{, convenience function}
12987 @item $_shell (@var{command-string})
12988
12989 Invoke a shell to execute @var{command-string}. @var{command-string}
12990 must be a string. The shell runs on the host machine, the machine
12991 @value{GDBN} is running on. Returns the command's exit status. On
12992 Unix systems, a command which exits with a zero exit status has
12993 succeeded, and non-zero exit status indicates failure. When a command
12994 terminates on a fatal signal whose number is @var{N}, @value{GDBN}
12995 uses the value 128+@var{N} as the exit status, as is standard in Unix
12996 shells. Note that @var{N} is a host signal number, not a target
12997 signal number. If you're native debugging, they will be the same, but
12998 if cross debugging, the host vs target signal numbers may be
12999 completely unrelated. Please consult your host operating system's
13000 documentation for the mapping between host signal numbers and signal
13001 names. The shell to run is determined in the same way as for the
13002 @code{shell} command. @xref{Shell Commands, ,Shell Commands}.
13003
13004 @smallexample
13005 (@value{GDBP}) print $_shell("true")
13006 $1 = 0
13007 (@value{GDBP}) print $_shell("false")
13008 $2 = 1
13009 (@value{GDBP}) p $_shell("echo hello")
13010 hello
13011 $3 = 0
13012 (@value{GDBP}) p $_shell("foobar")
13013 bash: line 1: foobar: command not found
13014 $4 = 127
13015 @end smallexample
13016
13017 This may also be useful in breakpoint conditions. For example:
13018
13019 @smallexample
13020 (@value{GDBP}) break function if $_shell("some command") == 0
13021 @end smallexample
13022
13023 In this scenario, you'll want to make sure that the shell command you
13024 run in the breakpoint condition takes the least amount of time
13025 possible. For example, avoid running a command that may block
13026 indefinitely, or that sleeps for a while before exiting. Prefer a
13027 command or script which analyzes some state and exits immediately.
13028 This is important because the debugged program stops for the
13029 breakpoint every time, and then @value{GDBN} evaluates the breakpoint
13030 condition. If the condition is false, the program is re-resumed
13031 transparently, without informing you of the stop. A quick shell
13032 command thus avoids significantly slowing down the debugged program
13033 unnecessarily.
13034
13035 Note: unlike the @code{shell} command, the @code{$_shell} convenience
13036 function does not affect the @code{$_shell_exitcode} and
13037 @code{$_shell_exitsignal} convenience variables.
13038
13039 @end table
13040
13041 The following functions require @value{GDBN} to be configured with
13042 @code{Python} support.
13043
13044 @table @code
13045
13046 @findex $_memeq@r{, convenience function}
13047 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
13048 Returns one if the @var{length} bytes at the addresses given by
13049 @var{buf1} and @var{buf2} are equal.
13050 Otherwise it returns zero.
13051
13052 @findex $_regex@r{, convenience function}
13053 @item $_regex(@var{str}, @var{regex})
13054 Returns one if the string @var{str} matches the regular expression
13055 @var{regex}. Otherwise it returns zero.
13056 The syntax of the regular expression is that specified by @code{Python}'s
13057 regular expression support.
13058
13059 @findex $_streq@r{, convenience function}
13060 @item $_streq(@var{str1}, @var{str2})
13061 Returns one if the strings @var{str1} and @var{str2} are equal.
13062 Otherwise it returns zero.
13063
13064 @findex $_strlen@r{, convenience function}
13065 @item $_strlen(@var{str})
13066 Returns the length of string @var{str}.
13067
13068 @findex $_caller_is@r{, convenience function}
13069 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
13070 Returns one if the calling function's name is equal to @var{name}.
13071 Otherwise it returns zero.
13072
13073 If the optional argument @var{number_of_frames} is provided,
13074 it is the number of frames up in the stack to look.
13075 The default is 1.
13076
13077 Example:
13078
13079 @smallexample
13080 (@value{GDBP}) backtrace
13081 #0 bottom_func ()
13082 at testsuite/gdb.python/py-caller-is.c:21
13083 #1 0x00000000004005a0 in middle_func ()
13084 at testsuite/gdb.python/py-caller-is.c:27
13085 #2 0x00000000004005ab in top_func ()
13086 at testsuite/gdb.python/py-caller-is.c:33
13087 #3 0x00000000004005b6 in main ()
13088 at testsuite/gdb.python/py-caller-is.c:39
13089 (@value{GDBP}) print $_caller_is ("middle_func")
13090 $1 = 1
13091 (@value{GDBP}) print $_caller_is ("top_func", 2)
13092 $1 = 1
13093 @end smallexample
13094
13095 @findex $_caller_matches@r{, convenience function}
13096 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
13097 Returns one if the calling function's name matches the regular expression
13098 @var{regexp}. Otherwise it returns zero.
13099
13100 If the optional argument @var{number_of_frames} is provided,
13101 it is the number of frames up in the stack to look.
13102 The default is 1.
13103
13104 @findex $_any_caller_is@r{, convenience function}
13105 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
13106 Returns one if any calling function's name is equal to @var{name}.
13107 Otherwise it returns zero.
13108
13109 If the optional argument @var{number_of_frames} is provided,
13110 it is the number of frames up in the stack to look.
13111 The default is 1.
13112
13113 This function differs from @code{$_caller_is} in that this function
13114 checks all stack frames from the immediate caller to the frame specified
13115 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
13116 frame specified by @var{number_of_frames}.
13117
13118 @findex $_any_caller_matches@r{, convenience function}
13119 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
13120 Returns one if any calling function's name matches the regular expression
13121 @var{regexp}. Otherwise it returns zero.
13122
13123 If the optional argument @var{number_of_frames} is provided,
13124 it is the number of frames up in the stack to look.
13125 The default is 1.
13126
13127 This function differs from @code{$_caller_matches} in that this function
13128 checks all stack frames from the immediate caller to the frame specified
13129 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
13130 frame specified by @var{number_of_frames}.
13131
13132 @findex $_as_string@r{, convenience function}
13133 @item $_as_string(@var{value})
13134 Return the string representation of @var{value}.
13135
13136 This function is useful to obtain the textual label (enumerator) of an
13137 enumeration value. For example, assuming the variable @var{node} is of
13138 an enumerated type:
13139
13140 @smallexample
13141 (@value{GDBP}) printf "Visiting node of type %s\n", $_as_string(node)
13142 Visiting node of type NODE_INTEGER
13143 @end smallexample
13144
13145 @findex $_cimag@r{, convenience function}
13146 @findex $_creal@r{, convenience function}
13147 @item $_cimag(@var{value})
13148 @itemx $_creal(@var{value})
13149 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
13150 the complex number @var{value}.
13151
13152 The type of the imaginary or real part depends on the type of the
13153 complex number, e.g., using @code{$_cimag} on a @code{float complex}
13154 will return an imaginary part of type @code{float}.
13155
13156 @end table
13157
13158 @value{GDBN} provides the ability to list and get help on
13159 convenience functions.
13160
13161 @table @code
13162 @item help function
13163 @kindex help function
13164 @cindex show all convenience functions
13165 Print a list of all convenience functions.
13166 @end table
13167
13168 @node Registers
13169 @section Registers
13170
13171 @cindex registers
13172 You can refer to machine register contents, in expressions, as variables
13173 with names starting with @samp{$}. The names of registers are different
13174 for each machine; use @code{info registers} to see the names used on
13175 your machine.
13176
13177 @table @code
13178 @kindex info registers
13179 @item info registers
13180 Print the names and values of all registers except floating-point
13181 and vector registers (in the selected stack frame).
13182
13183 @kindex info all-registers
13184 @cindex floating point registers
13185 @item info all-registers
13186 Print the names and values of all registers, including floating-point
13187 and vector registers (in the selected stack frame).
13188
13189 @anchor{info_registers_reggroup}
13190 @item info registers @var{reggroup} @dots{}
13191 Print the name and value of the registers in each of the specified
13192 @var{reggroup}s. The @var{reggroup} can be any of those returned by
13193 @code{maint print reggroups} (@pxref{Maintenance Commands}).
13194
13195 @item info registers @var{regname} @dots{}
13196 Print the @dfn{relativized} value of each specified register @var{regname}.
13197 As discussed in detail below, register values are normally relative to
13198 the selected stack frame. The @var{regname} may be any register name valid on
13199 the machine you are using, with or without the initial @samp{$}.
13200 @end table
13201
13202 @anchor{standard registers}
13203 @cindex stack pointer register
13204 @cindex program counter register
13205 @cindex process status register
13206 @cindex frame pointer register
13207 @cindex standard registers
13208 @value{GDBN} has four ``standard'' register names that are available (in
13209 expressions) on most machines---whenever they do not conflict with an
13210 architecture's canonical mnemonics for registers. The register names
13211 @code{$pc} and @code{$sp} are used for the program counter register and
13212 the stack pointer. @code{$fp} is used for a register that contains a
13213 pointer to the current stack frame, and @code{$ps} is used for a
13214 register that contains the processor status. For example,
13215 you could print the program counter in hex with
13216
13217 @smallexample
13218 p/x $pc
13219 @end smallexample
13220
13221 @noindent
13222 or print the instruction to be executed next with
13223
13224 @smallexample
13225 x/i $pc
13226 @end smallexample
13227
13228 @noindent
13229 or add four to the stack pointer@footnote{This is a way of removing
13230 one word from the stack, on machines where stacks grow downward in
13231 memory (most machines, nowadays). This assumes that the innermost
13232 stack frame is selected; setting @code{$sp} is not allowed when other
13233 stack frames are selected. To pop entire frames off the stack,
13234 regardless of machine architecture, use @code{return};
13235 see @ref{Returning, ,Returning from a Function}.} with
13236
13237 @smallexample
13238 set $sp += 4
13239 @end smallexample
13240
13241 Whenever possible, these four standard register names are available on
13242 your machine even though the machine has different canonical mnemonics,
13243 so long as there is no conflict. The @code{info registers} command
13244 shows the canonical names. For example, on the SPARC, @code{info
13245 registers} displays the processor status register as @code{$psr} but you
13246 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
13247 is an alias for the @sc{eflags} register.
13248
13249 @value{GDBN} always considers the contents of an ordinary register as an
13250 integer when the register is examined in this way. Some machines have
13251 special registers which can hold nothing but floating point; these
13252 registers are considered to have floating point values. There is no way
13253 to refer to the contents of an ordinary register as floating point value
13254 (although you can @emph{print} it as a floating point value with
13255 @samp{print/f $@var{regname}}).
13256
13257 Some registers have distinct ``raw'' and ``virtual'' data formats. This
13258 means that the data format in which the register contents are saved by
13259 the operating system is not the same one that your program normally
13260 sees. For example, the registers of the 68881 floating point
13261 coprocessor are always saved in ``extended'' (raw) format, but all C
13262 programs expect to work with ``double'' (virtual) format. In such
13263 cases, @value{GDBN} normally works with the virtual format only (the format
13264 that makes sense for your program), but the @code{info registers} command
13265 prints the data in both formats.
13266
13267 @cindex SSE registers (x86)
13268 @cindex MMX registers (x86)
13269 Some machines have special registers whose contents can be interpreted
13270 in several different ways. For example, modern x86-based machines
13271 have SSE and MMX registers that can hold several values packed
13272 together in several different formats. @value{GDBN} refers to such
13273 registers in @code{struct} notation:
13274
13275 @smallexample
13276 (@value{GDBP}) print $xmm1
13277 $1 = @{
13278 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
13279 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
13280 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
13281 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
13282 v4_int32 = @{0, 20657912, 11, 13@},
13283 v2_int64 = @{88725056443645952, 55834574859@},
13284 uint128 = 0x0000000d0000000b013b36f800000000
13285 @}
13286 @end smallexample
13287
13288 @noindent
13289 To set values of such registers, you need to tell @value{GDBN} which
13290 view of the register you wish to change, as if you were assigning
13291 value to a @code{struct} member:
13292
13293 @smallexample
13294 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
13295 @end smallexample
13296
13297 Normally, register values are relative to the selected stack frame
13298 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
13299 value that the register would contain if all stack frames farther in
13300 were exited and their saved registers restored. In order to see the
13301 true contents of hardware registers, you must select the innermost
13302 frame (with @samp{frame 0}).
13303
13304 @cindex caller-saved registers
13305 @cindex call-clobbered registers
13306 @cindex volatile registers
13307 @cindex <not saved> values
13308 Usually ABIs reserve some registers as not needed to be saved by the
13309 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
13310 registers). It may therefore not be possible for @value{GDBN} to know
13311 the value a register had before the call (in other words, in the outer
13312 frame), if the register value has since been changed by the callee.
13313 @value{GDBN} tries to deduce where the inner frame saved
13314 (``callee-saved'') registers, from the debug info, unwind info, or the
13315 machine code generated by your compiler. If some register is not
13316 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
13317 its own knowledge of the ABI, or because the debug/unwind info
13318 explicitly says the register's value is undefined), @value{GDBN}
13319 displays @w{@samp{<not saved>}} as the register's value. With targets
13320 that @value{GDBN} has no knowledge of the register saving convention,
13321 if a register was not saved by the callee, then its value and location
13322 in the outer frame are assumed to be the same of the inner frame.
13323 This is usually harmless, because if the register is call-clobbered,
13324 the caller either does not care what is in the register after the
13325 call, or has code to restore the value that it does care about. Note,
13326 however, that if you change such a register in the outer frame, you
13327 may also be affecting the inner frame. Also, the more ``outer'' the
13328 frame is you're looking at, the more likely a call-clobbered
13329 register's value is to be wrong, in the sense that it doesn't actually
13330 represent the value the register had just before the call.
13331
13332 @node Floating Point Hardware
13333 @section Floating Point Hardware
13334 @cindex floating point
13335
13336 Depending on the configuration, @value{GDBN} may be able to give
13337 you more information about the status of the floating point hardware.
13338
13339 @table @code
13340 @kindex info float
13341 @item info float
13342 Display hardware-dependent information about the floating
13343 point unit. The exact contents and layout vary depending on the
13344 floating point chip. Currently, @samp{info float} is supported on
13345 the ARM and x86 machines.
13346 @end table
13347
13348 @node Vector Unit
13349 @section Vector Unit
13350 @cindex vector unit
13351
13352 Depending on the configuration, @value{GDBN} may be able to give you
13353 more information about the status of the vector unit.
13354
13355 @table @code
13356 @kindex info vector
13357 @item info vector
13358 Display information about the vector unit. The exact contents and
13359 layout vary depending on the hardware.
13360 @end table
13361
13362 @node OS Information
13363 @section Operating System Auxiliary Information
13364 @cindex OS information
13365
13366 @value{GDBN} provides interfaces to useful OS facilities that can help
13367 you debug your program.
13368
13369 @cindex auxiliary vector
13370 @cindex vector, auxiliary
13371 Some operating systems supply an @dfn{auxiliary vector} to programs at
13372 startup. This is akin to the arguments and environment that you
13373 specify for a program, but contains a system-dependent variety of
13374 binary values that tell system libraries important details about the
13375 hardware, operating system, and process. Each value's purpose is
13376 identified by an integer tag; the meanings are well-known but system-specific.
13377 Depending on the configuration and operating system facilities,
13378 @value{GDBN} may be able to show you this information. For remote
13379 targets, this functionality may further depend on the remote stub's
13380 support of the @samp{qXfer:auxv:read} packet, see
13381 @ref{qXfer auxiliary vector read}.
13382
13383 @table @code
13384 @kindex info auxv
13385 @item info auxv
13386 Display the auxiliary vector of the inferior, which can be either a
13387 live process or a core dump file. @value{GDBN} prints each tag value
13388 numerically, and also shows names and text descriptions for recognized
13389 tags. Some values in the vector are numbers, some bit masks, and some
13390 pointers to strings or other data. @value{GDBN} displays each value in the
13391 most appropriate form for a recognized tag, and in hexadecimal for
13392 an unrecognized tag.
13393 @end table
13394
13395 On some targets, @value{GDBN} can access operating system-specific
13396 information and show it to you. The types of information available
13397 will differ depending on the type of operating system running on the
13398 target. The mechanism used to fetch the data is described in
13399 @ref{Operating System Information}. For remote targets, this
13400 functionality depends on the remote stub's support of the
13401 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
13402
13403 @table @code
13404 @kindex info os
13405 @item info os @var{infotype}
13406
13407 Display OS information of the requested type.
13408
13409 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
13410
13411 @anchor{linux info os infotypes}
13412 @table @code
13413 @kindex info os cpus
13414 @item cpus
13415 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
13416 the available fields from /proc/cpuinfo. For each supported architecture
13417 different fields are available. Two common entries are processor which gives
13418 CPU number and bogomips; a system constant that is calculated during
13419 kernel initialization.
13420
13421 @kindex info os files
13422 @item files
13423 Display the list of open file descriptors on the target. For each
13424 file descriptor, @value{GDBN} prints the identifier of the process
13425 owning the descriptor, the command of the owning process, the value
13426 of the descriptor, and the target of the descriptor.
13427
13428 @kindex info os modules
13429 @item modules
13430 Display the list of all loaded kernel modules on the target. For each
13431 module, @value{GDBN} prints the module name, the size of the module in
13432 bytes, the number of times the module is used, the dependencies of the
13433 module, the status of the module, and the address of the loaded module
13434 in memory.
13435
13436 @kindex info os msg
13437 @item msg
13438 Display the list of all System V message queues on the target. For each
13439 message queue, @value{GDBN} prints the message queue key, the message
13440 queue identifier, the access permissions, the current number of bytes
13441 on the queue, the current number of messages on the queue, the processes
13442 that last sent and received a message on the queue, the user and group
13443 of the owner and creator of the message queue, the times at which a
13444 message was last sent and received on the queue, and the time at which
13445 the message queue was last changed.
13446
13447 @kindex info os processes
13448 @item processes
13449 Display the list of processes on the target. For each process,
13450 @value{GDBN} prints the process identifier, the name of the user, the
13451 command corresponding to the process, and the list of processor cores
13452 that the process is currently running on. (To understand what these
13453 properties mean, for this and the following info types, please consult
13454 the general @sc{gnu}/Linux documentation.)
13455
13456 @kindex info os procgroups
13457 @item procgroups
13458 Display the list of process groups on the target. For each process,
13459 @value{GDBN} prints the identifier of the process group that it belongs
13460 to, the command corresponding to the process group leader, the process
13461 identifier, and the command line of the process. The list is sorted
13462 first by the process group identifier, then by the process identifier,
13463 so that processes belonging to the same process group are grouped together
13464 and the process group leader is listed first.
13465
13466 @kindex info os semaphores
13467 @item semaphores
13468 Display the list of all System V semaphore sets on the target. For each
13469 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
13470 set identifier, the access permissions, the number of semaphores in the
13471 set, the user and group of the owner and creator of the semaphore set,
13472 and the times at which the semaphore set was operated upon and changed.
13473
13474 @kindex info os shm
13475 @item shm
13476 Display the list of all System V shared-memory regions on the target.
13477 For each shared-memory region, @value{GDBN} prints the region key,
13478 the shared-memory identifier, the access permissions, the size of the
13479 region, the process that created the region, the process that last
13480 attached to or detached from the region, the current number of live
13481 attaches to the region, and the times at which the region was last
13482 attached to, detach from, and changed.
13483
13484 @kindex info os sockets
13485 @item sockets
13486 Display the list of Internet-domain sockets on the target. For each
13487 socket, @value{GDBN} prints the address and port of the local and
13488 remote endpoints, the current state of the connection, the creator of
13489 the socket, the IP address family of the socket, and the type of the
13490 connection.
13491
13492 @kindex info os threads
13493 @item threads
13494 Display the list of threads running on the target. For each thread,
13495 @value{GDBN} prints the identifier of the process that the thread
13496 belongs to, the command of the process, the thread identifier, and the
13497 processor core that it is currently running on. The main thread of a
13498 process is not listed.
13499 @end table
13500
13501 @item info os
13502 If @var{infotype} is omitted, then list the possible values for
13503 @var{infotype} and the kind of OS information available for each
13504 @var{infotype}. If the target does not return a list of possible
13505 types, this command will report an error.
13506 @end table
13507
13508 @node Memory Region Attributes
13509 @section Memory Region Attributes
13510 @cindex memory region attributes
13511
13512 @dfn{Memory region attributes} allow you to describe special handling
13513 required by regions of your target's memory. @value{GDBN} uses
13514 attributes to determine whether to allow certain types of memory
13515 accesses; whether to use specific width accesses; and whether to cache
13516 target memory. By default the description of memory regions is
13517 fetched from the target (if the current target supports this), but the
13518 user can override the fetched regions.
13519
13520 Defined memory regions can be individually enabled and disabled. When a
13521 memory region is disabled, @value{GDBN} uses the default attributes when
13522 accessing memory in that region. Similarly, if no memory regions have
13523 been defined, @value{GDBN} uses the default attributes when accessing
13524 all memory.
13525
13526 When a memory region is defined, it is given a number to identify it;
13527 to enable, disable, or remove a memory region, you specify that number.
13528
13529 @table @code
13530 @kindex mem
13531 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
13532 Define a memory region bounded by @var{lower} and @var{upper} with
13533 attributes @var{attributes}@dots{}, and add it to the list of regions
13534 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
13535 case: it is treated as the target's maximum memory address.
13536 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
13537
13538 @item mem auto
13539 Discard any user changes to the memory regions and use target-supplied
13540 regions, if available, or no regions if the target does not support.
13541
13542 @kindex delete mem
13543 @item delete mem @var{nums}@dots{}
13544 Remove memory regions @var{nums}@dots{} from the list of regions
13545 monitored by @value{GDBN}.
13546
13547 @kindex disable mem
13548 @item disable mem @var{nums}@dots{}
13549 Disable monitoring of memory regions @var{nums}@dots{}.
13550 A disabled memory region is not forgotten.
13551 It may be enabled again later.
13552
13553 @kindex enable mem
13554 @item enable mem @var{nums}@dots{}
13555 Enable monitoring of memory regions @var{nums}@dots{}.
13556
13557 @kindex info mem
13558 @item info mem
13559 Print a table of all defined memory regions, with the following columns
13560 for each region:
13561
13562 @table @emph
13563 @item Memory Region Number
13564 @item Enabled or Disabled.
13565 Enabled memory regions are marked with @samp{y}.
13566 Disabled memory regions are marked with @samp{n}.
13567
13568 @item Lo Address
13569 The address defining the inclusive lower bound of the memory region.
13570
13571 @item Hi Address
13572 The address defining the exclusive upper bound of the memory region.
13573
13574 @item Attributes
13575 The list of attributes set for this memory region.
13576 @end table
13577 @end table
13578
13579
13580 @subsection Attributes
13581
13582 @subsubsection Memory Access Mode
13583 The access mode attributes set whether @value{GDBN} may make read or
13584 write accesses to a memory region.
13585
13586 While these attributes prevent @value{GDBN} from performing invalid
13587 memory accesses, they do nothing to prevent the target system, I/O DMA,
13588 etc.@: from accessing memory.
13589
13590 @table @code
13591 @item ro
13592 Memory is read only.
13593 @item wo
13594 Memory is write only.
13595 @item rw
13596 Memory is read/write. This is the default.
13597 @end table
13598
13599 @subsubsection Memory Access Size
13600 The access size attribute tells @value{GDBN} to use specific sized
13601 accesses in the memory region. Often memory mapped device registers
13602 require specific sized accesses. If no access size attribute is
13603 specified, @value{GDBN} may use accesses of any size.
13604
13605 @table @code
13606 @item 8
13607 Use 8 bit memory accesses.
13608 @item 16
13609 Use 16 bit memory accesses.
13610 @item 32
13611 Use 32 bit memory accesses.
13612 @item 64
13613 Use 64 bit memory accesses.
13614 @end table
13615
13616 @c @subsubsection Hardware/Software Breakpoints
13617 @c The hardware/software breakpoint attributes set whether @value{GDBN}
13618 @c will use hardware or software breakpoints for the internal breakpoints
13619 @c used by the step, next, finish, until, etc. commands.
13620 @c
13621 @c @table @code
13622 @c @item hwbreak
13623 @c Always use hardware breakpoints
13624 @c @item swbreak (default)
13625 @c @end table
13626
13627 @subsubsection Data Cache
13628 The data cache attributes set whether @value{GDBN} will cache target
13629 memory. While this generally improves performance by reducing debug
13630 protocol overhead, it can lead to incorrect results because @value{GDBN}
13631 does not know about volatile variables or memory mapped device
13632 registers.
13633
13634 @table @code
13635 @item cache
13636 Enable @value{GDBN} to cache target memory.
13637 @item nocache
13638 Disable @value{GDBN} from caching target memory. This is the default.
13639 @end table
13640
13641 @subsection Memory Access Checking
13642 @value{GDBN} can be instructed to refuse accesses to memory that is
13643 not explicitly described. This can be useful if accessing such
13644 regions has undesired effects for a specific target, or to provide
13645 better error checking. The following commands control this behaviour.
13646
13647 @table @code
13648 @kindex set mem inaccessible-by-default
13649 @item set mem inaccessible-by-default [on|off]
13650 If @code{on} is specified, make @value{GDBN} treat memory not
13651 explicitly described by the memory ranges as non-existent and refuse accesses
13652 to such memory. The checks are only performed if there's at least one
13653 memory range defined. If @code{off} is specified, make @value{GDBN}
13654 treat the memory not explicitly described by the memory ranges as RAM.
13655 The default value is @code{on}.
13656 @kindex show mem inaccessible-by-default
13657 @item show mem inaccessible-by-default
13658 Show the current handling of accesses to unknown memory.
13659 @end table
13660
13661
13662 @c @subsubsection Memory Write Verification
13663 @c The memory write verification attributes set whether @value{GDBN}
13664 @c will re-reads data after each write to verify the write was successful.
13665 @c
13666 @c @table @code
13667 @c @item verify
13668 @c @item noverify (default)
13669 @c @end table
13670
13671 @node Dump/Restore Files
13672 @section Copy Between Memory and a File
13673 @cindex dump/restore files
13674 @cindex append data to a file
13675 @cindex dump data to a file
13676 @cindex restore data from a file
13677
13678 You can use the commands @code{dump}, @code{append}, and
13679 @code{restore} to copy data between target memory and a file. The
13680 @code{dump} and @code{append} commands write data to a file, and the
13681 @code{restore} command reads data from a file back into the inferior's
13682 memory. Files may be in binary, Motorola S-record, Intel hex,
13683 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13684 append to binary files, and cannot read from Verilog Hex files.
13685
13686 @table @code
13687
13688 @kindex dump
13689 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13690 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13691 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13692 or the value of @var{expr}, to @var{filename} in the given format.
13693
13694 The @var{format} parameter may be any one of:
13695 @table @code
13696 @item binary
13697 Raw binary form.
13698 @item ihex
13699 Intel hex format.
13700 @item srec
13701 Motorola S-record format.
13702 @item tekhex
13703 Tektronix Hex format.
13704 @item verilog
13705 Verilog Hex format.
13706 @end table
13707
13708 @value{GDBN} uses the same definitions of these formats as the
13709 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13710 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13711 form.
13712
13713 @kindex append
13714 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13715 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13716 Append the contents of memory from @var{start_addr} to @var{end_addr},
13717 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13718 (@value{GDBN} can only append data to files in raw binary form.)
13719
13720 @kindex restore
13721 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13722 Restore the contents of file @var{filename} into memory. The
13723 @code{restore} command can automatically recognize any known @sc{bfd}
13724 file format, except for raw binary. To restore a raw binary file you
13725 must specify the optional keyword @code{binary} after the filename.
13726
13727 If @var{bias} is non-zero, its value will be added to the addresses
13728 contained in the file. Binary files always start at address zero, so
13729 they will be restored at address @var{bias}. Other bfd files have
13730 a built-in location; they will be restored at offset @var{bias}
13731 from that location.
13732
13733 If @var{start} and/or @var{end} are non-zero, then only data between
13734 file offset @var{start} and file offset @var{end} will be restored.
13735 These offsets are relative to the addresses in the file, before
13736 the @var{bias} argument is applied.
13737
13738 @end table
13739
13740 @node Core File Generation
13741 @section How to Produce a Core File from Your Program
13742 @cindex dump core from inferior
13743
13744 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13745 image of a running process and its process status (register values
13746 etc.). Its primary use is post-mortem debugging of a program that
13747 crashed while it ran outside a debugger. A program that crashes
13748 automatically produces a core file, unless this feature is disabled by
13749 the user. @xref{Files}, for information on invoking @value{GDBN} in
13750 the post-mortem debugging mode.
13751
13752 Occasionally, you may wish to produce a core file of the program you
13753 are debugging in order to preserve a snapshot of its state.
13754 @value{GDBN} has a special command for that.
13755
13756 @table @code
13757 @kindex gcore
13758 @kindex generate-core-file
13759 @item generate-core-file [@var{file}]
13760 @itemx gcore [@var{file}]
13761 Produce a core dump of the inferior process. The optional argument
13762 @var{file} specifies the file name where to put the core dump. If not
13763 specified, the file name defaults to @file{core.@var{pid}}, where
13764 @var{pid} is the inferior process ID.
13765
13766 Note that this command is implemented only for some systems (as of
13767 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13768
13769 On @sc{gnu}/Linux, this command can take into account the value of the
13770 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13771 dump (@pxref{set use-coredump-filter}), and by default honors the
13772 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13773 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13774
13775 @kindex set use-coredump-filter
13776 @anchor{set use-coredump-filter}
13777 @item set use-coredump-filter on
13778 @itemx set use-coredump-filter off
13779 Enable or disable the use of the file
13780 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13781 files. This file is used by the Linux kernel to decide what types of
13782 memory mappings will be dumped or ignored when generating a core dump
13783 file. @var{pid} is the process ID of a currently running process.
13784
13785 To make use of this feature, you have to write in the
13786 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13787 which is a bit mask representing the memory mapping types. If a bit
13788 is set in the bit mask, then the memory mappings of the corresponding
13789 types will be dumped; otherwise, they will be ignored. This
13790 configuration is inherited by child processes. For more information
13791 about the bits that can be set in the
13792 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13793 manpage of @code{core(5)}.
13794
13795 By default, this option is @code{on}. If this option is turned
13796 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13797 and instead uses the same default value as the Linux kernel in order
13798 to decide which pages will be dumped in the core dump file. This
13799 value is currently @code{0x33}, which means that bits @code{0}
13800 (anonymous private mappings), @code{1} (anonymous shared mappings),
13801 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13802 This will cause these memory mappings to be dumped automatically.
13803
13804 @kindex set dump-excluded-mappings
13805 @anchor{set dump-excluded-mappings}
13806 @item set dump-excluded-mappings on
13807 @itemx set dump-excluded-mappings off
13808 If @code{on} is specified, @value{GDBN} will dump memory mappings
13809 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13810 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13811
13812 The default value is @code{off}.
13813 @end table
13814
13815 @node Character Sets
13816 @section Character Sets
13817 @cindex character sets
13818 @cindex charset
13819 @cindex translating between character sets
13820 @cindex host character set
13821 @cindex target character set
13822
13823 If the program you are debugging uses a different character set to
13824 represent characters and strings than the one @value{GDBN} uses itself,
13825 @value{GDBN} can automatically translate between the character sets for
13826 you. The character set @value{GDBN} uses we call the @dfn{host
13827 character set}; the one the inferior program uses we call the
13828 @dfn{target character set}.
13829
13830 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13831 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13832 remote protocol (@pxref{Remote Debugging}) to debug a program
13833 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13834 then the host character set is Latin-1, and the target character set is
13835 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13836 target-charset EBCDIC-US}, then @value{GDBN} translates between
13837 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13838 character and string literals in expressions.
13839
13840 @value{GDBN} has no way to automatically recognize which character set
13841 the inferior program uses; you must tell it, using the @code{set
13842 target-charset} command, described below.
13843
13844 Here are the commands for controlling @value{GDBN}'s character set
13845 support:
13846
13847 @table @code
13848 @item set target-charset @var{charset}
13849 @kindex set target-charset
13850 Set the current target character set to @var{charset}. To display the
13851 list of supported target character sets, type
13852 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13853
13854 @item set host-charset @var{charset}
13855 @kindex set host-charset
13856 Set the current host character set to @var{charset}.
13857
13858 By default, @value{GDBN} uses a host character set appropriate to the
13859 system it is running on; you can override that default using the
13860 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13861 automatically determine the appropriate host character set. In this
13862 case, @value{GDBN} uses @samp{UTF-8}.
13863
13864 @value{GDBN} can only use certain character sets as its host character
13865 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13866 @value{GDBN} will list the host character sets it supports.
13867
13868 @item set charset @var{charset}
13869 @kindex set charset
13870 Set the current host and target character sets to @var{charset}. As
13871 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13872 @value{GDBN} will list the names of the character sets that can be used
13873 for both host and target.
13874
13875 @item show charset
13876 @kindex show charset
13877 Show the names of the current host and target character sets.
13878
13879 @item show host-charset
13880 @kindex show host-charset
13881 Show the name of the current host character set.
13882
13883 @item show target-charset
13884 @kindex show target-charset
13885 Show the name of the current target character set.
13886
13887 @item set target-wide-charset @var{charset}
13888 @kindex set target-wide-charset
13889 Set the current target's wide character set to @var{charset}. This is
13890 the character set used by the target's @code{wchar_t} type. To
13891 display the list of supported wide character sets, type
13892 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13893
13894 @item show target-wide-charset
13895 @kindex show target-wide-charset
13896 Show the name of the current target's wide character set.
13897 @end table
13898
13899 Here is an example of @value{GDBN}'s character set support in action.
13900 Assume that the following source code has been placed in the file
13901 @file{charset-test.c}:
13902
13903 @smallexample
13904 #include <stdio.h>
13905
13906 char ascii_hello[]
13907 = @{72, 101, 108, 108, 111, 44, 32, 119,
13908 111, 114, 108, 100, 33, 10, 0@};
13909 char ibm1047_hello[]
13910 = @{200, 133, 147, 147, 150, 107, 64, 166,
13911 150, 153, 147, 132, 90, 37, 0@};
13912
13913 main ()
13914 @{
13915 printf ("Hello, world!\n");
13916 @}
13917 @end smallexample
13918
13919 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13920 containing the string @samp{Hello, world!} followed by a newline,
13921 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13922
13923 We compile the program, and invoke the debugger on it:
13924
13925 @smallexample
13926 $ gcc -g charset-test.c -o charset-test
13927 $ gdb -nw charset-test
13928 GNU gdb 2001-12-19-cvs
13929 Copyright 2001 Free Software Foundation, Inc.
13930 @dots{}
13931 (@value{GDBP})
13932 @end smallexample
13933
13934 We can use the @code{show charset} command to see what character sets
13935 @value{GDBN} is currently using to interpret and display characters and
13936 strings:
13937
13938 @smallexample
13939 (@value{GDBP}) show charset
13940 The current host and target character set is `ISO-8859-1'.
13941 (@value{GDBP})
13942 @end smallexample
13943
13944 For the sake of printing this manual, let's use @sc{ascii} as our
13945 initial character set:
13946 @smallexample
13947 (@value{GDBP}) set charset ASCII
13948 (@value{GDBP}) show charset
13949 The current host and target character set is `ASCII'.
13950 (@value{GDBP})
13951 @end smallexample
13952
13953 Let's assume that @sc{ascii} is indeed the correct character set for our
13954 host system --- in other words, let's assume that if @value{GDBN} prints
13955 characters using the @sc{ascii} character set, our terminal will display
13956 them properly. Since our current target character set is also
13957 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13958
13959 @smallexample
13960 (@value{GDBP}) print ascii_hello
13961 $1 = 0x401698 "Hello, world!\n"
13962 (@value{GDBP}) print ascii_hello[0]
13963 $2 = 72 'H'
13964 (@value{GDBP})
13965 @end smallexample
13966
13967 @value{GDBN} uses the target character set for character and string
13968 literals you use in expressions:
13969
13970 @smallexample
13971 (@value{GDBP}) print '+'
13972 $3 = 43 '+'
13973 (@value{GDBP})
13974 @end smallexample
13975
13976 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13977 character.
13978
13979 @value{GDBN} relies on the user to tell it which character set the
13980 target program uses. If we print @code{ibm1047_hello} while our target
13981 character set is still @sc{ascii}, we get jibberish:
13982
13983 @smallexample
13984 (@value{GDBP}) print ibm1047_hello
13985 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13986 (@value{GDBP}) print ibm1047_hello[0]
13987 $5 = 200 '\310'
13988 (@value{GDBP})
13989 @end smallexample
13990
13991 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13992 @value{GDBN} tells us the character sets it supports:
13993
13994 @smallexample
13995 (@value{GDBP}) set target-charset
13996 ASCII EBCDIC-US IBM1047 ISO-8859-1
13997 (@value{GDBP}) set target-charset
13998 @end smallexample
13999
14000 We can select @sc{ibm1047} as our target character set, and examine the
14001 program's strings again. Now the @sc{ascii} string is wrong, but
14002 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
14003 target character set, @sc{ibm1047}, to the host character set,
14004 @sc{ascii}, and they display correctly:
14005
14006 @smallexample
14007 (@value{GDBP}) set target-charset IBM1047
14008 (@value{GDBP}) show charset
14009 The current host character set is `ASCII'.
14010 The current target character set is `IBM1047'.
14011 (@value{GDBP}) print ascii_hello
14012 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
14013 (@value{GDBP}) print ascii_hello[0]
14014 $7 = 72 '\110'
14015 (@value{GDBP}) print ibm1047_hello
14016 $8 = 0x4016a8 "Hello, world!\n"
14017 (@value{GDBP}) print ibm1047_hello[0]
14018 $9 = 200 'H'
14019 (@value{GDBP})
14020 @end smallexample
14021
14022 As above, @value{GDBN} uses the target character set for character and
14023 string literals you use in expressions:
14024
14025 @smallexample
14026 (@value{GDBP}) print '+'
14027 $10 = 78 '+'
14028 (@value{GDBP})
14029 @end smallexample
14030
14031 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
14032 character.
14033
14034 @node Caching Target Data
14035 @section Caching Data of Targets
14036 @cindex caching data of targets
14037
14038 @value{GDBN} caches data exchanged between the debugger and a target.
14039 Each cache is associated with the address space of the inferior.
14040 @xref{Inferiors Connections and Programs}, about inferior and address space.
14041 Such caching generally improves performance in remote debugging
14042 (@pxref{Remote Debugging}), because it reduces the overhead of the
14043 remote protocol by bundling memory reads and writes into large chunks.
14044 Unfortunately, simply caching everything would lead to incorrect results,
14045 since @value{GDBN} does not necessarily know anything about volatile
14046 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
14047 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
14048 is executing.
14049 Therefore, by default, @value{GDBN} only caches data
14050 known to be on the stack@footnote{In non-stop mode, it is moderately
14051 rare for a running thread to modify the stack of a stopped thread
14052 in a way that would interfere with a backtrace, and caching of
14053 stack reads provides a significant speed up of remote backtraces.} or
14054 in the code segment.
14055 Other regions of memory can be explicitly marked as
14056 cacheable; @pxref{Memory Region Attributes}.
14057
14058 @table @code
14059 @kindex set remotecache
14060 @item set remotecache on
14061 @itemx set remotecache off
14062 This option no longer does anything; it exists for compatibility
14063 with old scripts.
14064
14065 @kindex show remotecache
14066 @item show remotecache
14067 Show the current state of the obsolete remotecache flag.
14068
14069 @kindex set stack-cache
14070 @item set stack-cache on
14071 @itemx set stack-cache off
14072 Enable or disable caching of stack accesses. When @code{on}, use
14073 caching. By default, this option is @code{on}.
14074
14075 @kindex show stack-cache
14076 @item show stack-cache
14077 Show the current state of data caching for memory accesses.
14078
14079 @kindex set code-cache
14080 @item set code-cache on
14081 @itemx set code-cache off
14082 Enable or disable caching of code segment accesses. When @code{on},
14083 use caching. By default, this option is @code{on}. This improves
14084 performance of disassembly in remote debugging.
14085
14086 @kindex show code-cache
14087 @item show code-cache
14088 Show the current state of target memory cache for code segment
14089 accesses.
14090
14091 @kindex info dcache
14092 @item info dcache @r{[}line@r{]}
14093 Print the information about the performance of data cache of the
14094 current inferior's address space. The information displayed
14095 includes the dcache width and depth, and for each cache line, its
14096 number, address, and how many times it was referenced. This
14097 command is useful for debugging the data cache operation.
14098
14099 If a line number is specified, the contents of that line will be
14100 printed in hex.
14101
14102 @item set dcache size @var{size}
14103 @cindex dcache size
14104 @kindex set dcache size
14105 Set maximum number of entries in dcache (dcache depth above).
14106
14107 @item set dcache line-size @var{line-size}
14108 @cindex dcache line-size
14109 @kindex set dcache line-size
14110 Set number of bytes each dcache entry caches (dcache width above).
14111 Must be a power of 2.
14112
14113 @item show dcache size
14114 @kindex show dcache size
14115 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
14116
14117 @item show dcache line-size
14118 @kindex show dcache line-size
14119 Show default size of dcache lines.
14120
14121 @item maint flush dcache
14122 @cindex dcache, flushing
14123 @kindex maint flush dcache
14124 Flush the contents (if any) of the dcache. This maintainer command is
14125 useful when debugging the dcache implementation.
14126
14127 @end table
14128
14129 @node Searching Memory
14130 @section Search Memory
14131 @cindex searching memory
14132
14133 Memory can be searched for a particular sequence of bytes with the
14134 @code{find} command.
14135
14136 @table @code
14137 @kindex find
14138 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
14139 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
14140 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
14141 etc. The search begins at address @var{start_addr} and continues for either
14142 @var{len} bytes or through to @var{end_addr} inclusive.
14143 @end table
14144
14145 @var{s} and @var{n} are optional parameters.
14146 They may be specified in either order, apart or together.
14147
14148 @table @r
14149 @item @var{s}, search query size
14150 The size of each search query value.
14151
14152 @table @code
14153 @item b
14154 bytes
14155 @item h
14156 halfwords (two bytes)
14157 @item w
14158 words (four bytes)
14159 @item g
14160 giant words (eight bytes)
14161 @end table
14162
14163 All values are interpreted in the current language.
14164 This means, for example, that if the current source language is C/C@t{++}
14165 then searching for the string ``hello'' includes the trailing '\0'.
14166 The null terminator can be removed from searching by using casts,
14167 e.g.: @samp{@{char[5]@}"hello"}.
14168
14169 If the value size is not specified, it is taken from the
14170 value's type in the current language.
14171 This is useful when one wants to specify the search
14172 pattern as a mixture of types.
14173 Note that this means, for example, that in the case of C-like languages
14174 a search for an untyped 0x42 will search for @samp{(int) 0x42}
14175 which is typically four bytes.
14176
14177 @item @var{n}, maximum number of finds
14178 The maximum number of matches to print. The default is to print all finds.
14179 @end table
14180
14181 You can use strings as search values. Quote them with double-quotes
14182 (@code{"}).
14183 The string value is copied into the search pattern byte by byte,
14184 regardless of the endianness of the target and the size specification.
14185
14186 The address of each match found is printed as well as a count of the
14187 number of matches found.
14188
14189 The address of the last value found is stored in convenience variable
14190 @samp{$_}.
14191 A count of the number of matches is stored in @samp{$numfound}.
14192
14193 For example, if stopped at the @code{printf} in this function:
14194
14195 @smallexample
14196 void
14197 hello ()
14198 @{
14199 static char hello[] = "hello-hello";
14200 static struct @{ char c; short s; int i; @}
14201 __attribute__ ((packed)) mixed
14202 = @{ 'c', 0x1234, 0x87654321 @};
14203 printf ("%s\n", hello);
14204 @}
14205 @end smallexample
14206
14207 @noindent
14208 you get during debugging:
14209
14210 @smallexample
14211 (@value{GDBP}) find &hello[0], +sizeof(hello), "hello"
14212 0x804956d <hello.1620+6>
14213 1 pattern found
14214 (@value{GDBP}) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
14215 0x8049567 <hello.1620>
14216 0x804956d <hello.1620+6>
14217 2 patterns found.
14218 (@value{GDBP}) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
14219 0x8049567 <hello.1620>
14220 0x804956d <hello.1620+6>
14221 2 patterns found.
14222 (@value{GDBP}) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
14223 0x8049567 <hello.1620>
14224 1 pattern found
14225 (@value{GDBP}) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
14226 0x8049560 <mixed.1625>
14227 1 pattern found
14228 (@value{GDBP}) print $numfound
14229 $1 = 1
14230 (@value{GDBP}) print $_
14231 $2 = (void *) 0x8049560
14232 @end smallexample
14233
14234 @node Value Sizes
14235 @section Value Sizes
14236
14237 Whenever @value{GDBN} prints a value memory will be allocated within
14238 @value{GDBN} to hold the contents of the value. It is possible in
14239 some languages with dynamic typing systems, that an invalid program
14240 may indicate a value that is incorrectly large, this in turn may cause
14241 @value{GDBN} to try and allocate an overly large amount of memory.
14242
14243 @table @code
14244 @anchor{set max-value-size}
14245 @kindex set max-value-size
14246 @item set max-value-size @var{bytes}
14247 @itemx set max-value-size unlimited
14248 Set the maximum size of memory that @value{GDBN} will allocate for the
14249 contents of a value to @var{bytes}, trying to display a value that
14250 requires more memory than that will result in an error.
14251
14252 Setting this variable does not effect values that have already been
14253 allocated within @value{GDBN}, only future allocations.
14254
14255 There's a minimum size that @code{max-value-size} can be set to in
14256 order that @value{GDBN} can still operate correctly, this minimum is
14257 currently 16 bytes.
14258
14259 The limit applies to the results of some subexpressions as well as to
14260 complete expressions. For example, an expression denoting a simple
14261 integer component, such as @code{x.y.z}, may fail if the size of
14262 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
14263 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
14264 @var{A} is an array variable with non-constant size, will generally
14265 succeed regardless of the bounds on @var{A}, as long as the component
14266 size is less than @var{bytes}.
14267
14268 The default value of @code{max-value-size} is currently 64k.
14269
14270 @kindex show max-value-size
14271 @item show max-value-size
14272 Show the maximum size of memory, in bytes, that @value{GDBN} will
14273 allocate for the contents of a value.
14274 @end table
14275
14276 @node Optimized Code
14277 @chapter Debugging Optimized Code
14278 @cindex optimized code, debugging
14279 @cindex debugging optimized code
14280
14281 Almost all compilers support optimization. With optimization
14282 disabled, the compiler generates assembly code that corresponds
14283 directly to your source code, in a simplistic way. As the compiler
14284 applies more powerful optimizations, the generated assembly code
14285 diverges from your original source code. With help from debugging
14286 information generated by the compiler, @value{GDBN} can map from
14287 the running program back to constructs from your original source.
14288
14289 @value{GDBN} is more accurate with optimization disabled. If you
14290 can recompile without optimization, it is easier to follow the
14291 progress of your program during debugging. But, there are many cases
14292 where you may need to debug an optimized version.
14293
14294 When you debug a program compiled with @samp{-g -O}, remember that the
14295 optimizer has rearranged your code; the debugger shows you what is
14296 really there. Do not be too surprised when the execution path does not
14297 exactly match your source file! An extreme example: if you define a
14298 variable, but never use it, @value{GDBN} never sees that
14299 variable---because the compiler optimizes it out of existence.
14300
14301 Some things do not work as well with @samp{-g -O} as with just
14302 @samp{-g}, particularly on machines with instruction scheduling. If in
14303 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
14304 please report it to us as a bug (including a test case!).
14305 @xref{Variables}, for more information about debugging optimized code.
14306
14307 @menu
14308 * Inline Functions:: How @value{GDBN} presents inlining
14309 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
14310 @end menu
14311
14312 @node Inline Functions
14313 @section Inline Functions
14314 @cindex inline functions, debugging
14315
14316 @dfn{Inlining} is an optimization that inserts a copy of the function
14317 body directly at each call site, instead of jumping to a shared
14318 routine. @value{GDBN} displays inlined functions just like
14319 non-inlined functions. They appear in backtraces. You can view their
14320 arguments and local variables, step into them with @code{step}, skip
14321 them with @code{next}, and escape from them with @code{finish}.
14322 You can check whether a function was inlined by using the
14323 @code{info frame} command.
14324
14325 For @value{GDBN} to support inlined functions, the compiler must
14326 record information about inlining in the debug information ---
14327 @value{NGCC} using the @sc{dwarf 2} format does this, and several
14328 other compilers do also. @value{GDBN} only supports inlined functions
14329 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
14330 do not emit two required attributes (@samp{DW_AT_call_file} and
14331 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
14332 function calls with earlier versions of @value{NGCC}. It instead
14333 displays the arguments and local variables of inlined functions as
14334 local variables in the caller.
14335
14336 The body of an inlined function is directly included at its call site;
14337 unlike a non-inlined function, there are no instructions devoted to
14338 the call. @value{GDBN} still pretends that the call site and the
14339 start of the inlined function are different instructions. Stepping to
14340 the call site shows the call site, and then stepping again shows
14341 the first line of the inlined function, even though no additional
14342 instructions are executed.
14343
14344 This makes source-level debugging much clearer; you can see both the
14345 context of the call and then the effect of the call. Only stepping by
14346 a single instruction using @code{stepi} or @code{nexti} does not do
14347 this; single instruction steps always show the inlined body.
14348
14349 There are some ways that @value{GDBN} does not pretend that inlined
14350 function calls are the same as normal calls:
14351
14352 @itemize @bullet
14353 @item
14354 Setting breakpoints at the call site of an inlined function may not
14355 work, because the call site does not contain any code. @value{GDBN}
14356 may incorrectly move the breakpoint to the next line of the enclosing
14357 function, after the call. This limitation will be removed in a future
14358 version of @value{GDBN}; until then, set a breakpoint on an earlier line
14359 or inside the inlined function instead.
14360
14361 @item
14362 @value{GDBN} cannot locate the return value of inlined calls after
14363 using the @code{finish} command. This is a limitation of compiler-generated
14364 debugging information; after @code{finish}, you can step to the next line
14365 and print a variable where your program stored the return value.
14366
14367 @end itemize
14368
14369 @node Tail Call Frames
14370 @section Tail Call Frames
14371 @cindex tail call frames, debugging
14372
14373 Function @code{B} can call function @code{C} in its very last statement. In
14374 unoptimized compilation the call of @code{C} is immediately followed by return
14375 instruction at the end of @code{B} code. Optimizing compiler may replace the
14376 call and return in function @code{B} into one jump to function @code{C}
14377 instead. Such use of a jump instruction is called @dfn{tail call}.
14378
14379 During execution of function @code{C}, there will be no indication in the
14380 function call stack frames that it was tail-called from @code{B}. If function
14381 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
14382 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
14383 some cases @value{GDBN} can determine that @code{C} was tail-called from
14384 @code{B}, and it will then create fictitious call frame for that, with the
14385 return address set up as if @code{B} called @code{C} normally.
14386
14387 This functionality is currently supported only by DWARF 2 debugging format and
14388 the compiler has to produce @samp{DW_TAG_call_site} tags. With
14389 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
14390 this information.
14391
14392 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
14393 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
14394
14395 @smallexample
14396 (@value{GDBP}) x/i $pc - 2
14397 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
14398 (@value{GDBP}) info frame
14399 Stack level 1, frame at 0x7fffffffda30:
14400 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
14401 tail call frame, caller of frame at 0x7fffffffda30
14402 source language c++.
14403 Arglist at unknown address.
14404 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
14405 @end smallexample
14406
14407 The detection of all the possible code path executions can find them ambiguous.
14408 There is no execution history stored (possible @ref{Reverse Execution} is never
14409 used for this purpose) and the last known caller could have reached the known
14410 callee by multiple different jump sequences. In such case @value{GDBN} still
14411 tries to show at least all the unambiguous top tail callers and all the
14412 unambiguous bottom tail calees, if any.
14413
14414 @table @code
14415 @anchor{set debug entry-values}
14416 @item set debug entry-values
14417 @kindex set debug entry-values
14418 When set to on, enables printing of analysis messages for both frame argument
14419 values at function entry and tail calls. It will show all the possible valid
14420 tail calls code paths it has considered. It will also print the intersection
14421 of them with the final unambiguous (possibly partial or even empty) code path
14422 result.
14423
14424 @item show debug entry-values
14425 @kindex show debug entry-values
14426 Show the current state of analysis messages printing for both frame argument
14427 values at function entry and tail calls.
14428 @end table
14429
14430 The analysis messages for tail calls can for example show why the virtual tail
14431 call frame for function @code{c} has not been recognized (due to the indirect
14432 reference by variable @code{x}):
14433
14434 @smallexample
14435 static void __attribute__((noinline, noclone)) c (void);
14436 void (*x) (void) = c;
14437 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
14438 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
14439 int main (void) @{ x (); return 0; @}
14440
14441 Breakpoint 1, DW_OP_entry_value resolving cannot find
14442 DW_TAG_call_site 0x40039a in main
14443 a () at t.c:3
14444 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
14445 (@value{GDBP}) bt
14446 #0 a () at t.c:3
14447 #1 0x000000000040039a in main () at t.c:5
14448 @end smallexample
14449
14450 Another possibility is an ambiguous virtual tail call frames resolution:
14451
14452 @smallexample
14453 int i;
14454 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
14455 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
14456 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
14457 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
14458 static void __attribute__((noinline, noclone)) b (void)
14459 @{ if (i) c (); else e (); @}
14460 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
14461 int main (void) @{ a (); return 0; @}
14462
14463 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
14464 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
14465 tailcall: reduced: 0x4004d2(a) |
14466 (@value{GDBP}) bt
14467 #0 f () at t.c:2
14468 #1 0x00000000004004d2 in a () at t.c:8
14469 #2 0x0000000000400395 in main () at t.c:9
14470 @end smallexample
14471
14472 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
14473 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
14474
14475 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
14476 @ifset HAVE_MAKEINFO_CLICK
14477 @set ARROW @click{}
14478 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
14479 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
14480 @end ifset
14481 @ifclear HAVE_MAKEINFO_CLICK
14482 @set ARROW ->
14483 @set CALLSEQ1B @value{CALLSEQ1A}
14484 @set CALLSEQ2B @value{CALLSEQ2A}
14485 @end ifclear
14486
14487 Frames #0 and #2 are real, #1 is a virtual tail call frame.
14488 The code can have possible execution paths @value{CALLSEQ1B} or
14489 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
14490
14491 @code{initial:} state shows some random possible calling sequence @value{GDBN}
14492 has found. It then finds another possible calling sequence - that one is
14493 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
14494 printed as the @code{reduced:} calling sequence. That one could have many
14495 further @code{compare:} and @code{reduced:} statements as long as there remain
14496 any non-ambiguous sequence entries.
14497
14498 For the frame of function @code{b} in both cases there are different possible
14499 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
14500 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
14501 therefore this one is displayed to the user while the ambiguous frames are
14502 omitted.
14503
14504 There can be also reasons why printing of frame argument values at function
14505 entry may fail:
14506
14507 @smallexample
14508 int v;
14509 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
14510 static void __attribute__((noinline, noclone)) a (int i);
14511 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
14512 static void __attribute__((noinline, noclone)) a (int i)
14513 @{ if (i) b (i - 1); else c (0); @}
14514 int main (void) @{ a (5); return 0; @}
14515
14516 (@value{GDBP}) bt
14517 #0 c (i=i@@entry=0) at t.c:2
14518 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
14519 function "a" at 0x400420 can call itself via tail calls
14520 i=<optimized out>) at t.c:6
14521 #2 0x000000000040036e in main () at t.c:7
14522 @end smallexample
14523
14524 @value{GDBN} cannot find out from the inferior state if and how many times did
14525 function @code{a} call itself (via function @code{b}) as these calls would be
14526 tail calls. Such tail calls would modify the @code{i} variable, therefore
14527 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
14528 prints @code{<optimized out>} instead.
14529
14530 @node Macros
14531 @chapter C Preprocessor Macros
14532
14533 Some languages, such as C and C@t{++}, provide a way to define and invoke
14534 ``preprocessor macros'' which expand into strings of tokens.
14535 @value{GDBN} can evaluate expressions containing macro invocations, show
14536 the result of macro expansion, and show a macro's definition, including
14537 where it was defined.
14538
14539 You may need to compile your program specially to provide @value{GDBN}
14540 with information about preprocessor macros. Most compilers do not
14541 include macros in their debugging information, even when you compile
14542 with the @option{-g} flag. @xref{Compilation}.
14543
14544 A program may define a macro at one point, remove that definition later,
14545 and then provide a different definition after that. Thus, at different
14546 points in the program, a macro may have different definitions, or have
14547 no definition at all. If there is a current stack frame, @value{GDBN}
14548 uses the macros in scope at that frame's source code line. Otherwise,
14549 @value{GDBN} uses the macros in scope at the current listing location;
14550 see @ref{List}.
14551
14552 Whenever @value{GDBN} evaluates an expression, it always expands any
14553 macro invocations present in the expression. @value{GDBN} also provides
14554 the following commands for working with macros explicitly.
14555
14556 @table @code
14557
14558 @kindex macro expand
14559 @cindex macro expansion, showing the results of preprocessor
14560 @cindex preprocessor macro expansion, showing the results of
14561 @cindex expanding preprocessor macros
14562 @item macro expand @var{expression}
14563 @itemx macro exp @var{expression}
14564 Show the results of expanding all preprocessor macro invocations in
14565 @var{expression}. Since @value{GDBN} simply expands macros, but does
14566 not parse the result, @var{expression} need not be a valid expression;
14567 it can be any string of tokens.
14568
14569 @kindex macro exp1
14570 @item macro expand-once @var{expression}
14571 @itemx macro exp1 @var{expression}
14572 @cindex expand macro once
14573 @i{(This command is not yet implemented.)} Show the results of
14574 expanding those preprocessor macro invocations that appear explicitly in
14575 @var{expression}. Macro invocations appearing in that expansion are
14576 left unchanged. This command allows you to see the effect of a
14577 particular macro more clearly, without being confused by further
14578 expansions. Since @value{GDBN} simply expands macros, but does not
14579 parse the result, @var{expression} need not be a valid expression; it
14580 can be any string of tokens.
14581
14582 @kindex info macro
14583 @cindex macro definition, showing
14584 @cindex definition of a macro, showing
14585 @cindex macros, from debug info
14586 @item info macro [-a|-all] [--] @var{macro}
14587 Show the current definition or all definitions of the named @var{macro},
14588 and describe the source location or compiler command-line where that
14589 definition was established. The optional double dash is to signify the end of
14590 argument processing and the beginning of @var{macro} for non C-like macros where
14591 the macro may begin with a hyphen.
14592
14593 @kindex info macros
14594 @item info macros @var{locspec}
14595 Show all macro definitions that are in effect at the source line of
14596 the code location that results from resolving @var{locspec}, and
14597 describe the source location or compiler command-line where those
14598 definitions were established.
14599
14600 @kindex macro define
14601 @cindex user-defined macros
14602 @cindex defining macros interactively
14603 @cindex macros, user-defined
14604 @item macro define @var{macro} @var{replacement-list}
14605 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
14606 Introduce a definition for a preprocessor macro named @var{macro},
14607 invocations of which are replaced by the tokens given in
14608 @var{replacement-list}. The first form of this command defines an
14609 ``object-like'' macro, which takes no arguments; the second form
14610 defines a ``function-like'' macro, which takes the arguments given in
14611 @var{arglist}.
14612
14613 A definition introduced by this command is in scope in every
14614 expression evaluated in @value{GDBN}, until it is removed with the
14615 @code{macro undef} command, described below. The definition overrides
14616 all definitions for @var{macro} present in the program being debugged,
14617 as well as any previous user-supplied definition.
14618
14619 @kindex macro undef
14620 @item macro undef @var{macro}
14621 Remove any user-supplied definition for the macro named @var{macro}.
14622 This command only affects definitions provided with the @code{macro
14623 define} command, described above; it cannot remove definitions present
14624 in the program being debugged.
14625
14626 @kindex macro list
14627 @item macro list
14628 List all the macros defined using the @code{macro define} command.
14629 @end table
14630
14631 @cindex macros, example of debugging with
14632 Here is a transcript showing the above commands in action. First, we
14633 show our source files:
14634
14635 @smallexample
14636 $ cat sample.c
14637 #include <stdio.h>
14638 #include "sample.h"
14639
14640 #define M 42
14641 #define ADD(x) (M + x)
14642
14643 main ()
14644 @{
14645 #define N 28
14646 printf ("Hello, world!\n");
14647 #undef N
14648 printf ("We're so creative.\n");
14649 #define N 1729
14650 printf ("Goodbye, world!\n");
14651 @}
14652 $ cat sample.h
14653 #define Q <
14654 $
14655 @end smallexample
14656
14657 Now, we compile the program using the @sc{gnu} C compiler,
14658 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14659 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14660 and @option{-gdwarf-4}; we recommend always choosing the most recent
14661 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14662 includes information about preprocessor macros in the debugging
14663 information.
14664
14665 @smallexample
14666 $ gcc -gdwarf-2 -g3 sample.c -o sample
14667 $
14668 @end smallexample
14669
14670 Now, we start @value{GDBN} on our sample program:
14671
14672 @smallexample
14673 $ gdb -nw sample
14674 GNU gdb 2002-05-06-cvs
14675 Copyright 2002 Free Software Foundation, Inc.
14676 GDB is free software, @dots{}
14677 (@value{GDBP})
14678 @end smallexample
14679
14680 We can expand macros and examine their definitions, even when the
14681 program is not running. @value{GDBN} uses the current listing position
14682 to decide which macro definitions are in scope:
14683
14684 @smallexample
14685 (@value{GDBP}) list main
14686 3
14687 4 #define M 42
14688 5 #define ADD(x) (M + x)
14689 6
14690 7 main ()
14691 8 @{
14692 9 #define N 28
14693 10 printf ("Hello, world!\n");
14694 11 #undef N
14695 12 printf ("We're so creative.\n");
14696 (@value{GDBP}) info macro ADD
14697 Defined at /home/jimb/gdb/macros/play/sample.c:5
14698 #define ADD(x) (M + x)
14699 (@value{GDBP}) info macro Q
14700 Defined at /home/jimb/gdb/macros/play/sample.h:1
14701 included at /home/jimb/gdb/macros/play/sample.c:2
14702 #define Q <
14703 (@value{GDBP}) macro expand ADD(1)
14704 expands to: (42 + 1)
14705 (@value{GDBP}) macro expand-once ADD(1)
14706 expands to: once (M + 1)
14707 (@value{GDBP})
14708 @end smallexample
14709
14710 In the example above, note that @code{macro expand-once} expands only
14711 the macro invocation explicit in the original text --- the invocation of
14712 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14713 which was introduced by @code{ADD}.
14714
14715 Once the program is running, @value{GDBN} uses the macro definitions in
14716 force at the source line of the current stack frame:
14717
14718 @smallexample
14719 (@value{GDBP}) break main
14720 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14721 (@value{GDBP}) run
14722 Starting program: /home/jimb/gdb/macros/play/sample
14723
14724 Breakpoint 1, main () at sample.c:10
14725 10 printf ("Hello, world!\n");
14726 (@value{GDBP})
14727 @end smallexample
14728
14729 At line 10, the definition of the macro @code{N} at line 9 is in force:
14730
14731 @smallexample
14732 (@value{GDBP}) info macro N
14733 Defined at /home/jimb/gdb/macros/play/sample.c:9
14734 #define N 28
14735 (@value{GDBP}) macro expand N Q M
14736 expands to: 28 < 42
14737 (@value{GDBP}) print N Q M
14738 $1 = 1
14739 (@value{GDBP})
14740 @end smallexample
14741
14742 As we step over directives that remove @code{N}'s definition, and then
14743 give it a new definition, @value{GDBN} finds the definition (or lack
14744 thereof) in force at each point:
14745
14746 @smallexample
14747 (@value{GDBP}) next
14748 Hello, world!
14749 12 printf ("We're so creative.\n");
14750 (@value{GDBP}) info macro N
14751 The symbol `N' has no definition as a C/C++ preprocessor macro
14752 at /home/jimb/gdb/macros/play/sample.c:12
14753 (@value{GDBP}) next
14754 We're so creative.
14755 14 printf ("Goodbye, world!\n");
14756 (@value{GDBP}) info macro N
14757 Defined at /home/jimb/gdb/macros/play/sample.c:13
14758 #define N 1729
14759 (@value{GDBP}) macro expand N Q M
14760 expands to: 1729 < 42
14761 (@value{GDBP}) print N Q M
14762 $2 = 0
14763 (@value{GDBP})
14764 @end smallexample
14765
14766 In addition to source files, macros can be defined on the compilation command
14767 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14768 such a way, @value{GDBN} displays the location of their definition as line zero
14769 of the source file submitted to the compiler.
14770
14771 @smallexample
14772 (@value{GDBP}) info macro __STDC__
14773 Defined at /home/jimb/gdb/macros/play/sample.c:0
14774 -D__STDC__=1
14775 (@value{GDBP})
14776 @end smallexample
14777
14778
14779 @node Tracepoints
14780 @chapter Tracepoints
14781 @c This chapter is based on the documentation written by Michael
14782 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14783
14784 @cindex tracepoints
14785 In some applications, it is not feasible for the debugger to interrupt
14786 the program's execution long enough for the developer to learn
14787 anything helpful about its behavior. If the program's correctness
14788 depends on its real-time behavior, delays introduced by a debugger
14789 might cause the program to change its behavior drastically, or perhaps
14790 fail, even when the code itself is correct. It is useful to be able
14791 to observe the program's behavior without interrupting it.
14792
14793 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14794 specify locations in the program, called @dfn{tracepoints}, and
14795 arbitrary expressions to evaluate when those tracepoints are reached.
14796 Later, using the @code{tfind} command, you can examine the values
14797 those expressions had when the program hit the tracepoints. The
14798 expressions may also denote objects in memory---structures or arrays,
14799 for example---whose values @value{GDBN} should record; while visiting
14800 a particular tracepoint, you may inspect those objects as if they were
14801 in memory at that moment. However, because @value{GDBN} records these
14802 values without interacting with you, it can do so quickly and
14803 unobtrusively, hopefully not disturbing the program's behavior.
14804
14805 The tracepoint facility is currently available only for remote
14806 targets. @xref{Targets}. In addition, your remote target must know
14807 how to collect trace data. This functionality is implemented in the
14808 remote stub; however, none of the stubs distributed with @value{GDBN}
14809 support tracepoints as of this writing. The format of the remote
14810 packets used to implement tracepoints are described in @ref{Tracepoint
14811 Packets}.
14812
14813 It is also possible to get trace data from a file, in a manner reminiscent
14814 of corefiles; you specify the filename, and use @code{tfind} to search
14815 through the file. @xref{Trace Files}, for more details.
14816
14817 This chapter describes the tracepoint commands and features.
14818
14819 @menu
14820 * Set Tracepoints::
14821 * Analyze Collected Data::
14822 * Tracepoint Variables::
14823 * Trace Files::
14824 @end menu
14825
14826 @node Set Tracepoints
14827 @section Commands to Set Tracepoints
14828
14829 Before running such a @dfn{trace experiment}, an arbitrary number of
14830 tracepoints can be set. A tracepoint is actually a special type of
14831 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14832 standard breakpoint commands. For instance, as with breakpoints,
14833 tracepoint numbers are successive integers starting from one, and many
14834 of the commands associated with tracepoints take the tracepoint number
14835 as their argument, to identify which tracepoint to work on.
14836
14837 For each tracepoint, you can specify, in advance, some arbitrary set
14838 of data that you want the target to collect in the trace buffer when
14839 it hits that tracepoint. The collected data can include registers,
14840 local variables, or global data. Later, you can use @value{GDBN}
14841 commands to examine the values these data had at the time the
14842 tracepoint was hit.
14843
14844 Tracepoints do not support every breakpoint feature. Ignore counts on
14845 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14846 commands when they are hit. Tracepoints may not be thread-specific
14847 either.
14848
14849 @cindex fast tracepoints
14850 Some targets may support @dfn{fast tracepoints}, which are inserted in
14851 a different way (such as with a jump instead of a trap), that is
14852 faster but possibly restricted in where they may be installed.
14853
14854 @cindex static tracepoints
14855 @cindex markers, static tracepoints
14856 @cindex probing markers, static tracepoints
14857 Regular and fast tracepoints are dynamic tracing facilities, meaning
14858 that they can be used to insert tracepoints at (almost) any location
14859 in the target. Some targets may also support controlling @dfn{static
14860 tracepoints} from @value{GDBN}. With static tracing, a set of
14861 instrumentation points, also known as @dfn{markers}, are embedded in
14862 the target program, and can be activated or deactivated by name or
14863 address. These are usually placed at locations which facilitate
14864 investigating what the target is actually doing. @value{GDBN}'s
14865 support for static tracing includes being able to list instrumentation
14866 points, and attach them with @value{GDBN} defined high level
14867 tracepoints that expose the whole range of convenience of
14868 @value{GDBN}'s tracepoints support. Namely, support for collecting
14869 registers values and values of global or local (to the instrumentation
14870 point) variables; tracepoint conditions and trace state variables.
14871 The act of installing a @value{GDBN} static tracepoint on an
14872 instrumentation point, or marker, is referred to as @dfn{probing} a
14873 static tracepoint marker.
14874
14875 @code{gdbserver} supports tracepoints on some target systems.
14876 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14877
14878 This section describes commands to set tracepoints and associated
14879 conditions and actions.
14880
14881 @menu
14882 * Create and Delete Tracepoints::
14883 * Enable and Disable Tracepoints::
14884 * Tracepoint Passcounts::
14885 * Tracepoint Conditions::
14886 * Trace State Variables::
14887 * Tracepoint Actions::
14888 * Listing Tracepoints::
14889 * Listing Static Tracepoint Markers::
14890 * Starting and Stopping Trace Experiments::
14891 * Tracepoint Restrictions::
14892 @end menu
14893
14894 @node Create and Delete Tracepoints
14895 @subsection Create and Delete Tracepoints
14896
14897 @table @code
14898 @cindex set tracepoint
14899 @kindex trace
14900 @item trace @var{locspec}
14901 The @code{trace} command is very similar to the @code{break} command.
14902 Its argument @var{locspec} can be any valid location specification.
14903 @xref{Location Specifications}. The @code{trace} command defines a tracepoint,
14904 which is a point in the target program where the debugger will briefly stop,
14905 collect some data, and then allow the program to continue. Setting a tracepoint
14906 or changing its actions takes effect immediately if the remote stub
14907 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14908 in tracing}).
14909 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14910 these changes don't take effect until the next @code{tstart}
14911 command, and once a trace experiment is running, further changes will
14912 not have any effect until the next trace experiment starts. In addition,
14913 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14914 address is not yet resolved. (This is similar to pending breakpoints.)
14915 Pending tracepoints are not downloaded to the target and not installed
14916 until they are resolved. The resolution of pending tracepoints requires
14917 @value{GDBN} support---when debugging with the remote target, and
14918 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14919 tracing}), pending tracepoints can not be resolved (and downloaded to
14920 the remote stub) while @value{GDBN} is disconnected.
14921
14922 Here are some examples of using the @code{trace} command:
14923
14924 @smallexample
14925 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14926
14927 (@value{GDBP}) @b{trace +2} // 2 lines forward
14928
14929 (@value{GDBP}) @b{trace my_function} // first source line of function
14930
14931 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14932
14933 (@value{GDBP}) @b{trace *0x2117c4} // an address
14934 @end smallexample
14935
14936 @noindent
14937 You can abbreviate @code{trace} as @code{tr}.
14938
14939 @item trace @var{locspec} if @var{cond}
14940 Set a tracepoint with condition @var{cond}; evaluate the expression
14941 @var{cond} each time the tracepoint is reached, and collect data only
14942 if the value is nonzero---that is, if @var{cond} evaluates as true.
14943 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14944 information on tracepoint conditions.
14945
14946 @item ftrace @var{locspec} [ if @var{cond} ]
14947 @cindex set fast tracepoint
14948 @cindex fast tracepoints, setting
14949 @kindex ftrace
14950 The @code{ftrace} command sets a fast tracepoint. For targets that
14951 support them, fast tracepoints will use a more efficient but possibly
14952 less general technique to trigger data collection, such as a jump
14953 instruction instead of a trap, or some sort of hardware support. It
14954 may not be possible to create a fast tracepoint at the desired
14955 location, in which case the command will exit with an explanatory
14956 message.
14957
14958 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14959 @code{trace}.
14960
14961 On 32-bit x86-architecture systems, fast tracepoints normally need to
14962 be placed at an instruction that is 5 bytes or longer, but can be
14963 placed at 4-byte instructions if the low 64K of memory of the target
14964 program is available to install trampolines. Some Unix-type systems,
14965 such as @sc{gnu}/Linux, exclude low addresses from the program's
14966 address space; but for instance with the Linux kernel it is possible
14967 to let @value{GDBN} use this area by doing a @command{sysctl} command
14968 to set the @code{mmap_min_addr} kernel parameter, as in
14969
14970 @example
14971 sudo sysctl -w vm.mmap_min_addr=32768
14972 @end example
14973
14974 @noindent
14975 which sets the low address to 32K, which leaves plenty of room for
14976 trampolines. The minimum address should be set to a page boundary.
14977
14978 @item strace [@var{locspec} | -m @var{marker}] [ if @var{cond} ]
14979 @cindex set static tracepoint
14980 @cindex static tracepoints, setting
14981 @cindex probe static tracepoint marker
14982 @kindex strace
14983 The @code{strace} command sets a static tracepoint. For targets that
14984 support it, setting a static tracepoint probes a static
14985 instrumentation point, or marker, found at the code locations that
14986 result from resolving @var{locspec}. It may not be possible to set a
14987 static tracepoint at the desired code location, in which case the
14988 command will exit with an explanatory message.
14989
14990 @value{GDBN} handles arguments to @code{strace} exactly as for
14991 @code{trace}, with the addition that the user can also specify
14992 @code{-m @var{marker}} instead of a location spec. This probes the marker
14993 identified by the @var{marker} string identifier. This identifier
14994 depends on the static tracepoint backend library your program is
14995 using. You can find all the marker identifiers in the @samp{ID} field
14996 of the @code{info static-tracepoint-markers} command output.
14997 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14998 Markers}. For example, in the following small program using the UST
14999 tracing engine:
15000
15001 @smallexample
15002 main ()
15003 @{
15004 trace_mark(ust, bar33, "str %s", "FOOBAZ");
15005 @}
15006 @end smallexample
15007
15008 @noindent
15009 the marker id is composed of joining the first two arguments to the
15010 @code{trace_mark} call with a slash, which translates to:
15011
15012 @smallexample
15013 (@value{GDBP}) info static-tracepoint-markers
15014 Cnt Enb ID Address What
15015 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
15016 Data: "str %s"
15017 [etc...]
15018 @end smallexample
15019
15020 @noindent
15021 so you may probe the marker above with:
15022
15023 @smallexample
15024 (@value{GDBP}) strace -m ust/bar33
15025 @end smallexample
15026
15027 Static tracepoints accept an extra collect action --- @code{collect
15028 $_sdata}. This collects arbitrary user data passed in the probe point
15029 call to the tracing library. In the UST example above, you'll see
15030 that the third argument to @code{trace_mark} is a printf-like format
15031 string. The user data is then the result of running that formatting
15032 string against the following arguments. Note that @code{info
15033 static-tracepoint-markers} command output lists that format string in
15034 the @samp{Data:} field.
15035
15036 You can inspect this data when analyzing the trace buffer, by printing
15037 the $_sdata variable like any other variable available to
15038 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
15039
15040 @vindex $tpnum
15041 @cindex last tracepoint number
15042 @cindex recent tracepoint number
15043 @cindex tracepoint number
15044 The convenience variable @code{$tpnum} records the tracepoint number
15045 of the most recently set tracepoint.
15046
15047 @kindex delete tracepoint
15048 @cindex tracepoint deletion
15049 @item delete tracepoint @r{[}@var{num}@r{]}
15050 Permanently delete one or more tracepoints. With no argument, the
15051 default is to delete all tracepoints. Note that the regular
15052 @code{delete} command can remove tracepoints also.
15053
15054 Examples:
15055
15056 @smallexample
15057 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
15058
15059 (@value{GDBP}) @b{delete trace} // remove all tracepoints
15060 @end smallexample
15061
15062 @noindent
15063 You can abbreviate this command as @code{del tr}.
15064 @end table
15065
15066 @node Enable and Disable Tracepoints
15067 @subsection Enable and Disable Tracepoints
15068
15069 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
15070
15071 @table @code
15072 @kindex disable tracepoint
15073 @item disable tracepoint @r{[}@var{num}@r{]}
15074 Disable tracepoint @var{num}, or all tracepoints if no argument
15075 @var{num} is given. A disabled tracepoint will have no effect during
15076 a trace experiment, but it is not forgotten. You can re-enable
15077 a disabled tracepoint using the @code{enable tracepoint} command.
15078 If the command is issued during a trace experiment and the debug target
15079 has support for disabling tracepoints during a trace experiment, then the
15080 change will be effective immediately. Otherwise, it will be applied to the
15081 next trace experiment.
15082
15083 @kindex enable tracepoint
15084 @item enable tracepoint @r{[}@var{num}@r{]}
15085 Enable tracepoint @var{num}, or all tracepoints. If this command is
15086 issued during a trace experiment and the debug target supports enabling
15087 tracepoints during a trace experiment, then the enabled tracepoints will
15088 become effective immediately. Otherwise, they will become effective the
15089 next time a trace experiment is run.
15090 @end table
15091
15092 @node Tracepoint Passcounts
15093 @subsection Tracepoint Passcounts
15094
15095 @table @code
15096 @kindex passcount
15097 @cindex tracepoint pass count
15098 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
15099 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
15100 automatically stop a trace experiment. If a tracepoint's passcount is
15101 @var{n}, then the trace experiment will be automatically stopped on
15102 the @var{n}'th time that tracepoint is hit. If the tracepoint number
15103 @var{num} is not specified, the @code{passcount} command sets the
15104 passcount of the most recently defined tracepoint. If no passcount is
15105 given, the trace experiment will run until stopped explicitly by the
15106 user.
15107
15108 Examples:
15109
15110 @smallexample
15111 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
15112 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
15113
15114 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
15115 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
15116 (@value{GDBP}) @b{trace foo}
15117 (@value{GDBP}) @b{pass 3}
15118 (@value{GDBP}) @b{trace bar}
15119 (@value{GDBP}) @b{pass 2}
15120 (@value{GDBP}) @b{trace baz}
15121 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
15122 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
15123 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
15124 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
15125 @end smallexample
15126 @end table
15127
15128 @node Tracepoint Conditions
15129 @subsection Tracepoint Conditions
15130 @cindex conditional tracepoints
15131 @cindex tracepoint conditions
15132
15133 The simplest sort of tracepoint collects data every time your program
15134 reaches a specified place. You can also specify a @dfn{condition} for
15135 a tracepoint. A condition is just a Boolean expression in your
15136 programming language (@pxref{Expressions, ,Expressions}). A
15137 tracepoint with a condition evaluates the expression each time your
15138 program reaches it, and data collection happens only if the condition
15139 is true.
15140
15141 Tracepoint conditions can be specified when a tracepoint is set, by
15142 using @samp{if} in the arguments to the @code{trace} command.
15143 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
15144 also be set or changed at any time with the @code{condition} command,
15145 just as with breakpoints.
15146
15147 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
15148 the conditional expression itself. Instead, @value{GDBN} encodes the
15149 expression into an agent expression (@pxref{Agent Expressions})
15150 suitable for execution on the target, independently of @value{GDBN}.
15151 Global variables become raw memory locations, locals become stack
15152 accesses, and so forth.
15153
15154 For instance, suppose you have a function that is usually called
15155 frequently, but should not be called after an error has occurred. You
15156 could use the following tracepoint command to collect data about calls
15157 of that function that happen while the error code is propagating
15158 through the program; an unconditional tracepoint could end up
15159 collecting thousands of useless trace frames that you would have to
15160 search through.
15161
15162 @smallexample
15163 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
15164 @end smallexample
15165
15166 @node Trace State Variables
15167 @subsection Trace State Variables
15168 @cindex trace state variables
15169
15170 A @dfn{trace state variable} is a special type of variable that is
15171 created and managed by target-side code. The syntax is the same as
15172 that for GDB's convenience variables (a string prefixed with ``$''),
15173 but they are stored on the target. They must be created explicitly,
15174 using a @code{tvariable} command. They are always 64-bit signed
15175 integers.
15176
15177 Trace state variables are remembered by @value{GDBN}, and downloaded
15178 to the target along with tracepoint information when the trace
15179 experiment starts. There are no intrinsic limits on the number of
15180 trace state variables, beyond memory limitations of the target.
15181
15182 @cindex convenience variables, and trace state variables
15183 Although trace state variables are managed by the target, you can use
15184 them in print commands and expressions as if they were convenience
15185 variables; @value{GDBN} will get the current value from the target
15186 while the trace experiment is running. Trace state variables share
15187 the same namespace as other ``$'' variables, which means that you
15188 cannot have trace state variables with names like @code{$23} or
15189 @code{$pc}, nor can you have a trace state variable and a convenience
15190 variable with the same name.
15191
15192 @table @code
15193
15194 @item tvariable $@var{name} [ = @var{expression} ]
15195 @kindex tvariable
15196 The @code{tvariable} command creates a new trace state variable named
15197 @code{$@var{name}}, and optionally gives it an initial value of
15198 @var{expression}. The @var{expression} is evaluated when this command is
15199 entered; the result will be converted to an integer if possible,
15200 otherwise @value{GDBN} will report an error. A subsequent
15201 @code{tvariable} command specifying the same name does not create a
15202 variable, but instead assigns the supplied initial value to the
15203 existing variable of that name, overwriting any previous initial
15204 value. The default initial value is 0.
15205
15206 @item info tvariables
15207 @kindex info tvariables
15208 List all the trace state variables along with their initial values.
15209 Their current values may also be displayed, if the trace experiment is
15210 currently running.
15211
15212 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
15213 @kindex delete tvariable
15214 Delete the given trace state variables, or all of them if no arguments
15215 are specified.
15216
15217 @end table
15218
15219 @node Tracepoint Actions
15220 @subsection Tracepoint Action Lists
15221
15222 @table @code
15223 @kindex actions
15224 @cindex tracepoint actions
15225 @item actions @r{[}@var{num}@r{]}
15226 This command will prompt for a list of actions to be taken when the
15227 tracepoint is hit. If the tracepoint number @var{num} is not
15228 specified, this command sets the actions for the one that was most
15229 recently defined (so that you can define a tracepoint and then say
15230 @code{actions} without bothering about its number). You specify the
15231 actions themselves on the following lines, one action at a time, and
15232 terminate the actions list with a line containing just @code{end}. So
15233 far, the only defined actions are @code{collect}, @code{teval}, and
15234 @code{while-stepping}.
15235
15236 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
15237 Commands, ,Breakpoint Command Lists}), except that only the defined
15238 actions are allowed; any other @value{GDBN} command is rejected.
15239
15240 @cindex remove actions from a tracepoint
15241 To remove all actions from a tracepoint, type @samp{actions @var{num}}
15242 and follow it immediately with @samp{end}.
15243
15244 @smallexample
15245 (@value{GDBP}) @b{collect @var{data}} // collect some data
15246
15247 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
15248
15249 (@value{GDBP}) @b{end} // signals the end of actions.
15250 @end smallexample
15251
15252 In the following example, the action list begins with @code{collect}
15253 commands indicating the things to be collected when the tracepoint is
15254 hit. Then, in order to single-step and collect additional data
15255 following the tracepoint, a @code{while-stepping} command is used,
15256 followed by the list of things to be collected after each step in a
15257 sequence of single steps. The @code{while-stepping} command is
15258 terminated by its own separate @code{end} command. Lastly, the action
15259 list is terminated by an @code{end} command.
15260
15261 @smallexample
15262 (@value{GDBP}) @b{trace foo}
15263 (@value{GDBP}) @b{actions}
15264 Enter actions for tracepoint 1, one per line:
15265 > collect bar,baz
15266 > collect $regs
15267 > while-stepping 12
15268 > collect $pc, arr[i]
15269 > end
15270 end
15271 @end smallexample
15272
15273 @kindex collect @r{(tracepoints)}
15274 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
15275 Collect values of the given expressions when the tracepoint is hit.
15276 This command accepts a comma-separated list of any valid expressions.
15277 In addition to global, static, or local variables, the following
15278 special arguments are supported:
15279
15280 @table @code
15281 @item $regs
15282 Collect all registers.
15283
15284 @item $args
15285 Collect all function arguments.
15286
15287 @item $locals
15288 Collect all local variables.
15289
15290 @item $_ret
15291 Collect the return address. This is helpful if you want to see more
15292 of a backtrace.
15293
15294 @emph{Note:} The return address location can not always be reliably
15295 determined up front, and the wrong address / registers may end up
15296 collected instead. On some architectures the reliability is higher
15297 for tracepoints at function entry, while on others it's the opposite.
15298 When this happens, backtracing will stop because the return address is
15299 found unavailable (unless another collect rule happened to match it).
15300
15301 @item $_probe_argc
15302 Collects the number of arguments from the static probe at which the
15303 tracepoint is located.
15304 @xref{Static Probe Points}.
15305
15306 @item $_probe_arg@var{n}
15307 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
15308 from the static probe at which the tracepoint is located.
15309 @xref{Static Probe Points}.
15310
15311 @item $_sdata
15312 @vindex $_sdata@r{, collect}
15313 Collect static tracepoint marker specific data. Only available for
15314 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
15315 Lists}. On the UST static tracepoints library backend, an
15316 instrumentation point resembles a @code{printf} function call. The
15317 tracing library is able to collect user specified data formatted to a
15318 character string using the format provided by the programmer that
15319 instrumented the program. Other backends have similar mechanisms.
15320 Here's an example of a UST marker call:
15321
15322 @smallexample
15323 const char master_name[] = "$your_name";
15324 trace_mark(channel1, marker1, "hello %s", master_name)
15325 @end smallexample
15326
15327 In this case, collecting @code{$_sdata} collects the string
15328 @samp{hello $yourname}. When analyzing the trace buffer, you can
15329 inspect @samp{$_sdata} like any other variable available to
15330 @value{GDBN}.
15331 @end table
15332
15333 You can give several consecutive @code{collect} commands, each one
15334 with a single argument, or one @code{collect} command with several
15335 arguments separated by commas; the effect is the same.
15336
15337 The optional @var{mods} changes the usual handling of the arguments.
15338 @code{s} requests that pointers to chars be handled as strings, in
15339 particular collecting the contents of the memory being pointed at, up
15340 to the first zero. The upper bound is by default the value of the
15341 @code{print characters} variable; if @code{s} is followed by a decimal
15342 number, that is the upper bound instead. So for instance
15343 @samp{collect/s25 mystr} collects as many as 25 characters at
15344 @samp{mystr}.
15345
15346 The command @code{info scope} (@pxref{Symbols, info scope}) is
15347 particularly useful for figuring out what data to collect.
15348
15349 @kindex teval @r{(tracepoints)}
15350 @item teval @var{expr1}, @var{expr2}, @dots{}
15351 Evaluate the given expressions when the tracepoint is hit. This
15352 command accepts a comma-separated list of expressions. The results
15353 are discarded, so this is mainly useful for assigning values to trace
15354 state variables (@pxref{Trace State Variables}) without adding those
15355 values to the trace buffer, as would be the case if the @code{collect}
15356 action were used.
15357
15358 @kindex while-stepping @r{(tracepoints)}
15359 @item while-stepping @var{n}
15360 Perform @var{n} single-step instruction traces after the tracepoint,
15361 collecting new data after each step. The @code{while-stepping}
15362 command is followed by the list of what to collect while stepping
15363 (followed by its own @code{end} command):
15364
15365 @smallexample
15366 > while-stepping 12
15367 > collect $regs, myglobal
15368 > end
15369 >
15370 @end smallexample
15371
15372 @noindent
15373 Note that @code{$pc} is not automatically collected by
15374 @code{while-stepping}; you need to explicitly collect that register if
15375 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
15376 @code{stepping}.
15377
15378 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
15379 @kindex set default-collect
15380 @cindex default collection action
15381 This variable is a list of expressions to collect at each tracepoint
15382 hit. It is effectively an additional @code{collect} action prepended
15383 to every tracepoint action list. The expressions are parsed
15384 individually for each tracepoint, so for instance a variable named
15385 @code{xyz} may be interpreted as a global for one tracepoint, and a
15386 local for another, as appropriate to the tracepoint's location.
15387
15388 @item show default-collect
15389 @kindex show default-collect
15390 Show the list of expressions that are collected by default at each
15391 tracepoint hit.
15392
15393 @end table
15394
15395 @node Listing Tracepoints
15396 @subsection Listing Tracepoints
15397
15398 @table @code
15399 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
15400 @kindex info tp @r{[}@var{n}@dots{}@r{]}
15401 @cindex information about tracepoints
15402 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
15403 Display information about the tracepoint @var{num}. If you don't
15404 specify a tracepoint number, displays information about all the
15405 tracepoints defined so far. The format is similar to that used for
15406 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
15407 command, simply restricting itself to tracepoints.
15408
15409 A tracepoint's listing may include additional information specific to
15410 tracing:
15411
15412 @itemize @bullet
15413 @item
15414 its passcount as given by the @code{passcount @var{n}} command
15415
15416 @item
15417 the state about installed on target of each location
15418 @end itemize
15419
15420 @smallexample
15421 (@value{GDBP}) @b{info trace}
15422 Num Type Disp Enb Address What
15423 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
15424 while-stepping 20
15425 collect globfoo, $regs
15426 end
15427 collect globfoo2
15428 end
15429 pass count 1200
15430 2 tracepoint keep y <MULTIPLE>
15431 collect $eip
15432 2.1 y 0x0804859c in func4 at change-loc.h:35
15433 installed on target
15434 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
15435 installed on target
15436 2.3 y <PENDING> set_tracepoint
15437 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
15438 not installed on target
15439 (@value{GDBP})
15440 @end smallexample
15441
15442 @noindent
15443 This command can be abbreviated @code{info tp}.
15444 @end table
15445
15446 @node Listing Static Tracepoint Markers
15447 @subsection Listing Static Tracepoint Markers
15448
15449 @table @code
15450 @kindex info static-tracepoint-markers
15451 @cindex information about static tracepoint markers
15452 @item info static-tracepoint-markers
15453 Display information about all static tracepoint markers defined in the
15454 program.
15455
15456 For each marker, the following columns are printed:
15457
15458 @table @emph
15459 @item Count
15460 An incrementing counter, output to help readability. This is not a
15461 stable identifier.
15462 @item ID
15463 The marker ID, as reported by the target.
15464 @item Enabled or Disabled
15465 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
15466 that are not enabled.
15467 @item Address
15468 Where the marker is in your program, as a memory address.
15469 @item What
15470 Where the marker is in the source for your program, as a file and line
15471 number. If the debug information included in the program does not
15472 allow @value{GDBN} to locate the source of the marker, this column
15473 will be left blank.
15474 @end table
15475
15476 @noindent
15477 In addition, the following information may be printed for each marker:
15478
15479 @table @emph
15480 @item Data
15481 User data passed to the tracing library by the marker call. In the
15482 UST backend, this is the format string passed as argument to the
15483 marker call.
15484 @item Static tracepoints probing the marker
15485 The list of static tracepoints attached to the marker.
15486 @end table
15487
15488 @smallexample
15489 (@value{GDBP}) info static-tracepoint-markers
15490 Cnt ID Enb Address What
15491 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
15492 Data: number1 %d number2 %d
15493 Probed by static tracepoints: #2
15494 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
15495 Data: str %s
15496 (@value{GDBP})
15497 @end smallexample
15498 @end table
15499
15500 @node Starting and Stopping Trace Experiments
15501 @subsection Starting and Stopping Trace Experiments
15502
15503 @table @code
15504 @kindex tstart [ @var{notes} ]
15505 @cindex start a new trace experiment
15506 @cindex collected data discarded
15507 @item tstart
15508 This command starts the trace experiment, and begins collecting data.
15509 It has the side effect of discarding all the data collected in the
15510 trace buffer during the previous trace experiment. If any arguments
15511 are supplied, they are taken as a note and stored with the trace
15512 experiment's state. The notes may be arbitrary text, and are
15513 especially useful with disconnected tracing in a multi-user context;
15514 the notes can explain what the trace is doing, supply user contact
15515 information, and so forth.
15516
15517 @kindex tstop [ @var{notes} ]
15518 @cindex stop a running trace experiment
15519 @item tstop
15520 This command stops the trace experiment. If any arguments are
15521 supplied, they are recorded with the experiment as a note. This is
15522 useful if you are stopping a trace started by someone else, for
15523 instance if the trace is interfering with the system's behavior and
15524 needs to be stopped quickly.
15525
15526 @strong{Note}: a trace experiment and data collection may stop
15527 automatically if any tracepoint's passcount is reached
15528 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
15529
15530 @kindex tstatus
15531 @cindex status of trace data collection
15532 @cindex trace experiment, status of
15533 @item tstatus
15534 This command displays the status of the current trace data
15535 collection.
15536 @end table
15537
15538 Here is an example of the commands we described so far:
15539
15540 @smallexample
15541 (@value{GDBP}) @b{trace gdb_c_test}
15542 (@value{GDBP}) @b{actions}
15543 Enter actions for tracepoint #1, one per line.
15544 > collect $regs,$locals,$args
15545 > while-stepping 11
15546 > collect $regs
15547 > end
15548 > end
15549 (@value{GDBP}) @b{tstart}
15550 [time passes @dots{}]
15551 (@value{GDBP}) @b{tstop}
15552 @end smallexample
15553
15554 @anchor{disconnected tracing}
15555 @cindex disconnected tracing
15556 You can choose to continue running the trace experiment even if
15557 @value{GDBN} disconnects from the target, voluntarily or
15558 involuntarily. For commands such as @code{detach}, the debugger will
15559 ask what you want to do with the trace. But for unexpected
15560 terminations (@value{GDBN} crash, network outage), it would be
15561 unfortunate to lose hard-won trace data, so the variable
15562 @code{disconnected-tracing} lets you decide whether the trace should
15563 continue running without @value{GDBN}.
15564
15565 @table @code
15566 @item set disconnected-tracing on
15567 @itemx set disconnected-tracing off
15568 @kindex set disconnected-tracing
15569 Choose whether a tracing run should continue to run if @value{GDBN}
15570 has disconnected from the target. Note that @code{detach} or
15571 @code{quit} will ask you directly what to do about a running trace no
15572 matter what this variable's setting, so the variable is mainly useful
15573 for handling unexpected situations, such as loss of the network.
15574
15575 @item show disconnected-tracing
15576 @kindex show disconnected-tracing
15577 Show the current choice for disconnected tracing.
15578
15579 @end table
15580
15581 When you reconnect to the target, the trace experiment may or may not
15582 still be running; it might have filled the trace buffer in the
15583 meantime, or stopped for one of the other reasons. If it is running,
15584 it will continue after reconnection.
15585
15586 Upon reconnection, the target will upload information about the
15587 tracepoints in effect. @value{GDBN} will then compare that
15588 information to the set of tracepoints currently defined, and attempt
15589 to match them up, allowing for the possibility that the numbers may
15590 have changed due to creation and deletion in the meantime. If one of
15591 the target's tracepoints does not match any in @value{GDBN}, the
15592 debugger will create a new tracepoint, so that you have a number with
15593 which to specify that tracepoint. This matching-up process is
15594 necessarily heuristic, and it may result in useless tracepoints being
15595 created; you may simply delete them if they are of no use.
15596
15597 @cindex circular trace buffer
15598 If your target agent supports a @dfn{circular trace buffer}, then you
15599 can run a trace experiment indefinitely without filling the trace
15600 buffer; when space runs out, the agent deletes already-collected trace
15601 frames, oldest first, until there is enough room to continue
15602 collecting. This is especially useful if your tracepoints are being
15603 hit too often, and your trace gets terminated prematurely because the
15604 buffer is full. To ask for a circular trace buffer, simply set
15605 @samp{circular-trace-buffer} to on. You can set this at any time,
15606 including during tracing; if the agent can do it, it will change
15607 buffer handling on the fly, otherwise it will not take effect until
15608 the next run.
15609
15610 @table @code
15611 @item set circular-trace-buffer on
15612 @itemx set circular-trace-buffer off
15613 @kindex set circular-trace-buffer
15614 Choose whether a tracing run should use a linear or circular buffer
15615 for trace data. A linear buffer will not lose any trace data, but may
15616 fill up prematurely, while a circular buffer will discard old trace
15617 data, but it will have always room for the latest tracepoint hits.
15618
15619 @item show circular-trace-buffer
15620 @kindex show circular-trace-buffer
15621 Show the current choice for the trace buffer. Note that this may not
15622 match the agent's current buffer handling, nor is it guaranteed to
15623 match the setting that might have been in effect during a past run,
15624 for instance if you are looking at frames from a trace file.
15625
15626 @end table
15627
15628 @table @code
15629 @item set trace-buffer-size @var{n}
15630 @itemx set trace-buffer-size unlimited
15631 @kindex set trace-buffer-size
15632 Request that the target use a trace buffer of @var{n} bytes. Not all
15633 targets will honor the request; they may have a compiled-in size for
15634 the trace buffer, or some other limitation. Set to a value of
15635 @code{unlimited} or @code{-1} to let the target use whatever size it
15636 likes. This is also the default.
15637
15638 @item show trace-buffer-size
15639 @kindex show trace-buffer-size
15640 Show the current requested size for the trace buffer. Note that this
15641 will only match the actual size if the target supports size-setting,
15642 and was able to handle the requested size. For instance, if the
15643 target can only change buffer size between runs, this variable will
15644 not reflect the change until the next run starts. Use @code{tstatus}
15645 to get a report of the actual buffer size.
15646 @end table
15647
15648 @table @code
15649 @item set trace-user @var{text}
15650 @kindex set trace-user
15651
15652 @item show trace-user
15653 @kindex show trace-user
15654
15655 @item set trace-notes @var{text}
15656 @kindex set trace-notes
15657 Set the trace run's notes.
15658
15659 @item show trace-notes
15660 @kindex show trace-notes
15661 Show the trace run's notes.
15662
15663 @item set trace-stop-notes @var{text}
15664 @kindex set trace-stop-notes
15665 Set the trace run's stop notes. The handling of the note is as for
15666 @code{tstop} arguments; the set command is convenient way to fix a
15667 stop note that is mistaken or incomplete.
15668
15669 @item show trace-stop-notes
15670 @kindex show trace-stop-notes
15671 Show the trace run's stop notes.
15672
15673 @end table
15674
15675 @node Tracepoint Restrictions
15676 @subsection Tracepoint Restrictions
15677
15678 @cindex tracepoint restrictions
15679 There are a number of restrictions on the use of tracepoints. As
15680 described above, tracepoint data gathering occurs on the target
15681 without interaction from @value{GDBN}. Thus the full capabilities of
15682 the debugger are not available during data gathering, and then at data
15683 examination time, you will be limited by only having what was
15684 collected. The following items describe some common problems, but it
15685 is not exhaustive, and you may run into additional difficulties not
15686 mentioned here.
15687
15688 @itemize @bullet
15689
15690 @item
15691 Tracepoint expressions are intended to gather objects (lvalues). Thus
15692 the full flexibility of GDB's expression evaluator is not available.
15693 You cannot call functions, cast objects to aggregate types, access
15694 convenience variables or modify values (except by assignment to trace
15695 state variables). Some language features may implicitly call
15696 functions (for instance Objective-C fields with accessors), and therefore
15697 cannot be collected either.
15698
15699 @item
15700 Collection of local variables, either individually or in bulk with
15701 @code{$locals} or @code{$args}, during @code{while-stepping} may
15702 behave erratically. The stepping action may enter a new scope (for
15703 instance by stepping into a function), or the location of the variable
15704 may change (for instance it is loaded into a register). The
15705 tracepoint data recorded uses the location information for the
15706 variables that is correct for the tracepoint location. When the
15707 tracepoint is created, it is not possible, in general, to determine
15708 where the steps of a @code{while-stepping} sequence will advance the
15709 program---particularly if a conditional branch is stepped.
15710
15711 @item
15712 Collection of an incompletely-initialized or partially-destroyed object
15713 may result in something that @value{GDBN} cannot display, or displays
15714 in a misleading way.
15715
15716 @item
15717 When @value{GDBN} displays a pointer to character it automatically
15718 dereferences the pointer to also display characters of the string
15719 being pointed to. However, collecting the pointer during tracing does
15720 not automatically collect the string. You need to explicitly
15721 dereference the pointer and provide size information if you want to
15722 collect not only the pointer, but the memory pointed to. For example,
15723 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15724 by @code{ptr}.
15725
15726 @item
15727 It is not possible to collect a complete stack backtrace at a
15728 tracepoint. Instead, you may collect the registers and a few hundred
15729 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15730 (adjust to use the name of the actual stack pointer register on your
15731 target architecture, and the amount of stack you wish to capture).
15732 Then the @code{backtrace} command will show a partial backtrace when
15733 using a trace frame. The number of stack frames that can be examined
15734 depends on the sizes of the frames in the collected stack. Note that
15735 if you ask for a block so large that it goes past the bottom of the
15736 stack, the target agent may report an error trying to read from an
15737 invalid address.
15738
15739 @item
15740 If you do not collect registers at a tracepoint, @value{GDBN} can
15741 infer that the value of @code{$pc} must be the same as the address of
15742 the tracepoint and use that when you are looking at a trace frame
15743 for that tracepoint. However, this cannot work if the tracepoint has
15744 multiple locations (for instance if it was set in a function that was
15745 inlined), or if it has a @code{while-stepping} loop. In those cases
15746 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15747 it to zero.
15748
15749 @end itemize
15750
15751 @node Analyze Collected Data
15752 @section Using the Collected Data
15753
15754 After the tracepoint experiment ends, you use @value{GDBN} commands
15755 for examining the trace data. The basic idea is that each tracepoint
15756 collects a trace @dfn{snapshot} every time it is hit and another
15757 snapshot every time it single-steps. All these snapshots are
15758 consecutively numbered from zero and go into a buffer, and you can
15759 examine them later. The way you examine them is to @dfn{focus} on a
15760 specific trace snapshot. When the remote stub is focused on a trace
15761 snapshot, it will respond to all @value{GDBN} requests for memory and
15762 registers by reading from the buffer which belongs to that snapshot,
15763 rather than from @emph{real} memory or registers of the program being
15764 debugged. This means that @strong{all} @value{GDBN} commands
15765 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15766 behave as if we were currently debugging the program state as it was
15767 when the tracepoint occurred. Any requests for data that are not in
15768 the buffer will fail.
15769
15770 @menu
15771 * tfind:: How to select a trace snapshot
15772 * tdump:: How to display all data for a snapshot
15773 * save tracepoints:: How to save tracepoints for a future run
15774 @end menu
15775
15776 @node tfind
15777 @subsection @code{tfind @var{n}}
15778
15779 @kindex tfind
15780 @cindex select trace snapshot
15781 @cindex find trace snapshot
15782 The basic command for selecting a trace snapshot from the buffer is
15783 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15784 counting from zero. If no argument @var{n} is given, the next
15785 snapshot is selected.
15786
15787 Here are the various forms of using the @code{tfind} command.
15788
15789 @table @code
15790 @item tfind start
15791 Find the first snapshot in the buffer. This is a synonym for
15792 @code{tfind 0} (since 0 is the number of the first snapshot).
15793
15794 @item tfind none
15795 Stop debugging trace snapshots, resume @emph{live} debugging.
15796
15797 @item tfind end
15798 Same as @samp{tfind none}.
15799
15800 @item tfind
15801 No argument means find the next trace snapshot or find the first
15802 one if no trace snapshot is selected.
15803
15804 @item tfind -
15805 Find the previous trace snapshot before the current one. This permits
15806 retracing earlier steps.
15807
15808 @item tfind tracepoint @var{num}
15809 Find the next snapshot associated with tracepoint @var{num}. Search
15810 proceeds forward from the last examined trace snapshot. If no
15811 argument @var{num} is given, it means find the next snapshot collected
15812 for the same tracepoint as the current snapshot.
15813
15814 @item tfind pc @var{addr}
15815 Find the next snapshot associated with the value @var{addr} of the
15816 program counter. Search proceeds forward from the last examined trace
15817 snapshot. If no argument @var{addr} is given, it means find the next
15818 snapshot with the same value of PC as the current snapshot.
15819
15820 @item tfind outside @var{addr1}, @var{addr2}
15821 Find the next snapshot whose PC is outside the given range of
15822 addresses (exclusive).
15823
15824 @item tfind range @var{addr1}, @var{addr2}
15825 Find the next snapshot whose PC is between @var{addr1} and
15826 @var{addr2} (inclusive).
15827
15828 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15829 Find the next snapshot associated with the source line @var{n}. If
15830 the optional argument @var{file} is given, refer to line @var{n} in
15831 that source file. Search proceeds forward from the last examined
15832 trace snapshot. If no argument @var{n} is given, it means find the
15833 next line other than the one currently being examined; thus saying
15834 @code{tfind line} repeatedly can appear to have the same effect as
15835 stepping from line to line in a @emph{live} debugging session.
15836 @end table
15837
15838 The default arguments for the @code{tfind} commands are specifically
15839 designed to make it easy to scan through the trace buffer. For
15840 instance, @code{tfind} with no argument selects the next trace
15841 snapshot, and @code{tfind -} with no argument selects the previous
15842 trace snapshot. So, by giving one @code{tfind} command, and then
15843 simply hitting @key{RET} repeatedly you can examine all the trace
15844 snapshots in order. Or, by saying @code{tfind -} and then hitting
15845 @key{RET} repeatedly you can examine the snapshots in reverse order.
15846 The @code{tfind line} command with no argument selects the snapshot
15847 for the next source line executed. The @code{tfind pc} command with
15848 no argument selects the next snapshot with the same program counter
15849 (PC) as the current frame. The @code{tfind tracepoint} command with
15850 no argument selects the next trace snapshot collected by the same
15851 tracepoint as the current one.
15852
15853 In addition to letting you scan through the trace buffer manually,
15854 these commands make it easy to construct @value{GDBN} scripts that
15855 scan through the trace buffer and print out whatever collected data
15856 you are interested in. Thus, if we want to examine the PC, FP, and SP
15857 registers from each trace frame in the buffer, we can say this:
15858
15859 @smallexample
15860 (@value{GDBP}) @b{tfind start}
15861 (@value{GDBP}) @b{while ($trace_frame != -1)}
15862 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15863 $trace_frame, $pc, $sp, $fp
15864 > tfind
15865 > end
15866
15867 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15868 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15869 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15870 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15871 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15872 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15873 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15874 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15875 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15876 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15877 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15878 @end smallexample
15879
15880 Or, if we want to examine the variable @code{X} at each source line in
15881 the buffer:
15882
15883 @smallexample
15884 (@value{GDBP}) @b{tfind start}
15885 (@value{GDBP}) @b{while ($trace_frame != -1)}
15886 > printf "Frame %d, X == %d\n", $trace_frame, X
15887 > tfind line
15888 > end
15889
15890 Frame 0, X = 1
15891 Frame 7, X = 2
15892 Frame 13, X = 255
15893 @end smallexample
15894
15895 @node tdump
15896 @subsection @code{tdump}
15897 @kindex tdump
15898 @cindex dump all data collected at tracepoint
15899 @cindex tracepoint data, display
15900
15901 This command takes no arguments. It prints all the data collected at
15902 the current trace snapshot.
15903
15904 @smallexample
15905 (@value{GDBP}) @b{trace 444}
15906 (@value{GDBP}) @b{actions}
15907 Enter actions for tracepoint #2, one per line:
15908 > collect $regs, $locals, $args, gdb_long_test
15909 > end
15910
15911 (@value{GDBP}) @b{tstart}
15912
15913 (@value{GDBP}) @b{tfind line 444}
15914 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15915 at gdb_test.c:444
15916 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15917
15918 (@value{GDBP}) @b{tdump}
15919 Data collected at tracepoint 2, trace frame 1:
15920 d0 0xc4aa0085 -995491707
15921 d1 0x18 24
15922 d2 0x80 128
15923 d3 0x33 51
15924 d4 0x71aea3d 119204413
15925 d5 0x22 34
15926 d6 0xe0 224
15927 d7 0x380035 3670069
15928 a0 0x19e24a 1696330
15929 a1 0x3000668 50333288
15930 a2 0x100 256
15931 a3 0x322000 3284992
15932 a4 0x3000698 50333336
15933 a5 0x1ad3cc 1758156
15934 fp 0x30bf3c 0x30bf3c
15935 sp 0x30bf34 0x30bf34
15936 ps 0x0 0
15937 pc 0x20b2c8 0x20b2c8
15938 fpcontrol 0x0 0
15939 fpstatus 0x0 0
15940 fpiaddr 0x0 0
15941 p = 0x20e5b4 "gdb-test"
15942 p1 = (void *) 0x11
15943 p2 = (void *) 0x22
15944 p3 = (void *) 0x33
15945 p4 = (void *) 0x44
15946 p5 = (void *) 0x55
15947 p6 = (void *) 0x66
15948 gdb_long_test = 17 '\021'
15949
15950 (@value{GDBP})
15951 @end smallexample
15952
15953 @code{tdump} works by scanning the tracepoint's current collection
15954 actions and printing the value of each expression listed. So
15955 @code{tdump} can fail, if after a run, you change the tracepoint's
15956 actions to mention variables that were not collected during the run.
15957
15958 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15959 uses the collected value of @code{$pc} to distinguish between trace
15960 frames that were collected at the tracepoint hit, and frames that were
15961 collected while stepping. This allows it to correctly choose whether
15962 to display the basic list of collections, or the collections from the
15963 body of the while-stepping loop. However, if @code{$pc} was not collected,
15964 then @code{tdump} will always attempt to dump using the basic collection
15965 list, and may fail if a while-stepping frame does not include all the
15966 same data that is collected at the tracepoint hit.
15967 @c This is getting pretty arcane, example would be good.
15968
15969 @node save tracepoints
15970 @subsection @code{save tracepoints @var{filename}}
15971 @kindex save tracepoints
15972 @kindex save-tracepoints
15973 @cindex save tracepoints for future sessions
15974
15975 This command saves all current tracepoint definitions together with
15976 their actions and passcounts, into a file @file{@var{filename}}
15977 suitable for use in a later debugging session. To read the saved
15978 tracepoint definitions, use the @code{source} command (@pxref{Command
15979 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15980 alias for @w{@code{save tracepoints}}
15981
15982 @node Tracepoint Variables
15983 @section Convenience Variables for Tracepoints
15984 @cindex tracepoint variables
15985 @cindex convenience variables for tracepoints
15986
15987 @table @code
15988 @vindex $trace_frame
15989 @item (int) $trace_frame
15990 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15991 snapshot is selected.
15992
15993 @vindex $tracepoint
15994 @item (int) $tracepoint
15995 The tracepoint for the current trace snapshot.
15996
15997 @vindex $trace_line
15998 @item (int) $trace_line
15999 The line number for the current trace snapshot.
16000
16001 @vindex $trace_file
16002 @item (char []) $trace_file
16003 The source file for the current trace snapshot.
16004
16005 @vindex $trace_func
16006 @item (char []) $trace_func
16007 The name of the function containing @code{$tracepoint}.
16008 @end table
16009
16010 Note: @code{$trace_file} is not suitable for use in @code{printf},
16011 use @code{output} instead.
16012
16013 Here's a simple example of using these convenience variables for
16014 stepping through all the trace snapshots and printing some of their
16015 data. Note that these are not the same as trace state variables,
16016 which are managed by the target.
16017
16018 @smallexample
16019 (@value{GDBP}) @b{tfind start}
16020
16021 (@value{GDBP}) @b{while $trace_frame != -1}
16022 > output $trace_file
16023 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
16024 > tfind
16025 > end
16026 @end smallexample
16027
16028 @node Trace Files
16029 @section Using Trace Files
16030 @cindex trace files
16031
16032 In some situations, the target running a trace experiment may no
16033 longer be available; perhaps it crashed, or the hardware was needed
16034 for a different activity. To handle these cases, you can arrange to
16035 dump the trace data into a file, and later use that file as a source
16036 of trace data, via the @code{target tfile} command.
16037
16038 @table @code
16039
16040 @kindex tsave
16041 @item tsave [ -r ] @var{filename}
16042 @itemx tsave [-ctf] @var{dirname}
16043 Save the trace data to @var{filename}. By default, this command
16044 assumes that @var{filename} refers to the host filesystem, so if
16045 necessary @value{GDBN} will copy raw trace data up from the target and
16046 then save it. If the target supports it, you can also supply the
16047 optional argument @code{-r} (``remote'') to direct the target to save
16048 the data directly into @var{filename} in its own filesystem, which may be
16049 more efficient if the trace buffer is very large. (Note, however, that
16050 @code{target tfile} can only read from files accessible to the host.)
16051 By default, this command will save trace frame in tfile format.
16052 You can supply the optional argument @code{-ctf} to save data in CTF
16053 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
16054 that can be shared by multiple debugging and tracing tools. Please go to
16055 @indicateurl{http://www.efficios.com/ctf} to get more information.
16056
16057 @kindex target tfile
16058 @kindex tfile
16059 @kindex target ctf
16060 @kindex ctf
16061 @item target tfile @var{filename}
16062 @itemx target ctf @var{dirname}
16063 Use the file named @var{filename} or directory named @var{dirname} as
16064 a source of trace data. Commands that examine data work as they do with
16065 a live target, but it is not possible to run any new trace experiments.
16066 @code{tstatus} will report the state of the trace run at the moment
16067 the data was saved, as well as the current trace frame you are examining.
16068 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
16069 the host.
16070
16071 @smallexample
16072 (@value{GDBP}) target ctf ctf.ctf
16073 (@value{GDBP}) tfind
16074 Found trace frame 0, tracepoint 2
16075 39 ++a; /* set tracepoint 1 here */
16076 (@value{GDBP}) tdump
16077 Data collected at tracepoint 2, trace frame 0:
16078 i = 0
16079 a = 0
16080 b = 1 '\001'
16081 c = @{"123", "456", "789", "123", "456", "789"@}
16082 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
16083 (@value{GDBP}) p b
16084 $1 = 1
16085 @end smallexample
16086
16087 @end table
16088
16089 @node Overlays
16090 @chapter Debugging Programs That Use Overlays
16091 @cindex overlays
16092
16093 If your program is too large to fit completely in your target system's
16094 memory, you can sometimes use @dfn{overlays} to work around this
16095 problem. @value{GDBN} provides some support for debugging programs that
16096 use overlays.
16097
16098 @menu
16099 * How Overlays Work:: A general explanation of overlays.
16100 * Overlay Commands:: Managing overlays in @value{GDBN}.
16101 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
16102 mapped by asking the inferior.
16103 * Overlay Sample Program:: A sample program using overlays.
16104 @end menu
16105
16106 @node How Overlays Work
16107 @section How Overlays Work
16108 @cindex mapped overlays
16109 @cindex unmapped overlays
16110 @cindex load address, overlay's
16111 @cindex mapped address
16112 @cindex overlay area
16113
16114 Suppose you have a computer whose instruction address space is only 64
16115 kilobytes long, but which has much more memory which can be accessed by
16116 other means: special instructions, segment registers, or memory
16117 management hardware, for example. Suppose further that you want to
16118 adapt a program which is larger than 64 kilobytes to run on this system.
16119
16120 One solution is to identify modules of your program which are relatively
16121 independent, and need not call each other directly; call these modules
16122 @dfn{overlays}. Separate the overlays from the main program, and place
16123 their machine code in the larger memory. Place your main program in
16124 instruction memory, but leave at least enough space there to hold the
16125 largest overlay as well.
16126
16127 Now, to call a function located in an overlay, you must first copy that
16128 overlay's machine code from the large memory into the space set aside
16129 for it in the instruction memory, and then jump to its entry point
16130 there.
16131
16132 @c NB: In the below the mapped area's size is greater or equal to the
16133 @c size of all overlays. This is intentional to remind the developer
16134 @c that overlays don't necessarily need to be the same size.
16135
16136 @smallexample
16137 @group
16138 Data Instruction Larger
16139 Address Space Address Space Address Space
16140 +-----------+ +-----------+ +-----------+
16141 | | | | | |
16142 +-----------+ +-----------+ +-----------+<-- overlay 1
16143 | program | | main | .----| overlay 1 | load address
16144 | variables | | program | | +-----------+
16145 | and heap | | | | | |
16146 +-----------+ | | | +-----------+<-- overlay 2
16147 | | +-----------+ | | | load address
16148 +-----------+ | | | .-| overlay 2 |
16149 | | | | | |
16150 mapped --->+-----------+ | | +-----------+
16151 address | | | | | |
16152 | overlay | <-' | | |
16153 | area | <---' +-----------+<-- overlay 3
16154 | | <---. | | load address
16155 +-----------+ `--| overlay 3 |
16156 | | | |
16157 +-----------+ | |
16158 +-----------+
16159 | |
16160 +-----------+
16161
16162 @anchor{A code overlay}A code overlay
16163 @end group
16164 @end smallexample
16165
16166 The diagram (@pxref{A code overlay}) shows a system with separate data
16167 and instruction address spaces. To map an overlay, the program copies
16168 its code from the larger address space to the instruction address space.
16169 Since the overlays shown here all use the same mapped address, only one
16170 may be mapped at a time. For a system with a single address space for
16171 data and instructions, the diagram would be similar, except that the
16172 program variables and heap would share an address space with the main
16173 program and the overlay area.
16174
16175 An overlay loaded into instruction memory and ready for use is called a
16176 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
16177 instruction memory. An overlay not present (or only partially present)
16178 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
16179 is its address in the larger memory. The mapped address is also called
16180 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
16181 called the @dfn{load memory address}, or @dfn{LMA}.
16182
16183 Unfortunately, overlays are not a completely transparent way to adapt a
16184 program to limited instruction memory. They introduce a new set of
16185 global constraints you must keep in mind as you design your program:
16186
16187 @itemize @bullet
16188
16189 @item
16190 Before calling or returning to a function in an overlay, your program
16191 must make sure that overlay is actually mapped. Otherwise, the call or
16192 return will transfer control to the right address, but in the wrong
16193 overlay, and your program will probably crash.
16194
16195 @item
16196 If the process of mapping an overlay is expensive on your system, you
16197 will need to choose your overlays carefully to minimize their effect on
16198 your program's performance.
16199
16200 @item
16201 The executable file you load onto your system must contain each
16202 overlay's instructions, appearing at the overlay's load address, not its
16203 mapped address. However, each overlay's instructions must be relocated
16204 and its symbols defined as if the overlay were at its mapped address.
16205 You can use GNU linker scripts to specify different load and relocation
16206 addresses for pieces of your program; see @ref{Overlay Description,,,
16207 ld.info, Using ld: the GNU linker}.
16208
16209 @item
16210 The procedure for loading executable files onto your system must be able
16211 to load their contents into the larger address space as well as the
16212 instruction and data spaces.
16213
16214 @end itemize
16215
16216 The overlay system described above is rather simple, and could be
16217 improved in many ways:
16218
16219 @itemize @bullet
16220
16221 @item
16222 If your system has suitable bank switch registers or memory management
16223 hardware, you could use those facilities to make an overlay's load area
16224 contents simply appear at their mapped address in instruction space.
16225 This would probably be faster than copying the overlay to its mapped
16226 area in the usual way.
16227
16228 @item
16229 If your overlays are small enough, you could set aside more than one
16230 overlay area, and have more than one overlay mapped at a time.
16231
16232 @item
16233 You can use overlays to manage data, as well as instructions. In
16234 general, data overlays are even less transparent to your design than
16235 code overlays: whereas code overlays only require care when you call or
16236 return to functions, data overlays require care every time you access
16237 the data. Also, if you change the contents of a data overlay, you
16238 must copy its contents back out to its load address before you can copy a
16239 different data overlay into the same mapped area.
16240
16241 @end itemize
16242
16243
16244 @node Overlay Commands
16245 @section Overlay Commands
16246
16247 To use @value{GDBN}'s overlay support, each overlay in your program must
16248 correspond to a separate section of the executable file. The section's
16249 virtual memory address and load memory address must be the overlay's
16250 mapped and load addresses. Identifying overlays with sections allows
16251 @value{GDBN} to determine the appropriate address of a function or
16252 variable, depending on whether the overlay is mapped or not.
16253
16254 @value{GDBN}'s overlay commands all start with the word @code{overlay};
16255 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
16256
16257 @table @code
16258 @item overlay off
16259 @kindex overlay
16260 Disable @value{GDBN}'s overlay support. When overlay support is
16261 disabled, @value{GDBN} assumes that all functions and variables are
16262 always present at their mapped addresses. By default, @value{GDBN}'s
16263 overlay support is disabled.
16264
16265 @item overlay manual
16266 @cindex manual overlay debugging
16267 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
16268 relies on you to tell it which overlays are mapped, and which are not,
16269 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
16270 commands described below.
16271
16272 @item overlay map-overlay @var{overlay}
16273 @itemx overlay map @var{overlay}
16274 @cindex map an overlay
16275 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
16276 be the name of the object file section containing the overlay. When an
16277 overlay is mapped, @value{GDBN} assumes it can find the overlay's
16278 functions and variables at their mapped addresses. @value{GDBN} assumes
16279 that any other overlays whose mapped ranges overlap that of
16280 @var{overlay} are now unmapped.
16281
16282 @item overlay unmap-overlay @var{overlay}
16283 @itemx overlay unmap @var{overlay}
16284 @cindex unmap an overlay
16285 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
16286 must be the name of the object file section containing the overlay.
16287 When an overlay is unmapped, @value{GDBN} assumes it can find the
16288 overlay's functions and variables at their load addresses.
16289
16290 @item overlay auto
16291 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
16292 consults a data structure the overlay manager maintains in the inferior
16293 to see which overlays are mapped. For details, see @ref{Automatic
16294 Overlay Debugging}.
16295
16296 @item overlay load-target
16297 @itemx overlay load
16298 @cindex reloading the overlay table
16299 Re-read the overlay table from the inferior. Normally, @value{GDBN}
16300 re-reads the table @value{GDBN} automatically each time the inferior
16301 stops, so this command should only be necessary if you have changed the
16302 overlay mapping yourself using @value{GDBN}. This command is only
16303 useful when using automatic overlay debugging.
16304
16305 @item overlay list-overlays
16306 @itemx overlay list
16307 @cindex listing mapped overlays
16308 Display a list of the overlays currently mapped, along with their mapped
16309 addresses, load addresses, and sizes.
16310
16311 @end table
16312
16313 Normally, when @value{GDBN} prints a code address, it includes the name
16314 of the function the address falls in:
16315
16316 @smallexample
16317 (@value{GDBP}) print main
16318 $3 = @{int ()@} 0x11a0 <main>
16319 @end smallexample
16320 @noindent
16321 When overlay debugging is enabled, @value{GDBN} recognizes code in
16322 unmapped overlays, and prints the names of unmapped functions with
16323 asterisks around them. For example, if @code{foo} is a function in an
16324 unmapped overlay, @value{GDBN} prints it this way:
16325
16326 @smallexample
16327 (@value{GDBP}) overlay list
16328 No sections are mapped.
16329 (@value{GDBP}) print foo
16330 $5 = @{int (int)@} 0x100000 <*foo*>
16331 @end smallexample
16332 @noindent
16333 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
16334 name normally:
16335
16336 @smallexample
16337 (@value{GDBP}) overlay list
16338 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
16339 mapped at 0x1016 - 0x104a
16340 (@value{GDBP}) print foo
16341 $6 = @{int (int)@} 0x1016 <foo>
16342 @end smallexample
16343
16344 When overlay debugging is enabled, @value{GDBN} can find the correct
16345 address for functions and variables in an overlay, whether or not the
16346 overlay is mapped. This allows most @value{GDBN} commands, like
16347 @code{break} and @code{disassemble}, to work normally, even on unmapped
16348 code. However, @value{GDBN}'s breakpoint support has some limitations:
16349
16350 @itemize @bullet
16351 @item
16352 @cindex breakpoints in overlays
16353 @cindex overlays, setting breakpoints in
16354 You can set breakpoints in functions in unmapped overlays, as long as
16355 @value{GDBN} can write to the overlay at its load address.
16356 @item
16357 @value{GDBN} can not set hardware or simulator-based breakpoints in
16358 unmapped overlays. However, if you set a breakpoint at the end of your
16359 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
16360 you are using manual overlay management), @value{GDBN} will re-set its
16361 breakpoints properly.
16362 @end itemize
16363
16364
16365 @node Automatic Overlay Debugging
16366 @section Automatic Overlay Debugging
16367 @cindex automatic overlay debugging
16368
16369 @value{GDBN} can automatically track which overlays are mapped and which
16370 are not, given some simple co-operation from the overlay manager in the
16371 inferior. If you enable automatic overlay debugging with the
16372 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
16373 looks in the inferior's memory for certain variables describing the
16374 current state of the overlays.
16375
16376 Here are the variables your overlay manager must define to support
16377 @value{GDBN}'s automatic overlay debugging:
16378
16379 @table @asis
16380
16381 @item @code{_ovly_table}:
16382 This variable must be an array of the following structures:
16383
16384 @smallexample
16385 struct
16386 @{
16387 /* The overlay's mapped address. */
16388 unsigned long vma;
16389
16390 /* The size of the overlay, in bytes. */
16391 unsigned long size;
16392
16393 /* The overlay's load address. */
16394 unsigned long lma;
16395
16396 /* Non-zero if the overlay is currently mapped;
16397 zero otherwise. */
16398 unsigned long mapped;
16399 @}
16400 @end smallexample
16401
16402 @item @code{_novlys}:
16403 This variable must be a four-byte signed integer, holding the total
16404 number of elements in @code{_ovly_table}.
16405
16406 @end table
16407
16408 To decide whether a particular overlay is mapped or not, @value{GDBN}
16409 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
16410 @code{lma} members equal the VMA and LMA of the overlay's section in the
16411 executable file. When @value{GDBN} finds a matching entry, it consults
16412 the entry's @code{mapped} member to determine whether the overlay is
16413 currently mapped.
16414
16415 In addition, your overlay manager may define a function called
16416 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
16417 will silently set a breakpoint there. If the overlay manager then
16418 calls this function whenever it has changed the overlay table, this
16419 will enable @value{GDBN} to accurately keep track of which overlays
16420 are in program memory, and update any breakpoints that may be set
16421 in overlays. This will allow breakpoints to work even if the
16422 overlays are kept in ROM or other non-writable memory while they
16423 are not being executed.
16424
16425 @node Overlay Sample Program
16426 @section Overlay Sample Program
16427 @cindex overlay example program
16428
16429 When linking a program which uses overlays, you must place the overlays
16430 at their load addresses, while relocating them to run at their mapped
16431 addresses. To do this, you must write a linker script (@pxref{Overlay
16432 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
16433 since linker scripts are specific to a particular host system, target
16434 architecture, and target memory layout, this manual cannot provide
16435 portable sample code demonstrating @value{GDBN}'s overlay support.
16436
16437 However, the @value{GDBN} source distribution does contain an overlaid
16438 program, with linker scripts for a few systems, as part of its test
16439 suite. The program consists of the following files from
16440 @file{gdb/testsuite/gdb.base}:
16441
16442 @table @file
16443 @item overlays.c
16444 The main program file.
16445 @item ovlymgr.c
16446 A simple overlay manager, used by @file{overlays.c}.
16447 @item foo.c
16448 @itemx bar.c
16449 @itemx baz.c
16450 @itemx grbx.c
16451 Overlay modules, loaded and used by @file{overlays.c}.
16452 @item d10v.ld
16453 @itemx m32r.ld
16454 Linker scripts for linking the test program on the @code{d10v-elf}
16455 and @code{m32r-elf} targets.
16456 @end table
16457
16458 You can build the test program using the @code{d10v-elf} GCC
16459 cross-compiler like this:
16460
16461 @smallexample
16462 $ d10v-elf-gcc -g -c overlays.c
16463 $ d10v-elf-gcc -g -c ovlymgr.c
16464 $ d10v-elf-gcc -g -c foo.c
16465 $ d10v-elf-gcc -g -c bar.c
16466 $ d10v-elf-gcc -g -c baz.c
16467 $ d10v-elf-gcc -g -c grbx.c
16468 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
16469 baz.o grbx.o -Wl,-Td10v.ld -o overlays
16470 @end smallexample
16471
16472 The build process is identical for any other architecture, except that
16473 you must substitute the appropriate compiler and linker script for the
16474 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
16475
16476
16477 @node Languages
16478 @chapter Using @value{GDBN} with Different Languages
16479 @cindex languages
16480
16481 Although programming languages generally have common aspects, they are
16482 rarely expressed in the same manner. For instance, in ANSI C,
16483 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
16484 Modula-2, it is accomplished by @code{p^}. Values can also be
16485 represented (and displayed) differently. Hex numbers in C appear as
16486 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
16487
16488 @cindex working language
16489 Language-specific information is built into @value{GDBN} for some languages,
16490 allowing you to express operations like the above in your program's
16491 native language, and allowing @value{GDBN} to output values in a manner
16492 consistent with the syntax of your program's native language. The
16493 language you use to build expressions is called the @dfn{working
16494 language}.
16495
16496 @menu
16497 * Setting:: Switching between source languages
16498 * Show:: Displaying the language
16499 * Checks:: Type and range checks
16500 * Supported Languages:: Supported languages
16501 * Unsupported Languages:: Unsupported languages
16502 @end menu
16503
16504 @node Setting
16505 @section Switching Between Source Languages
16506
16507 There are two ways to control the working language---either have @value{GDBN}
16508 set it automatically, or select it manually yourself. You can use the
16509 @code{set language} command for either purpose. On startup, @value{GDBN}
16510 defaults to setting the language automatically. The working language is
16511 used to determine how expressions you type are interpreted, how values
16512 are printed, etc.
16513
16514 In addition to the working language, every source file that
16515 @value{GDBN} knows about has its own working language. For some object
16516 file formats, the compiler might indicate which language a particular
16517 source file is in. However, most of the time @value{GDBN} infers the
16518 language from the name of the file. The language of a source file
16519 controls whether C@t{++} names are demangled---this way @code{backtrace} can
16520 show each frame appropriately for its own language. There is no way to
16521 set the language of a source file from within @value{GDBN}, but you can
16522 set the language associated with a filename extension. @xref{Show, ,
16523 Displaying the Language}.
16524
16525 This is most commonly a problem when you use a program, such
16526 as @code{cfront} or @code{f2c}, that generates C but is written in
16527 another language. In that case, make the
16528 program use @code{#line} directives in its C output; that way
16529 @value{GDBN} will know the correct language of the source code of the original
16530 program, and will display that source code, not the generated C code.
16531
16532 @menu
16533 * Filenames:: Filename extensions and languages.
16534 * Manually:: Setting the working language manually
16535 * Automatically:: Having @value{GDBN} infer the source language
16536 @end menu
16537
16538 @node Filenames
16539 @subsection List of Filename Extensions and Languages
16540
16541 If a source file name ends in one of the following extensions, then
16542 @value{GDBN} infers that its language is the one indicated.
16543
16544 @table @file
16545 @item .ada
16546 @itemx .ads
16547 @itemx .adb
16548 @itemx .a
16549 Ada source file.
16550
16551 @item .c
16552 C source file
16553
16554 @item .C
16555 @itemx .cc
16556 @itemx .cp
16557 @itemx .cpp
16558 @itemx .cxx
16559 @itemx .c++
16560 C@t{++} source file
16561
16562 @item .d
16563 D source file
16564
16565 @item .m
16566 Objective-C source file
16567
16568 @item .f
16569 @itemx .F
16570 Fortran source file
16571
16572 @item .mod
16573 Modula-2 source file
16574
16575 @item .s
16576 @itemx .S
16577 Assembler source file. This actually behaves almost like C, but
16578 @value{GDBN} does not skip over function prologues when stepping.
16579 @end table
16580
16581 In addition, you may set the language associated with a filename
16582 extension. @xref{Show, , Displaying the Language}.
16583
16584 @node Manually
16585 @subsection Setting the Working Language
16586
16587 If you allow @value{GDBN} to set the language automatically,
16588 expressions are interpreted the same way in your debugging session and
16589 your program.
16590
16591 @kindex set language
16592 If you wish, you may set the language manually. To do this, issue the
16593 command @samp{set language @var{lang}}, where @var{lang} is the name of
16594 a language, such as
16595 @code{c} or @code{modula-2}.
16596 For a list of the supported languages, type @samp{set language}.
16597
16598 Setting the language manually prevents @value{GDBN} from updating the working
16599 language automatically. This can lead to confusion if you try
16600 to debug a program when the working language is not the same as the
16601 source language, when an expression is acceptable to both
16602 languages---but means different things. For instance, if the current
16603 source file were written in C, and @value{GDBN} was parsing Modula-2, a
16604 command such as:
16605
16606 @smallexample
16607 print a = b + c
16608 @end smallexample
16609
16610 @noindent
16611 might not have the effect you intended. In C, this means to add
16612 @code{b} and @code{c} and place the result in @code{a}. The result
16613 printed would be the value of @code{a}. In Modula-2, this means to compare
16614 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
16615
16616 @node Automatically
16617 @subsection Having @value{GDBN} Infer the Source Language
16618
16619 To have @value{GDBN} set the working language automatically, use
16620 @samp{set language local} or @samp{set language auto}. @value{GDBN}
16621 then infers the working language. That is, when your program stops in a
16622 frame (usually by encountering a breakpoint), @value{GDBN} sets the
16623 working language to the language recorded for the function in that
16624 frame. If the language for a frame is unknown (that is, if the function
16625 or block corresponding to the frame was defined in a source file that
16626 does not have a recognized extension), the current working language is
16627 not changed, and @value{GDBN} issues a warning.
16628
16629 This may not seem necessary for most programs, which are written
16630 entirely in one source language. However, program modules and libraries
16631 written in one source language can be used by a main program written in
16632 a different source language. Using @samp{set language auto} in this
16633 case frees you from having to set the working language manually.
16634
16635 @node Show
16636 @section Displaying the Language
16637
16638 The following commands help you find out which language is the
16639 working language, and also what language source files were written in.
16640
16641 @table @code
16642 @item show language
16643 @anchor{show language}
16644 @kindex show language
16645 Display the current working language. This is the
16646 language you can use with commands such as @code{print} to
16647 build and compute expressions that may involve variables in your program.
16648
16649 @item info frame
16650 @kindex info frame@r{, show the source language}
16651 Display the source language for this frame. This language becomes the
16652 working language if you use an identifier from this frame.
16653 @xref{Frame Info, ,Information about a Frame}, to identify the other
16654 information listed here.
16655
16656 @item info source
16657 @kindex info source@r{, show the source language}
16658 Display the source language of this source file.
16659 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16660 information listed here.
16661 @end table
16662
16663 In unusual circumstances, you may have source files with extensions
16664 not in the standard list. You can then set the extension associated
16665 with a language explicitly:
16666
16667 @table @code
16668 @item set extension-language @var{ext} @var{language}
16669 @kindex set extension-language
16670 Tell @value{GDBN} that source files with extension @var{ext} are to be
16671 assumed as written in the source language @var{language}.
16672
16673 @item info extensions
16674 @kindex info extensions
16675 List all the filename extensions and the associated languages.
16676 @end table
16677
16678 @node Checks
16679 @section Type and Range Checking
16680
16681 Some languages are designed to guard you against making seemingly common
16682 errors through a series of compile- and run-time checks. These include
16683 checking the type of arguments to functions and operators and making
16684 sure mathematical overflows are caught at run time. Checks such as
16685 these help to ensure a program's correctness once it has been compiled
16686 by eliminating type mismatches and providing active checks for range
16687 errors when your program is running.
16688
16689 By default @value{GDBN} checks for these errors according to the
16690 rules of the current source language. Although @value{GDBN} does not check
16691 the statements in your program, it can check expressions entered directly
16692 into @value{GDBN} for evaluation via the @code{print} command, for example.
16693
16694 @menu
16695 * Type Checking:: An overview of type checking
16696 * Range Checking:: An overview of range checking
16697 @end menu
16698
16699 @cindex type checking
16700 @cindex checks, type
16701 @node Type Checking
16702 @subsection An Overview of Type Checking
16703
16704 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16705 arguments to operators and functions have to be of the correct type,
16706 otherwise an error occurs. These checks prevent type mismatch
16707 errors from ever causing any run-time problems. For example,
16708
16709 @smallexample
16710 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16711
16712 (@value{GDBP}) print obj.my_method (0)
16713 $1 = 2
16714 @exdent but
16715 (@value{GDBP}) print obj.my_method (0x1234)
16716 Cannot resolve method klass::my_method to any overloaded instance
16717 @end smallexample
16718
16719 The second example fails because in C@t{++} the integer constant
16720 @samp{0x1234} is not type-compatible with the pointer parameter type.
16721
16722 For the expressions you use in @value{GDBN} commands, you can tell
16723 @value{GDBN} to not enforce strict type checking or
16724 to treat any mismatches as errors and abandon the expression;
16725 When type checking is disabled, @value{GDBN} successfully evaluates
16726 expressions like the second example above.
16727
16728 Even if type checking is off, there may be other reasons
16729 related to type that prevent @value{GDBN} from evaluating an expression.
16730 For instance, @value{GDBN} does not know how to add an @code{int} and
16731 a @code{struct foo}. These particular type errors have nothing to do
16732 with the language in use and usually arise from expressions which make
16733 little sense to evaluate anyway.
16734
16735 @value{GDBN} provides some additional commands for controlling type checking:
16736
16737 @kindex set check type
16738 @kindex show check type
16739 @table @code
16740 @item set check type on
16741 @itemx set check type off
16742 Set strict type checking on or off. If any type mismatches occur in
16743 evaluating an expression while type checking is on, @value{GDBN} prints a
16744 message and aborts evaluation of the expression.
16745
16746 @item show check type
16747 Show the current setting of type checking and whether @value{GDBN}
16748 is enforcing strict type checking rules.
16749 @end table
16750
16751 @cindex range checking
16752 @cindex checks, range
16753 @node Range Checking
16754 @subsection An Overview of Range Checking
16755
16756 In some languages (such as Modula-2), it is an error to exceed the
16757 bounds of a type; this is enforced with run-time checks. Such range
16758 checking is meant to ensure program correctness by making sure
16759 computations do not overflow, or indices on an array element access do
16760 not exceed the bounds of the array.
16761
16762 For expressions you use in @value{GDBN} commands, you can tell
16763 @value{GDBN} to treat range errors in one of three ways: ignore them,
16764 always treat them as errors and abandon the expression, or issue
16765 warnings but evaluate the expression anyway.
16766
16767 A range error can result from numerical overflow, from exceeding an
16768 array index bound, or when you type a constant that is not a member
16769 of any type. Some languages, however, do not treat overflows as an
16770 error. In many implementations of C, mathematical overflow causes the
16771 result to ``wrap around'' to lower values---for example, if @var{m} is
16772 the largest integer value, and @var{s} is the smallest, then
16773
16774 @smallexample
16775 @var{m} + 1 @result{} @var{s}
16776 @end smallexample
16777
16778 This, too, is specific to individual languages, and in some cases
16779 specific to individual compilers or machines. @xref{Supported Languages, ,
16780 Supported Languages}, for further details on specific languages.
16781
16782 @value{GDBN} provides some additional commands for controlling the range checker:
16783
16784 @kindex set check range
16785 @kindex show check range
16786 @table @code
16787 @item set check range auto
16788 Set range checking on or off based on the current working language.
16789 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16790 each language.
16791
16792 @item set check range on
16793 @itemx set check range off
16794 Set range checking on or off, overriding the default setting for the
16795 current working language. A warning is issued if the setting does not
16796 match the language default. If a range error occurs and range checking is on,
16797 then a message is printed and evaluation of the expression is aborted.
16798
16799 @item set check range warn
16800 Output messages when the @value{GDBN} range checker detects a range error,
16801 but attempt to evaluate the expression anyway. Evaluating the
16802 expression may still be impossible for other reasons, such as accessing
16803 memory that the process does not own (a typical example from many Unix
16804 systems).
16805
16806 @item show check range
16807 Show the current setting of the range checker, and whether or not it is
16808 being set automatically by @value{GDBN}.
16809 @end table
16810
16811 @node Supported Languages
16812 @section Supported Languages
16813
16814 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16815 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16816 @c This is false ...
16817 Some @value{GDBN} features may be used in expressions regardless of the
16818 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16819 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16820 ,Expressions}) can be used with the constructs of any supported
16821 language.
16822
16823 The following sections detail to what degree each source language is
16824 supported by @value{GDBN}. These sections are not meant to be language
16825 tutorials or references, but serve only as a reference guide to what the
16826 @value{GDBN} expression parser accepts, and what input and output
16827 formats should look like for different languages. There are many good
16828 books written on each of these languages; please look to these for a
16829 language reference or tutorial.
16830
16831 @menu
16832 * C:: C and C@t{++}
16833 * D:: D
16834 * Go:: Go
16835 * Objective-C:: Objective-C
16836 * OpenCL C:: OpenCL C
16837 * Fortran:: Fortran
16838 * Pascal:: Pascal
16839 * Rust:: Rust
16840 * Modula-2:: Modula-2
16841 * Ada:: Ada
16842 @end menu
16843
16844 @node C
16845 @subsection C and C@t{++}
16846
16847 @cindex C and C@t{++}
16848 @cindex expressions in C or C@t{++}
16849
16850 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16851 to both languages. Whenever this is the case, we discuss those languages
16852 together.
16853
16854 @cindex C@t{++}
16855 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16856 @cindex @sc{gnu} C@t{++}
16857 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16858 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16859 effectively, you must compile your C@t{++} programs with a supported
16860 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16861 compiler (@code{aCC}).
16862
16863 @menu
16864 * C Operators:: C and C@t{++} operators
16865 * C Constants:: C and C@t{++} constants
16866 * C Plus Plus Expressions:: C@t{++} expressions
16867 * C Defaults:: Default settings for C and C@t{++}
16868 * C Checks:: C and C@t{++} type and range checks
16869 * Debugging C:: @value{GDBN} and C
16870 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16871 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16872 @end menu
16873
16874 @node C Operators
16875 @subsubsection C and C@t{++} Operators
16876
16877 @cindex C and C@t{++} operators
16878
16879 Operators must be defined on values of specific types. For instance,
16880 @code{+} is defined on numbers, but not on structures. Operators are
16881 often defined on groups of types.
16882
16883 For the purposes of C and C@t{++}, the following definitions hold:
16884
16885 @itemize @bullet
16886
16887 @item
16888 @emph{Integral types} include @code{int} with any of its storage-class
16889 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16890
16891 @item
16892 @emph{Floating-point types} include @code{float}, @code{double}, and
16893 @code{long double} (if supported by the target platform).
16894
16895 @item
16896 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16897
16898 @item
16899 @emph{Scalar types} include all of the above.
16900
16901 @end itemize
16902
16903 @noindent
16904 The following operators are supported. They are listed here
16905 in order of increasing precedence:
16906
16907 @table @code
16908 @item ,
16909 The comma or sequencing operator. Expressions in a comma-separated list
16910 are evaluated from left to right, with the result of the entire
16911 expression being the last expression evaluated.
16912
16913 @item =
16914 Assignment. The value of an assignment expression is the value
16915 assigned. Defined on scalar types.
16916
16917 @item @var{op}=
16918 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16919 and translated to @w{@code{@var{a} = @var{a op b}}}.
16920 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16921 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16922 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16923
16924 @item ?:
16925 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16926 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16927 should be of an integral type.
16928
16929 @item ||
16930 Logical @sc{or}. Defined on integral types.
16931
16932 @item &&
16933 Logical @sc{and}. Defined on integral types.
16934
16935 @item |
16936 Bitwise @sc{or}. Defined on integral types.
16937
16938 @item ^
16939 Bitwise exclusive-@sc{or}. Defined on integral types.
16940
16941 @item &
16942 Bitwise @sc{and}. Defined on integral types.
16943
16944 @item ==@r{, }!=
16945 Equality and inequality. Defined on scalar types. The value of these
16946 expressions is 0 for false and non-zero for true.
16947
16948 @item <@r{, }>@r{, }<=@r{, }>=
16949 Less than, greater than, less than or equal, greater than or equal.
16950 Defined on scalar types. The value of these expressions is 0 for false
16951 and non-zero for true.
16952
16953 @item <<@r{, }>>
16954 left shift, and right shift. Defined on integral types.
16955
16956 @item @@
16957 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16958
16959 @item +@r{, }-
16960 Addition and subtraction. Defined on integral types, floating-point types and
16961 pointer types.
16962
16963 @item *@r{, }/@r{, }%
16964 Multiplication, division, and modulus. Multiplication and division are
16965 defined on integral and floating-point types. Modulus is defined on
16966 integral types.
16967
16968 @item ++@r{, }--
16969 Increment and decrement. When appearing before a variable, the
16970 operation is performed before the variable is used in an expression;
16971 when appearing after it, the variable's value is used before the
16972 operation takes place.
16973
16974 @item *
16975 Pointer dereferencing. Defined on pointer types. Same precedence as
16976 @code{++}.
16977
16978 @item &
16979 Address operator. Defined on variables. Same precedence as @code{++}.
16980
16981 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16982 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16983 to examine the address
16984 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16985 stored.
16986
16987 @item -
16988 Negative. Defined on integral and floating-point types. Same
16989 precedence as @code{++}.
16990
16991 @item !
16992 Logical negation. Defined on integral types. Same precedence as
16993 @code{++}.
16994
16995 @item ~
16996 Bitwise complement operator. Defined on integral types. Same precedence as
16997 @code{++}.
16998
16999
17000 @item .@r{, }->
17001 Structure member, and pointer-to-structure member. For convenience,
17002 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
17003 pointer based on the stored type information.
17004 Defined on @code{struct} and @code{union} data.
17005
17006 @item .*@r{, }->*
17007 Dereferences of pointers to members.
17008
17009 @item []
17010 Array indexing. @code{@var{a}[@var{i}]} is defined as
17011 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
17012
17013 @item ()
17014 Function parameter list. Same precedence as @code{->}.
17015
17016 @item ::
17017 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
17018 and @code{class} types.
17019
17020 @item ::
17021 Doubled colons also represent the @value{GDBN} scope operator
17022 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
17023 above.
17024 @end table
17025
17026 If an operator is redefined in the user code, @value{GDBN} usually
17027 attempts to invoke the redefined version instead of using the operator's
17028 predefined meaning.
17029
17030 @node C Constants
17031 @subsubsection C and C@t{++} Constants
17032
17033 @cindex C and C@t{++} constants
17034
17035 @value{GDBN} allows you to express the constants of C and C@t{++} in the
17036 following ways:
17037
17038 @itemize @bullet
17039 @item
17040 Integer constants are a sequence of digits. Octal constants are
17041 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
17042 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
17043 @samp{l}, specifying that the constant should be treated as a
17044 @code{long} value.
17045
17046 @item
17047 Floating point constants are a sequence of digits, followed by a decimal
17048 point, followed by a sequence of digits, and optionally followed by an
17049 exponent. An exponent is of the form:
17050 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
17051 sequence of digits. The @samp{+} is optional for positive exponents.
17052 A floating-point constant may also end with a letter @samp{f} or
17053 @samp{F}, specifying that the constant should be treated as being of
17054 the @code{float} (as opposed to the default @code{double}) type; or with
17055 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
17056 constant.
17057
17058 @item
17059 Enumerated constants consist of enumerated identifiers, or their
17060 integral equivalents.
17061
17062 @item
17063 Character constants are a single character surrounded by single quotes
17064 (@code{'}), or a number---the ordinal value of the corresponding character
17065 (usually its @sc{ascii} value). Within quotes, the single character may
17066 be represented by a letter or by @dfn{escape sequences}, which are of
17067 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
17068 of the character's ordinal value; or of the form @samp{\@var{x}}, where
17069 @samp{@var{x}} is a predefined special character---for example,
17070 @samp{\n} for newline.
17071
17072 Wide character constants can be written by prefixing a character
17073 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
17074 form of @samp{x}. The target wide character set is used when
17075 computing the value of this constant (@pxref{Character Sets}).
17076
17077 @item
17078 String constants are a sequence of character constants surrounded by
17079 double quotes (@code{"}). Any valid character constant (as described
17080 above) may appear. Double quotes within the string must be preceded by
17081 a backslash, so for instance @samp{"a\"b'c"} is a string of five
17082 characters.
17083
17084 Wide string constants can be written by prefixing a string constant
17085 with @samp{L}, as in C. The target wide character set is used when
17086 computing the value of this constant (@pxref{Character Sets}).
17087
17088 @item
17089 Pointer constants are an integral value. You can also write pointers
17090 to constants using the C operator @samp{&}.
17091
17092 @item
17093 Array constants are comma-separated lists surrounded by braces @samp{@{}
17094 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
17095 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
17096 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
17097 @end itemize
17098
17099 @node C Plus Plus Expressions
17100 @subsubsection C@t{++} Expressions
17101
17102 @cindex expressions in C@t{++}
17103 @value{GDBN} expression handling can interpret most C@t{++} expressions.
17104
17105 @cindex debugging C@t{++} programs
17106 @cindex C@t{++} compilers
17107 @cindex debug formats and C@t{++}
17108 @cindex @value{NGCC} and C@t{++}
17109 @quotation
17110 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
17111 the proper compiler and the proper debug format. Currently,
17112 @value{GDBN} works best when debugging C@t{++} code that is compiled
17113 with the most recent version of @value{NGCC} possible. The DWARF
17114 debugging format is preferred; @value{NGCC} defaults to this on most
17115 popular platforms. Other compilers and/or debug formats are likely to
17116 work badly or not at all when using @value{GDBN} to debug C@t{++}
17117 code. @xref{Compilation}.
17118 @end quotation
17119
17120 @enumerate
17121
17122 @cindex member functions
17123 @item
17124 Member function calls are allowed; you can use expressions like
17125
17126 @smallexample
17127 count = aml->GetOriginal(x, y)
17128 @end smallexample
17129
17130 @vindex this@r{, inside C@t{++} member functions}
17131 @cindex namespace in C@t{++}
17132 @item
17133 While a member function is active (in the selected stack frame), your
17134 expressions have the same namespace available as the member function;
17135 that is, @value{GDBN} allows implicit references to the class instance
17136 pointer @code{this} following the same rules as C@t{++}. @code{using}
17137 declarations in the current scope are also respected by @value{GDBN}.
17138
17139 @cindex call overloaded functions
17140 @cindex overloaded functions, calling
17141 @cindex type conversions in C@t{++}
17142 @item
17143 You can call overloaded functions; @value{GDBN} resolves the function
17144 call to the right definition, with some restrictions. @value{GDBN} does not
17145 perform overload resolution involving user-defined type conversions,
17146 calls to constructors, or instantiations of templates that do not exist
17147 in the program. It also cannot handle ellipsis argument lists or
17148 default arguments.
17149
17150 It does perform integral conversions and promotions, floating-point
17151 promotions, arithmetic conversions, pointer conversions, conversions of
17152 class objects to base classes, and standard conversions such as those of
17153 functions or arrays to pointers; it requires an exact match on the
17154 number of function arguments.
17155
17156 Overload resolution is always performed, unless you have specified
17157 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
17158 ,@value{GDBN} Features for C@t{++}}.
17159
17160 You must specify @code{set overload-resolution off} in order to use an
17161 explicit function signature to call an overloaded function, as in
17162 @smallexample
17163 p 'foo(char,int)'('x', 13)
17164 @end smallexample
17165
17166 The @value{GDBN} command-completion facility can simplify this;
17167 see @ref{Completion, ,Command Completion}.
17168
17169 @cindex reference declarations
17170 @item
17171 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
17172 references; you can use them in expressions just as you do in C@t{++}
17173 source---they are automatically dereferenced.
17174
17175 In the parameter list shown when @value{GDBN} displays a frame, the values of
17176 reference variables are not displayed (unlike other variables); this
17177 avoids clutter, since references are often used for large structures.
17178 The @emph{address} of a reference variable is always shown, unless
17179 you have specified @samp{set print address off}.
17180
17181 @item
17182 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
17183 expressions can use it just as expressions in your program do. Since
17184 one scope may be defined in another, you can use @code{::} repeatedly if
17185 necessary, for example in an expression like
17186 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
17187 resolving name scope by reference to source files, in both C and C@t{++}
17188 debugging (@pxref{Variables, ,Program Variables}).
17189
17190 @item
17191 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
17192 specification.
17193 @end enumerate
17194
17195 @node C Defaults
17196 @subsubsection C and C@t{++} Defaults
17197
17198 @cindex C and C@t{++} defaults
17199
17200 If you allow @value{GDBN} to set range checking automatically, it
17201 defaults to @code{off} whenever the working language changes to
17202 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
17203 selects the working language.
17204
17205 If you allow @value{GDBN} to set the language automatically, it
17206 recognizes source files whose names end with @file{.c}, @file{.C}, or
17207 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
17208 these files, it sets the working language to C or C@t{++}.
17209 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
17210 for further details.
17211
17212 @node C Checks
17213 @subsubsection C and C@t{++} Type and Range Checks
17214
17215 @cindex C and C@t{++} checks
17216
17217 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
17218 checking is used. However, if you turn type checking off, @value{GDBN}
17219 will allow certain non-standard conversions, such as promoting integer
17220 constants to pointers.
17221
17222 Range checking, if turned on, is done on mathematical operations. Array
17223 indices are not checked, since they are often used to index a pointer
17224 that is not itself an array.
17225
17226 @node Debugging C
17227 @subsubsection @value{GDBN} and C
17228
17229 The @code{set print union} and @code{show print union} commands apply to
17230 the @code{union} type. When set to @samp{on}, any @code{union} that is
17231 inside a @code{struct} or @code{class} is also printed. Otherwise, it
17232 appears as @samp{@{...@}}.
17233
17234 The @code{@@} operator aids in the debugging of dynamic arrays, formed
17235 with pointers and a memory allocation function. @xref{Expressions,
17236 ,Expressions}.
17237
17238 @node Debugging C Plus Plus
17239 @subsubsection @value{GDBN} Features for C@t{++}
17240
17241 @cindex commands for C@t{++}
17242
17243 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
17244 designed specifically for use with C@t{++}. Here is a summary:
17245
17246 @table @code
17247 @cindex break in overloaded functions
17248 @item @r{breakpoint menus}
17249 When you want a breakpoint in a function whose name is overloaded,
17250 @value{GDBN} has the capability to display a menu of possible breakpoint
17251 locations to help you specify which function definition you want.
17252 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
17253
17254 @cindex overloading in C@t{++}
17255 @item rbreak @var{regex}
17256 Setting breakpoints using regular expressions is helpful for setting
17257 breakpoints on overloaded functions that are not members of any special
17258 classes.
17259 @xref{Set Breaks, ,Setting Breakpoints}.
17260
17261 @cindex C@t{++} exception handling
17262 @item catch throw
17263 @itemx catch rethrow
17264 @itemx catch catch
17265 Debug C@t{++} exception handling using these commands. @xref{Set
17266 Catchpoints, , Setting Catchpoints}.
17267
17268 @cindex inheritance
17269 @item ptype @var{typename}
17270 Print inheritance relationships as well as other information for type
17271 @var{typename}.
17272 @xref{Symbols, ,Examining the Symbol Table}.
17273
17274 @item info vtbl @var{expression}.
17275 The @code{info vtbl} command can be used to display the virtual
17276 method tables of the object computed by @var{expression}. This shows
17277 one entry per virtual table; there may be multiple virtual tables when
17278 multiple inheritance is in use.
17279
17280 @cindex C@t{++} demangling
17281 @item demangle @var{name}
17282 Demangle @var{name}.
17283 @xref{Symbols}, for a more complete description of the @code{demangle} command.
17284
17285 @cindex C@t{++} symbol display
17286 @item set print demangle
17287 @itemx show print demangle
17288 @itemx set print asm-demangle
17289 @itemx show print asm-demangle
17290 Control whether C@t{++} symbols display in their source form, both when
17291 displaying code as C@t{++} source and when displaying disassemblies.
17292 @xref{Print Settings, ,Print Settings}.
17293
17294 @item set print object
17295 @itemx show print object
17296 Choose whether to print derived (actual) or declared types of objects.
17297 @xref{Print Settings, ,Print Settings}.
17298
17299 @item set print vtbl
17300 @itemx show print vtbl
17301 Control the format for printing virtual function tables.
17302 @xref{Print Settings, ,Print Settings}.
17303 (The @code{vtbl} commands do not work on programs compiled with the HP
17304 ANSI C@t{++} compiler (@code{aCC}).)
17305
17306 @kindex set overload-resolution
17307 @cindex overloaded functions, overload resolution
17308 @item set overload-resolution on
17309 Enable overload resolution for C@t{++} expression evaluation. The default
17310 is on. For overloaded functions, @value{GDBN} evaluates the arguments
17311 and searches for a function whose signature matches the argument types,
17312 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
17313 Expressions, ,C@t{++} Expressions}, for details).
17314 If it cannot find a match, it emits a message.
17315
17316 @item set overload-resolution off
17317 Disable overload resolution for C@t{++} expression evaluation. For
17318 overloaded functions that are not class member functions, @value{GDBN}
17319 chooses the first function of the specified name that it finds in the
17320 symbol table, whether or not its arguments are of the correct type. For
17321 overloaded functions that are class member functions, @value{GDBN}
17322 searches for a function whose signature @emph{exactly} matches the
17323 argument types.
17324
17325 @kindex show overload-resolution
17326 @item show overload-resolution
17327 Show the current setting of overload resolution.
17328
17329 @item @r{Overloaded symbol names}
17330 You can specify a particular definition of an overloaded symbol, using
17331 the same notation that is used to declare such symbols in C@t{++}: type
17332 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
17333 also use the @value{GDBN} command-line word completion facilities to list the
17334 available choices, or to finish the type list for you.
17335 @xref{Completion,, Command Completion}, for details on how to do this.
17336
17337 @item @r{Breakpoints in template functions}
17338
17339 Similar to how overloaded symbols are handled, @value{GDBN} will ignore
17340 template parameter lists when it encounters a symbol which includes a
17341 C@t{++} template. This permits setting breakpoints on families of template functions
17342 or functions whose parameters include template types.
17343
17344 The @kbd{-qualified} flag may be used to override this behavior, causing
17345 @value{GDBN} to search for a specific function or type.
17346
17347 The @value{GDBN} command-line word completion facility also understands
17348 template parameters and may be used to list available choices or finish
17349 template parameter lists for you. @xref{Completion,, Command Completion}, for
17350 details on how to do this.
17351
17352 @item @r{Breakpoints in functions with ABI tags}
17353
17354 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
17355 correspond to changes in the ABI of a type, function, or variable that
17356 would not otherwise be reflected in a mangled name. See
17357 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
17358 for more detail.
17359
17360 The ABI tags are visible in C@t{++} demangled names. For example, a
17361 function that returns a std::string:
17362
17363 @smallexample
17364 std::string function(int);
17365 @end smallexample
17366
17367 @noindent
17368 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
17369 tag, and @value{GDBN} displays the symbol like this:
17370
17371 @smallexample
17372 function[abi:cxx11](int)
17373 @end smallexample
17374
17375 You can set a breakpoint on such functions simply as if they had no
17376 tag. For example:
17377
17378 @smallexample
17379 (@value{GDBP}) b function(int)
17380 Breakpoint 2 at 0x40060d: file main.cc, line 10.
17381 (@value{GDBP}) info breakpoints
17382 Num Type Disp Enb Address What
17383 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
17384 at main.cc:10
17385 @end smallexample
17386
17387 On the rare occasion you need to disambiguate between different ABI
17388 tags, you can do so by simply including the ABI tag in the function
17389 name, like:
17390
17391 @smallexample
17392 (@value{GDBP}) b ambiguous[abi:other_tag](int)
17393 @end smallexample
17394 @end table
17395
17396 @node Decimal Floating Point
17397 @subsubsection Decimal Floating Point format
17398 @cindex decimal floating point format
17399
17400 @value{GDBN} can examine, set and perform computations with numbers in
17401 decimal floating point format, which in the C language correspond to the
17402 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
17403 specified by the extension to support decimal floating-point arithmetic.
17404
17405 There are two encodings in use, depending on the architecture: BID (Binary
17406 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
17407 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
17408 configured target.
17409
17410 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
17411 to manipulate decimal floating point numbers, it is not possible to convert
17412 (using a cast, for example) integers wider than 32-bit to decimal float.
17413
17414 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
17415 point computations, error checking in decimal float operations ignores
17416 underflow, overflow and divide by zero exceptions.
17417
17418 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
17419 to inspect @code{_Decimal128} values stored in floating point registers.
17420 See @ref{PowerPC,,PowerPC} for more details.
17421
17422 @node D
17423 @subsection D
17424
17425 @cindex D
17426 @value{GDBN} can be used to debug programs written in D and compiled with
17427 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
17428 specific feature --- dynamic arrays.
17429
17430 @node Go
17431 @subsection Go
17432
17433 @cindex Go (programming language)
17434 @value{GDBN} can be used to debug programs written in Go and compiled with
17435 @file{gccgo} or @file{6g} compilers.
17436
17437 Here is a summary of the Go-specific features and restrictions:
17438
17439 @table @code
17440 @cindex current Go package
17441 @item The current Go package
17442 The name of the current package does not need to be specified when
17443 specifying global variables and functions.
17444
17445 For example, given the program:
17446
17447 @example
17448 package main
17449 var myglob = "Shall we?"
17450 func main () @{
17451 // ...
17452 @}
17453 @end example
17454
17455 When stopped inside @code{main} either of these work:
17456
17457 @example
17458 (@value{GDBP}) p myglob
17459 (@value{GDBP}) p main.myglob
17460 @end example
17461
17462 @cindex builtin Go types
17463 @item Builtin Go types
17464 The @code{string} type is recognized by @value{GDBN} and is printed
17465 as a string.
17466
17467 @cindex builtin Go functions
17468 @item Builtin Go functions
17469 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
17470 function and handles it internally.
17471
17472 @cindex restrictions on Go expressions
17473 @item Restrictions on Go expressions
17474 All Go operators are supported except @code{&^}.
17475 The Go @code{_} ``blank identifier'' is not supported.
17476 Automatic dereferencing of pointers is not supported.
17477 @end table
17478
17479 @node Objective-C
17480 @subsection Objective-C
17481
17482 @cindex Objective-C
17483 This section provides information about some commands and command
17484 options that are useful for debugging Objective-C code. See also
17485 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
17486 few more commands specific to Objective-C support.
17487
17488 @menu
17489 * Method Names in Commands::
17490 * The Print Command with Objective-C::
17491 @end menu
17492
17493 @node Method Names in Commands
17494 @subsubsection Method Names in Commands
17495
17496 The following commands have been extended to accept Objective-C method
17497 names as line specifications:
17498
17499 @kindex clear@r{, and Objective-C}
17500 @kindex break@r{, and Objective-C}
17501 @kindex info line@r{, and Objective-C}
17502 @kindex jump@r{, and Objective-C}
17503 @kindex list@r{, and Objective-C}
17504 @itemize
17505 @item @code{clear}
17506 @item @code{break}
17507 @item @code{info line}
17508 @item @code{jump}
17509 @item @code{list}
17510 @end itemize
17511
17512 A fully qualified Objective-C method name is specified as
17513
17514 @smallexample
17515 -[@var{Class} @var{methodName}]
17516 @end smallexample
17517
17518 where the minus sign is used to indicate an instance method and a
17519 plus sign (not shown) is used to indicate a class method. The class
17520 name @var{Class} and method name @var{methodName} are enclosed in
17521 brackets, similar to the way messages are specified in Objective-C
17522 source code. For example, to set a breakpoint at the @code{create}
17523 instance method of class @code{Fruit} in the program currently being
17524 debugged, enter:
17525
17526 @smallexample
17527 break -[Fruit create]
17528 @end smallexample
17529
17530 To list ten program lines around the @code{initialize} class method,
17531 enter:
17532
17533 @smallexample
17534 list +[NSText initialize]
17535 @end smallexample
17536
17537 In the current version of @value{GDBN}, the plus or minus sign is
17538 required. In future versions of @value{GDBN}, the plus or minus
17539 sign will be optional, but you can use it to narrow the search. It
17540 is also possible to specify just a method name:
17541
17542 @smallexample
17543 break create
17544 @end smallexample
17545
17546 You must specify the complete method name, including any colons. If
17547 your program's source files contain more than one @code{create} method,
17548 you'll be presented with a numbered list of classes that implement that
17549 method. Indicate your choice by number, or type @samp{0} to exit if
17550 none apply.
17551
17552 As another example, to clear a breakpoint established at the
17553 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
17554
17555 @smallexample
17556 clear -[NSWindow makeKeyAndOrderFront:]
17557 @end smallexample
17558
17559 @node The Print Command with Objective-C
17560 @subsubsection The Print Command With Objective-C
17561 @cindex Objective-C, print objects
17562 @kindex print-object
17563 @kindex po @r{(@code{print-object})}
17564
17565 The print command has also been extended to accept methods. For example:
17566
17567 @smallexample
17568 print -[@var{object} hash]
17569 @end smallexample
17570
17571 @cindex print an Objective-C object description
17572 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
17573 @noindent
17574 will tell @value{GDBN} to send the @code{hash} message to @var{object}
17575 and print the result. Also, an additional command has been added,
17576 @code{print-object} or @code{po} for short, which is meant to print
17577 the description of an object. However, this command may only work
17578 with certain Objective-C libraries that have a particular hook
17579 function, @code{_NSPrintForDebugger}, defined.
17580
17581 @node OpenCL C
17582 @subsection OpenCL C
17583
17584 @cindex OpenCL C
17585 This section provides information about @value{GDBN}s OpenCL C support.
17586
17587 @menu
17588 * OpenCL C Datatypes::
17589 * OpenCL C Expressions::
17590 * OpenCL C Operators::
17591 @end menu
17592
17593 @node OpenCL C Datatypes
17594 @subsubsection OpenCL C Datatypes
17595
17596 @cindex OpenCL C Datatypes
17597 @value{GDBN} supports the builtin scalar and vector datatypes specified
17598 by OpenCL 1.1. In addition the half- and double-precision floating point
17599 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
17600 extensions are also known to @value{GDBN}.
17601
17602 @node OpenCL C Expressions
17603 @subsubsection OpenCL C Expressions
17604
17605 @cindex OpenCL C Expressions
17606 @value{GDBN} supports accesses to vector components including the access as
17607 lvalue where possible. Since OpenCL C is based on C99 most C expressions
17608 supported by @value{GDBN} can be used as well.
17609
17610 @node OpenCL C Operators
17611 @subsubsection OpenCL C Operators
17612
17613 @cindex OpenCL C Operators
17614 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
17615 vector data types.
17616
17617 @node Fortran
17618 @subsection Fortran
17619 @cindex Fortran-specific support in @value{GDBN}
17620
17621 @value{GDBN} can be used to debug programs written in Fortran. Note, that not
17622 all Fortran language features are available yet.
17623
17624 @cindex trailing underscore, in Fortran symbols
17625 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
17626 among them) append an underscore to the names of variables and
17627 functions. When you debug programs compiled by those compilers, you
17628 will need to refer to variables and functions with a trailing
17629 underscore.
17630
17631 @cindex Fortran Defaults
17632 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17633 default uses case-insensitive matching for Fortran symbols. You can
17634 change that with the @samp{set case-insensitive} command, see
17635 @ref{Symbols}, for the details.
17636
17637 @menu
17638 * Fortran Types:: Fortran builtin types
17639 * Fortran Operators:: Fortran operators and expressions
17640 * Fortran Intrinsics:: Fortran intrinsic functions
17641 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
17642 @end menu
17643
17644 @node Fortran Types
17645 @subsubsection Fortran Types
17646
17647 @cindex Fortran Types
17648
17649 In Fortran the primitive data-types have an associated @code{KIND} type
17650 parameter, written as @samp{@var{type}*@var{kindparam}},
17651 @samp{@var{type}*@var{kindparam}}, or in the @value{GDBN}-only dialect
17652 @samp{@var{type}_@var{kindparam}}. A concrete example would be
17653 @samp{@code{Real*4}}, @samp{@code{Real(kind=4)}}, and @samp{@code{Real_4}}.
17654 The kind of a type can be retrieved by using the intrinsic function
17655 @code{KIND}, see @ref{Fortran Intrinsics}.
17656
17657 Generally, the actual implementation of the @code{KIND} type parameter is
17658 compiler specific. In @value{GDBN} the kind parameter is implemented in
17659 accordance with its use in the @sc{gnu} @command{gfortran} compiler. Here, the
17660 kind parameter for a given @var{type} specifies its size in memory --- a
17661 Fortran @code{Integer*4} or @code{Integer(kind=4)} would be an integer type
17662 occupying 4 bytes of memory. An exception to this rule is the @code{Complex}
17663 type for which the kind of the type does not specify its entire size, but
17664 the size of each of the two @code{Real}'s it is composed of. A
17665 @code{Complex*4} would thus consist of two @code{Real*4}s and occupy 8 bytes
17666 of memory.
17667
17668 For every type there is also a default kind associated with it, e.g.@
17669 @code{Integer} in @value{GDBN} will internally be an @code{Integer*4} (see the
17670 table below for default types). The default types are the same as in @sc{gnu}
17671 compilers but note, that the @sc{gnu} default types can actually be changed by
17672 compiler flags such as @option{-fdefault-integer-8} and
17673 @option{-fdefault-real-8}.
17674
17675 Not every kind parameter is valid for every type and in @value{GDBN} the
17676 following type kinds are available.
17677
17678 @table @code
17679 @item Integer
17680 @code{Integer*1}, @code{Integer*2}, @code{Integer*4}, @code{Integer*8}, and
17681 @code{Integer} = @code{Integer*4}.
17682
17683 @item Logical
17684 @code{Logical*1}, @code{Logical*2}, @code{Logical*4}, @code{Logical*8}, and
17685 @code{Logical} = @code{Logical*4}.
17686
17687 @item Real
17688 @code{Real*4}, @code{Real*8}, @code{Real*16}, and @code{Real} = @code{Real*4}.
17689
17690 @item Complex
17691 @code{Complex*4}, @code{Complex*8}, @code{Complex*16}, and @code{Complex} =
17692 @code{Complex*4}.
17693
17694 @end table
17695
17696 @node Fortran Operators
17697 @subsubsection Fortran Operators and Expressions
17698
17699 @cindex Fortran operators and expressions
17700
17701 Operators must be defined on values of specific types. For instance,
17702 @code{+} is defined on numbers, but not on characters or other non-
17703 arithmetic types. Operators are often defined on groups of types.
17704
17705 @table @code
17706 @item **
17707 The exponentiation operator. It raises the first operand to the power
17708 of the second one.
17709
17710 @item :
17711 The range operator. Normally used in the form of array(low:high) to
17712 represent a section of array.
17713
17714 @item %
17715 The access component operator. Normally used to access elements in derived
17716 types. Also suitable for unions. As unions aren't part of regular Fortran,
17717 this can only happen when accessing a register that uses a gdbarch-defined
17718 union type.
17719 @item ::
17720 The scope operator. Normally used to access variables in modules or
17721 to set breakpoints on subroutines nested in modules or in other
17722 subroutines (internal subroutines).
17723 @end table
17724
17725 @node Fortran Intrinsics
17726 @subsubsection Fortran Intrinsics
17727
17728 @cindex Fortran Intrinsics
17729
17730 Fortran provides a large set of intrinsic procedures. @value{GDBN} implements
17731 an incomplete subset of those procedures and their overloads. Some of these
17732 procedures take an optional @code{KIND} parameter, see @ref{Fortran Types}.
17733
17734 @table @code
17735 @item ABS(@var{a})
17736 Computes the absolute value of its argument @var{a}. Currently not supported
17737 for @code{Complex} arguments.
17738
17739 @item ALLOCATE(@var{array})
17740 Returns whether @var{array} is allocated or not.
17741
17742 @item ASSOCIATED(@var{pointer} [, @var{target}])
17743 Returns the association status of the pointer @var{pointer} or, if @var{target}
17744 is present, whether @var{pointer} is associated with the target @var{target}.
17745
17746 @item CEILING(@var{a} [, @var{kind}])
17747 Computes the least integer greater than or equal to @var{a}. The optional
17748 parameter @var{kind} specifies the kind of the return type
17749 @code{Integer(@var{kind})}.
17750
17751 @item CMPLX(@var{x} [, @var{y} [, @var{kind}]])
17752 Returns a complex number where @var{x} is converted to the real component. If
17753 @var{y} is present it is converted to the imaginary component. If @var{y} is
17754 not present then the imaginary component is set to @code{0.0} except if @var{x}
17755 itself is of @code{Complex} type. The optional parameter @var{kind} specifies
17756 the kind of the return type @code{Complex(@var{kind})}.
17757
17758 @item FLOOR(@var{a} [, @var{kind}])
17759 Computes the greatest integer less than or equal to @var{a}. The optional
17760 parameter @var{kind} specifies the kind of the return type
17761 @code{Integer(@var{kind})}.
17762
17763 @item KIND(@var{a})
17764 Returns the kind value of the argument @var{a}, see @ref{Fortran Types}.
17765
17766 @item LBOUND(@var{array} [, @var{dim} [, @var{kind}]])
17767 Returns the lower bounds of an @var{array}, or a single lower bound along the
17768 @var{dim} dimension if present. The optional parameter @var{kind} specifies
17769 the kind of the return type @code{Integer(@var{kind})}.
17770
17771 @item LOC(@var{x})
17772 Returns the address of @var{x} as an @code{Integer}.
17773
17774 @item MOD(@var{a}, @var{p})
17775 Computes the remainder of the division of @var{a} by @var{p}.
17776
17777 @item MODULO(@var{a}, @var{p})
17778 Computes the @var{a} modulo @var{p}.
17779
17780 @item RANK(@var{a})
17781 Returns the rank of a scalar or array (scalars have rank @code{0}).
17782
17783 @item SHAPE(@var{a})
17784 Returns the shape of a scalar or array (scalars have shape @samp{()}).
17785
17786 @item SIZE(@var{array}[, @var{dim} [, @var{kind}]])
17787 Returns the extent of @var{array} along a specified dimension @var{dim}, or the
17788 total number of elements in @var{array} if @var{dim} is absent. The optional
17789 parameter @var{kind} specifies the kind of the return type
17790 @code{Integer(@var{kind})}.
17791
17792 @item UBOUND(@var{array} [, @var{dim} [, @var{kind}]])
17793 Returns the upper bounds of an @var{array}, or a single upper bound along the
17794 @var{dim} dimension if present. The optional parameter @var{kind} specifies
17795 the kind of the return type @code{Integer(@var{kind})}.
17796
17797 @end table
17798
17799 @node Special Fortran Commands
17800 @subsubsection Special Fortran Commands
17801
17802 @cindex Special Fortran commands
17803
17804 @value{GDBN} has some commands to support Fortran-specific features,
17805 such as displaying common blocks.
17806
17807 @table @code
17808 @cindex @code{COMMON} blocks, Fortran
17809 @kindex info common
17810 @item info common @r{[}@var{common-name}@r{]}
17811 This command prints the values contained in the Fortran @code{COMMON}
17812 block whose name is @var{common-name}. With no argument, the names of
17813 all @code{COMMON} blocks visible at the current program location are
17814 printed.
17815 @cindex arrays slices (Fortran)
17816 @kindex set fortran repack-array-slices
17817 @kindex show fortran repack-array-slices
17818 @item set fortran repack-array-slices [on|off]
17819 @item show fortran repack-array-slices
17820 When taking a slice from an array, a Fortran compiler can choose to
17821 either produce an array descriptor that describes the slice in place,
17822 or it may repack the slice, copying the elements of the slice into a
17823 new region of memory.
17824
17825 When this setting is on, then @value{GDBN} will also repack array
17826 slices in some situations. When this setting is off, then
17827 @value{GDBN} will create array descriptors for slices that reference
17828 the original data in place.
17829
17830 @value{GDBN} will never repack an array slice if the data for the
17831 slice is contiguous within the original array.
17832
17833 @value{GDBN} will always repack string slices if the data for the
17834 slice is non-contiguous within the original string as @value{GDBN}
17835 does not support printing non-contiguous strings.
17836
17837 The default for this setting is @code{off}.
17838 @end table
17839
17840 @node Pascal
17841 @subsection Pascal
17842
17843 @cindex Pascal support in @value{GDBN}, limitations
17844 Debugging Pascal programs which use sets, subranges, file variables, or
17845 nested functions does not currently work. @value{GDBN} does not support
17846 entering expressions, printing values, or similar features using Pascal
17847 syntax.
17848
17849 The Pascal-specific command @code{set print pascal_static-members}
17850 controls whether static members of Pascal objects are displayed.
17851 @xref{Print Settings, pascal_static-members}.
17852
17853 @node Rust
17854 @subsection Rust
17855
17856 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17857 Programming Language}. Type- and value-printing, and expression
17858 parsing, are reasonably complete. However, there are a few
17859 peculiarities and holes to be aware of.
17860
17861 @itemize @bullet
17862 @item
17863 Linespecs (@pxref{Location Specifications}) are never relative to the
17864 current crate. Instead, they act as if there were a global namespace
17865 of crates, somewhat similar to the way @code{extern crate} behaves.
17866
17867 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17868 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17869 to set a breakpoint in a function named @samp{f} in a crate named
17870 @samp{B}.
17871
17872 As a consequence of this approach, linespecs also cannot refer to
17873 items using @samp{self::} or @samp{super::}.
17874
17875 @item
17876 Because @value{GDBN} implements Rust name-lookup semantics in
17877 expressions, it will sometimes prepend the current crate to a name.
17878 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17879 @samp{K}, then @code{print ::x::y} will try to find the symbol
17880 @samp{K::x::y}.
17881
17882 However, since it is useful to be able to refer to other crates when
17883 debugging, @value{GDBN} provides the @code{extern} extension to
17884 circumvent this. To use the extension, just put @code{extern} before
17885 a path expression to refer to the otherwise unavailable ``global''
17886 scope.
17887
17888 In the above example, if you wanted to refer to the symbol @samp{y} in
17889 the crate @samp{x}, you would use @code{print extern x::y}.
17890
17891 @item
17892 The Rust expression evaluator does not support ``statement-like''
17893 expressions such as @code{if} or @code{match}, or lambda expressions.
17894
17895 @item
17896 Tuple expressions are not implemented.
17897
17898 @item
17899 The Rust expression evaluator does not currently implement the
17900 @code{Drop} trait. Objects that may be created by the evaluator will
17901 never be destroyed.
17902
17903 @item
17904 @value{GDBN} does not implement type inference for generics. In order
17905 to call generic functions or otherwise refer to generic items, you
17906 will have to specify the type parameters manually.
17907
17908 @item
17909 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17910 cases this does not cause any problems. However, in an expression
17911 context, completing a generic function name will give syntactically
17912 invalid results. This happens because Rust requires the @samp{::}
17913 operator between the function name and its generic arguments. For
17914 example, @value{GDBN} might provide a completion like
17915 @code{crate::f<u32>}, where the parser would require
17916 @code{crate::f::<u32>}.
17917
17918 @item
17919 As of this writing, the Rust compiler (version 1.8) has a few holes in
17920 the debugging information it generates. These holes prevent certain
17921 features from being implemented by @value{GDBN}:
17922 @itemize @bullet
17923
17924 @item
17925 Method calls cannot be made via traits.
17926
17927 @item
17928 Operator overloading is not implemented.
17929
17930 @item
17931 When debugging in a monomorphized function, you cannot use the generic
17932 type names.
17933
17934 @item
17935 The type @code{Self} is not available.
17936
17937 @item
17938 @code{use} statements are not available, so some names may not be
17939 available in the crate.
17940 @end itemize
17941 @end itemize
17942
17943 @node Modula-2
17944 @subsection Modula-2
17945
17946 @cindex Modula-2, @value{GDBN} support
17947
17948 The extensions made to @value{GDBN} to support Modula-2 only support
17949 output from the @sc{gnu} Modula-2 compiler (which is currently being
17950 developed). Other Modula-2 compilers are not currently supported, and
17951 attempting to debug executables produced by them is most likely
17952 to give an error as @value{GDBN} reads in the executable's symbol
17953 table.
17954
17955 @cindex expressions in Modula-2
17956 @menu
17957 * M2 Operators:: Built-in operators
17958 * Built-In Func/Proc:: Built-in functions and procedures
17959 * M2 Constants:: Modula-2 constants
17960 * M2 Types:: Modula-2 types
17961 * M2 Defaults:: Default settings for Modula-2
17962 * Deviations:: Deviations from standard Modula-2
17963 * M2 Checks:: Modula-2 type and range checks
17964 * M2 Scope:: The scope operators @code{::} and @code{.}
17965 * GDB/M2:: @value{GDBN} and Modula-2
17966 @end menu
17967
17968 @node M2 Operators
17969 @subsubsection Operators
17970 @cindex Modula-2 operators
17971
17972 Operators must be defined on values of specific types. For instance,
17973 @code{+} is defined on numbers, but not on structures. Operators are
17974 often defined on groups of types. For the purposes of Modula-2, the
17975 following definitions hold:
17976
17977 @itemize @bullet
17978
17979 @item
17980 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17981 their subranges.
17982
17983 @item
17984 @emph{Character types} consist of @code{CHAR} and its subranges.
17985
17986 @item
17987 @emph{Floating-point types} consist of @code{REAL}.
17988
17989 @item
17990 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17991 @var{type}}.
17992
17993 @item
17994 @emph{Scalar types} consist of all of the above.
17995
17996 @item
17997 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17998
17999 @item
18000 @emph{Boolean types} consist of @code{BOOLEAN}.
18001 @end itemize
18002
18003 @noindent
18004 The following operators are supported, and appear in order of
18005 increasing precedence:
18006
18007 @table @code
18008 @item ,
18009 Function argument or array index separator.
18010
18011 @item :=
18012 Assignment. The value of @var{var} @code{:=} @var{value} is
18013 @var{value}.
18014
18015 @item <@r{, }>
18016 Less than, greater than on integral, floating-point, or enumerated
18017 types.
18018
18019 @item <=@r{, }>=
18020 Less than or equal to, greater than or equal to
18021 on integral, floating-point and enumerated types, or set inclusion on
18022 set types. Same precedence as @code{<}.
18023
18024 @item =@r{, }<>@r{, }#
18025 Equality and two ways of expressing inequality, valid on scalar types.
18026 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
18027 available for inequality, since @code{#} conflicts with the script
18028 comment character.
18029
18030 @item IN
18031 Set membership. Defined on set types and the types of their members.
18032 Same precedence as @code{<}.
18033
18034 @item OR
18035 Boolean disjunction. Defined on boolean types.
18036
18037 @item AND@r{, }&
18038 Boolean conjunction. Defined on boolean types.
18039
18040 @item @@
18041 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
18042
18043 @item +@r{, }-
18044 Addition and subtraction on integral and floating-point types, or union
18045 and difference on set types.
18046
18047 @item *
18048 Multiplication on integral and floating-point types, or set intersection
18049 on set types.
18050
18051 @item /
18052 Division on floating-point types, or symmetric set difference on set
18053 types. Same precedence as @code{*}.
18054
18055 @item DIV@r{, }MOD
18056 Integer division and remainder. Defined on integral types. Same
18057 precedence as @code{*}.
18058
18059 @item -
18060 Negative. Defined on @code{INTEGER} and @code{REAL} data.
18061
18062 @item ^
18063 Pointer dereferencing. Defined on pointer types.
18064
18065 @item NOT
18066 Boolean negation. Defined on boolean types. Same precedence as
18067 @code{^}.
18068
18069 @item .
18070 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
18071 precedence as @code{^}.
18072
18073 @item []
18074 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
18075
18076 @item ()
18077 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
18078 as @code{^}.
18079
18080 @item ::@r{, }.
18081 @value{GDBN} and Modula-2 scope operators.
18082 @end table
18083
18084 @quotation
18085 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
18086 treats the use of the operator @code{IN}, or the use of operators
18087 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
18088 @code{<=}, and @code{>=} on sets as an error.
18089 @end quotation
18090
18091
18092 @node Built-In Func/Proc
18093 @subsubsection Built-in Functions and Procedures
18094 @cindex Modula-2 built-ins
18095
18096 Modula-2 also makes available several built-in procedures and functions.
18097 In describing these, the following metavariables are used:
18098
18099 @table @var
18100
18101 @item a
18102 represents an @code{ARRAY} variable.
18103
18104 @item c
18105 represents a @code{CHAR} constant or variable.
18106
18107 @item i
18108 represents a variable or constant of integral type.
18109
18110 @item m
18111 represents an identifier that belongs to a set. Generally used in the
18112 same function with the metavariable @var{s}. The type of @var{s} should
18113 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
18114
18115 @item n
18116 represents a variable or constant of integral or floating-point type.
18117
18118 @item r
18119 represents a variable or constant of floating-point type.
18120
18121 @item t
18122 represents a type.
18123
18124 @item v
18125 represents a variable.
18126
18127 @item x
18128 represents a variable or constant of one of many types. See the
18129 explanation of the function for details.
18130 @end table
18131
18132 All Modula-2 built-in procedures also return a result, described below.
18133
18134 @table @code
18135 @item ABS(@var{n})
18136 Returns the absolute value of @var{n}.
18137
18138 @item CAP(@var{c})
18139 If @var{c} is a lower case letter, it returns its upper case
18140 equivalent, otherwise it returns its argument.
18141
18142 @item CHR(@var{i})
18143 Returns the character whose ordinal value is @var{i}.
18144
18145 @item DEC(@var{v})
18146 Decrements the value in the variable @var{v} by one. Returns the new value.
18147
18148 @item DEC(@var{v},@var{i})
18149 Decrements the value in the variable @var{v} by @var{i}. Returns the
18150 new value.
18151
18152 @item EXCL(@var{m},@var{s})
18153 Removes the element @var{m} from the set @var{s}. Returns the new
18154 set.
18155
18156 @item FLOAT(@var{i})
18157 Returns the floating point equivalent of the integer @var{i}.
18158
18159 @item HIGH(@var{a})
18160 Returns the index of the last member of @var{a}.
18161
18162 @item INC(@var{v})
18163 Increments the value in the variable @var{v} by one. Returns the new value.
18164
18165 @item INC(@var{v},@var{i})
18166 Increments the value in the variable @var{v} by @var{i}. Returns the
18167 new value.
18168
18169 @item INCL(@var{m},@var{s})
18170 Adds the element @var{m} to the set @var{s} if it is not already
18171 there. Returns the new set.
18172
18173 @item MAX(@var{t})
18174 Returns the maximum value of the type @var{t}.
18175
18176 @item MIN(@var{t})
18177 Returns the minimum value of the type @var{t}.
18178
18179 @item ODD(@var{i})
18180 Returns boolean TRUE if @var{i} is an odd number.
18181
18182 @item ORD(@var{x})
18183 Returns the ordinal value of its argument. For example, the ordinal
18184 value of a character is its @sc{ascii} value (on machines supporting
18185 the @sc{ascii} character set). The argument @var{x} must be of an
18186 ordered type, which include integral, character and enumerated types.
18187
18188 @item SIZE(@var{x})
18189 Returns the size of its argument. The argument @var{x} can be a
18190 variable or a type.
18191
18192 @item TRUNC(@var{r})
18193 Returns the integral part of @var{r}.
18194
18195 @item TSIZE(@var{x})
18196 Returns the size of its argument. The argument @var{x} can be a
18197 variable or a type.
18198
18199 @item VAL(@var{t},@var{i})
18200 Returns the member of the type @var{t} whose ordinal value is @var{i}.
18201 @end table
18202
18203 @quotation
18204 @emph{Warning:} Sets and their operations are not yet supported, so
18205 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
18206 an error.
18207 @end quotation
18208
18209 @cindex Modula-2 constants
18210 @node M2 Constants
18211 @subsubsection Constants
18212
18213 @value{GDBN} allows you to express the constants of Modula-2 in the following
18214 ways:
18215
18216 @itemize @bullet
18217
18218 @item
18219 Integer constants are simply a sequence of digits. When used in an
18220 expression, a constant is interpreted to be type-compatible with the
18221 rest of the expression. Hexadecimal integers are specified by a
18222 trailing @samp{H}, and octal integers by a trailing @samp{B}.
18223
18224 @item
18225 Floating point constants appear as a sequence of digits, followed by a
18226 decimal point and another sequence of digits. An optional exponent can
18227 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
18228 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
18229 digits of the floating point constant must be valid decimal (base 10)
18230 digits.
18231
18232 @item
18233 Character constants consist of a single character enclosed by a pair of
18234 like quotes, either single (@code{'}) or double (@code{"}). They may
18235 also be expressed by their ordinal value (their @sc{ascii} value, usually)
18236 followed by a @samp{C}.
18237
18238 @item
18239 String constants consist of a sequence of characters enclosed by a
18240 pair of like quotes, either single (@code{'}) or double (@code{"}).
18241 Escape sequences in the style of C are also allowed. @xref{C
18242 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
18243 sequences.
18244
18245 @item
18246 Enumerated constants consist of an enumerated identifier.
18247
18248 @item
18249 Boolean constants consist of the identifiers @code{TRUE} and
18250 @code{FALSE}.
18251
18252 @item
18253 Pointer constants consist of integral values only.
18254
18255 @item
18256 Set constants are not yet supported.
18257 @end itemize
18258
18259 @node M2 Types
18260 @subsubsection Modula-2 Types
18261 @cindex Modula-2 types
18262
18263 Currently @value{GDBN} can print the following data types in Modula-2
18264 syntax: array types, record types, set types, pointer types, procedure
18265 types, enumerated types, subrange types and base types. You can also
18266 print the contents of variables declared using these type.
18267 This section gives a number of simple source code examples together with
18268 sample @value{GDBN} sessions.
18269
18270 The first example contains the following section of code:
18271
18272 @smallexample
18273 VAR
18274 s: SET OF CHAR ;
18275 r: [20..40] ;
18276 @end smallexample
18277
18278 @noindent
18279 and you can request @value{GDBN} to interrogate the type and value of
18280 @code{r} and @code{s}.
18281
18282 @smallexample
18283 (@value{GDBP}) print s
18284 @{'A'..'C', 'Z'@}
18285 (@value{GDBP}) ptype s
18286 SET OF CHAR
18287 (@value{GDBP}) print r
18288 21
18289 (@value{GDBP}) ptype r
18290 [20..40]
18291 @end smallexample
18292
18293 @noindent
18294 Likewise if your source code declares @code{s} as:
18295
18296 @smallexample
18297 VAR
18298 s: SET ['A'..'Z'] ;
18299 @end smallexample
18300
18301 @noindent
18302 then you may query the type of @code{s} by:
18303
18304 @smallexample
18305 (@value{GDBP}) ptype s
18306 type = SET ['A'..'Z']
18307 @end smallexample
18308
18309 @noindent
18310 Note that at present you cannot interactively manipulate set
18311 expressions using the debugger.
18312
18313 The following example shows how you might declare an array in Modula-2
18314 and how you can interact with @value{GDBN} to print its type and contents:
18315
18316 @smallexample
18317 VAR
18318 s: ARRAY [-10..10] OF CHAR ;
18319 @end smallexample
18320
18321 @smallexample
18322 (@value{GDBP}) ptype s
18323 ARRAY [-10..10] OF CHAR
18324 @end smallexample
18325
18326 Note that the array handling is not yet complete and although the type
18327 is printed correctly, expression handling still assumes that all
18328 arrays have a lower bound of zero and not @code{-10} as in the example
18329 above.
18330
18331 Here are some more type related Modula-2 examples:
18332
18333 @smallexample
18334 TYPE
18335 colour = (blue, red, yellow, green) ;
18336 t = [blue..yellow] ;
18337 VAR
18338 s: t ;
18339 BEGIN
18340 s := blue ;
18341 @end smallexample
18342
18343 @noindent
18344 The @value{GDBN} interaction shows how you can query the data type
18345 and value of a variable.
18346
18347 @smallexample
18348 (@value{GDBP}) print s
18349 $1 = blue
18350 (@value{GDBP}) ptype t
18351 type = [blue..yellow]
18352 @end smallexample
18353
18354 @noindent
18355 In this example a Modula-2 array is declared and its contents
18356 displayed. Observe that the contents are written in the same way as
18357 their @code{C} counterparts.
18358
18359 @smallexample
18360 VAR
18361 s: ARRAY [1..5] OF CARDINAL ;
18362 BEGIN
18363 s[1] := 1 ;
18364 @end smallexample
18365
18366 @smallexample
18367 (@value{GDBP}) print s
18368 $1 = @{1, 0, 0, 0, 0@}
18369 (@value{GDBP}) ptype s
18370 type = ARRAY [1..5] OF CARDINAL
18371 @end smallexample
18372
18373 The Modula-2 language interface to @value{GDBN} also understands
18374 pointer types as shown in this example:
18375
18376 @smallexample
18377 VAR
18378 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
18379 BEGIN
18380 NEW(s) ;
18381 s^[1] := 1 ;
18382 @end smallexample
18383
18384 @noindent
18385 and you can request that @value{GDBN} describes the type of @code{s}.
18386
18387 @smallexample
18388 (@value{GDBP}) ptype s
18389 type = POINTER TO ARRAY [1..5] OF CARDINAL
18390 @end smallexample
18391
18392 @value{GDBN} handles compound types as we can see in this example.
18393 Here we combine array types, record types, pointer types and subrange
18394 types:
18395
18396 @smallexample
18397 TYPE
18398 foo = RECORD
18399 f1: CARDINAL ;
18400 f2: CHAR ;
18401 f3: myarray ;
18402 END ;
18403
18404 myarray = ARRAY myrange OF CARDINAL ;
18405 myrange = [-2..2] ;
18406 VAR
18407 s: POINTER TO ARRAY myrange OF foo ;
18408 @end smallexample
18409
18410 @noindent
18411 and you can ask @value{GDBN} to describe the type of @code{s} as shown
18412 below.
18413
18414 @smallexample
18415 (@value{GDBP}) ptype s
18416 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
18417 f1 : CARDINAL;
18418 f2 : CHAR;
18419 f3 : ARRAY [-2..2] OF CARDINAL;
18420 END
18421 @end smallexample
18422
18423 @node M2 Defaults
18424 @subsubsection Modula-2 Defaults
18425 @cindex Modula-2 defaults
18426
18427 If type and range checking are set automatically by @value{GDBN}, they
18428 both default to @code{on} whenever the working language changes to
18429 Modula-2. This happens regardless of whether you or @value{GDBN}
18430 selected the working language.
18431
18432 If you allow @value{GDBN} to set the language automatically, then entering
18433 code compiled from a file whose name ends with @file{.mod} sets the
18434 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
18435 Infer the Source Language}, for further details.
18436
18437 @node Deviations
18438 @subsubsection Deviations from Standard Modula-2
18439 @cindex Modula-2, deviations from
18440
18441 A few changes have been made to make Modula-2 programs easier to debug.
18442 This is done primarily via loosening its type strictness:
18443
18444 @itemize @bullet
18445 @item
18446 Unlike in standard Modula-2, pointer constants can be formed by
18447 integers. This allows you to modify pointer variables during
18448 debugging. (In standard Modula-2, the actual address contained in a
18449 pointer variable is hidden from you; it can only be modified
18450 through direct assignment to another pointer variable or expression that
18451 returned a pointer.)
18452
18453 @item
18454 C escape sequences can be used in strings and characters to represent
18455 non-printable characters. @value{GDBN} prints out strings with these
18456 escape sequences embedded. Single non-printable characters are
18457 printed using the @samp{CHR(@var{nnn})} format.
18458
18459 @item
18460 The assignment operator (@code{:=}) returns the value of its right-hand
18461 argument.
18462
18463 @item
18464 All built-in procedures both modify @emph{and} return their argument.
18465 @end itemize
18466
18467 @node M2 Checks
18468 @subsubsection Modula-2 Type and Range Checks
18469 @cindex Modula-2 checks
18470
18471 @quotation
18472 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
18473 range checking.
18474 @end quotation
18475 @c FIXME remove warning when type/range checks added
18476
18477 @value{GDBN} considers two Modula-2 variables type equivalent if:
18478
18479 @itemize @bullet
18480 @item
18481 They are of types that have been declared equivalent via a @code{TYPE
18482 @var{t1} = @var{t2}} statement
18483
18484 @item
18485 They have been declared on the same line. (Note: This is true of the
18486 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
18487 @end itemize
18488
18489 As long as type checking is enabled, any attempt to combine variables
18490 whose types are not equivalent is an error.
18491
18492 Range checking is done on all mathematical operations, assignment, array
18493 index bounds, and all built-in functions and procedures.
18494
18495 @node M2 Scope
18496 @subsubsection The Scope Operators @code{::} and @code{.}
18497 @cindex scope
18498 @cindex @code{.}, Modula-2 scope operator
18499 @cindex colon, doubled as scope operator
18500 @ifinfo
18501 @vindex colon-colon@r{, in Modula-2}
18502 @c Info cannot handle :: but TeX can.
18503 @end ifinfo
18504 @ifnotinfo
18505 @vindex ::@r{, in Modula-2}
18506 @end ifnotinfo
18507
18508 There are a few subtle differences between the Modula-2 scope operator
18509 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
18510 similar syntax:
18511
18512 @smallexample
18513
18514 @var{module} . @var{id}
18515 @var{scope} :: @var{id}
18516 @end smallexample
18517
18518 @noindent
18519 where @var{scope} is the name of a module or a procedure,
18520 @var{module} the name of a module, and @var{id} is any declared
18521 identifier within your program, except another module.
18522
18523 Using the @code{::} operator makes @value{GDBN} search the scope
18524 specified by @var{scope} for the identifier @var{id}. If it is not
18525 found in the specified scope, then @value{GDBN} searches all scopes
18526 enclosing the one specified by @var{scope}.
18527
18528 Using the @code{.} operator makes @value{GDBN} search the current scope for
18529 the identifier specified by @var{id} that was imported from the
18530 definition module specified by @var{module}. With this operator, it is
18531 an error if the identifier @var{id} was not imported from definition
18532 module @var{module}, or if @var{id} is not an identifier in
18533 @var{module}.
18534
18535 @node GDB/M2
18536 @subsubsection @value{GDBN} and Modula-2
18537
18538 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
18539 Five subcommands of @code{set print} and @code{show print} apply
18540 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
18541 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
18542 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
18543 analogue in Modula-2.
18544
18545 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
18546 with any language, is not useful with Modula-2. Its
18547 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
18548 created in Modula-2 as they can in C or C@t{++}. However, because an
18549 address can be specified by an integral constant, the construct
18550 @samp{@{@var{type}@}@var{adrexp}} is still useful.
18551
18552 @cindex @code{#} in Modula-2
18553 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
18554 interpreted as the beginning of a comment. Use @code{<>} instead.
18555
18556 @node Ada
18557 @subsection Ada
18558 @cindex Ada
18559
18560 The extensions made to @value{GDBN} for Ada only support
18561 output from the @sc{gnu} Ada (GNAT) compiler.
18562 Other Ada compilers are not currently supported, and
18563 attempting to debug executables produced by them is most likely
18564 to be difficult.
18565
18566
18567 @cindex expressions in Ada
18568 @menu
18569 * Ada Mode Intro:: General remarks on the Ada syntax
18570 and semantics supported by Ada mode
18571 in @value{GDBN}.
18572 * Omissions from Ada:: Restrictions on the Ada expression syntax.
18573 * Additions to Ada:: Extensions of the Ada expression syntax.
18574 * Overloading support for Ada:: Support for expressions involving overloaded
18575 subprograms.
18576 * Stopping Before Main Program:: Debugging the program during elaboration.
18577 * Ada Exceptions:: Ada Exceptions
18578 * Ada Tasks:: Listing and setting breakpoints in tasks.
18579 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
18580 * Ravenscar Profile:: Tasking Support when using the Ravenscar
18581 Profile
18582 * Ada Source Character Set:: Character set of Ada source files.
18583 * Ada Glitches:: Known peculiarities of Ada mode.
18584 @end menu
18585
18586 @node Ada Mode Intro
18587 @subsubsection Introduction
18588 @cindex Ada mode, general
18589
18590 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
18591 syntax, with some extensions.
18592 The philosophy behind the design of this subset is
18593
18594 @itemize @bullet
18595 @item
18596 That @value{GDBN} should provide basic literals and access to operations for
18597 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
18598 leaving more sophisticated computations to subprograms written into the
18599 program (which therefore may be called from @value{GDBN}).
18600
18601 @item
18602 That type safety and strict adherence to Ada language restrictions
18603 are not particularly important to the @value{GDBN} user.
18604
18605 @item
18606 That brevity is important to the @value{GDBN} user.
18607 @end itemize
18608
18609 Thus, for brevity, the debugger acts as if all names declared in
18610 user-written packages are directly visible, even if they are not visible
18611 according to Ada rules, thus making it unnecessary to fully qualify most
18612 names with their packages, regardless of context. Where this causes
18613 ambiguity, @value{GDBN} asks the user's intent.
18614
18615 The debugger will start in Ada mode if it detects an Ada main program.
18616 As for other languages, it will enter Ada mode when stopped in a program that
18617 was translated from an Ada source file.
18618
18619 While in Ada mode, you may use `@t{--}' for comments. This is useful
18620 mostly for documenting command files. The standard @value{GDBN} comment
18621 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
18622 middle (to allow based literals).
18623
18624 @node Omissions from Ada
18625 @subsubsection Omissions from Ada
18626 @cindex Ada, omissions from
18627
18628 Here are the notable omissions from the subset:
18629
18630 @itemize @bullet
18631 @item
18632 Only a subset of the attributes are supported:
18633
18634 @itemize @minus
18635 @item
18636 @t{'First}, @t{'Last}, and @t{'Length}
18637 on array objects (not on types and subtypes).
18638
18639 @item
18640 @t{'Min} and @t{'Max}.
18641
18642 @item
18643 @t{'Pos} and @t{'Val}.
18644
18645 @item
18646 @t{'Tag}.
18647
18648 @item
18649 @t{'Range} on array objects (not subtypes), but only as the right
18650 operand of the membership (@code{in}) operator.
18651
18652 @item
18653 @t{'Access}, @t{'Unchecked_Access}, and
18654 @t{'Unrestricted_Access} (a GNAT extension).
18655
18656 @item
18657 @t{'Address}.
18658 @end itemize
18659
18660 @item
18661 The names in @code{Characters.Latin_1} are not available.
18662
18663 @item
18664 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
18665 equality of representations. They will generally work correctly
18666 for strings and arrays whose elements have integer or enumeration types.
18667 They may not work correctly for arrays whose element
18668 types have user-defined equality, for arrays of real values
18669 (in particular, IEEE-conformant floating point, because of negative
18670 zeroes and NaNs), and for arrays whose elements contain unused bits with
18671 indeterminate values.
18672
18673 @item
18674 The other component-by-component array operations (@code{and}, @code{or},
18675 @code{xor}, @code{not}, and relational tests other than equality)
18676 are not implemented.
18677
18678 @item
18679 @cindex array aggregates (Ada)
18680 @cindex record aggregates (Ada)
18681 @cindex aggregates (Ada)
18682 There is limited support for array and record aggregates. They are
18683 permitted only on the right sides of assignments, as in these examples:
18684
18685 @smallexample
18686 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
18687 (@value{GDBP}) set An_Array := (1, others => 0)
18688 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
18689 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
18690 (@value{GDBP}) set A_Record := (1, "Peter", True);
18691 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
18692 @end smallexample
18693
18694 Changing a
18695 discriminant's value by assigning an aggregate has an
18696 undefined effect if that discriminant is used within the record.
18697 However, you can first modify discriminants by directly assigning to
18698 them (which normally would not be allowed in Ada), and then performing an
18699 aggregate assignment. For example, given a variable @code{A_Rec}
18700 declared to have a type such as:
18701
18702 @smallexample
18703 type Rec (Len : Small_Integer := 0) is record
18704 Id : Integer;
18705 Vals : IntArray (1 .. Len);
18706 end record;
18707 @end smallexample
18708
18709 you can assign a value with a different size of @code{Vals} with two
18710 assignments:
18711
18712 @smallexample
18713 (@value{GDBP}) set A_Rec.Len := 4
18714 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
18715 @end smallexample
18716
18717 As this example also illustrates, @value{GDBN} is very loose about the usual
18718 rules concerning aggregates. You may leave out some of the
18719 components of an array or record aggregate (such as the @code{Len}
18720 component in the assignment to @code{A_Rec} above); they will retain their
18721 original values upon assignment. You may freely use dynamic values as
18722 indices in component associations. You may even use overlapping or
18723 redundant component associations, although which component values are
18724 assigned in such cases is not defined.
18725
18726 @item
18727 Calls to dispatching subprograms are not implemented.
18728
18729 @item
18730 The overloading algorithm is much more limited (i.e., less selective)
18731 than that of real Ada. It makes only limited use of the context in
18732 which a subexpression appears to resolve its meaning, and it is much
18733 looser in its rules for allowing type matches. As a result, some
18734 function calls will be ambiguous, and the user will be asked to choose
18735 the proper resolution.
18736
18737 @item
18738 The @code{new} operator is not implemented.
18739
18740 @item
18741 Entry calls are not implemented.
18742
18743 @item
18744 Aside from printing, arithmetic operations on the native VAX floating-point
18745 formats are not supported.
18746
18747 @item
18748 It is not possible to slice a packed array.
18749
18750 @item
18751 The names @code{True} and @code{False}, when not part of a qualified name,
18752 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
18753 context.
18754 Should your program
18755 redefine these names in a package or procedure (at best a dubious practice),
18756 you will have to use fully qualified names to access their new definitions.
18757
18758 @item
18759 Based real literals are not implemented.
18760 @end itemize
18761
18762 @node Additions to Ada
18763 @subsubsection Additions to Ada
18764 @cindex Ada, deviations from
18765
18766 As it does for other languages, @value{GDBN} makes certain generic
18767 extensions to Ada (@pxref{Expressions}):
18768
18769 @itemize @bullet
18770 @item
18771 If the expression @var{E} is a variable residing in memory (typically
18772 a local variable or array element) and @var{N} is a positive integer,
18773 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18774 @var{N}-1 adjacent variables following it in memory as an array. In
18775 Ada, this operator is generally not necessary, since its prime use is
18776 in displaying parts of an array, and slicing will usually do this in
18777 Ada. However, there are occasional uses when debugging programs in
18778 which certain debugging information has been optimized away.
18779
18780 @item
18781 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18782 appears in function or file @var{B}.'' When @var{B} is a file name,
18783 you must typically surround it in single quotes.
18784
18785 @item
18786 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18787 @var{type} that appears at address @var{addr}.''
18788
18789 @item
18790 A name starting with @samp{$} is a convenience variable
18791 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18792 @end itemize
18793
18794 In addition, @value{GDBN} provides a few other shortcuts and outright
18795 additions specific to Ada:
18796
18797 @itemize @bullet
18798 @item
18799 The assignment statement is allowed as an expression, returning
18800 its right-hand operand as its value. Thus, you may enter
18801
18802 @smallexample
18803 (@value{GDBP}) set x := y + 3
18804 (@value{GDBP}) print A(tmp := y + 1)
18805 @end smallexample
18806
18807 @item
18808 The semicolon is allowed as an ``operator,'' returning as its value
18809 the value of its right-hand operand.
18810 This allows, for example,
18811 complex conditional breaks:
18812
18813 @smallexample
18814 (@value{GDBP}) break f
18815 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18816 @end smallexample
18817
18818 @item
18819 An extension to based literals can be used to specify the exact byte
18820 contents of a floating-point literal. After the base, you can use
18821 from zero to two @samp{l} characters, followed by an @samp{f}. The
18822 number of @samp{l} characters controls the width of the resulting real
18823 constant: zero means @code{Float} is used, one means
18824 @code{Long_Float}, and two means @code{Long_Long_Float}.
18825
18826 @smallexample
18827 (@value{GDBP}) print 16f#41b80000#
18828 $1 = 23.0
18829 @end smallexample
18830
18831 @item
18832 Rather than use catenation and symbolic character names to introduce special
18833 characters into strings, one may instead use a special bracket notation,
18834 which is also used to print strings. A sequence of characters of the form
18835 @samp{["@var{XX}"]} within a string or character literal denotes the
18836 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18837 sequence of characters @samp{["""]} also denotes a single quotation mark
18838 in strings. For example,
18839 @smallexample
18840 "One line.["0a"]Next line.["0a"]"
18841 @end smallexample
18842 @noindent
18843 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18844 after each period.
18845
18846 @item
18847 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18848 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18849 to write
18850
18851 @smallexample
18852 (@value{GDBP}) print 'max(x, y)
18853 @end smallexample
18854
18855 @item
18856 When printing arrays, @value{GDBN} uses positional notation when the
18857 array has a lower bound of 1, and uses a modified named notation otherwise.
18858 For example, a one-dimensional array of three integers with a lower bound
18859 of 3 might print as
18860
18861 @smallexample
18862 (3 => 10, 17, 1)
18863 @end smallexample
18864
18865 @noindent
18866 That is, in contrast to valid Ada, only the first component has a @code{=>}
18867 clause.
18868
18869 @item
18870 You may abbreviate attributes in expressions with any unique,
18871 multi-character subsequence of
18872 their names (an exact match gets preference).
18873 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18874 in place of @t{a'length}.
18875
18876 @item
18877 @cindex quoting Ada internal identifiers
18878 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18879 to lower case. The GNAT compiler uses upper-case characters for
18880 some of its internal identifiers, which are normally of no interest to users.
18881 For the rare occasions when you actually have to look at them,
18882 enclose them in angle brackets to avoid the lower-case mapping.
18883 For example,
18884 @smallexample
18885 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18886 @end smallexample
18887
18888 @item
18889 Printing an object of class-wide type or dereferencing an
18890 access-to-class-wide value will display all the components of the object's
18891 specific type (as indicated by its run-time tag). Likewise, component
18892 selection on such a value will operate on the specific type of the
18893 object.
18894
18895 @end itemize
18896
18897 @node Overloading support for Ada
18898 @subsubsection Overloading support for Ada
18899 @cindex overloading, Ada
18900
18901 The debugger supports limited overloading. Given a subprogram call in which
18902 the function symbol has multiple definitions, it will use the number of
18903 actual parameters and some information about their types to attempt to narrow
18904 the set of definitions. It also makes very limited use of context, preferring
18905 procedures to functions in the context of the @code{call} command, and
18906 functions to procedures elsewhere.
18907
18908 If, after narrowing, the set of matching definitions still contains more than
18909 one definition, @value{GDBN} will display a menu to query which one it should
18910 use, for instance:
18911
18912 @smallexample
18913 (@value{GDBP}) print f(1)
18914 Multiple matches for f
18915 [0] cancel
18916 [1] foo.f (integer) return boolean at foo.adb:23
18917 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18918 >
18919 @end smallexample
18920
18921 In this case, just select one menu entry either to cancel expression evaluation
18922 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18923 instance (type the corresponding number and press @key{RET}).
18924
18925 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18926 case:
18927
18928 @table @code
18929
18930 @kindex set ada print-signatures
18931 @item set ada print-signatures
18932 Control whether parameter types and return types are displayed in overloads
18933 selection menus. It is @code{on} by default.
18934 @xref{Overloading support for Ada}.
18935
18936 @kindex show ada print-signatures
18937 @item show ada print-signatures
18938 Show the current setting for displaying parameter types and return types in
18939 overloads selection menu.
18940 @xref{Overloading support for Ada}.
18941
18942 @end table
18943
18944 @node Stopping Before Main Program
18945 @subsubsection Stopping at the Very Beginning
18946
18947 @cindex breakpointing Ada elaboration code
18948 It is sometimes necessary to debug the program during elaboration, and
18949 before reaching the main procedure.
18950 As defined in the Ada Reference
18951 Manual, the elaboration code is invoked from a procedure called
18952 @code{adainit}. To run your program up to the beginning of
18953 elaboration, simply use the following two commands:
18954 @code{tbreak adainit} and @code{run}.
18955
18956 @node Ada Exceptions
18957 @subsubsection Ada Exceptions
18958
18959 A command is provided to list all Ada exceptions:
18960
18961 @table @code
18962 @kindex info exceptions
18963 @item info exceptions
18964 @itemx info exceptions @var{regexp}
18965 The @code{info exceptions} command allows you to list all Ada exceptions
18966 defined within the program being debugged, as well as their addresses.
18967 With a regular expression, @var{regexp}, as argument, only those exceptions
18968 whose names match @var{regexp} are listed.
18969 @end table
18970
18971 Below is a small example, showing how the command can be used, first
18972 without argument, and next with a regular expression passed as an
18973 argument.
18974
18975 @smallexample
18976 (@value{GDBP}) info exceptions
18977 All defined Ada exceptions:
18978 constraint_error: 0x613da0
18979 program_error: 0x613d20
18980 storage_error: 0x613ce0
18981 tasking_error: 0x613ca0
18982 const.aint_global_e: 0x613b00
18983 (@value{GDBP}) info exceptions const.aint
18984 All Ada exceptions matching regular expression "const.aint":
18985 constraint_error: 0x613da0
18986 const.aint_global_e: 0x613b00
18987 @end smallexample
18988
18989 It is also possible to ask @value{GDBN} to stop your program's execution
18990 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18991
18992 @node Ada Tasks
18993 @subsubsection Extensions for Ada Tasks
18994 @cindex Ada, tasking
18995
18996 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18997 @value{GDBN} provides the following task-related commands:
18998
18999 @table @code
19000 @kindex info tasks
19001 @item info tasks
19002 This command shows a list of current Ada tasks, as in the following example:
19003
19004
19005 @smallexample
19006 @iftex
19007 @leftskip=0.5cm
19008 @end iftex
19009 (@value{GDBP}) info tasks
19010 ID TID P-ID Pri State Name
19011 1 8088000 0 15 Child Activation Wait main_task
19012 2 80a4000 1 15 Accept Statement b
19013 3 809a800 1 15 Child Activation Wait a
19014 * 4 80ae800 3 15 Runnable c
19015
19016 @end smallexample
19017
19018 @noindent
19019 In this listing, the asterisk before the last task indicates it to be the
19020 task currently being inspected.
19021
19022 @table @asis
19023 @item ID
19024 Represents @value{GDBN}'s internal task number.
19025
19026 @item TID
19027 The Ada task ID.
19028
19029 @item P-ID
19030 The parent's task ID (@value{GDBN}'s internal task number).
19031
19032 @item Pri
19033 The base priority of the task.
19034
19035 @item State
19036 Current state of the task.
19037
19038 @table @code
19039 @item Unactivated
19040 The task has been created but has not been activated. It cannot be
19041 executing.
19042
19043 @item Runnable
19044 The task is not blocked for any reason known to Ada. (It may be waiting
19045 for a mutex, though.) It is conceptually "executing" in normal mode.
19046
19047 @item Terminated
19048 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
19049 that were waiting on terminate alternatives have been awakened and have
19050 terminated themselves.
19051
19052 @item Child Activation Wait
19053 The task is waiting for created tasks to complete activation.
19054
19055 @item Accept or Select Term
19056 The task is waiting on an accept or selective wait statement.
19057
19058 @item Waiting on entry call
19059 The task is waiting on an entry call.
19060
19061 @item Async Select Wait
19062 The task is waiting to start the abortable part of an asynchronous
19063 select statement.
19064
19065 @item Delay Sleep
19066 The task is waiting on a select statement with only a delay
19067 alternative open.
19068
19069 @item Child Termination Wait
19070 The task is sleeping having completed a master within itself, and is
19071 waiting for the tasks dependent on that master to become terminated or
19072 waiting on a terminate Phase.
19073
19074 @item Wait Child in Term Alt
19075 The task is sleeping waiting for tasks on terminate alternatives to
19076 finish terminating.
19077
19078 @item Asynchronous Hold
19079 The task has been held by @code{Ada.Asynchronous_Task_Control.Hold_Task}.
19080
19081 @item Activating
19082 The task has been created and is being made runnable.
19083
19084 @item Selective Wait
19085 The task is waiting in a selective wait statement.
19086
19087 @item Accepting RV with @var{taskno}
19088 The task is accepting a rendez-vous with the task @var{taskno}.
19089
19090 @item Waiting on RV with @var{taskno}
19091 The task is waiting for a rendez-vous with the task @var{taskno}.
19092 @end table
19093
19094 @item Name
19095 Name of the task in the program.
19096
19097 @end table
19098
19099 @kindex info task @var{taskno}
19100 @item info task @var{taskno}
19101 This command shows detailed informations on the specified task, as in
19102 the following example:
19103 @smallexample
19104 @iftex
19105 @leftskip=0.5cm
19106 @end iftex
19107 (@value{GDBP}) info tasks
19108 ID TID P-ID Pri State Name
19109 1 8077880 0 15 Child Activation Wait main_task
19110 * 2 807c468 1 15 Runnable task_1
19111 (@value{GDBP}) info task 2
19112 Ada Task: 0x807c468
19113 Name: "task_1"
19114 Thread: 0
19115 LWP: 0x1fac
19116 Parent: 1 ("main_task")
19117 Base Priority: 15
19118 State: Runnable
19119 @end smallexample
19120
19121 @item task
19122 @kindex task@r{ (Ada)}
19123 @cindex current Ada task ID
19124 This command prints the ID and name of the current task.
19125
19126 @smallexample
19127 @iftex
19128 @leftskip=0.5cm
19129 @end iftex
19130 (@value{GDBP}) info tasks
19131 ID TID P-ID Pri State Name
19132 1 8077870 0 15 Child Activation Wait main_task
19133 * 2 807c458 1 15 Runnable some_task
19134 (@value{GDBP}) task
19135 [Current task is 2 "some_task"]
19136 @end smallexample
19137
19138 @item task @var{taskno}
19139 @cindex Ada task switching
19140 This command is like the @code{thread @var{thread-id}}
19141 command (@pxref{Threads}). It switches the context of debugging
19142 from the current task to the given task.
19143
19144 @smallexample
19145 @iftex
19146 @leftskip=0.5cm
19147 @end iftex
19148 (@value{GDBP}) info tasks
19149 ID TID P-ID Pri State Name
19150 1 8077870 0 15 Child Activation Wait main_task
19151 * 2 807c458 1 15 Runnable some_task
19152 (@value{GDBP}) task 1
19153 [Switching to task 1 "main_task"]
19154 #0 0x8067726 in pthread_cond_wait ()
19155 (@value{GDBP}) bt
19156 #0 0x8067726 in pthread_cond_wait ()
19157 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
19158 #2 0x805cb63 in system.task_primitives.operations.sleep ()
19159 #3 0x806153e in system.tasking.stages.activate_tasks ()
19160 #4 0x804aacc in un () at un.adb:5
19161 @end smallexample
19162
19163 @item task apply [@var{task-id-list} | all] [@var{flag}]@dots{} @var{command}
19164 The @code{task apply} command is the Ada tasking analogue of
19165 @code{thread apply} (@pxref{Threads}). It allows you to apply the
19166 named @var{command} to one or more tasks. Specify the tasks that you
19167 want affected using a list of task IDs, or specify @code{all} to apply
19168 to all tasks.
19169
19170 The @var{flag} arguments control what output to produce and how to
19171 handle errors raised when applying @var{command} to a task.
19172 @var{flag} must start with a @code{-} directly followed by one letter
19173 in @code{qcs}. If several flags are provided, they must be given
19174 individually, such as @code{-c -q}.
19175
19176 By default, @value{GDBN} displays some task information before the
19177 output produced by @var{command}, and an error raised during the
19178 execution of a @var{command} will abort @code{task apply}. The
19179 following flags can be used to fine-tune this behavior:
19180
19181 @table @code
19182 @item -c
19183 The flag @code{-c}, which stands for @samp{continue}, causes any
19184 errors in @var{command} to be displayed, and the execution of
19185 @code{task apply} then continues.
19186 @item -s
19187 The flag @code{-s}, which stands for @samp{silent}, causes any errors
19188 or empty output produced by a @var{command} to be silently ignored.
19189 That is, the execution continues, but the task information and errors
19190 are not printed.
19191 @item -q
19192 The flag @code{-q} (@samp{quiet}) disables printing the task
19193 information.
19194 @end table
19195
19196 Flags @code{-c} and @code{-s} cannot be used together.
19197
19198 @item break @var{locspec} task @var{taskno}
19199 @itemx break @var{locspec} task @var{taskno} if @dots{}
19200 @cindex breakpoints and tasks, in Ada
19201 @cindex task breakpoints, in Ada
19202 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
19203 These commands are like the @code{break @dots{} thread @dots{}}
19204 command (@pxref{Thread Stops}). @xref{Location Specifications}, for
19205 the various forms of @var{locspec}.
19206
19207 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
19208 to specify that you only want @value{GDBN} to stop the program when a
19209 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
19210 numeric task identifiers assigned by @value{GDBN}, shown in the first
19211 column of the @samp{info tasks} display.
19212
19213 If you do not specify @samp{task @var{taskno}} when you set a
19214 breakpoint, the breakpoint applies to @emph{all} tasks of your
19215 program.
19216
19217 You can use the @code{task} qualifier on conditional breakpoints as
19218 well; in this case, place @samp{task @var{taskno}} before the
19219 breakpoint condition (before the @code{if}).
19220
19221 For example,
19222
19223 @smallexample
19224 @iftex
19225 @leftskip=0.5cm
19226 @end iftex
19227 (@value{GDBP}) info tasks
19228 ID TID P-ID Pri State Name
19229 1 140022020 0 15 Child Activation Wait main_task
19230 2 140045060 1 15 Accept/Select Wait t2
19231 3 140044840 1 15 Runnable t1
19232 * 4 140056040 1 15 Runnable t3
19233 (@value{GDBP}) b 15 task 2
19234 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
19235 (@value{GDBP}) cont
19236 Continuing.
19237 task # 1 running
19238 task # 2 running
19239
19240 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
19241 15 flush;
19242 (@value{GDBP}) info tasks
19243 ID TID P-ID Pri State Name
19244 1 140022020 0 15 Child Activation Wait main_task
19245 * 2 140045060 1 15 Runnable t2
19246 3 140044840 1 15 Runnable t1
19247 4 140056040 1 15 Delay Sleep t3
19248 @end smallexample
19249 @end table
19250
19251 @node Ada Tasks and Core Files
19252 @subsubsection Tasking Support when Debugging Core Files
19253 @cindex Ada tasking and core file debugging
19254
19255 When inspecting a core file, as opposed to debugging a live program,
19256 tasking support may be limited or even unavailable, depending on
19257 the platform being used.
19258 For instance, on x86-linux, the list of tasks is available, but task
19259 switching is not supported.
19260
19261 On certain platforms, the debugger needs to perform some
19262 memory writes in order to provide Ada tasking support. When inspecting
19263 a core file, this means that the core file must be opened with read-write
19264 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
19265 Under these circumstances, you should make a backup copy of the core
19266 file before inspecting it with @value{GDBN}.
19267
19268 @node Ravenscar Profile
19269 @subsubsection Tasking Support when using the Ravenscar Profile
19270 @cindex Ravenscar Profile
19271
19272 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
19273 specifically designed for systems with safety-critical real-time
19274 requirements.
19275
19276 @table @code
19277 @kindex set ravenscar task-switching on
19278 @cindex task switching with program using Ravenscar Profile
19279 @item set ravenscar task-switching on
19280 Allows task switching when debugging a program that uses the Ravenscar
19281 Profile. This is the default.
19282
19283 @kindex set ravenscar task-switching off
19284 @item set ravenscar task-switching off
19285 Turn off task switching when debugging a program that uses the Ravenscar
19286 Profile. This is mostly intended to disable the code that adds support
19287 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
19288 the Ravenscar runtime is preventing @value{GDBN} from working properly.
19289 To be effective, this command should be run before the program is started.
19290
19291 @kindex show ravenscar task-switching
19292 @item show ravenscar task-switching
19293 Show whether it is possible to switch from task to task in a program
19294 using the Ravenscar Profile.
19295
19296 @end table
19297
19298 @cindex Ravenscar thread
19299 When Ravenscar task-switching is enabled, Ravenscar tasks are
19300 announced by @value{GDBN} as if they were threads:
19301
19302 @smallexample
19303 (gdb) continue
19304 [New Ravenscar Thread 0x2b8f0]
19305 @end smallexample
19306
19307 Both Ravenscar tasks and the underlying CPU threads will show up in
19308 the output of @code{info threads}:
19309
19310 @smallexample
19311 (gdb) info threads
19312 Id Target Id Frame
19313 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
19314 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
19315 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
19316 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
19317 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
19318 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
19319 @end smallexample
19320
19321 One known limitation of the Ravenscar support in @value{GDBN} is that
19322 it isn't currently possible to single-step through the runtime
19323 initialization sequence. If you need to debug this code, you should
19324 use @code{set ravenscar task-switching off}.
19325
19326 @node Ada Source Character Set
19327 @subsubsection Ada Source Character Set
19328 @cindex Ada, source character set
19329
19330 The GNAT compiler supports a number of character sets for source
19331 files. @xref{Character Set Control, , Character Set Control,
19332 gnat_ugn}. @value{GDBN} includes support for this as well.
19333
19334 @table @code
19335 @item set ada source-charset @var{charset}
19336 @kindex set ada source-charset
19337 Set the source character set for Ada. The character set must be
19338 supported by GNAT. Because this setting affects the decoding of
19339 symbols coming from the debug information in your program, the setting
19340 should be set as early as possible. The default is @code{ISO-8859-1},
19341 because that is also GNAT's default.
19342
19343 @item show ada source-charset
19344 @kindex show ada source-charset
19345 Show the current source character set for Ada.
19346 @end table
19347
19348 @node Ada Glitches
19349 @subsubsection Known Peculiarities of Ada Mode
19350 @cindex Ada, problems
19351
19352 Besides the omissions listed previously (@pxref{Omissions from Ada}),
19353 we know of several problems with and limitations of Ada mode in
19354 @value{GDBN},
19355 some of which will be fixed with planned future releases of the debugger
19356 and the GNU Ada compiler.
19357
19358 @itemize @bullet
19359 @item
19360 Static constants that the compiler chooses not to materialize as objects in
19361 storage are invisible to the debugger.
19362
19363 @item
19364 Named parameter associations in function argument lists are ignored (the
19365 argument lists are treated as positional).
19366
19367 @item
19368 Many useful library packages are currently invisible to the debugger.
19369
19370 @item
19371 Fixed-point arithmetic, conversions, input, and output is carried out using
19372 floating-point arithmetic, and may give results that only approximate those on
19373 the host machine.
19374
19375 @item
19376 The GNAT compiler never generates the prefix @code{Standard} for any of
19377 the standard symbols defined by the Ada language. @value{GDBN} knows about
19378 this: it will strip the prefix from names when you use it, and will never
19379 look for a name you have so qualified among local symbols, nor match against
19380 symbols in other packages or subprograms. If you have
19381 defined entities anywhere in your program other than parameters and
19382 local variables whose simple names match names in @code{Standard},
19383 GNAT's lack of qualification here can cause confusion. When this happens,
19384 you can usually resolve the confusion
19385 by qualifying the problematic names with package
19386 @code{Standard} explicitly.
19387 @end itemize
19388
19389 Older versions of the compiler sometimes generate erroneous debugging
19390 information, resulting in the debugger incorrectly printing the value
19391 of affected entities. In some cases, the debugger is able to work
19392 around an issue automatically. In other cases, the debugger is able
19393 to work around the issue, but the work-around has to be specifically
19394 enabled.
19395
19396 @kindex set ada trust-PAD-over-XVS
19397 @kindex show ada trust-PAD-over-XVS
19398 @table @code
19399
19400 @item set ada trust-PAD-over-XVS on
19401 Configure GDB to strictly follow the GNAT encoding when computing the
19402 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
19403 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
19404 a complete description of the encoding used by the GNAT compiler).
19405 This is the default.
19406
19407 @item set ada trust-PAD-over-XVS off
19408 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
19409 sometimes prints the wrong value for certain entities, changing @code{ada
19410 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
19411 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
19412 @code{off}, but this incurs a slight performance penalty, so it is
19413 recommended to leave this setting to @code{on} unless necessary.
19414
19415 @end table
19416
19417 @cindex GNAT descriptive types
19418 @cindex GNAT encoding
19419 Internally, the debugger also relies on the compiler following a number
19420 of conventions known as the @samp{GNAT Encoding}, all documented in
19421 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
19422 how the debugging information should be generated for certain types.
19423 In particular, this convention makes use of @dfn{descriptive types},
19424 which are artificial types generated purely to help the debugger.
19425
19426 These encodings were defined at a time when the debugging information
19427 format used was not powerful enough to describe some of the more complex
19428 types available in Ada. Since DWARF allows us to express nearly all
19429 Ada features, the long-term goal is to slowly replace these descriptive
19430 types by their pure DWARF equivalent. To facilitate that transition,
19431 a new maintenance option is available to force the debugger to ignore
19432 those descriptive types. It allows the user to quickly evaluate how
19433 well @value{GDBN} works without them.
19434
19435 @table @code
19436
19437 @kindex maint ada set ignore-descriptive-types
19438 @item maintenance ada set ignore-descriptive-types [on|off]
19439 Control whether the debugger should ignore descriptive types.
19440 The default is not to ignore descriptives types (@code{off}).
19441
19442 @kindex maint ada show ignore-descriptive-types
19443 @item maintenance ada show ignore-descriptive-types
19444 Show if descriptive types are ignored by @value{GDBN}.
19445
19446 @end table
19447
19448 @node Unsupported Languages
19449 @section Unsupported Languages
19450
19451 @cindex unsupported languages
19452 @cindex minimal language
19453 In addition to the other fully-supported programming languages,
19454 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
19455 It does not represent a real programming language, but provides a set
19456 of capabilities close to what the C or assembly languages provide.
19457 This should allow most simple operations to be performed while debugging
19458 an application that uses a language currently not supported by @value{GDBN}.
19459
19460 If the language is set to @code{auto}, @value{GDBN} will automatically
19461 select this language if the current frame corresponds to an unsupported
19462 language.
19463
19464 @node Symbols
19465 @chapter Examining the Symbol Table
19466
19467 The commands described in this chapter allow you to inquire about the
19468 symbols (names of variables, functions and types) defined in your
19469 program. This information is inherent in the text of your program and
19470 does not change as your program executes. @value{GDBN} finds it in your
19471 program's symbol table, in the file indicated when you started @value{GDBN}
19472 (@pxref{File Options, ,Choosing Files}), or by one of the
19473 file-management commands (@pxref{Files, ,Commands to Specify Files}).
19474
19475 @cindex symbol names
19476 @cindex names of symbols
19477 @cindex quoting names
19478 @anchor{quoting names}
19479 Occasionally, you may need to refer to symbols that contain unusual
19480 characters, which @value{GDBN} ordinarily treats as word delimiters. The
19481 most frequent case is in referring to static variables in other
19482 source files (@pxref{Variables,,Program Variables}). File names
19483 are recorded in object files as debugging symbols, but @value{GDBN} would
19484 ordinarily parse a typical file name, like @file{foo.c}, as the three words
19485 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
19486 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
19487
19488 @smallexample
19489 p 'foo.c'::x
19490 @end smallexample
19491
19492 @noindent
19493 looks up the value of @code{x} in the scope of the file @file{foo.c}.
19494
19495 @table @code
19496 @cindex case-insensitive symbol names
19497 @cindex case sensitivity in symbol names
19498 @kindex set case-sensitive
19499 @item set case-sensitive on
19500 @itemx set case-sensitive off
19501 @itemx set case-sensitive auto
19502 Normally, when @value{GDBN} looks up symbols, it matches their names
19503 with case sensitivity determined by the current source language.
19504 Occasionally, you may wish to control that. The command @code{set
19505 case-sensitive} lets you do that by specifying @code{on} for
19506 case-sensitive matches or @code{off} for case-insensitive ones. If
19507 you specify @code{auto}, case sensitivity is reset to the default
19508 suitable for the source language. The default is case-sensitive
19509 matches for all languages except for Fortran, for which the default is
19510 case-insensitive matches.
19511
19512 @kindex show case-sensitive
19513 @item show case-sensitive
19514 This command shows the current setting of case sensitivity for symbols
19515 lookups.
19516
19517 @kindex set print type methods
19518 @item set print type methods
19519 @itemx set print type methods on
19520 @itemx set print type methods off
19521 Normally, when @value{GDBN} prints a class, it displays any methods
19522 declared in that class. You can control this behavior either by
19523 passing the appropriate flag to @code{ptype}, or using @command{set
19524 print type methods}. Specifying @code{on} will cause @value{GDBN} to
19525 display the methods; this is the default. Specifying @code{off} will
19526 cause @value{GDBN} to omit the methods.
19527
19528 @kindex show print type methods
19529 @item show print type methods
19530 This command shows the current setting of method display when printing
19531 classes.
19532
19533 @kindex set print type nested-type-limit
19534 @item set print type nested-type-limit @var{limit}
19535 @itemx set print type nested-type-limit unlimited
19536 Set the limit of displayed nested types that the type printer will
19537 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
19538 nested definitions. By default, the type printer will not show any nested
19539 types defined in classes.
19540
19541 @kindex show print type nested-type-limit
19542 @item show print type nested-type-limit
19543 This command shows the current display limit of nested types when
19544 printing classes.
19545
19546 @kindex set print type typedefs
19547 @item set print type typedefs
19548 @itemx set print type typedefs on
19549 @itemx set print type typedefs off
19550
19551 Normally, when @value{GDBN} prints a class, it displays any typedefs
19552 defined in that class. You can control this behavior either by
19553 passing the appropriate flag to @code{ptype}, or using @command{set
19554 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
19555 display the typedef definitions; this is the default. Specifying
19556 @code{off} will cause @value{GDBN} to omit the typedef definitions.
19557 Note that this controls whether the typedef definition itself is
19558 printed, not whether typedef names are substituted when printing other
19559 types.
19560
19561 @kindex show print type typedefs
19562 @item show print type typedefs
19563 This command shows the current setting of typedef display when
19564 printing classes.
19565
19566 @kindex set print type hex
19567 @item set print type hex
19568 @itemx set print type hex on
19569 @itemx set print type hex off
19570
19571 When @value{GDBN} prints sizes and offsets of struct members, it can use
19572 either the decimal or hexadecimal notation. You can select one or the
19573 other either by passing the appropriate flag to @code{ptype}, or by using
19574 the @command{set print type hex} command.
19575
19576 @kindex show print type hex
19577 @item show print type hex
19578 This command shows whether the sizes and offsets of struct members are
19579 printed in decimal or hexadecimal notation.
19580
19581 @kindex info address
19582 @cindex address of a symbol
19583 @item info address @var{symbol}
19584 Describe where the data for @var{symbol} is stored. For a register
19585 variable, this says which register it is kept in. For a non-register
19586 local variable, this prints the stack-frame offset at which the variable
19587 is always stored.
19588
19589 Note the contrast with @samp{print &@var{symbol}}, which does not work
19590 at all for a register variable, and for a stack local variable prints
19591 the exact address of the current instantiation of the variable.
19592
19593 @kindex info symbol
19594 @cindex symbol from address
19595 @cindex closest symbol and offset for an address
19596 @item info symbol @var{addr}
19597 Print the name of a symbol which is stored at the address @var{addr}.
19598 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
19599 nearest symbol and an offset from it:
19600
19601 @smallexample
19602 (@value{GDBP}) info symbol 0x54320
19603 _initialize_vx + 396 in section .text
19604 @end smallexample
19605
19606 @noindent
19607 This is the opposite of the @code{info address} command. You can use
19608 it to find out the name of a variable or a function given its address.
19609
19610 For dynamically linked executables, the name of executable or shared
19611 library containing the symbol is also printed:
19612
19613 @smallexample
19614 (@value{GDBP}) info symbol 0x400225
19615 _start + 5 in section .text of /tmp/a.out
19616 (@value{GDBP}) info symbol 0x2aaaac2811cf
19617 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
19618 @end smallexample
19619
19620 @kindex demangle
19621 @cindex demangle
19622 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
19623 Demangle @var{name}.
19624 If @var{language} is provided it is the name of the language to demangle
19625 @var{name} in. Otherwise @var{name} is demangled in the current language.
19626
19627 The @samp{--} option specifies the end of options,
19628 and is useful when @var{name} begins with a dash.
19629
19630 The parameter @code{demangle-style} specifies how to interpret the kind
19631 of mangling used. @xref{Print Settings}.
19632
19633 @kindex whatis
19634 @item whatis[/@var{flags}] [@var{arg}]
19635 Print the data type of @var{arg}, which can be either an expression
19636 or a name of a data type. With no argument, print the data type of
19637 @code{$}, the last value in the value history.
19638
19639 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
19640 is not actually evaluated, and any side-effecting operations (such as
19641 assignments or function calls) inside it do not take place.
19642
19643 If @var{arg} is a variable or an expression, @code{whatis} prints its
19644 literal type as it is used in the source code. If the type was
19645 defined using a @code{typedef}, @code{whatis} will @emph{not} print
19646 the data type underlying the @code{typedef}. If the type of the
19647 variable or the expression is a compound data type, such as
19648 @code{struct} or @code{class}, @code{whatis} never prints their
19649 fields or methods. It just prints the @code{struct}/@code{class}
19650 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
19651 such a compound data type, use @code{ptype}.
19652
19653 If @var{arg} is a type name that was defined using @code{typedef},
19654 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
19655 Unrolling means that @code{whatis} will show the underlying type used
19656 in the @code{typedef} declaration of @var{arg}. However, if that
19657 underlying type is also a @code{typedef}, @code{whatis} will not
19658 unroll it.
19659
19660 For C code, the type names may also have the form @samp{class
19661 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
19662 @var{union-tag}} or @samp{enum @var{enum-tag}}.
19663
19664 @var{flags} can be used to modify how the type is displayed.
19665 Available flags are:
19666
19667 @table @code
19668 @item r
19669 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
19670 parameters and typedefs defined in a class when printing the class'
19671 members. The @code{/r} flag disables this.
19672
19673 @item m
19674 Do not print methods defined in the class.
19675
19676 @item M
19677 Print methods defined in the class. This is the default, but the flag
19678 exists in case you change the default with @command{set print type methods}.
19679
19680 @item t
19681 Do not print typedefs defined in the class. Note that this controls
19682 whether the typedef definition itself is printed, not whether typedef
19683 names are substituted when printing other types.
19684
19685 @item T
19686 Print typedefs defined in the class. This is the default, but the flag
19687 exists in case you change the default with @command{set print type typedefs}.
19688
19689 @item o
19690 Print the offsets and sizes of fields in a struct, similar to what the
19691 @command{pahole} tool does. This option implies the @code{/tm} flags.
19692
19693 @item x
19694 Use hexadecimal notation when printing offsets and sizes of fields in a
19695 struct.
19696
19697 @item d
19698 Use decimal notation when printing offsets and sizes of fields in a
19699 struct.
19700
19701 For example, given the following declarations:
19702
19703 @smallexample
19704 struct tuv
19705 @{
19706 int a1;
19707 char *a2;
19708 int a3;
19709 @};
19710
19711 struct xyz
19712 @{
19713 int f1;
19714 char f2;
19715 void *f3;
19716 struct tuv f4;
19717 @};
19718
19719 union qwe
19720 @{
19721 struct tuv fff1;
19722 struct xyz fff2;
19723 @};
19724
19725 struct tyu
19726 @{
19727 int a1 : 1;
19728 int a2 : 3;
19729 int a3 : 23;
19730 char a4 : 2;
19731 int64_t a5;
19732 int a6 : 5;
19733 int64_t a7 : 3;
19734 @};
19735 @end smallexample
19736
19737 Issuing a @kbd{ptype /o struct tuv} command would print:
19738
19739 @smallexample
19740 (@value{GDBP}) ptype /o struct tuv
19741 /* offset | size */ type = struct tuv @{
19742 /* 0 | 4 */ int a1;
19743 /* XXX 4-byte hole */
19744 /* 8 | 8 */ char *a2;
19745 /* 16 | 4 */ int a3;
19746
19747 /* total size (bytes): 24 */
19748 @}
19749 @end smallexample
19750
19751 Notice the format of the first column of comments. There, you can
19752 find two parts separated by the @samp{|} character: the @emph{offset},
19753 which indicates where the field is located inside the struct, in
19754 bytes, and the @emph{size} of the field. Another interesting line is
19755 the marker of a @emph{hole} in the struct, indicating that it may be
19756 possible to pack the struct and make it use less space by reorganizing
19757 its fields.
19758
19759 It is also possible to print offsets inside an union:
19760
19761 @smallexample
19762 (@value{GDBP}) ptype /o union qwe
19763 /* offset | size */ type = union qwe @{
19764 /* 24 */ struct tuv @{
19765 /* 0 | 4 */ int a1;
19766 /* XXX 4-byte hole */
19767 /* 8 | 8 */ char *a2;
19768 /* 16 | 4 */ int a3;
19769
19770 /* total size (bytes): 24 */
19771 @} fff1;
19772 /* 40 */ struct xyz @{
19773 /* 0 | 4 */ int f1;
19774 /* 4 | 1 */ char f2;
19775 /* XXX 3-byte hole */
19776 /* 8 | 8 */ void *f3;
19777 /* 16 | 24 */ struct tuv @{
19778 /* 16 | 4 */ int a1;
19779 /* XXX 4-byte hole */
19780 /* 24 | 8 */ char *a2;
19781 /* 32 | 4 */ int a3;
19782
19783 /* total size (bytes): 24 */
19784 @} f4;
19785
19786 /* total size (bytes): 40 */
19787 @} fff2;
19788
19789 /* total size (bytes): 40 */
19790 @}
19791 @end smallexample
19792
19793 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
19794 same space (because we are dealing with an union), the offset is not
19795 printed for them. However, you can still examine the offset of each
19796 of these structures' fields.
19797
19798 Another useful scenario is printing the offsets of a struct containing
19799 bitfields:
19800
19801 @smallexample
19802 (@value{GDBP}) ptype /o struct tyu
19803 /* offset | size */ type = struct tyu @{
19804 /* 0:31 | 4 */ int a1 : 1;
19805 /* 0:28 | 4 */ int a2 : 3;
19806 /* 0: 5 | 4 */ int a3 : 23;
19807 /* 3: 3 | 1 */ signed char a4 : 2;
19808 /* XXX 3-bit hole */
19809 /* XXX 4-byte hole */
19810 /* 8 | 8 */ int64_t a5;
19811 /* 16: 0 | 4 */ int a6 : 5;
19812 /* 16: 5 | 8 */ int64_t a7 : 3;
19813 /* XXX 7-byte padding */
19814
19815 /* total size (bytes): 24 */
19816 @}
19817 @end smallexample
19818
19819 Note how the offset information is now extended to also include the
19820 first bit of the bitfield.
19821 @end table
19822
19823 @kindex ptype
19824 @item ptype[/@var{flags}] [@var{arg}]
19825 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
19826 detailed description of the type, instead of just the name of the type.
19827 @xref{Expressions, ,Expressions}.
19828
19829 Contrary to @code{whatis}, @code{ptype} always unrolls any
19830 @code{typedef}s in its argument declaration, whether the argument is
19831 a variable, expression, or a data type. This means that @code{ptype}
19832 of a variable or an expression will not print literally its type as
19833 present in the source code---use @code{whatis} for that. @code{typedef}s at
19834 the pointer or reference targets are also unrolled. Only @code{typedef}s of
19835 fields, methods and inner @code{class typedef}s of @code{struct}s,
19836 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
19837
19838 For example, for this variable declaration:
19839
19840 @smallexample
19841 typedef double real_t;
19842 struct complex @{ real_t real; double imag; @};
19843 typedef struct complex complex_t;
19844 complex_t var;
19845 real_t *real_pointer_var;
19846 @end smallexample
19847
19848 @noindent
19849 the two commands give this output:
19850
19851 @smallexample
19852 @group
19853 (@value{GDBP}) whatis var
19854 type = complex_t
19855 (@value{GDBP}) ptype var
19856 type = struct complex @{
19857 real_t real;
19858 double imag;
19859 @}
19860 (@value{GDBP}) whatis complex_t
19861 type = struct complex
19862 (@value{GDBP}) whatis struct complex
19863 type = struct complex
19864 (@value{GDBP}) ptype struct complex
19865 type = struct complex @{
19866 real_t real;
19867 double imag;
19868 @}
19869 (@value{GDBP}) whatis real_pointer_var
19870 type = real_t *
19871 (@value{GDBP}) ptype real_pointer_var
19872 type = double *
19873 @end group
19874 @end smallexample
19875
19876 @noindent
19877 As with @code{whatis}, using @code{ptype} without an argument refers to
19878 the type of @code{$}, the last value in the value history.
19879
19880 @cindex incomplete type
19881 Sometimes, programs use opaque data types or incomplete specifications
19882 of complex data structure. If the debug information included in the
19883 program does not allow @value{GDBN} to display a full declaration of
19884 the data type, it will say @samp{<incomplete type>}. For example,
19885 given these declarations:
19886
19887 @smallexample
19888 struct foo;
19889 struct foo *fooptr;
19890 @end smallexample
19891
19892 @noindent
19893 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19894
19895 @smallexample
19896 (@value{GDBP}) ptype foo
19897 $1 = <incomplete type>
19898 @end smallexample
19899
19900 @noindent
19901 ``Incomplete type'' is C terminology for data types that are not
19902 completely specified.
19903
19904 @cindex unknown type
19905 Othertimes, information about a variable's type is completely absent
19906 from the debug information included in the program. This most often
19907 happens when the program or library where the variable is defined
19908 includes no debug information at all. @value{GDBN} knows the variable
19909 exists from inspecting the linker/loader symbol table (e.g., the ELF
19910 dynamic symbol table), but such symbols do not contain type
19911 information. Inspecting the type of a (global) variable for which
19912 @value{GDBN} has no type information shows:
19913
19914 @smallexample
19915 (@value{GDBP}) ptype var
19916 type = <data variable, no debug info>
19917 @end smallexample
19918
19919 @xref{Variables, no debug info variables}, for how to print the values
19920 of such variables.
19921
19922 @kindex info types
19923 @item info types [-q] [@var{regexp}]
19924 Print a brief description of all types whose names match the regular
19925 expression @var{regexp} (or all types in your program, if you supply
19926 no argument). Each complete typename is matched as though it were a
19927 complete line; thus, @samp{i type value} gives information on all
19928 types in your program whose names include the string @code{value}, but
19929 @samp{i type ^value$} gives information only on types whose complete
19930 name is @code{value}.
19931
19932 In programs using different languages, @value{GDBN} chooses the syntax
19933 to print the type description according to the
19934 @samp{set language} value: using @samp{set language auto}
19935 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19936 language of the type, other values mean to use
19937 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19938
19939 This command differs from @code{ptype} in two ways: first, like
19940 @code{whatis}, it does not print a detailed description; second, it
19941 lists all source files and line numbers where a type is defined.
19942
19943 The output from @samp{into types} is proceeded with a header line
19944 describing what types are being listed. The optional flag @samp{-q},
19945 which stands for @samp{quiet}, disables printing this header
19946 information.
19947
19948 @kindex info type-printers
19949 @item info type-printers
19950 Versions of @value{GDBN} that ship with Python scripting enabled may
19951 have ``type printers'' available. When using @command{ptype} or
19952 @command{whatis}, these printers are consulted when the name of a type
19953 is needed. @xref{Type Printing API}, for more information on writing
19954 type printers.
19955
19956 @code{info type-printers} displays all the available type printers.
19957
19958 @kindex enable type-printer
19959 @kindex disable type-printer
19960 @item enable type-printer @var{name}@dots{}
19961 @item disable type-printer @var{name}@dots{}
19962 These commands can be used to enable or disable type printers.
19963
19964 @kindex info scope
19965 @cindex local variables
19966 @item info scope @var{locspec}
19967 List all the variables local to the lexical scope of the code location
19968 that results from resolving @var{locspec}. @xref{Location
19969 Specifications}, for details about supported forms of @var{locspec}.
19970 For example:
19971
19972 @smallexample
19973 (@value{GDBP}) @b{info scope command_line_handler}
19974 Scope for command_line_handler:
19975 Symbol rl is an argument at stack/frame offset 8, length 4.
19976 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19977 Symbol linelength is in static storage at address 0x150a1c, length 4.
19978 Symbol p is a local variable in register $esi, length 4.
19979 Symbol p1 is a local variable in register $ebx, length 4.
19980 Symbol nline is a local variable in register $edx, length 4.
19981 Symbol repeat is a local variable at frame offset -8, length 4.
19982 @end smallexample
19983
19984 @noindent
19985 This command is especially useful for determining what data to collect
19986 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19987 collect}.
19988
19989 @kindex info source
19990 @item info source
19991 Show information about the current source file---that is, the source file for
19992 the function containing the current point of execution:
19993 @itemize @bullet
19994 @item
19995 the name of the source file, and the directory containing it,
19996 @item
19997 the directory it was compiled in,
19998 @item
19999 its length, in lines,
20000 @item
20001 which programming language it is written in,
20002 @item
20003 if the debug information provides it, the program that compiled the file
20004 (which may include, e.g., the compiler version and command line arguments),
20005 @item
20006 whether the executable includes debugging information for that file, and
20007 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
20008 @item
20009 whether the debugging information includes information about
20010 preprocessor macros.
20011 @end itemize
20012
20013
20014 @kindex info sources
20015 @item info sources @r{[}-dirname | -basename@r{]} @r{[}--@r{]} @r{[}@var{regexp}@r{]}
20016
20017
20018 With no options @samp{info sources} prints the names of all source
20019 files in your program for which there is debugging information. The
20020 source files are presented based on a list of object files
20021 (executables and libraries) currently loaded into @value{GDBN}. For
20022 each object file all of the associated source files are listed.
20023
20024 Each source file will only be printed once for each object file, but a
20025 single source file can be repeated in the output if it is part of
20026 multiple object files.
20027
20028 If the optional @var{regexp} is provided, then only source files that
20029 match the regular expression will be printed. The matching is
20030 case-sensitive, except on operating systems that have case-insensitive
20031 filesystem (e.g., MS-Windows). @samp{--} can be used before
20032 @var{regexp} to prevent @value{GDBN} interpreting @var{regexp} as a
20033 command option (e.g. if @var{regexp} starts with @samp{-}).
20034
20035 By default, the @var{regexp} is used to match anywhere in the
20036 filename. If @code{-dirname}, only files having a dirname matching
20037 @var{regexp} are shown. If @code{-basename}, only files having a
20038 basename matching @var{regexp} are shown.
20039
20040 It is possible that an object file may be printed in the list with no
20041 associated source files. This can happen when either no source files
20042 match @var{regexp}, or, the object file was compiled without debug
20043 information and so @value{GDBN} is unable to find any source file
20044 names.
20045
20046 @kindex info functions
20047 @item info functions [-q] [-n]
20048 Print the names and data types of all defined functions.
20049 Similarly to @samp{info types}, this command groups its output by source
20050 files and annotates each function definition with its source line
20051 number.
20052
20053 In programs using different languages, @value{GDBN} chooses the syntax
20054 to print the function name and type according to the
20055 @samp{set language} value: using @samp{set language auto}
20056 (see @ref{Automatically, ,Set Language Automatically}) means to use the
20057 language of the function, other values mean to use
20058 the manually specified language (see @ref{Manually, ,Set Language Manually}).
20059
20060 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
20061 results. A non-debugging symbol is a symbol that comes from the
20062 executable's symbol table, not from the debug information (for
20063 example, DWARF) associated with the executable.
20064
20065 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
20066 printing header information and messages explaining why no functions
20067 have been printed.
20068
20069 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
20070 Like @samp{info functions}, but only print the names and data types
20071 of the functions selected with the provided regexp(s).
20072
20073 If @var{regexp} is provided, print only the functions whose names
20074 match the regular expression @var{regexp}.
20075 Thus, @samp{info fun step} finds all functions whose
20076 names include @code{step}; @samp{info fun ^step} finds those whose names
20077 start with @code{step}. If a function name contains characters that
20078 conflict with the regular expression language (e.g.@:
20079 @samp{operator*()}), they may be quoted with a backslash.
20080
20081 If @var{type_regexp} is provided, print only the functions whose
20082 types, as printed by the @code{whatis} command, match
20083 the regular expression @var{type_regexp}.
20084 If @var{type_regexp} contains space(s), it should be enclosed in
20085 quote characters. If needed, use backslash to escape the meaning
20086 of special characters or quotes.
20087 Thus, @samp{info fun -t '^int ('} finds the functions that return
20088 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
20089 have an argument type containing int; @samp{info fun -t '^int (' ^step}
20090 finds the functions whose names start with @code{step} and that return
20091 int.
20092
20093 If both @var{regexp} and @var{type_regexp} are provided, a function
20094 is printed only if its name matches @var{regexp} and its type matches
20095 @var{type_regexp}.
20096
20097
20098 @kindex info variables
20099 @item info variables [-q] [-n]
20100 Print the names and data types of all variables that are defined
20101 outside of functions (i.e.@: excluding local variables).
20102 The printed variables are grouped by source files and annotated with
20103 their respective source line numbers.
20104
20105 In programs using different languages, @value{GDBN} chooses the syntax
20106 to print the variable name and type according to the
20107 @samp{set language} value: using @samp{set language auto}
20108 (see @ref{Automatically, ,Set Language Automatically}) means to use the
20109 language of the variable, other values mean to use
20110 the manually specified language (see @ref{Manually, ,Set Language Manually}).
20111
20112 The @samp{-n} flag excludes non-debugging symbols from the results.
20113
20114 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
20115 printing header information and messages explaining why no variables
20116 have been printed.
20117
20118 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
20119 Like @kbd{info variables}, but only print the variables selected
20120 with the provided regexp(s).
20121
20122 If @var{regexp} is provided, print only the variables whose names
20123 match the regular expression @var{regexp}.
20124
20125 If @var{type_regexp} is provided, print only the variables whose
20126 types, as printed by the @code{whatis} command, match
20127 the regular expression @var{type_regexp}.
20128 If @var{type_regexp} contains space(s), it should be enclosed in
20129 quote characters. If needed, use backslash to escape the meaning
20130 of special characters or quotes.
20131
20132 If both @var{regexp} and @var{type_regexp} are provided, an argument
20133 is printed only if its name matches @var{regexp} and its type matches
20134 @var{type_regexp}.
20135
20136 @kindex info modules
20137 @cindex modules
20138 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
20139 List all Fortran modules in the program, or all modules matching the
20140 optional regular expression @var{regexp}.
20141
20142 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
20143 printing header information and messages explaining why no modules
20144 have been printed.
20145
20146 @kindex info module
20147 @cindex Fortran modules, information about
20148 @cindex functions and variables by Fortran module
20149 @cindex module functions and variables
20150 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
20151 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
20152 List all functions or variables within all Fortran modules. The set
20153 of functions or variables listed can be limited by providing some or
20154 all of the optional regular expressions. If @var{module-regexp} is
20155 provided, then only Fortran modules matching @var{module-regexp} will
20156 be searched. Only functions or variables whose type matches the
20157 optional regular expression @var{type-regexp} will be listed. And
20158 only functions or variables whose name matches the optional regular
20159 expression @var{regexp} will be listed.
20160
20161 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
20162 printing header information and messages explaining why no functions
20163 or variables have been printed.
20164
20165 @kindex info classes
20166 @cindex Objective-C, classes and selectors
20167 @item info classes
20168 @itemx info classes @var{regexp}
20169 Display all Objective-C classes in your program, or
20170 (with the @var{regexp} argument) all those matching a particular regular
20171 expression.
20172
20173 @kindex info selectors
20174 @item info selectors
20175 @itemx info selectors @var{regexp}
20176 Display all Objective-C selectors in your program, or
20177 (with the @var{regexp} argument) all those matching a particular regular
20178 expression.
20179
20180 @ignore
20181 This was never implemented.
20182 @kindex info methods
20183 @item info methods
20184 @itemx info methods @var{regexp}
20185 The @code{info methods} command permits the user to examine all defined
20186 methods within C@t{++} program, or (with the @var{regexp} argument) a
20187 specific set of methods found in the various C@t{++} classes. Many
20188 C@t{++} classes provide a large number of methods. Thus, the output
20189 from the @code{ptype} command can be overwhelming and hard to use. The
20190 @code{info-methods} command filters the methods, printing only those
20191 which match the regular-expression @var{regexp}.
20192 @end ignore
20193
20194 @cindex opaque data types
20195 @kindex set opaque-type-resolution
20196 @item set opaque-type-resolution on
20197 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
20198 declared as a pointer to a @code{struct}, @code{class}, or
20199 @code{union}---for example, @code{struct MyType *}---that is used in one
20200 source file although the full declaration of @code{struct MyType} is in
20201 another source file. The default is on.
20202
20203 A change in the setting of this subcommand will not take effect until
20204 the next time symbols for a file are loaded.
20205
20206 @item set opaque-type-resolution off
20207 Tell @value{GDBN} not to resolve opaque types. In this case, the type
20208 is printed as follows:
20209 @smallexample
20210 @{<no data fields>@}
20211 @end smallexample
20212
20213 @kindex show opaque-type-resolution
20214 @item show opaque-type-resolution
20215 Show whether opaque types are resolved or not.
20216
20217 @kindex set print symbol-loading
20218 @cindex print messages when symbols are loaded
20219 @item set print symbol-loading
20220 @itemx set print symbol-loading full
20221 @itemx set print symbol-loading brief
20222 @itemx set print symbol-loading off
20223 The @code{set print symbol-loading} command allows you to control the
20224 printing of messages when @value{GDBN} loads symbol information.
20225 By default a message is printed for the executable and one for each
20226 shared library, and normally this is what you want. However, when
20227 debugging apps with large numbers of shared libraries these messages
20228 can be annoying.
20229 When set to @code{brief} a message is printed for each executable,
20230 and when @value{GDBN} loads a collection of shared libraries at once
20231 it will only print one message regardless of the number of shared
20232 libraries. When set to @code{off} no messages are printed.
20233
20234 @kindex show print symbol-loading
20235 @item show print symbol-loading
20236 Show whether messages will be printed when a @value{GDBN} command
20237 entered from the keyboard causes symbol information to be loaded.
20238
20239 @kindex maint print symbols
20240 @cindex symbol dump
20241 @kindex maint print psymbols
20242 @cindex partial symbol dump
20243 @kindex maint print msymbols
20244 @cindex minimal symbol dump
20245 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
20246 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
20247 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
20248 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
20249 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
20250 Write a dump of debugging symbol data into the file @var{filename} or
20251 the terminal if @var{filename} is unspecified.
20252 If @code{-objfile @var{objfile}} is specified, only dump symbols for
20253 that objfile.
20254 If @code{-pc @var{address}} is specified, only dump symbols for the file
20255 with code at that address. Note that @var{address} may be a symbol like
20256 @code{main}.
20257 If @code{-source @var{source}} is specified, only dump symbols for that
20258 source file.
20259
20260 These commands are used to debug the @value{GDBN} symbol-reading code.
20261 These commands do not modify internal @value{GDBN} state, therefore
20262 @samp{maint print symbols} will only print symbols for already expanded symbol
20263 tables.
20264 You can use the command @code{info sources} to find out which files these are.
20265 If you use @samp{maint print psymbols} instead, the dump shows information
20266 about symbols that @value{GDBN} only knows partially---that is, symbols
20267 defined in files that @value{GDBN} has skimmed, but not yet read completely.
20268 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
20269 ``ELF symbols''.
20270
20271 @xref{Files, ,Commands to Specify Files}, for a discussion of how
20272 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
20273
20274 @kindex maint info symtabs
20275 @kindex maint info psymtabs
20276 @cindex listing @value{GDBN}'s internal symbol tables
20277 @cindex symbol tables, listing @value{GDBN}'s internal
20278 @cindex full symbol tables, listing @value{GDBN}'s internal
20279 @cindex partial symbol tables, listing @value{GDBN}'s internal
20280 @item maint info symtabs @r{[} @var{regexp} @r{]}
20281 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
20282
20283 List the @code{struct symtab} or @code{struct partial_symtab}
20284 structures whose names match @var{regexp}. If @var{regexp} is not
20285 given, list them all. The output includes expressions which you can
20286 copy into a @value{GDBN} debugging this one to examine a particular
20287 structure in more detail. For example:
20288
20289 @smallexample
20290 (@value{GDBP}) maint info psymtabs dwarf2read
20291 @{ objfile /home/gnu/build/gdb/gdb
20292 ((struct objfile *) 0x82e69d0)
20293 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
20294 ((struct partial_symtab *) 0x8474b10)
20295 readin no
20296 fullname (null)
20297 text addresses 0x814d3c8 -- 0x8158074
20298 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
20299 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
20300 dependencies (none)
20301 @}
20302 @}
20303 (@value{GDBP}) maint info symtabs
20304 (@value{GDBP})
20305 @end smallexample
20306 @noindent
20307 We see that there is one partial symbol table whose filename contains
20308 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
20309 and we see that @value{GDBN} has not read in any symtabs yet at all.
20310 If we set a breakpoint on a function, that will cause @value{GDBN} to
20311 read the symtab for the compilation unit containing that function:
20312
20313 @smallexample
20314 (@value{GDBP}) break dwarf2_psymtab_to_symtab
20315 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
20316 line 1574.
20317 (@value{GDBP}) maint info symtabs
20318 @{ objfile /home/gnu/build/gdb/gdb
20319 ((struct objfile *) 0x82e69d0)
20320 @{ symtab /home/gnu/src/gdb/dwarf2read.c
20321 ((struct symtab *) 0x86c1f38)
20322 dirname (null)
20323 fullname (null)
20324 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
20325 linetable ((struct linetable *) 0x8370fa0)
20326 debugformat DWARF 2
20327 @}
20328 @}
20329 (@value{GDBP})
20330 @end smallexample
20331
20332 @kindex maint info line-table
20333 @cindex listing @value{GDBN}'s internal line tables
20334 @cindex line tables, listing @value{GDBN}'s internal
20335 @item maint info line-table @r{[} @var{regexp} @r{]}
20336
20337 List the @code{struct linetable} from all @code{struct symtab}
20338 instances whose name matches @var{regexp}. If @var{regexp} is not
20339 given, list the @code{struct linetable} from all @code{struct symtab}.
20340 For example:
20341
20342 @smallexample
20343 (@value{GDBP}) maint info line-table
20344 objfile: /home/gnu/build/a.out ((struct objfile *) 0x6120000e0d40)
20345 compunit_symtab: simple.cpp ((struct compunit_symtab *) 0x6210000ff450)
20346 symtab: /home/gnu/src/simple.cpp ((struct symtab *) 0x6210000ff4d0)
20347 linetable: ((struct linetable *) 0x62100012b760):
20348 INDEX LINE ADDRESS IS-STMT PROLOGUE-END
20349 0 3 0x0000000000401110 Y
20350 1 4 0x0000000000401114 Y Y
20351 2 9 0x0000000000401120 Y
20352 3 10 0x0000000000401124 Y Y
20353 4 10 0x0000000000401129
20354 5 15 0x0000000000401130 Y
20355 6 16 0x0000000000401134 Y Y
20356 7 16 0x0000000000401139
20357 8 21 0x0000000000401140 Y
20358 9 22 0x000000000040114f Y Y
20359 10 22 0x0000000000401154
20360 11 END 0x000000000040115a Y
20361 @end smallexample
20362 @noindent
20363 The @samp{IS-STMT} column indicates if the address is a recommended breakpoint
20364 location to represent a line or a statement. The @samp{PROLOGUE-END} column
20365 indicates that a given address is an adequate place to set a breakpoint at the
20366 first instruction following a function prologue.
20367
20368 @kindex maint set symbol-cache-size
20369 @cindex symbol cache size
20370 @item maint set symbol-cache-size @var{size}
20371 Set the size of the symbol cache to @var{size}.
20372 The default size is intended to be good enough for debugging
20373 most applications. This option exists to allow for experimenting
20374 with different sizes.
20375
20376 @kindex maint show symbol-cache-size
20377 @item maint show symbol-cache-size
20378 Show the size of the symbol cache.
20379
20380 @kindex maint print symbol-cache
20381 @cindex symbol cache, printing its contents
20382 @item maint print symbol-cache
20383 Print the contents of the symbol cache.
20384 This is useful when debugging symbol cache issues.
20385
20386 @kindex maint print symbol-cache-statistics
20387 @cindex symbol cache, printing usage statistics
20388 @item maint print symbol-cache-statistics
20389 Print symbol cache usage statistics.
20390 This helps determine how well the cache is being utilized.
20391
20392 @kindex maint flush symbol-cache
20393 @kindex maint flush-symbol-cache
20394 @cindex symbol cache, flushing
20395 @item maint flush symbol-cache
20396 @itemx maint flush-symbol-cache
20397 Flush the contents of the symbol cache, all entries are removed. This
20398 command is useful when debugging the symbol cache. It is also useful
20399 when collecting performance data. The command @code{maint
20400 flush-symbol-cache} is deprecated in favor of @code{maint flush
20401 symbol-cache}..
20402
20403 @kindex maint set ignore-prologue-end-flag
20404 @cindex prologue-end
20405 @item maint set ignore-prologue-end-flag [on|off]
20406 Enable or disable the use of the @samp{PROLOGUE-END} flag from the line-table.
20407 When @samp{off} (the default), @value{GDBN} uses the @samp{PROLOGUE-END} flag
20408 to place breakpoints past the end of a function prologue. When @samp{on},
20409 @value{GDBN} ignores the flag and relies on prologue analyzers to skip function
20410 prologues.
20411
20412 @kindex maint show ignore-prologue-end-flag
20413 @item maint show ignore-prologue-end-flag
20414 Show whether @value{GDBN} will ignore the @samp{PROLOGUE-END} flag.
20415
20416 @end table
20417
20418 @node Altering
20419 @chapter Altering Execution
20420
20421 Once you think you have found an error in your program, you might want to
20422 find out for certain whether correcting the apparent error would lead to
20423 correct results in the rest of the run. You can find the answer by
20424 experiment, using the @value{GDBN} features for altering execution of the
20425 program.
20426
20427 For example, you can store new values into variables or memory
20428 locations, give your program a signal, restart it at a different
20429 address, or even return prematurely from a function.
20430
20431 @menu
20432 * Assignment:: Assignment to variables
20433 * Jumping:: Continuing at a different address
20434 * Signaling:: Giving your program a signal
20435 * Returning:: Returning from a function
20436 * Calling:: Calling your program's functions
20437 * Patching:: Patching your program
20438 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
20439 @end menu
20440
20441 @node Assignment
20442 @section Assignment to Variables
20443
20444 @cindex assignment
20445 @cindex setting variables
20446 To alter the value of a variable, evaluate an assignment expression.
20447 @xref{Expressions, ,Expressions}. For example,
20448
20449 @smallexample
20450 print x=4
20451 @end smallexample
20452
20453 @noindent
20454 stores the value 4 into the variable @code{x}, and then prints the
20455 value of the assignment expression (which is 4).
20456 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
20457 information on operators in supported languages.
20458
20459 @kindex set variable
20460 @cindex variables, setting
20461 If you are not interested in seeing the value of the assignment, use the
20462 @code{set} command instead of the @code{print} command. @code{set} is
20463 really the same as @code{print} except that the expression's value is
20464 not printed and is not put in the value history (@pxref{Value History,
20465 ,Value History}). The expression is evaluated only for its effects.
20466
20467 If the beginning of the argument string of the @code{set} command
20468 appears identical to a @code{set} subcommand, use the @code{set
20469 variable} command instead of just @code{set}. This command is identical
20470 to @code{set} except for its lack of subcommands. For example, if your
20471 program has a variable @code{width}, you get an error if you try to set
20472 a new value with just @samp{set width=13}, because @value{GDBN} has the
20473 command @code{set width}:
20474
20475 @smallexample
20476 (@value{GDBP}) whatis width
20477 type = double
20478 (@value{GDBP}) p width
20479 $4 = 13
20480 (@value{GDBP}) set width=47
20481 Invalid syntax in expression.
20482 @end smallexample
20483
20484 @noindent
20485 The invalid expression, of course, is @samp{=47}. In
20486 order to actually set the program's variable @code{width}, use
20487
20488 @smallexample
20489 (@value{GDBP}) set var width=47
20490 @end smallexample
20491
20492 Because the @code{set} command has many subcommands that can conflict
20493 with the names of program variables, it is a good idea to use the
20494 @code{set variable} command instead of just @code{set}. For example, if
20495 your program has a variable @code{g}, you run into problems if you try
20496 to set a new value with just @samp{set g=4}, because @value{GDBN} has
20497 the command @code{set gnutarget}, abbreviated @code{set g}:
20498
20499 @smallexample
20500 @group
20501 (@value{GDBP}) whatis g
20502 type = double
20503 (@value{GDBP}) p g
20504 $1 = 1
20505 (@value{GDBP}) set g=4
20506 (@value{GDBP}) p g
20507 $2 = 1
20508 (@value{GDBP}) r
20509 The program being debugged has been started already.
20510 Start it from the beginning? (y or n) y
20511 Starting program: /home/smith/cc_progs/a.out
20512 "/home/smith/cc_progs/a.out": can't open to read symbols:
20513 Invalid bfd target.
20514 (@value{GDBP}) show g
20515 The current BFD target is "=4".
20516 @end group
20517 @end smallexample
20518
20519 @noindent
20520 The program variable @code{g} did not change, and you silently set the
20521 @code{gnutarget} to an invalid value. In order to set the variable
20522 @code{g}, use
20523
20524 @smallexample
20525 (@value{GDBP}) set var g=4
20526 @end smallexample
20527
20528 @value{GDBN} allows more implicit conversions in assignments than C; you can
20529 freely store an integer value into a pointer variable or vice versa,
20530 and you can convert any structure to any other structure that is the
20531 same length or shorter.
20532 @comment FIXME: how do structs align/pad in these conversions?
20533 @comment /doc@cygnus.com 18dec1990
20534
20535 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
20536 construct to generate a value of specified type at a specified address
20537 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
20538 to memory location @code{0x83040} as an integer (which implies a certain size
20539 and representation in memory), and
20540
20541 @smallexample
20542 set @{int@}0x83040 = 4
20543 @end smallexample
20544
20545 @noindent
20546 stores the value 4 into that memory location.
20547
20548 @node Jumping
20549 @section Continuing at a Different Address
20550
20551 Ordinarily, when you continue your program, you do so at the place where
20552 it stopped, with the @code{continue} command. You can instead continue at
20553 an address of your own choosing, with the following commands:
20554
20555 @table @code
20556 @kindex jump
20557 @kindex j @r{(@code{jump})}
20558 @item jump @var{locspec}
20559 @itemx j @var{locspec}
20560 Resume execution at the address of the code location that results from
20561 resolving @var{locspec}.
20562 @xref{Location Specifications}, for a description of the different
20563 forms of @var{locspec}. If @var{locspec} resolves to more than one
20564 address, the command aborts before jumping.
20565 Execution stops again immediately if there is a breakpoint there. It
20566 is common practice to use the @code{tbreak} command in conjunction
20567 with @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
20568
20569 The @code{jump} command does not change the current stack frame, or
20570 the stack pointer, or the contents of any memory location or any
20571 register other than the program counter. If @var{locspec} resolves to
20572 an address in a different function from the one currently executing, the
20573 results may be bizarre if the two functions expect different patterns
20574 of arguments or of local variables. For this reason, the @code{jump}
20575 command requests confirmation if the jump address is not in the
20576 function currently executing. However, even bizarre results are
20577 predictable if you are well acquainted with the machine-language code
20578 of your program.
20579 @end table
20580
20581 On many systems, you can get much the same effect as the @code{jump}
20582 command by storing a new value into the register @code{$pc}. The
20583 difference is that this does not start your program running; it only
20584 changes the address of where it @emph{will} run when you continue. For
20585 example,
20586
20587 @smallexample
20588 set $pc = 0x485
20589 @end smallexample
20590
20591 @noindent
20592 makes the next @code{continue} command or stepping command execute at
20593 address @code{0x485}, rather than at the address where your program stopped.
20594 @xref{Continuing and Stepping, ,Continuing and Stepping}.
20595
20596 The most common occasion to use the @code{jump} command is to back
20597 up---perhaps with more breakpoints set---over a portion of a program
20598 that has already executed, in order to examine its execution in more
20599 detail.
20600
20601 @c @group
20602 @node Signaling
20603 @section Giving your Program a Signal
20604 @cindex deliver a signal to a program
20605
20606 @table @code
20607 @kindex signal
20608 @item signal @var{signal}
20609 Resume execution where your program is stopped, but immediately give it the
20610 signal @var{signal}. The @var{signal} can be the name or the number of a
20611 signal. For example, on many systems @code{signal 2} and @code{signal
20612 SIGINT} are both ways of sending an interrupt signal.
20613
20614 Alternatively, if @var{signal} is zero, continue execution without
20615 giving a signal. This is useful when your program stopped on account of
20616 a signal and would ordinarily see the signal when resumed with the
20617 @code{continue} command; @samp{signal 0} causes it to resume without a
20618 signal.
20619
20620 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
20621 delivered to the currently selected thread, not the thread that last
20622 reported a stop. This includes the situation where a thread was
20623 stopped due to a signal. So if you want to continue execution
20624 suppressing the signal that stopped a thread, you should select that
20625 same thread before issuing the @samp{signal 0} command. If you issue
20626 the @samp{signal 0} command with another thread as the selected one,
20627 @value{GDBN} detects that and asks for confirmation.
20628
20629 Invoking the @code{signal} command is not the same as invoking the
20630 @code{kill} utility from the shell. Sending a signal with @code{kill}
20631 causes @value{GDBN} to decide what to do with the signal depending on
20632 the signal handling tables (@pxref{Signals}). The @code{signal} command
20633 passes the signal directly to your program.
20634
20635 @code{signal} does not repeat when you press @key{RET} a second time
20636 after executing the command.
20637
20638 @kindex queue-signal
20639 @item queue-signal @var{signal}
20640 Queue @var{signal} to be delivered immediately to the current thread
20641 when execution of the thread resumes. The @var{signal} can be the name or
20642 the number of a signal. For example, on many systems @code{signal 2} and
20643 @code{signal SIGINT} are both ways of sending an interrupt signal.
20644 The handling of the signal must be set to pass the signal to the program,
20645 otherwise @value{GDBN} will report an error.
20646 You can control the handling of signals from @value{GDBN} with the
20647 @code{handle} command (@pxref{Signals}).
20648
20649 Alternatively, if @var{signal} is zero, any currently queued signal
20650 for the current thread is discarded and when execution resumes no signal
20651 will be delivered. This is useful when your program stopped on account
20652 of a signal and would ordinarily see the signal when resumed with the
20653 @code{continue} command.
20654
20655 This command differs from the @code{signal} command in that the signal
20656 is just queued, execution is not resumed. And @code{queue-signal} cannot
20657 be used to pass a signal whose handling state has been set to @code{nopass}
20658 (@pxref{Signals}).
20659 @end table
20660 @c @end group
20661
20662 @xref{stepping into signal handlers}, for information on how stepping
20663 commands behave when the thread has a signal queued.
20664
20665 @node Returning
20666 @section Returning from a Function
20667
20668 @table @code
20669 @cindex returning from a function
20670 @kindex return
20671 @item return
20672 @itemx return @var{expression}
20673 You can cancel execution of a function call with the @code{return}
20674 command. If you give an
20675 @var{expression} argument, its value is used as the function's return
20676 value.
20677 @end table
20678
20679 When you use @code{return}, @value{GDBN} discards the selected stack frame
20680 (and all frames within it). You can think of this as making the
20681 discarded frame return prematurely. If you wish to specify a value to
20682 be returned, give that value as the argument to @code{return}.
20683
20684 This pops the selected stack frame (@pxref{Selection, ,Selecting a
20685 Frame}), and any other frames inside of it, leaving its caller as the
20686 innermost remaining frame. That frame becomes selected. The
20687 specified value is stored in the registers used for returning values
20688 of functions.
20689
20690 The @code{return} command does not resume execution; it leaves the
20691 program stopped in the state that would exist if the function had just
20692 returned. In contrast, the @code{finish} command (@pxref{Continuing
20693 and Stepping, ,Continuing and Stepping}) resumes execution until the
20694 selected stack frame returns naturally.
20695
20696 @value{GDBN} needs to know how the @var{expression} argument should be set for
20697 the inferior. The concrete registers assignment depends on the OS ABI and the
20698 type being returned by the selected stack frame. For example it is common for
20699 OS ABI to return floating point values in FPU registers while integer values in
20700 CPU registers. Still some ABIs return even floating point values in CPU
20701 registers. Larger integer widths (such as @code{long long int}) also have
20702 specific placement rules. @value{GDBN} already knows the OS ABI from its
20703 current target so it needs to find out also the type being returned to make the
20704 assignment into the right register(s).
20705
20706 Normally, the selected stack frame has debug info. @value{GDBN} will always
20707 use the debug info instead of the implicit type of @var{expression} when the
20708 debug info is available. For example, if you type @kbd{return -1}, and the
20709 function in the current stack frame is declared to return a @code{long long
20710 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
20711 into a @code{long long int}:
20712
20713 @smallexample
20714 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
20715 29 return 31;
20716 (@value{GDBP}) return -1
20717 Make func return now? (y or n) y
20718 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
20719 43 printf ("result=%lld\n", func ());
20720 (@value{GDBP})
20721 @end smallexample
20722
20723 However, if the selected stack frame does not have a debug info, e.g., if the
20724 function was compiled without debug info, @value{GDBN} has to find out the type
20725 to return from user. Specifying a different type by mistake may set the value
20726 in different inferior registers than the caller code expects. For example,
20727 typing @kbd{return -1} with its implicit type @code{int} would set only a part
20728 of a @code{long long int} result for a debug info less function (on 32-bit
20729 architectures). Therefore the user is required to specify the return type by
20730 an appropriate cast explicitly:
20731
20732 @smallexample
20733 Breakpoint 2, 0x0040050b in func ()
20734 (@value{GDBP}) return -1
20735 Return value type not available for selected stack frame.
20736 Please use an explicit cast of the value to return.
20737 (@value{GDBP}) return (long long int) -1
20738 Make selected stack frame return now? (y or n) y
20739 #0 0x00400526 in main ()
20740 (@value{GDBP})
20741 @end smallexample
20742
20743 @node Calling
20744 @section Calling Program Functions
20745
20746 @table @code
20747 @cindex calling functions
20748 @cindex inferior functions, calling
20749 @item print @var{expr}
20750 Evaluate the expression @var{expr} and display the resulting value.
20751 The expression may include calls to functions in the program being
20752 debugged.
20753
20754 @kindex call
20755 @item call @var{expr}
20756 Evaluate the expression @var{expr} without displaying @code{void}
20757 returned values.
20758
20759 You can use this variant of the @code{print} command if you want to
20760 execute a function from your program that does not return anything
20761 (a.k.a.@: @dfn{a void function}), but without cluttering the output
20762 with @code{void} returned values that @value{GDBN} will otherwise
20763 print. If the result is not void, it is printed and saved in the
20764 value history.
20765 @end table
20766
20767 It is possible for the function you call via the @code{print} or
20768 @code{call} command to generate a signal (e.g., if there's a bug in
20769 the function, or if you passed it incorrect arguments). What happens
20770 in that case is controlled by the @code{set unwindonsignal} command.
20771
20772 Similarly, with a C@t{++} program it is possible for the function you
20773 call via the @code{print} or @code{call} command to generate an
20774 exception that is not handled due to the constraints of the dummy
20775 frame. In this case, any exception that is raised in the frame, but has
20776 an out-of-frame exception handler will not be found. GDB builds a
20777 dummy-frame for the inferior function call, and the unwinder cannot
20778 seek for exception handlers outside of this dummy-frame. What happens
20779 in that case is controlled by the
20780 @code{set unwind-on-terminating-exception} command.
20781
20782 @table @code
20783 @item set unwindonsignal
20784 @kindex set unwindonsignal
20785 @cindex unwind stack in called functions
20786 @cindex call dummy stack unwinding
20787 Set unwinding of the stack if a signal is received while in a function
20788 that @value{GDBN} called in the program being debugged. If set to on,
20789 @value{GDBN} unwinds the stack it created for the call and restores
20790 the context to what it was before the call. If set to off (the
20791 default), @value{GDBN} stops in the frame where the signal was
20792 received.
20793
20794 @item show unwindonsignal
20795 @kindex show unwindonsignal
20796 Show the current setting of stack unwinding in the functions called by
20797 @value{GDBN}.
20798
20799 @item set unwind-on-terminating-exception
20800 @kindex set unwind-on-terminating-exception
20801 @cindex unwind stack in called functions with unhandled exceptions
20802 @cindex call dummy stack unwinding on unhandled exception.
20803 Set unwinding of the stack if a C@t{++} exception is raised, but left
20804 unhandled while in a function that @value{GDBN} called in the program being
20805 debugged. If set to on (the default), @value{GDBN} unwinds the stack
20806 it created for the call and restores the context to what it was before
20807 the call. If set to off, @value{GDBN} the exception is delivered to
20808 the default C@t{++} exception handler and the inferior terminated.
20809
20810 @item show unwind-on-terminating-exception
20811 @kindex show unwind-on-terminating-exception
20812 Show the current setting of stack unwinding in the functions called by
20813 @value{GDBN}.
20814
20815 @item set may-call-functions
20816 @kindex set may-call-functions
20817 @cindex disabling calling functions in the program
20818 @cindex calling functions in the program, disabling
20819 Set permission to call functions in the program.
20820 This controls whether @value{GDBN} will attempt to call functions in
20821 the program, such as with expressions in the @code{print} command. It
20822 defaults to @code{on}.
20823
20824 To call a function in the program, @value{GDBN} has to temporarily
20825 modify the state of the inferior. This has potentially undesired side
20826 effects. Also, having @value{GDBN} call nested functions is likely to
20827 be erroneous and may even crash the program being debugged. You can
20828 avoid such hazards by forbidding @value{GDBN} from calling functions
20829 in the program being debugged. If calling functions in the program
20830 is forbidden, GDB will throw an error when a command (such as printing
20831 an expression) starts a function call in the program.
20832
20833 @item show may-call-functions
20834 @kindex show may-call-functions
20835 Show permission to call functions in the program.
20836
20837 @end table
20838
20839 @subsection Calling functions with no debug info
20840
20841 @cindex no debug info functions
20842 Sometimes, a function you wish to call is missing debug information.
20843 In such case, @value{GDBN} does not know the type of the function,
20844 including the types of the function's parameters. To avoid calling
20845 the inferior function incorrectly, which could result in the called
20846 function functioning erroneously and even crash, @value{GDBN} refuses
20847 to call the function unless you tell it the type of the function.
20848
20849 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
20850 to do that. The simplest is to cast the call to the function's
20851 declared return type. For example:
20852
20853 @smallexample
20854 (@value{GDBP}) p getenv ("PATH")
20855 'getenv' has unknown return type; cast the call to its declared return type
20856 (@value{GDBP}) p (char *) getenv ("PATH")
20857 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
20858 @end smallexample
20859
20860 Casting the return type of a no-debug function is equivalent to
20861 casting the function to a pointer to a prototyped function that has a
20862 prototype that matches the types of the passed-in arguments, and
20863 calling that. I.e., the call above is equivalent to:
20864
20865 @smallexample
20866 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
20867 @end smallexample
20868
20869 @noindent
20870 and given this prototyped C or C++ function with float parameters:
20871
20872 @smallexample
20873 float multiply (float v1, float v2) @{ return v1 * v2; @}
20874 @end smallexample
20875
20876 @noindent
20877 these calls are equivalent:
20878
20879 @smallexample
20880 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
20881 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
20882 @end smallexample
20883
20884 If the function you wish to call is declared as unprototyped (i.e.@:
20885 old K&R style), you must use the cast-to-function-pointer syntax, so
20886 that @value{GDBN} knows that it needs to apply default argument
20887 promotions (promote float arguments to double). @xref{ABI, float
20888 promotion}. For example, given this unprototyped C function with
20889 float parameters, and no debug info:
20890
20891 @smallexample
20892 float
20893 multiply_noproto (v1, v2)
20894 float v1, v2;
20895 @{
20896 return v1 * v2;
20897 @}
20898 @end smallexample
20899
20900 @noindent
20901 you call it like this:
20902
20903 @smallexample
20904 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20905 @end smallexample
20906
20907 @node Patching
20908 @section Patching Programs
20909
20910 @cindex patching binaries
20911 @cindex writing into executables
20912 @cindex writing into corefiles
20913
20914 By default, @value{GDBN} opens the file containing your program's
20915 executable code (or the corefile) read-only. This prevents accidental
20916 alterations to machine code; but it also prevents you from intentionally
20917 patching your program's binary.
20918
20919 If you'd like to be able to patch the binary, you can specify that
20920 explicitly with the @code{set write} command. For example, you might
20921 want to turn on internal debugging flags, or even to make emergency
20922 repairs.
20923
20924 @table @code
20925 @kindex set write
20926 @item set write on
20927 @itemx set write off
20928 If you specify @samp{set write on}, @value{GDBN} opens executable and
20929 core files for both reading and writing; if you specify @kbd{set write
20930 off} (the default), @value{GDBN} opens them read-only.
20931
20932 If you have already loaded a file, you must load it again (using the
20933 @code{exec-file} or @code{core-file} command) after changing @code{set
20934 write}, for your new setting to take effect.
20935
20936 @item show write
20937 @kindex show write
20938 Display whether executable files and core files are opened for writing
20939 as well as reading.
20940 @end table
20941
20942 @node Compiling and Injecting Code
20943 @section Compiling and injecting code in @value{GDBN}
20944 @cindex injecting code
20945 @cindex writing into executables
20946 @cindex compiling code
20947
20948 @value{GDBN} supports on-demand compilation and code injection into
20949 programs running under @value{GDBN}. GCC 5.0 or higher built with
20950 @file{libcc1.so} must be installed for this functionality to be enabled.
20951 This functionality is implemented with the following commands.
20952
20953 @table @code
20954 @kindex compile code
20955 @item compile code @var{source-code}
20956 @itemx compile code -raw @var{--} @var{source-code}
20957 Compile @var{source-code} with the compiler language found as the current
20958 language in @value{GDBN} (@pxref{Languages}). If compilation and
20959 injection is not supported with the current language specified in
20960 @value{GDBN}, or the compiler does not support this feature, an error
20961 message will be printed. If @var{source-code} compiles and links
20962 successfully, @value{GDBN} will load the object-code emitted,
20963 and execute it within the context of the currently selected inferior.
20964 It is important to note that the compiled code is executed immediately.
20965 After execution, the compiled code is removed from @value{GDBN} and any
20966 new types or variables you have defined will be deleted.
20967
20968 The command allows you to specify @var{source-code} in two ways.
20969 The simplest method is to provide a single line of code to the command.
20970 E.g.:
20971
20972 @smallexample
20973 compile code printf ("hello world\n");
20974 @end smallexample
20975
20976 If you specify options on the command line as well as source code, they
20977 may conflict. The @samp{--} delimiter can be used to separate options
20978 from actual source code. E.g.:
20979
20980 @smallexample
20981 compile code -r -- printf ("hello world\n");
20982 @end smallexample
20983
20984 Alternatively you can enter source code as multiple lines of text. To
20985 enter this mode, invoke the @samp{compile code} command without any text
20986 following the command. This will start the multiple-line editor and
20987 allow you to type as many lines of source code as required. When you
20988 have completed typing, enter @samp{end} on its own line to exit the
20989 editor.
20990
20991 @smallexample
20992 compile code
20993 >printf ("hello\n");
20994 >printf ("world\n");
20995 >end
20996 @end smallexample
20997
20998 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20999 provided @var{source-code} in a callable scope. In this case, you must
21000 specify the entry point of the code by defining a function named
21001 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
21002 inferior. Using @samp{-raw} option may be needed for example when
21003 @var{source-code} requires @samp{#include} lines which may conflict with
21004 inferior symbols otherwise.
21005
21006 @kindex compile file
21007 @item compile file @var{filename}
21008 @itemx compile file -raw @var{filename}
21009 Like @code{compile code}, but take the source code from @var{filename}.
21010
21011 @smallexample
21012 compile file /home/user/example.c
21013 @end smallexample
21014 @end table
21015
21016 @table @code
21017 @item compile print [[@var{options}] --] @var{expr}
21018 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
21019 Compile and execute @var{expr} with the compiler language found as the
21020 current language in @value{GDBN} (@pxref{Languages}). By default the
21021 value of @var{expr} is printed in a format appropriate to its data type;
21022 you can choose a different format by specifying @samp{/@var{f}}, where
21023 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
21024 Formats}. The @code{compile print} command accepts the same options
21025 as the @code{print} command; see @ref{print options}.
21026
21027 @item compile print [[@var{options}] --]
21028 @itemx compile print [[@var{options}] --] /@var{f}
21029 @cindex reprint the last value
21030 Alternatively you can enter the expression (source code producing it) as
21031 multiple lines of text. To enter this mode, invoke the @samp{compile print}
21032 command without any text following the command. This will start the
21033 multiple-line editor.
21034 @end table
21035
21036 @noindent
21037 The process of compiling and injecting the code can be inspected using:
21038
21039 @table @code
21040 @anchor{set debug compile}
21041 @item set debug compile
21042 @cindex compile command debugging info
21043 Turns on or off display of @value{GDBN} process of compiling and
21044 injecting the code. The default is off.
21045
21046 @item show debug compile
21047 Displays the current state of displaying @value{GDBN} process of
21048 compiling and injecting the code.
21049
21050 @anchor{set debug compile-cplus-types}
21051 @item set debug compile-cplus-types
21052 @cindex compile C@t{++} type conversion
21053 Turns on or off the display of C@t{++} type conversion debugging information.
21054 The default is off.
21055
21056 @item show debug compile-cplus-types
21057 Displays the current state of displaying debugging information for
21058 C@t{++} type conversion.
21059 @end table
21060
21061 @subsection Compilation options for the @code{compile} command
21062
21063 @value{GDBN} needs to specify the right compilation options for the code
21064 to be injected, in part to make its ABI compatible with the inferior
21065 and in part to make the injected code compatible with @value{GDBN}'s
21066 injecting process.
21067
21068 @noindent
21069 The options used, in increasing precedence:
21070
21071 @table @asis
21072 @item target architecture and OS options (@code{gdbarch})
21073 These options depend on target processor type and target operating
21074 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
21075 (@code{-m64}) compilation option.
21076
21077 @item compilation options recorded in the target
21078 @value{NGCC} (since version 4.7) stores the options used for compilation
21079 into @code{DW_AT_producer} part of DWARF debugging information according
21080 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
21081 explicitly specify @code{-g} during inferior compilation otherwise
21082 @value{NGCC} produces no DWARF. This feature is only relevant for
21083 platforms where @code{-g} produces DWARF by default, otherwise one may
21084 try to enforce DWARF by using @code{-gdwarf-4}.
21085
21086 @item compilation options set by @code{set compile-args}
21087 @end table
21088
21089 @noindent
21090 You can override compilation options using the following command:
21091
21092 @table @code
21093 @item set compile-args
21094 @cindex compile command options override
21095 Set compilation options used for compiling and injecting code with the
21096 @code{compile} commands. These options override any conflicting ones
21097 from the target architecture and/or options stored during inferior
21098 compilation.
21099
21100 @item show compile-args
21101 Displays the current state of compilation options override.
21102 This does not show all the options actually used during compilation,
21103 use @ref{set debug compile} for that.
21104 @end table
21105
21106 @subsection Caveats when using the @code{compile} command
21107
21108 There are a few caveats to keep in mind when using the @code{compile}
21109 command. As the caveats are different per language, the table below
21110 highlights specific issues on a per language basis.
21111
21112 @table @asis
21113 @item C code examples and caveats
21114 When the language in @value{GDBN} is set to @samp{C}, the compiler will
21115 attempt to compile the source code with a @samp{C} compiler. The source
21116 code provided to the @code{compile} command will have much the same
21117 access to variables and types as it normally would if it were part of
21118 the program currently being debugged in @value{GDBN}.
21119
21120 Below is a sample program that forms the basis of the examples that
21121 follow. This program has been compiled and loaded into @value{GDBN},
21122 much like any other normal debugging session.
21123
21124 @smallexample
21125 void function1 (void)
21126 @{
21127 int i = 42;
21128 printf ("function 1\n");
21129 @}
21130
21131 void function2 (void)
21132 @{
21133 int j = 12;
21134 function1 ();
21135 @}
21136
21137 int main(void)
21138 @{
21139 int k = 6;
21140 int *p;
21141 function2 ();
21142 return 0;
21143 @}
21144 @end smallexample
21145
21146 For the purposes of the examples in this section, the program above has
21147 been compiled, loaded into @value{GDBN}, stopped at the function
21148 @code{main}, and @value{GDBN} is awaiting input from the user.
21149
21150 To access variables and types for any program in @value{GDBN}, the
21151 program must be compiled and packaged with debug information. The
21152 @code{compile} command is not an exception to this rule. Without debug
21153 information, you can still use the @code{compile} command, but you will
21154 be very limited in what variables and types you can access.
21155
21156 So with that in mind, the example above has been compiled with debug
21157 information enabled. The @code{compile} command will have access to
21158 all variables and types (except those that may have been optimized
21159 out). Currently, as @value{GDBN} has stopped the program in the
21160 @code{main} function, the @code{compile} command would have access to
21161 the variable @code{k}. You could invoke the @code{compile} command
21162 and type some source code to set the value of @code{k}. You can also
21163 read it, or do anything with that variable you would normally do in
21164 @code{C}. Be aware that changes to inferior variables in the
21165 @code{compile} command are persistent. In the following example:
21166
21167 @smallexample
21168 compile code k = 3;
21169 @end smallexample
21170
21171 @noindent
21172 the variable @code{k} is now 3. It will retain that value until
21173 something else in the example program changes it, or another
21174 @code{compile} command changes it.
21175
21176 Normal scope and access rules apply to source code compiled and
21177 injected by the @code{compile} command. In the example, the variables
21178 @code{j} and @code{k} are not accessible yet, because the program is
21179 currently stopped in the @code{main} function, where these variables
21180 are not in scope. Therefore, the following command
21181
21182 @smallexample
21183 compile code j = 3;
21184 @end smallexample
21185
21186 @noindent
21187 will result in a compilation error message.
21188
21189 Once the program is continued, execution will bring these variables in
21190 scope, and they will become accessible; then the code you specify via
21191 the @code{compile} command will be able to access them.
21192
21193 You can create variables and types with the @code{compile} command as
21194 part of your source code. Variables and types that are created as part
21195 of the @code{compile} command are not visible to the rest of the program for
21196 the duration of its run. This example is valid:
21197
21198 @smallexample
21199 compile code int ff = 5; printf ("ff is %d\n", ff);
21200 @end smallexample
21201
21202 However, if you were to type the following into @value{GDBN} after that
21203 command has completed:
21204
21205 @smallexample
21206 compile code printf ("ff is %d\n'', ff);
21207 @end smallexample
21208
21209 @noindent
21210 a compiler error would be raised as the variable @code{ff} no longer
21211 exists. Object code generated and injected by the @code{compile}
21212 command is removed when its execution ends. Caution is advised
21213 when assigning to program variables values of variables created by the
21214 code submitted to the @code{compile} command. This example is valid:
21215
21216 @smallexample
21217 compile code int ff = 5; k = ff;
21218 @end smallexample
21219
21220 The value of the variable @code{ff} is assigned to @code{k}. The variable
21221 @code{k} does not require the existence of @code{ff} to maintain the value
21222 it has been assigned. However, pointers require particular care in
21223 assignment. If the source code compiled with the @code{compile} command
21224 changed the address of a pointer in the example program, perhaps to a
21225 variable created in the @code{compile} command, that pointer would point
21226 to an invalid location when the command exits. The following example
21227 would likely cause issues with your debugged program:
21228
21229 @smallexample
21230 compile code int ff = 5; p = &ff;
21231 @end smallexample
21232
21233 In this example, @code{p} would point to @code{ff} when the
21234 @code{compile} command is executing the source code provided to it.
21235 However, as variables in the (example) program persist with their
21236 assigned values, the variable @code{p} would point to an invalid
21237 location when the command exists. A general rule should be followed
21238 in that you should either assign @code{NULL} to any assigned pointers,
21239 or restore a valid location to the pointer before the command exits.
21240
21241 Similar caution must be exercised with any structs, unions, and typedefs
21242 defined in @code{compile} command. Types defined in the @code{compile}
21243 command will no longer be available in the next @code{compile} command.
21244 Therefore, if you cast a variable to a type defined in the
21245 @code{compile} command, care must be taken to ensure that any future
21246 need to resolve the type can be achieved.
21247
21248 @smallexample
21249 (@value{GDBP}) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
21250 (@value{GDBP}) compile code printf ("%d\n", ((struct a *) argv)->a);
21251 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
21252 Compilation failed.
21253 (@value{GDBP}) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
21254 42
21255 @end smallexample
21256
21257 Variables that have been optimized away by the compiler are not
21258 accessible to the code submitted to the @code{compile} command.
21259 Access to those variables will generate a compiler error which @value{GDBN}
21260 will print to the console.
21261 @end table
21262
21263 @subsection Compiler search for the @code{compile} command
21264
21265 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
21266 which may not be obvious for remote targets of different architecture
21267 than where @value{GDBN} is running. Environment variable @env{PATH} on
21268 @value{GDBN} host is searched for @value{NGCC} binary matching the
21269 target architecture and operating system. This search can be overriden
21270 by @code{set compile-gcc} @value{GDBN} command below. @env{PATH} is
21271 taken from shell that executed @value{GDBN}, it is not the value set by
21272 @value{GDBN} command @code{set environment}). @xref{Environment}.
21273
21274
21275 Specifically @env{PATH} is searched for binaries matching regular expression
21276 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
21277 debugged. @var{arch} is processor name --- multiarch is supported, so for
21278 example both @code{i386} and @code{x86_64} targets look for pattern
21279 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
21280 for pattern @code{s390x?}. @var{os} is currently supported only for
21281 pattern @code{linux(-gnu)?}.
21282
21283 On Posix hosts the compiler driver @value{GDBN} needs to find also
21284 shared library @file{libcc1.so} from the compiler. It is searched in
21285 default shared library search path (overridable with usual environment
21286 variable @env{LD_LIBRARY_PATH}), unrelated to @env{PATH} or @code{set
21287 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
21288 according to the installation of the found compiler --- as possibly
21289 specified by the @code{set compile-gcc} command.
21290
21291 @table @code
21292 @item set compile-gcc
21293 @cindex compile command driver filename override
21294 Set compilation command used for compiling and injecting code with the
21295 @code{compile} commands. If this option is not set (it is set to
21296 an empty string), the search described above will occur --- that is the
21297 default.
21298
21299 @item show compile-gcc
21300 Displays the current compile command @value{NGCC} driver filename.
21301 If set, it is the main command @command{gcc}, found usually for example
21302 under name @file{x86_64-linux-gnu-gcc}.
21303 @end table
21304
21305 @node GDB Files
21306 @chapter @value{GDBN} Files
21307
21308 @value{GDBN} needs to know the file name of the program to be debugged,
21309 both in order to read its symbol table and in order to start your
21310 program. To debug a core dump of a previous run, you must also tell
21311 @value{GDBN} the name of the core dump file.
21312
21313 @menu
21314 * Files:: Commands to specify files
21315 * File Caching:: Information about @value{GDBN}'s file caching
21316 * Separate Debug Files:: Debugging information in separate files
21317 * MiniDebugInfo:: Debugging information in a special section
21318 * Index Files:: Index files speed up GDB
21319 * Symbol Errors:: Errors reading symbol files
21320 * Data Files:: GDB data files
21321 @end menu
21322
21323 @node Files
21324 @section Commands to Specify Files
21325
21326 @cindex symbol table
21327 @cindex core dump file
21328
21329 You may want to specify executable and core dump file names. The usual
21330 way to do this is at start-up time, using the arguments to
21331 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
21332 Out of @value{GDBN}}).
21333
21334 Occasionally it is necessary to change to a different file during a
21335 @value{GDBN} session. Or you may run @value{GDBN} and forget to
21336 specify a file you want to use. Or you are debugging a remote target
21337 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
21338 Program}). In these situations the @value{GDBN} commands to specify
21339 new files are useful.
21340
21341 @table @code
21342 @cindex executable file
21343 @kindex file
21344 @item file @var{filename}
21345 Use @var{filename} as the program to be debugged. It is read for its
21346 symbols and for the contents of pure memory. It is also the program
21347 executed when you use the @code{run} command. If you do not specify a
21348 directory and the file is not found in the @value{GDBN} working directory,
21349 @value{GDBN} uses the environment variable @env{PATH} as a list of
21350 directories to search, just as the shell does when looking for a program
21351 to run. You can change the value of this variable, for both @value{GDBN}
21352 and your program, using the @code{path} command.
21353
21354 @cindex unlinked object files
21355 @cindex patching object files
21356 You can load unlinked object @file{.o} files into @value{GDBN} using
21357 the @code{file} command. You will not be able to ``run'' an object
21358 file, but you can disassemble functions and inspect variables. Also,
21359 if the underlying BFD functionality supports it, you could use
21360 @kbd{gdb -write} to patch object files using this technique. Note
21361 that @value{GDBN} can neither interpret nor modify relocations in this
21362 case, so branches and some initialized variables will appear to go to
21363 the wrong place. But this feature is still handy from time to time.
21364
21365 @item file
21366 @code{file} with no argument makes @value{GDBN} discard any information it
21367 has on both executable file and the symbol table.
21368
21369 @kindex exec-file
21370 @item exec-file @r{[} @var{filename} @r{]}
21371 Specify that the program to be run (but not the symbol table) is found
21372 in @var{filename}. @value{GDBN} searches the environment variable @env{PATH}
21373 if necessary to locate your program. Omitting @var{filename} means to
21374 discard information on the executable file.
21375
21376 @kindex symbol-file
21377 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
21378 Read symbol table information from file @var{filename}. @env{PATH} is
21379 searched when necessary. Use the @code{file} command to get both symbol
21380 table and program to run from the same file.
21381
21382 If an optional @var{offset} is specified, it is added to the start
21383 address of each section in the symbol file. This is useful if the
21384 program is relocated at runtime, such as the Linux kernel with kASLR
21385 enabled.
21386
21387 @code{symbol-file} with no argument clears out @value{GDBN} information on your
21388 program's symbol table.
21389
21390 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
21391 some breakpoints and auto-display expressions. This is because they may
21392 contain pointers to the internal data recording symbols and data types,
21393 which are part of the old symbol table data being discarded inside
21394 @value{GDBN}.
21395
21396 @code{symbol-file} does not repeat if you press @key{RET} again after
21397 executing it once.
21398
21399 When @value{GDBN} is configured for a particular environment, it
21400 understands debugging information in whatever format is the standard
21401 generated for that environment; you may use either a @sc{gnu} compiler, or
21402 other compilers that adhere to the local conventions.
21403 Best results are usually obtained from @sc{gnu} compilers; for example,
21404 using @code{@value{NGCC}} you can generate debugging information for
21405 optimized code.
21406
21407 For most kinds of object files, with the exception of old SVR3 systems
21408 using COFF, the @code{symbol-file} command does not normally read the
21409 symbol table in full right away. Instead, it scans the symbol table
21410 quickly to find which source files and which symbols are present. The
21411 details are read later, one source file at a time, as they are needed.
21412
21413 The purpose of this two-stage reading strategy is to make @value{GDBN}
21414 start up faster. For the most part, it is invisible except for
21415 occasional pauses while the symbol table details for a particular source
21416 file are being read. (The @code{set verbose} command can turn these
21417 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
21418 Warnings and Messages}.)
21419
21420 We have not implemented the two-stage strategy for COFF yet. When the
21421 symbol table is stored in COFF format, @code{symbol-file} reads the
21422 symbol table data in full right away. Note that ``stabs-in-COFF''
21423 still does the two-stage strategy, since the debug info is actually
21424 in stabs format.
21425
21426 @kindex readnow
21427 @cindex reading symbols immediately
21428 @cindex symbols, reading immediately
21429 @item symbol-file @r{[} -readnow @r{]} @var{filename}
21430 @itemx file @r{[} -readnow @r{]} @var{filename}
21431 You can override the @value{GDBN} two-stage strategy for reading symbol
21432 tables by using the @samp{-readnow} option with any of the commands that
21433 load symbol table information, if you want to be sure @value{GDBN} has the
21434 entire symbol table available.
21435
21436 @cindex @code{-readnever}, option for symbol-file command
21437 @cindex never read symbols
21438 @cindex symbols, never read
21439 @item symbol-file @r{[} -readnever @r{]} @var{filename}
21440 @itemx file @r{[} -readnever @r{]} @var{filename}
21441 You can instruct @value{GDBN} to never read the symbolic information
21442 contained in @var{filename} by using the @samp{-readnever} option.
21443 @xref{--readnever}.
21444
21445 @c FIXME: for now no mention of directories, since this seems to be in
21446 @c flux. 13mar1992 status is that in theory GDB would look either in
21447 @c current dir or in same dir as myprog; but issues like competing
21448 @c GDB's, or clutter in system dirs, mean that in practice right now
21449 @c only current dir is used. FFish says maybe a special GDB hierarchy
21450 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
21451 @c files.
21452
21453 @kindex core-file
21454 @item core-file @r{[}@var{filename}@r{]}
21455 @itemx core
21456 Specify the whereabouts of a core dump file to be used as the ``contents
21457 of memory''. Traditionally, core files contain only some parts of the
21458 address space of the process that generated them; @value{GDBN} can access the
21459 executable file itself for other parts.
21460
21461 @code{core-file} with no argument specifies that no core file is
21462 to be used.
21463
21464 Note that the core file is ignored when your program is actually running
21465 under @value{GDBN}. So, if you have been running your program and you
21466 wish to debug a core file instead, you must kill the subprocess in which
21467 the program is running. To do this, use the @code{kill} command
21468 (@pxref{Kill Process, ,Killing the Child Process}).
21469
21470 @kindex add-symbol-file
21471 @cindex dynamic linking
21472 @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{]}
21473 The @code{add-symbol-file} command reads additional symbol table
21474 information from the file @var{filename}. You would use this command
21475 when @var{filename} has been dynamically loaded (by some other means)
21476 into the program that is running. The @var{textaddress} parameter gives
21477 the memory address at which the file's text section has been loaded.
21478 You can additionally specify the base address of other sections using
21479 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
21480 If a section is omitted, @value{GDBN} will use its default addresses
21481 as found in @var{filename}. Any @var{address} or @var{textaddress}
21482 can be given as an expression.
21483
21484 If an optional @var{offset} is specified, it is added to the start
21485 address of each section, except those for which the address was
21486 specified explicitly.
21487
21488 The symbol table of the file @var{filename} is added to the symbol table
21489 originally read with the @code{symbol-file} command. You can use the
21490 @code{add-symbol-file} command any number of times; the new symbol data
21491 thus read is kept in addition to the old.
21492
21493 Changes can be reverted using the command @code{remove-symbol-file}.
21494
21495 @cindex relocatable object files, reading symbols from
21496 @cindex object files, relocatable, reading symbols from
21497 @cindex reading symbols from relocatable object files
21498 @cindex symbols, reading from relocatable object files
21499 @cindex @file{.o} files, reading symbols from
21500 Although @var{filename} is typically a shared library file, an
21501 executable file, or some other object file which has been fully
21502 relocated for loading into a process, you can also load symbolic
21503 information from relocatable @file{.o} files, as long as:
21504
21505 @itemize @bullet
21506 @item
21507 the file's symbolic information refers only to linker symbols defined in
21508 that file, not to symbols defined by other object files,
21509 @item
21510 every section the file's symbolic information refers to has actually
21511 been loaded into the inferior, as it appears in the file, and
21512 @item
21513 you can determine the address at which every section was loaded, and
21514 provide these to the @code{add-symbol-file} command.
21515 @end itemize
21516
21517 @noindent
21518 Some embedded operating systems, like Sun Chorus and VxWorks, can load
21519 relocatable files into an already running program; such systems
21520 typically make the requirements above easy to meet. However, it's
21521 important to recognize that many native systems use complex link
21522 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
21523 assembly, for example) that make the requirements difficult to meet. In
21524 general, one cannot assume that using @code{add-symbol-file} to read a
21525 relocatable object file's symbolic information will have the same effect
21526 as linking the relocatable object file into the program in the normal
21527 way.
21528
21529 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
21530
21531 @kindex remove-symbol-file
21532 @item remove-symbol-file @var{filename}
21533 @item remove-symbol-file -a @var{address}
21534 Remove a symbol file added via the @code{add-symbol-file} command. The
21535 file to remove can be identified by its @var{filename} or by an @var{address}
21536 that lies within the boundaries of this symbol file in memory. Example:
21537
21538 @smallexample
21539 (@value{GDBP}) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
21540 add symbol table from file "/home/user/gdb/mylib.so" at
21541 .text_addr = 0x7ffff7ff9480
21542 (y or n) y
21543 Reading symbols from /home/user/gdb/mylib.so...
21544 (@value{GDBP}) remove-symbol-file -a 0x7ffff7ff9480
21545 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
21546 (@value{GDBP})
21547 @end smallexample
21548
21549
21550 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
21551
21552 @kindex add-symbol-file-from-memory
21553 @cindex @code{syscall DSO}
21554 @cindex load symbols from memory
21555 @item add-symbol-file-from-memory @var{address}
21556 Load symbols from the given @var{address} in a dynamically loaded
21557 object file whose image is mapped directly into the inferior's memory.
21558 For example, the Linux kernel maps a @code{syscall DSO} into each
21559 process's address space; this DSO provides kernel-specific code for
21560 some system calls. The argument can be any expression whose
21561 evaluation yields the address of the file's shared object file header.
21562 For this command to work, you must have used @code{symbol-file} or
21563 @code{exec-file} commands in advance.
21564
21565 @kindex section
21566 @item section @var{section} @var{addr}
21567 The @code{section} command changes the base address of the named
21568 @var{section} of the exec file to @var{addr}. This can be used if the
21569 exec file does not contain section addresses, (such as in the
21570 @code{a.out} format), or when the addresses specified in the file
21571 itself are wrong. Each section must be changed separately. The
21572 @code{info files} command, described below, lists all the sections and
21573 their addresses.
21574
21575 @kindex info files
21576 @kindex info target
21577 @item info files
21578 @itemx info target
21579 @code{info files} and @code{info target} are synonymous; both print the
21580 current target (@pxref{Targets, ,Specifying a Debugging Target}),
21581 including the names of the executable and core dump files currently in
21582 use by @value{GDBN}, and the files from which symbols were loaded. The
21583 command @code{help target} lists all possible targets rather than
21584 current ones.
21585
21586 @kindex maint info sections
21587 @item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
21588 Another command that can give you extra information about program sections
21589 is @code{maint info sections}. In addition to the section information
21590 displayed by @code{info files}, this command displays the flags and file
21591 offset of each section in the executable and core dump files.
21592
21593 When @samp{-all-objects} is passed then sections from all loaded object
21594 files, including shared libraries, are printed.
21595
21596 The optional @var{filter-list} is a space separated list of filter
21597 keywords. Sections that match any one of the filter criteria will be
21598 printed. There are two types of filter:
21599
21600 @table @code
21601 @item @var{section-name}
21602 Display information about any section named @var{section-name}.
21603 @item @var{section-flag}
21604 Display information for any section with @var{section-flag}. The
21605 section flags that @value{GDBN} currently knows about are:
21606 @table @code
21607 @item ALLOC
21608 Section will have space allocated in the process when loaded.
21609 Set for all sections except those containing debug information.
21610 @item LOAD
21611 Section will be loaded from the file into the child process memory.
21612 Set for pre-initialized code and data, clear for @code{.bss} sections.
21613 @item RELOC
21614 Section needs to be relocated before loading.
21615 @item READONLY
21616 Section cannot be modified by the child process.
21617 @item CODE
21618 Section contains executable code only.
21619 @item DATA
21620 Section contains data only (no executable code).
21621 @item ROM
21622 Section will reside in ROM.
21623 @item CONSTRUCTOR
21624 Section contains data for constructor/destructor lists.
21625 @item HAS_CONTENTS
21626 Section is not empty.
21627 @item NEVER_LOAD
21628 An instruction to the linker to not output the section.
21629 @item COFF_SHARED_LIBRARY
21630 A notification to the linker that the section contains
21631 COFF shared library information.
21632 @item IS_COMMON
21633 Section contains common symbols.
21634 @end table
21635 @end table
21636
21637 @kindex maint info target-sections
21638 @item maint info target-sections
21639 This command prints @value{GDBN}'s internal section table. For each
21640 target @value{GDBN} maintains a table containing the allocatable
21641 sections from all currently mapped objects, along with information
21642 about where the section is mapped.
21643
21644 @kindex set trust-readonly-sections
21645 @cindex read-only sections
21646 @item set trust-readonly-sections on
21647 Tell @value{GDBN} that readonly sections in your object file
21648 really are read-only (i.e.@: that their contents will not change).
21649 In that case, @value{GDBN} can fetch values from these sections
21650 out of the object file, rather than from the target program.
21651 For some targets (notably embedded ones), this can be a significant
21652 enhancement to debugging performance.
21653
21654 The default is off.
21655
21656 @item set trust-readonly-sections off
21657 Tell @value{GDBN} not to trust readonly sections. This means that
21658 the contents of the section might change while the program is running,
21659 and must therefore be fetched from the target when needed.
21660
21661 @item show trust-readonly-sections
21662 Show the current setting of trusting readonly sections.
21663 @end table
21664
21665 All file-specifying commands allow both absolute and relative file names
21666 as arguments. @value{GDBN} always converts the file name to an absolute file
21667 name and remembers it that way.
21668
21669 @cindex shared libraries
21670 @anchor{Shared Libraries}
21671 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
21672 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
21673 DSBT (TIC6X) shared libraries.
21674
21675 On MS-Windows @value{GDBN} must be linked with the Expat library to support
21676 shared libraries. @xref{Expat}.
21677
21678 @value{GDBN} automatically loads symbol definitions from shared libraries
21679 when you use the @code{run} command, or when you examine a core file.
21680 (Before you issue the @code{run} command, @value{GDBN} does not understand
21681 references to a function in a shared library, however---unless you are
21682 debugging a core file).
21683
21684 @c FIXME: some @value{GDBN} release may permit some refs to undef
21685 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
21686 @c FIXME...lib; check this from time to time when updating manual
21687
21688 There are times, however, when you may wish to not automatically load
21689 symbol definitions from shared libraries, such as when they are
21690 particularly large or there are many of them.
21691
21692 To control the automatic loading of shared library symbols, use the
21693 commands:
21694
21695 @table @code
21696 @kindex set auto-solib-add
21697 @item set auto-solib-add @var{mode}
21698 If @var{mode} is @code{on}, symbols from all shared object libraries
21699 will be loaded automatically when the inferior begins execution, you
21700 attach to an independently started inferior, or when the dynamic linker
21701 informs @value{GDBN} that a new library has been loaded. If @var{mode}
21702 is @code{off}, symbols must be loaded manually, using the
21703 @code{sharedlibrary} command. The default value is @code{on}.
21704
21705 @cindex memory used for symbol tables
21706 If your program uses lots of shared libraries with debug info that
21707 takes large amounts of memory, you can decrease the @value{GDBN}
21708 memory footprint by preventing it from automatically loading the
21709 symbols from shared libraries. To that end, type @kbd{set
21710 auto-solib-add off} before running the inferior, then load each
21711 library whose debug symbols you do need with @kbd{sharedlibrary
21712 @var{regexp}}, where @var{regexp} is a regular expression that matches
21713 the libraries whose symbols you want to be loaded.
21714
21715 @kindex show auto-solib-add
21716 @item show auto-solib-add
21717 Display the current autoloading mode.
21718 @end table
21719
21720 @cindex load shared library
21721 To explicitly load shared library symbols, use the @code{sharedlibrary}
21722 command:
21723
21724 @table @code
21725 @kindex info sharedlibrary
21726 @kindex info share
21727 @item info share @var{regex}
21728 @itemx info sharedlibrary @var{regex}
21729 Print the names of the shared libraries which are currently loaded
21730 that match @var{regex}. If @var{regex} is omitted then print
21731 all shared libraries that are loaded.
21732
21733 @kindex info dll
21734 @item info dll @var{regex}
21735 This is an alias of @code{info sharedlibrary}.
21736
21737 @kindex sharedlibrary
21738 @kindex share
21739 @item sharedlibrary @var{regex}
21740 @itemx share @var{regex}
21741 Load shared object library symbols for files matching a
21742 Unix regular expression.
21743 As with files loaded automatically, it only loads shared libraries
21744 required by your program for a core file or after typing @code{run}. If
21745 @var{regex} is omitted all shared libraries required by your program are
21746 loaded.
21747
21748 @item nosharedlibrary
21749 @kindex nosharedlibrary
21750 @cindex unload symbols from shared libraries
21751 Unload all shared object library symbols. This discards all symbols
21752 that have been loaded from all shared libraries. Symbols from shared
21753 libraries that were loaded by explicit user requests are not
21754 discarded.
21755 @end table
21756
21757 Sometimes you may wish that @value{GDBN} stops and gives you control
21758 when any of shared library events happen. The best way to do this is
21759 to use @code{catch load} and @code{catch unload} (@pxref{Set
21760 Catchpoints}).
21761
21762 @value{GDBN} also supports the @code{set stop-on-solib-events}
21763 command for this. This command exists for historical reasons. It is
21764 less useful than setting a catchpoint, because it does not allow for
21765 conditions or commands as a catchpoint does.
21766
21767 @table @code
21768 @item set stop-on-solib-events
21769 @kindex set stop-on-solib-events
21770 This command controls whether @value{GDBN} should give you control
21771 when the dynamic linker notifies it about some shared library event.
21772 The most common event of interest is loading or unloading of a new
21773 shared library.
21774
21775 @item show stop-on-solib-events
21776 @kindex show stop-on-solib-events
21777 Show whether @value{GDBN} stops and gives you control when shared
21778 library events happen.
21779 @end table
21780
21781 Shared libraries are also supported in many cross or remote debugging
21782 configurations. @value{GDBN} needs to have access to the target's libraries;
21783 this can be accomplished either by providing copies of the libraries
21784 on the host system, or by asking @value{GDBN} to automatically retrieve the
21785 libraries from the target. If copies of the target libraries are
21786 provided, they need to be the same as the target libraries, although the
21787 copies on the target can be stripped as long as the copies on the host are
21788 not.
21789
21790 @cindex where to look for shared libraries
21791 For remote debugging, you need to tell @value{GDBN} where the target
21792 libraries are, so that it can load the correct copies---otherwise, it
21793 may try to load the host's libraries. @value{GDBN} has two variables
21794 to specify the search directories for target libraries.
21795
21796 @table @code
21797 @cindex prefix for executable and shared library file names
21798 @cindex system root, alternate
21799 @kindex set solib-absolute-prefix
21800 @kindex set sysroot
21801 @item set sysroot @var{path}
21802 Use @var{path} as the system root for the program being debugged. Any
21803 absolute shared library paths will be prefixed with @var{path}; many
21804 runtime loaders store the absolute paths to the shared library in the
21805 target program's memory. When starting processes remotely, and when
21806 attaching to already-running processes (local or remote), their
21807 executable filenames will be prefixed with @var{path} if reported to
21808 @value{GDBN} as absolute by the operating system. If you use
21809 @code{set sysroot} to find executables and shared libraries, they need
21810 to be laid out in the same way that they are on the target, with
21811 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
21812 @var{path}.
21813
21814 If @var{path} starts with the sequence @file{target:} and the target
21815 system is remote then @value{GDBN} will retrieve the target binaries
21816 from the remote system. This is only supported when using a remote
21817 target that supports the @code{remote get} command (@pxref{File
21818 Transfer,,Sending files to a remote system}). The part of @var{path}
21819 following the initial @file{target:} (if present) is used as system
21820 root prefix on the remote file system. If @var{path} starts with the
21821 sequence @file{remote:} this is converted to the sequence
21822 @file{target:} by @code{set sysroot}@footnote{Historically the
21823 functionality to retrieve binaries from the remote system was
21824 provided by prefixing @var{path} with @file{remote:}}. If you want
21825 to specify a local system root using a directory that happens to be
21826 named @file{target:} or @file{remote:}, you need to use some
21827 equivalent variant of the name like @file{./target:}.
21828
21829 For targets with an MS-DOS based filesystem, such as MS-Windows,
21830 @value{GDBN} tries prefixing a few variants of the target
21831 absolute file name with @var{path}. But first, on Unix hosts,
21832 @value{GDBN} converts all backslash directory separators into forward
21833 slashes, because the backslash is not a directory separator on Unix:
21834
21835 @smallexample
21836 c:\foo\bar.dll @result{} c:/foo/bar.dll
21837 @end smallexample
21838
21839 Then, @value{GDBN} attempts prefixing the target file name with
21840 @var{path}, and looks for the resulting file name in the host file
21841 system:
21842
21843 @smallexample
21844 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
21845 @end smallexample
21846
21847 If that does not find the binary, @value{GDBN} tries removing
21848 the @samp{:} character from the drive spec, both for convenience, and,
21849 for the case of the host file system not supporting file names with
21850 colons:
21851
21852 @smallexample
21853 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
21854 @end smallexample
21855
21856 This makes it possible to have a system root that mirrors a target
21857 with more than one drive. E.g., you may want to setup your local
21858 copies of the target system shared libraries like so (note @samp{c} vs
21859 @samp{z}):
21860
21861 @smallexample
21862 @file{/path/to/sysroot/c/sys/bin/foo.dll}
21863 @file{/path/to/sysroot/c/sys/bin/bar.dll}
21864 @file{/path/to/sysroot/z/sys/bin/bar.dll}
21865 @end smallexample
21866
21867 @noindent
21868 and point the system root at @file{/path/to/sysroot}, so that
21869 @value{GDBN} can find the correct copies of both
21870 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
21871
21872 If that still does not find the binary, @value{GDBN} tries
21873 removing the whole drive spec from the target file name:
21874
21875 @smallexample
21876 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
21877 @end smallexample
21878
21879 This last lookup makes it possible to not care about the drive name,
21880 if you don't want or need to.
21881
21882 The @code{set solib-absolute-prefix} command is an alias for @code{set
21883 sysroot}.
21884
21885 @cindex default system root
21886 @cindex @samp{--with-sysroot}
21887 You can set the default system root by using the configure-time
21888 @samp{--with-sysroot} option. If the system root is inside
21889 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21890 @samp{--exec-prefix}), then the default system root will be updated
21891 automatically if the installed @value{GDBN} is moved to a new
21892 location.
21893
21894 @kindex show sysroot
21895 @item show sysroot
21896 Display the current executable and shared library prefix.
21897
21898 @kindex set solib-search-path
21899 @item set solib-search-path @var{path}
21900 If this variable is set, @var{path} is a colon-separated list of
21901 directories to search for shared libraries. @samp{solib-search-path}
21902 is used after @samp{sysroot} fails to locate the library, or if the
21903 path to the library is relative instead of absolute. If you want to
21904 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
21905 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
21906 finding your host's libraries. @samp{sysroot} is preferred; setting
21907 it to a nonexistent directory may interfere with automatic loading
21908 of shared library symbols.
21909
21910 @kindex show solib-search-path
21911 @item show solib-search-path
21912 Display the current shared library search path.
21913
21914 @cindex DOS file-name semantics of file names.
21915 @kindex set target-file-system-kind (unix|dos-based|auto)
21916 @kindex show target-file-system-kind
21917 @item set target-file-system-kind @var{kind}
21918 Set assumed file system kind for target reported file names.
21919
21920 Shared library file names as reported by the target system may not
21921 make sense as is on the system @value{GDBN} is running on. For
21922 example, when remote debugging a target that has MS-DOS based file
21923 system semantics, from a Unix host, the target may be reporting to
21924 @value{GDBN} a list of loaded shared libraries with file names such as
21925 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21926 drive letters, so the @samp{c:\} prefix is not normally understood as
21927 indicating an absolute file name, and neither is the backslash
21928 normally considered a directory separator character. In that case,
21929 the native file system would interpret this whole absolute file name
21930 as a relative file name with no directory components. This would make
21931 it impossible to point @value{GDBN} at a copy of the remote target's
21932 shared libraries on the host using @code{set sysroot}, and impractical
21933 with @code{set solib-search-path}. Setting
21934 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21935 to interpret such file names similarly to how the target would, and to
21936 map them to file names valid on @value{GDBN}'s native file system
21937 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21938 to one of the supported file system kinds. In that case, @value{GDBN}
21939 tries to determine the appropriate file system variant based on the
21940 current target's operating system (@pxref{ABI, ,Configuring the
21941 Current ABI}). The supported file system settings are:
21942
21943 @table @code
21944 @item unix
21945 Instruct @value{GDBN} to assume the target file system is of Unix
21946 kind. Only file names starting the forward slash (@samp{/}) character
21947 are considered absolute, and the directory separator character is also
21948 the forward slash.
21949
21950 @item dos-based
21951 Instruct @value{GDBN} to assume the target file system is DOS based.
21952 File names starting with either a forward slash, or a drive letter
21953 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21954 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21955 considered directory separators.
21956
21957 @item auto
21958 Instruct @value{GDBN} to use the file system kind associated with the
21959 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21960 This is the default.
21961 @end table
21962 @end table
21963
21964 @cindex file name canonicalization
21965 @cindex base name differences
21966 When processing file names provided by the user, @value{GDBN}
21967 frequently needs to compare them to the file names recorded in the
21968 program's debug info. Normally, @value{GDBN} compares just the
21969 @dfn{base names} of the files as strings, which is reasonably fast
21970 even for very large programs. (The base name of a file is the last
21971 portion of its name, after stripping all the leading directories.)
21972 This shortcut in comparison is based upon the assumption that files
21973 cannot have more than one base name. This is usually true, but
21974 references to files that use symlinks or similar filesystem
21975 facilities violate that assumption. If your program records files
21976 using such facilities, or if you provide file names to @value{GDBN}
21977 using symlinks etc., you can set @code{basenames-may-differ} to
21978 @code{true} to instruct @value{GDBN} to completely canonicalize each
21979 pair of file names it needs to compare. This will make file-name
21980 comparisons accurate, but at a price of a significant slowdown.
21981
21982 @table @code
21983 @item set basenames-may-differ
21984 @kindex set basenames-may-differ
21985 Set whether a source file may have multiple base names.
21986
21987 @item show basenames-may-differ
21988 @kindex show basenames-may-differ
21989 Show whether a source file may have multiple base names.
21990 @end table
21991
21992 @node File Caching
21993 @section File Caching
21994 @cindex caching of opened files
21995 @cindex caching of bfd objects
21996
21997 To speed up file loading, and reduce memory usage, @value{GDBN} will
21998 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21999 BFD, bfd, The Binary File Descriptor Library}. The following commands
22000 allow visibility and control of the caching behavior.
22001
22002 @table @code
22003 @kindex maint info bfds
22004 @item maint info bfds
22005 This prints information about each @code{bfd} object that is known to
22006 @value{GDBN}.
22007
22008 @kindex maint set bfd-sharing
22009 @kindex maint show bfd-sharing
22010 @kindex bfd caching
22011 @item maint set bfd-sharing
22012 @item maint show bfd-sharing
22013 Control whether @code{bfd} objects can be shared. When sharing is
22014 enabled @value{GDBN} reuses already open @code{bfd} objects rather
22015 than reopening the same file. Turning sharing off does not cause
22016 already shared @code{bfd} objects to be unshared, but all future files
22017 that are opened will create a new @code{bfd} object. Similarly,
22018 re-enabling sharing does not cause multiple existing @code{bfd}
22019 objects to be collapsed into a single shared @code{bfd} object.
22020
22021 @kindex set debug bfd-cache @var{level}
22022 @kindex bfd caching
22023 @item set debug bfd-cache @var{level}
22024 Turns on debugging of the bfd cache, setting the level to @var{level}.
22025
22026 @kindex show debug bfd-cache
22027 @kindex bfd caching
22028 @item show debug bfd-cache
22029 Show the current debugging level of the bfd cache.
22030 @end table
22031
22032 @node Separate Debug Files
22033 @section Debugging Information in Separate Files
22034 @cindex separate debugging information files
22035 @cindex debugging information in separate files
22036 @cindex @file{.debug} subdirectories
22037 @cindex debugging information directory, global
22038 @cindex global debugging information directories
22039 @cindex build ID, and separate debugging files
22040 @cindex @file{.build-id} directory
22041
22042 @value{GDBN} allows you to put a program's debugging information in a
22043 file separate from the executable itself, in a way that allows
22044 @value{GDBN} to find and load the debugging information automatically.
22045 Since debugging information can be very large---sometimes larger
22046 than the executable code itself---some systems distribute debugging
22047 information for their executables in separate files, which users can
22048 install only when they need to debug a problem.
22049
22050 @value{GDBN} supports two ways of specifying the separate debug info
22051 file:
22052
22053 @itemize @bullet
22054 @item
22055 The executable contains a @dfn{debug link} that specifies the name of
22056 the separate debug info file. The separate debug file's name is
22057 usually @file{@var{executable}.debug}, where @var{executable} is the
22058 name of the corresponding executable file without leading directories
22059 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
22060 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
22061 checksum for the debug file, which @value{GDBN} uses to validate that
22062 the executable and the debug file came from the same build.
22063
22064 @item
22065 @anchor{build ID}
22066 The executable contains a @dfn{build ID}, a unique bit string that is
22067 also present in the corresponding debug info file. (This is supported
22068 only on some operating systems, when using the ELF or PE file formats
22069 for binary files and the @sc{gnu} Binutils.) For more details about
22070 this feature, see the description of the @option{--build-id}
22071 command-line option in @ref{Options, , Command Line Options, ld,
22072 The GNU Linker}. The debug info file's name is not specified
22073 explicitly by the build ID, but can be computed from the build ID, see
22074 below.
22075 @end itemize
22076
22077 Depending on the way the debug info file is specified, @value{GDBN}
22078 uses two different methods of looking for the debug file:
22079
22080 @itemize @bullet
22081 @item
22082 For the ``debug link'' method, @value{GDBN} looks up the named file in
22083 the directory of the executable file, then in a subdirectory of that
22084 directory named @file{.debug}, and finally under each one of the
22085 global debug directories, in a subdirectory whose name is identical to
22086 the leading directories of the executable's absolute file name. (On
22087 MS-Windows/MS-DOS, the drive letter of the executable's leading
22088 directories is converted to a one-letter subdirectory, i.e.@:
22089 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
22090 filesystems disallow colons in file names.)
22091
22092 @item
22093 For the ``build ID'' method, @value{GDBN} looks in the
22094 @file{.build-id} subdirectory of each one of the global debug directories for
22095 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
22096 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
22097 are the rest of the bit string. (Real build ID strings are 32 or more
22098 hex characters, not 10.) @value{GDBN} can automatically query
22099 @code{debuginfod} servers using build IDs in order to download separate debug
22100 files that cannot be found locally. For more information see @ref{Debuginfod}.
22101 @end itemize
22102
22103 So, for example, suppose you ask @value{GDBN} to debug
22104 @file{/usr/bin/ls}, which has a debug link that specifies the
22105 file @file{ls.debug}, and a build ID whose value in hex is
22106 @code{abcdef1234}. If the list of the global debug directories includes
22107 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
22108 debug information files, in the indicated order:
22109
22110 @itemize @minus
22111 @item
22112 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
22113 @item
22114 @file{/usr/bin/ls.debug}
22115 @item
22116 @file{/usr/bin/.debug/ls.debug}
22117 @item
22118 @file{/usr/lib/debug/usr/bin/ls.debug}.
22119 @end itemize
22120
22121 If the debug file still has not been found and @code{debuginfod}
22122 (@pxref{Debuginfod}) is enabled, @value{GDBN} will attempt to download the
22123 file from @code{debuginfod} servers.
22124
22125 @anchor{debug-file-directory}
22126 Global debugging info directories default to what is set by @value{GDBN}
22127 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
22128 you can also set the global debugging info directories, and view the list
22129 @value{GDBN} is currently using.
22130
22131 @table @code
22132
22133 @kindex set debug-file-directory
22134 @item set debug-file-directory @var{directories}
22135 Set the directories which @value{GDBN} searches for separate debugging
22136 information files to @var{directory}. Multiple path components can be set
22137 concatenating them by a path separator.
22138
22139 @kindex show debug-file-directory
22140 @item show debug-file-directory
22141 Show the directories @value{GDBN} searches for separate debugging
22142 information files.
22143
22144 @end table
22145
22146 @cindex @code{.gnu_debuglink} sections
22147 @cindex debug link sections
22148 A debug link is a special section of the executable file named
22149 @code{.gnu_debuglink}. The section must contain:
22150
22151 @itemize
22152 @item
22153 A filename, with any leading directory components removed, followed by
22154 a zero byte,
22155 @item
22156 zero to three bytes of padding, as needed to reach the next four-byte
22157 boundary within the section, and
22158 @item
22159 a four-byte CRC checksum, stored in the same endianness used for the
22160 executable file itself. The checksum is computed on the debugging
22161 information file's full contents by the function given below, passing
22162 zero as the @var{crc} argument.
22163 @end itemize
22164
22165 Any executable file format can carry a debug link, as long as it can
22166 contain a section named @code{.gnu_debuglink} with the contents
22167 described above.
22168
22169 @cindex @code{.note.gnu.build-id} sections
22170 @cindex build ID sections
22171 The build ID is a special section in the executable file (and in other
22172 ELF binary files that @value{GDBN} may consider). This section is
22173 often named @code{.note.gnu.build-id}, but that name is not mandatory.
22174 It contains unique identification for the built files---the ID remains
22175 the same across multiple builds of the same build tree. The default
22176 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
22177 content for the build ID string. The same section with an identical
22178 value is present in the original built binary with symbols, in its
22179 stripped variant, and in the separate debugging information file.
22180
22181 The debugging information file itself should be an ordinary
22182 executable, containing a full set of linker symbols, sections, and
22183 debugging information. The sections of the debugging information file
22184 should have the same names, addresses, and sizes as the original file,
22185 but they need not contain any data---much like a @code{.bss} section
22186 in an ordinary executable.
22187
22188 The @sc{gnu} binary utilities (Binutils) package includes the
22189 @samp{objcopy} utility that can produce
22190 the separated executable / debugging information file pairs using the
22191 following commands:
22192
22193 @smallexample
22194 @kbd{objcopy --only-keep-debug foo foo.debug}
22195 @kbd{strip -g foo}
22196 @end smallexample
22197
22198 @noindent
22199 These commands remove the debugging
22200 information from the executable file @file{foo} and place it in the file
22201 @file{foo.debug}. You can use the first, second or both methods to link the
22202 two files:
22203
22204 @itemize @bullet
22205 @item
22206 The debug link method needs the following additional command to also leave
22207 behind a debug link in @file{foo}:
22208
22209 @smallexample
22210 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
22211 @end smallexample
22212
22213 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
22214 a version of the @code{strip} command such that the command @kbd{strip foo -f
22215 foo.debug} has the same functionality as the two @code{objcopy} commands and
22216 the @code{ln -s} command above, together.
22217
22218 @item
22219 Build ID gets embedded into the main executable using @code{ld --build-id} or
22220 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
22221 compatibility fixes for debug files separation are present in @sc{gnu} binary
22222 utilities (Binutils) package since version 2.18.
22223 @end itemize
22224
22225 @noindent
22226
22227 @cindex CRC algorithm definition
22228 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
22229 IEEE 802.3 using the polynomial:
22230
22231 @c TexInfo requires naked braces for multi-digit exponents for Tex
22232 @c output, but this causes HTML output to barf. HTML has to be set using
22233 @c raw commands. So we end up having to specify this equation in 2
22234 @c different ways!
22235 @ifhtml
22236 @display
22237 @html
22238 <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>
22239 + <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
22240 @end html
22241 @end display
22242 @end ifhtml
22243 @ifnothtml
22244 @display
22245 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
22246 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
22247 @end display
22248 @end ifnothtml
22249
22250 The function is computed byte at a time, taking the least
22251 significant bit of each byte first. The initial pattern
22252 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
22253 the final result is inverted to ensure trailing zeros also affect the
22254 CRC.
22255
22256 @emph{Note:} This is the same CRC polynomial as used in handling the
22257 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
22258 However in the case of the Remote Serial Protocol, the CRC is computed
22259 @emph{most} significant bit first, and the result is not inverted, so
22260 trailing zeros have no effect on the CRC value.
22261
22262 To complete the description, we show below the code of the function
22263 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
22264 initially supplied @code{crc} argument means that an initial call to
22265 this function passing in zero will start computing the CRC using
22266 @code{0xffffffff}.
22267
22268 @kindex gnu_debuglink_crc32
22269 @smallexample
22270 unsigned long
22271 gnu_debuglink_crc32 (unsigned long crc,
22272 unsigned char *buf, size_t len)
22273 @{
22274 static const unsigned long crc32_table[256] =
22275 @{
22276 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
22277 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
22278 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
22279 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
22280 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
22281 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
22282 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
22283 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
22284 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
22285 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
22286 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
22287 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
22288 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
22289 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
22290 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
22291 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
22292 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
22293 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
22294 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
22295 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
22296 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
22297 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
22298 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
22299 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
22300 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
22301 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
22302 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
22303 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
22304 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
22305 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
22306 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
22307 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
22308 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
22309 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
22310 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
22311 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
22312 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
22313 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
22314 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
22315 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
22316 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
22317 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
22318 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
22319 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
22320 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
22321 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
22322 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
22323 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
22324 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
22325 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
22326 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
22327 0x2d02ef8d
22328 @};
22329 unsigned char *end;
22330
22331 crc = ~crc & 0xffffffff;
22332 for (end = buf + len; buf < end; ++buf)
22333 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
22334 return ~crc & 0xffffffff;
22335 @}
22336 @end smallexample
22337
22338 @noindent
22339 This computation does not apply to the ``build ID'' method.
22340
22341 @node MiniDebugInfo
22342 @section Debugging information in a special section
22343 @cindex separate debug sections
22344 @cindex @samp{.gnu_debugdata} section
22345
22346 Some systems ship pre-built executables and libraries that have a
22347 special @samp{.gnu_debugdata} section. This feature is called
22348 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
22349 is used to supply extra symbols for backtraces.
22350
22351 The intent of this section is to provide extra minimal debugging
22352 information for use in simple backtraces. It is not intended to be a
22353 replacement for full separate debugging information (@pxref{Separate
22354 Debug Files}). The example below shows the intended use; however,
22355 @value{GDBN} does not currently put restrictions on what sort of
22356 debugging information might be included in the section.
22357
22358 @value{GDBN} has support for this extension. If the section exists,
22359 then it is used provided that no other source of debugging information
22360 can be found, and that @value{GDBN} was configured with LZMA support.
22361
22362 This section can be easily created using @command{objcopy} and other
22363 standard utilities:
22364
22365 @smallexample
22366 # Extract the dynamic symbols from the main binary, there is no need
22367 # to also have these in the normal symbol table.
22368 nm -D @var{binary} --format=posix --defined-only \
22369 | awk '@{ print $1 @}' | sort > dynsyms
22370
22371 # Extract all the text (i.e. function) symbols from the debuginfo.
22372 # (Note that we actually also accept "D" symbols, for the benefit
22373 # of platforms like PowerPC64 that use function descriptors.)
22374 nm @var{binary} --format=posix --defined-only \
22375 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
22376 | sort > funcsyms
22377
22378 # Keep all the function symbols not already in the dynamic symbol
22379 # table.
22380 comm -13 dynsyms funcsyms > keep_symbols
22381
22382 # Separate full debug info into debug binary.
22383 objcopy --only-keep-debug @var{binary} debug
22384
22385 # Copy the full debuginfo, keeping only a minimal set of symbols and
22386 # removing some unnecessary sections.
22387 objcopy -S --remove-section .gdb_index --remove-section .comment \
22388 --keep-symbols=keep_symbols debug mini_debuginfo
22389
22390 # Drop the full debug info from the original binary.
22391 strip --strip-all -R .comment @var{binary}
22392
22393 # Inject the compressed data into the .gnu_debugdata section of the
22394 # original binary.
22395 xz mini_debuginfo
22396 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
22397 @end smallexample
22398
22399 @node Index Files
22400 @section Index Files Speed Up @value{GDBN}
22401 @cindex index files
22402 @cindex @samp{.gdb_index} section
22403
22404 When @value{GDBN} finds a symbol file, it scans the symbols in the
22405 file in order to construct an internal symbol table. This lets most
22406 @value{GDBN} operations work quickly---at the cost of a delay early
22407 on. For large programs, this delay can be quite lengthy, so
22408 @value{GDBN} provides a way to build an index, which speeds up
22409 startup.
22410
22411 For convenience, @value{GDBN} comes with a program,
22412 @command{gdb-add-index}, which can be used to add the index to a
22413 symbol file. It takes the symbol file as its only argument:
22414
22415 @smallexample
22416 $ gdb-add-index symfile
22417 @end smallexample
22418
22419 @xref{gdb-add-index}.
22420
22421 It is also possible to do the work manually. Here is what
22422 @command{gdb-add-index} does behind the curtains.
22423
22424 The index is stored as a section in the symbol file. @value{GDBN} can
22425 write the index to a file, then you can put it into the symbol file
22426 using @command{objcopy}.
22427
22428 To create an index file, use the @code{save gdb-index} command:
22429
22430 @table @code
22431 @item save gdb-index [-dwarf-5] @var{directory}
22432 @kindex save gdb-index
22433 Create index files for all symbol files currently known by
22434 @value{GDBN}. For each known @var{symbol-file}, this command by
22435 default creates it produces a single file
22436 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
22437 the @option{-dwarf-5} option, it produces 2 files:
22438 @file{@var{symbol-file}.debug_names} and
22439 @file{@var{symbol-file}.debug_str}. The files are created in the
22440 given @var{directory}.
22441 @end table
22442
22443 Once you have created an index file you can merge it into your symbol
22444 file, here named @file{symfile}, using @command{objcopy}:
22445
22446 @smallexample
22447 $ objcopy --add-section .gdb_index=symfile.gdb-index \
22448 --set-section-flags .gdb_index=readonly symfile symfile
22449 @end smallexample
22450
22451 Or for @code{-dwarf-5}:
22452
22453 @smallexample
22454 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
22455 $ cat symfile.debug_str >>symfile.debug_str.new
22456 $ objcopy --add-section .debug_names=symfile.gdb-index \
22457 --set-section-flags .debug_names=readonly \
22458 --update-section .debug_str=symfile.debug_str.new symfile symfile
22459 @end smallexample
22460
22461 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
22462 sections that have been deprecated. Usually they are deprecated because
22463 they are missing a new feature or have performance issues.
22464 To tell @value{GDBN} to use a deprecated index section anyway
22465 specify @code{set use-deprecated-index-sections on}.
22466 The default is @code{off}.
22467 This can speed up startup, but may result in some functionality being lost.
22468 @xref{Index Section Format}.
22469
22470 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
22471 must be done before gdb reads the file. The following will not work:
22472
22473 @smallexample
22474 $ gdb -ex "set use-deprecated-index-sections on" <program>
22475 @end smallexample
22476
22477 Instead you must do, for example,
22478
22479 @smallexample
22480 $ gdb -iex "set use-deprecated-index-sections on" <program>
22481 @end smallexample
22482
22483 Indices only work when using DWARF debugging information, not stabs.
22484
22485 @subsection Automatic symbol index cache
22486
22487 @cindex automatic symbol index cache
22488 It is possible for @value{GDBN} to automatically save a copy of this index in a
22489 cache on disk and retrieve it from there when loading the same binary in the
22490 future. This feature can be turned on with @kbd{set index-cache enabled on}.
22491 The following commands can be used to tweak the behavior of the index cache.
22492
22493 @table @code
22494
22495 @kindex set index-cache
22496 @item set index-cache enabled on
22497 @itemx set index-cache enabled off
22498 Enable or disable the use of the symbol index cache.
22499
22500 @item set index-cache directory @var{directory}
22501 @kindex show index-cache
22502 @itemx show index-cache directory
22503 Set/show the directory where index files will be saved.
22504
22505 The default value for this directory depends on the host platform. On
22506 most systems, the index is cached in the @file{gdb} subdirectory of
22507 the directory pointed to by the @env{XDG_CACHE_HOME} environment
22508 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
22509 of your home directory. However, on some systems, the default may
22510 differ according to local convention.
22511
22512 There is no limit on the disk space used by index cache. It is perfectly safe
22513 to delete the content of that directory to free up disk space.
22514
22515 @item show index-cache stats
22516 Print the number of cache hits and misses since the launch of @value{GDBN}.
22517
22518 @end table
22519
22520 @node Symbol Errors
22521 @section Errors Reading Symbol Files
22522
22523 While reading a symbol file, @value{GDBN} occasionally encounters problems,
22524 such as symbol types it does not recognize, or known bugs in compiler
22525 output. By default, @value{GDBN} does not notify you of such problems, since
22526 they are relatively common and primarily of interest to people
22527 debugging compilers. If you are interested in seeing information
22528 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
22529 only one message about each such type of problem, no matter how many
22530 times the problem occurs; or you can ask @value{GDBN} to print more messages,
22531 to see how many times the problems occur, with the @code{set
22532 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
22533 Messages}).
22534
22535 The messages currently printed, and their meanings, include:
22536
22537 @table @code
22538 @item inner block not inside outer block in @var{symbol}
22539
22540 The symbol information shows where symbol scopes begin and end
22541 (such as at the start of a function or a block of statements). This
22542 error indicates that an inner scope block is not fully contained
22543 in its outer scope blocks.
22544
22545 @value{GDBN} circumvents the problem by treating the inner block as if it had
22546 the same scope as the outer block. In the error message, @var{symbol}
22547 may be shown as ``@code{(don't know)}'' if the outer block is not a
22548 function.
22549
22550 @item block at @var{address} out of order
22551
22552 The symbol information for symbol scope blocks should occur in
22553 order of increasing addresses. This error indicates that it does not
22554 do so.
22555
22556 @value{GDBN} does not circumvent this problem, and has trouble
22557 locating symbols in the source file whose symbols it is reading. (You
22558 can often determine what source file is affected by specifying
22559 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
22560 Messages}.)
22561
22562 @item bad block start address patched
22563
22564 The symbol information for a symbol scope block has a start address
22565 smaller than the address of the preceding source line. This is known
22566 to occur in the SunOS 4.1.1 (and earlier) C compiler.
22567
22568 @value{GDBN} circumvents the problem by treating the symbol scope block as
22569 starting on the previous source line.
22570
22571 @item bad string table offset in symbol @var{n}
22572
22573 @cindex foo
22574 Symbol number @var{n} contains a pointer into the string table which is
22575 larger than the size of the string table.
22576
22577 @value{GDBN} circumvents the problem by considering the symbol to have the
22578 name @code{foo}, which may cause other problems if many symbols end up
22579 with this name.
22580
22581 @item unknown symbol type @code{0x@var{nn}}
22582
22583 The symbol information contains new data types that @value{GDBN} does
22584 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
22585 uncomprehended information, in hexadecimal.
22586
22587 @value{GDBN} circumvents the error by ignoring this symbol information.
22588 This usually allows you to debug your program, though certain symbols
22589 are not accessible. If you encounter such a problem and feel like
22590 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
22591 on @code{complain}, then go up to the function @code{read_dbx_symtab}
22592 and examine @code{*bufp} to see the symbol.
22593
22594 @item stub type has NULL name
22595
22596 @value{GDBN} could not find the full definition for a struct or class.
22597
22598 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
22599 The symbol information for a C@t{++} member function is missing some
22600 information that recent versions of the compiler should have output for
22601 it.
22602
22603 @item info mismatch between compiler and debugger
22604
22605 @value{GDBN} could not parse a type specification output by the compiler.
22606
22607 @end table
22608
22609 @node Data Files
22610 @section GDB Data Files
22611
22612 @cindex prefix for data files
22613 @value{GDBN} will sometimes read an auxiliary data file. These files
22614 are kept in a directory known as the @dfn{data directory}.
22615
22616 You can set the data directory's name, and view the name @value{GDBN}
22617 is currently using.
22618
22619 @table @code
22620 @kindex set data-directory
22621 @item set data-directory @var{directory}
22622 Set the directory which @value{GDBN} searches for auxiliary data files
22623 to @var{directory}.
22624
22625 @kindex show data-directory
22626 @item show data-directory
22627 Show the directory @value{GDBN} searches for auxiliary data files.
22628 @end table
22629
22630 @cindex default data directory
22631 @cindex @samp{--with-gdb-datadir}
22632 You can set the default data directory by using the configure-time
22633 @samp{--with-gdb-datadir} option. If the data directory is inside
22634 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
22635 @samp{--exec-prefix}), then the default data directory will be updated
22636 automatically if the installed @value{GDBN} is moved to a new
22637 location.
22638
22639 The data directory may also be specified with the
22640 @code{--data-directory} command line option.
22641 @xref{Mode Options}.
22642
22643 @node Targets
22644 @chapter Specifying a Debugging Target
22645
22646 @cindex debugging target
22647 A @dfn{target} is the execution environment occupied by your program.
22648
22649 Often, @value{GDBN} runs in the same host environment as your program;
22650 in that case, the debugging target is specified as a side effect when
22651 you use the @code{file} or @code{core} commands. When you need more
22652 flexibility---for example, running @value{GDBN} on a physically separate
22653 host, or controlling a standalone system over a serial port or a
22654 realtime system over a TCP/IP connection---you can use the @code{target}
22655 command to specify one of the target types configured for @value{GDBN}
22656 (@pxref{Target Commands, ,Commands for Managing Targets}).
22657
22658 @cindex target architecture
22659 It is possible to build @value{GDBN} for several different @dfn{target
22660 architectures}. When @value{GDBN} is built like that, you can choose
22661 one of the available architectures with the @kbd{set architecture}
22662 command.
22663
22664 @table @code
22665 @kindex set architecture
22666 @kindex show architecture
22667 @item set architecture @var{arch}
22668 This command sets the current target architecture to @var{arch}. The
22669 value of @var{arch} can be @code{"auto"}, in addition to one of the
22670 supported architectures.
22671
22672 @item show architecture
22673 Show the current target architecture.
22674
22675 @item set processor
22676 @itemx processor
22677 @kindex set processor
22678 @kindex show processor
22679 These are alias commands for, respectively, @code{set architecture}
22680 and @code{show architecture}.
22681 @end table
22682
22683 @menu
22684 * Active Targets:: Active targets
22685 * Target Commands:: Commands for managing targets
22686 * Byte Order:: Choosing target byte order
22687 @end menu
22688
22689 @node Active Targets
22690 @section Active Targets
22691
22692 @cindex stacking targets
22693 @cindex active targets
22694 @cindex multiple targets
22695
22696 There are multiple classes of targets such as: processes, executable files or
22697 recording sessions. Core files belong to the process class, making core file
22698 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
22699 on multiple active targets, one in each class. This allows you to (for
22700 example) start a process and inspect its activity, while still having access to
22701 the executable file after the process finishes. Or if you start process
22702 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
22703 presented a virtual layer of the recording target, while the process target
22704 remains stopped at the chronologically last point of the process execution.
22705
22706 Use the @code{core-file} and @code{exec-file} commands to select a new core
22707 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
22708 specify as a target a process that is already running, use the @code{attach}
22709 command (@pxref{Attach, ,Debugging an Already-running Process}).
22710
22711 @node Target Commands
22712 @section Commands for Managing Targets
22713
22714 @table @code
22715 @item target @var{type} @var{parameters}
22716 Connects the @value{GDBN} host environment to a target machine or
22717 process. A target is typically a protocol for talking to debugging
22718 facilities. You use the argument @var{type} to specify the type or
22719 protocol of the target machine.
22720
22721 Further @var{parameters} are interpreted by the target protocol, but
22722 typically include things like device names or host names to connect
22723 with, process numbers, and baud rates.
22724
22725 The @code{target} command does not repeat if you press @key{RET} again
22726 after executing the command.
22727
22728 @kindex help target
22729 @item help target
22730 Displays the names of all targets available. To display targets
22731 currently selected, use either @code{info target} or @code{info files}
22732 (@pxref{Files, ,Commands to Specify Files}).
22733
22734 @item help target @var{name}
22735 Describe a particular target, including any parameters necessary to
22736 select it.
22737
22738 @kindex set gnutarget
22739 @item set gnutarget @var{args}
22740 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
22741 knows whether it is reading an @dfn{executable},
22742 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
22743 with the @code{set gnutarget} command. Unlike most @code{target} commands,
22744 with @code{gnutarget} the @code{target} refers to a program, not a machine.
22745
22746 @quotation
22747 @emph{Warning:} To specify a file format with @code{set gnutarget},
22748 you must know the actual BFD name.
22749 @end quotation
22750
22751 @noindent
22752 @xref{Files, , Commands to Specify Files}.
22753
22754 @kindex show gnutarget
22755 @item show gnutarget
22756 Use the @code{show gnutarget} command to display what file format
22757 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
22758 @value{GDBN} will determine the file format for each file automatically,
22759 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
22760 @end table
22761
22762 @cindex common targets
22763 Here are some common targets (available, or not, depending on the GDB
22764 configuration):
22765
22766 @table @code
22767 @kindex target
22768 @item target exec @var{program}
22769 @cindex executable file target
22770 An executable file. @samp{target exec @var{program}} is the same as
22771 @samp{exec-file @var{program}}.
22772
22773 @item target core @var{filename}
22774 @cindex core dump file target
22775 A core dump file. @samp{target core @var{filename}} is the same as
22776 @samp{core-file @var{filename}}.
22777
22778 @item target remote @var{medium}
22779 @cindex remote target
22780 A remote system connected to @value{GDBN} via a serial line or network
22781 connection. This command tells @value{GDBN} to use its own remote
22782 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
22783
22784 For example, if you have a board connected to @file{/dev/ttya} on the
22785 machine running @value{GDBN}, you could say:
22786
22787 @smallexample
22788 target remote /dev/ttya
22789 @end smallexample
22790
22791 @code{target remote} supports the @code{load} command. This is only
22792 useful if you have some other way of getting the stub to the target
22793 system, and you can put it somewhere in memory where it won't get
22794 clobbered by the download.
22795
22796 @item target sim @r{[}@var{simargs}@r{]} @dots{}
22797 @cindex built-in simulator target
22798 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
22799 In general,
22800 @smallexample
22801 target sim
22802 load
22803 run
22804 @end smallexample
22805 @noindent
22806 works; however, you cannot assume that a specific memory map, device
22807 drivers, or even basic I/O is available, although some simulators do
22808 provide these. For info about any processor-specific simulator details,
22809 see the appropriate section in @ref{Embedded Processors, ,Embedded
22810 Processors}.
22811
22812 @item target native
22813 @cindex native target
22814 Setup for local/native process debugging. Useful to make the
22815 @code{run} command spawn native processes (likewise @code{attach},
22816 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
22817 (@pxref{set auto-connect-native-target}).
22818
22819 @end table
22820
22821 Different targets are available on different configurations of @value{GDBN};
22822 your configuration may have more or fewer targets.
22823
22824 Many remote targets require you to download the executable's code once
22825 you've successfully established a connection. You may wish to control
22826 various aspects of this process.
22827
22828 @table @code
22829
22830 @item set hash
22831 @kindex set hash@r{, for remote monitors}
22832 @cindex hash mark while downloading
22833 This command controls whether a hash mark @samp{#} is displayed while
22834 downloading a file to the remote monitor. If on, a hash mark is
22835 displayed after each S-record is successfully downloaded to the
22836 monitor.
22837
22838 @item show hash
22839 @kindex show hash@r{, for remote monitors}
22840 Show the current status of displaying the hash mark.
22841
22842 @item set debug monitor
22843 @kindex set debug monitor
22844 @cindex display remote monitor communications
22845 Enable or disable display of communications messages between
22846 @value{GDBN} and the remote monitor.
22847
22848 @item show debug monitor
22849 @kindex show debug monitor
22850 Show the current status of displaying communications between
22851 @value{GDBN} and the remote monitor.
22852 @end table
22853
22854 @table @code
22855
22856 @kindex load @var{filename} @var{offset}
22857 @item load @var{filename} @var{offset}
22858 @anchor{load}
22859 Depending on what remote debugging facilities are configured into
22860 @value{GDBN}, the @code{load} command may be available. Where it exists, it
22861 is meant to make @var{filename} (an executable) available for debugging
22862 on the remote system---by downloading, or dynamic linking, for example.
22863 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
22864 the @code{add-symbol-file} command.
22865
22866 If your @value{GDBN} does not have a @code{load} command, attempting to
22867 execute it gets the error message ``@code{You can't do that when your
22868 target is @dots{}}''
22869
22870 The file is loaded at whatever address is specified in the executable.
22871 For some object file formats, you can specify the load address when you
22872 link the program; for other formats, like a.out, the object file format
22873 specifies a fixed address.
22874 @c FIXME! This would be a good place for an xref to the GNU linker doc.
22875
22876 It is also possible to tell @value{GDBN} to load the executable file at a
22877 specific offset described by the optional argument @var{offset}. When
22878 @var{offset} is provided, @var{filename} must also be provided.
22879
22880 Depending on the remote side capabilities, @value{GDBN} may be able to
22881 load programs into flash memory.
22882
22883 @code{load} does not repeat if you press @key{RET} again after using it.
22884 @end table
22885
22886 @table @code
22887
22888 @kindex flash-erase
22889 @item flash-erase
22890 @anchor{flash-erase}
22891
22892 Erases all known flash memory regions on the target.
22893
22894 @end table
22895
22896 @node Byte Order
22897 @section Choosing Target Byte Order
22898
22899 @cindex choosing target byte order
22900 @cindex target byte order
22901
22902 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
22903 offer the ability to run either big-endian or little-endian byte
22904 orders. Usually the executable or symbol will include a bit to
22905 designate the endian-ness, and you will not need to worry about
22906 which to use. However, you may still find it useful to adjust
22907 @value{GDBN}'s idea of processor endian-ness manually.
22908
22909 @table @code
22910 @kindex set endian
22911 @item set endian big
22912 Instruct @value{GDBN} to assume the target is big-endian.
22913
22914 @item set endian little
22915 Instruct @value{GDBN} to assume the target is little-endian.
22916
22917 @item set endian auto
22918 Instruct @value{GDBN} to use the byte order associated with the
22919 executable.
22920
22921 @item show endian
22922 Display @value{GDBN}'s current idea of the target byte order.
22923
22924 @end table
22925
22926 If the @code{set endian auto} mode is in effect and no executable has
22927 been selected, then the endianness used is the last one chosen either
22928 by one of the @code{set endian big} and @code{set endian little}
22929 commands or by inferring from the last executable used. If no
22930 endianness has been previously chosen, then the default for this mode
22931 is inferred from the target @value{GDBN} has been built for, and is
22932 @code{little} if the name of the target CPU has an @code{el} suffix
22933 and @code{big} otherwise.
22934
22935 Note that these commands merely adjust interpretation of symbolic
22936 data on the host, and that they have absolutely no effect on the
22937 target system.
22938
22939
22940 @node Remote Debugging
22941 @chapter Debugging Remote Programs
22942 @cindex remote debugging
22943
22944 If you are trying to debug a program running on a machine that cannot run
22945 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22946 For example, you might use remote debugging on an operating system kernel,
22947 or on a small system which does not have a general purpose operating system
22948 powerful enough to run a full-featured debugger.
22949
22950 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22951 to make this work with particular debugging targets. In addition,
22952 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22953 but not specific to any particular target system) which you can use if you
22954 write the remote stubs---the code that runs on the remote system to
22955 communicate with @value{GDBN}.
22956
22957 Other remote targets may be available in your
22958 configuration of @value{GDBN}; use @code{help target} to list them.
22959
22960 @menu
22961 * Connecting:: Connecting to a remote target
22962 * File Transfer:: Sending files to a remote system
22963 * Server:: Using the gdbserver program
22964 * Remote Configuration:: Remote configuration
22965 * Remote Stub:: Implementing a remote stub
22966 @end menu
22967
22968 @node Connecting
22969 @section Connecting to a Remote Target
22970 @cindex remote debugging, connecting
22971 @cindex @code{gdbserver}, connecting
22972 @cindex remote debugging, types of connections
22973 @cindex @code{gdbserver}, types of connections
22974 @cindex @code{gdbserver}, @code{target remote} mode
22975 @cindex @code{gdbserver}, @code{target extended-remote} mode
22976
22977 This section describes how to connect to a remote target, including the
22978 types of connections and their differences, how to set up executable and
22979 symbol files on the host and target, and the commands used for
22980 connecting to and disconnecting from the remote target.
22981
22982 @subsection Types of Remote Connections
22983
22984 @value{GDBN} supports two types of remote connections, @code{target remote}
22985 mode and @code{target extended-remote} mode. Note that many remote targets
22986 support only @code{target remote} mode. There are several major
22987 differences between the two types of connections, enumerated here:
22988
22989 @table @asis
22990
22991 @cindex remote debugging, detach and program exit
22992 @item Result of detach or program exit
22993 @strong{With target remote mode:} When the debugged program exits or you
22994 detach from it, @value{GDBN} disconnects from the target. When using
22995 @code{gdbserver}, @code{gdbserver} will exit.
22996
22997 @strong{With target extended-remote mode:} When the debugged program exits or
22998 you detach from it, @value{GDBN} remains connected to the target, even
22999 though no program is running. You can rerun the program, attach to a
23000 running program, or use @code{monitor} commands specific to the target.
23001
23002 When using @code{gdbserver} in this case, it does not exit unless it was
23003 invoked using the @option{--once} option. If the @option{--once} option
23004 was not used, you can ask @code{gdbserver} to exit using the
23005 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
23006
23007 @item Specifying the program to debug
23008 For both connection types you use the @code{file} command to specify the
23009 program on the host system. If you are using @code{gdbserver} there are
23010 some differences in how to specify the location of the program on the
23011 target.
23012
23013 @strong{With target remote mode:} You must either specify the program to debug
23014 on the @code{gdbserver} command line or use the @option{--attach} option
23015 (@pxref{Attaching to a program,,Attaching to a Running Program}).
23016
23017 @cindex @option{--multi}, @code{gdbserver} option
23018 @strong{With target extended-remote mode:} You may specify the program to debug
23019 on the @code{gdbserver} command line, or you can load the program or attach
23020 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
23021
23022 @anchor{--multi Option in Types of Remote Connnections}
23023 You can start @code{gdbserver} without supplying an initial command to run
23024 or process ID to attach. To do this, use the @option{--multi} command line
23025 option. Then you can connect using @code{target extended-remote} and start
23026 the program you want to debug (see below for details on using the
23027 @code{run} command in this scenario). Note that the conditions under which
23028 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
23029 (@code{target remote} or @code{target extended-remote}). The
23030 @option{--multi} option to @code{gdbserver} has no influence on that.
23031
23032 @item The @code{run} command
23033 @strong{With target remote mode:} The @code{run} command is not
23034 supported. Once a connection has been established, you can use all
23035 the usual @value{GDBN} commands to examine and change data. The
23036 remote program is already running, so you can use commands like
23037 @kbd{step} and @kbd{continue}.
23038
23039 @strong{With target extended-remote mode:} The @code{run} command is
23040 supported. The @code{run} command uses the value set by
23041 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
23042 the program to run. Command line arguments are supported, except for
23043 wildcard expansion and I/O redirection (@pxref{Arguments}).
23044
23045 If you specify the program to debug on the command line, then the
23046 @code{run} command is not required to start execution, and you can
23047 resume using commands like @kbd{step} and @kbd{continue} as with
23048 @code{target remote} mode.
23049
23050 @anchor{Attaching in Types of Remote Connections}
23051 @item Attaching
23052 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
23053 not supported. To attach to a running program using @code{gdbserver}, you
23054 must use the @option{--attach} option (@pxref{Running gdbserver}).
23055
23056 @strong{With target extended-remote mode:} To attach to a running program,
23057 you may use the @code{attach} command after the connection has been
23058 established. If you are using @code{gdbserver}, you may also invoke
23059 @code{gdbserver} using the @option{--attach} option
23060 (@pxref{Running gdbserver}).
23061
23062 Some remote targets allow @value{GDBN} to determine the executable file running
23063 in the process the debugger is attaching to. In such a case, @value{GDBN}
23064 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
23065 between the executable file name running in the process and the name of the
23066 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
23067
23068 @end table
23069
23070 @anchor{Host and target files}
23071 @subsection Host and Target Files
23072 @cindex remote debugging, symbol files
23073 @cindex symbol files, remote debugging
23074
23075 @value{GDBN}, running on the host, needs access to symbol and debugging
23076 information for your program running on the target. This requires
23077 access to an unstripped copy of your program, and possibly any associated
23078 symbol files. Note that this section applies equally to both @code{target
23079 remote} mode and @code{target extended-remote} mode.
23080
23081 Some remote targets (@pxref{qXfer executable filename read}, and
23082 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
23083 the same connection used to communicate with @value{GDBN}. With such a
23084 target, if the remote program is unstripped, the only command you need is
23085 @code{target remote} (or @code{target extended-remote}).
23086
23087 If the remote program is stripped, or the target does not support remote
23088 program file access, start up @value{GDBN} using the name of the local
23089 unstripped copy of your program as the first argument, or use the
23090 @code{file} command. Use @code{set sysroot} to specify the location (on
23091 the host) of target libraries (unless your @value{GDBN} was compiled with
23092 the correct sysroot using @code{--with-sysroot}). Alternatively, you
23093 may use @code{set solib-search-path} to specify how @value{GDBN} locates
23094 target libraries.
23095
23096 The symbol file and target libraries must exactly match the executable
23097 and libraries on the target, with one exception: the files on the host
23098 system should not be stripped, even if the files on the target system
23099 are. Mismatched or missing files will lead to confusing results
23100 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
23101 files may also prevent @code{gdbserver} from debugging multi-threaded
23102 programs.
23103
23104 @subsection Remote Connection Commands
23105 @cindex remote connection commands
23106 @value{GDBN} can communicate with the target over a serial line, a
23107 local Unix domain socket, or
23108 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
23109 each case, @value{GDBN} uses the same protocol for debugging your
23110 program; only the medium carrying the debugging packets varies. The
23111 @code{target remote} and @code{target extended-remote} commands
23112 establish a connection to the target. Both commands accept the same
23113 arguments, which indicate the medium to use:
23114
23115 @table @code
23116
23117 @item target remote @var{serial-device}
23118 @itemx target extended-remote @var{serial-device}
23119 @cindex serial line, @code{target remote}
23120 Use @var{serial-device} to communicate with the target. For example,
23121 to use a serial line connected to the device named @file{/dev/ttyb}:
23122
23123 @smallexample
23124 target remote /dev/ttyb
23125 @end smallexample
23126
23127 If you're using a serial line, you may want to give @value{GDBN} the
23128 @samp{--baud} option, or use the @code{set serial baud} command
23129 (@pxref{Remote Configuration, set serial baud}) before the
23130 @code{target} command.
23131
23132 @item target remote @var{local-socket}
23133 @itemx target extended-remote @var{local-socket}
23134 @cindex local socket, @code{target remote}
23135 @cindex Unix domain socket
23136 Use @var{local-socket} to communicate with the target. For example,
23137 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
23138
23139 @smallexample
23140 target remote /tmp/gdb-socket0
23141 @end smallexample
23142
23143 Note that this command has the same form as the command to connect
23144 to a serial line. @value{GDBN} will automatically determine which
23145 kind of file you have specified and will make the appropriate kind
23146 of connection.
23147 This feature is not available if the host system does not support
23148 Unix domain sockets.
23149
23150 @item target remote @code{@var{host}:@var{port}}
23151 @itemx target remote @code{[@var{host}]:@var{port}}
23152 @itemx target remote @code{tcp:@var{host}:@var{port}}
23153 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
23154 @itemx target remote @code{tcp4:@var{host}:@var{port}}
23155 @itemx target remote @code{tcp6:@var{host}:@var{port}}
23156 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
23157 @itemx target extended-remote @code{@var{host}:@var{port}}
23158 @itemx target extended-remote @code{[@var{host}]:@var{port}}
23159 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
23160 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
23161 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
23162 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
23163 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
23164 @cindex @acronym{TCP} port, @code{target remote}
23165 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
23166 The @var{host} may be either a host name, a numeric @acronym{IPv4}
23167 address, or a numeric @acronym{IPv6} address (with or without the
23168 square brackets to separate the address from the port); @var{port}
23169 must be a decimal number. The @var{host} could be the target machine
23170 itself, if it is directly connected to the net, or it might be a
23171 terminal server which in turn has a serial line to the target.
23172
23173 For example, to connect to port 2828 on a terminal server named
23174 @code{manyfarms}:
23175
23176 @smallexample
23177 target remote manyfarms:2828
23178 @end smallexample
23179
23180 To connect to port 2828 on a terminal server whose address is
23181 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
23182 square bracket syntax:
23183
23184 @smallexample
23185 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
23186 @end smallexample
23187
23188 @noindent
23189 or explicitly specify the @acronym{IPv6} protocol:
23190
23191 @smallexample
23192 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
23193 @end smallexample
23194
23195 This last example may be confusing to the reader, because there is no
23196 visible separation between the hostname and the port number.
23197 Therefore, we recommend the user to provide @acronym{IPv6} addresses
23198 using square brackets for clarity. However, it is important to
23199 mention that for @value{GDBN} there is no ambiguity: the number after
23200 the last colon is considered to be the port number.
23201
23202 If your remote target is actually running on the same machine as your
23203 debugger session (e.g.@: a simulator for your target running on the
23204 same host), you can omit the hostname. For example, to connect to
23205 port 1234 on your local machine:
23206
23207 @smallexample
23208 target remote :1234
23209 @end smallexample
23210 @noindent
23211
23212 Note that the colon is still required here.
23213
23214 @item target remote @code{udp:@var{host}:@var{port}}
23215 @itemx target remote @code{udp:[@var{host}]:@var{port}}
23216 @itemx target remote @code{udp4:@var{host}:@var{port}}
23217 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
23218 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
23219 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
23220 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
23221 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
23222 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
23223 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
23224 @cindex @acronym{UDP} port, @code{target remote}
23225 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
23226 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
23227
23228 @smallexample
23229 target remote udp:manyfarms:2828
23230 @end smallexample
23231
23232 When using a @acronym{UDP} connection for remote debugging, you should
23233 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
23234 can silently drop packets on busy or unreliable networks, which will
23235 cause havoc with your debugging session.
23236
23237 @item target remote | @var{command}
23238 @itemx target extended-remote | @var{command}
23239 @cindex pipe, @code{target remote} to
23240 Run @var{command} in the background and communicate with it using a
23241 pipe. The @var{command} is a shell command, to be parsed and expanded
23242 by the system's command shell, @code{/bin/sh}; it should expect remote
23243 protocol packets on its standard input, and send replies on its
23244 standard output. You could use this to run a stand-alone simulator
23245 that speaks the remote debugging protocol, to make net connections
23246 using programs like @code{ssh}, or for other similar tricks.
23247
23248 If @var{command} closes its standard output (perhaps by exiting),
23249 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
23250 program has already exited, this will have no effect.)
23251
23252 @end table
23253
23254 @cindex interrupting remote programs
23255 @cindex remote programs, interrupting
23256 Whenever @value{GDBN} is waiting for the remote program, if you type the
23257 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
23258 program. This may or may not succeed, depending in part on the hardware
23259 and the serial drivers the remote system uses. If you type the
23260 interrupt character once again, @value{GDBN} displays this prompt:
23261
23262 @smallexample
23263 Interrupted while waiting for the program.
23264 Give up (and stop debugging it)? (y or n)
23265 @end smallexample
23266
23267 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
23268 the remote debugging session. (If you decide you want to try again later,
23269 you can use @kbd{target remote} again to connect once more.) If you type
23270 @kbd{n}, @value{GDBN} goes back to waiting.
23271
23272 In @code{target extended-remote} mode, typing @kbd{n} will leave
23273 @value{GDBN} connected to the target.
23274
23275 @table @code
23276 @kindex detach (remote)
23277 @item detach
23278 When you have finished debugging the remote program, you can use the
23279 @code{detach} command to release it from @value{GDBN} control.
23280 Detaching from the target normally resumes its execution, but the results
23281 will depend on your particular remote stub. After the @code{detach}
23282 command in @code{target remote} mode, @value{GDBN} is free to connect to
23283 another target. In @code{target extended-remote} mode, @value{GDBN} is
23284 still connected to the target.
23285
23286 @kindex disconnect
23287 @item disconnect
23288 The @code{disconnect} command closes the connection to the target, and
23289 the target is generally not resumed. It will wait for @value{GDBN}
23290 (this instance or another one) to connect and continue debugging. After
23291 the @code{disconnect} command, @value{GDBN} is again free to connect to
23292 another target.
23293
23294 @cindex send command to remote monitor
23295 @cindex extend @value{GDBN} for remote targets
23296 @cindex add new commands for external monitor
23297 @kindex monitor
23298 @item monitor @var{cmd}
23299 This command allows you to send arbitrary commands directly to the
23300 remote monitor. Since @value{GDBN} doesn't care about the commands it
23301 sends like this, this command is the way to extend @value{GDBN}---you
23302 can add new commands that only the external monitor will understand
23303 and implement.
23304 @end table
23305
23306 @node File Transfer
23307 @section Sending files to a remote system
23308 @cindex remote target, file transfer
23309 @cindex file transfer
23310 @cindex sending files to remote systems
23311
23312 Some remote targets offer the ability to transfer files over the same
23313 connection used to communicate with @value{GDBN}. This is convenient
23314 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
23315 running @code{gdbserver} over a network interface. For other targets,
23316 e.g.@: embedded devices with only a single serial port, this may be
23317 the only way to upload or download files.
23318
23319 Not all remote targets support these commands.
23320
23321 @table @code
23322 @kindex remote put
23323 @item remote put @var{hostfile} @var{targetfile}
23324 Copy file @var{hostfile} from the host system (the machine running
23325 @value{GDBN}) to @var{targetfile} on the target system.
23326
23327 @kindex remote get
23328 @item remote get @var{targetfile} @var{hostfile}
23329 Copy file @var{targetfile} from the target system to @var{hostfile}
23330 on the host system.
23331
23332 @kindex remote delete
23333 @item remote delete @var{targetfile}
23334 Delete @var{targetfile} from the target system.
23335
23336 @end table
23337
23338 @node Server
23339 @section Using the @code{gdbserver} Program
23340
23341 @kindex gdbserver
23342 @cindex remote connection without stubs
23343 @code{gdbserver} is a control program for Unix-like systems, which
23344 allows you to connect your program with a remote @value{GDBN} via
23345 @code{target remote} or @code{target extended-remote}---but without
23346 linking in the usual debugging stub.
23347
23348 @code{gdbserver} is not a complete replacement for the debugging stubs,
23349 because it requires essentially the same operating-system facilities
23350 that @value{GDBN} itself does. In fact, a system that can run
23351 @code{gdbserver} to connect to a remote @value{GDBN} could also run
23352 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
23353 because it is a much smaller program than @value{GDBN} itself. It is
23354 also easier to port than all of @value{GDBN}, so you may be able to get
23355 started more quickly on a new system by using @code{gdbserver}.
23356 Finally, if you develop code for real-time systems, you may find that
23357 the tradeoffs involved in real-time operation make it more convenient to
23358 do as much development work as possible on another system, for example
23359 by cross-compiling. You can use @code{gdbserver} to make a similar
23360 choice for debugging.
23361
23362 @value{GDBN} and @code{gdbserver} communicate via either a serial line
23363 or a TCP connection, using the standard @value{GDBN} remote serial
23364 protocol.
23365
23366 @quotation
23367 @emph{Warning:} @code{gdbserver} does not have any built-in security.
23368 Do not run @code{gdbserver} connected to any public network; a
23369 @value{GDBN} connection to @code{gdbserver} provides access to the
23370 target system with the same privileges as the user running
23371 @code{gdbserver}.
23372 @end quotation
23373
23374 @anchor{Running gdbserver}
23375 @subsection Running @code{gdbserver}
23376 @cindex arguments, to @code{gdbserver}
23377 @cindex @code{gdbserver}, command-line arguments
23378
23379 Run @code{gdbserver} on the target system. You need a copy of the
23380 program you want to debug, including any libraries it requires.
23381 @code{gdbserver} does not need your program's symbol table, so you can
23382 strip the program if necessary to save space. @value{GDBN} on the host
23383 system does all the symbol handling.
23384
23385 To use the server, you must tell it how to communicate with @value{GDBN};
23386 the name of your program; and the arguments for your program. The usual
23387 syntax is:
23388
23389 @smallexample
23390 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
23391 @end smallexample
23392
23393 @var{comm} is either a device name (to use a serial line), or a TCP
23394 hostname and portnumber, or @code{-} or @code{stdio} to use
23395 stdin/stdout of @code{gdbserver}.
23396 For example, to debug Emacs with the argument
23397 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
23398 @file{/dev/com1}:
23399
23400 @smallexample
23401 target> gdbserver /dev/com1 emacs foo.txt
23402 @end smallexample
23403
23404 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
23405 with it.
23406
23407 To use a TCP connection instead of a serial line:
23408
23409 @smallexample
23410 target> gdbserver host:2345 emacs foo.txt
23411 @end smallexample
23412
23413 The only difference from the previous example is the first argument,
23414 specifying that you are communicating with the host @value{GDBN} via
23415 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
23416 expect a TCP connection from machine @samp{host} to local TCP port 2345.
23417 (Currently, the @samp{host} part is ignored.) You can choose any number
23418 you want for the port number as long as it does not conflict with any
23419 TCP ports already in use on the target system (for example, @code{23} is
23420 reserved for @code{telnet}).@footnote{If you choose a port number that
23421 conflicts with another service, @code{gdbserver} prints an error message
23422 and exits.} You must use the same port number with the host @value{GDBN}
23423 @code{target remote} command.
23424
23425 The @code{stdio} connection is useful when starting @code{gdbserver}
23426 with ssh:
23427
23428 @smallexample
23429 (@value{GDBP}) target remote | ssh -T hostname gdbserver - hello
23430 @end smallexample
23431
23432 The @samp{-T} option to ssh is provided because we don't need a remote pty,
23433 and we don't want escape-character handling. Ssh does this by default when
23434 a command is provided, the flag is provided to make it explicit.
23435 You could elide it if you want to.
23436
23437 Programs started with stdio-connected gdbserver have @file{/dev/null} for
23438 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
23439 display through a pipe connected to gdbserver.
23440 Both @code{stdout} and @code{stderr} use the same pipe.
23441
23442 @anchor{Attaching to a program}
23443 @subsubsection Attaching to a Running Program
23444 @cindex attach to a program, @code{gdbserver}
23445 @cindex @option{--attach}, @code{gdbserver} option
23446
23447 On some targets, @code{gdbserver} can also attach to running programs.
23448 This is accomplished via the @code{--attach} argument. The syntax is:
23449
23450 @smallexample
23451 target> gdbserver --attach @var{comm} @var{pid}
23452 @end smallexample
23453
23454 @var{pid} is the process ID of a currently running process. It isn't
23455 necessary to point @code{gdbserver} at a binary for the running process.
23456
23457 In @code{target extended-remote} mode, you can also attach using the
23458 @value{GDBN} attach command
23459 (@pxref{Attaching in Types of Remote Connections}).
23460
23461 @pindex pidof
23462 You can debug processes by name instead of process ID if your target has the
23463 @code{pidof} utility:
23464
23465 @smallexample
23466 target> gdbserver --attach @var{comm} `pidof @var{program}`
23467 @end smallexample
23468
23469 In case more than one copy of @var{program} is running, or @var{program}
23470 has multiple threads, most versions of @code{pidof} support the
23471 @code{-s} option to only return the first process ID.
23472
23473 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
23474
23475 This section applies only when @code{gdbserver} is run to listen on a TCP
23476 port.
23477
23478 @code{gdbserver} normally terminates after all of its debugged processes have
23479 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
23480 extended-remote}, @code{gdbserver} stays running even with no processes left.
23481 @value{GDBN} normally terminates the spawned debugged process on its exit,
23482 which normally also terminates @code{gdbserver} in the @kbd{target remote}
23483 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
23484 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
23485 stays running even in the @kbd{target remote} mode.
23486
23487 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
23488 Such reconnecting is useful for features like @ref{disconnected tracing}. For
23489 completeness, at most one @value{GDBN} can be connected at a time.
23490
23491 @cindex @option{--once}, @code{gdbserver} option
23492 By default, @code{gdbserver} keeps the listening TCP port open, so that
23493 subsequent connections are possible. However, if you start @code{gdbserver}
23494 with the @option{--once} option, it will stop listening for any further
23495 connection attempts after connecting to the first @value{GDBN} session. This
23496 means no further connections to @code{gdbserver} will be possible after the
23497 first one. It also means @code{gdbserver} will terminate after the first
23498 connection with remote @value{GDBN} has closed, even for unexpectedly closed
23499 connections and even in the @kbd{target extended-remote} mode. The
23500 @option{--once} option allows reusing the same port number for connecting to
23501 multiple instances of @code{gdbserver} running on the same host, since each
23502 instance closes its port after the first connection.
23503
23504 @anchor{Other Command-Line Arguments for gdbserver}
23505 @subsubsection Other Command-Line Arguments for @code{gdbserver}
23506
23507 You can use the @option{--multi} option to start @code{gdbserver} without
23508 specifying a program to debug or a process to attach to. Then you can
23509 attach in @code{target extended-remote} mode and run or attach to a
23510 program. For more information,
23511 @pxref{--multi Option in Types of Remote Connnections}.
23512
23513 @cindex @option{--debug}, @code{gdbserver} option
23514 The @option{--debug} option tells @code{gdbserver} to display extra
23515 status information about the debugging process.
23516 @cindex @option{--remote-debug}, @code{gdbserver} option
23517 The @option{--remote-debug} option tells @code{gdbserver} to display
23518 remote protocol debug output.
23519 @cindex @option{--debug-file}, @code{gdbserver} option
23520 @cindex @code{gdbserver}, send all debug output to a single file
23521 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
23522 write any debug output to the given @var{filename}. These options are intended
23523 for @code{gdbserver} development and for bug reports to the developers.
23524
23525 @cindex @option{--debug-format}, @code{gdbserver} option
23526 The @option{--debug-format=option1[,option2,...]} option tells
23527 @code{gdbserver} to include additional information in each output.
23528 Possible options are:
23529
23530 @table @code
23531 @item none
23532 Turn off all extra information in debugging output.
23533 @item all
23534 Turn on all extra information in debugging output.
23535 @item timestamps
23536 Include a timestamp in each line of debugging output.
23537 @end table
23538
23539 Options are processed in order. Thus, for example, if @option{none}
23540 appears last then no additional information is added to debugging output.
23541
23542 @cindex @option{--wrapper}, @code{gdbserver} option
23543 The @option{--wrapper} option specifies a wrapper to launch programs
23544 for debugging. The option should be followed by the name of the
23545 wrapper, then any command-line arguments to pass to the wrapper, then
23546 @kbd{--} indicating the end of the wrapper arguments.
23547
23548 @code{gdbserver} runs the specified wrapper program with a combined
23549 command line including the wrapper arguments, then the name of the
23550 program to debug, then any arguments to the program. The wrapper
23551 runs until it executes your program, and then @value{GDBN} gains control.
23552
23553 You can use any program that eventually calls @code{execve} with
23554 its arguments as a wrapper. Several standard Unix utilities do
23555 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
23556 with @code{exec "$@@"} will also work.
23557
23558 For example, you can use @code{env} to pass an environment variable to
23559 the debugged program, without setting the variable in @code{gdbserver}'s
23560 environment:
23561
23562 @smallexample
23563 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
23564 @end smallexample
23565
23566 @cindex @option{--selftest}
23567 The @option{--selftest} option runs the self tests in @code{gdbserver}:
23568
23569 @smallexample
23570 $ gdbserver --selftest
23571 Ran 2 unit tests, 0 failed
23572 @end smallexample
23573
23574 These tests are disabled in release.
23575 @subsection Connecting to @code{gdbserver}
23576
23577 The basic procedure for connecting to the remote target is:
23578 @itemize
23579
23580 @item
23581 Run @value{GDBN} on the host system.
23582
23583 @item
23584 Make sure you have the necessary symbol files
23585 (@pxref{Host and target files}).
23586 Load symbols for your application using the @code{file} command before you
23587 connect. Use @code{set sysroot} to locate target libraries (unless your
23588 @value{GDBN} was compiled with the correct sysroot using
23589 @code{--with-sysroot}).
23590
23591 @item
23592 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
23593 For TCP connections, you must start up @code{gdbserver} prior to using
23594 the @code{target} command. Otherwise you may get an error whose
23595 text depends on the host system, but which usually looks something like
23596 @samp{Connection refused}. Don't use the @code{load}
23597 command in @value{GDBN} when using @code{target remote} mode, since the
23598 program is already on the target.
23599
23600 @end itemize
23601
23602 @anchor{Monitor Commands for gdbserver}
23603 @subsection Monitor Commands for @code{gdbserver}
23604 @cindex monitor commands, for @code{gdbserver}
23605
23606 During a @value{GDBN} session using @code{gdbserver}, you can use the
23607 @code{monitor} command to send special requests to @code{gdbserver}.
23608 Here are the available commands.
23609
23610 @table @code
23611 @item monitor help
23612 List the available monitor commands.
23613
23614 @item monitor set debug 0
23615 @itemx monitor set debug 1
23616 Disable or enable general debugging messages.
23617
23618 @item monitor set remote-debug 0
23619 @itemx monitor set remote-debug 1
23620 Disable or enable specific debugging messages associated with the remote
23621 protocol (@pxref{Remote Protocol}).
23622
23623 @item monitor set debug-file filename
23624 @itemx monitor set debug-file
23625 Send any debug output to the given file, or to stderr.
23626
23627 @item monitor set debug-format option1@r{[},option2,...@r{]}
23628 Specify additional text to add to debugging messages.
23629 Possible options are:
23630
23631 @table @code
23632 @item none
23633 Turn off all extra information in debugging output.
23634 @item all
23635 Turn on all extra information in debugging output.
23636 @item timestamps
23637 Include a timestamp in each line of debugging output.
23638 @end table
23639
23640 Options are processed in order. Thus, for example, if @option{none}
23641 appears last then no additional information is added to debugging output.
23642
23643 @item monitor set libthread-db-search-path [PATH]
23644 @cindex gdbserver, search path for @code{libthread_db}
23645 When this command is issued, @var{path} is a colon-separated list of
23646 directories to search for @code{libthread_db} (@pxref{Threads,,set
23647 libthread-db-search-path}). If you omit @var{path},
23648 @samp{libthread-db-search-path} will be reset to its default value.
23649
23650 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
23651 not supported in @code{gdbserver}.
23652
23653 @item monitor exit
23654 Tell gdbserver to exit immediately. This command should be followed by
23655 @code{disconnect} to close the debugging session. @code{gdbserver} will
23656 detach from any attached processes and kill any processes it created.
23657 Use @code{monitor exit} to terminate @code{gdbserver} at the end
23658 of a multi-process mode debug session.
23659
23660 @end table
23661
23662 @subsection Tracepoints support in @code{gdbserver}
23663 @cindex tracepoints support in @code{gdbserver}
23664
23665 On some targets, @code{gdbserver} supports tracepoints, fast
23666 tracepoints and static tracepoints.
23667
23668 For fast or static tracepoints to work, a special library called the
23669 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
23670 This library is built and distributed as an integral part of
23671 @code{gdbserver}. In addition, support for static tracepoints
23672 requires building the in-process agent library with static tracepoints
23673 support. At present, the UST (LTTng Userspace Tracer,
23674 @url{http://lttng.org/ust}) tracing engine is supported. This support
23675 is automatically available if UST development headers are found in the
23676 standard include path when @code{gdbserver} is built, or if
23677 @code{gdbserver} was explicitly configured using @option{--with-ust}
23678 to point at such headers. You can explicitly disable the support
23679 using @option{--with-ust=no}.
23680
23681 There are several ways to load the in-process agent in your program:
23682
23683 @table @code
23684 @item Specifying it as dependency at link time
23685
23686 You can link your program dynamically with the in-process agent
23687 library. On most systems, this is accomplished by adding
23688 @code{-linproctrace} to the link command.
23689
23690 @item Using the system's preloading mechanisms
23691
23692 You can force loading the in-process agent at startup time by using
23693 your system's support for preloading shared libraries. Many Unixes
23694 support the concept of preloading user defined libraries. In most
23695 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
23696 in the environment. See also the description of @code{gdbserver}'s
23697 @option{--wrapper} command line option.
23698
23699 @item Using @value{GDBN} to force loading the agent at run time
23700
23701 On some systems, you can force the inferior to load a shared library,
23702 by calling a dynamic loader function in the inferior that takes care
23703 of dynamically looking up and loading a shared library. On most Unix
23704 systems, the function is @code{dlopen}. You'll use the @code{call}
23705 command for that. For example:
23706
23707 @smallexample
23708 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
23709 @end smallexample
23710
23711 Note that on most Unix systems, for the @code{dlopen} function to be
23712 available, the program needs to be linked with @code{-ldl}.
23713 @end table
23714
23715 On systems that have a userspace dynamic loader, like most Unix
23716 systems, when you connect to @code{gdbserver} using @code{target
23717 remote}, you'll find that the program is stopped at the dynamic
23718 loader's entry point, and no shared library has been loaded in the
23719 program's address space yet, including the in-process agent. In that
23720 case, before being able to use any of the fast or static tracepoints
23721 features, you need to let the loader run and load the shared
23722 libraries. The simplest way to do that is to run the program to the
23723 main procedure. E.g., if debugging a C or C@t{++} program, start
23724 @code{gdbserver} like so:
23725
23726 @smallexample
23727 $ gdbserver :9999 myprogram
23728 @end smallexample
23729
23730 Start GDB and connect to @code{gdbserver} like so, and run to main:
23731
23732 @smallexample
23733 $ gdb myprogram
23734 (@value{GDBP}) target remote myhost:9999
23735 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
23736 (@value{GDBP}) b main
23737 (@value{GDBP}) continue
23738 @end smallexample
23739
23740 The in-process tracing agent library should now be loaded into the
23741 process; you can confirm it with the @code{info sharedlibrary}
23742 command, which will list @file{libinproctrace.so} as loaded in the
23743 process. You are now ready to install fast tracepoints, list static
23744 tracepoint markers, probe static tracepoints markers, and start
23745 tracing.
23746
23747 @node Remote Configuration
23748 @section Remote Configuration
23749
23750 @kindex set remote
23751 @kindex show remote
23752 This section documents the configuration options available when
23753 debugging remote programs. For the options related to the File I/O
23754 extensions of the remote protocol, see @ref{system,
23755 system-call-allowed}.
23756
23757 @table @code
23758 @item set remoteaddresssize @var{bits}
23759 @cindex address size for remote targets
23760 @cindex bits in remote address
23761 Set the maximum size of address in a memory packet to the specified
23762 number of bits. @value{GDBN} will mask off the address bits above
23763 that number, when it passes addresses to the remote target. The
23764 default value is the number of bits in the target's address.
23765
23766 @item show remoteaddresssize
23767 Show the current value of remote address size in bits.
23768
23769 @item set serial baud @var{n}
23770 @cindex baud rate for remote targets
23771 Set the baud rate for the remote serial I/O to @var{n} baud. The
23772 value is used to set the speed of the serial port used for debugging
23773 remote targets.
23774
23775 @item show serial baud
23776 Show the current speed of the remote connection.
23777
23778 @item set serial parity @var{parity}
23779 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
23780 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
23781
23782 @item show serial parity
23783 Show the current parity of the serial port.
23784
23785 @item set remotebreak
23786 @cindex interrupt remote programs
23787 @cindex BREAK signal instead of Ctrl-C
23788 @anchor{set remotebreak}
23789 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
23790 when you type @kbd{Ctrl-c} to interrupt the program running
23791 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
23792 character instead. The default is off, since most remote systems
23793 expect to see @samp{Ctrl-C} as the interrupt signal.
23794
23795 @item show remotebreak
23796 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
23797 interrupt the remote program.
23798
23799 @item set remoteflow on
23800 @itemx set remoteflow off
23801 @kindex set remoteflow
23802 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
23803 on the serial port used to communicate to the remote target.
23804
23805 @item show remoteflow
23806 @kindex show remoteflow
23807 Show the current setting of hardware flow control.
23808
23809 @item set remotelogbase @var{base}
23810 Set the base (a.k.a.@: radix) of logging serial protocol
23811 communications to @var{base}. Supported values of @var{base} are:
23812 @code{ascii}, @code{octal}, and @code{hex}. The default is
23813 @code{ascii}.
23814
23815 @item show remotelogbase
23816 Show the current setting of the radix for logging remote serial
23817 protocol.
23818
23819 @item set remotelogfile @var{file}
23820 @cindex record serial communications on file
23821 Record remote serial communications on the named @var{file}. The
23822 default is not to record at all.
23823
23824 @item show remotelogfile
23825 Show the current setting of the file name on which to record the
23826 serial communications.
23827
23828 @item set remotetimeout @var{num}
23829 @cindex timeout for serial communications
23830 @cindex remote timeout
23831 Set the timeout limit to wait for the remote target to respond to
23832 @var{num} seconds. The default is 2 seconds.
23833
23834 @item show remotetimeout
23835 Show the current number of seconds to wait for the remote target
23836 responses.
23837
23838 @cindex limit hardware breakpoints and watchpoints
23839 @cindex remote target, limit break- and watchpoints
23840 @anchor{set remote hardware-watchpoint-limit}
23841 @anchor{set remote hardware-breakpoint-limit}
23842 @item set remote hardware-watchpoint-limit @var{limit}
23843 @itemx set remote hardware-breakpoint-limit @var{limit}
23844 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
23845 or breakpoints. The @var{limit} can be set to 0 to disable hardware
23846 watchpoints or breakpoints, and @code{unlimited} for unlimited
23847 watchpoints or breakpoints.
23848
23849 @item show remote hardware-watchpoint-limit
23850 @itemx show remote hardware-breakpoint-limit
23851 Show the current limit for the number of hardware watchpoints or
23852 breakpoints that @value{GDBN} can use.
23853
23854 @cindex limit hardware watchpoints length
23855 @cindex remote target, limit watchpoints length
23856 @anchor{set remote hardware-watchpoint-length-limit}
23857 @item set remote hardware-watchpoint-length-limit @var{limit}
23858 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
23859 length of a remote hardware watchpoint. A @var{limit} of 0 disables
23860 hardware watchpoints and @code{unlimited} allows watchpoints of any
23861 length.
23862
23863 @item show remote hardware-watchpoint-length-limit
23864 Show the current limit (in bytes) of the maximum length of
23865 a remote hardware watchpoint.
23866
23867 @item set remote exec-file @var{filename}
23868 @itemx show remote exec-file
23869 @anchor{set remote exec-file}
23870 @cindex executable file, for remote target
23871 Select the file used for @code{run} with @code{target
23872 extended-remote}. This should be set to a filename valid on the
23873 target system. If it is not set, the target will use a default
23874 filename (e.g.@: the last program run).
23875
23876 @item set remote interrupt-sequence
23877 @cindex interrupt remote programs
23878 @cindex select Ctrl-C, BREAK or BREAK-g
23879 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
23880 @samp{BREAK-g} as the
23881 sequence to the remote target in order to interrupt the execution.
23882 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
23883 is high level of serial line for some certain time.
23884 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
23885 It is @code{BREAK} signal followed by character @code{g}.
23886
23887 @item show remote interrupt-sequence
23888 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
23889 is sent by @value{GDBN} to interrupt the remote program.
23890 @code{BREAK-g} is BREAK signal followed by @code{g} and
23891 also known as Magic SysRq g.
23892
23893 @item set remote interrupt-on-connect
23894 @cindex send interrupt-sequence on start
23895 Specify whether interrupt-sequence is sent to remote target when
23896 @value{GDBN} connects to it. This is mostly needed when you debug
23897 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
23898 which is known as Magic SysRq g in order to connect @value{GDBN}.
23899
23900 @item show remote interrupt-on-connect
23901 Show whether interrupt-sequence is sent
23902 to remote target when @value{GDBN} connects to it.
23903
23904 @kindex set tcp
23905 @kindex show tcp
23906 @item set tcp auto-retry on
23907 @cindex auto-retry, for remote TCP target
23908 Enable auto-retry for remote TCP connections. This is useful if the remote
23909 debugging agent is launched in parallel with @value{GDBN}; there is a race
23910 condition because the agent may not become ready to accept the connection
23911 before @value{GDBN} attempts to connect. When auto-retry is
23912 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
23913 to establish the connection using the timeout specified by
23914 @code{set tcp connect-timeout}.
23915
23916 @item set tcp auto-retry off
23917 Do not auto-retry failed TCP connections.
23918
23919 @item show tcp auto-retry
23920 Show the current auto-retry setting.
23921
23922 @item set tcp connect-timeout @var{seconds}
23923 @itemx set tcp connect-timeout unlimited
23924 @cindex connection timeout, for remote TCP target
23925 @cindex timeout, for remote target connection
23926 Set the timeout for establishing a TCP connection to the remote target to
23927 @var{seconds}. The timeout affects both polling to retry failed connections
23928 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23929 that are merely slow to complete, and represents an approximate cumulative
23930 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23931 @value{GDBN} will keep attempting to establish a connection forever,
23932 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23933
23934 @item show tcp connect-timeout
23935 Show the current connection timeout setting.
23936 @end table
23937
23938 @cindex remote packets, enabling and disabling
23939 The @value{GDBN} remote protocol autodetects the packets supported by
23940 your debugging stub. If you need to override the autodetection, you
23941 can use these commands to enable or disable individual packets. Each
23942 packet can be set to @samp{on} (the remote target supports this
23943 packet), @samp{off} (the remote target does not support this packet),
23944 or @samp{auto} (detect remote target support for this packet). They
23945 all default to @samp{auto}. For more information about each packet,
23946 see @ref{Remote Protocol}.
23947
23948 During normal use, you should not have to use any of these commands.
23949 If you do, that may be a bug in your remote debugging stub, or a bug
23950 in @value{GDBN}. You may want to report the problem to the
23951 @value{GDBN} developers.
23952
23953 For each packet @var{name}, the command to enable or disable the
23954 packet is @code{set remote @var{name}-packet}. If you configure a packet, the
23955 configuration will apply for all future remote targets if no target is selected.
23956 In case there is a target selected, only the configuration of the current target
23957 is changed. All other existing remote targets' features are not affected.
23958 The command to print the current configuration of a packet is
23959 @code{show remote @var{name}-packet}. It displays the current remote target's
23960 configuration. If no remote target is selected, the default configuration for
23961 future connections is shown. The available settings are:
23962
23963 @multitable @columnfractions 0.28 0.32 0.25
23964 @item Command Name
23965 @tab Remote Packet
23966 @tab Related Features
23967
23968 @item @code{fetch-register}
23969 @tab @code{p}
23970 @tab @code{info registers}
23971
23972 @item @code{set-register}
23973 @tab @code{P}
23974 @tab @code{set}
23975
23976 @item @code{binary-download}
23977 @tab @code{X}
23978 @tab @code{load}, @code{set}
23979
23980 @item @code{read-aux-vector}
23981 @tab @code{qXfer:auxv:read}
23982 @tab @code{info auxv}
23983
23984 @item @code{symbol-lookup}
23985 @tab @code{qSymbol}
23986 @tab Detecting multiple threads
23987
23988 @item @code{attach}
23989 @tab @code{vAttach}
23990 @tab @code{attach}
23991
23992 @item @code{verbose-resume}
23993 @tab @code{vCont}
23994 @tab Stepping or resuming multiple threads
23995
23996 @item @code{run}
23997 @tab @code{vRun}
23998 @tab @code{run}
23999
24000 @item @code{software-breakpoint}
24001 @tab @code{Z0}
24002 @tab @code{break}
24003
24004 @item @code{hardware-breakpoint}
24005 @tab @code{Z1}
24006 @tab @code{hbreak}
24007
24008 @item @code{write-watchpoint}
24009 @tab @code{Z2}
24010 @tab @code{watch}
24011
24012 @item @code{read-watchpoint}
24013 @tab @code{Z3}
24014 @tab @code{rwatch}
24015
24016 @item @code{access-watchpoint}
24017 @tab @code{Z4}
24018 @tab @code{awatch}
24019
24020 @item @code{pid-to-exec-file}
24021 @tab @code{qXfer:exec-file:read}
24022 @tab @code{attach}, @code{run}
24023
24024 @item @code{target-features}
24025 @tab @code{qXfer:features:read}
24026 @tab @code{set architecture}
24027
24028 @item @code{library-info}
24029 @tab @code{qXfer:libraries:read}
24030 @tab @code{info sharedlibrary}
24031
24032 @item @code{memory-map}
24033 @tab @code{qXfer:memory-map:read}
24034 @tab @code{info mem}
24035
24036 @item @code{read-sdata-object}
24037 @tab @code{qXfer:sdata:read}
24038 @tab @code{print $_sdata}
24039
24040 @item @code{read-siginfo-object}
24041 @tab @code{qXfer:siginfo:read}
24042 @tab @code{print $_siginfo}
24043
24044 @item @code{write-siginfo-object}
24045 @tab @code{qXfer:siginfo:write}
24046 @tab @code{set $_siginfo}
24047
24048 @item @code{threads}
24049 @tab @code{qXfer:threads:read}
24050 @tab @code{info threads}
24051
24052 @item @code{get-thread-local-@*storage-address}
24053 @tab @code{qGetTLSAddr}
24054 @tab Displaying @code{__thread} variables
24055
24056 @item @code{get-thread-information-block-address}
24057 @tab @code{qGetTIBAddr}
24058 @tab Display MS-Windows Thread Information Block.
24059
24060 @item @code{search-memory}
24061 @tab @code{qSearch:memory}
24062 @tab @code{find}
24063
24064 @item @code{supported-packets}
24065 @tab @code{qSupported}
24066 @tab Remote communications parameters
24067
24068 @item @code{catch-syscalls}
24069 @tab @code{QCatchSyscalls}
24070 @tab @code{catch syscall}
24071
24072 @item @code{pass-signals}
24073 @tab @code{QPassSignals}
24074 @tab @code{handle @var{signal}}
24075
24076 @item @code{program-signals}
24077 @tab @code{QProgramSignals}
24078 @tab @code{handle @var{signal}}
24079
24080 @item @code{hostio-close-packet}
24081 @tab @code{vFile:close}
24082 @tab @code{remote get}, @code{remote put}
24083
24084 @item @code{hostio-open-packet}
24085 @tab @code{vFile:open}
24086 @tab @code{remote get}, @code{remote put}
24087
24088 @item @code{hostio-pread-packet}
24089 @tab @code{vFile:pread}
24090 @tab @code{remote get}, @code{remote put}
24091
24092 @item @code{hostio-pwrite-packet}
24093 @tab @code{vFile:pwrite}
24094 @tab @code{remote get}, @code{remote put}
24095
24096 @item @code{hostio-unlink-packet}
24097 @tab @code{vFile:unlink}
24098 @tab @code{remote delete}
24099
24100 @item @code{hostio-readlink-packet}
24101 @tab @code{vFile:readlink}
24102 @tab Host I/O
24103
24104 @item @code{hostio-fstat-packet}
24105 @tab @code{vFile:fstat}
24106 @tab Host I/O
24107
24108 @item @code{hostio-setfs-packet}
24109 @tab @code{vFile:setfs}
24110 @tab Host I/O
24111
24112 @item @code{noack-packet}
24113 @tab @code{QStartNoAckMode}
24114 @tab Packet acknowledgment
24115
24116 @item @code{osdata}
24117 @tab @code{qXfer:osdata:read}
24118 @tab @code{info os}
24119
24120 @item @code{query-attached}
24121 @tab @code{qAttached}
24122 @tab Querying remote process attach state.
24123
24124 @item @code{trace-buffer-size}
24125 @tab @code{QTBuffer:size}
24126 @tab @code{set trace-buffer-size}
24127
24128 @item @code{trace-status}
24129 @tab @code{qTStatus}
24130 @tab @code{tstatus}
24131
24132 @item @code{traceframe-info}
24133 @tab @code{qXfer:traceframe-info:read}
24134 @tab Traceframe info
24135
24136 @item @code{install-in-trace}
24137 @tab @code{InstallInTrace}
24138 @tab Install tracepoint in tracing
24139
24140 @item @code{disable-randomization}
24141 @tab @code{QDisableRandomization}
24142 @tab @code{set disable-randomization}
24143
24144 @item @code{startup-with-shell}
24145 @tab @code{QStartupWithShell}
24146 @tab @code{set startup-with-shell}
24147
24148 @item @code{environment-hex-encoded}
24149 @tab @code{QEnvironmentHexEncoded}
24150 @tab @code{set environment}
24151
24152 @item @code{environment-unset}
24153 @tab @code{QEnvironmentUnset}
24154 @tab @code{unset environment}
24155
24156 @item @code{environment-reset}
24157 @tab @code{QEnvironmentReset}
24158 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
24159
24160 @item @code{set-working-dir}
24161 @tab @code{QSetWorkingDir}
24162 @tab @code{set cwd}
24163
24164 @item @code{conditional-breakpoints-packet}
24165 @tab @code{Z0 and Z1}
24166 @tab @code{Support for target-side breakpoint condition evaluation}
24167
24168 @item @code{multiprocess-extensions}
24169 @tab @code{multiprocess extensions}
24170 @tab Debug multiple processes and remote process PID awareness
24171
24172 @item @code{swbreak-feature}
24173 @tab @code{swbreak stop reason}
24174 @tab @code{break}
24175
24176 @item @code{hwbreak-feature}
24177 @tab @code{hwbreak stop reason}
24178 @tab @code{hbreak}
24179
24180 @item @code{fork-event-feature}
24181 @tab @code{fork stop reason}
24182 @tab @code{fork}
24183
24184 @item @code{vfork-event-feature}
24185 @tab @code{vfork stop reason}
24186 @tab @code{vfork}
24187
24188 @item @code{exec-event-feature}
24189 @tab @code{exec stop reason}
24190 @tab @code{exec}
24191
24192 @item @code{thread-events}
24193 @tab @code{QThreadEvents}
24194 @tab Tracking thread lifetime.
24195
24196 @item @code{no-resumed-stop-reply}
24197 @tab @code{no resumed thread left stop reply}
24198 @tab Tracking thread lifetime.
24199
24200 @end multitable
24201
24202 @cindex packet size, remote, configuring
24203 The number of bytes per memory-read or memory-write packet for a remote target
24204 can be configured using the commands
24205 @w{@code{set remote memory-read-packet-size}} and
24206 @w{@code{set remote memory-write-packet-size}}. If set to @samp{0} (zero) the
24207 default packet size will be used. The actual limit is further reduced depending
24208 on the target. Specify @samp{fixed} to disable the target-dependent restriction
24209 and @samp{limit} to enable it. Similar to the enabling and disabling of remote
24210 packets, the command applies to the currently selected target (if available).
24211 If no remote target is selected, it applies to all future remote connections.
24212 The configuration of the selected target can be displayed using the commands
24213 @w{@code{show remote memory-read-packet-size}} and
24214 @w{@code{show remote memory-write-packet-size}}. If no remote target is
24215 selected, the default configuration for future connections is shown.
24216
24217 @node Remote Stub
24218 @section Implementing a Remote Stub
24219
24220 @cindex debugging stub, example
24221 @cindex remote stub, example
24222 @cindex stub example, remote debugging
24223 The stub files provided with @value{GDBN} implement the target side of the
24224 communication protocol, and the @value{GDBN} side is implemented in the
24225 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
24226 these subroutines to communicate, and ignore the details. (If you're
24227 implementing your own stub file, you can still ignore the details: start
24228 with one of the existing stub files. @file{sparc-stub.c} is the best
24229 organized, and therefore the easiest to read.)
24230
24231 @cindex remote serial debugging, overview
24232 To debug a program running on another machine (the debugging
24233 @dfn{target} machine), you must first arrange for all the usual
24234 prerequisites for the program to run by itself. For example, for a C
24235 program, you need:
24236
24237 @enumerate
24238 @item
24239 A startup routine to set up the C runtime environment; these usually
24240 have a name like @file{crt0}. The startup routine may be supplied by
24241 your hardware supplier, or you may have to write your own.
24242
24243 @item
24244 A C subroutine library to support your program's
24245 subroutine calls, notably managing input and output.
24246
24247 @item
24248 A way of getting your program to the other machine---for example, a
24249 download program. These are often supplied by the hardware
24250 manufacturer, but you may have to write your own from hardware
24251 documentation.
24252 @end enumerate
24253
24254 The next step is to arrange for your program to use a serial port to
24255 communicate with the machine where @value{GDBN} is running (the @dfn{host}
24256 machine). In general terms, the scheme looks like this:
24257
24258 @table @emph
24259 @item On the host,
24260 @value{GDBN} already understands how to use this protocol; when everything
24261 else is set up, you can simply use the @samp{target remote} command
24262 (@pxref{Targets,,Specifying a Debugging Target}).
24263
24264 @item On the target,
24265 you must link with your program a few special-purpose subroutines that
24266 implement the @value{GDBN} remote serial protocol. The file containing these
24267 subroutines is called a @dfn{debugging stub}.
24268
24269 On certain remote targets, you can use an auxiliary program
24270 @code{gdbserver} instead of linking a stub into your program.
24271 @xref{Server,,Using the @code{gdbserver} Program}, for details.
24272 @end table
24273
24274 The debugging stub is specific to the architecture of the remote
24275 machine; for example, use @file{sparc-stub.c} to debug programs on
24276 @sc{sparc} boards.
24277
24278 @cindex remote serial stub list
24279 These working remote stubs are distributed with @value{GDBN}:
24280
24281 @table @code
24282
24283 @item i386-stub.c
24284 @cindex @file{i386-stub.c}
24285 @cindex Intel
24286 @cindex i386
24287 For Intel 386 and compatible architectures.
24288
24289 @item m68k-stub.c
24290 @cindex @file{m68k-stub.c}
24291 @cindex Motorola 680x0
24292 @cindex m680x0
24293 For Motorola 680x0 architectures.
24294
24295 @item sh-stub.c
24296 @cindex @file{sh-stub.c}
24297 @cindex Renesas
24298 @cindex SH
24299 For Renesas SH architectures.
24300
24301 @item sparc-stub.c
24302 @cindex @file{sparc-stub.c}
24303 @cindex Sparc
24304 For @sc{sparc} architectures.
24305
24306 @item sparcl-stub.c
24307 @cindex @file{sparcl-stub.c}
24308 @cindex Fujitsu
24309 @cindex SparcLite
24310 For Fujitsu @sc{sparclite} architectures.
24311
24312 @end table
24313
24314 The @file{README} file in the @value{GDBN} distribution may list other
24315 recently added stubs.
24316
24317 @menu
24318 * Stub Contents:: What the stub can do for you
24319 * Bootstrapping:: What you must do for the stub
24320 * Debug Session:: Putting it all together
24321 @end menu
24322
24323 @node Stub Contents
24324 @subsection What the Stub Can Do for You
24325
24326 @cindex remote serial stub
24327 The debugging stub for your architecture supplies these three
24328 subroutines:
24329
24330 @table @code
24331 @findex set_debug_traps
24332 @item set_debug_traps
24333 @cindex remote serial stub, initialization
24334 This routine arranges for @code{handle_exception} to run when your
24335 program stops. You must call this subroutine explicitly in your
24336 program's startup code.
24337
24338 @findex handle_exception
24339 @item handle_exception
24340 @cindex remote serial stub, main routine
24341 This is the central workhorse, but your program never calls it
24342 explicitly---the setup code arranges for @code{handle_exception} to
24343 run when a trap is triggered.
24344
24345 @code{handle_exception} takes control when your program stops during
24346 execution (for example, on a breakpoint), and mediates communications
24347 with @value{GDBN} on the host machine. This is where the communications
24348 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
24349 representative on the target machine. It begins by sending summary
24350 information on the state of your program, then continues to execute,
24351 retrieving and transmitting any information @value{GDBN} needs, until you
24352 execute a @value{GDBN} command that makes your program resume; at that point,
24353 @code{handle_exception} returns control to your own code on the target
24354 machine.
24355
24356 @item breakpoint
24357 @cindex @code{breakpoint} subroutine, remote
24358 Use this auxiliary subroutine to make your program contain a
24359 breakpoint. Depending on the particular situation, this may be the only
24360 way for @value{GDBN} to get control. For instance, if your target
24361 machine has some sort of interrupt button, you won't need to call this;
24362 pressing the interrupt button transfers control to
24363 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
24364 simply receiving characters on the serial port may also trigger a trap;
24365 again, in that situation, you don't need to call @code{breakpoint} from
24366 your own program---simply running @samp{target remote} from the host
24367 @value{GDBN} session gets control.
24368
24369 Call @code{breakpoint} if none of these is true, or if you simply want
24370 to make certain your program stops at a predetermined point for the
24371 start of your debugging session.
24372 @end table
24373
24374 @node Bootstrapping
24375 @subsection What You Must Do for the Stub
24376
24377 @cindex remote stub, support routines
24378 The debugging stubs that come with @value{GDBN} are set up for a particular
24379 chip architecture, but they have no information about the rest of your
24380 debugging target machine.
24381
24382 First of all you need to tell the stub how to communicate with the
24383 serial port.
24384
24385 @table @code
24386 @findex getDebugChar
24387 @item int getDebugChar()
24388 Write this subroutine to read a single character from the serial port.
24389 It may be identical to @code{getchar} for your target system; a
24390 different name is used to allow you to distinguish the two if you wish.
24391
24392 @findex putDebugChar
24393 @item void putDebugChar(int)
24394 Write this subroutine to write a single character to the serial port.
24395 It may be identical to @code{putchar} for your target system; a
24396 different name is used to allow you to distinguish the two if you wish.
24397 @end table
24398
24399 @cindex control C, and remote debugging
24400 @cindex interrupting remote targets
24401 If you want @value{GDBN} to be able to stop your program while it is
24402 running, you need to use an interrupt-driven serial driver, and arrange
24403 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
24404 character). That is the character which @value{GDBN} uses to tell the
24405 remote system to stop.
24406
24407 Getting the debugging target to return the proper status to @value{GDBN}
24408 probably requires changes to the standard stub; one quick and dirty way
24409 is to just execute a breakpoint instruction (the ``dirty'' part is that
24410 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
24411
24412 Other routines you need to supply are:
24413
24414 @table @code
24415 @findex exceptionHandler
24416 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
24417 Write this function to install @var{exception_address} in the exception
24418 handling tables. You need to do this because the stub does not have any
24419 way of knowing what the exception handling tables on your target system
24420 are like (for example, the processor's table might be in @sc{rom},
24421 containing entries which point to a table in @sc{ram}).
24422 The @var{exception_number} specifies the exception which should be changed;
24423 its meaning is architecture-dependent (for example, different numbers
24424 might represent divide by zero, misaligned access, etc). When this
24425 exception occurs, control should be transferred directly to
24426 @var{exception_address}, and the processor state (stack, registers,
24427 and so on) should be just as it is when a processor exception occurs. So if
24428 you want to use a jump instruction to reach @var{exception_address}, it
24429 should be a simple jump, not a jump to subroutine.
24430
24431 For the 386, @var{exception_address} should be installed as an interrupt
24432 gate so that interrupts are masked while the handler runs. The gate
24433 should be at privilege level 0 (the most privileged level). The
24434 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
24435 help from @code{exceptionHandler}.
24436
24437 @findex flush_i_cache
24438 @item void flush_i_cache()
24439 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
24440 instruction cache, if any, on your target machine. If there is no
24441 instruction cache, this subroutine may be a no-op.
24442
24443 On target machines that have instruction caches, @value{GDBN} requires this
24444 function to make certain that the state of your program is stable.
24445 @end table
24446
24447 @noindent
24448 You must also make sure this library routine is available:
24449
24450 @table @code
24451 @findex memset
24452 @item void *memset(void *, int, int)
24453 This is the standard library function @code{memset} that sets an area of
24454 memory to a known value. If you have one of the free versions of
24455 @code{libc.a}, @code{memset} can be found there; otherwise, you must
24456 either obtain it from your hardware manufacturer, or write your own.
24457 @end table
24458
24459 If you do not use the GNU C compiler, you may need other standard
24460 library subroutines as well; this varies from one stub to another,
24461 but in general the stubs are likely to use any of the common library
24462 subroutines which @code{@value{NGCC}} generates as inline code.
24463
24464
24465 @node Debug Session
24466 @subsection Putting it All Together
24467
24468 @cindex remote serial debugging summary
24469 In summary, when your program is ready to debug, you must follow these
24470 steps.
24471
24472 @enumerate
24473 @item
24474 Make sure you have defined the supporting low-level routines
24475 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
24476 @display
24477 @code{getDebugChar}, @code{putDebugChar},
24478 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
24479 @end display
24480
24481 @item
24482 Insert these lines in your program's startup code, before the main
24483 procedure is called:
24484
24485 @smallexample
24486 set_debug_traps();
24487 breakpoint();
24488 @end smallexample
24489
24490 On some machines, when a breakpoint trap is raised, the hardware
24491 automatically makes the PC point to the instruction after the
24492 breakpoint. If your machine doesn't do that, you may need to adjust
24493 @code{handle_exception} to arrange for it to return to the instruction
24494 after the breakpoint on this first invocation, so that your program
24495 doesn't keep hitting the initial breakpoint instead of making
24496 progress.
24497
24498 @item
24499 For the 680x0 stub only, you need to provide a variable called
24500 @code{exceptionHook}. Normally you just use:
24501
24502 @smallexample
24503 void (*exceptionHook)() = 0;
24504 @end smallexample
24505
24506 @noindent
24507 but if before calling @code{set_debug_traps}, you set it to point to a
24508 function in your program, that function is called when
24509 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
24510 error). The function indicated by @code{exceptionHook} is called with
24511 one parameter: an @code{int} which is the exception number.
24512
24513 @item
24514 Compile and link together: your program, the @value{GDBN} debugging stub for
24515 your target architecture, and the supporting subroutines.
24516
24517 @item
24518 Make sure you have a serial connection between your target machine and
24519 the @value{GDBN} host, and identify the serial port on the host.
24520
24521 @item
24522 @c The "remote" target now provides a `load' command, so we should
24523 @c document that. FIXME.
24524 Download your program to your target machine (or get it there by
24525 whatever means the manufacturer provides), and start it.
24526
24527 @item
24528 Start @value{GDBN} on the host, and connect to the target
24529 (@pxref{Connecting,,Connecting to a Remote Target}).
24530
24531 @end enumerate
24532
24533 @node Configurations
24534 @chapter Configuration-Specific Information
24535
24536 While nearly all @value{GDBN} commands are available for all native and
24537 cross versions of the debugger, there are some exceptions. This chapter
24538 describes things that are only available in certain configurations.
24539
24540 There are three major categories of configurations: native
24541 configurations, where the host and target are the same, embedded
24542 operating system configurations, which are usually the same for several
24543 different processor architectures, and bare embedded processors, which
24544 are quite different from each other.
24545
24546 @menu
24547 * Native::
24548 * Embedded OS::
24549 * Embedded Processors::
24550 * Architectures::
24551 @end menu
24552
24553 @node Native
24554 @section Native
24555
24556 This section describes details specific to particular native
24557 configurations.
24558
24559 @menu
24560 * BSD libkvm Interface:: Debugging BSD kernel memory images
24561 * Process Information:: Process information
24562 * DJGPP Native:: Features specific to the DJGPP port
24563 * Cygwin Native:: Features specific to the Cygwin port
24564 * Hurd Native:: Features specific to @sc{gnu} Hurd
24565 * Darwin:: Features specific to Darwin
24566 * FreeBSD:: Features specific to FreeBSD
24567 @end menu
24568
24569 @node BSD libkvm Interface
24570 @subsection BSD libkvm Interface
24571
24572 @cindex libkvm
24573 @cindex kernel memory image
24574 @cindex kernel crash dump
24575
24576 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
24577 interface that provides a uniform interface for accessing kernel virtual
24578 memory images, including live systems and crash dumps. @value{GDBN}
24579 uses this interface to allow you to debug live kernels and kernel crash
24580 dumps on many native BSD configurations. This is implemented as a
24581 special @code{kvm} debugging target. For debugging a live system, load
24582 the currently running kernel into @value{GDBN} and connect to the
24583 @code{kvm} target:
24584
24585 @smallexample
24586 (@value{GDBP}) @b{target kvm}
24587 @end smallexample
24588
24589 For debugging crash dumps, provide the file name of the crash dump as an
24590 argument:
24591
24592 @smallexample
24593 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
24594 @end smallexample
24595
24596 Once connected to the @code{kvm} target, the following commands are
24597 available:
24598
24599 @table @code
24600 @kindex kvm
24601 @item kvm pcb
24602 Set current context from the @dfn{Process Control Block} (PCB) address.
24603
24604 @item kvm proc
24605 Set current context from proc address. This command isn't available on
24606 modern FreeBSD systems.
24607 @end table
24608
24609 @node Process Information
24610 @subsection Process Information
24611 @cindex /proc
24612 @cindex examine process image
24613 @cindex process info via @file{/proc}
24614
24615 Some operating systems provide interfaces to fetch additional
24616 information about running processes beyond memory and per-thread
24617 register state. If @value{GDBN} is configured for an operating system
24618 with a supported interface, the command @code{info proc} is available
24619 to report information about the process running your program, or about
24620 any process running on your system.
24621
24622 One supported interface is a facility called @samp{/proc} that can be
24623 used to examine the image of a running process using file-system
24624 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
24625 systems.
24626
24627 On FreeBSD and NetBSD systems, system control nodes are used to query
24628 process information.
24629
24630 In addition, some systems may provide additional process information
24631 in core files. Note that a core file may include a subset of the
24632 information available from a live process. Process information is
24633 currently available from cores created on @sc{gnu}/Linux and FreeBSD
24634 systems.
24635
24636 @table @code
24637 @kindex info proc
24638 @cindex process ID
24639 @item info proc
24640 @itemx info proc @var{process-id}
24641 Summarize available information about a process. If a
24642 process ID is specified by @var{process-id}, display information about
24643 that process; otherwise display information about the program being
24644 debugged. The summary includes the debugged process ID, the command
24645 line used to invoke it, its current working directory, and its
24646 executable file's absolute file name.
24647
24648 On some systems, @var{process-id} can be of the form
24649 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
24650 within a process. If the optional @var{pid} part is missing, it means
24651 a thread from the process being debugged (the leading @samp{/} still
24652 needs to be present, or else @value{GDBN} will interpret the number as
24653 a process ID rather than a thread ID).
24654
24655 @item info proc cmdline
24656 @cindex info proc cmdline
24657 Show the original command line of the process. This command is
24658 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24659
24660 @item info proc cwd
24661 @cindex info proc cwd
24662 Show the current working directory of the process. This command is
24663 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24664
24665 @item info proc exe
24666 @cindex info proc exe
24667 Show the name of executable of the process. This command is supported
24668 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24669
24670 @item info proc files
24671 @cindex info proc files
24672 Show the file descriptors open by the process. For each open file
24673 descriptor, @value{GDBN} shows its number, type (file, directory,
24674 character device, socket), file pointer offset, and the name of the
24675 resource open on the descriptor. The resource name can be a file name
24676 (for files, directories, and devices) or a protocol followed by socket
24677 address (for network connections). This command is supported on
24678 FreeBSD.
24679
24680 This example shows the open file descriptors for a process using a
24681 tty for standard input and output as well as two network sockets:
24682
24683 @smallexample
24684 (@value{GDBP}) info proc files 22136
24685 process 22136
24686 Open files:
24687
24688 FD Type Offset Flags Name
24689 text file - r-------- /usr/bin/ssh
24690 ctty chr - rw------- /dev/pts/20
24691 cwd dir - r-------- /usr/home/john
24692 root dir - r-------- /
24693 0 chr 0x32933a4 rw------- /dev/pts/20
24694 1 chr 0x32933a4 rw------- /dev/pts/20
24695 2 chr 0x32933a4 rw------- /dev/pts/20
24696 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
24697 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
24698 @end smallexample
24699
24700 @item info proc mappings
24701 @cindex memory address space mappings
24702 Report the memory address space ranges accessible in a process. On
24703 Solaris, FreeBSD and NetBSD systems, each memory range includes information
24704 on whether the process has read, write, or execute access rights to each
24705 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
24706 includes the object file which is mapped to that range.
24707
24708 @item info proc stat
24709 @itemx info proc status
24710 @cindex process detailed status information
24711 Show additional process-related information, including the user ID and
24712 group ID; virtual memory usage; the signals that are pending, blocked,
24713 and ignored; its TTY; its consumption of system and user time; its
24714 stack size; its @samp{nice} value; etc. These commands are supported
24715 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24716
24717 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
24718 information (type @kbd{man 5 proc} from your shell prompt).
24719
24720 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
24721 @code{info proc status}.
24722
24723 @item info proc all
24724 Show all the information about the process described under all of the
24725 above @code{info proc} subcommands.
24726
24727 @ignore
24728 @comment These sub-options of 'info proc' were not included when
24729 @comment procfs.c was re-written. Keep their descriptions around
24730 @comment against the day when someone finds the time to put them back in.
24731 @kindex info proc times
24732 @item info proc times
24733 Starting time, user CPU time, and system CPU time for your program and
24734 its children.
24735
24736 @kindex info proc id
24737 @item info proc id
24738 Report on the process IDs related to your program: its own process ID,
24739 the ID of its parent, the process group ID, and the session ID.
24740 @end ignore
24741
24742 @item set procfs-trace
24743 @kindex set procfs-trace
24744 @cindex @code{procfs} API calls
24745 This command enables and disables tracing of @code{procfs} API calls.
24746
24747 @item show procfs-trace
24748 @kindex show procfs-trace
24749 Show the current state of @code{procfs} API call tracing.
24750
24751 @item set procfs-file @var{file}
24752 @kindex set procfs-file
24753 Tell @value{GDBN} to write @code{procfs} API trace to the named
24754 @var{file}. @value{GDBN} appends the trace info to the previous
24755 contents of the file. The default is to display the trace on the
24756 standard output.
24757
24758 @item show procfs-file
24759 @kindex show procfs-file
24760 Show the file to which @code{procfs} API trace is written.
24761
24762 @item proc-trace-entry
24763 @itemx proc-trace-exit
24764 @itemx proc-untrace-entry
24765 @itemx proc-untrace-exit
24766 @kindex proc-trace-entry
24767 @kindex proc-trace-exit
24768 @kindex proc-untrace-entry
24769 @kindex proc-untrace-exit
24770 These commands enable and disable tracing of entries into and exits
24771 from the @code{syscall} interface.
24772
24773 @item info pidlist
24774 @kindex info pidlist
24775 @cindex process list, QNX Neutrino
24776 For QNX Neutrino only, this command displays the list of all the
24777 processes and all the threads within each process.
24778
24779 @item info meminfo
24780 @kindex info meminfo
24781 @cindex mapinfo list, QNX Neutrino
24782 For QNX Neutrino only, this command displays the list of all mapinfos.
24783 @end table
24784
24785 @node DJGPP Native
24786 @subsection Features for Debugging @sc{djgpp} Programs
24787 @cindex @sc{djgpp} debugging
24788 @cindex native @sc{djgpp} debugging
24789 @cindex MS-DOS-specific commands
24790
24791 @cindex DPMI
24792 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
24793 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
24794 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
24795 top of real-mode DOS systems and their emulations.
24796
24797 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
24798 defines a few commands specific to the @sc{djgpp} port. This
24799 subsection describes those commands.
24800
24801 @table @code
24802 @kindex info dos
24803 @item info dos
24804 This is a prefix of @sc{djgpp}-specific commands which print
24805 information about the target system and important OS structures.
24806
24807 @kindex sysinfo
24808 @cindex MS-DOS system info
24809 @cindex free memory information (MS-DOS)
24810 @item info dos sysinfo
24811 This command displays assorted information about the underlying
24812 platform: the CPU type and features, the OS version and flavor, the
24813 DPMI version, and the available conventional and DPMI memory.
24814
24815 @cindex GDT
24816 @cindex LDT
24817 @cindex IDT
24818 @cindex segment descriptor tables
24819 @cindex descriptor tables display
24820 @item info dos gdt
24821 @itemx info dos ldt
24822 @itemx info dos idt
24823 These 3 commands display entries from, respectively, Global, Local,
24824 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
24825 tables are data structures which store a descriptor for each segment
24826 that is currently in use. The segment's selector is an index into a
24827 descriptor table; the table entry for that index holds the
24828 descriptor's base address and limit, and its attributes and access
24829 rights.
24830
24831 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
24832 segment (used for both data and the stack), and a DOS segment (which
24833 allows access to DOS/BIOS data structures and absolute addresses in
24834 conventional memory). However, the DPMI host will usually define
24835 additional segments in order to support the DPMI environment.
24836
24837 @cindex garbled pointers
24838 These commands allow to display entries from the descriptor tables.
24839 Without an argument, all entries from the specified table are
24840 displayed. An argument, which should be an integer expression, means
24841 display a single entry whose index is given by the argument. For
24842 example, here's a convenient way to display information about the
24843 debugged program's data segment:
24844
24845 @smallexample
24846 @exdent @code{(@value{GDBP}) info dos ldt $ds}
24847 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
24848 @end smallexample
24849
24850 @noindent
24851 This comes in handy when you want to see whether a pointer is outside
24852 the data segment's limit (i.e.@: @dfn{garbled}).
24853
24854 @cindex page tables display (MS-DOS)
24855 @item info dos pde
24856 @itemx info dos pte
24857 These two commands display entries from, respectively, the Page
24858 Directory and the Page Tables. Page Directories and Page Tables are
24859 data structures which control how virtual memory addresses are mapped
24860 into physical addresses. A Page Table includes an entry for every
24861 page of memory that is mapped into the program's address space; there
24862 may be several Page Tables, each one holding up to 4096 entries. A
24863 Page Directory has up to 4096 entries, one each for every Page Table
24864 that is currently in use.
24865
24866 Without an argument, @kbd{info dos pde} displays the entire Page
24867 Directory, and @kbd{info dos pte} displays all the entries in all of
24868 the Page Tables. An argument, an integer expression, given to the
24869 @kbd{info dos pde} command means display only that entry from the Page
24870 Directory table. An argument given to the @kbd{info dos pte} command
24871 means display entries from a single Page Table, the one pointed to by
24872 the specified entry in the Page Directory.
24873
24874 @cindex direct memory access (DMA) on MS-DOS
24875 These commands are useful when your program uses @dfn{DMA} (Direct
24876 Memory Access), which needs physical addresses to program the DMA
24877 controller.
24878
24879 These commands are supported only with some DPMI servers.
24880
24881 @cindex physical address from linear address
24882 @item info dos address-pte @var{addr}
24883 This command displays the Page Table entry for a specified linear
24884 address. The argument @var{addr} is a linear address which should
24885 already have the appropriate segment's base address added to it,
24886 because this command accepts addresses which may belong to @emph{any}
24887 segment. For example, here's how to display the Page Table entry for
24888 the page where a variable @code{i} is stored:
24889
24890 @smallexample
24891 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
24892 @exdent @code{Page Table entry for address 0x11a00d30:}
24893 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
24894 @end smallexample
24895
24896 @noindent
24897 This says that @code{i} is stored at offset @code{0xd30} from the page
24898 whose physical base address is @code{0x02698000}, and shows all the
24899 attributes of that page.
24900
24901 Note that you must cast the addresses of variables to a @code{char *},
24902 since otherwise the value of @code{__djgpp_base_address}, the base
24903 address of all variables and functions in a @sc{djgpp} program, will
24904 be added using the rules of C pointer arithmetics: if @code{i} is
24905 declared an @code{int}, @value{GDBN} will add 4 times the value of
24906 @code{__djgpp_base_address} to the address of @code{i}.
24907
24908 Here's another example, it displays the Page Table entry for the
24909 transfer buffer:
24910
24911 @smallexample
24912 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
24913 @exdent @code{Page Table entry for address 0x29110:}
24914 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
24915 @end smallexample
24916
24917 @noindent
24918 (The @code{+ 3} offset is because the transfer buffer's address is the
24919 3rd member of the @code{_go32_info_block} structure.) The output
24920 clearly shows that this DPMI server maps the addresses in conventional
24921 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
24922 linear (@code{0x29110}) addresses are identical.
24923
24924 This command is supported only with some DPMI servers.
24925 @end table
24926
24927 @cindex DOS serial data link, remote debugging
24928 In addition to native debugging, the DJGPP port supports remote
24929 debugging via a serial data link. The following commands are specific
24930 to remote serial debugging in the DJGPP port of @value{GDBN}.
24931
24932 @table @code
24933 @kindex set com1base
24934 @kindex set com1irq
24935 @kindex set com2base
24936 @kindex set com2irq
24937 @kindex set com3base
24938 @kindex set com3irq
24939 @kindex set com4base
24940 @kindex set com4irq
24941 @item set com1base @var{addr}
24942 This command sets the base I/O port address of the @file{COM1} serial
24943 port.
24944
24945 @item set com1irq @var{irq}
24946 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24947 for the @file{COM1} serial port.
24948
24949 There are similar commands @samp{set com2base}, @samp{set com3irq},
24950 etc.@: for setting the port address and the @code{IRQ} lines for the
24951 other 3 COM ports.
24952
24953 @kindex show com1base
24954 @kindex show com1irq
24955 @kindex show com2base
24956 @kindex show com2irq
24957 @kindex show com3base
24958 @kindex show com3irq
24959 @kindex show com4base
24960 @kindex show com4irq
24961 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24962 display the current settings of the base address and the @code{IRQ}
24963 lines used by the COM ports.
24964
24965 @item info serial
24966 @kindex info serial
24967 @cindex DOS serial port status
24968 This command prints the status of the 4 DOS serial ports. For each
24969 port, it prints whether it's active or not, its I/O base address and
24970 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24971 counts of various errors encountered so far.
24972 @end table
24973
24974
24975 @node Cygwin Native
24976 @subsection Features for Debugging MS Windows PE Executables
24977 @cindex MS Windows debugging
24978 @cindex native Cygwin debugging
24979 @cindex Cygwin-specific commands
24980
24981 @value{GDBN} supports native debugging of MS Windows programs, including
24982 DLLs with and without symbolic debugging information.
24983
24984 @cindex Ctrl-BREAK, MS-Windows
24985 @cindex interrupt debuggee on MS-Windows
24986 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24987 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24988 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24989 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24990 sequence, which can be used to interrupt the debuggee even if it
24991 ignores @kbd{C-c}.
24992
24993 There are various additional Cygwin-specific commands, described in
24994 this section. Working with DLLs that have no debugging symbols is
24995 described in @ref{Non-debug DLL Symbols}.
24996
24997 @table @code
24998 @kindex info w32
24999 @item info w32
25000 This is a prefix of MS Windows-specific commands which print
25001 information about the target system and important OS structures.
25002
25003 @item info w32 selector
25004 This command displays information returned by
25005 the Win32 API @code{GetThreadSelectorEntry} function.
25006 It takes an optional argument that is evaluated to
25007 a long value to give the information about this given selector.
25008 Without argument, this command displays information
25009 about the six segment registers.
25010
25011 @item info w32 thread-information-block
25012 This command displays thread specific information stored in the
25013 Thread Information Block (readable on the X86 CPU family using @code{$fs}
25014 selector for 32-bit programs and @code{$gs} for 64-bit programs).
25015
25016 @kindex signal-event
25017 @item signal-event @var{id}
25018 This command signals an event with user-provided @var{id}. Used to resume
25019 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
25020
25021 To use it, create or edit the following keys in
25022 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
25023 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
25024 (for x86_64 versions):
25025
25026 @itemize @minus
25027 @item
25028 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
25029 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
25030 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
25031
25032 The first @code{%ld} will be replaced by the process ID of the
25033 crashing process, the second @code{%ld} will be replaced by the ID of
25034 the event that blocks the crashing process, waiting for @value{GDBN}
25035 to attach.
25036
25037 @item
25038 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
25039 make the system run debugger specified by the Debugger key
25040 automatically, @code{0} will cause a dialog box with ``OK'' and
25041 ``Cancel'' buttons to appear, which allows the user to either
25042 terminate the crashing process (OK) or debug it (Cancel).
25043 @end itemize
25044
25045 @kindex set cygwin-exceptions
25046 @cindex debugging the Cygwin DLL
25047 @cindex Cygwin DLL, debugging
25048 @item set cygwin-exceptions @var{mode}
25049 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
25050 happen inside the Cygwin DLL. If @var{mode} is @code{off},
25051 @value{GDBN} will delay recognition of exceptions, and may ignore some
25052 exceptions which seem to be caused by internal Cygwin DLL
25053 ``bookkeeping''. This option is meant primarily for debugging the
25054 Cygwin DLL itself; the default value is @code{off} to avoid annoying
25055 @value{GDBN} users with false @code{SIGSEGV} signals.
25056
25057 @kindex show cygwin-exceptions
25058 @item show cygwin-exceptions
25059 Displays whether @value{GDBN} will break on exceptions that happen
25060 inside the Cygwin DLL itself.
25061
25062 @kindex set new-console
25063 @item set new-console @var{mode}
25064 If @var{mode} is @code{on} the debuggee will
25065 be started in a new console on next start.
25066 If @var{mode} is @code{off}, the debuggee will
25067 be started in the same console as the debugger.
25068
25069 @kindex show new-console
25070 @item show new-console
25071 Displays whether a new console is used
25072 when the debuggee is started.
25073
25074 @kindex set new-group
25075 @item set new-group @var{mode}
25076 This boolean value controls whether the debuggee should
25077 start a new group or stay in the same group as the debugger.
25078 This affects the way the Windows OS handles
25079 @samp{Ctrl-C}.
25080
25081 @kindex show new-group
25082 @item show new-group
25083 Displays current value of new-group boolean.
25084
25085 @kindex set debugevents
25086 @item set debugevents
25087 This boolean value adds debug output concerning kernel events related
25088 to the debuggee seen by the debugger. This includes events that
25089 signal thread and process creation and exit, DLL loading and
25090 unloading, console interrupts, and debugging messages produced by the
25091 Windows @code{OutputDebugString} API call.
25092
25093 @kindex set debugexec
25094 @item set debugexec
25095 This boolean value adds debug output concerning execute events
25096 (such as resume thread) seen by the debugger.
25097
25098 @kindex set debugexceptions
25099 @item set debugexceptions
25100 This boolean value adds debug output concerning exceptions in the
25101 debuggee seen by the debugger.
25102
25103 @kindex set debugmemory
25104 @item set debugmemory
25105 This boolean value adds debug output concerning debuggee memory reads
25106 and writes by the debugger.
25107
25108 @kindex set shell
25109 @item set shell
25110 This boolean values specifies whether the debuggee is called
25111 via a shell or directly (default value is on).
25112
25113 @kindex show shell
25114 @item show shell
25115 Displays if the debuggee will be started with a shell.
25116
25117 @end table
25118
25119 @menu
25120 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
25121 @end menu
25122
25123 @node Non-debug DLL Symbols
25124 @subsubsection Support for DLLs without Debugging Symbols
25125 @cindex DLLs with no debugging symbols
25126 @cindex Minimal symbols and DLLs
25127
25128 Very often on windows, some of the DLLs that your program relies on do
25129 not include symbolic debugging information (for example,
25130 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
25131 symbols in a DLL, it relies on the minimal amount of symbolic
25132 information contained in the DLL's export table. This section
25133 describes working with such symbols, known internally to @value{GDBN} as
25134 ``minimal symbols''.
25135
25136 Note that before the debugged program has started execution, no DLLs
25137 will have been loaded. The easiest way around this problem is simply to
25138 start the program --- either by setting a breakpoint or letting the
25139 program run once to completion.
25140
25141 @subsubsection DLL Name Prefixes
25142
25143 In keeping with the naming conventions used by the Microsoft debugging
25144 tools, DLL export symbols are made available with a prefix based on the
25145 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
25146 also entered into the symbol table, so @code{CreateFileA} is often
25147 sufficient. In some cases there will be name clashes within a program
25148 (particularly if the executable itself includes full debugging symbols)
25149 necessitating the use of the fully qualified name when referring to the
25150 contents of the DLL. Use single-quotes around the name to avoid the
25151 exclamation mark (``!'') being interpreted as a language operator.
25152
25153 Note that the internal name of the DLL may be all upper-case, even
25154 though the file name of the DLL is lower-case, or vice-versa. Since
25155 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
25156 some confusion. If in doubt, try the @code{info functions} and
25157 @code{info variables} commands or even @code{maint print msymbols}
25158 (@pxref{Symbols}). Here's an example:
25159
25160 @smallexample
25161 (@value{GDBP}) info function CreateFileA
25162 All functions matching regular expression "CreateFileA":
25163
25164 Non-debugging symbols:
25165 0x77e885f4 CreateFileA
25166 0x77e885f4 KERNEL32!CreateFileA
25167 @end smallexample
25168
25169 @smallexample
25170 (@value{GDBP}) info function !
25171 All functions matching regular expression "!":
25172
25173 Non-debugging symbols:
25174 0x6100114c cygwin1!__assert
25175 0x61004034 cygwin1!_dll_crt0@@0
25176 0x61004240 cygwin1!dll_crt0(per_process *)
25177 [etc...]
25178 @end smallexample
25179
25180 @subsubsection Working with Minimal Symbols
25181
25182 Symbols extracted from a DLL's export table do not contain very much
25183 type information. All that @value{GDBN} can do is guess whether a symbol
25184 refers to a function or variable depending on the linker section that
25185 contains the symbol. Also note that the actual contents of the memory
25186 contained in a DLL are not available unless the program is running. This
25187 means that you cannot examine the contents of a variable or disassemble
25188 a function within a DLL without a running program.
25189
25190 Variables are generally treated as pointers and dereferenced
25191 automatically. For this reason, it is often necessary to prefix a
25192 variable name with the address-of operator (``&'') and provide explicit
25193 type information in the command. Here's an example of the type of
25194 problem:
25195
25196 @smallexample
25197 (@value{GDBP}) print 'cygwin1!__argv'
25198 'cygwin1!__argv' has unknown type; cast it to its declared type
25199 @end smallexample
25200
25201 @smallexample
25202 (@value{GDBP}) x 'cygwin1!__argv'
25203 'cygwin1!__argv' has unknown type; cast it to its declared type
25204 @end smallexample
25205
25206 And two possible solutions:
25207
25208 @smallexample
25209 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
25210 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
25211 @end smallexample
25212
25213 @smallexample
25214 (@value{GDBP}) x/2x &'cygwin1!__argv'
25215 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
25216 (@value{GDBP}) x/x 0x10021608
25217 0x10021608: 0x0022fd98
25218 (@value{GDBP}) x/s 0x0022fd98
25219 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
25220 @end smallexample
25221
25222 Setting a break point within a DLL is possible even before the program
25223 starts execution. However, under these circumstances, @value{GDBN} can't
25224 examine the initial instructions of the function in order to skip the
25225 function's frame set-up code. You can work around this by using ``*&''
25226 to set the breakpoint at a raw memory address:
25227
25228 @smallexample
25229 (@value{GDBP}) break *&'python22!PyOS_Readline'
25230 Breakpoint 1 at 0x1e04eff0
25231 @end smallexample
25232
25233 The author of these extensions is not entirely convinced that setting a
25234 break point within a shared DLL like @file{kernel32.dll} is completely
25235 safe.
25236
25237 @node Hurd Native
25238 @subsection Commands Specific to @sc{gnu} Hurd Systems
25239 @cindex @sc{gnu} Hurd debugging
25240
25241 This subsection describes @value{GDBN} commands specific to the
25242 @sc{gnu} Hurd native debugging.
25243
25244 @table @code
25245 @item set signals
25246 @itemx set sigs
25247 @kindex set signals@r{, Hurd command}
25248 @kindex set sigs@r{, Hurd command}
25249 This command toggles the state of inferior signal interception by
25250 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
25251 affected by this command. @code{sigs} is a shorthand alias for
25252 @code{signals}.
25253
25254 @item show signals
25255 @itemx show sigs
25256 @kindex show signals@r{, Hurd command}
25257 @kindex show sigs@r{, Hurd command}
25258 Show the current state of intercepting inferior's signals.
25259
25260 @item set signal-thread
25261 @itemx set sigthread
25262 @kindex set signal-thread
25263 @kindex set sigthread
25264 This command tells @value{GDBN} which thread is the @code{libc} signal
25265 thread. That thread is run when a signal is delivered to a running
25266 process. @code{set sigthread} is the shorthand alias of @code{set
25267 signal-thread}.
25268
25269 @item show signal-thread
25270 @itemx show sigthread
25271 @kindex show signal-thread
25272 @kindex show sigthread
25273 These two commands show which thread will run when the inferior is
25274 delivered a signal.
25275
25276 @item set stopped
25277 @kindex set stopped@r{, Hurd command}
25278 This commands tells @value{GDBN} that the inferior process is stopped,
25279 as with the @code{SIGSTOP} signal. The stopped process can be
25280 continued by delivering a signal to it.
25281
25282 @item show stopped
25283 @kindex show stopped@r{, Hurd command}
25284 This command shows whether @value{GDBN} thinks the debuggee is
25285 stopped.
25286
25287 @item set exceptions
25288 @kindex set exceptions@r{, Hurd command}
25289 Use this command to turn off trapping of exceptions in the inferior.
25290 When exception trapping is off, neither breakpoints nor
25291 single-stepping will work. To restore the default, set exception
25292 trapping on.
25293
25294 @item show exceptions
25295 @kindex show exceptions@r{, Hurd command}
25296 Show the current state of trapping exceptions in the inferior.
25297
25298 @item set task pause
25299 @kindex set task@r{, Hurd commands}
25300 @cindex task attributes (@sc{gnu} Hurd)
25301 @cindex pause current task (@sc{gnu} Hurd)
25302 This command toggles task suspension when @value{GDBN} has control.
25303 Setting it to on takes effect immediately, and the task is suspended
25304 whenever @value{GDBN} gets control. Setting it to off will take
25305 effect the next time the inferior is continued. If this option is set
25306 to off, you can use @code{set thread default pause on} or @code{set
25307 thread pause on} (see below) to pause individual threads.
25308
25309 @item show task pause
25310 @kindex show task@r{, Hurd commands}
25311 Show the current state of task suspension.
25312
25313 @item set task detach-suspend-count
25314 @cindex task suspend count
25315 @cindex detach from task, @sc{gnu} Hurd
25316 This command sets the suspend count the task will be left with when
25317 @value{GDBN} detaches from it.
25318
25319 @item show task detach-suspend-count
25320 Show the suspend count the task will be left with when detaching.
25321
25322 @item set task exception-port
25323 @itemx set task excp
25324 @cindex task exception port, @sc{gnu} Hurd
25325 This command sets the task exception port to which @value{GDBN} will
25326 forward exceptions. The argument should be the value of the @dfn{send
25327 rights} of the task. @code{set task excp} is a shorthand alias.
25328
25329 @item set noninvasive
25330 @cindex noninvasive task options
25331 This command switches @value{GDBN} to a mode that is the least
25332 invasive as far as interfering with the inferior is concerned. This
25333 is the same as using @code{set task pause}, @code{set exceptions}, and
25334 @code{set signals} to values opposite to the defaults.
25335
25336 @item info send-rights
25337 @itemx info receive-rights
25338 @itemx info port-rights
25339 @itemx info port-sets
25340 @itemx info dead-names
25341 @itemx info ports
25342 @itemx info psets
25343 @cindex send rights, @sc{gnu} Hurd
25344 @cindex receive rights, @sc{gnu} Hurd
25345 @cindex port rights, @sc{gnu} Hurd
25346 @cindex port sets, @sc{gnu} Hurd
25347 @cindex dead names, @sc{gnu} Hurd
25348 These commands display information about, respectively, send rights,
25349 receive rights, port rights, port sets, and dead names of a task.
25350 There are also shorthand aliases: @code{info ports} for @code{info
25351 port-rights} and @code{info psets} for @code{info port-sets}.
25352
25353 @item set thread pause
25354 @kindex set thread@r{, Hurd command}
25355 @cindex thread properties, @sc{gnu} Hurd
25356 @cindex pause current thread (@sc{gnu} Hurd)
25357 This command toggles current thread suspension when @value{GDBN} has
25358 control. Setting it to on takes effect immediately, and the current
25359 thread is suspended whenever @value{GDBN} gets control. Setting it to
25360 off will take effect the next time the inferior is continued.
25361 Normally, this command has no effect, since when @value{GDBN} has
25362 control, the whole task is suspended. However, if you used @code{set
25363 task pause off} (see above), this command comes in handy to suspend
25364 only the current thread.
25365
25366 @item show thread pause
25367 @kindex show thread@r{, Hurd command}
25368 This command shows the state of current thread suspension.
25369
25370 @item set thread run
25371 This command sets whether the current thread is allowed to run.
25372
25373 @item show thread run
25374 Show whether the current thread is allowed to run.
25375
25376 @item set thread detach-suspend-count
25377 @cindex thread suspend count, @sc{gnu} Hurd
25378 @cindex detach from thread, @sc{gnu} Hurd
25379 This command sets the suspend count @value{GDBN} will leave on a
25380 thread when detaching. This number is relative to the suspend count
25381 found by @value{GDBN} when it notices the thread; use @code{set thread
25382 takeover-suspend-count} to force it to an absolute value.
25383
25384 @item show thread detach-suspend-count
25385 Show the suspend count @value{GDBN} will leave on the thread when
25386 detaching.
25387
25388 @item set thread exception-port
25389 @itemx set thread excp
25390 Set the thread exception port to which to forward exceptions. This
25391 overrides the port set by @code{set task exception-port} (see above).
25392 @code{set thread excp} is the shorthand alias.
25393
25394 @item set thread takeover-suspend-count
25395 Normally, @value{GDBN}'s thread suspend counts are relative to the
25396 value @value{GDBN} finds when it notices each thread. This command
25397 changes the suspend counts to be absolute instead.
25398
25399 @item set thread default
25400 @itemx show thread default
25401 @cindex thread default settings, @sc{gnu} Hurd
25402 Each of the above @code{set thread} commands has a @code{set thread
25403 default} counterpart (e.g., @code{set thread default pause}, @code{set
25404 thread default exception-port}, etc.). The @code{thread default}
25405 variety of commands sets the default thread properties for all
25406 threads; you can then change the properties of individual threads with
25407 the non-default commands.
25408 @end table
25409
25410 @node Darwin
25411 @subsection Darwin
25412 @cindex Darwin
25413
25414 @value{GDBN} provides the following commands specific to the Darwin target:
25415
25416 @table @code
25417 @item set debug darwin @var{num}
25418 @kindex set debug darwin
25419 When set to a non zero value, enables debugging messages specific to
25420 the Darwin support. Higher values produce more verbose output.
25421
25422 @item show debug darwin
25423 @kindex show debug darwin
25424 Show the current state of Darwin messages.
25425
25426 @item set debug mach-o @var{num}
25427 @kindex set debug mach-o
25428 When set to a non zero value, enables debugging messages while
25429 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
25430 file format used on Darwin for object and executable files.) Higher
25431 values produce more verbose output. This is a command to diagnose
25432 problems internal to @value{GDBN} and should not be needed in normal
25433 usage.
25434
25435 @item show debug mach-o
25436 @kindex show debug mach-o
25437 Show the current state of Mach-O file messages.
25438
25439 @item set mach-exceptions on
25440 @itemx set mach-exceptions off
25441 @kindex set mach-exceptions
25442 On Darwin, faults are first reported as a Mach exception and are then
25443 mapped to a Posix signal. Use this command to turn on trapping of
25444 Mach exceptions in the inferior. This might be sometimes useful to
25445 better understand the cause of a fault. The default is off.
25446
25447 @item show mach-exceptions
25448 @kindex show mach-exceptions
25449 Show the current state of exceptions trapping.
25450 @end table
25451
25452 @node FreeBSD
25453 @subsection FreeBSD
25454 @cindex FreeBSD
25455
25456 When the ABI of a system call is changed in the FreeBSD kernel, this
25457 is implemented by leaving a compatibility system call using the old
25458 ABI at the existing number and allocating a new system call number for
25459 the version using the new ABI. As a convenience, when a system call
25460 is caught by name (@pxref{catch syscall}), compatibility system calls
25461 are also caught.
25462
25463 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
25464 system call and catching the @code{kevent} system call by name catches
25465 both variants:
25466
25467 @smallexample
25468 (@value{GDBP}) catch syscall kevent
25469 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
25470 (@value{GDBP})
25471 @end smallexample
25472
25473
25474 @node Embedded OS
25475 @section Embedded Operating Systems
25476
25477 This section describes configurations involving the debugging of
25478 embedded operating systems that are available for several different
25479 architectures.
25480
25481 @value{GDBN} includes the ability to debug programs running on
25482 various real-time operating systems.
25483
25484 @node Embedded Processors
25485 @section Embedded Processors
25486
25487 This section goes into details specific to particular embedded
25488 configurations.
25489
25490 @cindex send command to simulator
25491 Whenever a specific embedded processor has a simulator, @value{GDBN}
25492 allows to send an arbitrary command to the simulator.
25493
25494 @table @code
25495 @item sim @var{command}
25496 @kindex sim@r{, a command}
25497 Send an arbitrary @var{command} string to the simulator. Consult the
25498 documentation for the specific simulator in use for information about
25499 acceptable commands.
25500 @end table
25501
25502
25503 @menu
25504 * ARC:: Synopsys ARC
25505 * ARM:: ARM
25506 * BPF:: eBPF
25507 * M68K:: Motorola M68K
25508 * MicroBlaze:: Xilinx MicroBlaze
25509 * MIPS Embedded:: MIPS Embedded
25510 * OpenRISC 1000:: OpenRISC 1000 (or1k)
25511 * PowerPC Embedded:: PowerPC Embedded
25512 * AVR:: Atmel AVR
25513 * CRIS:: CRIS
25514 * Super-H:: Renesas Super-H
25515 @end menu
25516
25517 @node ARC
25518 @subsection Synopsys ARC
25519 @cindex Synopsys ARC
25520 @cindex ARC specific commands
25521 @cindex ARC600
25522 @cindex ARC700
25523 @cindex ARC EM
25524 @cindex ARC HS
25525
25526 @value{GDBN} provides the following ARC-specific commands:
25527
25528 @table @code
25529 @item set debug arc
25530 @kindex set debug arc
25531 Control the level of ARC specific debug messages. Use 0 for no messages (the
25532 default), 1 for debug messages, and 2 for even more debug messages.
25533
25534 @item show debug arc
25535 @kindex show debug arc
25536 Show the level of ARC specific debugging in operation.
25537
25538 @item maint print arc arc-instruction @var{address}
25539 @kindex maint print arc arc-instruction
25540 Print internal disassembler information about instruction at a given address.
25541
25542 @end table
25543
25544 @node ARM
25545 @subsection ARM
25546
25547 @value{GDBN} provides the following ARM-specific commands:
25548
25549 @table @code
25550 @item set arm disassembler
25551 @kindex set arm
25552 This commands selects from a list of disassembly styles. The
25553 @code{"std"} style is the standard style.
25554
25555 @item show arm disassembler
25556 @kindex show arm
25557 Show the current disassembly style.
25558
25559 @item set arm apcs32
25560 @cindex ARM 32-bit mode
25561 This command toggles ARM operation mode between 32-bit and 26-bit.
25562
25563 @item show arm apcs32
25564 Display the current usage of the ARM 32-bit mode.
25565
25566 @item set arm fpu @var{fputype}
25567 This command sets the ARM floating-point unit (FPU) type. The
25568 argument @var{fputype} can be one of these:
25569
25570 @table @code
25571 @item auto
25572 Determine the FPU type by querying the OS ABI.
25573 @item softfpa
25574 Software FPU, with mixed-endian doubles on little-endian ARM
25575 processors.
25576 @item fpa
25577 GCC-compiled FPA co-processor.
25578 @item softvfp
25579 Software FPU with pure-endian doubles.
25580 @item vfp
25581 VFP co-processor.
25582 @end table
25583
25584 @item show arm fpu
25585 Show the current type of the FPU.
25586
25587 @item set arm abi
25588 This command forces @value{GDBN} to use the specified ABI.
25589
25590 @item show arm abi
25591 Show the currently used ABI.
25592
25593 @item set arm fallback-mode (arm|thumb|auto)
25594 @value{GDBN} uses the symbol table, when available, to determine
25595 whether instructions are ARM or Thumb. This command controls
25596 @value{GDBN}'s default behavior when the symbol table is not
25597 available. The default is @samp{auto}, which causes @value{GDBN} to
25598 use the current execution mode (from the @code{T} bit in the @code{CPSR}
25599 register).
25600
25601 @item show arm fallback-mode
25602 Show the current fallback instruction mode.
25603
25604 @item set arm force-mode (arm|thumb|auto)
25605 This command overrides use of the symbol table to determine whether
25606 instructions are ARM or Thumb. The default is @samp{auto}, which
25607 causes @value{GDBN} to use the symbol table and then the setting
25608 of @samp{set arm fallback-mode}.
25609
25610 @item show arm force-mode
25611 Show the current forced instruction mode.
25612
25613 @item set arm unwind-secure-frames
25614 This command enables unwinding from Non-secure to Secure mode on
25615 Cortex-M with Security extension.
25616 This can trigger security exceptions when unwinding the exception
25617 stack.
25618 It is enabled by default.
25619
25620 @item show arm unwind-secure-frames
25621 Show whether unwinding from Non-secure to Secure mode is enabled.
25622
25623 @item set debug arm
25624 Toggle whether to display ARM-specific debugging messages from the ARM
25625 target support subsystem.
25626
25627 @item show debug arm
25628 Show whether ARM-specific debugging messages are enabled.
25629 @end table
25630
25631 @table @code
25632 @item target sim @r{[}@var{simargs}@r{]} @dots{}
25633 The @value{GDBN} ARM simulator accepts the following optional arguments.
25634
25635 @table @code
25636 @item --swi-support=@var{type}
25637 Tell the simulator which SWI interfaces to support. The argument
25638 @var{type} may be a comma separated list of the following values.
25639 The default value is @code{all}.
25640
25641 @table @code
25642 @item none
25643 @item demon
25644 @item angel
25645 @item redboot
25646 @item all
25647 @end table
25648 @end table
25649 @end table
25650
25651 @node BPF
25652 @subsection BPF
25653
25654 @table @code
25655 @item target sim @r{[}@var{simargs}@r{]} @dots{}
25656 The @value{GDBN} BPF simulator accepts the following optional arguments.
25657
25658 @table @code
25659 @item --skb-data-offset=@var{offset}
25660 Tell the simulator the offset, measured in bytes, of the
25661 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
25662 This offset is used by some BPF specific-purpose load/store
25663 instructions. Defaults to 0.
25664 @end table
25665 @end table
25666
25667 @node M68K
25668 @subsection M68k
25669
25670 The Motorola m68k configuration includes ColdFire support.
25671
25672 @node MicroBlaze
25673 @subsection MicroBlaze
25674 @cindex Xilinx MicroBlaze
25675 @cindex XMD, Xilinx Microprocessor Debugger
25676
25677 The MicroBlaze is a soft-core processor supported on various Xilinx
25678 FPGAs, such as Spartan or Virtex series. Boards with these processors
25679 usually have JTAG ports which connect to a host system running the Xilinx
25680 Embedded Development Kit (EDK) or Software Development Kit (SDK).
25681 This host system is used to download the configuration bitstream to
25682 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
25683 communicates with the target board using the JTAG interface and
25684 presents a @code{gdbserver} interface to the board. By default
25685 @code{xmd} uses port @code{1234}. (While it is possible to change
25686 this default port, it requires the use of undocumented @code{xmd}
25687 commands. Contact Xilinx support if you need to do this.)
25688
25689 Use these GDB commands to connect to the MicroBlaze target processor.
25690
25691 @table @code
25692 @item target remote :1234
25693 Use this command to connect to the target if you are running @value{GDBN}
25694 on the same system as @code{xmd}.
25695
25696 @item target remote @var{xmd-host}:1234
25697 Use this command to connect to the target if it is connected to @code{xmd}
25698 running on a different system named @var{xmd-host}.
25699
25700 @item load
25701 Use this command to download a program to the MicroBlaze target.
25702
25703 @item set debug microblaze @var{n}
25704 Enable MicroBlaze-specific debugging messages if non-zero.
25705
25706 @item show debug microblaze @var{n}
25707 Show MicroBlaze-specific debugging level.
25708 @end table
25709
25710 @node MIPS Embedded
25711 @subsection @acronym{MIPS} Embedded
25712
25713 @noindent
25714 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
25715
25716 @table @code
25717 @item set mipsfpu double
25718 @itemx set mipsfpu single
25719 @itemx set mipsfpu none
25720 @itemx set mipsfpu auto
25721 @itemx show mipsfpu
25722 @kindex set mipsfpu
25723 @kindex show mipsfpu
25724 @cindex @acronym{MIPS} remote floating point
25725 @cindex floating point, @acronym{MIPS} remote
25726 If your target board does not support the @acronym{MIPS} floating point
25727 coprocessor, you should use the command @samp{set mipsfpu none} (if you
25728 need this, you may wish to put the command in your @value{GDBN} init
25729 file). This tells @value{GDBN} how to find the return value of
25730 functions which return floating point values. It also allows
25731 @value{GDBN} to avoid saving the floating point registers when calling
25732 functions on the board. If you are using a floating point coprocessor
25733 with only single precision floating point support, as on the @sc{r4650}
25734 processor, use the command @samp{set mipsfpu single}. The default
25735 double precision floating point coprocessor may be selected using
25736 @samp{set mipsfpu double}.
25737
25738 In previous versions the only choices were double precision or no
25739 floating point, so @samp{set mipsfpu on} will select double precision
25740 and @samp{set mipsfpu off} will select no floating point.
25741
25742 As usual, you can inquire about the @code{mipsfpu} variable with
25743 @samp{show mipsfpu}.
25744 @end table
25745
25746 @node OpenRISC 1000
25747 @subsection OpenRISC 1000
25748 @cindex OpenRISC 1000
25749
25750 @noindent
25751 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
25752 mainly provided as a soft-core which can run on Xilinx, Altera and other
25753 FPGA's.
25754
25755 @value{GDBN} for OpenRISC supports the below commands when connecting to
25756 a target:
25757
25758 @table @code
25759
25760 @kindex target sim
25761 @item target sim
25762
25763 Runs the builtin CPU simulator which can run very basic
25764 programs but does not support most hardware functions like MMU.
25765 For more complex use cases the user is advised to run an external
25766 target, and connect using @samp{target remote}.
25767
25768 Example: @code{target sim}
25769
25770 @item set debug or1k
25771 Toggle whether to display OpenRISC-specific debugging messages from the
25772 OpenRISC target support subsystem.
25773
25774 @item show debug or1k
25775 Show whether OpenRISC-specific debugging messages are enabled.
25776 @end table
25777
25778 @node PowerPC Embedded
25779 @subsection PowerPC Embedded
25780
25781 @cindex DVC register
25782 @value{GDBN} supports using the DVC (Data Value Compare) register to
25783 implement in hardware simple hardware watchpoint conditions of the form:
25784
25785 @smallexample
25786 (@value{GDBP}) watch @var{address|variable} \
25787 if @var{address|variable} == @var{constant expression}
25788 @end smallexample
25789
25790 The DVC register will be automatically used when @value{GDBN} detects
25791 such pattern in a condition expression, and the created watchpoint uses one
25792 debug register (either the @code{exact-watchpoints} option is on and the
25793 variable is scalar, or the variable has a length of one byte). This feature
25794 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
25795 or newer.
25796
25797 When running on PowerPC embedded processors, @value{GDBN} automatically uses
25798 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
25799 in which case watchpoints using only one debug register are created when
25800 watching variables of scalar types.
25801
25802 You can create an artificial array to watch an arbitrary memory
25803 region using one of the following commands (@pxref{Expressions}):
25804
25805 @smallexample
25806 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
25807 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
25808 @end smallexample
25809
25810 PowerPC embedded processors support masked watchpoints. See the discussion
25811 about the @code{mask} argument in @ref{Set Watchpoints}.
25812
25813 @cindex ranged breakpoint
25814 PowerPC embedded processors support hardware accelerated
25815 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
25816 the inferior whenever it executes an instruction at any address within
25817 the range it was set at. To set a ranged breakpoint in @value{GDBN},
25818 use the @code{break-range} command.
25819
25820 @value{GDBN} provides the following PowerPC-specific commands:
25821
25822 @table @code
25823 @kindex break-range
25824 @item break-range @var{start-locspec}, @var{end-locspec}
25825 Set a breakpoint for an address range given by @var{start-locspec} and
25826 @var{end-locspec}, which are location specs. @xref{Location
25827 Specifications}, for a list of all the possible forms of location
25828 specs. @value{GDBN} resolves both @var{start-locspec} and
25829 @var{end-locspec}, and uses the addresses of the resolved code
25830 locations as start and end addresses of the range to break at. The
25831 breakpoint will stop execution of the inferior whenever it executes an
25832 instruction at any address between the start and end addresses,
25833 inclusive. If either @var{start-locspec} or @var{end-locspec} resolve
25834 to multiple code locations in the program, then the command aborts
25835 with an error without creating a breakpoint.
25836
25837 @kindex set powerpc
25838 @item set powerpc soft-float
25839 @itemx show powerpc soft-float
25840 Force @value{GDBN} to use (or not use) a software floating point calling
25841 convention. By default, @value{GDBN} selects the calling convention based
25842 on the selected architecture and the provided executable file.
25843
25844 @item set powerpc vector-abi
25845 @itemx show powerpc vector-abi
25846 Force @value{GDBN} to use the specified calling convention for vector
25847 arguments and return values. The valid options are @samp{auto};
25848 @samp{generic}, to avoid vector registers even if they are present;
25849 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
25850 registers. By default, @value{GDBN} selects the calling convention
25851 based on the selected architecture and the provided executable file.
25852
25853 @item set powerpc exact-watchpoints
25854 @itemx show powerpc exact-watchpoints
25855 Allow @value{GDBN} to use only one debug register when watching a variable
25856 of scalar type, thus assuming that the variable is accessed through the
25857 address of its first byte.
25858
25859 @end table
25860
25861 @node AVR
25862 @subsection Atmel AVR
25863 @cindex AVR
25864
25865 When configured for debugging the Atmel AVR, @value{GDBN} supports the
25866 following AVR-specific commands:
25867
25868 @table @code
25869 @item info io_registers
25870 @kindex info io_registers@r{, AVR}
25871 @cindex I/O registers (Atmel AVR)
25872 This command displays information about the AVR I/O registers. For
25873 each register, @value{GDBN} prints its number and value.
25874 @end table
25875
25876 @node CRIS
25877 @subsection CRIS
25878 @cindex CRIS
25879
25880 When configured for debugging CRIS, @value{GDBN} provides the
25881 following CRIS-specific commands:
25882
25883 @table @code
25884 @item set cris-version @var{ver}
25885 @cindex CRIS version
25886 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
25887 The CRIS version affects register names and sizes. This command is useful in
25888 case autodetection of the CRIS version fails.
25889
25890 @item show cris-version
25891 Show the current CRIS version.
25892
25893 @item set cris-dwarf2-cfi
25894 @cindex DWARF-2 CFI and CRIS
25895 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
25896 Change to @samp{off} when using @code{gcc-cris} whose version is below
25897 @code{R59}.
25898
25899 @item show cris-dwarf2-cfi
25900 Show the current state of using DWARF-2 CFI.
25901
25902 @item set cris-mode @var{mode}
25903 @cindex CRIS mode
25904 Set the current CRIS mode to @var{mode}. It should only be changed when
25905 debugging in guru mode, in which case it should be set to
25906 @samp{guru} (the default is @samp{normal}).
25907
25908 @item show cris-mode
25909 Show the current CRIS mode.
25910 @end table
25911
25912 @node Super-H
25913 @subsection Renesas Super-H
25914 @cindex Super-H
25915
25916 For the Renesas Super-H processor, @value{GDBN} provides these
25917 commands:
25918
25919 @table @code
25920 @item set sh calling-convention @var{convention}
25921 @kindex set sh calling-convention
25922 Set the calling-convention used when calling functions from @value{GDBN}.
25923 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
25924 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
25925 convention. If the DWARF-2 information of the called function specifies
25926 that the function follows the Renesas calling convention, the function
25927 is called using the Renesas calling convention. If the calling convention
25928 is set to @samp{renesas}, the Renesas calling convention is always used,
25929 regardless of the DWARF-2 information. This can be used to override the
25930 default of @samp{gcc} if debug information is missing, or the compiler
25931 does not emit the DWARF-2 calling convention entry for a function.
25932
25933 @item show sh calling-convention
25934 @kindex show sh calling-convention
25935 Show the current calling convention setting.
25936
25937 @end table
25938
25939
25940 @node Architectures
25941 @section Architectures
25942
25943 This section describes characteristics of architectures that affect
25944 all uses of @value{GDBN} with the architecture, both native and cross.
25945
25946 @menu
25947 * AArch64::
25948 * i386::
25949 * Alpha::
25950 * MIPS::
25951 * HPPA:: HP PA architecture
25952 * PowerPC::
25953 * Nios II::
25954 * Sparc64::
25955 * S12Z::
25956 * AMD GPU:: @acronym{AMD GPU} architectures
25957 @end menu
25958
25959 @node AArch64
25960 @subsection AArch64
25961 @cindex AArch64 support
25962
25963 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25964 following special commands:
25965
25966 @table @code
25967 @item set debug aarch64
25968 @kindex set debug aarch64
25969 This command determines whether AArch64 architecture-specific debugging
25970 messages are to be displayed.
25971
25972 @item show debug aarch64
25973 Show whether AArch64 debugging messages are displayed.
25974
25975 @end table
25976
25977 @subsubsection AArch64 SVE.
25978 @cindex AArch64 SVE.
25979
25980 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25981 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25982 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25983 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25984 @code{$vg} will be provided. This is the vector granule for the current thread
25985 and represents the number of 64-bit chunks in an SVE @code{z} register.
25986
25987 If the vector length changes, then the @code{$vg} register will be updated,
25988 but the lengths of the @code{z} and @code{p} registers will not change. This
25989 is a known limitation of @value{GDBN} and does not affect the execution of the
25990 target process.
25991
25992 @subsubsection AArch64 Pointer Authentication.
25993 @cindex AArch64 Pointer Authentication.
25994 @anchor{AArch64 PAC}
25995
25996 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25997 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25998 register @code{$lr} is pointing to an PAC function its value will be masked.
25999 When GDB prints a backtrace, any addresses that required unmasking will be
26000 postfixed with the marker [PAC]. When using the MI, this is printed as part
26001 of the @code{addr_flags} field.
26002
26003 @subsubsection AArch64 Memory Tagging Extension.
26004 @cindex AArch64 Memory Tagging Extension.
26005
26006 When @value{GDBN} is debugging the AArch64 architecture, the program is
26007 using the v8.5-A feature Memory Tagging Extension (MTE) and there is support
26008 in the kernel for MTE, @value{GDBN} will make memory tagging functionality
26009 available for inspection and editing of logical and allocation tags.
26010 @xref{Memory Tagging}.
26011
26012 To aid debugging, @value{GDBN} will output additional information when SIGSEGV
26013 signals are generated as a result of memory tag failures.
26014
26015 If the tag violation is synchronous, the following will be shown:
26016
26017 @smallexample
26018 Program received signal SIGSEGV, Segmentation fault
26019 Memory tag violation while accessing address 0x0500fffff7ff8000
26020 Allocation tag 0x1
26021 Logical tag 0x5.
26022 @end smallexample
26023
26024 If the tag violation is asynchronous, the fault address is not available.
26025 In this case @value{GDBN} will show the following:
26026
26027 @smallexample
26028 Program received signal SIGSEGV, Segmentation fault
26029 Memory tag violation
26030 Fault address unavailable.
26031 @end smallexample
26032
26033 A special register, @code{tag_ctl}, is made available through the
26034 @code{org.gnu.gdb.aarch64.mte} feature. This register exposes some
26035 options that can be controlled at runtime and emulates the @code{prctl}
26036 option @code{PR_SET_TAGGED_ADDR_CTRL}. For further information, see the
26037 documentation in the Linux kernel.
26038
26039 @value{GDBN} supports dumping memory tag data to core files through the
26040 @command{gcore} command and reading memory tag data from core files generated
26041 by the @command{gcore} command or the Linux kernel.
26042
26043 When a process uses memory-mapped pages protected by memory tags (for
26044 example, AArch64 MTE), this additional information will be recorded in
26045 the core file in the event of a crash or if @value{GDBN} generates a core file
26046 from the current process state.
26047
26048 The memory tag data will be used so developers can display the memory
26049 tags from a particular memory region (using the @samp{m} modifier to the
26050 @command{x} command, using the @command{print} command or using the various
26051 @command{memory-tag} subcommands.
26052
26053 In the case of a crash, @value{GDBN} will attempt to retrieve the memory tag
26054 information automatically from the core file, and will show one of the above
26055 messages depending on whether the synchronous or asynchronous mode is selected.
26056 @xref{Memory Tagging}. @xref{Memory}.
26057
26058 @node i386
26059 @subsection x86 Architecture-specific Issues
26060
26061 @table @code
26062 @item set struct-convention @var{mode}
26063 @kindex set struct-convention
26064 @cindex struct return convention
26065 @cindex struct/union returned in registers
26066 Set the convention used by the inferior to return @code{struct}s and
26067 @code{union}s from functions to @var{mode}. Possible values of
26068 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
26069 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
26070 are returned on the stack, while @code{"reg"} means that a
26071 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
26072 be returned in a register.
26073
26074 @item show struct-convention
26075 @kindex show struct-convention
26076 Show the current setting of the convention to return @code{struct}s
26077 from functions.
26078 @end table
26079
26080
26081 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
26082 @cindex Intel Memory Protection Extensions (MPX).
26083
26084 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
26085 @footnote{The register named with capital letters represent the architecture
26086 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
26087 which are the lower bound and upper bound. Bounds are effective addresses or
26088 memory locations. The upper bounds are architecturally represented in 1's
26089 complement form. A bound having lower bound = 0, and upper bound = 0
26090 (1's complement of all bits set) will allow access to the entire address space.
26091
26092 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
26093 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
26094 display the upper bound performing the complement of one operation on the
26095 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
26096 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
26097 can also be noted that the upper bounds are inclusive.
26098
26099 As an example, assume that the register BND0 holds bounds for a pointer having
26100 access allowed for the range between 0x32 and 0x71. The values present on
26101 bnd0raw and bnd registers are presented as follows:
26102
26103 @smallexample
26104 bnd0raw = @{0x32, 0xffffffff8e@}
26105 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
26106 @end smallexample
26107
26108 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
26109 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
26110 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
26111 Python, the display includes the memory size, in bits, accessible to
26112 the pointer.
26113
26114 Bounds can also be stored in bounds tables, which are stored in
26115 application memory. These tables store bounds for pointers by specifying
26116 the bounds pointer's value along with its bounds. Evaluating and changing
26117 bounds located in bound tables is therefore interesting while investigating
26118 bugs on MPX context. @value{GDBN} provides commands for this purpose:
26119
26120 @table @code
26121 @item show mpx bound @var{pointer}
26122 @kindex show mpx bound
26123 Display bounds of the given @var{pointer}.
26124
26125 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
26126 @kindex set mpx bound
26127 Set the bounds of a pointer in the bound table.
26128 This command takes three parameters: @var{pointer} is the pointers
26129 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
26130 for lower and upper bounds respectively.
26131 @end table
26132
26133 When you call an inferior function on an Intel MPX enabled program,
26134 GDB sets the inferior's bound registers to the init (disabled) state
26135 before calling the function. As a consequence, bounds checks for the
26136 pointer arguments passed to the function will always pass.
26137
26138 This is necessary because when you call an inferior function, the
26139 program is usually in the middle of the execution of other function.
26140 Since at that point bound registers are in an arbitrary state, not
26141 clearing them would lead to random bound violations in the called
26142 function.
26143
26144 You can still examine the influence of the bound registers on the
26145 execution of the called function by stopping the execution of the
26146 called function at its prologue, setting bound registers, and
26147 continuing the execution. For example:
26148
26149 @smallexample
26150 $ break *upper
26151 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
26152 $ print upper (a, b, c, d, 1)
26153 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
26154 $ print $bnd0
26155 @{lbound = 0x0, ubound = ffffffff@} : size -1
26156 @end smallexample
26157
26158 At this last step the value of bnd0 can be changed for investigation of bound
26159 violations caused along the execution of the call. In order to know how to
26160 set the bound registers or bound table for the call consult the ABI.
26161
26162 @node Alpha
26163 @subsection Alpha
26164
26165 See the following section.
26166
26167 @node MIPS
26168 @subsection @acronym{MIPS}
26169
26170 @cindex stack on Alpha
26171 @cindex stack on @acronym{MIPS}
26172 @cindex Alpha stack
26173 @cindex @acronym{MIPS} stack
26174 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
26175 sometimes requires @value{GDBN} to search backward in the object code to
26176 find the beginning of a function.
26177
26178 @cindex response time, @acronym{MIPS} debugging
26179 To improve response time (especially for embedded applications, where
26180 @value{GDBN} may be restricted to a slow serial line for this search)
26181 you may want to limit the size of this search, using one of these
26182 commands:
26183
26184 @table @code
26185 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
26186 @item set heuristic-fence-post @var{limit}
26187 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
26188 search for the beginning of a function. A value of @var{0} (the
26189 default) means there is no limit. However, except for @var{0}, the
26190 larger the limit the more bytes @code{heuristic-fence-post} must search
26191 and therefore the longer it takes to run. You should only need to use
26192 this command when debugging a stripped executable.
26193
26194 @item show heuristic-fence-post
26195 Display the current limit.
26196 @end table
26197
26198 @noindent
26199 These commands are available @emph{only} when @value{GDBN} is configured
26200 for debugging programs on Alpha or @acronym{MIPS} processors.
26201
26202 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
26203 programs:
26204
26205 @table @code
26206 @item set mips abi @var{arg}
26207 @kindex set mips abi
26208 @cindex set ABI for @acronym{MIPS}
26209 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
26210 values of @var{arg} are:
26211
26212 @table @samp
26213 @item auto
26214 The default ABI associated with the current binary (this is the
26215 default).
26216 @item o32
26217 @item o64
26218 @item n32
26219 @item n64
26220 @item eabi32
26221 @item eabi64
26222 @end table
26223
26224 @item show mips abi
26225 @kindex show mips abi
26226 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
26227
26228 @item set mips compression @var{arg}
26229 @kindex set mips compression
26230 @cindex code compression, @acronym{MIPS}
26231 Tell @value{GDBN} which @acronym{MIPS} compressed
26232 @acronym{ISA, Instruction Set Architecture} encoding is used by the
26233 inferior. @value{GDBN} uses this for code disassembly and other
26234 internal interpretation purposes. This setting is only referred to
26235 when no executable has been associated with the debugging session or
26236 the executable does not provide information about the encoding it uses.
26237 Otherwise this setting is automatically updated from information
26238 provided by the executable.
26239
26240 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
26241 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
26242 executables containing @acronym{MIPS16} code frequently are not
26243 identified as such.
26244
26245 This setting is ``sticky''; that is, it retains its value across
26246 debugging sessions until reset either explicitly with this command or
26247 implicitly from an executable.
26248
26249 The compiler and/or assembler typically add symbol table annotations to
26250 identify functions compiled for the @acronym{MIPS16} or
26251 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
26252 are present, @value{GDBN} uses them in preference to the global
26253 compressed @acronym{ISA} encoding setting.
26254
26255 @item show mips compression
26256 @kindex show mips compression
26257 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
26258 @value{GDBN} to debug the inferior.
26259
26260 @item set mipsfpu
26261 @itemx show mipsfpu
26262 @xref{MIPS Embedded, set mipsfpu}.
26263
26264 @item set mips mask-address @var{arg}
26265 @kindex set mips mask-address
26266 @cindex @acronym{MIPS} addresses, masking
26267 This command determines whether the most-significant 32 bits of 64-bit
26268 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
26269 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
26270 setting, which lets @value{GDBN} determine the correct value.
26271
26272 @item show mips mask-address
26273 @kindex show mips mask-address
26274 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
26275 not.
26276
26277 @item set remote-mips64-transfers-32bit-regs
26278 @kindex set remote-mips64-transfers-32bit-regs
26279 This command controls compatibility with 64-bit @acronym{MIPS} targets that
26280 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
26281 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
26282 and 64 bits for other registers, set this option to @samp{on}.
26283
26284 @item show remote-mips64-transfers-32bit-regs
26285 @kindex show remote-mips64-transfers-32bit-regs
26286 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
26287
26288 @item set debug mips
26289 @kindex set debug mips
26290 This command turns on and off debugging messages for the @acronym{MIPS}-specific
26291 target code in @value{GDBN}.
26292
26293 @item show debug mips
26294 @kindex show debug mips
26295 Show the current setting of @acronym{MIPS} debugging messages.
26296 @end table
26297
26298
26299 @node HPPA
26300 @subsection HPPA
26301 @cindex HPPA support
26302
26303 When @value{GDBN} is debugging the HP PA architecture, it provides the
26304 following special commands:
26305
26306 @table @code
26307 @item set debug hppa
26308 @kindex set debug hppa
26309 This command determines whether HPPA architecture-specific debugging
26310 messages are to be displayed.
26311
26312 @item show debug hppa
26313 Show whether HPPA debugging messages are displayed.
26314
26315 @item maint print unwind @var{address}
26316 @kindex maint print unwind@r{, HPPA}
26317 This command displays the contents of the unwind table entry at the
26318 given @var{address}.
26319
26320 @end table
26321
26322
26323 @node PowerPC
26324 @subsection PowerPC
26325 @cindex PowerPC architecture
26326
26327 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
26328 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
26329 numbers stored in the floating point registers. These values must be stored
26330 in two consecutive registers, always starting at an even register like
26331 @code{f0} or @code{f2}.
26332
26333 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
26334 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
26335 @code{f2} and @code{f3} for @code{$dl1} and so on.
26336
26337 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
26338 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
26339
26340 @node Nios II
26341 @subsection Nios II
26342 @cindex Nios II architecture
26343
26344 When @value{GDBN} is debugging the Nios II architecture,
26345 it provides the following special commands:
26346
26347 @table @code
26348
26349 @item set debug nios2
26350 @kindex set debug nios2
26351 This command turns on and off debugging messages for the Nios II
26352 target code in @value{GDBN}.
26353
26354 @item show debug nios2
26355 @kindex show debug nios2
26356 Show the current setting of Nios II debugging messages.
26357 @end table
26358
26359 @node Sparc64
26360 @subsection Sparc64
26361 @cindex Sparc64 support
26362 @cindex Application Data Integrity
26363 @subsubsection ADI Support
26364
26365 The M7 processor supports an Application Data Integrity (ADI) feature that
26366 detects invalid data accesses. When software allocates memory and enables
26367 ADI on the allocated memory, it chooses a 4-bit version number, sets the
26368 version in the upper 4 bits of the 64-bit pointer to that data, and stores
26369 the 4-bit version in every cacheline of that data. Hardware saves the latter
26370 in spare bits in the cache and memory hierarchy. On each load and store,
26371 the processor compares the upper 4 VA (virtual address) bits to the
26372 cacheline's version. If there is a mismatch, the processor generates a
26373 version mismatch trap which can be either precise or disrupting. The trap
26374 is an error condition which the kernel delivers to the process as a SIGSEGV
26375 signal.
26376
26377 Note that only 64-bit applications can use ADI and need to be built with
26378 ADI-enabled.
26379
26380 Values of the ADI version tags, which are in granularity of a
26381 cacheline (64 bytes), can be viewed or modified.
26382
26383
26384 @table @code
26385 @kindex adi examine
26386 @item adi (examine | x) [ / @var{n} ] @var{addr}
26387
26388 The @code{adi examine} command displays the value of one ADI version tag per
26389 cacheline.
26390
26391 @var{n} is a decimal integer specifying the number in bytes; the default
26392 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
26393 block size, to display.
26394
26395 @var{addr} is the address in user address space where you want @value{GDBN}
26396 to begin displaying the ADI version tags.
26397
26398 Below is an example of displaying ADI versions of variable "shmaddr".
26399
26400 @smallexample
26401 (@value{GDBP}) adi x/100 shmaddr
26402 0xfff800010002c000: 0 0
26403 @end smallexample
26404
26405 @kindex adi assign
26406 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
26407
26408 The @code{adi assign} command is used to assign new ADI version tag
26409 to an address.
26410
26411 @var{n} is a decimal integer specifying the number in bytes;
26412 the default is 1. It specifies how much ADI version information, at the
26413 ratio of 1:ADI block size, to modify.
26414
26415 @var{addr} is the address in user address space where you want @value{GDBN}
26416 to begin modifying the ADI version tags.
26417
26418 @var{tag} is the new ADI version tag.
26419
26420 For example, do the following to modify then verify ADI versions of
26421 variable "shmaddr":
26422
26423 @smallexample
26424 (@value{GDBP}) adi a/100 shmaddr = 7
26425 (@value{GDBP}) adi x/100 shmaddr
26426 0xfff800010002c000: 7 7
26427 @end smallexample
26428
26429 @end table
26430
26431 @node S12Z
26432 @subsection S12Z
26433 @cindex S12Z support
26434
26435 When @value{GDBN} is debugging the S12Z architecture,
26436 it provides the following special command:
26437
26438 @table @code
26439 @item maint info bdccsr
26440 @kindex maint info bdccsr@r{, S12Z}
26441 This command displays the current value of the microprocessor's
26442 BDCCSR register.
26443 @end table
26444
26445 @node AMD GPU
26446 @subsection @acronym{AMD GPU}
26447 @cindex @acronym{AMD GPU} support
26448
26449 @value{GDBN} supports debugging programs offloaded to @acronym{AMD GPU} devices
26450 using the @url{https://docs.amd.com/, @acronym{AMD ROCm}} platform.
26451 @value{GDBN} presents host threads alongside GPU wavefronts, allowing debugging
26452 both the host and device parts of the program simultaneously.
26453
26454 @subsubsection @acronym{AMD GPU} Architectures
26455
26456 The list of @acronym{AMD GPU} architectures supported by @value{GDBN} depends
26457 on the version of the AMD Debugger API library used. See its
26458 @uref{https://docs.amd.com/bundle/ROCDebugger_User_and_API, documentation} for
26459 more details.
26460
26461 @subsubsection @acronym{AMD GPU} Device Driver and @acronym{AMD ROCm} Runtime
26462
26463 @value{GDBN} requires a compatible @acronym{AMD GPU} device driver to
26464 be installed. A warning message is displayed if either the device
26465 driver version or the version of the debug support it implements is
26466 unsupported. @value{GDBN} will continue to function except no
26467 @acronym{AMD GPU} debugging will be possible.
26468
26469 @value{GDBN} requires each agent to have compatible firmware installed
26470 by the device driver. A warning message is displayed if unsupported
26471 firmware is detected. @value{GDBN} will continue to function except
26472 no @acronym{AMD GPU} debugging will be possible on the agent.
26473
26474 @value{GDBN} requires a compatible @acronym{AMD ROCm} runtime to be
26475 loaded in order to detect @acronym{AMD GPU} code objects and
26476 wavefronts. A warning message is displayed if an unsupported
26477 @acronym{AMD ROCm} runtime is detected, or there is an error or
26478 restriction that prevents debugging. @value{GDBN} will continue to
26479 function except no @acronym{AMD GPU} debugging will be possible.
26480
26481 @subsubsection @acronym{AMD GPU} Wavefronts
26482 @cindex wavefronts
26483
26484 An @acronym{AMD GPU} wavefront is represented in @value{GDBN} as a
26485 thread.
26486
26487 Note that some @acronym{AMD GPU} architectures may have restrictions
26488 on providing information about @acronym{AMD GPU} wavefronts created
26489 when @value{GDBN} is not attached (@pxref{AMD GPU Attaching
26490 Restrictions, , @acronym{AMD GPU} Attaching Restrictions}).
26491
26492 When scheduler-locking is in effect (@pxref{set scheduler-locking}),
26493 new wavefronts created by the resumed thread (either CPU thread or GPU
26494 wavefront) are held in the halt state.
26495
26496 @subsubsection @acronym{AMD GPU} Code Objects
26497
26498 The @samp{info sharedlibrary} command will show the @acronym{AMD GPU}
26499 code objects as file or memory URIs, together with the host's shared
26500 libraries. For example:
26501
26502 @smallexample
26503 (@value{GDBP}) info sharedlibrary
26504 From To Syms Read Shared Object Library
26505 0x1111 0x2222 Yes (*) /lib64/ld-linux-x86-64.so.2
26506 ...
26507 0x3333 0x4444 Yes (*) /opt/rocm-4.5.0/.../libamd_comgr.so
26508 0x5555 0x6666 Yes (*) /lib/x86_64-linux-gnu/libtinfo.so.5
26509 0x7777 0x8888 Yes file:///tmp/a.out#offset=6477&size=10832
26510 0x9999 0xaaaa Yes (*) memory://95557/mem#offset=0x1234&size=100
26511 (*): Shared library is missing debugging information.
26512 (@value{GDBP})
26513 @end smallexample
26514
26515 For a @samp{file} URI, the path portion is the file on disk containing
26516 the code object. The @var{offset} parameter is a 0-based offset in
26517 this file, to the start of the code object. If omitted, it defaults to
26518 0. The @var{size} parameter is the size of the code object in bytes.
26519 If omitted, it defaults to the size of the file.
26520
26521 For a @samp{memory} URI, the path portion is the process id of the
26522 process owning the memory containing the code object. The @var{offset}
26523 parameter is the memory address where the code object is found, and
26524 the @var{size} parameter is its size in bytes.
26525
26526 @acronym{AMD GPU} code objects are loaded into each @acronym{AMD GPU}
26527 device separately. The @samp{info sharedlibrary} command may
26528 therefore show the same code object loaded multiple times. As a
26529 consequence, setting a breakpoint in @acronym{AMD GPU} code will
26530 result in multiple breakpoint locations if there are multiple
26531 @acronym{AMD GPU} devices.
26532
26533 @subsubsection @acronym{AMD GPU} Entity Target Identifiers and Convenience Variables
26534
26535 The @acronym{AMD GPU} entities have the following target identifier formats:
26536
26537 @table @asis
26538
26539 @item Thread Target ID
26540 The @acronym{AMD GPU} thread target identifier (@var{systag}) string has the
26541 following format:
26542
26543 @smallexample
26544 AMDGPU Wave @var{agent-id}:@var{queue-id}:@var{dispatch-id}:@var{wave-id} (@var{work-group-x},@var{work-group-y},@var{work-group-z})/@var{work-group-thread-index}
26545 @end smallexample
26546
26547 @end table
26548
26549 @anchor{AMD GPU Signals}
26550 @subsubsection @acronym{AMD GPU} Signals
26551
26552 For @acronym{AMD GPU} wavefronts, @value{GDBN} maps target conditions to stop
26553 signals in the following way:
26554
26555 @table @code
26556
26557 @item SIGILL
26558 Execution of an illegal instruction.
26559
26560 @item SIGTRAP
26561 Execution of a @code{S_TRAP} instruction other than:
26562
26563 @itemize @bullet{}
26564
26565 @item
26566 @code{S_TRAP 1} which is used by @value{GDBN} to insert breakpoints.
26567
26568 @item
26569 @code{S_TRAP 2} which raises @code{SIGABRT}.
26570
26571 @end itemize
26572
26573 @item SIGABRT
26574 Execution of a @code{S_TRAP 2} instruction.
26575
26576 @item SIGFPE
26577 Execution of a floating point or integer instruction detects a
26578 condition that is enabled to raise a signal. The conditions include:
26579
26580 @itemize @bullet{}
26581
26582 @item
26583 Floating point operation is invalid.
26584
26585 @item
26586 Floating point operation had subnormal input that was rounded to zero.
26587
26588 @item
26589 Floating point operation performed a division by zero.
26590
26591 @item
26592 Floating point operation produced an overflow result. The result was
26593 rounded to infinity.
26594
26595 @item
26596 Floating point operation produced an underflow result. A subnormal
26597 result was rounded to zero.
26598
26599 @item
26600 Floating point operation produced an inexact result.
26601
26602 @item
26603 Integer operation performed a division by zero.
26604
26605 @end itemize
26606
26607 By default, these conditions are not enabled to raise signals. The
26608 @samp{set $mode} command can be used to change the @acronym{AMD GPU}
26609 wavefront's register that has bits controlling which conditions are
26610 enabled to raise signals. The @samp{print $trapsts} command can be
26611 used to inspect which conditions have been detected even if they are
26612 not enabled to raise a signal.
26613
26614 @item SIGBUS
26615 Execution of an instruction that accessed global memory using an
26616 address that is outside the virtual address range.
26617
26618 @item SIGSEGV
26619 Execution of an instruction that accessed a global memory page that is
26620 either not mapped or accessed with incompatible permissions.
26621
26622 @end table
26623
26624 If a single instruction raises more than one signal, they will be
26625 reported one at a time each time the wavefront is continued.
26626
26627 @subsubsection @acronym{AMD GPU} Logging
26628
26629 The @samp{set debug amd-dbgapi} command can be used
26630 to enable diagnostic messages in the @samp{amd-dbgapi} target. The
26631 @samp{show debug amd-dbgapi} command displays the current setting.
26632 @xref{set debug amd-dbgapi}.
26633
26634 The @samp{set debug amd-dbgapi-lib log-level @var{level}} command can be used
26635 to enable diagnostic messages from the @samp{amd-dbgapi} library (which
26636 @value{GDBN} uses under the hood). The @samp{show debug amd-dbgapi-lib
26637 log-level} command displays the current @samp{amd-dbgapi} library log level.
26638 @xref{set debug amd-dbgapi-lib}.
26639
26640 @subsubsection @acronym{AMD GPU} Restrictions
26641
26642 @enumerate
26643
26644 @item
26645 When in non-stop mode, wavefronts may not hit breakpoints inserted
26646 while not stopped, nor see memory updates made while not stopped,
26647 until the wavefront is next stopped. Memory updated by non-stopped
26648 wavefronts may not be visible until the wavefront is next stopped.
26649
26650 @item The HIP runtime performs deferred code object loading by default.
26651 @acronym{AMD GPU} code objects are not loaded until the first kernel is
26652 launched. Before then, all breakpoints have to be set as pending breakpoints.
26653
26654 If source line positions are used that only correspond to source lines in
26655 unloaded code objects, then @value{GDBN} may not set pending breakpoints, and
26656 instead set breakpoints on the next following source line that maps to host
26657 code. This can result in unexpected breakpoint hits being reported. When the
26658 code object containing the source lines is loaded, the incorrect breakpoints
26659 will be removed and replaced by the correct ones. This problem can be avoided
26660 by only setting breakpoints in unloaded code objects using symbol or function
26661 names.
26662
26663 Setting the @code{HIP_ENABLE_DEFERRED_LOADING} environment variable to @code{0}
26664 can be used to disable deferred code object loading by the HIP runtime. This
26665 ensures all code objects will be loaded when the inferior reaches the beginning
26666 of the @code{main} function.
26667
26668 @item
26669 If no CPU thread is running, then @samp{Ctrl-C} is not able to stop
26670 @acronym{AMD GPU} threads. This can happen for example if you enable
26671 @code{scheduler-locking} after the whole program stopped, and then resume an
26672 @acronym{AMD GPU} thread. The only way to unblock the situation is to kill the
26673 @value{GDBN} process.
26674
26675 @anchor{AMD GPU Attaching Restrictions}
26676 @item
26677
26678 By default, for some architectures, the @acronym{AMD GPU} device driver causes
26679 all @acronym{AMD GPU} wavefronts created when @value{GDBN} is not attached to
26680 be unable to report the dispatch associated with the wavefront, or the
26681 wavefront's work-group position. The @samp{info threads} command will display
26682 this missing information with a @samp{?}.
26683
26684 This does not affect wavefronts created while @value{GDBN} is attached which
26685 are always capable of reporting this information.
26686
26687 If the @env{HSA_ENABLE_DEBUG} environment variable is set to @samp{1} when the
26688 @acronym{AMD ROCm} runtime is initialized, then this information will be
26689 available for all architectures even for wavefronts created when @value{GDBN}
26690 was not attached.
26691
26692 @end enumerate
26693
26694 @node Controlling GDB
26695 @chapter Controlling @value{GDBN}
26696
26697 You can alter the way @value{GDBN} interacts with you by using the
26698 @code{set} command. For commands controlling how @value{GDBN} displays
26699 data, see @ref{Print Settings, ,Print Settings}. Other settings are
26700 described here.
26701
26702 @menu
26703 * Prompt:: Prompt
26704 * Editing:: Command editing
26705 * Command History:: Command history
26706 * Screen Size:: Screen size
26707 * Output Styling:: Output styling
26708 * Numbers:: Numbers
26709 * ABI:: Configuring the current ABI
26710 * Auto-loading:: Automatically loading associated files
26711 * Messages/Warnings:: Optional warnings and messages
26712 * Debugging Output:: Optional messages about internal happenings
26713 * Other Misc Settings:: Other Miscellaneous Settings
26714 @end menu
26715
26716 @node Prompt
26717 @section Prompt
26718
26719 @cindex prompt
26720
26721 @value{GDBN} indicates its readiness to read a command by printing a string
26722 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
26723 can change the prompt string with the @code{set prompt} command. For
26724 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
26725 the prompt in one of the @value{GDBN} sessions so that you can always tell
26726 which one you are talking to.
26727
26728 @emph{Note:} @code{set prompt} does not add a space for you after the
26729 prompt you set. This allows you to set a prompt which ends in a space
26730 or a prompt that does not.
26731
26732 @table @code
26733 @kindex set prompt
26734 @item set prompt @var{newprompt}
26735 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
26736
26737 @kindex show prompt
26738 @item show prompt
26739 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
26740 @end table
26741
26742 Versions of @value{GDBN} that ship with Python scripting enabled have
26743 prompt extensions. The commands for interacting with these extensions
26744 are:
26745
26746 @table @code
26747 @kindex set extended-prompt
26748 @item set extended-prompt @var{prompt}
26749 Set an extended prompt that allows for substitutions.
26750 @xref{gdb.prompt}, for a list of escape sequences that can be used for
26751 substitution. Any escape sequences specified as part of the prompt
26752 string are replaced with the corresponding strings each time the prompt
26753 is displayed.
26754
26755 For example:
26756
26757 @smallexample
26758 set extended-prompt Current working directory: \w (@value{GDBP})
26759 @end smallexample
26760
26761 Note that when an extended-prompt is set, it takes control of the
26762 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
26763
26764 @kindex show extended-prompt
26765 @item show extended-prompt
26766 Prints the extended prompt. Any escape sequences specified as part of
26767 the prompt string with @code{set extended-prompt}, are replaced with the
26768 corresponding strings each time the prompt is displayed.
26769 @end table
26770
26771 @node Editing
26772 @section Command Editing
26773 @cindex readline
26774 @cindex command line editing
26775
26776 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
26777 @sc{gnu} library provides consistent behavior for programs which provide a
26778 command line interface to the user. Advantages are @sc{gnu} Emacs-style
26779 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
26780 substitution, and a storage and recall of command history across
26781 debugging sessions.
26782
26783 You may control the behavior of command line editing in @value{GDBN} with the
26784 command @code{set}.
26785
26786 @table @code
26787 @kindex set editing
26788 @cindex editing
26789 @item set editing
26790 @itemx set editing on
26791 Enable command line editing (enabled by default).
26792
26793 @item set editing off
26794 Disable command line editing.
26795
26796 @kindex show editing
26797 @item show editing
26798 Show whether command line editing is enabled.
26799 @end table
26800
26801 @ifset SYSTEM_READLINE
26802 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
26803 @end ifset
26804 @ifclear SYSTEM_READLINE
26805 @xref{Command Line Editing},
26806 @end ifclear
26807 for more details about the Readline
26808 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
26809 encouraged to read that chapter.
26810
26811 @cindex Readline application name
26812 @value{GDBN} sets the Readline application name to @samp{gdb}. This
26813 is useful for conditions in @file{.inputrc}.
26814
26815 @cindex operate-and-get-next
26816 @value{GDBN} defines a bindable Readline command,
26817 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
26818 This command accepts the current line for execution and fetches the
26819 next line relative to the current line from the history for editing.
26820 Any argument is ignored.
26821
26822 @node Command History
26823 @section Command History
26824 @cindex command history
26825
26826 @value{GDBN} can keep track of the commands you type during your
26827 debugging sessions, so that you can be certain of precisely what
26828 happened. Use these commands to manage the @value{GDBN} command
26829 history facility.
26830
26831 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
26832 package, to provide the history facility.
26833 @ifset SYSTEM_READLINE
26834 @xref{Using History Interactively, , , history, GNU History Library},
26835 @end ifset
26836 @ifclear SYSTEM_READLINE
26837 @xref{Using History Interactively},
26838 @end ifclear
26839 for the detailed description of the History library.
26840
26841 To issue a command to @value{GDBN} without affecting certain aspects of
26842 the state which is seen by users, prefix it with @samp{server }
26843 (@pxref{Server Prefix}). This
26844 means that this command will not affect the command history, nor will it
26845 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
26846 pressed on a line by itself.
26847
26848 @cindex @code{server}, command prefix
26849 The server prefix does not affect the recording of values into the value
26850 history; to print a value without recording it into the value history,
26851 use the @code{output} command instead of the @code{print} command.
26852
26853 Here is the description of @value{GDBN} commands related to command
26854 history.
26855
26856 @table @code
26857 @cindex history substitution
26858 @cindex history file
26859 @kindex set history filename
26860 @cindex @env{GDBHISTFILE}, environment variable
26861 @item set history filename @r{[}@var{fname}@r{]}
26862 Set the name of the @value{GDBN} command history file to @var{fname}.
26863 This is the file where @value{GDBN} reads an initial command history
26864 list, and where it writes the command history from this session when it
26865 exits. You can access this list through history expansion or through
26866 the history command editing characters listed below. This file defaults
26867 to the value of the environment variable @env{GDBHISTFILE}, or to
26868 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
26869 is not set.
26870
26871 The @env{GDBHISTFILE} environment variable is read after processing
26872 any @value{GDBN} initialization files (@pxref{Startup}) and after
26873 processing any commands passed using command line options (for
26874 example, @code{-ex}).
26875
26876 If the @var{fname} argument is not given, or if the @env{GDBHISTFILE}
26877 is the empty string then @value{GDBN} will neither try to load an
26878 existing history file, nor will it try to save the history on exit.
26879
26880 @cindex save command history
26881 @kindex set history save
26882 @item set history save
26883 @itemx set history save on
26884 Record command history in a file, whose name may be specified with the
26885 @code{set history filename} command. By default, this option is
26886 disabled. The command history will be recorded when @value{GDBN}
26887 exits. If @code{set history filename} is set to the empty string then
26888 history saving is disabled, even when @code{set history save} is
26889 @code{on}.
26890
26891 @item set history save off
26892 Don't record the command history into the file specified by @code{set
26893 history filename} when @value{GDBN} exits.
26894
26895 @cindex history size
26896 @kindex set history size
26897 @cindex @env{GDBHISTSIZE}, environment variable
26898 @item set history size @var{size}
26899 @itemx set history size unlimited
26900 Set the number of commands which @value{GDBN} keeps in its history list.
26901 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
26902 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
26903 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
26904 either a negative number or the empty string, then the number of commands
26905 @value{GDBN} keeps in the history list is unlimited.
26906
26907 The @env{GDBHISTSIZE} environment variable is read after processing
26908 any @value{GDBN} initialization files (@pxref{Startup}) and after
26909 processing any commands passed using command line options (for
26910 example, @code{-ex}).
26911
26912 @cindex remove duplicate history
26913 @kindex set history remove-duplicates
26914 @item set history remove-duplicates @var{count}
26915 @itemx set history remove-duplicates unlimited
26916 Control the removal of duplicate history entries in the command history list.
26917 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
26918 history entries and remove the first entry that is a duplicate of the current
26919 entry being added to the command history list. If @var{count} is
26920 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
26921 removal of duplicate history entries is disabled.
26922
26923 Only history entries added during the current session are considered for
26924 removal. This option is set to 0 by default.
26925
26926 @end table
26927
26928 History expansion assigns special meaning to the character @kbd{!}.
26929 @ifset SYSTEM_READLINE
26930 @xref{Event Designators, , , history, GNU History Library},
26931 @end ifset
26932 @ifclear SYSTEM_READLINE
26933 @xref{Event Designators},
26934 @end ifclear
26935 for more details.
26936
26937 @cindex history expansion, turn on/off
26938 Since @kbd{!} is also the logical not operator in C, history expansion
26939 is off by default. If you decide to enable history expansion with the
26940 @code{set history expansion on} command, you may sometimes need to
26941 follow @kbd{!} (when it is used as logical not, in an expression) with
26942 a space or a tab to prevent it from being expanded. The readline
26943 history facilities do not attempt substitution on the strings
26944 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
26945
26946 The commands to control history expansion are:
26947
26948 @table @code
26949 @item set history expansion on
26950 @itemx set history expansion
26951 @kindex set history expansion
26952 Enable history expansion. History expansion is off by default.
26953
26954 @item set history expansion off
26955 Disable history expansion.
26956
26957 @c @group
26958 @kindex show history
26959 @item show history
26960 @itemx show history filename
26961 @itemx show history save
26962 @itemx show history size
26963 @itemx show history expansion
26964 These commands display the state of the @value{GDBN} history parameters.
26965 @code{show history} by itself displays all four states.
26966 @c @end group
26967 @end table
26968
26969 @table @code
26970 @kindex show commands
26971 @cindex show last commands
26972 @cindex display command history
26973 @item show commands
26974 Display the last ten commands in the command history.
26975
26976 @item show commands @var{n}
26977 Print ten commands centered on command number @var{n}.
26978
26979 @item show commands +
26980 Print ten commands just after the commands last printed.
26981 @end table
26982
26983 @node Screen Size
26984 @section Screen Size
26985 @cindex size of screen
26986 @cindex screen size
26987 @cindex pagination
26988 @cindex page size
26989 @cindex pauses in output
26990
26991 Certain commands to @value{GDBN} may produce large amounts of
26992 information output to the screen. To help you read all of it,
26993 @value{GDBN} pauses and asks you for input at the end of each page of
26994 output. Type @key{RET} when you want to see one more page of output,
26995 @kbd{q} to discard the remaining output, or @kbd{c} to continue
26996 without paging for the rest of the current command. Also, the screen
26997 width setting determines when to wrap lines of output. Depending on
26998 what is being printed, @value{GDBN} tries to break the line at a
26999 readable place, rather than simply letting it overflow onto the
27000 following line.
27001
27002 Normally @value{GDBN} knows the size of the screen from the terminal
27003 driver software. For example, on Unix @value{GDBN} uses the termcap data base
27004 together with the value of the @env{TERM} environment variable and the
27005 @code{stty rows} and @code{stty cols} settings. If this is not correct,
27006 you can override it with the @code{set height} and @code{set
27007 width} commands:
27008
27009 @table @code
27010 @kindex set height
27011 @kindex set width
27012 @kindex show width
27013 @kindex show height
27014 @item set height @var{lpp}
27015 @itemx set height unlimited
27016 @itemx show height
27017 @itemx set width @var{cpl}
27018 @itemx set width unlimited
27019 @itemx show width
27020 These @code{set} commands specify a screen height of @var{lpp} lines and
27021 a screen width of @var{cpl} characters. The associated @code{show}
27022 commands display the current settings.
27023
27024 If you specify a height of either @code{unlimited} or zero lines,
27025 @value{GDBN} does not pause during output no matter how long the
27026 output is. This is useful if output is to a file or to an editor
27027 buffer.
27028
27029 Likewise, you can specify @samp{set width unlimited} or @samp{set
27030 width 0} to prevent @value{GDBN} from wrapping its output.
27031
27032 @item set pagination on
27033 @itemx set pagination off
27034 @kindex set pagination
27035 Turn the output pagination on or off; the default is on. Turning
27036 pagination off is the alternative to @code{set height unlimited}. Note that
27037 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
27038 Options, -batch}) also automatically disables pagination.
27039
27040 @item show pagination
27041 @kindex show pagination
27042 Show the current pagination mode.
27043 @end table
27044
27045 @node Output Styling
27046 @section Output Styling
27047 @cindex styling
27048 @cindex colors
27049
27050 @kindex set style
27051 @kindex show style
27052 @value{GDBN} can style its output on a capable terminal. This is
27053 enabled by default on most systems, but disabled by default when in
27054 batch mode (@pxref{Mode Options}). Various style settings are available;
27055 and styles can also be disabled entirely.
27056
27057 @table @code
27058 @item set style enabled @samp{on|off}
27059 Enable or disable all styling. The default is host-dependent, with
27060 most hosts defaulting to @samp{on}.
27061
27062 @item show style enabled
27063 Show the current state of styling.
27064
27065 @item set style sources @samp{on|off}
27066 Enable or disable source code styling. This affects whether source
27067 code, such as the output of the @code{list} command, is styled. The
27068 default is @samp{on}. Note that source styling only works if styling
27069 in general is enabled, and if a source highlighting library is
27070 available to @value{GDBN}.
27071
27072 There are two ways that highlighting can be done. First, if
27073 @value{GDBN} was linked with the GNU Source Highlight library, then it
27074 is used. Otherwise, if @value{GDBN} was configured with Python
27075 scripting support, and if the Python Pygments package is available,
27076 then it will be used.
27077
27078 @item show style sources
27079 Show the current state of source code styling.
27080
27081 @item set style tui-current-position @samp{on|off}
27082 Enable or disable styling of the source and assembly code highlighted
27083 by the TUI's current position indicator. The default is @samp{off}.
27084 @xref{TUI, ,@value{GDBN} Text User Interface}.
27085
27086 @item show style tui-current-position
27087 Show whether the source and assembly code highlighted by the TUI's
27088 current position indicator is styled.
27089
27090 @anchor{style_disassembler_enabled}
27091 @item set style disassembler enabled @samp{on|off}
27092 Enable or disable disassembler styling. This affects whether
27093 disassembler output, such as the output of the @code{disassemble}
27094 command, is styled. Disassembler styling only works if styling in
27095 general is enabled (with @code{set style enabled on}), and if a source
27096 highlighting library is available to @value{GDBN}.
27097
27098 The two source highlighting libraries that @value{GDBN} could use to
27099 style disassembler output are; @value{GDBN}'s builtin disassembler, or
27100 the Python Pygments package.
27101
27102 @value{GDBN}'s first choice will be to use the builtin disassembler
27103 for styling, this usually provides better results, being able to style
27104 different types of instruction operands differently. However, the
27105 builtin disassembler is not able to style all architectures.
27106
27107 For architectures that the builtin disassembler is unable to style,
27108 @value{GDBN} will fall back to use the Python Pygments package where
27109 possible. In order to use the Python Pygments package, @value{GDBN}
27110 must be built with Python support, and the Pygments package must be
27111 installed.
27112
27113 If neither of these options are available then @value{GDBN} will
27114 produce unstyled disassembler output, even when this setting is
27115 @samp{on}.
27116
27117 To discover if the current architecture supports styling using the
27118 builtin disassembler library see @ref{maint_libopcodes_styling,,@kbd{maint
27119 show libopcodes-styling enabled}}.
27120
27121 @item show style disassembler enabled
27122 Show the current state of disassembler styling.
27123
27124 @end table
27125
27126 Subcommands of @code{set style} control specific forms of styling.
27127 These subcommands all follow the same pattern: each style-able object
27128 can be styled with a foreground color, a background color, and an
27129 intensity.
27130
27131 For example, the style of file names can be controlled using the
27132 @code{set style filename} group of commands:
27133
27134 @table @code
27135 @item set style filename background @var{color}
27136 Set the background to @var{color}. Valid colors are @samp{none}
27137 (meaning the terminal's default color), @samp{black}, @samp{red},
27138 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
27139 and@samp{white}.
27140
27141 @item set style filename foreground @var{color}
27142 Set the foreground to @var{color}. Valid colors are @samp{none}
27143 (meaning the terminal's default color), @samp{black}, @samp{red},
27144 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
27145 and@samp{white}.
27146
27147 @item set style filename intensity @var{value}
27148 Set the intensity to @var{value}. Valid intensities are @samp{normal}
27149 (the default), @samp{bold}, and @samp{dim}.
27150 @end table
27151
27152 The @code{show style} command and its subcommands are styling
27153 a style name in their output using its own style.
27154 So, use @command{show style} to see the complete list of styles,
27155 their characteristics and the visual aspect of each style.
27156
27157 The style-able objects are:
27158 @table @code
27159 @item filename
27160 Control the styling of file names and URLs. By default, this style's
27161 foreground color is green.
27162
27163 @item function
27164 Control the styling of function names. These are managed with the
27165 @code{set style function} family of commands. By default, this
27166 style's foreground color is yellow.
27167
27168 This style is also used for symbol names in styled disassembler output
27169 if @value{GDBN} is using its builtin disassembler library for styling
27170 (@pxref{style_disassembler_enabled,,@kbd{set style disassembler
27171 enabled}}).
27172
27173 @item variable
27174 Control the styling of variable names. These are managed with the
27175 @code{set style variable} family of commands. By default, this style's
27176 foreground color is cyan.
27177
27178 @item address
27179 Control the styling of addresses. These are managed with the
27180 @code{set style address} family of commands. By default, this style's
27181 foreground color is blue.
27182
27183 This style is also used for addresses in styled disassembler output
27184 if @value{GDBN} is using its builtin disassembler library for styling
27185 (@pxref{style_disassembler_enabled,,@kbd{set style disassembler
27186 enabled}}).
27187
27188 @item version
27189 Control the styling of @value{GDBN}'s version number text. By
27190 default, this style's foreground color is magenta and it has bold
27191 intensity. The version number is displayed in two places, the output
27192 of @command{show version}, and when @value{GDBN} starts up.
27193
27194 In order to control how @value{GDBN} styles the version number at
27195 startup, add the @code{set style version} family of commands to the
27196 early initialization command file (@pxref{Initialization
27197 Files}).
27198
27199 @item title
27200 Control the styling of titles. These are managed with the
27201 @code{set style title} family of commands. By default, this style's
27202 intensity is bold. Commands are using the title style to improve
27203 the readability of large output. For example, the commands
27204 @command{apropos} and @command{help} are using the title style
27205 for the command names.
27206
27207 @item highlight
27208 Control the styling of highlightings. These are managed with the
27209 @code{set style highlight} family of commands. By default, this style's
27210 foreground color is red. Commands are using the highlight style to draw
27211 the user attention to some specific parts of their output. For example,
27212 the command @command{apropos -v REGEXP} uses the highlight style to
27213 mark the documentation parts matching @var{regexp}.
27214
27215 @item metadata
27216 Control the styling of data annotations added by @value{GDBN} to data
27217 it displays. By default, this style's intensity is dim. Metadata
27218 annotations include the @samp{repeats @var{n} times} annotation for
27219 suppressed display of repeated array elements (@pxref{Print Settings}),
27220 @samp{<unavailable>} and @w{@samp{<error @var{descr}>}} annotations
27221 for errors and @samp{<optimized-out>} annotations for optimized-out
27222 values in displaying stack frame information in backtraces
27223 (@pxref{Backtrace}), etc.
27224
27225 @item tui-border
27226 Control the styling of the TUI border. Note that, unlike other
27227 styling options, only the color of the border can be controlled via
27228 @code{set style}. This was done for compatibility reasons, as TUI
27229 controls to set the border's intensity predated the addition of
27230 general styling to @value{GDBN}. @xref{TUI Configuration}.
27231
27232 @item tui-active-border
27233 Control the styling of the active TUI border; that is, the TUI window
27234 that has the focus.
27235
27236 @item disassembler comment
27237 Control the styling of comments in the disassembler output. These are
27238 managed with the @code{set style disassembler comment} family of
27239 commands. This style is only used when @value{GDBN} is styling using
27240 its builtin disassembler library
27241 (@pxref{style_disassembler_enabled,,@kbd{set style disassembler
27242 enabled}}). By default, this style's intensity is dim, and its
27243 foreground color is white.
27244
27245 @item disassembler immediate
27246 Control the styling of numeric operands in the disassembler output.
27247 These are managed with the @code{set style disassembler immediate}
27248 family of commands. This style is not used for instruction operands
27249 that represent addresses, in that case the @samp{disassembler address}
27250 style is used. This style is only used when @value{GDBN} is styling
27251 using its builtin disassembler library. By default, this style's
27252 foreground color is blue.
27253
27254 @item disassembler address
27255 Control the styling of address operands in the disassembler output.
27256 This is an alias for the @samp{address} style.
27257
27258 @item disassembler symbol
27259 Control the styling of symbol names in the disassembler output. This
27260 is an alias for the @samp{function} style.
27261
27262 @item disassembler mnemonic
27263 Control the styling of instruction mnemonics in the disassembler
27264 output. These are managed with the @code{set style disassembler
27265 mnemonic} family of commands. This style is also used for assembler
27266 directives, e.g.@: @code{.byte}, @code{.word}, etc. This style is
27267 only used when @value{GDBN} is styling using its builtin disassembler
27268 library. By default, this style's foreground color is green.
27269
27270 @item disassembler register
27271 Control the styling of register operands in the disassembler output.
27272 These are managed with the @code{set style disassembler register}
27273 family of commands. This style is only used when @value{GDBN} is
27274 styling using its builtin disassembler library. By default, this style's
27275 foreground color is red.
27276
27277 @end table
27278
27279 @node Numbers
27280 @section Numbers
27281 @cindex number representation
27282 @cindex entering numbers
27283
27284 You can always enter numbers in octal, decimal, or hexadecimal in
27285 @value{GDBN} by the usual conventions: octal numbers begin with
27286 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
27287 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
27288 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
27289 10; likewise, the default display for numbers---when no particular
27290 format is specified---is base 10. You can change the default base for
27291 both input and output with the commands described below.
27292
27293 @table @code
27294 @kindex set input-radix
27295 @item set input-radix @var{base}
27296 Set the default base for numeric input. Supported choices
27297 for @var{base} are decimal 8, 10, or 16. The base must itself be
27298 specified either unambiguously or using the current input radix; for
27299 example, any of
27300
27301 @smallexample
27302 set input-radix 012
27303 set input-radix 10.
27304 set input-radix 0xa
27305 @end smallexample
27306
27307 @noindent
27308 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
27309 leaves the input radix unchanged, no matter what it was, since
27310 @samp{10}, being without any leading or trailing signs of its base, is
27311 interpreted in the current radix. Thus, if the current radix is 16,
27312 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
27313 change the radix.
27314
27315 @kindex set output-radix
27316 @item set output-radix @var{base}
27317 Set the default base for numeric display. Supported choices
27318 for @var{base} are decimal 8, 10, or 16. The base must itself be
27319 specified either unambiguously or using the current input radix.
27320
27321 @kindex show input-radix
27322 @item show input-radix
27323 Display the current default base for numeric input.
27324
27325 @kindex show output-radix
27326 @item show output-radix
27327 Display the current default base for numeric display.
27328
27329 @item set radix @r{[}@var{base}@r{]}
27330 @itemx show radix
27331 @kindex set radix
27332 @kindex show radix
27333 These commands set and show the default base for both input and output
27334 of numbers. @code{set radix} sets the radix of input and output to
27335 the same base; without an argument, it resets the radix back to its
27336 default value of 10.
27337
27338 @end table
27339
27340 @node ABI
27341 @section Configuring the Current ABI
27342
27343 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
27344 application automatically. However, sometimes you need to override its
27345 conclusions. Use these commands to manage @value{GDBN}'s view of the
27346 current ABI.
27347
27348 @cindex OS ABI
27349 @kindex set osabi
27350 @kindex show osabi
27351 @cindex Newlib OS ABI and its influence on the longjmp handling
27352
27353 One @value{GDBN} configuration can debug binaries for multiple operating
27354 system targets, either via remote debugging or native emulation.
27355 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
27356 but you can override its conclusion using the @code{set osabi} command.
27357 One example where this is useful is in debugging of binaries which use
27358 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
27359 not have the same identifying marks that the standard C library for your
27360 platform provides.
27361
27362 When @value{GDBN} is debugging the AArch64 architecture, it provides a
27363 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
27364 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
27365 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
27366
27367 @table @code
27368 @item show osabi
27369 Show the OS ABI currently in use.
27370
27371 @item set osabi
27372 With no argument, show the list of registered available OS ABI's.
27373
27374 @item set osabi @var{abi}
27375 Set the current OS ABI to @var{abi}.
27376 @end table
27377
27378 @cindex float promotion
27379
27380 Generally, the way that an argument of type @code{float} is passed to a
27381 function depends on whether the function is prototyped. For a prototyped
27382 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
27383 according to the architecture's convention for @code{float}. For unprototyped
27384 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
27385 @code{double} and then passed.
27386
27387 Unfortunately, some forms of debug information do not reliably indicate whether
27388 a function is prototyped. If @value{GDBN} calls a function that is not marked
27389 as prototyped, it consults @kbd{set coerce-float-to-double}.
27390
27391 @table @code
27392 @kindex set coerce-float-to-double
27393 @item set coerce-float-to-double
27394 @itemx set coerce-float-to-double on
27395 Arguments of type @code{float} will be promoted to @code{double} when passed
27396 to an unprototyped function. This is the default setting.
27397
27398 @item set coerce-float-to-double off
27399 Arguments of type @code{float} will be passed directly to unprototyped
27400 functions.
27401
27402 @kindex show coerce-float-to-double
27403 @item show coerce-float-to-double
27404 Show the current setting of promoting @code{float} to @code{double}.
27405 @end table
27406
27407 @kindex set cp-abi
27408 @kindex show cp-abi
27409 @value{GDBN} needs to know the ABI used for your program's C@t{++}
27410 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
27411 used to build your application. @value{GDBN} only fully supports
27412 programs with a single C@t{++} ABI; if your program contains code using
27413 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
27414 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
27415 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
27416 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
27417 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
27418 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
27419 ``auto''.
27420
27421 @table @code
27422 @item show cp-abi
27423 Show the C@t{++} ABI currently in use.
27424
27425 @item set cp-abi
27426 With no argument, show the list of supported C@t{++} ABI's.
27427
27428 @item set cp-abi @var{abi}
27429 @itemx set cp-abi auto
27430 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
27431 @end table
27432
27433 @node Auto-loading
27434 @section Automatically loading associated files
27435 @cindex auto-loading
27436
27437 @value{GDBN} sometimes reads files with commands and settings automatically,
27438 without being explicitly told so by the user. We call this feature
27439 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
27440 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
27441 results or introduce security risks (e.g., if the file comes from untrusted
27442 sources).
27443
27444 There are various kinds of files @value{GDBN} can automatically load.
27445 In addition to these files, @value{GDBN} supports auto-loading code written
27446 in various extension languages. @xref{Auto-loading extensions}.
27447
27448 Note that loading of these associated files (including the local @file{.gdbinit}
27449 file) requires accordingly configured @code{auto-load safe-path}
27450 (@pxref{Auto-loading safe path}).
27451
27452 For these reasons, @value{GDBN} includes commands and options to let you
27453 control when to auto-load files and which files should be auto-loaded.
27454
27455 @table @code
27456 @anchor{set auto-load off}
27457 @kindex set auto-load off
27458 @item set auto-load off
27459 Globally disable loading of all auto-loaded files.
27460 You may want to use this command with the @samp{-iex} option
27461 (@pxref{Option -init-eval-command}) such as:
27462 @smallexample
27463 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
27464 @end smallexample
27465
27466 Be aware that system init file (@pxref{System-wide configuration})
27467 and init files from your home directory (@pxref{Home Directory Init File})
27468 still get read (as they come from generally trusted directories).
27469 To prevent @value{GDBN} from auto-loading even those init files, use the
27470 @option{-nx} option (@pxref{Mode Options}), in addition to
27471 @code{set auto-load no}.
27472
27473 @anchor{show auto-load}
27474 @kindex show auto-load
27475 @item show auto-load
27476 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
27477 or disabled.
27478
27479 @smallexample
27480 (@value{GDBP}) show auto-load
27481 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
27482 libthread-db: Auto-loading of inferior specific libthread_db is on.
27483 local-gdbinit: Auto-loading of .gdbinit script from current directory
27484 is on.
27485 python-scripts: Auto-loading of Python scripts is on.
27486 safe-path: List of directories from which it is safe to auto-load files
27487 is $debugdir:$datadir/auto-load.
27488 scripts-directory: List of directories from which to load auto-loaded scripts
27489 is $debugdir:$datadir/auto-load.
27490 @end smallexample
27491
27492 @anchor{info auto-load}
27493 @kindex info auto-load
27494 @item info auto-load
27495 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
27496 not.
27497
27498 @smallexample
27499 (@value{GDBP}) info auto-load
27500 gdb-scripts:
27501 Loaded Script
27502 Yes /home/user/gdb/gdb-gdb.gdb
27503 libthread-db: No auto-loaded libthread-db.
27504 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
27505 loaded.
27506 python-scripts:
27507 Loaded Script
27508 Yes /home/user/gdb/gdb-gdb.py
27509 @end smallexample
27510 @end table
27511
27512 These are @value{GDBN} control commands for the auto-loading:
27513
27514 @multitable @columnfractions .5 .5
27515 @item @xref{set auto-load off}.
27516 @tab Disable auto-loading globally.
27517 @item @xref{show auto-load}.
27518 @tab Show setting of all kinds of files.
27519 @item @xref{info auto-load}.
27520 @tab Show state of all kinds of files.
27521 @item @xref{set auto-load gdb-scripts}.
27522 @tab Control for @value{GDBN} command scripts.
27523 @item @xref{show auto-load gdb-scripts}.
27524 @tab Show setting of @value{GDBN} command scripts.
27525 @item @xref{info auto-load gdb-scripts}.
27526 @tab Show state of @value{GDBN} command scripts.
27527 @item @xref{set auto-load python-scripts}.
27528 @tab Control for @value{GDBN} Python scripts.
27529 @item @xref{show auto-load python-scripts}.
27530 @tab Show setting of @value{GDBN} Python scripts.
27531 @item @xref{info auto-load python-scripts}.
27532 @tab Show state of @value{GDBN} Python scripts.
27533 @item @xref{set auto-load guile-scripts}.
27534 @tab Control for @value{GDBN} Guile scripts.
27535 @item @xref{show auto-load guile-scripts}.
27536 @tab Show setting of @value{GDBN} Guile scripts.
27537 @item @xref{info auto-load guile-scripts}.
27538 @tab Show state of @value{GDBN} Guile scripts.
27539 @item @xref{set auto-load scripts-directory}.
27540 @tab Control for @value{GDBN} auto-loaded scripts location.
27541 @item @xref{show auto-load scripts-directory}.
27542 @tab Show @value{GDBN} auto-loaded scripts location.
27543 @item @xref{add-auto-load-scripts-directory}.
27544 @tab Add directory for auto-loaded scripts location list.
27545 @item @xref{set auto-load local-gdbinit}.
27546 @tab Control for init file in the current directory.
27547 @item @xref{show auto-load local-gdbinit}.
27548 @tab Show setting of init file in the current directory.
27549 @item @xref{info auto-load local-gdbinit}.
27550 @tab Show state of init file in the current directory.
27551 @item @xref{set auto-load libthread-db}.
27552 @tab Control for thread debugging library.
27553 @item @xref{show auto-load libthread-db}.
27554 @tab Show setting of thread debugging library.
27555 @item @xref{info auto-load libthread-db}.
27556 @tab Show state of thread debugging library.
27557 @item @xref{set auto-load safe-path}.
27558 @tab Control directories trusted for automatic loading.
27559 @item @xref{show auto-load safe-path}.
27560 @tab Show directories trusted for automatic loading.
27561 @item @xref{add-auto-load-safe-path}.
27562 @tab Add directory trusted for automatic loading.
27563 @end multitable
27564
27565 @menu
27566 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
27567 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
27568
27569 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
27570 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
27571 @end menu
27572
27573 @node Init File in the Current Directory
27574 @subsection Automatically loading init file in the current directory
27575 @cindex auto-loading init file in the current directory
27576
27577 By default, @value{GDBN} reads and executes the canned sequences of commands
27578 from init file (if any) in the current working directory,
27579 see @ref{Init File in the Current Directory during Startup}.
27580
27581 Note that loading of this local @file{.gdbinit} file also requires accordingly
27582 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27583
27584 @table @code
27585 @anchor{set auto-load local-gdbinit}
27586 @kindex set auto-load local-gdbinit
27587 @item set auto-load local-gdbinit [on|off]
27588 Enable or disable the auto-loading of canned sequences of commands
27589 (@pxref{Sequences}) found in init file in the current directory.
27590
27591 @anchor{show auto-load local-gdbinit}
27592 @kindex show auto-load local-gdbinit
27593 @item show auto-load local-gdbinit
27594 Show whether auto-loading of canned sequences of commands from init file in the
27595 current directory is enabled or disabled.
27596
27597 @anchor{info auto-load local-gdbinit}
27598 @kindex info auto-load local-gdbinit
27599 @item info auto-load local-gdbinit
27600 Print whether canned sequences of commands from init file in the
27601 current directory have been auto-loaded.
27602 @end table
27603
27604 @node libthread_db.so.1 file
27605 @subsection Automatically loading thread debugging library
27606 @cindex auto-loading libthread_db.so.1
27607
27608 This feature is currently present only on @sc{gnu}/Linux native hosts.
27609
27610 @value{GDBN} reads in some cases thread debugging library from places specific
27611 to the inferior (@pxref{set libthread-db-search-path}).
27612
27613 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
27614 without checking this @samp{set auto-load libthread-db} switch as system
27615 libraries have to be trusted in general. In all other cases of
27616 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
27617 auto-load libthread-db} is enabled before trying to open such thread debugging
27618 library.
27619
27620 Note that loading of this debugging library also requires accordingly configured
27621 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27622
27623 @table @code
27624 @anchor{set auto-load libthread-db}
27625 @kindex set auto-load libthread-db
27626 @item set auto-load libthread-db [on|off]
27627 Enable or disable the auto-loading of inferior specific thread debugging library.
27628
27629 @anchor{show auto-load libthread-db}
27630 @kindex show auto-load libthread-db
27631 @item show auto-load libthread-db
27632 Show whether auto-loading of inferior specific thread debugging library is
27633 enabled or disabled.
27634
27635 @anchor{info auto-load libthread-db}
27636 @kindex info auto-load libthread-db
27637 @item info auto-load libthread-db
27638 Print the list of all loaded inferior specific thread debugging libraries and
27639 for each such library print list of inferior @var{pid}s using it.
27640 @end table
27641
27642 @node Auto-loading safe path
27643 @subsection Security restriction for auto-loading
27644 @cindex auto-loading safe-path
27645
27646 As the files of inferior can come from untrusted source (such as submitted by
27647 an application user) @value{GDBN} does not always load any files automatically.
27648 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
27649 directories trusted for loading files not explicitly requested by user.
27650 Each directory can also be a shell wildcard pattern.
27651
27652 If the path is not set properly you will see a warning and the file will not
27653 get loaded:
27654
27655 @smallexample
27656 $ ./gdb -q ./gdb
27657 Reading symbols from /home/user/gdb/gdb...
27658 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
27659 declined by your `auto-load safe-path' set
27660 to "$debugdir:$datadir/auto-load".
27661 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
27662 declined by your `auto-load safe-path' set
27663 to "$debugdir:$datadir/auto-load".
27664 @end smallexample
27665
27666 @noindent
27667 To instruct @value{GDBN} to go ahead and use the init files anyway,
27668 invoke @value{GDBN} like this:
27669
27670 @smallexample
27671 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
27672 @end smallexample
27673
27674 The list of trusted directories is controlled by the following commands:
27675
27676 @table @code
27677 @anchor{set auto-load safe-path}
27678 @kindex set auto-load safe-path
27679 @item set auto-load safe-path @r{[}@var{directories}@r{]}
27680 Set the list of directories (and their subdirectories) trusted for automatic
27681 loading and execution of scripts. You can also enter a specific trusted file.
27682 Each directory can also be a shell wildcard pattern; wildcards do not match
27683 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
27684 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
27685 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
27686 its default value as specified during @value{GDBN} compilation.
27687
27688 The list of directories uses path separator (@samp{:} on GNU and Unix
27689 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27690 to the @env{PATH} environment variable.
27691
27692 @anchor{show auto-load safe-path}
27693 @kindex show auto-load safe-path
27694 @item show auto-load safe-path
27695 Show the list of directories trusted for automatic loading and execution of
27696 scripts.
27697
27698 @anchor{add-auto-load-safe-path}
27699 @kindex add-auto-load-safe-path
27700 @item add-auto-load-safe-path
27701 Add an entry (or list of entries) to the list of directories trusted for
27702 automatic loading and execution of scripts. Multiple entries may be delimited
27703 by the host platform path separator in use.
27704 @end table
27705
27706 This variable defaults to what @code{--with-auto-load-dir} has been configured
27707 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
27708 substitution applies the same as for @ref{set auto-load scripts-directory}.
27709 The default @code{set auto-load safe-path} value can be also overriden by
27710 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
27711
27712 Setting this variable to @file{/} disables this security protection,
27713 corresponding @value{GDBN} configuration option is
27714 @option{--without-auto-load-safe-path}.
27715 This variable is supposed to be set to the system directories writable by the
27716 system superuser only. Users can add their source directories in init files in
27717 their home directories (@pxref{Home Directory Init File}). See also deprecated
27718 init file in the current directory
27719 (@pxref{Init File in the Current Directory during Startup}).
27720
27721 To force @value{GDBN} to load the files it declined to load in the previous
27722 example, you could use one of the following ways:
27723
27724 @table @asis
27725 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
27726 Specify this trusted directory (or a file) as additional component of the list.
27727 You have to specify also any existing directories displayed by
27728 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
27729
27730 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
27731 Specify this directory as in the previous case but just for a single
27732 @value{GDBN} session.
27733
27734 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
27735 Disable auto-loading safety for a single @value{GDBN} session.
27736 This assumes all the files you debug during this @value{GDBN} session will come
27737 from trusted sources.
27738
27739 @item @kbd{./configure --without-auto-load-safe-path}
27740 During compilation of @value{GDBN} you may disable any auto-loading safety.
27741 This assumes all the files you will ever debug with this @value{GDBN} come from
27742 trusted sources.
27743 @end table
27744
27745 On the other hand you can also explicitly forbid automatic files loading which
27746 also suppresses any such warning messages:
27747
27748 @table @asis
27749 @item @kbd{gdb -iex "set auto-load no" @dots{}}
27750 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
27751
27752 @item @file{~/.gdbinit}: @samp{set auto-load no}
27753 Disable auto-loading globally for the user
27754 (@pxref{Home Directory Init File}). While it is improbable, you could also
27755 use system init file instead (@pxref{System-wide configuration}).
27756 @end table
27757
27758 This setting applies to the file names as entered by user. If no entry matches
27759 @value{GDBN} tries as a last resort to also resolve all the file names into
27760 their canonical form (typically resolving symbolic links) and compare the
27761 entries again. @value{GDBN} already canonicalizes most of the filenames on its
27762 own before starting the comparison so a canonical form of directories is
27763 recommended to be entered.
27764
27765 @node Auto-loading verbose mode
27766 @subsection Displaying files tried for auto-load
27767 @cindex auto-loading verbose mode
27768
27769 For better visibility of all the file locations where you can place scripts to
27770 be auto-loaded with inferior --- or to protect yourself against accidental
27771 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
27772 all the files attempted to be loaded. Both existing and non-existing files may
27773 be printed.
27774
27775 For example the list of directories from which it is safe to auto-load files
27776 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
27777 may not be too obvious while setting it up.
27778
27779 @smallexample
27780 (@value{GDBP}) set debug auto-load on
27781 (@value{GDBP}) file ~/src/t/true
27782 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
27783 for objfile "/tmp/true".
27784 auto-load: Updating directories of "/usr:/opt".
27785 auto-load: Using directory "/usr".
27786 auto-load: Using directory "/opt".
27787 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
27788 by your `auto-load safe-path' set to "/usr:/opt".
27789 @end smallexample
27790
27791 @table @code
27792 @anchor{set debug auto-load}
27793 @kindex set debug auto-load
27794 @item set debug auto-load [on|off]
27795 Set whether to print the filenames attempted to be auto-loaded.
27796
27797 @anchor{show debug auto-load}
27798 @kindex show debug auto-load
27799 @item show debug auto-load
27800 Show whether printing of the filenames attempted to be auto-loaded is turned
27801 on or off.
27802 @end table
27803
27804 @node Messages/Warnings
27805 @section Optional Warnings and Messages
27806
27807 @cindex verbose operation
27808 @cindex optional warnings
27809 By default, @value{GDBN} is silent about its inner workings. If you are
27810 running on a slow machine, you may want to use the @code{set verbose}
27811 command. This makes @value{GDBN} tell you when it does a lengthy
27812 internal operation, so you will not think it has crashed.
27813
27814 Currently, the messages controlled by @code{set verbose} are those
27815 which announce that the symbol table for a source file is being read;
27816 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
27817
27818 @table @code
27819 @kindex set verbose
27820 @item set verbose on
27821 Enables @value{GDBN} output of certain informational messages.
27822
27823 @item set verbose off
27824 Disables @value{GDBN} output of certain informational messages.
27825
27826 @kindex show verbose
27827 @item show verbose
27828 Displays whether @code{set verbose} is on or off.
27829 @end table
27830
27831 By default, if @value{GDBN} encounters bugs in the symbol table of an
27832 object file, it is silent; but if you are debugging a compiler, you may
27833 find this information useful (@pxref{Symbol Errors, ,Errors Reading
27834 Symbol Files}).
27835
27836 @table @code
27837
27838 @kindex set complaints
27839 @item set complaints @var{limit}
27840 Permits @value{GDBN} to output @var{limit} complaints about each type of
27841 unusual symbols before becoming silent about the problem. Set
27842 @var{limit} to zero to suppress all complaints; set it to a large number
27843 to prevent complaints from being suppressed.
27844
27845 @kindex show complaints
27846 @item show complaints
27847 Displays how many symbol complaints @value{GDBN} is permitted to produce.
27848
27849 @end table
27850
27851 @anchor{confirmation requests}
27852 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
27853 lot of stupid questions to confirm certain commands. For example, if
27854 you try to run a program which is already running:
27855
27856 @smallexample
27857 (@value{GDBP}) run
27858 The program being debugged has been started already.
27859 Start it from the beginning? (y or n)
27860 @end smallexample
27861
27862 If you are willing to unflinchingly face the consequences of your own
27863 commands, you can disable this ``feature'':
27864
27865 @table @code
27866
27867 @kindex set confirm
27868 @cindex flinching
27869 @cindex confirmation
27870 @cindex stupid questions
27871 @item set confirm off
27872 Disables confirmation requests. Note that running @value{GDBN} with
27873 the @option{--batch} option (@pxref{Mode Options, -batch}) also
27874 automatically disables confirmation requests.
27875
27876 @item set confirm on
27877 Enables confirmation requests (the default).
27878
27879 @kindex show confirm
27880 @item show confirm
27881 Displays state of confirmation requests.
27882
27883 @end table
27884
27885 @cindex command tracing
27886 If you need to debug user-defined commands or sourced files you may find it
27887 useful to enable @dfn{command tracing}. In this mode each command will be
27888 printed as it is executed, prefixed with one or more @samp{+} symbols, the
27889 quantity denoting the call depth of each command.
27890
27891 @table @code
27892 @kindex set trace-commands
27893 @cindex command scripts, debugging
27894 @item set trace-commands on
27895 Enable command tracing.
27896 @item set trace-commands off
27897 Disable command tracing.
27898 @item show trace-commands
27899 Display the current state of command tracing.
27900 @end table
27901
27902 @node Debugging Output
27903 @section Optional Messages about Internal Happenings
27904 @cindex optional debugging messages
27905
27906 @value{GDBN} has commands that enable optional debugging messages from
27907 various @value{GDBN} subsystems; normally these commands are of
27908 interest to @value{GDBN} maintainers, or when reporting a bug. This
27909 section documents those commands.
27910
27911 @table @code
27912 @kindex set exec-done-display
27913 @item set exec-done-display
27914 Turns on or off the notification of asynchronous commands'
27915 completion. When on, @value{GDBN} will print a message when an
27916 asynchronous command finishes its execution. The default is off.
27917 @kindex show exec-done-display
27918 @item show exec-done-display
27919 Displays the current setting of asynchronous command completion
27920 notification.
27921
27922 @kindex set debug
27923 @cindex ARM AArch64
27924 @item set debug aarch64
27925 Turns on or off display of debugging messages related to ARM AArch64.
27926 The default is off.
27927 @kindex show debug
27928 @item show debug aarch64
27929 Displays the current state of displaying debugging messages related to
27930 ARM AArch64.
27931
27932 @cindex gdbarch debugging info
27933 @cindex architecture debugging info
27934 @item set debug arch
27935 Turns on or off display of gdbarch debugging info. The default is off
27936 @item show debug arch
27937 Displays the current state of displaying gdbarch debugging info.
27938
27939 @item set debug aix-thread
27940 @cindex AIX threads
27941 Display debugging messages about inner workings of the AIX thread
27942 module.
27943 @item show debug aix-thread
27944 Show the current state of AIX thread debugging info display.
27945
27946 @cindex AMD GPU debugging info
27947 @anchor{set debug amd-dbgapi-lib}
27948 @item set debug amd-dbgapi-lib
27949 @itemx show debug amd-dbgapi-lib
27950
27951 The @code{set debug amd-dbgapi-lib log-level @var{level}} command can be used
27952 to enable diagnostic messages from the @samp{amd-dbgapi} library, where
27953 @var{level} can be:
27954
27955 @table @code
27956
27957 @item off
27958 no logging is enabled
27959
27960 @item error
27961 fatal errors are reported
27962
27963 @item warning
27964 fatal errors and warnings are reported
27965
27966 @item info
27967 fatal errors, warnings, and info messages are reported
27968
27969 @item verbose
27970 all messages are reported
27971
27972 @end table
27973
27974 The @code{show debug amd-dbgapi-lib log-level} command displays the current
27975 @acronym{amd-dbgapi} library log level.
27976
27977 @anchor{set debug amd-dbgapi}
27978 @item set debug amd-dbgapi
27979 @itemx show debug amd-dbgapi
27980
27981 The @samp{set debug amd-dbgapi} command can be used
27982 to enable diagnostic messages in the @samp{amd-dbgapi} target. The
27983 @samp{show debug amd-dbgapi} command displays the current setting.
27984 @xref{set debug amd-dbgapi}.
27985
27986 @item set debug check-physname
27987 @cindex physname
27988 Check the results of the ``physname'' computation. When reading DWARF
27989 debugging information for C@t{++}, @value{GDBN} attempts to compute
27990 each entity's name. @value{GDBN} can do this computation in two
27991 different ways, depending on exactly what information is present.
27992 When enabled, this setting causes @value{GDBN} to compute the names
27993 both ways and display any discrepancies.
27994 @item show debug check-physname
27995 Show the current state of ``physname'' checking.
27996
27997 @item set debug coff-pe-read
27998 @cindex COFF/PE exported symbols
27999 Control display of debugging messages related to reading of COFF/PE
28000 exported symbols. The default is off.
28001 @item show debug coff-pe-read
28002 Displays the current state of displaying debugging messages related to
28003 reading of COFF/PE exported symbols.
28004
28005 @item set debug dwarf-die
28006 @cindex DWARF DIEs
28007 Dump DWARF DIEs after they are read in.
28008 The value is the number of nesting levels to print.
28009 A value of zero turns off the display.
28010 @item show debug dwarf-die
28011 Show the current state of DWARF DIE debugging.
28012
28013 @item set debug dwarf-line
28014 @cindex DWARF Line Tables
28015 Turns on or off display of debugging messages related to reading
28016 DWARF line tables. The default is 0 (off).
28017 A value of 1 provides basic information.
28018 A value greater than 1 provides more verbose information.
28019 @item show debug dwarf-line
28020 Show the current state of DWARF line table debugging.
28021
28022 @item set debug dwarf-read
28023 @cindex DWARF Reading
28024 Turns on or off display of debugging messages related to reading
28025 DWARF debug info. The default is 0 (off).
28026 A value of 1 provides basic information.
28027 A value greater than 1 provides more verbose information.
28028 @item show debug dwarf-read
28029 Show the current state of DWARF reader debugging.
28030
28031 @item set debug displaced
28032 @cindex displaced stepping debugging info
28033 Turns on or off display of @value{GDBN} debugging info for the
28034 displaced stepping support. The default is off.
28035 @item show debug displaced
28036 Displays the current state of displaying @value{GDBN} debugging info
28037 related to displaced stepping.
28038
28039 @item set debug event
28040 @cindex event debugging info
28041 Turns on or off display of @value{GDBN} event debugging info. The
28042 default is off.
28043 @item show debug event
28044 Displays the current state of displaying @value{GDBN} event debugging
28045 info.
28046
28047 @item set debug event-loop
28048 @cindex event-loop debugging
28049 Controls output of debugging info about the event loop. The possible
28050 values are @samp{off}, @samp{all} (shows all debugging info) and
28051 @samp{all-except-ui} (shows all debugging info except those about
28052 UI-related events).
28053 @item show debug event-loop
28054 Shows the current state of displaying debugging info about the event
28055 loop.
28056
28057 @item set debug expression
28058 @cindex expression debugging info
28059 Turns on or off display of debugging info about @value{GDBN}
28060 expression parsing. The default is off.
28061 @item show debug expression
28062 Displays the current state of displaying debugging info about
28063 @value{GDBN} expression parsing.
28064
28065 @item set debug fbsd-lwp
28066 @cindex FreeBSD LWP debug messages
28067 Turns on or off debugging messages from the FreeBSD LWP debug support.
28068 @item show debug fbsd-lwp
28069 Show the current state of FreeBSD LWP debugging messages.
28070
28071 @item set debug fbsd-nat
28072 @cindex FreeBSD native target debug messages
28073 Turns on or off debugging messages from the FreeBSD native target.
28074 @item show debug fbsd-nat
28075 Show the current state of FreeBSD native target debugging messages.
28076
28077 @item set debug fortran-array-slicing
28078 @cindex fortran array slicing debugging info
28079 Turns on or off display of @value{GDBN} Fortran array slicing
28080 debugging info. The default is off.
28081
28082 @item show debug fortran-array-slicing
28083 Displays the current state of displaying @value{GDBN} Fortran array
28084 slicing debugging info.
28085
28086 @item set debug frame
28087 @cindex frame debugging info
28088 Turns on or off display of @value{GDBN} frame debugging info. The
28089 default is off.
28090 @item show debug frame
28091 Displays the current state of displaying @value{GDBN} frame debugging
28092 info.
28093
28094 @item set debug gnu-nat
28095 @cindex @sc{gnu}/Hurd debug messages
28096 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
28097 @item show debug gnu-nat
28098 Show the current state of @sc{gnu}/Hurd debugging messages.
28099
28100 @item set debug infrun
28101 @cindex inferior debugging info
28102 Turns on or off display of @value{GDBN} debugging info for running the inferior.
28103 The default is off. @file{infrun.c} contains GDB's runtime state machine used
28104 for implementing operations such as single-stepping the inferior.
28105 @item show debug infrun
28106 Displays the current state of @value{GDBN} inferior debugging.
28107
28108 @item set debug infcall
28109 @cindex inferior function call debugging info
28110 Turns on or off display of debugging info related to inferior function
28111 calls made by @value{GDBN}.
28112 @item show debug infcall
28113 Displays the current state of @value{GDBN} inferior function call debugging.
28114
28115 @item set debug jit
28116 @cindex just-in-time compilation, debugging messages
28117 Turn on or off debugging messages from JIT debug support.
28118 @item show debug jit
28119 Displays the current state of @value{GDBN} JIT debugging.
28120
28121 @item set debug linux-nat @r{[}on@r{|}off@r{]}
28122 @cindex @sc{gnu}/Linux native target debug messages
28123 @cindex Linux native targets
28124 Turn on or off debugging messages from the Linux native target debug support.
28125 @item show debug linux-nat
28126 Show the current state of Linux native target debugging messages.
28127
28128 @item set debug linux-namespaces
28129 @cindex @sc{gnu}/Linux namespaces debug messages
28130 Turn on or off debugging messages from the Linux namespaces debug support.
28131 @item show debug linux-namespaces
28132 Show the current state of Linux namespaces debugging messages.
28133
28134 @item set debug mach-o
28135 @cindex Mach-O symbols processing
28136 Control display of debugging messages related to Mach-O symbols
28137 processing. The default is off.
28138 @item show debug mach-o
28139 Displays the current state of displaying debugging messages related to
28140 reading of COFF/PE exported symbols.
28141
28142 @item set debug notification
28143 @cindex remote async notification debugging info
28144 Turn on or off debugging messages about remote async notification.
28145 The default is off.
28146 @item show debug notification
28147 Displays the current state of remote async notification debugging messages.
28148
28149 @item set debug observer
28150 @cindex observer debugging info
28151 Turns on or off display of @value{GDBN} observer debugging. This
28152 includes info such as the notification of observable events.
28153 @item show debug observer
28154 Displays the current state of observer debugging.
28155
28156 @item set debug overload
28157 @cindex C@t{++} overload debugging info
28158 Turns on or off display of @value{GDBN} C@t{++} overload debugging
28159 info. This includes info such as ranking of functions, etc. The default
28160 is off.
28161 @item show debug overload
28162 Displays the current state of displaying @value{GDBN} C@t{++} overload
28163 debugging info.
28164
28165 @cindex expression parser, debugging info
28166 @cindex debug expression parser
28167 @item set debug parser
28168 Turns on or off the display of expression parser debugging output.
28169 Internally, this sets the @code{yydebug} variable in the expression
28170 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
28171 details. The default is off.
28172 @item show debug parser
28173 Show the current state of expression parser debugging.
28174
28175 @cindex packets, reporting on stdout
28176 @cindex serial connections, debugging
28177 @cindex debug remote protocol
28178 @cindex remote protocol debugging
28179 @cindex display remote packets
28180 @item set debug remote
28181 Turns on or off display of reports on all packets sent back and forth across
28182 the serial line to the remote machine. The info is printed on the
28183 @value{GDBN} standard output stream. The default is off.
28184 @item show debug remote
28185 Displays the state of display of remote packets.
28186
28187 @item set debug remote-packet-max-chars
28188 Sets the maximum number of characters to display for each remote packet when
28189 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
28190 displaying lengthy remote packets and polluting the console.
28191
28192 The default value is @code{512}, which means @value{GDBN} will truncate each
28193 remote packet after 512 bytes.
28194
28195 Setting this option to @code{unlimited} will disable truncation and will output
28196 the full length of the remote packets.
28197 @item show debug remote-packet-max-chars
28198 Displays the number of bytes to output for remote packet debugging.
28199
28200 @item set debug separate-debug-file
28201 Turns on or off display of debug output about separate debug file search.
28202 @item show debug separate-debug-file
28203 Displays the state of separate debug file search debug output.
28204
28205 @item set debug serial
28206 Turns on or off display of @value{GDBN} serial debugging info. The
28207 default is off.
28208 @item show debug serial
28209 Displays the current state of displaying @value{GDBN} serial debugging
28210 info.
28211
28212 @item set debug solib
28213 Turns on or off display of debugging messages related to shared libraries.
28214 The default is off.
28215 @item show debug solib
28216 Show the current state of solib debugging messages.
28217
28218 @item set debug symbol-lookup
28219 @cindex symbol lookup
28220 Turns on or off display of debugging messages related to symbol lookup.
28221 The default is 0 (off).
28222 A value of 1 provides basic information.
28223 A value greater than 1 provides more verbose information.
28224 @item show debug symbol-lookup
28225 Show the current state of symbol lookup debugging messages.
28226
28227 @item set debug symfile
28228 @cindex symbol file functions
28229 Turns on or off display of debugging messages related to symbol file functions.
28230 The default is off. @xref{Files}.
28231 @item show debug symfile
28232 Show the current state of symbol file debugging messages.
28233
28234 @item set debug symtab-create
28235 @cindex symbol table creation
28236 Turns on or off display of debugging messages related to symbol table creation.
28237 The default is 0 (off).
28238 A value of 1 provides basic information.
28239 A value greater than 1 provides more verbose information.
28240 @item show debug symtab-create
28241 Show the current state of symbol table creation debugging.
28242
28243 @item set debug target
28244 @cindex target debugging info
28245 Turns on or off display of @value{GDBN} target debugging info. This info
28246 includes what is going on at the target level of GDB, as it happens. The
28247 default is 0. Set it to 1 to track events, and to 2 to also track the
28248 value of large memory transfers.
28249 @item show debug target
28250 Displays the current state of displaying @value{GDBN} target debugging
28251 info.
28252
28253 @item set debug timestamp
28254 @cindex timestamping debugging info
28255 Turns on or off display of timestamps with @value{GDBN} debugging info.
28256 When enabled, seconds and microseconds are displayed before each debugging
28257 message.
28258 @item show debug timestamp
28259 Displays the current state of displaying timestamps with @value{GDBN}
28260 debugging info.
28261
28262 @item set debug varobj
28263 @cindex variable object debugging info
28264 Turns on or off display of @value{GDBN} variable object debugging
28265 info. The default is off.
28266 @item show debug varobj
28267 Displays the current state of displaying @value{GDBN} variable object
28268 debugging info.
28269
28270 @item set debug xml
28271 @cindex XML parser debugging
28272 Turn on or off debugging messages for built-in XML parsers.
28273 @item show debug xml
28274 Displays the current state of XML debugging messages.
28275 @end table
28276
28277 @node Other Misc Settings
28278 @section Other Miscellaneous Settings
28279 @cindex miscellaneous settings
28280
28281 @table @code
28282 @kindex set interactive-mode
28283 @item set interactive-mode
28284 If @code{on}, forces @value{GDBN} to assume that GDB was started
28285 in a terminal. In practice, this means that @value{GDBN} should wait
28286 for the user to answer queries generated by commands entered at
28287 the command prompt. If @code{off}, forces @value{GDBN} to operate
28288 in the opposite mode, and it uses the default answers to all queries.
28289 If @code{auto} (the default), @value{GDBN} tries to determine whether
28290 its standard input is a terminal, and works in interactive-mode if it
28291 is, non-interactively otherwise.
28292
28293 In the vast majority of cases, the debugger should be able to guess
28294 correctly which mode should be used. But this setting can be useful
28295 in certain specific cases, such as running a MinGW @value{GDBN}
28296 inside a cygwin window.
28297
28298 @kindex show interactive-mode
28299 @item show interactive-mode
28300 Displays whether the debugger is operating in interactive mode or not.
28301 @end table
28302
28303 @table @code
28304 @kindex set suppress-cli-notifications
28305 @item set suppress-cli-notifications
28306 If @code{on}, command-line-interface (CLI) notifications that are
28307 printed by @value{GDBN} are suppressed. If @code{off}, the
28308 notifications are printed as usual. The default value is @code{off}.
28309 CLI notifications occur when you change the selected context or when
28310 the program being debugged stops, as detailed below.
28311
28312 @table @emph
28313 @item User-selected context changes:
28314 When you change the selected context (i.e.@: the current inferior,
28315 thread and/or the frame), @value{GDBN} prints information about the
28316 new context. For example, the default behavior is below:
28317
28318 @smallexample
28319 (gdb) inferior 1
28320 [Switching to inferior 1 [process 634] (/tmp/test)]
28321 [Switching to thread 1 (process 634)]
28322 #0 main () at test.c:3
28323 3 return 0;
28324 (gdb)
28325 @end smallexample
28326
28327 When the notifications are suppressed, the new context is not printed:
28328
28329 @smallexample
28330 (gdb) set suppress-cli-notifications on
28331 (gdb) inferior 1
28332 (gdb)
28333 @end smallexample
28334
28335 @item The program being debugged stops:
28336 When the program you are debugging stops (e.g.@: because of hitting a
28337 breakpoint, completing source-stepping, an interrupt, etc.),
28338 @value{GDBN} prints information about the stop event. For example,
28339 below is a breakpoint hit:
28340
28341 @smallexample
28342 (gdb) break test.c:3
28343 Breakpoint 2 at 0x555555555155: file test.c, line 3.
28344 (gdb) continue
28345 Continuing.
28346
28347 Breakpoint 2, main () at test.c:3
28348 3 return 0;
28349 (gdb)
28350 @end smallexample
28351
28352 When the notifications are suppressed, the output becomes:
28353
28354 @smallexample
28355 (gdb) break test.c:3
28356 Breakpoint 2 at 0x555555555155: file test.c, line 3.
28357 (gdb) set suppress-cli-notifications on
28358 (gdb) continue
28359 Continuing.
28360 (gdb)
28361 @end smallexample
28362
28363 Suppressing CLI notifications may be useful in scripts to obtain a
28364 reduced output from a list of commands.
28365 @end table
28366
28367 @kindex show suppress-cli-notifications
28368 @item show suppress-cli-notifications
28369 Displays whether printing CLI notifications is suppressed or not.
28370 @end table
28371
28372 @node Extending GDB
28373 @chapter Extending @value{GDBN}
28374 @cindex extending GDB
28375
28376 @value{GDBN} provides several mechanisms for extension.
28377 @value{GDBN} also provides the ability to automatically load
28378 extensions when it reads a file for debugging. This allows the
28379 user to automatically customize @value{GDBN} for the program
28380 being debugged.
28381
28382 To facilitate the use of extension languages, @value{GDBN} is capable
28383 of evaluating the contents of a file. When doing so, @value{GDBN}
28384 can recognize which extension language is being used by looking at
28385 the filename extension. Files with an unrecognized filename extension
28386 are always treated as a @value{GDBN} Command Files.
28387 @xref{Command Files,, Command files}.
28388
28389 You can control how @value{GDBN} evaluates these files with the following
28390 setting:
28391
28392 @table @code
28393 @kindex set script-extension
28394 @kindex show script-extension
28395 @item set script-extension off
28396 All scripts are always evaluated as @value{GDBN} Command Files.
28397
28398 @item set script-extension soft
28399 The debugger determines the scripting language based on filename
28400 extension. If this scripting language is supported, @value{GDBN}
28401 evaluates the script using that language. Otherwise, it evaluates
28402 the file as a @value{GDBN} Command File.
28403
28404 @item set script-extension strict
28405 The debugger determines the scripting language based on filename
28406 extension, and evaluates the script using that language. If the
28407 language is not supported, then the evaluation fails.
28408
28409 @item show script-extension
28410 Display the current value of the @code{script-extension} option.
28411
28412 @end table
28413
28414 @ifset SYSTEM_GDBINIT_DIR
28415 This setting is not used for files in the system-wide gdbinit directory.
28416 Files in that directory must have an extension matching their language,
28417 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
28418 commands. @xref{Startup}.
28419 @end ifset
28420
28421 @menu
28422 * Sequences:: Canned Sequences of @value{GDBN} Commands
28423 * Aliases:: Command Aliases
28424 * Python:: Extending @value{GDBN} using Python
28425 * Guile:: Extending @value{GDBN} using Guile
28426 * Auto-loading extensions:: Automatically loading extensions
28427 * Multiple Extension Languages:: Working with multiple extension languages
28428 @end menu
28429
28430 @node Sequences
28431 @section Canned Sequences of Commands
28432
28433 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
28434 Command Lists}), @value{GDBN} provides two ways to store sequences of
28435 commands for execution as a unit: user-defined commands and command
28436 files.
28437
28438 @menu
28439 * Define:: How to define your own commands
28440 * Hooks:: Hooks for user-defined commands
28441 * Command Files:: How to write scripts of commands to be stored in a file
28442 * Output:: Commands for controlled output
28443 * Auto-loading sequences:: Controlling auto-loaded command files
28444 @end menu
28445
28446 @node Define
28447 @subsection User-defined Commands
28448
28449 @cindex user-defined command
28450 @cindex arguments, to user-defined commands
28451 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
28452 which you assign a new name as a command. This is done with the
28453 @code{define} command. User commands may accept an unlimited number of arguments
28454 separated by whitespace. Arguments are accessed within the user command
28455 via @code{$arg0@dots{}$argN}. A trivial example:
28456
28457 @smallexample
28458 define adder
28459 print $arg0 + $arg1 + $arg2
28460 end
28461 @end smallexample
28462
28463 @noindent
28464 To execute the command use:
28465
28466 @smallexample
28467 adder 1 2 3
28468 @end smallexample
28469
28470 @noindent
28471 This defines the command @code{adder}, which prints the sum of
28472 its three arguments. Note the arguments are text substitutions, so they may
28473 reference variables, use complex expressions, or even perform inferior
28474 functions calls.
28475
28476 @cindex argument count in user-defined commands
28477 @cindex how many arguments (user-defined commands)
28478 In addition, @code{$argc} may be used to find out how many arguments have
28479 been passed.
28480
28481 @smallexample
28482 define adder
28483 if $argc == 2
28484 print $arg0 + $arg1
28485 end
28486 if $argc == 3
28487 print $arg0 + $arg1 + $arg2
28488 end
28489 end
28490 @end smallexample
28491
28492 Combining with the @code{eval} command (@pxref{eval}) makes it easier
28493 to process a variable number of arguments:
28494
28495 @smallexample
28496 define adder
28497 set $i = 0
28498 set $sum = 0
28499 while $i < $argc
28500 eval "set $sum = $sum + $arg%d", $i
28501 set $i = $i + 1
28502 end
28503 print $sum
28504 end
28505 @end smallexample
28506
28507 @table @code
28508
28509 @kindex define
28510 @item define @var{commandname}
28511 Define a command named @var{commandname}. If there is already a command
28512 by that name, you are asked to confirm that you want to redefine it.
28513 The argument @var{commandname} may be a bare command name consisting of letters,
28514 numbers, dashes, dots, and underscores. It may also start with any
28515 predefined or user-defined prefix command.
28516 For example, @samp{define target my-target} creates
28517 a user-defined @samp{target my-target} command.
28518
28519 The definition of the command is made up of other @value{GDBN} command lines,
28520 which are given following the @code{define} command. The end of these
28521 commands is marked by a line containing @code{end}.
28522
28523 @kindex document
28524 @kindex end@r{ (user-defined commands)}
28525 @item document @var{commandname}
28526 Document the user-defined command @var{commandname}, so that it can be
28527 accessed by @code{help}. The command @var{commandname} must already be
28528 defined. This command reads lines of documentation just as @code{define}
28529 reads the lines of the command definition, ending with @code{end}.
28530 After the @code{document} command is finished, @code{help} on command
28531 @var{commandname} displays the documentation you have written.
28532
28533 You may use the @code{document} command again to change the
28534 documentation of a command. Redefining the command with @code{define}
28535 does not change the documentation.
28536
28537 It is also possible to document user-defined aliases. The alias documentation
28538 will then be used by the @code{help} and @code{apropos} commands
28539 instead of the documentation of the aliased command.
28540 Documenting a user-defined alias is particularly useful when defining
28541 an alias as a set of nested @code{with} commands
28542 (@pxref{Command aliases default args}).
28543
28544 @kindex define-prefix
28545 @item define-prefix @var{commandname}
28546 Define or mark the command @var{commandname} as a user-defined prefix
28547 command. Once marked, @var{commandname} can be used as prefix command
28548 by the @code{define} command.
28549 Note that @code{define-prefix} can be used with a not yet defined
28550 @var{commandname}. In such a case, @var{commandname} is defined as
28551 an empty user-defined command.
28552 In case you redefine a command that was marked as a user-defined
28553 prefix command, the subcommands of the redefined command are kept
28554 (and @value{GDBN} indicates so to the user).
28555
28556 Example:
28557 @example
28558 (@value{GDBP}) define-prefix abc
28559 (@value{GDBP}) define-prefix abc def
28560 (@value{GDBP}) define abc def
28561 Type commands for definition of "abc def".
28562 End with a line saying just "end".
28563 >echo command initial def\n
28564 >end
28565 (@value{GDBP}) define abc def ghi
28566 Type commands for definition of "abc def ghi".
28567 End with a line saying just "end".
28568 >echo command ghi\n
28569 >end
28570 (@value{GDBP}) define abc def
28571 Keeping subcommands of prefix command "def".
28572 Redefine command "def"? (y or n) y
28573 Type commands for definition of "abc def".
28574 End with a line saying just "end".
28575 >echo command def\n
28576 >end
28577 (@value{GDBP}) abc def ghi
28578 command ghi
28579 (@value{GDBP}) abc def
28580 command def
28581 (@value{GDBP})
28582 @end example
28583
28584 @kindex dont-repeat
28585 @cindex don't repeat command
28586 @item dont-repeat
28587 Used inside a user-defined command, this tells @value{GDBN} that this
28588 command should not be repeated when the user hits @key{RET}
28589 (@pxref{Command Syntax, repeat last command}).
28590
28591 @kindex help user-defined
28592 @item help user-defined
28593 List all user-defined commands and all python commands defined in class
28594 COMMAND_USER. The first line of the documentation or docstring is
28595 included (if any).
28596
28597 @kindex show user
28598 @item show user
28599 @itemx show user @var{commandname}
28600 Display the @value{GDBN} commands used to define @var{commandname} (but
28601 not its documentation). If no @var{commandname} is given, display the
28602 definitions for all user-defined commands.
28603 This does not work for user-defined python commands.
28604
28605 @cindex infinite recursion in user-defined commands
28606 @kindex show max-user-call-depth
28607 @kindex set max-user-call-depth
28608 @item show max-user-call-depth
28609 @itemx set max-user-call-depth
28610 The value of @code{max-user-call-depth} controls how many recursion
28611 levels are allowed in user-defined commands before @value{GDBN} suspects an
28612 infinite recursion and aborts the command.
28613 This does not apply to user-defined python commands.
28614 @end table
28615
28616 In addition to the above commands, user-defined commands frequently
28617 use control flow commands, described in @ref{Command Files}.
28618
28619 When user-defined commands are executed, the
28620 commands of the definition are not printed. An error in any command
28621 stops execution of the user-defined command.
28622
28623 If used interactively, commands that would ask for confirmation proceed
28624 without asking when used inside a user-defined command. Many @value{GDBN}
28625 commands that normally print messages to say what they are doing omit the
28626 messages when used in a user-defined command.
28627
28628 @node Hooks
28629 @subsection User-defined Command Hooks
28630 @cindex command hooks
28631 @cindex hooks, for commands
28632 @cindex hooks, pre-command
28633
28634 @kindex hook
28635 You may define @dfn{hooks}, which are a special kind of user-defined
28636 command. Whenever you run the command @samp{foo}, if the user-defined
28637 command @samp{hook-foo} exists, it is executed (with no arguments)
28638 before that command.
28639
28640 @cindex hooks, post-command
28641 @kindex hookpost
28642 A hook may also be defined which is run after the command you executed.
28643 Whenever you run the command @samp{foo}, if the user-defined command
28644 @samp{hookpost-foo} exists, it is executed (with no arguments) after
28645 that command. Post-execution hooks may exist simultaneously with
28646 pre-execution hooks, for the same command.
28647
28648 It is valid for a hook to call the command which it hooks. If this
28649 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
28650
28651 @c It would be nice if hookpost could be passed a parameter indicating
28652 @c if the command it hooks executed properly or not. FIXME!
28653
28654 @kindex stop@r{, a pseudo-command}
28655 In addition, a pseudo-command, @samp{stop} exists. Defining
28656 (@samp{hook-stop}) makes the associated commands execute every time
28657 execution stops in your program: before breakpoint commands are run,
28658 displays are printed, or the stack frame is printed.
28659
28660 For example, to ignore @code{SIGALRM} signals while
28661 single-stepping, but treat them normally during normal execution,
28662 you could define:
28663
28664 @smallexample
28665 define hook-stop
28666 handle SIGALRM nopass
28667 end
28668
28669 define hook-run
28670 handle SIGALRM pass
28671 end
28672
28673 define hook-continue
28674 handle SIGALRM pass
28675 end
28676 @end smallexample
28677
28678 As a further example, to hook at the beginning and end of the @code{echo}
28679 command, and to add extra text to the beginning and end of the message,
28680 you could define:
28681
28682 @smallexample
28683 define hook-echo
28684 echo <<<---
28685 end
28686
28687 define hookpost-echo
28688 echo --->>>\n
28689 end
28690
28691 (@value{GDBP}) echo Hello World
28692 <<<---Hello World--->>>
28693 (@value{GDBP})
28694
28695 @end smallexample
28696
28697 You can define a hook for any single-word command in @value{GDBN}, but
28698 not for command aliases; you should define a hook for the basic command
28699 name, e.g.@: @code{backtrace} rather than @code{bt}.
28700 @c FIXME! So how does Joe User discover whether a command is an alias
28701 @c or not?
28702 You can hook a multi-word command by adding @code{hook-} or
28703 @code{hookpost-} to the last word of the command, e.g.@:
28704 @samp{define target hook-remote} to add a hook to @samp{target remote}.
28705
28706 If an error occurs during the execution of your hook, execution of
28707 @value{GDBN} commands stops and @value{GDBN} issues a prompt
28708 (before the command that you actually typed had a chance to run).
28709
28710 If you try to define a hook which does not match any known command, you
28711 get a warning from the @code{define} command.
28712
28713 @node Command Files
28714 @subsection Command Files
28715
28716 @cindex command files
28717 @cindex scripting commands
28718 A command file for @value{GDBN} is a text file made of lines that are
28719 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
28720 also be included. An empty line in a command file does nothing; it
28721 does not mean to repeat the last command, as it would from the
28722 terminal.
28723
28724 You can request the execution of a command file with the @code{source}
28725 command. Note that the @code{source} command is also used to evaluate
28726 scripts that are not Command Files. The exact behavior can be configured
28727 using the @code{script-extension} setting.
28728 @xref{Extending GDB,, Extending GDB}.
28729
28730 @table @code
28731 @kindex source
28732 @cindex execute commands from a file
28733 @item source [-s] [-v] @var{filename}
28734 Execute the command file @var{filename}.
28735 @end table
28736
28737 The lines in a command file are generally executed sequentially,
28738 unless the order of execution is changed by one of the
28739 @emph{flow-control commands} described below. The commands are not
28740 printed as they are executed. An error in any command terminates
28741 execution of the command file and control is returned to the console.
28742
28743 @value{GDBN} first searches for @var{filename} in the current directory.
28744 If the file is not found there, and @var{filename} does not specify a
28745 directory, then @value{GDBN} also looks for the file on the source search path
28746 (specified with the @samp{directory} command);
28747 except that @file{$cdir} is not searched because the compilation directory
28748 is not relevant to scripts.
28749
28750 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
28751 on the search path even if @var{filename} specifies a directory.
28752 The search is done by appending @var{filename} to each element of the
28753 search path. So, for example, if @var{filename} is @file{mylib/myscript}
28754 and the search path contains @file{/home/user} then @value{GDBN} will
28755 look for the script @file{/home/user/mylib/myscript}.
28756 The search is also done if @var{filename} is an absolute path.
28757 For example, if @var{filename} is @file{/tmp/myscript} and
28758 the search path contains @file{/home/user} then @value{GDBN} will
28759 look for the script @file{/home/user/tmp/myscript}.
28760 For DOS-like systems, if @var{filename} contains a drive specification,
28761 it is stripped before concatenation. For example, if @var{filename} is
28762 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
28763 will look for the script @file{c:/tmp/myscript}.
28764
28765 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
28766 each command as it is executed. The option must be given before
28767 @var{filename}, and is interpreted as part of the filename anywhere else.
28768
28769 Commands that would ask for confirmation if used interactively proceed
28770 without asking when used in a command file. Many @value{GDBN} commands that
28771 normally print messages to say what they are doing omit the messages
28772 when called from command files.
28773
28774 @value{GDBN} also accepts command input from standard input. In this
28775 mode, normal output goes to standard output and error output goes to
28776 standard error. Errors in a command file supplied on standard input do
28777 not terminate execution of the command file---execution continues with
28778 the next command.
28779
28780 @smallexample
28781 gdb < cmds > log 2>&1
28782 @end smallexample
28783
28784 (The syntax above will vary depending on the shell used.) This example
28785 will execute commands from the file @file{cmds}. All output and errors
28786 would be directed to @file{log}.
28787
28788 Since commands stored on command files tend to be more general than
28789 commands typed interactively, they frequently need to deal with
28790 complicated situations, such as different or unexpected values of
28791 variables and symbols, changes in how the program being debugged is
28792 built, etc. @value{GDBN} provides a set of flow-control commands to
28793 deal with these complexities. Using these commands, you can write
28794 complex scripts that loop over data structures, execute commands
28795 conditionally, etc.
28796
28797 @table @code
28798 @kindex if
28799 @kindex else
28800 @item if
28801 @itemx else
28802 This command allows to include in your script conditionally executed
28803 commands. The @code{if} command takes a single argument, which is an
28804 expression to evaluate. It is followed by a series of commands that
28805 are executed only if the expression is true (its value is nonzero).
28806 There can then optionally be an @code{else} line, followed by a series
28807 of commands that are only executed if the expression was false. The
28808 end of the list is marked by a line containing @code{end}.
28809
28810 @kindex while
28811 @item while
28812 This command allows to write loops. Its syntax is similar to
28813 @code{if}: the command takes a single argument, which is an expression
28814 to evaluate, and must be followed by the commands to execute, one per
28815 line, terminated by an @code{end}. These commands are called the
28816 @dfn{body} of the loop. The commands in the body of @code{while} are
28817 executed repeatedly as long as the expression evaluates to true.
28818
28819 @kindex loop_break
28820 @item loop_break
28821 This command exits the @code{while} loop in whose body it is included.
28822 Execution of the script continues after that @code{while}s @code{end}
28823 line.
28824
28825 @kindex loop_continue
28826 @item loop_continue
28827 This command skips the execution of the rest of the body of commands
28828 in the @code{while} loop in whose body it is included. Execution
28829 branches to the beginning of the @code{while} loop, where it evaluates
28830 the controlling expression.
28831
28832 @kindex end@r{ (if/else/while commands)}
28833 @item end
28834 Terminate the block of commands that are the body of @code{if},
28835 @code{else}, or @code{while} flow-control commands.
28836 @end table
28837
28838
28839 @node Output
28840 @subsection Commands for Controlled Output
28841
28842 During the execution of a command file or a user-defined command, normal
28843 @value{GDBN} output is suppressed; the only output that appears is what is
28844 explicitly printed by the commands in the definition. This section
28845 describes three commands useful for generating exactly the output you
28846 want.
28847
28848 @table @code
28849 @kindex echo
28850 @item echo @var{text}
28851 @c I do not consider backslash-space a standard C escape sequence
28852 @c because it is not in ANSI.
28853 Print @var{text}. Nonprinting characters can be included in
28854 @var{text} using C escape sequences, such as @samp{\n} to print a
28855 newline. @strong{No newline is printed unless you specify one.}
28856 In addition to the standard C escape sequences, a backslash followed
28857 by a space stands for a space. This is useful for displaying a
28858 string with spaces at the beginning or the end, since leading and
28859 trailing spaces are otherwise trimmed from all arguments.
28860 To print @samp{@w{ }and foo =@w{ }}, use the command
28861 @samp{echo \@w{ }and foo = \@w{ }}.
28862
28863 A backslash at the end of @var{text} can be used, as in C, to continue
28864 the command onto subsequent lines. For example,
28865
28866 @smallexample
28867 echo This is some text\n\
28868 which is continued\n\
28869 onto several lines.\n
28870 @end smallexample
28871
28872 produces the same output as
28873
28874 @smallexample
28875 echo This is some text\n
28876 echo which is continued\n
28877 echo onto several lines.\n
28878 @end smallexample
28879
28880 @kindex output
28881 @item output @var{expression}
28882 Print the value of @var{expression} and nothing but that value: no
28883 newlines, no @samp{$@var{nn} = }. The value is not entered in the
28884 value history either. @xref{Expressions, ,Expressions}, for more information
28885 on expressions.
28886
28887 @item output/@var{fmt} @var{expression}
28888 Print the value of @var{expression} in format @var{fmt}. You can use
28889 the same formats as for @code{print}. @xref{Output Formats,,Output
28890 Formats}, for more information.
28891
28892 @kindex printf
28893 @item printf @var{template}, @var{expressions}@dots{}
28894 Print the values of one or more @var{expressions} under the control of
28895 the string @var{template}. To print several values, make
28896 @var{expressions} be a comma-separated list of individual expressions,
28897 which may be either numbers or pointers. Their values are printed as
28898 specified by @var{template}, exactly as a C program would do by
28899 executing the code below:
28900
28901 @smallexample
28902 printf (@var{template}, @var{expressions}@dots{});
28903 @end smallexample
28904
28905 As in @code{C} @code{printf}, ordinary characters in @var{template}
28906 are printed verbatim, while @dfn{conversion specification} introduced
28907 by the @samp{%} character cause subsequent @var{expressions} to be
28908 evaluated, their values converted and formatted according to type and
28909 style information encoded in the conversion specifications, and then
28910 printed.
28911
28912 For example, you can print two values in hex like this:
28913
28914 @smallexample
28915 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
28916 @end smallexample
28917
28918 @code{printf} supports all the standard @code{C} conversion
28919 specifications, including the flags and modifiers between the @samp{%}
28920 character and the conversion letter, with the following exceptions:
28921
28922 @itemize @bullet
28923 @item
28924 The argument-ordering modifiers, such as @samp{2$}, are not supported.
28925
28926 @item
28927 The modifier @samp{*} is not supported for specifying precision or
28928 width.
28929
28930 @item
28931 The @samp{'} flag (for separation of digits into groups according to
28932 @code{LC_NUMERIC'}) is not supported.
28933
28934 @item
28935 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
28936 supported.
28937
28938 @item
28939 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
28940
28941 @item
28942 The conversion letters @samp{a} and @samp{A} are not supported.
28943 @end itemize
28944
28945 @noindent
28946 Note that the @samp{ll} type modifier is supported only if the
28947 underlying @code{C} implementation used to build @value{GDBN} supports
28948 the @code{long long int} type, and the @samp{L} type modifier is
28949 supported only if @code{long double} type is available.
28950
28951 As in @code{C}, @code{printf} supports simple backslash-escape
28952 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
28953 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
28954 single character. Octal and hexadecimal escape sequences are not
28955 supported.
28956
28957 Additionally, @code{printf} supports conversion specifications for DFP
28958 (@dfn{Decimal Floating Point}) types using the following length modifiers
28959 together with a floating point specifier.
28960 letters:
28961
28962 @itemize @bullet
28963 @item
28964 @samp{H} for printing @code{Decimal32} types.
28965
28966 @item
28967 @samp{D} for printing @code{Decimal64} types.
28968
28969 @item
28970 @samp{DD} for printing @code{Decimal128} types.
28971 @end itemize
28972
28973 If the underlying @code{C} implementation used to build @value{GDBN} has
28974 support for the three length modifiers for DFP types, other modifiers
28975 such as width and precision will also be available for @value{GDBN} to use.
28976
28977 In case there is no such @code{C} support, no additional modifiers will be
28978 available and the value will be printed in the standard way.
28979
28980 Here's an example of printing DFP types using the above conversion letters:
28981 @smallexample
28982 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
28983 @end smallexample
28984
28985 @anchor{eval}
28986 @kindex eval
28987 @item eval @var{template}, @var{expressions}@dots{}
28988 Convert the values of one or more @var{expressions} under the control of
28989 the string @var{template} to a command line, and call it.
28990
28991 @end table
28992
28993 @node Auto-loading sequences
28994 @subsection Controlling auto-loading native @value{GDBN} scripts
28995 @cindex native script auto-loading
28996
28997 When a new object file is read (for example, due to the @code{file}
28998 command, or because the inferior has loaded a shared library),
28999 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
29000 @xref{Auto-loading extensions}.
29001
29002 Auto-loading can be enabled or disabled,
29003 and the list of auto-loaded scripts can be printed.
29004
29005 @table @code
29006 @anchor{set auto-load gdb-scripts}
29007 @kindex set auto-load gdb-scripts
29008 @item set auto-load gdb-scripts [on|off]
29009 Enable or disable the auto-loading of canned sequences of commands scripts.
29010
29011 @anchor{show auto-load gdb-scripts}
29012 @kindex show auto-load gdb-scripts
29013 @item show auto-load gdb-scripts
29014 Show whether auto-loading of canned sequences of commands scripts is enabled or
29015 disabled.
29016
29017 @anchor{info auto-load gdb-scripts}
29018 @kindex info auto-load gdb-scripts
29019 @cindex print list of auto-loaded canned sequences of commands scripts
29020 @item info auto-load gdb-scripts [@var{regexp}]
29021 Print the list of all canned sequences of commands scripts that @value{GDBN}
29022 auto-loaded.
29023 @end table
29024
29025 If @var{regexp} is supplied only canned sequences of commands scripts with
29026 matching names are printed.
29027
29028 @node Aliases
29029 @section Command Aliases
29030 @cindex aliases for commands
29031
29032 Aliases allow you to define alternate spellings for existing commands.
29033 For example, if a new @value{GDBN} command defined in Python
29034 (@pxref{Python}) has a long name, it is handy to have an abbreviated
29035 version of it that involves less typing.
29036
29037 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
29038 of the @samp{step} command even though it is otherwise an ambiguous
29039 abbreviation of other commands like @samp{set} and @samp{show}.
29040
29041 Aliases are also used to provide shortened or more common versions
29042 of multi-word commands. For example, @value{GDBN} provides the
29043 @samp{tty} alias of the @samp{set inferior-tty} command.
29044
29045 You can define a new alias with the @samp{alias} command.
29046
29047 @table @code
29048
29049 @kindex alias
29050 @item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
29051
29052 @end table
29053
29054 @var{alias} specifies the name of the new alias. Each word of
29055 @var{alias} must consist of letters, numbers, dashes and underscores.
29056
29057 @var{command} specifies the name of an existing command
29058 that is being aliased.
29059
29060 @var{command} can also be the name of an existing alias. In this
29061 case, @var{command} cannot be an alias that has default arguments.
29062
29063 The @samp{-a} option specifies that the new alias is an abbreviation
29064 of the command. Abbreviations are not used in command completion.
29065
29066 The @samp{--} option specifies the end of options,
29067 and is useful when @var{alias} begins with a dash.
29068
29069 You can specify @var{default-args} for your alias. These
29070 @var{default-args} will be automatically added before the alias
29071 arguments typed explicitly on the command line.
29072
29073 For example, the below defines an alias @code{btfullall} that shows all local
29074 variables and all frame arguments:
29075 @smallexample
29076 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
29077 @end smallexample
29078
29079 For more information about @var{default-args}, see @ref{Command
29080 aliases default args, ,Default Arguments}.
29081
29082 Here is a simple example showing how to make an abbreviation of a
29083 command so that there is less to type. Suppose you were tired of
29084 typing @samp{disas}, the current shortest unambiguous abbreviation of
29085 the @samp{disassemble} command and you wanted an even shorter version
29086 named @samp{di}. The following will accomplish this.
29087
29088 @smallexample
29089 (@value{GDBP}) alias -a di = disas
29090 @end smallexample
29091
29092 Note that aliases are different from user-defined commands. With a
29093 user-defined command, you also need to write documentation for it with
29094 the @samp{document} command. An alias automatically picks up the
29095 documentation of the existing command.
29096
29097 Here is an example where we make @samp{elms} an abbreviation of
29098 @samp{elements} in the @samp{set print elements} command.
29099 This is to show that you can make an abbreviation of any part
29100 of a command.
29101
29102 @smallexample
29103 (@value{GDBP}) alias -a set print elms = set print elements
29104 (@value{GDBP}) alias -a show print elms = show print elements
29105 (@value{GDBP}) set p elms 200
29106 (@value{GDBP}) show p elms
29107 Limit on string chars or array elements to print is 200.
29108 @end smallexample
29109
29110 Note that if you are defining an alias of a @samp{set} command,
29111 and you want to have an alias for the corresponding @samp{show}
29112 command, then you need to define the latter separately.
29113
29114 Unambiguously abbreviated commands are allowed in @var{command} and
29115 @var{alias}, just as they are normally.
29116
29117 @smallexample
29118 (@value{GDBP}) alias -a set pr elms = set p ele
29119 @end smallexample
29120
29121 Finally, here is an example showing the creation of a one word
29122 alias for a more complex command.
29123 This creates alias @samp{spe} of the command @samp{set print elements}.
29124
29125 @smallexample
29126 (@value{GDBP}) alias spe = set print elements
29127 (@value{GDBP}) spe 20
29128 @end smallexample
29129
29130 @menu
29131 * Command aliases default args:: Default arguments for aliases
29132 @end menu
29133
29134 @node Command aliases default args
29135 @subsection Default Arguments
29136 @cindex aliases for commands, default arguments
29137
29138 You can tell @value{GDBN} to always prepend some default arguments to
29139 the list of arguments provided explicitly by the user when using a
29140 user-defined alias.
29141
29142 If you repeatedly use the same arguments or options for a command, you
29143 can define an alias for this command and tell @value{GDBN} to
29144 automatically prepend these arguments or options to the list of
29145 arguments you type explicitly when using the alias@footnote{@value{GDBN}
29146 could easily accept default arguments for pre-defined commands and aliases,
29147 but it was deemed this would be confusing, and so is not allowed.}.
29148
29149 For example, if you often use the command @code{thread apply all}
29150 specifying to work on the threads in ascending order and to continue in case it
29151 encounters an error, you can tell @value{GDBN} to automatically preprend
29152 the @code{-ascending} and @code{-c} options by using:
29153
29154 @smallexample
29155 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
29156 @end smallexample
29157
29158 Once you have defined this alias with its default args, any time you type
29159 the @code{thread apply asc-all} followed by @code{some arguments},
29160 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
29161
29162 To have even less to type, you can also define a one word alias:
29163 @smallexample
29164 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
29165 @end smallexample
29166
29167 As usual, unambiguous abbreviations can be used for @var{alias}
29168 and @var{default-args}.
29169
29170 The different aliases of a command do not share their default args.
29171 For example, you define a new alias @code{bt_ALL} showing all possible
29172 information and another alias @code{bt_SMALL} showing very limited information
29173 using:
29174 @smallexample
29175 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
29176 -past-main -past-entry -full
29177 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
29178 -past-main off -past-entry off
29179 @end smallexample
29180
29181 (For more on using the @code{alias} command, see @ref{Aliases}.)
29182
29183 Default args are not limited to the arguments and options of @var{command},
29184 but can specify nested commands if @var{command} accepts such a nested command
29185 as argument.
29186 For example, the below defines @code{faalocalsoftype} that lists the
29187 frames having locals of a certain type, together with the matching
29188 local vars:
29189 @smallexample
29190 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
29191 (@value{GDBP}) faalocalsoftype int
29192 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
29193 i = 0
29194 ret = 21845
29195 @end smallexample
29196
29197 This is also very useful to define an alias for a set of nested @code{with}
29198 commands to have a particular combination of temporary settings. For example,
29199 the below defines the alias @code{pp10} that pretty prints an expression
29200 argument, with a maximum of 10 elements if the expression is a string or
29201 an array:
29202 @smallexample
29203 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
29204 @end smallexample
29205 This defines the alias @code{pp10} as being a sequence of 3 commands.
29206 The first part @code{with print pretty --} temporarily activates the setting
29207 @code{set print pretty}, then launches the command that follows the separator
29208 @code{--}.
29209 The command following the first part is also a @code{with} command that
29210 temporarily changes the setting @code{set print elements} to 10, then
29211 launches the command that follows the second separator @code{--}.
29212 The third part @code{print} is the command the @code{pp10} alias will launch,
29213 using the temporary values of the settings and the arguments explicitly given
29214 by the user.
29215 For more information about the @code{with} command usage,
29216 see @ref{Command Settings}.
29217
29218 By default, asking the help for an alias shows the documentation of
29219 the aliased command. When the alias is a set of nested commands, @code{help}
29220 of an alias shows the documentation of the first command. This help
29221 is not particularly useful for an alias such as @code{pp10}.
29222 For such an alias, it is useful to give a specific documentation
29223 using the @code{document} command (@pxref{Define, document}).
29224
29225
29226 @c Python docs live in a separate file.
29227 @include python.texi
29228
29229 @c Guile docs live in a separate file.
29230 @include guile.texi
29231
29232 @node Auto-loading extensions
29233 @section Auto-loading extensions
29234 @cindex auto-loading extensions
29235
29236 @value{GDBN} provides two mechanisms for automatically loading
29237 extensions when a new object file is read (for example, due to the
29238 @code{file} command, or because the inferior has loaded a shared
29239 library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
29240 file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
29241 @code{.debug_gdb_scripts} section of modern file formats like ELF
29242 (@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
29243 section}). For a discussion of the differences between these two
29244 approaches see @ref{Which flavor to choose?}.
29245
29246 The auto-loading feature is useful for supplying application-specific
29247 debugging commands and features.
29248
29249 Auto-loading can be enabled or disabled,
29250 and the list of auto-loaded scripts can be printed.
29251 See the @samp{auto-loading} section of each extension language
29252 for more information.
29253 For @value{GDBN} command files see @ref{Auto-loading sequences}.
29254 For Python files see @ref{Python Auto-loading}.
29255
29256 Note that loading of this script file also requires accordingly configured
29257 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
29258
29259 @menu
29260 * objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
29261 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
29262 * Which flavor to choose?:: Choosing between these approaches
29263 @end menu
29264
29265 @node objfile-gdbdotext file
29266 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
29267 @cindex @file{@var{objfile}-gdb.gdb}
29268 @cindex @file{@var{objfile}-gdb.py}
29269 @cindex @file{@var{objfile}-gdb.scm}
29270
29271 When a new object file is read, @value{GDBN} looks for a file named
29272 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
29273 where @var{objfile} is the object file's name and
29274 where @var{ext} is the file extension for the extension language:
29275
29276 @table @code
29277 @item @file{@var{objfile}-gdb.gdb}
29278 GDB's own command language
29279 @item @file{@var{objfile}-gdb.py}
29280 Python
29281 @item @file{@var{objfile}-gdb.scm}
29282 Guile
29283 @end table
29284
29285 @var{script-name} is formed by ensuring that the file name of @var{objfile}
29286 is absolute, following all symlinks, and resolving @code{.} and @code{..}
29287 components, and appending the @file{-gdb.@var{ext}} suffix.
29288 If this file exists and is readable, @value{GDBN} will evaluate it as a
29289 script in the specified extension language.
29290
29291 If this file does not exist, then @value{GDBN} will look for
29292 @var{script-name} file in all of the directories as specified below.
29293 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
29294 directories is converted to a one-letter subdirectory, i.e.@:
29295 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
29296 filesystems disallow colons in file names.)
29297
29298 Note that loading of these files requires an accordingly configured
29299 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
29300
29301 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
29302 scripts normally according to its @file{.exe} filename. But if no scripts are
29303 found @value{GDBN} also tries script filenames matching the object file without
29304 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
29305 is attempted on any platform. This makes the script filenames compatible
29306 between Unix and MS-Windows hosts.
29307
29308 @table @code
29309 @anchor{set auto-load scripts-directory}
29310 @kindex set auto-load scripts-directory
29311 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
29312 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
29313 may be delimited by the host platform path separator in use
29314 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
29315
29316 Each entry here needs to be covered also by the security setting
29317 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
29318
29319 @anchor{with-auto-load-dir}
29320 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
29321 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
29322 configuration option @option{--with-auto-load-dir}.
29323
29324 Any reference to @file{$debugdir} will get replaced by
29325 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
29326 reference to @file{$datadir} will get replaced by @var{data-directory} which is
29327 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
29328 @file{$datadir} must be placed as a directory component --- either alone or
29329 delimited by @file{/} or @file{\} directory separators, depending on the host
29330 platform.
29331
29332 The list of directories uses path separator (@samp{:} on GNU and Unix
29333 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
29334 to the @env{PATH} environment variable.
29335
29336 @anchor{show auto-load scripts-directory}
29337 @kindex show auto-load scripts-directory
29338 @item show auto-load scripts-directory
29339 Show @value{GDBN} auto-loaded scripts location.
29340
29341 @anchor{add-auto-load-scripts-directory}
29342 @kindex add-auto-load-scripts-directory
29343 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
29344 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
29345 Multiple entries may be delimited by the host platform path separator in use.
29346 @end table
29347
29348 @value{GDBN} does not track which files it has already auto-loaded this way.
29349 @value{GDBN} will load the associated script every time the corresponding
29350 @var{objfile} is opened.
29351 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
29352 is evaluated more than once.
29353
29354 @node dotdebug_gdb_scripts section
29355 @subsection The @code{.debug_gdb_scripts} section
29356 @cindex @code{.debug_gdb_scripts} section
29357
29358 For systems using file formats like ELF and COFF,
29359 when @value{GDBN} loads a new object file
29360 it will look for a special section named @code{.debug_gdb_scripts}.
29361 If this section exists, its contents is a list of null-terminated entries
29362 specifying scripts to load. Each entry begins with a non-null prefix byte that
29363 specifies the kind of entry, typically the extension language and whether the
29364 script is in a file or inlined in @code{.debug_gdb_scripts}.
29365
29366 The following entries are supported:
29367
29368 @table @code
29369 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
29370 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
29371 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
29372 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
29373 @end table
29374
29375 @subsubsection Script File Entries
29376
29377 If the entry specifies a file, @value{GDBN} will look for the file first
29378 in the current directory and then along the source search path
29379 (@pxref{Source Path, ,Specifying Source Directories}),
29380 except that @file{$cdir} is not searched, since the compilation
29381 directory is not relevant to scripts.
29382
29383 File entries can be placed in section @code{.debug_gdb_scripts} with,
29384 for example, this GCC macro for Python scripts.
29385
29386 @example
29387 /* Note: The "MS" section flags are to remove duplicates. */
29388 #define DEFINE_GDB_PY_SCRIPT(script_name) \
29389 asm("\
29390 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
29391 .byte 1 /* Python */\n\
29392 .asciz \"" script_name "\"\n\
29393 .popsection \n\
29394 ");
29395 @end example
29396
29397 @noindent
29398 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
29399 Then one can reference the macro in a header or source file like this:
29400
29401 @example
29402 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
29403 @end example
29404
29405 The script name may include directories if desired.
29406
29407 Note that loading of this script file also requires accordingly configured
29408 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
29409
29410 If the macro invocation is put in a header, any application or library
29411 using this header will get a reference to the specified script,
29412 and with the use of @code{"MS"} attributes on the section, the linker
29413 will remove duplicates.
29414
29415 @subsubsection Script Text Entries
29416
29417 Script text entries allow to put the executable script in the entry
29418 itself instead of loading it from a file.
29419 The first line of the entry, everything after the prefix byte and up to
29420 the first newline (@code{0xa}) character, is the script name, and must not
29421 contain any kind of space character, e.g., spaces or tabs.
29422 The rest of the entry, up to the trailing null byte, is the script to
29423 execute in the specified language. The name needs to be unique among
29424 all script names, as @value{GDBN} executes each script only once based
29425 on its name.
29426
29427 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
29428 testsuite.
29429
29430 @example
29431 #include "symcat.h"
29432 #include "gdb/section-scripts.h"
29433 asm(
29434 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
29435 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
29436 ".ascii \"gdb.inlined-script\\n\"\n"
29437 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
29438 ".ascii \" def __init__ (self):\\n\"\n"
29439 ".ascii \" super (test_cmd, self).__init__ ("
29440 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
29441 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
29442 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
29443 ".ascii \"test_cmd ()\\n\"\n"
29444 ".byte 0\n"
29445 ".popsection\n"
29446 );
29447 @end example
29448
29449 Loading of inlined scripts requires a properly configured
29450 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
29451 The path to specify in @code{auto-load safe-path} is the path of the file
29452 containing the @code{.debug_gdb_scripts} section.
29453
29454 @node Which flavor to choose?
29455 @subsection Which flavor to choose?
29456
29457 Given the multiple ways of auto-loading extensions, it might not always
29458 be clear which one to choose. This section provides some guidance.
29459
29460 @noindent
29461 Benefits of the @file{-gdb.@var{ext}} way:
29462
29463 @itemize @bullet
29464 @item
29465 Can be used with file formats that don't support multiple sections.
29466
29467 @item
29468 Ease of finding scripts for public libraries.
29469
29470 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
29471 in the source search path.
29472 For publicly installed libraries, e.g., @file{libstdc++}, there typically
29473 isn't a source directory in which to find the script.
29474
29475 @item
29476 Doesn't require source code additions.
29477 @end itemize
29478
29479 @noindent
29480 Benefits of the @code{.debug_gdb_scripts} way:
29481
29482 @itemize @bullet
29483 @item
29484 Works with static linking.
29485
29486 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
29487 trigger their loading. When an application is statically linked the only
29488 objfile available is the executable, and it is cumbersome to attach all the
29489 scripts from all the input libraries to the executable's
29490 @file{-gdb.@var{ext}} script.
29491
29492 @item
29493 Works with classes that are entirely inlined.
29494
29495 Some classes can be entirely inlined, and thus there may not be an associated
29496 shared library to attach a @file{-gdb.@var{ext}} script to.
29497
29498 @item
29499 Scripts needn't be copied out of the source tree.
29500
29501 In some circumstances, apps can be built out of large collections of internal
29502 libraries, and the build infrastructure necessary to install the
29503 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
29504 cumbersome. It may be easier to specify the scripts in the
29505 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
29506 top of the source tree to the source search path.
29507 @end itemize
29508
29509 @node Multiple Extension Languages
29510 @section Multiple Extension Languages
29511
29512 The Guile and Python extension languages do not share any state,
29513 and generally do not interfere with each other.
29514 There are some things to be aware of, however.
29515
29516 @subsection Python comes first
29517
29518 Python was @value{GDBN}'s first extension language, and to avoid breaking
29519 existing behaviour Python comes first. This is generally solved by the
29520 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
29521 extension languages, and when it makes a call to an extension language,
29522 (say to pretty-print a value), it tries each in turn until an extension
29523 language indicates it has performed the request (e.g., has returned the
29524 pretty-printed form of a value).
29525 This extends to errors while performing such requests: If an error happens
29526 while, for example, trying to pretty-print an object then the error is
29527 reported and any following extension languages are not tried.
29528
29529 @node Interpreters
29530 @chapter Command Interpreters
29531 @cindex command interpreters
29532
29533 @value{GDBN} supports multiple command interpreters, and some command
29534 infrastructure to allow users or user interface writers to switch
29535 between interpreters or run commands in other interpreters.
29536
29537 @value{GDBN} currently supports two command interpreters, the console
29538 interpreter (sometimes called the command-line interpreter or @sc{cli})
29539 and the machine interface interpreter (or @sc{gdb/mi}). This manual
29540 describes both of these interfaces in great detail.
29541
29542 By default, @value{GDBN} will start with the console interpreter.
29543 However, the user may choose to start @value{GDBN} with another
29544 interpreter by specifying the @option{-i} or @option{--interpreter}
29545 startup options. Defined interpreters include:
29546
29547 @table @code
29548 @item console
29549 @cindex console interpreter
29550 The traditional console or command-line interpreter. This is the most often
29551 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
29552 @value{GDBN} will use this interpreter.
29553
29554 @item dap
29555 @cindex DAP
29556 @cindex Debugger Adapter Protocol
29557 When @value{GDBN} has been built with Python support, it also supports
29558 the Debugger Adapter Protocol. This protocol can be used by a
29559 debugger GUI or an IDE to communicate with @value{GDBN}. This
29560 protocol is documented at
29561 @url{https://microsoft.github.io/debug-adapter-protocol/}.
29562
29563 @item mi
29564 @cindex mi interpreter
29565 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
29566 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
29567 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
29568 Interface}.
29569
29570 @item mi3
29571 @cindex mi3 interpreter
29572 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
29573
29574 @item mi2
29575 @cindex mi2 interpreter
29576 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
29577
29578 @end table
29579
29580 @cindex invoke another interpreter
29581
29582 @kindex interpreter-exec
29583 You may execute commands in any interpreter from the current
29584 interpreter using the appropriate command. If you are running the
29585 console interpreter, simply use the @code{interpreter-exec} command:
29586
29587 @smallexample
29588 interpreter-exec mi "-data-list-register-names"
29589 @end smallexample
29590
29591 @sc{gdb/mi} has a similar command, although it is only available in versions of
29592 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
29593
29594 Note that @code{interpreter-exec} only changes the interpreter for the
29595 duration of the specified command. It does not change the interpreter
29596 permanently.
29597
29598 @cindex start a new independent interpreter
29599
29600 Although you may only choose a single interpreter at startup, it is
29601 possible to run an independent interpreter on a specified input/output
29602 device (usually a tty).
29603
29604 For example, consider a debugger GUI or IDE that wants to provide a
29605 @value{GDBN} console view. It may do so by embedding a terminal
29606 emulator widget in its GUI, starting @value{GDBN} in the traditional
29607 command-line mode with stdin/stdout/stderr redirected to that
29608 terminal, and then creating an MI interpreter running on a specified
29609 input/output device. The console interpreter created by @value{GDBN}
29610 at startup handles commands the user types in the terminal widget,
29611 while the GUI controls and synchronizes state with @value{GDBN} using
29612 the separate MI interpreter.
29613
29614 To start a new secondary @dfn{user interface} running MI, use the
29615 @code{new-ui} command:
29616
29617 @kindex new-ui
29618 @cindex new user interface
29619 @smallexample
29620 new-ui @var{interpreter} @var{tty}
29621 @end smallexample
29622
29623 The @var{interpreter} parameter specifies the interpreter to run.
29624 This accepts the same values as the @code{interpreter-exec} command.
29625 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
29626 @var{tty} parameter specifies the name of the bidirectional file the
29627 interpreter uses for input/output, usually the name of a
29628 pseudoterminal slave on Unix systems. For example:
29629
29630 @smallexample
29631 (@value{GDBP}) new-ui mi /dev/pts/9
29632 @end smallexample
29633
29634 @noindent
29635 runs an MI interpreter on @file{/dev/pts/9}.
29636
29637 @node TUI
29638 @chapter @value{GDBN} Text User Interface
29639 @cindex TUI
29640 @cindex Text User Interface
29641
29642 The @value{GDBN} Text User Interface (TUI) is a terminal
29643 interface which uses the @code{curses} library to show the source
29644 file, the assembly output, the program registers and @value{GDBN}
29645 commands in separate text windows. The TUI mode is supported only
29646 on platforms where a suitable version of the @code{curses} library
29647 is available.
29648
29649 The TUI mode is enabled by default when you invoke @value{GDBN} as
29650 @samp{@value{GDBP} -tui}.
29651 You can also switch in and out of TUI mode while @value{GDBN} runs by
29652 using various TUI commands and key bindings, such as @command{tui
29653 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
29654 @ref{TUI Keys, ,TUI Key Bindings}.
29655
29656 @menu
29657 * TUI Overview:: TUI overview
29658 * TUI Keys:: TUI key bindings
29659 * TUI Single Key Mode:: TUI single key mode
29660 * TUI Mouse Support:: TUI mouse support
29661 * TUI Commands:: TUI-specific commands
29662 * TUI Configuration:: TUI configuration variables
29663 @end menu
29664
29665 @node TUI Overview
29666 @section TUI Overview
29667
29668 In TUI mode, @value{GDBN} can display several text windows:
29669
29670 @table @emph
29671 @item command
29672 This window is the @value{GDBN} command window with the @value{GDBN}
29673 prompt and the @value{GDBN} output. The @value{GDBN} input is still
29674 managed using readline.
29675
29676 @item source
29677 The source window shows the source file of the program. The current
29678 line and active breakpoints are displayed in this window.
29679
29680 @item assembly
29681 The assembly window shows the disassembly output of the program.
29682
29683 @item register
29684 This window shows the processor registers. Registers are highlighted
29685 when their values change.
29686 @end table
29687
29688 The source and assembly windows show the current program position by
29689 highlighting the current line and marking it with a @samp{>} marker.
29690 By default, source and assembly code styling is disabled for the
29691 highlighted text, but you can enable it with the @code{set style
29692 tui-current-position on} command. @xref{Output Styling}.
29693
29694 Breakpoints are indicated with two markers. The first marker
29695 indicates the breakpoint type:
29696
29697 @table @code
29698 @item B
29699 Breakpoint which was hit at least once.
29700
29701 @item b
29702 Breakpoint which was never hit.
29703
29704 @item H
29705 Hardware breakpoint which was hit at least once.
29706
29707 @item h
29708 Hardware breakpoint which was never hit.
29709 @end table
29710
29711 The second marker indicates whether the breakpoint is enabled or not:
29712
29713 @table @code
29714 @item +
29715 Breakpoint is enabled.
29716
29717 @item -
29718 Breakpoint is disabled.
29719 @end table
29720
29721 The source, assembly and register windows are updated when the current
29722 thread changes, when the frame changes, or when the program counter
29723 changes.
29724
29725 These windows are not all visible at the same time. The command
29726 window is always visible. The others can be arranged in several
29727 layouts:
29728
29729 @itemize @bullet
29730 @item
29731 source only,
29732
29733 @item
29734 assembly only,
29735
29736 @item
29737 source and assembly,
29738
29739 @item
29740 source and registers, or
29741
29742 @item
29743 assembly and registers.
29744 @end itemize
29745
29746 These are the standard layouts, but other layouts can be defined.
29747
29748 A status line above the command window shows the following information:
29749
29750 @table @emph
29751 @item target
29752 Indicates the current @value{GDBN} target.
29753 (@pxref{Targets, ,Specifying a Debugging Target}).
29754
29755 @item process
29756 Gives the current process or thread number.
29757 When no process is being debugged, this field is set to @code{No process}.
29758
29759 @item function
29760 Gives the current function name for the selected frame.
29761 The name is demangled if demangling is turned on (@pxref{Print Settings}).
29762 When there is no symbol corresponding to the current program counter,
29763 the string @code{??} is displayed.
29764
29765 @item line
29766 Indicates the current line number for the selected frame.
29767 When the current line number is not known, the string @code{??} is displayed.
29768
29769 @item pc
29770 Indicates the current program counter address.
29771 @end table
29772
29773 @node TUI Keys
29774 @section TUI Key Bindings
29775 @cindex TUI key bindings
29776
29777 The TUI installs several key bindings in the readline keymaps
29778 @ifset SYSTEM_READLINE
29779 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
29780 @end ifset
29781 @ifclear SYSTEM_READLINE
29782 (@pxref{Command Line Editing}).
29783 @end ifclear
29784 The following key bindings are installed for both TUI mode and the
29785 @value{GDBN} standard mode.
29786
29787 @table @kbd
29788 @kindex C-x C-a
29789 @item C-x C-a
29790 @kindex C-x a
29791 @itemx C-x a
29792 @kindex C-x A
29793 @itemx C-x A
29794 Enter or leave the TUI mode. When leaving the TUI mode,
29795 the curses window management stops and @value{GDBN} operates using
29796 its standard mode, writing on the terminal directly. When reentering
29797 the TUI mode, control is given back to the curses windows.
29798 The screen is then refreshed.
29799
29800 This key binding uses the bindable Readline function
29801 @code{tui-switch-mode}.
29802
29803 @kindex C-x 1
29804 @item C-x 1
29805 Use a TUI layout with only one window. The layout will
29806 either be @samp{source} or @samp{assembly}. When the TUI mode
29807 is not active, it will switch to the TUI mode.
29808
29809 Think of this key binding as the Emacs @kbd{C-x 1} binding.
29810
29811 This key binding uses the bindable Readline function
29812 @code{tui-delete-other-windows}.
29813
29814 @kindex C-x 2
29815 @item C-x 2
29816 Use a TUI layout with at least two windows. When the current
29817 layout already has two windows, the next layout with two windows is used.
29818 When a new layout is chosen, one window will always be common to the
29819 previous layout and the new one.
29820
29821 Think of it as the Emacs @kbd{C-x 2} binding.
29822
29823 This key binding uses the bindable Readline function
29824 @code{tui-change-windows}.
29825
29826 @kindex C-x o
29827 @item C-x o
29828 Change the active window. The TUI associates several key bindings
29829 (like scrolling and arrow keys) with the active window. This command
29830 gives the focus to the next TUI window.
29831
29832 Think of it as the Emacs @kbd{C-x o} binding.
29833
29834 This key binding uses the bindable Readline function
29835 @code{tui-other-window}.
29836
29837 @kindex C-x s
29838 @item C-x s
29839 Switch in and out of the TUI SingleKey mode that binds single
29840 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
29841
29842 This key binding uses the bindable Readline function
29843 @code{next-keymap}.
29844 @end table
29845
29846 The following key bindings only work in the TUI mode:
29847
29848 @table @asis
29849 @kindex PgUp
29850 @item @key{PgUp}
29851 Scroll the active window one page up.
29852
29853 @kindex PgDn
29854 @item @key{PgDn}
29855 Scroll the active window one page down.
29856
29857 @kindex Up
29858 @item @key{Up}
29859 Scroll the active window one line up.
29860
29861 @kindex Down
29862 @item @key{Down}
29863 Scroll the active window one line down.
29864
29865 @kindex Left
29866 @item @key{Left}
29867 Scroll the active window one column left.
29868
29869 @kindex Right
29870 @item @key{Right}
29871 Scroll the active window one column right.
29872
29873 @kindex C-L
29874 @item @kbd{C-L}
29875 Refresh the screen.
29876 @end table
29877
29878 Because the arrow keys scroll the active window in the TUI mode, they
29879 are not available for their normal use by readline unless the command
29880 window has the focus. When another window is active, you must use
29881 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
29882 and @kbd{C-f} to control the command window.
29883
29884 @node TUI Single Key Mode
29885 @section TUI Single Key Mode
29886 @cindex TUI single key mode
29887
29888 The TUI also provides a @dfn{SingleKey} mode, which binds several
29889 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
29890 switch into this mode, where the following key bindings are used:
29891
29892 @table @kbd
29893 @kindex c @r{(SingleKey TUI key)}
29894 @item c
29895 continue
29896
29897 @kindex d @r{(SingleKey TUI key)}
29898 @item d
29899 down
29900
29901 @kindex f @r{(SingleKey TUI key)}
29902 @item f
29903 finish
29904
29905 @kindex n @r{(SingleKey TUI key)}
29906 @item n
29907 next
29908
29909 @kindex o @r{(SingleKey TUI key)}
29910 @item o
29911 nexti. The shortcut letter @samp{o} stands for ``step Over''.
29912
29913 @kindex q @r{(SingleKey TUI key)}
29914 @item q
29915 exit the SingleKey mode.
29916
29917 @kindex r @r{(SingleKey TUI key)}
29918 @item r
29919 run
29920
29921 @kindex s @r{(SingleKey TUI key)}
29922 @item s
29923 step
29924
29925 @kindex i @r{(SingleKey TUI key)}
29926 @item i
29927 stepi. The shortcut letter @samp{i} stands for ``step Into''.
29928
29929 @kindex u @r{(SingleKey TUI key)}
29930 @item u
29931 up
29932
29933 @kindex v @r{(SingleKey TUI key)}
29934 @item v
29935 info locals
29936
29937 @kindex w @r{(SingleKey TUI key)}
29938 @item w
29939 where
29940 @end table
29941
29942 Other keys temporarily switch to the @value{GDBN} command prompt.
29943 The key that was pressed is inserted in the editing buffer so that
29944 it is possible to type most @value{GDBN} commands without interaction
29945 with the TUI SingleKey mode. Once the command is entered the TUI
29946 SingleKey mode is restored. The only way to permanently leave
29947 this mode is by typing @kbd{q} or @kbd{C-x s}.
29948
29949 @cindex SingleKey keymap name
29950 If @value{GDBN} was built with Readline 8.0 or later, the TUI
29951 SingleKey keymap will be named @samp{SingleKey}. This can be used in
29952 @file{.inputrc} to add additional bindings to this keymap.
29953
29954 @node TUI Mouse Support
29955 @section TUI Mouse Support
29956 @cindex TUI mouse support
29957
29958 If the curses library supports the mouse, the TUI supports mouse
29959 actions.
29960
29961 The mouse wheel scrolls the appropriate window under the mouse cursor.
29962
29963 The TUI itself does not directly support copying/pasting with the
29964 mouse. However, on Unix terminals, you can typically press and hold
29965 the @key{SHIFT} key on your keyboard to temporarily bypass
29966 @value{GDBN}'s TUI and access the terminal's native mouse copy/paste
29967 functionality (commonly, click-drag-release or double-click to select
29968 text, middle-click to paste). This copy/paste works with the
29969 terminal's selection buffer, as opposed to the TUI's buffer.
29970
29971 @node TUI Commands
29972 @section TUI-specific Commands
29973 @cindex TUI commands
29974
29975 The TUI has specific commands to control the text windows.
29976 These commands are always available, even when @value{GDBN} is not in
29977 the TUI mode. When @value{GDBN} is in the standard mode, most
29978 of these commands will automatically switch to the TUI mode.
29979
29980 Note that if @value{GDBN}'s @code{stdout} is not connected to a
29981 terminal, or @value{GDBN} has been started with the machine interface
29982 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
29983 these commands will fail with an error, because it would not be
29984 possible or desirable to enable curses window management.
29985
29986 @table @code
29987 @item tui enable
29988 @kindex tui enable
29989 Activate TUI mode. The last active TUI window layout will be used if
29990 TUI mode has previously been used in the current debugging session,
29991 otherwise a default layout is used.
29992
29993 @item tui disable
29994 @kindex tui disable
29995 Disable TUI mode, returning to the console interpreter.
29996
29997 @anchor{info_win_command}
29998 @item info win
29999 @kindex info win
30000 List the names and sizes of all currently displayed windows.
30001
30002 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
30003 @kindex tui new-layout
30004 Create a new TUI layout. The new layout will be named @var{name}, and
30005 can be accessed using the @code{layout} command (see below).
30006
30007 Each @var{window} parameter is either the name of a window to display,
30008 or a window description. The windows will be displayed from top to
30009 bottom in the order listed.
30010
30011 The names of the windows are the same as the ones given to the
30012 @code{focus} command (see below); additional, the @code{status}
30013 window can be specified. Note that, because it is of fixed height,
30014 the weight assigned to the status window is of no importance. It is
30015 conventional to use @samp{0} here.
30016
30017 A window description looks a bit like an invocation of @code{tui
30018 new-layout}, and is of the form
30019 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
30020
30021 This specifies a sub-layout. If @code{-horizontal} is given, the
30022 windows in this description will be arranged side-by-side, rather than
30023 top-to-bottom.
30024
30025 Each @var{weight} is an integer. It is the weight of this window
30026 relative to all the other windows in the layout. These numbers are
30027 used to calculate how much of the screen is given to each window.
30028
30029 For example:
30030
30031 @example
30032 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
30033 @end example
30034
30035 Here, the new layout is called @samp{example}. It shows the source
30036 and register windows, followed by the status window, and then finally
30037 the command window. The non-status windows all have the same weight,
30038 so the terminal will be split into three roughly equal sections.
30039
30040 Here is a more complex example, showing a horizontal layout:
30041
30042 @example
30043 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
30044 @end example
30045
30046 This will result in side-by-side source and assembly windows; with the
30047 status and command window being beneath these, filling the entire
30048 width of the terminal. Because they have weight 2, the source and
30049 assembly windows will be twice the height of the command window.
30050
30051 @kindex tui layout
30052 @kindex layout
30053 @item tui layout @var{name}
30054 @itemx layout @var{name}
30055 Changes which TUI windows are displayed. The @var{name} parameter
30056 controls which layout is shown. It can be either one of the built-in
30057 layout names, or the name of a layout defined by the user using
30058 @code{tui new-layout}.
30059
30060 The built-in layouts are as follows:
30061
30062 @table @code
30063 @item next
30064 Display the next layout.
30065
30066 @item prev
30067 Display the previous layout.
30068
30069 @item src
30070 Display the source and command windows.
30071
30072 @item asm
30073 Display the assembly and command windows.
30074
30075 @item split
30076 Display the source, assembly, and command windows.
30077
30078 @item regs
30079 When in @code{src} layout display the register, source, and command
30080 windows. When in @code{asm} or @code{split} layout display the
30081 register, assembler, and command windows.
30082 @end table
30083
30084 @kindex focus
30085 @item tui focus @var{name}
30086 @itemx focus @var{name}
30087 Changes which TUI window is currently active for scrolling. The
30088 @var{name} parameter can be any of the following:
30089
30090 @table @code
30091 @item next
30092 Make the next window active for scrolling.
30093
30094 @item prev
30095 Make the previous window active for scrolling.
30096
30097 @item src
30098 Make the source window active for scrolling.
30099
30100 @item asm
30101 Make the assembly window active for scrolling.
30102
30103 @item regs
30104 Make the register window active for scrolling.
30105
30106 @item cmd
30107 Make the command window active for scrolling.
30108 @end table
30109
30110 @kindex tui refresh
30111 @kindex refresh
30112 @item tui refresh
30113 @itemx refresh
30114 Refresh the screen. This is similar to typing @kbd{C-L}.
30115
30116 @item tui reg @var{group}
30117 @kindex tui reg
30118 Changes the register group displayed in the tui register window to
30119 @var{group}. If the register window is not currently displayed this
30120 command will cause the register window to be displayed. The list of
30121 register groups, as well as their order is target specific. The
30122 following groups are available on most targets:
30123 @table @code
30124 @item next
30125 Repeatedly selecting this group will cause the display to cycle
30126 through all of the available register groups.
30127
30128 @item prev
30129 Repeatedly selecting this group will cause the display to cycle
30130 through all of the available register groups in the reverse order to
30131 @var{next}.
30132
30133 @item general
30134 Display the general registers.
30135 @item float
30136 Display the floating point registers.
30137 @item system
30138 Display the system registers.
30139 @item vector
30140 Display the vector registers.
30141 @item all
30142 Display all registers.
30143 @end table
30144
30145 @item update
30146 @kindex update
30147 Update the source window and the current execution point.
30148
30149 @kindex tui window height
30150 @kindex winheight
30151 @item tui window height @var{name} +@var{count}
30152 @itemx tui window height @var{name} -@var{count}
30153 @itemx winheight @var{name} +@var{count}
30154 @itemx winheight @var{name} -@var{count}
30155 Change the height of the window @var{name} by @var{count} lines.
30156 Positive counts increase the height, while negative counts decrease
30157 it. The @var{name} parameter can be the name of any currently visible
30158 window. The names of the currently visible windows can be discovered
30159 using @kbd{info win} (@pxref{info_win_command,,info win}).
30160
30161 The set of currently visible windows must always fill the terminal,
30162 and so, it is only possible to resize on window if there are other
30163 visible windows that can either give or receive the extra terminal
30164 space.
30165
30166 @kindex tui window width
30167 @kindex winwidth
30168 @item tui window width @var{name} +@var{count}
30169 @itemx tui window width @var{name} -@var{count}
30170 @itemx winwidth @var{name} +@var{count}
30171 @itemx winwidth @var{name} -@var{count}
30172 Change the width of the window @var{name} by @var{count} columns.
30173 Positive counts increase the width, while negative counts decrease it.
30174 The @var{name} parameter can be the name of any currently visible
30175 window. The names of the currently visible windows can be discovered
30176 using @code{info win} (@pxref{info_win_command,,info win}).
30177
30178 The set of currently visible windows must always fill the terminal,
30179 and so, it is only possible to resize on window if there are other
30180 visible windows that can either give or receive the extra terminal
30181 space.
30182 @end table
30183
30184 @node TUI Configuration
30185 @section TUI Configuration Variables
30186 @cindex TUI configuration variables
30187
30188 Several configuration variables control the appearance of TUI windows.
30189
30190 @table @code
30191 @item set tui border-kind @var{kind}
30192 @kindex set tui border-kind
30193 Select the border appearance for the source, assembly and register windows.
30194 The possible values are the following:
30195 @table @code
30196 @item space
30197 Use a space character to draw the border.
30198
30199 @item ascii
30200 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
30201
30202 @item acs
30203 Use the Alternate Character Set to draw the border. The border is
30204 drawn using character line graphics if the terminal supports them.
30205 @end table
30206
30207 @item set tui border-mode @var{mode}
30208 @kindex set tui border-mode
30209 @itemx set tui active-border-mode @var{mode}
30210 @kindex set tui active-border-mode
30211 Select the display attributes for the borders of the inactive windows
30212 or the active window. The @var{mode} can be one of the following:
30213 @table @code
30214 @item normal
30215 Use normal attributes to display the border.
30216
30217 @item standout
30218 Use standout mode.
30219
30220 @item reverse
30221 Use reverse video mode.
30222
30223 @item half
30224 Use half bright mode.
30225
30226 @item half-standout
30227 Use half bright and standout mode.
30228
30229 @item bold
30230 Use extra bright or bold mode.
30231
30232 @item bold-standout
30233 Use extra bright or bold and standout mode.
30234 @end table
30235
30236 @item set tui tab-width @var{nchars}
30237 @kindex set tui tab-width
30238 @kindex tabset
30239 Set the width of tab stops to be @var{nchars} characters. This
30240 setting affects the display of TAB characters in the source and
30241 assembly windows.
30242
30243 @item set tui compact-source @r{[}on@r{|}off@r{]}
30244 @kindex set tui compact-source
30245 Set whether the TUI source window is displayed in ``compact'' form.
30246 The default display uses more space for line numbers and starts the
30247 source text at the next tab stop; the compact display uses only as
30248 much space as is needed for the line numbers in the current file, and
30249 only a single space to separate the line numbers from the source.
30250
30251 @kindex set debug tui
30252 @item set debug tui @r{[}on|off@r{]}
30253 Turn on or off display of @value{GDBN} internal debug messages relating
30254 to the TUI.
30255
30256 @kindex show debug tui
30257 @item show debug tui
30258 Show the current status of displaying @value{GDBN} internal debug
30259 messages relating to the TUI.
30260
30261 @end table
30262
30263 Note that the colors of the TUI borders can be controlled using the
30264 appropriate @code{set style} commands. @xref{Output Styling}.
30265
30266 @node Emacs
30267 @chapter Using @value{GDBN} under @sc{gnu} Emacs
30268
30269 @cindex Emacs
30270 @cindex @sc{gnu} Emacs
30271 A special interface allows you to use @sc{gnu} Emacs to view (and
30272 edit) the source files for the program you are debugging with
30273 @value{GDBN}.
30274
30275 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
30276 executable file you want to debug as an argument. This command starts
30277 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
30278 created Emacs buffer.
30279 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
30280
30281 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
30282 things:
30283
30284 @itemize @bullet
30285 @item
30286 All ``terminal'' input and output goes through an Emacs buffer, called
30287 the GUD buffer.
30288
30289 This applies both to @value{GDBN} commands and their output, and to the input
30290 and output done by the program you are debugging.
30291
30292 This is useful because it means that you can copy the text of previous
30293 commands and input them again; you can even use parts of the output
30294 in this way.
30295
30296 All the facilities of Emacs' Shell mode are available for interacting
30297 with your program. In particular, you can send signals the usual
30298 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
30299 stop.
30300
30301 @item
30302 @value{GDBN} displays source code through Emacs.
30303
30304 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
30305 source file for that frame and puts an arrow (@samp{=>}) at the
30306 left margin of the current line. Emacs uses a separate buffer for
30307 source display, and splits the screen to show both your @value{GDBN} session
30308 and the source.
30309
30310 Explicit @value{GDBN} @code{list} or search commands still produce output as
30311 usual, but you probably have no reason to use them from Emacs.
30312 @end itemize
30313
30314 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
30315 a graphical mode, enabled by default, which provides further buffers
30316 that can control the execution and describe the state of your program.
30317 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
30318
30319 If you specify an absolute file name when prompted for the @kbd{M-x
30320 gdb} argument, then Emacs sets your current working directory to where
30321 your program resides. If you only specify the file name, then Emacs
30322 sets your current working directory to the directory associated
30323 with the previous buffer. In this case, @value{GDBN} may find your
30324 program by searching your environment's @env{PATH} variable, but on
30325 some operating systems it might not find the source. So, although the
30326 @value{GDBN} input and output session proceeds normally, the auxiliary
30327 buffer does not display the current source and line of execution.
30328
30329 The initial working directory of @value{GDBN} is printed on the top
30330 line of the GUD buffer and this serves as a default for the commands
30331 that specify files for @value{GDBN} to operate on. @xref{Files,
30332 ,Commands to Specify Files}.
30333
30334 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
30335 need to call @value{GDBN} by a different name (for example, if you
30336 keep several configurations around, with different names) you can
30337 customize the Emacs variable @code{gud-gdb-command-name} to run the
30338 one you want.
30339
30340 In the GUD buffer, you can use these special Emacs commands in
30341 addition to the standard Shell mode commands:
30342
30343 @table @kbd
30344 @item C-h m
30345 Describe the features of Emacs' GUD Mode.
30346
30347 @item C-c C-s
30348 Execute to another source line, like the @value{GDBN} @code{step} command; also
30349 update the display window to show the current file and location.
30350
30351 @item C-c C-n
30352 Execute to next source line in this function, skipping all function
30353 calls, like the @value{GDBN} @code{next} command. Then update the display window
30354 to show the current file and location.
30355
30356 @item C-c C-i
30357 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
30358 display window accordingly.
30359
30360 @item C-c C-f
30361 Execute until exit from the selected stack frame, like the @value{GDBN}
30362 @code{finish} command.
30363
30364 @item C-c C-r
30365 Continue execution of your program, like the @value{GDBN} @code{continue}
30366 command.
30367
30368 @item C-c <
30369 Go up the number of frames indicated by the numeric argument
30370 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
30371 like the @value{GDBN} @code{up} command.
30372
30373 @item C-c >
30374 Go down the number of frames indicated by the numeric argument, like the
30375 @value{GDBN} @code{down} command.
30376 @end table
30377
30378 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
30379 tells @value{GDBN} to set a breakpoint on the source line point is on.
30380
30381 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
30382 separate frame which shows a backtrace when the GUD buffer is current.
30383 Move point to any frame in the stack and type @key{RET} to make it
30384 become the current frame and display the associated source in the
30385 source buffer. Alternatively, click @kbd{Mouse-2} to make the
30386 selected frame become the current one. In graphical mode, the
30387 speedbar displays watch expressions.
30388
30389 If you accidentally delete the source-display buffer, an easy way to get
30390 it back is to type the command @code{f} in the @value{GDBN} buffer, to
30391 request a frame display; when you run under Emacs, this recreates
30392 the source buffer if necessary to show you the context of the current
30393 frame.
30394
30395 The source files displayed in Emacs are in ordinary Emacs buffers
30396 which are visiting the source files in the usual way. You can edit
30397 the files with these buffers if you wish; but keep in mind that @value{GDBN}
30398 communicates with Emacs in terms of line numbers. If you add or
30399 delete lines from the text, the line numbers that @value{GDBN} knows cease
30400 to correspond properly with the code.
30401
30402 A more detailed description of Emacs' interaction with @value{GDBN} is
30403 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
30404 Emacs Manual}).
30405
30406 @node GDB/MI
30407 @chapter The @sc{gdb/mi} Interface
30408
30409 @unnumberedsec Function and Purpose
30410
30411 @cindex @sc{gdb/mi}, its purpose
30412 @sc{gdb/mi} is a line based machine oriented text interface to
30413 @value{GDBN} and is activated by specifying using the
30414 @option{--interpreter} command line option (@pxref{Mode Options}). It
30415 is specifically intended to support the development of systems which
30416 use the debugger as just one small component of a larger system.
30417
30418 This chapter is a specification of the @sc{gdb/mi} interface. It is written
30419 in the form of a reference manual.
30420
30421 Note that @sc{gdb/mi} is still under construction, so some of the
30422 features described below are incomplete and subject to change
30423 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
30424
30425 @unnumberedsec Notation and Terminology
30426
30427 @cindex notational conventions, for @sc{gdb/mi}
30428 This chapter uses the following notation:
30429
30430 @itemize @bullet
30431 @item
30432 @code{|} separates two alternatives.
30433
30434 @item
30435 @code{[ @var{something} ]} indicates that @var{something} is optional:
30436 it may or may not be given.
30437
30438 @item
30439 @code{( @var{group} )*} means that @var{group} inside the parentheses
30440 may repeat zero or more times.
30441
30442 @item
30443 @code{( @var{group} )+} means that @var{group} inside the parentheses
30444 may repeat one or more times.
30445
30446 @item
30447 @code{( @var{group} )} means that @var{group} inside the parentheses
30448 occurs exactly once.
30449
30450 @item
30451 @code{"@var{string}"} means a literal @var{string}.
30452 @end itemize
30453
30454 @ignore
30455 @heading Dependencies
30456 @end ignore
30457
30458 @menu
30459 * GDB/MI General Design::
30460 * GDB/MI Command Syntax::
30461 * GDB/MI Compatibility with CLI::
30462 * GDB/MI Development and Front Ends::
30463 * GDB/MI Output Records::
30464 * GDB/MI Simple Examples::
30465 * GDB/MI Command Description Format::
30466 * GDB/MI Breakpoint Commands::
30467 * GDB/MI Catchpoint Commands::
30468 * GDB/MI Program Context::
30469 * GDB/MI Thread Commands::
30470 * GDB/MI Ada Tasking Commands::
30471 * GDB/MI Program Execution::
30472 * GDB/MI Stack Manipulation::
30473 * GDB/MI Variable Objects::
30474 * GDB/MI Data Manipulation::
30475 * GDB/MI Tracepoint Commands::
30476 * GDB/MI Symbol Query::
30477 * GDB/MI File Commands::
30478 @ignore
30479 * GDB/MI Kod Commands::
30480 * GDB/MI Memory Overlay Commands::
30481 * GDB/MI Signal Handling Commands::
30482 @end ignore
30483 * GDB/MI Target Manipulation::
30484 * GDB/MI File Transfer Commands::
30485 * GDB/MI Ada Exceptions Commands::
30486 * GDB/MI Support Commands::
30487 * GDB/MI Miscellaneous Commands::
30488 @end menu
30489
30490 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30491 @node GDB/MI General Design
30492 @section @sc{gdb/mi} General Design
30493 @cindex GDB/MI General Design
30494
30495 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
30496 parts---commands sent to @value{GDBN}, responses to those commands
30497 and notifications. Each command results in exactly one response,
30498 indicating either successful completion of the command, or an error.
30499 For the commands that do not resume the target, the response contains the
30500 requested information. For the commands that resume the target, the
30501 response only indicates whether the target was successfully resumed.
30502 Notifications is the mechanism for reporting changes in the state of the
30503 target, or in @value{GDBN} state, that cannot conveniently be associated with
30504 a command and reported as part of that command response.
30505
30506 The important examples of notifications are:
30507 @itemize @bullet
30508
30509 @item
30510 Exec notifications. These are used to report changes in
30511 target state---when a target is resumed, or stopped. It would not
30512 be feasible to include this information in response of resuming
30513 commands, because one resume commands can result in multiple events in
30514 different threads. Also, quite some time may pass before any event
30515 happens in the target, while a frontend needs to know whether the resuming
30516 command itself was successfully executed.
30517
30518 @item
30519 Console output, and status notifications. Console output
30520 notifications are used to report output of CLI commands, as well as
30521 diagnostics for other commands. Status notifications are used to
30522 report the progress of a long-running operation. Naturally, including
30523 this information in command response would mean no output is produced
30524 until the command is finished, which is undesirable.
30525
30526 @item
30527 General notifications. Commands may have various side effects on
30528 the @value{GDBN} or target state beyond their official purpose. For example,
30529 a command may change the selected thread. Although such changes can
30530 be included in command response, using notification allows for more
30531 orthogonal frontend design.
30532
30533 @end itemize
30534
30535 There's no guarantee that whenever an MI command reports an error,
30536 @value{GDBN} or the target are in any specific state, and especially,
30537 the state is not reverted to the state before the MI command was
30538 processed. Therefore, whenever an MI command results in an error,
30539 we recommend that the frontend refreshes all the information shown in
30540 the user interface.
30541
30542
30543 @menu
30544 * Context management::
30545 * Asynchronous and non-stop modes::
30546 * Thread groups::
30547 @end menu
30548
30549 @node Context management
30550 @subsection Context management
30551
30552 @subsubsection Threads and Frames
30553
30554 In most cases when @value{GDBN} accesses the target, this access is
30555 done in context of a specific thread and frame (@pxref{Frames}).
30556 Often, even when accessing global data, the target requires that a thread
30557 be specified. The CLI interface maintains the selected thread and frame,
30558 and supplies them to target on each command. This is convenient,
30559 because a command line user would not want to specify that information
30560 explicitly on each command, and because user interacts with
30561 @value{GDBN} via a single terminal, so no confusion is possible as
30562 to what thread and frame are the current ones.
30563
30564 In the case of MI, the concept of selected thread and frame is less
30565 useful. First, a frontend can easily remember this information
30566 itself. Second, a graphical frontend can have more than one window,
30567 each one used for debugging a different thread, and the frontend might
30568 want to access additional threads for internal purposes. This
30569 increases the risk that by relying on implicitly selected thread, the
30570 frontend may be operating on a wrong one. Therefore, each MI command
30571 should explicitly specify which thread and frame to operate on. To
30572 make it possible, each MI command accepts the @samp{--thread} and
30573 @samp{--frame} options, the value to each is @value{GDBN} global
30574 identifier for thread and frame to operate on.
30575
30576 Usually, each top-level window in a frontend allows the user to select
30577 a thread and a frame, and remembers the user selection for further
30578 operations. However, in some cases @value{GDBN} may suggest that the
30579 current thread or frame be changed. For example, when stopping on a
30580 breakpoint it is reasonable to switch to the thread where breakpoint is
30581 hit. For another example, if the user issues the CLI @samp{thread} or
30582 @samp{frame} commands via the frontend, it is desirable to change the
30583 frontend's selection to the one specified by user. @value{GDBN}
30584 communicates the suggestion to change current thread and frame using the
30585 @samp{=thread-selected} notification.
30586
30587 Note that historically, MI shares the selected thread with CLI, so
30588 frontends used the @code{-thread-select} to execute commands in the
30589 right context. However, getting this to work right is cumbersome. The
30590 simplest way is for frontend to emit @code{-thread-select} command
30591 before every command. This doubles the number of commands that need
30592 to be sent. The alternative approach is to suppress @code{-thread-select}
30593 if the selected thread in @value{GDBN} is supposed to be identical to the
30594 thread the frontend wants to operate on. However, getting this
30595 optimization right can be tricky. In particular, if the frontend
30596 sends several commands to @value{GDBN}, and one of the commands changes the
30597 selected thread, then the behaviour of subsequent commands will
30598 change. So, a frontend should either wait for response from such
30599 problematic commands, or explicitly add @code{-thread-select} for
30600 all subsequent commands. No frontend is known to do this exactly
30601 right, so it is suggested to just always pass the @samp{--thread} and
30602 @samp{--frame} options.
30603
30604 @subsubsection Language
30605
30606 The execution of several commands depends on which language is selected.
30607 By default, the current language (@pxref{show language}) is used.
30608 But for commands known to be language-sensitive, it is recommended
30609 to use the @samp{--language} option. This option takes one argument,
30610 which is the name of the language to use while executing the command.
30611 For instance:
30612
30613 @smallexample
30614 -data-evaluate-expression --language c "sizeof (void*)"
30615 ^done,value="4"
30616 (gdb)
30617 @end smallexample
30618
30619 The valid language names are the same names accepted by the
30620 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
30621 @samp{local} or @samp{unknown}.
30622
30623 @node Asynchronous and non-stop modes
30624 @subsection Asynchronous command execution and non-stop mode
30625
30626 On some targets, @value{GDBN} is capable of processing MI commands
30627 even while the target is running. This is called @dfn{asynchronous
30628 command execution} (@pxref{Background Execution}). The frontend may
30629 specify a preference for asynchronous execution using the
30630 @code{-gdb-set mi-async 1} command, which should be emitted before
30631 either running the executable or attaching to the target. After the
30632 frontend has started the executable or attached to the target, it can
30633 find if asynchronous execution is enabled using the
30634 @code{-list-target-features} command.
30635
30636 @table @code
30637 @cindex foreground execution
30638 @cindex background execution
30639 @cindex asynchronous execution
30640 @cindex execution, foreground, background and asynchronous
30641 @kindex set mi-async
30642 @item -gdb-set mi-async @r{[}on@r{|}off@r{]}
30643 Set whether MI is in asynchronous mode.
30644
30645 When @code{off}, which is the default, MI execution commands (e.g.,
30646 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
30647 for the program to stop before processing further commands.
30648
30649 When @code{on}, MI execution commands are background execution
30650 commands (e.g., @code{-exec-continue} becomes the equivalent of the
30651 @code{c&} CLI command), and so @value{GDBN} is capable of processing
30652 MI commands even while the target is running.
30653
30654 @kindex show mi-async
30655 @item -gdb-show mi-async
30656 Show whether MI asynchronous mode is enabled.
30657 @end table
30658
30659 Note: In @value{GDBN} version 7.7 and earlier, this option was called
30660 @code{target-async} instead of @code{mi-async}, and it had the effect
30661 of both putting MI in asynchronous mode and making CLI background
30662 commands possible. CLI background commands are now always possible
30663 ``out of the box'' if the target supports them. The old spelling is
30664 kept as a deprecated alias for backwards compatibility.
30665
30666 Even if @value{GDBN} can accept a command while target is running,
30667 many commands that access the target do not work when the target is
30668 running. Therefore, asynchronous command execution is most useful
30669 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
30670 it is possible to examine the state of one thread, while other threads
30671 are running.
30672
30673 When a given thread is running, MI commands that try to access the
30674 target in the context of that thread may not work, or may work only on
30675 some targets. In particular, commands that try to operate on thread's
30676 stack will not work, on any target. Commands that read memory, or
30677 modify breakpoints, may work or not work, depending on the target. Note
30678 that even commands that operate on global state, such as @code{print},
30679 @code{set}, and breakpoint commands, still access the target in the
30680 context of a specific thread, so frontend should try to find a
30681 stopped thread and perform the operation on that thread (using the
30682 @samp{--thread} option).
30683
30684 Which commands will work in the context of a running thread is
30685 highly target dependent. However, the two commands
30686 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
30687 to find the state of a thread, will always work.
30688
30689 @node Thread groups
30690 @subsection Thread groups
30691 @value{GDBN} may be used to debug several processes at the same time.
30692 On some platforms, @value{GDBN} may support debugging of several
30693 hardware systems, each one having several cores with several different
30694 processes running on each core. This section describes the MI
30695 mechanism to support such debugging scenarios.
30696
30697 The key observation is that regardless of the structure of the
30698 target, MI can have a global list of threads, because most commands that
30699 accept the @samp{--thread} option do not need to know what process that
30700 thread belongs to. Therefore, it is not necessary to introduce
30701 neither additional @samp{--process} option, nor an notion of the
30702 current process in the MI interface. The only strictly new feature
30703 that is required is the ability to find how the threads are grouped
30704 into processes.
30705
30706 To allow the user to discover such grouping, and to support arbitrary
30707 hierarchy of machines/cores/processes, MI introduces the concept of a
30708 @dfn{thread group}. Thread group is a collection of threads and other
30709 thread groups. A thread group always has a string identifier, a type,
30710 and may have additional attributes specific to the type. A new
30711 command, @code{-list-thread-groups}, returns the list of top-level
30712 thread groups, which correspond to processes that @value{GDBN} is
30713 debugging at the moment. By passing an identifier of a thread group
30714 to the @code{-list-thread-groups} command, it is possible to obtain
30715 the members of specific thread group.
30716
30717 To allow the user to easily discover processes, and other objects, he
30718 wishes to debug, a concept of @dfn{available thread group} is
30719 introduced. Available thread group is an thread group that
30720 @value{GDBN} is not debugging, but that can be attached to, using the
30721 @code{-target-attach} command. The list of available top-level thread
30722 groups can be obtained using @samp{-list-thread-groups --available}.
30723 In general, the content of a thread group may be only retrieved only
30724 after attaching to that thread group.
30725
30726 Thread groups are related to inferiors (@pxref{Inferiors Connections and
30727 Programs}). Each inferior corresponds to a thread group of a special
30728 type @samp{process}, and some additional operations are permitted on
30729 such thread groups.
30730
30731 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30732 @node GDB/MI Command Syntax
30733 @section @sc{gdb/mi} Command Syntax
30734
30735 @menu
30736 * GDB/MI Input Syntax::
30737 * GDB/MI Output Syntax::
30738 @end menu
30739
30740 @node GDB/MI Input Syntax
30741 @subsection @sc{gdb/mi} Input Syntax
30742
30743 @cindex input syntax for @sc{gdb/mi}
30744 @cindex @sc{gdb/mi}, input syntax
30745 @table @code
30746 @item @var{command} @expansion{}
30747 @code{@var{cli-command} | @var{mi-command}}
30748
30749 @item @var{cli-command} @expansion{}
30750 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
30751 @var{cli-command} is any existing @value{GDBN} CLI command.
30752
30753 @item @var{mi-command} @expansion{}
30754 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
30755 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
30756
30757 @item @var{token} @expansion{}
30758 "any sequence of digits"
30759
30760 @item @var{option} @expansion{}
30761 @code{"-" @var{parameter} [ " " @var{parameter} ]}
30762
30763 @item @var{parameter} @expansion{}
30764 @code{@var{non-blank-sequence} | @var{c-string}}
30765
30766 @item @var{operation} @expansion{}
30767 @emph{any of the operations described in this chapter}
30768
30769 @item @var{non-blank-sequence} @expansion{}
30770 @emph{anything, provided it doesn't contain special characters such as
30771 "-", @var{nl}, """ and of course " "}
30772
30773 @item @var{c-string} @expansion{}
30774 @code{""" @var{seven-bit-iso-c-string-content} """}
30775
30776 @item @var{nl} @expansion{}
30777 @code{CR | CR-LF}
30778 @end table
30779
30780 @noindent
30781 Notes:
30782
30783 @itemize @bullet
30784 @item
30785 The CLI commands are still handled by the @sc{mi} interpreter; their
30786 output is described below.
30787
30788 @item
30789 The @code{@var{token}}, when present, is passed back when the command
30790 finishes.
30791
30792 @item
30793 Some @sc{mi} commands accept optional arguments as part of the parameter
30794 list. Each option is identified by a leading @samp{-} (dash) and may be
30795 followed by an optional argument parameter. Options occur first in the
30796 parameter list and can be delimited from normal parameters using
30797 @samp{--} (this is useful when some parameters begin with a dash).
30798 @end itemize
30799
30800 Pragmatics:
30801
30802 @itemize @bullet
30803 @item
30804 We want easy access to the existing CLI syntax (for debugging).
30805
30806 @item
30807 We want it to be easy to spot a @sc{mi} operation.
30808 @end itemize
30809
30810 @node GDB/MI Output Syntax
30811 @subsection @sc{gdb/mi} Output Syntax
30812
30813 @cindex output syntax of @sc{gdb/mi}
30814 @cindex @sc{gdb/mi}, output syntax
30815 The output from @sc{gdb/mi} consists of zero or more out-of-band records
30816 followed, optionally, by a single result record. This result record
30817 is for the most recent command. The sequence of output records is
30818 terminated by @samp{(gdb)}.
30819
30820 If an input command was prefixed with a @code{@var{token}} then the
30821 corresponding output for that command will also be prefixed by that same
30822 @var{token}.
30823
30824 @table @code
30825 @item @var{output} @expansion{}
30826 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
30827
30828 @item @var{result-record} @expansion{}
30829 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
30830
30831 @item @var{out-of-band-record} @expansion{}
30832 @code{@var{async-record} | @var{stream-record}}
30833
30834 @item @var{async-record} @expansion{}
30835 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
30836
30837 @item @var{exec-async-output} @expansion{}
30838 @code{[ @var{token} ] "*" @var{async-output nl}}
30839
30840 @item @var{status-async-output} @expansion{}
30841 @code{[ @var{token} ] "+" @var{async-output nl}}
30842
30843 @item @var{notify-async-output} @expansion{}
30844 @code{[ @var{token} ] "=" @var{async-output nl}}
30845
30846 @item @var{async-output} @expansion{}
30847 @code{@var{async-class} ( "," @var{result} )*}
30848
30849 @item @var{result-class} @expansion{}
30850 @code{"done" | "running" | "connected" | "error" | "exit"}
30851
30852 @item @var{async-class} @expansion{}
30853 @code{"stopped" | @var{others}} (where @var{others} will be added
30854 depending on the needs---this is still in development).
30855
30856 @item @var{result} @expansion{}
30857 @code{ @var{variable} "=" @var{value}}
30858
30859 @item @var{variable} @expansion{}
30860 @code{ @var{string} }
30861
30862 @item @var{value} @expansion{}
30863 @code{ @var{const} | @var{tuple} | @var{list} }
30864
30865 @item @var{const} @expansion{}
30866 @code{@var{c-string}}
30867
30868 @item @var{tuple} @expansion{}
30869 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
30870
30871 @item @var{list} @expansion{}
30872 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
30873 @var{result} ( "," @var{result} )* "]" }
30874
30875 @item @var{stream-record} @expansion{}
30876 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
30877
30878 @item @var{console-stream-output} @expansion{}
30879 @code{"~" @var{c-string nl}}
30880
30881 @item @var{target-stream-output} @expansion{}
30882 @code{"@@" @var{c-string nl}}
30883
30884 @item @var{log-stream-output} @expansion{}
30885 @code{"&" @var{c-string nl}}
30886
30887 @item @var{nl} @expansion{}
30888 @code{CR | CR-LF}
30889
30890 @item @var{token} @expansion{}
30891 @emph{any sequence of digits}.
30892 @end table
30893
30894 @noindent
30895 Notes:
30896
30897 @itemize @bullet
30898 @item
30899 All output sequences end in a single line containing a period.
30900
30901 @item
30902 The @code{@var{token}} is from the corresponding request. Note that
30903 for all async output, while the token is allowed by the grammar and
30904 may be output by future versions of @value{GDBN} for select async
30905 output messages, it is generally omitted. Frontends should treat
30906 all async output as reporting general changes in the state of the
30907 target and there should be no need to associate async output to any
30908 prior command.
30909
30910 @item
30911 @cindex status output in @sc{gdb/mi}
30912 @var{status-async-output} contains on-going status information about the
30913 progress of a slow operation. It can be discarded. All status output is
30914 prefixed by @samp{+}.
30915
30916 @item
30917 @cindex async output in @sc{gdb/mi}
30918 @var{exec-async-output} contains asynchronous state change on the target
30919 (stopped, started, disappeared). All async output is prefixed by
30920 @samp{*}.
30921
30922 @item
30923 @cindex notify output in @sc{gdb/mi}
30924 @var{notify-async-output} contains supplementary information that the
30925 client should handle (e.g., a new breakpoint information). All notify
30926 output is prefixed by @samp{=}.
30927
30928 @item
30929 @cindex console output in @sc{gdb/mi}
30930 @var{console-stream-output} is output that should be displayed as is in the
30931 console. It is the textual response to a CLI command. All the console
30932 output is prefixed by @samp{~}.
30933
30934 @item
30935 @cindex target output in @sc{gdb/mi}
30936 @var{target-stream-output} is the output produced by the target program.
30937 All the target output is prefixed by @samp{@@}.
30938
30939 @item
30940 @cindex log output in @sc{gdb/mi}
30941 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
30942 instance messages that should be displayed as part of an error log. All
30943 the log output is prefixed by @samp{&}.
30944
30945 @item
30946 @cindex list output in @sc{gdb/mi}
30947 New @sc{gdb/mi} commands should only output @var{lists} containing
30948 @var{values}.
30949
30950
30951 @end itemize
30952
30953 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
30954 details about the various output records.
30955
30956 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30957 @node GDB/MI Compatibility with CLI
30958 @section @sc{gdb/mi} Compatibility with CLI
30959
30960 @cindex compatibility, @sc{gdb/mi} and CLI
30961 @cindex @sc{gdb/mi}, compatibility with CLI
30962
30963 For the developers convenience CLI commands can be entered directly,
30964 but there may be some unexpected behaviour. For example, commands
30965 that query the user will behave as if the user replied yes, breakpoint
30966 command lists are not executed and some CLI commands, such as
30967 @code{if}, @code{when} and @code{define}, prompt for further input with
30968 @samp{>}, which is not valid MI output.
30969
30970 This feature may be removed at some stage in the future and it is
30971 recommended that front ends use the @code{-interpreter-exec} command
30972 (@pxref{-interpreter-exec}).
30973
30974 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30975 @node GDB/MI Development and Front Ends
30976 @section @sc{gdb/mi} Development and Front Ends
30977 @cindex @sc{gdb/mi} development
30978
30979 The application which takes the MI output and presents the state of the
30980 program being debugged to the user is called a @dfn{front end}.
30981
30982 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
30983 to the MI interface may break existing usage. This section describes how the
30984 protocol changes and how to request previous version of the protocol when it
30985 does.
30986
30987 Some changes in MI need not break a carefully designed front end, and
30988 for these the MI version will remain unchanged. The following is a
30989 list of changes that may occur within one level, so front ends should
30990 parse MI output in a way that can handle them:
30991
30992 @itemize @bullet
30993 @item
30994 New MI commands may be added.
30995
30996 @item
30997 New fields may be added to the output of any MI command.
30998
30999 @item
31000 The range of values for fields with specified values, e.g.,
31001 @code{in_scope} (@pxref{-var-update}) may be extended.
31002
31003 @c The format of field's content e.g type prefix, may change so parse it
31004 @c at your own risk. Yes, in general?
31005
31006 @c The order of fields may change? Shouldn't really matter but it might
31007 @c resolve inconsistencies.
31008 @end itemize
31009
31010 If the changes are likely to break front ends, the MI version level
31011 will be increased by one. The new versions of the MI protocol are not compatible
31012 with the old versions. Old versions of MI remain available, allowing front ends
31013 to keep using them until they are modified to use the latest MI version.
31014
31015 Since @code{--interpreter=mi} always points to the latest MI version, it is
31016 recommended that front ends request a specific version of MI when launching
31017 @value{GDBN} (e.g.@: @code{--interpreter=mi2}) to make sure they get an
31018 interpreter with the MI version they expect.
31019
31020 The following table gives a summary of the released versions of the MI
31021 interface: the version number, the version of GDB in which it first appeared
31022 and the breaking changes compared to the previous version.
31023
31024 @multitable @columnfractions .1 .1 .8
31025 @headitem MI version @tab GDB version @tab Breaking changes
31026
31027 @item
31028 @center 1
31029 @tab
31030 @center 5.1
31031 @tab
31032 None
31033
31034 @item
31035 @center 2
31036 @tab
31037 @center 6.0
31038 @tab
31039
31040 @itemize
31041 @item
31042 The @code{-environment-pwd}, @code{-environment-directory} and
31043 @code{-environment-path} commands now returns values using the MI output
31044 syntax, rather than CLI output syntax.
31045
31046 @item
31047 @code{-var-list-children}'s @code{children} result field is now a list, rather
31048 than a tuple.
31049
31050 @item
31051 @code{-var-update}'s @code{changelist} result field is now a list, rather than
31052 a tuple.
31053 @end itemize
31054
31055 @item
31056 @center 3
31057 @tab
31058 @center 9.1
31059 @tab
31060
31061 @itemize
31062 @item
31063 The output of information about multi-location breakpoints has changed in the
31064 responses to the @code{-break-insert} and @code{-break-info} commands, as well
31065 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
31066 The multiple locations are now placed in a @code{locations} field, whose value
31067 is a list.
31068 @end itemize
31069
31070 @item
31071 @center 4
31072 @tab
31073 @center 13.1
31074 @tab
31075
31076 @itemize
31077 @item
31078 The syntax of the "script" field in breakpoint output has changed in the
31079 responses to the @code{-break-insert} and @code{-break-info} commands, as
31080 well as the @code{=breakpoint-created} and @code{=breakpoint-modified}
31081 events. The previous output was syntactically invalid. The new output is
31082 a list.
31083 @end itemize
31084
31085 @end multitable
31086
31087 If your front end cannot yet migrate to a more recent version of the
31088 MI protocol, you can nevertheless selectively enable specific features
31089 available in those recent MI versions, using the following commands:
31090
31091 @table @code
31092
31093 @item -fix-multi-location-breakpoint-output
31094 Use the output for multi-location breakpoints which was introduced by
31095 MI 3, even when using MI versions below 3. This command has no
31096 effect when using MI version 3 or later.
31097
31098 @item -fix-breakpoint-script-output
31099 Use the output for the breakpoint "script" field which was introduced by
31100 MI 4, even when using MI versions below 4. This command has no effect when
31101 using MI version 4 or later.
31102
31103 @end table
31104
31105 The best way to avoid unexpected changes in MI that might break your front
31106 end is to make your project known to @value{GDBN} developers and
31107 follow development on @email{gdb@@sourceware.org} and
31108 @email{gdb-patches@@sourceware.org}.
31109 @cindex mailing lists
31110
31111 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31112 @node GDB/MI Output Records
31113 @section @sc{gdb/mi} Output Records
31114
31115 @menu
31116 * GDB/MI Result Records::
31117 * GDB/MI Stream Records::
31118 * GDB/MI Async Records::
31119 * GDB/MI Breakpoint Information::
31120 * GDB/MI Frame Information::
31121 * GDB/MI Thread Information::
31122 * GDB/MI Ada Exception Information::
31123 @end menu
31124
31125 @node GDB/MI Result Records
31126 @subsection @sc{gdb/mi} Result Records
31127
31128 @cindex result records in @sc{gdb/mi}
31129 @cindex @sc{gdb/mi}, result records
31130 In addition to a number of out-of-band notifications, the response to a
31131 @sc{gdb/mi} command includes one of the following result indications:
31132
31133 @table @code
31134 @findex ^done
31135 @item "^done" [ "," @var{results} ]
31136 The synchronous operation was successful, @code{@var{results}} are the return
31137 values.
31138
31139 @findex ^running
31140 @item "^running"
31141 This result record is equivalent to @samp{^done}. Historically, it
31142 was output instead of @samp{^done} if the command has resumed the
31143 target. This behaviour is maintained for backward compatibility, but
31144 all frontends should treat @samp{^done} and @samp{^running}
31145 identically and rely on the @samp{*running} output record to determine
31146 which threads are resumed.
31147
31148 @findex ^connected
31149 @item "^connected"
31150 @value{GDBN} has connected to a remote target.
31151
31152 @findex ^error
31153 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
31154 The operation failed. The @code{msg=@var{c-string}} variable contains
31155 the corresponding error message.
31156
31157 If present, the @code{code=@var{c-string}} variable provides an error
31158 code on which consumers can rely on to detect the corresponding
31159 error condition. At present, only one error code is defined:
31160
31161 @table @samp
31162 @item "undefined-command"
31163 Indicates that the command causing the error does not exist.
31164 @end table
31165
31166 @findex ^exit
31167 @item "^exit"
31168 @value{GDBN} has terminated.
31169
31170 @end table
31171
31172 @node GDB/MI Stream Records
31173 @subsection @sc{gdb/mi} Stream Records
31174
31175 @cindex @sc{gdb/mi}, stream records
31176 @cindex stream records in @sc{gdb/mi}
31177 @value{GDBN} internally maintains a number of output streams: the console, the
31178 target, and the log. The output intended for each of these streams is
31179 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
31180
31181 Each stream record begins with a unique @dfn{prefix character} which
31182 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
31183 Syntax}). In addition to the prefix, each stream record contains a
31184 @code{@var{string-output}}. This is either raw text (with an implicit new
31185 line) or a quoted C string (which does not contain an implicit newline).
31186
31187 @table @code
31188 @item "~" @var{string-output}
31189 The console output stream contains text that should be displayed in the
31190 CLI console window. It contains the textual responses to CLI commands.
31191
31192 @item "@@" @var{string-output}
31193 The target output stream contains any textual output from the running
31194 target. This is only present when GDB's event loop is truly
31195 asynchronous, which is currently only the case for remote targets.
31196
31197 @item "&" @var{string-output}
31198 The log stream contains debugging messages being produced by @value{GDBN}'s
31199 internals.
31200 @end table
31201
31202 @node GDB/MI Async Records
31203 @subsection @sc{gdb/mi} Async Records
31204
31205 @cindex async records in @sc{gdb/mi}
31206 @cindex @sc{gdb/mi}, async records
31207 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
31208 additional changes that have occurred. Those changes can either be a
31209 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
31210 target activity (e.g., target stopped).
31211
31212 The following is the list of possible async records:
31213
31214 @table @code
31215
31216 @item *running,thread-id="@var{thread}"
31217 The target is now running. The @var{thread} field can be the global
31218 thread ID of the thread that is now running, and it can be
31219 @samp{all} if all threads are running. The frontend should assume
31220 that no interaction with a running thread is possible after this
31221 notification is produced. The frontend should not assume that this
31222 notification is output only once for any command. @value{GDBN} may
31223 emit this notification several times, either for different threads,
31224 because it cannot resume all threads together, or even for a single
31225 thread, if the thread must be stepped though some code before letting
31226 it run freely.
31227
31228 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
31229 The target has stopped. The @var{reason} field can have one of the
31230 following values:
31231
31232 @table @code
31233 @item breakpoint-hit
31234 A breakpoint was reached.
31235 @item watchpoint-trigger
31236 A watchpoint was triggered.
31237 @item read-watchpoint-trigger
31238 A read watchpoint was triggered.
31239 @item access-watchpoint-trigger
31240 An access watchpoint was triggered.
31241 @item function-finished
31242 An -exec-finish or similar CLI command was accomplished.
31243 @item location-reached
31244 An -exec-until or similar CLI command was accomplished.
31245 @item watchpoint-scope
31246 A watchpoint has gone out of scope.
31247 @item end-stepping-range
31248 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
31249 similar CLI command was accomplished.
31250 @item exited-signalled
31251 The inferior exited because of a signal.
31252 @item exited
31253 The inferior exited.
31254 @item exited-normally
31255 The inferior exited normally.
31256 @item signal-received
31257 A signal was received by the inferior.
31258 @item solib-event
31259 The inferior has stopped due to a library being loaded or unloaded.
31260 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
31261 set or when a @code{catch load} or @code{catch unload} catchpoint is
31262 in use (@pxref{Set Catchpoints}).
31263 @item fork
31264 The inferior has forked. This is reported when @code{catch fork}
31265 (@pxref{Set Catchpoints}) has been used.
31266 @item vfork
31267 The inferior has vforked. This is reported in when @code{catch vfork}
31268 (@pxref{Set Catchpoints}) has been used.
31269 @item syscall-entry
31270 The inferior entered a system call. This is reported when @code{catch
31271 syscall} (@pxref{Set Catchpoints}) has been used.
31272 @item syscall-return
31273 The inferior returned from a system call. This is reported when
31274 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
31275 @item exec
31276 The inferior called @code{exec}. This is reported when @code{catch exec}
31277 (@pxref{Set Catchpoints}) has been used.
31278 @item no-history
31279 There isn't enough history recorded to continue reverse execution.
31280 @end table
31281
31282 The @var{id} field identifies the global thread ID of the thread
31283 that directly caused the stop -- for example by hitting a breakpoint.
31284 Depending on whether all-stop
31285 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
31286 stop all threads, or only the thread that directly triggered the stop.
31287 If all threads are stopped, the @var{stopped} field will have the
31288 value of @code{"all"}. Otherwise, the value of the @var{stopped}
31289 field will be a list of thread identifiers. Presently, this list will
31290 always include a single thread, but frontend should be prepared to see
31291 several threads in the list. The @var{core} field reports the
31292 processor core on which the stop event has happened. This field may be absent
31293 if such information is not available.
31294
31295 @item =thread-group-added,id="@var{id}"
31296 @itemx =thread-group-removed,id="@var{id}"
31297 A thread group was either added or removed. The @var{id} field
31298 contains the @value{GDBN} identifier of the thread group. When a thread
31299 group is added, it generally might not be associated with a running
31300 process. When a thread group is removed, its id becomes invalid and
31301 cannot be used in any way.
31302
31303 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
31304 A thread group became associated with a running program,
31305 either because the program was just started or the thread group
31306 was attached to a program. The @var{id} field contains the
31307 @value{GDBN} identifier of the thread group. The @var{pid} field
31308 contains process identifier, specific to the operating system.
31309
31310 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
31311 A thread group is no longer associated with a running program,
31312 either because the program has exited, or because it was detached
31313 from. The @var{id} field contains the @value{GDBN} identifier of the
31314 thread group. The @var{code} field is the exit code of the inferior; it exists
31315 only when the inferior exited with some code.
31316
31317 @item =thread-created,id="@var{id}",group-id="@var{gid}"
31318 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
31319 A thread either was created, or has exited. The @var{id} field
31320 contains the global @value{GDBN} identifier of the thread. The @var{gid}
31321 field identifies the thread group this thread belongs to.
31322
31323 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
31324 Informs that the selected thread or frame were changed. This notification
31325 is not emitted as result of the @code{-thread-select} or
31326 @code{-stack-select-frame} commands, but is emitted whenever an MI command
31327 that is not documented to change the selected thread and frame actually
31328 changes them. In particular, invoking, directly or indirectly
31329 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
31330 will generate this notification. Changing the thread or frame from another
31331 user interface (see @ref{Interpreters}) will also generate this notification.
31332
31333 The @var{frame} field is only present if the newly selected thread is
31334 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
31335
31336 We suggest that in response to this notification, front ends
31337 highlight the selected thread and cause subsequent commands to apply to
31338 that thread.
31339
31340 @item =library-loaded,...
31341 Reports that a new library file was loaded by the program. This
31342 notification has 5 fields---@var{id}, @var{target-name},
31343 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
31344 opaque identifier of the library. For remote debugging case,
31345 @var{target-name} and @var{host-name} fields give the name of the
31346 library file on the target, and on the host respectively. For native
31347 debugging, both those fields have the same value. The
31348 @var{symbols-loaded} field is emitted only for backward compatibility
31349 and should not be relied on to convey any useful information. The
31350 @var{thread-group} field, if present, specifies the id of the thread
31351 group in whose context the library was loaded. If the field is
31352 absent, it means the library was loaded in the context of all present
31353 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
31354 to this library.
31355
31356 @item =library-unloaded,...
31357 Reports that a library was unloaded by the program. This notification
31358 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
31359 the same meaning as for the @code{=library-loaded} notification.
31360 The @var{thread-group} field, if present, specifies the id of the
31361 thread group in whose context the library was unloaded. If the field is
31362 absent, it means the library was unloaded in the context of all present
31363 thread groups.
31364
31365 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
31366 @itemx =traceframe-changed,end
31367 Reports that the trace frame was changed and its new number is
31368 @var{tfnum}. The number of the tracepoint associated with this trace
31369 frame is @var{tpnum}.
31370
31371 @item =tsv-created,name=@var{name},initial=@var{initial}
31372 Reports that the new trace state variable @var{name} is created with
31373 initial value @var{initial}.
31374
31375 @item =tsv-deleted,name=@var{name}
31376 @itemx =tsv-deleted
31377 Reports that the trace state variable @var{name} is deleted or all
31378 trace state variables are deleted.
31379
31380 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
31381 Reports that the trace state variable @var{name} is modified with
31382 the initial value @var{initial}. The current value @var{current} of
31383 trace state variable is optional and is reported if the current
31384 value of trace state variable is known.
31385
31386 @item =breakpoint-created,bkpt=@{...@}
31387 @itemx =breakpoint-modified,bkpt=@{...@}
31388 @itemx =breakpoint-deleted,id=@var{number}
31389 Reports that a breakpoint was created, modified, or deleted,
31390 respectively. Only user-visible breakpoints are reported to the MI
31391 user.
31392
31393 The @var{bkpt} argument is of the same form as returned by the various
31394 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
31395 @var{number} is the ordinal number of the breakpoint.
31396
31397 Note that if a breakpoint is emitted in the result record of a
31398 command, then it will not also be emitted in an async record.
31399
31400 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
31401 @itemx =record-stopped,thread-group="@var{id}"
31402 Execution log recording was either started or stopped on an
31403 inferior. The @var{id} is the @value{GDBN} identifier of the thread
31404 group corresponding to the affected inferior.
31405
31406 The @var{method} field indicates the method used to record execution. If the
31407 method in use supports multiple recording formats, @var{format} will be present
31408 and contain the currently used format. @xref{Process Record and Replay},
31409 for existing method and format values.
31410
31411 @item =cmd-param-changed,param=@var{param},value=@var{value}
31412 Reports that a parameter of the command @code{set @var{param}} is
31413 changed to @var{value}. In the multi-word @code{set} command,
31414 the @var{param} is the whole parameter list to @code{set} command.
31415 For example, In command @code{set check type on}, @var{param}
31416 is @code{check type} and @var{value} is @code{on}.
31417
31418 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
31419 Reports that bytes from @var{addr} to @var{data} + @var{len} were
31420 written in an inferior. The @var{id} is the identifier of the
31421 thread group corresponding to the affected inferior. The optional
31422 @code{type="code"} part is reported if the memory written to holds
31423 executable code.
31424 @end table
31425
31426 @node GDB/MI Breakpoint Information
31427 @subsection @sc{gdb/mi} Breakpoint Information
31428
31429 When @value{GDBN} reports information about a breakpoint, a
31430 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
31431 following fields:
31432
31433 @table @code
31434 @item number
31435 The breakpoint number.
31436
31437 @item type
31438 The type of the breakpoint. For ordinary breakpoints this will be
31439 @samp{breakpoint}, but many values are possible.
31440
31441 @item catch-type
31442 If the type of the breakpoint is @samp{catchpoint}, then this
31443 indicates the exact type of catchpoint.
31444
31445 @item disp
31446 This is the breakpoint disposition---either @samp{del}, meaning that
31447 the breakpoint will be deleted at the next stop, or @samp{keep},
31448 meaning that the breakpoint will not be deleted.
31449
31450 @item enabled
31451 This indicates whether the breakpoint is enabled, in which case the
31452 value is @samp{y}, or disabled, in which case the value is @samp{n}.
31453 Note that this is not the same as the field @code{enable}.
31454
31455 @item addr
31456 The address of the breakpoint. This may be a hexidecimal number,
31457 giving the address; or the string @samp{<PENDING>}, for a pending
31458 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
31459 multiple locations. This field will not be present if no address can
31460 be determined. For example, a watchpoint does not have an address.
31461
31462 @item addr_flags
31463 Optional field containing any flags related to the address. These flags are
31464 architecture-dependent; see @ref{Architectures} for their meaning for a
31465 particular CPU.
31466
31467 @item func
31468 If known, the function in which the breakpoint appears.
31469 If not known, this field is not present.
31470
31471 @item filename
31472 The name of the source file which contains this function, if known.
31473 If not known, this field is not present.
31474
31475 @item fullname
31476 The full file name of the source file which contains this function, if
31477 known. If not known, this field is not present.
31478
31479 @item line
31480 The line number at which this breakpoint appears, if known.
31481 If not known, this field is not present.
31482
31483 @item at
31484 If the source file is not known, this field may be provided. If
31485 provided, this holds the address of the breakpoint, possibly followed
31486 by a symbol name.
31487
31488 @item pending
31489 If this breakpoint is pending, this field is present and holds the
31490 text used to set the breakpoint, as entered by the user.
31491
31492 @item evaluated-by
31493 Where this breakpoint's condition is evaluated, either @samp{host} or
31494 @samp{target}.
31495
31496 @item thread
31497 If this is a thread-specific breakpoint, then this identifies the
31498 thread in which the breakpoint can trigger.
31499
31500 @item task
31501 If this breakpoint is restricted to a particular Ada task, then this
31502 field will hold the task identifier.
31503
31504 @item cond
31505 If the breakpoint is conditional, this is the condition expression.
31506
31507 @item ignore
31508 The ignore count of the breakpoint.
31509
31510 @item enable
31511 The enable count of the breakpoint.
31512
31513 @item traceframe-usage
31514 FIXME.
31515
31516 @item static-tracepoint-marker-string-id
31517 For a static tracepoint, the name of the static tracepoint marker.
31518
31519 @item mask
31520 For a masked watchpoint, this is the mask.
31521
31522 @item pass
31523 A tracepoint's pass count.
31524
31525 @item original-location
31526 The location of the breakpoint as originally specified by the user.
31527 This field is optional.
31528
31529 @item times
31530 The number of times the breakpoint has been hit.
31531
31532 @item installed
31533 This field is only given for tracepoints. This is either @samp{y},
31534 meaning that the tracepoint is installed, or @samp{n}, meaning that it
31535 is not.
31536
31537 @item what
31538 Some extra data, the exact contents of which are type-dependent.
31539
31540 @item locations
31541 This field is present if the breakpoint has multiple locations. It is also
31542 exceptionally present if the breakpoint is enabled and has a single, disabled
31543 location.
31544
31545 The value is a list of locations. The format of a location is described below.
31546
31547 @end table
31548
31549 A location in a multi-location breakpoint is represented as a tuple with the
31550 following fields:
31551
31552 @table @code
31553
31554 @item number
31555 The location number as a dotted pair, like @samp{1.2}. The first digit is the
31556 number of the parent breakpoint. The second digit is the number of the
31557 location within that breakpoint.
31558
31559 @item enabled
31560 There are three possible values, with the following meanings:
31561 @table @code
31562 @item y
31563 The location is enabled.
31564 @item n
31565 The location is disabled by the user.
31566 @item N
31567 The location is disabled because the breakpoint condition is invalid
31568 at this location.
31569 @end table
31570
31571 @item addr
31572 The address of this location as an hexidecimal number.
31573
31574 @item addr_flags
31575 Optional field containing any flags related to the address. These flags are
31576 architecture-dependent; see @ref{Architectures} for their meaning for a
31577 particular CPU.
31578
31579 @item func
31580 If known, the function in which the location appears.
31581 If not known, this field is not present.
31582
31583 @item file
31584 The name of the source file which contains this location, if known.
31585 If not known, this field is not present.
31586
31587 @item fullname
31588 The full file name of the source file which contains this location, if
31589 known. If not known, this field is not present.
31590
31591 @item line
31592 The line number at which this location appears, if known.
31593 If not known, this field is not present.
31594
31595 @item thread-groups
31596 The thread groups this location is in.
31597
31598 @end table
31599
31600 For example, here is what the output of @code{-break-insert}
31601 (@pxref{GDB/MI Breakpoint Commands}) might be:
31602
31603 @smallexample
31604 -> -break-insert main
31605 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31606 enabled="y",addr="0x08048564",func="main",file="myprog.c",
31607 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
31608 times="0"@}
31609 <- (gdb)
31610 @end smallexample
31611
31612 @node GDB/MI Frame Information
31613 @subsection @sc{gdb/mi} Frame Information
31614
31615 Response from many MI commands includes an information about stack
31616 frame. This information is a tuple that may have the following
31617 fields:
31618
31619 @table @code
31620 @item level
31621 The level of the stack frame. The innermost frame has the level of
31622 zero. This field is always present.
31623
31624 @item func
31625 The name of the function corresponding to the frame. This field may
31626 be absent if @value{GDBN} is unable to determine the function name.
31627
31628 @item addr
31629 The code address for the frame. This field is always present.
31630
31631 @item addr_flags
31632 Optional field containing any flags related to the address. These flags are
31633 architecture-dependent; see @ref{Architectures} for their meaning for a
31634 particular CPU.
31635
31636 @item file
31637 The name of the source files that correspond to the frame's code
31638 address. This field may be absent.
31639
31640 @item line
31641 The source line corresponding to the frames' code address. This field
31642 may be absent.
31643
31644 @item from
31645 The name of the binary file (either executable or shared library) the
31646 corresponds to the frame's code address. This field may be absent.
31647
31648 @end table
31649
31650 @node GDB/MI Thread Information
31651 @subsection @sc{gdb/mi} Thread Information
31652
31653 Whenever @value{GDBN} has to report an information about a thread, it
31654 uses a tuple with the following fields. The fields are always present unless
31655 stated otherwise.
31656
31657 @table @code
31658 @item id
31659 The global numeric id assigned to the thread by @value{GDBN}.
31660
31661 @item target-id
31662 The target-specific string identifying the thread.
31663
31664 @item details
31665 Additional information about the thread provided by the target.
31666 It is supposed to be human-readable and not interpreted by the
31667 frontend. This field is optional.
31668
31669 @item name
31670 The name of the thread. If the user specified a name using the
31671 @code{thread name} command, then this name is given. Otherwise, if
31672 @value{GDBN} can extract the thread name from the target, then that
31673 name is given. If @value{GDBN} cannot find the thread name, then this
31674 field is omitted.
31675
31676 @item state
31677 The execution state of the thread, either @samp{stopped} or @samp{running},
31678 depending on whether the thread is presently running.
31679
31680 @item frame
31681 The stack frame currently executing in the thread. This field is only present
31682 if the thread is stopped. Its format is documented in
31683 @ref{GDB/MI Frame Information}.
31684
31685 @item core
31686 The value of this field is an integer number of the processor core the
31687 thread was last seen on. This field is optional.
31688 @end table
31689
31690 @node GDB/MI Ada Exception Information
31691 @subsection @sc{gdb/mi} Ada Exception Information
31692
31693 Whenever a @code{*stopped} record is emitted because the program
31694 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
31695 @value{GDBN} provides the name of the exception that was raised via
31696 the @code{exception-name} field. Also, for exceptions that were raised
31697 with an exception message, @value{GDBN} provides that message via
31698 the @code{exception-message} field.
31699
31700 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31701 @node GDB/MI Simple Examples
31702 @section Simple Examples of @sc{gdb/mi} Interaction
31703 @cindex @sc{gdb/mi}, simple examples
31704
31705 This subsection presents several simple examples of interaction using
31706 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
31707 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
31708 the output received from @sc{gdb/mi}.
31709
31710 Note the line breaks shown in the examples are here only for
31711 readability, they don't appear in the real output.
31712
31713 @subheading Setting a Breakpoint
31714
31715 Setting a breakpoint generates synchronous output which contains detailed
31716 information of the breakpoint.
31717
31718 @smallexample
31719 -> -break-insert main
31720 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31721 enabled="y",addr="0x08048564",func="main",file="myprog.c",
31722 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
31723 times="0"@}
31724 <- (gdb)
31725 @end smallexample
31726
31727 @subheading Program Execution
31728
31729 Program execution generates asynchronous records and MI gives the
31730 reason that execution stopped.
31731
31732 @smallexample
31733 -> -exec-run
31734 <- ^running
31735 <- (gdb)
31736 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
31737 frame=@{addr="0x08048564",func="main",
31738 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
31739 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
31740 arch="i386:x86_64"@}
31741 <- (gdb)
31742 -> -exec-continue
31743 <- ^running
31744 <- (gdb)
31745 <- *stopped,reason="exited-normally"
31746 <- (gdb)
31747 @end smallexample
31748
31749 @subheading Quitting @value{GDBN}
31750
31751 Quitting @value{GDBN} just prints the result class @samp{^exit}.
31752
31753 @smallexample
31754 -> (gdb)
31755 <- -gdb-exit
31756 <- ^exit
31757 @end smallexample
31758
31759 Please note that @samp{^exit} is printed immediately, but it might
31760 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
31761 performs necessary cleanups, including killing programs being debugged
31762 or disconnecting from debug hardware, so the frontend should wait till
31763 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
31764 fails to exit in reasonable time.
31765
31766 @subheading A Bad Command
31767
31768 Here's what happens if you pass a non-existent command:
31769
31770 @smallexample
31771 -> -rubbish
31772 <- ^error,msg="Undefined MI command: rubbish"
31773 <- (gdb)
31774 @end smallexample
31775
31776
31777 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31778 @node GDB/MI Command Description Format
31779 @section @sc{gdb/mi} Command Description Format
31780
31781 The remaining sections describe blocks of commands. Each block of
31782 commands is laid out in a fashion similar to this section.
31783
31784 @subheading Motivation
31785
31786 The motivation for this collection of commands.
31787
31788 @subheading Introduction
31789
31790 A brief introduction to this collection of commands as a whole.
31791
31792 @subheading Commands
31793
31794 For each command in the block, the following is described:
31795
31796 @subsubheading Synopsis
31797
31798 @smallexample
31799 -command @var{args}@dots{}
31800 @end smallexample
31801
31802 @subsubheading Result
31803
31804 @subsubheading @value{GDBN} Command
31805
31806 The corresponding @value{GDBN} CLI command(s), if any.
31807
31808 @subsubheading Example
31809
31810 Example(s) formatted for readability. Some of the described commands have
31811 not been implemented yet and these are labeled N.A.@: (not available).
31812
31813
31814 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31815 @node GDB/MI Breakpoint Commands
31816 @section @sc{gdb/mi} Breakpoint Commands
31817
31818 @cindex breakpoint commands for @sc{gdb/mi}
31819 @cindex @sc{gdb/mi}, breakpoint commands
31820 This section documents @sc{gdb/mi} commands for manipulating
31821 breakpoints.
31822
31823 @findex -break-after
31824 @subheading The @code{-break-after} Command
31825
31826 @subsubheading Synopsis
31827
31828 @smallexample
31829 -break-after @var{number} @var{count}
31830 @end smallexample
31831
31832 The breakpoint number @var{number} is not in effect until it has been
31833 hit @var{count} times. To see how this is reflected in the output of
31834 the @samp{-break-list} command, see the description of the
31835 @samp{-break-list} command below.
31836
31837 @subsubheading @value{GDBN} Command
31838
31839 The corresponding @value{GDBN} command is @samp{ignore}.
31840
31841 @subsubheading Example
31842
31843 @smallexample
31844 (gdb)
31845 -break-insert main
31846 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31847 enabled="y",addr="0x000100d0",func="main",file="hello.c",
31848 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
31849 times="0"@}
31850 (gdb)
31851 -break-after 1 3
31852 ~
31853 ^done
31854 (gdb)
31855 -break-list
31856 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31857 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31858 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31859 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31860 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31861 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31862 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31863 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31864 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31865 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
31866 (gdb)
31867 @end smallexample
31868
31869 @ignore
31870 @findex -break-catch
31871 @subheading The @code{-break-catch} Command
31872 @end ignore
31873
31874 @findex -break-commands
31875 @subheading The @code{-break-commands} Command
31876
31877 @subsubheading Synopsis
31878
31879 @smallexample
31880 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
31881 @end smallexample
31882
31883 Specifies the CLI commands that should be executed when breakpoint
31884 @var{number} is hit. The parameters @var{command1} to @var{commandN}
31885 are the commands. If no command is specified, any previously-set
31886 commands are cleared. @xref{Break Commands}. Typical use of this
31887 functionality is tracing a program, that is, printing of values of
31888 some variables whenever breakpoint is hit and then continuing.
31889
31890 @subsubheading @value{GDBN} Command
31891
31892 The corresponding @value{GDBN} command is @samp{commands}.
31893
31894 @subsubheading Example
31895
31896 @smallexample
31897 (gdb)
31898 -break-insert main
31899 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31900 enabled="y",addr="0x000100d0",func="main",file="hello.c",
31901 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
31902 times="0"@}
31903 (gdb)
31904 -break-commands 1 "print v" "continue"
31905 ^done
31906 (gdb)
31907 @end smallexample
31908
31909 @findex -break-condition
31910 @subheading The @code{-break-condition} Command
31911
31912 @subsubheading Synopsis
31913
31914 @smallexample
31915 -break-condition [ --force ] @var{number} [ @var{expr} ]
31916 @end smallexample
31917
31918 Breakpoint @var{number} will stop the program only if the condition in
31919 @var{expr} is true. The condition becomes part of the
31920 @samp{-break-list} output (see the description of the @samp{-break-list}
31921 command below). If the @samp{--force} flag is passed, the condition
31922 is forcibly defined even when it is invalid for all locations of
31923 breakpoint @var{number}. If the @var{expr} argument is omitted,
31924 breakpoint @var{number} becomes unconditional.
31925
31926 @subsubheading @value{GDBN} Command
31927
31928 The corresponding @value{GDBN} command is @samp{condition}.
31929
31930 @subsubheading Example
31931
31932 @smallexample
31933 (gdb)
31934 -break-condition 1 1
31935 ^done
31936 (gdb)
31937 -break-list
31938 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31939 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31940 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31941 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31942 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31943 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31944 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31945 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31946 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31947 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
31948 (gdb)
31949 @end smallexample
31950
31951 @findex -break-delete
31952 @subheading The @code{-break-delete} Command
31953
31954 @subsubheading Synopsis
31955
31956 @smallexample
31957 -break-delete ( @var{breakpoint} )+
31958 @end smallexample
31959
31960 Delete the breakpoint(s) whose number(s) are specified in the argument
31961 list. This is obviously reflected in the breakpoint list.
31962
31963 @subsubheading @value{GDBN} Command
31964
31965 The corresponding @value{GDBN} command is @samp{delete}.
31966
31967 @subsubheading Example
31968
31969 @smallexample
31970 (gdb)
31971 -break-delete 1
31972 ^done
31973 (gdb)
31974 -break-list
31975 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
31976 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31977 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31978 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31979 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31980 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31981 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31982 body=[]@}
31983 (gdb)
31984 @end smallexample
31985
31986 @findex -break-disable
31987 @subheading The @code{-break-disable} Command
31988
31989 @subsubheading Synopsis
31990
31991 @smallexample
31992 -break-disable ( @var{breakpoint} )+
31993 @end smallexample
31994
31995 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
31996 break list is now set to @samp{n} for the named @var{breakpoint}(s).
31997
31998 @subsubheading @value{GDBN} Command
31999
32000 The corresponding @value{GDBN} command is @samp{disable}.
32001
32002 @subsubheading Example
32003
32004 @smallexample
32005 (gdb)
32006 -break-disable 2
32007 ^done
32008 (gdb)
32009 -break-list
32010 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
32011 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32012 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32013 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32014 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32015 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32016 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32017 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
32018 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
32019 line="5",thread-groups=["i1"],times="0"@}]@}
32020 (gdb)
32021 @end smallexample
32022
32023 @findex -break-enable
32024 @subheading The @code{-break-enable} Command
32025
32026 @subsubheading Synopsis
32027
32028 @smallexample
32029 -break-enable ( @var{breakpoint} )+
32030 @end smallexample
32031
32032 Enable (previously disabled) @var{breakpoint}(s).
32033
32034 @subsubheading @value{GDBN} Command
32035
32036 The corresponding @value{GDBN} command is @samp{enable}.
32037
32038 @subsubheading Example
32039
32040 @smallexample
32041 (gdb)
32042 -break-enable 2
32043 ^done
32044 (gdb)
32045 -break-list
32046 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
32047 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32048 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32049 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32050 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32051 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32052 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32053 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
32054 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
32055 line="5",thread-groups=["i1"],times="0"@}]@}
32056 (gdb)
32057 @end smallexample
32058
32059 @findex -break-info
32060 @subheading The @code{-break-info} Command
32061
32062 @subsubheading Synopsis
32063
32064 @smallexample
32065 -break-info @var{breakpoint}
32066 @end smallexample
32067
32068 @c REDUNDANT???
32069 Get information about a single breakpoint.
32070
32071 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
32072 Information}, for details on the format of each breakpoint in the
32073 table.
32074
32075 @subsubheading @value{GDBN} Command
32076
32077 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
32078
32079 @subsubheading Example
32080 N.A.
32081
32082 @findex -break-insert
32083 @anchor{-break-insert}
32084 @subheading The @code{-break-insert} Command
32085
32086 @subsubheading Synopsis
32087
32088 @smallexample
32089 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
32090 [ -c @var{condition} ] [ --force-condition ] [ -i @var{ignore-count} ]
32091 [ -p @var{thread-id} ] [ @var{locspec} ]
32092 @end smallexample
32093
32094 @noindent
32095 If specified, @var{locspec}, can be one of:
32096
32097 @table @var
32098 @item linespec location
32099 A linespec location. @xref{Linespec Locations}.
32100
32101 @item explicit location
32102 An explicit location. @sc{gdb/mi} explicit locations are
32103 analogous to the CLI's explicit locations using the option names
32104 listed below. @xref{Explicit Locations}.
32105
32106 @table @samp
32107 @item --source @var{filename}
32108 The source file name of the location. This option requires the use
32109 of either @samp{--function} or @samp{--line}.
32110
32111 @item --function @var{function}
32112 The name of a function or method.
32113
32114 @item --label @var{label}
32115 The name of a label.
32116
32117 @item --line @var{lineoffset}
32118 An absolute or relative line offset from the start of the location.
32119 @end table
32120
32121 @item address location
32122 An address location, *@var{address}. @xref{Address Locations}.
32123 @end table
32124
32125 @noindent
32126 The possible optional parameters of this command are:
32127
32128 @table @samp
32129 @item -t
32130 Insert a temporary breakpoint.
32131 @item -h
32132 Insert a hardware breakpoint.
32133 @item -f
32134 If @var{locspec} cannot be resolved (for example if it
32135 refers to unknown files or functions), create a pending
32136 breakpoint. Without this flag, @value{GDBN} will report
32137 an error, and won't create a breakpoint, if @var{locspec}
32138 cannot be parsed.
32139 @item -d
32140 Create a disabled breakpoint.
32141 @item -a
32142 Create a tracepoint. @xref{Tracepoints}. When this parameter
32143 is used together with @samp{-h}, a fast tracepoint is created.
32144 @item -c @var{condition}
32145 Make the breakpoint conditional on @var{condition}.
32146 @item --force-condition
32147 Forcibly define the breakpoint even if the condition is invalid at
32148 all of the breakpoint locations.
32149 @item -i @var{ignore-count}
32150 Initialize the @var{ignore-count}.
32151 @item -p @var{thread-id}
32152 Restrict the breakpoint to the thread with the specified global
32153 @var{thread-id}.
32154 @item --qualified
32155 This option makes @value{GDBN} interpret a function name specified as
32156 a complete fully-qualified name.
32157 @end table
32158
32159 @subsubheading Result
32160
32161 @xref{GDB/MI Breakpoint Information}, for details on the format of the
32162 resulting breakpoint.
32163
32164 Note: this format is open to change.
32165 @c An out-of-band breakpoint instead of part of the result?
32166
32167 @subsubheading @value{GDBN} Command
32168
32169 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
32170 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
32171
32172 @subsubheading Example
32173
32174 @smallexample
32175 (gdb)
32176 -break-insert main
32177 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
32178 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
32179 times="0"@}
32180 (gdb)
32181 -break-insert -t foo
32182 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
32183 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
32184 times="0"@}
32185 (gdb)
32186 -break-list
32187 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
32188 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32189 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32190 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32191 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32192 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32193 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32194 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32195 addr="0x0001072c", func="main",file="recursive2.c",
32196 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
32197 times="0"@},
32198 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
32199 addr="0x00010774",func="foo",file="recursive2.c",
32200 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
32201 times="0"@}]@}
32202 (gdb)
32203 @end smallexample
32204
32205 @findex -dprintf-insert
32206 @subheading The @code{-dprintf-insert} Command
32207
32208 @subsubheading Synopsis
32209
32210 @smallexample
32211 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
32212 [ -c @var{condition} ] [--force-condition] [ -i @var{ignore-count} ]
32213 [ -p @var{thread-id} ] [ @var{locspec} ] [ @var{format} ]
32214 [ @var{argument} ]
32215 @end smallexample
32216
32217 @noindent
32218 If supplied, @var{locspec} and @code{--qualified} may be specified
32219 the same way as for the @code{-break-insert} command.
32220 @xref{-break-insert}.
32221
32222 The possible optional parameters of this command are:
32223
32224 @table @samp
32225 @item -t
32226 Insert a temporary breakpoint.
32227 @item -f
32228 If @var{locspec} cannot be parsed (for example, if it
32229 refers to unknown files or functions), create a pending
32230 breakpoint. Without this flag, @value{GDBN} will report
32231 an error, and won't create a breakpoint, if @var{locspec}
32232 cannot be parsed.
32233 @item -d
32234 Create a disabled breakpoint.
32235 @item -c @var{condition}
32236 Make the breakpoint conditional on @var{condition}.
32237 @item --force-condition
32238 Forcibly define the breakpoint even if the condition is invalid at
32239 all of the breakpoint locations.
32240 @item -i @var{ignore-count}
32241 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
32242 to @var{ignore-count}.
32243 @item -p @var{thread-id}
32244 Restrict the breakpoint to the thread with the specified global
32245 @var{thread-id}.
32246 @end table
32247
32248 @subsubheading Result
32249
32250 @xref{GDB/MI Breakpoint Information}, for details on the format of the
32251 resulting breakpoint.
32252
32253 @c An out-of-band breakpoint instead of part of the result?
32254
32255 @subsubheading @value{GDBN} Command
32256
32257 The corresponding @value{GDBN} command is @samp{dprintf}.
32258
32259 @subsubheading Example
32260
32261 @smallexample
32262 (gdb)
32263 4-dprintf-insert foo "At foo entry\n"
32264 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
32265 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
32266 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
32267 times="0",script=["printf \"At foo entry\\n\"","continue"],
32268 original-location="foo"@}
32269 (gdb)
32270 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
32271 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
32272 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
32273 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
32274 times="0",script=["printf \"arg=%d, g=%d\\n\", arg, g","continue"],
32275 original-location="mi-dprintf.c:26"@}
32276 (gdb)
32277 @end smallexample
32278
32279 @findex -break-list
32280 @subheading The @code{-break-list} Command
32281
32282 @subsubheading Synopsis
32283
32284 @smallexample
32285 -break-list
32286 @end smallexample
32287
32288 Displays the list of inserted breakpoints, showing the following fields:
32289
32290 @table @samp
32291 @item Number
32292 number of the breakpoint
32293 @item Type
32294 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
32295 @item Disposition
32296 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
32297 or @samp{nokeep}
32298 @item Enabled
32299 is the breakpoint enabled or no: @samp{y} or @samp{n}
32300 @item Address
32301 memory location at which the breakpoint is set
32302 @item What
32303 logical location of the breakpoint, expressed by function name, file
32304 name, line number
32305 @item Thread-groups
32306 list of thread groups to which this breakpoint applies
32307 @item Times
32308 number of times the breakpoint has been hit
32309 @end table
32310
32311 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
32312 @code{body} field is an empty list.
32313
32314 @subsubheading @value{GDBN} Command
32315
32316 The corresponding @value{GDBN} command is @samp{info break}.
32317
32318 @subsubheading Example
32319
32320 @smallexample
32321 (gdb)
32322 -break-list
32323 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
32324 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32325 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32326 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32327 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32328 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32329 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32330 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32331 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
32332 times="0"@},
32333 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
32334 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
32335 line="13",thread-groups=["i1"],times="0"@}]@}
32336 (gdb)
32337 @end smallexample
32338
32339 Here's an example of the result when there are no breakpoints:
32340
32341 @smallexample
32342 (gdb)
32343 -break-list
32344 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
32345 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32346 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32347 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32348 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32349 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32350 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32351 body=[]@}
32352 (gdb)
32353 @end smallexample
32354
32355 @findex -break-passcount
32356 @subheading The @code{-break-passcount} Command
32357
32358 @subsubheading Synopsis
32359
32360 @smallexample
32361 -break-passcount @var{tracepoint-number} @var{passcount}
32362 @end smallexample
32363
32364 Set the passcount for tracepoint @var{tracepoint-number} to
32365 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
32366 is not a tracepoint, error is emitted. This corresponds to CLI
32367 command @samp{passcount}.
32368
32369 @findex -break-watch
32370 @subheading The @code{-break-watch} Command
32371
32372 @subsubheading Synopsis
32373
32374 @smallexample
32375 -break-watch [ -a | -r ]
32376 @end smallexample
32377
32378 Create a watchpoint. With the @samp{-a} option it will create an
32379 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
32380 read from or on a write to the memory location. With the @samp{-r}
32381 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
32382 trigger only when the memory location is accessed for reading. Without
32383 either of the options, the watchpoint created is a regular watchpoint,
32384 i.e., it will trigger when the memory location is accessed for writing.
32385 @xref{Set Watchpoints, , Setting Watchpoints}.
32386
32387 Note that @samp{-break-list} will report a single list of watchpoints and
32388 breakpoints inserted.
32389
32390 @subsubheading @value{GDBN} Command
32391
32392 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
32393 @samp{rwatch}.
32394
32395 @subsubheading Example
32396
32397 Setting a watchpoint on a variable in the @code{main} function:
32398
32399 @smallexample
32400 (gdb)
32401 -break-watch x
32402 ^done,wpt=@{number="2",exp="x"@}
32403 (gdb)
32404 -exec-continue
32405 ^running
32406 (gdb)
32407 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
32408 value=@{old="-268439212",new="55"@},
32409 frame=@{func="main",args=[],file="recursive2.c",
32410 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
32411 (gdb)
32412 @end smallexample
32413
32414 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
32415 the program execution twice: first for the variable changing value, then
32416 for the watchpoint going out of scope.
32417
32418 @smallexample
32419 (gdb)
32420 -break-watch C
32421 ^done,wpt=@{number="5",exp="C"@}
32422 (gdb)
32423 -exec-continue
32424 ^running
32425 (gdb)
32426 *stopped,reason="watchpoint-trigger",
32427 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
32428 frame=@{func="callee4",args=[],
32429 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32430 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
32431 arch="i386:x86_64"@}
32432 (gdb)
32433 -exec-continue
32434 ^running
32435 (gdb)
32436 *stopped,reason="watchpoint-scope",wpnum="5",
32437 frame=@{func="callee3",args=[@{name="strarg",
32438 value="0x11940 \"A string argument.\""@}],
32439 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32440 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32441 arch="i386:x86_64"@}
32442 (gdb)
32443 @end smallexample
32444
32445 Listing breakpoints and watchpoints, at different points in the program
32446 execution. Note that once the watchpoint goes out of scope, it is
32447 deleted.
32448
32449 @smallexample
32450 (gdb)
32451 -break-watch C
32452 ^done,wpt=@{number="2",exp="C"@}
32453 (gdb)
32454 -break-list
32455 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
32456 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32457 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32458 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32459 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32460 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32461 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32462 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32463 addr="0x00010734",func="callee4",
32464 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32465 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
32466 times="1"@},
32467 bkpt=@{number="2",type="watchpoint",disp="keep",
32468 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
32469 (gdb)
32470 -exec-continue
32471 ^running
32472 (gdb)
32473 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
32474 value=@{old="-276895068",new="3"@},
32475 frame=@{func="callee4",args=[],
32476 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32477 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
32478 arch="i386:x86_64"@}
32479 (gdb)
32480 -break-list
32481 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
32482 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32483 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32484 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32485 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32486 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32487 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32488 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32489 addr="0x00010734",func="callee4",
32490 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32491 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
32492 times="1"@},
32493 bkpt=@{number="2",type="watchpoint",disp="keep",
32494 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
32495 (gdb)
32496 -exec-continue
32497 ^running
32498 ^done,reason="watchpoint-scope",wpnum="2",
32499 frame=@{func="callee3",args=[@{name="strarg",
32500 value="0x11940 \"A string argument.\""@}],
32501 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32502 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32503 arch="i386:x86_64"@}
32504 (gdb)
32505 -break-list
32506 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
32507 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
32508 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
32509 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
32510 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
32511 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
32512 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
32513 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32514 addr="0x00010734",func="callee4",
32515 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32516 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32517 thread-groups=["i1"],times="1"@}]@}
32518 (gdb)
32519 @end smallexample
32520
32521
32522 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32523 @node GDB/MI Catchpoint Commands
32524 @section @sc{gdb/mi} Catchpoint Commands
32525
32526 This section documents @sc{gdb/mi} commands for manipulating
32527 catchpoints.
32528
32529 @menu
32530 * Shared Library GDB/MI Catchpoint Commands::
32531 * Ada Exception GDB/MI Catchpoint Commands::
32532 * C++ Exception GDB/MI Catchpoint Commands::
32533 @end menu
32534
32535 @node Shared Library GDB/MI Catchpoint Commands
32536 @subsection Shared Library @sc{gdb/mi} Catchpoints
32537
32538 @findex -catch-load
32539 @subheading The @code{-catch-load} Command
32540
32541 @subsubheading Synopsis
32542
32543 @smallexample
32544 -catch-load [ -t ] [ -d ] @var{regexp}
32545 @end smallexample
32546
32547 Add a catchpoint for library load events. If the @samp{-t} option is used,
32548 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
32549 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
32550 in a disabled state. The @samp{regexp} argument is a regular
32551 expression used to match the name of the loaded library.
32552
32553
32554 @subsubheading @value{GDBN} Command
32555
32556 The corresponding @value{GDBN} command is @samp{catch load}.
32557
32558 @subsubheading Example
32559
32560 @smallexample
32561 -catch-load -t foo.so
32562 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
32563 what="load of library matching foo.so",catch-type="load",times="0"@}
32564 (gdb)
32565 @end smallexample
32566
32567
32568 @findex -catch-unload
32569 @subheading The @code{-catch-unload} Command
32570
32571 @subsubheading Synopsis
32572
32573 @smallexample
32574 -catch-unload [ -t ] [ -d ] @var{regexp}
32575 @end smallexample
32576
32577 Add a catchpoint for library unload events. If the @samp{-t} option is
32578 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
32579 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
32580 created in a disabled state. The @samp{regexp} argument is a regular
32581 expression used to match the name of the unloaded library.
32582
32583 @subsubheading @value{GDBN} Command
32584
32585 The corresponding @value{GDBN} command is @samp{catch unload}.
32586
32587 @subsubheading Example
32588
32589 @smallexample
32590 -catch-unload -d bar.so
32591 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
32592 what="load of library matching bar.so",catch-type="unload",times="0"@}
32593 (gdb)
32594 @end smallexample
32595
32596 @node Ada Exception GDB/MI Catchpoint Commands
32597 @subsection Ada Exception @sc{gdb/mi} Catchpoints
32598
32599 The following @sc{gdb/mi} commands can be used to create catchpoints
32600 that stop the execution when Ada exceptions are being raised.
32601
32602 @findex -catch-assert
32603 @subheading The @code{-catch-assert} Command
32604
32605 @subsubheading Synopsis
32606
32607 @smallexample
32608 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
32609 @end smallexample
32610
32611 Add a catchpoint for failed Ada assertions.
32612
32613 The possible optional parameters for this command are:
32614
32615 @table @samp
32616 @item -c @var{condition}
32617 Make the catchpoint conditional on @var{condition}.
32618 @item -d
32619 Create a disabled catchpoint.
32620 @item -t
32621 Create a temporary catchpoint.
32622 @end table
32623
32624 @subsubheading @value{GDBN} Command
32625
32626 The corresponding @value{GDBN} command is @samp{catch assert}.
32627
32628 @subsubheading Example
32629
32630 @smallexample
32631 -catch-assert
32632 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
32633 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
32634 thread-groups=["i1"],times="0",
32635 original-location="__gnat_debug_raise_assert_failure"@}
32636 (gdb)
32637 @end smallexample
32638
32639 @findex -catch-exception
32640 @subheading The @code{-catch-exception} Command
32641
32642 @subsubheading Synopsis
32643
32644 @smallexample
32645 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
32646 [ -t ] [ -u ]
32647 @end smallexample
32648
32649 Add a catchpoint stopping when Ada exceptions are raised.
32650 By default, the command stops the program when any Ada exception
32651 gets raised. But it is also possible, by using some of the
32652 optional parameters described below, to create more selective
32653 catchpoints.
32654
32655 The possible optional parameters for this command are:
32656
32657 @table @samp
32658 @item -c @var{condition}
32659 Make the catchpoint conditional on @var{condition}.
32660 @item -d
32661 Create a disabled catchpoint.
32662 @item -e @var{exception-name}
32663 Only stop when @var{exception-name} is raised. This option cannot
32664 be used combined with @samp{-u}.
32665 @item -t
32666 Create a temporary catchpoint.
32667 @item -u
32668 Stop only when an unhandled exception gets raised. This option
32669 cannot be used combined with @samp{-e}.
32670 @end table
32671
32672 @subsubheading @value{GDBN} Command
32673
32674 The corresponding @value{GDBN} commands are @samp{catch exception}
32675 and @samp{catch exception unhandled}.
32676
32677 @subsubheading Example
32678
32679 @smallexample
32680 -catch-exception -e Program_Error
32681 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
32682 enabled="y",addr="0x0000000000404874",
32683 what="`Program_Error' Ada exception", thread-groups=["i1"],
32684 times="0",original-location="__gnat_debug_raise_exception"@}
32685 (gdb)
32686 @end smallexample
32687
32688 @findex -catch-handlers
32689 @subheading The @code{-catch-handlers} Command
32690
32691 @subsubheading Synopsis
32692
32693 @smallexample
32694 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
32695 [ -t ]
32696 @end smallexample
32697
32698 Add a catchpoint stopping when Ada exceptions are handled.
32699 By default, the command stops the program when any Ada exception
32700 gets handled. But it is also possible, by using some of the
32701 optional parameters described below, to create more selective
32702 catchpoints.
32703
32704 The possible optional parameters for this command are:
32705
32706 @table @samp
32707 @item -c @var{condition}
32708 Make the catchpoint conditional on @var{condition}.
32709 @item -d
32710 Create a disabled catchpoint.
32711 @item -e @var{exception-name}
32712 Only stop when @var{exception-name} is handled.
32713 @item -t
32714 Create a temporary catchpoint.
32715 @end table
32716
32717 @subsubheading @value{GDBN} Command
32718
32719 The corresponding @value{GDBN} command is @samp{catch handlers}.
32720
32721 @subsubheading Example
32722
32723 @smallexample
32724 -catch-handlers -e Constraint_Error
32725 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
32726 enabled="y",addr="0x0000000000402f68",
32727 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
32728 times="0",original-location="__gnat_begin_handler"@}
32729 (gdb)
32730 @end smallexample
32731
32732 @node C++ Exception GDB/MI Catchpoint Commands
32733 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
32734
32735 The following @sc{gdb/mi} commands can be used to create catchpoints
32736 that stop the execution when C@t{++} exceptions are being throw, rethrown,
32737 or caught.
32738
32739 @findex -catch-throw
32740 @subheading The @code{-catch-throw} Command
32741
32742 @subsubheading Synopsis
32743
32744 @smallexample
32745 -catch-throw [ -t ] [ -r @var{regexp}]
32746 @end smallexample
32747
32748 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
32749 given, then only exceptions whose type matches the regular expression
32750 will be caught.
32751
32752 If @samp{-t} is given, then the catchpoint is enabled only for one
32753 stop, the catchpoint is automatically deleted after stopping once for
32754 the event.
32755
32756 @subsubheading @value{GDBN} Command
32757
32758 The corresponding @value{GDBN} commands are @samp{catch throw}
32759 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
32760
32761 @subsubheading Example
32762
32763 @smallexample
32764 -catch-throw -r exception_type
32765 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32766 what="exception throw",catch-type="throw",
32767 thread-groups=["i1"],
32768 regexp="exception_type",times="0"@}
32769 (gdb)
32770 -exec-run
32771 ^running
32772 (gdb)
32773 ~"\n"
32774 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
32775 in __cxa_throw () from /lib64/libstdc++.so.6\n"
32776 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32777 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
32778 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32779 thread-id="1",stopped-threads="all",core="6"
32780 (gdb)
32781 @end smallexample
32782
32783 @findex -catch-rethrow
32784 @subheading The @code{-catch-rethrow} Command
32785
32786 @subsubheading Synopsis
32787
32788 @smallexample
32789 -catch-rethrow [ -t ] [ -r @var{regexp}]
32790 @end smallexample
32791
32792 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
32793 then only exceptions whose type matches the regular expression will be
32794 caught.
32795
32796 If @samp{-t} is given, then the catchpoint is enabled only for one
32797 stop, the catchpoint is automatically deleted after the first event is
32798 caught.
32799
32800 @subsubheading @value{GDBN} Command
32801
32802 The corresponding @value{GDBN} commands are @samp{catch rethrow}
32803 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
32804
32805 @subsubheading Example
32806
32807 @smallexample
32808 -catch-rethrow -r exception_type
32809 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32810 what="exception rethrow",catch-type="rethrow",
32811 thread-groups=["i1"],
32812 regexp="exception_type",times="0"@}
32813 (gdb)
32814 -exec-run
32815 ^running
32816 (gdb)
32817 ~"\n"
32818 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
32819 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
32820 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32821 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
32822 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32823 thread-id="1",stopped-threads="all",core="6"
32824 (gdb)
32825 @end smallexample
32826
32827 @findex -catch-catch
32828 @subheading The @code{-catch-catch} Command
32829
32830 @subsubheading Synopsis
32831
32832 @smallexample
32833 -catch-catch [ -t ] [ -r @var{regexp}]
32834 @end smallexample
32835
32836 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
32837 is given, then only exceptions whose type matches the regular
32838 expression will be caught.
32839
32840 If @samp{-t} is given, then the catchpoint is enabled only for one
32841 stop, the catchpoint is automatically deleted after the first event is
32842 caught.
32843
32844 @subsubheading @value{GDBN} Command
32845
32846 The corresponding @value{GDBN} commands are @samp{catch catch}
32847 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
32848
32849 @subsubheading Example
32850
32851 @smallexample
32852 -catch-catch -r exception_type
32853 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32854 what="exception catch",catch-type="catch",
32855 thread-groups=["i1"],
32856 regexp="exception_type",times="0"@}
32857 (gdb)
32858 -exec-run
32859 ^running
32860 (gdb)
32861 ~"\n"
32862 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
32863 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
32864 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32865 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
32866 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32867 thread-id="1",stopped-threads="all",core="6"
32868 (gdb)
32869 @end smallexample
32870
32871 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32872 @node GDB/MI Program Context
32873 @section @sc{gdb/mi} Program Context
32874
32875 @findex -exec-arguments
32876 @subheading The @code{-exec-arguments} Command
32877
32878
32879 @subsubheading Synopsis
32880
32881 @smallexample
32882 -exec-arguments @var{args}
32883 @end smallexample
32884
32885 Set the inferior program arguments, to be used in the next
32886 @samp{-exec-run}.
32887
32888 @subsubheading @value{GDBN} Command
32889
32890 The corresponding @value{GDBN} command is @samp{set args}.
32891
32892 @subsubheading Example
32893
32894 @smallexample
32895 (gdb)
32896 -exec-arguments -v word
32897 ^done
32898 (gdb)
32899 @end smallexample
32900
32901
32902 @ignore
32903 @findex -exec-show-arguments
32904 @subheading The @code{-exec-show-arguments} Command
32905
32906 @subsubheading Synopsis
32907
32908 @smallexample
32909 -exec-show-arguments
32910 @end smallexample
32911
32912 Print the arguments of the program.
32913
32914 @subsubheading @value{GDBN} Command
32915
32916 The corresponding @value{GDBN} command is @samp{show args}.
32917
32918 @subsubheading Example
32919 N.A.
32920 @end ignore
32921
32922
32923 @findex -environment-cd
32924 @subheading The @code{-environment-cd} Command
32925
32926 @subsubheading Synopsis
32927
32928 @smallexample
32929 -environment-cd @var{pathdir}
32930 @end smallexample
32931
32932 Set @value{GDBN}'s working directory.
32933
32934 @subsubheading @value{GDBN} Command
32935
32936 The corresponding @value{GDBN} command is @samp{cd}.
32937
32938 @subsubheading Example
32939
32940 @smallexample
32941 (gdb)
32942 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
32943 ^done
32944 (gdb)
32945 @end smallexample
32946
32947
32948 @findex -environment-directory
32949 @subheading The @code{-environment-directory} Command
32950
32951 @subsubheading Synopsis
32952
32953 @smallexample
32954 -environment-directory [ -r ] [ @var{pathdir} ]+
32955 @end smallexample
32956
32957 Add directories @var{pathdir} to beginning of search path for source files.
32958 If the @samp{-r} option is used, the search path is reset to the default
32959 search path. If directories @var{pathdir} are supplied in addition to the
32960 @samp{-r} option, the search path is first reset and then addition
32961 occurs as normal.
32962 Multiple directories may be specified, separated by blanks. Specifying
32963 multiple directories in a single command
32964 results in the directories added to the beginning of the
32965 search path in the same order they were presented in the command.
32966 If blanks are needed as
32967 part of a directory name, double-quotes should be used around
32968 the name. In the command output, the path will show up separated
32969 by the system directory-separator character. The directory-separator
32970 character must not be used
32971 in any directory name.
32972 If no directories are specified, the current search path is displayed.
32973
32974 @subsubheading @value{GDBN} Command
32975
32976 The corresponding @value{GDBN} command is @samp{dir}.
32977
32978 @subsubheading Example
32979
32980 @smallexample
32981 (gdb)
32982 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
32983 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
32984 (gdb)
32985 -environment-directory ""
32986 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
32987 (gdb)
32988 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
32989 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
32990 (gdb)
32991 -environment-directory -r
32992 ^done,source-path="$cdir:$cwd"
32993 (gdb)
32994 @end smallexample
32995
32996
32997 @findex -environment-path
32998 @subheading The @code{-environment-path} Command
32999
33000 @subsubheading Synopsis
33001
33002 @smallexample
33003 -environment-path [ -r ] [ @var{pathdir} ]+
33004 @end smallexample
33005
33006 Add directories @var{pathdir} to beginning of search path for object files.
33007 If the @samp{-r} option is used, the search path is reset to the original
33008 search path that existed at gdb start-up. If directories @var{pathdir} are
33009 supplied in addition to the
33010 @samp{-r} option, the search path is first reset and then addition
33011 occurs as normal.
33012 Multiple directories may be specified, separated by blanks. Specifying
33013 multiple directories in a single command
33014 results in the directories added to the beginning of the
33015 search path in the same order they were presented in the command.
33016 If blanks are needed as
33017 part of a directory name, double-quotes should be used around
33018 the name. In the command output, the path will show up separated
33019 by the system directory-separator character. The directory-separator
33020 character must not be used
33021 in any directory name.
33022 If no directories are specified, the current path is displayed.
33023
33024
33025 @subsubheading @value{GDBN} Command
33026
33027 The corresponding @value{GDBN} command is @samp{path}.
33028
33029 @subsubheading Example
33030
33031 @smallexample
33032 (gdb)
33033 -environment-path
33034 ^done,path="/usr/bin"
33035 (gdb)
33036 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
33037 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
33038 (gdb)
33039 -environment-path -r /usr/local/bin
33040 ^done,path="/usr/local/bin:/usr/bin"
33041 (gdb)
33042 @end smallexample
33043
33044
33045 @findex -environment-pwd
33046 @subheading The @code{-environment-pwd} Command
33047
33048 @subsubheading Synopsis
33049
33050 @smallexample
33051 -environment-pwd
33052 @end smallexample
33053
33054 Show the current working directory.
33055
33056 @subsubheading @value{GDBN} Command
33057
33058 The corresponding @value{GDBN} command is @samp{pwd}.
33059
33060 @subsubheading Example
33061
33062 @smallexample
33063 (gdb)
33064 -environment-pwd
33065 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
33066 (gdb)
33067 @end smallexample
33068
33069 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33070 @node GDB/MI Thread Commands
33071 @section @sc{gdb/mi} Thread Commands
33072
33073
33074 @findex -thread-info
33075 @subheading The @code{-thread-info} Command
33076
33077 @subsubheading Synopsis
33078
33079 @smallexample
33080 -thread-info [ @var{thread-id} ]
33081 @end smallexample
33082
33083 Reports information about either a specific thread, if the
33084 @var{thread-id} parameter is present, or about all threads.
33085 @var{thread-id} is the thread's global thread ID. When printing
33086 information about all threads, also reports the global ID of the
33087 current thread.
33088
33089 @subsubheading @value{GDBN} Command
33090
33091 The @samp{info thread} command prints the same information
33092 about all threads.
33093
33094 @subsubheading Result
33095
33096 The result contains the following attributes:
33097
33098 @table @samp
33099 @item threads
33100 A list of threads. The format of the elements of the list is described in
33101 @ref{GDB/MI Thread Information}.
33102
33103 @item current-thread-id
33104 The global id of the currently selected thread. This field is omitted if there
33105 is no selected thread (for example, when the selected inferior is not running,
33106 and therefore has no threads) or if a @var{thread-id} argument was passed to
33107 the command.
33108
33109 @end table
33110
33111 @subsubheading Example
33112
33113 @smallexample
33114 -thread-info
33115 ^done,threads=[
33116 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33117 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
33118 args=[]@},state="running"@},
33119 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33120 frame=@{level="0",addr="0x0804891f",func="foo",
33121 args=[@{name="i",value="10"@}],
33122 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
33123 state="running"@}],
33124 current-thread-id="1"
33125 (gdb)
33126 @end smallexample
33127
33128 @findex -thread-list-ids
33129 @subheading The @code{-thread-list-ids} Command
33130
33131 @subsubheading Synopsis
33132
33133 @smallexample
33134 -thread-list-ids
33135 @end smallexample
33136
33137 Produces a list of the currently known global @value{GDBN} thread ids.
33138 At the end of the list it also prints the total number of such
33139 threads.
33140
33141 This command is retained for historical reasons, the
33142 @code{-thread-info} command should be used instead.
33143
33144 @subsubheading @value{GDBN} Command
33145
33146 Part of @samp{info threads} supplies the same information.
33147
33148 @subsubheading Example
33149
33150 @smallexample
33151 (gdb)
33152 -thread-list-ids
33153 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
33154 current-thread-id="1",number-of-threads="3"
33155 (gdb)
33156 @end smallexample
33157
33158
33159 @findex -thread-select
33160 @subheading The @code{-thread-select} Command
33161
33162 @subsubheading Synopsis
33163
33164 @smallexample
33165 -thread-select @var{thread-id}
33166 @end smallexample
33167
33168 Make thread with global thread number @var{thread-id} the current
33169 thread. It prints the number of the new current thread, and the
33170 topmost frame for that thread.
33171
33172 This command is deprecated in favor of explicitly using the
33173 @samp{--thread} option to each command.
33174
33175 @subsubheading @value{GDBN} Command
33176
33177 The corresponding @value{GDBN} command is @samp{thread}.
33178
33179 @subsubheading Example
33180
33181 @smallexample
33182 (gdb)
33183 -exec-next
33184 ^running
33185 (gdb)
33186 *stopped,reason="end-stepping-range",thread-id="2",line="187",
33187 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
33188 (gdb)
33189 -thread-list-ids
33190 ^done,
33191 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
33192 number-of-threads="3"
33193 (gdb)
33194 -thread-select 3
33195 ^done,new-thread-id="3",
33196 frame=@{level="0",func="vprintf",
33197 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
33198 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
33199 (gdb)
33200 @end smallexample
33201
33202 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33203 @node GDB/MI Ada Tasking Commands
33204 @section @sc{gdb/mi} Ada Tasking Commands
33205
33206 @findex -ada-task-info
33207 @subheading The @code{-ada-task-info} Command
33208
33209 @subsubheading Synopsis
33210
33211 @smallexample
33212 -ada-task-info [ @var{task-id} ]
33213 @end smallexample
33214
33215 Reports information about either a specific Ada task, if the
33216 @var{task-id} parameter is present, or about all Ada tasks.
33217
33218 @subsubheading @value{GDBN} Command
33219
33220 The @samp{info tasks} command prints the same information
33221 about all Ada tasks (@pxref{Ada Tasks}).
33222
33223 @subsubheading Result
33224
33225 The result is a table of Ada tasks. The following columns are
33226 defined for each Ada task:
33227
33228 @table @samp
33229 @item current
33230 This field exists only for the current thread. It has the value @samp{*}.
33231
33232 @item id
33233 The identifier that @value{GDBN} uses to refer to the Ada task.
33234
33235 @item task-id
33236 The identifier that the target uses to refer to the Ada task.
33237
33238 @item thread-id
33239 The global thread identifier of the thread corresponding to the Ada
33240 task.
33241
33242 This field should always exist, as Ada tasks are always implemented
33243 on top of a thread. But if @value{GDBN} cannot find this corresponding
33244 thread for any reason, the field is omitted.
33245
33246 @item parent-id
33247 This field exists only when the task was created by another task.
33248 In this case, it provides the ID of the parent task.
33249
33250 @item priority
33251 The base priority of the task.
33252
33253 @item state
33254 The current state of the task. For a detailed description of the
33255 possible states, see @ref{Ada Tasks}.
33256
33257 @item name
33258 The name of the task.
33259
33260 @end table
33261
33262 @subsubheading Example
33263
33264 @smallexample
33265 -ada-task-info
33266 ^done,tasks=@{nr_rows="3",nr_cols="8",
33267 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
33268 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
33269 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
33270 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
33271 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
33272 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
33273 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
33274 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
33275 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
33276 state="Child Termination Wait",name="main_task"@}]@}
33277 (gdb)
33278 @end smallexample
33279
33280 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33281 @node GDB/MI Program Execution
33282 @section @sc{gdb/mi} Program Execution
33283
33284 These are the asynchronous commands which generate the out-of-band
33285 record @samp{*stopped}. Currently @value{GDBN} only really executes
33286 asynchronously with remote targets and this interaction is mimicked in
33287 other cases.
33288
33289 @findex -exec-continue
33290 @subheading The @code{-exec-continue} Command
33291
33292 @subsubheading Synopsis
33293
33294 @smallexample
33295 -exec-continue [--reverse] [--all|--thread-group N]
33296 @end smallexample
33297
33298 Resumes the execution of the inferior program, which will continue
33299 to execute until it reaches a debugger stop event. If the
33300 @samp{--reverse} option is specified, execution resumes in reverse until
33301 it reaches a stop event. Stop events may include
33302 @itemize @bullet
33303 @item
33304 breakpoints or watchpoints
33305 @item
33306 signals or exceptions
33307 @item
33308 the end of the process (or its beginning under @samp{--reverse})
33309 @item
33310 the end or beginning of a replay log if one is being used.
33311 @end itemize
33312 In all-stop mode (@pxref{All-Stop
33313 Mode}), may resume only one thread, or all threads, depending on the
33314 value of the @samp{scheduler-locking} variable. If @samp{--all} is
33315 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
33316 ignored in all-stop mode. If the @samp{--thread-group} options is
33317 specified, then all threads in that thread group are resumed.
33318
33319 @subsubheading @value{GDBN} Command
33320
33321 The corresponding @value{GDBN} corresponding is @samp{continue}.
33322
33323 @subsubheading Example
33324
33325 @smallexample
33326 -exec-continue
33327 ^running
33328 (gdb)
33329 @@Hello world
33330 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
33331 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
33332 line="13",arch="i386:x86_64"@}
33333 (gdb)
33334 @end smallexample
33335
33336 For a @samp{breakpoint-hit} stopped reason, when the breakpoint
33337 encountered has multiple locations, the field @samp{bkptno} is
33338 followed by the field @samp{locno}.
33339
33340 @smallexample
33341 -exec-continue
33342 ^running
33343 (gdb)
33344 @@Hello world
33345 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",locno="3",frame=@{
33346 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
33347 line="13",arch="i386:x86_64"@}
33348 (gdb)
33349 @end smallexample
33350
33351 @findex -exec-finish
33352 @subheading The @code{-exec-finish} Command
33353
33354 @subsubheading Synopsis
33355
33356 @smallexample
33357 -exec-finish [--reverse]
33358 @end smallexample
33359
33360 Resumes the execution of the inferior program until the current
33361 function is exited. Displays the results returned by the function.
33362 If the @samp{--reverse} option is specified, resumes the reverse
33363 execution of the inferior program until the point where current
33364 function was called.
33365
33366 @subsubheading @value{GDBN} Command
33367
33368 The corresponding @value{GDBN} command is @samp{finish}.
33369
33370 @subsubheading Example
33371
33372 Function returning @code{void}.
33373
33374 @smallexample
33375 -exec-finish
33376 ^running
33377 (gdb)
33378 @@hello from foo
33379 *stopped,reason="function-finished",frame=@{func="main",args=[],
33380 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
33381 (gdb)
33382 @end smallexample
33383
33384 Function returning other than @code{void}. The name of the internal
33385 @value{GDBN} variable storing the result is printed, together with the
33386 value itself.
33387
33388 @smallexample
33389 -exec-finish
33390 ^running
33391 (gdb)
33392 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
33393 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
33394 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33395 arch="i386:x86_64"@},
33396 gdb-result-var="$1",return-value="0"
33397 (gdb)
33398 @end smallexample
33399
33400
33401 @findex -exec-interrupt
33402 @subheading The @code{-exec-interrupt} Command
33403
33404 @subsubheading Synopsis
33405
33406 @smallexample
33407 -exec-interrupt [--all|--thread-group N]
33408 @end smallexample
33409
33410 Interrupts the background execution of the target. Note how the token
33411 associated with the stop message is the one for the execution command
33412 that has been interrupted. The token for the interrupt itself only
33413 appears in the @samp{^done} output. If the user is trying to
33414 interrupt a non-running program, an error message will be printed.
33415
33416 Note that when asynchronous execution is enabled, this command is
33417 asynchronous just like other execution commands. That is, first the
33418 @samp{^done} response will be printed, and the target stop will be
33419 reported after that using the @samp{*stopped} notification.
33420
33421 In non-stop mode, only the context thread is interrupted by default.
33422 All threads (in all inferiors) will be interrupted if the
33423 @samp{--all} option is specified. If the @samp{--thread-group}
33424 option is specified, all threads in that group will be interrupted.
33425
33426 @subsubheading @value{GDBN} Command
33427
33428 The corresponding @value{GDBN} command is @samp{interrupt}.
33429
33430 @subsubheading Example
33431
33432 @smallexample
33433 (gdb)
33434 111-exec-continue
33435 111^running
33436
33437 (gdb)
33438 222-exec-interrupt
33439 222^done
33440 (gdb)
33441 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
33442 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
33443 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
33444 (gdb)
33445
33446 (gdb)
33447 -exec-interrupt
33448 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
33449 (gdb)
33450 @end smallexample
33451
33452 @findex -exec-jump
33453 @subheading The @code{-exec-jump} Command
33454
33455 @subsubheading Synopsis
33456
33457 @smallexample
33458 -exec-jump @var{locspec}
33459 @end smallexample
33460
33461 Resumes execution of the inferior program at the address to
33462 which @var{locspec} resolves. @xref{Location Specifications},
33463 for a description of the different forms of @var{locspec}.
33464
33465 @subsubheading @value{GDBN} Command
33466
33467 The corresponding @value{GDBN} command is @samp{jump}.
33468
33469 @subsubheading Example
33470
33471 @smallexample
33472 -exec-jump foo.c:10
33473 *running,thread-id="all"
33474 ^running
33475 @end smallexample
33476
33477
33478 @findex -exec-next
33479 @subheading The @code{-exec-next} Command
33480
33481 @subsubheading Synopsis
33482
33483 @smallexample
33484 -exec-next [--reverse]
33485 @end smallexample
33486
33487 Resumes execution of the inferior program, stopping when the beginning
33488 of the next source line is reached.
33489
33490 If the @samp{--reverse} option is specified, resumes reverse execution
33491 of the inferior program, stopping at the beginning of the previous
33492 source line. If you issue this command on the first line of a
33493 function, it will take you back to the caller of that function, to the
33494 source line where the function was called.
33495
33496
33497 @subsubheading @value{GDBN} Command
33498
33499 The corresponding @value{GDBN} command is @samp{next}.
33500
33501 @subsubheading Example
33502
33503 @smallexample
33504 -exec-next
33505 ^running
33506 (gdb)
33507 *stopped,reason="end-stepping-range",line="8",file="hello.c"
33508 (gdb)
33509 @end smallexample
33510
33511
33512 @findex -exec-next-instruction
33513 @subheading The @code{-exec-next-instruction} Command
33514
33515 @subsubheading Synopsis
33516
33517 @smallexample
33518 -exec-next-instruction [--reverse]
33519 @end smallexample
33520
33521 Executes one machine instruction. If the instruction is a function
33522 call, continues until the function returns. If the program stops at an
33523 instruction in the middle of a source line, the address will be
33524 printed as well.
33525
33526 If the @samp{--reverse} option is specified, resumes reverse execution
33527 of the inferior program, stopping at the previous instruction. If the
33528 previously executed instruction was a return from another function,
33529 it will continue to execute in reverse until the call to that function
33530 (from the current stack frame) is reached.
33531
33532 @subsubheading @value{GDBN} Command
33533
33534 The corresponding @value{GDBN} command is @samp{nexti}.
33535
33536 @subsubheading Example
33537
33538 @smallexample
33539 (gdb)
33540 -exec-next-instruction
33541 ^running
33542
33543 (gdb)
33544 *stopped,reason="end-stepping-range",
33545 addr="0x000100d4",line="5",file="hello.c"
33546 (gdb)
33547 @end smallexample
33548
33549
33550 @findex -exec-return
33551 @subheading The @code{-exec-return} Command
33552
33553 @subsubheading Synopsis
33554
33555 @smallexample
33556 -exec-return
33557 @end smallexample
33558
33559 Makes current function return immediately. Doesn't execute the inferior.
33560 Displays the new current frame.
33561
33562 @subsubheading @value{GDBN} Command
33563
33564 The corresponding @value{GDBN} command is @samp{return}.
33565
33566 @subsubheading Example
33567
33568 @smallexample
33569 (gdb)
33570 200-break-insert callee4
33571 200^done,bkpt=@{number="1",addr="0x00010734",
33572 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
33573 (gdb)
33574 000-exec-run
33575 000^running
33576 (gdb)
33577 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
33578 frame=@{func="callee4",args=[],
33579 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33580 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
33581 arch="i386:x86_64"@}
33582 (gdb)
33583 205-break-delete
33584 205^done
33585 (gdb)
33586 111-exec-return
33587 111^done,frame=@{level="0",func="callee3",
33588 args=[@{name="strarg",
33589 value="0x11940 \"A string argument.\""@}],
33590 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33591 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
33592 arch="i386:x86_64"@}
33593 (gdb)
33594 @end smallexample
33595
33596
33597 @findex -exec-run
33598 @subheading The @code{-exec-run} Command
33599
33600 @subsubheading Synopsis
33601
33602 @smallexample
33603 -exec-run [ --all | --thread-group N ] [ --start ]
33604 @end smallexample
33605
33606 Starts execution of the inferior from the beginning. The inferior
33607 executes until either a breakpoint is encountered or the program
33608 exits. In the latter case the output will include an exit code, if
33609 the program has exited exceptionally.
33610
33611 When neither the @samp{--all} nor the @samp{--thread-group} option
33612 is specified, the current inferior is started. If the
33613 @samp{--thread-group} option is specified, it should refer to a thread
33614 group of type @samp{process}, and that thread group will be started.
33615 If the @samp{--all} option is specified, then all inferiors will be started.
33616
33617 Using the @samp{--start} option instructs the debugger to stop
33618 the execution at the start of the inferior's main subprogram,
33619 following the same behavior as the @code{start} command
33620 (@pxref{Starting}).
33621
33622 @subsubheading @value{GDBN} Command
33623
33624 The corresponding @value{GDBN} command is @samp{run}.
33625
33626 @subsubheading Examples
33627
33628 @smallexample
33629 (gdb)
33630 -break-insert main
33631 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
33632 (gdb)
33633 -exec-run
33634 ^running
33635 (gdb)
33636 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
33637 frame=@{func="main",args=[],file="recursive2.c",
33638 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
33639 (gdb)
33640 @end smallexample
33641
33642 @noindent
33643 Program exited normally:
33644
33645 @smallexample
33646 (gdb)
33647 -exec-run
33648 ^running
33649 (gdb)
33650 x = 55
33651 *stopped,reason="exited-normally"
33652 (gdb)
33653 @end smallexample
33654
33655 @noindent
33656 Program exited exceptionally:
33657
33658 @smallexample
33659 (gdb)
33660 -exec-run
33661 ^running
33662 (gdb)
33663 x = 55
33664 *stopped,reason="exited",exit-code="01"
33665 (gdb)
33666 @end smallexample
33667
33668 Another way the program can terminate is if it receives a signal such as
33669 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
33670
33671 @smallexample
33672 (gdb)
33673 *stopped,reason="exited-signalled",signal-name="SIGINT",
33674 signal-meaning="Interrupt"
33675 @end smallexample
33676
33677
33678 @c @subheading -exec-signal
33679
33680
33681 @findex -exec-step
33682 @subheading The @code{-exec-step} Command
33683
33684 @subsubheading Synopsis
33685
33686 @smallexample
33687 -exec-step [--reverse]
33688 @end smallexample
33689
33690 Resumes execution of the inferior program, stopping when the beginning
33691 of the next source line is reached, if the next source line is not a
33692 function call. If it is, stop at the first instruction of the called
33693 function. If the @samp{--reverse} option is specified, resumes reverse
33694 execution of the inferior program, stopping at the beginning of the
33695 previously executed source line.
33696
33697 @subsubheading @value{GDBN} Command
33698
33699 The corresponding @value{GDBN} command is @samp{step}.
33700
33701 @subsubheading Example
33702
33703 Stepping into a function:
33704
33705 @smallexample
33706 -exec-step
33707 ^running
33708 (gdb)
33709 *stopped,reason="end-stepping-range",
33710 frame=@{func="foo",args=[@{name="a",value="10"@},
33711 @{name="b",value="0"@}],file="recursive2.c",
33712 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
33713 (gdb)
33714 @end smallexample
33715
33716 Regular stepping:
33717
33718 @smallexample
33719 -exec-step
33720 ^running
33721 (gdb)
33722 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
33723 (gdb)
33724 @end smallexample
33725
33726
33727 @findex -exec-step-instruction
33728 @subheading The @code{-exec-step-instruction} Command
33729
33730 @subsubheading Synopsis
33731
33732 @smallexample
33733 -exec-step-instruction [--reverse]
33734 @end smallexample
33735
33736 Resumes the inferior which executes one machine instruction. If the
33737 @samp{--reverse} option is specified, resumes reverse execution of the
33738 inferior program, stopping at the previously executed instruction.
33739 The output, once @value{GDBN} has stopped, will vary depending on
33740 whether we have stopped in the middle of a source line or not. In the
33741 former case, the address at which the program stopped will be printed
33742 as well.
33743
33744 @subsubheading @value{GDBN} Command
33745
33746 The corresponding @value{GDBN} command is @samp{stepi}.
33747
33748 @subsubheading Example
33749
33750 @smallexample
33751 (gdb)
33752 -exec-step-instruction
33753 ^running
33754
33755 (gdb)
33756 *stopped,reason="end-stepping-range",
33757 frame=@{func="foo",args=[],file="try.c",
33758 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
33759 (gdb)
33760 -exec-step-instruction
33761 ^running
33762
33763 (gdb)
33764 *stopped,reason="end-stepping-range",
33765 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
33766 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
33767 (gdb)
33768 @end smallexample
33769
33770
33771 @findex -exec-until
33772 @subheading The @code{-exec-until} Command
33773
33774 @subsubheading Synopsis
33775
33776 @smallexample
33777 -exec-until [ @var{locspec} ]
33778 @end smallexample
33779
33780 Executes the inferior until it reaches the address to which
33781 @var{locspec} resolves. If there is no argument, the inferior
33782 executes until it reaches a source line greater than the current one.
33783 The reason for stopping in this case will be @samp{location-reached}.
33784
33785 @subsubheading @value{GDBN} Command
33786
33787 The corresponding @value{GDBN} command is @samp{until}.
33788
33789 @subsubheading Example
33790
33791 @smallexample
33792 (gdb)
33793 -exec-until recursive2.c:6
33794 ^running
33795 (gdb)
33796 x = 55
33797 *stopped,reason="location-reached",frame=@{func="main",args=[],
33798 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
33799 arch="i386:x86_64"@}
33800 (gdb)
33801 @end smallexample
33802
33803 @ignore
33804 @subheading -file-clear
33805 Is this going away????
33806 @end ignore
33807
33808 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33809 @node GDB/MI Stack Manipulation
33810 @section @sc{gdb/mi} Stack Manipulation Commands
33811
33812 @findex -enable-frame-filters
33813 @subheading The @code{-enable-frame-filters} Command
33814
33815 @smallexample
33816 -enable-frame-filters
33817 @end smallexample
33818
33819 @value{GDBN} allows Python-based frame filters to affect the output of
33820 the MI commands relating to stack traces. As there is no way to
33821 implement this in a fully backward-compatible way, a front end must
33822 request that this functionality be enabled.
33823
33824 Once enabled, this feature cannot be disabled.
33825
33826 Note that if Python support has not been compiled into @value{GDBN},
33827 this command will still succeed (and do nothing).
33828
33829 @findex -stack-info-frame
33830 @subheading The @code{-stack-info-frame} Command
33831
33832 @subsubheading Synopsis
33833
33834 @smallexample
33835 -stack-info-frame
33836 @end smallexample
33837
33838 Get info on the selected frame.
33839
33840 @subsubheading @value{GDBN} Command
33841
33842 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
33843 (without arguments).
33844
33845 @subsubheading Example
33846
33847 @smallexample
33848 (gdb)
33849 -stack-info-frame
33850 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
33851 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33852 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
33853 arch="i386:x86_64"@}
33854 (gdb)
33855 @end smallexample
33856
33857 @findex -stack-info-depth
33858 @subheading The @code{-stack-info-depth} Command
33859
33860 @subsubheading Synopsis
33861
33862 @smallexample
33863 -stack-info-depth [ @var{max-depth} ]
33864 @end smallexample
33865
33866 Return the depth of the stack. If the integer argument @var{max-depth}
33867 is specified, do not count beyond @var{max-depth} frames.
33868
33869 @subsubheading @value{GDBN} Command
33870
33871 There's no equivalent @value{GDBN} command.
33872
33873 @subsubheading Example
33874
33875 For a stack with frame levels 0 through 11:
33876
33877 @smallexample
33878 (gdb)
33879 -stack-info-depth
33880 ^done,depth="12"
33881 (gdb)
33882 -stack-info-depth 4
33883 ^done,depth="4"
33884 (gdb)
33885 -stack-info-depth 12
33886 ^done,depth="12"
33887 (gdb)
33888 -stack-info-depth 11
33889 ^done,depth="11"
33890 (gdb)
33891 -stack-info-depth 13
33892 ^done,depth="12"
33893 (gdb)
33894 @end smallexample
33895
33896 @anchor{-stack-list-arguments}
33897 @findex -stack-list-arguments
33898 @subheading The @code{-stack-list-arguments} Command
33899
33900 @subsubheading Synopsis
33901
33902 @smallexample
33903 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33904 [ @var{low-frame} @var{high-frame} ]
33905 @end smallexample
33906
33907 Display a list of the arguments for the frames between @var{low-frame}
33908 and @var{high-frame} (inclusive). If @var{low-frame} and
33909 @var{high-frame} are not provided, list the arguments for the whole
33910 call stack. If the two arguments are equal, show the single frame
33911 at the corresponding level. It is an error if @var{low-frame} is
33912 larger than the actual number of frames. On the other hand,
33913 @var{high-frame} may be larger than the actual number of frames, in
33914 which case only existing frames will be returned.
33915
33916 If @var{print-values} is 0 or @code{--no-values}, print only the names of
33917 the variables; if it is 1 or @code{--all-values}, print also their
33918 values; and if it is 2 or @code{--simple-values}, print the name,
33919 type and value for simple data types, and the name and type for arrays,
33920 structures and unions. If the option @code{--no-frame-filters} is
33921 supplied, then Python frame filters will not be executed.
33922
33923 If the @code{--skip-unavailable} option is specified, arguments that
33924 are not available are not listed. Partially available arguments
33925 are still displayed, however.
33926
33927 Use of this command to obtain arguments in a single frame is
33928 deprecated in favor of the @samp{-stack-list-variables} command.
33929
33930 @subsubheading @value{GDBN} Command
33931
33932 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
33933 @samp{gdb_get_args} command which partially overlaps with the
33934 functionality of @samp{-stack-list-arguments}.
33935
33936 @subsubheading Example
33937
33938 @smallexample
33939 (gdb)
33940 -stack-list-frames
33941 ^done,
33942 stack=[
33943 frame=@{level="0",addr="0x00010734",func="callee4",
33944 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33945 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
33946 arch="i386:x86_64"@},
33947 frame=@{level="1",addr="0x0001076c",func="callee3",
33948 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33949 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
33950 arch="i386:x86_64"@},
33951 frame=@{level="2",addr="0x0001078c",func="callee2",
33952 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33953 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
33954 arch="i386:x86_64"@},
33955 frame=@{level="3",addr="0x000107b4",func="callee1",
33956 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33957 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
33958 arch="i386:x86_64"@},
33959 frame=@{level="4",addr="0x000107e0",func="main",
33960 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33961 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
33962 arch="i386:x86_64"@}]
33963 (gdb)
33964 -stack-list-arguments 0
33965 ^done,
33966 stack-args=[
33967 frame=@{level="0",args=[]@},
33968 frame=@{level="1",args=[name="strarg"]@},
33969 frame=@{level="2",args=[name="intarg",name="strarg"]@},
33970 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
33971 frame=@{level="4",args=[]@}]
33972 (gdb)
33973 -stack-list-arguments 1
33974 ^done,
33975 stack-args=[
33976 frame=@{level="0",args=[]@},
33977 frame=@{level="1",
33978 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
33979 frame=@{level="2",args=[
33980 @{name="intarg",value="2"@},
33981 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
33982 @{frame=@{level="3",args=[
33983 @{name="intarg",value="2"@},
33984 @{name="strarg",value="0x11940 \"A string argument.\""@},
33985 @{name="fltarg",value="3.5"@}]@},
33986 frame=@{level="4",args=[]@}]
33987 (gdb)
33988 -stack-list-arguments 0 2 2
33989 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
33990 (gdb)
33991 -stack-list-arguments 1 2 2
33992 ^done,stack-args=[frame=@{level="2",
33993 args=[@{name="intarg",value="2"@},
33994 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
33995 (gdb)
33996 @end smallexample
33997
33998 @c @subheading -stack-list-exception-handlers
33999
34000
34001 @anchor{-stack-list-frames}
34002 @findex -stack-list-frames
34003 @subheading The @code{-stack-list-frames} Command
34004
34005 @subsubheading Synopsis
34006
34007 @smallexample
34008 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
34009 @end smallexample
34010
34011 List the frames currently on the stack. For each frame it displays the
34012 following info:
34013
34014 @table @samp
34015 @item @var{level}
34016 The frame number, 0 being the topmost frame, i.e., the innermost function.
34017 @item @var{addr}
34018 The @code{$pc} value for that frame.
34019 @item @var{func}
34020 Function name.
34021 @item @var{file}
34022 File name of the source file where the function lives.
34023 @item @var{fullname}
34024 The full file name of the source file where the function lives.
34025 @item @var{line}
34026 Line number corresponding to the @code{$pc}.
34027 @item @var{from}
34028 The shared library where this function is defined. This is only given
34029 if the frame's function is not known.
34030 @item @var{arch}
34031 Frame's architecture.
34032 @end table
34033
34034 If invoked without arguments, this command prints a backtrace for the
34035 whole stack. If given two integer arguments, it shows the frames whose
34036 levels are between the two arguments (inclusive). If the two arguments
34037 are equal, it shows the single frame at the corresponding level. It is
34038 an error if @var{low-frame} is larger than the actual number of
34039 frames. On the other hand, @var{high-frame} may be larger than the
34040 actual number of frames, in which case only existing frames will be
34041 returned. If the option @code{--no-frame-filters} is supplied, then
34042 Python frame filters will not be executed.
34043
34044 @subsubheading @value{GDBN} Command
34045
34046 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
34047
34048 @subsubheading Example
34049
34050 Full stack backtrace:
34051
34052 @smallexample
34053 (gdb)
34054 -stack-list-frames
34055 ^done,stack=
34056 [frame=@{level="0",addr="0x0001076c",func="foo",
34057 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
34058 arch="i386:x86_64"@},
34059 frame=@{level="1",addr="0x000107a4",func="foo",
34060 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34061 arch="i386:x86_64"@},
34062 frame=@{level="2",addr="0x000107a4",func="foo",
34063 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34064 arch="i386:x86_64"@},
34065 frame=@{level="3",addr="0x000107a4",func="foo",
34066 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34067 arch="i386:x86_64"@},
34068 frame=@{level="4",addr="0x000107a4",func="foo",
34069 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34070 arch="i386:x86_64"@},
34071 frame=@{level="5",addr="0x000107a4",func="foo",
34072 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34073 arch="i386:x86_64"@},
34074 frame=@{level="6",addr="0x000107a4",func="foo",
34075 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34076 arch="i386:x86_64"@},
34077 frame=@{level="7",addr="0x000107a4",func="foo",
34078 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34079 arch="i386:x86_64"@},
34080 frame=@{level="8",addr="0x000107a4",func="foo",
34081 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34082 arch="i386:x86_64"@},
34083 frame=@{level="9",addr="0x000107a4",func="foo",
34084 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34085 arch="i386:x86_64"@},
34086 frame=@{level="10",addr="0x000107a4",func="foo",
34087 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34088 arch="i386:x86_64"@},
34089 frame=@{level="11",addr="0x00010738",func="main",
34090 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
34091 arch="i386:x86_64"@}]
34092 (gdb)
34093 @end smallexample
34094
34095 Show frames between @var{low_frame} and @var{high_frame}:
34096
34097 @smallexample
34098 (gdb)
34099 -stack-list-frames 3 5
34100 ^done,stack=
34101 [frame=@{level="3",addr="0x000107a4",func="foo",
34102 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34103 arch="i386:x86_64"@},
34104 frame=@{level="4",addr="0x000107a4",func="foo",
34105 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34106 arch="i386:x86_64"@},
34107 frame=@{level="5",addr="0x000107a4",func="foo",
34108 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34109 arch="i386:x86_64"@}]
34110 (gdb)
34111 @end smallexample
34112
34113 Show a single frame:
34114
34115 @smallexample
34116 (gdb)
34117 -stack-list-frames 3 3
34118 ^done,stack=
34119 [frame=@{level="3",addr="0x000107a4",func="foo",
34120 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
34121 arch="i386:x86_64"@}]
34122 (gdb)
34123 @end smallexample
34124
34125
34126 @findex -stack-list-locals
34127 @anchor{-stack-list-locals}
34128 @subheading The @code{-stack-list-locals} Command
34129
34130 @subsubheading Synopsis
34131
34132 @smallexample
34133 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
34134 @end smallexample
34135
34136 Display the local variable names for the selected frame. If
34137 @var{print-values} is 0 or @code{--no-values}, print only the names of
34138 the variables; if it is 1 or @code{--all-values}, print also their
34139 values; and if it is 2 or @code{--simple-values}, print the name,
34140 type and value for simple data types, and the name and type for arrays,
34141 structures and unions. In this last case, a frontend can immediately
34142 display the value of simple data types and create variable objects for
34143 other data types when the user wishes to explore their values in
34144 more detail. If the option @code{--no-frame-filters} is supplied, then
34145 Python frame filters will not be executed.
34146
34147 If the @code{--skip-unavailable} option is specified, local variables
34148 that are not available are not listed. Partially available local
34149 variables are still displayed, however.
34150
34151 This command is deprecated in favor of the
34152 @samp{-stack-list-variables} command.
34153
34154 @subsubheading @value{GDBN} Command
34155
34156 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
34157
34158 @subsubheading Example
34159
34160 @smallexample
34161 (gdb)
34162 -stack-list-locals 0
34163 ^done,locals=[name="A",name="B",name="C"]
34164 (gdb)
34165 -stack-list-locals --all-values
34166 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
34167 @{name="C",value="@{1, 2, 3@}"@}]
34168 -stack-list-locals --simple-values
34169 ^done,locals=[@{name="A",type="int",value="1"@},
34170 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
34171 (gdb)
34172 @end smallexample
34173
34174 @anchor{-stack-list-variables}
34175 @findex -stack-list-variables
34176 @subheading The @code{-stack-list-variables} Command
34177
34178 @subsubheading Synopsis
34179
34180 @smallexample
34181 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
34182 @end smallexample
34183
34184 Display the names of local variables and function arguments for the selected frame. If
34185 @var{print-values} is 0 or @code{--no-values}, print only the names of
34186 the variables; if it is 1 or @code{--all-values}, print also their
34187 values; and if it is 2 or @code{--simple-values}, print the name,
34188 type and value for simple data types, and the name and type for arrays,
34189 structures and unions. If the option @code{--no-frame-filters} is
34190 supplied, then Python frame filters will not be executed.
34191
34192 If the @code{--skip-unavailable} option is specified, local variables
34193 and arguments that are not available are not listed. Partially
34194 available arguments and local variables are still displayed, however.
34195
34196 @subsubheading Example
34197
34198 @smallexample
34199 (gdb)
34200 -stack-list-variables --thread 1 --frame 0 --all-values
34201 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
34202 (gdb)
34203 @end smallexample
34204
34205
34206 @findex -stack-select-frame
34207 @subheading The @code{-stack-select-frame} Command
34208
34209 @subsubheading Synopsis
34210
34211 @smallexample
34212 -stack-select-frame @var{framenum}
34213 @end smallexample
34214
34215 Change the selected frame. Select a different frame @var{framenum} on
34216 the stack.
34217
34218 This command in deprecated in favor of passing the @samp{--frame}
34219 option to every command.
34220
34221 @subsubheading @value{GDBN} Command
34222
34223 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
34224 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
34225
34226 @subsubheading Example
34227
34228 @smallexample
34229 (gdb)
34230 -stack-select-frame 2
34231 ^done
34232 (gdb)
34233 @end smallexample
34234
34235 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34236 @node GDB/MI Variable Objects
34237 @section @sc{gdb/mi} Variable Objects
34238
34239 @ignore
34240
34241 @subheading Motivation for Variable Objects in @sc{gdb/mi}
34242
34243 For the implementation of a variable debugger window (locals, watched
34244 expressions, etc.), we are proposing the adaptation of the existing code
34245 used by @code{Insight}.
34246
34247 The two main reasons for that are:
34248
34249 @enumerate 1
34250 @item
34251 It has been proven in practice (it is already on its second generation).
34252
34253 @item
34254 It will shorten development time (needless to say how important it is
34255 now).
34256 @end enumerate
34257
34258 The original interface was designed to be used by Tcl code, so it was
34259 slightly changed so it could be used through @sc{gdb/mi}. This section
34260 describes the @sc{gdb/mi} operations that will be available and gives some
34261 hints about their use.
34262
34263 @emph{Note}: In addition to the set of operations described here, we
34264 expect the @sc{gui} implementation of a variable window to require, at
34265 least, the following operations:
34266
34267 @itemize @bullet
34268 @item @code{-gdb-show} @code{output-radix}
34269 @item @code{-stack-list-arguments}
34270 @item @code{-stack-list-locals}
34271 @item @code{-stack-select-frame}
34272 @end itemize
34273
34274 @end ignore
34275
34276 @subheading Introduction to Variable Objects
34277
34278 @cindex variable objects in @sc{gdb/mi}
34279
34280 Variable objects are "object-oriented" MI interface for examining and
34281 changing values of expressions. Unlike some other MI interfaces that
34282 work with expressions, variable objects are specifically designed for
34283 simple and efficient presentation in the frontend. A variable object
34284 is identified by string name. When a variable object is created, the
34285 frontend specifies the expression for that variable object. The
34286 expression can be a simple variable, or it can be an arbitrary complex
34287 expression, and can even involve CPU registers. After creating a
34288 variable object, the frontend can invoke other variable object
34289 operations---for example to obtain or change the value of a variable
34290 object, or to change display format.
34291
34292 Variable objects have hierarchical tree structure. Any variable object
34293 that corresponds to a composite type, such as structure in C, has
34294 a number of child variable objects, for example corresponding to each
34295 element of a structure. A child variable object can itself have
34296 children, recursively. Recursion ends when we reach
34297 leaf variable objects, which always have built-in types. Child variable
34298 objects are created only by explicit request, so if a frontend
34299 is not interested in the children of a particular variable object, no
34300 child will be created.
34301
34302 For a leaf variable object it is possible to obtain its value as a
34303 string, or set the value from a string. String value can be also
34304 obtained for a non-leaf variable object, but it's generally a string
34305 that only indicates the type of the object, and does not list its
34306 contents. Assignment to a non-leaf variable object is not allowed.
34307
34308 A frontend does not need to read the values of all variable objects each time
34309 the program stops. Instead, MI provides an update command that lists all
34310 variable objects whose values has changed since the last update
34311 operation. This considerably reduces the amount of data that must
34312 be transferred to the frontend. As noted above, children variable
34313 objects are created on demand, and only leaf variable objects have a
34314 real value. As result, gdb will read target memory only for leaf
34315 variables that frontend has created.
34316
34317 The automatic update is not always desirable. For example, a frontend
34318 might want to keep a value of some expression for future reference,
34319 and never update it. For another example, fetching memory is
34320 relatively slow for embedded targets, so a frontend might want
34321 to disable automatic update for the variables that are either not
34322 visible on the screen, or ``closed''. This is possible using so
34323 called ``frozen variable objects''. Such variable objects are never
34324 implicitly updated.
34325
34326 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
34327 fixed variable object, the expression is parsed when the variable
34328 object is created, including associating identifiers to specific
34329 variables. The meaning of expression never changes. For a floating
34330 variable object the values of variables whose names appear in the
34331 expressions are re-evaluated every time in the context of the current
34332 frame. Consider this example:
34333
34334 @smallexample
34335 void do_work(...)
34336 @{
34337 struct work_state state;
34338
34339 if (...)
34340 do_work(...);
34341 @}
34342 @end smallexample
34343
34344 If a fixed variable object for the @code{state} variable is created in
34345 this function, and we enter the recursive call, the variable
34346 object will report the value of @code{state} in the top-level
34347 @code{do_work} invocation. On the other hand, a floating variable
34348 object will report the value of @code{state} in the current frame.
34349
34350 If an expression specified when creating a fixed variable object
34351 refers to a local variable, the variable object becomes bound to the
34352 thread and frame in which the variable object is created. When such
34353 variable object is updated, @value{GDBN} makes sure that the
34354 thread/frame combination the variable object is bound to still exists,
34355 and re-evaluates the variable object in context of that thread/frame.
34356
34357 The following is the complete set of @sc{gdb/mi} operations defined to
34358 access this functionality:
34359
34360 @multitable @columnfractions .4 .6
34361 @item @strong{Operation}
34362 @tab @strong{Description}
34363
34364 @item @code{-enable-pretty-printing}
34365 @tab enable Python-based pretty-printing
34366 @item @code{-var-create}
34367 @tab create a variable object
34368 @item @code{-var-delete}
34369 @tab delete the variable object and/or its children
34370 @item @code{-var-set-format}
34371 @tab set the display format of this variable
34372 @item @code{-var-show-format}
34373 @tab show the display format of this variable
34374 @item @code{-var-info-num-children}
34375 @tab tells how many children this object has
34376 @item @code{-var-list-children}
34377 @tab return a list of the object's children
34378 @item @code{-var-info-type}
34379 @tab show the type of this variable object
34380 @item @code{-var-info-expression}
34381 @tab print parent-relative expression that this variable object represents
34382 @item @code{-var-info-path-expression}
34383 @tab print full expression that this variable object represents
34384 @item @code{-var-show-attributes}
34385 @tab is this variable editable? does it exist here?
34386 @item @code{-var-evaluate-expression}
34387 @tab get the value of this variable
34388 @item @code{-var-assign}
34389 @tab set the value of this variable
34390 @item @code{-var-update}
34391 @tab update the variable and its children
34392 @item @code{-var-set-frozen}
34393 @tab set frozenness attribute
34394 @item @code{-var-set-update-range}
34395 @tab set range of children to display on update
34396 @end multitable
34397
34398 In the next subsection we describe each operation in detail and suggest
34399 how it can be used.
34400
34401 @subheading Description And Use of Operations on Variable Objects
34402
34403 @findex -enable-pretty-printing
34404 @subheading The @code{-enable-pretty-printing} Command
34405
34406 @smallexample
34407 -enable-pretty-printing
34408 @end smallexample
34409
34410 @value{GDBN} allows Python-based visualizers to affect the output of the
34411 MI variable object commands. However, because there was no way to
34412 implement this in a fully backward-compatible way, a front end must
34413 request that this functionality be enabled.
34414
34415 Once enabled, this feature cannot be disabled.
34416
34417 Note that if Python support has not been compiled into @value{GDBN},
34418 this command will still succeed (and do nothing).
34419
34420 @findex -var-create
34421 @subheading The @code{-var-create} Command
34422
34423 @subsubheading Synopsis
34424
34425 @smallexample
34426 -var-create @{@var{name} | "-"@}
34427 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
34428 @end smallexample
34429
34430 This operation creates a variable object, which allows the monitoring of
34431 a variable, the result of an expression, a memory cell or a CPU
34432 register.
34433
34434 The @var{name} parameter is the string by which the object can be
34435 referenced. It must be unique. If @samp{-} is specified, the varobj
34436 system will generate a string ``varNNNNNN'' automatically. It will be
34437 unique provided that one does not specify @var{name} of that format.
34438 The command fails if a duplicate name is found.
34439
34440 The frame under which the expression should be evaluated can be
34441 specified by @var{frame-addr}. A @samp{*} indicates that the current
34442 frame should be used. A @samp{@@} indicates that a floating variable
34443 object must be created.
34444
34445 @var{expression} is any expression valid on the current language set (must not
34446 begin with a @samp{*}), or one of the following:
34447
34448 @itemize @bullet
34449 @item
34450 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
34451
34452 @item
34453 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
34454
34455 @item
34456 @samp{$@var{regname}} --- a CPU register name
34457 @end itemize
34458
34459 @cindex dynamic varobj
34460 A varobj's contents may be provided by a Python-based pretty-printer. In this
34461 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
34462 have slightly different semantics in some cases. If the
34463 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
34464 will never create a dynamic varobj. This ensures backward
34465 compatibility for existing clients.
34466
34467 @subsubheading Result
34468
34469 This operation returns attributes of the newly-created varobj. These
34470 are:
34471
34472 @table @samp
34473 @item name
34474 The name of the varobj.
34475
34476 @item numchild
34477 The number of children of the varobj. This number is not necessarily
34478 reliable for a dynamic varobj. Instead, you must examine the
34479 @samp{has_more} attribute.
34480
34481 @item value
34482 The varobj's scalar value. For a varobj whose type is some sort of
34483 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
34484 will not be interesting.
34485
34486 @item type
34487 The varobj's type. This is a string representation of the type, as
34488 would be printed by the @value{GDBN} CLI. If @samp{print object}
34489 (@pxref{Print Settings, set print object}) is set to @code{on}, the
34490 @emph{actual} (derived) type of the object is shown rather than the
34491 @emph{declared} one.
34492
34493 @item thread-id
34494 If a variable object is bound to a specific thread, then this is the
34495 thread's global identifier.
34496
34497 @item has_more
34498 For a dynamic varobj, this indicates whether there appear to be any
34499 children available. For a non-dynamic varobj, this will be 0.
34500
34501 @item dynamic
34502 This attribute will be present and have the value @samp{1} if the
34503 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
34504 then this attribute will not be present.
34505
34506 @item displayhint
34507 A dynamic varobj can supply a display hint to the front end. The
34508 value comes directly from the Python pretty-printer object's
34509 @code{display_hint} method. @xref{Pretty Printing API}.
34510 @end table
34511
34512 Typical output will look like this:
34513
34514 @smallexample
34515 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
34516 has_more="@var{has_more}"
34517 @end smallexample
34518
34519
34520 @findex -var-delete
34521 @subheading The @code{-var-delete} Command
34522
34523 @subsubheading Synopsis
34524
34525 @smallexample
34526 -var-delete [ -c ] @var{name}
34527 @end smallexample
34528
34529 Deletes a previously created variable object and all of its children.
34530 With the @samp{-c} option, just deletes the children.
34531
34532 Returns an error if the object @var{name} is not found.
34533
34534
34535 @findex -var-set-format
34536 @subheading The @code{-var-set-format} Command
34537
34538 @subsubheading Synopsis
34539
34540 @smallexample
34541 -var-set-format @var{name} @var{format-spec}
34542 @end smallexample
34543
34544 Sets the output format for the value of the object @var{name} to be
34545 @var{format-spec}.
34546
34547 @anchor{-var-set-format}
34548 The syntax for the @var{format-spec} is as follows:
34549
34550 @smallexample
34551 @var{format-spec} @expansion{}
34552 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
34553 @end smallexample
34554
34555 The natural format is the default format choosen automatically
34556 based on the variable type (like decimal for an @code{int}, hex
34557 for pointers, etc.).
34558
34559 The zero-hexadecimal format has a representation similar to hexadecimal
34560 but with padding zeroes to the left of the value. For example, a 32-bit
34561 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
34562 zero-hexadecimal format.
34563
34564 For a variable with children, the format is set only on the
34565 variable itself, and the children are not affected.
34566
34567 @findex -var-show-format
34568 @subheading The @code{-var-show-format} Command
34569
34570 @subsubheading Synopsis
34571
34572 @smallexample
34573 -var-show-format @var{name}
34574 @end smallexample
34575
34576 Returns the format used to display the value of the object @var{name}.
34577
34578 @smallexample
34579 @var{format} @expansion{}
34580 @var{format-spec}
34581 @end smallexample
34582
34583
34584 @findex -var-info-num-children
34585 @subheading The @code{-var-info-num-children} Command
34586
34587 @subsubheading Synopsis
34588
34589 @smallexample
34590 -var-info-num-children @var{name}
34591 @end smallexample
34592
34593 Returns the number of children of a variable object @var{name}:
34594
34595 @smallexample
34596 numchild=@var{n}
34597 @end smallexample
34598
34599 Note that this number is not completely reliable for a dynamic varobj.
34600 It will return the current number of children, but more children may
34601 be available.
34602
34603
34604 @findex -var-list-children
34605 @subheading The @code{-var-list-children} Command
34606
34607 @subsubheading Synopsis
34608
34609 @smallexample
34610 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
34611 @end smallexample
34612 @anchor{-var-list-children}
34613
34614 Return a list of the children of the specified variable object and
34615 create variable objects for them, if they do not already exist. With
34616 a single argument or if @var{print-values} has a value of 0 or
34617 @code{--no-values}, print only the names of the variables; if
34618 @var{print-values} is 1 or @code{--all-values}, also print their
34619 values; and if it is 2 or @code{--simple-values} print the name and
34620 value for simple data types and just the name for arrays, structures
34621 and unions.
34622
34623 @var{from} and @var{to}, if specified, indicate the range of children
34624 to report. If @var{from} or @var{to} is less than zero, the range is
34625 reset and all children will be reported. Otherwise, children starting
34626 at @var{from} (zero-based) and up to and excluding @var{to} will be
34627 reported.
34628
34629 If a child range is requested, it will only affect the current call to
34630 @code{-var-list-children}, but not future calls to @code{-var-update}.
34631 For this, you must instead use @code{-var-set-update-range}. The
34632 intent of this approach is to enable a front end to implement any
34633 update approach it likes; for example, scrolling a view may cause the
34634 front end to request more children with @code{-var-list-children}, and
34635 then the front end could call @code{-var-set-update-range} with a
34636 different range to ensure that future updates are restricted to just
34637 the visible items.
34638
34639 For each child the following results are returned:
34640
34641 @table @var
34642
34643 @item name
34644 Name of the variable object created for this child.
34645
34646 @item exp
34647 The expression to be shown to the user by the front end to designate this child.
34648 For example this may be the name of a structure member.
34649
34650 For a dynamic varobj, this value cannot be used to form an
34651 expression. There is no way to do this at all with a dynamic varobj.
34652
34653 For C/C@t{++} structures there are several pseudo children returned to
34654 designate access qualifiers. For these pseudo children @var{exp} is
34655 @samp{public}, @samp{private}, or @samp{protected}. In this case the
34656 type and value are not present.
34657
34658 A dynamic varobj will not report the access qualifying
34659 pseudo-children, regardless of the language. This information is not
34660 available at all with a dynamic varobj.
34661
34662 @item numchild
34663 Number of children this child has. For a dynamic varobj, this will be
34664 0.
34665
34666 @item type
34667 The type of the child. If @samp{print object}
34668 (@pxref{Print Settings, set print object}) is set to @code{on}, the
34669 @emph{actual} (derived) type of the object is shown rather than the
34670 @emph{declared} one.
34671
34672 @item value
34673 If values were requested, this is the value.
34674
34675 @item thread-id
34676 If this variable object is associated with a thread, this is the
34677 thread's global thread id. Otherwise this result is not present.
34678
34679 @item frozen
34680 If the variable object is frozen, this variable will be present with a value of 1.
34681
34682 @item displayhint
34683 A dynamic varobj can supply a display hint to the front end. The
34684 value comes directly from the Python pretty-printer object's
34685 @code{display_hint} method. @xref{Pretty Printing API}.
34686
34687 @item dynamic
34688 This attribute will be present and have the value @samp{1} if the
34689 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
34690 then this attribute will not be present.
34691
34692 @end table
34693
34694 The result may have its own attributes:
34695
34696 @table @samp
34697 @item displayhint
34698 A dynamic varobj can supply a display hint to the front end. The
34699 value comes directly from the Python pretty-printer object's
34700 @code{display_hint} method. @xref{Pretty Printing API}.
34701
34702 @item has_more
34703 This is an integer attribute which is nonzero if there are children
34704 remaining after the end of the selected range.
34705 @end table
34706
34707 @subsubheading Example
34708
34709 @smallexample
34710 (gdb)
34711 -var-list-children n
34712 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
34713 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
34714 (gdb)
34715 -var-list-children --all-values n
34716 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
34717 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
34718 @end smallexample
34719
34720
34721 @findex -var-info-type
34722 @subheading The @code{-var-info-type} Command
34723
34724 @subsubheading Synopsis
34725
34726 @smallexample
34727 -var-info-type @var{name}
34728 @end smallexample
34729
34730 Returns the type of the specified variable @var{name}. The type is
34731 returned as a string in the same format as it is output by the
34732 @value{GDBN} CLI:
34733
34734 @smallexample
34735 type=@var{typename}
34736 @end smallexample
34737
34738
34739 @findex -var-info-expression
34740 @subheading The @code{-var-info-expression} Command
34741
34742 @subsubheading Synopsis
34743
34744 @smallexample
34745 -var-info-expression @var{name}
34746 @end smallexample
34747
34748 Returns a string that is suitable for presenting this
34749 variable object in user interface. The string is generally
34750 not valid expression in the current language, and cannot be evaluated.
34751
34752 For example, if @code{a} is an array, and variable object
34753 @code{A} was created for @code{a}, then we'll get this output:
34754
34755 @smallexample
34756 (gdb) -var-info-expression A.1
34757 ^done,lang="C",exp="1"
34758 @end smallexample
34759
34760 @noindent
34761 Here, the value of @code{lang} is the language name, which can be
34762 found in @ref{Supported Languages}.
34763
34764 Note that the output of the @code{-var-list-children} command also
34765 includes those expressions, so the @code{-var-info-expression} command
34766 is of limited use.
34767
34768 @findex -var-info-path-expression
34769 @subheading The @code{-var-info-path-expression} Command
34770
34771 @subsubheading Synopsis
34772
34773 @smallexample
34774 -var-info-path-expression @var{name}
34775 @end smallexample
34776
34777 Returns an expression that can be evaluated in the current
34778 context and will yield the same value that a variable object has.
34779 Compare this with the @code{-var-info-expression} command, which
34780 result can be used only for UI presentation. Typical use of
34781 the @code{-var-info-path-expression} command is creating a
34782 watchpoint from a variable object.
34783
34784 This command is currently not valid for children of a dynamic varobj,
34785 and will give an error when invoked on one.
34786
34787 For example, suppose @code{C} is a C@t{++} class, derived from class
34788 @code{Base}, and that the @code{Base} class has a member called
34789 @code{m_size}. Assume a variable @code{c} is has the type of
34790 @code{C} and a variable object @code{C} was created for variable
34791 @code{c}. Then, we'll get this output:
34792 @smallexample
34793 (gdb) -var-info-path-expression C.Base.public.m_size
34794 ^done,path_expr=((Base)c).m_size)
34795 @end smallexample
34796
34797 @findex -var-show-attributes
34798 @subheading The @code{-var-show-attributes} Command
34799
34800 @subsubheading Synopsis
34801
34802 @smallexample
34803 -var-show-attributes @var{name}
34804 @end smallexample
34805
34806 List attributes of the specified variable object @var{name}:
34807
34808 @smallexample
34809 status=@var{attr} [ ( ,@var{attr} )* ]
34810 @end smallexample
34811
34812 @noindent
34813 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
34814
34815 @findex -var-evaluate-expression
34816 @subheading The @code{-var-evaluate-expression} Command
34817
34818 @subsubheading Synopsis
34819
34820 @smallexample
34821 -var-evaluate-expression [-f @var{format-spec}] @var{name}
34822 @end smallexample
34823
34824 Evaluates the expression that is represented by the specified variable
34825 object and returns its value as a string. The format of the string
34826 can be specified with the @samp{-f} option. The possible values of
34827 this option are the same as for @code{-var-set-format}
34828 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
34829 the current display format will be used. The current display format
34830 can be changed using the @code{-var-set-format} command.
34831
34832 @smallexample
34833 value=@var{value}
34834 @end smallexample
34835
34836 Note that one must invoke @code{-var-list-children} for a variable
34837 before the value of a child variable can be evaluated.
34838
34839 @findex -var-assign
34840 @subheading The @code{-var-assign} Command
34841
34842 @subsubheading Synopsis
34843
34844 @smallexample
34845 -var-assign @var{name} @var{expression}
34846 @end smallexample
34847
34848 Assigns the value of @var{expression} to the variable object specified
34849 by @var{name}. The object must be @samp{editable}. If the variable's
34850 value is altered by the assign, the variable will show up in any
34851 subsequent @code{-var-update} list.
34852
34853 @subsubheading Example
34854
34855 @smallexample
34856 (gdb)
34857 -var-assign var1 3
34858 ^done,value="3"
34859 (gdb)
34860 -var-update *
34861 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
34862 (gdb)
34863 @end smallexample
34864
34865 @findex -var-update
34866 @subheading The @code{-var-update} Command
34867
34868 @subsubheading Synopsis
34869
34870 @smallexample
34871 -var-update [@var{print-values}] @{@var{name} | "*"@}
34872 @end smallexample
34873
34874 Reevaluate the expressions corresponding to the variable object
34875 @var{name} and all its direct and indirect children, and return the
34876 list of variable objects whose values have changed; @var{name} must
34877 be a root variable object. Here, ``changed'' means that the result of
34878 @code{-var-evaluate-expression} before and after the
34879 @code{-var-update} is different. If @samp{*} is used as the variable
34880 object names, all existing variable objects are updated, except
34881 for frozen ones (@pxref{-var-set-frozen}). The option
34882 @var{print-values} determines whether both names and values, or just
34883 names are printed. The possible values of this option are the same
34884 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
34885 recommended to use the @samp{--all-values} option, to reduce the
34886 number of MI commands needed on each program stop.
34887
34888 With the @samp{*} parameter, if a variable object is bound to a
34889 currently running thread, it will not be updated, without any
34890 diagnostic.
34891
34892 If @code{-var-set-update-range} was previously used on a varobj, then
34893 only the selected range of children will be reported.
34894
34895 @code{-var-update} reports all the changed varobjs in a tuple named
34896 @samp{changelist}.
34897
34898 Each item in the change list is itself a tuple holding:
34899
34900 @table @samp
34901 @item name
34902 The name of the varobj.
34903
34904 @item value
34905 If values were requested for this update, then this field will be
34906 present and will hold the value of the varobj.
34907
34908 @item in_scope
34909 @anchor{-var-update}
34910 This field is a string which may take one of three values:
34911
34912 @table @code
34913 @item "true"
34914 The variable object's current value is valid.
34915
34916 @item "false"
34917 The variable object does not currently hold a valid value but it may
34918 hold one in the future if its associated expression comes back into
34919 scope.
34920
34921 @item "invalid"
34922 The variable object no longer holds a valid value.
34923 This can occur when the executable file being debugged has changed,
34924 either through recompilation or by using the @value{GDBN} @code{file}
34925 command. The front end should normally choose to delete these variable
34926 objects.
34927 @end table
34928
34929 In the future new values may be added to this list so the front should
34930 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
34931
34932 @item type_changed
34933 This is only present if the varobj is still valid. If the type
34934 changed, then this will be the string @samp{true}; otherwise it will
34935 be @samp{false}.
34936
34937 When a varobj's type changes, its children are also likely to have
34938 become incorrect. Therefore, the varobj's children are automatically
34939 deleted when this attribute is @samp{true}. Also, the varobj's update
34940 range, when set using the @code{-var-set-update-range} command, is
34941 unset.
34942
34943 @item new_type
34944 If the varobj's type changed, then this field will be present and will
34945 hold the new type.
34946
34947 @item new_num_children
34948 For a dynamic varobj, if the number of children changed, or if the
34949 type changed, this will be the new number of children.
34950
34951 The @samp{numchild} field in other varobj responses is generally not
34952 valid for a dynamic varobj -- it will show the number of children that
34953 @value{GDBN} knows about, but because dynamic varobjs lazily
34954 instantiate their children, this will not reflect the number of
34955 children which may be available.
34956
34957 The @samp{new_num_children} attribute only reports changes to the
34958 number of children known by @value{GDBN}. This is the only way to
34959 detect whether an update has removed children (which necessarily can
34960 only happen at the end of the update range).
34961
34962 @item displayhint
34963 The display hint, if any.
34964
34965 @item has_more
34966 This is an integer value, which will be 1 if there are more children
34967 available outside the varobj's update range.
34968
34969 @item dynamic
34970 This attribute will be present and have the value @samp{1} if the
34971 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
34972 then this attribute will not be present.
34973
34974 @item new_children
34975 If new children were added to a dynamic varobj within the selected
34976 update range (as set by @code{-var-set-update-range}), then they will
34977 be listed in this attribute.
34978 @end table
34979
34980 @subsubheading Example
34981
34982 @smallexample
34983 (gdb)
34984 -var-assign var1 3
34985 ^done,value="3"
34986 (gdb)
34987 -var-update --all-values var1
34988 ^done,changelist=[@{name="var1",value="3",in_scope="true",
34989 type_changed="false"@}]
34990 (gdb)
34991 @end smallexample
34992
34993 @findex -var-set-frozen
34994 @anchor{-var-set-frozen}
34995 @subheading The @code{-var-set-frozen} Command
34996
34997 @subsubheading Synopsis
34998
34999 @smallexample
35000 -var-set-frozen @var{name} @var{flag}
35001 @end smallexample
35002
35003 Set the frozenness flag on the variable object @var{name}. The
35004 @var{flag} parameter should be either @samp{1} to make the variable
35005 frozen or @samp{0} to make it unfrozen. If a variable object is
35006 frozen, then neither itself, nor any of its children, are
35007 implicitly updated by @code{-var-update} of
35008 a parent variable or by @code{-var-update *}. Only
35009 @code{-var-update} of the variable itself will update its value and
35010 values of its children. After a variable object is unfrozen, it is
35011 implicitly updated by all subsequent @code{-var-update} operations.
35012 Unfreezing a variable does not update it, only subsequent
35013 @code{-var-update} does.
35014
35015 @subsubheading Example
35016
35017 @smallexample
35018 (gdb)
35019 -var-set-frozen V 1
35020 ^done
35021 (gdb)
35022 @end smallexample
35023
35024 @findex -var-set-update-range
35025 @anchor{-var-set-update-range}
35026 @subheading The @code{-var-set-update-range} command
35027
35028 @subsubheading Synopsis
35029
35030 @smallexample
35031 -var-set-update-range @var{name} @var{from} @var{to}
35032 @end smallexample
35033
35034 Set the range of children to be returned by future invocations of
35035 @code{-var-update}.
35036
35037 @var{from} and @var{to} indicate the range of children to report. If
35038 @var{from} or @var{to} is less than zero, the range is reset and all
35039 children will be reported. Otherwise, children starting at @var{from}
35040 (zero-based) and up to and excluding @var{to} will be reported.
35041
35042 @subsubheading Example
35043
35044 @smallexample
35045 (gdb)
35046 -var-set-update-range V 1 2
35047 ^done
35048 @end smallexample
35049
35050 @findex -var-set-visualizer
35051 @anchor{-var-set-visualizer}
35052 @subheading The @code{-var-set-visualizer} command
35053
35054 @subsubheading Synopsis
35055
35056 @smallexample
35057 -var-set-visualizer @var{name} @var{visualizer}
35058 @end smallexample
35059
35060 Set a visualizer for the variable object @var{name}.
35061
35062 @var{visualizer} is the visualizer to use. The special value
35063 @samp{None} means to disable any visualizer in use.
35064
35065 If not @samp{None}, @var{visualizer} must be a Python expression.
35066 This expression must evaluate to a callable object which accepts a
35067 single argument. @value{GDBN} will call this object with the value of
35068 the varobj @var{name} as an argument (this is done so that the same
35069 Python pretty-printing code can be used for both the CLI and MI).
35070 When called, this object must return an object which conforms to the
35071 pretty-printing interface (@pxref{Pretty Printing API}).
35072
35073 The pre-defined function @code{gdb.default_visualizer} may be used to
35074 select a visualizer by following the built-in process
35075 (@pxref{Selecting Pretty-Printers}). This is done automatically when
35076 a varobj is created, and so ordinarily is not needed.
35077
35078 This feature is only available if Python support is enabled. The MI
35079 command @code{-list-features} (@pxref{GDB/MI Support Commands})
35080 can be used to check this.
35081
35082 @subsubheading Example
35083
35084 Resetting the visualizer:
35085
35086 @smallexample
35087 (gdb)
35088 -var-set-visualizer V None
35089 ^done
35090 @end smallexample
35091
35092 Reselecting the default (type-based) visualizer:
35093
35094 @smallexample
35095 (gdb)
35096 -var-set-visualizer V gdb.default_visualizer
35097 ^done
35098 @end smallexample
35099
35100 Suppose @code{SomeClass} is a visualizer class. A lambda expression
35101 can be used to instantiate this class for a varobj:
35102
35103 @smallexample
35104 (gdb)
35105 -var-set-visualizer V "lambda val: SomeClass()"
35106 ^done
35107 @end smallexample
35108
35109 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35110 @node GDB/MI Data Manipulation
35111 @section @sc{gdb/mi} Data Manipulation
35112
35113 @cindex data manipulation, in @sc{gdb/mi}
35114 @cindex @sc{gdb/mi}, data manipulation
35115 This section describes the @sc{gdb/mi} commands that manipulate data:
35116 examine memory and registers, evaluate expressions, etc.
35117
35118 For details about what an addressable memory unit is,
35119 @pxref{addressable memory unit}.
35120
35121 @c REMOVED FROM THE INTERFACE.
35122 @c @subheading -data-assign
35123 @c Change the value of a program variable. Plenty of side effects.
35124 @c @subsubheading GDB Command
35125 @c set variable
35126 @c @subsubheading Example
35127 @c N.A.
35128
35129 @findex -data-disassemble
35130 @subheading The @code{-data-disassemble} Command
35131
35132 @subsubheading Synopsis
35133
35134 @smallexample
35135 -data-disassemble
35136 ( -s @var{start-addr} -e @var{end-addr}
35137 | -a @var{addr}
35138 | -f @var{filename} -l @var{linenum} [ -n @var{lines} ] )
35139 [ --opcodes @var{opcodes-mode} ]
35140 [ --source ]
35141 [ -- @var{mode} ]
35142 @end smallexample
35143
35144 @noindent
35145 Where:
35146
35147 @table @samp
35148 @item @var{start-addr}
35149 is the beginning address (or @code{$pc})
35150 @item @var{end-addr}
35151 is the end address
35152 @item @var{addr}
35153 is an address anywhere within (or the name of) the function to
35154 disassemble. If an address is specified, the whole function
35155 surrounding that address will be disassembled. If a name is
35156 specified, the whole function with that name will be disassembled.
35157 @item @var{filename}
35158 is the name of the file to disassemble
35159 @item @var{linenum}
35160 is the line number to disassemble around
35161 @item @var{lines}
35162 is the number of disassembly lines to be produced. If it is -1,
35163 the whole function will be disassembled, in case no @var{end-addr} is
35164 specified. If @var{end-addr} is specified as a non-zero value, and
35165 @var{lines} is lower than the number of disassembly lines between
35166 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
35167 displayed; if @var{lines} is higher than the number of lines between
35168 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
35169 are displayed.
35170 @item @var{opcodes-mode}
35171 can only be used with @var{mode} 0, and should be one of the following:
35172 @table @samp
35173 @item none
35174 no opcode information will be included in the result.
35175
35176 @item bytes
35177 opcodes will be included in the result, the opcodes will be formatted
35178 as for @kbd{disassemble /b}.
35179
35180 @item display
35181 opcodes will be included in the result, the opcodes will be formatted
35182 as for @kbd{disassemble /r}.
35183 @end table
35184 @item @var{mode}
35185 the use of @var{mode} is deprecated in favour of using the
35186 @code{--opcodes} and @code{--source} options. When no @var{mode} is
35187 given, @var{mode} 0 will be assumed. However, the @var{mode} is still
35188 available for backward compatibility. The @var{mode} should be one of:
35189 @table @samp
35190 @item 0
35191 @emph{disassembly only}, this is the default mode if no mode is
35192 specified.
35193
35194 @item 1
35195 @emph{mixed source and disassembly (deprecated)}, it is not possible
35196 to recreate this mode using @code{--opcodes} and @code{--source}
35197 options.
35198
35199 @item 2
35200 @emph{disassembly with raw opcodes}, this mode is equivalent to using
35201 @var{mode} 0 and passing @code{--opcodes bytes} to the command.
35202
35203 @item 3
35204 @emph{mixed source and disassembly with raw opcodes (deprecated)}, it
35205 is not possible to recreate this mode using @code{--opcodes} and
35206 @code{--source} options.
35207
35208 @item 4
35209 @emph{mixed source and disassembly}, this mode is equivalent to using
35210 @var{mode} 0 and passing @code{--source} to the command.
35211
35212 @item 5
35213 @emph{mixed source and disassembly with raw opcodes}, this mode is
35214 equivalent to using @var{mode} 0 and passing @code{--opcodes bytes}
35215 and @code{--source} to the command.
35216 @end table
35217 Modes 1 and 3 are deprecated. The output is ``source centric''
35218 which hasn't proved useful in practice.
35219 @xref{Machine Code}, for a discussion of the difference between
35220 @code{/m} and @code{/s} output of the @code{disassemble} command.
35221 @end table
35222
35223 The @code{--source} can only be used with @var{mode} 0. Passing this
35224 option will include the source code in the disassembly result as if
35225 @var{mode} 4 or 5 had been used.
35226
35227 @subsubheading Result
35228
35229 The result of the @code{-data-disassemble} command will be a list named
35230 @samp{asm_insns}, the contents of this list depend on the options used
35231 with the @code{-data-disassemble} command.
35232
35233 For modes 0 and 2, and when the @code{--source} option is not used, the
35234 @samp{asm_insns} list contains tuples with the following fields:
35235
35236 @table @code
35237 @item address
35238 The address at which this instruction was disassembled.
35239
35240 @item func-name
35241 The name of the function this instruction is within.
35242
35243 @item offset
35244 The decimal offset in bytes from the start of @samp{func-name}.
35245
35246 @item inst
35247 The text disassembly for this @samp{address}.
35248
35249 @item opcodes
35250 This field is only present for modes 2, 3 and 5, or when the
35251 @code{--opcodes} option @samp{bytes} or @samp{display} is used. This
35252 contains the raw opcode bytes for the @samp{inst} field.
35253
35254 When the @samp{--opcodes} option is not passed to
35255 @code{-data-disassemble}, or the @samp{bytes} value is passed to
35256 @samp{--opcodes}, then the bytes are formatted as a series of single
35257 bytes, in hex, in ascending address order, with a single space between
35258 each byte. This format is equivalent to the @samp{/b} option being
35259 used with the @kbd{disassemble} command
35260 (@pxref{disassemble,,@kbd{disassemble}}).
35261
35262 When @samp{--opcodes} is passed the value @samp{display} then the bytes
35263 are formatted in the natural instruction display order. This means
35264 multiple bytes can be grouped together, and the bytes might be
35265 byte-swapped. This format is equivalent to the @samp{/r} option being
35266 used with the @kbd{disassemble} command.
35267 @end table
35268
35269 For modes 1, 3, 4 and 5, or when the @code{--source} option is used, the
35270 @samp{asm_insns} list contains tuples named @samp{src_and_asm_line},
35271 each of which has the following fields:
35272
35273 @table @code
35274 @item line
35275 The line number within @samp{file}.
35276
35277 @item file
35278 The file name from the compilation unit. This might be an absolute
35279 file name or a relative file name depending on the compile command
35280 used.
35281
35282 @item fullname
35283 Absolute file name of @samp{file}. It is converted to a canonical form
35284 using the source file search path
35285 (@pxref{Source Path, ,Specifying Source Directories})
35286 and after resolving all the symbolic links.
35287
35288 If the source file is not found this field will contain the path as
35289 present in the debug information.
35290
35291 @item line_asm_insn
35292 This is a list of tuples containing the disassembly for @samp{line} in
35293 @samp{file}. The fields of each tuple are the same as for
35294 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
35295 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
35296 @samp{opcodes}.
35297
35298 @end table
35299
35300 Note that whatever included in the @samp{inst} field, is not
35301 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
35302 adjust its format.
35303
35304 @subsubheading @value{GDBN} Command
35305
35306 The corresponding @value{GDBN} command is @samp{disassemble}.
35307
35308 @subsubheading Example
35309
35310 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
35311
35312 @smallexample
35313 (gdb)
35314 -data-disassemble -s $pc -e "$pc + 20" -- 0
35315 ^done,
35316 asm_insns=[
35317 @{address="0x000107c0",func-name="main",offset="4",
35318 inst="mov 2, %o0"@},
35319 @{address="0x000107c4",func-name="main",offset="8",
35320 inst="sethi %hi(0x11800), %o2"@},
35321 @{address="0x000107c8",func-name="main",offset="12",
35322 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
35323 @{address="0x000107cc",func-name="main",offset="16",
35324 inst="sethi %hi(0x11800), %o2"@},
35325 @{address="0x000107d0",func-name="main",offset="20",
35326 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
35327 (gdb)
35328 @end smallexample
35329
35330 Disassemble the whole @code{main} function. Line 32 is part of
35331 @code{main}.
35332
35333 @smallexample
35334 -data-disassemble -f basics.c -l 32 -- 0
35335 ^done,asm_insns=[
35336 @{address="0x000107bc",func-name="main",offset="0",
35337 inst="save %sp, -112, %sp"@},
35338 @{address="0x000107c0",func-name="main",offset="4",
35339 inst="mov 2, %o0"@},
35340 @{address="0x000107c4",func-name="main",offset="8",
35341 inst="sethi %hi(0x11800), %o2"@},
35342 [@dots{}]
35343 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
35344 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
35345 (gdb)
35346 @end smallexample
35347
35348 Disassemble 3 instructions from the start of @code{main}:
35349
35350 @smallexample
35351 (gdb)
35352 -data-disassemble -f basics.c -l 32 -n 3 -- 0
35353 ^done,asm_insns=[
35354 @{address="0x000107bc",func-name="main",offset="0",
35355 inst="save %sp, -112, %sp"@},
35356 @{address="0x000107c0",func-name="main",offset="4",
35357 inst="mov 2, %o0"@},
35358 @{address="0x000107c4",func-name="main",offset="8",
35359 inst="sethi %hi(0x11800), %o2"@}]
35360 (gdb)
35361 @end smallexample
35362
35363 Disassemble 3 instructions from the start of @code{main} in mixed mode:
35364
35365 @smallexample
35366 (gdb)
35367 -data-disassemble -f basics.c -l 32 -n 3 -- 1
35368 ^done,asm_insns=[
35369 src_and_asm_line=@{line="31",
35370 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
35371 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
35372 line_asm_insn=[@{address="0x000107bc",
35373 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
35374 src_and_asm_line=@{line="32",
35375 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
35376 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
35377 line_asm_insn=[@{address="0x000107c0",
35378 func-name="main",offset="4",inst="mov 2, %o0"@},
35379 @{address="0x000107c4",func-name="main",offset="8",
35380 inst="sethi %hi(0x11800), %o2"@}]@}]
35381 (gdb)
35382 @end smallexample
35383
35384
35385 @findex -data-evaluate-expression
35386 @subheading The @code{-data-evaluate-expression} Command
35387
35388 @subsubheading Synopsis
35389
35390 @smallexample
35391 -data-evaluate-expression @var{expr}
35392 @end smallexample
35393
35394 Evaluate @var{expr} as an expression. The expression could contain an
35395 inferior function call. The function call will execute synchronously.
35396 If the expression contains spaces, it must be enclosed in double quotes.
35397
35398 @subsubheading @value{GDBN} Command
35399
35400 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
35401 @samp{call}. In @code{gdbtk} only, there's a corresponding
35402 @samp{gdb_eval} command.
35403
35404 @subsubheading Example
35405
35406 In the following example, the numbers that precede the commands are the
35407 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
35408 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
35409 output.
35410
35411 @smallexample
35412 211-data-evaluate-expression A
35413 211^done,value="1"
35414 (gdb)
35415 311-data-evaluate-expression &A
35416 311^done,value="0xefffeb7c"
35417 (gdb)
35418 411-data-evaluate-expression A+3
35419 411^done,value="4"
35420 (gdb)
35421 511-data-evaluate-expression "A + 3"
35422 511^done,value="4"
35423 (gdb)
35424 @end smallexample
35425
35426
35427 @findex -data-list-changed-registers
35428 @subheading The @code{-data-list-changed-registers} Command
35429
35430 @subsubheading Synopsis
35431
35432 @smallexample
35433 -data-list-changed-registers
35434 @end smallexample
35435
35436 Display a list of the registers that have changed.
35437
35438 @subsubheading @value{GDBN} Command
35439
35440 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
35441 has the corresponding command @samp{gdb_changed_register_list}.
35442
35443 @subsubheading Example
35444
35445 On a PPC MBX board:
35446
35447 @smallexample
35448 (gdb)
35449 -exec-continue
35450 ^running
35451
35452 (gdb)
35453 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
35454 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
35455 line="5",arch="powerpc"@}
35456 (gdb)
35457 -data-list-changed-registers
35458 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
35459 "10","11","13","14","15","16","17","18","19","20","21","22","23",
35460 "24","25","26","27","28","30","31","64","65","66","67","69"]
35461 (gdb)
35462 @end smallexample
35463
35464
35465 @findex -data-list-register-names
35466 @subheading The @code{-data-list-register-names} Command
35467
35468 @subsubheading Synopsis
35469
35470 @smallexample
35471 -data-list-register-names [ ( @var{regno} )+ ]
35472 @end smallexample
35473
35474 Show a list of register names for the current target. If no arguments
35475 are given, it shows a list of the names of all the registers. If
35476 integer numbers are given as arguments, it will print a list of the
35477 names of the registers corresponding to the arguments. To ensure
35478 consistency between a register name and its number, the output list may
35479 include empty register names.
35480
35481 @subsubheading @value{GDBN} Command
35482
35483 @value{GDBN} does not have a command which corresponds to
35484 @samp{-data-list-register-names}. In @code{gdbtk} there is a
35485 corresponding command @samp{gdb_regnames}.
35486
35487 @subsubheading Example
35488
35489 For the PPC MBX board:
35490 @smallexample
35491 (gdb)
35492 -data-list-register-names
35493 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
35494 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
35495 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
35496 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
35497 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
35498 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
35499 "", "pc","ps","cr","lr","ctr","xer"]
35500 (gdb)
35501 -data-list-register-names 1 2 3
35502 ^done,register-names=["r1","r2","r3"]
35503 (gdb)
35504 @end smallexample
35505
35506 @findex -data-list-register-values
35507 @subheading The @code{-data-list-register-values} Command
35508
35509 @subsubheading Synopsis
35510
35511 @smallexample
35512 -data-list-register-values
35513 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
35514 @end smallexample
35515
35516 Display the registers' contents. The format according to which the
35517 registers' contents are to be returned is given by @var{fmt}, followed
35518 by an optional list of numbers specifying the registers to display. A
35519 missing list of numbers indicates that the contents of all the
35520 registers must be returned. The @code{--skip-unavailable} option
35521 indicates that only the available registers are to be returned.
35522
35523 Allowed formats for @var{fmt} are:
35524
35525 @table @code
35526 @item x
35527 Hexadecimal
35528 @item o
35529 Octal
35530 @item t
35531 Binary
35532 @item d
35533 Decimal
35534 @item r
35535 Raw
35536 @item N
35537 Natural
35538 @end table
35539
35540 @subsubheading @value{GDBN} Command
35541
35542 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
35543 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
35544
35545 @subsubheading Example
35546
35547 For a PPC MBX board (note: line breaks are for readability only, they
35548 don't appear in the actual output):
35549
35550 @smallexample
35551 (gdb)
35552 -data-list-register-values r 64 65
35553 ^done,register-values=[@{number="64",value="0xfe00a300"@},
35554 @{number="65",value="0x00029002"@}]
35555 (gdb)
35556 -data-list-register-values x
35557 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
35558 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
35559 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
35560 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
35561 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
35562 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
35563 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
35564 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
35565 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
35566 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
35567 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
35568 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
35569 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
35570 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
35571 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
35572 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
35573 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
35574 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
35575 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
35576 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
35577 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
35578 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
35579 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
35580 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
35581 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
35582 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
35583 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
35584 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
35585 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
35586 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
35587 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
35588 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
35589 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
35590 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
35591 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
35592 @{number="69",value="0x20002b03"@}]
35593 (gdb)
35594 @end smallexample
35595
35596
35597 @findex -data-read-memory
35598 @subheading The @code{-data-read-memory} Command
35599
35600 This command is deprecated, use @code{-data-read-memory-bytes} instead.
35601
35602 @subsubheading Synopsis
35603
35604 @smallexample
35605 -data-read-memory [ -o @var{byte-offset} ]
35606 @var{address} @var{word-format} @var{word-size}
35607 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
35608 @end smallexample
35609
35610 @noindent
35611 where:
35612
35613 @table @samp
35614 @item @var{address}
35615 An expression specifying the address of the first memory word to be
35616 read. Complex expressions containing embedded white space should be
35617 quoted using the C convention.
35618
35619 @item @var{word-format}
35620 The format to be used to print the memory words. The notation is the
35621 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
35622 ,Output Formats}).
35623
35624 @item @var{word-size}
35625 The size of each memory word in bytes.
35626
35627 @item @var{nr-rows}
35628 The number of rows in the output table.
35629
35630 @item @var{nr-cols}
35631 The number of columns in the output table.
35632
35633 @item @var{aschar}
35634 If present, indicates that each row should include an @sc{ascii} dump. The
35635 value of @var{aschar} is used as a padding character when a byte is not a
35636 member of the printable @sc{ascii} character set (printable @sc{ascii}
35637 characters are those whose code is between 32 and 126, inclusively).
35638
35639 @item @var{byte-offset}
35640 An offset to add to the @var{address} before fetching memory.
35641 @end table
35642
35643 This command displays memory contents as a table of @var{nr-rows} by
35644 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
35645 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
35646 (returned as @samp{total-bytes}). Should less than the requested number
35647 of bytes be returned by the target, the missing words are identified
35648 using @samp{N/A}. The number of bytes read from the target is returned
35649 in @samp{nr-bytes} and the starting address used to read memory in
35650 @samp{addr}.
35651
35652 The address of the next/previous row or page is available in
35653 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
35654 @samp{prev-page}.
35655
35656 @subsubheading @value{GDBN} Command
35657
35658 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
35659 @samp{gdb_get_mem} memory read command.
35660
35661 @subsubheading Example
35662
35663 Read six bytes of memory starting at @code{bytes+6} but then offset by
35664 @code{-6} bytes. Format as three rows of two columns. One byte per
35665 word. Display each word in hex.
35666
35667 @smallexample
35668 (gdb)
35669 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
35670 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
35671 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
35672 prev-page="0x0000138a",memory=[
35673 @{addr="0x00001390",data=["0x00","0x01"]@},
35674 @{addr="0x00001392",data=["0x02","0x03"]@},
35675 @{addr="0x00001394",data=["0x04","0x05"]@}]
35676 (gdb)
35677 @end smallexample
35678
35679 Read two bytes of memory starting at address @code{shorts + 64} and
35680 display as a single word formatted in decimal.
35681
35682 @smallexample
35683 (gdb)
35684 5-data-read-memory shorts+64 d 2 1 1
35685 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
35686 next-row="0x00001512",prev-row="0x0000150e",
35687 next-page="0x00001512",prev-page="0x0000150e",memory=[
35688 @{addr="0x00001510",data=["128"]@}]
35689 (gdb)
35690 @end smallexample
35691
35692 Read thirty two bytes of memory starting at @code{bytes+16} and format
35693 as eight rows of four columns. Include a string encoding with @samp{x}
35694 used as the non-printable character.
35695
35696 @smallexample
35697 (gdb)
35698 4-data-read-memory bytes+16 x 1 8 4 x
35699 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
35700 next-row="0x000013c0",prev-row="0x0000139c",
35701 next-page="0x000013c0",prev-page="0x00001380",memory=[
35702 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
35703 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
35704 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
35705 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
35706 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
35707 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
35708 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
35709 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
35710 (gdb)
35711 @end smallexample
35712
35713 @findex -data-read-memory-bytes
35714 @subheading The @code{-data-read-memory-bytes} Command
35715
35716 @subsubheading Synopsis
35717
35718 @smallexample
35719 -data-read-memory-bytes [ -o @var{offset} ]
35720 @var{address} @var{count}
35721 @end smallexample
35722
35723 @noindent
35724 where:
35725
35726 @table @samp
35727 @item @var{address}
35728 An expression specifying the address of the first addressable memory unit
35729 to be read. Complex expressions containing embedded white space should be
35730 quoted using the C convention.
35731
35732 @item @var{count}
35733 The number of addressable memory units to read. This should be an integer
35734 literal.
35735
35736 @item @var{offset}
35737 The offset relative to @var{address} at which to start reading. This
35738 should be an integer literal. This option is provided so that a frontend
35739 is not required to first evaluate address and then perform address
35740 arithmetics itself.
35741
35742 @end table
35743
35744 This command attempts to read all accessible memory regions in the
35745 specified range. First, all regions marked as unreadable in the memory
35746 map (if one is defined) will be skipped. @xref{Memory Region
35747 Attributes}. Second, @value{GDBN} will attempt to read the remaining
35748 regions. For each one, if reading full region results in an errors,
35749 @value{GDBN} will try to read a subset of the region.
35750
35751 In general, every single memory unit in the region may be readable or not,
35752 and the only way to read every readable unit is to try a read at
35753 every address, which is not practical. Therefore, @value{GDBN} will
35754 attempt to read all accessible memory units at either beginning or the end
35755 of the region, using a binary division scheme. This heuristic works
35756 well for reading across a memory map boundary. Note that if a region
35757 has a readable range that is neither at the beginning or the end,
35758 @value{GDBN} will not read it.
35759
35760 The result record (@pxref{GDB/MI Result Records}) that is output of
35761 the command includes a field named @samp{memory} whose content is a
35762 list of tuples. Each tuple represent a successfully read memory block
35763 and has the following fields:
35764
35765 @table @code
35766 @item begin
35767 The start address of the memory block, as hexadecimal literal.
35768
35769 @item end
35770 The end address of the memory block, as hexadecimal literal.
35771
35772 @item offset
35773 The offset of the memory block, as hexadecimal literal, relative to
35774 the start address passed to @code{-data-read-memory-bytes}.
35775
35776 @item contents
35777 The contents of the memory block, in hex.
35778
35779 @end table
35780
35781
35782
35783 @subsubheading @value{GDBN} Command
35784
35785 The corresponding @value{GDBN} command is @samp{x}.
35786
35787 @subsubheading Example
35788
35789 @smallexample
35790 (gdb)
35791 -data-read-memory-bytes &a 10
35792 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
35793 end="0xbffff15e",
35794 contents="01000000020000000300"@}]
35795 (gdb)
35796 @end smallexample
35797
35798
35799 @findex -data-write-memory-bytes
35800 @subheading The @code{-data-write-memory-bytes} Command
35801
35802 @subsubheading Synopsis
35803
35804 @smallexample
35805 -data-write-memory-bytes @var{address} @var{contents}
35806 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
35807 @end smallexample
35808
35809 @noindent
35810 where:
35811
35812 @table @samp
35813 @item @var{address}
35814 An expression specifying the address of the first addressable memory unit
35815 to be written. Complex expressions containing embedded white space should
35816 be quoted using the C convention.
35817
35818 @item @var{contents}
35819 The hex-encoded data to write. It is an error if @var{contents} does
35820 not represent an integral number of addressable memory units.
35821
35822 @item @var{count}
35823 Optional argument indicating the number of addressable memory units to be
35824 written. If @var{count} is greater than @var{contents}' length,
35825 @value{GDBN} will repeatedly write @var{contents} until it fills
35826 @var{count} memory units.
35827
35828 @end table
35829
35830 @subsubheading @value{GDBN} Command
35831
35832 There's no corresponding @value{GDBN} command.
35833
35834 @subsubheading Example
35835
35836 @smallexample
35837 (gdb)
35838 -data-write-memory-bytes &a "aabbccdd"
35839 ^done
35840 (gdb)
35841 @end smallexample
35842
35843 @smallexample
35844 (gdb)
35845 -data-write-memory-bytes &a "aabbccdd" 16e
35846 ^done
35847 (gdb)
35848 @end smallexample
35849
35850 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35851 @node GDB/MI Tracepoint Commands
35852 @section @sc{gdb/mi} Tracepoint Commands
35853
35854 The commands defined in this section implement MI support for
35855 tracepoints. For detailed introduction, see @ref{Tracepoints}.
35856
35857 @findex -trace-find
35858 @subheading The @code{-trace-find} Command
35859
35860 @subsubheading Synopsis
35861
35862 @smallexample
35863 -trace-find @var{mode} [@var{parameters}@dots{}]
35864 @end smallexample
35865
35866 Find a trace frame using criteria defined by @var{mode} and
35867 @var{parameters}. The following table lists permissible
35868 modes and their parameters. For details of operation, see @ref{tfind}.
35869
35870 @table @samp
35871
35872 @item none
35873 No parameters are required. Stops examining trace frames.
35874
35875 @item frame-number
35876 An integer is required as parameter. Selects tracepoint frame with
35877 that index.
35878
35879 @item tracepoint-number
35880 An integer is required as parameter. Finds next
35881 trace frame that corresponds to tracepoint with the specified number.
35882
35883 @item pc
35884 An address is required as parameter. Finds
35885 next trace frame that corresponds to any tracepoint at the specified
35886 address.
35887
35888 @item pc-inside-range
35889 Two addresses are required as parameters. Finds next trace
35890 frame that corresponds to a tracepoint at an address inside the
35891 specified range. Both bounds are considered to be inside the range.
35892
35893 @item pc-outside-range
35894 Two addresses are required as parameters. Finds
35895 next trace frame that corresponds to a tracepoint at an address outside
35896 the specified range. Both bounds are considered to be inside the range.
35897
35898 @item line
35899 Location specification is required as parameter. @xref{Location Specifications}.
35900 Finds next trace frame that corresponds to a tracepoint at
35901 the specified location.
35902
35903 @end table
35904
35905 If @samp{none} was passed as @var{mode}, the response does not
35906 have fields. Otherwise, the response may have the following fields:
35907
35908 @table @samp
35909 @item found
35910 This field has either @samp{0} or @samp{1} as the value, depending
35911 on whether a matching tracepoint was found.
35912
35913 @item traceframe
35914 The index of the found traceframe. This field is present iff
35915 the @samp{found} field has value of @samp{1}.
35916
35917 @item tracepoint
35918 The index of the found tracepoint. This field is present iff
35919 the @samp{found} field has value of @samp{1}.
35920
35921 @item frame
35922 The information about the frame corresponding to the found trace
35923 frame. This field is present only if a trace frame was found.
35924 @xref{GDB/MI Frame Information}, for description of this field.
35925
35926 @end table
35927
35928 @subsubheading @value{GDBN} Command
35929
35930 The corresponding @value{GDBN} command is @samp{tfind}.
35931
35932 @findex -trace-define-variable
35933 @subheading -trace-define-variable
35934
35935 @subsubheading Synopsis
35936
35937 @smallexample
35938 -trace-define-variable @var{name} [ @var{value} ]
35939 @end smallexample
35940
35941 Create trace variable @var{name} if it does not exist. If
35942 @var{value} is specified, sets the initial value of the specified
35943 trace variable to that value. Note that the @var{name} should start
35944 with the @samp{$} character.
35945
35946 @subsubheading @value{GDBN} Command
35947
35948 The corresponding @value{GDBN} command is @samp{tvariable}.
35949
35950 @findex -trace-frame-collected
35951 @subheading The @code{-trace-frame-collected} Command
35952
35953 @subsubheading Synopsis
35954
35955 @smallexample
35956 -trace-frame-collected
35957 [--var-print-values @var{var_pval}]
35958 [--comp-print-values @var{comp_pval}]
35959 [--registers-format @var{regformat}]
35960 [--memory-contents]
35961 @end smallexample
35962
35963 This command returns the set of collected objects, register names,
35964 trace state variable names, memory ranges and computed expressions
35965 that have been collected at a particular trace frame. The optional
35966 parameters to the command affect the output format in different ways.
35967 See the output description table below for more details.
35968
35969 The reported names can be used in the normal manner to create
35970 varobjs and inspect the objects themselves. The items returned by
35971 this command are categorized so that it is clear which is a variable,
35972 which is a register, which is a trace state variable, which is a
35973 memory range and which is a computed expression.
35974
35975 For instance, if the actions were
35976 @smallexample
35977 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
35978 collect *(int*)0xaf02bef0@@40
35979 @end smallexample
35980
35981 @noindent
35982 the object collected in its entirety would be @code{myVar}. The
35983 object @code{myArray} would be partially collected, because only the
35984 element at index @code{myIndex} would be collected. The remaining
35985 objects would be computed expressions.
35986
35987 An example output would be:
35988
35989 @smallexample
35990 (gdb)
35991 -trace-frame-collected
35992 ^done,
35993 explicit-variables=[@{name="myVar",value="1"@}],
35994 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
35995 @{name="myObj.field",value="0"@},
35996 @{name="myPtr->field",value="1"@},
35997 @{name="myCount + 2",value="3"@},
35998 @{name="$tvar1 + 1",value="43970027"@}],
35999 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
36000 @{number="1",value="0x0"@},
36001 @{number="2",value="0x4"@},
36002 ...
36003 @{number="125",value="0x0"@}],
36004 tvars=[@{name="$tvar1",current="43970026"@}],
36005 memory=[@{address="0x0000000000602264",length="4"@},
36006 @{address="0x0000000000615bc0",length="4"@}]
36007 (gdb)
36008 @end smallexample
36009
36010 Where:
36011
36012 @table @code
36013 @item explicit-variables
36014 The set of objects that have been collected in their entirety (as
36015 opposed to collecting just a few elements of an array or a few struct
36016 members). For each object, its name and value are printed.
36017 The @code{--var-print-values} option affects how or whether the value
36018 field is output. If @var{var_pval} is 0, then print only the names;
36019 if it is 1, print also their values; and if it is 2, print the name,
36020 type and value for simple data types, and the name and type for
36021 arrays, structures and unions.
36022
36023 @item computed-expressions
36024 The set of computed expressions that have been collected at the
36025 current trace frame. The @code{--comp-print-values} option affects
36026 this set like the @code{--var-print-values} option affects the
36027 @code{explicit-variables} set. See above.
36028
36029 @item registers
36030 The registers that have been collected at the current trace frame.
36031 For each register collected, the name and current value are returned.
36032 The value is formatted according to the @code{--registers-format}
36033 option. See the @command{-data-list-register-values} command for a
36034 list of the allowed formats. The default is @samp{x}.
36035
36036 @item tvars
36037 The trace state variables that have been collected at the current
36038 trace frame. For each trace state variable collected, the name and
36039 current value are returned.
36040
36041 @item memory
36042 The set of memory ranges that have been collected at the current trace
36043 frame. Its content is a list of tuples. Each tuple represents a
36044 collected memory range and has the following fields:
36045
36046 @table @code
36047 @item address
36048 The start address of the memory range, as hexadecimal literal.
36049
36050 @item length
36051 The length of the memory range, as decimal literal.
36052
36053 @item contents
36054 The contents of the memory block, in hex. This field is only present
36055 if the @code{--memory-contents} option is specified.
36056
36057 @end table
36058
36059 @end table
36060
36061 @subsubheading @value{GDBN} Command
36062
36063 There is no corresponding @value{GDBN} command.
36064
36065 @subsubheading Example
36066
36067 @findex -trace-list-variables
36068 @subheading -trace-list-variables
36069
36070 @subsubheading Synopsis
36071
36072 @smallexample
36073 -trace-list-variables
36074 @end smallexample
36075
36076 Return a table of all defined trace variables. Each element of the
36077 table has the following fields:
36078
36079 @table @samp
36080 @item name
36081 The name of the trace variable. This field is always present.
36082
36083 @item initial
36084 The initial value. This is a 64-bit signed integer. This
36085 field is always present.
36086
36087 @item current
36088 The value the trace variable has at the moment. This is a 64-bit
36089 signed integer. This field is absent iff current value is
36090 not defined, for example if the trace was never run, or is
36091 presently running.
36092
36093 @end table
36094
36095 @subsubheading @value{GDBN} Command
36096
36097 The corresponding @value{GDBN} command is @samp{tvariables}.
36098
36099 @subsubheading Example
36100
36101 @smallexample
36102 (gdb)
36103 -trace-list-variables
36104 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
36105 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
36106 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
36107 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
36108 body=[variable=@{name="$trace_timestamp",initial="0"@}
36109 variable=@{name="$foo",initial="10",current="15"@}]@}
36110 (gdb)
36111 @end smallexample
36112
36113 @findex -trace-save
36114 @subheading -trace-save
36115
36116 @subsubheading Synopsis
36117
36118 @smallexample
36119 -trace-save [ -r ] [ -ctf ] @var{filename}
36120 @end smallexample
36121
36122 Saves the collected trace data to @var{filename}. Without the
36123 @samp{-r} option, the data is downloaded from the target and saved
36124 in a local file. With the @samp{-r} option the target is asked
36125 to perform the save.
36126
36127 By default, this command will save the trace in the tfile format. You can
36128 supply the optional @samp{-ctf} argument to save it the CTF format. See
36129 @ref{Trace Files} for more information about CTF.
36130
36131 @subsubheading @value{GDBN} Command
36132
36133 The corresponding @value{GDBN} command is @samp{tsave}.
36134
36135
36136 @findex -trace-start
36137 @subheading -trace-start
36138
36139 @subsubheading Synopsis
36140
36141 @smallexample
36142 -trace-start
36143 @end smallexample
36144
36145 Starts a tracing experiment. The result of this command does not
36146 have any fields.
36147
36148 @subsubheading @value{GDBN} Command
36149
36150 The corresponding @value{GDBN} command is @samp{tstart}.
36151
36152 @findex -trace-status
36153 @subheading -trace-status
36154
36155 @subsubheading Synopsis
36156
36157 @smallexample
36158 -trace-status
36159 @end smallexample
36160
36161 Obtains the status of a tracing experiment. The result may include
36162 the following fields:
36163
36164 @table @samp
36165
36166 @item supported
36167 May have a value of either @samp{0}, when no tracing operations are
36168 supported, @samp{1}, when all tracing operations are supported, or
36169 @samp{file} when examining trace file. In the latter case, examining
36170 of trace frame is possible but new tracing experiement cannot be
36171 started. This field is always present.
36172
36173 @item running
36174 May have a value of either @samp{0} or @samp{1} depending on whether
36175 tracing experiement is in progress on target. This field is present
36176 if @samp{supported} field is not @samp{0}.
36177
36178 @item stop-reason
36179 Report the reason why the tracing was stopped last time. This field
36180 may be absent iff tracing was never stopped on target yet. The
36181 value of @samp{request} means the tracing was stopped as result of
36182 the @code{-trace-stop} command. The value of @samp{overflow} means
36183 the tracing buffer is full. The value of @samp{disconnection} means
36184 tracing was automatically stopped when @value{GDBN} has disconnected.
36185 The value of @samp{passcount} means tracing was stopped when a
36186 tracepoint was passed a maximal number of times for that tracepoint.
36187 This field is present if @samp{supported} field is not @samp{0}.
36188
36189 @item stopping-tracepoint
36190 The number of tracepoint whose passcount as exceeded. This field is
36191 present iff the @samp{stop-reason} field has the value of
36192 @samp{passcount}.
36193
36194 @item frames
36195 @itemx frames-created
36196 The @samp{frames} field is a count of the total number of trace frames
36197 in the trace buffer, while @samp{frames-created} is the total created
36198 during the run, including ones that were discarded, such as when a
36199 circular trace buffer filled up. Both fields are optional.
36200
36201 @item buffer-size
36202 @itemx buffer-free
36203 These fields tell the current size of the tracing buffer and the
36204 remaining space. These fields are optional.
36205
36206 @item circular
36207 The value of the circular trace buffer flag. @code{1} means that the
36208 trace buffer is circular and old trace frames will be discarded if
36209 necessary to make room, @code{0} means that the trace buffer is linear
36210 and may fill up.
36211
36212 @item disconnected
36213 The value of the disconnected tracing flag. @code{1} means that
36214 tracing will continue after @value{GDBN} disconnects, @code{0} means
36215 that the trace run will stop.
36216
36217 @item trace-file
36218 The filename of the trace file being examined. This field is
36219 optional, and only present when examining a trace file.
36220
36221 @end table
36222
36223 @subsubheading @value{GDBN} Command
36224
36225 The corresponding @value{GDBN} command is @samp{tstatus}.
36226
36227 @findex -trace-stop
36228 @subheading -trace-stop
36229
36230 @subsubheading Synopsis
36231
36232 @smallexample
36233 -trace-stop
36234 @end smallexample
36235
36236 Stops a tracing experiment. The result of this command has the same
36237 fields as @code{-trace-status}, except that the @samp{supported} and
36238 @samp{running} fields are not output.
36239
36240 @subsubheading @value{GDBN} Command
36241
36242 The corresponding @value{GDBN} command is @samp{tstop}.
36243
36244
36245 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36246 @node GDB/MI Symbol Query
36247 @section @sc{gdb/mi} Symbol Query Commands
36248
36249
36250 @ignore
36251 @findex -symbol-info-address
36252 @subheading The @code{-symbol-info-address} Command
36253
36254 @subsubheading Synopsis
36255
36256 @smallexample
36257 -symbol-info-address @var{symbol}
36258 @end smallexample
36259
36260 Describe where @var{symbol} is stored.
36261
36262 @subsubheading @value{GDBN} Command
36263
36264 The corresponding @value{GDBN} command is @samp{info address}.
36265
36266 @subsubheading Example
36267 N.A.
36268
36269
36270 @findex -symbol-info-file
36271 @subheading The @code{-symbol-info-file} Command
36272
36273 @subsubheading Synopsis
36274
36275 @smallexample
36276 -symbol-info-file
36277 @end smallexample
36278
36279 Show the file for the symbol.
36280
36281 @subsubheading @value{GDBN} Command
36282
36283 There's no equivalent @value{GDBN} command. @code{gdbtk} has
36284 @samp{gdb_find_file}.
36285
36286 @subsubheading Example
36287 N.A.
36288 @end ignore
36289
36290 @findex -symbol-info-functions
36291 @anchor{-symbol-info-functions}
36292 @subheading The @code{-symbol-info-functions} Command
36293
36294 @subsubheading Synopsis
36295
36296 @smallexample
36297 -symbol-info-functions [--include-nondebug]
36298 [--type @var{type_regexp}]
36299 [--name @var{name_regexp}]
36300 [--max-results @var{limit}]
36301 @end smallexample
36302
36303 @noindent
36304 Return a list containing the names and types for all global functions
36305 taken from the debug information. The functions are grouped by source
36306 file, and shown with the line number on which each function is
36307 defined.
36308
36309 The @code{--include-nondebug} option causes the output to include
36310 code symbols from the symbol table.
36311
36312 The options @code{--type} and @code{--name} allow the symbols returned
36313 to be filtered based on either the name of the function, or the type
36314 signature of the function.
36315
36316 The option @code{--max-results} restricts the command to return no
36317 more than @var{limit} results. If exactly @var{limit} results are
36318 returned then there might be additional results available if a higher
36319 limit is used.
36320
36321 @subsubheading @value{GDBN} Command
36322
36323 The corresponding @value{GDBN} command is @samp{info functions}.
36324
36325 @subsubheading Example
36326 @smallexample
36327 @group
36328 (gdb)
36329 -symbol-info-functions
36330 ^done,symbols=
36331 @{debug=
36332 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36333 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36334 symbols=[@{line="36", name="f4", type="void (int *)",
36335 description="void f4(int *);"@},
36336 @{line="42", name="main", type="int ()",
36337 description="int main();"@},
36338 @{line="30", name="f1", type="my_int_t (int, int)",
36339 description="static my_int_t f1(int, int);"@}]@},
36340 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36341 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36342 symbols=[@{line="33", name="f2", type="float (another_float_t)",
36343 description="float f2(another_float_t);"@},
36344 @{line="39", name="f3", type="int (another_int_t)",
36345 description="int f3(another_int_t);"@},
36346 @{line="27", name="f1", type="another_float_t (int)",
36347 description="static another_float_t f1(int);"@}]@}]@}
36348 @end group
36349 @group
36350 (gdb)
36351 -symbol-info-functions --name f1
36352 ^done,symbols=
36353 @{debug=
36354 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36355 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36356 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
36357 description="static my_int_t f1(int, int);"@}]@},
36358 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36359 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36360 symbols=[@{line="27", name="f1", type="another_float_t (int)",
36361 description="static another_float_t f1(int);"@}]@}]@}
36362 @end group
36363 @group
36364 (gdb)
36365 -symbol-info-functions --type void
36366 ^done,symbols=
36367 @{debug=
36368 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36369 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36370 symbols=[@{line="36", name="f4", type="void (int *)",
36371 description="void f4(int *);"@}]@}]@}
36372 @end group
36373 @group
36374 (gdb)
36375 -symbol-info-functions --include-nondebug
36376 ^done,symbols=
36377 @{debug=
36378 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36379 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36380 symbols=[@{line="36", name="f4", type="void (int *)",
36381 description="void f4(int *);"@},
36382 @{line="42", name="main", type="int ()",
36383 description="int main();"@},
36384 @{line="30", name="f1", type="my_int_t (int, int)",
36385 description="static my_int_t f1(int, int);"@}]@},
36386 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36387 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36388 symbols=[@{line="33", name="f2", type="float (another_float_t)",
36389 description="float f2(another_float_t);"@},
36390 @{line="39", name="f3", type="int (another_int_t)",
36391 description="int f3(another_int_t);"@},
36392 @{line="27", name="f1", type="another_float_t (int)",
36393 description="static another_float_t f1(int);"@}]@}],
36394 nondebug=
36395 [@{address="0x0000000000400398",name="_init"@},
36396 @{address="0x00000000004003b0",name="_start"@},
36397 ...
36398 ]@}
36399 @end group
36400 @end smallexample
36401
36402 @findex -symbol-info-module-functions
36403 @anchor{-symbol-info-module-functions}
36404 @subheading The @code{-symbol-info-module-functions} Command
36405
36406 @subsubheading Synopsis
36407
36408 @smallexample
36409 -symbol-info-module-functions [--module @var{module_regexp}]
36410 [--name @var{name_regexp}]
36411 [--type @var{type_regexp}]
36412 @end smallexample
36413
36414 @noindent
36415 Return a list containing the names of all known functions within all
36416 know Fortran modules. The functions are grouped by source file and
36417 containing module, and shown with the line number on which each
36418 function is defined.
36419
36420 The option @code{--module} only returns results for modules matching
36421 @var{module_regexp}. The option @code{--name} only returns functions
36422 whose name matches @var{name_regexp}, and @code{--type} only returns
36423 functions whose type matches @var{type_regexp}.
36424
36425 @subsubheading @value{GDBN} Command
36426
36427 The corresponding @value{GDBN} command is @samp{info module functions}.
36428
36429 @subsubheading Example
36430
36431 @smallexample
36432 @group
36433 (gdb)
36434 -symbol-info-module-functions
36435 ^done,symbols=
36436 [@{module="mod1",
36437 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36438 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36439 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
36440 description="void mod1::check_all(void);"@}]@}]@},
36441 @{module="mod2",
36442 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36443 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36444 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
36445 description="void mod2::check_var_i(void);"@}]@}]@},
36446 @{module="mod3",
36447 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36448 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36449 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
36450 description="void mod3::check_all(void);"@},
36451 @{line="27",name="mod3::check_mod2",type="void (void)",
36452 description="void mod3::check_mod2(void);"@}]@}]@},
36453 @{module="modmany",
36454 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36455 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36456 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
36457 description="void modmany::check_some(void);"@}]@}]@},
36458 @{module="moduse",
36459 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36460 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36461 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
36462 description="void moduse::check_all(void);"@},
36463 @{line="49",name="moduse::check_var_x",type="void (void)",
36464 description="void moduse::check_var_x(void);"@}]@}]@}]
36465 @end group
36466 @end smallexample
36467
36468 @findex -symbol-info-module-variables
36469 @anchor{-symbol-info-module-variables}
36470 @subheading The @code{-symbol-info-module-variables} Command
36471
36472 @subsubheading Synopsis
36473
36474 @smallexample
36475 -symbol-info-module-variables [--module @var{module_regexp}]
36476 [--name @var{name_regexp}]
36477 [--type @var{type_regexp}]
36478 @end smallexample
36479
36480 @noindent
36481 Return a list containing the names of all known variables within all
36482 know Fortran modules. The variables are grouped by source file and
36483 containing module, and shown with the line number on which each
36484 variable is defined.
36485
36486 The option @code{--module} only returns results for modules matching
36487 @var{module_regexp}. The option @code{--name} only returns variables
36488 whose name matches @var{name_regexp}, and @code{--type} only returns
36489 variables whose type matches @var{type_regexp}.
36490
36491 @subsubheading @value{GDBN} Command
36492
36493 The corresponding @value{GDBN} command is @samp{info module variables}.
36494
36495 @subsubheading Example
36496
36497 @smallexample
36498 @group
36499 (gdb)
36500 -symbol-info-module-variables
36501 ^done,symbols=
36502 [@{module="mod1",
36503 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36504 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36505 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
36506 description="integer(kind=4) mod1::var_const;"@},
36507 @{line="17",name="mod1::var_i",type="integer(kind=4)",
36508 description="integer(kind=4) mod1::var_i;"@}]@}]@},
36509 @{module="mod2",
36510 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36511 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36512 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
36513 description="integer(kind=4) mod2::var_i;"@}]@}]@},
36514 @{module="mod3",
36515 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36516 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36517 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
36518 description="integer(kind=4) mod3::mod1;"@},
36519 @{line="17",name="mod3::mod2",type="integer(kind=4)",
36520 description="integer(kind=4) mod3::mod2;"@},
36521 @{line="19",name="mod3::var_i",type="integer(kind=4)",
36522 description="integer(kind=4) mod3::var_i;"@}]@}]@},
36523 @{module="modmany",
36524 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36525 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36526 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
36527 description="integer(kind=4) modmany::var_a;"@},
36528 @{line="33",name="modmany::var_b",type="integer(kind=4)",
36529 description="integer(kind=4) modmany::var_b;"@},
36530 @{line="33",name="modmany::var_c",type="integer(kind=4)",
36531 description="integer(kind=4) modmany::var_c;"@},
36532 @{line="33",name="modmany::var_i",type="integer(kind=4)",
36533 description="integer(kind=4) modmany::var_i;"@}]@}]@},
36534 @{module="moduse",
36535 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36536 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36537 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
36538 description="integer(kind=4) moduse::var_x;"@},
36539 @{line="42",name="moduse::var_y",type="integer(kind=4)",
36540 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
36541 @end group
36542 @end smallexample
36543
36544 @findex -symbol-info-modules
36545 @anchor{-symbol-info-modules}
36546 @subheading The @code{-symbol-info-modules} Command
36547
36548 @subsubheading Synopsis
36549
36550 @smallexample
36551 -symbol-info-modules [--name @var{name_regexp}]
36552 [--max-results @var{limit}]
36553
36554 @end smallexample
36555
36556 @noindent
36557 Return a list containing the names of all known Fortran modules. The
36558 modules are grouped by source file, and shown with the line number on
36559 which each modules is defined.
36560
36561 The option @code{--name} allows the modules returned to be filtered
36562 based the name of the module.
36563
36564 The option @code{--max-results} restricts the command to return no
36565 more than @var{limit} results. If exactly @var{limit} results are
36566 returned then there might be additional results available if a higher
36567 limit is used.
36568
36569 @subsubheading @value{GDBN} Command
36570
36571 The corresponding @value{GDBN} command is @samp{info modules}.
36572
36573 @subsubheading Example
36574 @smallexample
36575 @group
36576 (gdb)
36577 -symbol-info-modules
36578 ^done,symbols=
36579 @{debug=
36580 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36581 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36582 symbols=[@{line="16",name="mod1"@},
36583 @{line="22",name="mod2"@}]@},
36584 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36585 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36586 symbols=[@{line="16",name="mod3"@},
36587 @{line="22",name="modmany"@},
36588 @{line="26",name="moduse"@}]@}]@}
36589 @end group
36590 @group
36591 (gdb)
36592 -symbol-info-modules --name mod[123]
36593 ^done,symbols=
36594 @{debug=
36595 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36596 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
36597 symbols=[@{line="16",name="mod1"@},
36598 @{line="22",name="mod2"@}]@},
36599 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36600 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
36601 symbols=[@{line="16",name="mod3"@}]@}]@}
36602 @end group
36603 @end smallexample
36604
36605 @findex -symbol-info-types
36606 @anchor{-symbol-info-types}
36607 @subheading The @code{-symbol-info-types} Command
36608
36609 @subsubheading Synopsis
36610
36611 @smallexample
36612 -symbol-info-types [--name @var{name_regexp}]
36613 [--max-results @var{limit}]
36614
36615 @end smallexample
36616
36617 @noindent
36618 Return a list of all defined types. The types are grouped by source
36619 file, and shown with the line number on which each user defined type
36620 is defined. Some base types are not defined in the source code but
36621 are added to the debug information by the compiler, for example
36622 @code{int}, @code{float}, etc.; these types do not have an associated
36623 line number.
36624
36625 The option @code{--name} allows the list of types returned to be
36626 filtered by name.
36627
36628 The option @code{--max-results} restricts the command to return no
36629 more than @var{limit} results. If exactly @var{limit} results are
36630 returned then there might be additional results available if a higher
36631 limit is used.
36632
36633 @subsubheading @value{GDBN} Command
36634
36635 The corresponding @value{GDBN} command is @samp{info types}.
36636
36637 @subsubheading Example
36638 @smallexample
36639 @group
36640 (gdb)
36641 -symbol-info-types
36642 ^done,symbols=
36643 @{debug=
36644 [@{filename="gdb.mi/mi-sym-info-1.c",
36645 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36646 symbols=[@{name="float"@},
36647 @{name="int"@},
36648 @{line="27",name="typedef int my_int_t;"@}]@},
36649 @{filename="gdb.mi/mi-sym-info-2.c",
36650 fullname="/project/gdb.mi/mi-sym-info-2.c",
36651 symbols=[@{line="24",name="typedef float another_float_t;"@},
36652 @{line="23",name="typedef int another_int_t;"@},
36653 @{name="float"@},
36654 @{name="int"@}]@}]@}
36655 @end group
36656 @group
36657 (gdb)
36658 -symbol-info-types --name _int_
36659 ^done,symbols=
36660 @{debug=
36661 [@{filename="gdb.mi/mi-sym-info-1.c",
36662 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36663 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
36664 @{filename="gdb.mi/mi-sym-info-2.c",
36665 fullname="/project/gdb.mi/mi-sym-info-2.c",
36666 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
36667 @end group
36668 @end smallexample
36669
36670 @findex -symbol-info-variables
36671 @anchor{-symbol-info-variables}
36672 @subheading The @code{-symbol-info-variables} Command
36673
36674 @subsubheading Synopsis
36675
36676 @smallexample
36677 -symbol-info-variables [--include-nondebug]
36678 [--type @var{type_regexp}]
36679 [--name @var{name_regexp}]
36680 [--max-results @var{limit}]
36681
36682 @end smallexample
36683
36684 @noindent
36685 Return a list containing the names and types for all global variables
36686 taken from the debug information. The variables are grouped by source
36687 file, and shown with the line number on which each variable is
36688 defined.
36689
36690 The @code{--include-nondebug} option causes the output to include
36691 data symbols from the symbol table.
36692
36693 The options @code{--type} and @code{--name} allow the symbols returned
36694 to be filtered based on either the name of the variable, or the type
36695 of the variable.
36696
36697 The option @code{--max-results} restricts the command to return no
36698 more than @var{limit} results. If exactly @var{limit} results are
36699 returned then there might be additional results available if a higher
36700 limit is used.
36701
36702 @subsubheading @value{GDBN} Command
36703
36704 The corresponding @value{GDBN} command is @samp{info variables}.
36705
36706 @subsubheading Example
36707 @smallexample
36708 @group
36709 (gdb)
36710 -symbol-info-variables
36711 ^done,symbols=
36712 @{debug=
36713 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36714 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36715 symbols=[@{line="25",name="global_f1",type="float",
36716 description="static float global_f1;"@},
36717 @{line="24",name="global_i1",type="int",
36718 description="static int global_i1;"@}]@},
36719 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36720 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36721 symbols=[@{line="21",name="global_f2",type="int",
36722 description="int global_f2;"@},
36723 @{line="20",name="global_i2",type="int",
36724 description="int global_i2;"@},
36725 @{line="19",name="global_f1",type="float",
36726 description="static float global_f1;"@},
36727 @{line="18",name="global_i1",type="int",
36728 description="static int global_i1;"@}]@}]@}
36729 @end group
36730 @group
36731 (gdb)
36732 -symbol-info-variables --name f1
36733 ^done,symbols=
36734 @{debug=
36735 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36736 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36737 symbols=[@{line="25",name="global_f1",type="float",
36738 description="static float global_f1;"@}]@},
36739 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36740 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36741 symbols=[@{line="19",name="global_f1",type="float",
36742 description="static float global_f1;"@}]@}]@}
36743 @end group
36744 @group
36745 (gdb)
36746 -symbol-info-variables --type float
36747 ^done,symbols=
36748 @{debug=
36749 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36750 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36751 symbols=[@{line="25",name="global_f1",type="float",
36752 description="static float global_f1;"@}]@},
36753 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36754 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36755 symbols=[@{line="19",name="global_f1",type="float",
36756 description="static float global_f1;"@}]@}]@}
36757 @end group
36758 @group
36759 (gdb)
36760 -symbol-info-variables --include-nondebug
36761 ^done,symbols=
36762 @{debug=
36763 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36764 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
36765 symbols=[@{line="25",name="global_f1",type="float",
36766 description="static float global_f1;"@},
36767 @{line="24",name="global_i1",type="int",
36768 description="static int global_i1;"@}]@},
36769 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36770 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
36771 symbols=[@{line="21",name="global_f2",type="int",
36772 description="int global_f2;"@},
36773 @{line="20",name="global_i2",type="int",
36774 description="int global_i2;"@},
36775 @{line="19",name="global_f1",type="float",
36776 description="static float global_f1;"@},
36777 @{line="18",name="global_i1",type="int",
36778 description="static int global_i1;"@}]@}],
36779 nondebug=
36780 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
36781 @{address="0x00000000004005d8",name="__dso_handle"@}
36782 ...
36783 ]@}
36784 @end group
36785 @end smallexample
36786
36787 @ignore
36788 @findex -symbol-info-line
36789 @subheading The @code{-symbol-info-line} Command
36790
36791 @subsubheading Synopsis
36792
36793 @smallexample
36794 -symbol-info-line
36795 @end smallexample
36796
36797 Show the core addresses of the code for a source line.
36798
36799 @subsubheading @value{GDBN} Command
36800
36801 The corresponding @value{GDBN} command is @samp{info line}.
36802 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
36803
36804 @subsubheading Example
36805 N.A.
36806
36807
36808 @findex -symbol-info-symbol
36809 @subheading The @code{-symbol-info-symbol} Command
36810
36811 @subsubheading Synopsis
36812
36813 @smallexample
36814 -symbol-info-symbol @var{addr}
36815 @end smallexample
36816
36817 Describe what symbol is at location @var{addr}.
36818
36819 @subsubheading @value{GDBN} Command
36820
36821 The corresponding @value{GDBN} command is @samp{info symbol}.
36822
36823 @subsubheading Example
36824 N.A.
36825
36826
36827 @findex -symbol-list-functions
36828 @subheading The @code{-symbol-list-functions} Command
36829
36830 @subsubheading Synopsis
36831
36832 @smallexample
36833 -symbol-list-functions
36834 @end smallexample
36835
36836 List the functions in the executable.
36837
36838 @subsubheading @value{GDBN} Command
36839
36840 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
36841 @samp{gdb_search} in @code{gdbtk}.
36842
36843 @subsubheading Example
36844 N.A.
36845 @end ignore
36846
36847
36848 @findex -symbol-list-lines
36849 @subheading The @code{-symbol-list-lines} Command
36850
36851 @subsubheading Synopsis
36852
36853 @smallexample
36854 -symbol-list-lines @var{filename}
36855 @end smallexample
36856
36857 Print the list of lines that contain code and their associated program
36858 addresses for the given source filename. The entries are sorted in
36859 ascending PC order.
36860
36861 @subsubheading @value{GDBN} Command
36862
36863 There is no corresponding @value{GDBN} command.
36864
36865 @subsubheading Example
36866 @smallexample
36867 (gdb)
36868 -symbol-list-lines basics.c
36869 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
36870 (gdb)
36871 @end smallexample
36872
36873
36874 @ignore
36875 @findex -symbol-list-types
36876 @subheading The @code{-symbol-list-types} Command
36877
36878 @subsubheading Synopsis
36879
36880 @smallexample
36881 -symbol-list-types
36882 @end smallexample
36883
36884 List all the type names.
36885
36886 @subsubheading @value{GDBN} Command
36887
36888 The corresponding commands are @samp{info types} in @value{GDBN},
36889 @samp{gdb_search} in @code{gdbtk}.
36890
36891 @subsubheading Example
36892 N.A.
36893
36894
36895 @findex -symbol-list-variables
36896 @subheading The @code{-symbol-list-variables} Command
36897
36898 @subsubheading Synopsis
36899
36900 @smallexample
36901 -symbol-list-variables
36902 @end smallexample
36903
36904 List all the global and static variable names.
36905
36906 @subsubheading @value{GDBN} Command
36907
36908 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
36909
36910 @subsubheading Example
36911 N.A.
36912
36913
36914 @findex -symbol-locate
36915 @subheading The @code{-symbol-locate} Command
36916
36917 @subsubheading Synopsis
36918
36919 @smallexample
36920 -symbol-locate
36921 @end smallexample
36922
36923 @subsubheading @value{GDBN} Command
36924
36925 @samp{gdb_loc} in @code{gdbtk}.
36926
36927 @subsubheading Example
36928 N.A.
36929
36930
36931 @findex -symbol-type
36932 @subheading The @code{-symbol-type} Command
36933
36934 @subsubheading Synopsis
36935
36936 @smallexample
36937 -symbol-type @var{variable}
36938 @end smallexample
36939
36940 Show type of @var{variable}.
36941
36942 @subsubheading @value{GDBN} Command
36943
36944 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
36945 @samp{gdb_obj_variable}.
36946
36947 @subsubheading Example
36948 N.A.
36949 @end ignore
36950
36951
36952 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36953 @node GDB/MI File Commands
36954 @section @sc{gdb/mi} File Commands
36955
36956 This section describes the GDB/MI commands to specify executable file names
36957 and to read in and obtain symbol table information.
36958
36959 @findex -file-exec-and-symbols
36960 @subheading The @code{-file-exec-and-symbols} Command
36961
36962 @subsubheading Synopsis
36963
36964 @smallexample
36965 -file-exec-and-symbols @var{file}
36966 @end smallexample
36967
36968 Specify the executable file to be debugged. This file is the one from
36969 which the symbol table is also read. If no file is specified, the
36970 command clears the executable and symbol information. If breakpoints
36971 are set when using this command with no arguments, @value{GDBN} will produce
36972 error messages. Otherwise, no output is produced, except a completion
36973 notification.
36974
36975 @subsubheading @value{GDBN} Command
36976
36977 The corresponding @value{GDBN} command is @samp{file}.
36978
36979 @subsubheading Example
36980
36981 @smallexample
36982 (gdb)
36983 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
36984 ^done
36985 (gdb)
36986 @end smallexample
36987
36988
36989 @findex -file-exec-file
36990 @subheading The @code{-file-exec-file} Command
36991
36992 @subsubheading Synopsis
36993
36994 @smallexample
36995 -file-exec-file @var{file}
36996 @end smallexample
36997
36998 Specify the executable file to be debugged. Unlike
36999 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
37000 from this file. If used without argument, @value{GDBN} clears the information
37001 about the executable file. No output is produced, except a completion
37002 notification.
37003
37004 @subsubheading @value{GDBN} Command
37005
37006 The corresponding @value{GDBN} command is @samp{exec-file}.
37007
37008 @subsubheading Example
37009
37010 @smallexample
37011 (gdb)
37012 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
37013 ^done
37014 (gdb)
37015 @end smallexample
37016
37017
37018 @ignore
37019 @findex -file-list-exec-sections
37020 @subheading The @code{-file-list-exec-sections} Command
37021
37022 @subsubheading Synopsis
37023
37024 @smallexample
37025 -file-list-exec-sections
37026 @end smallexample
37027
37028 List the sections of the current executable file.
37029
37030 @subsubheading @value{GDBN} Command
37031
37032 The @value{GDBN} command @samp{info file} shows, among the rest, the same
37033 information as this command. @code{gdbtk} has a corresponding command
37034 @samp{gdb_load_info}.
37035
37036 @subsubheading Example
37037 N.A.
37038 @end ignore
37039
37040
37041 @findex -file-list-exec-source-file
37042 @subheading The @code{-file-list-exec-source-file} Command
37043
37044 @subsubheading Synopsis
37045
37046 @smallexample
37047 -file-list-exec-source-file
37048 @end smallexample
37049
37050 List the line number, the current source file, and the absolute path
37051 to the current source file for the current executable. The macro
37052 information field has a value of @samp{1} or @samp{0} depending on
37053 whether or not the file includes preprocessor macro information.
37054
37055 @subsubheading @value{GDBN} Command
37056
37057 The @value{GDBN} equivalent is @samp{info source}
37058
37059 @subsubheading Example
37060
37061 @smallexample
37062 (gdb)
37063 123-file-list-exec-source-file
37064 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
37065 (gdb)
37066 @end smallexample
37067
37068
37069 @findex -file-list-exec-source-files
37070 @subheading The @code{-file-list-exec-source-files} Command
37071 @kindex info sources
37072
37073 @subsubheading Synopsis
37074
37075 @smallexample
37076 -file-list-exec-source-files @r{[} @var{--group-by-objfile} @r{]}
37077 @r{[} @var{--dirname} @r{|} @var{--basename} @r{]}
37078 @r{[} -- @r{]}
37079 @r{[} @var{regexp} @r{]}
37080 @end smallexample
37081
37082 This command returns information about the source files @value{GDBN}
37083 knows about, it will output both the filename and fullname (absolute
37084 file name) of a source file, though the fullname can be elided if this
37085 information is not known to @value{GDBN}.
37086
37087 With no arguments this command returns a list of source files. Each
37088 source file is represented by a tuple with the fields; @var{file},
37089 @var{fullname}, and @var{debug-fully-read}. The @var{file} is the
37090 display name for the file, while @var{fullname} is the absolute name
37091 of the file. The @var{fullname} field can be elided if the absolute
37092 name of the source file can't be computed. The field
37093 @var{debug-fully-read} will be a string, either @code{true} or
37094 @code{false}. When @code{true}, this indicates the full debug
37095 information for the compilation unit describing this file has been
37096 read in. When @code{false}, the full debug information has not yet
37097 been read in. While reading in the full debug information it is
37098 possible that @value{GDBN} could become aware of additional source
37099 files.
37100
37101 The optional @var{regexp} can be used to filter the list of source
37102 files returned. The @var{regexp} will be matched against the full
37103 source file name. The matching is case-sensitive, except on operating
37104 systems that have case-insensitive filesystem (e.g.,
37105 MS-Windows). @samp{--} can be used before @var{regexp} to prevent
37106 @value{GDBN} interpreting @var{regexp} as a command option (e.g.@: if
37107 @var{regexp} starts with @samp{-}).
37108
37109 If @code{--dirname} is provided, then @var{regexp} is matched only
37110 against the directory name of each source file. If @code{--basename}
37111 is provided, then @var{regexp} is matched against the basename of each
37112 source file. Only one of @code{--dirname} or @code{--basename} may be
37113 given, and if either is given then @var{regexp} is required.
37114
37115 If @code{--group-by-objfile} is used then the format of the results is
37116 changed. The results will now be a list of tuples, with each tuple
37117 representing an object file (executable or shared library) loaded into
37118 @value{GDBN}. The fields of these tuples are; @var{filename},
37119 @var{debug-info}, and @var{sources}. The @var{filename} is the
37120 absolute name of the object file, @var{debug-info} is a string with
37121 one of the following values:
37122
37123 @table @code
37124 @item none
37125 This object file has no debug information.
37126 @item partially-read
37127 This object file has debug information, but it is not fully read in
37128 yet. When it is read in later, GDB might become aware of additional
37129 source files.
37130 @item fully-read
37131 This object file has debug information, and this information is fully
37132 read into GDB. The list of source files is complete.
37133 @end table
37134
37135 The @var{sources} is a list or tuples, with each tuple describing a
37136 single source file with the same fields as described previously. The
37137 @var{sources} list can be empty for object files that have no debug
37138 information.
37139
37140 @subsubheading @value{GDBN} Command
37141
37142 The @value{GDBN} equivalent is @samp{info sources}.
37143 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
37144
37145 @subsubheading Example
37146 @smallexample
37147 (@value{GDBP})
37148 -file-list-exec-source-files
37149 ^done,files=[@{file="foo.c",fullname="/home/foo.c",debug-fully-read="true"@},
37150 @{file="/home/bar.c",fullname="/home/bar.c",debug-fully-read="true"@},
37151 @{file="gdb_could_not_find_fullpath.c",debug-fully-read="true"@}]
37152 (@value{GDBP})
37153 -file-list-exec-source-files
37154 ^done,files=[@{file="test.c",
37155 fullname="/tmp/info-sources/test.c",
37156 debug-fully-read="true"@},
37157 @{file="/usr/include/stdc-predef.h",
37158 fullname="/usr/include/stdc-predef.h",
37159 debug-fully-read="true"@},
37160 @{file="header.h",
37161 fullname="/tmp/info-sources/header.h",
37162 debug-fully-read="true"@},
37163 @{file="helper.c",
37164 fullname="/tmp/info-sources/helper.c",
37165 debug-fully-read="true"@}]
37166 (@value{GDBP})
37167 -file-list-exec-source-files -- \\.c
37168 ^done,files=[@{file="test.c",
37169 fullname="/tmp/info-sources/test.c",
37170 debug-fully-read="true"@},
37171 @{file="helper.c",
37172 fullname="/tmp/info-sources/helper.c",
37173 debug-fully-read="true"@}]
37174 (@value{GDBP})
37175 -file-list-exec-source-files --group-by-objfile
37176 ^done,files=[@{filename="/tmp/info-sources/test.x",
37177 debug-info="fully-read",
37178 sources=[@{file="test.c",
37179 fullname="/tmp/info-sources/test.c",
37180 debug-fully-read="true"@},
37181 @{file="/usr/include/stdc-predef.h",
37182 fullname="/usr/include/stdc-predef.h",
37183 debug-fully-read="true"@},
37184 @{file="header.h",
37185 fullname="/tmp/info-sources/header.h",
37186 debug-fully-read="true"@}]@},
37187 @{filename="/lib64/ld-linux-x86-64.so.2",
37188 debug-info="none",
37189 sources=[]@},
37190 @{filename="system-supplied DSO at 0x7ffff7fcf000",
37191 debug-info="none",
37192 sources=[]@},
37193 @{filename="/tmp/info-sources/libhelper.so",
37194 debug-info="fully-read",
37195 sources=[@{file="helper.c",
37196 fullname="/tmp/info-sources/helper.c",
37197 debug-fully-read="true"@},
37198 @{file="/usr/include/stdc-predef.h",
37199 fullname="/usr/include/stdc-predef.h",
37200 debug-fully-read="true"@},
37201 @{file="header.h",
37202 fullname="/tmp/info-sources/header.h",
37203 debug-fully-read="true"@}]@},
37204 @{filename="/lib64/libc.so.6",
37205 debug-info="none",
37206 sources=[]@}]
37207 @end smallexample
37208
37209 @findex -file-list-shared-libraries
37210 @subheading The @code{-file-list-shared-libraries} Command
37211
37212 @subsubheading Synopsis
37213
37214 @smallexample
37215 -file-list-shared-libraries [ @var{regexp} ]
37216 @end smallexample
37217
37218 List the shared libraries in the program.
37219 With a regular expression @var{regexp}, only those libraries whose
37220 names match @var{regexp} are listed.
37221
37222 @subsubheading @value{GDBN} Command
37223
37224 The corresponding @value{GDBN} command is @samp{info shared}. The fields
37225 have a similar meaning to the @code{=library-loaded} notification.
37226 The @code{ranges} field specifies the multiple segments belonging to this
37227 library. Each range has the following fields:
37228
37229 @table @samp
37230 @item from
37231 The address defining the inclusive lower bound of the segment.
37232 @item to
37233 The address defining the exclusive upper bound of the segment.
37234 @end table
37235
37236 @subsubheading Example
37237 @smallexample
37238 (gdb)
37239 -file-list-exec-source-files
37240 ^done,shared-libraries=[
37241 @{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"@}]@},
37242 @{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"@}]@}]
37243 (gdb)
37244 @end smallexample
37245
37246
37247 @ignore
37248 @findex -file-list-symbol-files
37249 @subheading The @code{-file-list-symbol-files} Command
37250
37251 @subsubheading Synopsis
37252
37253 @smallexample
37254 -file-list-symbol-files
37255 @end smallexample
37256
37257 List symbol files.
37258
37259 @subsubheading @value{GDBN} Command
37260
37261 The corresponding @value{GDBN} command is @samp{info file} (part of it).
37262
37263 @subsubheading Example
37264 N.A.
37265 @end ignore
37266
37267
37268 @findex -file-symbol-file
37269 @subheading The @code{-file-symbol-file} Command
37270
37271 @subsubheading Synopsis
37272
37273 @smallexample
37274 -file-symbol-file @var{file}
37275 @end smallexample
37276
37277 Read symbol table info from the specified @var{file} argument. When
37278 used without arguments, clears @value{GDBN}'s symbol table info. No output is
37279 produced, except for a completion notification.
37280
37281 @subsubheading @value{GDBN} Command
37282
37283 The corresponding @value{GDBN} command is @samp{symbol-file}.
37284
37285 @subsubheading Example
37286
37287 @smallexample
37288 (gdb)
37289 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
37290 ^done
37291 (gdb)
37292 @end smallexample
37293
37294 @ignore
37295 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37296 @node GDB/MI Memory Overlay Commands
37297 @section @sc{gdb/mi} Memory Overlay Commands
37298
37299 The memory overlay commands are not implemented.
37300
37301 @c @subheading -overlay-auto
37302
37303 @c @subheading -overlay-list-mapping-state
37304
37305 @c @subheading -overlay-list-overlays
37306
37307 @c @subheading -overlay-map
37308
37309 @c @subheading -overlay-off
37310
37311 @c @subheading -overlay-on
37312
37313 @c @subheading -overlay-unmap
37314
37315 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37316 @node GDB/MI Signal Handling Commands
37317 @section @sc{gdb/mi} Signal Handling Commands
37318
37319 Signal handling commands are not implemented.
37320
37321 @c @subheading -signal-handle
37322
37323 @c @subheading -signal-list-handle-actions
37324
37325 @c @subheading -signal-list-signal-types
37326 @end ignore
37327
37328
37329 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37330 @node GDB/MI Target Manipulation
37331 @section @sc{gdb/mi} Target Manipulation Commands
37332
37333
37334 @findex -target-attach
37335 @subheading The @code{-target-attach} Command
37336
37337 @subsubheading Synopsis
37338
37339 @smallexample
37340 -target-attach @var{pid} | @var{gid} | @var{file}
37341 @end smallexample
37342
37343 Attach to a process @var{pid} or a file @var{file} outside of
37344 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
37345 group, the id previously returned by
37346 @samp{-list-thread-groups --available} must be used.
37347
37348 @subsubheading @value{GDBN} Command
37349
37350 The corresponding @value{GDBN} command is @samp{attach}.
37351
37352 @subsubheading Example
37353 @smallexample
37354 (gdb)
37355 -target-attach 34
37356 =thread-created,id="1"
37357 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
37358 ^done
37359 (gdb)
37360 @end smallexample
37361
37362 @ignore
37363 @findex -target-compare-sections
37364 @subheading The @code{-target-compare-sections} Command
37365
37366 @subsubheading Synopsis
37367
37368 @smallexample
37369 -target-compare-sections [ @var{section} ]
37370 @end smallexample
37371
37372 Compare data of section @var{section} on target to the exec file.
37373 Without the argument, all sections are compared.
37374
37375 @subsubheading @value{GDBN} Command
37376
37377 The @value{GDBN} equivalent is @samp{compare-sections}.
37378
37379 @subsubheading Example
37380 N.A.
37381 @end ignore
37382
37383
37384 @findex -target-detach
37385 @subheading The @code{-target-detach} Command
37386
37387 @subsubheading Synopsis
37388
37389 @smallexample
37390 -target-detach [ @var{pid} | @var{gid} ]
37391 @end smallexample
37392
37393 Detach from the remote target which normally resumes its execution.
37394 If either @var{pid} or @var{gid} is specified, detaches from either
37395 the specified process, or specified thread group. There's no output.
37396
37397 @subsubheading @value{GDBN} Command
37398
37399 The corresponding @value{GDBN} command is @samp{detach}.
37400
37401 @subsubheading Example
37402
37403 @smallexample
37404 (gdb)
37405 -target-detach
37406 ^done
37407 (gdb)
37408 @end smallexample
37409
37410
37411 @findex -target-disconnect
37412 @subheading The @code{-target-disconnect} Command
37413
37414 @subsubheading Synopsis
37415
37416 @smallexample
37417 -target-disconnect
37418 @end smallexample
37419
37420 Disconnect from the remote target. There's no output and the target is
37421 generally not resumed.
37422
37423 @subsubheading @value{GDBN} Command
37424
37425 The corresponding @value{GDBN} command is @samp{disconnect}.
37426
37427 @subsubheading Example
37428
37429 @smallexample
37430 (gdb)
37431 -target-disconnect
37432 ^done
37433 (gdb)
37434 @end smallexample
37435
37436
37437 @findex -target-download
37438 @subheading The @code{-target-download} Command
37439
37440 @subsubheading Synopsis
37441
37442 @smallexample
37443 -target-download
37444 @end smallexample
37445
37446 Loads the executable onto the remote target.
37447 It prints out an update message every half second, which includes the fields:
37448
37449 @table @samp
37450 @item section
37451 The name of the section.
37452 @item section-sent
37453 The size of what has been sent so far for that section.
37454 @item section-size
37455 The size of the section.
37456 @item total-sent
37457 The total size of what was sent so far (the current and the previous sections).
37458 @item total-size
37459 The size of the overall executable to download.
37460 @end table
37461
37462 @noindent
37463 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
37464 @sc{gdb/mi} Output Syntax}).
37465
37466 In addition, it prints the name and size of the sections, as they are
37467 downloaded. These messages include the following fields:
37468
37469 @table @samp
37470 @item section
37471 The name of the section.
37472 @item section-size
37473 The size of the section.
37474 @item total-size
37475 The size of the overall executable to download.
37476 @end table
37477
37478 @noindent
37479 At the end, a summary is printed.
37480
37481 @subsubheading @value{GDBN} Command
37482
37483 The corresponding @value{GDBN} command is @samp{load}.
37484
37485 @subsubheading Example
37486
37487 Note: each status message appears on a single line. Here the messages
37488 have been broken down so that they can fit onto a page.
37489
37490 @smallexample
37491 (gdb)
37492 -target-download
37493 +download,@{section=".text",section-size="6668",total-size="9880"@}
37494 +download,@{section=".text",section-sent="512",section-size="6668",
37495 total-sent="512",total-size="9880"@}
37496 +download,@{section=".text",section-sent="1024",section-size="6668",
37497 total-sent="1024",total-size="9880"@}
37498 +download,@{section=".text",section-sent="1536",section-size="6668",
37499 total-sent="1536",total-size="9880"@}
37500 +download,@{section=".text",section-sent="2048",section-size="6668",
37501 total-sent="2048",total-size="9880"@}
37502 +download,@{section=".text",section-sent="2560",section-size="6668",
37503 total-sent="2560",total-size="9880"@}
37504 +download,@{section=".text",section-sent="3072",section-size="6668",
37505 total-sent="3072",total-size="9880"@}
37506 +download,@{section=".text",section-sent="3584",section-size="6668",
37507 total-sent="3584",total-size="9880"@}
37508 +download,@{section=".text",section-sent="4096",section-size="6668",
37509 total-sent="4096",total-size="9880"@}
37510 +download,@{section=".text",section-sent="4608",section-size="6668",
37511 total-sent="4608",total-size="9880"@}
37512 +download,@{section=".text",section-sent="5120",section-size="6668",
37513 total-sent="5120",total-size="9880"@}
37514 +download,@{section=".text",section-sent="5632",section-size="6668",
37515 total-sent="5632",total-size="9880"@}
37516 +download,@{section=".text",section-sent="6144",section-size="6668",
37517 total-sent="6144",total-size="9880"@}
37518 +download,@{section=".text",section-sent="6656",section-size="6668",
37519 total-sent="6656",total-size="9880"@}
37520 +download,@{section=".init",section-size="28",total-size="9880"@}
37521 +download,@{section=".fini",section-size="28",total-size="9880"@}
37522 +download,@{section=".data",section-size="3156",total-size="9880"@}
37523 +download,@{section=".data",section-sent="512",section-size="3156",
37524 total-sent="7236",total-size="9880"@}
37525 +download,@{section=".data",section-sent="1024",section-size="3156",
37526 total-sent="7748",total-size="9880"@}
37527 +download,@{section=".data",section-sent="1536",section-size="3156",
37528 total-sent="8260",total-size="9880"@}
37529 +download,@{section=".data",section-sent="2048",section-size="3156",
37530 total-sent="8772",total-size="9880"@}
37531 +download,@{section=".data",section-sent="2560",section-size="3156",
37532 total-sent="9284",total-size="9880"@}
37533 +download,@{section=".data",section-sent="3072",section-size="3156",
37534 total-sent="9796",total-size="9880"@}
37535 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
37536 write-rate="429"
37537 (gdb)
37538 @end smallexample
37539
37540
37541 @ignore
37542 @findex -target-exec-status
37543 @subheading The @code{-target-exec-status} Command
37544
37545 @subsubheading Synopsis
37546
37547 @smallexample
37548 -target-exec-status
37549 @end smallexample
37550
37551 Provide information on the state of the target (whether it is running or
37552 not, for instance).
37553
37554 @subsubheading @value{GDBN} Command
37555
37556 There's no equivalent @value{GDBN} command.
37557
37558 @subsubheading Example
37559 N.A.
37560
37561
37562 @findex -target-list-available-targets
37563 @subheading The @code{-target-list-available-targets} Command
37564
37565 @subsubheading Synopsis
37566
37567 @smallexample
37568 -target-list-available-targets
37569 @end smallexample
37570
37571 List the possible targets to connect to.
37572
37573 @subsubheading @value{GDBN} Command
37574
37575 The corresponding @value{GDBN} command is @samp{help target}.
37576
37577 @subsubheading Example
37578 N.A.
37579
37580
37581 @findex -target-list-current-targets
37582 @subheading The @code{-target-list-current-targets} Command
37583
37584 @subsubheading Synopsis
37585
37586 @smallexample
37587 -target-list-current-targets
37588 @end smallexample
37589
37590 Describe the current target.
37591
37592 @subsubheading @value{GDBN} Command
37593
37594 The corresponding information is printed by @samp{info file} (among
37595 other things).
37596
37597 @subsubheading Example
37598 N.A.
37599
37600
37601 @findex -target-list-parameters
37602 @subheading The @code{-target-list-parameters} Command
37603
37604 @subsubheading Synopsis
37605
37606 @smallexample
37607 -target-list-parameters
37608 @end smallexample
37609
37610 @c ????
37611 @end ignore
37612
37613 @subsubheading @value{GDBN} Command
37614
37615 No equivalent.
37616
37617 @subsubheading Example
37618 N.A.
37619
37620 @findex -target-flash-erase
37621 @subheading The @code{-target-flash-erase} Command
37622
37623 @subsubheading Synopsis
37624
37625 @smallexample
37626 -target-flash-erase
37627 @end smallexample
37628
37629 Erases all known flash memory regions on the target.
37630
37631 The corresponding @value{GDBN} command is @samp{flash-erase}.
37632
37633 The output is a list of flash regions that have been erased, with starting
37634 addresses and memory region sizes.
37635
37636 @smallexample
37637 (gdb)
37638 -target-flash-erase
37639 ^done,erased-regions=@{address="0x0",size="0x40000"@}
37640 (gdb)
37641 @end smallexample
37642
37643 @findex -target-select
37644 @subheading The @code{-target-select} Command
37645
37646 @subsubheading Synopsis
37647
37648 @smallexample
37649 -target-select @var{type} @var{parameters @dots{}}
37650 @end smallexample
37651
37652 Connect @value{GDBN} to the remote target. This command takes two args:
37653
37654 @table @samp
37655 @item @var{type}
37656 The type of target, for instance @samp{remote}, etc.
37657 @item @var{parameters}
37658 Device names, host names and the like. @xref{Target Commands, ,
37659 Commands for Managing Targets}, for more details.
37660 @end table
37661
37662 The output is a connection notification, followed by the address at
37663 which the target program is, in the following form:
37664
37665 @smallexample
37666 ^connected,addr="@var{address}",func="@var{function name}",
37667 args=[@var{arg list}]
37668 @end smallexample
37669
37670 @subsubheading @value{GDBN} Command
37671
37672 The corresponding @value{GDBN} command is @samp{target}.
37673
37674 @subsubheading Example
37675
37676 @smallexample
37677 (gdb)
37678 -target-select remote /dev/ttya
37679 ^connected,addr="0xfe00a300",func="??",args=[]
37680 (gdb)
37681 @end smallexample
37682
37683 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37684 @node GDB/MI File Transfer Commands
37685 @section @sc{gdb/mi} File Transfer Commands
37686
37687
37688 @findex -target-file-put
37689 @subheading The @code{-target-file-put} Command
37690
37691 @subsubheading Synopsis
37692
37693 @smallexample
37694 -target-file-put @var{hostfile} @var{targetfile}
37695 @end smallexample
37696
37697 Copy file @var{hostfile} from the host system (the machine running
37698 @value{GDBN}) to @var{targetfile} on the target system.
37699
37700 @subsubheading @value{GDBN} Command
37701
37702 The corresponding @value{GDBN} command is @samp{remote put}.
37703
37704 @subsubheading Example
37705
37706 @smallexample
37707 (gdb)
37708 -target-file-put localfile remotefile
37709 ^done
37710 (gdb)
37711 @end smallexample
37712
37713
37714 @findex -target-file-get
37715 @subheading The @code{-target-file-get} Command
37716
37717 @subsubheading Synopsis
37718
37719 @smallexample
37720 -target-file-get @var{targetfile} @var{hostfile}
37721 @end smallexample
37722
37723 Copy file @var{targetfile} from the target system to @var{hostfile}
37724 on the host system.
37725
37726 @subsubheading @value{GDBN} Command
37727
37728 The corresponding @value{GDBN} command is @samp{remote get}.
37729
37730 @subsubheading Example
37731
37732 @smallexample
37733 (gdb)
37734 -target-file-get remotefile localfile
37735 ^done
37736 (gdb)
37737 @end smallexample
37738
37739
37740 @findex -target-file-delete
37741 @subheading The @code{-target-file-delete} Command
37742
37743 @subsubheading Synopsis
37744
37745 @smallexample
37746 -target-file-delete @var{targetfile}
37747 @end smallexample
37748
37749 Delete @var{targetfile} from the target system.
37750
37751 @subsubheading @value{GDBN} Command
37752
37753 The corresponding @value{GDBN} command is @samp{remote delete}.
37754
37755 @subsubheading Example
37756
37757 @smallexample
37758 (gdb)
37759 -target-file-delete remotefile
37760 ^done
37761 (gdb)
37762 @end smallexample
37763
37764
37765 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37766 @node GDB/MI Ada Exceptions Commands
37767 @section Ada Exceptions @sc{gdb/mi} Commands
37768
37769 @findex -info-ada-exceptions
37770 @subheading The @code{-info-ada-exceptions} Command
37771
37772 @subsubheading Synopsis
37773
37774 @smallexample
37775 -info-ada-exceptions [ @var{regexp}]
37776 @end smallexample
37777
37778 List all Ada exceptions defined within the program being debugged.
37779 With a regular expression @var{regexp}, only those exceptions whose
37780 names match @var{regexp} are listed.
37781
37782 @subsubheading @value{GDBN} Command
37783
37784 The corresponding @value{GDBN} command is @samp{info exceptions}.
37785
37786 @subsubheading Result
37787
37788 The result is a table of Ada exceptions. The following columns are
37789 defined for each exception:
37790
37791 @table @samp
37792 @item name
37793 The name of the exception.
37794
37795 @item address
37796 The address of the exception.
37797
37798 @end table
37799
37800 @subsubheading Example
37801
37802 @smallexample
37803 -info-ada-exceptions aint
37804 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
37805 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
37806 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
37807 body=[@{name="constraint_error",address="0x0000000000613da0"@},
37808 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
37809 @end smallexample
37810
37811 @subheading Catching Ada Exceptions
37812
37813 The commands describing how to ask @value{GDBN} to stop when a program
37814 raises an exception are described at @ref{Ada Exception GDB/MI
37815 Catchpoint Commands}.
37816
37817
37818 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37819 @node GDB/MI Support Commands
37820 @section @sc{gdb/mi} Support Commands
37821
37822 Since new commands and features get regularly added to @sc{gdb/mi},
37823 some commands are available to help front-ends query the debugger
37824 about support for these capabilities. Similarly, it is also possible
37825 to query @value{GDBN} about target support of certain features.
37826
37827 @cindex @code{-info-gdb-mi-command}
37828 @findex -info-gdb-mi-command
37829 @subheading The @code{-info-gdb-mi-command} Command
37830
37831 @subsubheading Synopsis
37832
37833 @smallexample
37834 -info-gdb-mi-command @var{cmd_name}
37835 @end smallexample
37836
37837 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
37838
37839 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
37840 is technically not part of the command name (@pxref{GDB/MI Input
37841 Syntax}), and thus should be omitted in @var{cmd_name}. However,
37842 for ease of use, this command also accepts the form with the leading
37843 dash.
37844
37845 @subsubheading @value{GDBN} Command
37846
37847 There is no corresponding @value{GDBN} command.
37848
37849 @subsubheading Result
37850
37851 The result is a tuple. There is currently only one field:
37852
37853 @table @samp
37854 @item exists
37855 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
37856 @code{"false"} otherwise.
37857
37858 @end table
37859
37860 @subsubheading Example
37861
37862 Here is an example where the @sc{gdb/mi} command does not exist:
37863
37864 @smallexample
37865 -info-gdb-mi-command unsupported-command
37866 ^done,command=@{exists="false"@}
37867 @end smallexample
37868
37869 @noindent
37870 And here is an example where the @sc{gdb/mi} command is known
37871 to the debugger:
37872
37873 @smallexample
37874 -info-gdb-mi-command symbol-list-lines
37875 ^done,command=@{exists="true"@}
37876 @end smallexample
37877
37878 @findex -list-features
37879 @cindex supported @sc{gdb/mi} features, list
37880 @subheading The @code{-list-features} Command
37881
37882 Returns a list of particular features of the MI protocol that
37883 this version of gdb implements. A feature can be a command,
37884 or a new field in an output of some command, or even an
37885 important bugfix. While a frontend can sometimes detect presence
37886 of a feature at runtime, it is easier to perform detection at debugger
37887 startup.
37888
37889 The command returns a list of strings, with each string naming an
37890 available feature. Each returned string is just a name, it does not
37891 have any internal structure. The list of possible feature names
37892 is given below.
37893
37894 Example output:
37895
37896 @smallexample
37897 (gdb) -list-features
37898 ^done,result=["feature1","feature2"]
37899 @end smallexample
37900
37901 The current list of features is:
37902
37903 @ftable @samp
37904 @item frozen-varobjs
37905 Indicates support for the @code{-var-set-frozen} command, as well
37906 as possible presence of the @code{frozen} field in the output
37907 of @code{-varobj-create}.
37908 @item pending-breakpoints
37909 Indicates support for the @option{-f} option to the @code{-break-insert}
37910 command.
37911 @item python
37912 Indicates Python scripting support, Python-based
37913 pretty-printing commands, and possible presence of the
37914 @samp{display_hint} field in the output of @code{-var-list-children}
37915 @item thread-info
37916 Indicates support for the @code{-thread-info} command.
37917 @item data-read-memory-bytes
37918 Indicates support for the @code{-data-read-memory-bytes} and the
37919 @code{-data-write-memory-bytes} commands.
37920 @item breakpoint-notifications
37921 Indicates that changes to breakpoints and breakpoints created via the
37922 CLI will be announced via async records.
37923 @item ada-task-info
37924 Indicates support for the @code{-ada-task-info} command.
37925 @item language-option
37926 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
37927 option (@pxref{Context management}).
37928 @item info-gdb-mi-command
37929 Indicates support for the @code{-info-gdb-mi-command} command.
37930 @item undefined-command-error-code
37931 Indicates support for the "undefined-command" error code in error result
37932 records, produced when trying to execute an undefined @sc{gdb/mi} command
37933 (@pxref{GDB/MI Result Records}).
37934 @item exec-run-start-option
37935 Indicates that the @code{-exec-run} command supports the @option{--start}
37936 option (@pxref{GDB/MI Program Execution}).
37937 @item data-disassemble-a-option
37938 Indicates that the @code{-data-disassemble} command supports the @option{-a}
37939 option (@pxref{GDB/MI Data Manipulation}).
37940 @end ftable
37941
37942 @findex -list-target-features
37943 @subheading The @code{-list-target-features} Command
37944
37945 Returns a list of particular features that are supported by the
37946 target. Those features affect the permitted MI commands, but
37947 unlike the features reported by the @code{-list-features} command, the
37948 features depend on which target GDB is using at the moment. Whenever
37949 a target can change, due to commands such as @code{-target-select},
37950 @code{-target-attach} or @code{-exec-run}, the list of target features
37951 may change, and the frontend should obtain it again.
37952 Example output:
37953
37954 @smallexample
37955 (gdb) -list-target-features
37956 ^done,result=["async"]
37957 @end smallexample
37958
37959 The current list of features is:
37960
37961 @table @samp
37962 @item async
37963 Indicates that the target is capable of asynchronous command
37964 execution, which means that @value{GDBN} will accept further commands
37965 while the target is running.
37966
37967 @item reverse
37968 Indicates that the target is capable of reverse execution.
37969 @xref{Reverse Execution}, for more information.
37970
37971 @end table
37972
37973 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37974 @node GDB/MI Miscellaneous Commands
37975 @section Miscellaneous @sc{gdb/mi} Commands
37976
37977 @c @subheading -gdb-complete
37978
37979 @findex -gdb-exit
37980 @subheading The @code{-gdb-exit} Command
37981
37982 @subsubheading Synopsis
37983
37984 @smallexample
37985 -gdb-exit
37986 @end smallexample
37987
37988 Exit @value{GDBN} immediately.
37989
37990 @subsubheading @value{GDBN} Command
37991
37992 Approximately corresponds to @samp{quit}.
37993
37994 @subsubheading Example
37995
37996 @smallexample
37997 (gdb)
37998 -gdb-exit
37999 ^exit
38000 @end smallexample
38001
38002
38003 @ignore
38004 @findex -exec-abort
38005 @subheading The @code{-exec-abort} Command
38006
38007 @subsubheading Synopsis
38008
38009 @smallexample
38010 -exec-abort
38011 @end smallexample
38012
38013 Kill the inferior running program.
38014
38015 @subsubheading @value{GDBN} Command
38016
38017 The corresponding @value{GDBN} command is @samp{kill}.
38018
38019 @subsubheading Example
38020 N.A.
38021 @end ignore
38022
38023
38024 @findex -gdb-set
38025 @subheading The @code{-gdb-set} Command
38026
38027 @subsubheading Synopsis
38028
38029 @smallexample
38030 -gdb-set
38031 @end smallexample
38032
38033 Set an internal @value{GDBN} variable.
38034 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
38035
38036 @subsubheading @value{GDBN} Command
38037
38038 The corresponding @value{GDBN} command is @samp{set}.
38039
38040 @subsubheading Example
38041
38042 @smallexample
38043 (gdb)
38044 -gdb-set $foo=3
38045 ^done
38046 (gdb)
38047 @end smallexample
38048
38049
38050 @findex -gdb-show
38051 @subheading The @code{-gdb-show} Command
38052
38053 @subsubheading Synopsis
38054
38055 @smallexample
38056 -gdb-show
38057 @end smallexample
38058
38059 Show the current value of a @value{GDBN} variable.
38060
38061 @subsubheading @value{GDBN} Command
38062
38063 The corresponding @value{GDBN} command is @samp{show}.
38064
38065 @subsubheading Example
38066
38067 @smallexample
38068 (gdb)
38069 -gdb-show annotate
38070 ^done,value="0"
38071 (gdb)
38072 @end smallexample
38073
38074 @c @subheading -gdb-source
38075
38076
38077 @findex -gdb-version
38078 @subheading The @code{-gdb-version} Command
38079
38080 @subsubheading Synopsis
38081
38082 @smallexample
38083 -gdb-version
38084 @end smallexample
38085
38086 Show version information for @value{GDBN}. Used mostly in testing.
38087
38088 @subsubheading @value{GDBN} Command
38089
38090 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
38091 default shows this information when you start an interactive session.
38092
38093 @subsubheading Example
38094
38095 @c This example modifies the actual output from GDB to avoid overfull
38096 @c box in TeX.
38097 @smallexample
38098 (gdb)
38099 -gdb-version
38100 ~GNU gdb 5.2.1
38101 ~Copyright 2000 Free Software Foundation, Inc.
38102 ~GDB is free software, covered by the GNU General Public License, and
38103 ~you are welcome to change it and/or distribute copies of it under
38104 ~ certain conditions.
38105 ~Type "show copying" to see the conditions.
38106 ~There is absolutely no warranty for GDB. Type "show warranty" for
38107 ~ details.
38108 ~This GDB was configured as
38109 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
38110 ^done
38111 (gdb)
38112 @end smallexample
38113
38114 @findex -list-thread-groups
38115 @subheading The @code{-list-thread-groups} Command
38116
38117 @subheading Synopsis
38118
38119 @smallexample
38120 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
38121 @end smallexample
38122
38123 Lists thread groups (@pxref{Thread groups}). When a single thread
38124 group is passed as the argument, lists the children of that group.
38125 When several thread group are passed, lists information about those
38126 thread groups. Without any parameters, lists information about all
38127 top-level thread groups.
38128
38129 Normally, thread groups that are being debugged are reported.
38130 With the @samp{--available} option, @value{GDBN} reports thread groups
38131 available on the target.
38132
38133 The output of this command may have either a @samp{threads} result or
38134 a @samp{groups} result. The @samp{thread} result has a list of tuples
38135 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
38136 Information}). The @samp{groups} result has a list of tuples as value,
38137 each tuple describing a thread group. If top-level groups are
38138 requested (that is, no parameter is passed), or when several groups
38139 are passed, the output always has a @samp{groups} result. The format
38140 of the @samp{group} result is described below.
38141
38142 To reduce the number of roundtrips it's possible to list thread groups
38143 together with their children, by passing the @samp{--recurse} option
38144 and the recursion depth. Presently, only recursion depth of 1 is
38145 permitted. If this option is present, then every reported thread group
38146 will also include its children, either as @samp{group} or
38147 @samp{threads} field.
38148
38149 In general, any combination of option and parameters is permitted, with
38150 the following caveats:
38151
38152 @itemize @bullet
38153 @item
38154 When a single thread group is passed, the output will typically
38155 be the @samp{threads} result. Because threads may not contain
38156 anything, the @samp{recurse} option will be ignored.
38157
38158 @item
38159 When the @samp{--available} option is passed, limited information may
38160 be available. In particular, the list of threads of a process might
38161 be inaccessible. Further, specifying specific thread groups might
38162 not give any performance advantage over listing all thread groups.
38163 The frontend should assume that @samp{-list-thread-groups --available}
38164 is always an expensive operation and cache the results.
38165
38166 @end itemize
38167
38168 The @samp{groups} result is a list of tuples, where each tuple may
38169 have the following fields:
38170
38171 @table @code
38172 @item id
38173 Identifier of the thread group. This field is always present.
38174 The identifier is an opaque string; frontends should not try to
38175 convert it to an integer, even though it might look like one.
38176
38177 @item type
38178 The type of the thread group. At present, only @samp{process} is a
38179 valid type.
38180
38181 @item pid
38182 The target-specific process identifier. This field is only present
38183 for thread groups of type @samp{process} and only if the process exists.
38184
38185 @item exit-code
38186 The exit code of this group's last exited thread, formatted in octal.
38187 This field is only present for thread groups of type @samp{process} and
38188 only if the process is not running.
38189
38190 @item num_children
38191 The number of children this thread group has. This field may be
38192 absent for an available thread group.
38193
38194 @item threads
38195 This field has a list of tuples as value, each tuple describing a
38196 thread. It may be present if the @samp{--recurse} option is
38197 specified, and it's actually possible to obtain the threads.
38198
38199 @item cores
38200 This field is a list of integers, each identifying a core that one
38201 thread of the group is running on. This field may be absent if
38202 such information is not available.
38203
38204 @item executable
38205 The name of the executable file that corresponds to this thread group.
38206 The field is only present for thread groups of type @samp{process},
38207 and only if there is a corresponding executable file.
38208
38209 @end table
38210
38211 @subheading Example
38212
38213 @smallexample
38214 (@value{GDBP})
38215 -list-thread-groups
38216 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
38217 -list-thread-groups 17
38218 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
38219 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
38220 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
38221 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
38222 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
38223 -list-thread-groups --available
38224 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
38225 -list-thread-groups --available --recurse 1
38226 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
38227 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
38228 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
38229 -list-thread-groups --available --recurse 1 17 18
38230 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
38231 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
38232 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
38233 @end smallexample
38234
38235 @findex -info-os
38236 @subheading The @code{-info-os} Command
38237
38238 @subsubheading Synopsis
38239
38240 @smallexample
38241 -info-os [ @var{type} ]
38242 @end smallexample
38243
38244 If no argument is supplied, the command returns a table of available
38245 operating-system-specific information types. If one of these types is
38246 supplied as an argument @var{type}, then the command returns a table
38247 of data of that type.
38248
38249 The types of information available depend on the target operating
38250 system.
38251
38252 @subsubheading @value{GDBN} Command
38253
38254 The corresponding @value{GDBN} command is @samp{info os}.
38255
38256 @subsubheading Example
38257
38258 When run on a @sc{gnu}/Linux system, the output will look something
38259 like this:
38260
38261 @smallexample
38262 (@value{GDBP})
38263 -info-os
38264 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
38265 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
38266 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
38267 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
38268 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
38269 col2="CPUs"@},
38270 item=@{col0="files",col1="Listing of all file descriptors",
38271 col2="File descriptors"@},
38272 item=@{col0="modules",col1="Listing of all loaded kernel modules",
38273 col2="Kernel modules"@},
38274 item=@{col0="msg",col1="Listing of all message queues",
38275 col2="Message queues"@},
38276 item=@{col0="processes",col1="Listing of all processes",
38277 col2="Processes"@},
38278 item=@{col0="procgroups",col1="Listing of all process groups",
38279 col2="Process groups"@},
38280 item=@{col0="semaphores",col1="Listing of all semaphores",
38281 col2="Semaphores"@},
38282 item=@{col0="shm",col1="Listing of all shared-memory regions",
38283 col2="Shared-memory regions"@},
38284 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
38285 col2="Sockets"@},
38286 item=@{col0="threads",col1="Listing of all threads",
38287 col2="Threads"@}]
38288 (@value{GDBP})
38289 -info-os processes
38290 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
38291 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
38292 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
38293 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
38294 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
38295 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
38296 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
38297 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
38298 ...
38299 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
38300 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
38301 (@value{GDBP})
38302 @end smallexample
38303
38304 (Note that the MI output here includes a @code{"Title"} column that
38305 does not appear in command-line @code{info os}; this column is useful
38306 for MI clients that want to enumerate the types of data, such as in a
38307 popup menu, but is needless clutter on the command line, and
38308 @code{info os} omits it.)
38309
38310 @findex -add-inferior
38311 @subheading The @code{-add-inferior} Command
38312
38313 @subheading Synopsis
38314
38315 @smallexample
38316 -add-inferior [ --no-connection ]
38317 @end smallexample
38318
38319 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
38320 inferior is not associated with any executable. Such association may
38321 be established with the @samp{-file-exec-and-symbols} command
38322 (@pxref{GDB/MI File Commands}).
38323
38324 By default, the new inferior begins connected to the same target
38325 connection as the current inferior. For example, if the current
38326 inferior was connected to @code{gdbserver} with @code{target remote},
38327 then the new inferior will be connected to the same @code{gdbserver}
38328 instance. The @samp{--no-connection} option starts the new inferior
38329 with no connection yet. You can then for example use the
38330 @code{-target-select remote} command to connect to some other
38331 @code{gdbserver} instance, use @code{-exec-run} to spawn a local
38332 program, etc.
38333
38334 The command response always has a field, @var{inferior}, whose value
38335 is the identifier of the thread group corresponding to the new
38336 inferior.
38337
38338 An additional section field, @var{connection}, is optional. This
38339 field will only exist if the new inferior has a target connection. If
38340 this field exists, then its value will be a tuple containing the
38341 following fields:
38342
38343 @table @samp
38344 @item number
38345 The number of the connection used for the new inferior.
38346
38347 @item name
38348 The name of the connection type used for the new inferior.
38349 @end table
38350
38351 @subheading @value{GDBN} Command
38352
38353 The corresponding @value{GDBN} command is @samp{add-inferior}
38354 (@pxref{add_inferior_cli,,@samp{add-inferior}}).
38355
38356 @subheading Example
38357
38358 @smallexample
38359 (@value{GDBP})
38360 -add-inferior
38361 ^done,inferior="i3"
38362 @end smallexample
38363
38364 @findex -remove-inferior
38365 @subheading The @code{-remove-inferior} Command
38366
38367 @subsubheading Synopsis
38368
38369 @smallexample
38370 -remove-inferior @var{inferior-id}
38371 @end smallexample
38372
38373 Removes an inferior (@pxref{Inferiors Connections and Programs}).
38374 Only inferiors that have exited can be removed. The @var{inferior-id}
38375 is the inferior to be removed, and should be the same id string as
38376 returned by the @samp{-add-inferior} command.
38377
38378 When an inferior is successfully removed a
38379 @code{=thread-group-removed} notification (@pxref{GDB/MI Async
38380 Records}) is emitted, the @var{id} field of which contains the
38381 @var{inferior-id} for the removed inferior.
38382
38383 @subsubheading @value{GDBN} Command
38384
38385 The corresponding @value{GDBN} command is @samp{remove-inferiors}
38386 (@pxref{remove_inferiors_cli,,@samp{remove-inferiors}}).
38387
38388 @subsubheading Example
38389
38390 @smallexample
38391 (@value{GDBP})
38392 -remove-inferior i3
38393 =thread-group-removed,id="i3"
38394 ^done
38395 @end smallexample
38396
38397 @findex -interpreter-exec
38398 @subheading The @code{-interpreter-exec} Command
38399
38400 @subheading Synopsis
38401
38402 @smallexample
38403 -interpreter-exec @var{interpreter} @var{command}
38404 @end smallexample
38405 @anchor{-interpreter-exec}
38406
38407 Execute the specified @var{command} in the given @var{interpreter}.
38408
38409 @subheading @value{GDBN} Command
38410
38411 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
38412
38413 @subheading Example
38414
38415 @smallexample
38416 (gdb)
38417 -interpreter-exec console "break main"
38418 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
38419 &"During symbol reading, bad structure-type format.\n"
38420 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
38421 ^done
38422 (gdb)
38423 @end smallexample
38424
38425 @findex -inferior-tty-set
38426 @subheading The @code{-inferior-tty-set} Command
38427
38428 @subheading Synopsis
38429
38430 @smallexample
38431 -inferior-tty-set /dev/pts/1
38432 @end smallexample
38433
38434 Set terminal for future runs of the program being debugged.
38435
38436 @subheading @value{GDBN} Command
38437
38438 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
38439
38440 @subheading Example
38441
38442 @smallexample
38443 (gdb)
38444 -inferior-tty-set /dev/pts/1
38445 ^done
38446 (gdb)
38447 @end smallexample
38448
38449 @findex -inferior-tty-show
38450 @subheading The @code{-inferior-tty-show} Command
38451
38452 @subheading Synopsis
38453
38454 @smallexample
38455 -inferior-tty-show
38456 @end smallexample
38457
38458 Show terminal for future runs of program being debugged.
38459
38460 @subheading @value{GDBN} Command
38461
38462 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
38463
38464 @subheading Example
38465
38466 @smallexample
38467 (gdb)
38468 -inferior-tty-set /dev/pts/1
38469 ^done
38470 (gdb)
38471 -inferior-tty-show
38472 ^done,inferior_tty_terminal="/dev/pts/1"
38473 (gdb)
38474 @end smallexample
38475
38476 @findex -enable-timings
38477 @subheading The @code{-enable-timings} Command
38478
38479 @subheading Synopsis
38480
38481 @smallexample
38482 -enable-timings [yes | no]
38483 @end smallexample
38484
38485 Toggle the printing of the wallclock, user and system times for an MI
38486 command as a field in its output. This command is to help frontend
38487 developers optimize the performance of their code. No argument is
38488 equivalent to @samp{yes}.
38489
38490 @subheading @value{GDBN} Command
38491
38492 No equivalent.
38493
38494 @subheading Example
38495
38496 @smallexample
38497 (gdb)
38498 -enable-timings
38499 ^done
38500 (gdb)
38501 -break-insert main
38502 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
38503 addr="0x080484ed",func="main",file="myprog.c",
38504 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
38505 times="0"@},
38506 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
38507 (gdb)
38508 -enable-timings no
38509 ^done
38510 (gdb)
38511 -exec-run
38512 ^running
38513 (gdb)
38514 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
38515 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
38516 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
38517 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
38518 (gdb)
38519 @end smallexample
38520
38521 @findex -complete
38522 @subheading The @code{-complete} Command
38523
38524 @subheading Synopsis
38525
38526 @smallexample
38527 -complete @var{command}
38528 @end smallexample
38529
38530 Show a list of completions for partially typed CLI @var{command}.
38531
38532 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
38533 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
38534 because @value{GDBN} is used remotely via a SSH connection.
38535
38536 @subheading Result
38537
38538 The result consists of two or three fields:
38539
38540 @table @samp
38541 @item completion
38542 This field contains the completed @var{command}. If @var{command}
38543 has no known completions, this field is omitted.
38544
38545 @item matches
38546 This field contains a (possibly empty) array of matches. It is always present.
38547
38548 @item max_completions_reached
38549 This field contains @code{1} if number of known completions is above
38550 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
38551 @code{0}. It is always present.
38552
38553 @end table
38554
38555 @subheading @value{GDBN} Command
38556
38557 The corresponding @value{GDBN} command is @samp{complete}.
38558
38559 @subheading Example
38560
38561 @smallexample
38562 (gdb)
38563 -complete br
38564 ^done,completion="break",
38565 matches=["break","break-range"],
38566 max_completions_reached="0"
38567 (gdb)
38568 -complete "b ma"
38569 ^done,completion="b ma",
38570 matches=["b madvise","b main"],max_completions_reached="0"
38571 (gdb)
38572 -complete "b push_b"
38573 ^done,completion="b push_back(",
38574 matches=[
38575 "b A::push_back(void*)",
38576 "b std::string::push_back(char)",
38577 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
38578 max_completions_reached="0"
38579 (gdb)
38580 -complete "nonexist"
38581 ^done,matches=[],max_completions_reached="0"
38582 (gdb)
38583
38584 @end smallexample
38585
38586 @node Annotations
38587 @chapter @value{GDBN} Annotations
38588
38589 This chapter describes annotations in @value{GDBN}. Annotations were
38590 designed to interface @value{GDBN} to graphical user interfaces or other
38591 similar programs which want to interact with @value{GDBN} at a
38592 relatively high level.
38593
38594 The annotation mechanism has largely been superseded by @sc{gdb/mi}
38595 (@pxref{GDB/MI}).
38596
38597 @ignore
38598 This is Edition @value{EDITION}, @value{DATE}.
38599 @end ignore
38600
38601 @menu
38602 * Annotations Overview:: What annotations are; the general syntax.
38603 * Server Prefix:: Issuing a command without affecting user state.
38604 * Prompting:: Annotations marking @value{GDBN}'s need for input.
38605 * Errors:: Annotations for error messages.
38606 * Invalidation:: Some annotations describe things now invalid.
38607 * Annotations for Running::
38608 Whether the program is running, how it stopped, etc.
38609 * Source Annotations:: Annotations describing source code.
38610 @end menu
38611
38612 @node Annotations Overview
38613 @section What is an Annotation?
38614 @cindex annotations
38615
38616 Annotations start with a newline character, two @samp{control-z}
38617 characters, and the name of the annotation. If there is no additional
38618 information associated with this annotation, the name of the annotation
38619 is followed immediately by a newline. If there is additional
38620 information, the name of the annotation is followed by a space, the
38621 additional information, and a newline. The additional information
38622 cannot contain newline characters.
38623
38624 Any output not beginning with a newline and two @samp{control-z}
38625 characters denotes literal output from @value{GDBN}. Currently there is
38626 no need for @value{GDBN} to output a newline followed by two
38627 @samp{control-z} characters, but if there was such a need, the
38628 annotations could be extended with an @samp{escape} annotation which
38629 means those three characters as output.
38630
38631 The annotation @var{level}, which is specified using the
38632 @option{--annotate} command line option (@pxref{Mode Options}), controls
38633 how much information @value{GDBN} prints together with its prompt,
38634 values of expressions, source lines, and other types of output. Level 0
38635 is for no annotations, level 1 is for use when @value{GDBN} is run as a
38636 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
38637 for programs that control @value{GDBN}, and level 2 annotations have
38638 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
38639 Interface, annotate, GDB's Obsolete Annotations}).
38640
38641 @table @code
38642 @kindex set annotate
38643 @item set annotate @var{level}
38644 The @value{GDBN} command @code{set annotate} sets the level of
38645 annotations to the specified @var{level}.
38646
38647 @item show annotate
38648 @kindex show annotate
38649 Show the current annotation level.
38650 @end table
38651
38652 This chapter describes level 3 annotations.
38653
38654 A simple example of starting up @value{GDBN} with annotations is:
38655
38656 @smallexample
38657 $ @kbd{gdb --annotate=3}
38658 GNU gdb 6.0
38659 Copyright 2003 Free Software Foundation, Inc.
38660 GDB is free software, covered by the GNU General Public License,
38661 and you are welcome to change it and/or distribute copies of it
38662 under certain conditions.
38663 Type "show copying" to see the conditions.
38664 There is absolutely no warranty for GDB. Type "show warranty"
38665 for details.
38666 This GDB was configured as "i386-pc-linux-gnu"
38667
38668 ^Z^Zpre-prompt
38669 (@value{GDBP})
38670 ^Z^Zprompt
38671 @kbd{quit}
38672
38673 ^Z^Zpost-prompt
38674 $
38675 @end smallexample
38676
38677 Here @samp{quit} is input to @value{GDBN}; the rest is output from
38678 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
38679 denotes a @samp{control-z} character) are annotations; the rest is
38680 output from @value{GDBN}.
38681
38682 @node Server Prefix
38683 @section The Server Prefix
38684 @cindex server prefix
38685
38686 If you prefix a command with @samp{server } then it will not affect
38687 the command history, nor will it affect @value{GDBN}'s notion of which
38688 command to repeat if @key{RET} is pressed on a line by itself. This
38689 means that commands can be run behind a user's back by a front-end in
38690 a transparent manner.
38691
38692 The @code{server } prefix does not affect the recording of values into
38693 the value history; to print a value without recording it into the
38694 value history, use the @code{output} command instead of the
38695 @code{print} command.
38696
38697 Using this prefix also disables confirmation requests
38698 (@pxref{confirmation requests}).
38699
38700 @node Prompting
38701 @section Annotation for @value{GDBN} Input
38702
38703 @cindex annotations for prompts
38704 When @value{GDBN} prompts for input, it annotates this fact so it is possible
38705 to know when to send output, when the output from a given command is
38706 over, etc.
38707
38708 Different kinds of input each have a different @dfn{input type}. Each
38709 input type has three annotations: a @code{pre-} annotation, which
38710 denotes the beginning of any prompt which is being output, a plain
38711 annotation, which denotes the end of the prompt, and then a @code{post-}
38712 annotation which denotes the end of any echo which may (or may not) be
38713 associated with the input. For example, the @code{prompt} input type
38714 features the following annotations:
38715
38716 @smallexample
38717 ^Z^Zpre-prompt
38718 ^Z^Zprompt
38719 ^Z^Zpost-prompt
38720 @end smallexample
38721
38722 The input types are
38723
38724 @table @code
38725 @findex pre-prompt annotation
38726 @findex prompt annotation
38727 @findex post-prompt annotation
38728 @item prompt
38729 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
38730
38731 @findex pre-commands annotation
38732 @findex commands annotation
38733 @findex post-commands annotation
38734 @item commands
38735 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
38736 command. The annotations are repeated for each command which is input.
38737
38738 @findex pre-overload-choice annotation
38739 @findex overload-choice annotation
38740 @findex post-overload-choice annotation
38741 @item overload-choice
38742 When @value{GDBN} wants the user to select between various overloaded functions.
38743
38744 @findex pre-query annotation
38745 @findex query annotation
38746 @findex post-query annotation
38747 @item query
38748 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
38749
38750 @findex pre-prompt-for-continue annotation
38751 @findex prompt-for-continue annotation
38752 @findex post-prompt-for-continue annotation
38753 @item prompt-for-continue
38754 When @value{GDBN} is asking the user to press return to continue. Note: Don't
38755 expect this to work well; instead use @code{set height 0} to disable
38756 prompting. This is because the counting of lines is buggy in the
38757 presence of annotations.
38758 @end table
38759
38760 @node Errors
38761 @section Errors
38762 @cindex annotations for errors, warnings and interrupts
38763
38764 @findex quit annotation
38765 @smallexample
38766 ^Z^Zquit
38767 @end smallexample
38768
38769 This annotation occurs right before @value{GDBN} responds to an interrupt.
38770
38771 @findex error annotation
38772 @smallexample
38773 ^Z^Zerror
38774 @end smallexample
38775
38776 This annotation occurs right before @value{GDBN} responds to an error.
38777
38778 Quit and error annotations indicate that any annotations which @value{GDBN} was
38779 in the middle of may end abruptly. For example, if a
38780 @code{value-history-begin} annotation is followed by a @code{error}, one
38781 cannot expect to receive the matching @code{value-history-end}. One
38782 cannot expect not to receive it either, however; an error annotation
38783 does not necessarily mean that @value{GDBN} is immediately returning all the way
38784 to the top level.
38785
38786 @findex error-begin annotation
38787 A quit or error annotation may be preceded by
38788
38789 @smallexample
38790 ^Z^Zerror-begin
38791 @end smallexample
38792
38793 Any output between that and the quit or error annotation is the error
38794 message.
38795
38796 Warning messages are not yet annotated.
38797 @c If we want to change that, need to fix warning(), type_error(),
38798 @c range_error(), and possibly other places.
38799
38800 @node Invalidation
38801 @section Invalidation Notices
38802
38803 @cindex annotations for invalidation messages
38804 The following annotations say that certain pieces of state may have
38805 changed.
38806
38807 @table @code
38808 @findex frames-invalid annotation
38809 @item ^Z^Zframes-invalid
38810
38811 The frames (for example, output from the @code{backtrace} command) may
38812 have changed.
38813
38814 @findex breakpoints-invalid annotation
38815 @item ^Z^Zbreakpoints-invalid
38816
38817 The breakpoints may have changed. For example, the user just added or
38818 deleted a breakpoint.
38819 @end table
38820
38821 @node Annotations for Running
38822 @section Running the Program
38823 @cindex annotations for running programs
38824
38825 @findex starting annotation
38826 @findex stopping annotation
38827 When the program starts executing due to a @value{GDBN} command such as
38828 @code{step} or @code{continue},
38829
38830 @smallexample
38831 ^Z^Zstarting
38832 @end smallexample
38833
38834 is output. When the program stops,
38835
38836 @smallexample
38837 ^Z^Zstopped
38838 @end smallexample
38839
38840 is output. Before the @code{stopped} annotation, a variety of
38841 annotations describe how the program stopped.
38842
38843 @table @code
38844 @findex exited annotation
38845 @item ^Z^Zexited @var{exit-status}
38846 The program exited, and @var{exit-status} is the exit status (zero for
38847 successful exit, otherwise nonzero).
38848
38849 @findex signalled annotation
38850 @findex signal-name annotation
38851 @findex signal-name-end annotation
38852 @findex signal-string annotation
38853 @findex signal-string-end annotation
38854 @item ^Z^Zsignalled
38855 The program exited with a signal. After the @code{^Z^Zsignalled}, the
38856 annotation continues:
38857
38858 @smallexample
38859 @var{intro-text}
38860 ^Z^Zsignal-name
38861 @var{name}
38862 ^Z^Zsignal-name-end
38863 @var{middle-text}
38864 ^Z^Zsignal-string
38865 @var{string}
38866 ^Z^Zsignal-string-end
38867 @var{end-text}
38868 @end smallexample
38869
38870 @noindent
38871 where @var{name} is the name of the signal, such as @code{SIGILL} or
38872 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
38873 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
38874 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
38875 user's benefit and have no particular format.
38876
38877 @findex signal annotation
38878 @item ^Z^Zsignal
38879 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
38880 just saying that the program received the signal, not that it was
38881 terminated with it.
38882
38883 @findex breakpoint annotation
38884 @item ^Z^Zbreakpoint @var{number}
38885 The program hit breakpoint number @var{number}.
38886
38887 @findex watchpoint annotation
38888 @item ^Z^Zwatchpoint @var{number}
38889 The program hit watchpoint number @var{number}.
38890 @end table
38891
38892 @node Source Annotations
38893 @section Displaying Source
38894 @cindex annotations for source display
38895
38896 @findex source annotation
38897 The following annotation is used instead of displaying source code:
38898
38899 @smallexample
38900 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
38901 @end smallexample
38902
38903 where @var{filename} is an absolute file name indicating which source
38904 file, @var{line} is the line number within that file (where 1 is the
38905 first line in the file), @var{character} is the character position
38906 within the file (where 0 is the first character in the file) (for most
38907 debug formats this will necessarily point to the beginning of a line),
38908 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
38909 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
38910 @var{addr} is the address in the target program associated with the
38911 source which is being displayed. The @var{addr} is in the form @samp{0x}
38912 followed by one or more lowercase hex digits (note that this does not
38913 depend on the language).
38914
38915 @node JIT Interface
38916 @chapter JIT Compilation Interface
38917 @cindex just-in-time compilation
38918 @cindex JIT compilation interface
38919
38920 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
38921 interface. A JIT compiler is a program or library that generates native
38922 executable code at runtime and executes it, usually in order to achieve good
38923 performance while maintaining platform independence.
38924
38925 Programs that use JIT compilation are normally difficult to debug because
38926 portions of their code are generated at runtime, instead of being loaded from
38927 object files, which is where @value{GDBN} normally finds the program's symbols
38928 and debug information. In order to debug programs that use JIT compilation,
38929 @value{GDBN} has an interface that allows the program to register in-memory
38930 symbol files with @value{GDBN} at runtime.
38931
38932 If you are using @value{GDBN} to debug a program that uses this interface, then
38933 it should work transparently so long as you have not stripped the binary. If
38934 you are developing a JIT compiler, then the interface is documented in the rest
38935 of this chapter. At this time, the only known client of this interface is the
38936 LLVM JIT.
38937
38938 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
38939 JIT compiler communicates with @value{GDBN} by writing data into a global
38940 variable and calling a function at a well-known symbol. When @value{GDBN}
38941 attaches, it reads a linked list of symbol files from the global variable to
38942 find existing code, and puts a breakpoint in the function so that it can find
38943 out about additional code.
38944
38945 @menu
38946 * Declarations:: Relevant C struct declarations
38947 * Registering Code:: Steps to register code
38948 * Unregistering Code:: Steps to unregister code
38949 * Custom Debug Info:: Emit debug information in a custom format
38950 @end menu
38951
38952 @node Declarations
38953 @section JIT Declarations
38954
38955 These are the relevant struct declarations that a C program should include to
38956 implement the interface:
38957
38958 @smallexample
38959 typedef enum
38960 @{
38961 JIT_NOACTION = 0,
38962 JIT_REGISTER_FN,
38963 JIT_UNREGISTER_FN
38964 @} jit_actions_t;
38965
38966 struct jit_code_entry
38967 @{
38968 struct jit_code_entry *next_entry;
38969 struct jit_code_entry *prev_entry;
38970 const char *symfile_addr;
38971 uint64_t symfile_size;
38972 @};
38973
38974 struct jit_descriptor
38975 @{
38976 uint32_t version;
38977 /* This type should be jit_actions_t, but we use uint32_t
38978 to be explicit about the bitwidth. */
38979 uint32_t action_flag;
38980 struct jit_code_entry *relevant_entry;
38981 struct jit_code_entry *first_entry;
38982 @};
38983
38984 /* GDB puts a breakpoint in this function. */
38985 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
38986
38987 /* Make sure to specify the version statically, because the
38988 debugger may check the version before we can set it. */
38989 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
38990 @end smallexample
38991
38992 If the JIT is multi-threaded, then it is important that the JIT synchronize any
38993 modifications to this global data properly, which can easily be done by putting
38994 a global mutex around modifications to these structures.
38995
38996 @node Registering Code
38997 @section Registering Code
38998
38999 To register code with @value{GDBN}, the JIT should follow this protocol:
39000
39001 @itemize @bullet
39002 @item
39003 Generate an object file in memory with symbols and other desired debug
39004 information. The file must include the virtual addresses of the sections.
39005
39006 @item
39007 Create a code entry for the file, which gives the start and size of the symbol
39008 file.
39009
39010 @item
39011 Add it to the linked list in the JIT descriptor.
39012
39013 @item
39014 Point the relevant_entry field of the descriptor at the entry.
39015
39016 @item
39017 Set @code{action_flag} to @code{JIT_REGISTER} and call
39018 @code{__jit_debug_register_code}.
39019 @end itemize
39020
39021 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
39022 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
39023 new code. However, the linked list must still be maintained in order to allow
39024 @value{GDBN} to attach to a running process and still find the symbol files.
39025
39026 @node Unregistering Code
39027 @section Unregistering Code
39028
39029 If code is freed, then the JIT should use the following protocol:
39030
39031 @itemize @bullet
39032 @item
39033 Remove the code entry corresponding to the code from the linked list.
39034
39035 @item
39036 Point the @code{relevant_entry} field of the descriptor at the code entry.
39037
39038 @item
39039 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
39040 @code{__jit_debug_register_code}.
39041 @end itemize
39042
39043 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
39044 and the JIT will leak the memory used for the associated symbol files.
39045
39046 @node Custom Debug Info
39047 @section Custom Debug Info
39048 @cindex custom JIT debug info
39049 @cindex JIT debug info reader
39050
39051 Generating debug information in platform-native file formats (like ELF
39052 or COFF) may be an overkill for JIT compilers; especially if all the
39053 debug info is used for is displaying a meaningful backtrace. The
39054 issue can be resolved by having the JIT writers decide on a debug info
39055 format and also provide a reader that parses the debug info generated
39056 by the JIT compiler. This section gives a brief overview on writing
39057 such a parser. More specific details can be found in the source file
39058 @file{gdb/jit-reader.in}, which is also installed as a header at
39059 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
39060
39061 The reader is implemented as a shared object (so this functionality is
39062 not available on platforms which don't allow loading shared objects at
39063 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
39064 @code{jit-reader-unload} are provided, to be used to load and unload
39065 the readers from a preconfigured directory. Once loaded, the shared
39066 object is used the parse the debug information emitted by the JIT
39067 compiler.
39068
39069 @menu
39070 * Using JIT Debug Info Readers:: How to use supplied readers correctly
39071 * Writing JIT Debug Info Readers:: Creating a debug-info reader
39072 @end menu
39073
39074 @node Using JIT Debug Info Readers
39075 @subsection Using JIT Debug Info Readers
39076 @kindex jit-reader-load
39077 @kindex jit-reader-unload
39078
39079 Readers can be loaded and unloaded using the @code{jit-reader-load}
39080 and @code{jit-reader-unload} commands.
39081
39082 @table @code
39083 @item jit-reader-load @var{reader}
39084 Load the JIT reader named @var{reader}, which is a shared
39085 object specified as either an absolute or a relative file name. In
39086 the latter case, @value{GDBN} will try to load the reader from a
39087 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
39088 system (here @var{libdir} is the system library directory, often
39089 @file{/usr/local/lib}).
39090
39091 Only one reader can be active at a time; trying to load a second
39092 reader when one is already loaded will result in @value{GDBN}
39093 reporting an error. A new JIT reader can be loaded by first unloading
39094 the current one using @code{jit-reader-unload} and then invoking
39095 @code{jit-reader-load}.
39096
39097 @item jit-reader-unload
39098 Unload the currently loaded JIT reader.
39099
39100 @end table
39101
39102 @node Writing JIT Debug Info Readers
39103 @subsection Writing JIT Debug Info Readers
39104 @cindex writing JIT debug info readers
39105
39106 As mentioned, a reader is essentially a shared object conforming to a
39107 certain ABI. This ABI is described in @file{jit-reader.h}.
39108
39109 @file{jit-reader.h} defines the structures, macros and functions
39110 required to write a reader. It is installed (along with
39111 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
39112 the system include directory.
39113
39114 Readers need to be released under a GPL compatible license. A reader
39115 can be declared as released under such a license by placing the macro
39116 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
39117
39118 The entry point for readers is the symbol @code{gdb_init_reader},
39119 which is expected to be a function with the prototype
39120
39121 @findex gdb_init_reader
39122 @smallexample
39123 extern struct gdb_reader_funcs *gdb_init_reader (void);
39124 @end smallexample
39125
39126 @cindex @code{struct gdb_reader_funcs}
39127
39128 @code{struct gdb_reader_funcs} contains a set of pointers to callback
39129 functions. These functions are executed to read the debug info
39130 generated by the JIT compiler (@code{read}), to unwind stack frames
39131 (@code{unwind}) and to create canonical frame IDs
39132 (@code{get_frame_id}). It also has a callback that is called when the
39133 reader is being unloaded (@code{destroy}). The struct looks like this
39134
39135 @smallexample
39136 struct gdb_reader_funcs
39137 @{
39138 /* Must be set to GDB_READER_INTERFACE_VERSION. */
39139 int reader_version;
39140
39141 /* For use by the reader. */
39142 void *priv_data;
39143
39144 gdb_read_debug_info *read;
39145 gdb_unwind_frame *unwind;
39146 gdb_get_frame_id *get_frame_id;
39147 gdb_destroy_reader *destroy;
39148 @};
39149 @end smallexample
39150
39151 @cindex @code{struct gdb_symbol_callbacks}
39152 @cindex @code{struct gdb_unwind_callbacks}
39153
39154 The callbacks are provided with another set of callbacks by
39155 @value{GDBN} to do their job. For @code{read}, these callbacks are
39156 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
39157 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
39158 @code{struct gdb_symbol_callbacks} has callbacks to create new object
39159 files and new symbol tables inside those object files. @code{struct
39160 gdb_unwind_callbacks} has callbacks to read registers off the current
39161 frame and to write out the values of the registers in the previous
39162 frame. Both have a callback (@code{target_read}) to read bytes off the
39163 target's address space.
39164
39165 @node In-Process Agent
39166 @chapter In-Process Agent
39167 @cindex debugging agent
39168 The traditional debugging model is conceptually low-speed, but works fine,
39169 because most bugs can be reproduced in debugging-mode execution. However,
39170 as multi-core or many-core processors are becoming mainstream, and
39171 multi-threaded programs become more and more popular, there should be more
39172 and more bugs that only manifest themselves at normal-mode execution, for
39173 example, thread races, because debugger's interference with the program's
39174 timing may conceal the bugs. On the other hand, in some applications,
39175 it is not feasible for the debugger to interrupt the program's execution
39176 long enough for the developer to learn anything helpful about its behavior.
39177 If the program's correctness depends on its real-time behavior, delays
39178 introduced by a debugger might cause the program to fail, even when the
39179 code itself is correct. It is useful to be able to observe the program's
39180 behavior without interrupting it.
39181
39182 Therefore, traditional debugging model is too intrusive to reproduce
39183 some bugs. In order to reduce the interference with the program, we can
39184 reduce the number of operations performed by debugger. The
39185 @dfn{In-Process Agent}, a shared library, is running within the same
39186 process with inferior, and is able to perform some debugging operations
39187 itself. As a result, debugger is only involved when necessary, and
39188 performance of debugging can be improved accordingly. Note that
39189 interference with program can be reduced but can't be removed completely,
39190 because the in-process agent will still stop or slow down the program.
39191
39192 The in-process agent can interpret and execute Agent Expressions
39193 (@pxref{Agent Expressions}) during performing debugging operations. The
39194 agent expressions can be used for different purposes, such as collecting
39195 data in tracepoints, and condition evaluation in breakpoints.
39196
39197 @anchor{Control Agent}
39198 You can control whether the in-process agent is used as an aid for
39199 debugging with the following commands:
39200
39201 @table @code
39202 @kindex set agent on
39203 @item set agent on
39204 Causes the in-process agent to perform some operations on behalf of the
39205 debugger. Just which operations requested by the user will be done
39206 by the in-process agent depends on the its capabilities. For example,
39207 if you request to evaluate breakpoint conditions in the in-process agent,
39208 and the in-process agent has such capability as well, then breakpoint
39209 conditions will be evaluated in the in-process agent.
39210
39211 @kindex set agent off
39212 @item set agent off
39213 Disables execution of debugging operations by the in-process agent. All
39214 of the operations will be performed by @value{GDBN}.
39215
39216 @kindex show agent
39217 @item show agent
39218 Display the current setting of execution of debugging operations by
39219 the in-process agent.
39220 @end table
39221
39222 @menu
39223 * In-Process Agent Protocol::
39224 @end menu
39225
39226 @node In-Process Agent Protocol
39227 @section In-Process Agent Protocol
39228 @cindex in-process agent protocol
39229
39230 The in-process agent is able to communicate with both @value{GDBN} and
39231 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
39232 used for communications between @value{GDBN} or GDBserver and the IPA.
39233 In general, @value{GDBN} or GDBserver sends commands
39234 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
39235 in-process agent replies back with the return result of the command, or
39236 some other information. The data sent to in-process agent is composed
39237 of primitive data types, such as 4-byte or 8-byte type, and composite
39238 types, which are called objects (@pxref{IPA Protocol Objects}).
39239
39240 @menu
39241 * IPA Protocol Objects::
39242 * IPA Protocol Commands::
39243 @end menu
39244
39245 @node IPA Protocol Objects
39246 @subsection IPA Protocol Objects
39247 @cindex ipa protocol objects
39248
39249 The commands sent to and results received from agent may contain some
39250 complex data types called @dfn{objects}.
39251
39252 The in-process agent is running on the same machine with @value{GDBN}
39253 or GDBserver, so it doesn't have to handle as much differences between
39254 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
39255 However, there are still some differences of two ends in two processes:
39256
39257 @enumerate
39258 @item
39259 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
39260 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
39261 @item
39262 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
39263 GDBserver is compiled with one, and in-process agent is compiled with
39264 the other one.
39265 @end enumerate
39266
39267 Here are the IPA Protocol Objects:
39268
39269 @enumerate
39270 @item
39271 agent expression object. It represents an agent expression
39272 (@pxref{Agent Expressions}).
39273 @anchor{agent expression object}
39274 @item
39275 tracepoint action object. It represents a tracepoint action
39276 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
39277 memory, static trace data and to evaluate expression.
39278 @anchor{tracepoint action object}
39279 @item
39280 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
39281 @anchor{tracepoint object}
39282
39283 @end enumerate
39284
39285 The following table describes important attributes of each IPA protocol
39286 object:
39287
39288 @multitable @columnfractions .30 .20 .50
39289 @headitem Name @tab Size @tab Description
39290 @item @emph{agent expression object} @tab @tab
39291 @item length @tab 4 @tab length of bytes code
39292 @item byte code @tab @var{length} @tab contents of byte code
39293 @item @emph{tracepoint action for collecting memory} @tab @tab
39294 @item 'M' @tab 1 @tab type of tracepoint action
39295 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
39296 address of the lowest byte to collect, otherwise @var{addr} is the offset
39297 of @var{basereg} for memory collecting.
39298 @item len @tab 8 @tab length of memory for collecting
39299 @item basereg @tab 4 @tab the register number containing the starting
39300 memory address for collecting.
39301 @item @emph{tracepoint action for collecting registers} @tab @tab
39302 @item 'R' @tab 1 @tab type of tracepoint action
39303 @item @emph{tracepoint action for collecting static trace data} @tab @tab
39304 @item 'L' @tab 1 @tab type of tracepoint action
39305 @item @emph{tracepoint action for expression evaluation} @tab @tab
39306 @item 'X' @tab 1 @tab type of tracepoint action
39307 @item agent expression @tab length of @tab @ref{agent expression object}
39308 @item @emph{tracepoint object} @tab @tab
39309 @item number @tab 4 @tab number of tracepoint
39310 @item address @tab 8 @tab address of tracepoint inserted on
39311 @item type @tab 4 @tab type of tracepoint
39312 @item enabled @tab 1 @tab enable or disable of tracepoint
39313 @item step_count @tab 8 @tab step
39314 @item pass_count @tab 8 @tab pass
39315 @item numactions @tab 4 @tab number of tracepoint actions
39316 @item hit count @tab 8 @tab hit count
39317 @item trace frame usage @tab 8 @tab trace frame usage
39318 @item compiled_cond @tab 8 @tab compiled condition
39319 @item orig_size @tab 8 @tab orig size
39320 @item condition @tab 4 if condition is NULL otherwise length of
39321 @ref{agent expression object}
39322 @tab zero if condition is NULL, otherwise is
39323 @ref{agent expression object}
39324 @item actions @tab variable
39325 @tab numactions number of @ref{tracepoint action object}
39326 @end multitable
39327
39328 @node IPA Protocol Commands
39329 @subsection IPA Protocol Commands
39330 @cindex ipa protocol commands
39331
39332 The spaces in each command are delimiters to ease reading this commands
39333 specification. They don't exist in real commands.
39334
39335 @table @samp
39336
39337 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
39338 Installs a new fast tracepoint described by @var{tracepoint_object}
39339 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
39340 head of @dfn{jumppad}, which is used to jump to data collection routine
39341 in IPA finally.
39342
39343 Replies:
39344 @table @samp
39345 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
39346 @var{target_address} is address of tracepoint in the inferior.
39347 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
39348 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
39349 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
39350 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
39351 @item E @var{NN}
39352 for an error
39353
39354 @end table
39355
39356 @item close
39357 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
39358 is about to kill inferiors.
39359
39360 @item qTfSTM
39361 @xref{qTfSTM}.
39362 @item qTsSTM
39363 @xref{qTsSTM}.
39364 @item qTSTMat
39365 @xref{qTSTMat}.
39366 @item probe_marker_at:@var{address}
39367 Asks in-process agent to probe the marker at @var{address}.
39368
39369 Replies:
39370 @table @samp
39371 @item E @var{NN}
39372 for an error
39373 @end table
39374 @item unprobe_marker_at:@var{address}
39375 Asks in-process agent to unprobe the marker at @var{address}.
39376 @end table
39377
39378 @node GDB Bugs
39379 @chapter Reporting Bugs in @value{GDBN}
39380 @cindex bugs in @value{GDBN}
39381 @cindex reporting bugs in @value{GDBN}
39382
39383 Your bug reports play an essential role in making @value{GDBN} reliable.
39384
39385 Reporting a bug may help you by bringing a solution to your problem, or it
39386 may not. But in any case the principal function of a bug report is to help
39387 the entire community by making the next version of @value{GDBN} work better. Bug
39388 reports are your contribution to the maintenance of @value{GDBN}.
39389
39390 In order for a bug report to serve its purpose, you must include the
39391 information that enables us to fix the bug.
39392
39393 @menu
39394 * Bug Criteria:: Have you found a bug?
39395 * Bug Reporting:: How to report bugs
39396 @end menu
39397
39398 @node Bug Criteria
39399 @section Have You Found a Bug?
39400 @cindex bug criteria
39401
39402 If you are not sure whether you have found a bug, here are some guidelines:
39403
39404 @itemize @bullet
39405 @cindex fatal signal
39406 @cindex debugger crash
39407 @cindex crash of debugger
39408 @item
39409 If the debugger gets a fatal signal, for any input whatever, that is a
39410 @value{GDBN} bug. Reliable debuggers never crash.
39411
39412 @cindex error on valid input
39413 @item
39414 If @value{GDBN} produces an error message for valid input, that is a
39415 bug. (Note that if you're cross debugging, the problem may also be
39416 somewhere in the connection to the target.)
39417
39418 @cindex invalid input
39419 @item
39420 If @value{GDBN} does not produce an error message for invalid input,
39421 that is a bug. However, you should note that your idea of
39422 ``invalid input'' might be our idea of ``an extension'' or ``support
39423 for traditional practice''.
39424
39425 @item
39426 If you are an experienced user of debugging tools, your suggestions
39427 for improvement of @value{GDBN} are welcome in any case.
39428 @end itemize
39429
39430 @node Bug Reporting
39431 @section How to Report Bugs
39432 @cindex bug reports
39433 @cindex @value{GDBN} bugs, reporting
39434
39435 A number of companies and individuals offer support for @sc{gnu} products.
39436 If you obtained @value{GDBN} from a support organization, we recommend you
39437 contact that organization first.
39438
39439 You can find contact information for many support companies and
39440 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
39441 distribution.
39442 @c should add a web page ref...
39443
39444 @ifset BUGURL
39445 @ifset BUGURL_DEFAULT
39446 In any event, we also recommend that you submit bug reports for
39447 @value{GDBN}. The preferred method is to submit them directly using
39448 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
39449 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
39450 be used.
39451
39452 @strong{Do not send bug reports to @samp{info-gdb}, or to
39453 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
39454 not want to receive bug reports. Those that do have arranged to receive
39455 @samp{bug-gdb}.
39456
39457 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
39458 serves as a repeater. The mailing list and the newsgroup carry exactly
39459 the same messages. Often people think of posting bug reports to the
39460 newsgroup instead of mailing them. This appears to work, but it has one
39461 problem which can be crucial: a newsgroup posting often lacks a mail
39462 path back to the sender. Thus, if we need to ask for more information,
39463 we may be unable to reach you. For this reason, it is better to send
39464 bug reports to the mailing list.
39465 @end ifset
39466 @ifclear BUGURL_DEFAULT
39467 In any event, we also recommend that you submit bug reports for
39468 @value{GDBN} to @value{BUGURL}.
39469 @end ifclear
39470 @end ifset
39471
39472 The fundamental principle of reporting bugs usefully is this:
39473 @strong{report all the facts}. If you are not sure whether to state a
39474 fact or leave it out, state it!
39475
39476 Often people omit facts because they think they know what causes the
39477 problem and assume that some details do not matter. Thus, you might
39478 assume that the name of the variable you use in an example does not matter.
39479 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
39480 stray memory reference which happens to fetch from the location where that
39481 name is stored in memory; perhaps, if the name were different, the contents
39482 of that location would fool the debugger into doing the right thing despite
39483 the bug. Play it safe and give a specific, complete example. That is the
39484 easiest thing for you to do, and the most helpful.
39485
39486 Keep in mind that the purpose of a bug report is to enable us to fix the
39487 bug. It may be that the bug has been reported previously, but neither
39488 you nor we can know that unless your bug report is complete and
39489 self-contained.
39490
39491 Sometimes people give a few sketchy facts and ask, ``Does this ring a
39492 bell?'' Those bug reports are useless, and we urge everyone to
39493 @emph{refuse to respond to them} except to chide the sender to report
39494 bugs properly.
39495
39496 To enable us to fix the bug, you should include all these things:
39497
39498 @itemize @bullet
39499 @item
39500 The version of @value{GDBN}. @value{GDBN} announces it if you start
39501 with no arguments; you can also print it at any time using @code{show
39502 version}.
39503
39504 Without this, we will not know whether there is any point in looking for
39505 the bug in the current version of @value{GDBN}.
39506
39507 @item
39508 The type of machine you are using, and the operating system name and
39509 version number.
39510
39511 @item
39512 The details of the @value{GDBN} build-time configuration.
39513 @value{GDBN} shows these details if you invoke it with the
39514 @option{--configuration} command-line option, or if you type
39515 @code{show configuration} at @value{GDBN}'s prompt.
39516
39517 @item
39518 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
39519 ``@value{GCC}--2.8.1''.
39520
39521 @item
39522 What compiler (and its version) was used to compile the program you are
39523 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
39524 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
39525 to get this information; for other compilers, see the documentation for
39526 those compilers.
39527
39528 @item
39529 The command arguments you gave the compiler to compile your example and
39530 observe the bug. For example, did you use @samp{-O}? To guarantee
39531 you will not omit something important, list them all. A copy of the
39532 Makefile (or the output from make) is sufficient.
39533
39534 If we were to try to guess the arguments, we would probably guess wrong
39535 and then we might not encounter the bug.
39536
39537 @item
39538 A complete input script, and all necessary source files, that will
39539 reproduce the bug.
39540
39541 @item
39542 A description of what behavior you observe that you believe is
39543 incorrect. For example, ``It gets a fatal signal.''
39544
39545 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
39546 will certainly notice it. But if the bug is incorrect output, we might
39547 not notice unless it is glaringly wrong. You might as well not give us
39548 a chance to make a mistake.
39549
39550 Even if the problem you experience is a fatal signal, you should still
39551 say so explicitly. Suppose something strange is going on, such as, your
39552 copy of @value{GDBN} is out of synch, or you have encountered a bug in
39553 the C library on your system. (This has happened!) Your copy might
39554 crash and ours would not. If you told us to expect a crash, then when
39555 ours fails to crash, we would know that the bug was not happening for
39556 us. If you had not told us to expect a crash, then we would not be able
39557 to draw any conclusion from our observations.
39558
39559 @pindex script
39560 @cindex recording a session script
39561 To collect all this information, you can use a session recording program
39562 such as @command{script}, which is available on many Unix systems.
39563 Just run your @value{GDBN} session inside @command{script} and then
39564 include the @file{typescript} file with your bug report.
39565
39566 Another way to record a @value{GDBN} session is to run @value{GDBN}
39567 inside Emacs and then save the entire buffer to a file.
39568
39569 @item
39570 If you wish to suggest changes to the @value{GDBN} source, send us context
39571 diffs. If you even discuss something in the @value{GDBN} source, refer to
39572 it by context, not by line number.
39573
39574 The line numbers in our development sources will not match those in your
39575 sources. Your line numbers would convey no useful information to us.
39576
39577 @end itemize
39578
39579 Here are some things that are not necessary:
39580
39581 @itemize @bullet
39582 @item
39583 A description of the envelope of the bug.
39584
39585 Often people who encounter a bug spend a lot of time investigating
39586 which changes to the input file will make the bug go away and which
39587 changes will not affect it.
39588
39589 This is often time consuming and not very useful, because the way we
39590 will find the bug is by running a single example under the debugger
39591 with breakpoints, not by pure deduction from a series of examples.
39592 We recommend that you save your time for something else.
39593
39594 Of course, if you can find a simpler example to report @emph{instead}
39595 of the original one, that is a convenience for us. Errors in the
39596 output will be easier to spot, running under the debugger will take
39597 less time, and so on.
39598
39599 However, simplification is not vital; if you do not want to do this,
39600 report the bug anyway and send us the entire test case you used.
39601
39602 @item
39603 A patch for the bug.
39604
39605 A patch for the bug does help us if it is a good one. But do not omit
39606 the necessary information, such as the test case, on the assumption that
39607 a patch is all we need. We might see problems with your patch and decide
39608 to fix the problem another way, or we might not understand it at all.
39609
39610 Sometimes with a program as complicated as @value{GDBN} it is very hard to
39611 construct an example that will make the program follow a certain path
39612 through the code. If you do not send us the example, we will not be able
39613 to construct one, so we will not be able to verify that the bug is fixed.
39614
39615 And if we cannot understand what bug you are trying to fix, or why your
39616 patch should be an improvement, we will not install it. A test case will
39617 help us to understand.
39618
39619 @item
39620 A guess about what the bug is or what it depends on.
39621
39622 Such guesses are usually wrong. Even we cannot guess right about such
39623 things without first using the debugger to find the facts.
39624 @end itemize
39625
39626 @c The readline documentation is distributed with the readline code
39627 @c and consists of the two following files:
39628 @c rluser.texi
39629 @c hsuser.texi
39630 @c Use -I with makeinfo to point to the appropriate directory,
39631 @c environment var TEXINPUTS with TeX.
39632 @ifclear SYSTEM_READLINE
39633 @include rluser.texi
39634 @include hsuser.texi
39635 @end ifclear
39636
39637 @node In Memoriam
39638 @appendix In Memoriam
39639
39640 The @value{GDBN} project mourns the loss of the following long-time
39641 contributors:
39642
39643 @table @code
39644 @item Fred Fish
39645 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
39646 to Free Software in general. Outside of @value{GDBN}, he was known in
39647 the Amiga world for his series of Fish Disks, and the GeekGadget project.
39648
39649 @item Michael Snyder
39650 Michael was one of the Global Maintainers of the @value{GDBN} project,
39651 with contributions recorded as early as 1996, until 2011. In addition
39652 to his day to day participation, he was a large driving force behind
39653 adding Reverse Debugging to @value{GDBN}.
39654 @end table
39655
39656 Beyond their technical contributions to the project, they were also
39657 enjoyable members of the Free Software Community. We will miss them.
39658
39659 @node Formatting Documentation
39660 @appendix Formatting Documentation
39661
39662 @cindex @value{GDBN} reference card
39663 @cindex reference card
39664 The @value{GDBN} 4 release includes an already-formatted reference card, ready
39665 for printing with PostScript or Ghostscript, in the @file{gdb}
39666 subdirectory of the main source directory@footnote{In
39667 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
39668 release.}. If you can use PostScript or Ghostscript with your printer,
39669 you can print the reference card immediately with @file{refcard.ps}.
39670
39671 The release also includes the source for the reference card. You
39672 can format it, using @TeX{}, by typing:
39673
39674 @smallexample
39675 make refcard.dvi
39676 @end smallexample
39677
39678 The @value{GDBN} reference card is designed to print in @dfn{landscape}
39679 mode on US ``letter'' size paper;
39680 that is, on a sheet 11 inches wide by 8.5 inches
39681 high. You will need to specify this form of printing as an option to
39682 your @sc{dvi} output program.
39683
39684 @cindex documentation
39685
39686 All the documentation for @value{GDBN} comes as part of the machine-readable
39687 distribution. The documentation is written in Texinfo format, which is
39688 a documentation system that uses a single source file to produce both
39689 on-line information and a printed manual. You can use one of the Info
39690 formatting commands to create the on-line version of the documentation
39691 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
39692
39693 @value{GDBN} includes an already formatted copy of the on-line Info
39694 version of this manual in the @file{gdb} subdirectory. The main Info
39695 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
39696 subordinate files matching @samp{gdb.info*} in the same directory. If
39697 necessary, you can print out these files, or read them with any editor;
39698 but they are easier to read using the @code{info} subsystem in @sc{gnu}
39699 Emacs or the standalone @code{info} program, available as part of the
39700 @sc{gnu} Texinfo distribution.
39701
39702 If you want to format these Info files yourself, you need one of the
39703 Info formatting programs, such as @code{texinfo-format-buffer} or
39704 @code{makeinfo}.
39705
39706 If you have @code{makeinfo} installed, and are in the top level
39707 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
39708 version @value{GDBVN}), you can make the Info file by typing:
39709
39710 @smallexample
39711 cd gdb
39712 make gdb.info
39713 @end smallexample
39714
39715 If you want to typeset and print copies of this manual, you need @TeX{},
39716 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
39717 Texinfo definitions file.
39718
39719 @TeX{} is a typesetting program; it does not print files directly, but
39720 produces output files called @sc{dvi} files. To print a typeset
39721 document, you need a program to print @sc{dvi} files. If your system
39722 has @TeX{} installed, chances are it has such a program. The precise
39723 command to use depends on your system; @kbd{lpr -d} is common; another
39724 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
39725 require a file name without any extension or a @samp{.dvi} extension.
39726
39727 @TeX{} also requires a macro definitions file called
39728 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
39729 written in Texinfo format. On its own, @TeX{} cannot either read or
39730 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
39731 and is located in the @file{gdb-@var{version-number}/texinfo}
39732 directory.
39733
39734 If you have @TeX{} and a @sc{dvi} printer program installed, you can
39735 typeset and print this manual. First switch to the @file{gdb}
39736 subdirectory of the main source directory (for example, to
39737 @file{gdb-@value{GDBVN}/gdb}) and type:
39738
39739 @smallexample
39740 make gdb.dvi
39741 @end smallexample
39742
39743 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
39744
39745 @node Installing GDB
39746 @appendix Installing @value{GDBN}
39747 @cindex installation
39748
39749 @menu
39750 * Requirements:: Requirements for building @value{GDBN}
39751 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
39752 * Separate Objdir:: Compiling @value{GDBN} in another directory
39753 * Config Names:: Specifying names for hosts and targets
39754 * Configure Options:: Summary of options for configure
39755 * System-wide configuration:: Having a system-wide init file
39756 @end menu
39757
39758 @node Requirements
39759 @section Requirements for Building @value{GDBN}
39760 @cindex building @value{GDBN}, requirements for
39761
39762 Building @value{GDBN} requires various tools and packages to be available.
39763 Other packages will be used only if they are found.
39764
39765 @heading Tools/Packages Necessary for Building @value{GDBN}
39766 @table @asis
39767 @item C@t{++}11 compiler
39768 @value{GDBN} is written in C@t{++}11. It should be buildable with any
39769 recent C@t{++}11 compiler, e.g.@: GCC.
39770
39771 @item GNU make
39772 @value{GDBN}'s build system relies on features only found in the GNU
39773 make program. Other variants of @code{make} will not work.
39774
39775 @item GMP (The GNU Multiple Precision Arithmetic Library)
39776 @value{GDBN} now uses GMP to perform some of its arithmetics.
39777 This library may be included with your operating system distribution;
39778 if it is not, you can get the latest version from
39779 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
39780 you can use the @option{--with-gmp} option or options
39781 @option{--with-gmp-include} and @option{--with-gmp-lib} to specify
39782 its location.
39783
39784 @end table
39785
39786 @heading Tools/Packages Optional for Building @value{GDBN}
39787 @table @asis
39788 @item Expat
39789 @anchor{Expat}
39790 @value{GDBN} can use the Expat XML parsing library. This library may be
39791 included with your operating system distribution; if it is not, you
39792 can get the latest version from @url{http://expat.sourceforge.net}.
39793 The @file{configure} script will search for this library in several
39794 standard locations; if it is installed in an unusual path, you can
39795 use the @option{--with-libexpat-prefix} option to specify its location.
39796
39797 Expat is used for:
39798
39799 @itemize @bullet
39800 @item
39801 Remote protocol memory maps (@pxref{Memory Map Format})
39802 @item
39803 Target descriptions (@pxref{Target Descriptions})
39804 @item
39805 Remote shared library lists (@xref{Library List Format},
39806 or alternatively @pxref{Library List Format for SVR4 Targets})
39807 @item
39808 MS-Windows shared libraries (@pxref{Shared Libraries})
39809 @item
39810 Traceframe info (@pxref{Traceframe Info Format})
39811 @item
39812 Branch trace (@pxref{Branch Trace Format},
39813 @pxref{Branch Trace Configuration Format})
39814 @end itemize
39815
39816 @item Guile
39817 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
39818 default, @value{GDBN} will be compiled if the Guile libraries are
39819 installed and are found by @file{configure}. You can use the
39820 @code{--with-guile} option to request Guile, and pass either the Guile
39821 version number or the file name of the relevant @code{pkg-config}
39822 program to choose a particular version of Guile.
39823
39824 @item iconv
39825 @value{GDBN}'s features related to character sets (@pxref{Character
39826 Sets}) require a functioning @code{iconv} implementation. If you are
39827 on a GNU system, then this is provided by the GNU C Library. Some
39828 other systems also provide a working @code{iconv}.
39829
39830 If @value{GDBN} is using the @code{iconv} program which is installed
39831 in a non-standard place, you will need to tell @value{GDBN} where to
39832 find it. This is done with @option{--with-iconv-bin} which specifies
39833 the directory that contains the @code{iconv} program. This program is
39834 run in order to make a list of the available character sets.
39835
39836 On systems without @code{iconv}, you can install GNU Libiconv. If
39837 Libiconv is installed in a standard place, @value{GDBN} will
39838 automatically use it if it is needed. If you have previously
39839 installed Libiconv in a non-standard place, you can use the
39840 @option{--with-libiconv-prefix} option to @file{configure}.
39841
39842 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
39843 arrange to build Libiconv if a directory named @file{libiconv} appears
39844 in the top-most source directory. If Libiconv is built this way, and
39845 if the operating system does not provide a suitable @code{iconv}
39846 implementation, then the just-built library will automatically be used
39847 by @value{GDBN}. One easy way to set this up is to download GNU
39848 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
39849 source tree, and then rename the directory holding the Libiconv source
39850 code to @samp{libiconv}.
39851
39852 @item lzma
39853 @value{GDBN} can support debugging sections that are compressed with
39854 the LZMA library. @xref{MiniDebugInfo}. If this library is not
39855 included with your operating system, you can find it in the xz package
39856 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
39857 the usual place, then the @file{configure} script will use it
39858 automatically. If it is installed in an unusual path, you can use the
39859 @option{--with-liblzma-prefix} option to specify its location.
39860
39861 @item MPFR
39862 @anchor{MPFR}
39863 @value{GDBN} now uses the GNU MPFR multiple-precision floating-point
39864 library. This library may be included with your operating system
39865 distribution; if it is not, you can get the latest version from
39866 @url{http://www.mpfr.org}. The @file{configure} script will search
39867 for this library in several standard locations; if it is installed
39868 in an unusual path, you can use the @option{--with-mpfr} option or options
39869 @option{--with-mpfr-include} and @option{--with-mpfr-lib} to specify
39870 its location.
39871
39872 GNU MPFR is used to emulate target floating-point arithmetic during
39873 expression evaluation when the target uses different floating-point
39874 formats than the host.
39875
39876 @item Python
39877 @value{GDBN} can be scripted using Python language. @xref{Python}.
39878 By default, @value{GDBN} will be compiled if the Python libraries are
39879 installed and are found by @file{configure}. You can use the
39880 @code{--with-python} option to request Python, and pass either the
39881 file name of the relevant @code{python} executable, or the name of the
39882 directory in which Python is installed, to choose a particular
39883 installation of Python.
39884
39885 @item zlib
39886 @cindex compressed debug sections
39887 @value{GDBN} will use the @samp{zlib} library, if available, to read
39888 compressed debug sections. Some linkers, such as GNU gold, are capable
39889 of producing binaries with compressed debug sections. If @value{GDBN}
39890 is compiled with @samp{zlib}, it will be able to read the debug
39891 information in such binaries.
39892
39893 The @samp{zlib} library is likely included with your operating system
39894 distribution; if it is not, you can get the latest version from
39895 @url{http://zlib.net}.
39896 @end table
39897
39898 @node Running Configure
39899 @section Invoking the @value{GDBN} @file{configure} Script
39900 @cindex configuring @value{GDBN}
39901 @value{GDBN} comes with a @file{configure} script that automates the process
39902 of preparing @value{GDBN} for installation; you can then use @code{make} to
39903 build the @code{gdb} program.
39904 @iftex
39905 @c irrelevant in info file; it's as current as the code it lives with.
39906 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
39907 look at the @file{README} file in the sources; we may have improved the
39908 installation procedures since publishing this manual.}
39909 @end iftex
39910
39911 The @value{GDBN} distribution includes all the source code you need for
39912 @value{GDBN} in a single directory, whose name is usually composed by
39913 appending the version number to @samp{gdb}.
39914
39915 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
39916 @file{gdb-@value{GDBVN}} directory. That directory contains:
39917
39918 @table @code
39919 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
39920 script for configuring @value{GDBN} and all its supporting libraries
39921
39922 @item gdb-@value{GDBVN}/gdb
39923 the source specific to @value{GDBN} itself
39924
39925 @item gdb-@value{GDBVN}/bfd
39926 source for the Binary File Descriptor library
39927
39928 @item gdb-@value{GDBVN}/include
39929 @sc{gnu} include files
39930
39931 @item gdb-@value{GDBVN}/libiberty
39932 source for the @samp{-liberty} free software library
39933
39934 @item gdb-@value{GDBVN}/opcodes
39935 source for the library of opcode tables and disassemblers
39936
39937 @item gdb-@value{GDBVN}/readline
39938 source for the @sc{gnu} command-line interface
39939 @end table
39940
39941 There may be other subdirectories as well.
39942
39943 The simplest way to configure and build @value{GDBN} is to run @file{configure}
39944 from the @file{gdb-@var{version-number}} source directory, which in
39945 this example is the @file{gdb-@value{GDBVN}} directory.
39946
39947 First switch to the @file{gdb-@var{version-number}} source directory
39948 if you are not already in it; then run @file{configure}. Pass the
39949 identifier for the platform on which @value{GDBN} will run as an
39950 argument.
39951
39952 For example:
39953
39954 @smallexample
39955 cd gdb-@value{GDBVN}
39956 ./configure
39957 make
39958 @end smallexample
39959
39960 Running @samp{configure} and then running @code{make} builds the
39961 included supporting libraries, then @code{gdb} itself. The configured
39962 source files, and the binaries, are left in the corresponding source
39963 directories.
39964
39965 @need 750
39966 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
39967 system does not recognize this automatically when you run a different
39968 shell, you may need to run @code{sh} on it explicitly:
39969
39970 @smallexample
39971 sh configure
39972 @end smallexample
39973
39974 You should run the @file{configure} script from the top directory in the
39975 source tree, the @file{gdb-@var{version-number}} directory. If you run
39976 @file{configure} from one of the subdirectories, you will configure only
39977 that subdirectory. That is usually not what you want. In particular,
39978 if you run the first @file{configure} from the @file{gdb} subdirectory
39979 of the @file{gdb-@var{version-number}} directory, you will omit the
39980 configuration of @file{bfd}, @file{readline}, and other sibling
39981 directories of the @file{gdb} subdirectory. This leads to build errors
39982 about missing include files such as @file{bfd/bfd.h}.
39983
39984 You can install @code{@value{GDBN}} anywhere. The best way to do this
39985 is to pass the @code{--prefix} option to @code{configure}, and then
39986 install it with @code{make install}.
39987
39988 @node Separate Objdir
39989 @section Compiling @value{GDBN} in Another Directory
39990
39991 If you want to run @value{GDBN} versions for several host or target machines,
39992 you need a different @code{gdb} compiled for each combination of
39993 host and target. @file{configure} is designed to make this easy by
39994 allowing you to generate each configuration in a separate subdirectory,
39995 rather than in the source directory. If your @code{make} program
39996 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
39997 @code{make} in each of these directories builds the @code{gdb}
39998 program specified there.
39999
40000 To build @code{gdb} in a separate directory, run @file{configure}
40001 with the @samp{--srcdir} option to specify where to find the source.
40002 (You also need to specify a path to find @file{configure}
40003 itself from your working directory. If the path to @file{configure}
40004 would be the same as the argument to @samp{--srcdir}, you can leave out
40005 the @samp{--srcdir} option; it is assumed.)
40006
40007 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
40008 separate directory for a Sun 4 like this:
40009
40010 @smallexample
40011 @group
40012 cd gdb-@value{GDBVN}
40013 mkdir ../gdb-sun4
40014 cd ../gdb-sun4
40015 ../gdb-@value{GDBVN}/configure
40016 make
40017 @end group
40018 @end smallexample
40019
40020 When @file{configure} builds a configuration using a remote source
40021 directory, it creates a tree for the binaries with the same structure
40022 (and using the same names) as the tree under the source directory. In
40023 the example, you'd find the Sun 4 library @file{libiberty.a} in the
40024 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
40025 @file{gdb-sun4/gdb}.
40026
40027 Make sure that your path to the @file{configure} script has just one
40028 instance of @file{gdb} in it. If your path to @file{configure} looks
40029 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
40030 one subdirectory of @value{GDBN}, not the whole package. This leads to
40031 build errors about missing include files such as @file{bfd/bfd.h}.
40032
40033 One popular reason to build several @value{GDBN} configurations in separate
40034 directories is to configure @value{GDBN} for cross-compiling (where
40035 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
40036 programs that run on another machine---the @dfn{target}).
40037 You specify a cross-debugging target by
40038 giving the @samp{--target=@var{target}} option to @file{configure}.
40039
40040 When you run @code{make} to build a program or library, you must run
40041 it in a configured directory---whatever directory you were in when you
40042 called @file{configure} (or one of its subdirectories).
40043
40044 The @code{Makefile} that @file{configure} generates in each source
40045 directory also runs recursively. If you type @code{make} in a source
40046 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
40047 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
40048 will build all the required libraries, and then build GDB.
40049
40050 When you have multiple hosts or targets configured in separate
40051 directories, you can run @code{make} on them in parallel (for example,
40052 if they are NFS-mounted on each of the hosts); they will not interfere
40053 with each other.
40054
40055 @node Config Names
40056 @section Specifying Names for Hosts and Targets
40057
40058 The specifications used for hosts and targets in the @file{configure}
40059 script are based on a three-part naming scheme, but some short predefined
40060 aliases are also supported. The full naming scheme encodes three pieces
40061 of information in the following pattern:
40062
40063 @smallexample
40064 @var{architecture}-@var{vendor}-@var{os}
40065 @end smallexample
40066
40067 For example, you can use the alias @code{sun4} as a @var{host} argument,
40068 or as the value for @var{target} in a @code{--target=@var{target}}
40069 option. The equivalent full name is @samp{sparc-sun-sunos4}.
40070
40071 The @file{configure} script accompanying @value{GDBN} does not provide
40072 any query facility to list all supported host and target names or
40073 aliases. @file{configure} calls the Bourne shell script
40074 @code{config.sub} to map abbreviations to full names; you can read the
40075 script, if you wish, or you can use it to test your guesses on
40076 abbreviations---for example:
40077
40078 @smallexample
40079 % sh config.sub i386-linux
40080 i386-pc-linux-gnu
40081 % sh config.sub alpha-linux
40082 alpha-unknown-linux-gnu
40083 % sh config.sub hp9k700
40084 hppa1.1-hp-hpux
40085 % sh config.sub sun4
40086 sparc-sun-sunos4.1.1
40087 % sh config.sub sun3
40088 m68k-sun-sunos4.1.1
40089 % sh config.sub i986v
40090 Invalid configuration `i986v': machine `i986v' not recognized
40091 @end smallexample
40092
40093 @noindent
40094 @code{config.sub} is also distributed in the @value{GDBN} source
40095 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
40096
40097 @node Configure Options
40098 @section @file{configure} Options
40099
40100 Here is a summary of the @file{configure} options and arguments that
40101 are most often useful for building @value{GDBN}. @file{configure}
40102 also has several other options not listed here. @xref{Running
40103 configure Scripts,,,autoconf}, for a full
40104 explanation of @file{configure}.
40105
40106 @smallexample
40107 configure @r{[}--help@r{]}
40108 @r{[}--prefix=@var{dir}@r{]}
40109 @r{[}--exec-prefix=@var{dir}@r{]}
40110 @r{[}--srcdir=@var{dirname}@r{]}
40111 @r{[}--target=@var{target}@r{]}
40112 @end smallexample
40113
40114 @noindent
40115 You may introduce options with a single @samp{-} rather than
40116 @samp{--} if you prefer; but you may abbreviate option names if you use
40117 @samp{--}.
40118
40119 @table @code
40120 @item --help
40121 Display a quick summary of how to invoke @file{configure}.
40122
40123 @item --prefix=@var{dir}
40124 Configure the source to install programs and files under directory
40125 @file{@var{dir}}.
40126
40127 @item --exec-prefix=@var{dir}
40128 Configure the source to install programs under directory
40129 @file{@var{dir}}.
40130
40131 @c avoid splitting the warning from the explanation:
40132 @need 2000
40133 @item --srcdir=@var{dirname}
40134 Use this option to make configurations in directories separate from the
40135 @value{GDBN} source directories. Among other things, you can use this to
40136 build (or maintain) several configurations simultaneously, in separate
40137 directories. @file{configure} writes configuration-specific files in
40138 the current directory, but arranges for them to use the source in the
40139 directory @var{dirname}. @file{configure} creates directories under
40140 the working directory in parallel to the source directories below
40141 @var{dirname}.
40142
40143 @item --target=@var{target}
40144 Configure @value{GDBN} for cross-debugging programs running on the specified
40145 @var{target}. Without this option, @value{GDBN} is configured to debug
40146 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
40147
40148 There is no convenient way to generate a list of all available
40149 targets. Also see the @code{--enable-targets} option, below.
40150 @end table
40151
40152 There are many other options that are specific to @value{GDBN}. This
40153 lists just the most common ones; there are some very specialized
40154 options not described here.
40155
40156 @table @code
40157 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
40158 @itemx --enable-targets=all
40159 Configure @value{GDBN} for cross-debugging programs running on the
40160 specified list of targets. The special value @samp{all} configures
40161 @value{GDBN} for debugging programs running on any target it supports.
40162
40163 @item --with-gdb-datadir=@var{path}
40164 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
40165 here for certain supporting files or scripts. This defaults to the
40166 @file{gdb} subdirectory of @samp{datadir} (which can be set using
40167 @code{--datadir}).
40168
40169 @item --with-relocated-sources=@var{dir}
40170 Sets up the default source path substitution rule so that directory
40171 names recorded in debug information will be automatically adjusted for
40172 any directory under @var{dir}. @var{dir} should be a subdirectory of
40173 @value{GDBN}'s configured prefix, the one mentioned in the
40174 @code{--prefix} or @code{--exec-prefix} options to configure. This
40175 option is useful if GDB is supposed to be moved to a different place
40176 after it is built.
40177
40178 @item --enable-64-bit-bfd
40179 Enable 64-bit support in BFD on 32-bit hosts.
40180
40181 @item --disable-gdbmi
40182 Build @value{GDBN} without the GDB/MI machine interface
40183 (@pxref{GDB/MI}).
40184
40185 @item --enable-tui
40186 Build @value{GDBN} with the text-mode full-screen user interface
40187 (TUI). Requires a curses library (ncurses and cursesX are also
40188 supported).
40189
40190 @item --with-curses
40191 Use the curses library instead of the termcap library, for text-mode
40192 terminal operations.
40193
40194 @item --with-debuginfod
40195 Build @value{GDBN} with @file{libdebuginfod}, the @code{debuginfod} client
40196 library. Used to automatically fetch ELF, DWARF and source files from
40197 @code{debuginfod} servers using build IDs associated with any missing
40198 files. Enabled by default if @file{libdebuginfod} is installed and found
40199 at configure time. For more information regarding @code{debuginfod} see
40200 @ref{Debuginfod}.
40201
40202 @item --with-libunwind-ia64
40203 Use the libunwind library for unwinding function call stack on ia64
40204 target platforms. See http://www.nongnu.org/libunwind/index.html for
40205 details.
40206
40207 @item --with-system-readline
40208 Use the readline library installed on the host, rather than the
40209 library supplied as part of @value{GDBN}. Readline 7 or newer is
40210 required; this is enforced by the build system.
40211
40212 @item --with-system-zlib
40213 Use the zlib library installed on the host, rather than the library
40214 supplied as part of @value{GDBN}.
40215
40216 @item --with-expat
40217 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
40218 default if libexpat is installed and found at configure time.) This
40219 library is used to read XML files supplied with @value{GDBN}. If it
40220 is unavailable, some features, such as remote protocol memory maps,
40221 target descriptions, and shared library lists, that are based on XML
40222 files, will not be available in @value{GDBN}. If your host does not
40223 have libexpat installed, you can get the latest version from
40224 `http://expat.sourceforge.net'.
40225
40226 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
40227
40228 Build @value{GDBN} with GNU libiconv, a character set encoding
40229 conversion library. This is not done by default, as on GNU systems
40230 the @code{iconv} that is built in to the C library is sufficient. If
40231 your host does not have a working @code{iconv}, you can get the latest
40232 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
40233
40234 @value{GDBN}'s build system also supports building GNU libiconv as
40235 part of the overall build. @xref{Requirements}.
40236
40237 @item --with-lzma
40238 Build @value{GDBN} with LZMA, a compression library. (Done by default
40239 if liblzma is installed and found at configure time.) LZMA is used by
40240 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
40241 platforms using the ELF object file format. If your host does not
40242 have liblzma installed, you can get the latest version from
40243 `https://tukaani.org/xz/'.
40244
40245 @item --with-mpfr
40246 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
40247 floating-point computation with correct rounding. (Done by default if
40248 GNU MPFR is installed and found at configure time.) This library is
40249 used to emulate target floating-point arithmetic during expression
40250 evaluation when the target uses different floating-point formats than
40251 the host. If GNU MPFR is not available, @value{GDBN} will fall back
40252 to using host floating-point arithmetic. If your host does not have
40253 GNU MPFR installed, you can get the latest version from
40254 `http://www.mpfr.org'.
40255
40256 @item --with-python@r{[}=@var{python}@r{]}
40257 Build @value{GDBN} with Python scripting support. (Done by default if
40258 libpython is present and found at configure time.) Python makes
40259 @value{GDBN} scripting much more powerful than the restricted CLI
40260 scripting language. If your host does not have Python installed, you
40261 can find it on `http://www.python.org/download/'. The oldest version
40262 of Python supported by GDB is 2.6. The optional argument @var{python}
40263 is used to find the Python headers and libraries. It can be either
40264 the name of a Python executable, or the name of the directory in which
40265 Python is installed.
40266
40267 @item --with-guile[=GUILE]'
40268 Build @value{GDBN} with GNU Guile scripting support. (Done by default
40269 if libguile is present and found at configure time.) If your host
40270 does not have Guile installed, you can find it at
40271 `https://www.gnu.org/software/guile/'. The optional argument GUILE
40272 can be a version number, which will cause @code{configure} to try to
40273 use that version of Guile; or the file name of a @code{pkg-config}
40274 executable, which will be queried to find the information needed to
40275 compile and link against Guile.
40276
40277 @item --without-included-regex
40278 Don't use the regex library included with @value{GDBN} (as part of the
40279 libiberty library). This is the default on hosts with version 2 of
40280 the GNU C library.
40281
40282 @item --with-sysroot=@var{dir}
40283 Use @var{dir} as the default system root directory for libraries whose
40284 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
40285 @var{dir} can be modified at run time by using the @command{set
40286 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
40287 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
40288 default system root will be automatically adjusted if and when
40289 @value{GDBN} is moved to a different location.
40290
40291 @item --with-system-gdbinit=@var{file}
40292 Configure @value{GDBN} to automatically load a system-wide init file.
40293 @var{file} should be an absolute file name. If @var{file} is in a
40294 directory under the configured prefix, and @value{GDBN} is moved to
40295 another location after being built, the location of the system-wide
40296 init file will be adjusted accordingly.
40297
40298 @item --with-system-gdbinit-dir=@var{directory}
40299 Configure @value{GDBN} to automatically load init files from a
40300 system-wide directory. @var{directory} should be an absolute directory
40301 name. If @var{directory} is in a directory under the configured
40302 prefix, and @value{GDBN} is moved to another location after being
40303 built, the location of the system-wide init directory will be
40304 adjusted accordingly.
40305
40306 @item --enable-build-warnings
40307 When building the @value{GDBN} sources, ask the compiler to warn about
40308 any code which looks even vaguely suspicious. It passes many
40309 different warning flags, depending on the exact version of the
40310 compiler you are using.
40311
40312 @item --enable-werror
40313 Treat compiler warnings as errors. It adds the @code{-Werror} flag
40314 to the compiler, which will fail the compilation if the compiler
40315 outputs any warning messages.
40316
40317 @item --enable-ubsan
40318 Enable the GCC undefined behavior sanitizer. This is disabled by
40319 default, but passing @code{--enable-ubsan=yes} or
40320 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
40321 undefined behavior sanitizer checks for C@t{++} undefined behavior.
40322 It has a performance cost, so if you are looking at @value{GDBN}'s
40323 performance, you should disable it. The undefined behavior sanitizer
40324 was first introduced in GCC 4.9.
40325 @end table
40326
40327 @node System-wide configuration
40328 @section System-wide configuration and settings
40329 @cindex system-wide init file
40330
40331 @value{GDBN} can be configured to have a system-wide init file and a
40332 system-wide init file directory; this file and files in that directory
40333 (if they have a recognized file extension) will be read and executed at
40334 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
40335
40336 Here are the corresponding configure options:
40337
40338 @table @code
40339 @item --with-system-gdbinit=@var{file}
40340 Specify that the default location of the system-wide init file is
40341 @var{file}.
40342 @item --with-system-gdbinit-dir=@var{directory}
40343 Specify that the default location of the system-wide init file directory
40344 is @var{directory}.
40345 @end table
40346
40347 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
40348 they may be subject to relocation. Two possible cases:
40349
40350 @itemize @bullet
40351 @item
40352 If the default location of this init file/directory contains @file{$prefix},
40353 it will be subject to relocation. Suppose that the configure options
40354 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
40355 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
40356 init file is looked for as @file{$install/etc/gdbinit} instead of
40357 @file{$prefix/etc/gdbinit}.
40358
40359 @item
40360 By contrast, if the default location does not contain the prefix,
40361 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
40362 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
40363 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
40364 wherever @value{GDBN} is installed.
40365 @end itemize
40366
40367 If the configured location of the system-wide init file (as given by the
40368 @option{--with-system-gdbinit} option at configure time) is in the
40369 data-directory (as specified by @option{--with-gdb-datadir} at configure
40370 time) or in one of its subdirectories, then @value{GDBN} will look for the
40371 system-wide init file in the directory specified by the
40372 @option{--data-directory} command-line option.
40373 Note that the system-wide init file is only read once, during @value{GDBN}
40374 initialization. If the data-directory is changed after @value{GDBN} has
40375 started with the @code{set data-directory} command, the file will not be
40376 reread.
40377
40378 This applies similarly to the system-wide directory specified in
40379 @option{--with-system-gdbinit-dir}.
40380
40381 Any supported scripting language can be used for these init files, as long
40382 as the file extension matches the scripting language. To be interpreted
40383 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
40384 extension.
40385
40386 @menu
40387 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
40388 @end menu
40389
40390 @node System-wide Configuration Scripts
40391 @subsection Installed System-wide Configuration Scripts
40392 @cindex system-wide configuration scripts
40393
40394 The @file{system-gdbinit} directory, located inside the data-directory
40395 (as specified by @option{--with-gdb-datadir} at configure time) contains
40396 a number of scripts which can be used as system-wide init files. To
40397 automatically source those scripts at startup, @value{GDBN} should be
40398 configured with @option{--with-system-gdbinit}. Otherwise, any user
40399 should be able to source them by hand as needed.
40400
40401 The following scripts are currently available:
40402 @itemize @bullet
40403
40404 @item @file{elinos.py}
40405 @pindex elinos.py
40406 @cindex ELinOS system-wide configuration script
40407 This script is useful when debugging a program on an ELinOS target.
40408 It takes advantage of the environment variables defined in a standard
40409 ELinOS environment in order to determine the location of the system
40410 shared libraries, and then sets the @samp{solib-absolute-prefix}
40411 and @samp{solib-search-path} variables appropriately.
40412
40413 @item @file{wrs-linux.py}
40414 @pindex wrs-linux.py
40415 @cindex Wind River Linux system-wide configuration script
40416 This script is useful when debugging a program on a target running
40417 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
40418 the host-side sysroot used by the target system.
40419
40420 @end itemize
40421
40422 @node Maintenance Commands
40423 @appendix Maintenance Commands
40424 @cindex maintenance commands
40425 @cindex internal commands
40426
40427 In addition to commands intended for @value{GDBN} users, @value{GDBN}
40428 includes a number of commands intended for @value{GDBN} developers,
40429 that are not documented elsewhere in this manual. These commands are
40430 provided here for reference. (For commands that turn on debugging
40431 messages, see @ref{Debugging Output}.)
40432
40433 @table @code
40434 @kindex maint agent
40435 @kindex maint agent-eval
40436 @item maint agent @r{[}-at @var{linespec}@r{,}@r{]} @var{expression}
40437 @itemx maint agent-eval @r{[}-at @var{linespec}@r{,}@r{]} @var{expression}
40438 Translate the given @var{expression} into remote agent bytecodes.
40439 This command is useful for debugging the Agent Expression mechanism
40440 (@pxref{Agent Expressions}). The @samp{agent} version produces an
40441 expression useful for data collection, such as by tracepoints, while
40442 @samp{maint agent-eval} produces an expression that evaluates directly
40443 to a result. For instance, a collection expression for @code{globa +
40444 globb} will include bytecodes to record four bytes of memory at each
40445 of the addresses of @code{globa} and @code{globb}, while discarding
40446 the result of the addition, while an evaluation expression will do the
40447 addition and return the sum.
40448 If @code{-at} is given, generate remote agent bytecode for all the
40449 addresses to which @var{linespec} resolves (@pxref{Linespec
40450 Locations}).
40451 If not, generate remote agent bytecode for current frame PC address.
40452
40453 @kindex maint agent-printf
40454 @item maint agent-printf @var{format},@var{expr},...
40455 Translate the given format string and list of argument expressions
40456 into remote agent bytecodes and display them as a disassembled list.
40457 This command is useful for debugging the agent version of dynamic
40458 printf (@pxref{Dynamic Printf}).
40459
40460 @kindex maint info breakpoints
40461 @item @anchor{maint info breakpoints}maint info breakpoints
40462 Using the same format as @samp{info breakpoints}, display both the
40463 breakpoints you've set explicitly, and those @value{GDBN} is using for
40464 internal purposes. Internal breakpoints are shown with negative
40465 breakpoint numbers. The type column identifies what kind of breakpoint
40466 is shown:
40467
40468 @table @code
40469 @item breakpoint
40470 Normal, explicitly set breakpoint.
40471
40472 @item watchpoint
40473 Normal, explicitly set watchpoint.
40474
40475 @item longjmp
40476 Internal breakpoint, used to handle correctly stepping through
40477 @code{longjmp} calls.
40478
40479 @item longjmp resume
40480 Internal breakpoint at the target of a @code{longjmp}.
40481
40482 @item until
40483 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
40484
40485 @item finish
40486 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
40487
40488 @item shlib events
40489 Shared library events.
40490
40491 @end table
40492
40493 @kindex maint info btrace
40494 @item maint info btrace
40495 Pint information about raw branch tracing data.
40496
40497 @kindex maint btrace packet-history
40498 @item maint btrace packet-history
40499 Print the raw branch trace packets that are used to compute the
40500 execution history for the @samp{record btrace} command. Both the
40501 information and the format in which it is printed depend on the btrace
40502 recording format.
40503
40504 @table @code
40505 @item bts
40506 For the BTS recording format, print a list of blocks of sequential
40507 code. For each block, the following information is printed:
40508
40509 @table @asis
40510 @item Block number
40511 Newer blocks have higher numbers. The oldest block has number zero.
40512 @item Lowest @samp{PC}
40513 @item Highest @samp{PC}
40514 @end table
40515
40516 @item pt
40517 For the Intel Processor Trace recording format, print a list of
40518 Intel Processor Trace packets. For each packet, the following
40519 information is printed:
40520
40521 @table @asis
40522 @item Packet number
40523 Newer packets have higher numbers. The oldest packet has number zero.
40524 @item Trace offset
40525 The packet's offset in the trace stream.
40526 @item Packet opcode and payload
40527 @end table
40528 @end table
40529
40530 @kindex maint btrace clear-packet-history
40531 @item maint btrace clear-packet-history
40532 Discards the cached packet history printed by the @samp{maint btrace
40533 packet-history} command. The history will be computed again when
40534 needed.
40535
40536 @kindex maint btrace clear
40537 @item maint btrace clear
40538 Discard the branch trace data. The data will be fetched anew and the
40539 branch trace will be recomputed when needed.
40540
40541 This implicitly truncates the branch trace to a single branch trace
40542 buffer. When updating branch trace incrementally, the branch trace
40543 available to @value{GDBN} may be bigger than a single branch trace
40544 buffer.
40545
40546 @kindex maint set btrace pt skip-pad
40547 @item maint set btrace pt skip-pad
40548 @kindex maint show btrace pt skip-pad
40549 @item maint show btrace pt skip-pad
40550 Control whether @value{GDBN} will skip PAD packets when computing the
40551 packet history.
40552
40553 @kindex maint info jit
40554 @item maint info jit
40555 Print information about JIT code objects loaded in the current inferior.
40556
40557 @anchor{maint info python-disassemblers}
40558 @kindex maint info python-disassemblers
40559 @item maint info python-disassemblers
40560 This command is defined within the @code{gdb.disassembler} Python
40561 module (@pxref{Disassembly In Python}), and will only be present after
40562 that module has been imported. To force the module to be imported do
40563 the following:
40564
40565 @smallexample
40566 (@value{GDBP}) python import gdb.disassembler
40567 @end smallexample
40568
40569 This command lists all the architectures for which a disassembler is
40570 currently registered, and the name of the disassembler. If a
40571 disassembler is registered for all architectures, then this is listed
40572 last against the @samp{GLOBAL} architecture.
40573
40574 If one of the disassemblers would be selected for the architecture of
40575 the current inferior, then this disassembler will be marked.
40576
40577 The following example shows a situation in which two disassemblers are
40578 registered, initially the @samp{i386} disassembler matches the current
40579 architecture, then the architecture is changed, now the @samp{GLOBAL}
40580 disassembler matches.
40581
40582 @smallexample
40583 @group
40584 (@value{GDBP}) show architecture
40585 The target architecture is set to "auto" (currently "i386").
40586 (@value{GDBP}) maint info python-disassemblers
40587 Architecture Disassember Name
40588 i386 Disassembler_1 (Matches current architecture)
40589 GLOBAL Disassembler_2
40590 @end group
40591 @group
40592 (@value{GDBP}) set architecture arm
40593 The target architecture is set to "arm".
40594 (@value{GDBP}) maint info python-disassemblers
40595 quit
40596 Architecture Disassember Name
40597 i386 Disassembler_1
40598 GLOBAL Disassembler_2 (Matches current architecture)
40599 @end group
40600 @end smallexample
40601
40602 @kindex set displaced-stepping
40603 @kindex show displaced-stepping
40604 @cindex displaced stepping support
40605 @cindex out-of-line single-stepping
40606 @item set displaced-stepping
40607 @itemx show displaced-stepping
40608 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
40609 if the target supports it. Displaced stepping is a way to single-step
40610 over breakpoints without removing them from the inferior, by executing
40611 an out-of-line copy of the instruction that was originally at the
40612 breakpoint location. It is also known as out-of-line single-stepping.
40613
40614 @table @code
40615 @item set displaced-stepping on
40616 If the target architecture supports it, @value{GDBN} will use
40617 displaced stepping to step over breakpoints.
40618
40619 @item set displaced-stepping off
40620 @value{GDBN} will not use displaced stepping to step over breakpoints,
40621 even if such is supported by the target architecture.
40622
40623 @cindex non-stop mode, and @samp{set displaced-stepping}
40624 @item set displaced-stepping auto
40625 This is the default mode. @value{GDBN} will use displaced stepping
40626 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
40627 architecture supports displaced stepping.
40628 @end table
40629
40630 @kindex maint check-psymtabs
40631 @item maint check-psymtabs
40632 Check the consistency of currently expanded psymtabs versus symtabs.
40633 Use this to check, for example, whether a symbol is in one but not the other.
40634
40635 @kindex maint check-symtabs
40636 @item maint check-symtabs
40637 Check the consistency of currently expanded symtabs.
40638
40639 @kindex maint expand-symtabs
40640 @item maint expand-symtabs [@var{regexp}]
40641 Expand symbol tables.
40642 If @var{regexp} is specified, only expand symbol tables for file
40643 names matching @var{regexp}.
40644
40645 @kindex maint set catch-demangler-crashes
40646 @kindex maint show catch-demangler-crashes
40647 @cindex demangler crashes
40648 @item maint set catch-demangler-crashes [on|off]
40649 @itemx maint show catch-demangler-crashes
40650 Control whether @value{GDBN} should attempt to catch crashes in the
40651 symbol name demangler. The default is to attempt to catch crashes.
40652 If enabled, the first time a crash is caught, a core file is created,
40653 the offending symbol is displayed and the user is presented with the
40654 option to terminate the current session.
40655
40656 @kindex maint cplus first_component
40657 @item maint cplus first_component @var{name}
40658 Print the first C@t{++} class/namespace component of @var{name}.
40659
40660 @kindex maint cplus namespace
40661 @item maint cplus namespace
40662 Print the list of possible C@t{++} namespaces.
40663
40664 @kindex maint deprecate
40665 @kindex maint undeprecate
40666 @cindex deprecated commands
40667 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
40668 @itemx maint undeprecate @var{command}
40669 Deprecate or undeprecate the named @var{command}. Deprecated commands
40670 cause @value{GDBN} to issue a warning when you use them. The optional
40671 argument @var{replacement} says which newer command should be used in
40672 favor of the deprecated one; if it is given, @value{GDBN} will mention
40673 the replacement as part of the warning.
40674
40675 @kindex maint dump-me
40676 @item maint dump-me
40677 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
40678 Cause a fatal signal in the debugger and force it to dump its core.
40679 This is supported only on systems which support aborting a program
40680 with the @code{SIGQUIT} signal.
40681
40682 @kindex maint internal-error
40683 @kindex maint internal-warning
40684 @kindex maint demangler-warning
40685 @cindex demangler crashes
40686 @item maint internal-error @r{[}@var{message-text}@r{]}
40687 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
40688 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
40689
40690 Cause @value{GDBN} to call the internal function @code{internal_error},
40691 @code{internal_warning} or @code{demangler_warning} and hence behave
40692 as though an internal problem has been detected. In addition to
40693 reporting the internal problem, these functions give the user the
40694 opportunity to either quit @value{GDBN} or (for @code{internal_error}
40695 and @code{internal_warning}) create a core file of the current
40696 @value{GDBN} session.
40697
40698 These commands take an optional parameter @var{message-text} that is
40699 used as the text of the error or warning message.
40700
40701 Here's an example of using @code{internal-error}:
40702
40703 @smallexample
40704 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
40705 @dots{}/maint.c:121: internal-error: testing, 1, 2
40706 A problem internal to GDB has been detected. Further
40707 debugging may prove unreliable.
40708 Quit this debugging session? (y or n) @kbd{n}
40709 Create a core file? (y or n) @kbd{n}
40710 (@value{GDBP})
40711 @end smallexample
40712
40713 @cindex @value{GDBN} internal error
40714 @cindex internal errors, control of @value{GDBN} behavior
40715 @cindex demangler crashes
40716
40717 @kindex maint set internal-error
40718 @kindex maint show internal-error
40719 @kindex maint set internal-warning
40720 @kindex maint show internal-warning
40721 @kindex maint set demangler-warning
40722 @kindex maint show demangler-warning
40723 @item maint set internal-error @var{action} [ask|yes|no]
40724 @itemx maint show internal-error @var{action}
40725 @itemx maint set internal-warning @var{action} [ask|yes|no]
40726 @itemx maint show internal-warning @var{action}
40727 @itemx maint set demangler-warning @var{action} [ask|yes|no]
40728 @itemx maint show demangler-warning @var{action}
40729 When @value{GDBN} reports an internal problem (error or warning) it
40730 gives the user the opportunity to both quit @value{GDBN} and create a
40731 core file of the current @value{GDBN} session. These commands let you
40732 override the default behaviour for each particular @var{action},
40733 described in the table below.
40734
40735 @table @samp
40736 @item quit
40737 You can specify that @value{GDBN} should always (yes) or never (no)
40738 quit. The default is to ask the user what to do.
40739
40740 @item corefile
40741 You can specify that @value{GDBN} should always (yes) or never (no)
40742 create a core file. The default is to ask the user what to do. Note
40743 that there is no @code{corefile} option for @code{demangler-warning}:
40744 demangler warnings always create a core file and this cannot be
40745 disabled.
40746 @end table
40747
40748 @kindex maint set internal-error
40749 @kindex maint show internal-error
40750 @kindex maint set internal-warning
40751 @kindex maint show internal-warning
40752 @item maint set internal-error backtrace @r{[}on|off@r{]}
40753 @itemx maint show internal-error backtrace
40754 @itemx maint set internal-warning backtrace @r{[}on|off@r{]}
40755 @itemx maint show internal-warning backtrace
40756 When @value{GDBN} reports an internal problem (error or warning) it is
40757 possible to have a backtrace of @value{GDBN} printed to the standard
40758 error stream. This is @samp{on} by default for @code{internal-error}
40759 and @samp{off} by default for @code{internal-warning}.
40760
40761 @anchor{maint packet}
40762 @kindex maint packet
40763 @item maint packet @var{text}
40764 If @value{GDBN} is talking to an inferior via the serial protocol,
40765 then this command sends the string @var{text} to the inferior, and
40766 displays the response packet. @value{GDBN} supplies the initial
40767 @samp{$} character, the terminating @samp{#} character, and the
40768 checksum.
40769
40770 Any non-printable characters in the reply are printed as escaped hex,
40771 e.g. @samp{\x00}, @samp{\x01}, etc.
40772
40773 @kindex maint print architecture
40774 @item maint print architecture @r{[}@var{file}@r{]}
40775 Print the entire architecture configuration. The optional argument
40776 @var{file} names the file where the output goes.
40777
40778 @kindex maint print c-tdesc
40779 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
40780 Print the target description (@pxref{Target Descriptions}) as
40781 a C source file. By default, the target description is for the current
40782 target, but if the optional argument @var{file} is provided, that file
40783 is used to produce the description. The @var{file} should be an XML
40784 document, of the form described in @ref{Target Description Format}.
40785 The created source file is built into @value{GDBN} when @value{GDBN} is
40786 built again. This command is used by developers after they add or
40787 modify XML target descriptions.
40788
40789 When the optional flag @samp{-single-feature} is provided then the
40790 target description being processed (either the default, or from
40791 @var{file}) must only contain a single feature. The source file
40792 produced is different in this case.
40793
40794 @kindex maint print xml-tdesc
40795 @item maint print xml-tdesc @r{[}@var{file}@r{]}
40796 Print the target description (@pxref{Target Descriptions}) as an XML
40797 file. By default print the target description for the current target,
40798 but if the optional argument @var{file} is provided, then that file is
40799 read in by GDB and then used to produce the description. The
40800 @var{file} should be an XML document, of the form described in
40801 @ref{Target Description Format}.
40802
40803 @kindex maint check xml-descriptions
40804 @item maint check xml-descriptions @var{dir}
40805 Check that the target descriptions dynamically created by @value{GDBN}
40806 equal the descriptions created from XML files found in @var{dir}.
40807
40808 @anchor{maint check libthread-db}
40809 @kindex maint check libthread-db
40810 @item maint check libthread-db
40811 Run integrity checks on the current inferior's thread debugging
40812 library. This exercises all @code{libthread_db} functionality used by
40813 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
40814 @code{proc_service} functions provided by @value{GDBN} that
40815 @code{libthread_db} uses. Note that parts of the test may be skipped
40816 on some platforms when debugging core files.
40817
40818 @kindex maint print core-file-backed-mappings
40819 @cindex memory address space mappings
40820 @item maint print core-file-backed-mappings
40821 Print the file-backed mappings which were loaded from a core file note.
40822 This output represents state internal to @value{GDBN} and should be
40823 similar to the mappings displayed by the @code{info proc mappings}
40824 command.
40825
40826 @kindex maint print dummy-frames
40827 @item maint print dummy-frames
40828 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
40829
40830 @smallexample
40831 (@value{GDBP}) @kbd{b add}
40832 @dots{}
40833 (@value{GDBP}) @kbd{print add(2,3)}
40834 Breakpoint 2, add (a=2, b=3) at @dots{}
40835 58 return (a + b);
40836 The program being debugged stopped while in a function called from GDB.
40837 @dots{}
40838 (@value{GDBP}) @kbd{maint print dummy-frames}
40839 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
40840 (@value{GDBP})
40841 @end smallexample
40842
40843 Takes an optional file parameter.
40844
40845 @kindex maint print frame-id
40846 @item maint print frame-id
40847 @itemx maint print frame-id @var{level}
40848 Print @value{GDBN}'s internal frame-id for the frame at relative
40849 @var{level}, or for the currently selected frame when @var{level} is
40850 not given.
40851
40852 If used, @var{level} should be an integer, as displayed in the
40853 @command{backtrace} output.
40854
40855 @smallexample
40856 (@value{GDBP}) maint print frame-id
40857 frame-id for frame #0: @{stack=0x7fffffffac70,code=0x0000000000401106,!special@}
40858 (@value{GDBP}) maint print frame-id 2
40859 frame-id for frame #2: @{stack=0x7fffffffac90,code=0x000000000040111c,!special@}
40860 @end smallexample
40861
40862 @kindex maint print registers
40863 @kindex maint print raw-registers
40864 @kindex maint print cooked-registers
40865 @kindex maint print register-groups
40866 @kindex maint print remote-registers
40867 @item maint print registers @r{[}@var{file}@r{]}
40868 @itemx maint print raw-registers @r{[}@var{file}@r{]}
40869 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
40870 @itemx maint print register-groups @r{[}@var{file}@r{]}
40871 @itemx maint print remote-registers @r{[}@var{file}@r{]}
40872 Print @value{GDBN}'s internal register data structures.
40873
40874 The command @code{maint print raw-registers} includes the contents of
40875 the raw register cache; the command @code{maint print
40876 cooked-registers} includes the (cooked) value of all registers,
40877 including registers which aren't available on the target nor visible
40878 to user; the command @code{maint print register-groups} includes the
40879 groups that each register is a member of; and the command @code{maint
40880 print remote-registers} includes the remote target's register numbers
40881 and offsets in the `G' packets.
40882
40883 These commands take an optional parameter, a file name to which to
40884 write the information.
40885
40886 @kindex maint print reggroups
40887 @item maint print reggroups @r{[}@var{file}@r{]}
40888 Print @value{GDBN}'s internal register group data structures. The
40889 optional argument @var{file} tells to what file to write the
40890 information.
40891
40892 The register groups info looks like this:
40893
40894 @smallexample
40895 (@value{GDBP}) @kbd{maint print reggroups}
40896 Group Type
40897 general user
40898 float user
40899 all user
40900 vector user
40901 system user
40902 save internal
40903 restore internal
40904 @end smallexample
40905
40906 @kindex maint flush register-cache
40907 @kindex flushregs
40908 @cindex register cache, flushing
40909 @item maint flush register-cache
40910 @itemx flushregs
40911 Flush the contents of the register cache and as a consequence the
40912 frame cache. This command is useful when debugging issues related to
40913 register fetching, or frame unwinding. The command @code{flushregs}
40914 is deprecated in favor of @code{maint flush register-cache}.
40915
40916 @kindex maint flush source-cache
40917 @cindex source code, caching
40918 @item maint flush source-cache
40919 Flush @value{GDBN}'s cache of source code file contents. After
40920 @value{GDBN} reads a source file, and optionally applies styling
40921 (@pxref{Output Styling}), the file contents are cached. This command
40922 clears that cache. The next time @value{GDBN} wants to show lines
40923 from a source file, the content will be re-read.
40924
40925 This command is useful when debugging issues related to source code
40926 styling. After flushing the cache any source code displayed by
40927 @value{GDBN} will be re-read and re-styled.
40928
40929 @kindex maint print objfiles
40930 @cindex info for known object files
40931 @item maint print objfiles @r{[}@var{regexp}@r{]}
40932 Print a dump of all known object files.
40933 If @var{regexp} is specified, only print object files whose names
40934 match @var{regexp}. For each object file, this command prints its name,
40935 address in memory, and all of its psymtabs and symtabs.
40936
40937 @kindex maint print user-registers
40938 @cindex user registers
40939 @item maint print user-registers
40940 List all currently available @dfn{user registers}. User registers
40941 typically provide alternate names for actual hardware registers. They
40942 include the four ``standard'' registers @code{$fp}, @code{$pc},
40943 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
40944 registers can be used in expressions in the same way as the canonical
40945 register names, but only the latter are listed by the @code{info
40946 registers} and @code{maint print registers} commands.
40947
40948 @kindex maint print section-scripts
40949 @cindex info for known .debug_gdb_scripts-loaded scripts
40950 @item maint print section-scripts [@var{regexp}]
40951 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
40952 If @var{regexp} is specified, only print scripts loaded by object files
40953 matching @var{regexp}.
40954 For each script, this command prints its name as specified in the objfile,
40955 and the full path if known.
40956 @xref{dotdebug_gdb_scripts section}.
40957
40958 @kindex maint print statistics
40959 @cindex bcache statistics
40960 @item maint print statistics
40961 This command prints, for each object file in the program, various data
40962 about that object file followed by the byte cache (@dfn{bcache})
40963 statistics for the object file. The objfile data includes the number
40964 of minimal, partial, full, and stabs symbols, the number of types
40965 defined by the objfile, the number of as yet unexpanded psym tables,
40966 the number of line tables and string tables, and the amount of memory
40967 used by the various tables. The bcache statistics include the counts,
40968 sizes, and counts of duplicates of all and unique objects, max,
40969 average, and median entry size, total memory used and its overhead and
40970 savings, and various measures of the hash table size and chain
40971 lengths.
40972
40973 @kindex maint print target-stack
40974 @cindex target stack description
40975 @item maint print target-stack
40976 A @dfn{target} is an interface between the debugger and a particular
40977 kind of file or process. Targets can be stacked in @dfn{strata},
40978 so that more than one target can potentially respond to a request.
40979 In particular, memory accesses will walk down the stack of targets
40980 until they find a target that is interested in handling that particular
40981 address.
40982
40983 This command prints a short description of each layer that was pushed on
40984 the @dfn{target stack}, starting from the top layer down to the bottom one.
40985
40986 @kindex maint print type
40987 @cindex type chain of a data type
40988 @item maint print type @var{expr}
40989 Print the type chain for a type specified by @var{expr}. The argument
40990 can be either a type name or a symbol. If it is a symbol, the type of
40991 that symbol is described. The type chain produced by this command is
40992 a recursive definition of the data type as stored in @value{GDBN}'s
40993 data structures, including its flags and contained types.
40994
40995 @kindex maint print record-instruction
40996 @item maint print record-instruction
40997 @itemx maint print record-instruction @var{N}
40998 print how GDB recorded a given instruction. If @var{n} is not positive
40999 number, it prints the values stored by the inferior before the @var{n}-th previous
41000 instruction was exectued. If @var{n} is positive, print the values after the @var{n}-th
41001 following instruction is executed. If @var{n} is not given, 0 is assumed.
41002
41003 @kindex maint selftest
41004 @cindex self tests
41005 @item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}
41006 Run any self tests that were compiled in to @value{GDBN}. This will
41007 print a message showing how many tests were run, and how many failed.
41008 If a @var{filter} is passed, only the tests with @var{filter} in their
41009 name will be ran. If @code{-verbose} is passed, the self tests can be
41010 more verbose.
41011
41012 @kindex maint set selftest verbose
41013 @kindex maint show selftest verbose
41014 @cindex self tests
41015 @item maint set selftest verbose
41016 @item maint show selftest verbose
41017 Control whether self tests are run verbosely or not.
41018
41019 @kindex maint info selftests
41020 @cindex self tests
41021 @item maint info selftests
41022 List the selftests compiled in to @value{GDBN}.
41023
41024 @kindex maint set dwarf always-disassemble
41025 @kindex maint show dwarf always-disassemble
41026 @item maint set dwarf always-disassemble
41027 @item maint show dwarf always-disassemble
41028 Control the behavior of @code{info address} when using DWARF debugging
41029 information.
41030
41031 The default is @code{off}, which means that @value{GDBN} should try to
41032 describe a variable's location in an easily readable format. When
41033 @code{on}, @value{GDBN} will instead display the DWARF location
41034 expression in an assembly-like format. Note that some locations are
41035 too complex for @value{GDBN} to describe simply; in this case you will
41036 always see the disassembly form.
41037
41038 Here is an example of the resulting disassembly:
41039
41040 @smallexample
41041 (@value{GDBP}) info addr argc
41042 Symbol "argc" is a complex DWARF expression:
41043 1: DW_OP_fbreg 0
41044 @end smallexample
41045
41046 For more information on these expressions, see
41047 @uref{http://www.dwarfstd.org/, the DWARF standard}.
41048
41049 @kindex maint set dwarf max-cache-age
41050 @kindex maint show dwarf max-cache-age
41051 @item maint set dwarf max-cache-age
41052 @itemx maint show dwarf max-cache-age
41053 Control the DWARF compilation unit cache.
41054
41055 @cindex DWARF compilation units cache
41056 In object files with inter-compilation-unit references, such as those
41057 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
41058 reader needs to frequently refer to previously read compilation units.
41059 This setting controls how long a compilation unit will remain in the
41060 cache if it is not referenced. A higher limit means that cached
41061 compilation units will be stored in memory longer, and more total
41062 memory will be used. Setting it to zero disables caching, which will
41063 slow down @value{GDBN} startup, but reduce memory consumption.
41064
41065 @kindex maint set dwarf unwinders
41066 @kindex maint show dwarf unwinders
41067 @item maint set dwarf unwinders
41068 @itemx maint show dwarf unwinders
41069 Control use of the DWARF frame unwinders.
41070
41071 @cindex DWARF frame unwinders
41072 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
41073 frame unwinders to build the backtrace. Many of these targets will
41074 also have a second mechanism for building the backtrace for use in
41075 cases where DWARF information is not available, this second mechanism
41076 is often an analysis of a function's prologue.
41077
41078 In order to extend testing coverage of the second level stack
41079 unwinding mechanisms it is helpful to be able to disable the DWARF
41080 stack unwinders, this can be done with this switch.
41081
41082 In normal use of @value{GDBN} disabling the DWARF unwinders is not
41083 advisable, there are cases that are better handled through DWARF than
41084 prologue analysis, and the debug experience is likely to be better
41085 with the DWARF frame unwinders enabled.
41086
41087 If DWARF frame unwinders are not supported for a particular target
41088 architecture, then enabling this flag does not cause them to be used.
41089
41090 @kindex maint info frame-unwinders
41091 @item maint info frame-unwinders
41092 List the frame unwinders currently in effect, starting with the highest priority.
41093
41094 @kindex maint set worker-threads
41095 @kindex maint show worker-threads
41096 @item maint set worker-threads
41097 @item maint show worker-threads
41098 Control the number of worker threads that may be used by @value{GDBN}.
41099 On capable hosts, @value{GDBN} may use multiple threads to speed up
41100 certain CPU-intensive operations, such as demangling symbol names.
41101 While the number of threads used by @value{GDBN} may vary, this
41102 command can be used to set an upper bound on this number. The default
41103 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
41104 number. Note that this only controls worker threads started by
41105 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
41106 of their own.
41107
41108 @kindex maint set profile
41109 @kindex maint show profile
41110 @cindex profiling GDB
41111 @item maint set profile
41112 @itemx maint show profile
41113 Control profiling of @value{GDBN}.
41114
41115 Profiling will be disabled until you use the @samp{maint set profile}
41116 command to enable it. When you enable profiling, the system will begin
41117 collecting timing and execution count data; when you disable profiling or
41118 exit @value{GDBN}, the results will be written to a log file. Remember that
41119 if you use profiling, @value{GDBN} will overwrite the profiling log file
41120 (often called @file{gmon.out}). If you have a record of important profiling
41121 data in a @file{gmon.out} file, be sure to move it to a safe location.
41122
41123 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
41124 compiled with the @samp{-pg} compiler option.
41125
41126 @kindex maint set show-debug-regs
41127 @kindex maint show show-debug-regs
41128 @cindex hardware debug registers
41129 @item maint set show-debug-regs
41130 @itemx maint show show-debug-regs
41131 Control whether to show variables that mirror the hardware debug
41132 registers. Use @code{on} to enable, @code{off} to disable. If
41133 enabled, the debug registers values are shown when @value{GDBN} inserts or
41134 removes a hardware breakpoint or watchpoint, and when the inferior
41135 triggers a hardware-assisted breakpoint or watchpoint.
41136
41137 @kindex maint set show-all-tib
41138 @kindex maint show show-all-tib
41139 @item maint set show-all-tib
41140 @itemx maint show show-all-tib
41141 Control whether to show all non zero areas within a 1k block starting
41142 at thread local base, when using the @samp{info w32 thread-information-block}
41143 command.
41144
41145 @kindex maint set target-async
41146 @kindex maint show target-async
41147 @item maint set target-async
41148 @itemx maint show target-async
41149 This controls whether @value{GDBN} targets operate in synchronous or
41150 asynchronous mode (@pxref{Background Execution}). Normally the
41151 default is asynchronous, if it is available; but this can be changed
41152 to more easily debug problems occurring only in synchronous mode.
41153
41154 @kindex maint set target-non-stop @var{mode} [on|off|auto]
41155 @kindex maint show target-non-stop
41156 @item maint set target-non-stop
41157 @itemx maint show target-non-stop
41158
41159 This controls whether @value{GDBN} targets always operate in non-stop
41160 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
41161 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
41162 if supported by the target.
41163
41164 @table @code
41165 @item maint set target-non-stop auto
41166 This is the default mode. @value{GDBN} controls the target in
41167 non-stop mode if the target supports it.
41168
41169 @item maint set target-non-stop on
41170 @value{GDBN} controls the target in non-stop mode even if the target
41171 does not indicate support.
41172
41173 @item maint set target-non-stop off
41174 @value{GDBN} does not control the target in non-stop mode even if the
41175 target supports it.
41176 @end table
41177
41178 @kindex maint set tui-resize-message
41179 @kindex maint show tui-resize-message
41180 @item maint set tui-resize-message
41181 @item maint show tui-resize-message
41182 Control whether @value{GDBN} displays a message each time the terminal
41183 is resized when in TUI mode. The default is @code{off}, which means
41184 that @value{GDBN} is silent during resizes. When @code{on},
41185 @value{GDBN} will display a message after a resize is completed; the
41186 message will include a number indicating how many times the terminal
41187 has been resized. This setting is intended for use by the test suite,
41188 where it would otherwise be difficult to determine when a resize and
41189 refresh has been completed.
41190
41191 @kindex maint set per-command
41192 @kindex maint show per-command
41193 @item maint set per-command
41194 @itemx maint show per-command
41195 @cindex resources used by commands
41196
41197 @value{GDBN} can display the resources used by each command.
41198 This is useful in debugging performance problems.
41199
41200 @table @code
41201 @item maint set per-command space [on|off]
41202 @itemx maint show per-command space
41203 Enable or disable the printing of the memory used by GDB for each command.
41204 If enabled, @value{GDBN} will display how much memory each command
41205 took, following the command's own output.
41206 This can also be requested by invoking @value{GDBN} with the
41207 @option{--statistics} command-line switch (@pxref{Mode Options}).
41208
41209 @item maint set per-command time [on|off]
41210 @itemx maint show per-command time
41211 Enable or disable the printing of the execution time of @value{GDBN}
41212 for each command.
41213 If enabled, @value{GDBN} will display how much time it
41214 took to execute each command, following the command's own output.
41215 Both CPU time and wallclock time are printed.
41216 Printing both is useful when trying to determine whether the cost is
41217 CPU or, e.g., disk/network latency.
41218 Note that the CPU time printed is for @value{GDBN} only, it does not include
41219 the execution time of the inferior because there's no mechanism currently
41220 to compute how much time was spent by @value{GDBN} and how much time was
41221 spent by the program been debugged.
41222 This can also be requested by invoking @value{GDBN} with the
41223 @option{--statistics} command-line switch (@pxref{Mode Options}).
41224
41225 @item maint set per-command symtab [on|off]
41226 @itemx maint show per-command symtab
41227 Enable or disable the printing of basic symbol table statistics
41228 for each command.
41229 If enabled, @value{GDBN} will display the following information:
41230
41231 @enumerate a
41232 @item
41233 number of symbol tables
41234 @item
41235 number of primary symbol tables
41236 @item
41237 number of blocks in the blockvector
41238 @end enumerate
41239 @end table
41240
41241 @kindex maint set check-libthread-db
41242 @kindex maint show check-libthread-db
41243 @item maint set check-libthread-db [on|off]
41244 @itemx maint show check-libthread-db
41245 Control whether @value{GDBN} should run integrity checks on inferior
41246 specific thread debugging libraries as they are loaded. The default
41247 is not to perform such checks. If any check fails @value{GDBN} will
41248 unload the library and continue searching for a suitable candidate as
41249 described in @ref{set libthread-db-search-path}. For more information
41250 about the tests, see @ref{maint check libthread-db}.
41251
41252 @kindex maint set gnu-source-highlight enabled
41253 @kindex maint show gnu-source-highlight enabled
41254 @item maint set gnu-source-highlight enabled @r{[}on|off@r{]}
41255 @itemx maint show gnu-source-highlight enabled
41256 Control whether @value{GDBN} should use the GNU Source Highlight
41257 library for applying styling to source code (@pxref{Output Styling}).
41258 This will be @samp{on} by default if the GNU Source Highlight library
41259 is available. If the GNU Source Highlight library is not available,
41260 then this will be @samp{off} by default, and attempting to change this
41261 value to @samp{on} will give an error.
41262
41263 If the GNU Source Highlight library is not being used, then
41264 @value{GDBN} will use the Python Pygments package for source code
41265 styling, if it is available.
41266
41267 This option is useful for debugging @value{GDBN}'s use of the Pygments
41268 library when @value{GDBN} is linked against the GNU Source Highlight
41269 library.
41270
41271 @anchor{maint_libopcodes_styling}
41272 @kindex maint set libopcodes-styling enabled
41273 @kindex maint show libopcodes-styling enabled
41274 @item maint set libopcodes-styling enabled @r{[}on|off@r{]}
41275 @itemx maint show libopcodes-styling enabled
41276 Control whether @value{GDBN} should use its builtin disassembler
41277 (@file{libopcodes}) to style disassembler output (@pxref{Output
41278 Styling}). The builtin disassembler does not support styling for all
41279 architectures.
41280
41281 When this option is @samp{off} the builtin disassembler will not be
41282 used for styling, @value{GDBN} will fall back to using the Python
41283 Pygments package if possible.
41284
41285 Trying to set this option @samp{on} for an architecture that the
41286 builtin disassembler is unable to style will give an error, otherwise,
41287 the builtin disassembler will be used to style disassembler output.
41288
41289 This option is @samp{on} by default for supported architectures.
41290
41291 This option is useful for debugging @value{GDBN}'s use of the Pygments
41292 library when @value{GDBN} is built for an architecture that supports
41293 styling with the builtin disassembler
41294 @kindex maint space
41295 @cindex memory used by commands
41296 @item maint space @var{value}
41297 An alias for @code{maint set per-command space}.
41298 A non-zero value enables it, zero disables it.
41299
41300 @kindex maint time
41301 @cindex time of command execution
41302 @item maint time @var{value}
41303 An alias for @code{maint set per-command time}.
41304 A non-zero value enables it, zero disables it.
41305
41306 @kindex maint translate-address
41307 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
41308 Find the symbol stored at the location specified by the address
41309 @var{addr} and an optional section name @var{section}. If found,
41310 @value{GDBN} prints the name of the closest symbol and an offset from
41311 the symbol's location to the specified address. This is similar to
41312 the @code{info address} command (@pxref{Symbols}), except that this
41313 command also allows to find symbols in other sections.
41314
41315 If section was not specified, the section in which the symbol was found
41316 is also printed. For dynamically linked executables, the name of
41317 executable or shared library containing the symbol is printed as well.
41318
41319 @kindex maint test-options
41320 @item maint test-options require-delimiter
41321 @itemx maint test-options unknown-is-error
41322 @itemx maint test-options unknown-is-operand
41323 These commands are used by the testsuite to validate the command
41324 options framework. The @code{require-delimiter} variant requires a
41325 double-dash delimiter to indicate end of options. The
41326 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
41327 @code{unknown-is-error} variant throws an error on unknown option,
41328 while @code{unknown-is-operand} treats unknown options as the start of
41329 the command's operands. When run, the commands output the result of
41330 the processed options. When completed, the commands store the
41331 internal result of completion in a variable exposed by the @code{maint
41332 show test-options-completion-result} command.
41333
41334 @kindex maint show test-options-completion-result
41335 @item maint show test-options-completion-result
41336 Shows the result of completing the @code{maint test-options}
41337 subcommands. This is used by the testsuite to validate completion
41338 support in the command options framework.
41339
41340 @kindex maint set test-settings
41341 @kindex maint show test-settings
41342 @item maint set test-settings @var{kind}
41343 @itemx maint show test-settings @var{kind}
41344 These are representative commands for each @var{kind} of setting type
41345 @value{GDBN} supports. They are used by the testsuite for exercising
41346 the settings infrastructure.
41347
41348 @kindex maint set backtrace-on-fatal-signal
41349 @kindex maint show backtrace-on-fatal-signal
41350 @item maint set backtrace-on-fatal-signal [on|off]
41351 @itemx maint show backtrace-on-fatal-signal
41352 When this setting is @code{on}, if @value{GDBN} itself terminates with
41353 a fatal signal (e.g.@: SIGSEGV), then a limited backtrace will be
41354 printed to the standard error stream. This backtrace can be used to
41355 help diagnose crashes within @value{GDBN} in situations where a user
41356 is unable to share a corefile with the @value{GDBN} developers.
41357
41358 If the functionality to provide this backtrace is not available for
41359 the platform on which GDB is running then this feature will be
41360 @code{off} by default, and attempting to turn this feature on will
41361 give an error.
41362
41363 For platforms that do support creating the backtrace this feature is
41364 @code{on} by default.
41365
41366 @kindex maint with
41367 @item maint with @var{setting} [@var{value}] [-- @var{command}]
41368 Like the @code{with} command, but works with @code{maintenance set}
41369 variables. This is used by the testsuite to exercise the @code{with}
41370 command's infrastructure.
41371
41372 @kindex maint ignore-probes
41373 @item maint ignore-probes [@var{-v}|@var{-verbose}] [@var{provider} [@var{name} [@var{objfile}]]]
41374 @itemx maint ignore-probes @var{-reset}
41375 Set or reset the ignore-probes filter. The @var{provider}, @var{name}
41376 and @var{objfile} arguments are as in @code{enable probes} and
41377 @code{disable probes} (@pxref{enable probes}). Only supported for
41378 SystemTap probes.
41379
41380 Here's an example of using @code{maint ignore-probes}:
41381 @smallexample
41382 (gdb) maint ignore-probes -verbose libc ^longjmp$
41383 ignore-probes filter has been set to:
41384 PROVIDER: 'libc'
41385 PROBE_NAME: '^longjmp$'
41386 OBJNAME: ''
41387 (gdb) start
41388 <... more output ...>
41389 Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
41390 Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
41391 Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
41392 @end smallexample
41393 @end table
41394
41395 The following command is useful for non-interactive invocations of
41396 @value{GDBN}, such as in the test suite.
41397
41398 @table @code
41399 @item set watchdog @var{nsec}
41400 @kindex set watchdog
41401 @cindex watchdog timer
41402 @cindex timeout for commands
41403 Set the maximum number of seconds @value{GDBN} will wait for the
41404 target operation to finish. If this time expires, @value{GDBN}
41405 reports and error and the command is aborted.
41406
41407 @item show watchdog
41408 Show the current setting of the target wait timeout.
41409 @end table
41410
41411 @node Remote Protocol
41412 @appendix @value{GDBN} Remote Serial Protocol
41413
41414 @menu
41415 * Overview::
41416 * Packets::
41417 * Stop Reply Packets::
41418 * General Query Packets::
41419 * Architecture-Specific Protocol Details::
41420 * Tracepoint Packets::
41421 * Host I/O Packets::
41422 * Interrupts::
41423 * Notification Packets::
41424 * Remote Non-Stop::
41425 * Packet Acknowledgment::
41426 * Examples::
41427 * File-I/O Remote Protocol Extension::
41428 * Library List Format::
41429 * Library List Format for SVR4 Targets::
41430 * Memory Map Format::
41431 * Thread List Format::
41432 * Traceframe Info Format::
41433 * Branch Trace Format::
41434 * Branch Trace Configuration Format::
41435 @end menu
41436
41437 @node Overview
41438 @section Overview
41439
41440 There may be occasions when you need to know something about the
41441 protocol---for example, if there is only one serial port to your target
41442 machine, you might want your program to do something special if it
41443 recognizes a packet meant for @value{GDBN}.
41444
41445 In the examples below, @samp{->} and @samp{<-} are used to indicate
41446 transmitted and received data, respectively.
41447
41448 @cindex protocol, @value{GDBN} remote serial
41449 @cindex serial protocol, @value{GDBN} remote
41450 @cindex remote serial protocol
41451 All @value{GDBN} commands and responses (other than acknowledgments
41452 and notifications, see @ref{Notification Packets}) are sent as a
41453 @var{packet}. A @var{packet} is introduced with the character
41454 @samp{$}, the actual @var{packet-data}, and the terminating character
41455 @samp{#} followed by a two-digit @var{checksum}:
41456
41457 @smallexample
41458 @code{$}@var{packet-data}@code{#}@var{checksum}
41459 @end smallexample
41460 @noindent
41461
41462 @cindex checksum, for @value{GDBN} remote
41463 @noindent
41464 The two-digit @var{checksum} is computed as the modulo 256 sum of all
41465 characters between the leading @samp{$} and the trailing @samp{#} (an
41466 eight bit unsigned checksum).
41467
41468 Implementors should note that prior to @value{GDBN} 5.0 the protocol
41469 specification also included an optional two-digit @var{sequence-id}:
41470
41471 @smallexample
41472 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
41473 @end smallexample
41474
41475 @cindex sequence-id, for @value{GDBN} remote
41476 @noindent
41477 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
41478 has never output @var{sequence-id}s. Stubs that handle packets added
41479 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
41480
41481 When either the host or the target machine receives a packet, the first
41482 response expected is an acknowledgment: either @samp{+} (to indicate
41483 the package was received correctly) or @samp{-} (to request
41484 retransmission):
41485
41486 @smallexample
41487 -> @code{$}@var{packet-data}@code{#}@var{checksum}
41488 <- @code{+}
41489 @end smallexample
41490 @noindent
41491
41492 The @samp{+}/@samp{-} acknowledgments can be disabled
41493 once a connection is established.
41494 @xref{Packet Acknowledgment}, for details.
41495
41496 The host (@value{GDBN}) sends @var{command}s, and the target (the
41497 debugging stub incorporated in your program) sends a @var{response}. In
41498 the case of step and continue @var{command}s, the response is only sent
41499 when the operation has completed, and the target has again stopped all
41500 threads in all attached processes. This is the default all-stop mode
41501 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
41502 execution mode; see @ref{Remote Non-Stop}, for details.
41503
41504 @var{packet-data} consists of a sequence of characters with the
41505 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
41506 exceptions).
41507
41508 @cindex remote protocol, field separator
41509 Fields within the packet should be separated using @samp{,} @samp{;} or
41510 @samp{:}. Except where otherwise noted all numbers are represented in
41511 @sc{hex} with leading zeros suppressed.
41512
41513 Implementors should note that prior to @value{GDBN} 5.0, the character
41514 @samp{:} could not appear as the third character in a packet (as it
41515 would potentially conflict with the @var{sequence-id}).
41516
41517 @cindex remote protocol, binary data
41518 @anchor{Binary Data}
41519 Binary data in most packets is encoded either as two hexadecimal
41520 digits per byte of binary data. This allowed the traditional remote
41521 protocol to work over connections which were only seven-bit clean.
41522 Some packets designed more recently assume an eight-bit clean
41523 connection, and use a more efficient encoding to send and receive
41524 binary data.
41525
41526 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
41527 as an escape character. Any escaped byte is transmitted as the escape
41528 character followed by the original character XORed with @code{0x20}.
41529 For example, the byte @code{0x7d} would be transmitted as the two
41530 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
41531 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
41532 @samp{@}}) must always be escaped. Responses sent by the stub
41533 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
41534 is not interpreted as the start of a run-length encoded sequence
41535 (described next).
41536
41537 Response @var{data} can be run-length encoded to save space.
41538 Run-length encoding replaces runs of identical characters with one
41539 instance of the repeated character, followed by a @samp{*} and a
41540 repeat count. The repeat count is itself sent encoded, to avoid
41541 binary characters in @var{data}: a value of @var{n} is sent as
41542 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
41543 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
41544 code 32) for a repeat count of 3. (This is because run-length
41545 encoding starts to win for counts 3 or more.) Thus, for example,
41546 @samp{0* } is a run-length encoding of ``0000'': the space character
41547 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
41548 3}} more times.
41549
41550 The printable characters @samp{#} and @samp{$} or with a numeric value
41551 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
41552 seven repeats (@samp{$}) can be expanded using a repeat count of only
41553 five (@samp{"}). For example, @samp{00000000} can be encoded as
41554 @samp{0*"00}.
41555
41556 The error response returned for some packets includes a two character
41557 error number. That number is not well defined.
41558
41559 @cindex empty response, for unsupported packets
41560 For any @var{command} not supported by the stub, an empty response
41561 (@samp{$#00}) should be returned. That way it is possible to extend the
41562 protocol. A newer @value{GDBN} can tell if a packet is supported based
41563 on that response.
41564
41565 At a minimum, a stub is required to support the @samp{?} command to
41566 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
41567 commands for register access, and the @samp{m} and @samp{M} commands
41568 for memory access. Stubs that only control single-threaded targets
41569 can implement run control with the @samp{c} (continue) command, and if
41570 the target architecture supports hardware-assisted single-stepping,
41571 the @samp{s} (step) command. Stubs that support multi-threading
41572 targets should support the @samp{vCont} command. All other commands
41573 are optional.
41574
41575 @node Packets
41576 @section Packets
41577
41578 The following table provides a complete list of all currently defined
41579 @var{command}s and their corresponding response @var{data}.
41580 @xref{File-I/O Remote Protocol Extension}, for details about the File
41581 I/O extension of the remote protocol.
41582
41583 Each packet's description has a template showing the packet's overall
41584 syntax, followed by an explanation of the packet's meaning. We
41585 include spaces in some of the templates for clarity; these are not
41586 part of the packet's syntax. No @value{GDBN} packet uses spaces to
41587 separate its components. For example, a template like @samp{foo
41588 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
41589 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
41590 @var{baz}. @value{GDBN} does not transmit a space character between the
41591 @samp{foo} and the @var{bar}, or between the @var{bar} and the
41592 @var{baz}.
41593
41594 @cindex @var{thread-id}, in remote protocol
41595 @anchor{thread-id syntax}
41596 Several packets and replies include a @var{thread-id} field to identify
41597 a thread. Normally these are positive numbers with a target-specific
41598 interpretation, formatted as big-endian hex strings. A @var{thread-id}
41599 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
41600 pick any thread.
41601
41602 In addition, the remote protocol supports a multiprocess feature in
41603 which the @var{thread-id} syntax is extended to optionally include both
41604 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
41605 The @var{pid} (process) and @var{tid} (thread) components each have the
41606 format described above: a positive number with target-specific
41607 interpretation formatted as a big-endian hex string, literal @samp{-1}
41608 to indicate all processes or threads (respectively), or @samp{0} to
41609 indicate an arbitrary process or thread. Specifying just a process, as
41610 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
41611 error to specify all processes but a specific thread, such as
41612 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
41613 for those packets and replies explicitly documented to include a process
41614 ID, rather than a @var{thread-id}.
41615
41616 The multiprocess @var{thread-id} syntax extensions are only used if both
41617 @value{GDBN} and the stub report support for the @samp{multiprocess}
41618 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
41619 more information.
41620
41621 Note that all packet forms beginning with an upper- or lower-case
41622 letter, other than those described here, are reserved for future use.
41623
41624 Here are the packet descriptions.
41625
41626 @table @samp
41627
41628 @item !
41629 @cindex @samp{!} packet
41630 @anchor{extended mode}
41631 Enable extended mode. In extended mode, the remote server is made
41632 persistent. The @samp{R} packet is used to restart the program being
41633 debugged.
41634
41635 Reply:
41636 @table @samp
41637 @item OK
41638 The remote target both supports and has enabled extended mode.
41639 @end table
41640
41641 @item ?
41642 @cindex @samp{?} packet
41643 @anchor{? packet}
41644 This is sent when connection is first established to query the reason
41645 the target halted. The reply is the same as for step and continue.
41646 This packet has a special interpretation when the target is in
41647 non-stop mode; see @ref{Remote Non-Stop}.
41648
41649 Reply:
41650 @xref{Stop Reply Packets}, for the reply specifications.
41651
41652 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
41653 @cindex @samp{A} packet
41654 Initialized @code{argv[]} array passed into program. @var{arglen}
41655 specifies the number of bytes in the hex encoded byte stream
41656 @var{arg}. See @code{gdbserver} for more details.
41657
41658 Reply:
41659 @table @samp
41660 @item OK
41661 The arguments were set.
41662 @item E @var{NN}
41663 An error occurred.
41664 @end table
41665
41666 @item b @var{baud}
41667 @cindex @samp{b} packet
41668 (Don't use this packet; its behavior is not well-defined.)
41669 Change the serial line speed to @var{baud}.
41670
41671 JTC: @emph{When does the transport layer state change? When it's
41672 received, or after the ACK is transmitted. In either case, there are
41673 problems if the command or the acknowledgment packet is dropped.}
41674
41675 Stan: @emph{If people really wanted to add something like this, and get
41676 it working for the first time, they ought to modify ser-unix.c to send
41677 some kind of out-of-band message to a specially-setup stub and have the
41678 switch happen "in between" packets, so that from remote protocol's point
41679 of view, nothing actually happened.}
41680
41681 @item B @var{addr},@var{mode}
41682 @cindex @samp{B} packet
41683 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
41684 breakpoint at @var{addr}.
41685
41686 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
41687 (@pxref{insert breakpoint or watchpoint packet}).
41688
41689 @cindex @samp{bc} packet
41690 @anchor{bc}
41691 @item bc
41692 Backward continue. Execute the target system in reverse. No parameter.
41693 @xref{Reverse Execution}, for more information.
41694
41695 Reply:
41696 @xref{Stop Reply Packets}, for the reply specifications.
41697
41698 @cindex @samp{bs} packet
41699 @anchor{bs}
41700 @item bs
41701 Backward single step. Execute one instruction in reverse. No parameter.
41702 @xref{Reverse Execution}, for more information.
41703
41704 Reply:
41705 @xref{Stop Reply Packets}, for the reply specifications.
41706
41707 @item c @r{[}@var{addr}@r{]}
41708 @cindex @samp{c} packet
41709 Continue at @var{addr}, which is the address to resume. If @var{addr}
41710 is omitted, resume at current address.
41711
41712 This packet is deprecated for multi-threading support. @xref{vCont
41713 packet}.
41714
41715 Reply:
41716 @xref{Stop Reply Packets}, for the reply specifications.
41717
41718 @item C @var{sig}@r{[};@var{addr}@r{]}
41719 @cindex @samp{C} packet
41720 Continue with signal @var{sig} (hex signal number). If
41721 @samp{;@var{addr}} is omitted, resume at same address.
41722
41723 This packet is deprecated for multi-threading support. @xref{vCont
41724 packet}.
41725
41726 Reply:
41727 @xref{Stop Reply Packets}, for the reply specifications.
41728
41729 @item d
41730 @cindex @samp{d} packet
41731 Toggle debug flag.
41732
41733 Don't use this packet; instead, define a general set packet
41734 (@pxref{General Query Packets}).
41735
41736 @item D
41737 @itemx D;@var{pid}
41738 @cindex @samp{D} packet
41739 The first form of the packet is used to detach @value{GDBN} from the
41740 remote system. It is sent to the remote target
41741 before @value{GDBN} disconnects via the @code{detach} command.
41742
41743 The second form, including a process ID, is used when multiprocess
41744 protocol extensions are enabled (@pxref{multiprocess extensions}), to
41745 detach only a specific process. The @var{pid} is specified as a
41746 big-endian hex string.
41747
41748 Reply:
41749 @table @samp
41750 @item OK
41751 for success
41752 @item E @var{NN}
41753 for an error
41754 @end table
41755
41756 @item F @var{RC},@var{EE},@var{CF};@var{XX}
41757 @cindex @samp{F} packet
41758 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
41759 This is part of the File-I/O protocol extension. @xref{File-I/O
41760 Remote Protocol Extension}, for the specification.
41761
41762 @item g
41763 @anchor{read registers packet}
41764 @cindex @samp{g} packet
41765 Read general registers.
41766
41767 Reply:
41768 @table @samp
41769 @item @var{XX@dots{}}
41770 Each byte of register data is described by two hex digits. The bytes
41771 with the register are transmitted in target byte order. The size of
41772 each register and their position within the @samp{g} packet are
41773 determined by the target description (@pxref{Target Descriptions}); in
41774 the absence of a target description, this is done using code internal
41775 to @value{GDBN}; typically this is some customary register layout for
41776 the architecture in question.
41777
41778 When reading registers, the stub may also return a string of literal
41779 @samp{x}'s in place of the register data digits, to indicate that the
41780 corresponding register's value is unavailable. For example, when
41781 reading registers from a trace frame (@pxref{Analyze Collected
41782 Data,,Using the Collected Data}), this means that the register has not
41783 been collected in the trace frame. When reading registers from a live
41784 program, this indicates that the stub has no means to access the
41785 register contents, even though the corresponding register is known to
41786 exist. Note that if a register truly does not exist on the target,
41787 then it is better to not include it in the target description in the
41788 first place.
41789
41790 For example, for an architecture with 4 registers of
41791 4 bytes each, the following reply indicates to @value{GDBN} that
41792 registers 0 and 2 are unavailable, while registers 1 and 3
41793 are available, and both have zero value:
41794
41795 @smallexample
41796 -> @code{g}
41797 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
41798 @end smallexample
41799
41800 @item E @var{NN}
41801 for an error.
41802 @end table
41803
41804 @item G @var{XX@dots{}}
41805 @cindex @samp{G} packet
41806 Write general registers. @xref{read registers packet}, for a
41807 description of the @var{XX@dots{}} data.
41808
41809 Reply:
41810 @table @samp
41811 @item OK
41812 for success
41813 @item E @var{NN}
41814 for an error
41815 @end table
41816
41817 @item H @var{op} @var{thread-id}
41818 @cindex @samp{H} packet
41819 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
41820 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
41821 should be @samp{c} for step and continue operations (note that this
41822 is deprecated, supporting the @samp{vCont} command is a better
41823 option), and @samp{g} for other operations. The thread designator
41824 @var{thread-id} has the format and interpretation described in
41825 @ref{thread-id syntax}.
41826
41827 Reply:
41828 @table @samp
41829 @item OK
41830 for success
41831 @item E @var{NN}
41832 for an error
41833 @end table
41834
41835 @c FIXME: JTC:
41836 @c 'H': How restrictive (or permissive) is the thread model. If a
41837 @c thread is selected and stopped, are other threads allowed
41838 @c to continue to execute? As I mentioned above, I think the
41839 @c semantics of each command when a thread is selected must be
41840 @c described. For example:
41841 @c
41842 @c 'g': If the stub supports threads and a specific thread is
41843 @c selected, returns the register block from that thread;
41844 @c otherwise returns current registers.
41845 @c
41846 @c 'G' If the stub supports threads and a specific thread is
41847 @c selected, sets the registers of the register block of
41848 @c that thread; otherwise sets current registers.
41849
41850 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
41851 @anchor{cycle step packet}
41852 @cindex @samp{i} packet
41853 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
41854 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
41855 step starting at that address.
41856
41857 @item I
41858 @cindex @samp{I} packet
41859 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
41860 step packet}.
41861
41862 @item k
41863 @cindex @samp{k} packet
41864 Kill request.
41865
41866 The exact effect of this packet is not specified.
41867
41868 For a bare-metal target, it may power cycle or reset the target
41869 system. For that reason, the @samp{k} packet has no reply.
41870
41871 For a single-process target, it may kill that process if possible.
41872
41873 A multiple-process target may choose to kill just one process, or all
41874 that are under @value{GDBN}'s control. For more precise control, use
41875 the vKill packet (@pxref{vKill packet}).
41876
41877 If the target system immediately closes the connection in response to
41878 @samp{k}, @value{GDBN} does not consider the lack of packet
41879 acknowledgment to be an error, and assumes the kill was successful.
41880
41881 If connected using @kbd{target extended-remote}, and the target does
41882 not close the connection in response to a kill request, @value{GDBN}
41883 probes the target state as if a new connection was opened
41884 (@pxref{? packet}).
41885
41886 @item m @var{addr},@var{length}
41887 @cindex @samp{m} packet
41888 Read @var{length} addressable memory units starting at address @var{addr}
41889 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
41890 any particular boundary.
41891
41892 The stub need not use any particular size or alignment when gathering
41893 data from memory for the response; even if @var{addr} is word-aligned
41894 and @var{length} is a multiple of the word size, the stub is free to
41895 use byte accesses, or not. For this reason, this packet may not be
41896 suitable for accessing memory-mapped I/O devices.
41897 @cindex alignment of remote memory accesses
41898 @cindex size of remote memory accesses
41899 @cindex memory, alignment and size of remote accesses
41900
41901 Reply:
41902 @table @samp
41903 @item @var{XX@dots{}}
41904 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
41905 The reply may contain fewer addressable memory units than requested if the
41906 server was able to read only part of the region of memory.
41907 @item E @var{NN}
41908 @var{NN} is errno
41909 @end table
41910
41911 @item M @var{addr},@var{length}:@var{XX@dots{}}
41912 @cindex @samp{M} packet
41913 Write @var{length} addressable memory units starting at address @var{addr}
41914 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
41915 byte is transmitted as a two-digit hexadecimal number.
41916
41917 Reply:
41918 @table @samp
41919 @item OK
41920 for success
41921 @item E @var{NN}
41922 for an error (this includes the case where only part of the data was
41923 written).
41924 @end table
41925
41926 @item p @var{n}
41927 @cindex @samp{p} packet
41928 Read the value of register @var{n}; @var{n} is in hex.
41929 @xref{read registers packet}, for a description of how the returned
41930 register value is encoded.
41931
41932 Reply:
41933 @table @samp
41934 @item @var{XX@dots{}}
41935 the register's value
41936 @item E @var{NN}
41937 for an error
41938 @item @w{}
41939 Indicating an unrecognized @var{query}.
41940 @end table
41941
41942 @item P @var{n@dots{}}=@var{r@dots{}}
41943 @anchor{write register packet}
41944 @cindex @samp{P} packet
41945 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
41946 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
41947 digits for each byte in the register (target byte order).
41948
41949 Reply:
41950 @table @samp
41951 @item OK
41952 for success
41953 @item E @var{NN}
41954 for an error
41955 @end table
41956
41957 @item q @var{name} @var{params}@dots{}
41958 @itemx Q @var{name} @var{params}@dots{}
41959 @cindex @samp{q} packet
41960 @cindex @samp{Q} packet
41961 General query (@samp{q}) and set (@samp{Q}). These packets are
41962 described fully in @ref{General Query Packets}.
41963
41964 @item r
41965 @cindex @samp{r} packet
41966 Reset the entire system.
41967
41968 Don't use this packet; use the @samp{R} packet instead.
41969
41970 @item R @var{XX}
41971 @cindex @samp{R} packet
41972 Restart the program being debugged. The @var{XX}, while needed, is ignored.
41973 This packet is only available in extended mode (@pxref{extended mode}).
41974
41975 The @samp{R} packet has no reply.
41976
41977 @item s @r{[}@var{addr}@r{]}
41978 @cindex @samp{s} packet
41979 Single step, resuming at @var{addr}. If
41980 @var{addr} is omitted, resume at same address.
41981
41982 This packet is deprecated for multi-threading support. @xref{vCont
41983 packet}.
41984
41985 Reply:
41986 @xref{Stop Reply Packets}, for the reply specifications.
41987
41988 @item S @var{sig}@r{[};@var{addr}@r{]}
41989 @anchor{step with signal packet}
41990 @cindex @samp{S} packet
41991 Step with signal. This is analogous to the @samp{C} packet, but
41992 requests a single-step, rather than a normal resumption of execution.
41993
41994 This packet is deprecated for multi-threading support. @xref{vCont
41995 packet}.
41996
41997 Reply:
41998 @xref{Stop Reply Packets}, for the reply specifications.
41999
42000 @item t @var{addr}:@var{PP},@var{MM}
42001 @cindex @samp{t} packet
42002 Search backwards starting at address @var{addr} for a match with pattern
42003 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
42004 There must be at least 3 digits in @var{addr}.
42005
42006 @item T @var{thread-id}
42007 @cindex @samp{T} packet
42008 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
42009
42010 Reply:
42011 @table @samp
42012 @item OK
42013 thread is still alive
42014 @item E @var{NN}
42015 thread is dead
42016 @end table
42017
42018 @item v
42019 Packets starting with @samp{v} are identified by a multi-letter name,
42020 up to the first @samp{;} or @samp{?} (or the end of the packet).
42021
42022 @item vAttach;@var{pid}
42023 @cindex @samp{vAttach} packet
42024 Attach to a new process with the specified process ID @var{pid}.
42025 The process ID is a
42026 hexadecimal integer identifying the process. In all-stop mode, all
42027 threads in the attached process are stopped; in non-stop mode, it may be
42028 attached without being stopped if that is supported by the target.
42029
42030 @c In non-stop mode, on a successful vAttach, the stub should set the
42031 @c current thread to a thread of the newly-attached process. After
42032 @c attaching, GDB queries for the attached process's thread ID with qC.
42033 @c Also note that, from a user perspective, whether or not the
42034 @c target is stopped on attach in non-stop mode depends on whether you
42035 @c use the foreground or background version of the attach command, not
42036 @c on what vAttach does; GDB does the right thing with respect to either
42037 @c stopping or restarting threads.
42038
42039 This packet is only available in extended mode (@pxref{extended mode}).
42040
42041 Reply:
42042 @table @samp
42043 @item E @var{nn}
42044 for an error
42045 @item @r{Any stop packet}
42046 for success in all-stop mode (@pxref{Stop Reply Packets})
42047 @item OK
42048 for success in non-stop mode (@pxref{Remote Non-Stop})
42049 @end table
42050
42051 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
42052 @cindex @samp{vCont} packet
42053 @anchor{vCont packet}
42054 Resume the inferior, specifying different actions for each thread.
42055
42056 For each inferior thread, the leftmost action with a matching
42057 @var{thread-id} is applied. Threads that don't match any action
42058 remain in their current state. Thread IDs are specified using the
42059 syntax described in @ref{thread-id syntax}. If multiprocess
42060 extensions (@pxref{multiprocess extensions}) are supported, actions
42061 can be specified to match all threads in a process by using the
42062 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
42063 @var{thread-id} matches all threads. Specifying no actions is an
42064 error.
42065
42066 Currently supported actions are:
42067
42068 @table @samp
42069 @item c
42070 Continue.
42071 @item C @var{sig}
42072 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
42073 @item s
42074 Step.
42075 @item S @var{sig}
42076 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
42077 @item t
42078 Stop.
42079 @item r @var{start},@var{end}
42080 Step once, and then keep stepping as long as the thread stops at
42081 addresses between @var{start} (inclusive) and @var{end} (exclusive).
42082 The remote stub reports a stop reply when either the thread goes out
42083 of the range or is stopped due to an unrelated reason, such as hitting
42084 a breakpoint. @xref{range stepping}.
42085
42086 If the range is empty (@var{start} == @var{end}), then the action
42087 becomes equivalent to the @samp{s} action. In other words,
42088 single-step once, and report the stop (even if the stepped instruction
42089 jumps to @var{start}).
42090
42091 (A stop reply may be sent at any point even if the PC is still within
42092 the stepping range; for example, it is valid to implement this packet
42093 in a degenerate way as a single instruction step operation.)
42094
42095 @end table
42096
42097 The optional argument @var{addr} normally associated with the
42098 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
42099 not supported in @samp{vCont}.
42100
42101 The @samp{t} action is only relevant in non-stop mode
42102 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
42103 A stop reply should be generated for any affected thread not already stopped.
42104 When a thread is stopped by means of a @samp{t} action,
42105 the corresponding stop reply should indicate that the thread has stopped with
42106 signal @samp{0}, regardless of whether the target uses some other signal
42107 as an implementation detail.
42108
42109 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
42110 @samp{r} actions for threads that are already running. Conversely,
42111 the server must ignore @samp{t} actions for threads that are already
42112 stopped.
42113
42114 @emph{Note:} In non-stop mode, a thread is considered running until
42115 @value{GDBN} acknowledges an asynchronous stop notification for it with
42116 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
42117
42118 The stub must support @samp{vCont} if it reports support for
42119 multiprocess extensions (@pxref{multiprocess extensions}).
42120
42121 Reply:
42122 @xref{Stop Reply Packets}, for the reply specifications.
42123
42124 @item vCont?
42125 @cindex @samp{vCont?} packet
42126 Request a list of actions supported by the @samp{vCont} packet.
42127
42128 Reply:
42129 @table @samp
42130 @item vCont@r{[};@var{action}@dots{}@r{]}
42131 The @samp{vCont} packet is supported. Each @var{action} is a supported
42132 command in the @samp{vCont} packet.
42133 @item @w{}
42134 The @samp{vCont} packet is not supported.
42135 @end table
42136
42137 @anchor{vCtrlC packet}
42138 @item vCtrlC
42139 @cindex @samp{vCtrlC} packet
42140 Interrupt remote target as if a control-C was pressed on the remote
42141 terminal. This is the equivalent to reacting to the @code{^C}
42142 (@samp{\003}, the control-C character) character in all-stop mode
42143 while the target is running, except this works in non-stop mode.
42144 @xref{interrupting remote targets}, for more info on the all-stop
42145 variant.
42146
42147 Reply:
42148 @table @samp
42149 @item E @var{nn}
42150 for an error
42151 @item OK
42152 for success
42153 @end table
42154
42155 @item vFile:@var{operation}:@var{parameter}@dots{}
42156 @cindex @samp{vFile} packet
42157 Perform a file operation on the target system. For details,
42158 see @ref{Host I/O Packets}.
42159
42160 @item vFlashErase:@var{addr},@var{length}
42161 @cindex @samp{vFlashErase} packet
42162 Direct the stub to erase @var{length} bytes of flash starting at
42163 @var{addr}. The region may enclose any number of flash blocks, but
42164 its start and end must fall on block boundaries, as indicated by the
42165 flash block size appearing in the memory map (@pxref{Memory Map
42166 Format}). @value{GDBN} groups flash memory programming operations
42167 together, and sends a @samp{vFlashDone} request after each group; the
42168 stub is allowed to delay erase operation until the @samp{vFlashDone}
42169 packet is received.
42170
42171 Reply:
42172 @table @samp
42173 @item OK
42174 for success
42175 @item E @var{NN}
42176 for an error
42177 @end table
42178
42179 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
42180 @cindex @samp{vFlashWrite} packet
42181 Direct the stub to write data to flash address @var{addr}. The data
42182 is passed in binary form using the same encoding as for the @samp{X}
42183 packet (@pxref{Binary Data}). The memory ranges specified by
42184 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
42185 not overlap, and must appear in order of increasing addresses
42186 (although @samp{vFlashErase} packets for higher addresses may already
42187 have been received; the ordering is guaranteed only between
42188 @samp{vFlashWrite} packets). If a packet writes to an address that was
42189 neither erased by a preceding @samp{vFlashErase} packet nor by some other
42190 target-specific method, the results are unpredictable.
42191
42192
42193 Reply:
42194 @table @samp
42195 @item OK
42196 for success
42197 @item E.memtype
42198 for vFlashWrite addressing non-flash memory
42199 @item E @var{NN}
42200 for an error
42201 @end table
42202
42203 @item vFlashDone
42204 @cindex @samp{vFlashDone} packet
42205 Indicate to the stub that flash programming operation is finished.
42206 The stub is permitted to delay or batch the effects of a group of
42207 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
42208 @samp{vFlashDone} packet is received. The contents of the affected
42209 regions of flash memory are unpredictable until the @samp{vFlashDone}
42210 request is completed.
42211
42212 @item vKill;@var{pid}
42213 @cindex @samp{vKill} packet
42214 @anchor{vKill packet}
42215 Kill the process with the specified process ID @var{pid}, which is a
42216 hexadecimal integer identifying the process. This packet is used in
42217 preference to @samp{k} when multiprocess protocol extensions are
42218 supported; see @ref{multiprocess extensions}.
42219
42220 Reply:
42221 @table @samp
42222 @item E @var{nn}
42223 for an error
42224 @item OK
42225 for success
42226 @end table
42227
42228 @item vMustReplyEmpty
42229 @cindex @samp{vMustReplyEmpty} packet
42230 The correct reply to an unknown @samp{v} packet is to return the empty
42231 string, however, some older versions of @command{gdbserver} would
42232 incorrectly return @samp{OK} for unknown @samp{v} packets.
42233
42234 The @samp{vMustReplyEmpty} is used as a feature test to check how
42235 @command{gdbserver} handles unknown packets, it is important that this
42236 packet be handled in the same way as other unknown @samp{v} packets.
42237 If this packet is handled differently to other unknown @samp{v}
42238 packets then it is possible that @value{GDBN} may run into problems in
42239 other areas, specifically around use of @samp{vFile:setfs:}.
42240
42241 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
42242 @cindex @samp{vRun} packet
42243 Run the program @var{filename}, passing it each @var{argument} on its
42244 command line. The file and arguments are hex-encoded strings. If
42245 @var{filename} is an empty string, the stub may use a default program
42246 (e.g.@: the last program run). The program is created in the stopped
42247 state.
42248
42249 @c FIXME: What about non-stop mode?
42250
42251 This packet is only available in extended mode (@pxref{extended mode}).
42252
42253 Reply:
42254 @table @samp
42255 @item E @var{nn}
42256 for an error
42257 @item @r{Any stop packet}
42258 for success (@pxref{Stop Reply Packets})
42259 @end table
42260
42261 @item vStopped
42262 @cindex @samp{vStopped} packet
42263 @xref{Notification Packets}.
42264
42265 @item X @var{addr},@var{length}:@var{XX@dots{}}
42266 @anchor{X packet}
42267 @cindex @samp{X} packet
42268 Write data to memory, where the data is transmitted in binary.
42269 Memory is specified by its address @var{addr} and number of addressable memory
42270 units @var{length} (@pxref{addressable memory unit});
42271 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
42272
42273 Reply:
42274 @table @samp
42275 @item OK
42276 for success
42277 @item E @var{NN}
42278 for an error
42279 @end table
42280
42281 @item z @var{type},@var{addr},@var{kind}
42282 @itemx Z @var{type},@var{addr},@var{kind}
42283 @anchor{insert breakpoint or watchpoint packet}
42284 @cindex @samp{z} packet
42285 @cindex @samp{Z} packets
42286 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
42287 watchpoint starting at address @var{address} of kind @var{kind}.
42288
42289 Each breakpoint and watchpoint packet @var{type} is documented
42290 separately.
42291
42292 @emph{Implementation notes: A remote target shall return an empty string
42293 for an unrecognized breakpoint or watchpoint packet @var{type}. A
42294 remote target shall support either both or neither of a given
42295 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
42296 avoid potential problems with duplicate packets, the operations should
42297 be implemented in an idempotent way.}
42298
42299 @item z0,@var{addr},@var{kind}
42300 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
42301 @cindex @samp{z0} packet
42302 @cindex @samp{Z0} packet
42303 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
42304 @var{addr} of type @var{kind}.
42305
42306 A software breakpoint is implemented by replacing the instruction at
42307 @var{addr} with a software breakpoint or trap instruction. The
42308 @var{kind} is target-specific and typically indicates the size of the
42309 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
42310 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
42311 architectures have additional meanings for @var{kind}
42312 (@pxref{Architecture-Specific Protocol Details}); if no
42313 architecture-specific value is being used, it should be @samp{0}.
42314 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
42315 conditional expressions in bytecode form that should be evaluated on
42316 the target's side. These are the conditions that should be taken into
42317 consideration when deciding if the breakpoint trigger should be
42318 reported back to @value{GDBN}.
42319
42320 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
42321 for how to best report a software breakpoint event to @value{GDBN}.
42322
42323 The @var{cond_list} parameter is comprised of a series of expressions,
42324 concatenated without separators. Each expression has the following form:
42325
42326 @table @samp
42327
42328 @item X @var{len},@var{expr}
42329 @var{len} is the length of the bytecode expression and @var{expr} is the
42330 actual conditional expression in bytecode form.
42331
42332 @end table
42333
42334 The optional @var{cmd_list} parameter introduces commands that may be
42335 run on the target, rather than being reported back to @value{GDBN}.
42336 The parameter starts with a numeric flag @var{persist}; if the flag is
42337 nonzero, then the breakpoint may remain active and the commands
42338 continue to be run even when @value{GDBN} disconnects from the target.
42339 Following this flag is a series of expressions concatenated with no
42340 separators. Each expression has the following form:
42341
42342 @table @samp
42343
42344 @item X @var{len},@var{expr}
42345 @var{len} is the length of the bytecode expression and @var{expr} is the
42346 actual commands expression in bytecode form.
42347
42348 @end table
42349
42350 @emph{Implementation note: It is possible for a target to copy or move
42351 code that contains software breakpoints (e.g., when implementing
42352 overlays). The behavior of this packet, in the presence of such a
42353 target, is not defined.}
42354
42355 Reply:
42356 @table @samp
42357 @item OK
42358 success
42359 @item @w{}
42360 not supported
42361 @item E @var{NN}
42362 for an error
42363 @end table
42364
42365 @item z1,@var{addr},@var{kind}
42366 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
42367 @cindex @samp{z1} packet
42368 @cindex @samp{Z1} packet
42369 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
42370 address @var{addr}.
42371
42372 A hardware breakpoint is implemented using a mechanism that is not
42373 dependent on being able to modify the target's memory. The
42374 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
42375 same meaning as in @samp{Z0} packets.
42376
42377 @emph{Implementation note: A hardware breakpoint is not affected by code
42378 movement.}
42379
42380 Reply:
42381 @table @samp
42382 @item OK
42383 success
42384 @item @w{}
42385 not supported
42386 @item E @var{NN}
42387 for an error
42388 @end table
42389
42390 @item z2,@var{addr},@var{kind}
42391 @itemx Z2,@var{addr},@var{kind}
42392 @cindex @samp{z2} packet
42393 @cindex @samp{Z2} packet
42394 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
42395 The number of bytes to watch is specified by @var{kind}.
42396
42397 Reply:
42398 @table @samp
42399 @item OK
42400 success
42401 @item @w{}
42402 not supported
42403 @item E @var{NN}
42404 for an error
42405 @end table
42406
42407 @item z3,@var{addr},@var{kind}
42408 @itemx Z3,@var{addr},@var{kind}
42409 @cindex @samp{z3} packet
42410 @cindex @samp{Z3} packet
42411 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
42412 The number of bytes to watch is specified by @var{kind}.
42413
42414 Reply:
42415 @table @samp
42416 @item OK
42417 success
42418 @item @w{}
42419 not supported
42420 @item E @var{NN}
42421 for an error
42422 @end table
42423
42424 @item z4,@var{addr},@var{kind}
42425 @itemx Z4,@var{addr},@var{kind}
42426 @cindex @samp{z4} packet
42427 @cindex @samp{Z4} packet
42428 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
42429 The number of bytes to watch is specified by @var{kind}.
42430
42431 Reply:
42432 @table @samp
42433 @item OK
42434 success
42435 @item @w{}
42436 not supported
42437 @item E @var{NN}
42438 for an error
42439 @end table
42440
42441 @end table
42442
42443 @node Stop Reply Packets
42444 @section Stop Reply Packets
42445 @cindex stop reply packets
42446
42447 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
42448 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
42449 receive any of the below as a reply. Except for @samp{?}
42450 and @samp{vStopped}, that reply is only returned
42451 when the target halts. In the below the exact meaning of @dfn{signal
42452 number} is defined by the header @file{include/gdb/signals.h} in the
42453 @value{GDBN} source code.
42454
42455 In non-stop mode, the server will simply reply @samp{OK} to commands
42456 such as @samp{vCont}; any stop will be the subject of a future
42457 notification. @xref{Remote Non-Stop}.
42458
42459 As in the description of request packets, we include spaces in the
42460 reply templates for clarity; these are not part of the reply packet's
42461 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
42462 components.
42463
42464 @table @samp
42465
42466 @item S @var{AA}
42467 The program received signal number @var{AA} (a two-digit hexadecimal
42468 number). This is equivalent to a @samp{T} response with no
42469 @var{n}:@var{r} pairs.
42470
42471 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
42472 @cindex @samp{T} packet reply
42473 The program received signal number @var{AA} (a two-digit hexadecimal
42474 number). This is equivalent to an @samp{S} response, except that the
42475 @samp{@var{n}:@var{r}} pairs can carry values of important registers
42476 and other information directly in the stop reply packet, reducing
42477 round-trip latency. Single-step and breakpoint traps are reported
42478 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
42479
42480 @itemize @bullet
42481 @item
42482 If @var{n} is a hexadecimal number, it is a register number, and the
42483 corresponding @var{r} gives that register's value. The data @var{r} is a
42484 series of bytes in target byte order, with each byte given by a
42485 two-digit hex number.
42486
42487 @item
42488 If @var{n} is @samp{thread}, then @var{r} is the thread ID of
42489 the stopped thread, as specified in @ref{thread-id syntax}.
42490
42491 @item
42492 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
42493 the core on which the stop event was detected.
42494
42495 @item
42496 If @var{n} is a recognized @dfn{stop reason}, it describes a more
42497 specific event that stopped the target. The currently defined stop
42498 reasons are listed below. The @var{aa} should be @samp{05}, the trap
42499 signal. At most one stop reason should be present.
42500
42501 @item
42502 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
42503 and go on to the next; this allows us to extend the protocol in the
42504 future.
42505 @end itemize
42506
42507 The currently defined stop reasons are:
42508
42509 @table @samp
42510 @item watch
42511 @itemx rwatch
42512 @itemx awatch
42513 The packet indicates a watchpoint hit, and @var{r} is the data address, in
42514 hex.
42515
42516 @item syscall_entry
42517 @itemx syscall_return
42518 The packet indicates a syscall entry or return, and @var{r} is the
42519 syscall number, in hex.
42520
42521 @cindex shared library events, remote reply
42522 @item library
42523 The packet indicates that the loaded libraries have changed.
42524 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
42525 list of loaded libraries. The @var{r} part is ignored.
42526
42527 @cindex replay log events, remote reply
42528 @item replaylog
42529 The packet indicates that the target cannot continue replaying
42530 logged execution events, because it has reached the end (or the
42531 beginning when executing backward) of the log. The value of @var{r}
42532 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
42533 for more information.
42534
42535 @item swbreak
42536 @anchor{swbreak stop reason}
42537 The packet indicates a software breakpoint instruction was executed,
42538 irrespective of whether it was @value{GDBN} that planted the
42539 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
42540 part must be left empty.
42541
42542 On some architectures, such as x86, at the architecture level, when a
42543 breakpoint instruction executes the program counter points at the
42544 breakpoint address plus an offset. On such targets, the stub is
42545 responsible for adjusting the PC to point back at the breakpoint
42546 address.
42547
42548 This packet should not be sent by default; older @value{GDBN} versions
42549 did not support it. @value{GDBN} requests it, by supplying an
42550 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
42551 remote stub must also supply the appropriate @samp{qSupported} feature
42552 indicating support.
42553
42554 This packet is required for correct non-stop mode operation.
42555
42556 @item hwbreak
42557 The packet indicates the target stopped for a hardware breakpoint.
42558 The @var{r} part must be left empty.
42559
42560 The same remarks about @samp{qSupported} and non-stop mode above
42561 apply.
42562
42563 @cindex fork events, remote reply
42564 @item fork
42565 The packet indicates that @code{fork} was called, and @var{r} is the
42566 thread ID of the new child process, as specified in @ref{thread-id
42567 syntax}. This packet is only applicable to targets that support fork
42568 events.
42569
42570 This packet should not be sent by default; older @value{GDBN} versions
42571 did not support it. @value{GDBN} requests it, by supplying an
42572 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
42573 remote stub must also supply the appropriate @samp{qSupported} feature
42574 indicating support.
42575
42576 @cindex vfork events, remote reply
42577 @item vfork
42578 The packet indicates that @code{vfork} was called, and @var{r} is the
42579 thread ID of the new child process, as specified in @ref{thread-id
42580 syntax}. This packet is only applicable to targets that support vfork
42581 events.
42582
42583 This packet should not be sent by default; older @value{GDBN} versions
42584 did not support it. @value{GDBN} requests it, by supplying an
42585 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
42586 remote stub must also supply the appropriate @samp{qSupported} feature
42587 indicating support.
42588
42589 @cindex vforkdone events, remote reply
42590 @item vforkdone
42591 The packet indicates that a child process created by a vfork
42592 has either called @code{exec} or terminated, so that the
42593 address spaces of the parent and child process are no longer
42594 shared. The @var{r} part is ignored. This packet is only
42595 applicable to targets that support vforkdone events.
42596
42597 This packet should not be sent by default; older @value{GDBN} versions
42598 did not support it. @value{GDBN} requests it, by supplying an
42599 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
42600 remote stub must also supply the appropriate @samp{qSupported} feature
42601 indicating support.
42602
42603 @cindex exec events, remote reply
42604 @item exec
42605 The packet indicates that @code{execve} was called, and @var{r}
42606 is the absolute pathname of the file that was executed, in hex.
42607 This packet is only applicable to targets that support exec events.
42608
42609 This packet should not be sent by default; older @value{GDBN} versions
42610 did not support it. @value{GDBN} requests it, by supplying an
42611 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
42612 remote stub must also supply the appropriate @samp{qSupported} feature
42613 indicating support.
42614
42615 @cindex thread create event, remote reply
42616 @anchor{thread create event}
42617 @item create
42618 The packet indicates that the thread was just created. The new thread
42619 is stopped until @value{GDBN} sets it running with a resumption packet
42620 (@pxref{vCont packet}). This packet should not be sent by default;
42621 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
42622 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
42623 @var{r} part is ignored.
42624
42625 @end table
42626
42627 @item W @var{AA}
42628 @itemx W @var{AA} ; process:@var{pid}
42629 The process exited, and @var{AA} is the exit status. This is only
42630 applicable to certain targets.
42631
42632 The second form of the response, including the process ID of the
42633 exited process, can be used only when @value{GDBN} has reported
42634 support for multiprocess protocol extensions; see @ref{multiprocess
42635 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
42636 hex strings.
42637
42638 @item X @var{AA}
42639 @itemx X @var{AA} ; process:@var{pid}
42640 The process terminated with signal @var{AA}.
42641
42642 The second form of the response, including the process ID of the
42643 terminated process, can be used only when @value{GDBN} has reported
42644 support for multiprocess protocol extensions; see @ref{multiprocess
42645 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
42646 hex strings.
42647
42648 @anchor{thread exit event}
42649 @cindex thread exit event, remote reply
42650 @item w @var{AA} ; @var{tid}
42651
42652 The thread exited, and @var{AA} is the exit status. This response
42653 should not be sent by default; @value{GDBN} requests it with the
42654 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
42655 @var{AA} is formatted as a big-endian hex string.
42656
42657 @item N
42658 There are no resumed threads left in the target. In other words, even
42659 though the process is alive, the last resumed thread has exited. For
42660 example, say the target process has two threads: thread 1 and thread
42661 2. The client leaves thread 1 stopped, and resumes thread 2, which
42662 subsequently exits. At this point, even though the process is still
42663 alive, and thus no @samp{W} stop reply is sent, no thread is actually
42664 executing either. The @samp{N} stop reply thus informs the client
42665 that it can stop waiting for stop replies. This packet should not be
42666 sent by default; older @value{GDBN} versions did not support it.
42667 @value{GDBN} requests it, by supplying an appropriate
42668 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
42669 also supply the appropriate @samp{qSupported} feature indicating
42670 support.
42671
42672 @item O @var{XX}@dots{}
42673 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
42674 written as the program's console output. This can happen at any time
42675 while the program is running and the debugger should continue to wait
42676 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
42677
42678 @item F @var{call-id},@var{parameter}@dots{}
42679 @var{call-id} is the identifier which says which host system call should
42680 be called. This is just the name of the function. Translation into the
42681 correct system call is only applicable as it's defined in @value{GDBN}.
42682 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
42683 system calls.
42684
42685 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
42686 this very system call.
42687
42688 The target replies with this packet when it expects @value{GDBN} to
42689 call a host system call on behalf of the target. @value{GDBN} replies
42690 with an appropriate @samp{F} packet and keeps up waiting for the next
42691 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
42692 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
42693 Protocol Extension}, for more details.
42694
42695 @end table
42696
42697 @node General Query Packets
42698 @section General Query Packets
42699 @cindex remote query requests
42700
42701 Packets starting with @samp{q} are @dfn{general query packets};
42702 packets starting with @samp{Q} are @dfn{general set packets}. General
42703 query and set packets are a semi-unified form for retrieving and
42704 sending information to and from the stub.
42705
42706 The initial letter of a query or set packet is followed by a name
42707 indicating what sort of thing the packet applies to. For example,
42708 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
42709 definitions with the stub. These packet names follow some
42710 conventions:
42711
42712 @itemize @bullet
42713 @item
42714 The name must not contain commas, colons or semicolons.
42715 @item
42716 Most @value{GDBN} query and set packets have a leading upper case
42717 letter.
42718 @item
42719 The names of custom vendor packets should use a company prefix, in
42720 lower case, followed by a period. For example, packets designed at
42721 the Acme Corporation might begin with @samp{qacme.foo} (for querying
42722 foos) or @samp{Qacme.bar} (for setting bars).
42723 @end itemize
42724
42725 The name of a query or set packet should be separated from any
42726 parameters by a @samp{:}; the parameters themselves should be
42727 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
42728 full packet name, and check for a separator or the end of the packet,
42729 in case two packet names share a common prefix. New packets should not begin
42730 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
42731 packets predate these conventions, and have arguments without any terminator
42732 for the packet name; we suspect they are in widespread use in places that
42733 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
42734 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
42735 packet.}.
42736
42737 Like the descriptions of the other packets, each description here
42738 has a template showing the packet's overall syntax, followed by an
42739 explanation of the packet's meaning. We include spaces in some of the
42740 templates for clarity; these are not part of the packet's syntax. No
42741 @value{GDBN} packet uses spaces to separate its components.
42742
42743 Here are the currently defined query and set packets:
42744
42745 @table @samp
42746
42747 @item QAgent:1
42748 @itemx QAgent:0
42749 Turn on or off the agent as a helper to perform some debugging operations
42750 delegated from @value{GDBN} (@pxref{Control Agent}).
42751
42752 @item QAllow:@var{op}:@var{val}@dots{}
42753 @cindex @samp{QAllow} packet
42754 Specify which operations @value{GDBN} expects to request of the
42755 target, as a semicolon-separated list of operation name and value
42756 pairs. Possible values for @var{op} include @samp{WriteReg},
42757 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
42758 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
42759 indicating that @value{GDBN} will not request the operation, or 1,
42760 indicating that it may. (The target can then use this to set up its
42761 own internals optimally, for instance if the debugger never expects to
42762 insert breakpoints, it may not need to install its own trap handler.)
42763
42764 @item qC
42765 @cindex current thread, remote request
42766 @cindex @samp{qC} packet
42767 Return the current thread ID.
42768
42769 Reply:
42770 @table @samp
42771 @item QC @var{thread-id}
42772 Where @var{thread-id} is a thread ID as documented in
42773 @ref{thread-id syntax}.
42774 @item @r{(anything else)}
42775 Any other reply implies the old thread ID.
42776 @end table
42777
42778 @item qCRC:@var{addr},@var{length}
42779 @cindex CRC of memory block, remote request
42780 @cindex @samp{qCRC} packet
42781 @anchor{qCRC packet}
42782 Compute the CRC checksum of a block of memory using CRC-32 defined in
42783 IEEE 802.3. The CRC is computed byte at a time, taking the most
42784 significant bit of each byte first. The initial pattern code
42785 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
42786
42787 @emph{Note:} This is the same CRC used in validating separate debug
42788 files (@pxref{Separate Debug Files, , Debugging Information in Separate
42789 Files}). However the algorithm is slightly different. When validating
42790 separate debug files, the CRC is computed taking the @emph{least}
42791 significant bit of each byte first, and the final result is inverted to
42792 detect trailing zeros.
42793
42794 Reply:
42795 @table @samp
42796 @item E @var{NN}
42797 An error (such as memory fault)
42798 @item C @var{crc32}
42799 The specified memory region's checksum is @var{crc32}.
42800 @end table
42801
42802 @item QDisableRandomization:@var{value}
42803 @cindex disable address space randomization, remote request
42804 @cindex @samp{QDisableRandomization} packet
42805 Some target operating systems will randomize the virtual address space
42806 of the inferior process as a security feature, but provide a feature
42807 to disable such randomization, e.g.@: to allow for a more deterministic
42808 debugging experience. On such systems, this packet with a @var{value}
42809 of 1 directs the target to disable address space randomization for
42810 processes subsequently started via @samp{vRun} packets, while a packet
42811 with a @var{value} of 0 tells the target to enable address space
42812 randomization.
42813
42814 This packet is only available in extended mode (@pxref{extended mode}).
42815
42816 Reply:
42817 @table @samp
42818 @item OK
42819 The request succeeded.
42820
42821 @item E @var{nn}
42822 An error occurred. The error number @var{nn} is given as hex digits.
42823
42824 @item @w{}
42825 An empty reply indicates that @samp{QDisableRandomization} is not supported
42826 by the stub.
42827 @end table
42828
42829 This packet is not probed by default; the remote stub must request it,
42830 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42831 This should only be done on targets that actually support disabling
42832 address space randomization.
42833
42834 @item QStartupWithShell:@var{value}
42835 @cindex startup with shell, remote request
42836 @cindex @samp{QStartupWithShell} packet
42837 On UNIX-like targets, it is possible to start the inferior using a
42838 shell program. This is the default behavior on both @value{GDBN} and
42839 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
42840 used to inform @command{gdbserver} whether it should start the
42841 inferior using a shell or not.
42842
42843 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
42844 to start the inferior. If @var{value} is @samp{1},
42845 @command{gdbserver} will use a shell to start the inferior. All other
42846 values are considered an error.
42847
42848 This packet is only available in extended mode (@pxref{extended
42849 mode}).
42850
42851 Reply:
42852 @table @samp
42853 @item OK
42854 The request succeeded.
42855
42856 @item E @var{nn}
42857 An error occurred. The error number @var{nn} is given as hex digits.
42858 @end table
42859
42860 This packet is not probed by default; the remote stub must request it,
42861 by supplying an appropriate @samp{qSupported} response
42862 (@pxref{qSupported}). This should only be done on targets that
42863 actually support starting the inferior using a shell.
42864
42865 Use of this packet is controlled by the @code{set startup-with-shell}
42866 command; @pxref{set startup-with-shell}.
42867
42868 @item QEnvironmentHexEncoded:@var{hex-value}
42869 @anchor{QEnvironmentHexEncoded}
42870 @cindex set environment variable, remote request
42871 @cindex @samp{QEnvironmentHexEncoded} packet
42872 On UNIX-like targets, it is possible to set environment variables that
42873 will be passed to the inferior during the startup process. This
42874 packet is used to inform @command{gdbserver} of an environment
42875 variable that has been defined by the user on @value{GDBN} (@pxref{set
42876 environment}).
42877
42878 The packet is composed by @var{hex-value}, an hex encoded
42879 representation of the @var{name=value} format representing an
42880 environment variable. The name of the environment variable is
42881 represented by @var{name}, and the value to be assigned to the
42882 environment variable is represented by @var{value}. If the variable
42883 has no value (i.e., the value is @code{null}), then @var{value} will
42884 not be present.
42885
42886 This packet is only available in extended mode (@pxref{extended
42887 mode}).
42888
42889 Reply:
42890 @table @samp
42891 @item OK
42892 The request succeeded.
42893 @end table
42894
42895 This packet is not probed by default; the remote stub must request it,
42896 by supplying an appropriate @samp{qSupported} response
42897 (@pxref{qSupported}). This should only be done on targets that
42898 actually support passing environment variables to the starting
42899 inferior.
42900
42901 This packet is related to the @code{set environment} command;
42902 @pxref{set environment}.
42903
42904 @item QEnvironmentUnset:@var{hex-value}
42905 @anchor{QEnvironmentUnset}
42906 @cindex unset environment variable, remote request
42907 @cindex @samp{QEnvironmentUnset} packet
42908 On UNIX-like targets, it is possible to unset environment variables
42909 before starting the inferior in the remote target. This packet is
42910 used to inform @command{gdbserver} of an environment variable that has
42911 been unset by the user on @value{GDBN} (@pxref{unset environment}).
42912
42913 The packet is composed by @var{hex-value}, an hex encoded
42914 representation of the name of the environment variable to be unset.
42915
42916 This packet is only available in extended mode (@pxref{extended
42917 mode}).
42918
42919 Reply:
42920 @table @samp
42921 @item OK
42922 The request succeeded.
42923 @end table
42924
42925 This packet is not probed by default; the remote stub must request it,
42926 by supplying an appropriate @samp{qSupported} response
42927 (@pxref{qSupported}). This should only be done on targets that
42928 actually support passing environment variables to the starting
42929 inferior.
42930
42931 This packet is related to the @code{unset environment} command;
42932 @pxref{unset environment}.
42933
42934 @item QEnvironmentReset
42935 @anchor{QEnvironmentReset}
42936 @cindex reset environment, remote request
42937 @cindex @samp{QEnvironmentReset} packet
42938 On UNIX-like targets, this packet is used to reset the state of
42939 environment variables in the remote target before starting the
42940 inferior. In this context, reset means unsetting all environment
42941 variables that were previously set by the user (i.e., were not
42942 initially present in the environment). It is sent to
42943 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
42944 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
42945 (@pxref{QEnvironmentUnset}) packets.
42946
42947 This packet is only available in extended mode (@pxref{extended
42948 mode}).
42949
42950 Reply:
42951 @table @samp
42952 @item OK
42953 The request succeeded.
42954 @end table
42955
42956 This packet is not probed by default; the remote stub must request it,
42957 by supplying an appropriate @samp{qSupported} response
42958 (@pxref{qSupported}). This should only be done on targets that
42959 actually support passing environment variables to the starting
42960 inferior.
42961
42962 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
42963 @anchor{QSetWorkingDir packet}
42964 @cindex set working directory, remote request
42965 @cindex @samp{QSetWorkingDir} packet
42966 This packet is used to inform the remote server of the intended
42967 current working directory for programs that are going to be executed.
42968
42969 The packet is composed by @var{directory}, an hex encoded
42970 representation of the directory that the remote inferior will use as
42971 its current working directory. If @var{directory} is an empty string,
42972 the remote server should reset the inferior's current working
42973 directory to its original, empty value.
42974
42975 This packet is only available in extended mode (@pxref{extended
42976 mode}).
42977
42978 Reply:
42979 @table @samp
42980 @item OK
42981 The request succeeded.
42982 @end table
42983
42984 @item qfThreadInfo
42985 @itemx qsThreadInfo
42986 @cindex list active threads, remote request
42987 @cindex @samp{qfThreadInfo} packet
42988 @cindex @samp{qsThreadInfo} packet
42989 Obtain a list of all active thread IDs from the target (OS). Since there
42990 may be too many active threads to fit into one reply packet, this query
42991 works iteratively: it may require more than one query/reply sequence to
42992 obtain the entire list of threads. The first query of the sequence will
42993 be the @samp{qfThreadInfo} query; subsequent queries in the
42994 sequence will be the @samp{qsThreadInfo} query.
42995
42996 NOTE: This packet replaces the @samp{qL} query (see below).
42997
42998 Reply:
42999 @table @samp
43000 @item m @var{thread-id}
43001 A single thread ID
43002 @item m @var{thread-id},@var{thread-id}@dots{}
43003 a comma-separated list of thread IDs
43004 @item l
43005 (lower case letter @samp{L}) denotes end of list.
43006 @end table
43007
43008 In response to each query, the target will reply with a list of one or
43009 more thread IDs, separated by commas.
43010 @value{GDBN} will respond to each reply with a request for more thread
43011 ids (using the @samp{qs} form of the query), until the target responds
43012 with @samp{l} (lower-case ell, for @dfn{last}).
43013 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
43014 fields.
43015
43016 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
43017 initial connection with the remote target, and the very first thread ID
43018 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
43019 message. Therefore, the stub should ensure that the first thread ID in
43020 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
43021
43022 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
43023 @cindex get thread-local storage address, remote request
43024 @cindex @samp{qGetTLSAddr} packet
43025 Fetch the address associated with thread local storage specified
43026 by @var{thread-id}, @var{offset}, and @var{lm}.
43027
43028 @var{thread-id} is the thread ID associated with the
43029 thread for which to fetch the TLS address. @xref{thread-id syntax}.
43030
43031 @var{offset} is the (big endian, hex encoded) offset associated with the
43032 thread local variable. (This offset is obtained from the debug
43033 information associated with the variable.)
43034
43035 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
43036 load module associated with the thread local storage. For example,
43037 a @sc{gnu}/Linux system will pass the link map address of the shared
43038 object associated with the thread local storage under consideration.
43039 Other operating environments may choose to represent the load module
43040 differently, so the precise meaning of this parameter will vary.
43041
43042 Reply:
43043 @table @samp
43044 @item @var{XX}@dots{}
43045 Hex encoded (big endian) bytes representing the address of the thread
43046 local storage requested.
43047
43048 @item E @var{nn}
43049 An error occurred. The error number @var{nn} is given as hex digits.
43050
43051 @item @w{}
43052 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
43053 @end table
43054
43055 @item qGetTIBAddr:@var{thread-id}
43056 @cindex get thread information block address
43057 @cindex @samp{qGetTIBAddr} packet
43058 Fetch address of the Windows OS specific Thread Information Block.
43059
43060 @var{thread-id} is the thread ID associated with the thread.
43061
43062 Reply:
43063 @table @samp
43064 @item @var{XX}@dots{}
43065 Hex encoded (big endian) bytes representing the linear address of the
43066 thread information block.
43067
43068 @item E @var{nn}
43069 An error occured. This means that either the thread was not found, or the
43070 address could not be retrieved.
43071
43072 @item @w{}
43073 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
43074 @end table
43075
43076 @item qL @var{startflag} @var{threadcount} @var{nextthread}
43077 Obtain thread information from RTOS. Where: @var{startflag} (one hex
43078 digit) is one to indicate the first query and zero to indicate a
43079 subsequent query; @var{threadcount} (two hex digits) is the maximum
43080 number of threads the response packet can contain; and @var{nextthread}
43081 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
43082 returned in the response as @var{argthread}.
43083
43084 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
43085
43086 Reply:
43087 @table @samp
43088 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
43089 Where: @var{count} (two hex digits) is the number of threads being
43090 returned; @var{done} (one hex digit) is zero to indicate more threads
43091 and one indicates no further threads; @var{argthreadid} (eight hex
43092 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
43093 is a sequence of thread IDs, @var{threadid} (eight hex
43094 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
43095 @end table
43096
43097 @item qMemTags:@var{start address},@var{length}:@var{type}
43098 @anchor{qMemTags}
43099 @cindex fetch memory tags
43100 @cindex @samp{qMemTags} packet
43101 Fetch memory tags of type @var{type} from the address range
43102 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
43103 target is responsible for calculating how many tags will be returned, as this
43104 is architecture-specific.
43105
43106 @var{start address} is the starting address of the memory range.
43107
43108 @var{length} is the length, in bytes, of the memory range.
43109
43110 @var{type} is the type of tag the request wants to fetch. The type is a signed
43111 integer.
43112
43113 Reply:
43114 @table @samp
43115 @item @var{mxx}@dots{}
43116 Hex encoded sequence of uninterpreted bytes, @var{xx}@dots{}, representing the
43117 tags found in the requested memory range.
43118
43119 @item E @var{nn}
43120 An error occured. This means that fetching of memory tags failed for some
43121 reason.
43122
43123 @item @w{}
43124 An empty reply indicates that @samp{qMemTags} is not supported by the stub,
43125 although this should not happen given @value{GDBN} will only send this packet
43126 if the stub has advertised support for memory tagging via @samp{qSupported}.
43127 @end table
43128
43129 @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes}
43130 @anchor{QMemTags}
43131 @cindex store memory tags
43132 @cindex @samp{QMemTags} packet
43133 Store memory tags of type @var{type} to the address range
43134 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
43135 target is responsible for interpreting the type, the tag bytes and modifying
43136 the memory tag granules accordingly, given this is architecture-specific.
43137
43138 The interpretation of how many tags (@var{nt}) should be written to how many
43139 memory tag granules (@var{ng}) is also architecture-specific. The behavior is
43140 implementation-specific, but the following is suggested.
43141
43142 If the number of memory tags, @var{nt}, is greater than or equal to the
43143 number of memory tag granules, @var{ng}, only @var{ng} tags will be
43144 stored.
43145
43146 If @var{nt} is less than @var{ng}, the behavior is that of a fill operation,
43147 and the tag bytes will be used as a pattern that will get repeated until
43148 @var{ng} tags are stored.
43149
43150 @var{start address} is the starting address of the memory range. The address
43151 does not have any restriction on alignment or size.
43152
43153 @var{length} is the length, in bytes, of the memory range.
43154
43155 @var{type} is the type of tag the request wants to fetch. The type is a signed
43156 integer.
43157
43158 @var{tag bytes} is a sequence of hex encoded uninterpreted bytes which will be
43159 interpreted by the target. Each pair of hex digits is interpreted as a
43160 single byte.
43161
43162 Reply:
43163 @table @samp
43164 @item OK
43165 The request was successful and the memory tag granules were modified
43166 accordingly.
43167
43168 @item E @var{nn}
43169 An error occured. This means that modifying the memory tag granules failed
43170 for some reason.
43171
43172 @item @w{}
43173 An empty reply indicates that @samp{QMemTags} is not supported by the stub,
43174 although this should not happen given @value{GDBN} will only send this packet
43175 if the stub has advertised support for memory tagging via @samp{qSupported}.
43176 @end table
43177
43178 @item qOffsets
43179 @cindex section offsets, remote request
43180 @cindex @samp{qOffsets} packet
43181 Get section offsets that the target used when relocating the downloaded
43182 image.
43183
43184 Reply:
43185 @table @samp
43186 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
43187 Relocate the @code{Text} section by @var{xxx} from its original address.
43188 Relocate the @code{Data} section by @var{yyy} from its original address.
43189 If the object file format provides segment information (e.g.@: @sc{elf}
43190 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
43191 segments by the supplied offsets.
43192
43193 @emph{Note: while a @code{Bss} offset may be included in the response,
43194 @value{GDBN} ignores this and instead applies the @code{Data} offset
43195 to the @code{Bss} section.}
43196
43197 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
43198 Relocate the first segment of the object file, which conventionally
43199 contains program code, to a starting address of @var{xxx}. If
43200 @samp{DataSeg} is specified, relocate the second segment, which
43201 conventionally contains modifiable data, to a starting address of
43202 @var{yyy}. @value{GDBN} will report an error if the object file
43203 does not contain segment information, or does not contain at least
43204 as many segments as mentioned in the reply. Extra segments are
43205 kept at fixed offsets relative to the last relocated segment.
43206 @end table
43207
43208 @item qP @var{mode} @var{thread-id}
43209 @cindex thread information, remote request
43210 @cindex @samp{qP} packet
43211 Returns information on @var{thread-id}. Where: @var{mode} is a hex
43212 encoded 32 bit mode; @var{thread-id} is a thread ID
43213 (@pxref{thread-id syntax}).
43214
43215 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
43216 (see below).
43217
43218 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
43219
43220 @item QNonStop:1
43221 @itemx QNonStop:0
43222 @cindex non-stop mode, remote request
43223 @cindex @samp{QNonStop} packet
43224 @anchor{QNonStop}
43225 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
43226 @xref{Remote Non-Stop}, for more information.
43227
43228 Reply:
43229 @table @samp
43230 @item OK
43231 The request succeeded.
43232
43233 @item E @var{nn}
43234 An error occurred. The error number @var{nn} is given as hex digits.
43235
43236 @item @w{}
43237 An empty reply indicates that @samp{QNonStop} is not supported by
43238 the stub.
43239 @end table
43240
43241 This packet is not probed by default; the remote stub must request it,
43242 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43243 Use of this packet is controlled by the @code{set non-stop} command;
43244 @pxref{Non-Stop Mode}.
43245
43246 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
43247 @itemx QCatchSyscalls:0
43248 @cindex catch syscalls from inferior, remote request
43249 @cindex @samp{QCatchSyscalls} packet
43250 @anchor{QCatchSyscalls}
43251 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
43252 catching syscalls from the inferior process.
43253
43254 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
43255 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
43256 is listed, every system call should be reported.
43257
43258 Note that if a syscall not in the list is reported, @value{GDBN} will
43259 still filter the event according to its own list from all corresponding
43260 @code{catch syscall} commands. However, it is more efficient to only
43261 report the requested syscalls.
43262
43263 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
43264 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
43265
43266 If the inferior process execs, the state of @samp{QCatchSyscalls} is
43267 kept for the new process too. On targets where exec may affect syscall
43268 numbers, for example with exec between 32 and 64-bit processes, the
43269 client should send a new packet with the new syscall list.
43270
43271 Reply:
43272 @table @samp
43273 @item OK
43274 The request succeeded.
43275
43276 @item E @var{nn}
43277 An error occurred. @var{nn} are hex digits.
43278
43279 @item @w{}
43280 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
43281 the stub.
43282 @end table
43283
43284 Use of this packet is controlled by the @code{set remote catch-syscalls}
43285 command (@pxref{Remote Configuration, set remote catch-syscalls}).
43286 This packet is not probed by default; the remote stub must request it,
43287 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43288
43289 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
43290 @cindex pass signals to inferior, remote request
43291 @cindex @samp{QPassSignals} packet
43292 @anchor{QPassSignals}
43293 Each listed @var{signal} should be passed directly to the inferior process.
43294 Signals are numbered identically to continue packets and stop replies
43295 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
43296 strictly greater than the previous item. These signals do not need to stop
43297 the inferior, or be reported to @value{GDBN}. All other signals should be
43298 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
43299 combine; any earlier @samp{QPassSignals} list is completely replaced by the
43300 new list. This packet improves performance when using @samp{handle
43301 @var{signal} nostop noprint pass}.
43302
43303 Reply:
43304 @table @samp
43305 @item OK
43306 The request succeeded.
43307
43308 @item E @var{nn}
43309 An error occurred. The error number @var{nn} is given as hex digits.
43310
43311 @item @w{}
43312 An empty reply indicates that @samp{QPassSignals} is not supported by
43313 the stub.
43314 @end table
43315
43316 Use of this packet is controlled by the @code{set remote pass-signals}
43317 command (@pxref{Remote Configuration, set remote pass-signals}).
43318 This packet is not probed by default; the remote stub must request it,
43319 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43320
43321 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
43322 @cindex signals the inferior may see, remote request
43323 @cindex @samp{QProgramSignals} packet
43324 @anchor{QProgramSignals}
43325 Each listed @var{signal} may be delivered to the inferior process.
43326 Others should be silently discarded.
43327
43328 In some cases, the remote stub may need to decide whether to deliver a
43329 signal to the program or not without @value{GDBN} involvement. One
43330 example of that is while detaching --- the program's threads may have
43331 stopped for signals that haven't yet had a chance of being reported to
43332 @value{GDBN}, and so the remote stub can use the signal list specified
43333 by this packet to know whether to deliver or ignore those pending
43334 signals.
43335
43336 This does not influence whether to deliver a signal as requested by a
43337 resumption packet (@pxref{vCont packet}).
43338
43339 Signals are numbered identically to continue packets and stop replies
43340 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
43341 strictly greater than the previous item. Multiple
43342 @samp{QProgramSignals} packets do not combine; any earlier
43343 @samp{QProgramSignals} list is completely replaced by the new list.
43344
43345 Reply:
43346 @table @samp
43347 @item OK
43348 The request succeeded.
43349
43350 @item E @var{nn}
43351 An error occurred. The error number @var{nn} is given as hex digits.
43352
43353 @item @w{}
43354 An empty reply indicates that @samp{QProgramSignals} is not supported
43355 by the stub.
43356 @end table
43357
43358 Use of this packet is controlled by the @code{set remote program-signals}
43359 command (@pxref{Remote Configuration, set remote program-signals}).
43360 This packet is not probed by default; the remote stub must request it,
43361 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43362
43363 @anchor{QThreadEvents}
43364 @item QThreadEvents:1
43365 @itemx QThreadEvents:0
43366 @cindex thread create/exit events, remote request
43367 @cindex @samp{QThreadEvents} packet
43368
43369 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
43370 reporting of thread create and exit events. @xref{thread create
43371 event}, for the reply specifications. For example, this is used in
43372 non-stop mode when @value{GDBN} stops a set of threads and
43373 synchronously waits for the their corresponding stop replies. Without
43374 exit events, if one of the threads exits, @value{GDBN} would hang
43375 forever not knowing that it should no longer expect a stop for that
43376 same thread. @value{GDBN} does not enable this feature unless the
43377 stub reports that it supports it by including @samp{QThreadEvents+} in
43378 its @samp{qSupported} reply.
43379
43380 Reply:
43381 @table @samp
43382 @item OK
43383 The request succeeded.
43384
43385 @item E @var{nn}
43386 An error occurred. The error number @var{nn} is given as hex digits.
43387
43388 @item @w{}
43389 An empty reply indicates that @samp{QThreadEvents} is not supported by
43390 the stub.
43391 @end table
43392
43393 Use of this packet is controlled by the @code{set remote thread-events}
43394 command (@pxref{Remote Configuration, set remote thread-events}).
43395
43396 @item qRcmd,@var{command}
43397 @cindex execute remote command, remote request
43398 @cindex @samp{qRcmd} packet
43399 @var{command} (hex encoded) is passed to the local interpreter for
43400 execution. Invalid commands should be reported using the output
43401 string. Before the final result packet, the target may also respond
43402 with a number of intermediate @samp{O@var{output}} console output
43403 packets. @emph{Implementors should note that providing access to a
43404 stubs's interpreter may have security implications}.
43405
43406 Reply:
43407 @table @samp
43408 @item OK
43409 A command response with no output.
43410 @item @var{OUTPUT}
43411 A command response with the hex encoded output string @var{OUTPUT}.
43412 @item E @var{NN}
43413 Indicate a badly formed request. The error number @var{NN} is given as
43414 hex digits.
43415 @item @w{}
43416 An empty reply indicates that @samp{qRcmd} is not recognized.
43417 @end table
43418
43419 (Note that the @code{qRcmd} packet's name is separated from the
43420 command by a @samp{,}, not a @samp{:}, contrary to the naming
43421 conventions above. Please don't use this packet as a model for new
43422 packets.)
43423
43424 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
43425 @cindex searching memory, in remote debugging
43426 @ifnotinfo
43427 @cindex @samp{qSearch:memory} packet
43428 @end ifnotinfo
43429 @cindex @samp{qSearch memory} packet
43430 @anchor{qSearch memory}
43431 Search @var{length} bytes at @var{address} for @var{search-pattern}.
43432 Both @var{address} and @var{length} are encoded in hex;
43433 @var{search-pattern} is a sequence of bytes, also hex encoded.
43434
43435 Reply:
43436 @table @samp
43437 @item 0
43438 The pattern was not found.
43439 @item 1,address
43440 The pattern was found at @var{address}.
43441 @item E @var{NN}
43442 A badly formed request or an error was encountered while searching memory.
43443 @item @w{}
43444 An empty reply indicates that @samp{qSearch:memory} is not recognized.
43445 @end table
43446
43447 @item QStartNoAckMode
43448 @cindex @samp{QStartNoAckMode} packet
43449 @anchor{QStartNoAckMode}
43450 Request that the remote stub disable the normal @samp{+}/@samp{-}
43451 protocol acknowledgments (@pxref{Packet Acknowledgment}).
43452
43453 Reply:
43454 @table @samp
43455 @item OK
43456 The stub has switched to no-acknowledgment mode.
43457 @value{GDBN} acknowledges this response,
43458 but neither the stub nor @value{GDBN} shall send or expect further
43459 @samp{+}/@samp{-} acknowledgments in the current connection.
43460 @item @w{}
43461 An empty reply indicates that the stub does not support no-acknowledgment mode.
43462 @end table
43463
43464 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
43465 @cindex supported packets, remote query
43466 @cindex features of the remote protocol
43467 @cindex @samp{qSupported} packet
43468 @anchor{qSupported}
43469 Tell the remote stub about features supported by @value{GDBN}, and
43470 query the stub for features it supports. This packet allows
43471 @value{GDBN} and the remote stub to take advantage of each others'
43472 features. @samp{qSupported} also consolidates multiple feature probes
43473 at startup, to improve @value{GDBN} performance---a single larger
43474 packet performs better than multiple smaller probe packets on
43475 high-latency links. Some features may enable behavior which must not
43476 be on by default, e.g.@: because it would confuse older clients or
43477 stubs. Other features may describe packets which could be
43478 automatically probed for, but are not. These features must be
43479 reported before @value{GDBN} will use them. This ``default
43480 unsupported'' behavior is not appropriate for all packets, but it
43481 helps to keep the initial connection time under control with new
43482 versions of @value{GDBN} which support increasing numbers of packets.
43483
43484 Reply:
43485 @table @samp
43486 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
43487 The stub supports or does not support each returned @var{stubfeature},
43488 depending on the form of each @var{stubfeature} (see below for the
43489 possible forms).
43490 @item @w{}
43491 An empty reply indicates that @samp{qSupported} is not recognized,
43492 or that no features needed to be reported to @value{GDBN}.
43493 @end table
43494
43495 The allowed forms for each feature (either a @var{gdbfeature} in the
43496 @samp{qSupported} packet, or a @var{stubfeature} in the response)
43497 are:
43498
43499 @table @samp
43500 @item @var{name}=@var{value}
43501 The remote protocol feature @var{name} is supported, and associated
43502 with the specified @var{value}. The format of @var{value} depends
43503 on the feature, but it must not include a semicolon.
43504 @item @var{name}+
43505 The remote protocol feature @var{name} is supported, and does not
43506 need an associated value.
43507 @item @var{name}-
43508 The remote protocol feature @var{name} is not supported.
43509 @item @var{name}?
43510 The remote protocol feature @var{name} may be supported, and
43511 @value{GDBN} should auto-detect support in some other way when it is
43512 needed. This form will not be used for @var{gdbfeature} notifications,
43513 but may be used for @var{stubfeature} responses.
43514 @end table
43515
43516 Whenever the stub receives a @samp{qSupported} request, the
43517 supplied set of @value{GDBN} features should override any previous
43518 request. This allows @value{GDBN} to put the stub in a known
43519 state, even if the stub had previously been communicating with
43520 a different version of @value{GDBN}.
43521
43522 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
43523 are defined:
43524
43525 @table @samp
43526 @item multiprocess
43527 This feature indicates whether @value{GDBN} supports multiprocess
43528 extensions to the remote protocol. @value{GDBN} does not use such
43529 extensions unless the stub also reports that it supports them by
43530 including @samp{multiprocess+} in its @samp{qSupported} reply.
43531 @xref{multiprocess extensions}, for details.
43532
43533 @item xmlRegisters
43534 This feature indicates that @value{GDBN} supports the XML target
43535 description. If the stub sees @samp{xmlRegisters=} with target
43536 specific strings separated by a comma, it will report register
43537 description.
43538
43539 @item qRelocInsn
43540 This feature indicates whether @value{GDBN} supports the
43541 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
43542 instruction reply packet}).
43543
43544 @item swbreak
43545 This feature indicates whether @value{GDBN} supports the swbreak stop
43546 reason in stop replies. @xref{swbreak stop reason}, for details.
43547
43548 @item hwbreak
43549 This feature indicates whether @value{GDBN} supports the hwbreak stop
43550 reason in stop replies. @xref{swbreak stop reason}, for details.
43551
43552 @item fork-events
43553 This feature indicates whether @value{GDBN} supports fork event
43554 extensions to the remote protocol. @value{GDBN} does not use such
43555 extensions unless the stub also reports that it supports them by
43556 including @samp{fork-events+} in its @samp{qSupported} reply.
43557
43558 @item vfork-events
43559 This feature indicates whether @value{GDBN} supports vfork event
43560 extensions to the remote protocol. @value{GDBN} does not use such
43561 extensions unless the stub also reports that it supports them by
43562 including @samp{vfork-events+} in its @samp{qSupported} reply.
43563
43564 @item exec-events
43565 This feature indicates whether @value{GDBN} supports exec event
43566 extensions to the remote protocol. @value{GDBN} does not use such
43567 extensions unless the stub also reports that it supports them by
43568 including @samp{exec-events+} in its @samp{qSupported} reply.
43569
43570 @item vContSupported
43571 This feature indicates whether @value{GDBN} wants to know the
43572 supported actions in the reply to @samp{vCont?} packet.
43573 @end table
43574
43575 Stubs should ignore any unknown values for
43576 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
43577 packet supports receiving packets of unlimited length (earlier
43578 versions of @value{GDBN} may reject overly long responses). Additional values
43579 for @var{gdbfeature} may be defined in the future to let the stub take
43580 advantage of new features in @value{GDBN}, e.g.@: incompatible
43581 improvements in the remote protocol---the @samp{multiprocess} feature is
43582 an example of such a feature. The stub's reply should be independent
43583 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
43584 describes all the features it supports, and then the stub replies with
43585 all the features it supports.
43586
43587 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
43588 responses, as long as each response uses one of the standard forms.
43589
43590 Some features are flags. A stub which supports a flag feature
43591 should respond with a @samp{+} form response. Other features
43592 require values, and the stub should respond with an @samp{=}
43593 form response.
43594
43595 Each feature has a default value, which @value{GDBN} will use if
43596 @samp{qSupported} is not available or if the feature is not mentioned
43597 in the @samp{qSupported} response. The default values are fixed; a
43598 stub is free to omit any feature responses that match the defaults.
43599
43600 Not all features can be probed, but for those which can, the probing
43601 mechanism is useful: in some cases, a stub's internal
43602 architecture may not allow the protocol layer to know some information
43603 about the underlying target in advance. This is especially common in
43604 stubs which may be configured for multiple targets.
43605
43606 These are the currently defined stub features and their properties:
43607
43608 @multitable @columnfractions 0.35 0.2 0.12 0.2
43609 @c NOTE: The first row should be @headitem, but we do not yet require
43610 @c a new enough version of Texinfo (4.7) to use @headitem.
43611 @item Feature Name
43612 @tab Value Required
43613 @tab Default
43614 @tab Probe Allowed
43615
43616 @item @samp{PacketSize}
43617 @tab Yes
43618 @tab @samp{-}
43619 @tab No
43620
43621 @item @samp{qXfer:auxv:read}
43622 @tab No
43623 @tab @samp{-}
43624 @tab Yes
43625
43626 @item @samp{qXfer:btrace:read}
43627 @tab No
43628 @tab @samp{-}
43629 @tab Yes
43630
43631 @item @samp{qXfer:btrace-conf:read}
43632 @tab No
43633 @tab @samp{-}
43634 @tab Yes
43635
43636 @item @samp{qXfer:exec-file:read}
43637 @tab No
43638 @tab @samp{-}
43639 @tab Yes
43640
43641 @item @samp{qXfer:features:read}
43642 @tab No
43643 @tab @samp{-}
43644 @tab Yes
43645
43646 @item @samp{qXfer:libraries:read}
43647 @tab No
43648 @tab @samp{-}
43649 @tab Yes
43650
43651 @item @samp{qXfer:libraries-svr4:read}
43652 @tab No
43653 @tab @samp{-}
43654 @tab Yes
43655
43656 @item @samp{augmented-libraries-svr4-read}
43657 @tab No
43658 @tab @samp{-}
43659 @tab No
43660
43661 @item @samp{qXfer:memory-map:read}
43662 @tab No
43663 @tab @samp{-}
43664 @tab Yes
43665
43666 @item @samp{qXfer:sdata:read}
43667 @tab No
43668 @tab @samp{-}
43669 @tab Yes
43670
43671 @item @samp{qXfer:siginfo:read}
43672 @tab No
43673 @tab @samp{-}
43674 @tab Yes
43675
43676 @item @samp{qXfer:siginfo:write}
43677 @tab No
43678 @tab @samp{-}
43679 @tab Yes
43680
43681 @item @samp{qXfer:threads:read}
43682 @tab No
43683 @tab @samp{-}
43684 @tab Yes
43685
43686 @item @samp{qXfer:traceframe-info:read}
43687 @tab No
43688 @tab @samp{-}
43689 @tab Yes
43690
43691 @item @samp{qXfer:uib:read}
43692 @tab No
43693 @tab @samp{-}
43694 @tab Yes
43695
43696 @item @samp{qXfer:fdpic:read}
43697 @tab No
43698 @tab @samp{-}
43699 @tab Yes
43700
43701 @item @samp{Qbtrace:off}
43702 @tab Yes
43703 @tab @samp{-}
43704 @tab Yes
43705
43706 @item @samp{Qbtrace:bts}
43707 @tab Yes
43708 @tab @samp{-}
43709 @tab Yes
43710
43711 @item @samp{Qbtrace:pt}
43712 @tab Yes
43713 @tab @samp{-}
43714 @tab Yes
43715
43716 @item @samp{Qbtrace-conf:bts:size}
43717 @tab Yes
43718 @tab @samp{-}
43719 @tab Yes
43720
43721 @item @samp{Qbtrace-conf:pt:size}
43722 @tab Yes
43723 @tab @samp{-}
43724 @tab Yes
43725
43726 @item @samp{QNonStop}
43727 @tab No
43728 @tab @samp{-}
43729 @tab Yes
43730
43731 @item @samp{QCatchSyscalls}
43732 @tab No
43733 @tab @samp{-}
43734 @tab Yes
43735
43736 @item @samp{QPassSignals}
43737 @tab No
43738 @tab @samp{-}
43739 @tab Yes
43740
43741 @item @samp{QStartNoAckMode}
43742 @tab No
43743 @tab @samp{-}
43744 @tab Yes
43745
43746 @item @samp{multiprocess}
43747 @tab No
43748 @tab @samp{-}
43749 @tab No
43750
43751 @item @samp{ConditionalBreakpoints}
43752 @tab No
43753 @tab @samp{-}
43754 @tab No
43755
43756 @item @samp{ConditionalTracepoints}
43757 @tab No
43758 @tab @samp{-}
43759 @tab No
43760
43761 @item @samp{ReverseContinue}
43762 @tab No
43763 @tab @samp{-}
43764 @tab No
43765
43766 @item @samp{ReverseStep}
43767 @tab No
43768 @tab @samp{-}
43769 @tab No
43770
43771 @item @samp{TracepointSource}
43772 @tab No
43773 @tab @samp{-}
43774 @tab No
43775
43776 @item @samp{QAgent}
43777 @tab No
43778 @tab @samp{-}
43779 @tab No
43780
43781 @item @samp{QAllow}
43782 @tab No
43783 @tab @samp{-}
43784 @tab No
43785
43786 @item @samp{QDisableRandomization}
43787 @tab No
43788 @tab @samp{-}
43789 @tab No
43790
43791 @item @samp{EnableDisableTracepoints}
43792 @tab No
43793 @tab @samp{-}
43794 @tab No
43795
43796 @item @samp{QTBuffer:size}
43797 @tab No
43798 @tab @samp{-}
43799 @tab No
43800
43801 @item @samp{tracenz}
43802 @tab No
43803 @tab @samp{-}
43804 @tab No
43805
43806 @item @samp{BreakpointCommands}
43807 @tab No
43808 @tab @samp{-}
43809 @tab No
43810
43811 @item @samp{swbreak}
43812 @tab No
43813 @tab @samp{-}
43814 @tab No
43815
43816 @item @samp{hwbreak}
43817 @tab No
43818 @tab @samp{-}
43819 @tab No
43820
43821 @item @samp{fork-events}
43822 @tab No
43823 @tab @samp{-}
43824 @tab No
43825
43826 @item @samp{vfork-events}
43827 @tab No
43828 @tab @samp{-}
43829 @tab No
43830
43831 @item @samp{exec-events}
43832 @tab No
43833 @tab @samp{-}
43834 @tab No
43835
43836 @item @samp{QThreadEvents}
43837 @tab No
43838 @tab @samp{-}
43839 @tab No
43840
43841 @item @samp{no-resumed}
43842 @tab No
43843 @tab @samp{-}
43844 @tab No
43845
43846 @item @samp{memory-tagging}
43847 @tab No
43848 @tab @samp{-}
43849 @tab No
43850
43851 @end multitable
43852
43853 These are the currently defined stub features, in more detail:
43854
43855 @table @samp
43856 @cindex packet size, remote protocol
43857 @item PacketSize=@var{bytes}
43858 The remote stub can accept packets up to at least @var{bytes} in
43859 length. @value{GDBN} will send packets up to this size for bulk
43860 transfers, and will never send larger packets. This is a limit on the
43861 data characters in the packet, including the frame and checksum.
43862 There is no trailing NUL byte in a remote protocol packet; if the stub
43863 stores packets in a NUL-terminated format, it should allow an extra
43864 byte in its buffer for the NUL. If this stub feature is not supported,
43865 @value{GDBN} guesses based on the size of the @samp{g} packet response.
43866
43867 @item qXfer:auxv:read
43868 The remote stub understands the @samp{qXfer:auxv:read} packet
43869 (@pxref{qXfer auxiliary vector read}).
43870
43871 @item qXfer:btrace:read
43872 The remote stub understands the @samp{qXfer:btrace:read}
43873 packet (@pxref{qXfer btrace read}).
43874
43875 @item qXfer:btrace-conf:read
43876 The remote stub understands the @samp{qXfer:btrace-conf:read}
43877 packet (@pxref{qXfer btrace-conf read}).
43878
43879 @item qXfer:exec-file:read
43880 The remote stub understands the @samp{qXfer:exec-file:read} packet
43881 (@pxref{qXfer executable filename read}).
43882
43883 @item qXfer:features:read
43884 The remote stub understands the @samp{qXfer:features:read} packet
43885 (@pxref{qXfer target description read}).
43886
43887 @item qXfer:libraries:read
43888 The remote stub understands the @samp{qXfer:libraries:read} packet
43889 (@pxref{qXfer library list read}).
43890
43891 @item qXfer:libraries-svr4:read
43892 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
43893 (@pxref{qXfer svr4 library list read}).
43894
43895 @item augmented-libraries-svr4-read
43896 The remote stub understands the augmented form of the
43897 @samp{qXfer:libraries-svr4:read} packet
43898 (@pxref{qXfer svr4 library list read}).
43899
43900 @item qXfer:memory-map:read
43901 The remote stub understands the @samp{qXfer:memory-map:read} packet
43902 (@pxref{qXfer memory map read}).
43903
43904 @item qXfer:sdata:read
43905 The remote stub understands the @samp{qXfer:sdata:read} packet
43906 (@pxref{qXfer sdata read}).
43907
43908 @item qXfer:siginfo:read
43909 The remote stub understands the @samp{qXfer:siginfo:read} packet
43910 (@pxref{qXfer siginfo read}).
43911
43912 @item qXfer:siginfo:write
43913 The remote stub understands the @samp{qXfer:siginfo:write} packet
43914 (@pxref{qXfer siginfo write}).
43915
43916 @item qXfer:threads:read
43917 The remote stub understands the @samp{qXfer:threads:read} packet
43918 (@pxref{qXfer threads read}).
43919
43920 @item qXfer:traceframe-info:read
43921 The remote stub understands the @samp{qXfer:traceframe-info:read}
43922 packet (@pxref{qXfer traceframe info read}).
43923
43924 @item qXfer:uib:read
43925 The remote stub understands the @samp{qXfer:uib:read}
43926 packet (@pxref{qXfer unwind info block}).
43927
43928 @item qXfer:fdpic:read
43929 The remote stub understands the @samp{qXfer:fdpic:read}
43930 packet (@pxref{qXfer fdpic loadmap read}).
43931
43932 @item QNonStop
43933 The remote stub understands the @samp{QNonStop} packet
43934 (@pxref{QNonStop}).
43935
43936 @item QCatchSyscalls
43937 The remote stub understands the @samp{QCatchSyscalls} packet
43938 (@pxref{QCatchSyscalls}).
43939
43940 @item QPassSignals
43941 The remote stub understands the @samp{QPassSignals} packet
43942 (@pxref{QPassSignals}).
43943
43944 @item QStartNoAckMode
43945 The remote stub understands the @samp{QStartNoAckMode} packet and
43946 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
43947
43948 @item multiprocess
43949 @anchor{multiprocess extensions}
43950 @cindex multiprocess extensions, in remote protocol
43951 The remote stub understands the multiprocess extensions to the remote
43952 protocol syntax. The multiprocess extensions affect the syntax of
43953 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
43954 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
43955 replies. Note that reporting this feature indicates support for the
43956 syntactic extensions only, not that the stub necessarily supports
43957 debugging of more than one process at a time. The stub must not use
43958 multiprocess extensions in packet replies unless @value{GDBN} has also
43959 indicated it supports them in its @samp{qSupported} request.
43960
43961 @item qXfer:osdata:read
43962 The remote stub understands the @samp{qXfer:osdata:read} packet
43963 ((@pxref{qXfer osdata read}).
43964
43965 @item ConditionalBreakpoints
43966 The target accepts and implements evaluation of conditional expressions
43967 defined for breakpoints. The target will only report breakpoint triggers
43968 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
43969
43970 @item ConditionalTracepoints
43971 The remote stub accepts and implements conditional expressions defined
43972 for tracepoints (@pxref{Tracepoint Conditions}).
43973
43974 @item ReverseContinue
43975 The remote stub accepts and implements the reverse continue packet
43976 (@pxref{bc}).
43977
43978 @item ReverseStep
43979 The remote stub accepts and implements the reverse step packet
43980 (@pxref{bs}).
43981
43982 @item TracepointSource
43983 The remote stub understands the @samp{QTDPsrc} packet that supplies
43984 the source form of tracepoint definitions.
43985
43986 @item QAgent
43987 The remote stub understands the @samp{QAgent} packet.
43988
43989 @item QAllow
43990 The remote stub understands the @samp{QAllow} packet.
43991
43992 @item QDisableRandomization
43993 The remote stub understands the @samp{QDisableRandomization} packet.
43994
43995 @item StaticTracepoint
43996 @cindex static tracepoints, in remote protocol
43997 The remote stub supports static tracepoints.
43998
43999 @item InstallInTrace
44000 @anchor{install tracepoint in tracing}
44001 The remote stub supports installing tracepoint in tracing.
44002
44003 @item EnableDisableTracepoints
44004 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
44005 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
44006 to be enabled and disabled while a trace experiment is running.
44007
44008 @item QTBuffer:size
44009 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
44010 packet that allows to change the size of the trace buffer.
44011
44012 @item tracenz
44013 @cindex string tracing, in remote protocol
44014 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
44015 See @ref{Bytecode Descriptions} for details about the bytecode.
44016
44017 @item BreakpointCommands
44018 @cindex breakpoint commands, in remote protocol
44019 The remote stub supports running a breakpoint's command list itself,
44020 rather than reporting the hit to @value{GDBN}.
44021
44022 @item Qbtrace:off
44023 The remote stub understands the @samp{Qbtrace:off} packet.
44024
44025 @item Qbtrace:bts
44026 The remote stub understands the @samp{Qbtrace:bts} packet.
44027
44028 @item Qbtrace:pt
44029 The remote stub understands the @samp{Qbtrace:pt} packet.
44030
44031 @item Qbtrace-conf:bts:size
44032 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
44033
44034 @item Qbtrace-conf:pt:size
44035 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
44036
44037 @item swbreak
44038 The remote stub reports the @samp{swbreak} stop reason for memory
44039 breakpoints.
44040
44041 @item hwbreak
44042 The remote stub reports the @samp{hwbreak} stop reason for hardware
44043 breakpoints.
44044
44045 @item fork-events
44046 The remote stub reports the @samp{fork} stop reason for fork events.
44047
44048 @item vfork-events
44049 The remote stub reports the @samp{vfork} stop reason for vfork events
44050 and vforkdone events.
44051
44052 @item exec-events
44053 The remote stub reports the @samp{exec} stop reason for exec events.
44054
44055 @item vContSupported
44056 The remote stub reports the supported actions in the reply to
44057 @samp{vCont?} packet.
44058
44059 @item QThreadEvents
44060 The remote stub understands the @samp{QThreadEvents} packet.
44061
44062 @item no-resumed
44063 The remote stub reports the @samp{N} stop reply.
44064
44065
44066 @item memory-tagging
44067 The remote stub supports and implements the required memory tagging
44068 functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and
44069 @samp{QMemTags} (@pxref{QMemTags}) packets.
44070
44071 For AArch64 GNU/Linux systems, this feature also requires access to the
44072 @file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected.
44073 This is done via the @samp{vFile} requests.
44074
44075 @end table
44076
44077 @item qSymbol::
44078 @cindex symbol lookup, remote request
44079 @cindex @samp{qSymbol} packet
44080 Notify the target that @value{GDBN} is prepared to serve symbol lookup
44081 requests. Accept requests from the target for the values of symbols.
44082
44083 Reply:
44084 @table @samp
44085 @item OK
44086 The target does not need to look up any (more) symbols.
44087 @item qSymbol:@var{sym_name}
44088 The target requests the value of symbol @var{sym_name} (hex encoded).
44089 @value{GDBN} may provide the value by using the
44090 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
44091 below.
44092 @end table
44093
44094 @item qSymbol:@var{sym_value}:@var{sym_name}
44095 Set the value of @var{sym_name} to @var{sym_value}.
44096
44097 @var{sym_name} (hex encoded) is the name of a symbol whose value the
44098 target has previously requested.
44099
44100 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
44101 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
44102 will be empty.
44103
44104 Reply:
44105 @table @samp
44106 @item OK
44107 The target does not need to look up any (more) symbols.
44108 @item qSymbol:@var{sym_name}
44109 The target requests the value of a new symbol @var{sym_name} (hex
44110 encoded). @value{GDBN} will continue to supply the values of symbols
44111 (if available), until the target ceases to request them.
44112 @end table
44113
44114 @item qTBuffer
44115 @itemx QTBuffer
44116 @itemx QTDisconnected
44117 @itemx QTDP
44118 @itemx QTDPsrc
44119 @itemx QTDV
44120 @itemx qTfP
44121 @itemx qTfV
44122 @itemx QTFrame
44123 @itemx qTMinFTPILen
44124
44125 @xref{Tracepoint Packets}.
44126
44127 @anchor{qThreadExtraInfo}
44128 @item qThreadExtraInfo,@var{thread-id}
44129 @cindex thread attributes info, remote request
44130 @cindex @samp{qThreadExtraInfo} packet
44131 Obtain from the target OS a printable string description of thread
44132 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
44133 for the forms of @var{thread-id}. This
44134 string may contain anything that the target OS thinks is interesting
44135 for @value{GDBN} to tell the user about the thread. The string is
44136 displayed in @value{GDBN}'s @code{info threads} display. Some
44137 examples of possible thread extra info strings are @samp{Runnable}, or
44138 @samp{Blocked on Mutex}.
44139
44140 Reply:
44141 @table @samp
44142 @item @var{XX}@dots{}
44143 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
44144 comprising the printable string containing the extra information about
44145 the thread's attributes.
44146 @end table
44147
44148 (Note that the @code{qThreadExtraInfo} packet's name is separated from
44149 the command by a @samp{,}, not a @samp{:}, contrary to the naming
44150 conventions above. Please don't use this packet as a model for new
44151 packets.)
44152
44153 @item QTNotes
44154 @itemx qTP
44155 @itemx QTSave
44156 @itemx qTsP
44157 @itemx qTsV
44158 @itemx QTStart
44159 @itemx QTStop
44160 @itemx QTEnable
44161 @itemx QTDisable
44162 @itemx QTinit
44163 @itemx QTro
44164 @itemx qTStatus
44165 @itemx qTV
44166 @itemx qTfSTM
44167 @itemx qTsSTM
44168 @itemx qTSTMat
44169 @xref{Tracepoint Packets}.
44170
44171 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
44172 @cindex read special object, remote request
44173 @cindex @samp{qXfer} packet
44174 @anchor{qXfer read}
44175 Read uninterpreted bytes from the target's special data area
44176 identified by the keyword @var{object}. Request @var{length} bytes
44177 starting at @var{offset} bytes into the data. The content and
44178 encoding of @var{annex} is specific to @var{object}; it can supply
44179 additional details about what data to access.
44180
44181 Reply:
44182 @table @samp
44183 @item m @var{data}
44184 Data @var{data} (@pxref{Binary Data}) has been read from the
44185 target. There may be more data at a higher address (although
44186 it is permitted to return @samp{m} even for the last valid
44187 block of data, as long as at least one byte of data was read).
44188 It is possible for @var{data} to have fewer bytes than the @var{length} in the
44189 request.
44190
44191 @item l @var{data}
44192 Data @var{data} (@pxref{Binary Data}) has been read from the target.
44193 There is no more data to be read. It is possible for @var{data} to
44194 have fewer bytes than the @var{length} in the request.
44195
44196 @item l
44197 The @var{offset} in the request is at the end of the data.
44198 There is no more data to be read.
44199
44200 @item E00
44201 The request was malformed, or @var{annex} was invalid.
44202
44203 @item E @var{nn}
44204 The offset was invalid, or there was an error encountered reading the data.
44205 The @var{nn} part is a hex-encoded @code{errno} value.
44206
44207 @item @w{}
44208 An empty reply indicates the @var{object} string was not recognized by
44209 the stub, or that the object does not support reading.
44210 @end table
44211
44212 Here are the specific requests of this form defined so far. All the
44213 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
44214 formats, listed above.
44215
44216 @table @samp
44217 @item qXfer:auxv:read::@var{offset},@var{length}
44218 @anchor{qXfer auxiliary vector read}
44219 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
44220 auxiliary vector}. Note @var{annex} must be empty.
44221
44222 This packet is not probed by default; the remote stub must request it,
44223 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44224
44225 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
44226 @anchor{qXfer btrace read}
44227
44228 Return a description of the current branch trace.
44229 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
44230 packet may have one of the following values:
44231
44232 @table @code
44233 @item all
44234 Returns all available branch trace.
44235
44236 @item new
44237 Returns all available branch trace if the branch trace changed since
44238 the last read request.
44239
44240 @item delta
44241 Returns the new branch trace since the last read request. Adds a new
44242 block to the end of the trace that begins at zero and ends at the source
44243 location of the first branch in the trace buffer. This extra block is
44244 used to stitch traces together.
44245
44246 If the trace buffer overflowed, returns an error indicating the overflow.
44247 @end table
44248
44249 This packet is not probed by default; the remote stub must request it
44250 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44251
44252 @item qXfer:btrace-conf:read::@var{offset},@var{length}
44253 @anchor{qXfer btrace-conf read}
44254
44255 Return a description of the current branch trace configuration.
44256 @xref{Branch Trace Configuration Format}.
44257
44258 This packet is not probed by default; the remote stub must request it
44259 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44260
44261 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
44262 @anchor{qXfer executable filename read}
44263 Return the full absolute name of the file that was executed to create
44264 a process running on the remote system. The annex specifies the
44265 numeric process ID of the process to query, encoded as a hexadecimal
44266 number. If the annex part is empty the remote stub should return the
44267 filename corresponding to the currently executing process.
44268
44269 This packet is not probed by default; the remote stub must request it,
44270 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44271
44272 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
44273 @anchor{qXfer target description read}
44274 Access the @dfn{target description}. @xref{Target Descriptions}. The
44275 annex specifies which XML document to access. The main description is
44276 always loaded from the @samp{target.xml} annex.
44277
44278 This packet is not probed by default; the remote stub must request it,
44279 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44280
44281 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
44282 @anchor{qXfer library list read}
44283 Access the target's list of loaded libraries. @xref{Library List Format}.
44284 The annex part of the generic @samp{qXfer} packet must be empty
44285 (@pxref{qXfer read}).
44286
44287 Targets which maintain a list of libraries in the program's memory do
44288 not need to implement this packet; it is designed for platforms where
44289 the operating system manages the list of loaded libraries.
44290
44291 This packet is not probed by default; the remote stub must request it,
44292 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44293
44294 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
44295 @anchor{qXfer svr4 library list read}
44296 Access the target's list of loaded libraries when the target is an SVR4
44297 platform. @xref{Library List Format for SVR4 Targets}. The annex part
44298 of the generic @samp{qXfer} packet must be empty unless the remote
44299 stub indicated it supports the augmented form of this packet
44300 by supplying an appropriate @samp{qSupported} response
44301 (@pxref{qXfer read}, @ref{qSupported}).
44302
44303 This packet is optional for better performance on SVR4 targets.
44304 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
44305
44306 This packet is not probed by default; the remote stub must request it,
44307 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44308
44309 If the remote stub indicates it supports the augmented form of this
44310 packet then the annex part of the generic @samp{qXfer} packet may
44311 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
44312 arguments. The currently supported arguments are:
44313
44314 @table @code
44315 @item start=@var{address}
44316 A hexadecimal number specifying the address of the @samp{struct
44317 link_map} to start reading the library list from. If unset or zero
44318 then the first @samp{struct link_map} in the library list will be
44319 chosen as the starting point.
44320
44321 @item prev=@var{address}
44322 A hexadecimal number specifying the address of the @samp{struct
44323 link_map} immediately preceding the @samp{struct link_map}
44324 specified by the @samp{start} argument. If unset or zero then
44325 the remote stub will expect that no @samp{struct link_map}
44326 exists prior to the starting point.
44327
44328 @item lmid=@var{lmid}
44329 A hexadecimal number specifying a namespace identifier. This is
44330 currently only used together with @samp{start} to provide the
44331 namespace identifier back to @value{GDBN} in the response.
44332 @value{GDBN} will only provide values that were previously reported to
44333 it. If unset, the response will include @samp{lmid="0x0"}.
44334 @end table
44335
44336 Arguments that are not understood by the remote stub will be silently
44337 ignored.
44338
44339 @item qXfer:memory-map:read::@var{offset},@var{length}
44340 @anchor{qXfer memory map read}
44341 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
44342 annex part of the generic @samp{qXfer} packet must be empty
44343 (@pxref{qXfer read}).
44344
44345 This packet is not probed by default; the remote stub must request it,
44346 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44347
44348 @item qXfer:sdata:read::@var{offset},@var{length}
44349 @anchor{qXfer sdata read}
44350
44351 Read contents of the extra collected static tracepoint marker
44352 information. The annex part of the generic @samp{qXfer} packet must
44353 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
44354 Action Lists}.
44355
44356 This packet is not probed by default; the remote stub must request it,
44357 by supplying an appropriate @samp{qSupported} response
44358 (@pxref{qSupported}).
44359
44360 @item qXfer:siginfo:read::@var{offset},@var{length}
44361 @anchor{qXfer siginfo read}
44362 Read contents of the extra signal information on the target
44363 system. The annex part of the generic @samp{qXfer} packet must be
44364 empty (@pxref{qXfer read}).
44365
44366 This packet is not probed by default; the remote stub must request it,
44367 by supplying an appropriate @samp{qSupported} response
44368 (@pxref{qSupported}).
44369
44370 @item qXfer:threads:read::@var{offset},@var{length}
44371 @anchor{qXfer threads read}
44372 Access the list of threads on target. @xref{Thread List Format}. The
44373 annex part of the generic @samp{qXfer} packet must be empty
44374 (@pxref{qXfer read}).
44375
44376 This packet is not probed by default; the remote stub must request it,
44377 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44378
44379 @item qXfer:traceframe-info:read::@var{offset},@var{length}
44380 @anchor{qXfer traceframe info read}
44381
44382 Return a description of the current traceframe's contents.
44383 @xref{Traceframe Info Format}. The annex part of the generic
44384 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
44385
44386 This packet is not probed by default; the remote stub must request it,
44387 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44388
44389 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
44390 @anchor{qXfer unwind info block}
44391
44392 Return the unwind information block for @var{pc}. This packet is used
44393 on OpenVMS/ia64 to ask the kernel unwind information.
44394
44395 This packet is not probed by default.
44396
44397 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
44398 @anchor{qXfer fdpic loadmap read}
44399 Read contents of @code{loadmap}s on the target system. The
44400 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
44401 executable @code{loadmap} or interpreter @code{loadmap} to read.
44402
44403 This packet is not probed by default; the remote stub must request it,
44404 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
44405
44406 @item qXfer:osdata:read::@var{offset},@var{length}
44407 @anchor{qXfer osdata read}
44408 Access the target's @dfn{operating system information}.
44409 @xref{Operating System Information}.
44410
44411 @end table
44412
44413 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
44414 @cindex write data into object, remote request
44415 @anchor{qXfer write}
44416 Write uninterpreted bytes into the target's special data area
44417 identified by the keyword @var{object}, starting at @var{offset} bytes
44418 into the data. The binary-encoded data (@pxref{Binary Data}) to be
44419 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
44420 is specific to @var{object}; it can supply additional details about what data
44421 to access.
44422
44423 Reply:
44424 @table @samp
44425 @item @var{nn}
44426 @var{nn} (hex encoded) is the number of bytes written.
44427 This may be fewer bytes than supplied in the request.
44428
44429 @item E00
44430 The request was malformed, or @var{annex} was invalid.
44431
44432 @item E @var{nn}
44433 The offset was invalid, or there was an error encountered writing the data.
44434 The @var{nn} part is a hex-encoded @code{errno} value.
44435
44436 @item @w{}
44437 An empty reply indicates the @var{object} string was not
44438 recognized by the stub, or that the object does not support writing.
44439 @end table
44440
44441 Here are the specific requests of this form defined so far. All the
44442 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
44443 formats, listed above.
44444
44445 @table @samp
44446 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
44447 @anchor{qXfer siginfo write}
44448 Write @var{data} to the extra signal information on the target system.
44449 The annex part of the generic @samp{qXfer} packet must be
44450 empty (@pxref{qXfer write}).
44451
44452 This packet is not probed by default; the remote stub must request it,
44453 by supplying an appropriate @samp{qSupported} response
44454 (@pxref{qSupported}).
44455 @end table
44456
44457 @item qXfer:@var{object}:@var{operation}:@dots{}
44458 Requests of this form may be added in the future. When a stub does
44459 not recognize the @var{object} keyword, or its support for
44460 @var{object} does not recognize the @var{operation} keyword, the stub
44461 must respond with an empty packet.
44462
44463 @item qAttached:@var{pid}
44464 @cindex query attached, remote request
44465 @cindex @samp{qAttached} packet
44466 Return an indication of whether the remote server attached to an
44467 existing process or created a new process. When the multiprocess
44468 protocol extensions are supported (@pxref{multiprocess extensions}),
44469 @var{pid} is an integer in hexadecimal format identifying the target
44470 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
44471 the query packet will be simplified as @samp{qAttached}.
44472
44473 This query is used, for example, to know whether the remote process
44474 should be detached or killed when a @value{GDBN} session is ended with
44475 the @code{quit} command.
44476
44477 Reply:
44478 @table @samp
44479 @item 1
44480 The remote server attached to an existing process.
44481 @item 0
44482 The remote server created a new process.
44483 @item E @var{NN}
44484 A badly formed request or an error was encountered.
44485 @end table
44486
44487 @item Qbtrace:bts
44488 Enable branch tracing for the current thread using Branch Trace Store.
44489
44490 Reply:
44491 @table @samp
44492 @item OK
44493 Branch tracing has been enabled.
44494 @item E.errtext
44495 A badly formed request or an error was encountered.
44496 @end table
44497
44498 @item Qbtrace:pt
44499 Enable branch tracing for the current thread using Intel Processor Trace.
44500
44501 Reply:
44502 @table @samp
44503 @item OK
44504 Branch tracing has been enabled.
44505 @item E.errtext
44506 A badly formed request or an error was encountered.
44507 @end table
44508
44509 @item Qbtrace:off
44510 Disable branch tracing for the current thread.
44511
44512 Reply:
44513 @table @samp
44514 @item OK
44515 Branch tracing has been disabled.
44516 @item E.errtext
44517 A badly formed request or an error was encountered.
44518 @end table
44519
44520 @item Qbtrace-conf:bts:size=@var{value}
44521 Set the requested ring buffer size for new threads that use the
44522 btrace recording method in bts format.
44523
44524 Reply:
44525 @table @samp
44526 @item OK
44527 The ring buffer size has been set.
44528 @item E.errtext
44529 A badly formed request or an error was encountered.
44530 @end table
44531
44532 @item Qbtrace-conf:pt:size=@var{value}
44533 Set the requested ring buffer size for new threads that use the
44534 btrace recording method in pt format.
44535
44536 Reply:
44537 @table @samp
44538 @item OK
44539 The ring buffer size has been set.
44540 @item E.errtext
44541 A badly formed request or an error was encountered.
44542 @end table
44543
44544 @end table
44545
44546 @node Architecture-Specific Protocol Details
44547 @section Architecture-Specific Protocol Details
44548
44549 This section describes how the remote protocol is applied to specific
44550 target architectures. Also see @ref{Standard Target Features}, for
44551 details of XML target descriptions for each architecture.
44552
44553 @menu
44554 * ARM-Specific Protocol Details::
44555 * MIPS-Specific Protocol Details::
44556 @end menu
44557
44558 @node ARM-Specific Protocol Details
44559 @subsection @acronym{ARM}-specific Protocol Details
44560
44561 @menu
44562 * ARM Breakpoint Kinds::
44563 * ARM Memory Tag Types::
44564 @end menu
44565
44566 @node ARM Breakpoint Kinds
44567 @subsubsection @acronym{ARM} Breakpoint Kinds
44568 @cindex breakpoint kinds, @acronym{ARM}
44569
44570 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
44571
44572 @table @r
44573
44574 @item 2
44575 16-bit Thumb mode breakpoint.
44576
44577 @item 3
44578 32-bit Thumb mode (Thumb-2) breakpoint.
44579
44580 @item 4
44581 32-bit @acronym{ARM} mode breakpoint.
44582
44583 @end table
44584
44585 @node ARM Memory Tag Types
44586 @subsubsection @acronym{ARM} Memory Tag Types
44587 @cindex memory tag types, @acronym{ARM}
44588
44589 These memory tag types are defined for the @samp{qMemTag} and @samp{QMemTag}
44590 packets.
44591
44592 @table @r
44593
44594 @item 0
44595 MTE logical tag
44596
44597 @item 1
44598 MTE allocation tag
44599
44600 @end table
44601
44602 @node MIPS-Specific Protocol Details
44603 @subsection @acronym{MIPS}-specific Protocol Details
44604
44605 @menu
44606 * MIPS Register packet Format::
44607 * MIPS Breakpoint Kinds::
44608 @end menu
44609
44610 @node MIPS Register packet Format
44611 @subsubsection @acronym{MIPS} Register Packet Format
44612 @cindex register packet format, @acronym{MIPS}
44613
44614 The following @code{g}/@code{G} packets have previously been defined.
44615 In the below, some thirty-two bit registers are transferred as
44616 sixty-four bits. Those registers should be zero/sign extended (which?)
44617 to fill the space allocated. Register bytes are transferred in target
44618 byte order. The two nibbles within a register byte are transferred
44619 most-significant -- least-significant.
44620
44621 @table @r
44622
44623 @item MIPS32
44624 All registers are transferred as thirty-two bit quantities in the order:
44625 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
44626 registers; fsr; fir; fp.
44627
44628 @item MIPS64
44629 All registers are transferred as sixty-four bit quantities (including
44630 thirty-two bit registers such as @code{sr}). The ordering is the same
44631 as @code{MIPS32}.
44632
44633 @end table
44634
44635 @node MIPS Breakpoint Kinds
44636 @subsubsection @acronym{MIPS} Breakpoint Kinds
44637 @cindex breakpoint kinds, @acronym{MIPS}
44638
44639 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
44640
44641 @table @r
44642
44643 @item 2
44644 16-bit @acronym{MIPS16} mode breakpoint.
44645
44646 @item 3
44647 16-bit @acronym{microMIPS} mode breakpoint.
44648
44649 @item 4
44650 32-bit standard @acronym{MIPS} mode breakpoint.
44651
44652 @item 5
44653 32-bit @acronym{microMIPS} mode breakpoint.
44654
44655 @end table
44656
44657 @node Tracepoint Packets
44658 @section Tracepoint Packets
44659 @cindex tracepoint packets
44660 @cindex packets, tracepoint
44661
44662 Here we describe the packets @value{GDBN} uses to implement
44663 tracepoints (@pxref{Tracepoints}).
44664
44665 @table @samp
44666
44667 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
44668 @cindex @samp{QTDP} packet
44669 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
44670 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
44671 the tracepoint is disabled. The @var{step} gives the tracepoint's step
44672 count, and @var{pass} gives its pass count. If an @samp{F} is present,
44673 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
44674 the number of bytes that the target should copy elsewhere to make room
44675 for the tracepoint. If an @samp{X} is present, it introduces a
44676 tracepoint condition, which consists of a hexadecimal length, followed
44677 by a comma and hex-encoded bytes, in a manner similar to action
44678 encodings as described below. If the trailing @samp{-} is present,
44679 further @samp{QTDP} packets will follow to specify this tracepoint's
44680 actions.
44681
44682 Replies:
44683 @table @samp
44684 @item OK
44685 The packet was understood and carried out.
44686 @item qRelocInsn
44687 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
44688 @item @w{}
44689 The packet was not recognized.
44690 @end table
44691
44692 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
44693 Define actions to be taken when a tracepoint is hit. The @var{n} and
44694 @var{addr} must be the same as in the initial @samp{QTDP} packet for
44695 this tracepoint. This packet may only be sent immediately after
44696 another @samp{QTDP} packet that ended with a @samp{-}. If the
44697 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
44698 specifying more actions for this tracepoint.
44699
44700 In the series of action packets for a given tracepoint, at most one
44701 can have an @samp{S} before its first @var{action}. If such a packet
44702 is sent, it and the following packets define ``while-stepping''
44703 actions. Any prior packets define ordinary actions --- that is, those
44704 taken when the tracepoint is first hit. If no action packet has an
44705 @samp{S}, then all the packets in the series specify ordinary
44706 tracepoint actions.
44707
44708 The @samp{@var{action}@dots{}} portion of the packet is a series of
44709 actions, concatenated without separators. Each action has one of the
44710 following forms:
44711
44712 @table @samp
44713
44714 @item R @var{mask}
44715 Collect the registers whose bits are set in @var{mask},
44716 a hexadecimal number whose @var{i}'th bit is set if register number
44717 @var{i} should be collected. (The least significant bit is numbered
44718 zero.) Note that @var{mask} may be any number of digits long; it may
44719 not fit in a 32-bit word.
44720
44721 @item M @var{basereg},@var{offset},@var{len}
44722 Collect @var{len} bytes of memory starting at the address in register
44723 number @var{basereg}, plus @var{offset}. If @var{basereg} is
44724 @samp{-1}, then the range has a fixed address: @var{offset} is the
44725 address of the lowest byte to collect. The @var{basereg},
44726 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
44727 values (the @samp{-1} value for @var{basereg} is a special case).
44728
44729 @item X @var{len},@var{expr}
44730 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
44731 it directs. The agent expression @var{expr} is as described in
44732 @ref{Agent Expressions}. Each byte of the expression is encoded as a
44733 two-digit hex number in the packet; @var{len} is the number of bytes
44734 in the expression (and thus one-half the number of hex digits in the
44735 packet).
44736
44737 @end table
44738
44739 Any number of actions may be packed together in a single @samp{QTDP}
44740 packet, as long as the packet does not exceed the maximum packet
44741 length (400 bytes, for many stubs). There may be only one @samp{R}
44742 action per tracepoint, and it must precede any @samp{M} or @samp{X}
44743 actions. Any registers referred to by @samp{M} and @samp{X} actions
44744 must be collected by a preceding @samp{R} action. (The
44745 ``while-stepping'' actions are treated as if they were attached to a
44746 separate tracepoint, as far as these restrictions are concerned.)
44747
44748 Replies:
44749 @table @samp
44750 @item OK
44751 The packet was understood and carried out.
44752 @item qRelocInsn
44753 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
44754 @item @w{}
44755 The packet was not recognized.
44756 @end table
44757
44758 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
44759 @cindex @samp{QTDPsrc} packet
44760 Specify a source string of tracepoint @var{n} at address @var{addr}.
44761 This is useful to get accurate reproduction of the tracepoints
44762 originally downloaded at the beginning of the trace run. The @var{type}
44763 is the name of the tracepoint part, such as @samp{cond} for the
44764 tracepoint's conditional expression (see below for a list of types), while
44765 @var{bytes} is the string, encoded in hexadecimal.
44766
44767 @var{start} is the offset of the @var{bytes} within the overall source
44768 string, while @var{slen} is the total length of the source string.
44769 This is intended for handling source strings that are longer than will
44770 fit in a single packet.
44771 @c Add detailed example when this info is moved into a dedicated
44772 @c tracepoint descriptions section.
44773
44774 The available string types are @samp{at} for the location,
44775 @samp{cond} for the conditional, and @samp{cmd} for an action command.
44776 @value{GDBN} sends a separate packet for each command in the action
44777 list, in the same order in which the commands are stored in the list.
44778
44779 The target does not need to do anything with source strings except
44780 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
44781 query packets.
44782
44783 Although this packet is optional, and @value{GDBN} will only send it
44784 if the target replies with @samp{TracepointSource} @xref{General
44785 Query Packets}, it makes both disconnected tracing and trace files
44786 much easier to use. Otherwise the user must be careful that the
44787 tracepoints in effect while looking at trace frames are identical to
44788 the ones in effect during the trace run; even a small discrepancy
44789 could cause @samp{tdump} not to work, or a particular trace frame not
44790 be found.
44791
44792 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
44793 @cindex define trace state variable, remote request
44794 @cindex @samp{QTDV} packet
44795 Create a new trace state variable, number @var{n}, with an initial
44796 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
44797 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
44798 the option of not using this packet for initial values of zero; the
44799 target should simply create the trace state variables as they are
44800 mentioned in expressions. The value @var{builtin} should be 1 (one)
44801 if the trace state variable is builtin and 0 (zero) if it is not builtin.
44802 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
44803 @samp{qTsV} packet had it set. The contents of @var{name} is the
44804 hex-encoded name (without the leading @samp{$}) of the trace state
44805 variable.
44806
44807 @item QTFrame:@var{n}
44808 @cindex @samp{QTFrame} packet
44809 Select the @var{n}'th tracepoint frame from the buffer, and use the
44810 register and memory contents recorded there to answer subsequent
44811 request packets from @value{GDBN}.
44812
44813 A successful reply from the stub indicates that the stub has found the
44814 requested frame. The response is a series of parts, concatenated
44815 without separators, describing the frame we selected. Each part has
44816 one of the following forms:
44817
44818 @table @samp
44819 @item F @var{f}
44820 The selected frame is number @var{n} in the trace frame buffer;
44821 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
44822 was no frame matching the criteria in the request packet.
44823
44824 @item T @var{t}
44825 The selected trace frame records a hit of tracepoint number @var{t};
44826 @var{t} is a hexadecimal number.
44827
44828 @end table
44829
44830 @item QTFrame:pc:@var{addr}
44831 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
44832 currently selected frame whose PC is @var{addr};
44833 @var{addr} is a hexadecimal number.
44834
44835 @item QTFrame:tdp:@var{t}
44836 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
44837 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
44838 is a hexadecimal number.
44839
44840 @item QTFrame:range:@var{start}:@var{end}
44841 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
44842 currently selected frame whose PC is between @var{start} (inclusive)
44843 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
44844 numbers.
44845
44846 @item QTFrame:outside:@var{start}:@var{end}
44847 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
44848 frame @emph{outside} the given range of addresses (exclusive).
44849
44850 @item qTMinFTPILen
44851 @cindex @samp{qTMinFTPILen} packet
44852 This packet requests the minimum length of instruction at which a fast
44853 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
44854 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
44855 it depends on the target system being able to create trampolines in
44856 the first 64K of memory, which might or might not be possible for that
44857 system. So the reply to this packet will be 4 if it is able to
44858 arrange for that.
44859
44860 Replies:
44861
44862 @table @samp
44863 @item 0
44864 The minimum instruction length is currently unknown.
44865 @item @var{length}
44866 The minimum instruction length is @var{length}, where @var{length}
44867 is a hexadecimal number greater or equal to 1. A reply
44868 of 1 means that a fast tracepoint may be placed on any instruction
44869 regardless of size.
44870 @item E
44871 An error has occurred.
44872 @item @w{}
44873 An empty reply indicates that the request is not supported by the stub.
44874 @end table
44875
44876 @item QTStart
44877 @cindex @samp{QTStart} packet
44878 Begin the tracepoint experiment. Begin collecting data from
44879 tracepoint hits in the trace frame buffer. This packet supports the
44880 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
44881 instruction reply packet}).
44882
44883 @item QTStop
44884 @cindex @samp{QTStop} packet
44885 End the tracepoint experiment. Stop collecting trace frames.
44886
44887 @item QTEnable:@var{n}:@var{addr}
44888 @anchor{QTEnable}
44889 @cindex @samp{QTEnable} packet
44890 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
44891 experiment. If the tracepoint was previously disabled, then collection
44892 of data from it will resume.
44893
44894 @item QTDisable:@var{n}:@var{addr}
44895 @anchor{QTDisable}
44896 @cindex @samp{QTDisable} packet
44897 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
44898 experiment. No more data will be collected from the tracepoint unless
44899 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
44900
44901 @item QTinit
44902 @cindex @samp{QTinit} packet
44903 Clear the table of tracepoints, and empty the trace frame buffer.
44904
44905 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
44906 @cindex @samp{QTro} packet
44907 Establish the given ranges of memory as ``transparent''. The stub
44908 will answer requests for these ranges from memory's current contents,
44909 if they were not collected as part of the tracepoint hit.
44910
44911 @value{GDBN} uses this to mark read-only regions of memory, like those
44912 containing program code. Since these areas never change, they should
44913 still have the same contents they did when the tracepoint was hit, so
44914 there's no reason for the stub to refuse to provide their contents.
44915
44916 @item QTDisconnected:@var{value}
44917 @cindex @samp{QTDisconnected} packet
44918 Set the choice to what to do with the tracing run when @value{GDBN}
44919 disconnects from the target. A @var{value} of 1 directs the target to
44920 continue the tracing run, while 0 tells the target to stop tracing if
44921 @value{GDBN} is no longer in the picture.
44922
44923 @item qTStatus
44924 @cindex @samp{qTStatus} packet
44925 Ask the stub if there is a trace experiment running right now.
44926
44927 The reply has the form:
44928
44929 @table @samp
44930
44931 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
44932 @var{running} is a single digit @code{1} if the trace is presently
44933 running, or @code{0} if not. It is followed by semicolon-separated
44934 optional fields that an agent may use to report additional status.
44935
44936 @end table
44937
44938 If the trace is not running, the agent may report any of several
44939 explanations as one of the optional fields:
44940
44941 @table @samp
44942
44943 @item tnotrun:0
44944 No trace has been run yet.
44945
44946 @item tstop[:@var{text}]:0
44947 The trace was stopped by a user-originated stop command. The optional
44948 @var{text} field is a user-supplied string supplied as part of the
44949 stop command (for instance, an explanation of why the trace was
44950 stopped manually). It is hex-encoded.
44951
44952 @item tfull:0
44953 The trace stopped because the trace buffer filled up.
44954
44955 @item tdisconnected:0
44956 The trace stopped because @value{GDBN} disconnected from the target.
44957
44958 @item tpasscount:@var{tpnum}
44959 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
44960
44961 @item terror:@var{text}:@var{tpnum}
44962 The trace stopped because tracepoint @var{tpnum} had an error. The
44963 string @var{text} is available to describe the nature of the error
44964 (for instance, a divide by zero in the condition expression); it
44965 is hex encoded.
44966
44967 @item tunknown:0
44968 The trace stopped for some other reason.
44969
44970 @end table
44971
44972 Additional optional fields supply statistical and other information.
44973 Although not required, they are extremely useful for users monitoring
44974 the progress of a trace run. If a trace has stopped, and these
44975 numbers are reported, they must reflect the state of the just-stopped
44976 trace.
44977
44978 @table @samp
44979
44980 @item tframes:@var{n}
44981 The number of trace frames in the buffer.
44982
44983 @item tcreated:@var{n}
44984 The total number of trace frames created during the run. This may
44985 be larger than the trace frame count, if the buffer is circular.
44986
44987 @item tsize:@var{n}
44988 The total size of the trace buffer, in bytes.
44989
44990 @item tfree:@var{n}
44991 The number of bytes still unused in the buffer.
44992
44993 @item circular:@var{n}
44994 The value of the circular trace buffer flag. @code{1} means that the
44995 trace buffer is circular and old trace frames will be discarded if
44996 necessary to make room, @code{0} means that the trace buffer is linear
44997 and may fill up.
44998
44999 @item disconn:@var{n}
45000 The value of the disconnected tracing flag. @code{1} means that
45001 tracing will continue after @value{GDBN} disconnects, @code{0} means
45002 that the trace run will stop.
45003
45004 @end table
45005
45006 @item qTP:@var{tp}:@var{addr}
45007 @cindex tracepoint status, remote request
45008 @cindex @samp{qTP} packet
45009 Ask the stub for the current state of tracepoint number @var{tp} at
45010 address @var{addr}.
45011
45012 Replies:
45013 @table @samp
45014 @item V@var{hits}:@var{usage}
45015 The tracepoint has been hit @var{hits} times so far during the trace
45016 run, and accounts for @var{usage} in the trace buffer. Note that
45017 @code{while-stepping} steps are not counted as separate hits, but the
45018 steps' space consumption is added into the usage number.
45019
45020 @end table
45021
45022 @item qTV:@var{var}
45023 @cindex trace state variable value, remote request
45024 @cindex @samp{qTV} packet
45025 Ask the stub for the value of the trace state variable number @var{var}.
45026
45027 Replies:
45028 @table @samp
45029 @item V@var{value}
45030 The value of the variable is @var{value}. This will be the current
45031 value of the variable if the user is examining a running target, or a
45032 saved value if the variable was collected in the trace frame that the
45033 user is looking at. Note that multiple requests may result in
45034 different reply values, such as when requesting values while the
45035 program is running.
45036
45037 @item U
45038 The value of the variable is unknown. This would occur, for example,
45039 if the user is examining a trace frame in which the requested variable
45040 was not collected.
45041 @end table
45042
45043 @item qTfP
45044 @cindex @samp{qTfP} packet
45045 @itemx qTsP
45046 @cindex @samp{qTsP} packet
45047 These packets request data about tracepoints that are being used by
45048 the target. @value{GDBN} sends @code{qTfP} to get the first piece
45049 of data, and multiple @code{qTsP} to get additional pieces. Replies
45050 to these packets generally take the form of the @code{QTDP} packets
45051 that define tracepoints. (FIXME add detailed syntax)
45052
45053 @item qTfV
45054 @cindex @samp{qTfV} packet
45055 @itemx qTsV
45056 @cindex @samp{qTsV} packet
45057 These packets request data about trace state variables that are on the
45058 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
45059 and multiple @code{qTsV} to get additional variables. Replies to
45060 these packets follow the syntax of the @code{QTDV} packets that define
45061 trace state variables.
45062
45063 @item qTfSTM
45064 @itemx qTsSTM
45065 @anchor{qTfSTM}
45066 @anchor{qTsSTM}
45067 @cindex @samp{qTfSTM} packet
45068 @cindex @samp{qTsSTM} packet
45069 These packets request data about static tracepoint markers that exist
45070 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
45071 first piece of data, and multiple @code{qTsSTM} to get additional
45072 pieces. Replies to these packets take the following form:
45073
45074 Reply:
45075 @table @samp
45076 @item m @var{address}:@var{id}:@var{extra}
45077 A single marker
45078 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
45079 a comma-separated list of markers
45080 @item l
45081 (lower case letter @samp{L}) denotes end of list.
45082 @item E @var{nn}
45083 An error occurred. The error number @var{nn} is given as hex digits.
45084 @item @w{}
45085 An empty reply indicates that the request is not supported by the
45086 stub.
45087 @end table
45088
45089 The @var{address} is encoded in hex;
45090 @var{id} and @var{extra} are strings encoded in hex.
45091
45092 In response to each query, the target will reply with a list of one or
45093 more markers, separated by commas. @value{GDBN} will respond to each
45094 reply with a request for more markers (using the @samp{qs} form of the
45095 query), until the target responds with @samp{l} (lower-case ell, for
45096 @dfn{last}).
45097
45098 @item qTSTMat:@var{address}
45099 @anchor{qTSTMat}
45100 @cindex @samp{qTSTMat} packet
45101 This packets requests data about static tracepoint markers in the
45102 target program at @var{address}. Replies to this packet follow the
45103 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
45104 tracepoint markers.
45105
45106 @item QTSave:@var{filename}
45107 @cindex @samp{QTSave} packet
45108 This packet directs the target to save trace data to the file name
45109 @var{filename} in the target's filesystem. The @var{filename} is encoded
45110 as a hex string; the interpretation of the file name (relative vs
45111 absolute, wild cards, etc) is up to the target.
45112
45113 @item qTBuffer:@var{offset},@var{len}
45114 @cindex @samp{qTBuffer} packet
45115 Return up to @var{len} bytes of the current contents of trace buffer,
45116 starting at @var{offset}. The trace buffer is treated as if it were
45117 a contiguous collection of traceframes, as per the trace file format.
45118 The reply consists as many hex-encoded bytes as the target can deliver
45119 in a packet; it is not an error to return fewer than were asked for.
45120 A reply consisting of just @code{l} indicates that no bytes are
45121 available.
45122
45123 @item QTBuffer:circular:@var{value}
45124 This packet directs the target to use a circular trace buffer if
45125 @var{value} is 1, or a linear buffer if the value is 0.
45126
45127 @item QTBuffer:size:@var{size}
45128 @anchor{QTBuffer-size}
45129 @cindex @samp{QTBuffer size} packet
45130 This packet directs the target to make the trace buffer be of size
45131 @var{size} if possible. A value of @code{-1} tells the target to
45132 use whatever size it prefers.
45133
45134 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
45135 @cindex @samp{QTNotes} packet
45136 This packet adds optional textual notes to the trace run. Allowable
45137 types include @code{user}, @code{notes}, and @code{tstop}, the
45138 @var{text} fields are arbitrary strings, hex-encoded.
45139
45140 @end table
45141
45142 @subsection Relocate instruction reply packet
45143 When installing fast tracepoints in memory, the target may need to
45144 relocate the instruction currently at the tracepoint address to a
45145 different address in memory. For most instructions, a simple copy is
45146 enough, but, for example, call instructions that implicitly push the
45147 return address on the stack, and relative branches or other
45148 PC-relative instructions require offset adjustment, so that the effect
45149 of executing the instruction at a different address is the same as if
45150 it had executed in the original location.
45151
45152 In response to several of the tracepoint packets, the target may also
45153 respond with a number of intermediate @samp{qRelocInsn} request
45154 packets before the final result packet, to have @value{GDBN} handle
45155 this relocation operation. If a packet supports this mechanism, its
45156 documentation will explicitly say so. See for example the above
45157 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
45158 format of the request is:
45159
45160 @table @samp
45161 @item qRelocInsn:@var{from};@var{to}
45162
45163 This requests @value{GDBN} to copy instruction at address @var{from}
45164 to address @var{to}, possibly adjusted so that executing the
45165 instruction at @var{to} has the same effect as executing it at
45166 @var{from}. @value{GDBN} writes the adjusted instruction to target
45167 memory starting at @var{to}.
45168 @end table
45169
45170 Replies:
45171 @table @samp
45172 @item qRelocInsn:@var{adjusted_size}
45173 Informs the stub the relocation is complete. The @var{adjusted_size} is
45174 the length in bytes of resulting relocated instruction sequence.
45175 @item E @var{NN}
45176 A badly formed request was detected, or an error was encountered while
45177 relocating the instruction.
45178 @end table
45179
45180 @node Host I/O Packets
45181 @section Host I/O Packets
45182 @cindex Host I/O, remote protocol
45183 @cindex file transfer, remote protocol
45184
45185 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
45186 operations on the far side of a remote link. For example, Host I/O is
45187 used to upload and download files to a remote target with its own
45188 filesystem. Host I/O uses the same constant values and data structure
45189 layout as the target-initiated File-I/O protocol. However, the
45190 Host I/O packets are structured differently. The target-initiated
45191 protocol relies on target memory to store parameters and buffers.
45192 Host I/O requests are initiated by @value{GDBN}, and the
45193 target's memory is not involved. @xref{File-I/O Remote Protocol
45194 Extension}, for more details on the target-initiated protocol.
45195
45196 The Host I/O request packets all encode a single operation along with
45197 its arguments. They have this format:
45198
45199 @table @samp
45200
45201 @item vFile:@var{operation}: @var{parameter}@dots{}
45202 @var{operation} is the name of the particular request; the target
45203 should compare the entire packet name up to the second colon when checking
45204 for a supported operation. The format of @var{parameter} depends on
45205 the operation. Numbers are always passed in hexadecimal. Negative
45206 numbers have an explicit minus sign (i.e.@: two's complement is not
45207 used). Strings (e.g.@: filenames) are encoded as a series of
45208 hexadecimal bytes. The last argument to a system call may be a
45209 buffer of escaped binary data (@pxref{Binary Data}).
45210
45211 @end table
45212
45213 The valid responses to Host I/O packets are:
45214
45215 @table @samp
45216
45217 @item F @var{result} [, @var{errno}] [; @var{attachment}]
45218 @var{result} is the integer value returned by this operation, usually
45219 non-negative for success and -1 for errors. If an error has occured,
45220 @var{errno} will be included in the result specifying a
45221 value defined by the File-I/O protocol (@pxref{Errno Values}). For
45222 operations which return data, @var{attachment} supplies the data as a
45223 binary buffer. Binary buffers in response packets are escaped in the
45224 normal way (@pxref{Binary Data}). See the individual packet
45225 documentation for the interpretation of @var{result} and
45226 @var{attachment}.
45227
45228 @item @w{}
45229 An empty response indicates that this operation is not recognized.
45230
45231 @end table
45232
45233 These are the supported Host I/O operations:
45234
45235 @table @samp
45236 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
45237 Open a file at @var{filename} and return a file descriptor for it, or
45238 return -1 if an error occurs. The @var{filename} is a string,
45239 @var{flags} is an integer indicating a mask of open flags
45240 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
45241 of mode bits to use if the file is created (@pxref{mode_t Values}).
45242 @xref{open}, for details of the open flags and mode values.
45243
45244 @item vFile:close: @var{fd}
45245 Close the open file corresponding to @var{fd} and return 0, or
45246 -1 if an error occurs.
45247
45248 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
45249 Read data from the open file corresponding to @var{fd}. Up to
45250 @var{count} bytes will be read from the file, starting at @var{offset}
45251 relative to the start of the file. The target may read fewer bytes;
45252 common reasons include packet size limits and an end-of-file
45253 condition. The number of bytes read is returned. Zero should only be
45254 returned for a successful read at the end of the file, or if
45255 @var{count} was zero.
45256
45257 The data read should be returned as a binary attachment on success.
45258 If zero bytes were read, the response should include an empty binary
45259 attachment (i.e.@: a trailing semicolon). The return value is the
45260 number of target bytes read; the binary attachment may be longer if
45261 some characters were escaped.
45262
45263 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
45264 Write @var{data} (a binary buffer) to the open file corresponding
45265 to @var{fd}. Start the write at @var{offset} from the start of the
45266 file. Unlike many @code{write} system calls, there is no
45267 separate @var{count} argument; the length of @var{data} in the
45268 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
45269 which may be shorter than the length of @var{data}, or -1 if an
45270 error occurred.
45271
45272 @item vFile:fstat: @var{fd}
45273 Get information about the open file corresponding to @var{fd}.
45274 On success the information is returned as a binary attachment
45275 and the return value is the size of this attachment in bytes.
45276 If an error occurs the return value is -1. The format of the
45277 returned binary attachment is as described in @ref{struct stat}.
45278
45279 @item vFile:unlink: @var{filename}
45280 Delete the file at @var{filename} on the target. Return 0,
45281 or -1 if an error occurs. The @var{filename} is a string.
45282
45283 @item vFile:readlink: @var{filename}
45284 Read value of symbolic link @var{filename} on the target. Return
45285 the number of bytes read, or -1 if an error occurs.
45286
45287 The data read should be returned as a binary attachment on success.
45288 If zero bytes were read, the response should include an empty binary
45289 attachment (i.e.@: a trailing semicolon). The return value is the
45290 number of target bytes read; the binary attachment may be longer if
45291 some characters were escaped.
45292
45293 @item vFile:setfs: @var{pid}
45294 Select the filesystem on which @code{vFile} operations with
45295 @var{filename} arguments will operate. This is required for
45296 @value{GDBN} to be able to access files on remote targets where
45297 the remote stub does not share a common filesystem with the
45298 inferior(s).
45299
45300 If @var{pid} is nonzero, select the filesystem as seen by process
45301 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
45302 the remote stub. Return 0 on success, or -1 if an error occurs.
45303 If @code{vFile:setfs:} indicates success, the selected filesystem
45304 remains selected until the next successful @code{vFile:setfs:}
45305 operation.
45306
45307 @end table
45308
45309 @node Interrupts
45310 @section Interrupts
45311 @cindex interrupts (remote protocol)
45312 @anchor{interrupting remote targets}
45313
45314 In all-stop mode, when a program on the remote target is running,
45315 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
45316 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
45317 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
45318
45319 The precise meaning of @code{BREAK} is defined by the transport
45320 mechanism and may, in fact, be undefined. @value{GDBN} does not
45321 currently define a @code{BREAK} mechanism for any of the network
45322 interfaces except for TCP, in which case @value{GDBN} sends the
45323 @code{telnet} BREAK sequence.
45324
45325 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
45326 transport mechanisms. It is represented by sending the single byte
45327 @code{0x03} without any of the usual packet overhead described in
45328 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
45329 transmitted as part of a packet, it is considered to be packet data
45330 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
45331 (@pxref{X packet}), used for binary downloads, may include an unescaped
45332 @code{0x03} as part of its packet.
45333
45334 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
45335 When Linux kernel receives this sequence from serial port,
45336 it stops execution and connects to gdb.
45337
45338 In non-stop mode, because packet resumptions are asynchronous
45339 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
45340 command to the remote stub, even when the target is running. For that
45341 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
45342 packet}) with the usual packet framing instead of the single byte
45343 @code{0x03}.
45344
45345 Stubs are not required to recognize these interrupt mechanisms and the
45346 precise meaning associated with receipt of the interrupt is
45347 implementation defined. If the target supports debugging of multiple
45348 threads and/or processes, it should attempt to interrupt all
45349 currently-executing threads and processes.
45350 If the stub is successful at interrupting the
45351 running program, it should send one of the stop
45352 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
45353 of successfully stopping the program in all-stop mode, and a stop reply
45354 for each stopped thread in non-stop mode.
45355 Interrupts received while the
45356 program is stopped are queued and the program will be interrupted when
45357 it is resumed next time.
45358
45359 @node Notification Packets
45360 @section Notification Packets
45361 @cindex notification packets
45362 @cindex packets, notification
45363
45364 The @value{GDBN} remote serial protocol includes @dfn{notifications},
45365 packets that require no acknowledgment. Both the GDB and the stub
45366 may send notifications (although the only notifications defined at
45367 present are sent by the stub). Notifications carry information
45368 without incurring the round-trip latency of an acknowledgment, and so
45369 are useful for low-impact communications where occasional packet loss
45370 is not a problem.
45371
45372 A notification packet has the form @samp{% @var{data} #
45373 @var{checksum}}, where @var{data} is the content of the notification,
45374 and @var{checksum} is a checksum of @var{data}, computed and formatted
45375 as for ordinary @value{GDBN} packets. A notification's @var{data}
45376 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
45377 receiving a notification, the recipient sends no @samp{+} or @samp{-}
45378 to acknowledge the notification's receipt or to report its corruption.
45379
45380 Every notification's @var{data} begins with a name, which contains no
45381 colon characters, followed by a colon character.
45382
45383 Recipients should silently ignore corrupted notifications and
45384 notifications they do not understand. Recipients should restart
45385 timeout periods on receipt of a well-formed notification, whether or
45386 not they understand it.
45387
45388 Senders should only send the notifications described here when this
45389 protocol description specifies that they are permitted. In the
45390 future, we may extend the protocol to permit existing notifications in
45391 new contexts; this rule helps older senders avoid confusing newer
45392 recipients.
45393
45394 (Older versions of @value{GDBN} ignore bytes received until they see
45395 the @samp{$} byte that begins an ordinary packet, so new stubs may
45396 transmit notifications without fear of confusing older clients. There
45397 are no notifications defined for @value{GDBN} to send at the moment, but we
45398 assume that most older stubs would ignore them, as well.)
45399
45400 Each notification is comprised of three parts:
45401 @table @samp
45402 @item @var{name}:@var{event}
45403 The notification packet is sent by the side that initiates the
45404 exchange (currently, only the stub does that), with @var{event}
45405 carrying the specific information about the notification, and
45406 @var{name} specifying the name of the notification.
45407 @item @var{ack}
45408 The acknowledge sent by the other side, usually @value{GDBN}, to
45409 acknowledge the exchange and request the event.
45410 @end table
45411
45412 The purpose of an asynchronous notification mechanism is to report to
45413 @value{GDBN} that something interesting happened in the remote stub.
45414
45415 The remote stub may send notification @var{name}:@var{event}
45416 at any time, but @value{GDBN} acknowledges the notification when
45417 appropriate. The notification event is pending before @value{GDBN}
45418 acknowledges. Only one notification at a time may be pending; if
45419 additional events occur before @value{GDBN} has acknowledged the
45420 previous notification, they must be queued by the stub for later
45421 synchronous transmission in response to @var{ack} packets from
45422 @value{GDBN}. Because the notification mechanism is unreliable,
45423 the stub is permitted to resend a notification if it believes
45424 @value{GDBN} may not have received it.
45425
45426 Specifically, notifications may appear when @value{GDBN} is not
45427 otherwise reading input from the stub, or when @value{GDBN} is
45428 expecting to read a normal synchronous response or a
45429 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
45430 Notification packets are distinct from any other communication from
45431 the stub so there is no ambiguity.
45432
45433 After receiving a notification, @value{GDBN} shall acknowledge it by
45434 sending a @var{ack} packet as a regular, synchronous request to the
45435 stub. Such acknowledgment is not required to happen immediately, as
45436 @value{GDBN} is permitted to send other, unrelated packets to the
45437 stub first, which the stub should process normally.
45438
45439 Upon receiving a @var{ack} packet, if the stub has other queued
45440 events to report to @value{GDBN}, it shall respond by sending a
45441 normal @var{event}. @value{GDBN} shall then send another @var{ack}
45442 packet to solicit further responses; again, it is permitted to send
45443 other, unrelated packets as well which the stub should process
45444 normally.
45445
45446 If the stub receives a @var{ack} packet and there are no additional
45447 @var{event} to report, the stub shall return an @samp{OK} response.
45448 At this point, @value{GDBN} has finished processing a notification
45449 and the stub has completed sending any queued events. @value{GDBN}
45450 won't accept any new notifications until the final @samp{OK} is
45451 received . If further notification events occur, the stub shall send
45452 a new notification, @value{GDBN} shall accept the notification, and
45453 the process shall be repeated.
45454
45455 The process of asynchronous notification can be illustrated by the
45456 following example:
45457 @smallexample
45458 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
45459 @code{...}
45460 -> @code{vStopped}
45461 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
45462 -> @code{vStopped}
45463 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
45464 -> @code{vStopped}
45465 <- @code{OK}
45466 @end smallexample
45467
45468 The following notifications are defined:
45469 @multitable @columnfractions 0.12 0.12 0.38 0.38
45470
45471 @item Notification
45472 @tab Ack
45473 @tab Event
45474 @tab Description
45475
45476 @item Stop
45477 @tab vStopped
45478 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
45479 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
45480 for information on how these notifications are acknowledged by
45481 @value{GDBN}.
45482 @tab Report an asynchronous stop event in non-stop mode.
45483
45484 @end multitable
45485
45486 @node Remote Non-Stop
45487 @section Remote Protocol Support for Non-Stop Mode
45488
45489 @value{GDBN}'s remote protocol supports non-stop debugging of
45490 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
45491 supports non-stop mode, it should report that to @value{GDBN} by including
45492 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
45493
45494 @value{GDBN} typically sends a @samp{QNonStop} packet only when
45495 establishing a new connection with the stub. Entering non-stop mode
45496 does not alter the state of any currently-running threads, but targets
45497 must stop all threads in any already-attached processes when entering
45498 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
45499 probe the target state after a mode change.
45500
45501 In non-stop mode, when an attached process encounters an event that
45502 would otherwise be reported with a stop reply, it uses the
45503 asynchronous notification mechanism (@pxref{Notification Packets}) to
45504 inform @value{GDBN}. In contrast to all-stop mode, where all threads
45505 in all processes are stopped when a stop reply is sent, in non-stop
45506 mode only the thread reporting the stop event is stopped. That is,
45507 when reporting a @samp{S} or @samp{T} response to indicate completion
45508 of a step operation, hitting a breakpoint, or a fault, only the
45509 affected thread is stopped; any other still-running threads continue
45510 to run. When reporting a @samp{W} or @samp{X} response, all running
45511 threads belonging to other attached processes continue to run.
45512
45513 In non-stop mode, the target shall respond to the @samp{?} packet as
45514 follows. First, any incomplete stop reply notification/@samp{vStopped}
45515 sequence in progress is abandoned. The target must begin a new
45516 sequence reporting stop events for all stopped threads, whether or not
45517 it has previously reported those events to @value{GDBN}. The first
45518 stop reply is sent as a synchronous reply to the @samp{?} packet, and
45519 subsequent stop replies are sent as responses to @samp{vStopped} packets
45520 using the mechanism described above. The target must not send
45521 asynchronous stop reply notifications until the sequence is complete.
45522 If all threads are running when the target receives the @samp{?} packet,
45523 or if the target is not attached to any process, it shall respond
45524 @samp{OK}.
45525
45526 If the stub supports non-stop mode, it should also support the
45527 @samp{swbreak} stop reason if software breakpoints are supported, and
45528 the @samp{hwbreak} stop reason if hardware breakpoints are supported
45529 (@pxref{swbreak stop reason}). This is because given the asynchronous
45530 nature of non-stop mode, between the time a thread hits a breakpoint
45531 and the time the event is finally processed by @value{GDBN}, the
45532 breakpoint may have already been removed from the target. Due to
45533 this, @value{GDBN} needs to be able to tell whether a trap stop was
45534 caused by a delayed breakpoint event, which should be ignored, as
45535 opposed to a random trap signal, which should be reported to the user.
45536 Note the @samp{swbreak} feature implies that the target is responsible
45537 for adjusting the PC when a software breakpoint triggers, if
45538 necessary, such as on the x86 architecture.
45539
45540 @node Packet Acknowledgment
45541 @section Packet Acknowledgment
45542
45543 @cindex acknowledgment, for @value{GDBN} remote
45544 @cindex packet acknowledgment, for @value{GDBN} remote
45545 By default, when either the host or the target machine receives a packet,
45546 the first response expected is an acknowledgment: either @samp{+} (to indicate
45547 the package was received correctly) or @samp{-} (to request retransmission).
45548 This mechanism allows the @value{GDBN} remote protocol to operate over
45549 unreliable transport mechanisms, such as a serial line.
45550
45551 In cases where the transport mechanism is itself reliable (such as a pipe or
45552 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
45553 It may be desirable to disable them in that case to reduce communication
45554 overhead, or for other reasons. This can be accomplished by means of the
45555 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
45556
45557 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
45558 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
45559 and response format still includes the normal checksum, as described in
45560 @ref{Overview}, but the checksum may be ignored by the receiver.
45561
45562 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
45563 no-acknowledgment mode, it should report that to @value{GDBN}
45564 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
45565 @pxref{qSupported}.
45566 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
45567 disabled via the @code{set remote noack-packet off} command
45568 (@pxref{Remote Configuration}),
45569 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
45570 Only then may the stub actually turn off packet acknowledgments.
45571 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
45572 response, which can be safely ignored by the stub.
45573
45574 Note that @code{set remote noack-packet} command only affects negotiation
45575 between @value{GDBN} and the stub when subsequent connections are made;
45576 it does not affect the protocol acknowledgment state for any current
45577 connection.
45578 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
45579 new connection is established,
45580 there is also no protocol request to re-enable the acknowledgments
45581 for the current connection, once disabled.
45582
45583 @node Examples
45584 @section Examples
45585
45586 Example sequence of a target being re-started. Notice how the restart
45587 does not get any direct output:
45588
45589 @smallexample
45590 -> @code{R00}
45591 <- @code{+}
45592 @emph{target restarts}
45593 -> @code{?}
45594 <- @code{+}
45595 <- @code{T001:1234123412341234}
45596 -> @code{+}
45597 @end smallexample
45598
45599 Example sequence of a target being stepped by a single instruction:
45600
45601 @smallexample
45602 -> @code{G1445@dots{}}
45603 <- @code{+}
45604 -> @code{s}
45605 <- @code{+}
45606 @emph{time passes}
45607 <- @code{T001:1234123412341234}
45608 -> @code{+}
45609 -> @code{g}
45610 <- @code{+}
45611 <- @code{1455@dots{}}
45612 -> @code{+}
45613 @end smallexample
45614
45615 @node File-I/O Remote Protocol Extension
45616 @section File-I/O Remote Protocol Extension
45617 @cindex File-I/O remote protocol extension
45618
45619 @menu
45620 * File-I/O Overview::
45621 * Protocol Basics::
45622 * The F Request Packet::
45623 * The F Reply Packet::
45624 * The Ctrl-C Message::
45625 * Console I/O::
45626 * List of Supported Calls::
45627 * Protocol-specific Representation of Datatypes::
45628 * Constants::
45629 * File-I/O Examples::
45630 @end menu
45631
45632 @node File-I/O Overview
45633 @subsection File-I/O Overview
45634 @cindex file-i/o overview
45635
45636 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
45637 target to use the host's file system and console I/O to perform various
45638 system calls. System calls on the target system are translated into a
45639 remote protocol packet to the host system, which then performs the needed
45640 actions and returns a response packet to the target system.
45641 This simulates file system operations even on targets that lack file systems.
45642
45643 The protocol is defined to be independent of both the host and target systems.
45644 It uses its own internal representation of datatypes and values. Both
45645 @value{GDBN} and the target's @value{GDBN} stub are responsible for
45646 translating the system-dependent value representations into the internal
45647 protocol representations when data is transmitted.
45648
45649 The communication is synchronous. A system call is possible only when
45650 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
45651 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
45652 the target is stopped to allow deterministic access to the target's
45653 memory. Therefore File-I/O is not interruptible by target signals. On
45654 the other hand, it is possible to interrupt File-I/O by a user interrupt
45655 (@samp{Ctrl-C}) within @value{GDBN}.
45656
45657 The target's request to perform a host system call does not finish
45658 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
45659 after finishing the system call, the target returns to continuing the
45660 previous activity (continue, step). No additional continue or step
45661 request from @value{GDBN} is required.
45662
45663 @smallexample
45664 (@value{GDBP}) continue
45665 <- target requests 'system call X'
45666 target is stopped, @value{GDBN} executes system call
45667 -> @value{GDBN} returns result
45668 ... target continues, @value{GDBN} returns to wait for the target
45669 <- target hits breakpoint and sends a Txx packet
45670 @end smallexample
45671
45672 The protocol only supports I/O on the console and to regular files on
45673 the host file system. Character or block special devices, pipes,
45674 named pipes, sockets or any other communication method on the host
45675 system are not supported by this protocol.
45676
45677 File I/O is not supported in non-stop mode.
45678
45679 @node Protocol Basics
45680 @subsection Protocol Basics
45681 @cindex protocol basics, file-i/o
45682
45683 The File-I/O protocol uses the @code{F} packet as the request as well
45684 as reply packet. Since a File-I/O system call can only occur when
45685 @value{GDBN} is waiting for a response from the continuing or stepping target,
45686 the File-I/O request is a reply that @value{GDBN} has to expect as a result
45687 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
45688 This @code{F} packet contains all information needed to allow @value{GDBN}
45689 to call the appropriate host system call:
45690
45691 @itemize @bullet
45692 @item
45693 A unique identifier for the requested system call.
45694
45695 @item
45696 All parameters to the system call. Pointers are given as addresses
45697 in the target memory address space. Pointers to strings are given as
45698 pointer/length pair. Numerical values are given as they are.
45699 Numerical control flags are given in a protocol-specific representation.
45700
45701 @end itemize
45702
45703 At this point, @value{GDBN} has to perform the following actions.
45704
45705 @itemize @bullet
45706 @item
45707 If the parameters include pointer values to data needed as input to a
45708 system call, @value{GDBN} requests this data from the target with a
45709 standard @code{m} packet request. This additional communication has to be
45710 expected by the target implementation and is handled as any other @code{m}
45711 packet.
45712
45713 @item
45714 @value{GDBN} translates all value from protocol representation to host
45715 representation as needed. Datatypes are coerced into the host types.
45716
45717 @item
45718 @value{GDBN} calls the system call.
45719
45720 @item
45721 It then coerces datatypes back to protocol representation.
45722
45723 @item
45724 If the system call is expected to return data in buffer space specified
45725 by pointer parameters to the call, the data is transmitted to the
45726 target using a @code{M} or @code{X} packet. This packet has to be expected
45727 by the target implementation and is handled as any other @code{M} or @code{X}
45728 packet.
45729
45730 @end itemize
45731
45732 Eventually @value{GDBN} replies with another @code{F} packet which contains all
45733 necessary information for the target to continue. This at least contains
45734
45735 @itemize @bullet
45736 @item
45737 Return value.
45738
45739 @item
45740 @code{errno}, if has been changed by the system call.
45741
45742 @item
45743 ``Ctrl-C'' flag.
45744
45745 @end itemize
45746
45747 After having done the needed type and value coercion, the target continues
45748 the latest continue or step action.
45749
45750 @node The F Request Packet
45751 @subsection The @code{F} Request Packet
45752 @cindex file-i/o request packet
45753 @cindex @code{F} request packet
45754
45755 The @code{F} request packet has the following format:
45756
45757 @table @samp
45758 @item F@var{call-id},@var{parameter@dots{}}
45759
45760 @var{call-id} is the identifier to indicate the host system call to be called.
45761 This is just the name of the function.
45762
45763 @var{parameter@dots{}} are the parameters to the system call.
45764 Parameters are hexadecimal integer values, either the actual values in case
45765 of scalar datatypes, pointers to target buffer space in case of compound
45766 datatypes and unspecified memory areas, or pointer/length pairs in case
45767 of string parameters. These are appended to the @var{call-id} as a
45768 comma-delimited list. All values are transmitted in ASCII
45769 string representation, pointer/length pairs separated by a slash.
45770
45771 @end table
45772
45773
45774
45775 @node The F Reply Packet
45776 @subsection The @code{F} Reply Packet
45777 @cindex file-i/o reply packet
45778 @cindex @code{F} reply packet
45779
45780 The @code{F} reply packet has the following format:
45781
45782 @table @samp
45783
45784 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
45785
45786 @var{retcode} is the return code of the system call as hexadecimal value.
45787
45788 @var{errno} is the @code{errno} set by the call, in protocol-specific
45789 representation.
45790 This parameter can be omitted if the call was successful.
45791
45792 @var{Ctrl-C flag} is only sent if the user requested a break. In this
45793 case, @var{errno} must be sent as well, even if the call was successful.
45794 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
45795
45796 @smallexample
45797 F0,0,C
45798 @end smallexample
45799
45800 @noindent
45801 or, if the call was interrupted before the host call has been performed:
45802
45803 @smallexample
45804 F-1,4,C
45805 @end smallexample
45806
45807 @noindent
45808 assuming 4 is the protocol-specific representation of @code{EINTR}.
45809
45810 @end table
45811
45812
45813 @node The Ctrl-C Message
45814 @subsection The @samp{Ctrl-C} Message
45815 @cindex ctrl-c message, in file-i/o protocol
45816
45817 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
45818 reply packet (@pxref{The F Reply Packet}),
45819 the target should behave as if it had
45820 gotten a break message. The meaning for the target is ``system call
45821 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
45822 (as with a break message) and return to @value{GDBN} with a @code{T02}
45823 packet.
45824
45825 It's important for the target to know in which
45826 state the system call was interrupted. There are two possible cases:
45827
45828 @itemize @bullet
45829 @item
45830 The system call hasn't been performed on the host yet.
45831
45832 @item
45833 The system call on the host has been finished.
45834
45835 @end itemize
45836
45837 These two states can be distinguished by the target by the value of the
45838 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
45839 call hasn't been performed. This is equivalent to the @code{EINTR} handling
45840 on POSIX systems. In any other case, the target may presume that the
45841 system call has been finished --- successfully or not --- and should behave
45842 as if the break message arrived right after the system call.
45843
45844 @value{GDBN} must behave reliably. If the system call has not been called
45845 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
45846 @code{errno} in the packet. If the system call on the host has been finished
45847 before the user requests a break, the full action must be finished by
45848 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
45849 The @code{F} packet may only be sent when either nothing has happened
45850 or the full action has been completed.
45851
45852 @node Console I/O
45853 @subsection Console I/O
45854 @cindex console i/o as part of file-i/o
45855
45856 By default and if not explicitly closed by the target system, the file
45857 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
45858 on the @value{GDBN} console is handled as any other file output operation
45859 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
45860 by @value{GDBN} so that after the target read request from file descriptor
45861 0 all following typing is buffered until either one of the following
45862 conditions is met:
45863
45864 @itemize @bullet
45865 @item
45866 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
45867 @code{read}
45868 system call is treated as finished.
45869
45870 @item
45871 The user presses @key{RET}. This is treated as end of input with a trailing
45872 newline.
45873
45874 @item
45875 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
45876 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
45877
45878 @end itemize
45879
45880 If the user has typed more characters than fit in the buffer given to
45881 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
45882 either another @code{read(0, @dots{})} is requested by the target, or debugging
45883 is stopped at the user's request.
45884
45885
45886 @node List of Supported Calls
45887 @subsection List of Supported Calls
45888 @cindex list of supported file-i/o calls
45889
45890 @menu
45891 * open::
45892 * close::
45893 * read::
45894 * write::
45895 * lseek::
45896 * rename::
45897 * unlink::
45898 * stat/fstat::
45899 * gettimeofday::
45900 * isatty::
45901 * system::
45902 @end menu
45903
45904 @node open
45905 @unnumberedsubsubsec open
45906 @cindex open, file-i/o system call
45907
45908 @table @asis
45909 @item Synopsis:
45910 @smallexample
45911 int open(const char *pathname, int flags);
45912 int open(const char *pathname, int flags, mode_t mode);
45913 @end smallexample
45914
45915 @item Request:
45916 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
45917
45918 @noindent
45919 @var{flags} is the bitwise @code{OR} of the following values:
45920
45921 @table @code
45922 @item O_CREAT
45923 If the file does not exist it will be created. The host
45924 rules apply as far as file ownership and time stamps
45925 are concerned.
45926
45927 @item O_EXCL
45928 When used with @code{O_CREAT}, if the file already exists it is
45929 an error and open() fails.
45930
45931 @item O_TRUNC
45932 If the file already exists and the open mode allows
45933 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
45934 truncated to zero length.
45935
45936 @item O_APPEND
45937 The file is opened in append mode.
45938
45939 @item O_RDONLY
45940 The file is opened for reading only.
45941
45942 @item O_WRONLY
45943 The file is opened for writing only.
45944
45945 @item O_RDWR
45946 The file is opened for reading and writing.
45947 @end table
45948
45949 @noindent
45950 Other bits are silently ignored.
45951
45952
45953 @noindent
45954 @var{mode} is the bitwise @code{OR} of the following values:
45955
45956 @table @code
45957 @item S_IRUSR
45958 User has read permission.
45959
45960 @item S_IWUSR
45961 User has write permission.
45962
45963 @item S_IRGRP
45964 Group has read permission.
45965
45966 @item S_IWGRP
45967 Group has write permission.
45968
45969 @item S_IROTH
45970 Others have read permission.
45971
45972 @item S_IWOTH
45973 Others have write permission.
45974 @end table
45975
45976 @noindent
45977 Other bits are silently ignored.
45978
45979
45980 @item Return value:
45981 @code{open} returns the new file descriptor or -1 if an error
45982 occurred.
45983
45984 @item Errors:
45985
45986 @table @code
45987 @item EEXIST
45988 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
45989
45990 @item EISDIR
45991 @var{pathname} refers to a directory.
45992
45993 @item EACCES
45994 The requested access is not allowed.
45995
45996 @item ENAMETOOLONG
45997 @var{pathname} was too long.
45998
45999 @item ENOENT
46000 A directory component in @var{pathname} does not exist.
46001
46002 @item ENODEV
46003 @var{pathname} refers to a device, pipe, named pipe or socket.
46004
46005 @item EROFS
46006 @var{pathname} refers to a file on a read-only filesystem and
46007 write access was requested.
46008
46009 @item EFAULT
46010 @var{pathname} is an invalid pointer value.
46011
46012 @item ENOSPC
46013 No space on device to create the file.
46014
46015 @item EMFILE
46016 The process already has the maximum number of files open.
46017
46018 @item ENFILE
46019 The limit on the total number of files open on the system
46020 has been reached.
46021
46022 @item EINTR
46023 The call was interrupted by the user.
46024 @end table
46025
46026 @end table
46027
46028 @node close
46029 @unnumberedsubsubsec close
46030 @cindex close, file-i/o system call
46031
46032 @table @asis
46033 @item Synopsis:
46034 @smallexample
46035 int close(int fd);
46036 @end smallexample
46037
46038 @item Request:
46039 @samp{Fclose,@var{fd}}
46040
46041 @item Return value:
46042 @code{close} returns zero on success, or -1 if an error occurred.
46043
46044 @item Errors:
46045
46046 @table @code
46047 @item EBADF
46048 @var{fd} isn't a valid open file descriptor.
46049
46050 @item EINTR
46051 The call was interrupted by the user.
46052 @end table
46053
46054 @end table
46055
46056 @node read
46057 @unnumberedsubsubsec read
46058 @cindex read, file-i/o system call
46059
46060 @table @asis
46061 @item Synopsis:
46062 @smallexample
46063 int read(int fd, void *buf, unsigned int count);
46064 @end smallexample
46065
46066 @item Request:
46067 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
46068
46069 @item Return value:
46070 On success, the number of bytes read is returned.
46071 Zero indicates end of file. If count is zero, read
46072 returns zero as well. On error, -1 is returned.
46073
46074 @item Errors:
46075
46076 @table @code
46077 @item EBADF
46078 @var{fd} is not a valid file descriptor or is not open for
46079 reading.
46080
46081 @item EFAULT
46082 @var{bufptr} is an invalid pointer value.
46083
46084 @item EINTR
46085 The call was interrupted by the user.
46086 @end table
46087
46088 @end table
46089
46090 @node write
46091 @unnumberedsubsubsec write
46092 @cindex write, file-i/o system call
46093
46094 @table @asis
46095 @item Synopsis:
46096 @smallexample
46097 int write(int fd, const void *buf, unsigned int count);
46098 @end smallexample
46099
46100 @item Request:
46101 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
46102
46103 @item Return value:
46104 On success, the number of bytes written are returned.
46105 Zero indicates nothing was written. On error, -1
46106 is returned.
46107
46108 @item Errors:
46109
46110 @table @code
46111 @item EBADF
46112 @var{fd} is not a valid file descriptor or is not open for
46113 writing.
46114
46115 @item EFAULT
46116 @var{bufptr} is an invalid pointer value.
46117
46118 @item EFBIG
46119 An attempt was made to write a file that exceeds the
46120 host-specific maximum file size allowed.
46121
46122 @item ENOSPC
46123 No space on device to write the data.
46124
46125 @item EINTR
46126 The call was interrupted by the user.
46127 @end table
46128
46129 @end table
46130
46131 @node lseek
46132 @unnumberedsubsubsec lseek
46133 @cindex lseek, file-i/o system call
46134
46135 @table @asis
46136 @item Synopsis:
46137 @smallexample
46138 long lseek (int fd, long offset, int flag);
46139 @end smallexample
46140
46141 @item Request:
46142 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
46143
46144 @var{flag} is one of:
46145
46146 @table @code
46147 @item SEEK_SET
46148 The offset is set to @var{offset} bytes.
46149
46150 @item SEEK_CUR
46151 The offset is set to its current location plus @var{offset}
46152 bytes.
46153
46154 @item SEEK_END
46155 The offset is set to the size of the file plus @var{offset}
46156 bytes.
46157 @end table
46158
46159 @item Return value:
46160 On success, the resulting unsigned offset in bytes from
46161 the beginning of the file is returned. Otherwise, a
46162 value of -1 is returned.
46163
46164 @item Errors:
46165
46166 @table @code
46167 @item EBADF
46168 @var{fd} is not a valid open file descriptor.
46169
46170 @item ESPIPE
46171 @var{fd} is associated with the @value{GDBN} console.
46172
46173 @item EINVAL
46174 @var{flag} is not a proper value.
46175
46176 @item EINTR
46177 The call was interrupted by the user.
46178 @end table
46179
46180 @end table
46181
46182 @node rename
46183 @unnumberedsubsubsec rename
46184 @cindex rename, file-i/o system call
46185
46186 @table @asis
46187 @item Synopsis:
46188 @smallexample
46189 int rename(const char *oldpath, const char *newpath);
46190 @end smallexample
46191
46192 @item Request:
46193 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
46194
46195 @item Return value:
46196 On success, zero is returned. On error, -1 is returned.
46197
46198 @item Errors:
46199
46200 @table @code
46201 @item EISDIR
46202 @var{newpath} is an existing directory, but @var{oldpath} is not a
46203 directory.
46204
46205 @item EEXIST
46206 @var{newpath} is a non-empty directory.
46207
46208 @item EBUSY
46209 @var{oldpath} or @var{newpath} is a directory that is in use by some
46210 process.
46211
46212 @item EINVAL
46213 An attempt was made to make a directory a subdirectory
46214 of itself.
46215
46216 @item ENOTDIR
46217 A component used as a directory in @var{oldpath} or new
46218 path is not a directory. Or @var{oldpath} is a directory
46219 and @var{newpath} exists but is not a directory.
46220
46221 @item EFAULT
46222 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
46223
46224 @item EACCES
46225 No access to the file or the path of the file.
46226
46227 @item ENAMETOOLONG
46228
46229 @var{oldpath} or @var{newpath} was too long.
46230
46231 @item ENOENT
46232 A directory component in @var{oldpath} or @var{newpath} does not exist.
46233
46234 @item EROFS
46235 The file is on a read-only filesystem.
46236
46237 @item ENOSPC
46238 The device containing the file has no room for the new
46239 directory entry.
46240
46241 @item EINTR
46242 The call was interrupted by the user.
46243 @end table
46244
46245 @end table
46246
46247 @node unlink
46248 @unnumberedsubsubsec unlink
46249 @cindex unlink, file-i/o system call
46250
46251 @table @asis
46252 @item Synopsis:
46253 @smallexample
46254 int unlink(const char *pathname);
46255 @end smallexample
46256
46257 @item Request:
46258 @samp{Funlink,@var{pathnameptr}/@var{len}}
46259
46260 @item Return value:
46261 On success, zero is returned. On error, -1 is returned.
46262
46263 @item Errors:
46264
46265 @table @code
46266 @item EACCES
46267 No access to the file or the path of the file.
46268
46269 @item EPERM
46270 The system does not allow unlinking of directories.
46271
46272 @item EBUSY
46273 The file @var{pathname} cannot be unlinked because it's
46274 being used by another process.
46275
46276 @item EFAULT
46277 @var{pathnameptr} is an invalid pointer value.
46278
46279 @item ENAMETOOLONG
46280 @var{pathname} was too long.
46281
46282 @item ENOENT
46283 A directory component in @var{pathname} does not exist.
46284
46285 @item ENOTDIR
46286 A component of the path is not a directory.
46287
46288 @item EROFS
46289 The file is on a read-only filesystem.
46290
46291 @item EINTR
46292 The call was interrupted by the user.
46293 @end table
46294
46295 @end table
46296
46297 @node stat/fstat
46298 @unnumberedsubsubsec stat/fstat
46299 @cindex fstat, file-i/o system call
46300 @cindex stat, file-i/o system call
46301
46302 @table @asis
46303 @item Synopsis:
46304 @smallexample
46305 int stat(const char *pathname, struct stat *buf);
46306 int fstat(int fd, struct stat *buf);
46307 @end smallexample
46308
46309 @item Request:
46310 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
46311 @samp{Ffstat,@var{fd},@var{bufptr}}
46312
46313 @item Return value:
46314 On success, zero is returned. On error, -1 is returned.
46315
46316 @item Errors:
46317
46318 @table @code
46319 @item EBADF
46320 @var{fd} is not a valid open file.
46321
46322 @item ENOENT
46323 A directory component in @var{pathname} does not exist or the
46324 path is an empty string.
46325
46326 @item ENOTDIR
46327 A component of the path is not a directory.
46328
46329 @item EFAULT
46330 @var{pathnameptr} is an invalid pointer value.
46331
46332 @item EACCES
46333 No access to the file or the path of the file.
46334
46335 @item ENAMETOOLONG
46336 @var{pathname} was too long.
46337
46338 @item EINTR
46339 The call was interrupted by the user.
46340 @end table
46341
46342 @end table
46343
46344 @node gettimeofday
46345 @unnumberedsubsubsec gettimeofday
46346 @cindex gettimeofday, file-i/o system call
46347
46348 @table @asis
46349 @item Synopsis:
46350 @smallexample
46351 int gettimeofday(struct timeval *tv, void *tz);
46352 @end smallexample
46353
46354 @item Request:
46355 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
46356
46357 @item Return value:
46358 On success, 0 is returned, -1 otherwise.
46359
46360 @item Errors:
46361
46362 @table @code
46363 @item EINVAL
46364 @var{tz} is a non-NULL pointer.
46365
46366 @item EFAULT
46367 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
46368 @end table
46369
46370 @end table
46371
46372 @node isatty
46373 @unnumberedsubsubsec isatty
46374 @cindex isatty, file-i/o system call
46375
46376 @table @asis
46377 @item Synopsis:
46378 @smallexample
46379 int isatty(int fd);
46380 @end smallexample
46381
46382 @item Request:
46383 @samp{Fisatty,@var{fd}}
46384
46385 @item Return value:
46386 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
46387
46388 @item Errors:
46389
46390 @table @code
46391 @item EINTR
46392 The call was interrupted by the user.
46393 @end table
46394
46395 @end table
46396
46397 Note that the @code{isatty} call is treated as a special case: it returns
46398 1 to the target if the file descriptor is attached
46399 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
46400 would require implementing @code{ioctl} and would be more complex than
46401 needed.
46402
46403
46404 @node system
46405 @unnumberedsubsubsec system
46406 @cindex system, file-i/o system call
46407
46408 @table @asis
46409 @item Synopsis:
46410 @smallexample
46411 int system(const char *command);
46412 @end smallexample
46413
46414 @item Request:
46415 @samp{Fsystem,@var{commandptr}/@var{len}}
46416
46417 @item Return value:
46418 If @var{len} is zero, the return value indicates whether a shell is
46419 available. A zero return value indicates a shell is not available.
46420 For non-zero @var{len}, the value returned is -1 on error and the
46421 return status of the command otherwise. Only the exit status of the
46422 command is returned, which is extracted from the host's @code{system}
46423 return value by calling @code{WEXITSTATUS(retval)}. In case
46424 @file{/bin/sh} could not be executed, 127 is returned.
46425
46426 @item Errors:
46427
46428 @table @code
46429 @item EINTR
46430 The call was interrupted by the user.
46431 @end table
46432
46433 @end table
46434
46435 @value{GDBN} takes over the full task of calling the necessary host calls
46436 to perform the @code{system} call. The return value of @code{system} on
46437 the host is simplified before it's returned
46438 to the target. Any termination signal information from the child process
46439 is discarded, and the return value consists
46440 entirely of the exit status of the called command.
46441
46442 Due to security concerns, the @code{system} call is by default refused
46443 by @value{GDBN}. The user has to allow this call explicitly with the
46444 @code{set remote system-call-allowed 1} command.
46445
46446 @table @code
46447 @item set remote system-call-allowed
46448 @kindex set remote system-call-allowed
46449 Control whether to allow the @code{system} calls in the File I/O
46450 protocol for the remote target. The default is zero (disabled).
46451
46452 @item show remote system-call-allowed
46453 @kindex show remote system-call-allowed
46454 Show whether the @code{system} calls are allowed in the File I/O
46455 protocol.
46456 @end table
46457
46458 @node Protocol-specific Representation of Datatypes
46459 @subsection Protocol-specific Representation of Datatypes
46460 @cindex protocol-specific representation of datatypes, in file-i/o protocol
46461
46462 @menu
46463 * Integral Datatypes::
46464 * Pointer Values::
46465 * Memory Transfer::
46466 * struct stat::
46467 * struct timeval::
46468 @end menu
46469
46470 @node Integral Datatypes
46471 @unnumberedsubsubsec Integral Datatypes
46472 @cindex integral datatypes, in file-i/o protocol
46473
46474 The integral datatypes used in the system calls are @code{int},
46475 @code{unsigned int}, @code{long}, @code{unsigned long},
46476 @code{mode_t}, and @code{time_t}.
46477
46478 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
46479 implemented as 32 bit values in this protocol.
46480
46481 @code{long} and @code{unsigned long} are implemented as 64 bit types.
46482
46483 @xref{Limits}, for corresponding MIN and MAX values (similar to those
46484 in @file{limits.h}) to allow range checking on host and target.
46485
46486 @code{time_t} datatypes are defined as seconds since the Epoch.
46487
46488 All integral datatypes transferred as part of a memory read or write of a
46489 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
46490 byte order.
46491
46492 @node Pointer Values
46493 @unnumberedsubsubsec Pointer Values
46494 @cindex pointer values, in file-i/o protocol
46495
46496 Pointers to target data are transmitted as they are. An exception
46497 is made for pointers to buffers for which the length isn't
46498 transmitted as part of the function call, namely strings. Strings
46499 are transmitted as a pointer/length pair, both as hex values, e.g.@:
46500
46501 @smallexample
46502 @code{1aaf/12}
46503 @end smallexample
46504
46505 @noindent
46506 which is a pointer to data of length 18 bytes at position 0x1aaf.
46507 The length is defined as the full string length in bytes, including
46508 the trailing null byte. For example, the string @code{"hello world"}
46509 at address 0x123456 is transmitted as
46510
46511 @smallexample
46512 @code{123456/d}
46513 @end smallexample
46514
46515 @node Memory Transfer
46516 @unnumberedsubsubsec Memory Transfer
46517 @cindex memory transfer, in file-i/o protocol
46518
46519 Structured data which is transferred using a memory read or write (for
46520 example, a @code{struct stat}) is expected to be in a protocol-specific format
46521 with all scalar multibyte datatypes being big endian. Translation to
46522 this representation needs to be done both by the target before the @code{F}
46523 packet is sent, and by @value{GDBN} before
46524 it transfers memory to the target. Transferred pointers to structured
46525 data should point to the already-coerced data at any time.
46526
46527
46528 @node struct stat
46529 @unnumberedsubsubsec struct stat
46530 @cindex struct stat, in file-i/o protocol
46531
46532 The buffer of type @code{struct stat} used by the target and @value{GDBN}
46533 is defined as follows:
46534
46535 @smallexample
46536 struct stat @{
46537 unsigned int st_dev; /* device */
46538 unsigned int st_ino; /* inode */
46539 mode_t st_mode; /* protection */
46540 unsigned int st_nlink; /* number of hard links */
46541 unsigned int st_uid; /* user ID of owner */
46542 unsigned int st_gid; /* group ID of owner */
46543 unsigned int st_rdev; /* device type (if inode device) */
46544 unsigned long st_size; /* total size, in bytes */
46545 unsigned long st_blksize; /* blocksize for filesystem I/O */
46546 unsigned long st_blocks; /* number of blocks allocated */
46547 time_t st_atime; /* time of last access */
46548 time_t st_mtime; /* time of last modification */
46549 time_t st_ctime; /* time of last change */
46550 @};
46551 @end smallexample
46552
46553 The integral datatypes conform to the definitions given in the
46554 appropriate section (see @ref{Integral Datatypes}, for details) so this
46555 structure is of size 64 bytes.
46556
46557 The values of several fields have a restricted meaning and/or
46558 range of values.
46559
46560 @table @code
46561
46562 @item st_dev
46563 A value of 0 represents a file, 1 the console.
46564
46565 @item st_ino
46566 No valid meaning for the target. Transmitted unchanged.
46567
46568 @item st_mode
46569 Valid mode bits are described in @ref{Constants}. Any other
46570 bits have currently no meaning for the target.
46571
46572 @item st_uid
46573 @itemx st_gid
46574 @itemx st_rdev
46575 No valid meaning for the target. Transmitted unchanged.
46576
46577 @item st_atime
46578 @itemx st_mtime
46579 @itemx st_ctime
46580 These values have a host and file system dependent
46581 accuracy. Especially on Windows hosts, the file system may not
46582 support exact timing values.
46583 @end table
46584
46585 The target gets a @code{struct stat} of the above representation and is
46586 responsible for coercing it to the target representation before
46587 continuing.
46588
46589 Note that due to size differences between the host, target, and protocol
46590 representations of @code{struct stat} members, these members could eventually
46591 get truncated on the target.
46592
46593 @node struct timeval
46594 @unnumberedsubsubsec struct timeval
46595 @cindex struct timeval, in file-i/o protocol
46596
46597 The buffer of type @code{struct timeval} used by the File-I/O protocol
46598 is defined as follows:
46599
46600 @smallexample
46601 struct timeval @{
46602 time_t tv_sec; /* second */
46603 long tv_usec; /* microsecond */
46604 @};
46605 @end smallexample
46606
46607 The integral datatypes conform to the definitions given in the
46608 appropriate section (see @ref{Integral Datatypes}, for details) so this
46609 structure is of size 8 bytes.
46610
46611 @node Constants
46612 @subsection Constants
46613 @cindex constants, in file-i/o protocol
46614
46615 The following values are used for the constants inside of the
46616 protocol. @value{GDBN} and target are responsible for translating these
46617 values before and after the call as needed.
46618
46619 @menu
46620 * Open Flags::
46621 * mode_t Values::
46622 * Errno Values::
46623 * Lseek Flags::
46624 * Limits::
46625 @end menu
46626
46627 @node Open Flags
46628 @unnumberedsubsubsec Open Flags
46629 @cindex open flags, in file-i/o protocol
46630
46631 All values are given in hexadecimal representation.
46632
46633 @smallexample
46634 O_RDONLY 0x0
46635 O_WRONLY 0x1
46636 O_RDWR 0x2
46637 O_APPEND 0x8
46638 O_CREAT 0x200
46639 O_TRUNC 0x400
46640 O_EXCL 0x800
46641 @end smallexample
46642
46643 @node mode_t Values
46644 @unnumberedsubsubsec mode_t Values
46645 @cindex mode_t values, in file-i/o protocol
46646
46647 All values are given in octal representation.
46648
46649 @smallexample
46650 S_IFREG 0100000
46651 S_IFDIR 040000
46652 S_IRUSR 0400
46653 S_IWUSR 0200
46654 S_IXUSR 0100
46655 S_IRGRP 040
46656 S_IWGRP 020
46657 S_IXGRP 010
46658 S_IROTH 04
46659 S_IWOTH 02
46660 S_IXOTH 01
46661 @end smallexample
46662
46663 @node Errno Values
46664 @unnumberedsubsubsec Errno Values
46665 @cindex errno values, in file-i/o protocol
46666
46667 All values are given in decimal representation.
46668
46669 @smallexample
46670 EPERM 1
46671 ENOENT 2
46672 EINTR 4
46673 EBADF 9
46674 EACCES 13
46675 EFAULT 14
46676 EBUSY 16
46677 EEXIST 17
46678 ENODEV 19
46679 ENOTDIR 20
46680 EISDIR 21
46681 EINVAL 22
46682 ENFILE 23
46683 EMFILE 24
46684 EFBIG 27
46685 ENOSPC 28
46686 ESPIPE 29
46687 EROFS 30
46688 ENAMETOOLONG 91
46689 EUNKNOWN 9999
46690 @end smallexample
46691
46692 @code{EUNKNOWN} is used as a fallback error value if a host system returns
46693 any error value not in the list of supported error numbers.
46694
46695 @node Lseek Flags
46696 @unnumberedsubsubsec Lseek Flags
46697 @cindex lseek flags, in file-i/o protocol
46698
46699 @smallexample
46700 SEEK_SET 0
46701 SEEK_CUR 1
46702 SEEK_END 2
46703 @end smallexample
46704
46705 @node Limits
46706 @unnumberedsubsubsec Limits
46707 @cindex limits, in file-i/o protocol
46708
46709 All values are given in decimal representation.
46710
46711 @smallexample
46712 INT_MIN -2147483648
46713 INT_MAX 2147483647
46714 UINT_MAX 4294967295
46715 LONG_MIN -9223372036854775808
46716 LONG_MAX 9223372036854775807
46717 ULONG_MAX 18446744073709551615
46718 @end smallexample
46719
46720 @node File-I/O Examples
46721 @subsection File-I/O Examples
46722 @cindex file-i/o examples
46723
46724 Example sequence of a write call, file descriptor 3, buffer is at target
46725 address 0x1234, 6 bytes should be written:
46726
46727 @smallexample
46728 <- @code{Fwrite,3,1234,6}
46729 @emph{request memory read from target}
46730 -> @code{m1234,6}
46731 <- XXXXXX
46732 @emph{return "6 bytes written"}
46733 -> @code{F6}
46734 @end smallexample
46735
46736 Example sequence of a read call, file descriptor 3, buffer is at target
46737 address 0x1234, 6 bytes should be read:
46738
46739 @smallexample
46740 <- @code{Fread,3,1234,6}
46741 @emph{request memory write to target}
46742 -> @code{X1234,6:XXXXXX}
46743 @emph{return "6 bytes read"}
46744 -> @code{F6}
46745 @end smallexample
46746
46747 Example sequence of a read call, call fails on the host due to invalid
46748 file descriptor (@code{EBADF}):
46749
46750 @smallexample
46751 <- @code{Fread,3,1234,6}
46752 -> @code{F-1,9}
46753 @end smallexample
46754
46755 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
46756 host is called:
46757
46758 @smallexample
46759 <- @code{Fread,3,1234,6}
46760 -> @code{F-1,4,C}
46761 <- @code{T02}
46762 @end smallexample
46763
46764 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
46765 host is called:
46766
46767 @smallexample
46768 <- @code{Fread,3,1234,6}
46769 -> @code{X1234,6:XXXXXX}
46770 <- @code{T02}
46771 @end smallexample
46772
46773 @node Library List Format
46774 @section Library List Format
46775 @cindex library list format, remote protocol
46776
46777 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
46778 same process as your application to manage libraries. In this case,
46779 @value{GDBN} can use the loader's symbol table and normal memory
46780 operations to maintain a list of shared libraries. On other
46781 platforms, the operating system manages loaded libraries.
46782 @value{GDBN} can not retrieve the list of currently loaded libraries
46783 through memory operations, so it uses the @samp{qXfer:libraries:read}
46784 packet (@pxref{qXfer library list read}) instead. The remote stub
46785 queries the target's operating system and reports which libraries
46786 are loaded.
46787
46788 The @samp{qXfer:libraries:read} packet returns an XML document which
46789 lists loaded libraries and their offsets. Each library has an
46790 associated name and one or more segment or section base addresses,
46791 which report where the library was loaded in memory.
46792
46793 For the common case of libraries that are fully linked binaries, the
46794 library should have a list of segments. If the target supports
46795 dynamic linking of a relocatable object file, its library XML element
46796 should instead include a list of allocated sections. The segment or
46797 section bases are start addresses, not relocation offsets; they do not
46798 depend on the library's link-time base addresses.
46799
46800 @value{GDBN} must be linked with the Expat library to support XML
46801 library lists. @xref{Expat}.
46802
46803 A simple memory map, with one loaded library relocated by a single
46804 offset, looks like this:
46805
46806 @smallexample
46807 <library-list>
46808 <library name="/lib/libc.so.6">
46809 <segment address="0x10000000"/>
46810 </library>
46811 </library-list>
46812 @end smallexample
46813
46814 Another simple memory map, with one loaded library with three
46815 allocated sections (.text, .data, .bss), looks like this:
46816
46817 @smallexample
46818 <library-list>
46819 <library name="sharedlib.o">
46820 <section address="0x10000000"/>
46821 <section address="0x20000000"/>
46822 <section address="0x30000000"/>
46823 </library>
46824 </library-list>
46825 @end smallexample
46826
46827 The format of a library list is described by this DTD:
46828
46829 @smallexample
46830 <!-- library-list: Root element with versioning -->
46831 <!ELEMENT library-list (library)*>
46832 <!ATTLIST library-list version CDATA #FIXED "1.0">
46833 <!ELEMENT library (segment*, section*)>
46834 <!ATTLIST library name CDATA #REQUIRED>
46835 <!ELEMENT segment EMPTY>
46836 <!ATTLIST segment address CDATA #REQUIRED>
46837 <!ELEMENT section EMPTY>
46838 <!ATTLIST section address CDATA #REQUIRED>
46839 @end smallexample
46840
46841 In addition, segments and section descriptors cannot be mixed within a
46842 single library element, and you must supply at least one segment or
46843 section for each library.
46844
46845 @node Library List Format for SVR4 Targets
46846 @section Library List Format for SVR4 Targets
46847 @cindex library list format, remote protocol
46848
46849 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
46850 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
46851 shared libraries. Still a special library list provided by this packet is
46852 more efficient for the @value{GDBN} remote protocol.
46853
46854 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
46855 loaded libraries and their SVR4 linker parameters. For each library on SVR4
46856 target, the following parameters are reported:
46857
46858 @itemize @minus
46859 @item
46860 @code{name}, the absolute file name from the @code{l_name} field of
46861 @code{struct link_map}.
46862 @item
46863 @code{lm} with address of @code{struct link_map} used for TLS
46864 (Thread Local Storage) access.
46865 @item
46866 @code{l_addr}, the displacement as read from the field @code{l_addr} of
46867 @code{struct link_map}. For prelinked libraries this is not an absolute
46868 memory address. It is a displacement of absolute memory address against
46869 address the file was prelinked to during the library load.
46870 @item
46871 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
46872 @item
46873 @code{lmid}, which is an identifier for a linker namespace, such as
46874 the memory address of the @code{r_debug} object that contains this
46875 namespace's load map or the namespace identifier returned by
46876 @code{dlinfo (3)}.
46877 @end itemize
46878
46879 Additionally the single @code{main-lm} attribute specifies address of
46880 @code{struct link_map} used for the main executable. This parameter is used
46881 for TLS access and its presence is optional.
46882
46883 @value{GDBN} must be linked with the Expat library to support XML
46884 SVR4 library lists. @xref{Expat}.
46885
46886 A simple memory map, with two loaded libraries (which do not use prelink),
46887 looks like this:
46888
46889 @smallexample
46890 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
46891 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
46892 l_ld="0xe4eefc" lmid="0xfffe0"/>
46893 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
46894 l_ld="0x152350" lmid="0xfffe0"/>
46895 </library-list-svr>
46896 @end smallexample
46897
46898 The format of an SVR4 library list is described by this DTD:
46899
46900 @smallexample
46901 <!-- library-list-svr4: Root element with versioning -->
46902 <!ELEMENT library-list-svr4 (library)*>
46903 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
46904 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
46905 <!ELEMENT library EMPTY>
46906 <!ATTLIST library name CDATA #REQUIRED>
46907 <!ATTLIST library lm CDATA #REQUIRED>
46908 <!ATTLIST library l_addr CDATA #REQUIRED>
46909 <!ATTLIST library l_ld CDATA #REQUIRED>
46910 <!ATTLIST library lmid CDATA #IMPLIED>
46911 @end smallexample
46912
46913 @node Memory Map Format
46914 @section Memory Map Format
46915 @cindex memory map format
46916
46917 To be able to write into flash memory, @value{GDBN} needs to obtain a
46918 memory map from the target. This section describes the format of the
46919 memory map.
46920
46921 The memory map is obtained using the @samp{qXfer:memory-map:read}
46922 (@pxref{qXfer memory map read}) packet and is an XML document that
46923 lists memory regions.
46924
46925 @value{GDBN} must be linked with the Expat library to support XML
46926 memory maps. @xref{Expat}.
46927
46928 The top-level structure of the document is shown below:
46929
46930 @smallexample
46931 <?xml version="1.0"?>
46932 <!DOCTYPE memory-map
46933 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
46934 "http://sourceware.org/gdb/gdb-memory-map.dtd">
46935 <memory-map>
46936 region...
46937 </memory-map>
46938 @end smallexample
46939
46940 Each region can be either:
46941
46942 @itemize
46943
46944 @item
46945 A region of RAM starting at @var{addr} and extending for @var{length}
46946 bytes from there:
46947
46948 @smallexample
46949 <memory type="ram" start="@var{addr}" length="@var{length}"/>
46950 @end smallexample
46951
46952
46953 @item
46954 A region of read-only memory:
46955
46956 @smallexample
46957 <memory type="rom" start="@var{addr}" length="@var{length}"/>
46958 @end smallexample
46959
46960
46961 @item
46962 A region of flash memory, with erasure blocks @var{blocksize}
46963 bytes in length:
46964
46965 @smallexample
46966 <memory type="flash" start="@var{addr}" length="@var{length}">
46967 <property name="blocksize">@var{blocksize}</property>
46968 </memory>
46969 @end smallexample
46970
46971 @end itemize
46972
46973 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
46974 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
46975 packets to write to addresses in such ranges.
46976
46977 The formal DTD for memory map format is given below:
46978
46979 @smallexample
46980 <!-- ................................................... -->
46981 <!-- Memory Map XML DTD ................................ -->
46982 <!-- File: memory-map.dtd .............................. -->
46983 <!-- .................................... .............. -->
46984 <!-- memory-map.dtd -->
46985 <!-- memory-map: Root element with versioning -->
46986 <!ELEMENT memory-map (memory)*>
46987 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
46988 <!ELEMENT memory (property)*>
46989 <!-- memory: Specifies a memory region,
46990 and its type, or device. -->
46991 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
46992 start CDATA #REQUIRED
46993 length CDATA #REQUIRED>
46994 <!-- property: Generic attribute tag -->
46995 <!ELEMENT property (#PCDATA | property)*>
46996 <!ATTLIST property name (blocksize) #REQUIRED>
46997 @end smallexample
46998
46999 @node Thread List Format
47000 @section Thread List Format
47001 @cindex thread list format
47002
47003 To efficiently update the list of threads and their attributes,
47004 @value{GDBN} issues the @samp{qXfer:threads:read} packet
47005 (@pxref{qXfer threads read}) and obtains the XML document with
47006 the following structure:
47007
47008 @smallexample
47009 <?xml version="1.0"?>
47010 <threads>
47011 <thread id="id" core="0" name="name">
47012 ... description ...
47013 </thread>
47014 </threads>
47015 @end smallexample
47016
47017 Each @samp{thread} element must have the @samp{id} attribute that
47018 identifies the thread (@pxref{thread-id syntax}). The
47019 @samp{core} attribute, if present, specifies which processor core
47020 the thread was last executing on. The @samp{name} attribute, if
47021 present, specifies the human-readable name of the thread. The content
47022 of the of @samp{thread} element is interpreted as human-readable
47023 auxiliary information. The @samp{handle} attribute, if present,
47024 is a hex encoded representation of the thread handle.
47025
47026
47027 @node Traceframe Info Format
47028 @section Traceframe Info Format
47029 @cindex traceframe info format
47030
47031 To be able to know which objects in the inferior can be examined when
47032 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
47033 memory ranges, registers and trace state variables that have been
47034 collected in a traceframe.
47035
47036 This list is obtained using the @samp{qXfer:traceframe-info:read}
47037 (@pxref{qXfer traceframe info read}) packet and is an XML document.
47038
47039 @value{GDBN} must be linked with the Expat library to support XML
47040 traceframe info discovery. @xref{Expat}.
47041
47042 The top-level structure of the document is shown below:
47043
47044 @smallexample
47045 <?xml version="1.0"?>
47046 <!DOCTYPE traceframe-info
47047 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
47048 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
47049 <traceframe-info>
47050 block...
47051 </traceframe-info>
47052 @end smallexample
47053
47054 Each traceframe block can be either:
47055
47056 @itemize
47057
47058 @item
47059 A region of collected memory starting at @var{addr} and extending for
47060 @var{length} bytes from there:
47061
47062 @smallexample
47063 <memory start="@var{addr}" length="@var{length}"/>
47064 @end smallexample
47065
47066 @item
47067 A block indicating trace state variable numbered @var{number} has been
47068 collected:
47069
47070 @smallexample
47071 <tvar id="@var{number}"/>
47072 @end smallexample
47073
47074 @end itemize
47075
47076 The formal DTD for the traceframe info format is given below:
47077
47078 @smallexample
47079 <!ELEMENT traceframe-info (memory | tvar)* >
47080 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
47081
47082 <!ELEMENT memory EMPTY>
47083 <!ATTLIST memory start CDATA #REQUIRED
47084 length CDATA #REQUIRED>
47085 <!ELEMENT tvar>
47086 <!ATTLIST tvar id CDATA #REQUIRED>
47087 @end smallexample
47088
47089 @node Branch Trace Format
47090 @section Branch Trace Format
47091 @cindex branch trace format
47092
47093 In order to display the branch trace of an inferior thread,
47094 @value{GDBN} needs to obtain the list of branches. This list is
47095 represented as list of sequential code blocks that are connected via
47096 branches. The code in each block has been executed sequentially.
47097
47098 This list is obtained using the @samp{qXfer:btrace:read}
47099 (@pxref{qXfer btrace read}) packet and is an XML document.
47100
47101 @value{GDBN} must be linked with the Expat library to support XML
47102 traceframe info discovery. @xref{Expat}.
47103
47104 The top-level structure of the document is shown below:
47105
47106 @smallexample
47107 <?xml version="1.0"?>
47108 <!DOCTYPE btrace
47109 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
47110 "http://sourceware.org/gdb/gdb-btrace.dtd">
47111 <btrace>
47112 block...
47113 </btrace>
47114 @end smallexample
47115
47116 @itemize
47117
47118 @item
47119 A block of sequentially executed instructions starting at @var{begin}
47120 and ending at @var{end}:
47121
47122 @smallexample
47123 <block begin="@var{begin}" end="@var{end}"/>
47124 @end smallexample
47125
47126 @end itemize
47127
47128 The formal DTD for the branch trace format is given below:
47129
47130 @smallexample
47131 <!ELEMENT btrace (block* | pt) >
47132 <!ATTLIST btrace version CDATA #FIXED "1.0">
47133
47134 <!ELEMENT block EMPTY>
47135 <!ATTLIST block begin CDATA #REQUIRED
47136 end CDATA #REQUIRED>
47137
47138 <!ELEMENT pt (pt-config?, raw?)>
47139
47140 <!ELEMENT pt-config (cpu?)>
47141
47142 <!ELEMENT cpu EMPTY>
47143 <!ATTLIST cpu vendor CDATA #REQUIRED
47144 family CDATA #REQUIRED
47145 model CDATA #REQUIRED
47146 stepping CDATA #REQUIRED>
47147
47148 <!ELEMENT raw (#PCDATA)>
47149 @end smallexample
47150
47151 @node Branch Trace Configuration Format
47152 @section Branch Trace Configuration Format
47153 @cindex branch trace configuration format
47154
47155 For each inferior thread, @value{GDBN} can obtain the branch trace
47156 configuration using the @samp{qXfer:btrace-conf:read}
47157 (@pxref{qXfer btrace-conf read}) packet.
47158
47159 The configuration describes the branch trace format and configuration
47160 settings for that format. The following information is described:
47161
47162 @table @code
47163 @item bts
47164 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
47165 @table @code
47166 @item size
47167 The size of the @acronym{BTS} ring buffer in bytes.
47168 @end table
47169 @item pt
47170 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
47171 PT}) format.
47172 @table @code
47173 @item size
47174 The size of the @acronym{Intel PT} ring buffer in bytes.
47175 @end table
47176 @end table
47177
47178 @value{GDBN} must be linked with the Expat library to support XML
47179 branch trace configuration discovery. @xref{Expat}.
47180
47181 The formal DTD for the branch trace configuration format is given below:
47182
47183 @smallexample
47184 <!ELEMENT btrace-conf (bts?, pt?)>
47185 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
47186
47187 <!ELEMENT bts EMPTY>
47188 <!ATTLIST bts size CDATA #IMPLIED>
47189
47190 <!ELEMENT pt EMPTY>
47191 <!ATTLIST pt size CDATA #IMPLIED>
47192 @end smallexample
47193
47194 @include agentexpr.texi
47195
47196 @node Target Descriptions
47197 @appendix Target Descriptions
47198 @cindex target descriptions
47199
47200 One of the challenges of using @value{GDBN} to debug embedded systems
47201 is that there are so many minor variants of each processor
47202 architecture in use. It is common practice for vendors to start with
47203 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
47204 and then make changes to adapt it to a particular market niche. Some
47205 architectures have hundreds of variants, available from dozens of
47206 vendors. This leads to a number of problems:
47207
47208 @itemize @bullet
47209 @item
47210 With so many different customized processors, it is difficult for
47211 the @value{GDBN} maintainers to keep up with the changes.
47212 @item
47213 Since individual variants may have short lifetimes or limited
47214 audiences, it may not be worthwhile to carry information about every
47215 variant in the @value{GDBN} source tree.
47216 @item
47217 When @value{GDBN} does support the architecture of the embedded system
47218 at hand, the task of finding the correct architecture name to give the
47219 @command{set architecture} command can be error-prone.
47220 @end itemize
47221
47222 To address these problems, the @value{GDBN} remote protocol allows a
47223 target system to not only identify itself to @value{GDBN}, but to
47224 actually describe its own features. This lets @value{GDBN} support
47225 processor variants it has never seen before --- to the extent that the
47226 descriptions are accurate, and that @value{GDBN} understands them.
47227
47228 @value{GDBN} must be linked with the Expat library to support XML
47229 target descriptions. @xref{Expat}.
47230
47231 @menu
47232 * Retrieving Descriptions:: How descriptions are fetched from a target.
47233 * Target Description Format:: The contents of a target description.
47234 * Predefined Target Types:: Standard types available for target
47235 descriptions.
47236 * Enum Target Types:: How to define enum target types.
47237 * Standard Target Features:: Features @value{GDBN} knows about.
47238 @end menu
47239
47240 @node Retrieving Descriptions
47241 @section Retrieving Descriptions
47242
47243 Target descriptions can be read from the target automatically, or
47244 specified by the user manually. The default behavior is to read the
47245 description from the target. @value{GDBN} retrieves it via the remote
47246 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
47247 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
47248 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
47249 XML document, of the form described in @ref{Target Description
47250 Format}.
47251
47252 Alternatively, you can specify a file to read for the target description.
47253 If a file is set, the target will not be queried. The commands to
47254 specify a file are:
47255
47256 @table @code
47257 @cindex set tdesc filename
47258 @item set tdesc filename @var{path}
47259 Read the target description from @var{path}.
47260
47261 @cindex unset tdesc filename
47262 @item unset tdesc filename
47263 Do not read the XML target description from a file. @value{GDBN}
47264 will use the description supplied by the current target.
47265
47266 @cindex show tdesc filename
47267 @item show tdesc filename
47268 Show the filename to read for a target description, if any.
47269 @end table
47270
47271
47272 @node Target Description Format
47273 @section Target Description Format
47274 @cindex target descriptions, XML format
47275
47276 A target description annex is an @uref{http://www.w3.org/XML/, XML}
47277 document which complies with the Document Type Definition provided in
47278 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
47279 means you can use generally available tools like @command{xmllint} to
47280 check that your feature descriptions are well-formed and valid.
47281 However, to help people unfamiliar with XML write descriptions for
47282 their targets, we also describe the grammar here.
47283
47284 Target descriptions can identify the architecture of the remote target
47285 and (for some architectures) provide information about custom register
47286 sets. They can also identify the OS ABI of the remote target.
47287 @value{GDBN} can use this information to autoconfigure for your
47288 target, or to warn you if you connect to an unsupported target.
47289
47290 Here is a simple target description:
47291
47292 @smallexample
47293 <target version="1.0">
47294 <architecture>i386:x86-64</architecture>
47295 </target>
47296 @end smallexample
47297
47298 @noindent
47299 This minimal description only says that the target uses
47300 the x86-64 architecture.
47301
47302 A target description has the following overall form, with [ ] marking
47303 optional elements and @dots{} marking repeatable elements. The elements
47304 are explained further below.
47305
47306 @smallexample
47307 <?xml version="1.0"?>
47308 <!DOCTYPE target SYSTEM "gdb-target.dtd">
47309 <target version="1.0">
47310 @r{[}@var{architecture}@r{]}
47311 @r{[}@var{osabi}@r{]}
47312 @r{[}@var{compatible}@r{]}
47313 @r{[}@var{feature}@dots{}@r{]}
47314 </target>
47315 @end smallexample
47316
47317 @noindent
47318 The description is generally insensitive to whitespace and line
47319 breaks, under the usual common-sense rules. The XML version
47320 declaration and document type declaration can generally be omitted
47321 (@value{GDBN} does not require them), but specifying them may be
47322 useful for XML validation tools. The @samp{version} attribute for
47323 @samp{<target>} may also be omitted, but we recommend
47324 including it; if future versions of @value{GDBN} use an incompatible
47325 revision of @file{gdb-target.dtd}, they will detect and report
47326 the version mismatch.
47327
47328 @subsection Inclusion
47329 @cindex target descriptions, inclusion
47330 @cindex XInclude
47331 @ifnotinfo
47332 @cindex <xi:include>
47333 @end ifnotinfo
47334
47335 It can sometimes be valuable to split a target description up into
47336 several different annexes, either for organizational purposes, or to
47337 share files between different possible target descriptions. You can
47338 divide a description into multiple files by replacing any element of
47339 the target description with an inclusion directive of the form:
47340
47341 @smallexample
47342 <xi:include href="@var{document}"/>
47343 @end smallexample
47344
47345 @noindent
47346 When @value{GDBN} encounters an element of this form, it will retrieve
47347 the named XML @var{document}, and replace the inclusion directive with
47348 the contents of that document. If the current description was read
47349 using @samp{qXfer}, then so will be the included document;
47350 @var{document} will be interpreted as the name of an annex. If the
47351 current description was read from a file, @value{GDBN} will look for
47352 @var{document} as a file in the same directory where it found the
47353 original description.
47354
47355 @subsection Architecture
47356 @cindex <architecture>
47357
47358 An @samp{<architecture>} element has this form:
47359
47360 @smallexample
47361 <architecture>@var{arch}</architecture>
47362 @end smallexample
47363
47364 @var{arch} is one of the architectures from the set accepted by
47365 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
47366
47367 @subsection OS ABI
47368 @cindex @code{<osabi>}
47369
47370 This optional field was introduced in @value{GDBN} version 7.0.
47371 Previous versions of @value{GDBN} ignore it.
47372
47373 An @samp{<osabi>} element has this form:
47374
47375 @smallexample
47376 <osabi>@var{abi-name}</osabi>
47377 @end smallexample
47378
47379 @var{abi-name} is an OS ABI name from the same selection accepted by
47380 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
47381
47382 @subsection Compatible Architecture
47383 @cindex @code{<compatible>}
47384
47385 This optional field was introduced in @value{GDBN} version 7.0.
47386 Previous versions of @value{GDBN} ignore it.
47387
47388 A @samp{<compatible>} element has this form:
47389
47390 @smallexample
47391 <compatible>@var{arch}</compatible>
47392 @end smallexample
47393
47394 @var{arch} is one of the architectures from the set accepted by
47395 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
47396
47397 A @samp{<compatible>} element is used to specify that the target
47398 is able to run binaries in some other than the main target architecture
47399 given by the @samp{<architecture>} element. For example, on the
47400 Cell Broadband Engine, the main architecture is @code{powerpc:common}
47401 or @code{powerpc:common64}, but the system is able to run binaries
47402 in the @code{spu} architecture as well. The way to describe this
47403 capability with @samp{<compatible>} is as follows:
47404
47405 @smallexample
47406 <architecture>powerpc:common</architecture>
47407 <compatible>spu</compatible>
47408 @end smallexample
47409
47410 @subsection Features
47411 @cindex <feature>
47412
47413 Each @samp{<feature>} describes some logical portion of the target
47414 system. Features are currently used to describe available CPU
47415 registers and the types of their contents. A @samp{<feature>} element
47416 has this form:
47417
47418 @smallexample
47419 <feature name="@var{name}">
47420 @r{[}@var{type}@dots{}@r{]}
47421 @var{reg}@dots{}
47422 </feature>
47423 @end smallexample
47424
47425 @noindent
47426 Each feature's name should be unique within the description. The name
47427 of a feature does not matter unless @value{GDBN} has some special
47428 knowledge of the contents of that feature; if it does, the feature
47429 should have its standard name. @xref{Standard Target Features}.
47430
47431 @subsection Types
47432
47433 Any register's value is a collection of bits which @value{GDBN} must
47434 interpret. The default interpretation is a two's complement integer,
47435 but other types can be requested by name in the register description.
47436 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
47437 Target Types}), and the description can define additional composite
47438 and enum types.
47439
47440 Each type element must have an @samp{id} attribute, which gives
47441 a unique (within the containing @samp{<feature>}) name to the type.
47442 Types must be defined before they are used.
47443
47444 @cindex <vector>
47445 Some targets offer vector registers, which can be treated as arrays
47446 of scalar elements. These types are written as @samp{<vector>} elements,
47447 specifying the array element type, @var{type}, and the number of elements,
47448 @var{count}:
47449
47450 @smallexample
47451 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
47452 @end smallexample
47453
47454 @cindex <union>
47455 If a register's value is usefully viewed in multiple ways, define it
47456 with a union type containing the useful representations. The
47457 @samp{<union>} element contains one or more @samp{<field>} elements,
47458 each of which has a @var{name} and a @var{type}:
47459
47460 @smallexample
47461 <union id="@var{id}">
47462 <field name="@var{name}" type="@var{type}"/>
47463 @dots{}
47464 </union>
47465 @end smallexample
47466
47467 @cindex <struct>
47468 @cindex <flags>
47469 If a register's value is composed from several separate values, define
47470 it with either a structure type or a flags type.
47471 A flags type may only contain bitfields.
47472 A structure type may either contain only bitfields or contain no bitfields.
47473 If the value contains only bitfields, its total size in bytes must be
47474 specified.
47475
47476 Non-bitfield values have a @var{name} and @var{type}.
47477
47478 @smallexample
47479 <struct id="@var{id}">
47480 <field name="@var{name}" type="@var{type}"/>
47481 @dots{}
47482 </struct>
47483 @end smallexample
47484
47485 Both @var{name} and @var{type} values are required.
47486 No implicit padding is added.
47487
47488 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
47489
47490 @smallexample
47491 <struct id="@var{id}" size="@var{size}">
47492 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
47493 @dots{}
47494 </struct>
47495 @end smallexample
47496
47497 @smallexample
47498 <flags id="@var{id}" size="@var{size}">
47499 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
47500 @dots{}
47501 </flags>
47502 @end smallexample
47503
47504 The @var{name} value is required.
47505 Bitfield values may be named with the empty string, @samp{""},
47506 in which case the field is ``filler'' and its value is not printed.
47507 Not all bits need to be specified, so ``filler'' fields are optional.
47508
47509 The @var{start} and @var{end} values are required, and @var{type}
47510 is optional.
47511 The field's @var{start} must be less than or equal to its @var{end},
47512 and zero represents the least significant bit.
47513
47514 The default value of @var{type} is @code{bool} for single bit fields,
47515 and an unsigned integer otherwise.
47516
47517 Which to choose? Structures or flags?
47518
47519 Registers defined with @samp{flags} have these advantages over
47520 defining them with @samp{struct}:
47521
47522 @itemize @bullet
47523 @item
47524 Arithmetic may be performed on them as if they were integers.
47525 @item
47526 They are printed in a more readable fashion.
47527 @end itemize
47528
47529 Registers defined with @samp{struct} have one advantage over
47530 defining them with @samp{flags}:
47531
47532 @itemize @bullet
47533 @item
47534 One can fetch individual fields like in @samp{C}.
47535
47536 @smallexample
47537 (@value{GDBP}) print $my_struct_reg.field3
47538 $1 = 42
47539 @end smallexample
47540
47541 @end itemize
47542
47543 @subsection Registers
47544 @cindex <reg>
47545
47546 Each register is represented as an element with this form:
47547
47548 @smallexample
47549 <reg name="@var{name}"
47550 bitsize="@var{size}"
47551 @r{[}regnum="@var{num}"@r{]}
47552 @r{[}save-restore="@var{save-restore}"@r{]}
47553 @r{[}type="@var{type}"@r{]}
47554 @r{[}group="@var{group}"@r{]}/>
47555 @end smallexample
47556
47557 @noindent
47558 The components are as follows:
47559
47560 @table @var
47561
47562 @item name
47563 The register's name; it must be unique within the target description.
47564
47565 @item bitsize
47566 The register's size, in bits.
47567
47568 @item regnum
47569 The register's number. If omitted, a register's number is one greater
47570 than that of the previous register (either in the current feature or in
47571 a preceding feature); the first register in the target description
47572 defaults to zero. This register number is used to read or write
47573 the register; e.g.@: it is used in the remote @code{p} and @code{P}
47574 packets, and registers appear in the @code{g} and @code{G} packets
47575 in order of increasing register number.
47576
47577 @item save-restore
47578 Whether the register should be preserved across inferior function
47579 calls; this must be either @code{yes} or @code{no}. The default is
47580 @code{yes}, which is appropriate for most registers except for
47581 some system control registers; this is not related to the target's
47582 ABI.
47583
47584 @item type
47585 The type of the register. It may be a predefined type, a type
47586 defined in the current feature, or one of the special types @code{int}
47587 and @code{float}. @code{int} is an integer type of the correct size
47588 for @var{bitsize}, and @code{float} is a floating point type (in the
47589 architecture's normal floating point format) of the correct size for
47590 @var{bitsize}. The default is @code{int}.
47591
47592 @item group
47593 The register group to which this register belongs. It can be one of the
47594 standard register groups @code{general}, @code{float}, @code{vector} or an
47595 arbitrary string. Group names should be limited to alphanumeric characters.
47596 If a group name is made up of multiple words the words may be separated by
47597 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
47598 @var{group} is specified, @value{GDBN} will not display the register in
47599 @code{info registers}.
47600
47601 @end table
47602
47603 @node Predefined Target Types
47604 @section Predefined Target Types
47605 @cindex target descriptions, predefined types
47606
47607 Type definitions in the self-description can build up composite types
47608 from basic building blocks, but can not define fundamental types. Instead,
47609 standard identifiers are provided by @value{GDBN} for the fundamental
47610 types. The currently supported types are:
47611
47612 @table @code
47613
47614 @item bool
47615 Boolean type, occupying a single bit.
47616
47617 @item int8
47618 @itemx int16
47619 @itemx int24
47620 @itemx int32
47621 @itemx int64
47622 @itemx int128
47623 Signed integer types holding the specified number of bits.
47624
47625 @item uint8
47626 @itemx uint16
47627 @itemx uint24
47628 @itemx uint32
47629 @itemx uint64
47630 @itemx uint128
47631 Unsigned integer types holding the specified number of bits.
47632
47633 @item code_ptr
47634 @itemx data_ptr
47635 Pointers to unspecified code and data. The program counter and
47636 any dedicated return address register may be marked as code
47637 pointers; printing a code pointer converts it into a symbolic
47638 address. The stack pointer and any dedicated address registers
47639 may be marked as data pointers.
47640
47641 @item ieee_half
47642 Half precision IEEE floating point.
47643
47644 @item ieee_single
47645 Single precision IEEE floating point.
47646
47647 @item ieee_double
47648 Double precision IEEE floating point.
47649
47650 @item bfloat16
47651 The 16-bit @dfn{brain floating point} format used e.g.@: by x86 and ARM.
47652
47653 @item arm_fpa_ext
47654 The 12-byte extended precision format used by ARM FPA registers.
47655
47656 @item i387_ext
47657 The 10-byte extended precision format used by x87 registers.
47658
47659 @item i386_eflags
47660 32bit @sc{eflags} register used by x86.
47661
47662 @item i386_mxcsr
47663 32bit @sc{mxcsr} register used by x86.
47664
47665 @end table
47666
47667 @node Enum Target Types
47668 @section Enum Target Types
47669 @cindex target descriptions, enum types
47670
47671 Enum target types are useful in @samp{struct} and @samp{flags}
47672 register descriptions. @xref{Target Description Format}.
47673
47674 Enum types have a name, size and a list of name/value pairs.
47675
47676 @smallexample
47677 <enum id="@var{id}" size="@var{size}">
47678 <evalue name="@var{name}" value="@var{value}"/>
47679 @dots{}
47680 </enum>
47681 @end smallexample
47682
47683 Enums must be defined before they are used.
47684
47685 @smallexample
47686 <enum id="levels_type" size="4">
47687 <evalue name="low" value="0"/>
47688 <evalue name="high" value="1"/>
47689 </enum>
47690 <flags id="flags_type" size="4">
47691 <field name="X" start="0"/>
47692 <field name="LEVEL" start="1" end="1" type="levels_type"/>
47693 </flags>
47694 <reg name="flags" bitsize="32" type="flags_type"/>
47695 @end smallexample
47696
47697 Given that description, a value of 3 for the @samp{flags} register
47698 would be printed as:
47699
47700 @smallexample
47701 (@value{GDBP}) info register flags
47702 flags 0x3 [ X LEVEL=high ]
47703 @end smallexample
47704
47705 @node Standard Target Features
47706 @section Standard Target Features
47707 @cindex target descriptions, standard features
47708
47709 A target description must contain either no registers or all the
47710 target's registers. If the description contains no registers, then
47711 @value{GDBN} will assume a default register layout, selected based on
47712 the architecture. If the description contains any registers, the
47713 default layout will not be used; the standard registers must be
47714 described in the target description, in such a way that @value{GDBN}
47715 can recognize them.
47716
47717 This is accomplished by giving specific names to feature elements
47718 which contain standard registers. @value{GDBN} will look for features
47719 with those names and verify that they contain the expected registers;
47720 if any known feature is missing required registers, or if any required
47721 feature is missing, @value{GDBN} will reject the target
47722 description. You can add additional registers to any of the
47723 standard features --- @value{GDBN} will display them just as if
47724 they were added to an unrecognized feature.
47725
47726 This section lists the known features and their expected contents.
47727 Sample XML documents for these features are included in the
47728 @value{GDBN} source tree, in the directory @file{gdb/features}.
47729
47730 Names recognized by @value{GDBN} should include the name of the
47731 company or organization which selected the name, and the overall
47732 architecture to which the feature applies; so e.g.@: the feature
47733 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
47734
47735 The names of registers are not case sensitive for the purpose
47736 of recognizing standard features, but @value{GDBN} will only display
47737 registers using the capitalization used in the description.
47738
47739 @menu
47740 * AArch64 Features::
47741 * ARC Features::
47742 * ARM Features::
47743 * i386 Features::
47744 * LoongArch Features::
47745 * MicroBlaze Features::
47746 * MIPS Features::
47747 * M68K Features::
47748 * NDS32 Features::
47749 * Nios II Features::
47750 * OpenRISC 1000 Features::
47751 * PowerPC Features::
47752 * RISC-V Features::
47753 * RX Features::
47754 * S/390 and System z Features::
47755 * Sparc Features::
47756 * TIC6x Features::
47757 @end menu
47758
47759
47760 @node AArch64 Features
47761 @subsection AArch64 Features
47762 @cindex target descriptions, AArch64 features
47763
47764 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
47765 targets. It should contain registers @samp{x0} through @samp{x30},
47766 @samp{sp}, @samp{pc}, and @samp{cpsr}.
47767
47768 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
47769 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
47770 and @samp{fpcr}.
47771
47772 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
47773 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
47774 through @samp{p15}, @samp{ffr} and @samp{vg}.
47775
47776 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
47777 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
47778
47779 @node ARC Features
47780 @subsection ARC Features
47781 @cindex target descriptions, ARC Features
47782
47783 ARC processors are so configurable that even core registers and their numbers
47784 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
47785 registers, which are important to @value{GDBN}, are not ``core'' registers in
47786 ARC. Therefore, there are two features that their presence is mandatory:
47787 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
47788
47789 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
47790 contain registers:
47791
47792 @itemize @minus
47793 @item
47794 @samp{r0} through @samp{r25} for normal register file targets.
47795 @item
47796 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
47797 register file targets.
47798 @item
47799 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
47800 @samp{blink}, @samp{lp_count}, @samp{pcl}.
47801 @end itemize
47802
47803 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
47804 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
47805 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
47806 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
47807 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
47808 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
47809 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
47810 because of their inaccessibility during user space debugging sessions.
47811
47812 Extension core registers @samp{r32} through @samp{r59} are optional and their
47813 existence depends on the configuration. When debugging GNU/Linux applications,
47814 i.e.@: user space debugging, these core registers are not available.
47815
47816 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
47817 is the list of registers pertinent to this feature:
47818
47819 @itemize @minus
47820 @item
47821 mandatory: @samp{pc} and @samp{status32}.
47822 @item
47823 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
47824 @end itemize
47825
47826 @node ARM Features
47827 @subsection ARM Features
47828 @cindex target descriptions, ARM features
47829
47830 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
47831 ARM targets.
47832 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
47833 @samp{lr}, @samp{pc}, and @samp{cpsr}.
47834
47835 For M-profile targets (e.g.@: Cortex-M3), the @samp{org.gnu.gdb.arm.core}
47836 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
47837 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
47838 and @samp{xpsr}.
47839
47840 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
47841 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
47842
47843 The @samp{org.gnu.gdb.arm.m-profile-mve} feature is optional. If present, it
47844 must contain register @samp{vpr}.
47845
47846 If the @samp{org.gnu.gdb.arm.m-profile-mve} feature is available, @value{GDBN}
47847 will synthesize the @samp{p0} pseudo register from @samp{vpr} contents.
47848
47849 If the @samp{org.gnu.gdb.arm.vfp} feature is available alongside the
47850 @samp{org.gnu.gdb.arm.m-profile-mve} feature, @value{GDBN} will
47851 synthesize the @samp{q} pseudo registers from @samp{d} register
47852 contents.
47853
47854 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
47855 it should contain at least registers @samp{wR0} through @samp{wR15} and
47856 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
47857 @samp{wCSSF}, and @samp{wCASF} registers are optional.
47858
47859 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
47860 should contain at least registers @samp{d0} through @samp{d15}. If
47861 they are present, @samp{d16} through @samp{d31} should also be included.
47862 @value{GDBN} will synthesize the single-precision registers from
47863 halves of the double-precision registers.
47864
47865 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
47866 need to contain registers; it instructs @value{GDBN} to display the
47867 VFP double-precision registers as vectors and to synthesize the
47868 quad-precision registers from pairs of double-precision registers.
47869 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
47870 be present and include 32 double-precision registers.
47871
47872 The @samp{org.gnu.gdb.arm.m-profile-pacbti} feature is optional, and
47873 acknowledges support for the ARMv8.1-m PACBTI extensions. @value{GDBN}
47874 will track return address signing states and will decorate backtraces using
47875 the [PAC] marker, similar to AArch64's PAC extension.
47876 @xref{AArch64 PAC}.
47877
47878 @node i386 Features
47879 @subsection i386 Features
47880 @cindex target descriptions, i386 features
47881
47882 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
47883 targets. It should describe the following registers:
47884
47885 @itemize @minus
47886 @item
47887 @samp{eax} through @samp{edi} plus @samp{eip} for i386
47888 @item
47889 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
47890 @item
47891 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
47892 @samp{fs}, @samp{gs}
47893 @item
47894 @samp{st0} through @samp{st7}
47895 @item
47896 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
47897 @samp{foseg}, @samp{fooff} and @samp{fop}
47898 @end itemize
47899
47900 The register sets may be different, depending on the target.
47901
47902 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
47903 describe registers:
47904
47905 @itemize @minus
47906 @item
47907 @samp{xmm0} through @samp{xmm7} for i386
47908 @item
47909 @samp{xmm0} through @samp{xmm15} for amd64
47910 @item
47911 @samp{mxcsr}
47912 @end itemize
47913
47914 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
47915 @samp{org.gnu.gdb.i386.sse} feature. It should
47916 describe the upper 128 bits of @sc{ymm} registers:
47917
47918 @itemize @minus
47919 @item
47920 @samp{ymm0h} through @samp{ymm7h} for i386
47921 @item
47922 @samp{ymm0h} through @samp{ymm15h} for amd64
47923 @end itemize
47924
47925 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
47926 Memory Protection Extension (MPX). It should describe the following registers:
47927
47928 @itemize @minus
47929 @item
47930 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
47931 @item
47932 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
47933 @end itemize
47934
47935 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
47936 describe a single register, @samp{orig_eax}.
47937
47938 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
47939 describe two system registers: @samp{fs_base} and @samp{gs_base}.
47940
47941 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
47942 @samp{org.gnu.gdb.i386.avx} feature. It should
47943 describe additional @sc{xmm} registers:
47944
47945 @itemize @minus
47946 @item
47947 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
47948 @end itemize
47949
47950 It should describe the upper 128 bits of additional @sc{ymm} registers:
47951
47952 @itemize @minus
47953 @item
47954 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
47955 @end itemize
47956
47957 It should
47958 describe the upper 256 bits of @sc{zmm} registers:
47959
47960 @itemize @minus
47961 @item
47962 @samp{zmm0h} through @samp{zmm7h} for i386.
47963 @item
47964 @samp{zmm0h} through @samp{zmm15h} for amd64.
47965 @end itemize
47966
47967 It should
47968 describe the additional @sc{zmm} registers:
47969
47970 @itemize @minus
47971 @item
47972 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
47973 @end itemize
47974
47975 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
47976 describe a single register, @samp{pkru}. It is a 32-bit register
47977 valid for i386 and amd64.
47978
47979 @node LoongArch Features
47980 @subsection LoongArch Features
47981 @cindex target descriptions, LoongArch Features
47982
47983 The @samp{org.gnu.gdb.loongarch.base} feature is required for LoongArch
47984 targets. It should contain the registers @samp{r0} through @samp{r31},
47985 @samp{pc}, and @samp{badv}. Either the architectural names (@samp{r0},
47986 @samp{r1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra}, etc).
47987
47988 The @samp{org.gnu.gdb.loongarch.fpu} feature is optional. If present,
47989 it should contain registers @samp{f0} through @samp{f31}, @samp{fcc},
47990 and @samp{fcsr}.
47991
47992 @node MicroBlaze Features
47993 @subsection MicroBlaze Features
47994 @cindex target descriptions, MicroBlaze features
47995
47996 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
47997 targets. It should contain registers @samp{r0} through @samp{r31},
47998 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
47999 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
48000 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
48001
48002 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
48003 If present, it should contain registers @samp{rshr} and @samp{rslr}
48004
48005 @node MIPS Features
48006 @subsection @acronym{MIPS} Features
48007 @cindex target descriptions, @acronym{MIPS} features
48008
48009 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
48010 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
48011 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
48012 on the target.
48013
48014 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
48015 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
48016 registers. They may be 32-bit or 64-bit depending on the target.
48017
48018 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
48019 it may be optional in a future version of @value{GDBN}. It should
48020 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
48021 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
48022
48023 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
48024 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
48025 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
48026 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
48027
48028 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
48029 contain a single register, @samp{restart}, which is used by the
48030 Linux kernel to control restartable syscalls.
48031
48032 @node M68K Features
48033 @subsection M68K Features
48034 @cindex target descriptions, M68K features
48035
48036 @table @code
48037 @item @samp{org.gnu.gdb.m68k.core}
48038 @itemx @samp{org.gnu.gdb.coldfire.core}
48039 @itemx @samp{org.gnu.gdb.fido.core}
48040 One of those features must be always present.
48041 The feature that is present determines which flavor of m68k is
48042 used. The feature that is present should contain registers
48043 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
48044 @samp{sp}, @samp{ps} and @samp{pc}.
48045
48046 @item @samp{org.gnu.gdb.coldfire.fp}
48047 This feature is optional. If present, it should contain registers
48048 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
48049 @samp{fpiaddr}.
48050
48051 Note that, despite the fact that this feature's name says
48052 @samp{coldfire}, it is used to describe any floating point registers.
48053 The size of the registers must match the main m68k flavor; so, for
48054 example, if the primary feature is reported as @samp{coldfire}, then
48055 64-bit floating point registers are required.
48056 @end table
48057
48058 @node NDS32 Features
48059 @subsection NDS32 Features
48060 @cindex target descriptions, NDS32 features
48061
48062 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
48063 targets. It should contain at least registers @samp{r0} through
48064 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
48065 and @samp{pc}.
48066
48067 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
48068 it should contain 64-bit double-precision floating-point registers
48069 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
48070 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
48071
48072 @emph{Note:} The first sixteen 64-bit double-precision floating-point
48073 registers are overlapped with the thirty-two 32-bit single-precision
48074 floating-point registers. The 32-bit single-precision registers, if
48075 not being listed explicitly, will be synthesized from halves of the
48076 overlapping 64-bit double-precision registers. Listing 32-bit
48077 single-precision registers explicitly is deprecated, and the
48078 support to it could be totally removed some day.
48079
48080 @node Nios II Features
48081 @subsection Nios II Features
48082 @cindex target descriptions, Nios II features
48083
48084 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
48085 targets. It should contain the 32 core registers (@samp{zero},
48086 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
48087 @samp{pc}, and the 16 control registers (@samp{status} through
48088 @samp{mpuacc}).
48089
48090 @node OpenRISC 1000 Features
48091 @subsection Openrisc 1000 Features
48092 @cindex target descriptions, OpenRISC 1000 features
48093
48094 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
48095 targets. It should contain the 32 general purpose registers (@samp{r0}
48096 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
48097
48098 @node PowerPC Features
48099 @subsection PowerPC Features
48100 @cindex target descriptions, PowerPC features
48101
48102 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
48103 targets. It should contain registers @samp{r0} through @samp{r31},
48104 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
48105 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
48106
48107 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
48108 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
48109
48110 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
48111 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
48112 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
48113 through @samp{v31} as aliases for the corresponding @samp{vrX}
48114 registers.
48115
48116 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
48117 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
48118 combine these registers with the floating point registers (@samp{f0}
48119 through @samp{f31}) and the altivec registers (@samp{vr0} through
48120 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
48121 @samp{vs63}, the set of vector-scalar registers for POWER7.
48122 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
48123 @samp{org.gnu.gdb.power.altivec}.
48124
48125 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
48126 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
48127 @samp{spefscr}. SPE targets should provide 32-bit registers in
48128 @samp{org.gnu.gdb.power.core} and provide the upper halves in
48129 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
48130 these to present registers @samp{ev0} through @samp{ev31} to the
48131 user.
48132
48133 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
48134 contain the 64-bit register @samp{ppr}.
48135
48136 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
48137 contain the 64-bit register @samp{dscr}.
48138
48139 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
48140 contain the 64-bit register @samp{tar}.
48141
48142 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
48143 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
48144 64-bit wide.
48145
48146 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
48147 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
48148 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
48149 server PMU registers provided by @sc{gnu}/Linux.
48150
48151 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
48152 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
48153 64-bit wide.
48154
48155 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
48156 contain the checkpointed general-purpose registers @samp{cr0} through
48157 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
48158 @samp{cctr}. These registers may all be either 32-bit or 64-bit
48159 depending on the target. It should also contain the checkpointed
48160 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
48161 wide.
48162
48163 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
48164 contain the checkpointed 64-bit floating-point registers @samp{cf0}
48165 through @samp{cf31}, as well as the checkpointed 64-bit register
48166 @samp{cfpscr}.
48167
48168 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
48169 should contain the checkpointed altivec registers @samp{cvr0} through
48170 @samp{cvr31}, all 128-bit wide. It should also contain the
48171 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
48172 wide.
48173
48174 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
48175 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
48176 will combine these registers with the checkpointed floating point
48177 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
48178 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
48179 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
48180 @samp{cvs63}. Therefore, this feature requires both
48181 @samp{org.gnu.gdb.power.htm.altivec} and
48182 @samp{org.gnu.gdb.power.htm.fpu}.
48183
48184 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
48185 contain the 64-bit checkpointed register @samp{cppr}.
48186
48187 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
48188 contain the 64-bit checkpointed register @samp{cdscr}.
48189
48190 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
48191 contain the 64-bit checkpointed register @samp{ctar}.
48192
48193
48194 @node RISC-V Features
48195 @subsection RISC-V Features
48196 @cindex target descriptions, RISC-V Features
48197
48198 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
48199 targets. It should contain the registers @samp{x0} through
48200 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
48201 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
48202 etc).
48203
48204 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
48205 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
48206 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
48207 architectural register names, or the ABI names can be used.
48208
48209 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
48210 it should contain registers that are not backed by real registers on
48211 the target, but are instead virtual, where the register value is
48212 derived from other target state. In many ways these are like
48213 @value{GDBN}s pseudo-registers, except implemented by the target.
48214 Currently the only register expected in this set is the one byte
48215 @samp{priv} register that contains the target's privilege level in the
48216 least significant two bits.
48217
48218 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
48219 should contain all of the target's standard CSRs. Standard CSRs are
48220 those defined in the RISC-V specification documents. There is some
48221 overlap between this feature and the fpu feature; the @samp{fflags},
48222 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
48223 expectation is that these registers will be in the fpu feature if the
48224 target has floating point hardware, but can be moved into the csr
48225 feature if the target has the floating point control registers, but no
48226 other floating point hardware.
48227
48228 The @samp{org.gnu.gdb.riscv.vector} feature is optional. If present,
48229 it should contain registers @samp{v0} through @samp{v31}, all of which
48230 must be the same size. These requirements are based on the v0.10
48231 draft vector extension, as the vector extension is not yet final. In
48232 the event that the register set of the vector extension changes for
48233 the final specification, the requirements given here could change for
48234 future releases of @value{GDBN}.
48235
48236 @node RX Features
48237 @subsection RX Features
48238 @cindex target descriptions, RX Features
48239
48240 The @samp{org.gnu.gdb.rx.core} feature is required for RX
48241 targets. It should contain the registers @samp{r0} through
48242 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
48243 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
48244
48245 @node S/390 and System z Features
48246 @subsection S/390 and System z Features
48247 @cindex target descriptions, S/390 features
48248 @cindex target descriptions, System z features
48249
48250 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
48251 System z targets. It should contain the PSW and the 16 general
48252 registers. In particular, System z targets should provide the 64-bit
48253 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
48254 S/390 targets should provide the 32-bit versions of these registers.
48255 A System z target that runs in 31-bit addressing mode should provide
48256 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
48257 register's upper halves @samp{r0h} through @samp{r15h}, and their
48258 lower halves @samp{r0l} through @samp{r15l}.
48259
48260 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
48261 contain the 64-bit registers @samp{f0} through @samp{f15}, and
48262 @samp{fpc}.
48263
48264 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
48265 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
48266
48267 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
48268 contain the register @samp{orig_r2}, which is 64-bit wide on System z
48269 targets and 32-bit otherwise. In addition, the feature may contain
48270 the @samp{last_break} register, whose width depends on the addressing
48271 mode, as well as the @samp{system_call} register, which is always
48272 32-bit wide.
48273
48274 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
48275 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
48276 @samp{atia}, and @samp{tr0} through @samp{tr15}.
48277
48278 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
48279 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
48280 combined by @value{GDBN} with the floating point registers @samp{f0}
48281 through @samp{f15} to present the 128-bit wide vector registers
48282 @samp{v0} through @samp{v15}. In addition, this feature should
48283 contain the 128-bit wide vector registers @samp{v16} through
48284 @samp{v31}.
48285
48286 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
48287 the 64-bit wide guarded-storage-control registers @samp{gsd},
48288 @samp{gssm}, and @samp{gsepla}.
48289
48290 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
48291 the 64-bit wide guarded-storage broadcast control registers
48292 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
48293
48294 @node Sparc Features
48295 @subsection Sparc Features
48296 @cindex target descriptions, sparc32 features
48297 @cindex target descriptions, sparc64 features
48298 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
48299 targets. It should describe the following registers:
48300
48301 @itemize @minus
48302 @item
48303 @samp{g0} through @samp{g7}
48304 @item
48305 @samp{o0} through @samp{o7}
48306 @item
48307 @samp{l0} through @samp{l7}
48308 @item
48309 @samp{i0} through @samp{i7}
48310 @end itemize
48311
48312 They may be 32-bit or 64-bit depending on the target.
48313
48314 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
48315 targets. It should describe the following registers:
48316
48317 @itemize @minus
48318 @item
48319 @samp{f0} through @samp{f31}
48320 @item
48321 @samp{f32} through @samp{f62} for sparc64
48322 @end itemize
48323
48324 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
48325 targets. It should describe the following registers:
48326
48327 @itemize @minus
48328 @item
48329 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
48330 @samp{fsr}, and @samp{csr} for sparc32
48331 @item
48332 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
48333 for sparc64
48334 @end itemize
48335
48336 @node TIC6x Features
48337 @subsection TMS320C6x Features
48338 @cindex target descriptions, TIC6x features
48339 @cindex target descriptions, TMS320C6x features
48340 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
48341 targets. It should contain registers @samp{A0} through @samp{A15},
48342 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
48343
48344 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
48345 contain registers @samp{A16} through @samp{A31} and @samp{B16}
48346 through @samp{B31}.
48347
48348 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
48349 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
48350
48351 @node Operating System Information
48352 @appendix Operating System Information
48353 @cindex operating system information
48354
48355 Users of @value{GDBN} often wish to obtain information about the state of
48356 the operating system running on the target---for example the list of
48357 processes, or the list of open files. This section describes the
48358 mechanism that makes it possible. This mechanism is similar to the
48359 target features mechanism (@pxref{Target Descriptions}), but focuses
48360 on a different aspect of target.
48361
48362 Operating system information is retrieved from the target via the
48363 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
48364 read}). The object name in the request should be @samp{osdata}, and
48365 the @var{annex} identifies the data to be fetched.
48366
48367 @menu
48368 * Process list::
48369 @end menu
48370
48371 @node Process list
48372 @appendixsection Process list
48373 @cindex operating system information, process list
48374
48375 When requesting the process list, the @var{annex} field in the
48376 @samp{qXfer} request should be @samp{processes}. The returned data is
48377 an XML document. The formal syntax of this document is defined in
48378 @file{gdb/features/osdata.dtd}.
48379
48380 An example document is:
48381
48382 @smallexample
48383 <?xml version="1.0"?>
48384 <!DOCTYPE target SYSTEM "osdata.dtd">
48385 <osdata type="processes">
48386 <item>
48387 <column name="pid">1</column>
48388 <column name="user">root</column>
48389 <column name="command">/sbin/init</column>
48390 <column name="cores">1,2,3</column>
48391 </item>
48392 </osdata>
48393 @end smallexample
48394
48395 Each item should include a column whose name is @samp{pid}. The value
48396 of that column should identify the process on the target. The
48397 @samp{user} and @samp{command} columns are optional, and will be
48398 displayed by @value{GDBN}. The @samp{cores} column, if present,
48399 should contain a comma-separated list of cores that this process
48400 is running on. Target may provide additional columns,
48401 which @value{GDBN} currently ignores.
48402
48403 @node Trace File Format
48404 @appendix Trace File Format
48405 @cindex trace file format
48406
48407 The trace file comes in three parts: a header, a textual description
48408 section, and a trace frame section with binary data.
48409
48410 The header has the form @code{\x7fTRACE0\n}. The first byte is
48411 @code{0x7f} so as to indicate that the file contains binary data,
48412 while the @code{0} is a version number that may have different values
48413 in the future.
48414
48415 The description section consists of multiple lines of @sc{ascii} text
48416 separated by newline characters (@code{0xa}). The lines may include a
48417 variety of optional descriptive or context-setting information, such
48418 as tracepoint definitions or register set size. @value{GDBN} will
48419 ignore any line that it does not recognize. An empty line marks the end
48420 of this section.
48421
48422 @table @code
48423 @item R @var{size}
48424 Specifies the size of a register block in bytes. This is equal to the
48425 size of a @code{g} packet payload in the remote protocol. @var{size}
48426 is an ascii decimal number. There should be only one such line in
48427 a single trace file.
48428
48429 @item status @var{status}
48430 Trace status. @var{status} has the same format as a @code{qTStatus}
48431 remote packet reply. There should be only one such line in a single trace
48432 file.
48433
48434 @item tp @var{payload}
48435 Tracepoint definition. The @var{payload} has the same format as
48436 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
48437 may take multiple lines of definition, corresponding to the multiple
48438 reply packets.
48439
48440 @item tsv @var{payload}
48441 Trace state variable definition. The @var{payload} has the same format as
48442 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
48443 may take multiple lines of definition, corresponding to the multiple
48444 reply packets.
48445
48446 @item tdesc @var{payload}
48447 Target description in XML format. The @var{payload} is a single line of
48448 the XML file. All such lines should be concatenated together to get
48449 the original XML file. This file is in the same format as @code{qXfer}
48450 @code{features} payload, and corresponds to the main @code{target.xml}
48451 file. Includes are not allowed.
48452
48453 @end table
48454
48455 The trace frame section consists of a number of consecutive frames.
48456 Each frame begins with a two-byte tracepoint number, followed by a
48457 four-byte size giving the amount of data in the frame. The data in
48458 the frame consists of a number of blocks, each introduced by a
48459 character indicating its type (at least register, memory, and trace
48460 state variable). The data in this section is raw binary, not a
48461 hexadecimal or other encoding; its endianness matches the target's
48462 endianness.
48463
48464 @c FIXME bi-arch may require endianness/arch info in description section
48465
48466 @table @code
48467 @item R @var{bytes}
48468 Register block. The number and ordering of bytes matches that of a
48469 @code{g} packet in the remote protocol. Note that these are the
48470 actual bytes, in target order, not a hexadecimal encoding.
48471
48472 @item M @var{address} @var{length} @var{bytes}...
48473 Memory block. This is a contiguous block of memory, at the 8-byte
48474 address @var{address}, with a 2-byte length @var{length}, followed by
48475 @var{length} bytes.
48476
48477 @item V @var{number} @var{value}
48478 Trace state variable block. This records the 8-byte signed value
48479 @var{value} of trace state variable numbered @var{number}.
48480
48481 @end table
48482
48483 Future enhancements of the trace file format may include additional types
48484 of blocks.
48485
48486 @node Index Section Format
48487 @appendix @code{.gdb_index} section format
48488 @cindex .gdb_index section format
48489 @cindex index section format
48490
48491 This section documents the index section that is created by @code{save
48492 gdb-index} (@pxref{Index Files}). The index section is
48493 DWARF-specific; some knowledge of DWARF is assumed in this
48494 description.
48495
48496 The mapped index file format is designed to be directly
48497 @code{mmap}able on any architecture. In most cases, a datum is
48498 represented using a little-endian 32-bit integer value, called an
48499 @code{offset_type}. Big endian machines must byte-swap the values
48500 before using them. Exceptions to this rule are noted. The data is
48501 laid out such that alignment is always respected.
48502
48503 A mapped index consists of several areas, laid out in order.
48504
48505 @enumerate
48506 @item
48507 The file header. This is a sequence of values, of @code{offset_type}
48508 unless otherwise noted:
48509
48510 @enumerate
48511 @item
48512 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
48513 Version 4 uses a different hashing function from versions 5 and 6.
48514 Version 6 includes symbols for inlined functions, whereas versions 4
48515 and 5 do not. Version 7 adds attributes to the CU indices in the
48516 symbol table. Version 8 specifies that symbols from DWARF type units
48517 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
48518 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
48519
48520 @value{GDBN} will only read version 4, 5, or 6 indices
48521 by specifying @code{set use-deprecated-index-sections on}.
48522 GDB has a workaround for potentially broken version 7 indices so it is
48523 currently not flagged as deprecated.
48524
48525 @item
48526 The offset, from the start of the file, of the CU list.
48527
48528 @item
48529 The offset, from the start of the file, of the types CU list. Note
48530 that this area can be empty, in which case this offset will be equal
48531 to the next offset.
48532
48533 @item
48534 The offset, from the start of the file, of the address area.
48535
48536 @item
48537 The offset, from the start of the file, of the symbol table.
48538
48539 @item
48540 The offset, from the start of the file, of the constant pool.
48541 @end enumerate
48542
48543 @item
48544 The CU list. This is a sequence of pairs of 64-bit little-endian
48545 values, sorted by the CU offset. The first element in each pair is
48546 the offset of a CU in the @code{.debug_info} section. The second
48547 element in each pair is the length of that CU. References to a CU
48548 elsewhere in the map are done using a CU index, which is just the
48549 0-based index into this table. Note that if there are type CUs, then
48550 conceptually CUs and type CUs form a single list for the purposes of
48551 CU indices.
48552
48553 @item
48554 The types CU list. This is a sequence of triplets of 64-bit
48555 little-endian values. In a triplet, the first value is the CU offset,
48556 the second value is the type offset in the CU, and the third value is
48557 the type signature. The types CU list is not sorted.
48558
48559 @item
48560 The address area. The address area consists of a sequence of address
48561 entries. Each address entry has three elements:
48562
48563 @enumerate
48564 @item
48565 The low address. This is a 64-bit little-endian value.
48566
48567 @item
48568 The high address. This is a 64-bit little-endian value. Like
48569 @code{DW_AT_high_pc}, the value is one byte beyond the end.
48570
48571 @item
48572 The CU index. This is an @code{offset_type} value.
48573 @end enumerate
48574
48575 @item
48576 The symbol table. This is an open-addressed hash table. The size of
48577 the hash table is always a power of 2.
48578
48579 Each slot in the hash table consists of a pair of @code{offset_type}
48580 values. The first value is the offset of the symbol's name in the
48581 constant pool. The second value is the offset of the CU vector in the
48582 constant pool.
48583
48584 If both values are 0, then this slot in the hash table is empty. This
48585 is ok because while 0 is a valid constant pool index, it cannot be a
48586 valid index for both a string and a CU vector.
48587
48588 The hash value for a table entry is computed by applying an
48589 iterative hash function to the symbol's name. Starting with an
48590 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
48591 the string is incorporated into the hash using the formula depending on the
48592 index version:
48593
48594 @table @asis
48595 @item Version 4
48596 The formula is @code{r = r * 67 + c - 113}.
48597
48598 @item Versions 5 to 7
48599 The formula is @code{r = r * 67 + tolower (c) - 113}.
48600 @end table
48601
48602 The terminating @samp{\0} is not incorporated into the hash.
48603
48604 The step size used in the hash table is computed via
48605 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
48606 value, and @samp{size} is the size of the hash table. The step size
48607 is used to find the next candidate slot when handling a hash
48608 collision.
48609
48610 The names of C@t{++} symbols in the hash table are canonicalized. We
48611 don't currently have a simple description of the canonicalization
48612 algorithm; if you intend to create new index sections, you must read
48613 the code.
48614
48615 @item
48616 The constant pool. This is simply a bunch of bytes. It is organized
48617 so that alignment is correct: CU vectors are stored first, followed by
48618 strings.
48619
48620 A CU vector in the constant pool is a sequence of @code{offset_type}
48621 values. The first value is the number of CU indices in the vector.
48622 Each subsequent value is the index and symbol attributes of a CU in
48623 the CU list. This element in the hash table is used to indicate which
48624 CUs define the symbol and how the symbol is used.
48625 See below for the format of each CU index+attributes entry.
48626
48627 A string in the constant pool is zero-terminated.
48628 @end enumerate
48629
48630 Attributes were added to CU index values in @code{.gdb_index} version 7.
48631 If a symbol has multiple uses within a CU then there is one
48632 CU index+attributes value for each use.
48633
48634 The format of each CU index+attributes entry is as follows
48635 (bit 0 = LSB):
48636
48637 @table @asis
48638
48639 @item Bits 0-23
48640 This is the index of the CU in the CU list.
48641 @item Bits 24-27
48642 These bits are reserved for future purposes and must be zero.
48643 @item Bits 28-30
48644 The kind of the symbol in the CU.
48645
48646 @table @asis
48647 @item 0
48648 This value is reserved and should not be used.
48649 By reserving zero the full @code{offset_type} value is backwards compatible
48650 with previous versions of the index.
48651 @item 1
48652 The symbol is a type.
48653 @item 2
48654 The symbol is a variable or an enum value.
48655 @item 3
48656 The symbol is a function.
48657 @item 4
48658 Any other kind of symbol.
48659 @item 5,6,7
48660 These values are reserved.
48661 @end table
48662
48663 @item Bit 31
48664 This bit is zero if the value is global and one if it is static.
48665
48666 The determination of whether a symbol is global or static is complicated.
48667 The authorative reference is the file @file{dwarf2read.c} in
48668 @value{GDBN} sources.
48669
48670 @end table
48671
48672 This pseudo-code describes the computation of a symbol's kind and
48673 global/static attributes in the index.
48674
48675 @smallexample
48676 is_external = get_attribute (die, DW_AT_external);
48677 language = get_attribute (cu_die, DW_AT_language);
48678 switch (die->tag)
48679 @{
48680 case DW_TAG_typedef:
48681 case DW_TAG_base_type:
48682 case DW_TAG_subrange_type:
48683 kind = TYPE;
48684 is_static = 1;
48685 break;
48686 case DW_TAG_enumerator:
48687 kind = VARIABLE;
48688 is_static = language != CPLUS;
48689 break;
48690 case DW_TAG_subprogram:
48691 kind = FUNCTION;
48692 is_static = ! (is_external || language == ADA);
48693 break;
48694 case DW_TAG_constant:
48695 kind = VARIABLE;
48696 is_static = ! is_external;
48697 break;
48698 case DW_TAG_variable:
48699 kind = VARIABLE;
48700 is_static = ! is_external;
48701 break;
48702 case DW_TAG_namespace:
48703 kind = TYPE;
48704 is_static = 0;
48705 break;
48706 case DW_TAG_class_type:
48707 case DW_TAG_interface_type:
48708 case DW_TAG_structure_type:
48709 case DW_TAG_union_type:
48710 case DW_TAG_enumeration_type:
48711 kind = TYPE;
48712 is_static = language != CPLUS;
48713 break;
48714 default:
48715 assert (0);
48716 @}
48717 @end smallexample
48718
48719 @node Debuginfod
48720 @appendix Download debugging resources with Debuginfod
48721 @cindex debuginfod
48722
48723 @code{debuginfod} is an HTTP server for distributing ELF, DWARF and source
48724 files.
48725
48726 With the @code{debuginfod} client library, @file{libdebuginfod}, @value{GDBN}
48727 can query servers using the build IDs associated with missing debug info,
48728 executables and source files in order to download them on demand.
48729
48730 For instructions on building @value{GDBN} with @file{libdebuginfod},
48731 @pxref{Configure Options,,--with-debuginfod}. @code{debuginfod} is packaged
48732 with @code{elfutils}, starting with version 0.178. See
48733 @uref{https://sourceware.org/elfutils/Debuginfod.html} for more information
48734 regarding @code{debuginfod}.
48735
48736 @menu
48737 * Debuginfod Settings:: Configuring debuginfod with @value{GDBN}
48738 @end menu
48739
48740 @node Debuginfod Settings
48741 @section Debuginfod Settings
48742
48743 @value{GDBN} provides the following commands for configuring @code{debuginfod}.
48744
48745 @table @code
48746 @kindex set debuginfod enabled
48747 @anchor{set debuginfod enabled}
48748 @item set debuginfod enabled
48749 @itemx set debuginfod enabled on
48750 @cindex enable debuginfod
48751 @value{GDBN} will attempt to query @code{debuginfod} servers when missing debug
48752 info or source files.
48753
48754 @item set debuginfod enabled off
48755 @value{GDBN} will not attempt to query @code{debuginfod} servers when missing
48756 debug info or source files. By default, @code{debuginfod enabled} is set to
48757 @code{off} for non-interactive sessions.
48758
48759 @item set debuginfod enabled ask
48760 @value{GDBN} will prompt the user to enable or disable @code{debuginfod} before
48761 attempting to perform the next query. By default, @code{debuginfod enabled}
48762 is set to @code{ask} for interactive sessions.
48763
48764 @kindex show debuginfod enabled
48765 @item show debuginfod enabled
48766 Display whether @code{debuginfod enabled} is set to @code{on}, @code{off} or
48767 @code{ask}.
48768
48769 @kindex set debuginfod urls
48770 @cindex configure debuginfod URLs
48771 @item set debuginfod urls
48772 @itemx set debuginfod urls @var{urls}
48773 Set the space-separated list of URLs that @code{debuginfod} will attempt to
48774 query. Only @code{http://}, @code{https://} and @code{file://} protocols
48775 should be used. The default value of @code{debuginfod urls} is copied from
48776 the @var{DEBUGINFOD_URLS} environment variable.
48777
48778 @kindex show debuginfod urls
48779 @item show debuginfod urls
48780 Display the list of URLs that @code{debuginfod} will attempt to query.
48781
48782 @kindex set debuginfod verbose
48783 @cindex debuginfod verbosity
48784 @item set debuginfod verbose
48785 @itemx set debuginfod verbose @var{n}
48786 Enable or disable @code{debuginfod}-related output. Use a non-zero value
48787 to enable and @code{0} to disable. @code{debuginfod} output is shown by
48788 default.
48789
48790 @kindex show debuginfod verbose
48791 @item show debuginfod verbose
48792 Show the current verbosity setting.
48793
48794 @end table
48795
48796 @node Man Pages
48797 @appendix Manual pages
48798 @cindex Man pages
48799
48800 @menu
48801 * gdb man:: The GNU Debugger man page
48802 * gdbserver man:: Remote Server for the GNU Debugger man page
48803 * gcore man:: Generate a core file of a running program
48804 * gdbinit man:: gdbinit scripts
48805 * gdb-add-index man:: Add index files to speed up GDB
48806 @end menu
48807
48808 @node gdb man
48809 @heading gdb man
48810
48811 @c man title gdb The GNU Debugger
48812
48813 @c man begin SYNOPSIS gdb
48814 gdb [OPTIONS] [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
48815 @c man end
48816
48817 @c man begin DESCRIPTION gdb
48818 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
48819 going on ``inside'' another program while it executes -- or what another
48820 program was doing at the moment it crashed.
48821
48822 @value{GDBN} can do four main kinds of things (plus other things in support of
48823 these) to help you catch bugs in the act:
48824
48825 @itemize @bullet
48826 @item
48827 Start your program, specifying anything that might affect its behavior.
48828
48829 @item
48830 Make your program stop on specified conditions.
48831
48832 @item
48833 Examine what has happened, when your program has stopped.
48834
48835 @item
48836 Change things in your program, so you can experiment with correcting the
48837 effects of one bug and go on to learn about another.
48838 @end itemize
48839
48840 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
48841 Modula-2.
48842
48843 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
48844 commands from the terminal until you tell it to exit with the @value{GDBN}
48845 command @code{quit} or @code{exit}. You can get online help from @value{GDBN} itself
48846 by using the command @code{help}.
48847
48848 You can run @code{gdb} with no arguments or options; but the most
48849 usual way to start @value{GDBN} is with one argument or two, specifying an
48850 executable program as the argument:
48851
48852 @smallexample
48853 gdb program
48854 @end smallexample
48855
48856 You can also start with both an executable program and a core file specified:
48857
48858 @smallexample
48859 gdb program core
48860 @end smallexample
48861
48862 You can, instead, specify a process ID as a second argument or use option
48863 @code{-p}, if you want to debug a running process:
48864
48865 @smallexample
48866 gdb program 1234
48867 gdb -p 1234
48868 @end smallexample
48869
48870 @noindent
48871 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
48872 can omit the @var{program} filename.
48873
48874 Here are some of the most frequently needed @value{GDBN} commands:
48875
48876 @c pod2man highlights the right hand side of the @item lines.
48877 @table @env
48878 @item break [@var{file}:][@var{function}|@var{line}]
48879 Set a breakpoint at @var{function} or @var{line} (in @var{file}).
48880
48881 @item run [@var{arglist}]
48882 Start your program (with @var{arglist}, if specified).
48883
48884 @item bt
48885 Backtrace: display the program stack.
48886
48887 @item print @var{expr}
48888 Display the value of an expression.
48889
48890 @item c
48891 Continue running your program (after stopping, e.g.@: at a breakpoint).
48892
48893 @item next
48894 Execute next program line (after stopping); step @emph{over} any
48895 function calls in the line.
48896
48897 @item edit [@var{file}:]@var{function}
48898 look at the program line where it is presently stopped.
48899
48900 @item list [@var{file}:]@var{function}
48901 type the text of the program in the vicinity of where it is presently stopped.
48902
48903 @item step
48904 Execute next program line (after stopping); step @emph{into} any
48905 function calls in the line.
48906
48907 @item help [@var{name}]
48908 Show information about @value{GDBN} command @var{name}, or general information
48909 about using @value{GDBN}.
48910
48911 @item quit
48912 @itemx exit
48913 Exit from @value{GDBN}.
48914 @end table
48915
48916 @ifset man
48917 For full details on @value{GDBN},
48918 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48919 by Richard M. Stallman and Roland H. Pesch. The same text is available online
48920 as the @code{gdb} entry in the @code{info} program.
48921 @end ifset
48922 @c man end
48923
48924 @c man begin OPTIONS gdb
48925 Any arguments other than options specify an executable
48926 file and core file (or process ID); that is, the first argument
48927 encountered with no
48928 associated option flag is equivalent to a @option{--se} option, and the second,
48929 if any, is equivalent to a @option{-c} option if it's the name of a file.
48930 Many options have
48931 both long and abbreviated forms; both are shown here. The long forms are also
48932 recognized if you truncate them, so long as enough of the option is
48933 present to be unambiguous.
48934
48935 The abbreviated forms are shown here with @samp{-} and long forms are shown
48936 with @samp{--} to reflect how they are shown in @option{--help}. However,
48937 @value{GDBN} recognizes all of the following conventions for most options:
48938
48939 @table @code
48940 @item --option=@var{value}
48941 @item --option @var{value}
48942 @item -option=@var{value}
48943 @item -option @var{value}
48944 @item --o=@var{value}
48945 @item --o @var{value}
48946 @item -o=@var{value}
48947 @item -o @var{value}
48948 @end table
48949
48950 All the options and command line arguments you give are processed
48951 in sequential order. The order makes a difference when the @option{-x}
48952 option is used.
48953
48954 @table @env
48955 @item --help
48956 @itemx -h
48957 List all options, with brief explanations.
48958
48959 @item --symbols=@var{file}
48960 @itemx -s @var{file}
48961 Read symbol table from @var{file}.
48962
48963 @item --write
48964 Enable writing into executable and core files.
48965
48966 @item --exec=@var{file}
48967 @itemx -e @var{file}
48968 Use @var{file} as the executable file to execute when
48969 appropriate, and for examining pure data in conjunction with a core
48970 dump.
48971
48972 @item --se=@var{file}
48973 Read symbol table from @var{file} and use it as the executable
48974 file.
48975
48976 @item --core=@var{file}
48977 @itemx -c @var{file}
48978 Use @var{file} as a core dump to examine.
48979
48980 @item --command=@var{file}
48981 @itemx -x @var{file}
48982 Execute @value{GDBN} commands from @var{file}.
48983
48984 @item --eval-command=@var{command}
48985 @item -ex @var{command}
48986 Execute given @value{GDBN} @var{command}.
48987
48988 @item --init-eval-command=@var{command}
48989 @item -iex
48990 Execute @value{GDBN} @var{command} before loading the inferior.
48991
48992 @item --directory=@var{directory}
48993 @itemx -d @var{directory}
48994 Add @var{directory} to the path to search for source files.
48995
48996 @item --nh
48997 Do not execute commands from @file{~/.config/gdb/gdbinit},
48998 @file{~/.gdbinit}, @file{~/.config/gdb/gdbearlyinit}, or
48999 @file{~/.gdbearlyinit}
49000
49001 @item --nx
49002 @itemx -n
49003 Do not execute commands from any @file{.gdbinit} or
49004 @file{.gdbearlyinit} initialization files.
49005
49006 @item --quiet
49007 @item --silent
49008 @itemx -q
49009 ``Quiet''. Do not print the introductory and copyright messages. These
49010 messages are also suppressed in batch mode.
49011
49012 @item --batch
49013 Run in batch mode. Exit with status @code{0} after processing all the command
49014 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
49015 Exit with nonzero status if an error occurs in executing the @value{GDBN}
49016 commands in the command files.
49017
49018 Batch mode may be useful for running @value{GDBN} as a filter, for example to
49019 download and run a program on another computer; in order to make this
49020 more useful, the message
49021
49022 @smallexample
49023 Program exited normally.
49024 @end smallexample
49025
49026 @noindent
49027 (which is ordinarily issued whenever a program running under @value{GDBN} control
49028 terminates) is not issued when running in batch mode.
49029
49030 @item --batch-silent
49031 Run in batch mode, just like @option{--batch}, but totally silent. All @value{GDBN}
49032 output is supressed (stderr is unaffected). This is much quieter than
49033 @option{--silent} and would be useless for an interactive session.
49034
49035 This is particularly useful when using targets that give @samp{Loading section}
49036 messages, for example.
49037
49038 Note that targets that give their output via @value{GDBN}, as opposed to writing
49039 directly to @code{stdout}, will also be made silent.
49040
49041 @item --args @var{prog} [@var{arglist}]
49042 Change interpretation of command line so that arguments following this
49043 option are passed as arguments to the inferior. As an example, take
49044 the following command:
49045
49046 @smallexample
49047 gdb ./a.out -q
49048 @end smallexample
49049
49050 @noindent
49051 It would start @value{GDBN} with @option{-q}, not printing the introductory message. On
49052 the other hand, using:
49053
49054 @smallexample
49055 gdb --args ./a.out -q
49056 @end smallexample
49057
49058 @noindent
49059 starts @value{GDBN} with the introductory message, and passes the option to the inferior.
49060
49061 @item --pid=@var{pid}
49062 Attach @value{GDBN} to an already running program, with the PID @var{pid}.
49063
49064 @item --tui
49065 Open the terminal user interface.
49066
49067 @item --readnow
49068 Read all symbols from the given symfile on the first access.
49069
49070 @item --readnever
49071 Do not read symbol files.
49072
49073 @item --return-child-result
49074 @value{GDBN}'s exit code will be the same as the child's exit code.
49075
49076 @item --configuration
49077 Print details about GDB configuration and then exit.
49078
49079 @item --version
49080 Print version information and then exit.
49081
49082 @item --cd=@var{directory}
49083 Run @value{GDBN} using @var{directory} as its working directory,
49084 instead of the current directory.
49085
49086 @item --data-directory=@var{directory}
49087 @item -D
49088 Run @value{GDBN} using @var{directory} as its data directory. The data
49089 directory is where @value{GDBN} searches for its auxiliary files.
49090
49091 @item --fullname
49092 @itemx -f
49093 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
49094 @value{GDBN} to output the full file name and line number in a standard,
49095 recognizable fashion each time a stack frame is displayed (which
49096 includes each time the program stops). This recognizable format looks
49097 like two @samp{\032} characters, followed by the file name, line number
49098 and character position separated by colons, and a newline. The
49099 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
49100 characters as a signal to display the source code for the frame.
49101
49102 @item -b @var{baudrate}
49103 Set the line speed (baud rate or bits per second) of any serial
49104 interface used by @value{GDBN} for remote debugging.
49105
49106 @item -l @var{timeout}
49107 Set timeout, in seconds, for remote debugging.
49108
49109 @item --tty=@var{device}
49110 Run using @var{device} for your program's standard input and output.
49111 @end table
49112 @c man end
49113
49114 @c man begin SEEALSO gdb
49115 @ifset man
49116 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
49117 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
49118 documentation are properly installed at your site, the command
49119
49120 @smallexample
49121 info gdb
49122 @end smallexample
49123
49124 @noindent
49125 should give you access to the complete manual.
49126
49127 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
49128 Richard M. Stallman and Roland H. Pesch, July 1991.
49129 @end ifset
49130 @c man end
49131
49132 @node gdbserver man
49133 @heading gdbserver man
49134
49135 @c man title gdbserver Remote Server for the GNU Debugger
49136 @format
49137 @c man begin SYNOPSIS gdbserver
49138 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
49139
49140 gdbserver --attach @var{comm} @var{pid}
49141
49142 gdbserver --multi @var{comm}
49143 @c man end
49144 @end format
49145
49146 @c man begin DESCRIPTION gdbserver
49147 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
49148 than the one which is running the program being debugged.
49149
49150 @ifclear man
49151 @subheading Usage (server (target) side)
49152 @end ifclear
49153 @ifset man
49154 Usage (server (target) side):
49155 @end ifset
49156
49157 First, you need to have a copy of the program you want to debug put onto
49158 the target system. The program can be stripped to save space if needed, as
49159 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
49160 the @value{GDBN} running on the host system.
49161
49162 To use the server, you log on to the target system, and run the @command{gdbserver}
49163 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
49164 your program, and (c) its arguments. The general syntax is:
49165
49166 @smallexample
49167 target> gdbserver @var{comm} @var{program} [@var{args} ...]
49168 @end smallexample
49169
49170 For example, using a serial port, you might say:
49171
49172 @smallexample
49173 @ifset man
49174 @c @file would wrap it as F</dev/com1>.
49175 target> gdbserver /dev/com1 emacs foo.txt
49176 @end ifset
49177 @ifclear man
49178 target> gdbserver @file{/dev/com1} emacs foo.txt
49179 @end ifclear
49180 @end smallexample
49181
49182 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
49183 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
49184 waits patiently for the host @value{GDBN} to communicate with it.
49185
49186 To use a TCP connection, you could say:
49187
49188 @smallexample
49189 target> gdbserver host:2345 emacs foo.txt
49190 @end smallexample
49191
49192 This says pretty much the same thing as the last example, except that we are
49193 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
49194 that we are expecting to see a TCP connection from @code{host} to local TCP port
49195 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
49196 want for the port number as long as it does not conflict with any existing TCP
49197 ports on the target system. This same port number must be used in the host
49198 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
49199 you chose a port number that conflicts with another service, @command{gdbserver} will
49200 print an error message and exit.
49201
49202 @command{gdbserver} can also attach to running programs.
49203 This is accomplished via the @option{--attach} argument. The syntax is:
49204
49205 @smallexample
49206 target> gdbserver --attach @var{comm} @var{pid}
49207 @end smallexample
49208
49209 @var{pid} is the process ID of a currently running process. It isn't
49210 necessary to point @command{gdbserver} at a binary for the running process.
49211
49212 To start @code{gdbserver} without supplying an initial command to run
49213 or process ID to attach, use the @option{--multi} command line option.
49214 In such case you should connect using @kbd{target extended-remote} to start
49215 the program you want to debug.
49216
49217 @smallexample
49218 target> gdbserver --multi @var{comm}
49219 @end smallexample
49220
49221 @ifclear man
49222 @subheading Usage (host side)
49223 @end ifclear
49224 @ifset man
49225 Usage (host side):
49226 @end ifset
49227
49228 You need an unstripped copy of the target program on your host system, since
49229 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
49230 would, with the target program as the first argument. (You may need to use the
49231 @option{--baud} option if the serial line is running at anything except 9600 baud.)
49232 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
49233 new command you need to know about is @code{target remote}
49234 (or @code{target extended-remote}). Its argument is either
49235 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
49236 descriptor. For example:
49237
49238 @smallexample
49239 @ifset man
49240 @c @file would wrap it as F</dev/ttyb>.
49241 (@value{GDBP}) target remote /dev/ttyb
49242 @end ifset
49243 @ifclear man
49244 (@value{GDBP}) target remote @file{/dev/ttyb}
49245 @end ifclear
49246 @end smallexample
49247
49248 @noindent
49249 communicates with the server via serial line @file{/dev/ttyb}, and:
49250
49251 @smallexample
49252 (@value{GDBP}) target remote the-target:2345
49253 @end smallexample
49254
49255 @noindent
49256 communicates via a TCP connection to port 2345 on host `the-target', where
49257 you previously started up @command{gdbserver} with the same port number. Note that for
49258 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
49259 command, otherwise you may get an error that looks something like
49260 `Connection refused'.
49261
49262 @command{gdbserver} can also debug multiple inferiors at once,
49263 described in
49264 @ifset man
49265 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
49266 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
49267 @end ifset
49268 @ifclear man
49269 @ref{Inferiors Connections and Programs}.
49270 @end ifclear
49271 In such case use the @code{extended-remote} @value{GDBN} command variant:
49272
49273 @smallexample
49274 (@value{GDBP}) target extended-remote the-target:2345
49275 @end smallexample
49276
49277 The @command{gdbserver} option @option{--multi} may or may not be used in such
49278 case.
49279 @c man end
49280
49281 @c man begin OPTIONS gdbserver
49282 There are three different modes for invoking @command{gdbserver}:
49283
49284 @itemize @bullet
49285
49286 @item
49287 Debug a specific program specified by its program name:
49288
49289 @smallexample
49290 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
49291 @end smallexample
49292
49293 The @var{comm} parameter specifies how should the server communicate
49294 with @value{GDBN}; it is either a device name (to use a serial line),
49295 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
49296 stdin/stdout of @code{gdbserver}. Specify the name of the program to
49297 debug in @var{prog}. Any remaining arguments will be passed to the
49298 program verbatim. When the program exits, @value{GDBN} will close the
49299 connection, and @code{gdbserver} will exit.
49300
49301 @item
49302 Debug a specific program by specifying the process ID of a running
49303 program:
49304
49305 @smallexample
49306 gdbserver --attach @var{comm} @var{pid}
49307 @end smallexample
49308
49309 The @var{comm} parameter is as described above. Supply the process ID
49310 of a running program in @var{pid}; @value{GDBN} will do everything
49311 else. Like with the previous mode, when the process @var{pid} exits,
49312 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
49313
49314 @item
49315 Multi-process mode -- debug more than one program/process:
49316
49317 @smallexample
49318 gdbserver --multi @var{comm}
49319 @end smallexample
49320
49321 In this mode, @value{GDBN} can instruct @command{gdbserver} which
49322 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
49323 close the connection when a process being debugged exits, so you can
49324 debug several processes in the same session.
49325 @end itemize
49326
49327 In each of the modes you may specify these options:
49328
49329 @table @env
49330
49331 @item --help
49332 List all options, with brief explanations.
49333
49334 @item --version
49335 This option causes @command{gdbserver} to print its version number and exit.
49336
49337 @item --attach
49338 @command{gdbserver} will attach to a running program. The syntax is:
49339
49340 @smallexample
49341 target> gdbserver --attach @var{comm} @var{pid}
49342 @end smallexample
49343
49344 @var{pid} is the process ID of a currently running process. It isn't
49345 necessary to point @command{gdbserver} at a binary for the running process.
49346
49347 @item --multi
49348 To start @code{gdbserver} without supplying an initial command to run
49349 or process ID to attach, use this command line option.
49350 Then you can connect using @kbd{target extended-remote} and start
49351 the program you want to debug. The syntax is:
49352
49353 @smallexample
49354 target> gdbserver --multi @var{comm}
49355 @end smallexample
49356
49357 @item --debug
49358 Instruct @code{gdbserver} to display extra status information about the debugging
49359 process.
49360 This option is intended for @code{gdbserver} development and for bug reports to
49361 the developers.
49362
49363 @item --remote-debug
49364 Instruct @code{gdbserver} to display remote protocol debug output.
49365 This option is intended for @code{gdbserver} development and for bug reports to
49366 the developers.
49367
49368 @item --debug-file=@var{filename}
49369 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
49370 This option is intended for @code{gdbserver} development and for bug reports to
49371 the developers.
49372
49373 @item --debug-format=option1@r{[},option2,...@r{]}
49374 Instruct @code{gdbserver} to include extra information in each line
49375 of debugging output.
49376 @xref{Other Command-Line Arguments for gdbserver}.
49377
49378 @item --wrapper
49379 Specify a wrapper to launch programs
49380 for debugging. The option should be followed by the name of the
49381 wrapper, then any command-line arguments to pass to the wrapper, then
49382 @kbd{--} indicating the end of the wrapper arguments.
49383
49384 @item --once
49385 By default, @command{gdbserver} keeps the listening TCP port open, so that
49386 additional connections are possible. However, if you start @code{gdbserver}
49387 with the @option{--once} option, it will stop listening for any further
49388 connection attempts after connecting to the first @value{GDBN} session.
49389
49390 @c --disable-packet is not documented for users.
49391
49392 @c --disable-randomization and --no-disable-randomization are superseded by
49393 @c QDisableRandomization.
49394
49395 @end table
49396 @c man end
49397
49398 @c man begin SEEALSO gdbserver
49399 @ifset man
49400 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
49401 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
49402 documentation are properly installed at your site, the command
49403
49404 @smallexample
49405 info gdb
49406 @end smallexample
49407
49408 should give you access to the complete manual.
49409
49410 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
49411 Richard M. Stallman and Roland H. Pesch, July 1991.
49412 @end ifset
49413 @c man end
49414
49415 @node gcore man
49416 @heading gcore
49417
49418 @c man title gcore Generate a core file of a running program
49419
49420 @format
49421 @c man begin SYNOPSIS gcore
49422 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
49423 @c man end
49424 @end format
49425
49426 @c man begin DESCRIPTION gcore
49427 Generate core dumps of one or more running programs with process IDs
49428 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
49429 is equivalent to one produced by the kernel when the process crashes
49430 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
49431 limit). However, unlike after a crash, after @command{gcore} finishes
49432 its job the program remains running without any change.
49433 @c man end
49434
49435 @c man begin OPTIONS gcore
49436 @table @env
49437 @item -a
49438 Dump all memory mappings. The actual effect of this option depends on
49439 the Operating System. On @sc{gnu}/Linux, it will disable
49440 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
49441 enable @code{dump-excluded-mappings} (@pxref{set
49442 dump-excluded-mappings}).
49443
49444 @item -o @var{prefix}
49445 The optional argument @var{prefix} specifies the prefix to be used
49446 when composing the file names of the core dumps. The file name is
49447 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
49448 process ID of the running program being analyzed by @command{gcore}.
49449 If not specified, @var{prefix} defaults to @var{gcore}.
49450 @end table
49451 @c man end
49452
49453 @c man begin SEEALSO gcore
49454 @ifset man
49455 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
49456 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
49457 documentation are properly installed at your site, the command
49458
49459 @smallexample
49460 info gdb
49461 @end smallexample
49462
49463 @noindent
49464 should give you access to the complete manual.
49465
49466 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
49467 Richard M. Stallman and Roland H. Pesch, July 1991.
49468 @end ifset
49469 @c man end
49470
49471 @node gdbinit man
49472 @heading gdbinit
49473
49474 @c man title gdbinit GDB initialization scripts
49475
49476 @format
49477 @c man begin SYNOPSIS gdbinit
49478 @ifset SYSTEM_GDBINIT
49479 @value{SYSTEM_GDBINIT}
49480 @end ifset
49481
49482 @ifset SYSTEM_GDBINIT_DIR
49483 @value{SYSTEM_GDBINIT_DIR}/*
49484 @end ifset
49485
49486 ~/.config/gdb/gdbinit
49487
49488 ~/.gdbinit
49489
49490 ./.gdbinit
49491 @c man end
49492 @end format
49493
49494 @c man begin DESCRIPTION gdbinit
49495 These files contain @value{GDBN} commands to automatically execute during
49496 @value{GDBN} startup. The lines of contents are canned sequences of commands,
49497 described in
49498 @ifset man
49499 the @value{GDBN} manual in node @code{Sequences}
49500 -- shell command @code{info -f gdb -n Sequences}.
49501 @end ifset
49502 @ifclear man
49503 @ref{Sequences}.
49504 @end ifclear
49505
49506 Please read more in
49507 @ifset man
49508 the @value{GDBN} manual in node @code{Startup}
49509 -- shell command @code{info -f gdb -n Startup}.
49510 @end ifset
49511 @ifclear man
49512 @ref{Startup}.
49513 @end ifclear
49514
49515 @table @env
49516 @ifset SYSTEM_GDBINIT
49517 @item @value{SYSTEM_GDBINIT}
49518 @end ifset
49519 @ifclear SYSTEM_GDBINIT
49520 @item (not enabled with @code{--with-system-gdbinit} during compilation)
49521 @end ifclear
49522 System-wide initialization file. It is executed unless user specified
49523 @value{GDBN} option @code{-nx} or @code{-n}.
49524 See more in
49525 @ifset man
49526 the @value{GDBN} manual in node @code{System-wide configuration}
49527 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
49528 @end ifset
49529 @ifset SYSTEM_GDBINIT_DIR
49530 @item @value{SYSTEM_GDBINIT_DIR}
49531 @end ifset
49532 @ifclear SYSTEM_GDBINIT_DIR
49533 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
49534 @end ifclear
49535 System-wide initialization directory. All files in this directory are
49536 executed on startup unless user specified @value{GDBN} option @code{-nx} or
49537 @code{-n}, as long as they have a recognized file extension.
49538 See more in
49539 @ifset man
49540 the @value{GDBN} manual in node @code{System-wide configuration}
49541 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
49542 @end ifset
49543 @ifclear man
49544 @ref{System-wide configuration}.
49545 @end ifclear
49546
49547 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
49548 User initialization file. It is executed unless user specified
49549 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
49550
49551 @item @file{.gdbinit}
49552 Initialization file for current directory. It may need to be enabled with
49553 @value{GDBN} security command @code{set auto-load local-gdbinit}.
49554 See more in
49555 @ifset man
49556 the @value{GDBN} manual in node @code{Init File in the Current Directory}
49557 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
49558 @end ifset
49559 @ifclear man
49560 @ref{Init File in the Current Directory}.
49561 @end ifclear
49562 @end table
49563 @c man end
49564
49565 @c man begin SEEALSO gdbinit
49566 @ifset man
49567 gdb(1), @code{info -f gdb -n Startup}
49568
49569 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
49570 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
49571 documentation are properly installed at your site, the command
49572
49573 @smallexample
49574 info gdb
49575 @end smallexample
49576
49577 should give you access to the complete manual.
49578
49579 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
49580 Richard M. Stallman and Roland H. Pesch, July 1991.
49581 @end ifset
49582 @c man end
49583
49584 @node gdb-add-index man
49585 @heading gdb-add-index
49586 @pindex gdb-add-index
49587 @anchor{gdb-add-index}
49588
49589 @c man title gdb-add-index Add index files to speed up GDB
49590
49591 @c man begin SYNOPSIS gdb-add-index
49592 gdb-add-index @var{filename}
49593 @c man end
49594
49595 @c man begin DESCRIPTION gdb-add-index
49596 When @value{GDBN} finds a symbol file, it scans the symbols in the
49597 file in order to construct an internal symbol table. This lets most
49598 @value{GDBN} operations work quickly--at the cost of a delay early on.
49599 For large programs, this delay can be quite lengthy, so @value{GDBN}
49600 provides a way to build an index, which speeds up startup.
49601
49602 To determine whether a file contains such an index, use the command
49603 @kbd{readelf -S filename}: the index is stored in a section named
49604 @code{.gdb_index}. The index file can only be produced on systems
49605 which use ELF binaries and DWARF debug information (i.e., sections
49606 named @code{.debug_*}).
49607
49608 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
49609 in the @env{PATH} environment variable. If you want to use different
49610 versions of these programs, you can specify them through the
49611 @env{GDB} and @env{OBJDUMP} environment variables.
49612
49613 See more in
49614 @ifset man
49615 the @value{GDBN} manual in node @code{Index Files}
49616 -- shell command @kbd{info -f gdb -n "Index Files"}.
49617 @end ifset
49618 @ifclear man
49619 @ref{Index Files}.
49620 @end ifclear
49621 @c man end
49622
49623 @c man begin SEEALSO gdb-add-index
49624 @ifset man
49625 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
49626 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
49627 documentation are properly installed at your site, the command
49628
49629 @smallexample
49630 info gdb
49631 @end smallexample
49632
49633 should give you access to the complete manual.
49634
49635 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
49636 Richard M. Stallman and Roland H. Pesch, July 1991.
49637 @end ifset
49638 @c man end
49639
49640 @include gpl.texi
49641
49642 @node GNU Free Documentation License
49643 @appendix GNU Free Documentation License
49644 @include fdl.texi
49645
49646 @node Concept Index
49647 @unnumbered Concept Index
49648
49649 @printindex cp
49650
49651 @node Command and Variable Index
49652 @unnumbered Command, Variable, and Function Index
49653
49654 @printindex fn
49655
49656 @tex
49657 % I think something like @@colophon should be in texinfo. In the
49658 % meantime:
49659 \long\def\colophon{\hbox to0pt{}\vfill
49660 \centerline{The body of this manual is set in}
49661 \centerline{\fontname\tenrm,}
49662 \centerline{with headings in {\bf\fontname\tenbf}}
49663 \centerline{and examples in {\tt\fontname\tentt}.}
49664 \centerline{{\it\fontname\tenit\/},}
49665 \centerline{{\bf\fontname\tenbf}, and}
49666 \centerline{{\sl\fontname\tensl\/}}
49667 \centerline{are used for emphasis.}\vfill}
49668 \page\colophon
49669 % Blame: doc@@cygnus.com, 1991.
49670 @end tex
49671
49672 @bye