Document how GDB searches for files when using -s, -e, and -se options
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2022 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-2022 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-2022 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 GDB
178 * Maintenance Commands:: Maintenance Commands
179 * Remote Protocol:: GDB Remote Serial Protocol
180 * Agent Expressions:: The GDB Agent Expression Mechanism
181 * Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
183 * Operating System Information:: Getting additional information from
184 the operating system
185 * Trace File Format:: GDB 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 GDB
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 standard 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 The utility @code{make} is often needed in development environments.
1633 You do not have to use the @code{shell} command for this purpose in
1634 @value{GDBN}:
1635
1636 @table @code
1637 @kindex make
1638 @cindex calling make
1639 @item make @var{make-args}
1640 Execute the @code{make} program with the specified
1641 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1642 @end table
1643
1644 @table @code
1645 @kindex pipe
1646 @kindex |
1647 @cindex send the output of a gdb command to a shell command
1648 @anchor{pipe}
1649 @item pipe [@var{command}] | @var{shell_command}
1650 @itemx | [@var{command}] | @var{shell_command}
1651 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1652 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1653 Executes @var{command} and sends its output to @var{shell_command}.
1654 Note that no space is needed around @code{|}.
1655 If no @var{command} is provided, the last command executed is repeated.
1656
1657 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1658 can be used to specify an alternate delimiter string @var{delim} that separates
1659 the @var{command} from the @var{shell_command}.
1660
1661 Example:
1662 @smallexample
1663 @group
1664 (gdb) p var
1665 $1 = @{
1666 black = 144,
1667 red = 233,
1668 green = 377,
1669 blue = 610,
1670 white = 987
1671 @}
1672 @end group
1673 @group
1674 (gdb) pipe p var|wc
1675 7 19 80
1676 (gdb) |p var|wc -l
1677 7
1678 @end group
1679 @group
1680 (gdb) p /x var
1681 $4 = @{
1682 black = 0x90,
1683 red = 0xe9,
1684 green = 0x179,
1685 blue = 0x262,
1686 white = 0x3db
1687 @}
1688 (gdb) ||grep red
1689 red => 0xe9,
1690 @end group
1691 @group
1692 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1693 this contains a PIPE char
1694 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1695 this contains a PIPE char!
1696 (gdb)
1697 @end group
1698 @end smallexample
1699 @end table
1700
1701 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1702 can be used to examine the exit status of the last shell command launched
1703 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1704 @xref{Convenience Vars,, Convenience Variables}.
1705
1706 @node Logging Output
1707 @section Logging Output
1708 @cindex logging @value{GDBN} output
1709 @cindex save @value{GDBN} output to a file
1710
1711 You may want to save the output of @value{GDBN} commands to a file.
1712 There are several commands to control @value{GDBN}'s logging.
1713
1714 @table @code
1715 @kindex set logging enabled
1716 @item set logging enabled [on|off]
1717 Enable or disable logging.
1718 @cindex logging file name
1719 @item set logging file @var{file}
1720 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1721 @item set logging overwrite [on|off]
1722 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1723 you want @code{set logging enabled on} to overwrite the logfile instead.
1724 @item set logging redirect [on|off]
1725 By default, @value{GDBN} output will go to both the terminal and the logfile.
1726 Set @code{redirect} if you want output to go only to the log file.
1727 @item set logging debugredirect [on|off]
1728 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1729 Set @code{debugredirect} if you want debug output to go only to the log file.
1730 @kindex show logging
1731 @item show logging
1732 Show the current values of the logging settings.
1733 @end table
1734
1735 You can also redirect the output of a @value{GDBN} command to a
1736 shell command. @xref{pipe}.
1737 @node Commands
1738 @chapter @value{GDBN} Commands
1739
1740 You can abbreviate a @value{GDBN} command to the first few letters of the command
1741 name, if that abbreviation is unambiguous; and you can repeat certain
1742 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1743 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1744 show you the alternatives available, if there is more than one possibility).
1745
1746 @menu
1747 * Command Syntax:: How to give commands to @value{GDBN}
1748 * Command Settings:: How to change default behavior of commands
1749 * Completion:: Command completion
1750 * Command Options:: Command options
1751 * Help:: How to ask @value{GDBN} for help
1752 @end menu
1753
1754 @node Command Syntax
1755 @section Command Syntax
1756
1757 A @value{GDBN} command is a single line of input. There is no limit on
1758 how long it can be. It starts with a command name, which is followed by
1759 arguments whose meaning depends on the command name. For example, the
1760 command @code{step} accepts an argument which is the number of times to
1761 step, as in @samp{step 5}. You can also use the @code{step} command
1762 with no arguments. Some commands do not allow any arguments.
1763
1764 @cindex abbreviation
1765 @value{GDBN} command names may always be truncated if that abbreviation is
1766 unambiguous. Other possible command abbreviations are listed in the
1767 documentation for individual commands. In some cases, even ambiguous
1768 abbreviations are allowed; for example, @code{s} is specially defined as
1769 equivalent to @code{step} even though there are other commands whose
1770 names start with @code{s}. You can test abbreviations by using them as
1771 arguments to the @code{help} command.
1772
1773 @cindex repeating commands
1774 @kindex RET @r{(repeat last command)}
1775 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1776 repeat the previous command. Certain commands (for example, @code{run})
1777 will not repeat this way; these are commands whose unintentional
1778 repetition might cause trouble and which you are unlikely to want to
1779 repeat. User-defined commands can disable this feature; see
1780 @ref{Define, dont-repeat}.
1781
1782 The @code{list} and @code{x} commands, when you repeat them with
1783 @key{RET}, construct new arguments rather than repeating
1784 exactly as typed. This permits easy scanning of source or memory.
1785
1786 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1787 output, in a way similar to the common utility @code{more}
1788 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1789 @key{RET} too many in this situation, @value{GDBN} disables command
1790 repetition after any command that generates this sort of display.
1791
1792 @kindex # @r{(a comment)}
1793 @cindex comment
1794 Any text from a @kbd{#} to the end of the line is a comment; it does
1795 nothing. This is useful mainly in command files (@pxref{Command
1796 Files,,Command Files}).
1797
1798 @cindex repeating command sequences
1799 @kindex Ctrl-o @r{(operate-and-get-next)}
1800 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1801 commands. This command accepts the current line, like @key{RET}, and
1802 then fetches the next line relative to the current line from the history
1803 for editing.
1804
1805
1806 @node Command Settings
1807 @section Command Settings
1808 @cindex default behavior of commands, changing
1809 @cindex default settings, changing
1810
1811 Many commands change their behavior according to command-specific
1812 variables or settings. These settings can be changed with the
1813 @code{set} subcommands. For example, the @code{print} command
1814 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1815 settings changeable with the commands @code{set print elements
1816 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1817
1818 You can change these settings to your preference in the gdbinit files
1819 loaded at @value{GDBN} startup. @xref{Startup}.
1820
1821 The settings can also be changed interactively during the debugging
1822 session. For example, to change the limit of array elements to print,
1823 you can do the following:
1824 @smallexample
1825 (@value{GDBN}) set print elements 10
1826 (@value{GDBN}) print some_array
1827 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1828 @end smallexample
1829
1830 The above @code{set print elements 10} command changes the number of
1831 elements to print from the default of 200 to 10. If you only intend
1832 this limit of 10 to be used for printing @code{some_array}, then you
1833 must restore the limit back to 200, with @code{set print elements
1834 200}.
1835
1836 Some commands allow overriding settings with command options. For
1837 example, the @code{print} command supports a number of options that
1838 allow overriding relevant global print settings as set by @code{set
1839 print} subcommands. @xref{print options}. The example above could be
1840 rewritten as:
1841 @smallexample
1842 (@value{GDBN}) print -elements 10 -- some_array
1843 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1844 @end smallexample
1845
1846 Alternatively, you can use the @code{with} command to change a setting
1847 temporarily, for the duration of a command invocation.
1848
1849 @table @code
1850 @kindex with command
1851 @kindex w @r{(@code{with})}
1852 @cindex settings
1853 @cindex temporarily change settings
1854 @item with @var{setting} [@var{value}] [-- @var{command}]
1855 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1856 Temporarily set @var{setting} to @var{value} for the duration of
1857 @var{command}.
1858
1859 @var{setting} is any setting you can change with the @code{set}
1860 subcommands. @var{value} is the value to assign to @code{setting}
1861 while running @code{command}.
1862
1863 If no @var{command} is provided, the last command executed is
1864 repeated.
1865
1866 If a @var{command} is provided, it must be preceded by a double dash
1867 (@code{--}) separator. This is required because some settings accept
1868 free-form arguments, such as expressions or filenames.
1869
1870 For example, the command
1871 @smallexample
1872 (@value{GDBN}) with print array on -- print some_array
1873 @end smallexample
1874 @noindent
1875 is equivalent to the following 3 commands:
1876 @smallexample
1877 (@value{GDBN}) set print array on
1878 (@value{GDBN}) print some_array
1879 (@value{GDBN}) set print array off
1880 @end smallexample
1881
1882 The @code{with} command is particularly useful when you want to
1883 override a setting while running user-defined commands, or commands
1884 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1885
1886 @smallexample
1887 (@value{GDBN}) with print pretty on -- my_complex_command
1888 @end smallexample
1889
1890 To change several settings for the same command, you can nest
1891 @code{with} commands. For example, @code{with language ada -- with
1892 print elements 10} temporarily changes the language to Ada and sets a
1893 limit of 10 elements to print for arrays and strings.
1894
1895 @end table
1896
1897 @node Completion
1898 @section Command Completion
1899
1900 @cindex completion
1901 @cindex word completion
1902 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1903 only one possibility; it can also show you what the valid possibilities
1904 are for the next word in a command, at any time. This works for @value{GDBN}
1905 commands, @value{GDBN} subcommands, command options, and the names of symbols
1906 in your program.
1907
1908 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1909 of a word. If there is only one possibility, @value{GDBN} fills in the
1910 word, and waits for you to finish the command (or press @key{RET} to
1911 enter it). For example, if you type
1912
1913 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1914 @c complete accuracy in these examples; space introduced for clarity.
1915 @c If texinfo enhancements make it unnecessary, it would be nice to
1916 @c replace " @key" by "@key" in the following...
1917 @smallexample
1918 (@value{GDBP}) info bre @key{TAB}
1919 @end smallexample
1920
1921 @noindent
1922 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1923 the only @code{info} subcommand beginning with @samp{bre}:
1924
1925 @smallexample
1926 (@value{GDBP}) info breakpoints
1927 @end smallexample
1928
1929 @noindent
1930 You can either press @key{RET} at this point, to run the @code{info
1931 breakpoints} command, or backspace and enter something else, if
1932 @samp{breakpoints} does not look like the command you expected. (If you
1933 were sure you wanted @code{info breakpoints} in the first place, you
1934 might as well just type @key{RET} immediately after @samp{info bre},
1935 to exploit command abbreviations rather than command completion).
1936
1937 If there is more than one possibility for the next word when you press
1938 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1939 characters and try again, or just press @key{TAB} a second time;
1940 @value{GDBN} displays all the possible completions for that word. For
1941 example, you might want to set a breakpoint on a subroutine whose name
1942 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1943 just sounds the bell. Typing @key{TAB} again displays all the
1944 function names in your program that begin with those characters, for
1945 example:
1946
1947 @smallexample
1948 (@value{GDBP}) b make_ @key{TAB}
1949 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1950 make_a_section_from_file make_environ
1951 make_abs_section make_function_type
1952 make_blockvector make_pointer_type
1953 make_cleanup make_reference_type
1954 make_command make_symbol_completion_list
1955 (@value{GDBP}) b make_
1956 @end smallexample
1957
1958 @noindent
1959 After displaying the available possibilities, @value{GDBN} copies your
1960 partial input (@samp{b make_} in the example) so you can finish the
1961 command.
1962
1963 If you just want to see the list of alternatives in the first place, you
1964 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1965 means @kbd{@key{META} ?}. You can type this either by holding down a
1966 key designated as the @key{META} shift on your keyboard (if there is
1967 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1968
1969 If the number of possible completions is large, @value{GDBN} will
1970 print as much of the list as it has collected, as well as a message
1971 indicating that the list may be truncated.
1972
1973 @smallexample
1974 (@value{GDBP}) b m@key{TAB}@key{TAB}
1975 main
1976 <... the rest of the possible completions ...>
1977 *** List may be truncated, max-completions reached. ***
1978 (@value{GDBP}) b m
1979 @end smallexample
1980
1981 @noindent
1982 This behavior can be controlled with the following commands:
1983
1984 @table @code
1985 @kindex set max-completions
1986 @item set max-completions @var{limit}
1987 @itemx set max-completions unlimited
1988 Set the maximum number of completion candidates. @value{GDBN} will
1989 stop looking for more completions once it collects this many candidates.
1990 This is useful when completing on things like function names as collecting
1991 all the possible candidates can be time consuming.
1992 The default value is 200. A value of zero disables tab-completion.
1993 Note that setting either no limit or a very large limit can make
1994 completion slow.
1995 @kindex show max-completions
1996 @item show max-completions
1997 Show the maximum number of candidates that @value{GDBN} will collect and show
1998 during completion.
1999 @end table
2000
2001 @cindex quotes in commands
2002 @cindex completion of quoted strings
2003 Sometimes the string you need, while logically a ``word'', may contain
2004 parentheses or other characters that @value{GDBN} normally excludes from
2005 its notion of a word. To permit word completion to work in this
2006 situation, you may enclose words in @code{'} (single quote marks) in
2007 @value{GDBN} commands.
2008
2009 A likely situation where you might need this is in typing an
2010 expression that involves a C@t{++} symbol name with template
2011 parameters. This is because when completing expressions, GDB treats
2012 the @samp{<} character as word delimiter, assuming that it's the
2013 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
2014 Operators}).
2015
2016 For example, when you want to call a C@t{++} template function
2017 interactively using the @code{print} or @code{call} commands, you may
2018 need to distinguish whether you mean the version of @code{name} that
2019 was specialized for @code{int}, @code{name<int>()}, or the version
2020 that was specialized for @code{float}, @code{name<float>()}. To use
2021 the word-completion facilities in this situation, type a single quote
2022 @code{'} at the beginning of the function name. This alerts
2023 @value{GDBN} that it may need to consider more information than usual
2024 when you press @key{TAB} or @kbd{M-?} to request word completion:
2025
2026 @smallexample
2027 (@value{GDBP}) p 'func< @kbd{M-?}
2028 func<int>() func<float>()
2029 (@value{GDBP}) p 'func<
2030 @end smallexample
2031
2032 When setting breakpoints however (@pxref{Location Specifications}), you don't
2033 usually need to type a quote before the function name, because
2034 @value{GDBN} understands that you want to set a breakpoint on a
2035 function:
2036
2037 @smallexample
2038 (@value{GDBP}) b func< @kbd{M-?}
2039 func<int>() func<float>()
2040 (@value{GDBP}) b func<
2041 @end smallexample
2042
2043 This is true even in the case of typing the name of C@t{++} overloaded
2044 functions (multiple definitions of the same function, distinguished by
2045 argument type). For example, when you want to set a breakpoint you
2046 don't need to distinguish whether you mean the version of @code{name}
2047 that takes an @code{int} parameter, @code{name(int)}, or the version
2048 that takes a @code{float} parameter, @code{name(float)}.
2049
2050 @smallexample
2051 (@value{GDBP}) b bubble( @kbd{M-?}
2052 bubble(int) bubble(double)
2053 (@value{GDBP}) b bubble(dou @kbd{M-?}
2054 bubble(double)
2055 @end smallexample
2056
2057 See @ref{quoting names} for a description of other scenarios that
2058 require quoting.
2059
2060 For more information about overloaded functions, see @ref{C Plus Plus
2061 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
2062 overload-resolution off} to disable overload resolution;
2063 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
2064
2065 @cindex completion of structure field names
2066 @cindex structure field name completion
2067 @cindex completion of union field names
2068 @cindex union field name completion
2069 When completing in an expression which looks up a field in a
2070 structure, @value{GDBN} also tries@footnote{The completer can be
2071 confused by certain kinds of invalid expressions. Also, it only
2072 examines the static type of the expression, not the dynamic type.} to
2073 limit completions to the field names available in the type of the
2074 left-hand-side:
2075
2076 @smallexample
2077 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
2078 magic to_fputs to_rewind
2079 to_data to_isatty to_write
2080 to_delete to_put to_write_async_safe
2081 to_flush to_read
2082 @end smallexample
2083
2084 @noindent
2085 This is because the @code{gdb_stdout} is a variable of the type
2086 @code{struct ui_file} that is defined in @value{GDBN} sources as
2087 follows:
2088
2089 @smallexample
2090 struct ui_file
2091 @{
2092 int *magic;
2093 ui_file_flush_ftype *to_flush;
2094 ui_file_write_ftype *to_write;
2095 ui_file_write_async_safe_ftype *to_write_async_safe;
2096 ui_file_fputs_ftype *to_fputs;
2097 ui_file_read_ftype *to_read;
2098 ui_file_delete_ftype *to_delete;
2099 ui_file_isatty_ftype *to_isatty;
2100 ui_file_rewind_ftype *to_rewind;
2101 ui_file_put_ftype *to_put;
2102 void *to_data;
2103 @}
2104 @end smallexample
2105
2106 @node Command Options
2107 @section Command options
2108
2109 @cindex command options
2110 Some commands accept options starting with a leading dash. For
2111 example, @code{print -pretty}. Similarly to command names, you can
2112 abbreviate a @value{GDBN} option to the first few letters of the
2113 option name, if that abbreviation is unambiguous, and you can also use
2114 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2115 in an option (or to show you the alternatives available, if there is
2116 more than one possibility).
2117
2118 @cindex command options, raw input
2119 Some commands take raw input as argument. For example, the print
2120 command processes arbitrary expressions in any of the languages
2121 supported by @value{GDBN}. With such commands, because raw input may
2122 start with a leading dash that would be confused with an option or any
2123 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2124 -pretty} or printing negative @code{p}?), if you specify any command
2125 option, then you must use a double-dash (@code{--}) delimiter to
2126 indicate the end of options.
2127
2128 @cindex command options, boolean
2129
2130 Some options are described as accepting an argument which can be
2131 either @code{on} or @code{off}. These are known as @dfn{boolean
2132 options}. Similarly to boolean settings commands---@code{on} and
2133 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2134 @code{enable} can also be used as ``true'' value, and any of @code{0},
2135 @code{no} and @code{disable} can also be used as ``false'' value. You
2136 can also omit a ``true'' value, as it is implied by default.
2137
2138 For example, these are equivalent:
2139
2140 @smallexample
2141 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2142 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2143 @end smallexample
2144
2145 You can discover the set of options some command accepts by completing
2146 on @code{-} after the command name. For example:
2147
2148 @smallexample
2149 (@value{GDBP}) print -@key{TAB}@key{TAB}
2150 -address -max-depth -object -static-members
2151 -array -memory-tag-violations -pretty -symbol
2152 -array-indexes -nibbles -raw-values -union
2153 -elements -null-stop -repeats -vtbl
2154 @end smallexample
2155
2156 Completion will in some cases guide you with a suggestion of what kind
2157 of argument an option expects. For example:
2158
2159 @smallexample
2160 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2161 NUMBER unlimited
2162 @end smallexample
2163
2164 Here, the option expects a number (e.g., @code{100}), not literal
2165 @code{NUMBER}. Such metasyntactical arguments are always presented in
2166 uppercase.
2167
2168 (For more on using the @code{print} command, see @ref{Data, ,Examining
2169 Data}.)
2170
2171 @node Help
2172 @section Getting Help
2173 @cindex online documentation
2174 @kindex help
2175
2176 You can always ask @value{GDBN} itself for information on its commands,
2177 using the command @code{help}.
2178
2179 @table @code
2180 @kindex h @r{(@code{help})}
2181 @item help
2182 @itemx h
2183 You can use @code{help} (abbreviated @code{h}) with no arguments to
2184 display a short list of named classes of commands:
2185
2186 @smallexample
2187 (@value{GDBP}) help
2188 List of classes of commands:
2189
2190 aliases -- User-defined aliases of other commands
2191 breakpoints -- Making program stop at certain points
2192 data -- Examining data
2193 files -- Specifying and examining files
2194 internals -- Maintenance commands
2195 obscure -- Obscure features
2196 running -- Running the program
2197 stack -- Examining the stack
2198 status -- Status inquiries
2199 support -- Support facilities
2200 tracepoints -- Tracing of program execution without
2201 stopping the program
2202 user-defined -- User-defined commands
2203
2204 Type "help" followed by a class name for a list of
2205 commands in that class.
2206 Type "help" followed by command name for full
2207 documentation.
2208 Command name abbreviations are allowed if unambiguous.
2209 (@value{GDBP})
2210 @end smallexample
2211 @c the above line break eliminates huge line overfull...
2212
2213 @item help @var{class}
2214 Using one of the general help classes as an argument, you can get a
2215 list of the individual commands in that class. If a command has
2216 aliases, the aliases are given after the command name, separated by
2217 commas. If an alias has default arguments, the full definition of
2218 the alias is given after the first line.
2219 For example, here is the help display for the class @code{status}:
2220
2221 @smallexample
2222 (@value{GDBP}) help status
2223 Status inquiries.
2224
2225 List of commands:
2226
2227 @c Line break in "show" line falsifies real output, but needed
2228 @c to fit in smallbook page size.
2229 info, inf, i -- Generic command for showing things
2230 about the program being debugged
2231 info address, iamain -- Describe where symbol SYM is stored.
2232 alias iamain = info address main
2233 info all-registers -- List of all registers and their contents,
2234 for selected stack frame.
2235 ...
2236 show, info set -- Generic command for showing things
2237 about the debugger
2238
2239 Type "help" followed by command name for full
2240 documentation.
2241 Command name abbreviations are allowed if unambiguous.
2242 (@value{GDBP})
2243 @end smallexample
2244
2245 @item help @var{command}
2246 With a command name as @code{help} argument, @value{GDBN} displays a
2247 short paragraph on how to use that command. If that command has
2248 one or more aliases, @value{GDBN} will display a first line with
2249 the command name and all its aliases separated by commas.
2250 This first line will be followed by the full definition of all aliases
2251 having default arguments.
2252
2253 @kindex apropos
2254 @item apropos [-v] @var{regexp}
2255 The @code{apropos} command searches through all of the @value{GDBN}
2256 commands, and their documentation, for the regular expression specified in
2257 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2258 which stands for @samp{verbose}, indicates to output the full documentation
2259 of the matching commands and highlight the parts of the documentation
2260 matching @var{regexp}. For example:
2261
2262 @smallexample
2263 apropos alias
2264 @end smallexample
2265
2266 @noindent
2267 results in:
2268
2269 @smallexample
2270 @group
2271 alias -- Define a new command that is an alias of an existing command
2272 aliases -- User-defined aliases of other commands
2273 @end group
2274 @end smallexample
2275
2276 @noindent
2277 while
2278
2279 @smallexample
2280 apropos -v cut.*thread apply
2281 @end smallexample
2282
2283 @noindent
2284 results in the below output, where @samp{cut for 'thread apply}
2285 is highlighted if styling is enabled.
2286
2287 @smallexample
2288 @group
2289 taas -- Apply a command to all threads (ignoring errors
2290 and empty output).
2291 Usage: taas COMMAND
2292 shortcut for 'thread apply all -s COMMAND'
2293
2294 tfaas -- Apply a command to all frames of all threads
2295 (ignoring errors and empty output).
2296 Usage: tfaas COMMAND
2297 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2298 @end group
2299 @end smallexample
2300
2301 @kindex complete
2302 @item complete @var{args}
2303 The @code{complete @var{args}} command lists all the possible completions
2304 for the beginning of a command. Use @var{args} to specify the beginning of the
2305 command you want completed. For example:
2306
2307 @smallexample
2308 complete i
2309 @end smallexample
2310
2311 @noindent results in:
2312
2313 @smallexample
2314 @group
2315 if
2316 ignore
2317 info
2318 inspect
2319 @end group
2320 @end smallexample
2321
2322 @noindent This is intended for use by @sc{gnu} Emacs.
2323 @end table
2324
2325 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2326 and @code{show} to inquire about the state of your program, or the state
2327 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2328 manual introduces each of them in the appropriate context. The listings
2329 under @code{info} and under @code{show} in the Command, Variable, and
2330 Function Index point to all the sub-commands. @xref{Command and Variable
2331 Index}.
2332
2333 @c @group
2334 @table @code
2335 @kindex info
2336 @kindex i @r{(@code{info})}
2337 @item info
2338 This command (abbreviated @code{i}) is for describing the state of your
2339 program. For example, you can show the arguments passed to a function
2340 with @code{info args}, list the registers currently in use with @code{info
2341 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2342 You can get a complete list of the @code{info} sub-commands with
2343 @w{@code{help info}}.
2344
2345 @kindex set
2346 @item set
2347 You can assign the result of an expression to an environment variable with
2348 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2349 @code{set prompt $}.
2350
2351 @kindex show
2352 @item show
2353 In contrast to @code{info}, @code{show} is for describing the state of
2354 @value{GDBN} itself.
2355 You can change most of the things you can @code{show}, by using the
2356 related command @code{set}; for example, you can control what number
2357 system is used for displays with @code{set radix}, or simply inquire
2358 which is currently in use with @code{show radix}.
2359
2360 @kindex info set
2361 To display all the settable parameters and their current
2362 values, you can use @code{show} with no arguments; you may also use
2363 @code{info set}. Both commands produce the same display.
2364 @c FIXME: "info set" violates the rule that "info" is for state of
2365 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2366 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2367 @end table
2368 @c @end group
2369
2370 Here are several miscellaneous @code{show} subcommands, all of which are
2371 exceptional in lacking corresponding @code{set} commands:
2372
2373 @table @code
2374 @kindex show version
2375 @cindex @value{GDBN} version number
2376 @item show version
2377 Show what version of @value{GDBN} is running. You should include this
2378 information in @value{GDBN} bug-reports. If multiple versions of
2379 @value{GDBN} are in use at your site, you may need to determine which
2380 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2381 commands are introduced, and old ones may wither away. Also, many
2382 system vendors ship variant versions of @value{GDBN}, and there are
2383 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2384 The version number is the same as the one announced when you start
2385 @value{GDBN}.
2386
2387 @kindex show copying
2388 @kindex info copying
2389 @cindex display @value{GDBN} copyright
2390 @item show copying
2391 @itemx info copying
2392 Display information about permission for copying @value{GDBN}.
2393
2394 @kindex show warranty
2395 @kindex info warranty
2396 @item show warranty
2397 @itemx info warranty
2398 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2399 if your version of @value{GDBN} comes with one.
2400
2401 @kindex show configuration
2402 @item show configuration
2403 Display detailed information about the way @value{GDBN} was configured
2404 when it was built. This displays the optional arguments passed to the
2405 @file{configure} script and also configuration parameters detected
2406 automatically by @command{configure}. When reporting a @value{GDBN}
2407 bug (@pxref{GDB Bugs}), it is important to include this information in
2408 your report.
2409
2410 @end table
2411
2412 @node Running
2413 @chapter Running Programs Under @value{GDBN}
2414
2415 When you run a program under @value{GDBN}, you must first generate
2416 debugging information when you compile it.
2417
2418 You may start @value{GDBN} with its arguments, if any, in an environment
2419 of your choice. If you are doing native debugging, you may redirect
2420 your program's input and output, debug an already running process, or
2421 kill a child process.
2422
2423 @menu
2424 * Compilation:: Compiling for debugging
2425 * Starting:: Starting your program
2426 * Arguments:: Your program's arguments
2427 * Environment:: Your program's environment
2428
2429 * Working Directory:: Your program's working directory
2430 * Input/Output:: Your program's input and output
2431 * Attach:: Debugging an already-running process
2432 * Kill Process:: Killing the child process
2433 * Inferiors Connections and Programs:: Debugging multiple inferiors
2434 connections and programs
2435 * Threads:: Debugging programs with multiple threads
2436 * Forks:: Debugging forks
2437 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2438 @end menu
2439
2440 @node Compilation
2441 @section Compiling for Debugging
2442
2443 In order to debug a program effectively, you need to generate
2444 debugging information when you compile it. This debugging information
2445 is stored in the object file; it describes the data type of each
2446 variable or function and the correspondence between source line numbers
2447 and addresses in the executable code.
2448
2449 To request debugging information, specify the @samp{-g} option when you run
2450 the compiler.
2451
2452 Programs that are to be shipped to your customers are compiled with
2453 optimizations, using the @samp{-O} compiler option. However, some
2454 compilers are unable to handle the @samp{-g} and @samp{-O} options
2455 together. Using those compilers, you cannot generate optimized
2456 executables containing debugging information.
2457
2458 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2459 without @samp{-O}, making it possible to debug optimized code. We
2460 recommend that you @emph{always} use @samp{-g} whenever you compile a
2461 program. You may think your program is correct, but there is no sense
2462 in pushing your luck. For more information, see @ref{Optimized Code}.
2463
2464 Older versions of the @sc{gnu} C compiler permitted a variant option
2465 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2466 format; if your @sc{gnu} C compiler has this option, do not use it.
2467
2468 @value{GDBN} knows about preprocessor macros and can show you their
2469 expansion (@pxref{Macros}). Most compilers do not include information
2470 about preprocessor macros in the debugging information if you specify
2471 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2472 the @sc{gnu} C compiler, provides macro information if you are using
2473 the DWARF debugging format, and specify the option @option{-g3}.
2474
2475 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2476 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2477 information on @value{NGCC} options affecting debug information.
2478
2479 You will have the best debugging experience if you use the latest
2480 version of the DWARF debugging format that your compiler supports.
2481 DWARF is currently the most expressive and best supported debugging
2482 format in @value{GDBN}.
2483
2484 @need 2000
2485 @node Starting
2486 @section Starting your Program
2487 @cindex starting
2488 @cindex running
2489
2490 @table @code
2491 @kindex run
2492 @kindex r @r{(@code{run})}
2493 @item run
2494 @itemx r
2495 Use the @code{run} command to start your program under @value{GDBN}.
2496 You must first specify the program name with an argument to
2497 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2498 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2499 command (@pxref{Files, ,Commands to Specify Files}).
2500
2501 @end table
2502
2503 If you are running your program in an execution environment that
2504 supports processes, @code{run} creates an inferior process and makes
2505 that process run your program. In some environments without processes,
2506 @code{run} jumps to the start of your program. Other targets,
2507 like @samp{remote}, are always running. If you get an error
2508 message like this one:
2509
2510 @smallexample
2511 The "remote" target does not support "run".
2512 Try "help target" or "continue".
2513 @end smallexample
2514
2515 @noindent
2516 then use @code{continue} to run your program. You may need @code{load}
2517 first (@pxref{load}).
2518
2519 The execution of a program is affected by certain information it
2520 receives from its superior. @value{GDBN} provides ways to specify this
2521 information, which you must do @emph{before} starting your program. (You
2522 can change it after starting your program, but such changes only affect
2523 your program the next time you start it.) This information may be
2524 divided into four categories:
2525
2526 @table @asis
2527 @item The @emph{arguments.}
2528 Specify the arguments to give your program as the arguments of the
2529 @code{run} command. If a shell is available on your target, the shell
2530 is used to pass the arguments, so that you may use normal conventions
2531 (such as wildcard expansion or variable substitution) in describing
2532 the arguments.
2533 In Unix systems, you can control which shell is used with the
2534 @env{SHELL} environment variable. If you do not define @env{SHELL},
2535 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2536 use of any shell with the @code{set startup-with-shell} command (see
2537 below for details).
2538
2539 @item The @emph{environment.}
2540 Your program normally inherits its environment from @value{GDBN}, but you can
2541 use the @value{GDBN} commands @code{set environment} and @code{unset
2542 environment} to change parts of the environment that affect
2543 your program. @xref{Environment, ,Your Program's Environment}.
2544
2545 @item The @emph{working directory.}
2546 You can set your program's working directory with the command
2547 @kbd{set cwd}. If you do not set any working directory with this
2548 command, your program will inherit @value{GDBN}'s working directory if
2549 native debugging, or the remote server's working directory if remote
2550 debugging. @xref{Working Directory, ,Your Program's Working
2551 Directory}.
2552
2553 @item The @emph{standard input and output.}
2554 Your program normally uses the same device for standard input and
2555 standard output as @value{GDBN} is using. You can redirect input and output
2556 in the @code{run} command line, or you can use the @code{tty} command to
2557 set a different device for your program.
2558 @xref{Input/Output, ,Your Program's Input and Output}.
2559
2560 @cindex pipes
2561 @emph{Warning:} While input and output redirection work, you cannot use
2562 pipes to pass the output of the program you are debugging to another
2563 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2564 wrong program.
2565 @end table
2566
2567 When you issue the @code{run} command, your program begins to execute
2568 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2569 of how to arrange for your program to stop. Once your program has
2570 stopped, you may call functions in your program, using the @code{print}
2571 or @code{call} commands. @xref{Data, ,Examining Data}.
2572
2573 If the modification time of your symbol file has changed since the last
2574 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2575 table, and reads it again. When it does this, @value{GDBN} tries to retain
2576 your current breakpoints.
2577
2578 @table @code
2579 @kindex start
2580 @item start
2581 @cindex run to main procedure
2582 The name of the main procedure can vary from language to language.
2583 With C or C@t{++}, the main procedure name is always @code{main}, but
2584 other languages such as Ada do not require a specific name for their
2585 main procedure. The debugger provides a convenient way to start the
2586 execution of the program and to stop at the beginning of the main
2587 procedure, depending on the language used.
2588
2589 The @samp{start} command does the equivalent of setting a temporary
2590 breakpoint at the beginning of the main procedure and then invoking
2591 the @samp{run} command.
2592
2593 @cindex elaboration phase
2594 Some programs contain an @dfn{elaboration} phase where some startup code is
2595 executed before the main procedure is called. This depends on the
2596 languages used to write your program. In C@t{++}, for instance,
2597 constructors for static and global objects are executed before
2598 @code{main} is called. It is therefore possible that the debugger stops
2599 before reaching the main procedure. However, the temporary breakpoint
2600 will remain to halt execution.
2601
2602 Specify the arguments to give to your program as arguments to the
2603 @samp{start} command. These arguments will be given verbatim to the
2604 underlying @samp{run} command. Note that the same arguments will be
2605 reused if no argument is provided during subsequent calls to
2606 @samp{start} or @samp{run}.
2607
2608 It is sometimes necessary to debug the program during elaboration. In
2609 these cases, using the @code{start} command would stop the execution
2610 of your program too late, as the program would have already completed
2611 the elaboration phase. Under these circumstances, either insert
2612 breakpoints in your elaboration code before running your program or
2613 use the @code{starti} command.
2614
2615 @kindex starti
2616 @item starti
2617 @cindex run to first instruction
2618 The @samp{starti} command does the equivalent of setting a temporary
2619 breakpoint at the first instruction of a program's execution and then
2620 invoking the @samp{run} command. For programs containing an
2621 elaboration phase, the @code{starti} command will stop execution at
2622 the start of the elaboration phase.
2623
2624 @anchor{set exec-wrapper}
2625 @kindex set exec-wrapper
2626 @item set exec-wrapper @var{wrapper}
2627 @itemx show exec-wrapper
2628 @itemx unset exec-wrapper
2629 When @samp{exec-wrapper} is set, the specified wrapper is used to
2630 launch programs for debugging. @value{GDBN} starts your program
2631 with a shell command of the form @kbd{exec @var{wrapper}
2632 @var{program}}. Quoting is added to @var{program} and its
2633 arguments, but not to @var{wrapper}, so you should add quotes if
2634 appropriate for your shell. The wrapper runs until it executes
2635 your program, and then @value{GDBN} takes control.
2636
2637 You can use any program that eventually calls @code{execve} with
2638 its arguments as a wrapper. Several standard Unix utilities do
2639 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2640 with @code{exec "$@@"} will also work.
2641
2642 For example, you can use @code{env} to pass an environment variable to
2643 the debugged program, without setting the variable in your shell's
2644 environment:
2645
2646 @smallexample
2647 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2648 (@value{GDBP}) run
2649 @end smallexample
2650
2651 This command is available when debugging locally on most targets, excluding
2652 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2653
2654 @kindex set startup-with-shell
2655 @anchor{set startup-with-shell}
2656 @item set startup-with-shell
2657 @itemx set startup-with-shell on
2658 @itemx set startup-with-shell off
2659 @itemx show startup-with-shell
2660 On Unix systems, by default, if a shell is available on your target,
2661 @value{GDBN}) uses it to start your program. Arguments of the
2662 @code{run} command are passed to the shell, which does variable
2663 substitution, expands wildcard characters and performs redirection of
2664 I/O. In some circumstances, it may be useful to disable such use of a
2665 shell, for example, when debugging the shell itself or diagnosing
2666 startup failures such as:
2667
2668 @smallexample
2669 (@value{GDBP}) run
2670 Starting program: ./a.out
2671 During startup program terminated with signal SIGSEGV, Segmentation fault.
2672 @end smallexample
2673
2674 @noindent
2675 which indicates the shell or the wrapper specified with
2676 @samp{exec-wrapper} crashed, not your program. Most often, this is
2677 caused by something odd in your shell's non-interactive mode
2678 initialization file---such as @file{.cshrc} for C-shell,
2679 $@file{.zshenv} for the Z shell, or the file specified in the
2680 @env{BASH_ENV} environment variable for BASH.
2681
2682 @anchor{set auto-connect-native-target}
2683 @kindex set auto-connect-native-target
2684 @item set auto-connect-native-target
2685 @itemx set auto-connect-native-target on
2686 @itemx set auto-connect-native-target off
2687 @itemx show auto-connect-native-target
2688
2689 By default, if the current inferior is not connected to any target yet
2690 (e.g., with @code{target remote}), the @code{run} command starts your
2691 program as a native process under @value{GDBN}, on your local machine.
2692 If you're sure you don't want to debug programs on your local machine,
2693 you can tell @value{GDBN} to not connect to the native target
2694 automatically with the @code{set auto-connect-native-target off}
2695 command.
2696
2697 If @code{on}, which is the default, and if the current inferior is not
2698 connected to a target already, the @code{run} command automaticaly
2699 connects to the native target, if one is available.
2700
2701 If @code{off}, and if the current inferior is not connected to a
2702 target already, the @code{run} command fails with an error:
2703
2704 @smallexample
2705 (@value{GDBP}) run
2706 Don't know how to run. Try "help target".
2707 @end smallexample
2708
2709 If the current inferior is already connected to a target, @value{GDBN}
2710 always uses it with the @code{run} command.
2711
2712 In any case, you can explicitly connect to the native target with the
2713 @code{target native} command. For example,
2714
2715 @smallexample
2716 (@value{GDBP}) set auto-connect-native-target off
2717 (@value{GDBP}) run
2718 Don't know how to run. Try "help target".
2719 (@value{GDBP}) target native
2720 (@value{GDBP}) run
2721 Starting program: ./a.out
2722 [Inferior 1 (process 10421) exited normally]
2723 @end smallexample
2724
2725 In case you connected explicitly to the @code{native} target,
2726 @value{GDBN} remains connected even if all inferiors exit, ready for
2727 the next @code{run} command. Use the @code{disconnect} command to
2728 disconnect.
2729
2730 Examples of other commands that likewise respect the
2731 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2732 proc}, @code{info os}.
2733
2734 @kindex set disable-randomization
2735 @item set disable-randomization
2736 @itemx set disable-randomization on
2737 This option (enabled by default in @value{GDBN}) will turn off the native
2738 randomization of the virtual address space of the started program. This option
2739 is useful for multiple debugging sessions to make the execution better
2740 reproducible and memory addresses reusable across debugging sessions.
2741
2742 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2743 On @sc{gnu}/Linux you can get the same behavior using
2744
2745 @smallexample
2746 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2747 @end smallexample
2748
2749 @item set disable-randomization off
2750 Leave the behavior of the started executable unchanged. Some bugs rear their
2751 ugly heads only when the program is loaded at certain addresses. If your bug
2752 disappears when you run the program under @value{GDBN}, that might be because
2753 @value{GDBN} by default disables the address randomization on platforms, such
2754 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2755 disable-randomization off} to try to reproduce such elusive bugs.
2756
2757 On targets where it is available, virtual address space randomization
2758 protects the programs against certain kinds of security attacks. In these
2759 cases the attacker needs to know the exact location of a concrete executable
2760 code. Randomizing its location makes it impossible to inject jumps misusing
2761 a code at its expected addresses.
2762
2763 Prelinking shared libraries provides a startup performance advantage but it
2764 makes addresses in these libraries predictable for privileged processes by
2765 having just unprivileged access at the target system. Reading the shared
2766 library binary gives enough information for assembling the malicious code
2767 misusing it. Still even a prelinked shared library can get loaded at a new
2768 random address just requiring the regular relocation process during the
2769 startup. Shared libraries not already prelinked are always loaded at
2770 a randomly chosen address.
2771
2772 Position independent executables (PIE) contain position independent code
2773 similar to the shared libraries and therefore such executables get loaded at
2774 a randomly chosen address upon startup. PIE executables always load even
2775 already prelinked shared libraries at a random address. You can build such
2776 executable using @command{gcc -fPIE -pie}.
2777
2778 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2779 (as long as the randomization is enabled).
2780
2781 @item show disable-randomization
2782 Show the current setting of the explicit disable of the native randomization of
2783 the virtual address space of the started program.
2784
2785 @end table
2786
2787 @node Arguments
2788 @section Your Program's Arguments
2789
2790 @cindex arguments (to your program)
2791 The arguments to your program can be specified by the arguments of the
2792 @code{run} command.
2793 They are passed to a shell, which expands wildcard characters and
2794 performs redirection of I/O, and thence to your program. Your
2795 @env{SHELL} environment variable (if it exists) specifies what shell
2796 @value{GDBN} uses. If you do not define @env{SHELL}, @value{GDBN} uses
2797 the default shell (@file{/bin/sh} on Unix).
2798
2799 On non-Unix systems, the program is usually invoked directly by
2800 @value{GDBN}, which emulates I/O redirection via the appropriate system
2801 calls, and the wildcard characters are expanded by the startup code of
2802 the program, not by the shell.
2803
2804 @code{run} with no arguments uses the same arguments used by the previous
2805 @code{run}, or those set by the @code{set args} command.
2806
2807 @table @code
2808 @kindex set args
2809 @item set args
2810 Specify the arguments to be used the next time your program is run. If
2811 @code{set args} has no arguments, @code{run} executes your program
2812 with no arguments. Once you have run your program with arguments,
2813 using @code{set args} before the next @code{run} is the only way to run
2814 it again without arguments.
2815
2816 @kindex show args
2817 @item show args
2818 Show the arguments to give your program when it is started.
2819 @end table
2820
2821 @node Environment
2822 @section Your Program's Environment
2823
2824 @cindex environment (of your program)
2825 The @dfn{environment} consists of a set of environment variables and
2826 their values. Environment variables conventionally record such things as
2827 your user name, your home directory, your terminal type, and your search
2828 path for programs to run. Usually you set up environment variables with
2829 the shell and they are inherited by all the other programs you run. When
2830 debugging, it can be useful to try running your program with a modified
2831 environment without having to start @value{GDBN} over again.
2832
2833 @table @code
2834 @kindex path
2835 @item path @var{directory}
2836 Add @var{directory} to the front of the @env{PATH} environment variable
2837 (the search path for executables) that will be passed to your program.
2838 The value of @env{PATH} used by @value{GDBN} does not change.
2839 You may specify several directory names, separated by whitespace or by a
2840 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2841 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2842 is moved to the front, so it is searched sooner.
2843
2844 You can use the string @samp{$cwd} to refer to whatever is the current
2845 working directory at the time @value{GDBN} searches the path. If you
2846 use @samp{.} instead, it refers to the directory where you executed the
2847 @code{path} command. @value{GDBN} replaces @samp{.} in the
2848 @var{directory} argument (with the current path) before adding
2849 @var{directory} to the search path.
2850 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2851 @c document that, since repeating it would be a no-op.
2852
2853 @kindex show paths
2854 @item show paths
2855 Display the list of search paths for executables (the @env{PATH}
2856 environment variable).
2857
2858 @kindex show environment
2859 @item show environment @r{[}@var{varname}@r{]}
2860 Print the value of environment variable @var{varname} to be given to
2861 your program when it starts. If you do not supply @var{varname},
2862 print the names and values of all environment variables to be given to
2863 your program. You can abbreviate @code{environment} as @code{env}.
2864
2865 @kindex set environment
2866 @anchor{set environment}
2867 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2868 Set environment variable @var{varname} to @var{value}. The value
2869 changes for your program (and the shell @value{GDBN} uses to launch
2870 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2871 values of environment variables are just strings, and any
2872 interpretation is supplied by your program itself. The @var{value}
2873 parameter is optional; if it is eliminated, the variable is set to a
2874 null value.
2875 @c "any string" here does not include leading, trailing
2876 @c blanks. Gnu asks: does anyone care?
2877
2878 For example, this command:
2879
2880 @smallexample
2881 set env USER = foo
2882 @end smallexample
2883
2884 @noindent
2885 tells the debugged program, when subsequently run, that its user is named
2886 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2887 are not actually required.)
2888
2889 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2890 which also inherits the environment set with @code{set environment}.
2891 If necessary, you can avoid that by using the @samp{env} program as a
2892 wrapper instead of using @code{set environment}. @xref{set
2893 exec-wrapper}, for an example doing just that.
2894
2895 Environment variables that are set by the user are also transmitted to
2896 @command{gdbserver} to be used when starting the remote inferior.
2897 @pxref{QEnvironmentHexEncoded}.
2898
2899 @kindex unset environment
2900 @anchor{unset environment}
2901 @item unset environment @var{varname}
2902 Remove variable @var{varname} from the environment to be passed to your
2903 program. This is different from @samp{set env @var{varname} =};
2904 @code{unset environment} removes the variable from the environment,
2905 rather than assigning it an empty value.
2906
2907 Environment variables that are unset by the user are also unset on
2908 @command{gdbserver} when starting the remote inferior.
2909 @pxref{QEnvironmentUnset}.
2910 @end table
2911
2912 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2913 the shell indicated by your @env{SHELL} environment variable if it
2914 exists (or @code{/bin/sh} if not). If your @env{SHELL} variable
2915 names a shell that runs an initialization file when started
2916 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2917 for the Z shell, or the file specified in the @env{BASH_ENV}
2918 environment variable for BASH---any variables you set in that file
2919 affect your program. You may wish to move setting of environment
2920 variables to files that are only run when you sign on, such as
2921 @file{.login} or @file{.profile}.
2922
2923 @node Working Directory
2924 @section Your Program's Working Directory
2925
2926 @cindex working directory (of your program)
2927 Each time you start your program with @code{run}, the inferior will be
2928 initialized with the current working directory specified by the
2929 @kbd{set cwd} command. If no directory has been specified by this
2930 command, then the inferior will inherit @value{GDBN}'s current working
2931 directory as its working directory if native debugging, or it will
2932 inherit the remote server's current working directory if remote
2933 debugging.
2934
2935 @table @code
2936 @kindex set cwd
2937 @cindex change inferior's working directory
2938 @anchor{set cwd command}
2939 @item set cwd @r{[}@var{directory}@r{]}
2940 Set the inferior's working directory to @var{directory}, which will be
2941 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2942 argument has been specified, the command clears the setting and resets
2943 it to an empty state. This setting has no effect on @value{GDBN}'s
2944 working directory, and it only takes effect the next time you start
2945 the inferior. The @file{~} in @var{directory} is a short for the
2946 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2947 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2948 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2949 fallback.
2950
2951 You can also change @value{GDBN}'s current working directory by using
2952 the @code{cd} command.
2953 @xref{cd command}.
2954
2955 @kindex show cwd
2956 @cindex show inferior's working directory
2957 @item show cwd
2958 Show the inferior's working directory. If no directory has been
2959 specified by @kbd{set cwd}, then the default inferior's working
2960 directory is the same as @value{GDBN}'s working directory.
2961
2962 @kindex cd
2963 @cindex change @value{GDBN}'s working directory
2964 @anchor{cd command}
2965 @item cd @r{[}@var{directory}@r{]}
2966 Set the @value{GDBN} working directory to @var{directory}. If not
2967 given, @var{directory} uses @file{'~'}.
2968
2969 The @value{GDBN} working directory serves as a default for the
2970 commands that specify files for @value{GDBN} to operate on.
2971 @xref{Files, ,Commands to Specify Files}.
2972 @xref{set cwd command}.
2973
2974 @kindex pwd
2975 @item pwd
2976 Print the @value{GDBN} working directory.
2977 @end table
2978
2979 It is generally impossible to find the current working directory of
2980 the process being debugged (since a program can change its directory
2981 during its run). If you work on a system where @value{GDBN} supports
2982 the @code{info proc} command (@pxref{Process Information}), you can
2983 use the @code{info proc} command to find out the
2984 current working directory of the debuggee.
2985
2986 @node Input/Output
2987 @section Your Program's Input and Output
2988
2989 @cindex redirection
2990 @cindex i/o
2991 @cindex terminal
2992 By default, the program you run under @value{GDBN} does input and output to
2993 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2994 to its own terminal modes to interact with you, but it records the terminal
2995 modes your program was using and switches back to them when you continue
2996 running your program.
2997
2998 @table @code
2999 @kindex info terminal
3000 @item info terminal
3001 Displays information recorded by @value{GDBN} about the terminal modes your
3002 program is using.
3003 @end table
3004
3005 You can redirect your program's input and/or output using shell
3006 redirection with the @code{run} command. For example,
3007
3008 @smallexample
3009 run > outfile
3010 @end smallexample
3011
3012 @noindent
3013 starts your program, diverting its output to the file @file{outfile}.
3014
3015 @kindex tty
3016 @cindex controlling terminal
3017 Another way to specify where your program should do input and output is
3018 with the @code{tty} command. This command accepts a file name as
3019 argument, and causes this file to be the default for future @code{run}
3020 commands. It also resets the controlling terminal for the child
3021 process, for future @code{run} commands. For example,
3022
3023 @smallexample
3024 tty /dev/ttyb
3025 @end smallexample
3026
3027 @noindent
3028 directs that processes started with subsequent @code{run} commands
3029 default to do input and output on the terminal @file{/dev/ttyb} and have
3030 that as their controlling terminal.
3031
3032 An explicit redirection in @code{run} overrides the @code{tty} command's
3033 effect on the input/output device, but not its effect on the controlling
3034 terminal.
3035
3036 When you use the @code{tty} command or redirect input in the @code{run}
3037 command, only the input @emph{for your program} is affected. The input
3038 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3039 for @code{set inferior-tty}.
3040
3041 @cindex inferior tty
3042 @cindex set inferior controlling terminal
3043 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3044 display the name of the terminal that will be used for future runs of your
3045 program.
3046
3047 @table @code
3048 @item set inferior-tty [ @var{tty} ]
3049 @kindex set inferior-tty
3050 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3051 restores the default behavior, which is to use the same terminal as
3052 @value{GDBN}.
3053
3054 @item show inferior-tty
3055 @kindex show inferior-tty
3056 Show the current tty for the program being debugged.
3057 @end table
3058
3059 @node Attach
3060 @section Debugging an Already-running Process
3061 @kindex attach
3062 @cindex attach
3063
3064 @table @code
3065 @item attach @var{process-id}
3066 This command attaches to a running process---one that was started
3067 outside @value{GDBN}. (@code{info files} shows your active
3068 targets.) The command takes as argument a process ID. The usual way to
3069 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3070 or with the @samp{jobs -l} shell command.
3071
3072 @code{attach} does not repeat if you press @key{RET} a second time after
3073 executing the command.
3074 @end table
3075
3076 To use @code{attach}, your program must be running in an environment
3077 which supports processes; for example, @code{attach} does not work for
3078 programs on bare-board targets that lack an operating system. You must
3079 also have permission to send the process a signal.
3080
3081 When you use @code{attach}, the debugger finds the program running in
3082 the process first by looking in the current working directory, then (if
3083 the program is not found) by using the source file search path
3084 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3085 the @code{file} command to load the program. @xref{Files, ,Commands to
3086 Specify Files}.
3087
3088 @anchor{set exec-file-mismatch}
3089 If the debugger can determine that the executable file running in the
3090 process it is attaching to does not match the current exec-file loaded
3091 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3092 handle the mismatch. @value{GDBN} tries to compare the files by
3093 comparing their build IDs (@pxref{build ID}), if available.
3094
3095 @table @code
3096 @kindex exec-file-mismatch
3097 @cindex set exec-file-mismatch
3098 @item set exec-file-mismatch @samp{ask|warn|off}
3099
3100 Whether to detect mismatch between the current executable file loaded
3101 by @value{GDBN} and the executable file used to start the process. If
3102 @samp{ask}, the default, display a warning and ask the user whether to
3103 load the process executable file; if @samp{warn}, just display a
3104 warning; if @samp{off}, don't attempt to detect a mismatch.
3105 If the user confirms loading the process executable file, then its symbols
3106 will be loaded as well.
3107
3108 @cindex show exec-file-mismatch
3109 @item show exec-file-mismatch
3110 Show the current value of @code{exec-file-mismatch}.
3111
3112 @end table
3113
3114 The first thing @value{GDBN} does after arranging to debug the specified
3115 process is to stop it. You can examine and modify an attached process
3116 with all the @value{GDBN} commands that are ordinarily available when
3117 you start processes with @code{run}. You can insert breakpoints; you
3118 can step and continue; you can modify storage. If you would rather the
3119 process continue running, you may use the @code{continue} command after
3120 attaching @value{GDBN} to the process.
3121
3122 @table @code
3123 @kindex detach
3124 @item detach
3125 When you have finished debugging the attached process, you can use the
3126 @code{detach} command to release it from @value{GDBN} control. Detaching
3127 the process continues its execution. After the @code{detach} command,
3128 that process and @value{GDBN} become completely independent once more, and you
3129 are ready to @code{attach} another process or start one with @code{run}.
3130 @code{detach} does not repeat if you press @key{RET} again after
3131 executing the command.
3132 @end table
3133
3134 If you exit @value{GDBN} while you have an attached process, you detach
3135 that process. If you use the @code{run} command, you kill that process.
3136 By default, @value{GDBN} asks for confirmation if you try to do either of these
3137 things; you can control whether or not you need to confirm by using the
3138 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3139 Messages}).
3140
3141 @node Kill Process
3142 @section Killing the Child Process
3143
3144 @table @code
3145 @kindex kill
3146 @item kill
3147 Kill the child process in which your program is running under @value{GDBN}.
3148 @end table
3149
3150 This command is useful if you wish to debug a core dump instead of a
3151 running process. @value{GDBN} ignores any core dump file while your program
3152 is running.
3153
3154 On some operating systems, a program cannot be executed outside @value{GDBN}
3155 while you have breakpoints set on it inside @value{GDBN}. You can use the
3156 @code{kill} command in this situation to permit running your program
3157 outside the debugger.
3158
3159 The @code{kill} command is also useful if you wish to recompile and
3160 relink your program, since on many systems it is impossible to modify an
3161 executable file while it is running in a process. In this case, when you
3162 next type @code{run}, @value{GDBN} notices that the file has changed, and
3163 reads the symbol table again (while trying to preserve your current
3164 breakpoint settings).
3165
3166 @node Inferiors Connections and Programs
3167 @section Debugging Multiple Inferiors Connections and Programs
3168
3169 @value{GDBN} lets you run and debug multiple programs in a single
3170 session. In addition, @value{GDBN} on some systems may let you run
3171 several programs simultaneously (otherwise you have to exit from one
3172 before starting another). On some systems @value{GDBN} may even let
3173 you debug several programs simultaneously on different remote systems.
3174 In the most general case, you can have multiple threads of execution
3175 in each of multiple processes, launched from multiple executables,
3176 running on different machines.
3177
3178 @cindex inferior
3179 @value{GDBN} represents the state of each program execution with an
3180 object called an @dfn{inferior}. An inferior typically corresponds to
3181 a process, but is more general and applies also to targets that do not
3182 have processes. Inferiors may be created before a process runs, and
3183 may be retained after a process exits. Inferiors have unique
3184 identifiers that are different from process ids. Usually each
3185 inferior will also have its own distinct address space, although some
3186 embedded targets may have several inferiors running in different parts
3187 of a single address space. Each inferior may in turn have multiple
3188 threads running in it.
3189
3190 To find out what inferiors exist at any moment, use @w{@code{info
3191 inferiors}}:
3192
3193 @table @code
3194 @kindex info inferiors [ @var{id}@dots{} ]
3195 @item info inferiors
3196 Print a list of all inferiors currently being managed by @value{GDBN}.
3197 By default all inferiors are printed, but the argument @var{id}@dots{}
3198 -- a space separated list of inferior numbers -- can be used to limit
3199 the display to just the requested inferiors.
3200
3201 @value{GDBN} displays for each inferior (in this order):
3202
3203 @enumerate
3204 @item
3205 the inferior number assigned by @value{GDBN}
3206
3207 @item
3208 the target system's inferior identifier
3209
3210 @item
3211 the target connection the inferior is bound to, including the unique
3212 connection number assigned by @value{GDBN}, and the protocol used by
3213 the connection.
3214
3215 @item
3216 the name of the executable the inferior is running.
3217
3218 @end enumerate
3219
3220 @noindent
3221 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3222 indicates the current inferior.
3223
3224 For example,
3225 @end table
3226 @c end table here to get a little more width for example
3227
3228 @smallexample
3229 (@value{GDBP}) info inferiors
3230 Num Description Connection Executable
3231 * 1 process 3401 1 (native) goodbye
3232 2 process 2307 2 (extended-remote host:10000) hello
3233 @end smallexample
3234
3235 To get informations about the current inferior, use @code{inferior}:
3236
3237 @table @code
3238 @kindex inferior
3239 @item inferior
3240 Shows information about the current inferior.
3241
3242 For example,
3243 @end table
3244 @c end table here to get a little more width for example
3245
3246 @smallexample
3247 (@value{GDBP}) inferior
3248 [Current inferior is 1 [process 3401] (helloworld)]
3249 @end smallexample
3250
3251 To find out what open target connections exist at any moment, use
3252 @w{@code{info connections}}:
3253
3254 @table @code
3255 @kindex info connections [ @var{id}@dots{} ]
3256 @item info connections
3257 Print a list of all open target connections currently being managed by
3258 @value{GDBN}. By default all connections are printed, but the
3259 argument @var{id}@dots{} -- a space separated list of connections
3260 numbers -- can be used to limit the display to just the requested
3261 connections.
3262
3263 @value{GDBN} displays for each connection (in this order):
3264
3265 @enumerate
3266 @item
3267 the connection number assigned by @value{GDBN}.
3268
3269 @item
3270 the protocol used by the connection.
3271
3272 @item
3273 a textual description of the protocol used by the connection.
3274
3275 @end enumerate
3276
3277 @noindent
3278 An asterisk @samp{*} preceding the connection number indicates the
3279 connection of the current inferior.
3280
3281 For example,
3282 @end table
3283 @c end table here to get a little more width for example
3284
3285 @smallexample
3286 (@value{GDBP}) info connections
3287 Num What Description
3288 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3289 2 native Native process
3290 3 core Local core dump file
3291 @end smallexample
3292
3293 To switch focus between inferiors, use the @code{inferior} command:
3294
3295 @table @code
3296 @kindex inferior @var{infno}
3297 @item inferior @var{infno}
3298 Make inferior number @var{infno} the current inferior. The argument
3299 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3300 in the first field of the @samp{info inferiors} display.
3301 @end table
3302
3303 @vindex $_inferior@r{, convenience variable}
3304 The debugger convenience variable @samp{$_inferior} contains the
3305 number of the current inferior. You may find this useful in writing
3306 breakpoint conditional expressions, command scripts, and so forth.
3307 @xref{Convenience Vars,, Convenience Variables}, for general
3308 information on convenience variables.
3309
3310 You can get multiple executables into a debugging session via the
3311 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3312 systems @value{GDBN} can add inferiors to the debug session
3313 automatically by following calls to @code{fork} and @code{exec}. To
3314 remove inferiors from the debugging session use the
3315 @w{@code{remove-inferiors}} command.
3316
3317 @table @code
3318 @anchor{add_inferior_cli}
3319 @kindex add-inferior
3320 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3321 Adds @var{n} inferiors to be run using @var{executable} as the
3322 executable; @var{n} defaults to 1. If no executable is specified,
3323 the inferiors begins empty, with no program. You can still assign or
3324 change the program assigned to the inferior at any time by using the
3325 @code{file} command with the executable name as its argument.
3326
3327 By default, the new inferior begins connected to the same target
3328 connection as the current inferior. For example, if the current
3329 inferior was connected to @code{gdbserver} with @code{target remote},
3330 then the new inferior will be connected to the same @code{gdbserver}
3331 instance. The @samp{-no-connection} option starts the new inferior
3332 with no connection yet. You can then for example use the @code{target
3333 remote} command to connect to some other @code{gdbserver} instance,
3334 use @code{run} to spawn a local program, etc.
3335
3336 @kindex clone-inferior
3337 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3338 Adds @var{n} inferiors ready to execute the same program as inferior
3339 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3340 number of the current inferior. This command copies the values of the
3341 @var{args}, @w{@var{inferior-tty}} and @var{cwd} properties from the
3342 current inferior to the new one. It also propagates changes the user
3343 made to environment variables using the @w{@code{set environment}} and
3344 @w{@code{unset environment}} commands. This is a convenient command
3345 when you want to run another instance of the inferior you are debugging.
3346
3347 @smallexample
3348 (@value{GDBP}) info inferiors
3349 Num Description Connection Executable
3350 * 1 process 29964 1 (native) helloworld
3351 (@value{GDBP}) clone-inferior
3352 Added inferior 2.
3353 1 inferiors added.
3354 (@value{GDBP}) info inferiors
3355 Num Description Connection Executable
3356 * 1 process 29964 1 (native) helloworld
3357 2 <null> 1 (native) helloworld
3358 @end smallexample
3359
3360 You can now simply switch focus to inferior 2 and run it.
3361
3362 @kindex remove-inferiors
3363 @item remove-inferiors @var{infno}@dots{}
3364 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3365 possible to remove an inferior that is running with this command. For
3366 those, use the @code{kill} or @code{detach} command first.
3367
3368 @end table
3369
3370 To quit debugging one of the running inferiors that is not the current
3371 inferior, you can either detach from it by using the @w{@code{detach
3372 inferior}} command (allowing it to run independently), or kill it
3373 using the @w{@code{kill inferiors}} command:
3374
3375 @table @code
3376 @kindex detach inferiors @var{infno}@dots{}
3377 @item detach inferior @var{infno}@dots{}
3378 Detach from the inferior or inferiors identified by @value{GDBN}
3379 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3380 still stays on the list of inferiors shown by @code{info inferiors},
3381 but its Description will show @samp{<null>}.
3382
3383 @kindex kill inferiors @var{infno}@dots{}
3384 @item kill inferiors @var{infno}@dots{}
3385 Kill the inferior or inferiors identified by @value{GDBN} inferior
3386 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3387 stays on the list of inferiors shown by @code{info inferiors}, but its
3388 Description will show @samp{<null>}.
3389 @end table
3390
3391 After the successful completion of a command such as @code{detach},
3392 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3393 a normal process exit, the inferior is still valid and listed with
3394 @code{info inferiors}, ready to be restarted.
3395
3396
3397 To be notified when inferiors are started or exit under @value{GDBN}'s
3398 control use @w{@code{set print inferior-events}}:
3399
3400 @table @code
3401 @kindex set print inferior-events
3402 @cindex print messages on inferior start and exit
3403 @item set print inferior-events
3404 @itemx set print inferior-events on
3405 @itemx set print inferior-events off
3406 The @code{set print inferior-events} command allows you to enable or
3407 disable printing of messages when @value{GDBN} notices that new
3408 inferiors have started or that inferiors have exited or have been
3409 detached. By default, these messages will be printed.
3410
3411 @kindex show print inferior-events
3412 @item show print inferior-events
3413 Show whether messages will be printed when @value{GDBN} detects that
3414 inferiors have started, exited or have been detached.
3415 @end table
3416
3417 Many commands will work the same with multiple programs as with a
3418 single program: e.g., @code{print myglobal} will simply display the
3419 value of @code{myglobal} in the current inferior.
3420
3421
3422 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3423 get more info about the relationship of inferiors, programs, address
3424 spaces in a debug session. You can do that with the @w{@code{maint
3425 info program-spaces}} command.
3426
3427 @table @code
3428 @kindex maint info program-spaces
3429 @item maint info program-spaces
3430 Print a list of all program spaces currently being managed by
3431 @value{GDBN}.
3432
3433 @value{GDBN} displays for each program space (in this order):
3434
3435 @enumerate
3436 @item
3437 the program space number assigned by @value{GDBN}
3438
3439 @item
3440 the name of the executable loaded into the program space, with e.g.,
3441 the @code{file} command.
3442
3443 @end enumerate
3444
3445 @noindent
3446 An asterisk @samp{*} preceding the @value{GDBN} program space number
3447 indicates the current program space.
3448
3449 In addition, below each program space line, @value{GDBN} prints extra
3450 information that isn't suitable to display in tabular form. For
3451 example, the list of inferiors bound to the program space.
3452
3453 @smallexample
3454 (@value{GDBP}) maint info program-spaces
3455 Id Executable
3456 * 1 hello
3457 2 goodbye
3458 Bound inferiors: ID 1 (process 21561)
3459 @end smallexample
3460
3461 Here we can see that no inferior is running the program @code{hello},
3462 while @code{process 21561} is running the program @code{goodbye}. On
3463 some targets, it is possible that multiple inferiors are bound to the
3464 same program space. The most common example is that of debugging both
3465 the parent and child processes of a @code{vfork} call. For example,
3466
3467 @smallexample
3468 (@value{GDBP}) maint info program-spaces
3469 Id Executable
3470 * 1 vfork-test
3471 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3472 @end smallexample
3473
3474 Here, both inferior 2 and inferior 1 are running in the same program
3475 space as a result of inferior 1 having executed a @code{vfork} call.
3476 @end table
3477
3478 @node Threads
3479 @section Debugging Programs with Multiple Threads
3480
3481 @cindex threads of execution
3482 @cindex multiple threads
3483 @cindex switching threads
3484 In some operating systems, such as GNU/Linux and Solaris, a single program
3485 may have more than one @dfn{thread} of execution. The precise semantics
3486 of threads differ from one operating system to another, but in general
3487 the threads of a single program are akin to multiple processes---except
3488 that they share one address space (that is, they can all examine and
3489 modify the same variables). On the other hand, each thread has its own
3490 registers and execution stack, and perhaps private memory.
3491
3492 @value{GDBN} provides these facilities for debugging multi-thread
3493 programs:
3494
3495 @itemize @bullet
3496 @item automatic notification of new threads
3497 @item @samp{thread @var{thread-id}}, a command to switch among threads
3498 @item @samp{info threads}, a command to inquire about existing threads
3499 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3500 a command to apply a command to a list of threads
3501 @item thread-specific breakpoints
3502 @item @samp{set print thread-events}, which controls printing of
3503 messages on thread start and exit.
3504 @item @samp{set libthread-db-search-path @var{path}}, which lets
3505 the user specify which @code{libthread_db} to use if the default choice
3506 isn't compatible with the program.
3507 @end itemize
3508
3509 @cindex focus of debugging
3510 @cindex current thread
3511 The @value{GDBN} thread debugging facility allows you to observe all
3512 threads while your program runs---but whenever @value{GDBN} takes
3513 control, one thread in particular is always the focus of debugging.
3514 This thread is called the @dfn{current thread}. Debugging commands show
3515 program information from the perspective of the current thread.
3516
3517 @cindex @code{New} @var{systag} message
3518 @cindex thread identifier (system)
3519 @c FIXME-implementors!! It would be more helpful if the [New...] message
3520 @c included GDB's numeric thread handle, so you could just go to that
3521 @c thread without first checking `info threads'.
3522 Whenever @value{GDBN} detects a new thread in your program, it displays
3523 the target system's identification for the thread with a message in the
3524 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3525 whose form varies depending on the particular system. For example, on
3526 @sc{gnu}/Linux, you might see
3527
3528 @smallexample
3529 [New Thread 0x41e02940 (LWP 25582)]
3530 @end smallexample
3531
3532 @noindent
3533 when @value{GDBN} notices a new thread. In contrast, on other systems,
3534 the @var{systag} is simply something like @samp{process 368}, with no
3535 further qualifier.
3536
3537 @c FIXME!! (1) Does the [New...] message appear even for the very first
3538 @c thread of a program, or does it only appear for the
3539 @c second---i.e.@: when it becomes obvious we have a multithread
3540 @c program?
3541 @c (2) *Is* there necessarily a first thread always? Or do some
3542 @c multithread systems permit starting a program with multiple
3543 @c threads ab initio?
3544
3545 @anchor{thread numbers}
3546 @cindex thread number, per inferior
3547 @cindex thread identifier (GDB)
3548 For debugging purposes, @value{GDBN} associates its own thread number
3549 ---always a single integer---with each thread of an inferior. This
3550 number is unique between all threads of an inferior, but not unique
3551 between threads of different inferiors.
3552
3553 @cindex qualified thread ID
3554 You can refer to a given thread in an inferior using the qualified
3555 @var{inferior-num}.@var{thread-num} syntax, also known as
3556 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3557 number and @var{thread-num} being the thread number of the given
3558 inferior. For example, thread @code{2.3} refers to thread number 3 of
3559 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3560 then @value{GDBN} infers you're referring to a thread of the current
3561 inferior.
3562
3563 Until you create a second inferior, @value{GDBN} does not show the
3564 @var{inferior-num} part of thread IDs, even though you can always use
3565 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3566 of inferior 1, the initial inferior.
3567
3568 @anchor{thread ID lists}
3569 @cindex thread ID lists
3570 Some commands accept a space-separated @dfn{thread ID list} as
3571 argument. A list element can be:
3572
3573 @enumerate
3574 @item
3575 A thread ID as shown in the first field of the @samp{info threads}
3576 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3577 @samp{1}.
3578
3579 @item
3580 A range of thread numbers, again with or without an inferior
3581 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3582 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3583
3584 @item
3585 All threads of an inferior, specified with a star wildcard, with or
3586 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3587 @samp{1.*}) or @code{*}. The former refers to all threads of the
3588 given inferior, and the latter form without an inferior qualifier
3589 refers to all threads of the current inferior.
3590
3591 @end enumerate
3592
3593 For example, if the current inferior is 1, and inferior 7 has one
3594 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3595 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3596 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3597 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3598 7.1}.
3599
3600
3601 @anchor{global thread numbers}
3602 @cindex global thread number
3603 @cindex global thread identifier (GDB)
3604 In addition to a @emph{per-inferior} number, each thread is also
3605 assigned a unique @emph{global} number, also known as @dfn{global
3606 thread ID}, a single integer. Unlike the thread number component of
3607 the thread ID, no two threads have the same global ID, even when
3608 you're debugging multiple inferiors.
3609
3610 From @value{GDBN}'s perspective, a process always has at least one
3611 thread. In other words, @value{GDBN} assigns a thread number to the
3612 program's ``main thread'' even if the program is not multi-threaded.
3613
3614 @vindex $_thread@r{, convenience variable}
3615 @vindex $_gthread@r{, convenience variable}
3616 The debugger convenience variables @samp{$_thread} and
3617 @samp{$_gthread} contain, respectively, the per-inferior thread number
3618 and the global thread number of the current thread. You may find this
3619 useful in writing breakpoint conditional expressions, command scripts,
3620 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3621 general information on convenience variables.
3622
3623 If @value{GDBN} detects the program is multi-threaded, it augments the
3624 usual message about stopping at a breakpoint with the ID and name of
3625 the thread that hit the breakpoint.
3626
3627 @smallexample
3628 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3629 @end smallexample
3630
3631 Likewise when the program receives a signal:
3632
3633 @smallexample
3634 Thread 1 "main" received signal SIGINT, Interrupt.
3635 @end smallexample
3636
3637 @table @code
3638 @anchor{info_threads}
3639 @kindex info threads
3640 @item info threads @r{[}@var{thread-id-list}@r{]}
3641
3642 Display information about one or more threads. With no arguments
3643 displays information about all threads. You can specify the list of
3644 threads that you want to display using the thread ID list syntax
3645 (@pxref{thread ID lists}).
3646
3647 @value{GDBN} displays for each thread (in this order):
3648
3649 @enumerate
3650 @item
3651 the per-inferior thread number assigned by @value{GDBN}
3652
3653 @item
3654 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3655 option was specified
3656
3657 @item
3658 the target system's thread identifier (@var{systag})
3659
3660 @item
3661 the thread's name, if one is known. A thread can either be named by
3662 the user (see @code{thread name}, below), or, in some cases, by the
3663 program itself.
3664
3665 @item
3666 the current stack frame summary for that thread
3667 @end enumerate
3668
3669 @noindent
3670 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3671 indicates the current thread.
3672
3673 For example,
3674 @end table
3675 @c end table here to get a little more width for example
3676
3677 @smallexample
3678 (@value{GDBP}) info threads
3679 Id Target Id Frame
3680 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3681 2 process 35 thread 23 0x34e5 in sigpause ()
3682 3 process 35 thread 27 0x34e5 in sigpause ()
3683 at threadtest.c:68
3684 @end smallexample
3685
3686 If you're debugging multiple inferiors, @value{GDBN} displays thread
3687 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3688 Otherwise, only @var{thread-num} is shown.
3689
3690 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3691 indicating each thread's global thread ID:
3692
3693 @smallexample
3694 (@value{GDBP}) info threads
3695 Id GId Target Id Frame
3696 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3697 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3698 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3699 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3700 @end smallexample
3701
3702 On Solaris, you can display more information about user threads with a
3703 Solaris-specific command:
3704
3705 @table @code
3706 @item maint info sol-threads
3707 @kindex maint info sol-threads
3708 @cindex thread info (Solaris)
3709 Display info on Solaris user threads.
3710 @end table
3711
3712 @table @code
3713 @kindex thread @var{thread-id}
3714 @item thread @var{thread-id}
3715 Make thread ID @var{thread-id} the current thread. The command
3716 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3717 the first field of the @samp{info threads} display, with or without an
3718 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3719
3720 @value{GDBN} responds by displaying the system identifier of the
3721 thread you selected, and its current stack frame summary:
3722
3723 @smallexample
3724 (@value{GDBP}) thread 2
3725 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3726 #0 some_function (ignore=0x0) at example.c:8
3727 8 printf ("hello\n");
3728 @end smallexample
3729
3730 @noindent
3731 As with the @samp{[New @dots{}]} message, the form of the text after
3732 @samp{Switching to} depends on your system's conventions for identifying
3733 threads.
3734
3735 @anchor{thread apply all}
3736 @kindex thread apply
3737 @cindex apply command to several threads
3738 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3739 The @code{thread apply} command allows you to apply the named
3740 @var{command} to one or more threads. Specify the threads that you
3741 want affected using the thread ID list syntax (@pxref{thread ID
3742 lists}), or specify @code{all} to apply to all threads. To apply a
3743 command to all threads in descending order, type @kbd{thread apply all
3744 @var{command}}. To apply a command to all threads in ascending order,
3745 type @kbd{thread apply all -ascending @var{command}}.
3746
3747 The @var{flag} arguments control what output to produce and how to handle
3748 errors raised when applying @var{command} to a thread. @var{flag}
3749 must start with a @code{-} directly followed by one letter in
3750 @code{qcs}. If several flags are provided, they must be given
3751 individually, such as @code{-c -q}.
3752
3753 By default, @value{GDBN} displays some thread information before the
3754 output produced by @var{command}, and an error raised during the
3755 execution of a @var{command} will abort @code{thread apply}. The
3756 following flags can be used to fine-tune this behavior:
3757
3758 @table @code
3759 @item -c
3760 The flag @code{-c}, which stands for @samp{continue}, causes any
3761 errors in @var{command} to be displayed, and the execution of
3762 @code{thread apply} then continues.
3763 @item -s
3764 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3765 or empty output produced by a @var{command} to be silently ignored.
3766 That is, the execution continues, but the thread information and errors
3767 are not printed.
3768 @item -q
3769 The flag @code{-q} (@samp{quiet}) disables printing the thread
3770 information.
3771 @end table
3772
3773 Flags @code{-c} and @code{-s} cannot be used together.
3774
3775 @kindex taas
3776 @cindex apply command to all threads (ignoring errors and empty output)
3777 @item taas [@var{option}]@dots{} @var{command}
3778 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3779 Applies @var{command} on all threads, ignoring errors and empty output.
3780
3781 The @code{taas} command accepts the same options as the @code{thread
3782 apply all} command. @xref{thread apply all}.
3783
3784 @kindex tfaas
3785 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3786 @item tfaas [@var{option}]@dots{} @var{command}
3787 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3788 Applies @var{command} on all frames of all threads, ignoring errors
3789 and empty output. Note that the flag @code{-s} is specified twice:
3790 The first @code{-s} ensures that @code{thread apply} only shows the thread
3791 information of the threads for which @code{frame apply} produces
3792 some output. The second @code{-s} is needed to ensure that @code{frame
3793 apply} shows the frame information of a frame only if the
3794 @var{command} successfully produced some output.
3795
3796 It can for example be used to print a local variable or a function
3797 argument without knowing the thread or frame where this variable or argument
3798 is, using:
3799 @smallexample
3800 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3801 @end smallexample
3802
3803 The @code{tfaas} command accepts the same options as the @code{frame
3804 apply} command. @xref{Frame Apply,,frame apply}.
3805
3806 @kindex thread name
3807 @cindex name a thread
3808 @item thread name [@var{name}]
3809 This command assigns a name to the current thread. If no argument is
3810 given, any existing user-specified name is removed. The thread name
3811 appears in the @samp{info threads} display.
3812
3813 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3814 determine the name of the thread as given by the OS. On these
3815 systems, a name specified with @samp{thread name} will override the
3816 system-give name, and removing the user-specified name will cause
3817 @value{GDBN} to once again display the system-specified name.
3818
3819 @kindex thread find
3820 @cindex search for a thread
3821 @item thread find [@var{regexp}]
3822 Search for and display thread ids whose name or @var{systag}
3823 matches the supplied regular expression.
3824
3825 As well as being the complement to the @samp{thread name} command,
3826 this command also allows you to identify a thread by its target
3827 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3828 is the LWP id.
3829
3830 @smallexample
3831 (@value{GDBN}) thread find 26688
3832 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3833 (@value{GDBN}) info thread 4
3834 Id Target Id Frame
3835 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3836 @end smallexample
3837
3838 @kindex set print thread-events
3839 @cindex print messages on thread start and exit
3840 @item set print thread-events
3841 @itemx set print thread-events on
3842 @itemx set print thread-events off
3843 The @code{set print thread-events} command allows you to enable or
3844 disable printing of messages when @value{GDBN} notices that new threads have
3845 started or that threads have exited. By default, these messages will
3846 be printed if detection of these events is supported by the target.
3847 Note that these messages cannot be disabled on all targets.
3848
3849 @kindex show print thread-events
3850 @item show print thread-events
3851 Show whether messages will be printed when @value{GDBN} detects that threads
3852 have started and exited.
3853 @end table
3854
3855 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3856 more information about how @value{GDBN} behaves when you stop and start
3857 programs with multiple threads.
3858
3859 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3860 watchpoints in programs with multiple threads.
3861
3862 @anchor{set libthread-db-search-path}
3863 @table @code
3864 @kindex set libthread-db-search-path
3865 @cindex search path for @code{libthread_db}
3866 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3867 If this variable is set, @var{path} is a colon-separated list of
3868 directories @value{GDBN} will use to search for @code{libthread_db}.
3869 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3870 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3871 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3872 macro.
3873
3874 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3875 @code{libthread_db} library to obtain information about threads in the
3876 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3877 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3878 specific thread debugging library loading is enabled
3879 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3880
3881 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3882 refers to the default system directories that are
3883 normally searched for loading shared libraries. The @samp{$sdir} entry
3884 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3885 (@pxref{libthread_db.so.1 file}).
3886
3887 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3888 refers to the directory from which @code{libpthread}
3889 was loaded in the inferior process.
3890
3891 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3892 @value{GDBN} attempts to initialize it with the current inferior process.
3893 If this initialization fails (which could happen because of a version
3894 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3895 will unload @code{libthread_db}, and continue with the next directory.
3896 If none of @code{libthread_db} libraries initialize successfully,
3897 @value{GDBN} will issue a warning and thread debugging will be disabled.
3898
3899 Setting @code{libthread-db-search-path} is currently implemented
3900 only on some platforms.
3901
3902 @kindex show libthread-db-search-path
3903 @item show libthread-db-search-path
3904 Display current libthread_db search path.
3905
3906 @kindex set debug libthread-db
3907 @kindex show debug libthread-db
3908 @cindex debugging @code{libthread_db}
3909 @item set debug libthread-db
3910 @itemx show debug libthread-db
3911 Turns on or off display of @code{libthread_db}-related events.
3912 Use @code{1} to enable, @code{0} to disable.
3913
3914 @kindex set debug threads
3915 @kindex show debug threads
3916 @cindex debugging @code{threads}
3917 @item set debug threads @r{[}on@r{|}off@r{]}
3918 @itemx show debug threads
3919 When @samp{on} @value{GDBN} will print additional messages when
3920 threads are created and deleted.
3921 @end table
3922
3923 @node Forks
3924 @section Debugging Forks
3925
3926 @cindex fork, debugging programs which call
3927 @cindex multiple processes
3928 @cindex processes, multiple
3929 On most systems, @value{GDBN} has no special support for debugging
3930 programs which create additional processes using the @code{fork}
3931 function. When a program forks, @value{GDBN} will continue to debug the
3932 parent process and the child process will run unimpeded. If you have
3933 set a breakpoint in any code which the child then executes, the child
3934 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3935 will cause it to terminate.
3936
3937 However, if you want to debug the child process there is a workaround
3938 which isn't too painful. Put a call to @code{sleep} in the code which
3939 the child process executes after the fork. It may be useful to sleep
3940 only if a certain environment variable is set, or a certain file exists,
3941 so that the delay need not occur when you don't want to run @value{GDBN}
3942 on the child. While the child is sleeping, use the @code{ps} program to
3943 get its process ID. Then tell @value{GDBN} (a new invocation of
3944 @value{GDBN} if you are also debugging the parent process) to attach to
3945 the child process (@pxref{Attach}). From that point on you can debug
3946 the child process just like any other process which you attached to.
3947
3948 On some systems, @value{GDBN} provides support for debugging programs
3949 that create additional processes using the @code{fork} or @code{vfork}
3950 functions. On @sc{gnu}/Linux platforms, this feature is supported
3951 with kernel version 2.5.46 and later.
3952
3953 The fork debugging commands are supported in native mode and when
3954 connected to @code{gdbserver} in either @code{target remote} mode or
3955 @code{target extended-remote} mode.
3956
3957 By default, when a program forks, @value{GDBN} will continue to debug
3958 the parent process and the child process will run unimpeded.
3959
3960 If you want to follow the child process instead of the parent process,
3961 use the command @w{@code{set follow-fork-mode}}.
3962
3963 @table @code
3964 @kindex set follow-fork-mode
3965 @item set follow-fork-mode @var{mode}
3966 Set the debugger response to a program call of @code{fork} or
3967 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3968 process. The @var{mode} argument can be:
3969
3970 @table @code
3971 @item parent
3972 The original process is debugged after a fork. The child process runs
3973 unimpeded. This is the default.
3974
3975 @item child
3976 The new process is debugged after a fork. The parent process runs
3977 unimpeded.
3978
3979 @end table
3980
3981 @kindex show follow-fork-mode
3982 @item show follow-fork-mode
3983 Display the current debugger response to a @code{fork} or @code{vfork} call.
3984 @end table
3985
3986 @cindex debugging multiple processes
3987 On Linux, if you want to debug both the parent and child processes, use the
3988 command @w{@code{set detach-on-fork}}.
3989
3990 @table @code
3991 @kindex set detach-on-fork
3992 @item set detach-on-fork @var{mode}
3993 Tells gdb whether to detach one of the processes after a fork, or
3994 retain debugger control over them both.
3995
3996 @table @code
3997 @item on
3998 The child process (or parent process, depending on the value of
3999 @code{follow-fork-mode}) will be detached and allowed to run
4000 independently. This is the default.
4001
4002 @item off
4003 Both processes will be held under the control of @value{GDBN}.
4004 One process (child or parent, depending on the value of
4005 @code{follow-fork-mode}) is debugged as usual, while the other
4006 is held suspended.
4007
4008 @end table
4009
4010 @kindex show detach-on-fork
4011 @item show detach-on-fork
4012 Show whether detach-on-fork mode is on/off.
4013 @end table
4014
4015 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
4016 will retain control of all forked processes (including nested forks).
4017 You can list the forked processes under the control of @value{GDBN} by
4018 using the @w{@code{info inferiors}} command, and switch from one fork
4019 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
4020 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
4021
4022 To quit debugging one of the forked processes, you can either detach
4023 from it by using the @w{@code{detach inferiors}} command (allowing it
4024 to run independently), or kill it using the @w{@code{kill inferiors}}
4025 command. @xref{Inferiors Connections and Programs, ,Debugging
4026 Multiple Inferiors Connections and Programs}.
4027
4028 If you ask to debug a child process and a @code{vfork} is followed by an
4029 @code{exec}, @value{GDBN} executes the new target up to the first
4030 breakpoint in the new target. If you have a breakpoint set on
4031 @code{main} in your original program, the breakpoint will also be set on
4032 the child process's @code{main}.
4033
4034 On some systems, when a child process is spawned by @code{vfork}, you
4035 cannot debug the child or parent until an @code{exec} call completes.
4036
4037 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
4038 call executes, the new target restarts. To restart the parent
4039 process, use the @code{file} command with the parent executable name
4040 as its argument. By default, after an @code{exec} call executes,
4041 @value{GDBN} discards the symbols of the previous executable image.
4042 You can change this behaviour with the @w{@code{set follow-exec-mode}}
4043 command.
4044
4045 @table @code
4046 @kindex set follow-exec-mode
4047 @item set follow-exec-mode @var{mode}
4048
4049 Set debugger response to a program call of @code{exec}. An
4050 @code{exec} call replaces the program image of a process.
4051
4052 @code{follow-exec-mode} can be:
4053
4054 @table @code
4055 @item new
4056 @value{GDBN} creates a new inferior and rebinds the process to this
4057 new inferior. The program the process was running before the
4058 @code{exec} call can be restarted afterwards by restarting the
4059 original inferior.
4060
4061 For example:
4062
4063 @smallexample
4064 (@value{GDBP}) info inferiors
4065 (gdb) info inferior
4066 Id Description Executable
4067 * 1 <null> prog1
4068 (@value{GDBP}) run
4069 process 12020 is executing new program: prog2
4070 Program exited normally.
4071 (@value{GDBP}) info inferiors
4072 Id Description Executable
4073 1 <null> prog1
4074 * 2 <null> prog2
4075 @end smallexample
4076
4077 @item same
4078 @value{GDBN} keeps the process bound to the same inferior. The new
4079 executable image replaces the previous executable loaded in the
4080 inferior. Restarting the inferior after the @code{exec} call, with
4081 e.g., the @code{run} command, restarts the executable the process was
4082 running after the @code{exec} call. This is the default mode.
4083
4084 For example:
4085
4086 @smallexample
4087 (@value{GDBP}) info inferiors
4088 Id Description Executable
4089 * 1 <null> prog1
4090 (@value{GDBP}) run
4091 process 12020 is executing new program: prog2
4092 Program exited normally.
4093 (@value{GDBP}) info inferiors
4094 Id Description Executable
4095 * 1 <null> prog2
4096 @end smallexample
4097
4098 @end table
4099 @end table
4100
4101 @code{follow-exec-mode} is supported in native mode and
4102 @code{target extended-remote} mode.
4103
4104 You can use the @code{catch} command to make @value{GDBN} stop whenever
4105 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4106 Catchpoints, ,Setting Catchpoints}.
4107
4108 @node Checkpoint/Restart
4109 @section Setting a @emph{Bookmark} to Return to Later
4110
4111 @cindex checkpoint
4112 @cindex restart
4113 @cindex bookmark
4114 @cindex snapshot of a process
4115 @cindex rewind program state
4116
4117 On certain operating systems@footnote{Currently, only
4118 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4119 program's state, called a @dfn{checkpoint}, and come back to it
4120 later.
4121
4122 Returning to a checkpoint effectively undoes everything that has
4123 happened in the program since the @code{checkpoint} was saved. This
4124 includes changes in memory, registers, and even (within some limits)
4125 system state. Effectively, it is like going back in time to the
4126 moment when the checkpoint was saved.
4127
4128 Thus, if you're stepping thru a program and you think you're
4129 getting close to the point where things go wrong, you can save
4130 a checkpoint. Then, if you accidentally go too far and miss
4131 the critical statement, instead of having to restart your program
4132 from the beginning, you can just go back to the checkpoint and
4133 start again from there.
4134
4135 This can be especially useful if it takes a lot of time or
4136 steps to reach the point where you think the bug occurs.
4137
4138 To use the @code{checkpoint}/@code{restart} method of debugging:
4139
4140 @table @code
4141 @kindex checkpoint
4142 @item checkpoint
4143 Save a snapshot of the debugged program's current execution state.
4144 The @code{checkpoint} command takes no arguments, but each checkpoint
4145 is assigned a small integer id, similar to a breakpoint id.
4146
4147 @kindex info checkpoints
4148 @item info checkpoints
4149 List the checkpoints that have been saved in the current debugging
4150 session. For each checkpoint, the following information will be
4151 listed:
4152
4153 @table @code
4154 @item Checkpoint ID
4155 @item Process ID
4156 @item Code Address
4157 @item Source line, or label
4158 @end table
4159
4160 @kindex restart @var{checkpoint-id}
4161 @item restart @var{checkpoint-id}
4162 Restore the program state that was saved as checkpoint number
4163 @var{checkpoint-id}. All program variables, registers, stack frames
4164 etc.@: will be returned to the values that they had when the checkpoint
4165 was saved. In essence, gdb will ``wind back the clock'' to the point
4166 in time when the checkpoint was saved.
4167
4168 Note that breakpoints, @value{GDBN} variables, command history etc.
4169 are not affected by restoring a checkpoint. In general, a checkpoint
4170 only restores things that reside in the program being debugged, not in
4171 the debugger.
4172
4173 @kindex delete checkpoint @var{checkpoint-id}
4174 @item delete checkpoint @var{checkpoint-id}
4175 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4176
4177 @end table
4178
4179 Returning to a previously saved checkpoint will restore the user state
4180 of the program being debugged, plus a significant subset of the system
4181 (OS) state, including file pointers. It won't ``un-write'' data from
4182 a file, but it will rewind the file pointer to the previous location,
4183 so that the previously written data can be overwritten. For files
4184 opened in read mode, the pointer will also be restored so that the
4185 previously read data can be read again.
4186
4187 Of course, characters that have been sent to a printer (or other
4188 external device) cannot be ``snatched back'', and characters received
4189 from eg.@: a serial device can be removed from internal program buffers,
4190 but they cannot be ``pushed back'' into the serial pipeline, ready to
4191 be received again. Similarly, the actual contents of files that have
4192 been changed cannot be restored (at this time).
4193
4194 However, within those constraints, you actually can ``rewind'' your
4195 program to a previously saved point in time, and begin debugging it
4196 again --- and you can change the course of events so as to debug a
4197 different execution path this time.
4198
4199 @cindex checkpoints and process id
4200 Finally, there is one bit of internal program state that will be
4201 different when you return to a checkpoint --- the program's process
4202 id. Each checkpoint will have a unique process id (or @var{pid}),
4203 and each will be different from the program's original @var{pid}.
4204 If your program has saved a local copy of its process id, this could
4205 potentially pose a problem.
4206
4207 @subsection A Non-obvious Benefit of Using Checkpoints
4208
4209 On some systems such as @sc{gnu}/Linux, address space randomization
4210 is performed on new processes for security reasons. This makes it
4211 difficult or impossible to set a breakpoint, or watchpoint, on an
4212 absolute address if you have to restart the program, since the
4213 absolute location of a symbol will change from one execution to the
4214 next.
4215
4216 A checkpoint, however, is an @emph{identical} copy of a process.
4217 Therefore if you create a checkpoint at (eg.@:) the start of main,
4218 and simply return to that checkpoint instead of restarting the
4219 process, you can avoid the effects of address randomization and
4220 your symbols will all stay in the same place.
4221
4222 @node Stopping
4223 @chapter Stopping and Continuing
4224
4225 The principal purposes of using a debugger are so that you can stop your
4226 program before it terminates; or so that, if your program runs into
4227 trouble, you can investigate and find out why.
4228
4229 Inside @value{GDBN}, your program may stop for any of several reasons,
4230 such as a signal, a breakpoint, or reaching a new line after a
4231 @value{GDBN} command such as @code{step}. You may then examine and
4232 change variables, set new breakpoints or remove old ones, and then
4233 continue execution. Usually, the messages shown by @value{GDBN} provide
4234 ample explanation of the status of your program---but you can also
4235 explicitly request this information at any time.
4236
4237 @table @code
4238 @kindex info program
4239 @item info program
4240 Display information about the status of your program: whether it is
4241 running or not, what process it is, and why it stopped.
4242 @end table
4243
4244 @menu
4245 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4246 * Continuing and Stepping:: Resuming execution
4247 * Skipping Over Functions and Files::
4248 Skipping over functions and files
4249 * Signals:: Signals
4250 * Thread Stops:: Stopping and starting multi-thread programs
4251 @end menu
4252
4253 @node Breakpoints
4254 @section Breakpoints, Watchpoints, and Catchpoints
4255
4256 @cindex breakpoints
4257 A @dfn{breakpoint} makes your program stop whenever a certain point in
4258 the program is reached. For each breakpoint, you can add conditions to
4259 control in finer detail whether your program stops. You can set
4260 breakpoints with the @code{break} command and its variants (@pxref{Set
4261 Breaks, ,Setting Breakpoints}), to specify the place where your program
4262 should stop by line number, function name or exact address in the
4263 program.
4264
4265 On some systems, you can set breakpoints in shared libraries before
4266 the executable is run.
4267
4268 @cindex watchpoints
4269 @cindex data breakpoints
4270 @cindex memory tracing
4271 @cindex breakpoint on memory address
4272 @cindex breakpoint on variable modification
4273 A @dfn{watchpoint} is a special breakpoint that stops your program
4274 when the value of an expression changes. The expression may be a value
4275 of a variable, or it could involve values of one or more variables
4276 combined by operators, such as @samp{a + b}. This is sometimes called
4277 @dfn{data breakpoints}. You must use a different command to set
4278 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4279 from that, you can manage a watchpoint like any other breakpoint: you
4280 enable, disable, and delete both breakpoints and watchpoints using the
4281 same commands.
4282
4283 You can arrange to have values from your program displayed automatically
4284 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4285 Automatic Display}.
4286
4287 @cindex catchpoints
4288 @cindex breakpoint on events
4289 A @dfn{catchpoint} is another special breakpoint that stops your program
4290 when a certain kind of event occurs, such as the throwing of a C@t{++}
4291 exception or the loading of a library. As with watchpoints, you use a
4292 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4293 Catchpoints}), but aside from that, you can manage a catchpoint like any
4294 other breakpoint. (To stop when your program receives a signal, use the
4295 @code{handle} command; see @ref{Signals, ,Signals}.)
4296
4297 @cindex breakpoint numbers
4298 @cindex numbers for breakpoints
4299 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4300 catchpoint when you create it; these numbers are successive integers
4301 starting with one. In many of the commands for controlling various
4302 features of breakpoints you use the breakpoint number to say which
4303 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4304 @dfn{disabled}; if disabled, it has no effect on your program until you
4305 enable it again.
4306
4307 @cindex breakpoint ranges
4308 @cindex breakpoint lists
4309 @cindex ranges of breakpoints
4310 @cindex lists of breakpoints
4311 Some @value{GDBN} commands accept a space-separated list of breakpoints
4312 on which to operate. A list element can be either a single breakpoint number,
4313 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4314 When a breakpoint list is given to a command, all breakpoints in that list
4315 are operated on.
4316
4317 @menu
4318 * Set Breaks:: Setting breakpoints
4319 * Set Watchpoints:: Setting watchpoints
4320 * Set Catchpoints:: Setting catchpoints
4321 * Delete Breaks:: Deleting breakpoints
4322 * Disabling:: Disabling breakpoints
4323 * Conditions:: Break conditions
4324 * Break Commands:: Breakpoint command lists
4325 * Dynamic Printf:: Dynamic printf
4326 * Save Breakpoints:: How to save breakpoints in a file
4327 * Static Probe Points:: Listing static probe points
4328 * Error in Breakpoints:: ``Cannot insert breakpoints''
4329 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4330 @end menu
4331
4332 @node Set Breaks
4333 @subsection Setting Breakpoints
4334
4335 @c FIXME LMB what does GDB do if no code on line of breakpt?
4336 @c consider in particular declaration with/without initialization.
4337 @c
4338 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4339
4340 @kindex break
4341 @kindex b @r{(@code{break})}
4342 @vindex $bpnum@r{, convenience variable}
4343 @cindex latest breakpoint
4344 Breakpoints are set with the @code{break} command (abbreviated
4345 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4346 number of the breakpoint you've set most recently; see @ref{Convenience
4347 Vars,, Convenience Variables}, for a discussion of what you can do with
4348 convenience variables.
4349
4350 @table @code
4351 @item break @var{locspec}
4352 Set a breakpoint at all the code locations in your program that result
4353 from resolving the given @var{locspec}. @var{locspec} can specify a
4354 function name, a line number, an address of an instruction, and more.
4355 @xref{Location Specifications}, for the various forms of
4356 @var{locspec}. The breakpoint will stop your program just before it
4357 executes the instruction at the address of any of the breakpoint's
4358 code locations.
4359
4360 When using source languages that permit overloading of symbols, such
4361 as C@t{++}, a function name may refer to more than one symbol, and
4362 thus more than one place to break. @xref{Ambiguous
4363 Expressions,,Ambiguous Expressions}, for a discussion of that
4364 situation.
4365
4366 It is also possible to insert a breakpoint that will stop the program
4367 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4368 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4369
4370 @item break
4371 When called without any arguments, @code{break} sets a breakpoint at
4372 the next instruction to be executed in the selected stack frame
4373 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4374 innermost, this makes your program stop as soon as control
4375 returns to that frame. This is similar to the effect of a
4376 @code{finish} command in the frame inside the selected frame---except
4377 that @code{finish} does not leave an active breakpoint. If you use
4378 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4379 the next time it reaches the current location; this may be useful
4380 inside loops.
4381
4382 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4383 least one instruction has been executed. If it did not do this, you
4384 would be unable to proceed past a breakpoint without first disabling the
4385 breakpoint. This rule applies whether or not the breakpoint already
4386 existed when your program stopped.
4387
4388 @item break @dots{} if @var{cond}
4389 Set a breakpoint with condition @var{cond}; evaluate the expression
4390 @var{cond} each time the breakpoint is reached, and stop only if the
4391 value is nonzero---that is, if @var{cond} evaluates as true.
4392 @samp{@dots{}} stands for one of the possible arguments described
4393 above (or no argument) specifying where to break. @xref{Conditions,
4394 ,Break Conditions}, for more information on breakpoint conditions.
4395
4396 The breakpoint may be mapped to multiple locations. If the breakpoint
4397 condition @var{cond} is invalid at some but not all of the locations,
4398 the locations for which the condition is invalid are disabled. For
4399 example, @value{GDBN} reports below that two of the three locations
4400 are disabled.
4401
4402 @smallexample
4403 (@value{GDBP}) break func if a == 10
4404 warning: failed to validate condition at location 0x11ce, disabling:
4405 No symbol "a" in current context.
4406 warning: failed to validate condition at location 0x11b6, disabling:
4407 No symbol "a" in current context.
4408 Breakpoint 1 at 0x11b6: func. (3 locations)
4409 @end smallexample
4410
4411 Locations that are disabled because of the condition are denoted by an
4412 uppercase @code{N} in the output of the @code{info breakpoints}
4413 command:
4414
4415 @smallexample
4416 (@value{GDBP}) info breakpoints
4417 Num Type Disp Enb Address What
4418 1 breakpoint keep y <MULTIPLE>
4419 stop only if a == 10
4420 1.1 N* 0x00000000000011b6 in ...
4421 1.2 y 0x00000000000011c2 in ...
4422 1.3 N* 0x00000000000011ce in ...
4423 (*): Breakpoint condition is invalid at this location.
4424 @end smallexample
4425
4426 If the breakpoint condition @var{cond} is invalid in the context of
4427 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4428 define the breakpoint. For example, if variable @code{foo} is an
4429 undefined variable:
4430
4431 @smallexample
4432 (@value{GDBP}) break func if foo
4433 No symbol "foo" in current context.
4434 @end smallexample
4435
4436 @item break @dots{} -force-condition if @var{cond}
4437 There may be cases where the condition @var{cond} is invalid at all
4438 the current locations, but the user knows that it will be valid at a
4439 future location; for example, because of a library load. In such
4440 cases, by using the @code{-force-condition} keyword before @samp{if},
4441 @value{GDBN} can be forced to define the breakpoint with the given
4442 condition expression instead of refusing it.
4443
4444 @smallexample
4445 (@value{GDBP}) break func -force-condition if foo
4446 warning: failed to validate condition at location 1, disabling:
4447 No symbol "foo" in current context.
4448 warning: failed to validate condition at location 2, disabling:
4449 No symbol "foo" in current context.
4450 warning: failed to validate condition at location 3, disabling:
4451 No symbol "foo" in current context.
4452 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4453 @end smallexample
4454
4455 This causes all the present locations where the breakpoint would
4456 otherwise be inserted, to be disabled, as seen in the example above.
4457 However, if there exist locations at which the condition is valid, the
4458 @code{-force-condition} keyword has no effect.
4459
4460 @kindex tbreak
4461 @item tbreak @var{args}
4462 Set a breakpoint enabled only for one stop. The @var{args} are the
4463 same as for the @code{break} command, and the breakpoint is set in the same
4464 way, but the breakpoint is automatically deleted after the first time your
4465 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4466
4467 @kindex hbreak
4468 @cindex hardware breakpoints
4469 @item hbreak @var{args}
4470 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4471 @code{break} command and the breakpoint is set in the same way, but the
4472 breakpoint requires hardware support and some target hardware may not
4473 have this support. The main purpose of this is EPROM/ROM code
4474 debugging, so you can set a breakpoint at an instruction without
4475 changing the instruction. This can be used with the new trap-generation
4476 provided by SPARClite DSU and most x86-based targets. These targets
4477 will generate traps when a program accesses some data or instruction
4478 address that is assigned to the debug registers. However the hardware
4479 breakpoint registers can take a limited number of breakpoints. For
4480 example, on the DSU, only two data breakpoints can be set at a time, and
4481 @value{GDBN} will reject this command if more than two are used. Delete
4482 or disable unused hardware breakpoints before setting new ones
4483 (@pxref{Disabling, ,Disabling Breakpoints}).
4484 @xref{Conditions, ,Break Conditions}.
4485 For remote targets, you can restrict the number of hardware
4486 breakpoints @value{GDBN} will use, see @ref{set remote
4487 hardware-breakpoint-limit}.
4488
4489 @kindex thbreak
4490 @item thbreak @var{args}
4491 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4492 are the same as for the @code{hbreak} command and the breakpoint is set in
4493 the same way. However, like the @code{tbreak} command,
4494 the breakpoint is automatically deleted after the
4495 first time your program stops there. Also, like the @code{hbreak}
4496 command, the breakpoint requires hardware support and some target hardware
4497 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4498 See also @ref{Conditions, ,Break Conditions}.
4499
4500 @kindex rbreak
4501 @cindex regular expression
4502 @cindex breakpoints at functions matching a regexp
4503 @cindex set breakpoints in many functions
4504 @item rbreak @var{regex}
4505 Set breakpoints on all functions matching the regular expression
4506 @var{regex}. This command sets an unconditional breakpoint on all
4507 matches, printing a list of all breakpoints it set. Once these
4508 breakpoints are set, they are treated just like the breakpoints set with
4509 the @code{break} command. You can delete them, disable them, or make
4510 them conditional the same way as any other breakpoint.
4511
4512 In programs using different languages, @value{GDBN} chooses the syntax
4513 to print the list of all breakpoints it sets according to the
4514 @samp{set language} value: using @samp{set language auto}
4515 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4516 language of the breakpoint's function, other values mean to use
4517 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4518
4519 The syntax of the regular expression is the standard one used with tools
4520 like @file{grep}. Note that this is different from the syntax used by
4521 shells, so for instance @code{foo*} matches all functions that include
4522 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4523 @code{.*} leading and trailing the regular expression you supply, so to
4524 match only functions that begin with @code{foo}, use @code{^foo}.
4525
4526 @cindex non-member C@t{++} functions, set breakpoint in
4527 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4528 breakpoints on overloaded functions that are not members of any special
4529 classes.
4530
4531 @cindex set breakpoints on all functions
4532 The @code{rbreak} command can be used to set breakpoints in
4533 @strong{all} the functions in a program, like this:
4534
4535 @smallexample
4536 (@value{GDBP}) rbreak .
4537 @end smallexample
4538
4539 @item rbreak @var{file}:@var{regex}
4540 If @code{rbreak} is called with a filename qualification, it limits
4541 the search for functions matching the given regular expression to the
4542 specified @var{file}. This can be used, for example, to set breakpoints on
4543 every function in a given file:
4544
4545 @smallexample
4546 (@value{GDBP}) rbreak file.c:.
4547 @end smallexample
4548
4549 The colon separating the filename qualifier from the regex may
4550 optionally be surrounded by spaces.
4551
4552 @kindex info breakpoints
4553 @cindex @code{$_} and @code{info breakpoints}
4554 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4555 @itemx info break @r{[}@var{list}@dots{}@r{]}
4556 Print a table of all breakpoints, watchpoints, and catchpoints set and
4557 not deleted. Optional argument @var{n} means print information only
4558 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4559 For each breakpoint, following columns are printed:
4560
4561 @table @emph
4562 @item Breakpoint Numbers
4563 @item Type
4564 Breakpoint, watchpoint, or catchpoint.
4565 @item Disposition
4566 Whether the breakpoint is marked to be disabled or deleted when hit.
4567 @item Enabled or Disabled
4568 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4569 that are not enabled.
4570 @item Address
4571 Where the breakpoint is in your program, as a memory address. For a
4572 pending breakpoint whose address is not yet known, this field will
4573 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4574 library that has the symbol or line referred by breakpoint is loaded.
4575 See below for details. A breakpoint with several locations will
4576 have @samp{<MULTIPLE>} in this field---see below for details.
4577 @item What
4578 Where the breakpoint is in the source for your program, as a file and
4579 line number. For a pending breakpoint, the original string passed to
4580 the breakpoint command will be listed as it cannot be resolved until
4581 the appropriate shared library is loaded in the future.
4582 @end table
4583
4584 @noindent
4585 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4586 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4587 @value{GDBN} on the host's side. If it is ``target'', then the condition
4588 is evaluated by the target. The @code{info break} command shows
4589 the condition on the line following the affected breakpoint, together with
4590 its condition evaluation mode in between parentheses.
4591
4592 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4593 allowed to have a condition specified for it. The condition is not parsed for
4594 validity until a shared library is loaded that allows the pending
4595 breakpoint to resolve to a valid location.
4596
4597 @noindent
4598 @code{info break} with a breakpoint
4599 number @var{n} as argument lists only that breakpoint. The
4600 convenience variable @code{$_} and the default examining-address for
4601 the @code{x} command are set to the address of the last breakpoint
4602 listed (@pxref{Memory, ,Examining Memory}).
4603
4604 @noindent
4605 @code{info break} displays a count of the number of times the breakpoint
4606 has been hit. This is especially useful in conjunction with the
4607 @code{ignore} command. You can ignore a large number of breakpoint
4608 hits, look at the breakpoint info to see how many times the breakpoint
4609 was hit, and then run again, ignoring one less than that number. This
4610 will get you quickly to the last hit of that breakpoint.
4611
4612 @noindent
4613 For a breakpoints with an enable count (xref) greater than 1,
4614 @code{info break} also displays that count.
4615
4616 @end table
4617
4618 @value{GDBN} allows you to set any number of breakpoints at the same place in
4619 your program. There is nothing silly or meaningless about this. When
4620 the breakpoints are conditional, this is even useful
4621 (@pxref{Conditions, ,Break Conditions}).
4622
4623 @cindex multiple locations, breakpoints
4624 @cindex breakpoints, multiple locations
4625 It is possible that a single logical breakpoint is set at several code
4626 locations in your program. @xref{Location Specifications}, for
4627 examples.
4628
4629 A breakpoint with multiple code locations is displayed in the
4630 breakpoint table using several rows---one header row, followed by one
4631 row for each code location. The header row has @samp{<MULTIPLE>} in
4632 the address column. Each code location row contains the actual
4633 address, source file, source line and function of its code location.
4634 The number column for a code location is of the form
4635 @var{breakpoint-number}.@var{location-number}.
4636
4637 For example:
4638
4639 @smallexample
4640 Num Type Disp Enb Address What
4641 1 breakpoint keep y <MULTIPLE>
4642 stop only if i==1
4643 breakpoint already hit 1 time
4644 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4645 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4646 @end smallexample
4647
4648 You cannot delete the individual locations from a breakpoint. However,
4649 each location can be individually enabled or disabled by passing
4650 @var{breakpoint-number}.@var{location-number} as argument to the
4651 @code{enable} and @code{disable} commands. It's also possible to
4652 @code{enable} and @code{disable} a range of @var{location-number}
4653 locations using a @var{breakpoint-number} and two @var{location-number}s,
4654 in increasing order, separated by a hyphen, like
4655 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4656 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4657 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4658 all of the locations that belong to that breakpoint.
4659
4660 Locations that are enabled while their parent breakpoint is disabled
4661 won't trigger a break, and are denoted by @code{y-} in the @code{Enb}
4662 column. For example:
4663
4664 @smallexample
4665 (@value{GDBP}) info breakpoints
4666 Num Type Disp Enb Address What
4667 1 breakpoint keep n <MULTIPLE>
4668 1.1 y- 0x00000000000011b6 in ...
4669 1.2 y- 0x00000000000011c2 in ...
4670 1.3 n 0x00000000000011ce in ...
4671 @end smallexample
4672
4673 @cindex pending breakpoints
4674 It's quite common to have a breakpoint inside a shared library.
4675 Shared libraries can be loaded and unloaded explicitly,
4676 and possibly repeatedly, as the program is executed. To support
4677 this use case, @value{GDBN} updates breakpoint locations whenever
4678 any shared library is loaded or unloaded. Typically, you would
4679 set a breakpoint in a shared library at the beginning of your
4680 debugging session, when the library is not loaded, and when the
4681 symbols from the library are not available. When you try to set
4682 breakpoint, @value{GDBN} will ask you if you want to set
4683 a so called @dfn{pending breakpoint}---breakpoint whose address
4684 is not yet resolved.
4685
4686 After the program is run, whenever a new shared library is loaded,
4687 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4688 shared library contains the symbol or line referred to by some
4689 pending breakpoint, that breakpoint is resolved and becomes an
4690 ordinary breakpoint. When a library is unloaded, all breakpoints
4691 that refer to its symbols or source lines become pending again.
4692
4693 This logic works for breakpoints with multiple locations, too. For
4694 example, if you have a breakpoint in a C@t{++} template function, and
4695 a newly loaded shared library has an instantiation of that template,
4696 a new location is added to the list of locations for the breakpoint.
4697
4698 Except for having unresolved address, pending breakpoints do not
4699 differ from regular breakpoints. You can set conditions or commands,
4700 enable and disable them and perform other breakpoint operations.
4701
4702 @value{GDBN} provides some additional commands for controlling what
4703 happens when the @samp{break} command cannot resolve the location spec
4704 to any code location in your program (@pxref{Location
4705 Specifications}):
4706
4707 @kindex set breakpoint pending
4708 @kindex show breakpoint pending
4709 @table @code
4710 @item set breakpoint pending auto
4711 This is the default behavior. When @value{GDBN} cannot resolve the
4712 location spec, it queries you whether a pending breakpoint should be
4713 created.
4714
4715 @item set breakpoint pending on
4716 This indicates that when @value{GDBN} cannot resolve the location
4717 spec, it should create a pending breakpoint without confirmation.
4718
4719 @item set breakpoint pending off
4720 This indicates that pending breakpoints are not to be created. If
4721 @value{GDBN} cannot resolve the location spec, it aborts the
4722 breakpoint creation with an error. This setting does not affect any
4723 pending breakpoints previously created.
4724
4725 @item show breakpoint pending
4726 Show the current behavior setting for creating pending breakpoints.
4727 @end table
4728
4729 The settings above only affect the @code{break} command and its
4730 variants. Once a breakpoint is set, it will be automatically updated
4731 as shared libraries are loaded and unloaded.
4732
4733 @cindex automatic hardware breakpoints
4734 For some targets, @value{GDBN} can automatically decide if hardware or
4735 software breakpoints should be used, depending on whether the
4736 breakpoint address is read-only or read-write. This applies to
4737 breakpoints set with the @code{break} command as well as to internal
4738 breakpoints set by commands like @code{next} and @code{finish}. For
4739 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4740 breakpoints.
4741
4742 You can control this automatic behaviour with the following commands:
4743
4744 @kindex set breakpoint auto-hw
4745 @kindex show breakpoint auto-hw
4746 @table @code
4747 @item set breakpoint auto-hw on
4748 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4749 will try to use the target memory map to decide if software or hardware
4750 breakpoint must be used.
4751
4752 @item set breakpoint auto-hw off
4753 This indicates @value{GDBN} should not automatically select breakpoint
4754 type. If the target provides a memory map, @value{GDBN} will warn when
4755 trying to set software breakpoint at a read-only address.
4756 @end table
4757
4758 @value{GDBN} normally implements breakpoints by replacing the program code
4759 at the breakpoint address with a special instruction, which, when
4760 executed, given control to the debugger. By default, the program
4761 code is so modified only when the program is resumed. As soon as
4762 the program stops, @value{GDBN} restores the original instructions. This
4763 behaviour guards against leaving breakpoints inserted in the
4764 target should gdb abrubptly disconnect. However, with slow remote
4765 targets, inserting and removing breakpoint can reduce the performance.
4766 This behavior can be controlled with the following commands::
4767
4768 @kindex set breakpoint always-inserted
4769 @kindex show breakpoint always-inserted
4770 @table @code
4771 @item set breakpoint always-inserted off
4772 All breakpoints, including newly added by the user, are inserted in
4773 the target only when the target is resumed. All breakpoints are
4774 removed from the target when it stops. This is the default mode.
4775
4776 @item set breakpoint always-inserted on
4777 Causes all breakpoints to be inserted in the target at all times. If
4778 the user adds a new breakpoint, or changes an existing breakpoint, the
4779 breakpoints in the target are updated immediately. A breakpoint is
4780 removed from the target only when breakpoint itself is deleted.
4781 @end table
4782
4783 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4784 when a breakpoint breaks. If the condition is true, then the process being
4785 debugged stops, otherwise the process is resumed.
4786
4787 If the target supports evaluating conditions on its end, @value{GDBN} may
4788 download the breakpoint, together with its conditions, to it.
4789
4790 This feature can be controlled via the following commands:
4791
4792 @kindex set breakpoint condition-evaluation
4793 @kindex show breakpoint condition-evaluation
4794 @table @code
4795 @item set breakpoint condition-evaluation host
4796 This option commands @value{GDBN} to evaluate the breakpoint
4797 conditions on the host's side. Unconditional breakpoints are sent to
4798 the target which in turn receives the triggers and reports them back to GDB
4799 for condition evaluation. This is the standard evaluation mode.
4800
4801 @item set breakpoint condition-evaluation target
4802 This option commands @value{GDBN} to download breakpoint conditions
4803 to the target at the moment of their insertion. The target
4804 is responsible for evaluating the conditional expression and reporting
4805 breakpoint stop events back to @value{GDBN} whenever the condition
4806 is true. Due to limitations of target-side evaluation, some conditions
4807 cannot be evaluated there, e.g., conditions that depend on local data
4808 that is only known to the host. Examples include
4809 conditional expressions involving convenience variables, complex types
4810 that cannot be handled by the agent expression parser and expressions
4811 that are too long to be sent over to the target, specially when the
4812 target is a remote system. In these cases, the conditions will be
4813 evaluated by @value{GDBN}.
4814
4815 @item set breakpoint condition-evaluation auto
4816 This is the default mode. If the target supports evaluating breakpoint
4817 conditions on its end, @value{GDBN} will download breakpoint conditions to
4818 the target (limitations mentioned previously apply). If the target does
4819 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4820 to evaluating all these conditions on the host's side.
4821 @end table
4822
4823
4824 @cindex negative breakpoint numbers
4825 @cindex internal @value{GDBN} breakpoints
4826 @value{GDBN} itself sometimes sets breakpoints in your program for
4827 special purposes, such as proper handling of @code{longjmp} (in C
4828 programs). These internal breakpoints are assigned negative numbers,
4829 starting with @code{-1}; @samp{info breakpoints} does not display them.
4830 You can see these breakpoints with the @value{GDBN} maintenance command
4831 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4832
4833
4834 @node Set Watchpoints
4835 @subsection Setting Watchpoints
4836
4837 @cindex setting watchpoints
4838 You can use a watchpoint to stop execution whenever the value of an
4839 expression changes, without having to predict a particular place where
4840 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4841 The expression may be as simple as the value of a single variable, or
4842 as complex as many variables combined by operators. Examples include:
4843
4844 @itemize @bullet
4845 @item
4846 A reference to the value of a single variable.
4847
4848 @item
4849 An address cast to an appropriate data type. For example,
4850 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4851 address (assuming an @code{int} occupies 4 bytes).
4852
4853 @item
4854 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4855 expression can use any operators valid in the program's native
4856 language (@pxref{Languages}).
4857 @end itemize
4858
4859 You can set a watchpoint on an expression even if the expression can
4860 not be evaluated yet. For instance, you can set a watchpoint on
4861 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4862 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4863 the expression produces a valid value. If the expression becomes
4864 valid in some other way than changing a variable (e.g.@: if the memory
4865 pointed to by @samp{*global_ptr} becomes readable as the result of a
4866 @code{malloc} call), @value{GDBN} may not stop until the next time
4867 the expression changes.
4868
4869 @cindex software watchpoints
4870 @cindex hardware watchpoints
4871 Depending on your system, watchpoints may be implemented in software or
4872 hardware. @value{GDBN} does software watchpointing by single-stepping your
4873 program and testing the variable's value each time, which is hundreds of
4874 times slower than normal execution. (But this may still be worth it, to
4875 catch errors where you have no clue what part of your program is the
4876 culprit.)
4877
4878 On some systems, such as most PowerPC or x86-based targets,
4879 @value{GDBN} includes support for hardware watchpoints, which do not
4880 slow down the running of your program.
4881
4882 @table @code
4883 @kindex watch
4884 @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{]}
4885 Set a watchpoint for an expression. @value{GDBN} will break when the
4886 expression @var{expr} is written into by the program and its value
4887 changes. The simplest (and the most popular) use of this command is
4888 to watch the value of a single variable:
4889
4890 @smallexample
4891 (@value{GDBP}) watch foo
4892 @end smallexample
4893
4894 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4895 argument, @value{GDBN} breaks only when the thread identified by
4896 @var{thread-id} changes the value of @var{expr}. If any other threads
4897 change the value of @var{expr}, @value{GDBN} will not break. Note
4898 that watchpoints restricted to a single thread in this way only work
4899 with Hardware Watchpoints.
4900
4901 Similarly, if the @code{task} argument is given, then the watchpoint
4902 will be specific to the indicated Ada task (@pxref{Ada Tasks}).
4903
4904 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4905 (see below). The @code{-location} argument tells @value{GDBN} to
4906 instead watch the memory referred to by @var{expr}. In this case,
4907 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4908 and watch the memory at that address. The type of the result is used
4909 to determine the size of the watched memory. If the expression's
4910 result does not have an address, then @value{GDBN} will print an
4911 error.
4912
4913 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4914 of masked watchpoints, if the current architecture supports this
4915 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4916 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4917 to an address to watch. The mask specifies that some bits of an address
4918 (the bits which are reset in the mask) should be ignored when matching
4919 the address accessed by the inferior against the watchpoint address.
4920 Thus, a masked watchpoint watches many addresses simultaneously---those
4921 addresses whose unmasked bits are identical to the unmasked bits in the
4922 watchpoint address. The @code{mask} argument implies @code{-location}.
4923 Examples:
4924
4925 @smallexample
4926 (@value{GDBP}) watch foo mask 0xffff00ff
4927 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4928 @end smallexample
4929
4930 @kindex rwatch
4931 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4932 Set a watchpoint that will break when the value of @var{expr} is read
4933 by the program.
4934
4935 @kindex awatch
4936 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4937 Set a watchpoint that will break when @var{expr} is either read from
4938 or written into by the program.
4939
4940 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4941 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4942 This command prints a list of watchpoints, using the same format as
4943 @code{info break} (@pxref{Set Breaks}).
4944 @end table
4945
4946 If you watch for a change in a numerically entered address you need to
4947 dereference it, as the address itself is just a constant number which will
4948 never change. @value{GDBN} refuses to create a watchpoint that watches
4949 a never-changing value:
4950
4951 @smallexample
4952 (@value{GDBP}) watch 0x600850
4953 Cannot watch constant value 0x600850.
4954 (@value{GDBP}) watch *(int *) 0x600850
4955 Watchpoint 1: *(int *) 6293584
4956 @end smallexample
4957
4958 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4959 watchpoints execute very quickly, and the debugger reports a change in
4960 value at the exact instruction where the change occurs. If @value{GDBN}
4961 cannot set a hardware watchpoint, it sets a software watchpoint, which
4962 executes more slowly and reports the change in value at the next
4963 @emph{statement}, not the instruction, after the change occurs.
4964
4965 @cindex use only software watchpoints
4966 You can force @value{GDBN} to use only software watchpoints with the
4967 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4968 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4969 the underlying system supports them. (Note that hardware-assisted
4970 watchpoints that were set @emph{before} setting
4971 @code{can-use-hw-watchpoints} to zero will still use the hardware
4972 mechanism of watching expression values.)
4973
4974 @table @code
4975 @item set can-use-hw-watchpoints
4976 @kindex set can-use-hw-watchpoints
4977 Set whether or not to use hardware watchpoints.
4978
4979 @item show can-use-hw-watchpoints
4980 @kindex show can-use-hw-watchpoints
4981 Show the current mode of using hardware watchpoints.
4982 @end table
4983
4984 For remote targets, you can restrict the number of hardware
4985 watchpoints @value{GDBN} will use, see @ref{set remote
4986 hardware-breakpoint-limit}.
4987
4988 When you issue the @code{watch} command, @value{GDBN} reports
4989
4990 @smallexample
4991 Hardware watchpoint @var{num}: @var{expr}
4992 @end smallexample
4993
4994 @noindent
4995 if it was able to set a hardware watchpoint.
4996
4997 Currently, the @code{awatch} and @code{rwatch} commands can only set
4998 hardware watchpoints, because accesses to data that don't change the
4999 value of the watched expression cannot be detected without examining
5000 every instruction as it is being executed, and @value{GDBN} does not do
5001 that currently. If @value{GDBN} finds that it is unable to set a
5002 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
5003 will print a message like this:
5004
5005 @smallexample
5006 Expression cannot be implemented with read/access watchpoint.
5007 @end smallexample
5008
5009 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
5010 data type of the watched expression is wider than what a hardware
5011 watchpoint on the target machine can handle. For example, some systems
5012 can only watch regions that are up to 4 bytes wide; on such systems you
5013 cannot set hardware watchpoints for an expression that yields a
5014 double-precision floating-point number (which is typically 8 bytes
5015 wide). As a work-around, it might be possible to break the large region
5016 into a series of smaller ones and watch them with separate watchpoints.
5017
5018 If you set too many hardware watchpoints, @value{GDBN} might be unable
5019 to insert all of them when you resume the execution of your program.
5020 Since the precise number of active watchpoints is unknown until such
5021 time as the program is about to be resumed, @value{GDBN} might not be
5022 able to warn you about this when you set the watchpoints, and the
5023 warning will be printed only when the program is resumed:
5024
5025 @smallexample
5026 Hardware watchpoint @var{num}: Could not insert watchpoint
5027 @end smallexample
5028
5029 @noindent
5030 If this happens, delete or disable some of the watchpoints.
5031
5032 Watching complex expressions that reference many variables can also
5033 exhaust the resources available for hardware-assisted watchpoints.
5034 That's because @value{GDBN} needs to watch every variable in the
5035 expression with separately allocated resources.
5036
5037 If you call a function interactively using @code{print} or @code{call},
5038 any watchpoints you have set will be inactive until @value{GDBN} reaches another
5039 kind of breakpoint or the call completes.
5040
5041 @value{GDBN} automatically deletes watchpoints that watch local
5042 (automatic) variables, or expressions that involve such variables, when
5043 they go out of scope, that is, when the execution leaves the block in
5044 which these variables were defined. In particular, when the program
5045 being debugged terminates, @emph{all} local variables go out of scope,
5046 and so only watchpoints that watch global variables remain set. If you
5047 rerun the program, you will need to set all such watchpoints again. One
5048 way of doing that would be to set a code breakpoint at the entry to the
5049 @code{main} function and when it breaks, set all the watchpoints.
5050
5051 @cindex watchpoints and threads
5052 @cindex threads and watchpoints
5053 In multi-threaded programs, watchpoints will detect changes to the
5054 watched expression from every thread.
5055
5056 @quotation
5057 @emph{Warning:} In multi-threaded programs, software watchpoints
5058 have only limited usefulness. If @value{GDBN} creates a software
5059 watchpoint, it can only watch the value of an expression @emph{in a
5060 single thread}. If you are confident that the expression can only
5061 change due to the current thread's activity (and if you are also
5062 confident that no other thread can become current), then you can use
5063 software watchpoints as usual. However, @value{GDBN} may not notice
5064 when a non-current thread's activity changes the expression. (Hardware
5065 watchpoints, in contrast, watch an expression in all threads.)
5066 @end quotation
5067
5068 @xref{set remote hardware-watchpoint-limit}.
5069
5070 @node Set Catchpoints
5071 @subsection Setting Catchpoints
5072 @cindex catchpoints, setting
5073 @cindex exception handlers
5074 @cindex event handling
5075
5076 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5077 kinds of program events, such as C@t{++} exceptions or the loading of a
5078 shared library. Use the @code{catch} command to set a catchpoint.
5079
5080 @table @code
5081 @kindex catch
5082 @item catch @var{event}
5083 Stop when @var{event} occurs. The @var{event} can be any of the following:
5084
5085 @table @code
5086 @item throw @r{[}@var{regexp}@r{]}
5087 @itemx rethrow @r{[}@var{regexp}@r{]}
5088 @itemx catch @r{[}@var{regexp}@r{]}
5089 @kindex catch throw
5090 @kindex catch rethrow
5091 @kindex catch catch
5092 @cindex stop on C@t{++} exceptions
5093 The throwing, re-throwing, or catching of a C@t{++} exception.
5094
5095 If @var{regexp} is given, then only exceptions whose type matches the
5096 regular expression will be caught.
5097
5098 @vindex $_exception@r{, convenience variable}
5099 The convenience variable @code{$_exception} is available at an
5100 exception-related catchpoint, on some systems. This holds the
5101 exception being thrown.
5102
5103 There are currently some limitations to C@t{++} exception handling in
5104 @value{GDBN}:
5105
5106 @itemize @bullet
5107 @item
5108 The support for these commands is system-dependent. Currently, only
5109 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5110 supported.
5111
5112 @item
5113 The regular expression feature and the @code{$_exception} convenience
5114 variable rely on the presence of some SDT probes in @code{libstdc++}.
5115 If these probes are not present, then these features cannot be used.
5116 These probes were first available in the GCC 4.8 release, but whether
5117 or not they are available in your GCC also depends on how it was
5118 built.
5119
5120 @item
5121 The @code{$_exception} convenience variable is only valid at the
5122 instruction at which an exception-related catchpoint is set.
5123
5124 @item
5125 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5126 location in the system library which implements runtime exception
5127 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5128 (@pxref{Selection}) to get to your code.
5129
5130 @item
5131 If you call a function interactively, @value{GDBN} normally returns
5132 control to you when the function has finished executing. If the call
5133 raises an exception, however, the call may bypass the mechanism that
5134 returns control to you and cause your program either to abort or to
5135 simply continue running until it hits a breakpoint, catches a signal
5136 that @value{GDBN} is listening for, or exits. This is the case even if
5137 you set a catchpoint for the exception; catchpoints on exceptions are
5138 disabled within interactive calls. @xref{Calling}, for information on
5139 controlling this with @code{set unwind-on-terminating-exception}.
5140
5141 @item
5142 You cannot raise an exception interactively.
5143
5144 @item
5145 You cannot install an exception handler interactively.
5146 @end itemize
5147
5148 @item exception @r{[}@var{name}@r{]}
5149 @kindex catch exception
5150 @cindex Ada exception catching
5151 @cindex catch Ada exceptions
5152 An Ada exception being raised. If an exception name is specified
5153 at the end of the command (eg @code{catch exception Program_Error}),
5154 the debugger will stop only when this specific exception is raised.
5155 Otherwise, the debugger stops execution when any Ada exception is raised.
5156
5157 When inserting an exception catchpoint on a user-defined exception whose
5158 name is identical to one of the exceptions defined by the language, the
5159 fully qualified name must be used as the exception name. Otherwise,
5160 @value{GDBN} will assume that it should stop on the pre-defined exception
5161 rather than the user-defined one. For instance, assuming an exception
5162 called @code{Constraint_Error} is defined in package @code{Pck}, then
5163 the command to use to catch such exceptions is @kbd{catch exception
5164 Pck.Constraint_Error}.
5165
5166 @vindex $_ada_exception@r{, convenience variable}
5167 The convenience variable @code{$_ada_exception} holds the address of
5168 the exception being thrown. This can be useful when setting a
5169 condition for such a catchpoint.
5170
5171 @item exception unhandled
5172 @kindex catch exception unhandled
5173 An exception that was raised but is not handled by the program. The
5174 convenience variable @code{$_ada_exception} is set as for @code{catch
5175 exception}.
5176
5177 @item handlers @r{[}@var{name}@r{]}
5178 @kindex catch handlers
5179 @cindex Ada exception handlers catching
5180 @cindex catch Ada exceptions when handled
5181 An Ada exception being handled. If an exception name is
5182 specified at the end of the command
5183 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5184 only when this specific exception is handled.
5185 Otherwise, the debugger stops execution when any Ada exception is handled.
5186
5187 When inserting a handlers catchpoint on a user-defined
5188 exception whose name is identical to one of the exceptions
5189 defined by the language, the fully qualified name must be used
5190 as the exception name. Otherwise, @value{GDBN} will assume that it
5191 should stop on the pre-defined exception rather than the
5192 user-defined one. For instance, assuming an exception called
5193 @code{Constraint_Error} is defined in package @code{Pck}, then the
5194 command to use to catch such exceptions handling is
5195 @kbd{catch handlers Pck.Constraint_Error}.
5196
5197 The convenience variable @code{$_ada_exception} is set as for
5198 @code{catch exception}.
5199
5200 @item assert
5201 @kindex catch assert
5202 A failed Ada assertion. Note that the convenience variable
5203 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5204
5205 @item exec
5206 @kindex catch exec
5207 @cindex break on fork/exec
5208 A call to @code{exec}.
5209
5210 @anchor{catch syscall}
5211 @item syscall
5212 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5213 @kindex catch syscall
5214 @cindex break on a system call.
5215 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5216 syscall is a mechanism for application programs to request a service
5217 from the operating system (OS) or one of the OS system services.
5218 @value{GDBN} can catch some or all of the syscalls issued by the
5219 debuggee, and show the related information for each syscall. If no
5220 argument is specified, calls to and returns from all system calls
5221 will be caught.
5222
5223 @var{name} can be any system call name that is valid for the
5224 underlying OS. Just what syscalls are valid depends on the OS. On
5225 GNU and Unix systems, you can find the full list of valid syscall
5226 names on @file{/usr/include/asm/unistd.h}.
5227
5228 @c For MS-Windows, the syscall names and the corresponding numbers
5229 @c can be found, e.g., on this URL:
5230 @c http://www.metasploit.com/users/opcode/syscalls.html
5231 @c but we don't support Windows syscalls yet.
5232
5233 Normally, @value{GDBN} knows in advance which syscalls are valid for
5234 each OS, so you can use the @value{GDBN} command-line completion
5235 facilities (@pxref{Completion,, command completion}) to list the
5236 available choices.
5237
5238 You may also specify the system call numerically. A syscall's
5239 number is the value passed to the OS's syscall dispatcher to
5240 identify the requested service. When you specify the syscall by its
5241 name, @value{GDBN} uses its database of syscalls to convert the name
5242 into the corresponding numeric code, but using the number directly
5243 may be useful if @value{GDBN}'s database does not have the complete
5244 list of syscalls on your system (e.g., because @value{GDBN} lags
5245 behind the OS upgrades).
5246
5247 You may specify a group of related syscalls to be caught at once using
5248 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5249 instance, on some platforms @value{GDBN} allows you to catch all
5250 network related syscalls, by passing the argument @code{group:network}
5251 to @code{catch syscall}. Note that not all syscall groups are
5252 available in every system. You can use the command completion
5253 facilities (@pxref{Completion,, command completion}) to list the
5254 syscall groups available on your environment.
5255
5256 The example below illustrates how this command works if you don't provide
5257 arguments to it:
5258
5259 @smallexample
5260 (@value{GDBP}) catch syscall
5261 Catchpoint 1 (syscall)
5262 (@value{GDBP}) r
5263 Starting program: /tmp/catch-syscall
5264
5265 Catchpoint 1 (call to syscall 'close'), \
5266 0xffffe424 in __kernel_vsyscall ()
5267 (@value{GDBP}) c
5268 Continuing.
5269
5270 Catchpoint 1 (returned from syscall 'close'), \
5271 0xffffe424 in __kernel_vsyscall ()
5272 (@value{GDBP})
5273 @end smallexample
5274
5275 Here is an example of catching a system call by name:
5276
5277 @smallexample
5278 (@value{GDBP}) catch syscall chroot
5279 Catchpoint 1 (syscall 'chroot' [61])
5280 (@value{GDBP}) r
5281 Starting program: /tmp/catch-syscall
5282
5283 Catchpoint 1 (call to syscall 'chroot'), \
5284 0xffffe424 in __kernel_vsyscall ()
5285 (@value{GDBP}) c
5286 Continuing.
5287
5288 Catchpoint 1 (returned from syscall 'chroot'), \
5289 0xffffe424 in __kernel_vsyscall ()
5290 (@value{GDBP})
5291 @end smallexample
5292
5293 An example of specifying a system call numerically. In the case
5294 below, the syscall number has a corresponding entry in the XML
5295 file, so @value{GDBN} finds its name and prints it:
5296
5297 @smallexample
5298 (@value{GDBP}) catch syscall 252
5299 Catchpoint 1 (syscall(s) 'exit_group')
5300 (@value{GDBP}) r
5301 Starting program: /tmp/catch-syscall
5302
5303 Catchpoint 1 (call to syscall 'exit_group'), \
5304 0xffffe424 in __kernel_vsyscall ()
5305 (@value{GDBP}) c
5306 Continuing.
5307
5308 Program exited normally.
5309 (@value{GDBP})
5310 @end smallexample
5311
5312 Here is an example of catching a syscall group:
5313
5314 @smallexample
5315 (@value{GDBP}) catch syscall group:process
5316 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5317 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5318 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5319 (@value{GDBP}) r
5320 Starting program: /tmp/catch-syscall
5321
5322 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5323 from /lib64/ld-linux-x86-64.so.2
5324
5325 (@value{GDBP}) c
5326 Continuing.
5327 @end smallexample
5328
5329 However, there can be situations when there is no corresponding name
5330 in XML file for that syscall number. In this case, @value{GDBN} prints
5331 a warning message saying that it was not able to find the syscall name,
5332 but the catchpoint will be set anyway. See the example below:
5333
5334 @smallexample
5335 (@value{GDBP}) catch syscall 764
5336 warning: The number '764' does not represent a known syscall.
5337 Catchpoint 2 (syscall 764)
5338 (@value{GDBP})
5339 @end smallexample
5340
5341 If you configure @value{GDBN} using the @samp{--without-expat} option,
5342 it will not be able to display syscall names. Also, if your
5343 architecture does not have an XML file describing its system calls,
5344 you will not be able to see the syscall names. It is important to
5345 notice that these two features are used for accessing the syscall
5346 name database. In either case, you will see a warning like this:
5347
5348 @smallexample
5349 (@value{GDBP}) catch syscall
5350 warning: Could not open "syscalls/i386-linux.xml"
5351 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5352 GDB will not be able to display syscall names.
5353 Catchpoint 1 (syscall)
5354 (@value{GDBP})
5355 @end smallexample
5356
5357 Of course, the file name will change depending on your architecture and system.
5358
5359 Still using the example above, you can also try to catch a syscall by its
5360 number. In this case, you would see something like:
5361
5362 @smallexample
5363 (@value{GDBP}) catch syscall 252
5364 Catchpoint 1 (syscall(s) 252)
5365 @end smallexample
5366
5367 Again, in this case @value{GDBN} would not be able to display syscall's names.
5368
5369 @item fork
5370 @kindex catch fork
5371 A call to @code{fork}.
5372
5373 @item vfork
5374 @kindex catch vfork
5375 A call to @code{vfork}.
5376
5377 @item load @r{[}@var{regexp}@r{]}
5378 @itemx unload @r{[}@var{regexp}@r{]}
5379 @kindex catch load
5380 @kindex catch unload
5381 The loading or unloading of a shared library. If @var{regexp} is
5382 given, then the catchpoint will stop only if the regular expression
5383 matches one of the affected libraries.
5384
5385 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5386 @kindex catch signal
5387 The delivery of a signal.
5388
5389 With no arguments, this catchpoint will catch any signal that is not
5390 used internally by @value{GDBN}, specifically, all signals except
5391 @samp{SIGTRAP} and @samp{SIGINT}.
5392
5393 With the argument @samp{all}, all signals, including those used by
5394 @value{GDBN}, will be caught. This argument cannot be used with other
5395 signal names.
5396
5397 Otherwise, the arguments are a list of signal names as given to
5398 @code{handle} (@pxref{Signals}). Only signals specified in this list
5399 will be caught.
5400
5401 One reason that @code{catch signal} can be more useful than
5402 @code{handle} is that you can attach commands and conditions to the
5403 catchpoint.
5404
5405 When a signal is caught by a catchpoint, the signal's @code{stop} and
5406 @code{print} settings, as specified by @code{handle}, are ignored.
5407 However, whether the signal is still delivered to the inferior depends
5408 on the @code{pass} setting; this can be changed in the catchpoint's
5409 commands.
5410
5411 @end table
5412
5413 @item tcatch @var{event}
5414 @kindex tcatch
5415 Set a catchpoint that is enabled only for one stop. The catchpoint is
5416 automatically deleted after the first time the event is caught.
5417
5418 @end table
5419
5420 Use the @code{info break} command to list the current catchpoints.
5421
5422
5423 @node Delete Breaks
5424 @subsection Deleting Breakpoints
5425
5426 @cindex clearing breakpoints, watchpoints, catchpoints
5427 @cindex deleting breakpoints, watchpoints, catchpoints
5428 It is often necessary to eliminate a breakpoint, watchpoint, or
5429 catchpoint once it has done its job and you no longer want your program
5430 to stop there. This is called @dfn{deleting} the breakpoint. A
5431 breakpoint that has been deleted no longer exists; it is forgotten.
5432
5433 With the @code{clear} command you can delete breakpoints according to
5434 where they are in your program. With the @code{delete} command you can
5435 delete individual breakpoints, watchpoints, or catchpoints by specifying
5436 their breakpoint numbers.
5437
5438 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5439 automatically ignores breakpoints on the first instruction to be executed
5440 when you continue execution without changing the execution address.
5441
5442 @table @code
5443 @kindex clear
5444 @item clear
5445 Delete any breakpoints at the next instruction to be executed in the
5446 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5447 the innermost frame is selected, this is a good way to delete a
5448 breakpoint where your program just stopped.
5449
5450 @item clear @var{locspec}
5451 Delete any breakpoint with a code location that corresponds to
5452 @var{locspec}. @xref{Location Specifications}, for the various forms
5453 of @var{locspec}. Which code locations correspond to @var{locspec}
5454 depends on the form used in the location specification @var{locspec}:
5455
5456 @table @code
5457 @item @var{linenum}
5458 @itemx @var{filename}:@var{linenum}
5459 @itemx -line @var{linenum}
5460 @itemx -source @var{filename} -line @var{linenum}
5461 If @var{locspec} specifies a line number, with or without a file name,
5462 the command deletes any breakpoint with a code location that is at or
5463 within the specified line @var{linenum} in files that match the
5464 specified @var{filename}. If @var{filename} is omitted, it defaults
5465 to the current source file.
5466
5467 @item *@var{address}
5468 If @var{locspec} specifies an address, the command deletes any
5469 breakpoint with a code location that is at the given @var{address}.
5470
5471 @item @var{function}
5472 @itemx -function @var{function}
5473 If @var{locspec} specifies a function, the command deletes any
5474 breakpoint with a code location that is at the entry to any function
5475 whose name matches @var{function}.
5476 @end table
5477
5478 Ambiguity in names of files and functions can be resolved as described
5479 in @ref{Location Specifications}.
5480
5481 @cindex delete breakpoints
5482 @kindex delete
5483 @kindex d @r{(@code{delete})}
5484 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5485 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5486 list specified as argument. If no argument is specified, delete all
5487 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5488 confirm off}). You can abbreviate this command as @code{d}.
5489 @end table
5490
5491 @node Disabling
5492 @subsection Disabling Breakpoints
5493
5494 @cindex enable/disable a breakpoint
5495 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5496 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5497 it had been deleted, but remembers the information on the breakpoint so
5498 that you can @dfn{enable} it again later.
5499
5500 You disable and enable breakpoints, watchpoints, and catchpoints with
5501 the @code{enable} and @code{disable} commands, optionally specifying
5502 one or more breakpoint numbers as arguments. Use @code{info break} to
5503 print a list of all breakpoints, watchpoints, and catchpoints if you
5504 do not know which numbers to use.
5505
5506 Disabling and enabling a breakpoint that has multiple locations
5507 affects all of its locations.
5508
5509 A breakpoint, watchpoint, or catchpoint can have any of several
5510 different states of enablement:
5511
5512 @itemize @bullet
5513 @item
5514 Enabled. The breakpoint stops your program. A breakpoint set
5515 with the @code{break} command starts out in this state.
5516 @item
5517 Disabled. The breakpoint has no effect on your program.
5518 @item
5519 Enabled once. The breakpoint stops your program, but then becomes
5520 disabled.
5521 @item
5522 Enabled for a count. The breakpoint stops your program for the next
5523 N times, then becomes disabled.
5524 @item
5525 Enabled for deletion. The breakpoint stops your program, but
5526 immediately after it does so it is deleted permanently. A breakpoint
5527 set with the @code{tbreak} command starts out in this state.
5528 @end itemize
5529
5530 You can use the following commands to enable or disable breakpoints,
5531 watchpoints, and catchpoints:
5532
5533 @table @code
5534 @kindex disable
5535 @kindex dis @r{(@code{disable})}
5536 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5537 Disable the specified breakpoints---or all breakpoints, if none are
5538 listed. A disabled breakpoint has no effect but is not forgotten. All
5539 options such as ignore-counts, conditions and commands are remembered in
5540 case the breakpoint is enabled again later. You may abbreviate
5541 @code{disable} as @code{dis}.
5542
5543 @kindex enable
5544 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5545 Enable the specified breakpoints (or all defined breakpoints). They
5546 become effective once again in stopping your program.
5547
5548 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5549 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5550 of these breakpoints immediately after stopping your program.
5551
5552 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5553 Enable the specified breakpoints temporarily. @value{GDBN} records
5554 @var{count} with each of the specified breakpoints, and decrements a
5555 breakpoint's count when it is hit. When any count reaches 0,
5556 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5557 count (@pxref{Conditions, ,Break Conditions}), that will be
5558 decremented to 0 before @var{count} is affected.
5559
5560 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5561 Enable the specified breakpoints to work once, then die. @value{GDBN}
5562 deletes any of these breakpoints as soon as your program stops there.
5563 Breakpoints set by the @code{tbreak} command start out in this state.
5564 @end table
5565
5566 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5567 @c confusing: tbreak is also initially enabled.
5568 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5569 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5570 subsequently, they become disabled or enabled only when you use one of
5571 the commands above. (The command @code{until} can set and delete a
5572 breakpoint of its own, but it does not change the state of your other
5573 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5574 Stepping}.)
5575
5576 @node Conditions
5577 @subsection Break Conditions
5578 @cindex conditional breakpoints
5579 @cindex breakpoint conditions
5580
5581 @c FIXME what is scope of break condition expr? Context where wanted?
5582 @c in particular for a watchpoint?
5583 The simplest sort of breakpoint breaks every time your program reaches a
5584 specified place. You can also specify a @dfn{condition} for a
5585 breakpoint. A condition is just a Boolean expression in your
5586 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5587 a condition evaluates the expression each time your program reaches it,
5588 and your program stops only if the condition is @emph{true}.
5589
5590 This is the converse of using assertions for program validation; in that
5591 situation, you want to stop when the assertion is violated---that is,
5592 when the condition is false. In C, if you want to test an assertion expressed
5593 by the condition @var{assert}, you should set the condition
5594 @samp{! @var{assert}} on the appropriate breakpoint.
5595
5596 Conditions are also accepted for watchpoints; you may not need them,
5597 since a watchpoint is inspecting the value of an expression anyhow---but
5598 it might be simpler, say, to just set a watchpoint on a variable name,
5599 and specify a condition that tests whether the new value is an interesting
5600 one.
5601
5602 Break conditions can have side effects, and may even call functions in
5603 your program. This can be useful, for example, to activate functions
5604 that log program progress, or to use your own print functions to
5605 format special data structures. The effects are completely predictable
5606 unless there is another enabled breakpoint at the same address. (In
5607 that case, @value{GDBN} might see the other breakpoint first and stop your
5608 program without checking the condition of this one.) Note that
5609 breakpoint commands are usually more convenient and flexible than break
5610 conditions for the
5611 purpose of performing side effects when a breakpoint is reached
5612 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5613
5614 Breakpoint conditions can also be evaluated on the target's side if
5615 the target supports it. Instead of evaluating the conditions locally,
5616 @value{GDBN} encodes the expression into an agent expression
5617 (@pxref{Agent Expressions}) suitable for execution on the target,
5618 independently of @value{GDBN}. Global variables become raw memory
5619 locations, locals become stack accesses, and so forth.
5620
5621 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5622 when its condition evaluates to true. This mechanism may provide faster
5623 response times depending on the performance characteristics of the target
5624 since it does not need to keep @value{GDBN} informed about
5625 every breakpoint trigger, even those with false conditions.
5626
5627 Break conditions can be specified when a breakpoint is set, by using
5628 @samp{if} in the arguments to the @code{break} command. @xref{Set
5629 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5630 with the @code{condition} command.
5631
5632 You can also use the @code{if} keyword with the @code{watch} command.
5633 The @code{catch} command does not recognize the @code{if} keyword;
5634 @code{condition} is the only way to impose a further condition on a
5635 catchpoint.
5636
5637 @table @code
5638 @kindex condition
5639 @item condition @var{bnum} @var{expression}
5640 Specify @var{expression} as the break condition for breakpoint,
5641 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5642 breakpoint @var{bnum} stops your program only if the value of
5643 @var{expression} is true (nonzero, in C). When you use
5644 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5645 syntactic correctness, and to determine whether symbols in it have
5646 referents in the context of your breakpoint. If @var{expression} uses
5647 symbols not referenced in the context of the breakpoint, @value{GDBN}
5648 prints an error message:
5649
5650 @smallexample
5651 No symbol "foo" in current context.
5652 @end smallexample
5653
5654 @noindent
5655 @value{GDBN} does
5656 not actually evaluate @var{expression} at the time the @code{condition}
5657 command (or a command that sets a breakpoint with a condition, like
5658 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5659
5660 @item condition -force @var{bnum} @var{expression}
5661 When the @code{-force} flag is used, define the condition even if
5662 @var{expression} is invalid at all the current locations of breakpoint
5663 @var{bnum}. This is similar to the @code{-force-condition} option
5664 of the @code{break} command.
5665
5666 @item condition @var{bnum}
5667 Remove the condition from breakpoint number @var{bnum}. It becomes
5668 an ordinary unconditional breakpoint.
5669 @end table
5670
5671 @cindex ignore count (of breakpoint)
5672 A special case of a breakpoint condition is to stop only when the
5673 breakpoint has been reached a certain number of times. This is so
5674 useful that there is a special way to do it, using the @dfn{ignore
5675 count} of the breakpoint. Every breakpoint has an ignore count, which
5676 is an integer. Most of the time, the ignore count is zero, and
5677 therefore has no effect. But if your program reaches a breakpoint whose
5678 ignore count is positive, then instead of stopping, it just decrements
5679 the ignore count by one and continues. As a result, if the ignore count
5680 value is @var{n}, the breakpoint does not stop the next @var{n} times
5681 your program reaches it.
5682
5683 @table @code
5684 @kindex ignore
5685 @item ignore @var{bnum} @var{count}
5686 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5687 The next @var{count} times the breakpoint is reached, your program's
5688 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5689 takes no action.
5690
5691 To make the breakpoint stop the next time it is reached, specify
5692 a count of zero.
5693
5694 When you use @code{continue} to resume execution of your program from a
5695 breakpoint, you can specify an ignore count directly as an argument to
5696 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5697 Stepping,,Continuing and Stepping}.
5698
5699 If a breakpoint has a positive ignore count and a condition, the
5700 condition is not checked. Once the ignore count reaches zero,
5701 @value{GDBN} resumes checking the condition.
5702
5703 You could achieve the effect of the ignore count with a condition such
5704 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5705 is decremented each time. @xref{Convenience Vars, ,Convenience
5706 Variables}.
5707 @end table
5708
5709 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5710
5711
5712 @node Break Commands
5713 @subsection Breakpoint Command Lists
5714
5715 @cindex breakpoint commands
5716 You can give any breakpoint (or watchpoint or catchpoint) a series of
5717 commands to execute when your program stops due to that breakpoint. For
5718 example, you might want to print the values of certain expressions, or
5719 enable other breakpoints.
5720
5721 @table @code
5722 @kindex commands
5723 @kindex end@r{ (breakpoint commands)}
5724 @item commands @r{[}@var{list}@dots{}@r{]}
5725 @itemx @dots{} @var{command-list} @dots{}
5726 @itemx end
5727 Specify a list of commands for the given breakpoints. The commands
5728 themselves appear on the following lines. Type a line containing just
5729 @code{end} to terminate the commands.
5730
5731 To remove all commands from a breakpoint, type @code{commands} and
5732 follow it immediately with @code{end}; that is, give no commands.
5733
5734 With no argument, @code{commands} refers to the last breakpoint,
5735 watchpoint, or catchpoint set (not to the breakpoint most recently
5736 encountered). If the most recent breakpoints were set with a single
5737 command, then the @code{commands} will apply to all the breakpoints
5738 set by that command. This applies to breakpoints set by
5739 @code{rbreak}, and also applies when a single @code{break} command
5740 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5741 Expressions}).
5742 @end table
5743
5744 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5745 disabled within a @var{command-list}.
5746
5747 You can use breakpoint commands to start your program up again. Simply
5748 use the @code{continue} command, or @code{step}, or any other command
5749 that resumes execution.
5750
5751 Any other commands in the command list, after a command that resumes
5752 execution, are ignored. This is because any time you resume execution
5753 (even with a simple @code{next} or @code{step}), you may encounter
5754 another breakpoint---which could have its own command list, leading to
5755 ambiguities about which list to execute.
5756
5757 @kindex silent
5758 If the first command you specify in a command list is @code{silent}, the
5759 usual message about stopping at a breakpoint is not printed. This may
5760 be desirable for breakpoints that are to print a specific message and
5761 then continue. If none of the remaining commands print anything, you
5762 see no sign that the breakpoint was reached. @code{silent} is
5763 meaningful only at the beginning of a breakpoint command list.
5764
5765 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5766 print precisely controlled output, and are often useful in silent
5767 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5768
5769 For example, here is how you could use breakpoint commands to print the
5770 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5771
5772 @smallexample
5773 break foo if x>0
5774 commands
5775 silent
5776 printf "x is %d\n",x
5777 cont
5778 end
5779 @end smallexample
5780
5781 One application for breakpoint commands is to compensate for one bug so
5782 you can test for another. Put a breakpoint just after the erroneous line
5783 of code, give it a condition to detect the case in which something
5784 erroneous has been done, and give it commands to assign correct values
5785 to any variables that need them. End with the @code{continue} command
5786 so that your program does not stop, and start with the @code{silent}
5787 command so that no output is produced. Here is an example:
5788
5789 @smallexample
5790 break 403
5791 commands
5792 silent
5793 set x = y + 4
5794 cont
5795 end
5796 @end smallexample
5797
5798 @node Dynamic Printf
5799 @subsection Dynamic Printf
5800
5801 @cindex dynamic printf
5802 @cindex dprintf
5803 The dynamic printf command @code{dprintf} combines a breakpoint with
5804 formatted printing of your program's data to give you the effect of
5805 inserting @code{printf} calls into your program on-the-fly, without
5806 having to recompile it.
5807
5808 In its most basic form, the output goes to the GDB console. However,
5809 you can set the variable @code{dprintf-style} for alternate handling.
5810 For instance, you can ask to format the output by calling your
5811 program's @code{printf} function. This has the advantage that the
5812 characters go to the program's output device, so they can recorded in
5813 redirects to files and so forth.
5814
5815 If you are doing remote debugging with a stub or agent, you can also
5816 ask to have the printf handled by the remote agent. In addition to
5817 ensuring that the output goes to the remote program's device along
5818 with any other output the program might produce, you can also ask that
5819 the dprintf remain active even after disconnecting from the remote
5820 target. Using the stub/agent is also more efficient, as it can do
5821 everything without needing to communicate with @value{GDBN}.
5822
5823 @table @code
5824 @kindex dprintf
5825 @item dprintf @var{locspec},@var{template},@var{expression}[,@var{expression}@dots{}]
5826 Whenever execution reaches a code location that results from resolving
5827 @var{locspec}, print the values of one or more @var{expressions} under
5828 the control of the string @var{template}. To print several values,
5829 separate them with commas.
5830
5831 @item set dprintf-style @var{style}
5832 Set the dprintf output to be handled in one of several different
5833 styles enumerated below. A change of style affects all existing
5834 dynamic printfs immediately. (If you need individual control over the
5835 print commands, simply define normal breakpoints with
5836 explicitly-supplied command lists.)
5837
5838 @table @code
5839 @item gdb
5840 @kindex dprintf-style gdb
5841 Handle the output using the @value{GDBN} @code{printf} command.
5842
5843 @item call
5844 @kindex dprintf-style call
5845 Handle the output by calling a function in your program (normally
5846 @code{printf}).
5847
5848 @item agent
5849 @kindex dprintf-style agent
5850 Have the remote debugging agent (such as @code{gdbserver}) handle
5851 the output itself. This style is only available for agents that
5852 support running commands on the target.
5853 @end table
5854
5855 @item set dprintf-function @var{function}
5856 Set the function to call if the dprintf style is @code{call}. By
5857 default its value is @code{printf}. You may set it to any expression.
5858 that @value{GDBN} can evaluate to a function, as per the @code{call}
5859 command.
5860
5861 @item set dprintf-channel @var{channel}
5862 Set a ``channel'' for dprintf. If set to a non-empty value,
5863 @value{GDBN} will evaluate it as an expression and pass the result as
5864 a first argument to the @code{dprintf-function}, in the manner of
5865 @code{fprintf} and similar functions. Otherwise, the dprintf format
5866 string will be the first argument, in the manner of @code{printf}.
5867
5868 As an example, if you wanted @code{dprintf} output to go to a logfile
5869 that is a standard I/O stream assigned to the variable @code{mylog},
5870 you could do the following:
5871
5872 @example
5873 (gdb) set dprintf-style call
5874 (gdb) set dprintf-function fprintf
5875 (gdb) set dprintf-channel mylog
5876 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5877 Dprintf 1 at 0x123456: file main.c, line 25.
5878 (gdb) info break
5879 1 dprintf keep y 0x00123456 in main at main.c:25
5880 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5881 continue
5882 (gdb)
5883 @end example
5884
5885 Note that the @code{info break} displays the dynamic printf commands
5886 as normal breakpoint commands; you can thus easily see the effect of
5887 the variable settings.
5888
5889 @item set disconnected-dprintf on
5890 @itemx set disconnected-dprintf off
5891 @kindex set disconnected-dprintf
5892 Choose whether @code{dprintf} commands should continue to run if
5893 @value{GDBN} has disconnected from the target. This only applies
5894 if the @code{dprintf-style} is @code{agent}.
5895
5896 @item show disconnected-dprintf off
5897 @kindex show disconnected-dprintf
5898 Show the current choice for disconnected @code{dprintf}.
5899
5900 @end table
5901
5902 @value{GDBN} does not check the validity of function and channel,
5903 relying on you to supply values that are meaningful for the contexts
5904 in which they are being used. For instance, the function and channel
5905 may be the values of local variables, but if that is the case, then
5906 all enabled dynamic prints must be at locations within the scope of
5907 those locals. If evaluation fails, @value{GDBN} will report an error.
5908
5909 @node Save Breakpoints
5910 @subsection How to save breakpoints to a file
5911
5912 To save breakpoint definitions to a file use the @w{@code{save
5913 breakpoints}} command.
5914
5915 @table @code
5916 @kindex save breakpoints
5917 @cindex save breakpoints to a file for future sessions
5918 @item save breakpoints [@var{filename}]
5919 This command saves all current breakpoint definitions together with
5920 their commands and ignore counts, into a file @file{@var{filename}}
5921 suitable for use in a later debugging session. This includes all
5922 types of breakpoints (breakpoints, watchpoints, catchpoints,
5923 tracepoints). To read the saved breakpoint definitions, use the
5924 @code{source} command (@pxref{Command Files}). Note that watchpoints
5925 with expressions involving local variables may fail to be recreated
5926 because it may not be possible to access the context where the
5927 watchpoint is valid anymore. Because the saved breakpoint definitions
5928 are simply a sequence of @value{GDBN} commands that recreate the
5929 breakpoints, you can edit the file in your favorite editing program,
5930 and remove the breakpoint definitions you're not interested in, or
5931 that can no longer be recreated.
5932 @end table
5933
5934 @node Static Probe Points
5935 @subsection Static Probe Points
5936
5937 @cindex static probe point, SystemTap
5938 @cindex static probe point, DTrace
5939 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5940 for Statically Defined Tracing, and the probes are designed to have a tiny
5941 runtime code and data footprint, and no dynamic relocations.
5942
5943 Currently, the following types of probes are supported on
5944 ELF-compatible systems:
5945
5946 @itemize @bullet
5947
5948 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5949 @acronym{SDT} probes@footnote{See
5950 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5951 for more information on how to add @code{SystemTap} @acronym{SDT}
5952 probes in your applications.}. @code{SystemTap} probes are usable
5953 from assembly, C and C@t{++} languages@footnote{See
5954 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5955 for a good reference on how the @acronym{SDT} probes are implemented.}.
5956
5957 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5958 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5959 C@t{++} languages.
5960 @end itemize
5961
5962 @cindex semaphores on static probe points
5963 Some @code{SystemTap} probes have an associated semaphore variable;
5964 for instance, this happens automatically if you defined your probe
5965 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5966 @value{GDBN} will automatically enable it when you specify a
5967 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5968 breakpoint at a probe's location by some other method (e.g.,
5969 @code{break file:line}), then @value{GDBN} will not automatically set
5970 the semaphore. @code{DTrace} probes do not support semaphores.
5971
5972 You can examine the available static static probes using @code{info
5973 probes}, with optional arguments:
5974
5975 @table @code
5976 @kindex info probes
5977 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5978 If given, @var{type} is either @code{stap} for listing
5979 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5980 probes. If omitted all probes are listed regardless of their types.
5981
5982 If given, @var{provider} is a regular expression used to match against provider
5983 names when selecting which probes to list. If omitted, probes by all
5984 probes from all providers are listed.
5985
5986 If given, @var{name} is a regular expression to match against probe names
5987 when selecting which probes to list. If omitted, probe names are not
5988 considered when deciding whether to display them.
5989
5990 If given, @var{objfile} is a regular expression used to select which
5991 object files (executable or shared libraries) to examine. If not
5992 given, all object files are considered.
5993
5994 @item info probes all
5995 List the available static probes, from all types.
5996 @end table
5997
5998 @cindex enabling and disabling probes
5999 Some probe points can be enabled and/or disabled. The effect of
6000 enabling or disabling a probe depends on the type of probe being
6001 handled. Some @code{DTrace} probes can be enabled or
6002 disabled, but @code{SystemTap} probes cannot be disabled.
6003
6004 You can enable (or disable) one or more probes using the following
6005 commands, with optional arguments:
6006
6007 @table @code
6008 @kindex enable probes
6009 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6010 If given, @var{provider} is a regular expression used to match against
6011 provider names when selecting which probes to enable. If omitted,
6012 all probes from all providers are enabled.
6013
6014 If given, @var{name} is a regular expression to match against probe
6015 names when selecting which probes to enable. If omitted, probe names
6016 are not considered when deciding whether to enable them.
6017
6018 If given, @var{objfile} is a regular expression used to select which
6019 object files (executable or shared libraries) to examine. If not
6020 given, all object files are considered.
6021
6022 @kindex disable probes
6023 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6024 See the @code{enable probes} command above for a description of the
6025 optional arguments accepted by this command.
6026 @end table
6027
6028 @vindex $_probe_arg@r{, convenience variable}
6029 A probe may specify up to twelve arguments. These are available at the
6030 point at which the probe is defined---that is, when the current PC is
6031 at the probe's location. The arguments are available using the
6032 convenience variables (@pxref{Convenience Vars})
6033 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
6034 probes each probe argument is an integer of the appropriate size;
6035 types are not preserved. In @code{DTrace} probes types are preserved
6036 provided that they are recognized as such by @value{GDBN}; otherwise
6037 the value of the probe argument will be a long integer. The
6038 convenience variable @code{$_probe_argc} holds the number of arguments
6039 at the current probe point.
6040
6041 These variables are always available, but attempts to access them at
6042 any location other than a probe point will cause @value{GDBN} to give
6043 an error message.
6044
6045
6046 @c @ifclear BARETARGET
6047 @node Error in Breakpoints
6048 @subsection ``Cannot insert breakpoints''
6049
6050 If you request too many active hardware-assisted breakpoints and
6051 watchpoints, you will see this error message:
6052
6053 @c FIXME: the precise wording of this message may change; the relevant
6054 @c source change is not committed yet (Sep 3, 1999).
6055 @smallexample
6056 Stopped; cannot insert breakpoints.
6057 You may have requested too many hardware breakpoints and watchpoints.
6058 @end smallexample
6059
6060 @noindent
6061 This message is printed when you attempt to resume the program, since
6062 only then @value{GDBN} knows exactly how many hardware breakpoints and
6063 watchpoints it needs to insert.
6064
6065 When this message is printed, you need to disable or remove some of the
6066 hardware-assisted breakpoints and watchpoints, and then continue.
6067
6068 @node Breakpoint-related Warnings
6069 @subsection ``Breakpoint address adjusted...''
6070 @cindex breakpoint address adjusted
6071
6072 Some processor architectures place constraints on the addresses at
6073 which breakpoints may be placed. For architectures thus constrained,
6074 @value{GDBN} will attempt to adjust the breakpoint's address to comply
6075 with the constraints dictated by the architecture.
6076
6077 One example of such an architecture is the Fujitsu FR-V. The FR-V is
6078 a VLIW architecture in which a number of RISC-like instructions may be
6079 bundled together for parallel execution. The FR-V architecture
6080 constrains the location of a breakpoint instruction within such a
6081 bundle to the instruction with the lowest address. @value{GDBN}
6082 honors this constraint by adjusting a breakpoint's address to the
6083 first in the bundle.
6084
6085 It is not uncommon for optimized code to have bundles which contain
6086 instructions from different source statements, thus it may happen that
6087 a breakpoint's address will be adjusted from one source statement to
6088 another. Since this adjustment may significantly alter @value{GDBN}'s
6089 breakpoint related behavior from what the user expects, a warning is
6090 printed when the breakpoint is first set and also when the breakpoint
6091 is hit.
6092
6093 A warning like the one below is printed when setting a breakpoint
6094 that's been subject to address adjustment:
6095
6096 @smallexample
6097 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6098 @end smallexample
6099
6100 Such warnings are printed both for user settable and @value{GDBN}'s
6101 internal breakpoints. If you see one of these warnings, you should
6102 verify that a breakpoint set at the adjusted address will have the
6103 desired affect. If not, the breakpoint in question may be removed and
6104 other breakpoints may be set which will have the desired behavior.
6105 E.g., it may be sufficient to place the breakpoint at a later
6106 instruction. A conditional breakpoint may also be useful in some
6107 cases to prevent the breakpoint from triggering too often.
6108
6109 @value{GDBN} will also issue a warning when stopping at one of these
6110 adjusted breakpoints:
6111
6112 @smallexample
6113 warning: Breakpoint 1 address previously adjusted from 0x00010414
6114 to 0x00010410.
6115 @end smallexample
6116
6117 When this warning is encountered, it may be too late to take remedial
6118 action except in cases where the breakpoint is hit earlier or more
6119 frequently than expected.
6120
6121 @node Continuing and Stepping
6122 @section Continuing and Stepping
6123
6124 @cindex stepping
6125 @cindex continuing
6126 @cindex resuming execution
6127 @dfn{Continuing} means resuming program execution until your program
6128 completes normally. In contrast, @dfn{stepping} means executing just
6129 one more ``step'' of your program, where ``step'' may mean either one
6130 line of source code, or one machine instruction (depending on what
6131 particular command you use). Either when continuing or when stepping,
6132 your program may stop even sooner, due to a breakpoint or a signal. (If
6133 it stops due to a signal, you may want to use @code{handle}, or use
6134 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6135 or you may step into the signal's handler (@pxref{stepping and signal
6136 handlers}).)
6137
6138 @table @code
6139 @kindex continue
6140 @kindex c @r{(@code{continue})}
6141 @kindex fg @r{(resume foreground execution)}
6142 @item continue @r{[}@var{ignore-count}@r{]}
6143 @itemx c @r{[}@var{ignore-count}@r{]}
6144 @itemx fg @r{[}@var{ignore-count}@r{]}
6145 Resume program execution, at the address where your program last stopped;
6146 any breakpoints set at that address are bypassed. The optional argument
6147 @var{ignore-count} allows you to specify a further number of times to
6148 ignore a breakpoint at this location; its effect is like that of
6149 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6150
6151 The argument @var{ignore-count} is meaningful only when your program
6152 stopped due to a breakpoint. At other times, the argument to
6153 @code{continue} is ignored.
6154
6155 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6156 debugged program is deemed to be the foreground program) are provided
6157 purely for convenience, and have exactly the same behavior as
6158 @code{continue}.
6159 @end table
6160
6161 To resume execution at a different place, you can use @code{return}
6162 (@pxref{Returning, ,Returning from a Function}) to go back to the
6163 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6164 Different Address}) to go to an arbitrary location in your program.
6165
6166 A typical technique for using stepping is to set a breakpoint
6167 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6168 beginning of the function or the section of your program where a problem
6169 is believed to lie, run your program until it stops at that breakpoint,
6170 and then step through the suspect area, examining the variables that are
6171 interesting, until you see the problem happen.
6172
6173 @table @code
6174 @kindex step
6175 @kindex s @r{(@code{step})}
6176 @item step
6177 Continue running your program until control reaches a different source
6178 line, then stop it and return control to @value{GDBN}. This command is
6179 abbreviated @code{s}.
6180
6181 @quotation
6182 @c "without debugging information" is imprecise; actually "without line
6183 @c numbers in the debugging information". (gcc -g1 has debugging info but
6184 @c not line numbers). But it seems complex to try to make that
6185 @c distinction here.
6186 @emph{Warning:} If you use the @code{step} command while control is
6187 within a function that was compiled without debugging information,
6188 execution proceeds until control reaches a function that does have
6189 debugging information. Likewise, it will not step into a function which
6190 is compiled without debugging information. To step through functions
6191 without debugging information, use the @code{stepi} command, described
6192 below.
6193 @end quotation
6194
6195 The @code{step} command only stops at the first instruction of a source
6196 line. This prevents the multiple stops that could otherwise occur in
6197 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6198 to stop if a function that has debugging information is called within
6199 the line. In other words, @code{step} @emph{steps inside} any functions
6200 called within the line.
6201
6202 Also, the @code{step} command only enters a function if there is line
6203 number information for the function. Otherwise it acts like the
6204 @code{next} command. This avoids problems when using @code{cc -gl}
6205 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6206 was any debugging information about the routine.
6207
6208 @item step @var{count}
6209 Continue running as in @code{step}, but do so @var{count} times. If a
6210 breakpoint is reached, or a signal not related to stepping occurs before
6211 @var{count} steps, stepping stops right away.
6212
6213 @kindex next
6214 @kindex n @r{(@code{next})}
6215 @item next @r{[}@var{count}@r{]}
6216 Continue to the next source line in the current (innermost) stack frame.
6217 This is similar to @code{step}, but function calls that appear within
6218 the line of code are executed without stopping. Execution stops when
6219 control reaches a different line of code at the original stack level
6220 that was executing when you gave the @code{next} command. This command
6221 is abbreviated @code{n}.
6222
6223 An argument @var{count} is a repeat count, as for @code{step}.
6224
6225
6226 @c FIX ME!! Do we delete this, or is there a way it fits in with
6227 @c the following paragraph? --- Vctoria
6228 @c
6229 @c @code{next} within a function that lacks debugging information acts like
6230 @c @code{step}, but any function calls appearing within the code of the
6231 @c function are executed without stopping.
6232
6233 The @code{next} command only stops at the first instruction of a
6234 source line. This prevents multiple stops that could otherwise occur in
6235 @code{switch} statements, @code{for} loops, etc.
6236
6237 @kindex set step-mode
6238 @item set step-mode
6239 @cindex functions without line info, and stepping
6240 @cindex stepping into functions with no line info
6241 @itemx set step-mode on
6242 The @code{set step-mode on} command causes the @code{step} command to
6243 stop at the first instruction of a function which contains no debug line
6244 information rather than stepping over it.
6245
6246 This is useful in cases where you may be interested in inspecting the
6247 machine instructions of a function which has no symbolic info and do not
6248 want @value{GDBN} to automatically skip over this function.
6249
6250 @item set step-mode off
6251 Causes the @code{step} command to step over any functions which contains no
6252 debug information. This is the default.
6253
6254 @item show step-mode
6255 Show whether @value{GDBN} will stop in or step over functions without
6256 source line debug information.
6257
6258 @kindex finish
6259 @kindex fin @r{(@code{finish})}
6260 @item finish
6261 Continue running until just after function in the selected stack frame
6262 returns. Print the returned value (if any). This command can be
6263 abbreviated as @code{fin}.
6264
6265 Contrast this with the @code{return} command (@pxref{Returning,
6266 ,Returning from a Function}).
6267
6268 @kindex set print finish
6269 @kindex show print finish
6270 @item set print finish @r{[}on|off@r{]}
6271 @itemx show print finish
6272 By default the @code{finish} command will show the value that is
6273 returned by the function. This can be disabled using @code{set print
6274 finish off}. When disabled, the value is still entered into the value
6275 history (@pxref{Value History}), but not displayed.
6276
6277 @kindex until
6278 @kindex u @r{(@code{until})}
6279 @cindex run until specified location
6280 @item until
6281 @itemx u
6282 Continue running until a source line past the current line, in the
6283 current stack frame, is reached. This command is used to avoid single
6284 stepping through a loop more than once. It is like the @code{next}
6285 command, except that when @code{until} encounters a jump, it
6286 automatically continues execution until the program counter is greater
6287 than the address of the jump.
6288
6289 This means that when you reach the end of a loop after single stepping
6290 though it, @code{until} makes your program continue execution until it
6291 exits the loop. In contrast, a @code{next} command at the end of a loop
6292 simply steps back to the beginning of the loop, which forces you to step
6293 through the next iteration.
6294
6295 @code{until} always stops your program if it attempts to exit the current
6296 stack frame.
6297
6298 @code{until} may produce somewhat counterintuitive results if the order
6299 of machine code does not match the order of the source lines. For
6300 example, in the following excerpt from a debugging session, the @code{f}
6301 (@code{frame}) command shows that execution is stopped at line
6302 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6303
6304 @smallexample
6305 (@value{GDBP}) f
6306 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6307 206 expand_input();
6308 (@value{GDBP}) until
6309 195 for ( ; argc > 0; NEXTARG) @{
6310 @end smallexample
6311
6312 This happened because, for execution efficiency, the compiler had
6313 generated code for the loop closure test at the end, rather than the
6314 start, of the loop---even though the test in a C @code{for}-loop is
6315 written before the body of the loop. The @code{until} command appeared
6316 to step back to the beginning of the loop when it advanced to this
6317 expression; however, it has not really gone to an earlier
6318 statement---not in terms of the actual machine code.
6319
6320 @code{until} with no argument works by means of single
6321 instruction stepping, and hence is slower than @code{until} with an
6322 argument.
6323
6324 @item until @var{locspec}
6325 @itemx u @var{locspec}
6326 Continue running your program until either it reaches a code location
6327 that results from resolving @var{locspec}, or the current stack frame
6328 returns. @var{locspec} is any of the forms described in @ref{Location
6329 Specifications}.
6330 This form of the command uses temporary breakpoints, and
6331 hence is quicker than @code{until} without an argument. The specified
6332 location is actually reached only if it is in the current frame. This
6333 implies that @code{until} can be used to skip over recursive function
6334 invocations. For instance in the code below, if the current location is
6335 line @code{96}, issuing @code{until 99} will execute the program up to
6336 line @code{99} in the same invocation of factorial, i.e., after the inner
6337 invocations have returned.
6338
6339 @smallexample
6340 94 int factorial (int value)
6341 95 @{
6342 96 if (value > 1) @{
6343 97 value *= factorial (value - 1);
6344 98 @}
6345 99 return (value);
6346 100 @}
6347 @end smallexample
6348
6349
6350 @kindex advance @var{locspec}
6351 @item advance @var{locspec}
6352 Continue running your program until either it reaches a code location
6353 that results from resolving @var{locspec}, or the current stack frame
6354 returns. @var{locspec} is any of the forms described in @ref{Location
6355 Specifications}. This command is similar to @code{until}, but
6356 @code{advance} will not skip over recursive function calls, and the
6357 target code location doesn't have to be in the same frame as the
6358 current one.
6359
6360
6361 @kindex stepi
6362 @kindex si @r{(@code{stepi})}
6363 @item stepi
6364 @itemx stepi @var{arg}
6365 @itemx si
6366 Execute one machine instruction, then stop and return to the debugger.
6367
6368 It is often useful to do @samp{display/i $pc} when stepping by machine
6369 instructions. This makes @value{GDBN} automatically display the next
6370 instruction to be executed, each time your program stops. @xref{Auto
6371 Display,, Automatic Display}.
6372
6373 An argument is a repeat count, as in @code{step}.
6374
6375 @need 750
6376 @kindex nexti
6377 @kindex ni @r{(@code{nexti})}
6378 @item nexti
6379 @itemx nexti @var{arg}
6380 @itemx ni
6381 Execute one machine instruction, but if it is a function call,
6382 proceed until the function returns.
6383
6384 An argument is a repeat count, as in @code{next}.
6385
6386 @end table
6387
6388 @anchor{range stepping}
6389 @cindex range stepping
6390 @cindex target-assisted range stepping
6391 By default, and if available, @value{GDBN} makes use of
6392 target-assisted @dfn{range stepping}. In other words, whenever you
6393 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6394 tells the target to step the corresponding range of instruction
6395 addresses instead of issuing multiple single-steps. This speeds up
6396 line stepping, particularly for remote targets. Ideally, there should
6397 be no reason you would want to turn range stepping off. However, it's
6398 possible that a bug in the debug info, a bug in the remote stub (for
6399 remote targets), or even a bug in @value{GDBN} could make line
6400 stepping behave incorrectly when target-assisted range stepping is
6401 enabled. You can use the following command to turn off range stepping
6402 if necessary:
6403
6404 @table @code
6405 @kindex set range-stepping
6406 @kindex show range-stepping
6407 @item set range-stepping
6408 @itemx show range-stepping
6409 Control whether range stepping is enabled.
6410
6411 If @code{on}, and the target supports it, @value{GDBN} tells the
6412 target to step a range of addresses itself, instead of issuing
6413 multiple single-steps. If @code{off}, @value{GDBN} always issues
6414 single-steps, even if range stepping is supported by the target. The
6415 default is @code{on}.
6416
6417 @end table
6418
6419 @node Skipping Over Functions and Files
6420 @section Skipping Over Functions and Files
6421 @cindex skipping over functions and files
6422
6423 The program you are debugging may contain some functions which are
6424 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6425 skip a function, all functions in a file or a particular function in
6426 a particular file when stepping.
6427
6428 For example, consider the following C function:
6429
6430 @smallexample
6431 101 int func()
6432 102 @{
6433 103 foo(boring());
6434 104 bar(boring());
6435 105 @}
6436 @end smallexample
6437
6438 @noindent
6439 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6440 are not interested in stepping through @code{boring}. If you run @code{step}
6441 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6442 step over both @code{foo} and @code{boring}!
6443
6444 One solution is to @code{step} into @code{boring} and use the @code{finish}
6445 command to immediately exit it. But this can become tedious if @code{boring}
6446 is called from many places.
6447
6448 A more flexible solution is to execute @kbd{skip boring}. This instructs
6449 @value{GDBN} never to step into @code{boring}. Now when you execute
6450 @code{step} at line 103, you'll step over @code{boring} and directly into
6451 @code{foo}.
6452
6453 Functions may be skipped by providing either a function name, linespec
6454 (@pxref{Location Specifications}), regular expression that matches the function's
6455 name, file name or a @code{glob}-style pattern that matches the file name.
6456
6457 On Posix systems the form of the regular expression is
6458 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6459 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6460 expression is whatever is provided by the @code{regcomp} function of
6461 the underlying system.
6462 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6463 description of @code{glob}-style patterns.
6464
6465 @table @code
6466 @kindex skip
6467 @item skip @r{[}@var{options}@r{]}
6468 The basic form of the @code{skip} command takes zero or more options
6469 that specify what to skip.
6470 The @var{options} argument is any useful combination of the following:
6471
6472 @table @code
6473 @item -file @var{file}
6474 @itemx -fi @var{file}
6475 Functions in @var{file} will be skipped over when stepping.
6476
6477 @item -gfile @var{file-glob-pattern}
6478 @itemx -gfi @var{file-glob-pattern}
6479 @cindex skipping over files via glob-style patterns
6480 Functions in files matching @var{file-glob-pattern} will be skipped
6481 over when stepping.
6482
6483 @smallexample
6484 (gdb) skip -gfi utils/*.c
6485 @end smallexample
6486
6487 @item -function @var{linespec}
6488 @itemx -fu @var{linespec}
6489 Functions named by @var{linespec} or the function containing the line
6490 named by @var{linespec} will be skipped over when stepping.
6491 @xref{Location Specifications}.
6492
6493 @item -rfunction @var{regexp}
6494 @itemx -rfu @var{regexp}
6495 @cindex skipping over functions via regular expressions
6496 Functions whose name matches @var{regexp} will be skipped over when stepping.
6497
6498 This form is useful for complex function names.
6499 For example, there is generally no need to step into C@t{++} @code{std::string}
6500 constructors or destructors. Plus with C@t{++} templates it can be hard to
6501 write out the full name of the function, and often it doesn't matter what
6502 the template arguments are. Specifying the function to be skipped as a
6503 regular expression makes this easier.
6504
6505 @smallexample
6506 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6507 @end smallexample
6508
6509 If you want to skip every templated C@t{++} constructor and destructor
6510 in the @code{std} namespace you can do:
6511
6512 @smallexample
6513 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6514 @end smallexample
6515 @end table
6516
6517 If no options are specified, the function you're currently debugging
6518 will be skipped.
6519
6520 @kindex skip function
6521 @item skip function @r{[}@var{linespec}@r{]}
6522 After running this command, the function named by @var{linespec} or the
6523 function containing the line named by @var{linespec} will be skipped over when
6524 stepping. @xref{Location Specifications}.
6525
6526 If you do not specify @var{linespec}, the function you're currently debugging
6527 will be skipped.
6528
6529 (If you have a function called @code{file} that you want to skip, use
6530 @kbd{skip function file}.)
6531
6532 @kindex skip file
6533 @item skip file @r{[}@var{filename}@r{]}
6534 After running this command, any function whose source lives in @var{filename}
6535 will be skipped over when stepping.
6536
6537 @smallexample
6538 (gdb) skip file boring.c
6539 File boring.c will be skipped when stepping.
6540 @end smallexample
6541
6542 If you do not specify @var{filename}, functions whose source lives in the file
6543 you're currently debugging will be skipped.
6544 @end table
6545
6546 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6547 These are the commands for managing your list of skips:
6548
6549 @table @code
6550 @kindex info skip
6551 @item info skip @r{[}@var{range}@r{]}
6552 Print details about the specified skip(s). If @var{range} is not specified,
6553 print a table with details about all functions and files marked for skipping.
6554 @code{info skip} prints the following information about each skip:
6555
6556 @table @emph
6557 @item Identifier
6558 A number identifying this skip.
6559 @item Enabled or Disabled
6560 Enabled skips are marked with @samp{y}.
6561 Disabled skips are marked with @samp{n}.
6562 @item Glob
6563 If the file name is a @samp{glob} pattern this is @samp{y}.
6564 Otherwise it is @samp{n}.
6565 @item File
6566 The name or @samp{glob} pattern of the file to be skipped.
6567 If no file is specified this is @samp{<none>}.
6568 @item RE
6569 If the function name is a @samp{regular expression} this is @samp{y}.
6570 Otherwise it is @samp{n}.
6571 @item Function
6572 The name or regular expression of the function to skip.
6573 If no function is specified this is @samp{<none>}.
6574 @end table
6575
6576 @kindex skip delete
6577 @item skip delete @r{[}@var{range}@r{]}
6578 Delete the specified skip(s). If @var{range} is not specified, delete all
6579 skips.
6580
6581 @kindex skip enable
6582 @item skip enable @r{[}@var{range}@r{]}
6583 Enable the specified skip(s). If @var{range} is not specified, enable all
6584 skips.
6585
6586 @kindex skip disable
6587 @item skip disable @r{[}@var{range}@r{]}
6588 Disable the specified skip(s). If @var{range} is not specified, disable all
6589 skips.
6590
6591 @kindex set debug skip
6592 @item set debug skip @r{[}on|off@r{]}
6593 Set whether to print the debug output about skipping files and functions.
6594
6595 @kindex show debug skip
6596 @item show debug skip
6597 Show whether the debug output about skipping files and functions is printed.
6598
6599 @end table
6600
6601 @node Signals
6602 @section Signals
6603 @cindex signals
6604
6605 A signal is an asynchronous event that can happen in a program. The
6606 operating system defines the possible kinds of signals, and gives each
6607 kind a name and a number. For example, in Unix @code{SIGINT} is the
6608 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6609 @code{SIGSEGV} is the signal a program gets from referencing a place in
6610 memory far away from all the areas in use; @code{SIGALRM} occurs when
6611 the alarm clock timer goes off (which happens only if your program has
6612 requested an alarm).
6613
6614 @cindex fatal signals
6615 Some signals, including @code{SIGALRM}, are a normal part of the
6616 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6617 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6618 program has not specified in advance some other way to handle the signal.
6619 @code{SIGINT} does not indicate an error in your program, but it is normally
6620 fatal so it can carry out the purpose of the interrupt: to kill the program.
6621
6622 @value{GDBN} has the ability to detect any occurrence of a signal in your
6623 program. You can tell @value{GDBN} in advance what to do for each kind of
6624 signal.
6625
6626 @cindex handling signals
6627 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6628 @code{SIGALRM} be silently passed to your program
6629 (so as not to interfere with their role in the program's functioning)
6630 but to stop your program immediately whenever an error signal happens.
6631 You can change these settings with the @code{handle} command.
6632
6633 @table @code
6634 @kindex info signals
6635 @kindex info handle
6636 @item info signals
6637 @itemx info handle
6638 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6639 handle each one. You can use this to see the signal numbers of all
6640 the defined types of signals.
6641
6642 @item info signals @var{sig}
6643 Similar, but print information only about the specified signal number.
6644
6645 @code{info handle} is an alias for @code{info signals}.
6646
6647 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6648 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6649 for details about this command.
6650
6651 @kindex handle
6652 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6653 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6654 can be the number of a signal or its name (with or without the
6655 @samp{SIG} at the beginning); a list of signal numbers of the form
6656 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6657 known signals. Optional arguments @var{keywords}, described below,
6658 say what change to make.
6659 @end table
6660
6661 @c @group
6662 The keywords allowed by the @code{handle} command can be abbreviated.
6663 Their full names are:
6664
6665 @table @code
6666 @item nostop
6667 @value{GDBN} should not stop your program when this signal happens. It may
6668 still print a message telling you that the signal has come in.
6669
6670 @item stop
6671 @value{GDBN} should stop your program when this signal happens. This implies
6672 the @code{print} keyword as well.
6673
6674 @item print
6675 @value{GDBN} should print a message when this signal happens.
6676
6677 @item noprint
6678 @value{GDBN} should not mention the occurrence of the signal at all. This
6679 implies the @code{nostop} keyword as well.
6680
6681 @item pass
6682 @itemx noignore
6683 @value{GDBN} should allow your program to see this signal; your program
6684 can handle the signal, or else it may terminate if the signal is fatal
6685 and not handled. @code{pass} and @code{noignore} are synonyms.
6686
6687 @item nopass
6688 @itemx ignore
6689 @value{GDBN} should not allow your program to see this signal.
6690 @code{nopass} and @code{ignore} are synonyms.
6691 @end table
6692 @c @end group
6693
6694 When a signal stops your program, the signal is not visible to the
6695 program until you
6696 continue. Your program sees the signal then, if @code{pass} is in
6697 effect for the signal in question @emph{at that time}. In other words,
6698 after @value{GDBN} reports a signal, you can use the @code{handle}
6699 command with @code{pass} or @code{nopass} to control whether your
6700 program sees that signal when you continue.
6701
6702 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6703 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6704 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6705 erroneous signals.
6706
6707 You can also use the @code{signal} command to prevent your program from
6708 seeing a signal, or cause it to see a signal it normally would not see,
6709 or to give it any signal at any time. For example, if your program stopped
6710 due to some sort of memory reference error, you might store correct
6711 values into the erroneous variables and continue, hoping to see more
6712 execution; but your program would probably terminate immediately as
6713 a result of the fatal signal once it saw the signal. To prevent this,
6714 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6715 Program a Signal}.
6716
6717 @cindex stepping and signal handlers
6718 @anchor{stepping and signal handlers}
6719
6720 @value{GDBN} optimizes for stepping the mainline code. If a signal
6721 that has @code{handle nostop} and @code{handle pass} set arrives while
6722 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6723 in progress, @value{GDBN} lets the signal handler run and then resumes
6724 stepping the mainline code once the signal handler returns. In other
6725 words, @value{GDBN} steps over the signal handler. This prevents
6726 signals that you've specified as not interesting (with @code{handle
6727 nostop}) from changing the focus of debugging unexpectedly. Note that
6728 the signal handler itself may still hit a breakpoint, stop for another
6729 signal that has @code{handle stop} in effect, or for any other event
6730 that normally results in stopping the stepping command sooner. Also
6731 note that @value{GDBN} still informs you that the program received a
6732 signal if @code{handle print} is set.
6733
6734 @anchor{stepping into signal handlers}
6735
6736 If you set @code{handle pass} for a signal, and your program sets up a
6737 handler for it, then issuing a stepping command, such as @code{step}
6738 or @code{stepi}, when your program is stopped due to the signal will
6739 step @emph{into} the signal handler (if the target supports that).
6740
6741 Likewise, if you use the @code{queue-signal} command to queue a signal
6742 to be delivered to the current thread when execution of the thread
6743 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6744 stepping command will step into the signal handler.
6745
6746 Here's an example, using @code{stepi} to step to the first instruction
6747 of @code{SIGUSR1}'s handler:
6748
6749 @smallexample
6750 (@value{GDBP}) handle SIGUSR1
6751 Signal Stop Print Pass to program Description
6752 SIGUSR1 Yes Yes Yes User defined signal 1
6753 (@value{GDBP}) c
6754 Continuing.
6755
6756 Program received signal SIGUSR1, User defined signal 1.
6757 main () sigusr1.c:28
6758 28 p = 0;
6759 (@value{GDBP}) si
6760 sigusr1_handler () at sigusr1.c:9
6761 9 @{
6762 @end smallexample
6763
6764 The same, but using @code{queue-signal} instead of waiting for the
6765 program to receive the signal first:
6766
6767 @smallexample
6768 (@value{GDBP}) n
6769 28 p = 0;
6770 (@value{GDBP}) queue-signal SIGUSR1
6771 (@value{GDBP}) si
6772 sigusr1_handler () at sigusr1.c:9
6773 9 @{
6774 (@value{GDBP})
6775 @end smallexample
6776
6777 @cindex extra signal information
6778 @anchor{extra signal information}
6779
6780 On some targets, @value{GDBN} can inspect extra signal information
6781 associated with the intercepted signal, before it is actually
6782 delivered to the program being debugged. This information is exported
6783 by the convenience variable @code{$_siginfo}, and consists of data
6784 that is passed by the kernel to the signal handler at the time of the
6785 receipt of a signal. The data type of the information itself is
6786 target dependent. You can see the data type using the @code{ptype
6787 $_siginfo} command. On Unix systems, it typically corresponds to the
6788 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6789 system header.
6790
6791 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6792 referenced address that raised a segmentation fault.
6793
6794 @smallexample
6795 @group
6796 (@value{GDBP}) continue
6797 Program received signal SIGSEGV, Segmentation fault.
6798 0x0000000000400766 in main ()
6799 69 *(int *)p = 0;
6800 (@value{GDBP}) ptype $_siginfo
6801 type = struct @{
6802 int si_signo;
6803 int si_errno;
6804 int si_code;
6805 union @{
6806 int _pad[28];
6807 struct @{...@} _kill;
6808 struct @{...@} _timer;
6809 struct @{...@} _rt;
6810 struct @{...@} _sigchld;
6811 struct @{...@} _sigfault;
6812 struct @{...@} _sigpoll;
6813 @} _sifields;
6814 @}
6815 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6816 type = struct @{
6817 void *si_addr;
6818 @}
6819 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6820 $1 = (void *) 0x7ffff7ff7000
6821 @end group
6822 @end smallexample
6823
6824 Depending on target support, @code{$_siginfo} may also be writable.
6825
6826 @cindex Intel MPX boundary violations
6827 @cindex boundary violations, Intel MPX
6828 On some targets, a @code{SIGSEGV} can be caused by a boundary
6829 violation, i.e., accessing an address outside of the allowed range.
6830 In those cases @value{GDBN} may displays additional information,
6831 depending on how @value{GDBN} has been told to handle the signal.
6832 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6833 kind: "Upper" or "Lower", the memory address accessed and the
6834 bounds, while with @code{handle nostop SIGSEGV} no additional
6835 information is displayed.
6836
6837 The usual output of a segfault is:
6838 @smallexample
6839 Program received signal SIGSEGV, Segmentation fault
6840 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6841 68 value = *(p + len);
6842 @end smallexample
6843
6844 While a bound violation is presented as:
6845 @smallexample
6846 Program received signal SIGSEGV, Segmentation fault
6847 Upper bound violation while accessing address 0x7fffffffc3b3
6848 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6849 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6850 68 value = *(p + len);
6851 @end smallexample
6852
6853 @node Thread Stops
6854 @section Stopping and Starting Multi-thread Programs
6855
6856 @cindex stopped threads
6857 @cindex threads, stopped
6858
6859 @cindex continuing threads
6860 @cindex threads, continuing
6861
6862 @value{GDBN} supports debugging programs with multiple threads
6863 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6864 are two modes of controlling execution of your program within the
6865 debugger. In the default mode, referred to as @dfn{all-stop mode},
6866 when any thread in your program stops (for example, at a breakpoint
6867 or while being stepped), all other threads in the program are also stopped by
6868 @value{GDBN}. On some targets, @value{GDBN} also supports
6869 @dfn{non-stop mode}, in which other threads can continue to run freely while
6870 you examine the stopped thread in the debugger.
6871
6872 @menu
6873 * All-Stop Mode:: All threads stop when GDB takes control
6874 * Non-Stop Mode:: Other threads continue to execute
6875 * Background Execution:: Running your program asynchronously
6876 * Thread-Specific Breakpoints:: Controlling breakpoints
6877 * Interrupted System Calls:: GDB may interfere with system calls
6878 * Observer Mode:: GDB does not alter program behavior
6879 @end menu
6880
6881 @node All-Stop Mode
6882 @subsection All-Stop Mode
6883
6884 @cindex all-stop mode
6885
6886 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6887 @emph{all} threads of execution stop, not just the current thread. This
6888 allows you to examine the overall state of the program, including
6889 switching between threads, without worrying that things may change
6890 underfoot.
6891
6892 Conversely, whenever you restart the program, @emph{all} threads start
6893 executing. @emph{This is true even when single-stepping} with commands
6894 like @code{step} or @code{next}.
6895
6896 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6897 Since thread scheduling is up to your debugging target's operating
6898 system (not controlled by @value{GDBN}), other threads may
6899 execute more than one statement while the current thread completes a
6900 single step. Moreover, in general other threads stop in the middle of a
6901 statement, rather than at a clean statement boundary, when the program
6902 stops.
6903
6904 You might even find your program stopped in another thread after
6905 continuing or even single-stepping. This happens whenever some other
6906 thread runs into a breakpoint, a signal, or an exception before the
6907 first thread completes whatever you requested.
6908
6909 @cindex automatic thread selection
6910 @cindex switching threads automatically
6911 @cindex threads, automatic switching
6912 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6913 signal, it automatically selects the thread where that breakpoint or
6914 signal happened. @value{GDBN} alerts you to the context switch with a
6915 message such as @samp{[Switching to Thread @var{n}]} to identify the
6916 thread.
6917
6918 On some OSes, you can modify @value{GDBN}'s default behavior by
6919 locking the OS scheduler to allow only a single thread to run.
6920
6921 @table @code
6922 @item set scheduler-locking @var{mode}
6923 @cindex scheduler locking mode
6924 @cindex lock scheduler
6925 Set the scheduler locking mode. It applies to normal execution,
6926 record mode, and replay mode. If it is @code{off}, then there is no
6927 locking and any thread may run at any time. If @code{on}, then only
6928 the current thread may run when the inferior is resumed. The
6929 @code{step} mode optimizes for single-stepping; it prevents other
6930 threads from preempting the current thread while you are stepping, so
6931 that the focus of debugging does not change unexpectedly. Other
6932 threads never get a chance to run when you step, and they are
6933 completely free to run when you use commands like @samp{continue},
6934 @samp{until}, or @samp{finish}. However, unless another thread hits a
6935 breakpoint during its timeslice, @value{GDBN} does not change the
6936 current thread away from the thread that you are debugging. The
6937 @code{replay} mode behaves like @code{off} in record mode and like
6938 @code{on} in replay mode.
6939
6940 @item show scheduler-locking
6941 Display the current scheduler locking mode.
6942 @end table
6943
6944 @cindex resume threads of multiple processes simultaneously
6945 By default, when you issue one of the execution commands such as
6946 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6947 threads of the current inferior to run. For example, if @value{GDBN}
6948 is attached to two inferiors, each with two threads, the
6949 @code{continue} command resumes only the two threads of the current
6950 inferior. This is useful, for example, when you debug a program that
6951 forks and you want to hold the parent stopped (so that, for instance,
6952 it doesn't run to exit), while you debug the child. In other
6953 situations, you may not be interested in inspecting the current state
6954 of any of the processes @value{GDBN} is attached to, and you may want
6955 to resume them all until some breakpoint is hit. In the latter case,
6956 you can instruct @value{GDBN} to allow all threads of all the
6957 inferiors to run with the @w{@code{set schedule-multiple}} command.
6958
6959 @table @code
6960 @kindex set schedule-multiple
6961 @item set schedule-multiple
6962 Set the mode for allowing threads of multiple processes to be resumed
6963 when an execution command is issued. When @code{on}, all threads of
6964 all processes are allowed to run. When @code{off}, only the threads
6965 of the current process are resumed. The default is @code{off}. The
6966 @code{scheduler-locking} mode takes precedence when set to @code{on},
6967 or while you are stepping and set to @code{step}.
6968
6969 @item show schedule-multiple
6970 Display the current mode for resuming the execution of threads of
6971 multiple processes.
6972 @end table
6973
6974 @node Non-Stop Mode
6975 @subsection Non-Stop Mode
6976
6977 @cindex non-stop mode
6978
6979 @c This section is really only a place-holder, and needs to be expanded
6980 @c with more details.
6981
6982 For some multi-threaded targets, @value{GDBN} supports an optional
6983 mode of operation in which you can examine stopped program threads in
6984 the debugger while other threads continue to execute freely. This
6985 minimizes intrusion when debugging live systems, such as programs
6986 where some threads have real-time constraints or must continue to
6987 respond to external events. This is referred to as @dfn{non-stop} mode.
6988
6989 In non-stop mode, when a thread stops to report a debugging event,
6990 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6991 threads as well, in contrast to the all-stop mode behavior. Additionally,
6992 execution commands such as @code{continue} and @code{step} apply by default
6993 only to the current thread in non-stop mode, rather than all threads as
6994 in all-stop mode. This allows you to control threads explicitly in
6995 ways that are not possible in all-stop mode --- for example, stepping
6996 one thread while allowing others to run freely, stepping
6997 one thread while holding all others stopped, or stepping several threads
6998 independently and simultaneously.
6999
7000 To enter non-stop mode, use this sequence of commands before you run
7001 or attach to your program:
7002
7003 @smallexample
7004 # If using the CLI, pagination breaks non-stop.
7005 set pagination off
7006
7007 # Finally, turn it on!
7008 set non-stop on
7009 @end smallexample
7010
7011 You can use these commands to manipulate the non-stop mode setting:
7012
7013 @table @code
7014 @kindex set non-stop
7015 @item set non-stop on
7016 Enable selection of non-stop mode.
7017 @item set non-stop off
7018 Disable selection of non-stop mode.
7019 @kindex show non-stop
7020 @item show non-stop
7021 Show the current non-stop enablement setting.
7022 @end table
7023
7024 Note these commands only reflect whether non-stop mode is enabled,
7025 not whether the currently-executing program is being run in non-stop mode.
7026 In particular, the @code{set non-stop} preference is only consulted when
7027 @value{GDBN} starts or connects to the target program, and it is generally
7028 not possible to switch modes once debugging has started. Furthermore,
7029 since not all targets support non-stop mode, even when you have enabled
7030 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
7031 default.
7032
7033 In non-stop mode, all execution commands apply only to the current thread
7034 by default. That is, @code{continue} only continues one thread.
7035 To continue all threads, issue @code{continue -a} or @code{c -a}.
7036
7037 You can use @value{GDBN}'s background execution commands
7038 (@pxref{Background Execution}) to run some threads in the background
7039 while you continue to examine or step others from @value{GDBN}.
7040 The MI execution commands (@pxref{GDB/MI Program Execution}) are
7041 always executed asynchronously in non-stop mode.
7042
7043 Suspending execution is done with the @code{interrupt} command when
7044 running in the background, or @kbd{Ctrl-c} during foreground execution.
7045 In all-stop mode, this stops the whole process;
7046 but in non-stop mode the interrupt applies only to the current thread.
7047 To stop the whole program, use @code{interrupt -a}.
7048
7049 Other execution commands do not currently support the @code{-a} option.
7050
7051 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
7052 that thread current, as it does in all-stop mode. This is because the
7053 thread stop notifications are asynchronous with respect to @value{GDBN}'s
7054 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
7055 changed to a different thread just as you entered a command to operate on the
7056 previously current thread.
7057
7058 @node Background Execution
7059 @subsection Background Execution
7060
7061 @cindex foreground execution
7062 @cindex background execution
7063 @cindex asynchronous execution
7064 @cindex execution, foreground, background and asynchronous
7065
7066 @value{GDBN}'s execution commands have two variants: the normal
7067 foreground (synchronous) behavior, and a background
7068 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
7069 the program to report that some thread has stopped before prompting for
7070 another command. In background execution, @value{GDBN} immediately gives
7071 a command prompt so that you can issue other commands while your program runs.
7072
7073 If the target doesn't support async mode, @value{GDBN} issues an error
7074 message if you attempt to use the background execution commands.
7075
7076 @cindex @code{&}, background execution of commands
7077 To specify background execution, add a @code{&} to the command. For example,
7078 the background form of the @code{continue} command is @code{continue&}, or
7079 just @code{c&}. The execution commands that accept background execution
7080 are:
7081
7082 @table @code
7083 @kindex run&
7084 @item run
7085 @xref{Starting, , Starting your Program}.
7086
7087 @item attach
7088 @kindex attach&
7089 @xref{Attach, , Debugging an Already-running Process}.
7090
7091 @item step
7092 @kindex step&
7093 @xref{Continuing and Stepping, step}.
7094
7095 @item stepi
7096 @kindex stepi&
7097 @xref{Continuing and Stepping, stepi}.
7098
7099 @item next
7100 @kindex next&
7101 @xref{Continuing and Stepping, next}.
7102
7103 @item nexti
7104 @kindex nexti&
7105 @xref{Continuing and Stepping, nexti}.
7106
7107 @item continue
7108 @kindex continue&
7109 @xref{Continuing and Stepping, continue}.
7110
7111 @item finish
7112 @kindex finish&
7113 @xref{Continuing and Stepping, finish}.
7114
7115 @item until
7116 @kindex until&
7117 @xref{Continuing and Stepping, until}.
7118
7119 @end table
7120
7121 Background execution is especially useful in conjunction with non-stop
7122 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7123 However, you can also use these commands in the normal all-stop mode with
7124 the restriction that you cannot issue another execution command until the
7125 previous one finishes. Examples of commands that are valid in all-stop
7126 mode while the program is running include @code{help} and @code{info break}.
7127
7128 You can interrupt your program while it is running in the background by
7129 using the @code{interrupt} command.
7130
7131 @table @code
7132 @kindex interrupt
7133 @item interrupt
7134 @itemx interrupt -a
7135
7136 Suspend execution of the running program. In all-stop mode,
7137 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7138 only the current thread. To stop the whole program in non-stop mode,
7139 use @code{interrupt -a}.
7140 @end table
7141
7142 @node Thread-Specific Breakpoints
7143 @subsection Thread-Specific Breakpoints
7144
7145 When your program has multiple threads (@pxref{Threads,, Debugging
7146 Programs with Multiple Threads}), you can choose whether to set
7147 breakpoints on all threads, or on a particular thread.
7148
7149 @table @code
7150 @cindex breakpoints and threads
7151 @cindex thread breakpoints
7152 @kindex break @dots{} thread @var{thread-id}
7153 @item break @var{locspec} thread @var{thread-id}
7154 @itemx break @var{locspec} thread @var{thread-id} if @dots{}
7155 @var{locspec} specifies a code location or locations in your program.
7156 @xref{Location Specifications}, for details.
7157
7158 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7159 to specify that you only want @value{GDBN} to stop the program when a
7160 particular thread reaches this breakpoint. The @var{thread-id} specifier
7161 is one of the thread identifiers assigned by @value{GDBN}, shown
7162 in the first column of the @samp{info threads} display.
7163
7164 If you do not specify @samp{thread @var{thread-id}} when you set a
7165 breakpoint, the breakpoint applies to @emph{all} threads of your
7166 program.
7167
7168 You can use the @code{thread} qualifier on conditional breakpoints as
7169 well; in this case, place @samp{thread @var{thread-id}} before or
7170 after the breakpoint condition, like this:
7171
7172 @smallexample
7173 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7174 @end smallexample
7175
7176 @end table
7177
7178 Thread-specific breakpoints are automatically deleted when
7179 @value{GDBN} detects the corresponding thread is no longer in the
7180 thread list. For example:
7181
7182 @smallexample
7183 (@value{GDBP}) c
7184 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7185 @end smallexample
7186
7187 There are several ways for a thread to disappear, such as a regular
7188 thread exit, but also when you detach from the process with the
7189 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7190 Process}), or if @value{GDBN} loses the remote connection
7191 (@pxref{Remote Debugging}), etc. Note that with some targets,
7192 @value{GDBN} is only able to detect a thread has exited when the user
7193 explictly asks for the thread list with the @code{info threads}
7194 command.
7195
7196 @node Interrupted System Calls
7197 @subsection Interrupted System Calls
7198
7199 @cindex thread breakpoints and system calls
7200 @cindex system calls and thread breakpoints
7201 @cindex premature return from system calls
7202 There is an unfortunate side effect when using @value{GDBN} to debug
7203 multi-threaded programs. If one thread stops for a
7204 breakpoint, or for some other reason, and another thread is blocked in a
7205 system call, then the system call may return prematurely. This is a
7206 consequence of the interaction between multiple threads and the signals
7207 that @value{GDBN} uses to implement breakpoints and other events that
7208 stop execution.
7209
7210 To handle this problem, your program should check the return value of
7211 each system call and react appropriately. This is good programming
7212 style anyways.
7213
7214 For example, do not write code like this:
7215
7216 @smallexample
7217 sleep (10);
7218 @end smallexample
7219
7220 The call to @code{sleep} will return early if a different thread stops
7221 at a breakpoint or for some other reason.
7222
7223 Instead, write this:
7224
7225 @smallexample
7226 int unslept = 10;
7227 while (unslept > 0)
7228 unslept = sleep (unslept);
7229 @end smallexample
7230
7231 A system call is allowed to return early, so the system is still
7232 conforming to its specification. But @value{GDBN} does cause your
7233 multi-threaded program to behave differently than it would without
7234 @value{GDBN}.
7235
7236 Also, @value{GDBN} uses internal breakpoints in the thread library to
7237 monitor certain events such as thread creation and thread destruction.
7238 When such an event happens, a system call in another thread may return
7239 prematurely, even though your program does not appear to stop.
7240
7241 @node Observer Mode
7242 @subsection Observer Mode
7243
7244 If you want to build on non-stop mode and observe program behavior
7245 without any chance of disruption by @value{GDBN}, you can set
7246 variables to disable all of the debugger's attempts to modify state,
7247 whether by writing memory, inserting breakpoints, etc. These operate
7248 at a low level, intercepting operations from all commands.
7249
7250 When all of these are set to @code{off}, then @value{GDBN} is said to
7251 be @dfn{observer mode}. As a convenience, the variable
7252 @code{observer} can be set to disable these, plus enable non-stop
7253 mode.
7254
7255 Note that @value{GDBN} will not prevent you from making nonsensical
7256 combinations of these settings. For instance, if you have enabled
7257 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7258 then breakpoints that work by writing trap instructions into the code
7259 stream will still not be able to be placed.
7260
7261 @table @code
7262
7263 @kindex observer
7264 @item set observer on
7265 @itemx set observer off
7266 When set to @code{on}, this disables all the permission variables
7267 below (except for @code{insert-fast-tracepoints}), plus enables
7268 non-stop debugging. Setting this to @code{off} switches back to
7269 normal debugging, though remaining in non-stop mode.
7270
7271 @item show observer
7272 Show whether observer mode is on or off.
7273
7274 @kindex may-write-registers
7275 @item set may-write-registers on
7276 @itemx set may-write-registers off
7277 This controls whether @value{GDBN} will attempt to alter the values of
7278 registers, such as with assignment expressions in @code{print}, or the
7279 @code{jump} command. It defaults to @code{on}.
7280
7281 @item show may-write-registers
7282 Show the current permission to write registers.
7283
7284 @kindex may-write-memory
7285 @item set may-write-memory on
7286 @itemx set may-write-memory off
7287 This controls whether @value{GDBN} will attempt to alter the contents
7288 of memory, such as with assignment expressions in @code{print}. It
7289 defaults to @code{on}.
7290
7291 @item show may-write-memory
7292 Show the current permission to write memory.
7293
7294 @kindex may-insert-breakpoints
7295 @item set may-insert-breakpoints on
7296 @itemx set may-insert-breakpoints off
7297 This controls whether @value{GDBN} will attempt to insert breakpoints.
7298 This affects all breakpoints, including internal breakpoints defined
7299 by @value{GDBN}. It defaults to @code{on}.
7300
7301 @item show may-insert-breakpoints
7302 Show the current permission to insert breakpoints.
7303
7304 @kindex may-insert-tracepoints
7305 @item set may-insert-tracepoints on
7306 @itemx set may-insert-tracepoints off
7307 This controls whether @value{GDBN} will attempt to insert (regular)
7308 tracepoints at the beginning of a tracing experiment. It affects only
7309 non-fast tracepoints, fast tracepoints being under the control of
7310 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7311
7312 @item show may-insert-tracepoints
7313 Show the current permission to insert tracepoints.
7314
7315 @kindex may-insert-fast-tracepoints
7316 @item set may-insert-fast-tracepoints on
7317 @itemx set may-insert-fast-tracepoints off
7318 This controls whether @value{GDBN} will attempt to insert fast
7319 tracepoints at the beginning of a tracing experiment. It affects only
7320 fast tracepoints, regular (non-fast) tracepoints being under the
7321 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7322
7323 @item show may-insert-fast-tracepoints
7324 Show the current permission to insert fast tracepoints.
7325
7326 @kindex may-interrupt
7327 @item set may-interrupt on
7328 @itemx set may-interrupt off
7329 This controls whether @value{GDBN} will attempt to interrupt or stop
7330 program execution. When this variable is @code{off}, the
7331 @code{interrupt} command will have no effect, nor will
7332 @kbd{Ctrl-c}. It defaults to @code{on}.
7333
7334 @item show may-interrupt
7335 Show the current permission to interrupt or stop the program.
7336
7337 @end table
7338
7339 @node Reverse Execution
7340 @chapter Running programs backward
7341 @cindex reverse execution
7342 @cindex running programs backward
7343
7344 When you are debugging a program, it is not unusual to realize that
7345 you have gone too far, and some event of interest has already happened.
7346 If the target environment supports it, @value{GDBN} can allow you to
7347 ``rewind'' the program by running it backward.
7348
7349 A target environment that supports reverse execution should be able
7350 to ``undo'' the changes in machine state that have taken place as the
7351 program was executing normally. Variables, registers etc.@: should
7352 revert to their previous values. Obviously this requires a great
7353 deal of sophistication on the part of the target environment; not
7354 all target environments can support reverse execution.
7355
7356 When a program is executed in reverse, the instructions that
7357 have most recently been executed are ``un-executed'', in reverse
7358 order. The program counter runs backward, following the previous
7359 thread of execution in reverse. As each instruction is ``un-executed'',
7360 the values of memory and/or registers that were changed by that
7361 instruction are reverted to their previous states. After executing
7362 a piece of source code in reverse, all side effects of that code
7363 should be ``undone'', and all variables should be returned to their
7364 prior values@footnote{
7365 Note that some side effects are easier to undo than others. For instance,
7366 memory and registers are relatively easy, but device I/O is hard. Some
7367 targets may be able undo things like device I/O, and some may not.
7368
7369 The contract between @value{GDBN} and the reverse executing target
7370 requires only that the target do something reasonable when
7371 @value{GDBN} tells it to execute backwards, and then report the
7372 results back to @value{GDBN}. Whatever the target reports back to
7373 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7374 assumes that the memory and registers that the target reports are in a
7375 consistent state, but @value{GDBN} accepts whatever it is given.
7376 }.
7377
7378 On some platforms, @value{GDBN} has built-in support for reverse
7379 execution, activated with the @code{record} or @code{record btrace}
7380 commands. @xref{Process Record and Replay}. Some remote targets,
7381 typically full system emulators, support reverse execution directly
7382 without requiring any special command.
7383
7384 If you are debugging in a target environment that supports
7385 reverse execution, @value{GDBN} provides the following commands.
7386
7387 @table @code
7388 @kindex reverse-continue
7389 @kindex rc @r{(@code{reverse-continue})}
7390 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7391 @itemx rc @r{[}@var{ignore-count}@r{]}
7392 Beginning at the point where your program last stopped, start executing
7393 in reverse. Reverse execution will stop for breakpoints and synchronous
7394 exceptions (signals), just like normal execution. Behavior of
7395 asynchronous signals depends on the target environment.
7396
7397 @kindex reverse-step
7398 @kindex rs @r{(@code{step})}
7399 @item reverse-step @r{[}@var{count}@r{]}
7400 Run the program backward until control reaches the start of a
7401 different source line; then stop it, and return control to @value{GDBN}.
7402
7403 Like the @code{step} command, @code{reverse-step} will only stop
7404 at the beginning of a source line. It ``un-executes'' the previously
7405 executed source line. If the previous source line included calls to
7406 debuggable functions, @code{reverse-step} will step (backward) into
7407 the called function, stopping at the beginning of the @emph{last}
7408 statement in the called function (typically a return statement).
7409
7410 Also, as with the @code{step} command, if non-debuggable functions are
7411 called, @code{reverse-step} will run thru them backward without stopping.
7412
7413 @kindex reverse-stepi
7414 @kindex rsi @r{(@code{reverse-stepi})}
7415 @item reverse-stepi @r{[}@var{count}@r{]}
7416 Reverse-execute one machine instruction. Note that the instruction
7417 to be reverse-executed is @emph{not} the one pointed to by the program
7418 counter, but the instruction executed prior to that one. For instance,
7419 if the last instruction was a jump, @code{reverse-stepi} will take you
7420 back from the destination of the jump to the jump instruction itself.
7421
7422 @kindex reverse-next
7423 @kindex rn @r{(@code{reverse-next})}
7424 @item reverse-next @r{[}@var{count}@r{]}
7425 Run backward to the beginning of the previous line executed in
7426 the current (innermost) stack frame. If the line contains function
7427 calls, they will be ``un-executed'' without stopping. Starting from
7428 the first line of a function, @code{reverse-next} will take you back
7429 to the caller of that function, @emph{before} the function was called,
7430 just as the normal @code{next} command would take you from the last
7431 line of a function back to its return to its caller
7432 @footnote{Unless the code is too heavily optimized.}.
7433
7434 @kindex reverse-nexti
7435 @kindex rni @r{(@code{reverse-nexti})}
7436 @item reverse-nexti @r{[}@var{count}@r{]}
7437 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7438 in reverse, except that called functions are ``un-executed'' atomically.
7439 That is, if the previously executed instruction was a return from
7440 another function, @code{reverse-nexti} will continue to execute
7441 in reverse until the call to that function (from the current stack
7442 frame) is reached.
7443
7444 @kindex reverse-finish
7445 @item reverse-finish
7446 Just as the @code{finish} command takes you to the point where the
7447 current function returns, @code{reverse-finish} takes you to the point
7448 where it was called. Instead of ending up at the end of the current
7449 function invocation, you end up at the beginning.
7450
7451 @kindex set exec-direction
7452 @item set exec-direction
7453 Set the direction of target execution.
7454 @item set exec-direction reverse
7455 @cindex execute forward or backward in time
7456 @value{GDBN} will perform all execution commands in reverse, until the
7457 exec-direction mode is changed to ``forward''. Affected commands include
7458 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7459 command cannot be used in reverse mode.
7460 @item set exec-direction forward
7461 @value{GDBN} will perform all execution commands in the normal fashion.
7462 This is the default.
7463 @end table
7464
7465
7466 @node Process Record and Replay
7467 @chapter Recording Inferior's Execution and Replaying It
7468 @cindex process record and replay
7469 @cindex recording inferior's execution and replaying it
7470
7471 On some platforms, @value{GDBN} provides a special @dfn{process record
7472 and replay} target that can record a log of the process execution, and
7473 replay it later with both forward and reverse execution commands.
7474
7475 @cindex replay mode
7476 When this target is in use, if the execution log includes the record
7477 for the next instruction, @value{GDBN} will debug in @dfn{replay
7478 mode}. In the replay mode, the inferior does not really execute code
7479 instructions. Instead, all the events that normally happen during
7480 code execution are taken from the execution log. While code is not
7481 really executed in replay mode, the values of registers (including the
7482 program counter register) and the memory of the inferior are still
7483 changed as they normally would. Their contents are taken from the
7484 execution log.
7485
7486 @cindex record mode
7487 If the record for the next instruction is not in the execution log,
7488 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7489 inferior executes normally, and @value{GDBN} records the execution log
7490 for future replay.
7491
7492 The process record and replay target supports reverse execution
7493 (@pxref{Reverse Execution}), even if the platform on which the
7494 inferior runs does not. However, the reverse execution is limited in
7495 this case by the range of the instructions recorded in the execution
7496 log. In other words, reverse execution on platforms that don't
7497 support it directly can only be done in the replay mode.
7498
7499 When debugging in the reverse direction, @value{GDBN} will work in
7500 replay mode as long as the execution log includes the record for the
7501 previous instruction; otherwise, it will work in record mode, if the
7502 platform supports reverse execution, or stop if not.
7503
7504 Currently, process record and replay is supported on ARM, Aarch64,
7505 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7506 GNU/Linux. Process record and replay can be used both when native
7507 debugging, and when remote debugging via @code{gdbserver}.
7508
7509 For architecture environments that support process record and replay,
7510 @value{GDBN} provides the following commands:
7511
7512 @table @code
7513 @kindex target record
7514 @kindex target record-full
7515 @kindex target record-btrace
7516 @kindex record
7517 @kindex record full
7518 @kindex record btrace
7519 @kindex record btrace bts
7520 @kindex record btrace pt
7521 @kindex record bts
7522 @kindex record pt
7523 @kindex rec
7524 @kindex rec full
7525 @kindex rec btrace
7526 @kindex rec btrace bts
7527 @kindex rec btrace pt
7528 @kindex rec bts
7529 @kindex rec pt
7530 @item record @var{method}
7531 This command starts the process record and replay target. The
7532 recording method can be specified as parameter. Without a parameter
7533 the command uses the @code{full} recording method. The following
7534 recording methods are available:
7535
7536 @table @code
7537 @item full
7538 Full record/replay recording using @value{GDBN}'s software record and
7539 replay implementation. This method allows replaying and reverse
7540 execution.
7541
7542 @item btrace @var{format}
7543 Hardware-supported instruction recording, supported on Intel
7544 processors. This method does not record data. Further, the data is
7545 collected in a ring buffer so old data will be overwritten when the
7546 buffer is full. It allows limited reverse execution. Variables and
7547 registers are not available during reverse execution. In remote
7548 debugging, recording continues on disconnect. Recorded data can be
7549 inspected after reconnecting. The recording may be stopped using
7550 @code{record stop}.
7551
7552 The recording format can be specified as parameter. Without a parameter
7553 the command chooses the recording format. The following recording
7554 formats are available:
7555
7556 @table @code
7557 @item bts
7558 @cindex branch trace store
7559 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7560 this format, the processor stores a from/to record for each executed
7561 branch in the btrace ring buffer.
7562
7563 @item pt
7564 @cindex Intel Processor Trace
7565 Use the @dfn{Intel Processor Trace} recording format. In this
7566 format, the processor stores the execution trace in a compressed form
7567 that is afterwards decoded by @value{GDBN}.
7568
7569 The trace can be recorded with very low overhead. The compressed
7570 trace format also allows small trace buffers to already contain a big
7571 number of instructions compared to @acronym{BTS}.
7572
7573 Decoding the recorded execution trace, on the other hand, is more
7574 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7575 increased number of instructions to process. You should increase the
7576 buffer-size with care.
7577 @end table
7578
7579 Not all recording formats may be available on all processors.
7580 @end table
7581
7582 The process record and replay target can only debug a process that is
7583 already running. Therefore, you need first to start the process with
7584 the @kbd{run} or @kbd{start} commands, and then start the recording
7585 with the @kbd{record @var{method}} command.
7586
7587 @cindex displaced stepping, and process record and replay
7588 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7589 will be automatically disabled when process record and replay target
7590 is started. That's because the process record and replay target
7591 doesn't support displaced stepping.
7592
7593 @cindex non-stop mode, and process record and replay
7594 @cindex asynchronous execution, and process record and replay
7595 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7596 the asynchronous execution mode (@pxref{Background Execution}), not
7597 all recording methods are available. The @code{full} recording method
7598 does not support these two modes.
7599
7600 @kindex record stop
7601 @kindex rec s
7602 @item record stop
7603 Stop the process record and replay target. When process record and
7604 replay target stops, the entire execution log will be deleted and the
7605 inferior will either be terminated, or will remain in its final state.
7606
7607 When you stop the process record and replay target in record mode (at
7608 the end of the execution log), the inferior will be stopped at the
7609 next instruction that would have been recorded. In other words, if
7610 you record for a while and then stop recording, the inferior process
7611 will be left in the same state as if the recording never happened.
7612
7613 On the other hand, if the process record and replay target is stopped
7614 while in replay mode (that is, not at the end of the execution log,
7615 but at some earlier point), the inferior process will become ``live''
7616 at that earlier state, and it will then be possible to continue the
7617 usual ``live'' debugging of the process from that state.
7618
7619 When the inferior process exits, or @value{GDBN} detaches from it,
7620 process record and replay target will automatically stop itself.
7621
7622 @kindex record goto
7623 @item record goto
7624 Go to a specific location in the execution log. There are several
7625 ways to specify the location to go to:
7626
7627 @table @code
7628 @item record goto begin
7629 @itemx record goto start
7630 Go to the beginning of the execution log.
7631
7632 @item record goto end
7633 Go to the end of the execution log.
7634
7635 @item record goto @var{n}
7636 Go to instruction number @var{n} in the execution log.
7637 @end table
7638
7639 @kindex record save
7640 @item record save @var{filename}
7641 Save the execution log to a file @file{@var{filename}}.
7642 Default filename is @file{gdb_record.@var{process_id}}, where
7643 @var{process_id} is the process ID of the inferior.
7644
7645 This command may not be available for all recording methods.
7646
7647 @kindex record restore
7648 @item record restore @var{filename}
7649 Restore the execution log from a file @file{@var{filename}}.
7650 File must have been created with @code{record save}.
7651
7652 @kindex set record full
7653 @item set record full insn-number-max @var{limit}
7654 @itemx set record full insn-number-max unlimited
7655 Set the limit of instructions to be recorded for the @code{full}
7656 recording method. Default value is 200000.
7657
7658 If @var{limit} is a positive number, then @value{GDBN} will start
7659 deleting instructions from the log once the number of the record
7660 instructions becomes greater than @var{limit}. For every new recorded
7661 instruction, @value{GDBN} will delete the earliest recorded
7662 instruction to keep the number of recorded instructions at the limit.
7663 (Since deleting recorded instructions loses information, @value{GDBN}
7664 lets you control what happens when the limit is reached, by means of
7665 the @code{stop-at-limit} option, described below.)
7666
7667 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7668 delete recorded instructions from the execution log. The number of
7669 recorded instructions is limited only by the available memory.
7670
7671 @kindex show record full
7672 @item show record full insn-number-max
7673 Show the limit of instructions to be recorded with the @code{full}
7674 recording method.
7675
7676 @item set record full stop-at-limit
7677 Control the behavior of the @code{full} recording method when the
7678 number of recorded instructions reaches the limit. If ON (the
7679 default), @value{GDBN} will stop when the limit is reached for the
7680 first time and ask you whether you want to stop the inferior or
7681 continue running it and recording the execution log. If you decide
7682 to continue recording, each new recorded instruction will cause the
7683 oldest one to be deleted.
7684
7685 If this option is OFF, @value{GDBN} will automatically delete the
7686 oldest record to make room for each new one, without asking.
7687
7688 @item show record full stop-at-limit
7689 Show the current setting of @code{stop-at-limit}.
7690
7691 @item set record full memory-query
7692 Control the behavior when @value{GDBN} is unable to record memory
7693 changes caused by an instruction for the @code{full} recording method.
7694 If ON, @value{GDBN} will query whether to stop the inferior in that
7695 case.
7696
7697 If this option is OFF (the default), @value{GDBN} will automatically
7698 ignore the effect of such instructions on memory. Later, when
7699 @value{GDBN} replays this execution log, it will mark the log of this
7700 instruction as not accessible, and it will not affect the replay
7701 results.
7702
7703 @item show record full memory-query
7704 Show the current setting of @code{memory-query}.
7705
7706 @kindex set record btrace
7707 The @code{btrace} record target does not trace data. As a
7708 convenience, when replaying, @value{GDBN} reads read-only memory off
7709 the live program directly, assuming that the addresses of the
7710 read-only areas don't change. This for example makes it possible to
7711 disassemble code while replaying, but not to print variables.
7712 In some cases, being able to inspect variables might be useful.
7713 You can use the following command for that:
7714
7715 @item set record btrace replay-memory-access
7716 Control the behavior of the @code{btrace} recording method when
7717 accessing memory during replay. If @code{read-only} (the default),
7718 @value{GDBN} will only allow accesses to read-only memory.
7719 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7720 and to read-write memory. Beware that the accessed memory corresponds
7721 to the live target and not necessarily to the current replay
7722 position.
7723
7724 @item set record btrace cpu @var{identifier}
7725 Set the processor to be used for enabling workarounds for processor
7726 errata when decoding the trace.
7727
7728 Processor errata are defects in processor operation, caused by its
7729 design or manufacture. They can cause a trace not to match the
7730 specification. This, in turn, may cause trace decode to fail.
7731 @value{GDBN} can detect erroneous trace packets and correct them, thus
7732 avoiding the decoding failures. These corrections are known as
7733 @dfn{errata workarounds}, and are enabled based on the processor on
7734 which the trace was recorded.
7735
7736 By default, @value{GDBN} attempts to detect the processor
7737 automatically, and apply the necessary workarounds for it. However,
7738 you may need to specify the processor if @value{GDBN} does not yet
7739 support it. This command allows you to do that, and also allows to
7740 disable the workarounds.
7741
7742 The argument @var{identifier} identifies the @sc{cpu} and is of the
7743 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7744 there are two special identifiers, @code{none} and @code{auto}
7745 (default).
7746
7747 The following vendor identifiers and corresponding processor
7748 identifiers are currently supported:
7749
7750 @multitable @columnfractions .1 .9
7751
7752 @item @code{intel}
7753 @tab @var{family}/@var{model}[/@var{stepping}]
7754
7755 @end multitable
7756
7757 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7758 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7759
7760 If @var{identifier} is @code{auto}, enable errata workarounds for the
7761 processor on which the trace was recorded. If @var{identifier} is
7762 @code{none}, errata workarounds are disabled.
7763
7764 For example, when using an old @value{GDBN} on a new system, decode
7765 may fail because @value{GDBN} does not support the new processor. It
7766 often suffices to specify an older processor that @value{GDBN}
7767 supports.
7768
7769 @smallexample
7770 (gdb) info record
7771 Active record target: record-btrace
7772 Recording format: Intel Processor Trace.
7773 Buffer size: 16kB.
7774 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7775 (gdb) set record btrace cpu intel:6/158
7776 (gdb) info record
7777 Active record target: record-btrace
7778 Recording format: Intel Processor Trace.
7779 Buffer size: 16kB.
7780 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7781 @end smallexample
7782
7783 @kindex show record btrace
7784 @item show record btrace replay-memory-access
7785 Show the current setting of @code{replay-memory-access}.
7786
7787 @item show record btrace cpu
7788 Show the processor to be used for enabling trace decode errata
7789 workarounds.
7790
7791 @kindex set record btrace bts
7792 @item set record btrace bts buffer-size @var{size}
7793 @itemx set record btrace bts buffer-size unlimited
7794 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7795 format. Default is 64KB.
7796
7797 If @var{size} is a positive number, then @value{GDBN} will try to
7798 allocate a buffer of at least @var{size} bytes for each new thread
7799 that uses the btrace recording method and the @acronym{BTS} format.
7800 The actually obtained buffer size may differ from the requested
7801 @var{size}. Use the @code{info record} command to see the actual
7802 buffer size for each thread that uses the btrace recording method and
7803 the @acronym{BTS} format.
7804
7805 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7806 allocate a buffer of 4MB.
7807
7808 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7809 also need longer to process the branch trace data before it can be used.
7810
7811 @item show record btrace bts buffer-size @var{size}
7812 Show the current setting of the requested ring buffer size for branch
7813 tracing in @acronym{BTS} format.
7814
7815 @kindex set record btrace pt
7816 @item set record btrace pt buffer-size @var{size}
7817 @itemx set record btrace pt buffer-size unlimited
7818 Set the requested ring buffer size for branch tracing in Intel
7819 Processor Trace format. Default is 16KB.
7820
7821 If @var{size} is a positive number, then @value{GDBN} will try to
7822 allocate a buffer of at least @var{size} bytes for each new thread
7823 that uses the btrace recording method and the Intel Processor Trace
7824 format. The actually obtained buffer size may differ from the
7825 requested @var{size}. Use the @code{info record} command to see the
7826 actual buffer size for each thread.
7827
7828 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7829 allocate a buffer of 4MB.
7830
7831 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7832 also need longer to process the branch trace data before it can be used.
7833
7834 @item show record btrace pt buffer-size @var{size}
7835 Show the current setting of the requested ring buffer size for branch
7836 tracing in Intel Processor Trace format.
7837
7838 @kindex info record
7839 @item info record
7840 Show various statistics about the recording depending on the recording
7841 method:
7842
7843 @table @code
7844 @item full
7845 For the @code{full} recording method, it shows the state of process
7846 record and its in-memory execution log buffer, including:
7847
7848 @itemize @bullet
7849 @item
7850 Whether in record mode or replay mode.
7851 @item
7852 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7853 @item
7854 Highest recorded instruction number.
7855 @item
7856 Current instruction about to be replayed (if in replay mode).
7857 @item
7858 Number of instructions contained in the execution log.
7859 @item
7860 Maximum number of instructions that may be contained in the execution log.
7861 @end itemize
7862
7863 @item btrace
7864 For the @code{btrace} recording method, it shows:
7865
7866 @itemize @bullet
7867 @item
7868 Recording format.
7869 @item
7870 Number of instructions that have been recorded.
7871 @item
7872 Number of blocks of sequential control-flow formed by the recorded
7873 instructions.
7874 @item
7875 Whether in record mode or replay mode.
7876 @end itemize
7877
7878 For the @code{bts} recording format, it also shows:
7879 @itemize @bullet
7880 @item
7881 Size of the perf ring buffer.
7882 @end itemize
7883
7884 For the @code{pt} recording format, it also shows:
7885 @itemize @bullet
7886 @item
7887 Size of the perf ring buffer.
7888 @end itemize
7889 @end table
7890
7891 @kindex record delete
7892 @kindex rec del
7893 @item record delete
7894 When record target runs in replay mode (``in the past''), delete the
7895 subsequent execution log and begin to record a new execution log starting
7896 from the current address. This means you will abandon the previously
7897 recorded ``future'' and begin recording a new ``future''.
7898
7899 @kindex record instruction-history
7900 @kindex rec instruction-history
7901 @item record instruction-history
7902 Disassembles instructions from the recorded execution log. By
7903 default, ten instructions are disassembled. This can be changed using
7904 the @code{set record instruction-history-size} command. Instructions
7905 are printed in execution order.
7906
7907 It can also print mixed source+disassembly if you specify the the
7908 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7909 as well as in symbolic form by specifying the @code{/r} modifier.
7910
7911 The current position marker is printed for the instruction at the
7912 current program counter value. This instruction can appear multiple
7913 times in the trace and the current position marker will be printed
7914 every time. To omit the current position marker, specify the
7915 @code{/p} modifier.
7916
7917 To better align the printed instructions when the trace contains
7918 instructions from more than one function, the function name may be
7919 omitted by specifying the @code{/f} modifier.
7920
7921 Speculatively executed instructions are prefixed with @samp{?}. This
7922 feature is not available for all recording formats.
7923
7924 There are several ways to specify what part of the execution log to
7925 disassemble:
7926
7927 @table @code
7928 @item record instruction-history @var{insn}
7929 Disassembles ten instructions starting from instruction number
7930 @var{insn}.
7931
7932 @item record instruction-history @var{insn}, +/-@var{n}
7933 Disassembles @var{n} instructions around instruction number
7934 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7935 @var{n} instructions after instruction number @var{insn}. If
7936 @var{n} is preceded with @code{-}, disassembles @var{n}
7937 instructions before instruction number @var{insn}.
7938
7939 @item record instruction-history
7940 Disassembles ten more instructions after the last disassembly.
7941
7942 @item record instruction-history -
7943 Disassembles ten more instructions before the last disassembly.
7944
7945 @item record instruction-history @var{begin}, @var{end}
7946 Disassembles instructions beginning with instruction number
7947 @var{begin} until instruction number @var{end}. The instruction
7948 number @var{end} is included.
7949 @end table
7950
7951 This command may not be available for all recording methods.
7952
7953 @kindex set record
7954 @item set record instruction-history-size @var{size}
7955 @itemx set record instruction-history-size unlimited
7956 Define how many instructions to disassemble in the @code{record
7957 instruction-history} command. The default value is 10.
7958 A @var{size} of @code{unlimited} means unlimited instructions.
7959
7960 @kindex show record
7961 @item show record instruction-history-size
7962 Show how many instructions to disassemble in the @code{record
7963 instruction-history} command.
7964
7965 @kindex record function-call-history
7966 @kindex rec function-call-history
7967 @item record function-call-history
7968 Prints the execution history at function granularity. For each sequence
7969 of instructions that belong to the same function, it prints the name of
7970 that function, the source lines for this instruction sequence (if the
7971 @code{/l} modifier is specified), and the instructions numbers that form
7972 the sequence (if the @code{/i} modifier is specified). The function names
7973 are indented to reflect the call stack depth if the @code{/c} modifier is
7974 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be given
7975 together.
7976
7977 @smallexample
7978 (@value{GDBP}) @b{list 1, 10}
7979 1 void foo (void)
7980 2 @{
7981 3 @}
7982 4
7983 5 void bar (void)
7984 6 @{
7985 7 ...
7986 8 foo ();
7987 9 ...
7988 10 @}
7989 (@value{GDBP}) @b{record function-call-history /ilc}
7990 1 bar inst 1,4 at foo.c:6,8
7991 2 foo inst 5,10 at foo.c:2,3
7992 3 bar inst 11,13 at foo.c:9,10
7993 @end smallexample
7994
7995 By default, ten functions are printed. This can be changed using the
7996 @code{set record function-call-history-size} command. Functions are
7997 printed in execution order. There are several ways to specify what
7998 to print:
7999
8000 @table @code
8001 @item record function-call-history @var{func}
8002 Prints ten functions starting from function number @var{func}.
8003
8004 @item record function-call-history @var{func}, +/-@var{n}
8005 Prints @var{n} functions around function number @var{func}. If
8006 @var{n} is preceded with @code{+}, prints @var{n} functions after
8007 function number @var{func}. If @var{n} is preceded with @code{-},
8008 prints @var{n} functions before function number @var{func}.
8009
8010 @item record function-call-history
8011 Prints ten more functions after the last ten-function print.
8012
8013 @item record function-call-history -
8014 Prints ten more functions before the last ten-function print.
8015
8016 @item record function-call-history @var{begin}, @var{end}
8017 Prints functions beginning with function number @var{begin} until
8018 function number @var{end}. The function number @var{end} is included.
8019 @end table
8020
8021 This command may not be available for all recording methods.
8022
8023 @item set record function-call-history-size @var{size}
8024 @itemx set record function-call-history-size unlimited
8025 Define how many functions to print in the
8026 @code{record function-call-history} command. The default value is 10.
8027 A size of @code{unlimited} means unlimited functions.
8028
8029 @item show record function-call-history-size
8030 Show how many functions to print in the
8031 @code{record function-call-history} command.
8032 @end table
8033
8034
8035 @node Stack
8036 @chapter Examining the Stack
8037
8038 When your program has stopped, the first thing you need to know is where it
8039 stopped and how it got there.
8040
8041 @cindex call stack
8042 Each time your program performs a function call, information about the call
8043 is generated.
8044 That information includes the location of the call in your program,
8045 the arguments of the call,
8046 and the local variables of the function being called.
8047 The information is saved in a block of data called a @dfn{stack frame}.
8048 The stack frames are allocated in a region of memory called the @dfn{call
8049 stack}.
8050
8051 When your program stops, the @value{GDBN} commands for examining the
8052 stack allow you to see all of this information.
8053
8054 @cindex selected frame
8055 One of the stack frames is @dfn{selected} by @value{GDBN} and many
8056 @value{GDBN} commands refer implicitly to the selected frame. In
8057 particular, whenever you ask @value{GDBN} for the value of a variable in
8058 your program, the value is found in the selected frame. There are
8059 special @value{GDBN} commands to select whichever frame you are
8060 interested in. @xref{Selection, ,Selecting a Frame}.
8061
8062 When your program stops, @value{GDBN} automatically selects the
8063 currently executing frame and describes it briefly, similar to the
8064 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
8065
8066 @menu
8067 * Frames:: Stack frames
8068 * Backtrace:: Backtraces
8069 * Selection:: Selecting a frame
8070 * Frame Info:: Information on a frame
8071 * Frame Apply:: Applying a command to several frames
8072 * Frame Filter Management:: Managing frame filters
8073
8074 @end menu
8075
8076 @node Frames
8077 @section Stack Frames
8078
8079 @cindex frame, definition
8080 @cindex stack frame
8081 The call stack is divided up into contiguous pieces called @dfn{stack
8082 frames}, or @dfn{frames} for short; each frame is the data associated
8083 with one call to one function. The frame contains the arguments given
8084 to the function, the function's local variables, and the address at
8085 which the function is executing.
8086
8087 @cindex initial frame
8088 @cindex outermost frame
8089 @cindex innermost frame
8090 When your program is started, the stack has only one frame, that of the
8091 function @code{main}. This is called the @dfn{initial} frame or the
8092 @dfn{outermost} frame. Each time a function is called, a new frame is
8093 made. Each time a function returns, the frame for that function invocation
8094 is eliminated. If a function is recursive, there can be many frames for
8095 the same function. The frame for the function in which execution is
8096 actually occurring is called the @dfn{innermost} frame. This is the most
8097 recently created of all the stack frames that still exist.
8098
8099 @cindex frame pointer
8100 Inside your program, stack frames are identified by their addresses. A
8101 stack frame consists of many bytes, each of which has its own address; each
8102 kind of computer has a convention for choosing one byte whose
8103 address serves as the address of the frame. Usually this address is kept
8104 in a register called the @dfn{frame pointer register}
8105 (@pxref{Registers, $fp}) while execution is going on in that frame.
8106
8107 @cindex frame level
8108 @cindex frame number
8109 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8110 number that is zero for the innermost frame, one for the frame that
8111 called it, and so on upward. These level numbers give you a way of
8112 designating stack frames in @value{GDBN} commands. The terms
8113 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8114 describe this number.
8115
8116 @c The -fomit-frame-pointer below perennially causes hbox overflow
8117 @c underflow problems.
8118 @cindex frameless execution
8119 Some compilers provide a way to compile functions so that they operate
8120 without stack frames. (For example, the @value{NGCC} option
8121 @smallexample
8122 @samp{-fomit-frame-pointer}
8123 @end smallexample
8124 generates functions without a frame.)
8125 This is occasionally done with heavily used library functions to save
8126 the frame setup time. @value{GDBN} has limited facilities for dealing
8127 with these function invocations. If the innermost function invocation
8128 has no stack frame, @value{GDBN} nevertheless regards it as though
8129 it had a separate frame, which is numbered zero as usual, allowing
8130 correct tracing of the function call chain. However, @value{GDBN} has
8131 no provision for frameless functions elsewhere in the stack.
8132
8133 @node Backtrace
8134 @section Backtraces
8135
8136 @cindex traceback
8137 @cindex call stack traces
8138 A backtrace is a summary of how your program got where it is. It shows one
8139 line per frame, for many frames, starting with the currently executing
8140 frame (frame zero), followed by its caller (frame one), and on up the
8141 stack.
8142
8143 @anchor{backtrace-command}
8144 @kindex backtrace
8145 @kindex bt @r{(@code{backtrace})}
8146 To print a backtrace of the entire stack, use the @code{backtrace}
8147 command, or its alias @code{bt}. This command will print one line per
8148 frame for frames in the stack. By default, all stack frames are
8149 printed. You can stop the backtrace at any time by typing the system
8150 interrupt character, normally @kbd{Ctrl-c}.
8151
8152 @table @code
8153 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8154 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8155 Print the backtrace of the entire stack.
8156
8157 The optional @var{count} can be one of the following:
8158
8159 @table @code
8160 @item @var{n}
8161 @itemx @var{n}
8162 Print only the innermost @var{n} frames, where @var{n} is a positive
8163 number.
8164
8165 @item -@var{n}
8166 @itemx -@var{n}
8167 Print only the outermost @var{n} frames, where @var{n} is a positive
8168 number.
8169 @end table
8170
8171 Options:
8172
8173 @table @code
8174 @item -full
8175 Print the values of the local variables also. This can be combined
8176 with the optional @var{count} to limit the number of frames shown.
8177
8178 @item -no-filters
8179 Do not run Python frame filters on this backtrace. @xref{Frame
8180 Filter API}, for more information. Additionally use @ref{disable
8181 frame-filter all} to turn off all frame filters. This is only
8182 relevant when @value{GDBN} has been configured with @code{Python}
8183 support.
8184
8185 @item -hide
8186 A Python frame filter might decide to ``elide'' some frames. Normally
8187 such elided frames are still printed, but they are indented relative
8188 to the filtered frames that cause them to be elided. The @code{-hide}
8189 option causes elided frames to not be printed at all.
8190 @end table
8191
8192 The @code{backtrace} command also supports a number of options that
8193 allow overriding relevant global print settings as set by @code{set
8194 backtrace} and @code{set print} subcommands:
8195
8196 @table @code
8197 @item -past-main [@code{on}|@code{off}]
8198 Set whether backtraces should continue past @code{main}. Related setting:
8199 @ref{set backtrace past-main}.
8200
8201 @item -past-entry [@code{on}|@code{off}]
8202 Set whether backtraces should continue past the entry point of a program.
8203 Related setting: @ref{set backtrace past-entry}.
8204
8205 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8206 Set printing of function arguments at function entry.
8207 Related setting: @ref{set print entry-values}.
8208
8209 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8210 Set printing of non-scalar frame arguments.
8211 Related setting: @ref{set print frame-arguments}.
8212
8213 @item -raw-frame-arguments [@code{on}|@code{off}]
8214 Set whether to print frame arguments in raw form.
8215 Related setting: @ref{set print raw-frame-arguments}.
8216
8217 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8218 Set printing of frame information.
8219 Related setting: @ref{set print frame-info}.
8220 @end table
8221
8222 The optional @var{qualifier} is maintained for backward compatibility.
8223 It can be one of the following:
8224
8225 @table @code
8226 @item full
8227 Equivalent to the @code{-full} option.
8228
8229 @item no-filters
8230 Equivalent to the @code{-no-filters} option.
8231
8232 @item hide
8233 Equivalent to the @code{-hide} option.
8234 @end table
8235
8236 @end table
8237
8238 @kindex where
8239 @kindex info stack
8240 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8241 are additional aliases for @code{backtrace}.
8242
8243 @cindex multiple threads, backtrace
8244 In a multi-threaded program, @value{GDBN} by default shows the
8245 backtrace only for the current thread. To display the backtrace for
8246 several or all of the threads, use the command @code{thread apply}
8247 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8248 apply all backtrace}, @value{GDBN} will display the backtrace for all
8249 the threads; this is handy when you debug a core dump of a
8250 multi-threaded program.
8251
8252 Each line in the backtrace shows the frame number and the function name.
8253 The program counter value is also shown---unless you use @code{set
8254 print address off}. The backtrace also shows the source file name and
8255 line number, as well as the arguments to the function. The program
8256 counter value is omitted if it is at the beginning of the code for that
8257 line number.
8258
8259 Here is an example of a backtrace. It was made with the command
8260 @samp{bt 3}, so it shows the innermost three frames.
8261
8262 @smallexample
8263 @group
8264 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8265 at builtin.c:993
8266 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8267 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8268 at macro.c:71
8269 (More stack frames follow...)
8270 @end group
8271 @end smallexample
8272
8273 @noindent
8274 The display for frame zero does not begin with a program counter
8275 value, indicating that your program has stopped at the beginning of the
8276 code for line @code{993} of @code{builtin.c}.
8277
8278 @noindent
8279 The value of parameter @code{data} in frame 1 has been replaced by
8280 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8281 only if it is a scalar (integer, pointer, enumeration, etc). See command
8282 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8283 on how to configure the way function parameter values are printed.
8284 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8285 what frame information is printed.
8286
8287 @cindex optimized out, in backtrace
8288 @cindex function call arguments, optimized out
8289 If your program was compiled with optimizations, some compilers will
8290 optimize away arguments passed to functions if those arguments are
8291 never used after the call. Such optimizations generate code that
8292 passes arguments through registers, but doesn't store those arguments
8293 in the stack frame. @value{GDBN} has no way of displaying such
8294 arguments in stack frames other than the innermost one. Here's what
8295 such a backtrace might look like:
8296
8297 @smallexample
8298 @group
8299 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8300 at builtin.c:993
8301 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8302 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8303 at macro.c:71
8304 (More stack frames follow...)
8305 @end group
8306 @end smallexample
8307
8308 @noindent
8309 The values of arguments that were not saved in their stack frames are
8310 shown as @samp{<optimized out>}.
8311
8312 If you need to display the values of such optimized-out arguments,
8313 either deduce that from other variables whose values depend on the one
8314 you are interested in, or recompile without optimizations.
8315
8316 @cindex backtrace beyond @code{main} function
8317 @cindex program entry point
8318 @cindex startup code, and backtrace
8319 Most programs have a standard user entry point---a place where system
8320 libraries and startup code transition into user code. For C this is
8321 @code{main}@footnote{
8322 Note that embedded programs (the so-called ``free-standing''
8323 environment) are not required to have a @code{main} function as the
8324 entry point. They could even have multiple entry points.}.
8325 When @value{GDBN} finds the entry function in a backtrace
8326 it will terminate the backtrace, to avoid tracing into highly
8327 system-specific (and generally uninteresting) code.
8328
8329 If you need to examine the startup code, or limit the number of levels
8330 in a backtrace, you can change this behavior:
8331
8332 @table @code
8333 @item set backtrace past-main
8334 @itemx set backtrace past-main on
8335 @anchor{set backtrace past-main}
8336 @kindex set backtrace
8337 Backtraces will continue past the user entry point.
8338
8339 @item set backtrace past-main off
8340 Backtraces will stop when they encounter the user entry point. This is the
8341 default.
8342
8343 @item show backtrace past-main
8344 @kindex show backtrace
8345 Display the current user entry point backtrace policy.
8346
8347 @item set backtrace past-entry
8348 @itemx set backtrace past-entry on
8349 @anchor{set backtrace past-entry}
8350 Backtraces will continue past the internal entry point of an application.
8351 This entry point is encoded by the linker when the application is built,
8352 and is likely before the user entry point @code{main} (or equivalent) is called.
8353
8354 @item set backtrace past-entry off
8355 Backtraces will stop when they encounter the internal entry point of an
8356 application. This is the default.
8357
8358 @item show backtrace past-entry
8359 Display the current internal entry point backtrace policy.
8360
8361 @item set backtrace limit @var{n}
8362 @itemx set backtrace limit 0
8363 @itemx set backtrace limit unlimited
8364 @anchor{set backtrace limit}
8365 @cindex backtrace limit
8366 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8367 or zero means unlimited levels.
8368
8369 @item show backtrace limit
8370 Display the current limit on backtrace levels.
8371 @end table
8372
8373 You can control how file names are displayed.
8374
8375 @table @code
8376 @item set filename-display
8377 @itemx set filename-display relative
8378 @cindex filename-display
8379 Display file names relative to the compilation directory. This is the default.
8380
8381 @item set filename-display basename
8382 Display only basename of a filename.
8383
8384 @item set filename-display absolute
8385 Display an absolute filename.
8386
8387 @item show filename-display
8388 Show the current way to display filenames.
8389 @end table
8390
8391 @node Selection
8392 @section Selecting a Frame
8393
8394 Most commands for examining the stack and other data in your program work on
8395 whichever stack frame is selected at the moment. Here are the commands for
8396 selecting a stack frame; all of them finish by printing a brief description
8397 of the stack frame just selected.
8398
8399 @table @code
8400 @kindex frame@r{, selecting}
8401 @kindex f @r{(@code{frame})}
8402 @item frame @r{[} @var{frame-selection-spec} @r{]}
8403 @item f @r{[} @var{frame-selection-spec} @r{]}
8404 The @command{frame} command allows different stack frames to be
8405 selected. The @var{frame-selection-spec} can be any of the following:
8406
8407 @table @code
8408 @kindex frame level
8409 @item @var{num}
8410 @item level @var{num}
8411 Select frame level @var{num}. Recall that frame zero is the innermost
8412 (currently executing) frame, frame one is the frame that called the
8413 innermost one, and so on. The highest level frame is usually the one
8414 for @code{main}.
8415
8416 As this is the most common method of navigating the frame stack, the
8417 string @command{level} can be omitted. For example, the following two
8418 commands are equivalent:
8419
8420 @smallexample
8421 (@value{GDBP}) frame 3
8422 (@value{GDBP}) frame level 3
8423 @end smallexample
8424
8425 @kindex frame address
8426 @item address @var{stack-address}
8427 Select the frame with stack address @var{stack-address}. The
8428 @var{stack-address} for a frame can be seen in the output of
8429 @command{info frame}, for example:
8430
8431 @smallexample
8432 (gdb) info frame
8433 Stack level 1, frame at 0x7fffffffda30:
8434 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8435 tail call frame, caller of frame at 0x7fffffffda30
8436 source language c++.
8437 Arglist at unknown address.
8438 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8439 @end smallexample
8440
8441 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8442 indicated by the line:
8443
8444 @smallexample
8445 Stack level 1, frame at 0x7fffffffda30:
8446 @end smallexample
8447
8448 @kindex frame function
8449 @item function @var{function-name}
8450 Select the stack frame for function @var{function-name}. If there are
8451 multiple stack frames for function @var{function-name} then the inner
8452 most stack frame is selected.
8453
8454 @kindex frame view
8455 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8456 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8457 viewed has stack address @var{stack-addr}, and optionally, a program
8458 counter address of @var{pc-addr}.
8459
8460 This is useful mainly if the chaining of stack frames has been
8461 damaged by a bug, making it impossible for @value{GDBN} to assign
8462 numbers properly to all frames. In addition, this can be useful
8463 when your program has multiple stacks and switches between them.
8464
8465 When viewing a frame outside the current backtrace using
8466 @command{frame view} then you can always return to the original
8467 stack using one of the previous stack frame selection instructions,
8468 for example @command{frame level 0}.
8469
8470 @end table
8471
8472 @kindex up
8473 @item up @var{n}
8474 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8475 numbers @var{n}, this advances toward the outermost frame, to higher
8476 frame numbers, to frames that have existed longer.
8477
8478 @kindex down
8479 @kindex do @r{(@code{down})}
8480 @item down @var{n}
8481 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8482 positive numbers @var{n}, this advances toward the innermost frame, to
8483 lower frame numbers, to frames that were created more recently.
8484 You may abbreviate @code{down} as @code{do}.
8485 @end table
8486
8487 All of these commands end by printing two lines of output describing the
8488 frame. The first line shows the frame number, the function name, the
8489 arguments, and the source file and line number of execution in that
8490 frame. The second line shows the text of that source line.
8491
8492 @need 1000
8493 For example:
8494
8495 @smallexample
8496 @group
8497 (@value{GDBP}) up
8498 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8499 at env.c:10
8500 10 read_input_file (argv[i]);
8501 @end group
8502 @end smallexample
8503
8504 After such a printout, the @code{list} command with no arguments
8505 prints ten lines centered on the point of execution in the frame.
8506 You can also edit the program at the point of execution with your favorite
8507 editing program by typing @code{edit}.
8508 @xref{List, ,Printing Source Lines},
8509 for details.
8510
8511 @table @code
8512 @kindex select-frame
8513 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8514 The @code{select-frame} command is a variant of @code{frame} that does
8515 not display the new frame after selecting it. This command is
8516 intended primarily for use in @value{GDBN} command scripts, where the
8517 output might be unnecessary and distracting. The
8518 @var{frame-selection-spec} is as for the @command{frame} command
8519 described in @ref{Selection, ,Selecting a Frame}.
8520
8521 @kindex down-silently
8522 @kindex up-silently
8523 @item up-silently @var{n}
8524 @itemx down-silently @var{n}
8525 These two commands are variants of @code{up} and @code{down},
8526 respectively; they differ in that they do their work silently, without
8527 causing display of the new frame. They are intended primarily for use
8528 in @value{GDBN} command scripts, where the output might be unnecessary and
8529 distracting.
8530 @end table
8531
8532 @node Frame Info
8533 @section Information About a Frame
8534
8535 There are several other commands to print information about the selected
8536 stack frame.
8537
8538 @table @code
8539 @item frame
8540 @itemx f
8541 When used without any argument, this command does not change which
8542 frame is selected, but prints a brief description of the currently
8543 selected stack frame. It can be abbreviated @code{f}. With an
8544 argument, this command is used to select a stack frame.
8545 @xref{Selection, ,Selecting a Frame}.
8546
8547 @kindex info frame
8548 @kindex info f @r{(@code{info frame})}
8549 @item info frame
8550 @itemx info f
8551 This command prints a verbose description of the selected stack frame,
8552 including:
8553
8554 @itemize @bullet
8555 @item
8556 the address of the frame
8557 @item
8558 the address of the next frame down (called by this frame)
8559 @item
8560 the address of the next frame up (caller of this frame)
8561 @item
8562 the language in which the source code corresponding to this frame is written
8563 @item
8564 the address of the frame's arguments
8565 @item
8566 the address of the frame's local variables
8567 @item
8568 the program counter saved in it (the address of execution in the caller frame)
8569 @item
8570 which registers were saved in the frame
8571 @end itemize
8572
8573 @noindent The verbose description is useful when
8574 something has gone wrong that has made the stack format fail to fit
8575 the usual conventions.
8576
8577 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8578 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8579 Print a verbose description of the frame selected by
8580 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8581 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8582 a Frame}). The selected frame remains unchanged by this command.
8583
8584 @kindex info args
8585 @item info args [-q]
8586 Print the arguments of the selected frame, each on a separate line.
8587
8588 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8589 printing header information and messages explaining why no argument
8590 have been printed.
8591
8592 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8593 Like @kbd{info args}, but only print the arguments selected
8594 with the provided regexp(s).
8595
8596 If @var{regexp} is provided, print only the arguments whose names
8597 match the regular expression @var{regexp}.
8598
8599 If @var{type_regexp} is provided, print only the arguments whose
8600 types, as printed by the @code{whatis} command, match
8601 the regular expression @var{type_regexp}.
8602 If @var{type_regexp} contains space(s), it should be enclosed in
8603 quote characters. If needed, use backslash to escape the meaning
8604 of special characters or quotes.
8605
8606 If both @var{regexp} and @var{type_regexp} are provided, an argument
8607 is printed only if its name matches @var{regexp} and its type matches
8608 @var{type_regexp}.
8609
8610 @item info locals [-q]
8611 @kindex info locals
8612 Print the local variables of the selected frame, each on a separate
8613 line. These are all variables (declared either static or automatic)
8614 accessible at the point of execution of the selected frame.
8615
8616 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8617 printing header information and messages explaining why no local variables
8618 have been printed.
8619
8620 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8621 Like @kbd{info locals}, but only print the local variables selected
8622 with the provided regexp(s).
8623
8624 If @var{regexp} is provided, print only the local variables whose names
8625 match the regular expression @var{regexp}.
8626
8627 If @var{type_regexp} is provided, print only the local variables whose
8628 types, as printed by the @code{whatis} command, match
8629 the regular expression @var{type_regexp}.
8630 If @var{type_regexp} contains space(s), it should be enclosed in
8631 quote characters. If needed, use backslash to escape the meaning
8632 of special characters or quotes.
8633
8634 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8635 is printed only if its name matches @var{regexp} and its type matches
8636 @var{type_regexp}.
8637
8638 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8639 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8640 For example, your program might use Resource Acquisition Is
8641 Initialization types (RAII) such as @code{lock_something_t}: each
8642 local variable of type @code{lock_something_t} automatically places a
8643 lock that is destroyed when the variable goes out of scope. You can
8644 then list all acquired locks in your program by doing
8645 @smallexample
8646 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8647 @end smallexample
8648 @noindent
8649 or the equivalent shorter form
8650 @smallexample
8651 tfaas i lo -q -t lock_something_t
8652 @end smallexample
8653
8654 @end table
8655
8656 @node Frame Apply
8657 @section Applying a Command to Several Frames.
8658 @kindex frame apply
8659 @cindex apply command to several frames
8660 @table @code
8661 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8662 The @code{frame apply} command allows you to apply the named
8663 @var{command} to one or more frames.
8664
8665 @table @code
8666 @item @code{all}
8667 Specify @code{all} to apply @var{command} to all frames.
8668
8669 @item @var{count}
8670 Use @var{count} to apply @var{command} to the innermost @var{count}
8671 frames, where @var{count} is a positive number.
8672
8673 @item @var{-count}
8674 Use @var{-count} to apply @var{command} to the outermost @var{count}
8675 frames, where @var{count} is a positive number.
8676
8677 @item @code{level}
8678 Use @code{level} to apply @var{command} to the set of frames identified
8679 by the @var{level} list. @var{level} is a frame level or a range of frame
8680 levels as @var{level1}-@var{level2}. The frame level is the number shown
8681 in the first field of the @samp{backtrace} command output.
8682 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8683 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8684
8685 @end table
8686
8687 Note that the frames on which @code{frame apply} applies a command are
8688 also influenced by the @code{set backtrace} settings such as @code{set
8689 backtrace past-main} and @code{set backtrace limit N}.
8690 @xref{Backtrace,,Backtraces}.
8691
8692 The @code{frame apply} command also supports a number of options that
8693 allow overriding relevant @code{set backtrace} settings:
8694
8695 @table @code
8696 @item -past-main [@code{on}|@code{off}]
8697 Whether backtraces should continue past @code{main}.
8698 Related setting: @ref{set backtrace past-main}.
8699
8700 @item -past-entry [@code{on}|@code{off}]
8701 Whether backtraces should continue past the entry point of a program.
8702 Related setting: @ref{set backtrace past-entry}.
8703 @end table
8704
8705 By default, @value{GDBN} displays some frame information before the
8706 output produced by @var{command}, and an error raised during the
8707 execution of a @var{command} will abort @code{frame apply}. The
8708 following options can be used to fine-tune these behaviors:
8709
8710 @table @code
8711 @item -c
8712 The flag @code{-c}, which stands for @samp{continue}, causes any
8713 errors in @var{command} to be displayed, and the execution of
8714 @code{frame apply} then continues.
8715 @item -s
8716 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8717 or empty output produced by a @var{command} to be silently ignored.
8718 That is, the execution continues, but the frame information and errors
8719 are not printed.
8720 @item -q
8721 The flag @code{-q} (@samp{quiet}) disables printing the frame
8722 information.
8723 @end table
8724
8725 The following example shows how the flags @code{-c} and @code{-s} are
8726 working when applying the command @code{p j} to all frames, where
8727 variable @code{j} can only be successfully printed in the outermost
8728 @code{#1 main} frame.
8729
8730 @smallexample
8731 @group
8732 (gdb) frame apply all p j
8733 #0 some_function (i=5) at fun.c:4
8734 No symbol "j" in current context.
8735 (gdb) frame apply all -c p j
8736 #0 some_function (i=5) at fun.c:4
8737 No symbol "j" in current context.
8738 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8739 $1 = 5
8740 (gdb) frame apply all -s p j
8741 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8742 $2 = 5
8743 (gdb)
8744 @end group
8745 @end smallexample
8746
8747 By default, @samp{frame apply}, prints the frame location
8748 information before the command output:
8749
8750 @smallexample
8751 @group
8752 (gdb) frame apply all p $sp
8753 #0 some_function (i=5) at fun.c:4
8754 $4 = (void *) 0xffffd1e0
8755 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8756 $5 = (void *) 0xffffd1f0
8757 (gdb)
8758 @end group
8759 @end smallexample
8760
8761 If the flag @code{-q} is given, no frame information is printed:
8762 @smallexample
8763 @group
8764 (gdb) frame apply all -q p $sp
8765 $12 = (void *) 0xffffd1e0
8766 $13 = (void *) 0xffffd1f0
8767 (gdb)
8768 @end group
8769 @end smallexample
8770
8771 @end table
8772
8773 @table @code
8774
8775 @kindex faas
8776 @cindex apply a command to all frames (ignoring errors and empty output)
8777 @item faas @var{command}
8778 Shortcut for @code{frame apply all -s @var{command}}.
8779 Applies @var{command} on all frames, ignoring errors and empty output.
8780
8781 It can for example be used to print a local variable or a function
8782 argument without knowing the frame where this variable or argument
8783 is, using:
8784 @smallexample
8785 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8786 @end smallexample
8787
8788 The @code{faas} command accepts the same options as the @code{frame
8789 apply} command. @xref{Frame Apply,,frame apply}.
8790
8791 Note that the command @code{tfaas @var{command}} applies @var{command}
8792 on all frames of all threads. See @xref{Threads,,Threads}.
8793 @end table
8794
8795
8796 @node Frame Filter Management
8797 @section Management of Frame Filters.
8798 @cindex managing frame filters
8799
8800 Frame filters are Python based utilities to manage and decorate the
8801 output of frames. @xref{Frame Filter API}, for further information.
8802
8803 Managing frame filters is performed by several commands available
8804 within @value{GDBN}, detailed here.
8805
8806 @table @code
8807 @kindex info frame-filter
8808 @item info frame-filter
8809 Print a list of installed frame filters from all dictionaries, showing
8810 their name, priority and enabled status.
8811
8812 @kindex disable frame-filter
8813 @anchor{disable frame-filter all}
8814 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8815 Disable a frame filter in the dictionary matching
8816 @var{filter-dictionary} and @var{filter-name}. The
8817 @var{filter-dictionary} may be @code{all}, @code{global},
8818 @code{progspace}, or the name of the object file where the frame filter
8819 dictionary resides. When @code{all} is specified, all frame filters
8820 across all dictionaries are disabled. The @var{filter-name} is the name
8821 of the frame filter and is used when @code{all} is not the option for
8822 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8823 may be enabled again later.
8824
8825 @kindex enable frame-filter
8826 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8827 Enable a frame filter in the dictionary matching
8828 @var{filter-dictionary} and @var{filter-name}. The
8829 @var{filter-dictionary} may be @code{all}, @code{global},
8830 @code{progspace} or the name of the object file where the frame filter
8831 dictionary resides. When @code{all} is specified, all frame filters across
8832 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8833 filter and is used when @code{all} is not the option for
8834 @var{filter-dictionary}.
8835
8836 Example:
8837
8838 @smallexample
8839 (gdb) info frame-filter
8840
8841 global frame-filters:
8842 Priority Enabled Name
8843 1000 No PrimaryFunctionFilter
8844 100 Yes Reverse
8845
8846 progspace /build/test frame-filters:
8847 Priority Enabled Name
8848 100 Yes ProgspaceFilter
8849
8850 objfile /build/test frame-filters:
8851 Priority Enabled Name
8852 999 Yes BuildProgramFilter
8853
8854 (gdb) disable frame-filter /build/test BuildProgramFilter
8855 (gdb) info frame-filter
8856
8857 global frame-filters:
8858 Priority Enabled Name
8859 1000 No PrimaryFunctionFilter
8860 100 Yes Reverse
8861
8862 progspace /build/test frame-filters:
8863 Priority Enabled Name
8864 100 Yes ProgspaceFilter
8865
8866 objfile /build/test frame-filters:
8867 Priority Enabled Name
8868 999 No BuildProgramFilter
8869
8870 (gdb) enable frame-filter global PrimaryFunctionFilter
8871 (gdb) info frame-filter
8872
8873 global frame-filters:
8874 Priority Enabled Name
8875 1000 Yes PrimaryFunctionFilter
8876 100 Yes Reverse
8877
8878 progspace /build/test frame-filters:
8879 Priority Enabled Name
8880 100 Yes ProgspaceFilter
8881
8882 objfile /build/test frame-filters:
8883 Priority Enabled Name
8884 999 No BuildProgramFilter
8885 @end smallexample
8886
8887 @kindex set frame-filter priority
8888 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8889 Set the @var{priority} of a frame filter in the dictionary matching
8890 @var{filter-dictionary}, and the frame filter name matching
8891 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8892 @code{progspace} or the name of the object file where the frame filter
8893 dictionary resides. The @var{priority} is an integer.
8894
8895 @kindex show frame-filter priority
8896 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8897 Show the @var{priority} of a frame filter in the dictionary matching
8898 @var{filter-dictionary}, and the frame filter name matching
8899 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8900 @code{progspace} or the name of the object file where the frame filter
8901 dictionary resides.
8902
8903 Example:
8904
8905 @smallexample
8906 (gdb) info frame-filter
8907
8908 global frame-filters:
8909 Priority Enabled Name
8910 1000 Yes PrimaryFunctionFilter
8911 100 Yes Reverse
8912
8913 progspace /build/test frame-filters:
8914 Priority Enabled Name
8915 100 Yes ProgspaceFilter
8916
8917 objfile /build/test frame-filters:
8918 Priority Enabled Name
8919 999 No BuildProgramFilter
8920
8921 (gdb) set frame-filter priority global Reverse 50
8922 (gdb) info frame-filter
8923
8924 global frame-filters:
8925 Priority Enabled Name
8926 1000 Yes PrimaryFunctionFilter
8927 50 Yes Reverse
8928
8929 progspace /build/test frame-filters:
8930 Priority Enabled Name
8931 100 Yes ProgspaceFilter
8932
8933 objfile /build/test frame-filters:
8934 Priority Enabled Name
8935 999 No BuildProgramFilter
8936 @end smallexample
8937 @end table
8938
8939 @node Source
8940 @chapter Examining Source Files
8941
8942 @value{GDBN} can print parts of your program's source, since the debugging
8943 information recorded in the program tells @value{GDBN} what source files were
8944 used to build it. When your program stops, @value{GDBN} spontaneously prints
8945 the line where it stopped. Likewise, when you select a stack frame
8946 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8947 execution in that frame has stopped. You can print other portions of
8948 source files by explicit command.
8949
8950 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8951 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8952 @value{GDBN} under @sc{gnu} Emacs}.
8953
8954 @menu
8955 * List:: Printing source lines
8956 * Location Specifications:: How to specify code locations
8957 * Edit:: Editing source files
8958 * Search:: Searching source files
8959 * Source Path:: Specifying source directories
8960 * Machine Code:: Source and machine code
8961 * Disable Reading Source:: Disable Reading Source Code
8962 @end menu
8963
8964 @node List
8965 @section Printing Source Lines
8966
8967 @kindex list
8968 @kindex l @r{(@code{list})}
8969 To print lines from a source file, use the @code{list} command
8970 (abbreviated @code{l}). By default, ten lines are printed.
8971 There are several ways to specify what part of the file you want to
8972 print; see @ref{Location Specifications}, for the full list.
8973
8974 Here are the forms of the @code{list} command most commonly used:
8975
8976 @table @code
8977 @item list @var{linenum}
8978 Print lines centered around line number @var{linenum} in the
8979 current source file.
8980
8981 @item list @var{function}
8982 Print lines centered around the beginning of function
8983 @var{function}.
8984
8985 @item list
8986 Print more lines. If the last lines printed were printed with a
8987 @code{list} command, this prints lines following the last lines
8988 printed; however, if the last line printed was a solitary line printed
8989 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8990 Stack}), this prints lines centered around that line.
8991
8992 @item list -
8993 Print lines just before the lines last printed.
8994 @end table
8995
8996 @cindex @code{list}, how many lines to display
8997 By default, @value{GDBN} prints ten source lines with any of these forms of
8998 the @code{list} command. You can change this using @code{set listsize}:
8999
9000 @table @code
9001 @kindex set listsize
9002 @item set listsize @var{count}
9003 @itemx set listsize unlimited
9004 Make the @code{list} command display @var{count} source lines (unless
9005 the @code{list} argument explicitly specifies some other number).
9006 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
9007
9008 @kindex show listsize
9009 @item show listsize
9010 Display the number of lines that @code{list} prints.
9011 @end table
9012
9013 Repeating a @code{list} command with @key{RET} discards the argument,
9014 so it is equivalent to typing just @code{list}. This is more useful
9015 than listing the same lines again. An exception is made for an
9016 argument of @samp{-}; that argument is preserved in repetition so that
9017 each repetition moves up in the source file.
9018
9019 In general, the @code{list} command expects you to supply zero, one or
9020 two location specs. These location specs are interpreted to resolve
9021 to source code lines; there are several ways of writing them
9022 (@pxref{Location Specifications}), but the effect is always to resolve
9023 to some source lines to display.
9024
9025 Here is a complete description of the possible arguments for @code{list}:
9026
9027 @table @code
9028 @item list @var{locspec}
9029 Print lines centered around the line or lines of all the code
9030 locations that result from resolving @var{locspec}.
9031
9032 @item list @var{first},@var{last}
9033 Print lines from @var{first} to @var{last}. Both arguments are
9034 location specs. When a @code{list} command has two location specs,
9035 and the source file of the second location spec is omitted, this
9036 refers to the same source file as the first location spec. If either
9037 @var{first} or @var{last} resolve to more than one source line in the
9038 program, then the list command shows the list of resolved source
9039 lines and does not proceed with the source code listing.
9040
9041 @item list ,@var{last}
9042 Print lines ending with @var{last}.
9043
9044 Likewise, if @var{last} resolves to more than one source line in the
9045 program, then the list command prints the list of resolved source
9046 lines and does not proceed with the source code listing.
9047
9048 @item list @var{first},
9049 Print lines starting with @var{first}.
9050
9051 @item list +
9052 Print lines just after the lines last printed.
9053
9054 @item list -
9055 Print lines just before the lines last printed.
9056
9057 @item list
9058 As described in the preceding table.
9059 @end table
9060
9061 @node Location Specifications
9062 @section Location Specifications
9063 @cindex specifying location
9064 @cindex locspec
9065 @cindex source location
9066 @cindex code location
9067
9068 @cindex location spec
9069 Several @value{GDBN} commands accept arguments that specify a location
9070 or locations of your program's code. Many times locations are
9071 specified using a source line number, but they can also be specified
9072 by a function name, an address, a label, etc. The different
9073 forms of specifying a location that @value{GDBN} recognizes are
9074 collectively known as forms of @dfn{location specification}, or
9075 @dfn{location spec}. This section documents the forms of specifying
9076 locations that @value{GDBN} recognizes.
9077
9078 @cindex location resolution
9079 @cindex resolution of location spec
9080 When you specify a location, @value{GDBN} needs to find the place in
9081 your program, known as @dfn{code location}, that corresponds to the
9082 given location spec. We call this process of finding actual code
9083 locations corresponding to a location spec @dfn{location resolution}.
9084
9085 A concrete code location in your program is uniquely identifiable by a
9086 set of several attributes: its source line number, the name of its
9087 source file, the fully-qualified and prototyped function in which it
9088 is defined, and an instruction address. Because each inferior has its
9089 own address space, the inferior number is also a necessary part of
9090 these attributes.
9091
9092 By contrast, location specs you type will many times omit some of
9093 these attributes. For example, it is customary to specify just the
9094 source line number to mean a line in the current source file, or
9095 specify just the basename of the file, omitting its directories. In
9096 other words, a location spec is usually incomplete, a kind of
9097 blueprint, and @value{GDBN} needs to complete the missing attributes
9098 by using the implied defaults, and by considering the source code and
9099 the debug information available to it. This is what location
9100 resolution is about.
9101
9102 The resolution of an incomplete location spec can produce more than a
9103 single code location, if the spec doesn't allow distinguishing between
9104 them. Here are some examples of situations that result in a location
9105 spec matching multiple code locations in your program:
9106
9107 @itemize @bullet
9108 @item
9109 The location spec specifies a function name, and there are several
9110 functions in the program which have that name. (To distinguish
9111 between them, you can specify a fully-qualified and prototyped
9112 function name, such as @code{A::func(int)} instead of just
9113 @code{func}.)
9114
9115 @item
9116 The location spec specifies a source file name, and there are several
9117 source files in the program that share the same name, for example
9118 several files with the same basename in different subdirectories. (To
9119 distinguish between them, specify enough leading directories with the
9120 file name.)
9121
9122 @item
9123 For a C@t{++} constructor, the @value{NGCC} compiler generates several
9124 instances of the function body, used in different cases, but their
9125 source-level names are identical.
9126
9127 @item
9128 For a C@t{++} template function, a given line in the function can
9129 correspond to any number of instantiations.
9130
9131 @item
9132 For an inlined function, a given source line can correspond to several
9133 actual code locations with that function's inlined code.
9134 @end itemize
9135
9136 Resolution of a location spec can also fail to produce a complete code
9137 location, or even fail to produce any code location. Here are some
9138 examples of such situations:
9139
9140 @itemize @bullet
9141 @item
9142 Some parts of the program lack detailed enough debug info, so the
9143 resolved code location lacks some attributes, like source file name
9144 and line number, leaving just the instruction address and perhaps also
9145 a function name. Such an incomplete code location is only usable in
9146 contexts that work with addresses and/or function names. Some
9147 commands can only work with complete code locations.
9148
9149 @item
9150 The location spec specifies a function name, and there are no
9151 functions in the program by that name, or they only exist in a
9152 yet-unloaded shared library.
9153
9154 @item
9155 The location spec specifies a source file name, and there are no
9156 source files in the program by that name, or they only exist in a
9157 yet-unloaded shared library.
9158
9159 @item
9160 The location spec specifies both a source file name and a source line
9161 number, and even though there are source files in the program that
9162 match the file name, none of those files has the specified line
9163 number.
9164 @end itemize
9165
9166 Locations may be specified using three different formats: linespec
9167 locations, explicit locations, or address locations. The following
9168 subsections describe these formats.
9169
9170 @menu
9171 * Linespec Locations:: Linespec locations
9172 * Explicit Locations:: Explicit locations
9173 * Address Locations:: Address locations
9174 @end menu
9175
9176 @node Linespec Locations
9177 @subsection Linespec Locations
9178 @cindex linespec locations
9179
9180 A @dfn{linespec} is a colon-separated list of source location parameters such
9181 as file name, function name, etc. Here are all the different ways of
9182 specifying a linespec:
9183
9184 @table @code
9185 @item @var{linenum}
9186 Specifies the line number @var{linenum} of the current source file.
9187
9188 @item -@var{offset}
9189 @itemx +@var{offset}
9190 Specifies the line @var{offset} lines before or after the @dfn{current
9191 line}. For the @code{list} command, the current line is the last one
9192 printed; for the breakpoint commands, this is the line at which
9193 execution stopped in the currently selected @dfn{stack frame}
9194 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9195 used as the second of the two linespecs in a @code{list} command,
9196 this specifies the line @var{offset} lines up or down from the first
9197 linespec.
9198
9199 @item @var{filename}:@var{linenum}
9200 Specifies the line @var{linenum} in the source file @var{filename}.
9201 If @var{filename} is a relative file name, then it will match any
9202 source file name with the same trailing components. For example, if
9203 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9204 name of @file{/build/trunk/gcc/expr.c}, but not
9205 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9206
9207 @item @var{function}
9208 Specifies the line that begins the body of the function @var{function}.
9209 For example, in C, this is the line with the open brace.
9210
9211 By default, in C@t{++} and Ada, @var{function} is interpreted as
9212 specifying all functions named @var{function} in all scopes. For
9213 C@t{++}, this means in all namespaces and classes. For Ada, this
9214 means in all packages.
9215
9216 For example, assuming a program with C@t{++} symbols named
9217 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9218 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9219
9220 Commands that accept a linespec let you override this with the
9221 @code{-qualified} option. For example, @w{@kbd{break -qualified
9222 func}} sets a breakpoint on a free-function named @code{func} ignoring
9223 any C@t{++} class methods and namespace functions called @code{func}.
9224
9225 @xref{Explicit Locations}.
9226
9227 @item @var{function}:@var{label}
9228 Specifies the line where @var{label} appears in @var{function}.
9229
9230 @item @var{filename}:@var{function}
9231 Specifies the line that begins the body of the function @var{function}
9232 in the file @var{filename}. You only need the file name with a
9233 function name to avoid ambiguity when there are identically named
9234 functions in different source files.
9235
9236 @item @var{label}
9237 Specifies the line at which the label named @var{label} appears
9238 in the function corresponding to the currently selected stack frame.
9239 If there is no current selected stack frame (for instance, if the inferior
9240 is not running), then @value{GDBN} will not search for a label.
9241
9242 @cindex breakpoint at static probe point
9243 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9244 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9245 applications to embed static probes. @xref{Static Probe Points}, for more
9246 information on finding and using static probes. This form of linespec
9247 specifies the location of such a static probe.
9248
9249 If @var{objfile} is given, only probes coming from that shared library
9250 or executable matching @var{objfile} as a regular expression are considered.
9251 If @var{provider} is given, then only probes from that provider are considered.
9252 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9253 each one of those probes.
9254 @end table
9255
9256 @node Explicit Locations
9257 @subsection Explicit Locations
9258 @cindex explicit locations
9259
9260 @dfn{Explicit locations} allow the user to directly specify the source
9261 location's parameters using option-value pairs.
9262
9263 Explicit locations are useful when several functions, labels, or
9264 file names have the same name (base name for files) in the program's
9265 sources. In these cases, explicit locations point to the source
9266 line you meant more accurately and unambiguously. Also, using
9267 explicit locations might be faster in large programs.
9268
9269 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9270 defined in the file named @file{foo} or the label @code{bar} in a function
9271 named @code{foo}. @value{GDBN} must search either the file system or
9272 the symbol table to know.
9273
9274 The list of valid explicit location options is summarized in the
9275 following table:
9276
9277 @table @code
9278 @item -source @var{filename}
9279 The value specifies the source file name. To differentiate between
9280 files with the same base name, prepend as many directories as is necessary
9281 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9282 @value{GDBN} will use the first file it finds with the given base
9283 name. This option requires the use of either @code{-function} or @code{-line}.
9284
9285 @item -function @var{function}
9286 The value specifies the name of a function. Operations
9287 on function locations unmodified by other options (such as @code{-label}
9288 or @code{-line}) refer to the line that begins the body of the function.
9289 In C, for example, this is the line with the open brace.
9290
9291 By default, in C@t{++} and Ada, @var{function} is interpreted as
9292 specifying all functions named @var{function} in all scopes. For
9293 C@t{++}, this means in all namespaces and classes. For Ada, this
9294 means in all packages.
9295
9296 For example, assuming a program with C@t{++} symbols named
9297 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9298 -function func}} and @w{@kbd{break -function B::func}} set a
9299 breakpoint on both symbols.
9300
9301 You can use the @kbd{-qualified} flag to override this (see below).
9302
9303 @item -qualified
9304
9305 This flag makes @value{GDBN} interpret a function name specified with
9306 @kbd{-function} as a complete fully-qualified name.
9307
9308 For example, assuming a C@t{++} program with symbols named
9309 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9310 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9311
9312 (Note: the @kbd{-qualified} option can precede a linespec as well
9313 (@pxref{Linespec Locations}), so the particular example above could be
9314 simplified as @w{@kbd{break -qualified B::func}}.)
9315
9316 @item -label @var{label}
9317 The value specifies the name of a label. When the function
9318 name is not specified, the label is searched in the function of the currently
9319 selected stack frame.
9320
9321 @item -line @var{number}
9322 The value specifies a line offset for the location. The offset may either
9323 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9324 the command. When specified without any other options, the line offset is
9325 relative to the current line.
9326 @end table
9327
9328 Explicit location options may be abbreviated by omitting any non-unique
9329 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9330
9331 @node Address Locations
9332 @subsection Address Locations
9333 @cindex address locations
9334
9335 @dfn{Address locations} indicate a specific program address. They have
9336 the generalized form *@var{address}.
9337
9338 For line-oriented commands, such as @code{list} and @code{edit}, this
9339 specifies a source line that contains @var{address}. For @code{break} and
9340 other breakpoint-oriented commands, this can be used to set breakpoints in
9341 parts of your program which do not have debugging information or
9342 source files.
9343
9344 Here @var{address} may be any expression valid in the current working
9345 language (@pxref{Languages, working language}) that specifies a code
9346 address. In addition, as a convenience, @value{GDBN} extends the
9347 semantics of expressions used in locations to cover several situations
9348 that frequently occur during debugging. Here are the various forms
9349 of @var{address}:
9350
9351 @table @code
9352 @item @var{expression}
9353 Any expression valid in the current working language.
9354
9355 @item @var{funcaddr}
9356 An address of a function or procedure derived from its name. In C,
9357 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9358 simply the function's name @var{function} (and actually a special case
9359 of a valid expression). In Pascal and Modula-2, this is
9360 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9361 (although the Pascal form also works).
9362
9363 This form specifies the address of the function's first instruction,
9364 before the stack frame and arguments have been set up.
9365
9366 @item '@var{filename}':@var{funcaddr}
9367 Like @var{funcaddr} above, but also specifies the name of the source
9368 file explicitly. This is useful if the name of the function does not
9369 specify the function unambiguously, e.g., if there are several
9370 functions with identical names in different source files.
9371 @end table
9372
9373 @node Edit
9374 @section Editing Source Files
9375 @cindex editing source files
9376
9377 @kindex edit
9378 @kindex e @r{(@code{edit})}
9379 To edit the lines in a source file, use the @code{edit} command.
9380 The editing program of your choice
9381 is invoked with the current line set to
9382 the active line in the program.
9383 Alternatively, there are several ways to specify what part of the file you
9384 want to print if you want to see other parts of the program:
9385
9386 @table @code
9387 @item edit @var{locspec}
9388 Edit the source file of the code location that results from resolving
9389 @code{locspec}. Editing starts at the source file and source line
9390 @code{locspec} resolves to.
9391 @xref{Location Specifications}, for all the possible forms of the
9392 @var{locspec} argument.
9393
9394 If @code{locspec} resolves to more than one source line in your
9395 program, then the command prints the list of resolved source lines and
9396 does not proceed with the editing.
9397
9398 Here are the forms of the @code{edit} command most commonly used:
9399
9400 @table @code
9401 @item edit @var{number}
9402 Edit the current source file with @var{number} as the active line number.
9403
9404 @item edit @var{function}
9405 Edit the file containing @var{function} at the beginning of its definition.
9406 @end table
9407
9408 @end table
9409
9410 @subsection Choosing your Editor
9411 You can customize @value{GDBN} to use any editor you want
9412 @footnote{
9413 The only restriction is that your editor (say @code{ex}), recognizes the
9414 following command-line syntax:
9415 @smallexample
9416 ex +@var{number} file
9417 @end smallexample
9418 The optional numeric value +@var{number} specifies the number of the line in
9419 the file where to start editing.}.
9420 By default, it is @file{@value{EDITOR}}, but you can change this
9421 by setting the environment variable @env{EDITOR} before using
9422 @value{GDBN}. For example, to configure @value{GDBN} to use the
9423 @code{vi} editor, you could use these commands with the @code{sh} shell:
9424 @smallexample
9425 EDITOR=/usr/bin/vi
9426 export EDITOR
9427 gdb @dots{}
9428 @end smallexample
9429 or in the @code{csh} shell,
9430 @smallexample
9431 setenv EDITOR /usr/bin/vi
9432 gdb @dots{}
9433 @end smallexample
9434
9435 @node Search
9436 @section Searching Source Files
9437 @cindex searching source files
9438
9439 There are two commands for searching through the current source file for a
9440 regular expression.
9441
9442 @table @code
9443 @kindex search
9444 @kindex forward-search
9445 @kindex fo @r{(@code{forward-search})}
9446 @item forward-search @var{regexp}
9447 @itemx search @var{regexp}
9448 The command @samp{forward-search @var{regexp}} checks each line,
9449 starting with the one following the last line listed, for a match for
9450 @var{regexp}. It lists the line that is found. You can use the
9451 synonym @samp{search @var{regexp}} or abbreviate the command name as
9452 @code{fo}.
9453
9454 @kindex reverse-search
9455 @item reverse-search @var{regexp}
9456 The command @samp{reverse-search @var{regexp}} checks each line, starting
9457 with the one before the last line listed and going backward, for a match
9458 for @var{regexp}. It lists the line that is found. You can abbreviate
9459 this command as @code{rev}.
9460 @end table
9461
9462 @node Source Path
9463 @section Specifying Source Directories
9464
9465 @cindex source path
9466 @cindex directories for source files
9467 Executable programs sometimes do not record the directories of the source
9468 files from which they were compiled, just the names. Even when they do,
9469 the directories could be moved between the compilation and your debugging
9470 session. @value{GDBN} has a list of directories to search for source files;
9471 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9472 it tries all the directories in the list, in the order they are present
9473 in the list, until it finds a file with the desired name.
9474
9475 For example, suppose an executable references the file
9476 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9477 directory, and the @dfn{source path} is @file{/mnt/cross}.
9478 @value{GDBN} would look for the source file in the following
9479 locations:
9480
9481 @enumerate
9482
9483 @item @file{/usr/src/foo-1.0/lib/foo.c}
9484 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9485 @item @file{/mnt/cross/foo.c}
9486
9487 @end enumerate
9488
9489 If the source file is not present at any of the above locations then
9490 an error is printed. @value{GDBN} does not look up the parts of the
9491 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9492 Likewise, the subdirectories of the source path are not searched: if
9493 the source path is @file{/mnt/cross}, and the binary refers to
9494 @file{foo.c}, @value{GDBN} would not find it under
9495 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9496
9497 Plain file names, relative file names with leading directories, file
9498 names containing dots, etc.@: are all treated as described above,
9499 except that non-absolute file names are not looked up literally. If
9500 the @dfn{source path} is @file{/mnt/cross}, the source file is
9501 recorded as @file{../lib/foo.c}, and no compilation directory is
9502 recorded, then @value{GDBN} will search in the following locations:
9503
9504 @enumerate
9505
9506 @item @file{/mnt/cross/../lib/foo.c}
9507 @item @file{/mnt/cross/foo.c}
9508
9509 @end enumerate
9510
9511 @kindex cdir
9512 @kindex cwd
9513 @vindex $cdir@r{, convenience variable}
9514 @vindex $cwd@r{, convenience variable}
9515 @cindex compilation directory
9516 @cindex current directory
9517 @cindex working directory
9518 @cindex directory, current
9519 @cindex directory, compilation
9520 The @dfn{source path} will always include two special entries
9521 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9522 (if one is recorded) and the current working directory respectively.
9523
9524 @samp{$cdir} causes @value{GDBN} to search within the compilation
9525 directory, if one is recorded in the debug information. If no
9526 compilation directory is recorded in the debug information then
9527 @samp{$cdir} is ignored.
9528
9529 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9530 current working directory as it changes during your @value{GDBN}
9531 session, while the latter is immediately expanded to the current
9532 directory at the time you add an entry to the source path.
9533
9534 If a compilation directory is recorded in the debug information, and
9535 @value{GDBN} has not found the source file after the first search
9536 using @dfn{source path}, then @value{GDBN} will combine the
9537 compilation directory and the filename, and then search for the source
9538 file again using the @dfn{source path}.
9539
9540 For example, if the executable records the source file as
9541 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9542 recorded as @file{/project/build}, and the @dfn{source path} is
9543 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9544 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9545 search for the source file in the following locations:
9546
9547 @enumerate
9548
9549 @item @file{/usr/src/foo-1.0/lib/foo.c}
9550 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9551 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9552 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9553 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9554 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9555 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9556 @item @file{/mnt/cross/foo.c}
9557 @item @file{/project/build/foo.c}
9558 @item @file{/home/user/foo.c}
9559
9560 @end enumerate
9561
9562 If the file name in the previous example had been recorded in the
9563 executable as a relative path rather than an absolute path, then the
9564 first look up would not have occurred, but all of the remaining steps
9565 would be similar.
9566
9567 When searching for source files on MS-DOS and MS-Windows, where
9568 absolute paths start with a drive letter (e.g.@:
9569 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9570 from the file name before appending it to a search directory from
9571 @dfn{source path}; for instance if the executable references the
9572 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9573 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9574 locations for the source file:
9575
9576 @enumerate
9577
9578 @item @file{C:/project/foo.c}
9579 @item @file{D:/mnt/cross/project/foo.c}
9580 @item @file{D:/mnt/cross/foo.c}
9581
9582 @end enumerate
9583
9584 Note that the executable search path is @emph{not} used to locate the
9585 source files.
9586
9587 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9588 any information it has cached about where source files are found and where
9589 each line is in the file.
9590
9591 @kindex directory
9592 @kindex dir
9593 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9594 and @samp{$cwd}, in that order.
9595 To add other directories, use the @code{directory} command.
9596
9597 The search path is used to find both program source files and @value{GDBN}
9598 script files (read using the @samp{-command} option and @samp{source} command).
9599
9600 In addition to the source path, @value{GDBN} provides a set of commands
9601 that manage a list of source path substitution rules. A @dfn{substitution
9602 rule} specifies how to rewrite source directories stored in the program's
9603 debug information in case the sources were moved to a different
9604 directory between compilation and debugging. A rule is made of
9605 two strings, the first specifying what needs to be rewritten in
9606 the path, and the second specifying how it should be rewritten.
9607 In @ref{set substitute-path}, we name these two parts @var{from} and
9608 @var{to} respectively. @value{GDBN} does a simple string replacement
9609 of @var{from} with @var{to} at the start of the directory part of the
9610 source file name, and uses that result instead of the original file
9611 name to look up the sources.
9612
9613 Using the previous example, suppose the @file{foo-1.0} tree has been
9614 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9615 @value{GDBN} to replace @file{/usr/src} in all source path names with
9616 @file{/mnt/cross}. The first lookup will then be
9617 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9618 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9619 substitution rule, use the @code{set substitute-path} command
9620 (@pxref{set substitute-path}).
9621
9622 To avoid unexpected substitution results, a rule is applied only if the
9623 @var{from} part of the directory name ends at a directory separator.
9624 For instance, a rule substituting @file{/usr/source} into
9625 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9626 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9627 is applied only at the beginning of the directory name, this rule will
9628 not be applied to @file{/root/usr/source/baz.c} either.
9629
9630 In many cases, you can achieve the same result using the @code{directory}
9631 command. However, @code{set substitute-path} can be more efficient in
9632 the case where the sources are organized in a complex tree with multiple
9633 subdirectories. With the @code{directory} command, you need to add each
9634 subdirectory of your project. If you moved the entire tree while
9635 preserving its internal organization, then @code{set substitute-path}
9636 allows you to direct the debugger to all the sources with one single
9637 command.
9638
9639 @code{set substitute-path} is also more than just a shortcut command.
9640 The source path is only used if the file at the original location no
9641 longer exists. On the other hand, @code{set substitute-path} modifies
9642 the debugger behavior to look at the rewritten location instead. So, if
9643 for any reason a source file that is not relevant to your executable is
9644 located at the original location, a substitution rule is the only
9645 method available to point @value{GDBN} at the new location.
9646
9647 @cindex @samp{--with-relocated-sources}
9648 @cindex default source path substitution
9649 You can configure a default source path substitution rule by
9650 configuring @value{GDBN} with the
9651 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9652 should be the name of a directory under @value{GDBN}'s configured
9653 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9654 directory names in debug information under @var{dir} will be adjusted
9655 automatically if the installed @value{GDBN} is moved to a new
9656 location. This is useful if @value{GDBN}, libraries or executables
9657 with debug information and corresponding source code are being moved
9658 together.
9659
9660 @table @code
9661 @item directory @var{dirname} @dots{}
9662 @item dir @var{dirname} @dots{}
9663 Add directory @var{dirname} to the front of the source path. Several
9664 directory names may be given to this command, separated by @samp{:}
9665 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9666 part of absolute file names) or
9667 whitespace. You may specify a directory that is already in the source
9668 path; this moves it forward, so @value{GDBN} searches it sooner.
9669
9670 The special strings @samp{$cdir} (to refer to the compilation
9671 directory, if one is recorded), and @samp{$cwd} (to refer to the
9672 current working directory) can also be included in the list of
9673 directories @var{dirname}. Though these will already be in the source
9674 path they will be moved forward in the list so @value{GDBN} searches
9675 them sooner.
9676
9677 @item directory
9678 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9679
9680 @c RET-repeat for @code{directory} is explicitly disabled, but since
9681 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9682
9683 @item set directories @var{path-list}
9684 @kindex set directories
9685 Set the source path to @var{path-list}.
9686 @samp{$cdir:$cwd} are added if missing.
9687
9688 @item show directories
9689 @kindex show directories
9690 Print the source path: show which directories it contains.
9691
9692 @anchor{set substitute-path}
9693 @item set substitute-path @var{from} @var{to}
9694 @kindex set substitute-path
9695 Define a source path substitution rule, and add it at the end of the
9696 current list of existing substitution rules. If a rule with the same
9697 @var{from} was already defined, then the old rule is also deleted.
9698
9699 For example, if the file @file{/foo/bar/baz.c} was moved to
9700 @file{/mnt/cross/baz.c}, then the command
9701
9702 @smallexample
9703 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9704 @end smallexample
9705
9706 @noindent
9707 will tell @value{GDBN} to replace @samp{/foo/bar} with
9708 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9709 @file{baz.c} even though it was moved.
9710
9711 In the case when more than one substitution rule have been defined,
9712 the rules are evaluated one by one in the order where they have been
9713 defined. The first one matching, if any, is selected to perform
9714 the substitution.
9715
9716 For instance, if we had entered the following commands:
9717
9718 @smallexample
9719 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9720 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9721 @end smallexample
9722
9723 @noindent
9724 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9725 @file{/mnt/include/defs.h} by using the first rule. However, it would
9726 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9727 @file{/mnt/src/lib/foo.c}.
9728
9729
9730 @item unset substitute-path [path]
9731 @kindex unset substitute-path
9732 If a path is specified, search the current list of substitution rules
9733 for a rule that would rewrite that path. Delete that rule if found.
9734 A warning is emitted by the debugger if no rule could be found.
9735
9736 If no path is specified, then all substitution rules are deleted.
9737
9738 @item show substitute-path [path]
9739 @kindex show substitute-path
9740 If a path is specified, then print the source path substitution rule
9741 which would rewrite that path, if any.
9742
9743 If no path is specified, then print all existing source path substitution
9744 rules.
9745
9746 @end table
9747
9748 If your source path is cluttered with directories that are no longer of
9749 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9750 versions of source. You can correct the situation as follows:
9751
9752 @enumerate
9753 @item
9754 Use @code{directory} with no argument to reset the source path to its default value.
9755
9756 @item
9757 Use @code{directory} with suitable arguments to reinstall the
9758 directories you want in the source path. You can add all the
9759 directories in one command.
9760 @end enumerate
9761
9762 @node Machine Code
9763 @section Source and Machine Code
9764 @cindex source line and its code address
9765
9766 You can use the command @code{info line} to map source lines to program
9767 addresses (and vice versa), and the command @code{disassemble} to display
9768 a range of addresses as machine instructions. You can use the command
9769 @code{set disassemble-next-line} to set whether to disassemble next
9770 source line when execution stops. When run under @sc{gnu} Emacs
9771 mode, the @code{info line} command causes the arrow to point to the
9772 line specified. Also, @code{info line} prints addresses in symbolic form as
9773 well as hex.
9774
9775 @table @code
9776 @kindex info line
9777 @item info line
9778 @itemx info line @var{locspec}
9779 Print the starting and ending addresses of the compiled code for the
9780 source lines of the code locations that result from resolving
9781 @var{locspec}. @xref{Location Specifications}, for the various forms
9782 of @var{locspec}.
9783 With no @var{locspec}, information about the current source line is
9784 printed.
9785 @end table
9786
9787 For example, we can use @code{info line} to discover the location of
9788 the object code for the first line of function
9789 @code{m4_changequote}:
9790
9791 @smallexample
9792 (@value{GDBP}) info line m4_changequote
9793 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9794 ends at 0x6350 <m4_changequote+4>.
9795 @end smallexample
9796
9797 @noindent
9798 @cindex code address and its source line
9799 We can also inquire, using @code{*@var{addr}} as the form for
9800 @var{locspec}, what source line covers a particular address
9801 @var{addr}:
9802 @smallexample
9803 (@value{GDBP}) info line *0x63ff
9804 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9805 ends at 0x6404 <m4_changequote+184>.
9806 @end smallexample
9807
9808 @cindex @code{$_} and @code{info line}
9809 @cindex @code{x} command, default address
9810 @kindex x@r{(examine), and} info line
9811 After @code{info line}, the default address for the @code{x} command
9812 is changed to the starting address of the line, so that @samp{x/i} is
9813 sufficient to begin examining the machine code (@pxref{Memory,
9814 ,Examining Memory}). Also, this address is saved as the value of the
9815 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9816 Variables}).
9817
9818 @cindex info line, repeated calls
9819 After @code{info line}, using @code{info line} again without
9820 specifying a location will display information about the next source
9821 line.
9822
9823 @table @code
9824 @kindex disassemble
9825 @cindex assembly instructions
9826 @cindex instructions, assembly
9827 @cindex machine instructions
9828 @cindex listing machine instructions
9829 @item disassemble
9830 @itemx disassemble /m
9831 @itemx disassemble /s
9832 @itemx disassemble /r
9833 This specialized command dumps a range of memory as machine
9834 instructions. It can also print mixed source+disassembly by specifying
9835 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9836 as well as in symbolic form by specifying the @code{/r} modifier.
9837 The default memory range is the function surrounding the
9838 program counter of the selected frame. A single argument to this
9839 command is a program counter value; @value{GDBN} dumps the function
9840 surrounding this value. When two arguments are given, they should
9841 be separated by a comma, possibly surrounded by whitespace. The
9842 arguments specify a range of addresses to dump, in one of two forms:
9843
9844 @table @code
9845 @item @var{start},@var{end}
9846 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9847 @item @var{start},+@var{length}
9848 the addresses from @var{start} (inclusive) to
9849 @code{@var{start}+@var{length}} (exclusive).
9850 @end table
9851
9852 @noindent
9853 When 2 arguments are specified, the name of the function is also
9854 printed (since there could be several functions in the given range).
9855
9856 The argument(s) can be any expression yielding a numeric value, such as
9857 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9858
9859 If the range of memory being disassembled contains current program counter,
9860 the instruction at that location is shown with a @code{=>} marker.
9861 @end table
9862
9863 The following example shows the disassembly of a range of addresses of
9864 HP PA-RISC 2.0 code:
9865
9866 @smallexample
9867 (@value{GDBP}) disas 0x32c4, 0x32e4
9868 Dump of assembler code from 0x32c4 to 0x32e4:
9869 0x32c4 <main+204>: addil 0,dp
9870 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9871 0x32cc <main+212>: ldil 0x3000,r31
9872 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9873 0x32d4 <main+220>: ldo 0(r31),rp
9874 0x32d8 <main+224>: addil -0x800,dp
9875 0x32dc <main+228>: ldo 0x588(r1),r26
9876 0x32e0 <main+232>: ldil 0x3000,r31
9877 End of assembler dump.
9878 @end smallexample
9879
9880 Here is an example showing mixed source+assembly for Intel x86
9881 with @code{/m} or @code{/s}, when the program is stopped just after
9882 function prologue in a non-optimized function with no inline code.
9883
9884 @smallexample
9885 (@value{GDBP}) disas /m main
9886 Dump of assembler code for function main:
9887 5 @{
9888 0x08048330 <+0>: push %ebp
9889 0x08048331 <+1>: mov %esp,%ebp
9890 0x08048333 <+3>: sub $0x8,%esp
9891 0x08048336 <+6>: and $0xfffffff0,%esp
9892 0x08048339 <+9>: sub $0x10,%esp
9893
9894 6 printf ("Hello.\n");
9895 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9896 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9897
9898 7 return 0;
9899 8 @}
9900 0x08048348 <+24>: mov $0x0,%eax
9901 0x0804834d <+29>: leave
9902 0x0804834e <+30>: ret
9903
9904 End of assembler dump.
9905 @end smallexample
9906
9907 The @code{/m} option is deprecated as its output is not useful when
9908 there is either inlined code or re-ordered code.
9909 The @code{/s} option is the preferred choice.
9910 Here is an example for AMD x86-64 showing the difference between
9911 @code{/m} output and @code{/s} output.
9912 This example has one inline function defined in a header file,
9913 and the code is compiled with @samp{-O2} optimization.
9914 Note how the @code{/m} output is missing the disassembly of
9915 several instructions that are present in the @code{/s} output.
9916
9917 @file{foo.h}:
9918
9919 @smallexample
9920 int
9921 foo (int a)
9922 @{
9923 if (a < 0)
9924 return a * 2;
9925 if (a == 0)
9926 return 1;
9927 return a + 10;
9928 @}
9929 @end smallexample
9930
9931 @file{foo.c}:
9932
9933 @smallexample
9934 #include "foo.h"
9935 volatile int x, y;
9936 int
9937 main ()
9938 @{
9939 x = foo (y);
9940 return 0;
9941 @}
9942 @end smallexample
9943
9944 @smallexample
9945 (@value{GDBP}) disas /m main
9946 Dump of assembler code for function main:
9947 5 @{
9948
9949 6 x = foo (y);
9950 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9951 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9952
9953 7 return 0;
9954 8 @}
9955 0x000000000040041d <+29>: xor %eax,%eax
9956 0x000000000040041f <+31>: retq
9957 0x0000000000400420 <+32>: add %eax,%eax
9958 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9959
9960 End of assembler dump.
9961 (@value{GDBP}) disas /s main
9962 Dump of assembler code for function main:
9963 foo.c:
9964 5 @{
9965 6 x = foo (y);
9966 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9967
9968 foo.h:
9969 4 if (a < 0)
9970 0x0000000000400406 <+6>: test %eax,%eax
9971 0x0000000000400408 <+8>: js 0x400420 <main+32>
9972
9973 6 if (a == 0)
9974 7 return 1;
9975 8 return a + 10;
9976 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9977 0x000000000040040d <+13>: test %eax,%eax
9978 0x000000000040040f <+15>: mov $0x1,%eax
9979 0x0000000000400414 <+20>: cmovne %edx,%eax
9980
9981 foo.c:
9982 6 x = foo (y);
9983 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9984
9985 7 return 0;
9986 8 @}
9987 0x000000000040041d <+29>: xor %eax,%eax
9988 0x000000000040041f <+31>: retq
9989
9990 foo.h:
9991 5 return a * 2;
9992 0x0000000000400420 <+32>: add %eax,%eax
9993 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9994 End of assembler dump.
9995 @end smallexample
9996
9997 Here is another example showing raw instructions in hex for AMD x86-64,
9998
9999 @smallexample
10000 (gdb) disas /r 0x400281,+10
10001 Dump of assembler code from 0x400281 to 0x40028b:
10002 0x0000000000400281: 38 36 cmp %dh,(%rsi)
10003 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
10004 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
10005 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
10006 End of assembler dump.
10007 @end smallexample
10008
10009 Note that the @samp{disassemble} command's address arguments are
10010 specified using expressions in your programming language
10011 (@pxref{Expressions, ,Expressions}), not location specs
10012 (@pxref{Location Specifications}). So, for example, if you want to
10013 disassemble function @code{bar} in file @file{foo.c}, you must type
10014 @samp{disassemble 'foo.c'::bar} and not @samp{disassemble foo.c:bar}.
10015
10016 Some architectures have more than one commonly-used set of instruction
10017 mnemonics or other syntax.
10018
10019 For programs that were dynamically linked and use shared libraries,
10020 instructions that call functions or branch to locations in the shared
10021 libraries might show a seemingly bogus location---it's actually a
10022 location of the relocation table. On some architectures, @value{GDBN}
10023 might be able to resolve these to actual function names.
10024
10025 @table @code
10026 @kindex set disassembler-options
10027 @cindex disassembler options
10028 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
10029 This command controls the passing of target specific information to
10030 the disassembler. For a list of valid options, please refer to the
10031 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
10032 manual and/or the output of @kbd{objdump --help}
10033 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
10034 The default value is the empty string.
10035
10036 If it is necessary to specify more than one disassembler option, then
10037 multiple options can be placed together into a comma separated list.
10038 Currently this command is only supported on targets ARC, ARM, MIPS,
10039 PowerPC and S/390.
10040
10041 @kindex show disassembler-options
10042 @item show disassembler-options
10043 Show the current setting of the disassembler options.
10044 @end table
10045
10046 @table @code
10047 @kindex set disassembly-flavor
10048 @cindex Intel disassembly flavor
10049 @cindex AT&T disassembly flavor
10050 @item set disassembly-flavor @var{instruction-set}
10051 Select the instruction set to use when disassembling the
10052 program via the @code{disassemble} or @code{x/i} commands.
10053
10054 Currently this command is only defined for the Intel x86 family. You
10055 can set @var{instruction-set} to either @code{intel} or @code{att}.
10056 The default is @code{att}, the AT&T flavor used by default by Unix
10057 assemblers for x86-based targets.
10058
10059 @kindex show disassembly-flavor
10060 @item show disassembly-flavor
10061 Show the current setting of the disassembly flavor.
10062 @end table
10063
10064 @table @code
10065 @kindex set disassemble-next-line
10066 @kindex show disassemble-next-line
10067 @item set disassemble-next-line
10068 @itemx show disassemble-next-line
10069 Control whether or not @value{GDBN} will disassemble the next source
10070 line or instruction when execution stops. If ON, @value{GDBN} will
10071 display disassembly of the next source line when execution of the
10072 program being debugged stops. This is @emph{in addition} to
10073 displaying the source line itself, which @value{GDBN} always does if
10074 possible. If the next source line cannot be displayed for some reason
10075 (e.g., if @value{GDBN} cannot find the source file, or there's no line
10076 info in the debug info), @value{GDBN} will display disassembly of the
10077 next @emph{instruction} instead of showing the next source line. If
10078 AUTO, @value{GDBN} will display disassembly of next instruction only
10079 if the source line cannot be displayed. This setting causes
10080 @value{GDBN} to display some feedback when you step through a function
10081 with no line info or whose source file is unavailable. The default is
10082 OFF, which means never display the disassembly of the next line or
10083 instruction.
10084 @end table
10085
10086 @node Disable Reading Source
10087 @section Disable Reading Source Code
10088 @cindex source code, disable access
10089
10090 In some cases it can be desirable to prevent @value{GDBN} from
10091 accessing source code files. One case where this might be desirable
10092 is if the source code files are located over a slow network
10093 connection.
10094
10095 The following command can be used to control whether @value{GDBN}
10096 should access source code files or not:
10097
10098 @table @code
10099 @kindex set source open
10100 @kindex show source open
10101 @item set source open @r{[}on@r{|}off@r{]}
10102 @itemx show source open
10103 When this option is @code{on}, which is the default, @value{GDBN} will
10104 access source code files when needed, for example to print source
10105 lines when @value{GDBN} stops, or in response to the @code{list}
10106 command.
10107
10108 When this option is @code{off}, @value{GDBN} will not access source
10109 code files.
10110 @end table
10111
10112 @node Data
10113 @chapter Examining Data
10114
10115 @cindex printing data
10116 @cindex examining data
10117 @kindex print
10118 @kindex inspect
10119 The usual way to examine data in your program is with the @code{print}
10120 command (abbreviated @code{p}), or its synonym @code{inspect}. It
10121 evaluates and prints the value of an expression of the language your
10122 program is written in (@pxref{Languages, ,Using @value{GDBN} with
10123 Different Languages}). It may also print the expression using a
10124 Python-based pretty-printer (@pxref{Pretty Printing}).
10125
10126 @table @code
10127 @item print [[@var{options}] --] @var{expr}
10128 @itemx print [[@var{options}] --] /@var{f} @var{expr}
10129 @var{expr} is an expression (in the source language). By default the
10130 value of @var{expr} is printed in a format appropriate to its data type;
10131 you can choose a different format by specifying @samp{/@var{f}}, where
10132 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
10133 Formats}.
10134
10135 @anchor{print options}
10136 The @code{print} command supports a number of options that allow
10137 overriding relevant global print settings as set by @code{set print}
10138 subcommands:
10139
10140 @table @code
10141 @item -address [@code{on}|@code{off}]
10142 Set printing of addresses.
10143 Related setting: @ref{set print address}.
10144
10145 @item -array [@code{on}|@code{off}]
10146 Pretty formatting of arrays.
10147 Related setting: @ref{set print array}.
10148
10149 @item -array-indexes [@code{on}|@code{off}]
10150 Set printing of array indexes.
10151 Related setting: @ref{set print array-indexes}.
10152
10153 @item -elements @var{number-of-elements}|@code{unlimited}
10154 Set limit on string chars or array elements to print. The value
10155 @code{unlimited} causes there to be no limit. Related setting:
10156 @ref{set print elements}.
10157
10158 @item -max-depth @var{depth}|@code{unlimited}
10159 Set the threshold after which nested structures are replaced with
10160 ellipsis. Related setting: @ref{set print max-depth}.
10161
10162 @item -nibbles [@code{on}|@code{off}]
10163 Set whether to print binary values in groups of four bits, known
10164 as ``nibbles''. @xref{set print nibbles}.
10165
10166 @item -memory-tag-violations [@code{on}|@code{off}]
10167 Set printing of additional information about memory tag violations.
10168 @xref{set print memory-tag-violations}.
10169
10170 @item -null-stop [@code{on}|@code{off}]
10171 Set printing of char arrays to stop at first null char. Related
10172 setting: @ref{set print null-stop}.
10173
10174 @item -object [@code{on}|@code{off}]
10175 Set printing C@t{++} virtual function tables. Related setting:
10176 @ref{set print object}.
10177
10178 @item -pretty [@code{on}|@code{off}]
10179 Set pretty formatting of structures. Related setting: @ref{set print
10180 pretty}.
10181
10182 @item -raw-values [@code{on}|@code{off}]
10183 Set whether to print values in raw form, bypassing any
10184 pretty-printers for that value. Related setting: @ref{set print
10185 raw-values}.
10186
10187 @item -repeats @var{number-of-repeats}|@code{unlimited}
10188 Set threshold for repeated print elements. @code{unlimited} causes
10189 all elements to be individually printed. Related setting: @ref{set
10190 print repeats}.
10191
10192 @item -static-members [@code{on}|@code{off}]
10193 Set printing C@t{++} static members. Related setting: @ref{set print
10194 static-members}.
10195
10196 @item -symbol [@code{on}|@code{off}]
10197 Set printing of symbol names when printing pointers. Related setting:
10198 @ref{set print symbol}.
10199
10200 @item -union [@code{on}|@code{off}]
10201 Set printing of unions interior to structures. Related setting:
10202 @ref{set print union}.
10203
10204 @item -vtbl [@code{on}|@code{off}]
10205 Set printing of C++ virtual function tables. Related setting:
10206 @ref{set print vtbl}.
10207 @end table
10208
10209 Because the @code{print} command accepts arbitrary expressions which
10210 may look like options (including abbreviations), if you specify any
10211 command option, then you must use a double dash (@code{--}) to mark
10212 the end of option processing.
10213
10214 For example, this prints the value of the @code{-p} expression:
10215
10216 @smallexample
10217 (@value{GDBP}) print -p
10218 @end smallexample
10219
10220 While this repeats the last value in the value history (see below)
10221 with the @code{-pretty} option in effect:
10222
10223 @smallexample
10224 (@value{GDBP}) print -p --
10225 @end smallexample
10226
10227 Here is an example including both on option and an expression:
10228
10229 @smallexample
10230 @group
10231 (@value{GDBP}) print -pretty -- *myptr
10232 $1 = @{
10233 next = 0x0,
10234 flags = @{
10235 sweet = 1,
10236 sour = 1
10237 @},
10238 meat = 0x54 "Pork"
10239 @}
10240 @end group
10241 @end smallexample
10242
10243 @item print [@var{options}]
10244 @itemx print [@var{options}] /@var{f}
10245 @cindex reprint the last value
10246 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10247 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10248 conveniently inspect the same value in an alternative format.
10249 @end table
10250
10251 If the architecture supports memory tagging, the @code{print} command will
10252 display pointer/memory tag mismatches if what is being printed is a pointer
10253 or reference type. @xref{Memory Tagging}.
10254
10255 A more low-level way of examining data is with the @code{x} command.
10256 It examines data in memory at a specified address and prints it in a
10257 specified format. @xref{Memory, ,Examining Memory}.
10258
10259 If you are interested in information about types, or about how the
10260 fields of a struct or a class are declared, use the @code{ptype @var{expr}}
10261 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10262 Table}.
10263
10264 @cindex exploring hierarchical data structures
10265 @kindex explore
10266 Another way of examining values of expressions and type information is
10267 through the Python extension command @code{explore} (available only if
10268 the @value{GDBN} build is configured with @code{--with-python}). It
10269 offers an interactive way to start at the highest level (or, the most
10270 abstract level) of the data type of an expression (or, the data type
10271 itself) and explore all the way down to leaf scalar values/fields
10272 embedded in the higher level data types.
10273
10274 @table @code
10275 @item explore @var{arg}
10276 @var{arg} is either an expression (in the source language), or a type
10277 visible in the current context of the program being debugged.
10278 @end table
10279
10280 The working of the @code{explore} command can be illustrated with an
10281 example. If a data type @code{struct ComplexStruct} is defined in your
10282 C program as
10283
10284 @smallexample
10285 struct SimpleStruct
10286 @{
10287 int i;
10288 double d;
10289 @};
10290
10291 struct ComplexStruct
10292 @{
10293 struct SimpleStruct *ss_p;
10294 int arr[10];
10295 @};
10296 @end smallexample
10297
10298 @noindent
10299 followed by variable declarations as
10300
10301 @smallexample
10302 struct SimpleStruct ss = @{ 10, 1.11 @};
10303 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10304 @end smallexample
10305
10306 @noindent
10307 then, the value of the variable @code{cs} can be explored using the
10308 @code{explore} command as follows.
10309
10310 @smallexample
10311 (gdb) explore cs
10312 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10313 the following fields:
10314
10315 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10316 arr = <Enter 1 to explore this field of type `int [10]'>
10317
10318 Enter the field number of choice:
10319 @end smallexample
10320
10321 @noindent
10322 Since the fields of @code{cs} are not scalar values, you are being
10323 prompted to chose the field you want to explore. Let's say you choose
10324 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10325 pointer, you will be asked if it is pointing to a single value. From
10326 the declaration of @code{cs} above, it is indeed pointing to a single
10327 value, hence you enter @code{y}. If you enter @code{n}, then you will
10328 be asked if it were pointing to an array of values, in which case this
10329 field will be explored as if it were an array.
10330
10331 @smallexample
10332 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10333 Continue exploring it as a pointer to a single value [y/n]: y
10334 The value of `*(cs.ss_p)' is a struct/class of type `struct
10335 SimpleStruct' with the following fields:
10336
10337 i = 10 .. (Value of type `int')
10338 d = 1.1100000000000001 .. (Value of type `double')
10339
10340 Press enter to return to parent value:
10341 @end smallexample
10342
10343 @noindent
10344 If the field @code{arr} of @code{cs} was chosen for exploration by
10345 entering @code{1} earlier, then since it is as array, you will be
10346 prompted to enter the index of the element in the array that you want
10347 to explore.
10348
10349 @smallexample
10350 `cs.arr' is an array of `int'.
10351 Enter the index of the element you want to explore in `cs.arr': 5
10352
10353 `(cs.arr)[5]' is a scalar value of type `int'.
10354
10355 (cs.arr)[5] = 4
10356
10357 Press enter to return to parent value:
10358 @end smallexample
10359
10360 In general, at any stage of exploration, you can go deeper towards the
10361 leaf values by responding to the prompts appropriately, or hit the
10362 return key to return to the enclosing data structure (the @i{higher}
10363 level data structure).
10364
10365 Similar to exploring values, you can use the @code{explore} command to
10366 explore types. Instead of specifying a value (which is typically a
10367 variable name or an expression valid in the current context of the
10368 program being debugged), you specify a type name. If you consider the
10369 same example as above, your can explore the type
10370 @code{struct ComplexStruct} by passing the argument
10371 @code{struct ComplexStruct} to the @code{explore} command.
10372
10373 @smallexample
10374 (gdb) explore struct ComplexStruct
10375 @end smallexample
10376
10377 @noindent
10378 By responding to the prompts appropriately in the subsequent interactive
10379 session, you can explore the type @code{struct ComplexStruct} in a
10380 manner similar to how the value @code{cs} was explored in the above
10381 example.
10382
10383 The @code{explore} command also has two sub-commands,
10384 @code{explore value} and @code{explore type}. The former sub-command is
10385 a way to explicitly specify that value exploration of the argument is
10386 being invoked, while the latter is a way to explicitly specify that type
10387 exploration of the argument is being invoked.
10388
10389 @table @code
10390 @item explore value @var{expr}
10391 @cindex explore value
10392 This sub-command of @code{explore} explores the value of the
10393 expression @var{expr} (if @var{expr} is an expression valid in the
10394 current context of the program being debugged). The behavior of this
10395 command is identical to that of the behavior of the @code{explore}
10396 command being passed the argument @var{expr}.
10397
10398 @item explore type @var{arg}
10399 @cindex explore type
10400 This sub-command of @code{explore} explores the type of @var{arg} (if
10401 @var{arg} is a type visible in the current context of program being
10402 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10403 is an expression valid in the current context of the program being
10404 debugged). If @var{arg} is a type, then the behavior of this command is
10405 identical to that of the @code{explore} command being passed the
10406 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10407 this command will be identical to that of the @code{explore} command
10408 being passed the type of @var{arg} as the argument.
10409 @end table
10410
10411 @menu
10412 * Expressions:: Expressions
10413 * Ambiguous Expressions:: Ambiguous Expressions
10414 * Variables:: Program variables
10415 * Arrays:: Artificial arrays
10416 * Output Formats:: Output formats
10417 * Memory:: Examining memory
10418 * Memory Tagging:: Memory Tagging
10419 * Auto Display:: Automatic display
10420 * Print Settings:: Print settings
10421 * Pretty Printing:: Python pretty printing
10422 * Value History:: Value history
10423 * Convenience Vars:: Convenience variables
10424 * Convenience Funs:: Convenience functions
10425 * Registers:: Registers
10426 * Floating Point Hardware:: Floating point hardware
10427 * Vector Unit:: Vector Unit
10428 * OS Information:: Auxiliary data provided by operating system
10429 * Memory Region Attributes:: Memory region attributes
10430 * Dump/Restore Files:: Copy between memory and a file
10431 * Core File Generation:: Cause a program dump its core
10432 * Character Sets:: Debugging programs that use a different
10433 character set than GDB does
10434 * Caching Target Data:: Data caching for targets
10435 * Searching Memory:: Searching memory for a sequence of bytes
10436 * Value Sizes:: Managing memory allocated for values
10437 @end menu
10438
10439 @node Expressions
10440 @section Expressions
10441
10442 @cindex expressions
10443 @code{print} and many other @value{GDBN} commands accept an expression and
10444 compute its value. Any kind of constant, variable or operator defined
10445 by the programming language you are using is valid in an expression in
10446 @value{GDBN}. This includes conditional expressions, function calls,
10447 casts, and string constants. It also includes preprocessor macros, if
10448 you compiled your program to include this information; see
10449 @ref{Compilation}.
10450
10451 @cindex arrays in expressions
10452 @value{GDBN} supports array constants in expressions input by
10453 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10454 you can use the command @code{print @{1, 2, 3@}} to create an array
10455 of three integers. If you pass an array to a function or assign it
10456 to a program variable, @value{GDBN} copies the array to memory that
10457 is @code{malloc}ed in the target program.
10458
10459 Because C is so widespread, most of the expressions shown in examples in
10460 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10461 Languages}, for information on how to use expressions in other
10462 languages.
10463
10464 In this section, we discuss operators that you can use in @value{GDBN}
10465 expressions regardless of your programming language.
10466
10467 @cindex casts, in expressions
10468 Casts are supported in all languages, not just in C, because it is so
10469 useful to cast a number into a pointer in order to examine a structure
10470 at that address in memory.
10471 @c FIXME: casts supported---Mod2 true?
10472
10473 @value{GDBN} supports these operators, in addition to those common
10474 to programming languages:
10475
10476 @table @code
10477 @item @@
10478 @samp{@@} is a binary operator for treating parts of memory as arrays.
10479 @xref{Arrays, ,Artificial Arrays}, for more information.
10480
10481 @item ::
10482 @samp{::} allows you to specify a variable in terms of the file or
10483 function where it is defined. @xref{Variables, ,Program Variables}.
10484
10485 @cindex @{@var{type}@}
10486 @cindex type casting memory
10487 @cindex memory, viewing as typed object
10488 @cindex casts, to view memory
10489 @item @{@var{type}@} @var{addr}
10490 Refers to an object of type @var{type} stored at address @var{addr} in
10491 memory. The address @var{addr} may be any expression whose value is
10492 an integer or pointer (but parentheses are required around binary
10493 operators, just as in a cast). This construct is allowed regardless
10494 of what kind of data is normally supposed to reside at @var{addr}.
10495 @end table
10496
10497 @node Ambiguous Expressions
10498 @section Ambiguous Expressions
10499 @cindex ambiguous expressions
10500
10501 Expressions can sometimes contain some ambiguous elements. For instance,
10502 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10503 a single function name to be defined several times, for application in
10504 different contexts. This is called @dfn{overloading}. Another example
10505 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10506 templates and is typically instantiated several times, resulting in
10507 the same function name being defined in different contexts.
10508
10509 In some cases and depending on the language, it is possible to adjust
10510 the expression to remove the ambiguity. For instance in C@t{++}, you
10511 can specify the signature of the function you want to break on, as in
10512 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10513 qualified name of your function often makes the expression unambiguous
10514 as well.
10515
10516 When an ambiguity that needs to be resolved is detected, the debugger
10517 has the capability to display a menu of numbered choices for each
10518 possibility, and then waits for the selection with the prompt @samp{>}.
10519 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10520 aborts the current command. If the command in which the expression was
10521 used allows more than one choice to be selected, the next option in the
10522 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10523 choices.
10524
10525 For example, the following session excerpt shows an attempt to set a
10526 breakpoint at the overloaded symbol @code{String::after}.
10527 We choose three particular definitions of that function name:
10528
10529 @c FIXME! This is likely to change to show arg type lists, at least
10530 @smallexample
10531 @group
10532 (@value{GDBP}) b String::after
10533 [0] cancel
10534 [1] all
10535 [2] file:String.cc; line number:867
10536 [3] file:String.cc; line number:860
10537 [4] file:String.cc; line number:875
10538 [5] file:String.cc; line number:853
10539 [6] file:String.cc; line number:846
10540 [7] file:String.cc; line number:735
10541 > 2 4 6
10542 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10543 Breakpoint 2 at 0xb344: file String.cc, line 875.
10544 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10545 Multiple breakpoints were set.
10546 Use the "delete" command to delete unwanted
10547 breakpoints.
10548 (@value{GDBP})
10549 @end group
10550 @end smallexample
10551
10552 @table @code
10553 @kindex set multiple-symbols
10554 @item set multiple-symbols @var{mode}
10555 @cindex multiple-symbols menu
10556
10557 This option allows you to adjust the debugger behavior when an expression
10558 is ambiguous.
10559
10560 By default, @var{mode} is set to @code{all}. If the command with which
10561 the expression is used allows more than one choice, then @value{GDBN}
10562 automatically selects all possible choices. For instance, inserting
10563 a breakpoint on a function using an ambiguous name results in a breakpoint
10564 inserted on each possible match. However, if a unique choice must be made,
10565 then @value{GDBN} uses the menu to help you disambiguate the expression.
10566 For instance, printing the address of an overloaded function will result
10567 in the use of the menu.
10568
10569 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10570 when an ambiguity is detected.
10571
10572 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10573 an error due to the ambiguity and the command is aborted.
10574
10575 @kindex show multiple-symbols
10576 @item show multiple-symbols
10577 Show the current value of the @code{multiple-symbols} setting.
10578 @end table
10579
10580 @node Variables
10581 @section Program Variables
10582
10583 The most common kind of expression to use is the name of a variable
10584 in your program.
10585
10586 Variables in expressions are understood in the selected stack frame
10587 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10588
10589 @itemize @bullet
10590 @item
10591 global (or file-static)
10592 @end itemize
10593
10594 @noindent or
10595
10596 @itemize @bullet
10597 @item
10598 visible according to the scope rules of the
10599 programming language from the point of execution in that frame
10600 @end itemize
10601
10602 @noindent This means that in the function
10603
10604 @smallexample
10605 foo (a)
10606 int a;
10607 @{
10608 bar (a);
10609 @{
10610 int b = test ();
10611 bar (b);
10612 @}
10613 @}
10614 @end smallexample
10615
10616 @noindent
10617 you can examine and use the variable @code{a} whenever your program is
10618 executing within the function @code{foo}, but you can only use or
10619 examine the variable @code{b} while your program is executing inside
10620 the block where @code{b} is declared.
10621
10622 @cindex variable name conflict
10623 There is an exception: you can refer to a variable or function whose
10624 scope is a single source file even if the current execution point is not
10625 in this file. But it is possible to have more than one such variable or
10626 function with the same name (in different source files). If that
10627 happens, referring to that name has unpredictable effects. If you wish,
10628 you can specify a static variable in a particular function or file by
10629 using the colon-colon (@code{::}) notation:
10630
10631 @cindex colon-colon, context for variables/functions
10632 @ifnotinfo
10633 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10634 @cindex @code{::}, context for variables/functions
10635 @end ifnotinfo
10636 @smallexample
10637 @var{file}::@var{variable}
10638 @var{function}::@var{variable}
10639 @end smallexample
10640
10641 @noindent
10642 Here @var{file} or @var{function} is the name of the context for the
10643 static @var{variable}. In the case of file names, you can use quotes to
10644 make sure @value{GDBN} parses the file name as a single word---for example,
10645 to print a global value of @code{x} defined in @file{f2.c}:
10646
10647 @smallexample
10648 (@value{GDBP}) p 'f2.c'::x
10649 @end smallexample
10650
10651 The @code{::} notation is normally used for referring to
10652 static variables, since you typically disambiguate uses of local variables
10653 in functions by selecting the appropriate frame and using the
10654 simple name of the variable. However, you may also use this notation
10655 to refer to local variables in frames enclosing the selected frame:
10656
10657 @smallexample
10658 void
10659 foo (int a)
10660 @{
10661 if (a < 10)
10662 bar (a);
10663 else
10664 process (a); /* Stop here */
10665 @}
10666
10667 int
10668 bar (int a)
10669 @{
10670 foo (a + 5);
10671 @}
10672 @end smallexample
10673
10674 @noindent
10675 For example, if there is a breakpoint at the commented line,
10676 here is what you might see
10677 when the program stops after executing the call @code{bar(0)}:
10678
10679 @smallexample
10680 (@value{GDBP}) p a
10681 $1 = 10
10682 (@value{GDBP}) p bar::a
10683 $2 = 5
10684 (@value{GDBP}) up 2
10685 #2 0x080483d0 in foo (a=5) at foobar.c:12
10686 (@value{GDBP}) p a
10687 $3 = 5
10688 (@value{GDBP}) p bar::a
10689 $4 = 0
10690 @end smallexample
10691
10692 @cindex C@t{++} scope resolution
10693 These uses of @samp{::} are very rarely in conflict with the very
10694 similar use of the same notation in C@t{++}. When they are in
10695 conflict, the C@t{++} meaning takes precedence; however, this can be
10696 overridden by quoting the file or function name with single quotes.
10697
10698 For example, suppose the program is stopped in a method of a class
10699 that has a field named @code{includefile}, and there is also an
10700 include file named @file{includefile} that defines a variable,
10701 @code{some_global}.
10702
10703 @smallexample
10704 (@value{GDBP}) p includefile
10705 $1 = 23
10706 (@value{GDBP}) p includefile::some_global
10707 A syntax error in expression, near `'.
10708 (@value{GDBP}) p 'includefile'::some_global
10709 $2 = 27
10710 @end smallexample
10711
10712 @cindex wrong values
10713 @cindex variable values, wrong
10714 @cindex function entry/exit, wrong values of variables
10715 @cindex optimized code, wrong values of variables
10716 @quotation
10717 @emph{Warning:} Occasionally, a local variable may appear to have the
10718 wrong value at certain points in a function---just after entry to a new
10719 scope, and just before exit.
10720 @end quotation
10721 You may see this problem when you are stepping by machine instructions.
10722 This is because, on most machines, it takes more than one instruction to
10723 set up a stack frame (including local variable definitions); if you are
10724 stepping by machine instructions, variables may appear to have the wrong
10725 values until the stack frame is completely built. On exit, it usually
10726 also takes more than one machine instruction to destroy a stack frame;
10727 after you begin stepping through that group of instructions, local
10728 variable definitions may be gone.
10729
10730 This may also happen when the compiler does significant optimizations.
10731 To be sure of always seeing accurate values, turn off all optimization
10732 when compiling.
10733
10734 @cindex ``No symbol "foo" in current context''
10735 Another possible effect of compiler optimizations is to optimize
10736 unused variables out of existence, or assign variables to registers (as
10737 opposed to memory addresses). Depending on the support for such cases
10738 offered by the debug info format used by the compiler, @value{GDBN}
10739 might not be able to display values for such local variables. If that
10740 happens, @value{GDBN} will print a message like this:
10741
10742 @smallexample
10743 No symbol "foo" in current context.
10744 @end smallexample
10745
10746 To solve such problems, either recompile without optimizations, or use a
10747 different debug info format, if the compiler supports several such
10748 formats. @xref{Compilation}, for more information on choosing compiler
10749 options. @xref{C, ,C and C@t{++}}, for more information about debug
10750 info formats that are best suited to C@t{++} programs.
10751
10752 If you ask to print an object whose contents are unknown to
10753 @value{GDBN}, e.g., because its data type is not completely specified
10754 by the debug information, @value{GDBN} will say @samp{<incomplete
10755 type>}. @xref{Symbols, incomplete type}, for more about this.
10756
10757 @cindex no debug info variables
10758 If you try to examine or use the value of a (global) variable for
10759 which @value{GDBN} has no type information, e.g., because the program
10760 includes no debug information, @value{GDBN} displays an error message.
10761 @xref{Symbols, unknown type}, for more about unknown types. If you
10762 cast the variable to its declared type, @value{GDBN} gets the
10763 variable's value using the cast-to type as the variable's type. For
10764 example, in a C program:
10765
10766 @smallexample
10767 (@value{GDBP}) p var
10768 'var' has unknown type; cast it to its declared type
10769 (@value{GDBP}) p (float) var
10770 $1 = 3.14
10771 @end smallexample
10772
10773 If you append @kbd{@@entry} string to a function parameter name you get its
10774 value at the time the function got called. If the value is not available an
10775 error message is printed. Entry values are available only with some compilers.
10776 Entry values are normally also printed at the function parameter list according
10777 to @ref{set print entry-values}.
10778
10779 @smallexample
10780 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10781 29 i++;
10782 (gdb) next
10783 30 e (i);
10784 (gdb) print i
10785 $1 = 31
10786 (gdb) print i@@entry
10787 $2 = 30
10788 @end smallexample
10789
10790 Strings are identified as arrays of @code{char} values without specified
10791 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10792 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10793 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10794 defines literal string type @code{"char"} as @code{char} without a sign.
10795 For program code
10796
10797 @smallexample
10798 char var0[] = "A";
10799 signed char var1[] = "A";
10800 @end smallexample
10801
10802 You get during debugging
10803 @smallexample
10804 (gdb) print var0
10805 $1 = "A"
10806 (gdb) print var1
10807 $2 = @{65 'A', 0 '\0'@}
10808 @end smallexample
10809
10810 @node Arrays
10811 @section Artificial Arrays
10812
10813 @cindex artificial array
10814 @cindex arrays
10815 @kindex @@@r{, referencing memory as an array}
10816 It is often useful to print out several successive objects of the
10817 same type in memory; a section of an array, or an array of
10818 dynamically determined size for which only a pointer exists in the
10819 program.
10820
10821 You can do this by referring to a contiguous span of memory as an
10822 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10823 operand of @samp{@@} should be the first element of the desired array
10824 and be an individual object. The right operand should be the desired length
10825 of the array. The result is an array value whose elements are all of
10826 the type of the left argument. The first element is actually the left
10827 argument; the second element comes from bytes of memory immediately
10828 following those that hold the first element, and so on. Here is an
10829 example. If a program says
10830
10831 @smallexample
10832 int *array = (int *) malloc (len * sizeof (int));
10833 @end smallexample
10834
10835 @noindent
10836 you can print the contents of @code{array} with
10837
10838 @smallexample
10839 p *array@@len
10840 @end smallexample
10841
10842 The left operand of @samp{@@} must reside in memory. Array values made
10843 with @samp{@@} in this way behave just like other arrays in terms of
10844 subscripting, and are coerced to pointers when used in expressions.
10845 Artificial arrays most often appear in expressions via the value history
10846 (@pxref{Value History, ,Value History}), after printing one out.
10847
10848 Another way to create an artificial array is to use a cast.
10849 This re-interprets a value as if it were an array.
10850 The value need not be in memory:
10851 @smallexample
10852 (@value{GDBP}) p/x (short[2])0x12345678
10853 $1 = @{0x1234, 0x5678@}
10854 @end smallexample
10855
10856 As a convenience, if you leave the array length out (as in
10857 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10858 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10859 @smallexample
10860 (@value{GDBP}) p/x (short[])0x12345678
10861 $2 = @{0x1234, 0x5678@}
10862 @end smallexample
10863
10864 Sometimes the artificial array mechanism is not quite enough; in
10865 moderately complex data structures, the elements of interest may not
10866 actually be adjacent---for example, if you are interested in the values
10867 of pointers in an array. One useful work-around in this situation is
10868 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10869 Variables}) as a counter in an expression that prints the first
10870 interesting value, and then repeat that expression via @key{RET}. For
10871 instance, suppose you have an array @code{dtab} of pointers to
10872 structures, and you are interested in the values of a field @code{fv}
10873 in each structure. Here is an example of what you might type:
10874
10875 @smallexample
10876 set $i = 0
10877 p dtab[$i++]->fv
10878 @key{RET}
10879 @key{RET}
10880 @dots{}
10881 @end smallexample
10882
10883 @node Output Formats
10884 @section Output Formats
10885
10886 @cindex formatted output
10887 @cindex output formats
10888 By default, @value{GDBN} prints a value according to its data type. Sometimes
10889 this is not what you want. For example, you might want to print a number
10890 in hex, or a pointer in decimal. Or you might want to view data in memory
10891 at a certain address as a character string or as an instruction. To do
10892 these things, specify an @dfn{output format} when you print a value.
10893
10894 The simplest use of output formats is to say how to print a value
10895 already computed. This is done by starting the arguments of the
10896 @code{print} command with a slash and a format letter. The format
10897 letters supported are:
10898
10899 @table @code
10900 @item x
10901 Print the binary representation of the value in hexadecimal.
10902
10903 @item d
10904 Print the binary representation of the value in decimal.
10905
10906 @item u
10907 Print the binary representation of the value as an decimal, as if it
10908 were unsigned.
10909
10910 @item o
10911 Print the binary representation of the value in octal.
10912
10913 @item t
10914 Print the binary representation of the value in binary. The letter
10915 @samp{t} stands for ``two''. @footnote{@samp{b} cannot be used
10916 because these format letters are also used with the @code{x} command,
10917 where @samp{b} stands for ``byte''; see @ref{Memory,,Examining
10918 Memory}.}
10919
10920 @item a
10921 @cindex unknown address, locating
10922 @cindex locate address
10923 Print as an address, both absolute in hexadecimal and as an offset from
10924 the nearest preceding symbol. You can use this format used to discover
10925 where (in what function) an unknown address is located:
10926
10927 @smallexample
10928 (@value{GDBP}) p/a 0x54320
10929 $3 = 0x54320 <_initialize_vx+396>
10930 @end smallexample
10931
10932 @noindent
10933 The command @code{info symbol 0x54320} yields similar results.
10934 @xref{Symbols, info symbol}.
10935
10936 @item c
10937 Cast the value to an integer (unlike other formats, this does not just
10938 reinterpret the underlying bits) and print it as a character constant.
10939 This prints both the numerical value and its character representation.
10940 The character representation is replaced with the octal escape
10941 @samp{\nnn} for characters outside the 7-bit @sc{ascii} range.
10942
10943 Without this format, @value{GDBN} displays @code{char},
10944 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10945 constants. Single-byte members of vectors are displayed as integer
10946 data.
10947
10948 @item f
10949 Regard the bits of the value as a floating point number and print
10950 using typical floating point syntax.
10951
10952 @item s
10953 @cindex printing strings
10954 @cindex printing byte arrays
10955 Regard as a string, if possible. With this format, pointers to single-byte
10956 data are displayed as null-terminated strings and arrays of single-byte data
10957 are displayed as fixed-length strings. Other values are displayed in their
10958 natural types.
10959
10960 Without this format, @value{GDBN} displays pointers to and arrays of
10961 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10962 strings. Single-byte members of a vector are displayed as an integer
10963 array.
10964
10965 @item z
10966 Like @samp{x} formatting, the value is treated as an integer and
10967 printed as hexadecimal, but leading zeros are printed to pad the value
10968 to the size of the integer type.
10969
10970 @item r
10971 @cindex raw printing
10972 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10973 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10974 Printing}). This typically results in a higher-level display of the
10975 value's contents. The @samp{r} format bypasses any Python
10976 pretty-printer which might exist.
10977 @end table
10978
10979 For example, to print the program counter in hex (@pxref{Registers}), type
10980
10981 @smallexample
10982 p/x $pc
10983 @end smallexample
10984
10985 @noindent
10986 Note that no space is required before the slash; this is because command
10987 names in @value{GDBN} cannot contain a slash.
10988
10989 To reprint the last value in the value history with a different format,
10990 you can use the @code{print} command with just a format and no
10991 expression. For example, @samp{p/x} reprints the last value in hex.
10992
10993 @node Memory
10994 @section Examining Memory
10995
10996 You can use the command @code{x} (for ``examine'') to examine memory in
10997 any of several formats, independently of your program's data types.
10998
10999 @cindex examining memory
11000 @table @code
11001 @kindex x @r{(examine memory)}
11002 @item x/@var{nfu} @var{addr}
11003 @itemx x @var{addr}
11004 @itemx x
11005 Use the @code{x} command to examine memory.
11006 @end table
11007
11008 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
11009 much memory to display and how to format it; @var{addr} is an
11010 expression giving the address where you want to start displaying memory.
11011 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
11012 Several commands set convenient defaults for @var{addr}.
11013
11014 @table @r
11015 @item @var{n}, the repeat count
11016 The repeat count is a decimal integer; the default is 1. It specifies
11017 how much memory (counting by units @var{u}) to display. If a negative
11018 number is specified, memory is examined backward from @var{addr}.
11019 @c This really is **decimal**; unaffected by 'set radix' as of GDB
11020 @c 4.1.2.
11021
11022 @item @var{f}, the display format
11023 The display format is one of the formats used by @code{print}
11024 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
11025 @samp{f}, @samp{s}), @samp{i} (for machine instructions) and
11026 @samp{m} (for displaying memory tags).
11027 The default is @samp{x} (hexadecimal) initially. The default changes
11028 each time you use either @code{x} or @code{print}.
11029
11030 @item @var{u}, the unit size
11031 The unit size is any of
11032
11033 @table @code
11034 @item b
11035 Bytes.
11036 @item h
11037 Halfwords (two bytes).
11038 @item w
11039 Words (four bytes). This is the initial default.
11040 @item g
11041 Giant words (eight bytes).
11042 @end table
11043
11044 Each time you specify a unit size with @code{x}, that size becomes the
11045 default unit the next time you use @code{x}. For the @samp{i} format,
11046 the unit size is ignored and is normally not written. For the @samp{s} format,
11047 the unit size defaults to @samp{b}, unless it is explicitly given.
11048 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
11049 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
11050 Note that the results depend on the programming language of the
11051 current compilation unit. If the language is C, the @samp{s}
11052 modifier will use the UTF-16 encoding while @samp{w} will use
11053 UTF-32. The encoding is set by the programming language and cannot
11054 be altered.
11055
11056 @item @var{addr}, starting display address
11057 @var{addr} is the address where you want @value{GDBN} to begin displaying
11058 memory. The expression need not have a pointer value (though it may);
11059 it is always interpreted as an integer address of a byte of memory.
11060 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
11061 @var{addr} is usually just after the last address examined---but several
11062 other commands also set the default address: @code{info breakpoints} (to
11063 the address of the last breakpoint listed), @code{info line} (to the
11064 starting address of a line), and @code{print} (if you use it to display
11065 a value from memory).
11066 @end table
11067
11068 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
11069 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
11070 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
11071 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
11072 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
11073
11074 You can also specify a negative repeat count to examine memory backward
11075 from the given address. For example, @samp{x/-3uh 0x54320} prints three
11076 halfwords (@code{h}) at @code{0x5431a}, @code{0x5431c}, and @code{0x5431e}.
11077
11078 Since the letters indicating unit sizes are all distinct from the
11079 letters specifying output formats, you do not have to remember whether
11080 unit size or format comes first; either order works. The output
11081 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
11082 (However, the count @var{n} must come first; @samp{wx4} does not work.)
11083
11084 Even though the unit size @var{u} is ignored for the formats @samp{s}
11085 and @samp{i}, you might still want to use a count @var{n}; for example,
11086 @samp{3i} specifies that you want to see three machine instructions,
11087 including any operands. For convenience, especially when used with
11088 the @code{display} command, the @samp{i} format also prints branch delay
11089 slot instructions, if any, beyond the count specified, which immediately
11090 follow the last instruction that is within the count. The command
11091 @code{disassemble} gives an alternative way of inspecting machine
11092 instructions; see @ref{Machine Code,,Source and Machine Code}.
11093
11094 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
11095 the command displays null-terminated strings or instructions before the given
11096 address as many as the absolute value of the given number. For the @samp{i}
11097 format, we use line number information in the debug info to accurately locate
11098 instruction boundaries while disassembling backward. If line info is not
11099 available, the command stops examining memory with an error message.
11100
11101 All the defaults for the arguments to @code{x} are designed to make it
11102 easy to continue scanning memory with minimal specifications each time
11103 you use @code{x}. For example, after you have inspected three machine
11104 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
11105 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
11106 the repeat count @var{n} is used again; the other arguments default as
11107 for successive uses of @code{x}.
11108
11109 When examining machine instructions, the instruction at current program
11110 counter is shown with a @code{=>} marker. For example:
11111
11112 @smallexample
11113 (@value{GDBP}) x/5i $pc-6
11114 0x804837f <main+11>: mov %esp,%ebp
11115 0x8048381 <main+13>: push %ecx
11116 0x8048382 <main+14>: sub $0x4,%esp
11117 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
11118 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
11119 @end smallexample
11120
11121 If the architecture supports memory tagging, the tags can be displayed by
11122 using @samp{m}. @xref{Memory Tagging}.
11123
11124 The information will be displayed once per granule size
11125 (the amount of bytes a particular memory tag covers). For example, AArch64
11126 has a granule size of 16 bytes, so it will display a tag every 16 bytes.
11127
11128 Due to the way @value{GDBN} prints information with the @code{x} command (not
11129 aligned to a particular boundary), the tag information will refer to the
11130 initial address displayed on a particular line. If a memory tag boundary
11131 is crossed in the middle of a line displayed by the @code{x} command, it
11132 will be displayed on the next line.
11133
11134 The @samp{m} format doesn't affect any other specified formats that were
11135 passed to the @code{x} command.
11136
11137 @cindex @code{$_}, @code{$__}, and value history
11138 The addresses and contents printed by the @code{x} command are not saved
11139 in the value history because there is often too much of them and they
11140 would get in the way. Instead, @value{GDBN} makes these values available for
11141 subsequent use in expressions as values of the convenience variables
11142 @code{$_} and @code{$__}. After an @code{x} command, the last address
11143 examined is available for use in expressions in the convenience variable
11144 @code{$_}. The contents of that address, as examined, are available in
11145 the convenience variable @code{$__}.
11146
11147 If the @code{x} command has a repeat count, the address and contents saved
11148 are from the last memory unit printed; this is not the same as the last
11149 address printed if several units were printed on the last line of output.
11150
11151 @anchor{addressable memory unit}
11152 @cindex addressable memory unit
11153 Most targets have an addressable memory unit size of 8 bits. This means
11154 that to each memory address are associated 8 bits of data. Some
11155 targets, however, have other addressable memory unit sizes.
11156 Within @value{GDBN} and this document, the term
11157 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
11158 when explicitly referring to a chunk of data of that size. The word
11159 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
11160 the addressable memory unit size of the target. For most systems,
11161 addressable memory unit is a synonym of byte.
11162
11163 @cindex remote memory comparison
11164 @cindex target memory comparison
11165 @cindex verify remote memory image
11166 @cindex verify target memory image
11167 When you are debugging a program running on a remote target machine
11168 (@pxref{Remote Debugging}), you may wish to verify the program's image
11169 in the remote machine's memory against the executable file you
11170 downloaded to the target. Or, on any target, you may want to check
11171 whether the program has corrupted its own read-only sections. The
11172 @code{compare-sections} command is provided for such situations.
11173
11174 @table @code
11175 @kindex compare-sections
11176 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
11177 Compare the data of a loadable section @var{section-name} in the
11178 executable file of the program being debugged with the same section in
11179 the target machine's memory, and report any mismatches. With no
11180 arguments, compares all loadable sections. With an argument of
11181 @code{-r}, compares all loadable read-only sections.
11182
11183 Note: for remote targets, this command can be accelerated if the
11184 target supports computing the CRC checksum of a block of memory
11185 (@pxref{qCRC packet}).
11186 @end table
11187
11188 @node Memory Tagging
11189 @section Memory Tagging
11190
11191 Memory tagging is a memory protection technology that uses a pair of tags to
11192 validate memory accesses through pointers. The tags are integer values
11193 usually comprised of a few bits, depending on the architecture.
11194
11195 There are two types of tags that are used in this setup: logical and
11196 allocation. A logical tag is stored in the pointers themselves, usually at the
11197 higher bits of the pointers. An allocation tag is the tag associated
11198 with particular ranges of memory in the physical address space, against which
11199 the logical tags from pointers are compared.
11200
11201 The pointer tag (logical tag) must match the memory tag (allocation tag)
11202 for the memory access to be valid. If the logical tag does not match the
11203 allocation tag, that will raise a memory violation.
11204
11205 Allocation tags cover multiple contiguous bytes of physical memory. This
11206 range of bytes is called a memory tag granule and is architecture-specific.
11207 For example, AArch64 has a tag granule of 16 bytes, meaning each allocation
11208 tag spans 16 bytes of memory.
11209
11210 If the underlying architecture supports memory tagging, like AArch64 MTE
11211 or SPARC ADI do, @value{GDBN} can make use of it to validate pointers
11212 against memory allocation tags.
11213
11214 The @code{print} (@pxref{Data}) and @code{x} (@pxref{Memory}) commands will
11215 display tag information when appropriate, and a command prefix of
11216 @code{memory-tag} gives access to the various memory tagging commands.
11217
11218 The @code{memory-tag} commands are the following:
11219
11220 @table @code
11221 @kindex memory-tag print-logical-tag
11222 @item memory-tag print-logical-tag @var{pointer_expression}
11223 Print the logical tag stored in @var{pointer_expression}.
11224 @kindex memory-tag with-logical-tag
11225 @item memory-tag with-logical-tag @var{pointer_expression} @var{tag_bytes}
11226 Print the pointer given by @var{pointer_expression}, augmented with a logical
11227 tag of @var{tag_bytes}.
11228 @kindex memory-tag print-allocation-tag
11229 @item memory-tag print-allocation-tag @var{address_expression}
11230 Print the allocation tag associated with the memory address given by
11231 @var{address_expression}.
11232 @kindex memory-tag setatag
11233 @item memory-tag setatag @var{starting_address} @var{length} @var{tag_bytes}
11234 Set the allocation tag(s) for memory range @r{[}@var{starting_address},
11235 @var{starting_address} + @var{length}@r{)} to @var{tag_bytes}.
11236 @kindex memory-tag check
11237 @item memory-tag check @var{pointer_expression}
11238 Check if the logical tag in the pointer given by @var{pointer_expression}
11239 matches the allocation tag for the memory referenced by the pointer.
11240
11241 This essentially emulates the hardware validation that is done when tagged
11242 memory is accessed through a pointer, but does not cause a memory fault as
11243 it would during hardware validation.
11244
11245 It can be used to inspect potential memory tagging violations in the running
11246 process, before any faults get triggered.
11247 @end table
11248
11249 @node Auto Display
11250 @section Automatic Display
11251 @cindex automatic display
11252 @cindex display of expressions
11253
11254 If you find that you want to print the value of an expression frequently
11255 (to see how it changes), you might want to add it to the @dfn{automatic
11256 display list} so that @value{GDBN} prints its value each time your program stops.
11257 Each expression added to the list is given a number to identify it;
11258 to remove an expression from the list, you specify that number.
11259 The automatic display looks like this:
11260
11261 @smallexample
11262 2: foo = 38
11263 3: bar[5] = (struct hack *) 0x3804
11264 @end smallexample
11265
11266 @noindent
11267 This display shows item numbers, expressions and their current values. As with
11268 displays you request manually using @code{x} or @code{print}, you can
11269 specify the output format you prefer; in fact, @code{display} decides
11270 whether to use @code{print} or @code{x} depending your format
11271 specification---it uses @code{x} if you specify either the @samp{i}
11272 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
11273
11274 @table @code
11275 @kindex display
11276 @item display @var{expr}
11277 Add the expression @var{expr} to the list of expressions to display
11278 each time your program stops. @xref{Expressions, ,Expressions}.
11279
11280 @code{display} does not repeat if you press @key{RET} again after using it.
11281
11282 @item display/@var{fmt} @var{expr}
11283 For @var{fmt} specifying only a display format and not a size or
11284 count, add the expression @var{expr} to the auto-display list but
11285 arrange to display it each time in the specified format @var{fmt}.
11286 @xref{Output Formats,,Output Formats}.
11287
11288 @item display/@var{fmt} @var{addr}
11289 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
11290 number of units, add the expression @var{addr} as a memory address to
11291 be examined each time your program stops. Examining means in effect
11292 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
11293 @end table
11294
11295 For example, @samp{display/i $pc} can be helpful, to see the machine
11296 instruction about to be executed each time execution stops (@samp{$pc}
11297 is a common name for the program counter; @pxref{Registers, ,Registers}).
11298
11299 @table @code
11300 @kindex delete display
11301 @kindex undisplay
11302 @item undisplay @var{dnums}@dots{}
11303 @itemx delete display @var{dnums}@dots{}
11304 Remove items from the list of expressions to display. Specify the
11305 numbers of the displays that you want affected with the command
11306 argument @var{dnums}. It can be a single display number, one of the
11307 numbers shown in the first field of the @samp{info display} display;
11308 or it could be a range of display numbers, as in @code{2-4}.
11309
11310 @code{undisplay} does not repeat if you press @key{RET} after using it.
11311 (Otherwise you would just get the error @samp{No display number @dots{}}.)
11312
11313 @kindex disable display
11314 @item disable display @var{dnums}@dots{}
11315 Disable the display of item numbers @var{dnums}. A disabled display
11316 item is not printed automatically, but is not forgotten. It may be
11317 enabled again later. Specify the numbers of the displays that you
11318 want affected with the command argument @var{dnums}. It can be a
11319 single display number, one of the numbers shown in the first field of
11320 the @samp{info display} display; or it could be a range of display
11321 numbers, as in @code{2-4}.
11322
11323 @kindex enable display
11324 @item enable display @var{dnums}@dots{}
11325 Enable display of item numbers @var{dnums}. It becomes effective once
11326 again in auto display of its expression, until you specify otherwise.
11327 Specify the numbers of the displays that you want affected with the
11328 command argument @var{dnums}. It can be a single display number, one
11329 of the numbers shown in the first field of the @samp{info display}
11330 display; or it could be a range of display numbers, as in @code{2-4}.
11331
11332 @item display
11333 Display the current values of the expressions on the list, just as is
11334 done when your program stops.
11335
11336 @kindex info display
11337 @item info display
11338 Print the list of expressions previously set up to display
11339 automatically, each one with its item number, but without showing the
11340 values. This includes disabled expressions, which are marked as such.
11341 It also includes expressions which would not be displayed right now
11342 because they refer to automatic variables not currently available.
11343 @end table
11344
11345 @cindex display disabled out of scope
11346 If a display expression refers to local variables, then it does not make
11347 sense outside the lexical context for which it was set up. Such an
11348 expression is disabled when execution enters a context where one of its
11349 variables is not defined. For example, if you give the command
11350 @code{display last_char} while inside a function with an argument
11351 @code{last_char}, @value{GDBN} displays this argument while your program
11352 continues to stop inside that function. When it stops elsewhere---where
11353 there is no variable @code{last_char}---the display is disabled
11354 automatically. The next time your program stops where @code{last_char}
11355 is meaningful, you can enable the display expression once again.
11356
11357 @node Print Settings
11358 @section Print Settings
11359
11360 @cindex format options
11361 @cindex print settings
11362 @value{GDBN} provides the following ways to control how arrays, structures,
11363 and symbols are printed.
11364
11365 @noindent
11366 These settings are useful for debugging programs in any language:
11367
11368 @table @code
11369 @kindex set print
11370 @anchor{set print address}
11371 @item set print address
11372 @itemx set print address on
11373 @cindex print/don't print memory addresses
11374 @value{GDBN} prints memory addresses showing the location of stack
11375 traces, structure values, pointer values, breakpoints, and so forth,
11376 even when it also displays the contents of those addresses. The default
11377 is @code{on}. For example, this is what a stack frame display looks like with
11378 @code{set print address on}:
11379
11380 @smallexample
11381 @group
11382 (@value{GDBP}) f
11383 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11384 at input.c:530
11385 530 if (lquote != def_lquote)
11386 @end group
11387 @end smallexample
11388
11389 @item set print address off
11390 Do not print addresses when displaying their contents. For example,
11391 this is the same stack frame displayed with @code{set print address off}:
11392
11393 @smallexample
11394 @group
11395 (@value{GDBP}) set print addr off
11396 (@value{GDBP}) f
11397 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11398 530 if (lquote != def_lquote)
11399 @end group
11400 @end smallexample
11401
11402 You can use @samp{set print address off} to eliminate all machine
11403 dependent displays from the @value{GDBN} interface. For example, with
11404 @code{print address off}, you should get the same text for backtraces on
11405 all machines---whether or not they involve pointer arguments.
11406
11407 @kindex show print
11408 @item show print address
11409 Show whether or not addresses are to be printed.
11410 @end table
11411
11412 When @value{GDBN} prints a symbolic address, it normally prints the
11413 closest earlier symbol plus an offset. If that symbol does not uniquely
11414 identify the address (for example, it is a name whose scope is a single
11415 source file), you may need to clarify. One way to do this is with
11416 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11417 you can set @value{GDBN} to print the source file and line number when
11418 it prints a symbolic address:
11419
11420 @table @code
11421 @item set print symbol-filename on
11422 @cindex source file and line of a symbol
11423 @cindex symbol, source file and line
11424 Tell @value{GDBN} to print the source file name and line number of a
11425 symbol in the symbolic form of an address.
11426
11427 @item set print symbol-filename off
11428 Do not print source file name and line number of a symbol. This is the
11429 default.
11430
11431 @item show print symbol-filename
11432 Show whether or not @value{GDBN} will print the source file name and
11433 line number of a symbol in the symbolic form of an address.
11434 @end table
11435
11436 Another situation where it is helpful to show symbol filenames and line
11437 numbers is when disassembling code; @value{GDBN} shows you the line
11438 number and source file that corresponds to each instruction.
11439
11440 Also, you may wish to see the symbolic form only if the address being
11441 printed is reasonably close to the closest earlier symbol:
11442
11443 @table @code
11444 @item set print max-symbolic-offset @var{max-offset}
11445 @itemx set print max-symbolic-offset unlimited
11446 @cindex maximum value for offset of closest symbol
11447 Tell @value{GDBN} to only display the symbolic form of an address if the
11448 offset between the closest earlier symbol and the address is less than
11449 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11450 to always print the symbolic form of an address if any symbol precedes
11451 it. Zero is equivalent to @code{unlimited}.
11452
11453 @item show print max-symbolic-offset
11454 Ask how large the maximum offset is that @value{GDBN} prints in a
11455 symbolic address.
11456 @end table
11457
11458 @cindex wild pointer, interpreting
11459 @cindex pointer, finding referent
11460 If you have a pointer and you are not sure where it points, try
11461 @samp{set print symbol-filename on}. Then you can determine the name
11462 and source file location of the variable where it points, using
11463 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11464 For example, here @value{GDBN} shows that a variable @code{ptt} points
11465 at another variable @code{t}, defined in @file{hi2.c}:
11466
11467 @smallexample
11468 (@value{GDBP}) set print symbol-filename on
11469 (@value{GDBP}) p/a ptt
11470 $4 = 0xe008 <t in hi2.c>
11471 @end smallexample
11472
11473 @quotation
11474 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11475 does not show the symbol name and filename of the referent, even with
11476 the appropriate @code{set print} options turned on.
11477 @end quotation
11478
11479 You can also enable @samp{/a}-like formatting all the time using
11480 @samp{set print symbol on}:
11481
11482 @anchor{set print symbol}
11483 @table @code
11484 @item set print symbol on
11485 Tell @value{GDBN} to print the symbol corresponding to an address, if
11486 one exists.
11487
11488 @item set print symbol off
11489 Tell @value{GDBN} not to print the symbol corresponding to an
11490 address. In this mode, @value{GDBN} will still print the symbol
11491 corresponding to pointers to functions. This is the default.
11492
11493 @item show print symbol
11494 Show whether @value{GDBN} will display the symbol corresponding to an
11495 address.
11496 @end table
11497
11498 Other settings control how different kinds of objects are printed:
11499
11500 @table @code
11501 @anchor{set print array}
11502 @item set print array
11503 @itemx set print array on
11504 @cindex pretty print arrays
11505 Pretty print arrays. This format is more convenient to read,
11506 but uses more space. The default is off.
11507
11508 @item set print array off
11509 Return to compressed format for arrays.
11510
11511 @item show print array
11512 Show whether compressed or pretty format is selected for displaying
11513 arrays.
11514
11515 @cindex print array indexes
11516 @anchor{set print array-indexes}
11517 @item set print array-indexes
11518 @itemx set print array-indexes on
11519 Print the index of each element when displaying arrays. May be more
11520 convenient to locate a given element in the array or quickly find the
11521 index of a given element in that printed array. The default is off.
11522
11523 @item set print array-indexes off
11524 Stop printing element indexes when displaying arrays.
11525
11526 @item show print array-indexes
11527 Show whether the index of each element is printed when displaying
11528 arrays.
11529
11530 @anchor{set print nibbles}
11531 @item set print nibbles
11532 @itemx set print nibbles on
11533 @cindex print binary values in groups of four bits
11534 Print binary values in groups of four bits, known as @dfn{nibbles},
11535 when using the print command of @value{GDBN} with the option @samp{/t}.
11536 For example, this is what it looks like with @code{set print nibbles on}:
11537
11538 @smallexample
11539 @group
11540 (@value{GDBP}) print val_flags
11541 $1 = 1230
11542 (@value{GDBP}) print/t val_flags
11543 $2 = 0100 1100 1110
11544 @end group
11545 @end smallexample
11546
11547 @item set print nibbles off
11548 Don't printing binary values in groups. This is the default.
11549
11550 @item show print nibbles
11551 Show whether to print binary values in groups of four bits.
11552
11553 @anchor{set print elements}
11554 @item set print elements @var{number-of-elements}
11555 @itemx set print elements unlimited
11556 @cindex number of array elements to print
11557 @cindex limit on number of printed array elements
11558 Set a limit on how many elements of an array @value{GDBN} will print.
11559 If @value{GDBN} is printing a large array, it stops printing after it has
11560 printed the number of elements set by the @code{set print elements} command.
11561 This limit also applies to the display of strings.
11562 When @value{GDBN} starts, this limit is set to 200.
11563 Setting @var{number-of-elements} to @code{unlimited} or zero means
11564 that the number of elements to print is unlimited.
11565
11566 @item show print elements
11567 Display the number of elements of a large array that @value{GDBN} will print.
11568
11569 @anchor{set print frame-arguments}
11570 @item set print frame-arguments @var{value}
11571 @kindex set print frame-arguments
11572 @cindex printing frame argument values
11573 @cindex print all frame argument values
11574 @cindex print frame argument values for scalars only
11575 @cindex do not print frame arguments
11576 This command allows to control how the values of arguments are printed
11577 when the debugger prints a frame (@pxref{Frames}). The possible
11578 values are:
11579
11580 @table @code
11581 @item all
11582 The values of all arguments are printed.
11583
11584 @item scalars
11585 Print the value of an argument only if it is a scalar. The value of more
11586 complex arguments such as arrays, structures, unions, etc, is replaced
11587 by @code{@dots{}}. This is the default. Here is an example where
11588 only scalar arguments are shown:
11589
11590 @smallexample
11591 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11592 at frame-args.c:23
11593 @end smallexample
11594
11595 @item none
11596 None of the argument values are printed. Instead, the value of each argument
11597 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11598
11599 @smallexample
11600 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11601 at frame-args.c:23
11602 @end smallexample
11603
11604 @item presence
11605 Only the presence of arguments is indicated by @code{@dots{}}.
11606 The @code{@dots{}} are not printed for function without any arguments.
11607 None of the argument names and values are printed.
11608 In this case, the example above now becomes:
11609
11610 @smallexample
11611 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11612 @end smallexample
11613
11614 @end table
11615
11616 By default, only scalar arguments are printed. This command can be used
11617 to configure the debugger to print the value of all arguments, regardless
11618 of their type. However, it is often advantageous to not print the value
11619 of more complex parameters. For instance, it reduces the amount of
11620 information printed in each frame, making the backtrace more readable.
11621 Also, it improves performance when displaying Ada frames, because
11622 the computation of large arguments can sometimes be CPU-intensive,
11623 especially in large applications. Setting @code{print frame-arguments}
11624 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11625 this computation, thus speeding up the display of each Ada frame.
11626
11627 @item show print frame-arguments
11628 Show how the value of arguments should be displayed when printing a frame.
11629
11630 @anchor{set print raw-frame-arguments}
11631 @item set print raw-frame-arguments on
11632 Print frame arguments in raw, non pretty-printed, form.
11633
11634 @item set print raw-frame-arguments off
11635 Print frame arguments in pretty-printed form, if there is a pretty-printer
11636 for the value (@pxref{Pretty Printing}),
11637 otherwise print the value in raw form.
11638 This is the default.
11639
11640 @item show print raw-frame-arguments
11641 Show whether to print frame arguments in raw form.
11642
11643 @anchor{set print entry-values}
11644 @item set print entry-values @var{value}
11645 @kindex set print entry-values
11646 Set printing of frame argument values at function entry. In some cases
11647 @value{GDBN} can determine the value of function argument which was passed by
11648 the function caller, even if the value was modified inside the called function
11649 and therefore is different. With optimized code, the current value could be
11650 unavailable, but the entry value may still be known.
11651
11652 The default value is @code{default} (see below for its description). Older
11653 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11654 this feature will behave in the @code{default} setting the same way as with the
11655 @code{no} setting.
11656
11657 This functionality is currently supported only by DWARF 2 debugging format and
11658 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11659 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11660 this information.
11661
11662 The @var{value} parameter can be one of the following:
11663
11664 @table @code
11665 @item no
11666 Print only actual parameter values, never print values from function entry
11667 point.
11668 @smallexample
11669 #0 equal (val=5)
11670 #0 different (val=6)
11671 #0 lost (val=<optimized out>)
11672 #0 born (val=10)
11673 #0 invalid (val=<optimized out>)
11674 @end smallexample
11675
11676 @item only
11677 Print only parameter values from function entry point. The actual parameter
11678 values are never printed.
11679 @smallexample
11680 #0 equal (val@@entry=5)
11681 #0 different (val@@entry=5)
11682 #0 lost (val@@entry=5)
11683 #0 born (val@@entry=<optimized out>)
11684 #0 invalid (val@@entry=<optimized out>)
11685 @end smallexample
11686
11687 @item preferred
11688 Print only parameter values from function entry point. If value from function
11689 entry point is not known while the actual value is known, print the actual
11690 value for such parameter.
11691 @smallexample
11692 #0 equal (val@@entry=5)
11693 #0 different (val@@entry=5)
11694 #0 lost (val@@entry=5)
11695 #0 born (val=10)
11696 #0 invalid (val@@entry=<optimized out>)
11697 @end smallexample
11698
11699 @item if-needed
11700 Print actual parameter values. If actual parameter value is not known while
11701 value from function entry point is known, print the entry point value for such
11702 parameter.
11703 @smallexample
11704 #0 equal (val=5)
11705 #0 different (val=6)
11706 #0 lost (val@@entry=5)
11707 #0 born (val=10)
11708 #0 invalid (val=<optimized out>)
11709 @end smallexample
11710
11711 @item both
11712 Always print both the actual parameter value and its value from function entry
11713 point, even if values of one or both are not available due to compiler
11714 optimizations.
11715 @smallexample
11716 #0 equal (val=5, val@@entry=5)
11717 #0 different (val=6, val@@entry=5)
11718 #0 lost (val=<optimized out>, val@@entry=5)
11719 #0 born (val=10, val@@entry=<optimized out>)
11720 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11721 @end smallexample
11722
11723 @item compact
11724 Print the actual parameter value if it is known and also its value from
11725 function entry point if it is known. If neither is known, print for the actual
11726 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11727 values are known and identical, print the shortened
11728 @code{param=param@@entry=VALUE} notation.
11729 @smallexample
11730 #0 equal (val=val@@entry=5)
11731 #0 different (val=6, val@@entry=5)
11732 #0 lost (val@@entry=5)
11733 #0 born (val=10)
11734 #0 invalid (val=<optimized out>)
11735 @end smallexample
11736
11737 @item default
11738 Always print the actual parameter value. Print also its value from function
11739 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11740 if both values are known and identical, print the shortened
11741 @code{param=param@@entry=VALUE} notation.
11742 @smallexample
11743 #0 equal (val=val@@entry=5)
11744 #0 different (val=6, val@@entry=5)
11745 #0 lost (val=<optimized out>, val@@entry=5)
11746 #0 born (val=10)
11747 #0 invalid (val=<optimized out>)
11748 @end smallexample
11749 @end table
11750
11751 For analysis messages on possible failures of frame argument values at function
11752 entry resolution see @ref{set debug entry-values}.
11753
11754 @item show print entry-values
11755 Show the method being used for printing of frame argument values at function
11756 entry.
11757
11758 @anchor{set print frame-info}
11759 @item set print frame-info @var{value}
11760 @kindex set print frame-info
11761 @cindex printing frame information
11762 @cindex frame information, printing
11763 This command allows to control the information printed when
11764 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11765 for a general explanation about frames and frame information.
11766 Note that some other settings (such as @code{set print frame-arguments}
11767 and @code{set print address}) are also influencing if and how some frame
11768 information is displayed. In particular, the frame program counter is never
11769 printed if @code{set print address} is off.
11770
11771 The possible values for @code{set print frame-info} are:
11772 @table @code
11773 @item short-location
11774 Print the frame level, the program counter (if not at the
11775 beginning of the location source line), the function, the function
11776 arguments.
11777 @item location
11778 Same as @code{short-location} but also print the source file and source line
11779 number.
11780 @item location-and-address
11781 Same as @code{location} but print the program counter even if located at the
11782 beginning of the location source line.
11783 @item source-line
11784 Print the program counter (if not at the beginning of the location
11785 source line), the line number and the source line.
11786 @item source-and-location
11787 Print what @code{location} and @code{source-line} are printing.
11788 @item auto
11789 The information printed for a frame is decided automatically
11790 by the @value{GDBN} command that prints a frame.
11791 For example, @code{frame} prints the information printed by
11792 @code{source-and-location} while @code{stepi} will switch between
11793 @code{source-line} and @code{source-and-location} depending on the program
11794 counter.
11795 The default value is @code{auto}.
11796 @end table
11797
11798 @anchor{set print repeats}
11799 @item set print repeats @var{number-of-repeats}
11800 @itemx set print repeats unlimited
11801 @cindex repeated array elements
11802 Set the threshold for suppressing display of repeated array
11803 elements. When the number of consecutive identical elements of an
11804 array exceeds the threshold, @value{GDBN} prints the string
11805 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11806 identical repetitions, instead of displaying the identical elements
11807 themselves. Setting the threshold to @code{unlimited} or zero will
11808 cause all elements to be individually printed. The default threshold
11809 is 10.
11810
11811 @item show print repeats
11812 Display the current threshold for printing repeated identical
11813 elements.
11814
11815 @anchor{set print max-depth}
11816 @item set print max-depth @var{depth}
11817 @item set print max-depth unlimited
11818 @cindex printing nested structures
11819 Set the threshold after which nested structures are replaced with
11820 ellipsis, this can make visualising deeply nested structures easier.
11821
11822 For example, given this C code
11823
11824 @smallexample
11825 typedef struct s1 @{ int a; @} s1;
11826 typedef struct s2 @{ s1 b; @} s2;
11827 typedef struct s3 @{ s2 c; @} s3;
11828 typedef struct s4 @{ s3 d; @} s4;
11829
11830 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11831 @end smallexample
11832
11833 The following table shows how different values of @var{depth} will
11834 effect how @code{var} is printed by @value{GDBN}:
11835
11836 @multitable @columnfractions .3 .7
11837 @headitem @var{depth} setting @tab Result of @samp{p var}
11838 @item unlimited
11839 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11840 @item @code{0}
11841 @tab @code{$1 = @{...@}}
11842 @item @code{1}
11843 @tab @code{$1 = @{d = @{...@}@}}
11844 @item @code{2}
11845 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11846 @item @code{3}
11847 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11848 @item @code{4}
11849 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11850 @end multitable
11851
11852 To see the contents of structures that have been hidden the user can
11853 either increase the print max-depth, or they can print the elements of
11854 the structure that are visible, for example
11855
11856 @smallexample
11857 (gdb) set print max-depth 2
11858 (gdb) p var
11859 $1 = @{d = @{c = @{...@}@}@}
11860 (gdb) p var.d
11861 $2 = @{c = @{b = @{...@}@}@}
11862 (gdb) p var.d.c
11863 $3 = @{b = @{a = 3@}@}
11864 @end smallexample
11865
11866 The pattern used to replace nested structures varies based on
11867 language, for most languages @code{@{...@}} is used, but Fortran uses
11868 @code{(...)}.
11869
11870 @item show print max-depth
11871 Display the current threshold after which nested structures are
11872 replaces with ellipsis.
11873
11874 @anchor{set print memory-tag-violations}
11875 @cindex printing memory tag violation information
11876 @item set print memory-tag-violations
11877 @itemx set print memory-tag-violations on
11878 Cause @value{GDBN} to display additional information about memory tag violations
11879 when printing pointers and addresses.
11880
11881 @item set print memory-tag-violations off
11882 Stop printing memory tag violation information.
11883
11884 @item show print memory-tag-violations
11885 Show whether memory tag violation information is displayed when printing
11886 pointers and addresses.
11887
11888 @anchor{set print null-stop}
11889 @item set print null-stop
11890 @cindex @sc{null} elements in arrays
11891 Cause @value{GDBN} to stop printing the characters of an array when the first
11892 @sc{null} is encountered. This is useful when large arrays actually
11893 contain only short strings.
11894 The default is off.
11895
11896 @item show print null-stop
11897 Show whether @value{GDBN} stops printing an array on the first
11898 @sc{null} character.
11899
11900 @anchor{set print pretty}
11901 @item set print pretty on
11902 @cindex print structures in indented form
11903 @cindex indentation in structure display
11904 Cause @value{GDBN} to print structures in an indented format with one member
11905 per line, like this:
11906
11907 @smallexample
11908 @group
11909 $1 = @{
11910 next = 0x0,
11911 flags = @{
11912 sweet = 1,
11913 sour = 1
11914 @},
11915 meat = 0x54 "Pork"
11916 @}
11917 @end group
11918 @end smallexample
11919
11920 @item set print pretty off
11921 Cause @value{GDBN} to print structures in a compact format, like this:
11922
11923 @smallexample
11924 @group
11925 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11926 meat = 0x54 "Pork"@}
11927 @end group
11928 @end smallexample
11929
11930 @noindent
11931 This is the default format.
11932
11933 @item show print pretty
11934 Show which format @value{GDBN} is using to print structures.
11935
11936 @anchor{set print raw-values}
11937 @item set print raw-values on
11938 Print values in raw form, without applying the pretty
11939 printers for the value.
11940
11941 @item set print raw-values off
11942 Print values in pretty-printed form, if there is a pretty-printer
11943 for the value (@pxref{Pretty Printing}),
11944 otherwise print the value in raw form.
11945
11946 The default setting is ``off''.
11947
11948 @item show print raw-values
11949 Show whether to print values in raw form.
11950
11951 @item set print sevenbit-strings on
11952 @cindex eight-bit characters in strings
11953 @cindex octal escapes in strings
11954 Print using only seven-bit characters; if this option is set,
11955 @value{GDBN} displays any eight-bit characters (in strings or
11956 character values) using the notation @code{\}@var{nnn}. This setting is
11957 best if you are working in English (@sc{ascii}) and you use the
11958 high-order bit of characters as a marker or ``meta'' bit.
11959
11960 @item set print sevenbit-strings off
11961 Print full eight-bit characters. This allows the use of more
11962 international character sets, and is the default.
11963
11964 @item show print sevenbit-strings
11965 Show whether or not @value{GDBN} is printing only seven-bit characters.
11966
11967 @anchor{set print union}
11968 @item set print union on
11969 @cindex unions in structures, printing
11970 Tell @value{GDBN} to print unions which are contained in structures
11971 and other unions. This is the default setting.
11972
11973 @item set print union off
11974 Tell @value{GDBN} not to print unions which are contained in
11975 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11976 instead.
11977
11978 @item show print union
11979 Ask @value{GDBN} whether or not it will print unions which are contained in
11980 structures and other unions.
11981
11982 For example, given the declarations
11983
11984 @smallexample
11985 typedef enum @{Tree, Bug@} Species;
11986 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11987 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11988 Bug_forms;
11989
11990 struct thing @{
11991 Species it;
11992 union @{
11993 Tree_forms tree;
11994 Bug_forms bug;
11995 @} form;
11996 @};
11997
11998 struct thing foo = @{Tree, @{Acorn@}@};
11999 @end smallexample
12000
12001 @noindent
12002 with @code{set print union on} in effect @samp{p foo} would print
12003
12004 @smallexample
12005 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
12006 @end smallexample
12007
12008 @noindent
12009 and with @code{set print union off} in effect it would print
12010
12011 @smallexample
12012 $1 = @{it = Tree, form = @{...@}@}
12013 @end smallexample
12014
12015 @noindent
12016 @code{set print union} affects programs written in C-like languages
12017 and in Pascal.
12018 @end table
12019
12020 @need 1000
12021 @noindent
12022 These settings are of interest when debugging C@t{++} programs:
12023
12024 @table @code
12025 @cindex demangling C@t{++} names
12026 @item set print demangle
12027 @itemx set print demangle on
12028 Print C@t{++} names in their source form rather than in the encoded
12029 (``mangled'') form passed to the assembler and linker for type-safe
12030 linkage. The default is on.
12031
12032 @item show print demangle
12033 Show whether C@t{++} names are printed in mangled or demangled form.
12034
12035 @item set print asm-demangle
12036 @itemx set print asm-demangle on
12037 Print C@t{++} names in their source form rather than their mangled form, even
12038 in assembler code printouts such as instruction disassemblies.
12039 The default is off.
12040
12041 @item show print asm-demangle
12042 Show whether C@t{++} names in assembly listings are printed in mangled
12043 or demangled form.
12044
12045 @cindex C@t{++} symbol decoding style
12046 @cindex symbol decoding style, C@t{++}
12047 @kindex set demangle-style
12048 @item set demangle-style @var{style}
12049 Choose among several encoding schemes used by different compilers to represent
12050 C@t{++} names. If you omit @var{style}, you will see a list of possible
12051 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
12052 decoding style by inspecting your program.
12053
12054 @item show demangle-style
12055 Display the encoding style currently in use for decoding C@t{++} symbols.
12056
12057 @anchor{set print object}
12058 @item set print object
12059 @itemx set print object on
12060 @cindex derived type of an object, printing
12061 @cindex display derived types
12062 When displaying a pointer to an object, identify the @emph{actual}
12063 (derived) type of the object rather than the @emph{declared} type, using
12064 the virtual function table. Note that the virtual function table is
12065 required---this feature can only work for objects that have run-time
12066 type identification; a single virtual method in the object's declared
12067 type is sufficient. Note that this setting is also taken into account when
12068 working with variable objects via MI (@pxref{GDB/MI}).
12069
12070 @item set print object off
12071 Display only the declared type of objects, without reference to the
12072 virtual function table. This is the default setting.
12073
12074 @item show print object
12075 Show whether actual, or declared, object types are displayed.
12076
12077 @anchor{set print static-members}
12078 @item set print static-members
12079 @itemx set print static-members on
12080 @cindex static members of C@t{++} objects
12081 Print static members when displaying a C@t{++} object. The default is on.
12082
12083 @item set print static-members off
12084 Do not print static members when displaying a C@t{++} object.
12085
12086 @item show print static-members
12087 Show whether C@t{++} static members are printed or not.
12088
12089 @item set print pascal_static-members
12090 @itemx set print pascal_static-members on
12091 @cindex static members of Pascal objects
12092 @cindex Pascal objects, static members display
12093 Print static members when displaying a Pascal object. The default is on.
12094
12095 @item set print pascal_static-members off
12096 Do not print static members when displaying a Pascal object.
12097
12098 @item show print pascal_static-members
12099 Show whether Pascal static members are printed or not.
12100
12101 @c These don't work with HP ANSI C++ yet.
12102 @anchor{set print vtbl}
12103 @item set print vtbl
12104 @itemx set print vtbl on
12105 @cindex pretty print C@t{++} virtual function tables
12106 @cindex virtual functions (C@t{++}) display
12107 @cindex VTBL display
12108 Pretty print C@t{++} virtual function tables. The default is off.
12109 (The @code{vtbl} commands do not work on programs compiled with the HP
12110 ANSI C@t{++} compiler (@code{aCC}).)
12111
12112 @item set print vtbl off
12113 Do not pretty print C@t{++} virtual function tables.
12114
12115 @item show print vtbl
12116 Show whether C@t{++} virtual function tables are pretty printed, or not.
12117 @end table
12118
12119 @node Pretty Printing
12120 @section Pretty Printing
12121
12122 @value{GDBN} provides a mechanism to allow pretty-printing of values using
12123 Python code. It greatly simplifies the display of complex objects. This
12124 mechanism works for both MI and the CLI.
12125
12126 @menu
12127 * Pretty-Printer Introduction:: Introduction to pretty-printers
12128 * Pretty-Printer Example:: An example pretty-printer
12129 * Pretty-Printer Commands:: Pretty-printer commands
12130 @end menu
12131
12132 @node Pretty-Printer Introduction
12133 @subsection Pretty-Printer Introduction
12134
12135 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
12136 registered for the value. If there is then @value{GDBN} invokes the
12137 pretty-printer to print the value. Otherwise the value is printed normally.
12138
12139 Pretty-printers are normally named. This makes them easy to manage.
12140 The @samp{info pretty-printer} command will list all the installed
12141 pretty-printers with their names.
12142 If a pretty-printer can handle multiple data types, then its
12143 @dfn{subprinters} are the printers for the individual data types.
12144 Each such subprinter has its own name.
12145 The format of the name is @var{printer-name};@var{subprinter-name}.
12146
12147 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
12148 Typically they are automatically loaded and registered when the corresponding
12149 debug information is loaded, thus making them available without having to
12150 do anything special.
12151
12152 There are three places where a pretty-printer can be registered.
12153
12154 @itemize @bullet
12155 @item
12156 Pretty-printers registered globally are available when debugging
12157 all inferiors.
12158
12159 @item
12160 Pretty-printers registered with a program space are available only
12161 when debugging that program.
12162 @xref{Progspaces In Python}, for more details on program spaces in Python.
12163
12164 @item
12165 Pretty-printers registered with an objfile are loaded and unloaded
12166 with the corresponding objfile (e.g., shared library).
12167 @xref{Objfiles In Python}, for more details on objfiles in Python.
12168 @end itemize
12169
12170 @xref{Selecting Pretty-Printers}, for further information on how
12171 pretty-printers are selected,
12172
12173 @xref{Writing a Pretty-Printer}, for implementing pretty printers
12174 for new types.
12175
12176 @node Pretty-Printer Example
12177 @subsection Pretty-Printer Example
12178
12179 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
12180
12181 @smallexample
12182 (@value{GDBP}) print s
12183 $1 = @{
12184 static npos = 4294967295,
12185 _M_dataplus = @{
12186 <std::allocator<char>> = @{
12187 <__gnu_cxx::new_allocator<char>> = @{
12188 <No data fields>@}, <No data fields>
12189 @},
12190 members of std::basic_string<char, std::char_traits<char>,
12191 std::allocator<char> >::_Alloc_hider:
12192 _M_p = 0x804a014 "abcd"
12193 @}
12194 @}
12195 @end smallexample
12196
12197 With a pretty-printer for @code{std::string} only the contents are printed:
12198
12199 @smallexample
12200 (@value{GDBP}) print s
12201 $2 = "abcd"
12202 @end smallexample
12203
12204 @node Pretty-Printer Commands
12205 @subsection Pretty-Printer Commands
12206 @cindex pretty-printer commands
12207
12208 @table @code
12209 @kindex info pretty-printer
12210 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12211 Print the list of installed pretty-printers.
12212 This includes disabled pretty-printers, which are marked as such.
12213
12214 @var{object-regexp} is a regular expression matching the objects
12215 whose pretty-printers to list.
12216 Objects can be @code{global}, the program space's file
12217 (@pxref{Progspaces In Python}),
12218 and the object files within that program space (@pxref{Objfiles In Python}).
12219 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
12220 looks up a printer from these three objects.
12221
12222 @var{name-regexp} is a regular expression matching the name of the printers
12223 to list.
12224
12225 @kindex disable pretty-printer
12226 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12227 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12228 A disabled pretty-printer is not forgotten, it may be enabled again later.
12229
12230 @kindex enable pretty-printer
12231 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12232 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12233 @end table
12234
12235 Example:
12236
12237 Suppose we have three pretty-printers installed: one from library1.so
12238 named @code{foo} that prints objects of type @code{foo}, and
12239 another from library2.so named @code{bar} that prints two types of objects,
12240 @code{bar1} and @code{bar2}.
12241
12242 @smallexample
12243 @group
12244 (@value{GDBP}) info pretty-printer
12245 library1.so:
12246 foo
12247 library2.so:
12248 bar
12249 bar1
12250 bar2
12251 @end group
12252 @group
12253 (@value{GDBP}) info pretty-printer library2
12254 library2.so:
12255 bar
12256 bar1
12257 bar2
12258 @end group
12259 @group
12260 (@value{GDBP}) disable pretty-printer library1
12261 1 printer disabled
12262 2 of 3 printers enabled
12263 (@value{GDBP}) info pretty-printer
12264 library1.so:
12265 foo [disabled]
12266 library2.so:
12267 bar
12268 bar1
12269 bar2
12270 @end group
12271 @group
12272 (@value{GDBP}) disable pretty-printer library2 bar;bar1
12273 1 printer disabled
12274 1 of 3 printers enabled
12275 (@value{GDBP}) info pretty-printer library2
12276 library2.so:
12277 bar
12278 bar1 [disabled]
12279 bar2
12280 @end group
12281 @group
12282 (@value{GDBP}) disable pretty-printer library2 bar
12283 1 printer disabled
12284 0 of 3 printers enabled
12285 (@value{GDBP}) info pretty-printer
12286 library1.so:
12287 foo [disabled]
12288 library2.so:
12289 bar [disabled]
12290 bar1 [disabled]
12291 bar2
12292 @end group
12293 @end smallexample
12294
12295 Note that for @code{bar} the entire printer can be disabled,
12296 as can each individual subprinter.
12297
12298 Printing values and frame arguments is done by default using
12299 the enabled pretty printers.
12300
12301 The print option @code{-raw-values} and @value{GDBN} setting
12302 @code{set print raw-values} (@pxref{set print raw-values}) can be
12303 used to print values without applying the enabled pretty printers.
12304
12305 Similarly, the backtrace option @code{-raw-frame-arguments} and
12306 @value{GDBN} setting @code{set print raw-frame-arguments}
12307 (@pxref{set print raw-frame-arguments}) can be used to ignore the
12308 enabled pretty printers when printing frame argument values.
12309
12310 @node Value History
12311 @section Value History
12312
12313 @cindex value history
12314 @cindex history of values printed by @value{GDBN}
12315 Values printed by the @code{print} command are saved in the @value{GDBN}
12316 @dfn{value history}. This allows you to refer to them in other expressions.
12317 Values are kept until the symbol table is re-read or discarded
12318 (for example with the @code{file} or @code{symbol-file} commands).
12319 When the symbol table changes, the value history is discarded,
12320 since the values may contain pointers back to the types defined in the
12321 symbol table.
12322
12323 @cindex @code{$}
12324 @cindex @code{$$}
12325 @cindex history number
12326 The values printed are given @dfn{history numbers} by which you can
12327 refer to them. These are successive integers starting with one.
12328 @code{print} shows you the history number assigned to a value by
12329 printing @samp{$@var{num} = } before the value; here @var{num} is the
12330 history number.
12331
12332 To refer to any previous value, use @samp{$} followed by the value's
12333 history number. The way @code{print} labels its output is designed to
12334 remind you of this. Just @code{$} refers to the most recent value in
12335 the history, and @code{$$} refers to the value before that.
12336 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
12337 is the value just prior to @code{$$}, @code{$$1} is equivalent to
12338 @code{$$}, and @code{$$0} is equivalent to @code{$}.
12339
12340 For example, suppose you have just printed a pointer to a structure and
12341 want to see the contents of the structure. It suffices to type
12342
12343 @smallexample
12344 p *$
12345 @end smallexample
12346
12347 If you have a chain of structures where the component @code{next} points
12348 to the next one, you can print the contents of the next one with this:
12349
12350 @smallexample
12351 p *$.next
12352 @end smallexample
12353
12354 @noindent
12355 You can print successive links in the chain by repeating this
12356 command---which you can do by just typing @key{RET}.
12357
12358 Note that the history records values, not expressions. If the value of
12359 @code{x} is 4 and you type these commands:
12360
12361 @smallexample
12362 print x
12363 set x=5
12364 @end smallexample
12365
12366 @noindent
12367 then the value recorded in the value history by the @code{print} command
12368 remains 4 even though the value of @code{x} has changed.
12369
12370 @table @code
12371 @kindex show values
12372 @item show values
12373 Print the last ten values in the value history, with their item numbers.
12374 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12375 values} does not change the history.
12376
12377 @item show values @var{n}
12378 Print ten history values centered on history item number @var{n}.
12379
12380 @item show values +
12381 Print ten history values just after the values last printed. If no more
12382 values are available, @code{show values +} produces no display.
12383 @end table
12384
12385 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12386 same effect as @samp{show values +}.
12387
12388 @node Convenience Vars
12389 @section Convenience Variables
12390
12391 @cindex convenience variables
12392 @cindex user-defined variables
12393 @value{GDBN} provides @dfn{convenience variables} that you can use within
12394 @value{GDBN} to hold on to a value and refer to it later. These variables
12395 exist entirely within @value{GDBN}; they are not part of your program, and
12396 setting a convenience variable has no direct effect on further execution
12397 of your program. That is why you can use them freely.
12398
12399 Convenience variables are prefixed with @samp{$}. Any name preceded by
12400 @samp{$} can be used for a convenience variable, unless it is one of
12401 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12402 (Value history references, in contrast, are @emph{numbers} preceded
12403 by @samp{$}. @xref{Value History, ,Value History}.)
12404
12405 You can save a value in a convenience variable with an assignment
12406 expression, just as you would set a variable in your program.
12407 For example:
12408
12409 @smallexample
12410 set $foo = *object_ptr
12411 @end smallexample
12412
12413 @noindent
12414 would save in @code{$foo} the value contained in the object pointed to by
12415 @code{object_ptr}.
12416
12417 Using a convenience variable for the first time creates it, but its
12418 value is @code{void} until you assign a new value. You can alter the
12419 value with another assignment at any time.
12420
12421 Convenience variables have no fixed types. You can assign a convenience
12422 variable any type of value, including structures and arrays, even if
12423 that variable already has a value of a different type. The convenience
12424 variable, when used as an expression, has the type of its current value.
12425
12426 @table @code
12427 @kindex show convenience
12428 @cindex show all user variables and functions
12429 @item show convenience
12430 Print a list of convenience variables used so far, and their values,
12431 as well as a list of the convenience functions.
12432 Abbreviated @code{show conv}.
12433
12434 @kindex init-if-undefined
12435 @cindex convenience variables, initializing
12436 @item init-if-undefined $@var{variable} = @var{expression}
12437 Set a convenience variable if it has not already been set. This is useful
12438 for user-defined commands that keep some state. It is similar, in concept,
12439 to using local static variables with initializers in C (except that
12440 convenience variables are global). It can also be used to allow users to
12441 override default values used in a command script.
12442
12443 If the variable is already defined then the expression is not evaluated so
12444 any side-effects do not occur.
12445 @end table
12446
12447 One of the ways to use a convenience variable is as a counter to be
12448 incremented or a pointer to be advanced. For example, to print
12449 a field from successive elements of an array of structures:
12450
12451 @smallexample
12452 set $i = 0
12453 print bar[$i++]->contents
12454 @end smallexample
12455
12456 @noindent
12457 Repeat that command by typing @key{RET}.
12458
12459 Some convenience variables are created automatically by @value{GDBN} and given
12460 values likely to be useful.
12461
12462 @table @code
12463 @vindex $_@r{, convenience variable}
12464 @item $_
12465 The variable @code{$_} is automatically set by the @code{x} command to
12466 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12467 commands which provide a default address for @code{x} to examine also
12468 set @code{$_} to that address; these commands include @code{info line}
12469 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12470 except when set by the @code{x} command, in which case it is a pointer
12471 to the type of @code{$__}.
12472
12473 @vindex $__@r{, convenience variable}
12474 @item $__
12475 The variable @code{$__} is automatically set by the @code{x} command
12476 to the value found in the last address examined. Its type is chosen
12477 to match the format in which the data was printed.
12478
12479 @item $_exitcode
12480 @vindex $_exitcode@r{, convenience variable}
12481 When the program being debugged terminates normally, @value{GDBN}
12482 automatically sets this variable to the exit code of the program, and
12483 resets @code{$_exitsignal} to @code{void}.
12484
12485 @item $_exitsignal
12486 @vindex $_exitsignal@r{, convenience variable}
12487 When the program being debugged dies due to an uncaught signal,
12488 @value{GDBN} automatically sets this variable to that signal's number,
12489 and resets @code{$_exitcode} to @code{void}.
12490
12491 To distinguish between whether the program being debugged has exited
12492 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12493 @code{$_exitsignal} is not @code{void}), the convenience function
12494 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12495 Functions}). For example, considering the following source code:
12496
12497 @smallexample
12498 #include <signal.h>
12499
12500 int
12501 main (int argc, char *argv[])
12502 @{
12503 raise (SIGALRM);
12504 return 0;
12505 @}
12506 @end smallexample
12507
12508 A valid way of telling whether the program being debugged has exited
12509 or signalled would be:
12510
12511 @smallexample
12512 (@value{GDBP}) define has_exited_or_signalled
12513 Type commands for definition of ``has_exited_or_signalled''.
12514 End with a line saying just ``end''.
12515 >if $_isvoid ($_exitsignal)
12516 >echo The program has exited\n
12517 >else
12518 >echo The program has signalled\n
12519 >end
12520 >end
12521 (@value{GDBP}) run
12522 Starting program:
12523
12524 Program terminated with signal SIGALRM, Alarm clock.
12525 The program no longer exists.
12526 (@value{GDBP}) has_exited_or_signalled
12527 The program has signalled
12528 @end smallexample
12529
12530 As can be seen, @value{GDBN} correctly informs that the program being
12531 debugged has signalled, since it calls @code{raise} and raises a
12532 @code{SIGALRM} signal. If the program being debugged had not called
12533 @code{raise}, then @value{GDBN} would report a normal exit:
12534
12535 @smallexample
12536 (@value{GDBP}) has_exited_or_signalled
12537 The program has exited
12538 @end smallexample
12539
12540 @item $_exception
12541 The variable @code{$_exception} is set to the exception object being
12542 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12543
12544 @item $_ada_exception
12545 The variable @code{$_ada_exception} is set to the address of the
12546 exception being caught or thrown at an Ada exception-related
12547 catchpoint. @xref{Set Catchpoints}.
12548
12549 @item $_probe_argc
12550 @itemx $_probe_arg0@dots{}$_probe_arg11
12551 Arguments to a static probe. @xref{Static Probe Points}.
12552
12553 @item $_sdata
12554 @vindex $_sdata@r{, inspect, convenience variable}
12555 The variable @code{$_sdata} contains extra collected static tracepoint
12556 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12557 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12558 if extra static tracepoint data has not been collected.
12559
12560 @item $_siginfo
12561 @vindex $_siginfo@r{, convenience variable}
12562 The variable @code{$_siginfo} contains extra signal information
12563 (@pxref{extra signal information}). Note that @code{$_siginfo}
12564 could be empty, if the application has not yet received any signals.
12565 For example, it will be empty before you execute the @code{run} command.
12566
12567 @item $_tlb
12568 @vindex $_tlb@r{, convenience variable}
12569 The variable @code{$_tlb} is automatically set when debugging
12570 applications running on MS-Windows in native mode or connected to
12571 gdbserver that supports the @code{qGetTIBAddr} request.
12572 @xref{General Query Packets}.
12573 This variable contains the address of the thread information block.
12574
12575 @item $_inferior
12576 The number of the current inferior. @xref{Inferiors Connections and
12577 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12578
12579 @item $_thread
12580 The thread number of the current thread. @xref{thread numbers}.
12581
12582 @item $_gthread
12583 The global number of the current thread. @xref{global thread numbers}.
12584
12585 @item $_gdb_major
12586 @itemx $_gdb_minor
12587 @vindex $_gdb_major@r{, convenience variable}
12588 @vindex $_gdb_minor@r{, convenience variable}
12589 The major and minor version numbers of the running @value{GDBN}.
12590 Development snapshots and pretest versions have their minor version
12591 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12592 the value 12 for @code{$_gdb_minor}. These variables allow you to
12593 write scripts that work with different versions of @value{GDBN}
12594 without errors caused by features unavailable in some of those
12595 versions.
12596
12597 @item $_shell_exitcode
12598 @itemx $_shell_exitsignal
12599 @vindex $_shell_exitcode@r{, convenience variable}
12600 @vindex $_shell_exitsignal@r{, convenience variable}
12601 @cindex shell command, exit code
12602 @cindex shell command, exit signal
12603 @cindex exit status of shell commands
12604 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12605 shell commands. When a launched command terminates, @value{GDBN}
12606 automatically maintains the variables @code{$_shell_exitcode}
12607 and @code{$_shell_exitsignal} according to the exit status of the last
12608 launched command. These variables are set and used similarly to
12609 the variables @code{$_exitcode} and @code{$_exitsignal}.
12610
12611 @end table
12612
12613 @node Convenience Funs
12614 @section Convenience Functions
12615
12616 @cindex convenience functions
12617 @value{GDBN} also supplies some @dfn{convenience functions}. These
12618 have a syntax similar to convenience variables. A convenience
12619 function can be used in an expression just like an ordinary function;
12620 however, a convenience function is implemented internally to
12621 @value{GDBN}.
12622
12623 These functions do not require @value{GDBN} to be configured with
12624 @code{Python} support, which means that they are always available.
12625
12626 @table @code
12627
12628 @item $_isvoid (@var{expr})
12629 @findex $_isvoid@r{, convenience function}
12630 Return one if the expression @var{expr} is @code{void}. Otherwise it
12631 returns zero.
12632
12633 A @code{void} expression is an expression where the type of the result
12634 is @code{void}. For example, you can examine a convenience variable
12635 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12636 it is @code{void}:
12637
12638 @smallexample
12639 (@value{GDBP}) print $_exitcode
12640 $1 = void
12641 (@value{GDBP}) print $_isvoid ($_exitcode)
12642 $2 = 1
12643 (@value{GDBP}) run
12644 Starting program: ./a.out
12645 [Inferior 1 (process 29572) exited normally]
12646 (@value{GDBP}) print $_exitcode
12647 $3 = 0
12648 (@value{GDBP}) print $_isvoid ($_exitcode)
12649 $4 = 0
12650 @end smallexample
12651
12652 In the example above, we used @code{$_isvoid} to check whether
12653 @code{$_exitcode} is @code{void} before and after the execution of the
12654 program being debugged. Before the execution there is no exit code to
12655 be examined, therefore @code{$_exitcode} is @code{void}. After the
12656 execution the program being debugged returned zero, therefore
12657 @code{$_exitcode} is zero, which means that it is not @code{void}
12658 anymore.
12659
12660 The @code{void} expression can also be a call of a function from the
12661 program being debugged. For example, given the following function:
12662
12663 @smallexample
12664 void
12665 foo (void)
12666 @{
12667 @}
12668 @end smallexample
12669
12670 The result of calling it inside @value{GDBN} is @code{void}:
12671
12672 @smallexample
12673 (@value{GDBP}) print foo ()
12674 $1 = void
12675 (@value{GDBP}) print $_isvoid (foo ())
12676 $2 = 1
12677 (@value{GDBP}) set $v = foo ()
12678 (@value{GDBP}) print $v
12679 $3 = void
12680 (@value{GDBP}) print $_isvoid ($v)
12681 $4 = 1
12682 @end smallexample
12683
12684 @item $_gdb_setting_str (@var{setting})
12685 @findex $_gdb_setting_str@r{, convenience function}
12686 Return the value of the @value{GDBN} @var{setting} as a string.
12687 @var{setting} is any setting that can be used in a @code{set} or
12688 @code{show} command (@pxref{Controlling GDB}).
12689
12690 @smallexample
12691 (@value{GDBP}) show print frame-arguments
12692 Printing of non-scalar frame arguments is "scalars".
12693 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12694 $1 = "scalars"
12695 (@value{GDBP}) p $_gdb_setting_str("height")
12696 $2 = "30"
12697 (@value{GDBP})
12698 @end smallexample
12699
12700 @item $_gdb_setting (@var{setting})
12701 @findex $_gdb_setting@r{, convenience function}
12702 Return the value of the @value{GDBN} @var{setting}.
12703 The type of the returned value depends on the setting.
12704
12705 The value type for boolean and auto boolean settings is @code{int}.
12706 The boolean values @code{off} and @code{on} are converted to
12707 the integer values @code{0} and @code{1}. The value @code{auto} is
12708 converted to the value @code{-1}.
12709
12710 The value type for integer settings is either @code{unsigned int}
12711 or @code{int}, depending on the setting.
12712
12713 Some integer settings accept an @code{unlimited} value.
12714 Depending on the setting, the @code{set} command also accepts
12715 the value @code{0} or the value @code{@minus{}1} as a synonym for
12716 @code{unlimited}.
12717 For example, @code{set height unlimited} is equivalent to
12718 @code{set height 0}.
12719
12720 Some other settings that accept the @code{unlimited} value
12721 use the value @code{0} to literally mean zero.
12722 For example, @code{set history size 0} indicates to not
12723 record any @value{GDBN} commands in the command history.
12724 For such settings, @code{@minus{}1} is the synonym
12725 for @code{unlimited}.
12726
12727 See the documentation of the corresponding @code{set} command for
12728 the numerical value equivalent to @code{unlimited}.
12729
12730 The @code{$_gdb_setting} function converts the unlimited value
12731 to a @code{0} or a @code{@minus{}1} value according to what the
12732 @code{set} command uses.
12733
12734 @smallexample
12735 @group
12736 (@value{GDBP}) p $_gdb_setting_str("height")
12737 $1 = "30"
12738 (@value{GDBP}) p $_gdb_setting("height")
12739 $2 = 30
12740 (@value{GDBP}) set height unlimited
12741 (@value{GDBP}) p $_gdb_setting_str("height")
12742 $3 = "unlimited"
12743 (@value{GDBP}) p $_gdb_setting("height")
12744 $4 = 0
12745 @end group
12746 @group
12747 (@value{GDBP}) p $_gdb_setting_str("history size")
12748 $5 = "unlimited"
12749 (@value{GDBP}) p $_gdb_setting("history size")
12750 $6 = -1
12751 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12752 $7 = "auto"
12753 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12754 $8 = -1
12755 (@value{GDBP})
12756 @end group
12757 @end smallexample
12758
12759 Other setting types (enum, filename, optional filename, string, string noescape)
12760 are returned as string values.
12761
12762
12763 @item $_gdb_maint_setting_str (@var{setting})
12764 @findex $_gdb_maint_setting_str@r{, convenience function}
12765 Like the @code{$_gdb_setting_str} function, but works with
12766 @code{maintenance set} variables.
12767
12768 @item $_gdb_maint_setting (@var{setting})
12769 @findex $_gdb_maint_setting@r{, convenience function}
12770 Like the @code{$_gdb_setting} function, but works with
12771 @code{maintenance set} variables.
12772
12773 @end table
12774
12775 The following functions require @value{GDBN} to be configured with
12776 @code{Python} support.
12777
12778 @table @code
12779
12780 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12781 @findex $_memeq@r{, convenience function}
12782 Returns one if the @var{length} bytes at the addresses given by
12783 @var{buf1} and @var{buf2} are equal.
12784 Otherwise it returns zero.
12785
12786 @item $_regex(@var{str}, @var{regex})
12787 @findex $_regex@r{, convenience function}
12788 Returns one if the string @var{str} matches the regular expression
12789 @var{regex}. Otherwise it returns zero.
12790 The syntax of the regular expression is that specified by @code{Python}'s
12791 regular expression support.
12792
12793 @item $_streq(@var{str1}, @var{str2})
12794 @findex $_streq@r{, convenience function}
12795 Returns one if the strings @var{str1} and @var{str2} are equal.
12796 Otherwise it returns zero.
12797
12798 @item $_strlen(@var{str})
12799 @findex $_strlen@r{, convenience function}
12800 Returns the length of string @var{str}.
12801
12802 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12803 @findex $_caller_is@r{, convenience function}
12804 Returns one if the calling function's name is equal to @var{name}.
12805 Otherwise it returns zero.
12806
12807 If the optional argument @var{number_of_frames} is provided,
12808 it is the number of frames up in the stack to look.
12809 The default is 1.
12810
12811 Example:
12812
12813 @smallexample
12814 (gdb) backtrace
12815 #0 bottom_func ()
12816 at testsuite/gdb.python/py-caller-is.c:21
12817 #1 0x00000000004005a0 in middle_func ()
12818 at testsuite/gdb.python/py-caller-is.c:27
12819 #2 0x00000000004005ab in top_func ()
12820 at testsuite/gdb.python/py-caller-is.c:33
12821 #3 0x00000000004005b6 in main ()
12822 at testsuite/gdb.python/py-caller-is.c:39
12823 (gdb) print $_caller_is ("middle_func")
12824 $1 = 1
12825 (gdb) print $_caller_is ("top_func", 2)
12826 $1 = 1
12827 @end smallexample
12828
12829 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12830 @findex $_caller_matches@r{, convenience function}
12831 Returns one if the calling function's name matches the regular expression
12832 @var{regexp}. Otherwise it returns zero.
12833
12834 If the optional argument @var{number_of_frames} is provided,
12835 it is the number of frames up in the stack to look.
12836 The default is 1.
12837
12838 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12839 @findex $_any_caller_is@r{, convenience function}
12840 Returns one if any calling function's name is equal to @var{name}.
12841 Otherwise it returns zero.
12842
12843 If the optional argument @var{number_of_frames} is provided,
12844 it is the number of frames up in the stack to look.
12845 The default is 1.
12846
12847 This function differs from @code{$_caller_is} in that this function
12848 checks all stack frames from the immediate caller to the frame specified
12849 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12850 frame specified by @var{number_of_frames}.
12851
12852 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12853 @findex $_any_caller_matches@r{, convenience function}
12854 Returns one if any calling function's name matches the regular expression
12855 @var{regexp}. Otherwise it returns zero.
12856
12857 If the optional argument @var{number_of_frames} is provided,
12858 it is the number of frames up in the stack to look.
12859 The default is 1.
12860
12861 This function differs from @code{$_caller_matches} in that this function
12862 checks all stack frames from the immediate caller to the frame specified
12863 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12864 frame specified by @var{number_of_frames}.
12865
12866 @item $_as_string(@var{value})
12867 @findex $_as_string@r{, convenience function}
12868 Return the string representation of @var{value}.
12869
12870 This function is useful to obtain the textual label (enumerator) of an
12871 enumeration value. For example, assuming the variable @var{node} is of
12872 an enumerated type:
12873
12874 @smallexample
12875 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12876 Visiting node of type NODE_INTEGER
12877 @end smallexample
12878
12879 @item $_cimag(@var{value})
12880 @itemx $_creal(@var{value})
12881 @findex $_cimag@r{, convenience function}
12882 @findex $_creal@r{, convenience function}
12883 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12884 the complex number @var{value}.
12885
12886 The type of the imaginary or real part depends on the type of the
12887 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12888 will return an imaginary part of type @code{float}.
12889
12890 @end table
12891
12892 @value{GDBN} provides the ability to list and get help on
12893 convenience functions.
12894
12895 @table @code
12896 @item help function
12897 @kindex help function
12898 @cindex show all convenience functions
12899 Print a list of all convenience functions.
12900 @end table
12901
12902 @node Registers
12903 @section Registers
12904
12905 @cindex registers
12906 You can refer to machine register contents, in expressions, as variables
12907 with names starting with @samp{$}. The names of registers are different
12908 for each machine; use @code{info registers} to see the names used on
12909 your machine.
12910
12911 @table @code
12912 @kindex info registers
12913 @item info registers
12914 Print the names and values of all registers except floating-point
12915 and vector registers (in the selected stack frame).
12916
12917 @kindex info all-registers
12918 @cindex floating point registers
12919 @item info all-registers
12920 Print the names and values of all registers, including floating-point
12921 and vector registers (in the selected stack frame).
12922
12923 @anchor{info_registers_reggroup}
12924 @item info registers @var{reggroup} @dots{}
12925 Print the name and value of the registers in each of the specified
12926 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12927 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12928
12929 @item info registers @var{regname} @dots{}
12930 Print the @dfn{relativized} value of each specified register @var{regname}.
12931 As discussed in detail below, register values are normally relative to
12932 the selected stack frame. The @var{regname} may be any register name valid on
12933 the machine you are using, with or without the initial @samp{$}.
12934 @end table
12935
12936 @anchor{standard registers}
12937 @cindex stack pointer register
12938 @cindex program counter register
12939 @cindex process status register
12940 @cindex frame pointer register
12941 @cindex standard registers
12942 @value{GDBN} has four ``standard'' register names that are available (in
12943 expressions) on most machines---whenever they do not conflict with an
12944 architecture's canonical mnemonics for registers. The register names
12945 @code{$pc} and @code{$sp} are used for the program counter register and
12946 the stack pointer. @code{$fp} is used for a register that contains a
12947 pointer to the current stack frame, and @code{$ps} is used for a
12948 register that contains the processor status. For example,
12949 you could print the program counter in hex with
12950
12951 @smallexample
12952 p/x $pc
12953 @end smallexample
12954
12955 @noindent
12956 or print the instruction to be executed next with
12957
12958 @smallexample
12959 x/i $pc
12960 @end smallexample
12961
12962 @noindent
12963 or add four to the stack pointer@footnote{This is a way of removing
12964 one word from the stack, on machines where stacks grow downward in
12965 memory (most machines, nowadays). This assumes that the innermost
12966 stack frame is selected; setting @code{$sp} is not allowed when other
12967 stack frames are selected. To pop entire frames off the stack,
12968 regardless of machine architecture, use @code{return};
12969 see @ref{Returning, ,Returning from a Function}.} with
12970
12971 @smallexample
12972 set $sp += 4
12973 @end smallexample
12974
12975 Whenever possible, these four standard register names are available on
12976 your machine even though the machine has different canonical mnemonics,
12977 so long as there is no conflict. The @code{info registers} command
12978 shows the canonical names. For example, on the SPARC, @code{info
12979 registers} displays the processor status register as @code{$psr} but you
12980 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12981 is an alias for the @sc{eflags} register.
12982
12983 @value{GDBN} always considers the contents of an ordinary register as an
12984 integer when the register is examined in this way. Some machines have
12985 special registers which can hold nothing but floating point; these
12986 registers are considered to have floating point values. There is no way
12987 to refer to the contents of an ordinary register as floating point value
12988 (although you can @emph{print} it as a floating point value with
12989 @samp{print/f $@var{regname}}).
12990
12991 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12992 means that the data format in which the register contents are saved by
12993 the operating system is not the same one that your program normally
12994 sees. For example, the registers of the 68881 floating point
12995 coprocessor are always saved in ``extended'' (raw) format, but all C
12996 programs expect to work with ``double'' (virtual) format. In such
12997 cases, @value{GDBN} normally works with the virtual format only (the format
12998 that makes sense for your program), but the @code{info registers} command
12999 prints the data in both formats.
13000
13001 @cindex SSE registers (x86)
13002 @cindex MMX registers (x86)
13003 Some machines have special registers whose contents can be interpreted
13004 in several different ways. For example, modern x86-based machines
13005 have SSE and MMX registers that can hold several values packed
13006 together in several different formats. @value{GDBN} refers to such
13007 registers in @code{struct} notation:
13008
13009 @smallexample
13010 (@value{GDBP}) print $xmm1
13011 $1 = @{
13012 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
13013 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
13014 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
13015 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
13016 v4_int32 = @{0, 20657912, 11, 13@},
13017 v2_int64 = @{88725056443645952, 55834574859@},
13018 uint128 = 0x0000000d0000000b013b36f800000000
13019 @}
13020 @end smallexample
13021
13022 @noindent
13023 To set values of such registers, you need to tell @value{GDBN} which
13024 view of the register you wish to change, as if you were assigning
13025 value to a @code{struct} member:
13026
13027 @smallexample
13028 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
13029 @end smallexample
13030
13031 Normally, register values are relative to the selected stack frame
13032 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
13033 value that the register would contain if all stack frames farther in
13034 were exited and their saved registers restored. In order to see the
13035 true contents of hardware registers, you must select the innermost
13036 frame (with @samp{frame 0}).
13037
13038 @cindex caller-saved registers
13039 @cindex call-clobbered registers
13040 @cindex volatile registers
13041 @cindex <not saved> values
13042 Usually ABIs reserve some registers as not needed to be saved by the
13043 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
13044 registers). It may therefore not be possible for @value{GDBN} to know
13045 the value a register had before the call (in other words, in the outer
13046 frame), if the register value has since been changed by the callee.
13047 @value{GDBN} tries to deduce where the inner frame saved
13048 (``callee-saved'') registers, from the debug info, unwind info, or the
13049 machine code generated by your compiler. If some register is not
13050 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
13051 its own knowledge of the ABI, or because the debug/unwind info
13052 explicitly says the register's value is undefined), @value{GDBN}
13053 displays @w{@samp{<not saved>}} as the register's value. With targets
13054 that @value{GDBN} has no knowledge of the register saving convention,
13055 if a register was not saved by the callee, then its value and location
13056 in the outer frame are assumed to be the same of the inner frame.
13057 This is usually harmless, because if the register is call-clobbered,
13058 the caller either does not care what is in the register after the
13059 call, or has code to restore the value that it does care about. Note,
13060 however, that if you change such a register in the outer frame, you
13061 may also be affecting the inner frame. Also, the more ``outer'' the
13062 frame is you're looking at, the more likely a call-clobbered
13063 register's value is to be wrong, in the sense that it doesn't actually
13064 represent the value the register had just before the call.
13065
13066 @node Floating Point Hardware
13067 @section Floating Point Hardware
13068 @cindex floating point
13069
13070 Depending on the configuration, @value{GDBN} may be able to give
13071 you more information about the status of the floating point hardware.
13072
13073 @table @code
13074 @kindex info float
13075 @item info float
13076 Display hardware-dependent information about the floating
13077 point unit. The exact contents and layout vary depending on the
13078 floating point chip. Currently, @samp{info float} is supported on
13079 the ARM and x86 machines.
13080 @end table
13081
13082 @node Vector Unit
13083 @section Vector Unit
13084 @cindex vector unit
13085
13086 Depending on the configuration, @value{GDBN} may be able to give you
13087 more information about the status of the vector unit.
13088
13089 @table @code
13090 @kindex info vector
13091 @item info vector
13092 Display information about the vector unit. The exact contents and
13093 layout vary depending on the hardware.
13094 @end table
13095
13096 @node OS Information
13097 @section Operating System Auxiliary Information
13098 @cindex OS information
13099
13100 @value{GDBN} provides interfaces to useful OS facilities that can help
13101 you debug your program.
13102
13103 @cindex auxiliary vector
13104 @cindex vector, auxiliary
13105 Some operating systems supply an @dfn{auxiliary vector} to programs at
13106 startup. This is akin to the arguments and environment that you
13107 specify for a program, but contains a system-dependent variety of
13108 binary values that tell system libraries important details about the
13109 hardware, operating system, and process. Each value's purpose is
13110 identified by an integer tag; the meanings are well-known but system-specific.
13111 Depending on the configuration and operating system facilities,
13112 @value{GDBN} may be able to show you this information. For remote
13113 targets, this functionality may further depend on the remote stub's
13114 support of the @samp{qXfer:auxv:read} packet, see
13115 @ref{qXfer auxiliary vector read}.
13116
13117 @table @code
13118 @kindex info auxv
13119 @item info auxv
13120 Display the auxiliary vector of the inferior, which can be either a
13121 live process or a core dump file. @value{GDBN} prints each tag value
13122 numerically, and also shows names and text descriptions for recognized
13123 tags. Some values in the vector are numbers, some bit masks, and some
13124 pointers to strings or other data. @value{GDBN} displays each value in the
13125 most appropriate form for a recognized tag, and in hexadecimal for
13126 an unrecognized tag.
13127 @end table
13128
13129 On some targets, @value{GDBN} can access operating system-specific
13130 information and show it to you. The types of information available
13131 will differ depending on the type of operating system running on the
13132 target. The mechanism used to fetch the data is described in
13133 @ref{Operating System Information}. For remote targets, this
13134 functionality depends on the remote stub's support of the
13135 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
13136
13137 @table @code
13138 @kindex info os
13139 @item info os @var{infotype}
13140
13141 Display OS information of the requested type.
13142
13143 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
13144
13145 @anchor{linux info os infotypes}
13146 @table @code
13147 @kindex info os cpus
13148 @item cpus
13149 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
13150 the available fields from /proc/cpuinfo. For each supported architecture
13151 different fields are available. Two common entries are processor which gives
13152 CPU number and bogomips; a system constant that is calculated during
13153 kernel initialization.
13154
13155 @kindex info os files
13156 @item files
13157 Display the list of open file descriptors on the target. For each
13158 file descriptor, @value{GDBN} prints the identifier of the process
13159 owning the descriptor, the command of the owning process, the value
13160 of the descriptor, and the target of the descriptor.
13161
13162 @kindex info os modules
13163 @item modules
13164 Display the list of all loaded kernel modules on the target. For each
13165 module, @value{GDBN} prints the module name, the size of the module in
13166 bytes, the number of times the module is used, the dependencies of the
13167 module, the status of the module, and the address of the loaded module
13168 in memory.
13169
13170 @kindex info os msg
13171 @item msg
13172 Display the list of all System V message queues on the target. For each
13173 message queue, @value{GDBN} prints the message queue key, the message
13174 queue identifier, the access permissions, the current number of bytes
13175 on the queue, the current number of messages on the queue, the processes
13176 that last sent and received a message on the queue, the user and group
13177 of the owner and creator of the message queue, the times at which a
13178 message was last sent and received on the queue, and the time at which
13179 the message queue was last changed.
13180
13181 @kindex info os processes
13182 @item processes
13183 Display the list of processes on the target. For each process,
13184 @value{GDBN} prints the process identifier, the name of the user, the
13185 command corresponding to the process, and the list of processor cores
13186 that the process is currently running on. (To understand what these
13187 properties mean, for this and the following info types, please consult
13188 the general @sc{gnu}/Linux documentation.)
13189
13190 @kindex info os procgroups
13191 @item procgroups
13192 Display the list of process groups on the target. For each process,
13193 @value{GDBN} prints the identifier of the process group that it belongs
13194 to, the command corresponding to the process group leader, the process
13195 identifier, and the command line of the process. The list is sorted
13196 first by the process group identifier, then by the process identifier,
13197 so that processes belonging to the same process group are grouped together
13198 and the process group leader is listed first.
13199
13200 @kindex info os semaphores
13201 @item semaphores
13202 Display the list of all System V semaphore sets on the target. For each
13203 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
13204 set identifier, the access permissions, the number of semaphores in the
13205 set, the user and group of the owner and creator of the semaphore set,
13206 and the times at which the semaphore set was operated upon and changed.
13207
13208 @kindex info os shm
13209 @item shm
13210 Display the list of all System V shared-memory regions on the target.
13211 For each shared-memory region, @value{GDBN} prints the region key,
13212 the shared-memory identifier, the access permissions, the size of the
13213 region, the process that created the region, the process that last
13214 attached to or detached from the region, the current number of live
13215 attaches to the region, and the times at which the region was last
13216 attached to, detach from, and changed.
13217
13218 @kindex info os sockets
13219 @item sockets
13220 Display the list of Internet-domain sockets on the target. For each
13221 socket, @value{GDBN} prints the address and port of the local and
13222 remote endpoints, the current state of the connection, the creator of
13223 the socket, the IP address family of the socket, and the type of the
13224 connection.
13225
13226 @kindex info os threads
13227 @item threads
13228 Display the list of threads running on the target. For each thread,
13229 @value{GDBN} prints the identifier of the process that the thread
13230 belongs to, the command of the process, the thread identifier, and the
13231 processor core that it is currently running on. The main thread of a
13232 process is not listed.
13233 @end table
13234
13235 @item info os
13236 If @var{infotype} is omitted, then list the possible values for
13237 @var{infotype} and the kind of OS information available for each
13238 @var{infotype}. If the target does not return a list of possible
13239 types, this command will report an error.
13240 @end table
13241
13242 @node Memory Region Attributes
13243 @section Memory Region Attributes
13244 @cindex memory region attributes
13245
13246 @dfn{Memory region attributes} allow you to describe special handling
13247 required by regions of your target's memory. @value{GDBN} uses
13248 attributes to determine whether to allow certain types of memory
13249 accesses; whether to use specific width accesses; and whether to cache
13250 target memory. By default the description of memory regions is
13251 fetched from the target (if the current target supports this), but the
13252 user can override the fetched regions.
13253
13254 Defined memory regions can be individually enabled and disabled. When a
13255 memory region is disabled, @value{GDBN} uses the default attributes when
13256 accessing memory in that region. Similarly, if no memory regions have
13257 been defined, @value{GDBN} uses the default attributes when accessing
13258 all memory.
13259
13260 When a memory region is defined, it is given a number to identify it;
13261 to enable, disable, or remove a memory region, you specify that number.
13262
13263 @table @code
13264 @kindex mem
13265 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
13266 Define a memory region bounded by @var{lower} and @var{upper} with
13267 attributes @var{attributes}@dots{}, and add it to the list of regions
13268 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
13269 case: it is treated as the target's maximum memory address.
13270 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
13271
13272 @item mem auto
13273 Discard any user changes to the memory regions and use target-supplied
13274 regions, if available, or no regions if the target does not support.
13275
13276 @kindex delete mem
13277 @item delete mem @var{nums}@dots{}
13278 Remove memory regions @var{nums}@dots{} from the list of regions
13279 monitored by @value{GDBN}.
13280
13281 @kindex disable mem
13282 @item disable mem @var{nums}@dots{}
13283 Disable monitoring of memory regions @var{nums}@dots{}.
13284 A disabled memory region is not forgotten.
13285 It may be enabled again later.
13286
13287 @kindex enable mem
13288 @item enable mem @var{nums}@dots{}
13289 Enable monitoring of memory regions @var{nums}@dots{}.
13290
13291 @kindex info mem
13292 @item info mem
13293 Print a table of all defined memory regions, with the following columns
13294 for each region:
13295
13296 @table @emph
13297 @item Memory Region Number
13298 @item Enabled or Disabled.
13299 Enabled memory regions are marked with @samp{y}.
13300 Disabled memory regions are marked with @samp{n}.
13301
13302 @item Lo Address
13303 The address defining the inclusive lower bound of the memory region.
13304
13305 @item Hi Address
13306 The address defining the exclusive upper bound of the memory region.
13307
13308 @item Attributes
13309 The list of attributes set for this memory region.
13310 @end table
13311 @end table
13312
13313
13314 @subsection Attributes
13315
13316 @subsubsection Memory Access Mode
13317 The access mode attributes set whether @value{GDBN} may make read or
13318 write accesses to a memory region.
13319
13320 While these attributes prevent @value{GDBN} from performing invalid
13321 memory accesses, they do nothing to prevent the target system, I/O DMA,
13322 etc.@: from accessing memory.
13323
13324 @table @code
13325 @item ro
13326 Memory is read only.
13327 @item wo
13328 Memory is write only.
13329 @item rw
13330 Memory is read/write. This is the default.
13331 @end table
13332
13333 @subsubsection Memory Access Size
13334 The access size attribute tells @value{GDBN} to use specific sized
13335 accesses in the memory region. Often memory mapped device registers
13336 require specific sized accesses. If no access size attribute is
13337 specified, @value{GDBN} may use accesses of any size.
13338
13339 @table @code
13340 @item 8
13341 Use 8 bit memory accesses.
13342 @item 16
13343 Use 16 bit memory accesses.
13344 @item 32
13345 Use 32 bit memory accesses.
13346 @item 64
13347 Use 64 bit memory accesses.
13348 @end table
13349
13350 @c @subsubsection Hardware/Software Breakpoints
13351 @c The hardware/software breakpoint attributes set whether @value{GDBN}
13352 @c will use hardware or software breakpoints for the internal breakpoints
13353 @c used by the step, next, finish, until, etc. commands.
13354 @c
13355 @c @table @code
13356 @c @item hwbreak
13357 @c Always use hardware breakpoints
13358 @c @item swbreak (default)
13359 @c @end table
13360
13361 @subsubsection Data Cache
13362 The data cache attributes set whether @value{GDBN} will cache target
13363 memory. While this generally improves performance by reducing debug
13364 protocol overhead, it can lead to incorrect results because @value{GDBN}
13365 does not know about volatile variables or memory mapped device
13366 registers.
13367
13368 @table @code
13369 @item cache
13370 Enable @value{GDBN} to cache target memory.
13371 @item nocache
13372 Disable @value{GDBN} from caching target memory. This is the default.
13373 @end table
13374
13375 @subsection Memory Access Checking
13376 @value{GDBN} can be instructed to refuse accesses to memory that is
13377 not explicitly described. This can be useful if accessing such
13378 regions has undesired effects for a specific target, or to provide
13379 better error checking. The following commands control this behaviour.
13380
13381 @table @code
13382 @kindex set mem inaccessible-by-default
13383 @item set mem inaccessible-by-default [on|off]
13384 If @code{on} is specified, make @value{GDBN} treat memory not
13385 explicitly described by the memory ranges as non-existent and refuse accesses
13386 to such memory. The checks are only performed if there's at least one
13387 memory range defined. If @code{off} is specified, make @value{GDBN}
13388 treat the memory not explicitly described by the memory ranges as RAM.
13389 The default value is @code{on}.
13390 @kindex show mem inaccessible-by-default
13391 @item show mem inaccessible-by-default
13392 Show the current handling of accesses to unknown memory.
13393 @end table
13394
13395
13396 @c @subsubsection Memory Write Verification
13397 @c The memory write verification attributes set whether @value{GDBN}
13398 @c will re-reads data after each write to verify the write was successful.
13399 @c
13400 @c @table @code
13401 @c @item verify
13402 @c @item noverify (default)
13403 @c @end table
13404
13405 @node Dump/Restore Files
13406 @section Copy Between Memory and a File
13407 @cindex dump/restore files
13408 @cindex append data to a file
13409 @cindex dump data to a file
13410 @cindex restore data from a file
13411
13412 You can use the commands @code{dump}, @code{append}, and
13413 @code{restore} to copy data between target memory and a file. The
13414 @code{dump} and @code{append} commands write data to a file, and the
13415 @code{restore} command reads data from a file back into the inferior's
13416 memory. Files may be in binary, Motorola S-record, Intel hex,
13417 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13418 append to binary files, and cannot read from Verilog Hex files.
13419
13420 @table @code
13421
13422 @kindex dump
13423 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13424 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13425 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13426 or the value of @var{expr}, to @var{filename} in the given format.
13427
13428 The @var{format} parameter may be any one of:
13429 @table @code
13430 @item binary
13431 Raw binary form.
13432 @item ihex
13433 Intel hex format.
13434 @item srec
13435 Motorola S-record format.
13436 @item tekhex
13437 Tektronix Hex format.
13438 @item verilog
13439 Verilog Hex format.
13440 @end table
13441
13442 @value{GDBN} uses the same definitions of these formats as the
13443 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13444 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13445 form.
13446
13447 @kindex append
13448 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13449 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13450 Append the contents of memory from @var{start_addr} to @var{end_addr},
13451 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13452 (@value{GDBN} can only append data to files in raw binary form.)
13453
13454 @kindex restore
13455 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13456 Restore the contents of file @var{filename} into memory. The
13457 @code{restore} command can automatically recognize any known @sc{bfd}
13458 file format, except for raw binary. To restore a raw binary file you
13459 must specify the optional keyword @code{binary} after the filename.
13460
13461 If @var{bias} is non-zero, its value will be added to the addresses
13462 contained in the file. Binary files always start at address zero, so
13463 they will be restored at address @var{bias}. Other bfd files have
13464 a built-in location; they will be restored at offset @var{bias}
13465 from that location.
13466
13467 If @var{start} and/or @var{end} are non-zero, then only data between
13468 file offset @var{start} and file offset @var{end} will be restored.
13469 These offsets are relative to the addresses in the file, before
13470 the @var{bias} argument is applied.
13471
13472 @end table
13473
13474 @node Core File Generation
13475 @section How to Produce a Core File from Your Program
13476 @cindex dump core from inferior
13477
13478 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13479 image of a running process and its process status (register values
13480 etc.). Its primary use is post-mortem debugging of a program that
13481 crashed while it ran outside a debugger. A program that crashes
13482 automatically produces a core file, unless this feature is disabled by
13483 the user. @xref{Files}, for information on invoking @value{GDBN} in
13484 the post-mortem debugging mode.
13485
13486 Occasionally, you may wish to produce a core file of the program you
13487 are debugging in order to preserve a snapshot of its state.
13488 @value{GDBN} has a special command for that.
13489
13490 @table @code
13491 @kindex gcore
13492 @kindex generate-core-file
13493 @item generate-core-file [@var{file}]
13494 @itemx gcore [@var{file}]
13495 Produce a core dump of the inferior process. The optional argument
13496 @var{file} specifies the file name where to put the core dump. If not
13497 specified, the file name defaults to @file{core.@var{pid}}, where
13498 @var{pid} is the inferior process ID.
13499
13500 Note that this command is implemented only for some systems (as of
13501 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13502
13503 On @sc{gnu}/Linux, this command can take into account the value of the
13504 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13505 dump (@pxref{set use-coredump-filter}), and by default honors the
13506 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13507 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13508
13509 @kindex set use-coredump-filter
13510 @anchor{set use-coredump-filter}
13511 @item set use-coredump-filter on
13512 @itemx set use-coredump-filter off
13513 Enable or disable the use of the file
13514 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13515 files. This file is used by the Linux kernel to decide what types of
13516 memory mappings will be dumped or ignored when generating a core dump
13517 file. @var{pid} is the process ID of a currently running process.
13518
13519 To make use of this feature, you have to write in the
13520 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13521 which is a bit mask representing the memory mapping types. If a bit
13522 is set in the bit mask, then the memory mappings of the corresponding
13523 types will be dumped; otherwise, they will be ignored. This
13524 configuration is inherited by child processes. For more information
13525 about the bits that can be set in the
13526 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13527 manpage of @code{core(5)}.
13528
13529 By default, this option is @code{on}. If this option is turned
13530 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13531 and instead uses the same default value as the Linux kernel in order
13532 to decide which pages will be dumped in the core dump file. This
13533 value is currently @code{0x33}, which means that bits @code{0}
13534 (anonymous private mappings), @code{1} (anonymous shared mappings),
13535 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13536 This will cause these memory mappings to be dumped automatically.
13537
13538 @kindex set dump-excluded-mappings
13539 @anchor{set dump-excluded-mappings}
13540 @item set dump-excluded-mappings on
13541 @itemx set dump-excluded-mappings off
13542 If @code{on} is specified, @value{GDBN} will dump memory mappings
13543 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13544 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13545
13546 The default value is @code{off}.
13547 @end table
13548
13549 @node Character Sets
13550 @section Character Sets
13551 @cindex character sets
13552 @cindex charset
13553 @cindex translating between character sets
13554 @cindex host character set
13555 @cindex target character set
13556
13557 If the program you are debugging uses a different character set to
13558 represent characters and strings than the one @value{GDBN} uses itself,
13559 @value{GDBN} can automatically translate between the character sets for
13560 you. The character set @value{GDBN} uses we call the @dfn{host
13561 character set}; the one the inferior program uses we call the
13562 @dfn{target character set}.
13563
13564 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13565 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13566 remote protocol (@pxref{Remote Debugging}) to debug a program
13567 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13568 then the host character set is Latin-1, and the target character set is
13569 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13570 target-charset EBCDIC-US}, then @value{GDBN} translates between
13571 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13572 character and string literals in expressions.
13573
13574 @value{GDBN} has no way to automatically recognize which character set
13575 the inferior program uses; you must tell it, using the @code{set
13576 target-charset} command, described below.
13577
13578 Here are the commands for controlling @value{GDBN}'s character set
13579 support:
13580
13581 @table @code
13582 @item set target-charset @var{charset}
13583 @kindex set target-charset
13584 Set the current target character set to @var{charset}. To display the
13585 list of supported target character sets, type
13586 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13587
13588 @item set host-charset @var{charset}
13589 @kindex set host-charset
13590 Set the current host character set to @var{charset}.
13591
13592 By default, @value{GDBN} uses a host character set appropriate to the
13593 system it is running on; you can override that default using the
13594 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13595 automatically determine the appropriate host character set. In this
13596 case, @value{GDBN} uses @samp{UTF-8}.
13597
13598 @value{GDBN} can only use certain character sets as its host character
13599 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13600 @value{GDBN} will list the host character sets it supports.
13601
13602 @item set charset @var{charset}
13603 @kindex set charset
13604 Set the current host and target character sets to @var{charset}. As
13605 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13606 @value{GDBN} will list the names of the character sets that can be used
13607 for both host and target.
13608
13609 @item show charset
13610 @kindex show charset
13611 Show the names of the current host and target character sets.
13612
13613 @item show host-charset
13614 @kindex show host-charset
13615 Show the name of the current host character set.
13616
13617 @item show target-charset
13618 @kindex show target-charset
13619 Show the name of the current target character set.
13620
13621 @item set target-wide-charset @var{charset}
13622 @kindex set target-wide-charset
13623 Set the current target's wide character set to @var{charset}. This is
13624 the character set used by the target's @code{wchar_t} type. To
13625 display the list of supported wide character sets, type
13626 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13627
13628 @item show target-wide-charset
13629 @kindex show target-wide-charset
13630 Show the name of the current target's wide character set.
13631 @end table
13632
13633 Here is an example of @value{GDBN}'s character set support in action.
13634 Assume that the following source code has been placed in the file
13635 @file{charset-test.c}:
13636
13637 @smallexample
13638 #include <stdio.h>
13639
13640 char ascii_hello[]
13641 = @{72, 101, 108, 108, 111, 44, 32, 119,
13642 111, 114, 108, 100, 33, 10, 0@};
13643 char ibm1047_hello[]
13644 = @{200, 133, 147, 147, 150, 107, 64, 166,
13645 150, 153, 147, 132, 90, 37, 0@};
13646
13647 main ()
13648 @{
13649 printf ("Hello, world!\n");
13650 @}
13651 @end smallexample
13652
13653 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13654 containing the string @samp{Hello, world!} followed by a newline,
13655 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13656
13657 We compile the program, and invoke the debugger on it:
13658
13659 @smallexample
13660 $ gcc -g charset-test.c -o charset-test
13661 $ gdb -nw charset-test
13662 GNU gdb 2001-12-19-cvs
13663 Copyright 2001 Free Software Foundation, Inc.
13664 @dots{}
13665 (@value{GDBP})
13666 @end smallexample
13667
13668 We can use the @code{show charset} command to see what character sets
13669 @value{GDBN} is currently using to interpret and display characters and
13670 strings:
13671
13672 @smallexample
13673 (@value{GDBP}) show charset
13674 The current host and target character set is `ISO-8859-1'.
13675 (@value{GDBP})
13676 @end smallexample
13677
13678 For the sake of printing this manual, let's use @sc{ascii} as our
13679 initial character set:
13680 @smallexample
13681 (@value{GDBP}) set charset ASCII
13682 (@value{GDBP}) show charset
13683 The current host and target character set is `ASCII'.
13684 (@value{GDBP})
13685 @end smallexample
13686
13687 Let's assume that @sc{ascii} is indeed the correct character set for our
13688 host system --- in other words, let's assume that if @value{GDBN} prints
13689 characters using the @sc{ascii} character set, our terminal will display
13690 them properly. Since our current target character set is also
13691 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13692
13693 @smallexample
13694 (@value{GDBP}) print ascii_hello
13695 $1 = 0x401698 "Hello, world!\n"
13696 (@value{GDBP}) print ascii_hello[0]
13697 $2 = 72 'H'
13698 (@value{GDBP})
13699 @end smallexample
13700
13701 @value{GDBN} uses the target character set for character and string
13702 literals you use in expressions:
13703
13704 @smallexample
13705 (@value{GDBP}) print '+'
13706 $3 = 43 '+'
13707 (@value{GDBP})
13708 @end smallexample
13709
13710 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13711 character.
13712
13713 @value{GDBN} relies on the user to tell it which character set the
13714 target program uses. If we print @code{ibm1047_hello} while our target
13715 character set is still @sc{ascii}, we get jibberish:
13716
13717 @smallexample
13718 (@value{GDBP}) print ibm1047_hello
13719 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13720 (@value{GDBP}) print ibm1047_hello[0]
13721 $5 = 200 '\310'
13722 (@value{GDBP})
13723 @end smallexample
13724
13725 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13726 @value{GDBN} tells us the character sets it supports:
13727
13728 @smallexample
13729 (@value{GDBP}) set target-charset
13730 ASCII EBCDIC-US IBM1047 ISO-8859-1
13731 (@value{GDBP}) set target-charset
13732 @end smallexample
13733
13734 We can select @sc{ibm1047} as our target character set, and examine the
13735 program's strings again. Now the @sc{ascii} string is wrong, but
13736 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13737 target character set, @sc{ibm1047}, to the host character set,
13738 @sc{ascii}, and they display correctly:
13739
13740 @smallexample
13741 (@value{GDBP}) set target-charset IBM1047
13742 (@value{GDBP}) show charset
13743 The current host character set is `ASCII'.
13744 The current target character set is `IBM1047'.
13745 (@value{GDBP}) print ascii_hello
13746 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13747 (@value{GDBP}) print ascii_hello[0]
13748 $7 = 72 '\110'
13749 (@value{GDBP}) print ibm1047_hello
13750 $8 = 0x4016a8 "Hello, world!\n"
13751 (@value{GDBP}) print ibm1047_hello[0]
13752 $9 = 200 'H'
13753 (@value{GDBP})
13754 @end smallexample
13755
13756 As above, @value{GDBN} uses the target character set for character and
13757 string literals you use in expressions:
13758
13759 @smallexample
13760 (@value{GDBP}) print '+'
13761 $10 = 78 '+'
13762 (@value{GDBP})
13763 @end smallexample
13764
13765 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13766 character.
13767
13768 @node Caching Target Data
13769 @section Caching Data of Targets
13770 @cindex caching data of targets
13771
13772 @value{GDBN} caches data exchanged between the debugger and a target.
13773 Each cache is associated with the address space of the inferior.
13774 @xref{Inferiors Connections and Programs}, about inferior and address space.
13775 Such caching generally improves performance in remote debugging
13776 (@pxref{Remote Debugging}), because it reduces the overhead of the
13777 remote protocol by bundling memory reads and writes into large chunks.
13778 Unfortunately, simply caching everything would lead to incorrect results,
13779 since @value{GDBN} does not necessarily know anything about volatile
13780 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13781 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13782 is executing.
13783 Therefore, by default, @value{GDBN} only caches data
13784 known to be on the stack@footnote{In non-stop mode, it is moderately
13785 rare for a running thread to modify the stack of a stopped thread
13786 in a way that would interfere with a backtrace, and caching of
13787 stack reads provides a significant speed up of remote backtraces.} or
13788 in the code segment.
13789 Other regions of memory can be explicitly marked as
13790 cacheable; @pxref{Memory Region Attributes}.
13791
13792 @table @code
13793 @kindex set remotecache
13794 @item set remotecache on
13795 @itemx set remotecache off
13796 This option no longer does anything; it exists for compatibility
13797 with old scripts.
13798
13799 @kindex show remotecache
13800 @item show remotecache
13801 Show the current state of the obsolete remotecache flag.
13802
13803 @kindex set stack-cache
13804 @item set stack-cache on
13805 @itemx set stack-cache off
13806 Enable or disable caching of stack accesses. When @code{on}, use
13807 caching. By default, this option is @code{on}.
13808
13809 @kindex show stack-cache
13810 @item show stack-cache
13811 Show the current state of data caching for memory accesses.
13812
13813 @kindex set code-cache
13814 @item set code-cache on
13815 @itemx set code-cache off
13816 Enable or disable caching of code segment accesses. When @code{on},
13817 use caching. By default, this option is @code{on}. This improves
13818 performance of disassembly in remote debugging.
13819
13820 @kindex show code-cache
13821 @item show code-cache
13822 Show the current state of target memory cache for code segment
13823 accesses.
13824
13825 @kindex info dcache
13826 @item info dcache @r{[}line@r{]}
13827 Print the information about the performance of data cache of the
13828 current inferior's address space. The information displayed
13829 includes the dcache width and depth, and for each cache line, its
13830 number, address, and how many times it was referenced. This
13831 command is useful for debugging the data cache operation.
13832
13833 If a line number is specified, the contents of that line will be
13834 printed in hex.
13835
13836 @item set dcache size @var{size}
13837 @cindex dcache size
13838 @kindex set dcache size
13839 Set maximum number of entries in dcache (dcache depth above).
13840
13841 @item set dcache line-size @var{line-size}
13842 @cindex dcache line-size
13843 @kindex set dcache line-size
13844 Set number of bytes each dcache entry caches (dcache width above).
13845 Must be a power of 2.
13846
13847 @item show dcache size
13848 @kindex show dcache size
13849 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13850
13851 @item show dcache line-size
13852 @kindex show dcache line-size
13853 Show default size of dcache lines.
13854
13855 @item maint flush dcache
13856 @cindex dcache, flushing
13857 @kindex maint flush dcache
13858 Flush the contents (if any) of the dcache. This maintainer command is
13859 useful when debugging the dcache implementation.
13860
13861 @end table
13862
13863 @node Searching Memory
13864 @section Search Memory
13865 @cindex searching memory
13866
13867 Memory can be searched for a particular sequence of bytes with the
13868 @code{find} command.
13869
13870 @table @code
13871 @kindex find
13872 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13873 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13874 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13875 etc. The search begins at address @var{start_addr} and continues for either
13876 @var{len} bytes or through to @var{end_addr} inclusive.
13877 @end table
13878
13879 @var{s} and @var{n} are optional parameters.
13880 They may be specified in either order, apart or together.
13881
13882 @table @r
13883 @item @var{s}, search query size
13884 The size of each search query value.
13885
13886 @table @code
13887 @item b
13888 bytes
13889 @item h
13890 halfwords (two bytes)
13891 @item w
13892 words (four bytes)
13893 @item g
13894 giant words (eight bytes)
13895 @end table
13896
13897 All values are interpreted in the current language.
13898 This means, for example, that if the current source language is C/C@t{++}
13899 then searching for the string ``hello'' includes the trailing '\0'.
13900 The null terminator can be removed from searching by using casts,
13901 e.g.: @samp{@{char[5]@}"hello"}.
13902
13903 If the value size is not specified, it is taken from the
13904 value's type in the current language.
13905 This is useful when one wants to specify the search
13906 pattern as a mixture of types.
13907 Note that this means, for example, that in the case of C-like languages
13908 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13909 which is typically four bytes.
13910
13911 @item @var{n}, maximum number of finds
13912 The maximum number of matches to print. The default is to print all finds.
13913 @end table
13914
13915 You can use strings as search values. Quote them with double-quotes
13916 (@code{"}).
13917 The string value is copied into the search pattern byte by byte,
13918 regardless of the endianness of the target and the size specification.
13919
13920 The address of each match found is printed as well as a count of the
13921 number of matches found.
13922
13923 The address of the last value found is stored in convenience variable
13924 @samp{$_}.
13925 A count of the number of matches is stored in @samp{$numfound}.
13926
13927 For example, if stopped at the @code{printf} in this function:
13928
13929 @smallexample
13930 void
13931 hello ()
13932 @{
13933 static char hello[] = "hello-hello";
13934 static struct @{ char c; short s; int i; @}
13935 __attribute__ ((packed)) mixed
13936 = @{ 'c', 0x1234, 0x87654321 @};
13937 printf ("%s\n", hello);
13938 @}
13939 @end smallexample
13940
13941 @noindent
13942 you get during debugging:
13943
13944 @smallexample
13945 (gdb) find &hello[0], +sizeof(hello), "hello"
13946 0x804956d <hello.1620+6>
13947 1 pattern found
13948 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13949 0x8049567 <hello.1620>
13950 0x804956d <hello.1620+6>
13951 2 patterns found.
13952 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13953 0x8049567 <hello.1620>
13954 0x804956d <hello.1620+6>
13955 2 patterns found.
13956 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13957 0x8049567 <hello.1620>
13958 1 pattern found
13959 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13960 0x8049560 <mixed.1625>
13961 1 pattern found
13962 (gdb) print $numfound
13963 $1 = 1
13964 (gdb) print $_
13965 $2 = (void *) 0x8049560
13966 @end smallexample
13967
13968 @node Value Sizes
13969 @section Value Sizes
13970
13971 Whenever @value{GDBN} prints a value memory will be allocated within
13972 @value{GDBN} to hold the contents of the value. It is possible in
13973 some languages with dynamic typing systems, that an invalid program
13974 may indicate a value that is incorrectly large, this in turn may cause
13975 @value{GDBN} to try and allocate an overly large amount of memory.
13976
13977 @table @code
13978 @kindex set max-value-size
13979 @item set max-value-size @var{bytes}
13980 @itemx set max-value-size unlimited
13981 Set the maximum size of memory that @value{GDBN} will allocate for the
13982 contents of a value to @var{bytes}, trying to display a value that
13983 requires more memory than that will result in an error.
13984
13985 Setting this variable does not effect values that have already been
13986 allocated within @value{GDBN}, only future allocations.
13987
13988 There's a minimum size that @code{max-value-size} can be set to in
13989 order that @value{GDBN} can still operate correctly, this minimum is
13990 currently 16 bytes.
13991
13992 The limit applies to the results of some subexpressions as well as to
13993 complete expressions. For example, an expression denoting a simple
13994 integer component, such as @code{x.y.z}, may fail if the size of
13995 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13996 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13997 @var{A} is an array variable with non-constant size, will generally
13998 succeed regardless of the bounds on @var{A}, as long as the component
13999 size is less than @var{bytes}.
14000
14001 The default value of @code{max-value-size} is currently 64k.
14002
14003 @kindex show max-value-size
14004 @item show max-value-size
14005 Show the maximum size of memory, in bytes, that @value{GDBN} will
14006 allocate for the contents of a value.
14007 @end table
14008
14009 @node Optimized Code
14010 @chapter Debugging Optimized Code
14011 @cindex optimized code, debugging
14012 @cindex debugging optimized code
14013
14014 Almost all compilers support optimization. With optimization
14015 disabled, the compiler generates assembly code that corresponds
14016 directly to your source code, in a simplistic way. As the compiler
14017 applies more powerful optimizations, the generated assembly code
14018 diverges from your original source code. With help from debugging
14019 information generated by the compiler, @value{GDBN} can map from
14020 the running program back to constructs from your original source.
14021
14022 @value{GDBN} is more accurate with optimization disabled. If you
14023 can recompile without optimization, it is easier to follow the
14024 progress of your program during debugging. But, there are many cases
14025 where you may need to debug an optimized version.
14026
14027 When you debug a program compiled with @samp{-g -O}, remember that the
14028 optimizer has rearranged your code; the debugger shows you what is
14029 really there. Do not be too surprised when the execution path does not
14030 exactly match your source file! An extreme example: if you define a
14031 variable, but never use it, @value{GDBN} never sees that
14032 variable---because the compiler optimizes it out of existence.
14033
14034 Some things do not work as well with @samp{-g -O} as with just
14035 @samp{-g}, particularly on machines with instruction scheduling. If in
14036 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
14037 please report it to us as a bug (including a test case!).
14038 @xref{Variables}, for more information about debugging optimized code.
14039
14040 @menu
14041 * Inline Functions:: How @value{GDBN} presents inlining
14042 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
14043 @end menu
14044
14045 @node Inline Functions
14046 @section Inline Functions
14047 @cindex inline functions, debugging
14048
14049 @dfn{Inlining} is an optimization that inserts a copy of the function
14050 body directly at each call site, instead of jumping to a shared
14051 routine. @value{GDBN} displays inlined functions just like
14052 non-inlined functions. They appear in backtraces. You can view their
14053 arguments and local variables, step into them with @code{step}, skip
14054 them with @code{next}, and escape from them with @code{finish}.
14055 You can check whether a function was inlined by using the
14056 @code{info frame} command.
14057
14058 For @value{GDBN} to support inlined functions, the compiler must
14059 record information about inlining in the debug information ---
14060 @value{NGCC} using the @sc{dwarf 2} format does this, and several
14061 other compilers do also. @value{GDBN} only supports inlined functions
14062 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
14063 do not emit two required attributes (@samp{DW_AT_call_file} and
14064 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
14065 function calls with earlier versions of @value{NGCC}. It instead
14066 displays the arguments and local variables of inlined functions as
14067 local variables in the caller.
14068
14069 The body of an inlined function is directly included at its call site;
14070 unlike a non-inlined function, there are no instructions devoted to
14071 the call. @value{GDBN} still pretends that the call site and the
14072 start of the inlined function are different instructions. Stepping to
14073 the call site shows the call site, and then stepping again shows
14074 the first line of the inlined function, even though no additional
14075 instructions are executed.
14076
14077 This makes source-level debugging much clearer; you can see both the
14078 context of the call and then the effect of the call. Only stepping by
14079 a single instruction using @code{stepi} or @code{nexti} does not do
14080 this; single instruction steps always show the inlined body.
14081
14082 There are some ways that @value{GDBN} does not pretend that inlined
14083 function calls are the same as normal calls:
14084
14085 @itemize @bullet
14086 @item
14087 Setting breakpoints at the call site of an inlined function may not
14088 work, because the call site does not contain any code. @value{GDBN}
14089 may incorrectly move the breakpoint to the next line of the enclosing
14090 function, after the call. This limitation will be removed in a future
14091 version of @value{GDBN}; until then, set a breakpoint on an earlier line
14092 or inside the inlined function instead.
14093
14094 @item
14095 @value{GDBN} cannot locate the return value of inlined calls after
14096 using the @code{finish} command. This is a limitation of compiler-generated
14097 debugging information; after @code{finish}, you can step to the next line
14098 and print a variable where your program stored the return value.
14099
14100 @end itemize
14101
14102 @node Tail Call Frames
14103 @section Tail Call Frames
14104 @cindex tail call frames, debugging
14105
14106 Function @code{B} can call function @code{C} in its very last statement. In
14107 unoptimized compilation the call of @code{C} is immediately followed by return
14108 instruction at the end of @code{B} code. Optimizing compiler may replace the
14109 call and return in function @code{B} into one jump to function @code{C}
14110 instead. Such use of a jump instruction is called @dfn{tail call}.
14111
14112 During execution of function @code{C}, there will be no indication in the
14113 function call stack frames that it was tail-called from @code{B}. If function
14114 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
14115 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
14116 some cases @value{GDBN} can determine that @code{C} was tail-called from
14117 @code{B}, and it will then create fictitious call frame for that, with the
14118 return address set up as if @code{B} called @code{C} normally.
14119
14120 This functionality is currently supported only by DWARF 2 debugging format and
14121 the compiler has to produce @samp{DW_TAG_call_site} tags. With
14122 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
14123 this information.
14124
14125 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
14126 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
14127
14128 @smallexample
14129 (gdb) x/i $pc - 2
14130 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
14131 (gdb) info frame
14132 Stack level 1, frame at 0x7fffffffda30:
14133 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
14134 tail call frame, caller of frame at 0x7fffffffda30
14135 source language c++.
14136 Arglist at unknown address.
14137 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
14138 @end smallexample
14139
14140 The detection of all the possible code path executions can find them ambiguous.
14141 There is no execution history stored (possible @ref{Reverse Execution} is never
14142 used for this purpose) and the last known caller could have reached the known
14143 callee by multiple different jump sequences. In such case @value{GDBN} still
14144 tries to show at least all the unambiguous top tail callers and all the
14145 unambiguous bottom tail calees, if any.
14146
14147 @table @code
14148 @anchor{set debug entry-values}
14149 @item set debug entry-values
14150 @kindex set debug entry-values
14151 When set to on, enables printing of analysis messages for both frame argument
14152 values at function entry and tail calls. It will show all the possible valid
14153 tail calls code paths it has considered. It will also print the intersection
14154 of them with the final unambiguous (possibly partial or even empty) code path
14155 result.
14156
14157 @item show debug entry-values
14158 @kindex show debug entry-values
14159 Show the current state of analysis messages printing for both frame argument
14160 values at function entry and tail calls.
14161 @end table
14162
14163 The analysis messages for tail calls can for example show why the virtual tail
14164 call frame for function @code{c} has not been recognized (due to the indirect
14165 reference by variable @code{x}):
14166
14167 @smallexample
14168 static void __attribute__((noinline, noclone)) c (void);
14169 void (*x) (void) = c;
14170 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
14171 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
14172 int main (void) @{ x (); return 0; @}
14173
14174 Breakpoint 1, DW_OP_entry_value resolving cannot find
14175 DW_TAG_call_site 0x40039a in main
14176 a () at t.c:3
14177 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
14178 (gdb) bt
14179 #0 a () at t.c:3
14180 #1 0x000000000040039a in main () at t.c:5
14181 @end smallexample
14182
14183 Another possibility is an ambiguous virtual tail call frames resolution:
14184
14185 @smallexample
14186 int i;
14187 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
14188 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
14189 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
14190 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
14191 static void __attribute__((noinline, noclone)) b (void)
14192 @{ if (i) c (); else e (); @}
14193 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
14194 int main (void) @{ a (); return 0; @}
14195
14196 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
14197 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
14198 tailcall: reduced: 0x4004d2(a) |
14199 (gdb) bt
14200 #0 f () at t.c:2
14201 #1 0x00000000004004d2 in a () at t.c:8
14202 #2 0x0000000000400395 in main () at t.c:9
14203 @end smallexample
14204
14205 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
14206 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
14207
14208 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
14209 @ifset HAVE_MAKEINFO_CLICK
14210 @set ARROW @click{}
14211 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
14212 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
14213 @end ifset
14214 @ifclear HAVE_MAKEINFO_CLICK
14215 @set ARROW ->
14216 @set CALLSEQ1B @value{CALLSEQ1A}
14217 @set CALLSEQ2B @value{CALLSEQ2A}
14218 @end ifclear
14219
14220 Frames #0 and #2 are real, #1 is a virtual tail call frame.
14221 The code can have possible execution paths @value{CALLSEQ1B} or
14222 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
14223
14224 @code{initial:} state shows some random possible calling sequence @value{GDBN}
14225 has found. It then finds another possible calling sequence - that one is
14226 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
14227 printed as the @code{reduced:} calling sequence. That one could have many
14228 further @code{compare:} and @code{reduced:} statements as long as there remain
14229 any non-ambiguous sequence entries.
14230
14231 For the frame of function @code{b} in both cases there are different possible
14232 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
14233 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
14234 therefore this one is displayed to the user while the ambiguous frames are
14235 omitted.
14236
14237 There can be also reasons why printing of frame argument values at function
14238 entry may fail:
14239
14240 @smallexample
14241 int v;
14242 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
14243 static void __attribute__((noinline, noclone)) a (int i);
14244 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
14245 static void __attribute__((noinline, noclone)) a (int i)
14246 @{ if (i) b (i - 1); else c (0); @}
14247 int main (void) @{ a (5); return 0; @}
14248
14249 (gdb) bt
14250 #0 c (i=i@@entry=0) at t.c:2
14251 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
14252 function "a" at 0x400420 can call itself via tail calls
14253 i=<optimized out>) at t.c:6
14254 #2 0x000000000040036e in main () at t.c:7
14255 @end smallexample
14256
14257 @value{GDBN} cannot find out from the inferior state if and how many times did
14258 function @code{a} call itself (via function @code{b}) as these calls would be
14259 tail calls. Such tail calls would modify the @code{i} variable, therefore
14260 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
14261 prints @code{<optimized out>} instead.
14262
14263 @node Macros
14264 @chapter C Preprocessor Macros
14265
14266 Some languages, such as C and C@t{++}, provide a way to define and invoke
14267 ``preprocessor macros'' which expand into strings of tokens.
14268 @value{GDBN} can evaluate expressions containing macro invocations, show
14269 the result of macro expansion, and show a macro's definition, including
14270 where it was defined.
14271
14272 You may need to compile your program specially to provide @value{GDBN}
14273 with information about preprocessor macros. Most compilers do not
14274 include macros in their debugging information, even when you compile
14275 with the @option{-g} flag. @xref{Compilation}.
14276
14277 A program may define a macro at one point, remove that definition later,
14278 and then provide a different definition after that. Thus, at different
14279 points in the program, a macro may have different definitions, or have
14280 no definition at all. If there is a current stack frame, @value{GDBN}
14281 uses the macros in scope at that frame's source code line. Otherwise,
14282 @value{GDBN} uses the macros in scope at the current listing location;
14283 see @ref{List}.
14284
14285 Whenever @value{GDBN} evaluates an expression, it always expands any
14286 macro invocations present in the expression. @value{GDBN} also provides
14287 the following commands for working with macros explicitly.
14288
14289 @table @code
14290
14291 @kindex macro expand
14292 @cindex macro expansion, showing the results of preprocessor
14293 @cindex preprocessor macro expansion, showing the results of
14294 @cindex expanding preprocessor macros
14295 @item macro expand @var{expression}
14296 @itemx macro exp @var{expression}
14297 Show the results of expanding all preprocessor macro invocations in
14298 @var{expression}. Since @value{GDBN} simply expands macros, but does
14299 not parse the result, @var{expression} need not be a valid expression;
14300 it can be any string of tokens.
14301
14302 @kindex macro exp1
14303 @item macro expand-once @var{expression}
14304 @itemx macro exp1 @var{expression}
14305 @cindex expand macro once
14306 @i{(This command is not yet implemented.)} Show the results of
14307 expanding those preprocessor macro invocations that appear explicitly in
14308 @var{expression}. Macro invocations appearing in that expansion are
14309 left unchanged. This command allows you to see the effect of a
14310 particular macro more clearly, without being confused by further
14311 expansions. Since @value{GDBN} simply expands macros, but does not
14312 parse the result, @var{expression} need not be a valid expression; it
14313 can be any string of tokens.
14314
14315 @kindex info macro
14316 @cindex macro definition, showing
14317 @cindex definition of a macro, showing
14318 @cindex macros, from debug info
14319 @item info macro [-a|-all] [--] @var{macro}
14320 Show the current definition or all definitions of the named @var{macro},
14321 and describe the source location or compiler command-line where that
14322 definition was established. The optional double dash is to signify the end of
14323 argument processing and the beginning of @var{macro} for non C-like macros where
14324 the macro may begin with a hyphen.
14325
14326 @kindex info macros
14327 @item info macros @var{locspec}
14328 Show all macro definitions that are in effect at the source line of
14329 the code location that results from resolving @var{locspec}, and
14330 describe the source location or compiler command-line where those
14331 definitions were established.
14332
14333 @kindex macro define
14334 @cindex user-defined macros
14335 @cindex defining macros interactively
14336 @cindex macros, user-defined
14337 @item macro define @var{macro} @var{replacement-list}
14338 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
14339 Introduce a definition for a preprocessor macro named @var{macro},
14340 invocations of which are replaced by the tokens given in
14341 @var{replacement-list}. The first form of this command defines an
14342 ``object-like'' macro, which takes no arguments; the second form
14343 defines a ``function-like'' macro, which takes the arguments given in
14344 @var{arglist}.
14345
14346 A definition introduced by this command is in scope in every
14347 expression evaluated in @value{GDBN}, until it is removed with the
14348 @code{macro undef} command, described below. The definition overrides
14349 all definitions for @var{macro} present in the program being debugged,
14350 as well as any previous user-supplied definition.
14351
14352 @kindex macro undef
14353 @item macro undef @var{macro}
14354 Remove any user-supplied definition for the macro named @var{macro}.
14355 This command only affects definitions provided with the @code{macro
14356 define} command, described above; it cannot remove definitions present
14357 in the program being debugged.
14358
14359 @kindex macro list
14360 @item macro list
14361 List all the macros defined using the @code{macro define} command.
14362 @end table
14363
14364 @cindex macros, example of debugging with
14365 Here is a transcript showing the above commands in action. First, we
14366 show our source files:
14367
14368 @smallexample
14369 $ cat sample.c
14370 #include <stdio.h>
14371 #include "sample.h"
14372
14373 #define M 42
14374 #define ADD(x) (M + x)
14375
14376 main ()
14377 @{
14378 #define N 28
14379 printf ("Hello, world!\n");
14380 #undef N
14381 printf ("We're so creative.\n");
14382 #define N 1729
14383 printf ("Goodbye, world!\n");
14384 @}
14385 $ cat sample.h
14386 #define Q <
14387 $
14388 @end smallexample
14389
14390 Now, we compile the program using the @sc{gnu} C compiler,
14391 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14392 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14393 and @option{-gdwarf-4}; we recommend always choosing the most recent
14394 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14395 includes information about preprocessor macros in the debugging
14396 information.
14397
14398 @smallexample
14399 $ gcc -gdwarf-2 -g3 sample.c -o sample
14400 $
14401 @end smallexample
14402
14403 Now, we start @value{GDBN} on our sample program:
14404
14405 @smallexample
14406 $ gdb -nw sample
14407 GNU gdb 2002-05-06-cvs
14408 Copyright 2002 Free Software Foundation, Inc.
14409 GDB is free software, @dots{}
14410 (@value{GDBP})
14411 @end smallexample
14412
14413 We can expand macros and examine their definitions, even when the
14414 program is not running. @value{GDBN} uses the current listing position
14415 to decide which macro definitions are in scope:
14416
14417 @smallexample
14418 (@value{GDBP}) list main
14419 3
14420 4 #define M 42
14421 5 #define ADD(x) (M + x)
14422 6
14423 7 main ()
14424 8 @{
14425 9 #define N 28
14426 10 printf ("Hello, world!\n");
14427 11 #undef N
14428 12 printf ("We're so creative.\n");
14429 (@value{GDBP}) info macro ADD
14430 Defined at /home/jimb/gdb/macros/play/sample.c:5
14431 #define ADD(x) (M + x)
14432 (@value{GDBP}) info macro Q
14433 Defined at /home/jimb/gdb/macros/play/sample.h:1
14434 included at /home/jimb/gdb/macros/play/sample.c:2
14435 #define Q <
14436 (@value{GDBP}) macro expand ADD(1)
14437 expands to: (42 + 1)
14438 (@value{GDBP}) macro expand-once ADD(1)
14439 expands to: once (M + 1)
14440 (@value{GDBP})
14441 @end smallexample
14442
14443 In the example above, note that @code{macro expand-once} expands only
14444 the macro invocation explicit in the original text --- the invocation of
14445 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14446 which was introduced by @code{ADD}.
14447
14448 Once the program is running, @value{GDBN} uses the macro definitions in
14449 force at the source line of the current stack frame:
14450
14451 @smallexample
14452 (@value{GDBP}) break main
14453 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14454 (@value{GDBP}) run
14455 Starting program: /home/jimb/gdb/macros/play/sample
14456
14457 Breakpoint 1, main () at sample.c:10
14458 10 printf ("Hello, world!\n");
14459 (@value{GDBP})
14460 @end smallexample
14461
14462 At line 10, the definition of the macro @code{N} at line 9 is in force:
14463
14464 @smallexample
14465 (@value{GDBP}) info macro N
14466 Defined at /home/jimb/gdb/macros/play/sample.c:9
14467 #define N 28
14468 (@value{GDBP}) macro expand N Q M
14469 expands to: 28 < 42
14470 (@value{GDBP}) print N Q M
14471 $1 = 1
14472 (@value{GDBP})
14473 @end smallexample
14474
14475 As we step over directives that remove @code{N}'s definition, and then
14476 give it a new definition, @value{GDBN} finds the definition (or lack
14477 thereof) in force at each point:
14478
14479 @smallexample
14480 (@value{GDBP}) next
14481 Hello, world!
14482 12 printf ("We're so creative.\n");
14483 (@value{GDBP}) info macro N
14484 The symbol `N' has no definition as a C/C++ preprocessor macro
14485 at /home/jimb/gdb/macros/play/sample.c:12
14486 (@value{GDBP}) next
14487 We're so creative.
14488 14 printf ("Goodbye, world!\n");
14489 (@value{GDBP}) info macro N
14490 Defined at /home/jimb/gdb/macros/play/sample.c:13
14491 #define N 1729
14492 (@value{GDBP}) macro expand N Q M
14493 expands to: 1729 < 42
14494 (@value{GDBP}) print N Q M
14495 $2 = 0
14496 (@value{GDBP})
14497 @end smallexample
14498
14499 In addition to source files, macros can be defined on the compilation command
14500 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14501 such a way, @value{GDBN} displays the location of their definition as line zero
14502 of the source file submitted to the compiler.
14503
14504 @smallexample
14505 (@value{GDBP}) info macro __STDC__
14506 Defined at /home/jimb/gdb/macros/play/sample.c:0
14507 -D__STDC__=1
14508 (@value{GDBP})
14509 @end smallexample
14510
14511
14512 @node Tracepoints
14513 @chapter Tracepoints
14514 @c This chapter is based on the documentation written by Michael
14515 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14516
14517 @cindex tracepoints
14518 In some applications, it is not feasible for the debugger to interrupt
14519 the program's execution long enough for the developer to learn
14520 anything helpful about its behavior. If the program's correctness
14521 depends on its real-time behavior, delays introduced by a debugger
14522 might cause the program to change its behavior drastically, or perhaps
14523 fail, even when the code itself is correct. It is useful to be able
14524 to observe the program's behavior without interrupting it.
14525
14526 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14527 specify locations in the program, called @dfn{tracepoints}, and
14528 arbitrary expressions to evaluate when those tracepoints are reached.
14529 Later, using the @code{tfind} command, you can examine the values
14530 those expressions had when the program hit the tracepoints. The
14531 expressions may also denote objects in memory---structures or arrays,
14532 for example---whose values @value{GDBN} should record; while visiting
14533 a particular tracepoint, you may inspect those objects as if they were
14534 in memory at that moment. However, because @value{GDBN} records these
14535 values without interacting with you, it can do so quickly and
14536 unobtrusively, hopefully not disturbing the program's behavior.
14537
14538 The tracepoint facility is currently available only for remote
14539 targets. @xref{Targets}. In addition, your remote target must know
14540 how to collect trace data. This functionality is implemented in the
14541 remote stub; however, none of the stubs distributed with @value{GDBN}
14542 support tracepoints as of this writing. The format of the remote
14543 packets used to implement tracepoints are described in @ref{Tracepoint
14544 Packets}.
14545
14546 It is also possible to get trace data from a file, in a manner reminiscent
14547 of corefiles; you specify the filename, and use @code{tfind} to search
14548 through the file. @xref{Trace Files}, for more details.
14549
14550 This chapter describes the tracepoint commands and features.
14551
14552 @menu
14553 * Set Tracepoints::
14554 * Analyze Collected Data::
14555 * Tracepoint Variables::
14556 * Trace Files::
14557 @end menu
14558
14559 @node Set Tracepoints
14560 @section Commands to Set Tracepoints
14561
14562 Before running such a @dfn{trace experiment}, an arbitrary number of
14563 tracepoints can be set. A tracepoint is actually a special type of
14564 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14565 standard breakpoint commands. For instance, as with breakpoints,
14566 tracepoint numbers are successive integers starting from one, and many
14567 of the commands associated with tracepoints take the tracepoint number
14568 as their argument, to identify which tracepoint to work on.
14569
14570 For each tracepoint, you can specify, in advance, some arbitrary set
14571 of data that you want the target to collect in the trace buffer when
14572 it hits that tracepoint. The collected data can include registers,
14573 local variables, or global data. Later, you can use @value{GDBN}
14574 commands to examine the values these data had at the time the
14575 tracepoint was hit.
14576
14577 Tracepoints do not support every breakpoint feature. Ignore counts on
14578 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14579 commands when they are hit. Tracepoints may not be thread-specific
14580 either.
14581
14582 @cindex fast tracepoints
14583 Some targets may support @dfn{fast tracepoints}, which are inserted in
14584 a different way (such as with a jump instead of a trap), that is
14585 faster but possibly restricted in where they may be installed.
14586
14587 @cindex static tracepoints
14588 @cindex markers, static tracepoints
14589 @cindex probing markers, static tracepoints
14590 Regular and fast tracepoints are dynamic tracing facilities, meaning
14591 that they can be used to insert tracepoints at (almost) any location
14592 in the target. Some targets may also support controlling @dfn{static
14593 tracepoints} from @value{GDBN}. With static tracing, a set of
14594 instrumentation points, also known as @dfn{markers}, are embedded in
14595 the target program, and can be activated or deactivated by name or
14596 address. These are usually placed at locations which facilitate
14597 investigating what the target is actually doing. @value{GDBN}'s
14598 support for static tracing includes being able to list instrumentation
14599 points, and attach them with @value{GDBN} defined high level
14600 tracepoints that expose the whole range of convenience of
14601 @value{GDBN}'s tracepoints support. Namely, support for collecting
14602 registers values and values of global or local (to the instrumentation
14603 point) variables; tracepoint conditions and trace state variables.
14604 The act of installing a @value{GDBN} static tracepoint on an
14605 instrumentation point, or marker, is referred to as @dfn{probing} a
14606 static tracepoint marker.
14607
14608 @code{gdbserver} supports tracepoints on some target systems.
14609 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14610
14611 This section describes commands to set tracepoints and associated
14612 conditions and actions.
14613
14614 @menu
14615 * Create and Delete Tracepoints::
14616 * Enable and Disable Tracepoints::
14617 * Tracepoint Passcounts::
14618 * Tracepoint Conditions::
14619 * Trace State Variables::
14620 * Tracepoint Actions::
14621 * Listing Tracepoints::
14622 * Listing Static Tracepoint Markers::
14623 * Starting and Stopping Trace Experiments::
14624 * Tracepoint Restrictions::
14625 @end menu
14626
14627 @node Create and Delete Tracepoints
14628 @subsection Create and Delete Tracepoints
14629
14630 @table @code
14631 @cindex set tracepoint
14632 @kindex trace
14633 @item trace @var{locspec}
14634 The @code{trace} command is very similar to the @code{break} command.
14635 Its argument @var{locspec} can be any valid location specification.
14636 @xref{Location Specifications}. The @code{trace} command defines a tracepoint,
14637 which is a point in the target program where the debugger will briefly stop,
14638 collect some data, and then allow the program to continue. Setting a tracepoint
14639 or changing its actions takes effect immediately if the remote stub
14640 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14641 in tracing}).
14642 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14643 these changes don't take effect until the next @code{tstart}
14644 command, and once a trace experiment is running, further changes will
14645 not have any effect until the next trace experiment starts. In addition,
14646 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14647 address is not yet resolved. (This is similar to pending breakpoints.)
14648 Pending tracepoints are not downloaded to the target and not installed
14649 until they are resolved. The resolution of pending tracepoints requires
14650 @value{GDBN} support---when debugging with the remote target, and
14651 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14652 tracing}), pending tracepoints can not be resolved (and downloaded to
14653 the remote stub) while @value{GDBN} is disconnected.
14654
14655 Here are some examples of using the @code{trace} command:
14656
14657 @smallexample
14658 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14659
14660 (@value{GDBP}) @b{trace +2} // 2 lines forward
14661
14662 (@value{GDBP}) @b{trace my_function} // first source line of function
14663
14664 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14665
14666 (@value{GDBP}) @b{trace *0x2117c4} // an address
14667 @end smallexample
14668
14669 @noindent
14670 You can abbreviate @code{trace} as @code{tr}.
14671
14672 @item trace @var{locspec} if @var{cond}
14673 Set a tracepoint with condition @var{cond}; evaluate the expression
14674 @var{cond} each time the tracepoint is reached, and collect data only
14675 if the value is nonzero---that is, if @var{cond} evaluates as true.
14676 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14677 information on tracepoint conditions.
14678
14679 @item ftrace @var{locspec} [ if @var{cond} ]
14680 @cindex set fast tracepoint
14681 @cindex fast tracepoints, setting
14682 @kindex ftrace
14683 The @code{ftrace} command sets a fast tracepoint. For targets that
14684 support them, fast tracepoints will use a more efficient but possibly
14685 less general technique to trigger data collection, such as a jump
14686 instruction instead of a trap, or some sort of hardware support. It
14687 may not be possible to create a fast tracepoint at the desired
14688 location, in which case the command will exit with an explanatory
14689 message.
14690
14691 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14692 @code{trace}.
14693
14694 On 32-bit x86-architecture systems, fast tracepoints normally need to
14695 be placed at an instruction that is 5 bytes or longer, but can be
14696 placed at 4-byte instructions if the low 64K of memory of the target
14697 program is available to install trampolines. Some Unix-type systems,
14698 such as @sc{gnu}/Linux, exclude low addresses from the program's
14699 address space; but for instance with the Linux kernel it is possible
14700 to let @value{GDBN} use this area by doing a @command{sysctl} command
14701 to set the @code{mmap_min_addr} kernel parameter, as in
14702
14703 @example
14704 sudo sysctl -w vm.mmap_min_addr=32768
14705 @end example
14706
14707 @noindent
14708 which sets the low address to 32K, which leaves plenty of room for
14709 trampolines. The minimum address should be set to a page boundary.
14710
14711 @item strace [@var{locspec} | -m @var{marker}] [ if @var{cond} ]
14712 @cindex set static tracepoint
14713 @cindex static tracepoints, setting
14714 @cindex probe static tracepoint marker
14715 @kindex strace
14716 The @code{strace} command sets a static tracepoint. For targets that
14717 support it, setting a static tracepoint probes a static
14718 instrumentation point, or marker, found at the code locations that
14719 result from resolving @var{locspec}. It may not be possible to set a
14720 static tracepoint at the desired code location, in which case the
14721 command will exit with an explanatory message.
14722
14723 @value{GDBN} handles arguments to @code{strace} exactly as for
14724 @code{trace}, with the addition that the user can also specify
14725 @code{-m @var{marker}} instead of a location spec. This probes the marker
14726 identified by the @var{marker} string identifier. This identifier
14727 depends on the static tracepoint backend library your program is
14728 using. You can find all the marker identifiers in the @samp{ID} field
14729 of the @code{info static-tracepoint-markers} command output.
14730 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14731 Markers}. For example, in the following small program using the UST
14732 tracing engine:
14733
14734 @smallexample
14735 main ()
14736 @{
14737 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14738 @}
14739 @end smallexample
14740
14741 @noindent
14742 the marker id is composed of joining the first two arguments to the
14743 @code{trace_mark} call with a slash, which translates to:
14744
14745 @smallexample
14746 (@value{GDBP}) info static-tracepoint-markers
14747 Cnt Enb ID Address What
14748 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14749 Data: "str %s"
14750 [etc...]
14751 @end smallexample
14752
14753 @noindent
14754 so you may probe the marker above with:
14755
14756 @smallexample
14757 (@value{GDBP}) strace -m ust/bar33
14758 @end smallexample
14759
14760 Static tracepoints accept an extra collect action --- @code{collect
14761 $_sdata}. This collects arbitrary user data passed in the probe point
14762 call to the tracing library. In the UST example above, you'll see
14763 that the third argument to @code{trace_mark} is a printf-like format
14764 string. The user data is then the result of running that formatting
14765 string against the following arguments. Note that @code{info
14766 static-tracepoint-markers} command output lists that format string in
14767 the @samp{Data:} field.
14768
14769 You can inspect this data when analyzing the trace buffer, by printing
14770 the $_sdata variable like any other variable available to
14771 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14772
14773 @vindex $tpnum
14774 @cindex last tracepoint number
14775 @cindex recent tracepoint number
14776 @cindex tracepoint number
14777 The convenience variable @code{$tpnum} records the tracepoint number
14778 of the most recently set tracepoint.
14779
14780 @kindex delete tracepoint
14781 @cindex tracepoint deletion
14782 @item delete tracepoint @r{[}@var{num}@r{]}
14783 Permanently delete one or more tracepoints. With no argument, the
14784 default is to delete all tracepoints. Note that the regular
14785 @code{delete} command can remove tracepoints also.
14786
14787 Examples:
14788
14789 @smallexample
14790 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14791
14792 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14793 @end smallexample
14794
14795 @noindent
14796 You can abbreviate this command as @code{del tr}.
14797 @end table
14798
14799 @node Enable and Disable Tracepoints
14800 @subsection Enable and Disable Tracepoints
14801
14802 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14803
14804 @table @code
14805 @kindex disable tracepoint
14806 @item disable tracepoint @r{[}@var{num}@r{]}
14807 Disable tracepoint @var{num}, or all tracepoints if no argument
14808 @var{num} is given. A disabled tracepoint will have no effect during
14809 a trace experiment, but it is not forgotten. You can re-enable
14810 a disabled tracepoint using the @code{enable tracepoint} command.
14811 If the command is issued during a trace experiment and the debug target
14812 has support for disabling tracepoints during a trace experiment, then the
14813 change will be effective immediately. Otherwise, it will be applied to the
14814 next trace experiment.
14815
14816 @kindex enable tracepoint
14817 @item enable tracepoint @r{[}@var{num}@r{]}
14818 Enable tracepoint @var{num}, or all tracepoints. If this command is
14819 issued during a trace experiment and the debug target supports enabling
14820 tracepoints during a trace experiment, then the enabled tracepoints will
14821 become effective immediately. Otherwise, they will become effective the
14822 next time a trace experiment is run.
14823 @end table
14824
14825 @node Tracepoint Passcounts
14826 @subsection Tracepoint Passcounts
14827
14828 @table @code
14829 @kindex passcount
14830 @cindex tracepoint pass count
14831 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14832 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14833 automatically stop a trace experiment. If a tracepoint's passcount is
14834 @var{n}, then the trace experiment will be automatically stopped on
14835 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14836 @var{num} is not specified, the @code{passcount} command sets the
14837 passcount of the most recently defined tracepoint. If no passcount is
14838 given, the trace experiment will run until stopped explicitly by the
14839 user.
14840
14841 Examples:
14842
14843 @smallexample
14844 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14845 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14846
14847 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14848 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14849 (@value{GDBP}) @b{trace foo}
14850 (@value{GDBP}) @b{pass 3}
14851 (@value{GDBP}) @b{trace bar}
14852 (@value{GDBP}) @b{pass 2}
14853 (@value{GDBP}) @b{trace baz}
14854 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14855 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14856 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14857 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14858 @end smallexample
14859 @end table
14860
14861 @node Tracepoint Conditions
14862 @subsection Tracepoint Conditions
14863 @cindex conditional tracepoints
14864 @cindex tracepoint conditions
14865
14866 The simplest sort of tracepoint collects data every time your program
14867 reaches a specified place. You can also specify a @dfn{condition} for
14868 a tracepoint. A condition is just a Boolean expression in your
14869 programming language (@pxref{Expressions, ,Expressions}). A
14870 tracepoint with a condition evaluates the expression each time your
14871 program reaches it, and data collection happens only if the condition
14872 is true.
14873
14874 Tracepoint conditions can be specified when a tracepoint is set, by
14875 using @samp{if} in the arguments to the @code{trace} command.
14876 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14877 also be set or changed at any time with the @code{condition} command,
14878 just as with breakpoints.
14879
14880 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14881 the conditional expression itself. Instead, @value{GDBN} encodes the
14882 expression into an agent expression (@pxref{Agent Expressions})
14883 suitable for execution on the target, independently of @value{GDBN}.
14884 Global variables become raw memory locations, locals become stack
14885 accesses, and so forth.
14886
14887 For instance, suppose you have a function that is usually called
14888 frequently, but should not be called after an error has occurred. You
14889 could use the following tracepoint command to collect data about calls
14890 of that function that happen while the error code is propagating
14891 through the program; an unconditional tracepoint could end up
14892 collecting thousands of useless trace frames that you would have to
14893 search through.
14894
14895 @smallexample
14896 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14897 @end smallexample
14898
14899 @node Trace State Variables
14900 @subsection Trace State Variables
14901 @cindex trace state variables
14902
14903 A @dfn{trace state variable} is a special type of variable that is
14904 created and managed by target-side code. The syntax is the same as
14905 that for GDB's convenience variables (a string prefixed with ``$''),
14906 but they are stored on the target. They must be created explicitly,
14907 using a @code{tvariable} command. They are always 64-bit signed
14908 integers.
14909
14910 Trace state variables are remembered by @value{GDBN}, and downloaded
14911 to the target along with tracepoint information when the trace
14912 experiment starts. There are no intrinsic limits on the number of
14913 trace state variables, beyond memory limitations of the target.
14914
14915 @cindex convenience variables, and trace state variables
14916 Although trace state variables are managed by the target, you can use
14917 them in print commands and expressions as if they were convenience
14918 variables; @value{GDBN} will get the current value from the target
14919 while the trace experiment is running. Trace state variables share
14920 the same namespace as other ``$'' variables, which means that you
14921 cannot have trace state variables with names like @code{$23} or
14922 @code{$pc}, nor can you have a trace state variable and a convenience
14923 variable with the same name.
14924
14925 @table @code
14926
14927 @item tvariable $@var{name} [ = @var{expression} ]
14928 @kindex tvariable
14929 The @code{tvariable} command creates a new trace state variable named
14930 @code{$@var{name}}, and optionally gives it an initial value of
14931 @var{expression}. The @var{expression} is evaluated when this command is
14932 entered; the result will be converted to an integer if possible,
14933 otherwise @value{GDBN} will report an error. A subsequent
14934 @code{tvariable} command specifying the same name does not create a
14935 variable, but instead assigns the supplied initial value to the
14936 existing variable of that name, overwriting any previous initial
14937 value. The default initial value is 0.
14938
14939 @item info tvariables
14940 @kindex info tvariables
14941 List all the trace state variables along with their initial values.
14942 Their current values may also be displayed, if the trace experiment is
14943 currently running.
14944
14945 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14946 @kindex delete tvariable
14947 Delete the given trace state variables, or all of them if no arguments
14948 are specified.
14949
14950 @end table
14951
14952 @node Tracepoint Actions
14953 @subsection Tracepoint Action Lists
14954
14955 @table @code
14956 @kindex actions
14957 @cindex tracepoint actions
14958 @item actions @r{[}@var{num}@r{]}
14959 This command will prompt for a list of actions to be taken when the
14960 tracepoint is hit. If the tracepoint number @var{num} is not
14961 specified, this command sets the actions for the one that was most
14962 recently defined (so that you can define a tracepoint and then say
14963 @code{actions} without bothering about its number). You specify the
14964 actions themselves on the following lines, one action at a time, and
14965 terminate the actions list with a line containing just @code{end}. So
14966 far, the only defined actions are @code{collect}, @code{teval}, and
14967 @code{while-stepping}.
14968
14969 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14970 Commands, ,Breakpoint Command Lists}), except that only the defined
14971 actions are allowed; any other @value{GDBN} command is rejected.
14972
14973 @cindex remove actions from a tracepoint
14974 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14975 and follow it immediately with @samp{end}.
14976
14977 @smallexample
14978 (@value{GDBP}) @b{collect @var{data}} // collect some data
14979
14980 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14981
14982 (@value{GDBP}) @b{end} // signals the end of actions.
14983 @end smallexample
14984
14985 In the following example, the action list begins with @code{collect}
14986 commands indicating the things to be collected when the tracepoint is
14987 hit. Then, in order to single-step and collect additional data
14988 following the tracepoint, a @code{while-stepping} command is used,
14989 followed by the list of things to be collected after each step in a
14990 sequence of single steps. The @code{while-stepping} command is
14991 terminated by its own separate @code{end} command. Lastly, the action
14992 list is terminated by an @code{end} command.
14993
14994 @smallexample
14995 (@value{GDBP}) @b{trace foo}
14996 (@value{GDBP}) @b{actions}
14997 Enter actions for tracepoint 1, one per line:
14998 > collect bar,baz
14999 > collect $regs
15000 > while-stepping 12
15001 > collect $pc, arr[i]
15002 > end
15003 end
15004 @end smallexample
15005
15006 @kindex collect @r{(tracepoints)}
15007 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
15008 Collect values of the given expressions when the tracepoint is hit.
15009 This command accepts a comma-separated list of any valid expressions.
15010 In addition to global, static, or local variables, the following
15011 special arguments are supported:
15012
15013 @table @code
15014 @item $regs
15015 Collect all registers.
15016
15017 @item $args
15018 Collect all function arguments.
15019
15020 @item $locals
15021 Collect all local variables.
15022
15023 @item $_ret
15024 Collect the return address. This is helpful if you want to see more
15025 of a backtrace.
15026
15027 @emph{Note:} The return address location can not always be reliably
15028 determined up front, and the wrong address / registers may end up
15029 collected instead. On some architectures the reliability is higher
15030 for tracepoints at function entry, while on others it's the opposite.
15031 When this happens, backtracing will stop because the return address is
15032 found unavailable (unless another collect rule happened to match it).
15033
15034 @item $_probe_argc
15035 Collects the number of arguments from the static probe at which the
15036 tracepoint is located.
15037 @xref{Static Probe Points}.
15038
15039 @item $_probe_arg@var{n}
15040 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
15041 from the static probe at which the tracepoint is located.
15042 @xref{Static Probe Points}.
15043
15044 @item $_sdata
15045 @vindex $_sdata@r{, collect}
15046 Collect static tracepoint marker specific data. Only available for
15047 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
15048 Lists}. On the UST static tracepoints library backend, an
15049 instrumentation point resembles a @code{printf} function call. The
15050 tracing library is able to collect user specified data formatted to a
15051 character string using the format provided by the programmer that
15052 instrumented the program. Other backends have similar mechanisms.
15053 Here's an example of a UST marker call:
15054
15055 @smallexample
15056 const char master_name[] = "$your_name";
15057 trace_mark(channel1, marker1, "hello %s", master_name)
15058 @end smallexample
15059
15060 In this case, collecting @code{$_sdata} collects the string
15061 @samp{hello $yourname}. When analyzing the trace buffer, you can
15062 inspect @samp{$_sdata} like any other variable available to
15063 @value{GDBN}.
15064 @end table
15065
15066 You can give several consecutive @code{collect} commands, each one
15067 with a single argument, or one @code{collect} command with several
15068 arguments separated by commas; the effect is the same.
15069
15070 The optional @var{mods} changes the usual handling of the arguments.
15071 @code{s} requests that pointers to chars be handled as strings, in
15072 particular collecting the contents of the memory being pointed at, up
15073 to the first zero. The upper bound is by default the value of the
15074 @code{print elements} variable; if @code{s} is followed by a decimal
15075 number, that is the upper bound instead. So for instance
15076 @samp{collect/s25 mystr} collects as many as 25 characters at
15077 @samp{mystr}.
15078
15079 The command @code{info scope} (@pxref{Symbols, info scope}) is
15080 particularly useful for figuring out what data to collect.
15081
15082 @kindex teval @r{(tracepoints)}
15083 @item teval @var{expr1}, @var{expr2}, @dots{}
15084 Evaluate the given expressions when the tracepoint is hit. This
15085 command accepts a comma-separated list of expressions. The results
15086 are discarded, so this is mainly useful for assigning values to trace
15087 state variables (@pxref{Trace State Variables}) without adding those
15088 values to the trace buffer, as would be the case if the @code{collect}
15089 action were used.
15090
15091 @kindex while-stepping @r{(tracepoints)}
15092 @item while-stepping @var{n}
15093 Perform @var{n} single-step instruction traces after the tracepoint,
15094 collecting new data after each step. The @code{while-stepping}
15095 command is followed by the list of what to collect while stepping
15096 (followed by its own @code{end} command):
15097
15098 @smallexample
15099 > while-stepping 12
15100 > collect $regs, myglobal
15101 > end
15102 >
15103 @end smallexample
15104
15105 @noindent
15106 Note that @code{$pc} is not automatically collected by
15107 @code{while-stepping}; you need to explicitly collect that register if
15108 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
15109 @code{stepping}.
15110
15111 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
15112 @kindex set default-collect
15113 @cindex default collection action
15114 This variable is a list of expressions to collect at each tracepoint
15115 hit. It is effectively an additional @code{collect} action prepended
15116 to every tracepoint action list. The expressions are parsed
15117 individually for each tracepoint, so for instance a variable named
15118 @code{xyz} may be interpreted as a global for one tracepoint, and a
15119 local for another, as appropriate to the tracepoint's location.
15120
15121 @item show default-collect
15122 @kindex show default-collect
15123 Show the list of expressions that are collected by default at each
15124 tracepoint hit.
15125
15126 @end table
15127
15128 @node Listing Tracepoints
15129 @subsection Listing Tracepoints
15130
15131 @table @code
15132 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
15133 @kindex info tp @r{[}@var{n}@dots{}@r{]}
15134 @cindex information about tracepoints
15135 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
15136 Display information about the tracepoint @var{num}. If you don't
15137 specify a tracepoint number, displays information about all the
15138 tracepoints defined so far. The format is similar to that used for
15139 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
15140 command, simply restricting itself to tracepoints.
15141
15142 A tracepoint's listing may include additional information specific to
15143 tracing:
15144
15145 @itemize @bullet
15146 @item
15147 its passcount as given by the @code{passcount @var{n}} command
15148
15149 @item
15150 the state about installed on target of each location
15151 @end itemize
15152
15153 @smallexample
15154 (@value{GDBP}) @b{info trace}
15155 Num Type Disp Enb Address What
15156 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
15157 while-stepping 20
15158 collect globfoo, $regs
15159 end
15160 collect globfoo2
15161 end
15162 pass count 1200
15163 2 tracepoint keep y <MULTIPLE>
15164 collect $eip
15165 2.1 y 0x0804859c in func4 at change-loc.h:35
15166 installed on target
15167 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
15168 installed on target
15169 2.3 y <PENDING> set_tracepoint
15170 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
15171 not installed on target
15172 (@value{GDBP})
15173 @end smallexample
15174
15175 @noindent
15176 This command can be abbreviated @code{info tp}.
15177 @end table
15178
15179 @node Listing Static Tracepoint Markers
15180 @subsection Listing Static Tracepoint Markers
15181
15182 @table @code
15183 @kindex info static-tracepoint-markers
15184 @cindex information about static tracepoint markers
15185 @item info static-tracepoint-markers
15186 Display information about all static tracepoint markers defined in the
15187 program.
15188
15189 For each marker, the following columns are printed:
15190
15191 @table @emph
15192 @item Count
15193 An incrementing counter, output to help readability. This is not a
15194 stable identifier.
15195 @item ID
15196 The marker ID, as reported by the target.
15197 @item Enabled or Disabled
15198 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
15199 that are not enabled.
15200 @item Address
15201 Where the marker is in your program, as a memory address.
15202 @item What
15203 Where the marker is in the source for your program, as a file and line
15204 number. If the debug information included in the program does not
15205 allow @value{GDBN} to locate the source of the marker, this column
15206 will be left blank.
15207 @end table
15208
15209 @noindent
15210 In addition, the following information may be printed for each marker:
15211
15212 @table @emph
15213 @item Data
15214 User data passed to the tracing library by the marker call. In the
15215 UST backend, this is the format string passed as argument to the
15216 marker call.
15217 @item Static tracepoints probing the marker
15218 The list of static tracepoints attached to the marker.
15219 @end table
15220
15221 @smallexample
15222 (@value{GDBP}) info static-tracepoint-markers
15223 Cnt ID Enb Address What
15224 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
15225 Data: number1 %d number2 %d
15226 Probed by static tracepoints: #2
15227 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
15228 Data: str %s
15229 (@value{GDBP})
15230 @end smallexample
15231 @end table
15232
15233 @node Starting and Stopping Trace Experiments
15234 @subsection Starting and Stopping Trace Experiments
15235
15236 @table @code
15237 @kindex tstart [ @var{notes} ]
15238 @cindex start a new trace experiment
15239 @cindex collected data discarded
15240 @item tstart
15241 This command starts the trace experiment, and begins collecting data.
15242 It has the side effect of discarding all the data collected in the
15243 trace buffer during the previous trace experiment. If any arguments
15244 are supplied, they are taken as a note and stored with the trace
15245 experiment's state. The notes may be arbitrary text, and are
15246 especially useful with disconnected tracing in a multi-user context;
15247 the notes can explain what the trace is doing, supply user contact
15248 information, and so forth.
15249
15250 @kindex tstop [ @var{notes} ]
15251 @cindex stop a running trace experiment
15252 @item tstop
15253 This command stops the trace experiment. If any arguments are
15254 supplied, they are recorded with the experiment as a note. This is
15255 useful if you are stopping a trace started by someone else, for
15256 instance if the trace is interfering with the system's behavior and
15257 needs to be stopped quickly.
15258
15259 @strong{Note}: a trace experiment and data collection may stop
15260 automatically if any tracepoint's passcount is reached
15261 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
15262
15263 @kindex tstatus
15264 @cindex status of trace data collection
15265 @cindex trace experiment, status of
15266 @item tstatus
15267 This command displays the status of the current trace data
15268 collection.
15269 @end table
15270
15271 Here is an example of the commands we described so far:
15272
15273 @smallexample
15274 (@value{GDBP}) @b{trace gdb_c_test}
15275 (@value{GDBP}) @b{actions}
15276 Enter actions for tracepoint #1, one per line.
15277 > collect $regs,$locals,$args
15278 > while-stepping 11
15279 > collect $regs
15280 > end
15281 > end
15282 (@value{GDBP}) @b{tstart}
15283 [time passes @dots{}]
15284 (@value{GDBP}) @b{tstop}
15285 @end smallexample
15286
15287 @anchor{disconnected tracing}
15288 @cindex disconnected tracing
15289 You can choose to continue running the trace experiment even if
15290 @value{GDBN} disconnects from the target, voluntarily or
15291 involuntarily. For commands such as @code{detach}, the debugger will
15292 ask what you want to do with the trace. But for unexpected
15293 terminations (@value{GDBN} crash, network outage), it would be
15294 unfortunate to lose hard-won trace data, so the variable
15295 @code{disconnected-tracing} lets you decide whether the trace should
15296 continue running without @value{GDBN}.
15297
15298 @table @code
15299 @item set disconnected-tracing on
15300 @itemx set disconnected-tracing off
15301 @kindex set disconnected-tracing
15302 Choose whether a tracing run should continue to run if @value{GDBN}
15303 has disconnected from the target. Note that @code{detach} or
15304 @code{quit} will ask you directly what to do about a running trace no
15305 matter what this variable's setting, so the variable is mainly useful
15306 for handling unexpected situations, such as loss of the network.
15307
15308 @item show disconnected-tracing
15309 @kindex show disconnected-tracing
15310 Show the current choice for disconnected tracing.
15311
15312 @end table
15313
15314 When you reconnect to the target, the trace experiment may or may not
15315 still be running; it might have filled the trace buffer in the
15316 meantime, or stopped for one of the other reasons. If it is running,
15317 it will continue after reconnection.
15318
15319 Upon reconnection, the target will upload information about the
15320 tracepoints in effect. @value{GDBN} will then compare that
15321 information to the set of tracepoints currently defined, and attempt
15322 to match them up, allowing for the possibility that the numbers may
15323 have changed due to creation and deletion in the meantime. If one of
15324 the target's tracepoints does not match any in @value{GDBN}, the
15325 debugger will create a new tracepoint, so that you have a number with
15326 which to specify that tracepoint. This matching-up process is
15327 necessarily heuristic, and it may result in useless tracepoints being
15328 created; you may simply delete them if they are of no use.
15329
15330 @cindex circular trace buffer
15331 If your target agent supports a @dfn{circular trace buffer}, then you
15332 can run a trace experiment indefinitely without filling the trace
15333 buffer; when space runs out, the agent deletes already-collected trace
15334 frames, oldest first, until there is enough room to continue
15335 collecting. This is especially useful if your tracepoints are being
15336 hit too often, and your trace gets terminated prematurely because the
15337 buffer is full. To ask for a circular trace buffer, simply set
15338 @samp{circular-trace-buffer} to on. You can set this at any time,
15339 including during tracing; if the agent can do it, it will change
15340 buffer handling on the fly, otherwise it will not take effect until
15341 the next run.
15342
15343 @table @code
15344 @item set circular-trace-buffer on
15345 @itemx set circular-trace-buffer off
15346 @kindex set circular-trace-buffer
15347 Choose whether a tracing run should use a linear or circular buffer
15348 for trace data. A linear buffer will not lose any trace data, but may
15349 fill up prematurely, while a circular buffer will discard old trace
15350 data, but it will have always room for the latest tracepoint hits.
15351
15352 @item show circular-trace-buffer
15353 @kindex show circular-trace-buffer
15354 Show the current choice for the trace buffer. Note that this may not
15355 match the agent's current buffer handling, nor is it guaranteed to
15356 match the setting that might have been in effect during a past run,
15357 for instance if you are looking at frames from a trace file.
15358
15359 @end table
15360
15361 @table @code
15362 @item set trace-buffer-size @var{n}
15363 @itemx set trace-buffer-size unlimited
15364 @kindex set trace-buffer-size
15365 Request that the target use a trace buffer of @var{n} bytes. Not all
15366 targets will honor the request; they may have a compiled-in size for
15367 the trace buffer, or some other limitation. Set to a value of
15368 @code{unlimited} or @code{-1} to let the target use whatever size it
15369 likes. This is also the default.
15370
15371 @item show trace-buffer-size
15372 @kindex show trace-buffer-size
15373 Show the current requested size for the trace buffer. Note that this
15374 will only match the actual size if the target supports size-setting,
15375 and was able to handle the requested size. For instance, if the
15376 target can only change buffer size between runs, this variable will
15377 not reflect the change until the next run starts. Use @code{tstatus}
15378 to get a report of the actual buffer size.
15379 @end table
15380
15381 @table @code
15382 @item set trace-user @var{text}
15383 @kindex set trace-user
15384
15385 @item show trace-user
15386 @kindex show trace-user
15387
15388 @item set trace-notes @var{text}
15389 @kindex set trace-notes
15390 Set the trace run's notes.
15391
15392 @item show trace-notes
15393 @kindex show trace-notes
15394 Show the trace run's notes.
15395
15396 @item set trace-stop-notes @var{text}
15397 @kindex set trace-stop-notes
15398 Set the trace run's stop notes. The handling of the note is as for
15399 @code{tstop} arguments; the set command is convenient way to fix a
15400 stop note that is mistaken or incomplete.
15401
15402 @item show trace-stop-notes
15403 @kindex show trace-stop-notes
15404 Show the trace run's stop notes.
15405
15406 @end table
15407
15408 @node Tracepoint Restrictions
15409 @subsection Tracepoint Restrictions
15410
15411 @cindex tracepoint restrictions
15412 There are a number of restrictions on the use of tracepoints. As
15413 described above, tracepoint data gathering occurs on the target
15414 without interaction from @value{GDBN}. Thus the full capabilities of
15415 the debugger are not available during data gathering, and then at data
15416 examination time, you will be limited by only having what was
15417 collected. The following items describe some common problems, but it
15418 is not exhaustive, and you may run into additional difficulties not
15419 mentioned here.
15420
15421 @itemize @bullet
15422
15423 @item
15424 Tracepoint expressions are intended to gather objects (lvalues). Thus
15425 the full flexibility of GDB's expression evaluator is not available.
15426 You cannot call functions, cast objects to aggregate types, access
15427 convenience variables or modify values (except by assignment to trace
15428 state variables). Some language features may implicitly call
15429 functions (for instance Objective-C fields with accessors), and therefore
15430 cannot be collected either.
15431
15432 @item
15433 Collection of local variables, either individually or in bulk with
15434 @code{$locals} or @code{$args}, during @code{while-stepping} may
15435 behave erratically. The stepping action may enter a new scope (for
15436 instance by stepping into a function), or the location of the variable
15437 may change (for instance it is loaded into a register). The
15438 tracepoint data recorded uses the location information for the
15439 variables that is correct for the tracepoint location. When the
15440 tracepoint is created, it is not possible, in general, to determine
15441 where the steps of a @code{while-stepping} sequence will advance the
15442 program---particularly if a conditional branch is stepped.
15443
15444 @item
15445 Collection of an incompletely-initialized or partially-destroyed object
15446 may result in something that @value{GDBN} cannot display, or displays
15447 in a misleading way.
15448
15449 @item
15450 When @value{GDBN} displays a pointer to character it automatically
15451 dereferences the pointer to also display characters of the string
15452 being pointed to. However, collecting the pointer during tracing does
15453 not automatically collect the string. You need to explicitly
15454 dereference the pointer and provide size information if you want to
15455 collect not only the pointer, but the memory pointed to. For example,
15456 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15457 by @code{ptr}.
15458
15459 @item
15460 It is not possible to collect a complete stack backtrace at a
15461 tracepoint. Instead, you may collect the registers and a few hundred
15462 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15463 (adjust to use the name of the actual stack pointer register on your
15464 target architecture, and the amount of stack you wish to capture).
15465 Then the @code{backtrace} command will show a partial backtrace when
15466 using a trace frame. The number of stack frames that can be examined
15467 depends on the sizes of the frames in the collected stack. Note that
15468 if you ask for a block so large that it goes past the bottom of the
15469 stack, the target agent may report an error trying to read from an
15470 invalid address.
15471
15472 @item
15473 If you do not collect registers at a tracepoint, @value{GDBN} can
15474 infer that the value of @code{$pc} must be the same as the address of
15475 the tracepoint and use that when you are looking at a trace frame
15476 for that tracepoint. However, this cannot work if the tracepoint has
15477 multiple locations (for instance if it was set in a function that was
15478 inlined), or if it has a @code{while-stepping} loop. In those cases
15479 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15480 it to zero.
15481
15482 @end itemize
15483
15484 @node Analyze Collected Data
15485 @section Using the Collected Data
15486
15487 After the tracepoint experiment ends, you use @value{GDBN} commands
15488 for examining the trace data. The basic idea is that each tracepoint
15489 collects a trace @dfn{snapshot} every time it is hit and another
15490 snapshot every time it single-steps. All these snapshots are
15491 consecutively numbered from zero and go into a buffer, and you can
15492 examine them later. The way you examine them is to @dfn{focus} on a
15493 specific trace snapshot. When the remote stub is focused on a trace
15494 snapshot, it will respond to all @value{GDBN} requests for memory and
15495 registers by reading from the buffer which belongs to that snapshot,
15496 rather than from @emph{real} memory or registers of the program being
15497 debugged. This means that @strong{all} @value{GDBN} commands
15498 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15499 behave as if we were currently debugging the program state as it was
15500 when the tracepoint occurred. Any requests for data that are not in
15501 the buffer will fail.
15502
15503 @menu
15504 * tfind:: How to select a trace snapshot
15505 * tdump:: How to display all data for a snapshot
15506 * save tracepoints:: How to save tracepoints for a future run
15507 @end menu
15508
15509 @node tfind
15510 @subsection @code{tfind @var{n}}
15511
15512 @kindex tfind
15513 @cindex select trace snapshot
15514 @cindex find trace snapshot
15515 The basic command for selecting a trace snapshot from the buffer is
15516 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15517 counting from zero. If no argument @var{n} is given, the next
15518 snapshot is selected.
15519
15520 Here are the various forms of using the @code{tfind} command.
15521
15522 @table @code
15523 @item tfind start
15524 Find the first snapshot in the buffer. This is a synonym for
15525 @code{tfind 0} (since 0 is the number of the first snapshot).
15526
15527 @item tfind none
15528 Stop debugging trace snapshots, resume @emph{live} debugging.
15529
15530 @item tfind end
15531 Same as @samp{tfind none}.
15532
15533 @item tfind
15534 No argument means find the next trace snapshot or find the first
15535 one if no trace snapshot is selected.
15536
15537 @item tfind -
15538 Find the previous trace snapshot before the current one. This permits
15539 retracing earlier steps.
15540
15541 @item tfind tracepoint @var{num}
15542 Find the next snapshot associated with tracepoint @var{num}. Search
15543 proceeds forward from the last examined trace snapshot. If no
15544 argument @var{num} is given, it means find the next snapshot collected
15545 for the same tracepoint as the current snapshot.
15546
15547 @item tfind pc @var{addr}
15548 Find the next snapshot associated with the value @var{addr} of the
15549 program counter. Search proceeds forward from the last examined trace
15550 snapshot. If no argument @var{addr} is given, it means find the next
15551 snapshot with the same value of PC as the current snapshot.
15552
15553 @item tfind outside @var{addr1}, @var{addr2}
15554 Find the next snapshot whose PC is outside the given range of
15555 addresses (exclusive).
15556
15557 @item tfind range @var{addr1}, @var{addr2}
15558 Find the next snapshot whose PC is between @var{addr1} and
15559 @var{addr2} (inclusive).
15560
15561 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15562 Find the next snapshot associated with the source line @var{n}. If
15563 the optional argument @var{file} is given, refer to line @var{n} in
15564 that source file. Search proceeds forward from the last examined
15565 trace snapshot. If no argument @var{n} is given, it means find the
15566 next line other than the one currently being examined; thus saying
15567 @code{tfind line} repeatedly can appear to have the same effect as
15568 stepping from line to line in a @emph{live} debugging session.
15569 @end table
15570
15571 The default arguments for the @code{tfind} commands are specifically
15572 designed to make it easy to scan through the trace buffer. For
15573 instance, @code{tfind} with no argument selects the next trace
15574 snapshot, and @code{tfind -} with no argument selects the previous
15575 trace snapshot. So, by giving one @code{tfind} command, and then
15576 simply hitting @key{RET} repeatedly you can examine all the trace
15577 snapshots in order. Or, by saying @code{tfind -} and then hitting
15578 @key{RET} repeatedly you can examine the snapshots in reverse order.
15579 The @code{tfind line} command with no argument selects the snapshot
15580 for the next source line executed. The @code{tfind pc} command with
15581 no argument selects the next snapshot with the same program counter
15582 (PC) as the current frame. The @code{tfind tracepoint} command with
15583 no argument selects the next trace snapshot collected by the same
15584 tracepoint as the current one.
15585
15586 In addition to letting you scan through the trace buffer manually,
15587 these commands make it easy to construct @value{GDBN} scripts that
15588 scan through the trace buffer and print out whatever collected data
15589 you are interested in. Thus, if we want to examine the PC, FP, and SP
15590 registers from each trace frame in the buffer, we can say this:
15591
15592 @smallexample
15593 (@value{GDBP}) @b{tfind start}
15594 (@value{GDBP}) @b{while ($trace_frame != -1)}
15595 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15596 $trace_frame, $pc, $sp, $fp
15597 > tfind
15598 > end
15599
15600 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15601 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15602 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15603 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15604 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15605 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15606 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15607 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15608 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15609 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15610 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15611 @end smallexample
15612
15613 Or, if we want to examine the variable @code{X} at each source line in
15614 the buffer:
15615
15616 @smallexample
15617 (@value{GDBP}) @b{tfind start}
15618 (@value{GDBP}) @b{while ($trace_frame != -1)}
15619 > printf "Frame %d, X == %d\n", $trace_frame, X
15620 > tfind line
15621 > end
15622
15623 Frame 0, X = 1
15624 Frame 7, X = 2
15625 Frame 13, X = 255
15626 @end smallexample
15627
15628 @node tdump
15629 @subsection @code{tdump}
15630 @kindex tdump
15631 @cindex dump all data collected at tracepoint
15632 @cindex tracepoint data, display
15633
15634 This command takes no arguments. It prints all the data collected at
15635 the current trace snapshot.
15636
15637 @smallexample
15638 (@value{GDBP}) @b{trace 444}
15639 (@value{GDBP}) @b{actions}
15640 Enter actions for tracepoint #2, one per line:
15641 > collect $regs, $locals, $args, gdb_long_test
15642 > end
15643
15644 (@value{GDBP}) @b{tstart}
15645
15646 (@value{GDBP}) @b{tfind line 444}
15647 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15648 at gdb_test.c:444
15649 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15650
15651 (@value{GDBP}) @b{tdump}
15652 Data collected at tracepoint 2, trace frame 1:
15653 d0 0xc4aa0085 -995491707
15654 d1 0x18 24
15655 d2 0x80 128
15656 d3 0x33 51
15657 d4 0x71aea3d 119204413
15658 d5 0x22 34
15659 d6 0xe0 224
15660 d7 0x380035 3670069
15661 a0 0x19e24a 1696330
15662 a1 0x3000668 50333288
15663 a2 0x100 256
15664 a3 0x322000 3284992
15665 a4 0x3000698 50333336
15666 a5 0x1ad3cc 1758156
15667 fp 0x30bf3c 0x30bf3c
15668 sp 0x30bf34 0x30bf34
15669 ps 0x0 0
15670 pc 0x20b2c8 0x20b2c8
15671 fpcontrol 0x0 0
15672 fpstatus 0x0 0
15673 fpiaddr 0x0 0
15674 p = 0x20e5b4 "gdb-test"
15675 p1 = (void *) 0x11
15676 p2 = (void *) 0x22
15677 p3 = (void *) 0x33
15678 p4 = (void *) 0x44
15679 p5 = (void *) 0x55
15680 p6 = (void *) 0x66
15681 gdb_long_test = 17 '\021'
15682
15683 (@value{GDBP})
15684 @end smallexample
15685
15686 @code{tdump} works by scanning the tracepoint's current collection
15687 actions and printing the value of each expression listed. So
15688 @code{tdump} can fail, if after a run, you change the tracepoint's
15689 actions to mention variables that were not collected during the run.
15690
15691 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15692 uses the collected value of @code{$pc} to distinguish between trace
15693 frames that were collected at the tracepoint hit, and frames that were
15694 collected while stepping. This allows it to correctly choose whether
15695 to display the basic list of collections, or the collections from the
15696 body of the while-stepping loop. However, if @code{$pc} was not collected,
15697 then @code{tdump} will always attempt to dump using the basic collection
15698 list, and may fail if a while-stepping frame does not include all the
15699 same data that is collected at the tracepoint hit.
15700 @c This is getting pretty arcane, example would be good.
15701
15702 @node save tracepoints
15703 @subsection @code{save tracepoints @var{filename}}
15704 @kindex save tracepoints
15705 @kindex save-tracepoints
15706 @cindex save tracepoints for future sessions
15707
15708 This command saves all current tracepoint definitions together with
15709 their actions and passcounts, into a file @file{@var{filename}}
15710 suitable for use in a later debugging session. To read the saved
15711 tracepoint definitions, use the @code{source} command (@pxref{Command
15712 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15713 alias for @w{@code{save tracepoints}}
15714
15715 @node Tracepoint Variables
15716 @section Convenience Variables for Tracepoints
15717 @cindex tracepoint variables
15718 @cindex convenience variables for tracepoints
15719
15720 @table @code
15721 @vindex $trace_frame
15722 @item (int) $trace_frame
15723 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15724 snapshot is selected.
15725
15726 @vindex $tracepoint
15727 @item (int) $tracepoint
15728 The tracepoint for the current trace snapshot.
15729
15730 @vindex $trace_line
15731 @item (int) $trace_line
15732 The line number for the current trace snapshot.
15733
15734 @vindex $trace_file
15735 @item (char []) $trace_file
15736 The source file for the current trace snapshot.
15737
15738 @vindex $trace_func
15739 @item (char []) $trace_func
15740 The name of the function containing @code{$tracepoint}.
15741 @end table
15742
15743 Note: @code{$trace_file} is not suitable for use in @code{printf},
15744 use @code{output} instead.
15745
15746 Here's a simple example of using these convenience variables for
15747 stepping through all the trace snapshots and printing some of their
15748 data. Note that these are not the same as trace state variables,
15749 which are managed by the target.
15750
15751 @smallexample
15752 (@value{GDBP}) @b{tfind start}
15753
15754 (@value{GDBP}) @b{while $trace_frame != -1}
15755 > output $trace_file
15756 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15757 > tfind
15758 > end
15759 @end smallexample
15760
15761 @node Trace Files
15762 @section Using Trace Files
15763 @cindex trace files
15764
15765 In some situations, the target running a trace experiment may no
15766 longer be available; perhaps it crashed, or the hardware was needed
15767 for a different activity. To handle these cases, you can arrange to
15768 dump the trace data into a file, and later use that file as a source
15769 of trace data, via the @code{target tfile} command.
15770
15771 @table @code
15772
15773 @kindex tsave
15774 @item tsave [ -r ] @var{filename}
15775 @itemx tsave [-ctf] @var{dirname}
15776 Save the trace data to @var{filename}. By default, this command
15777 assumes that @var{filename} refers to the host filesystem, so if
15778 necessary @value{GDBN} will copy raw trace data up from the target and
15779 then save it. If the target supports it, you can also supply the
15780 optional argument @code{-r} (``remote'') to direct the target to save
15781 the data directly into @var{filename} in its own filesystem, which may be
15782 more efficient if the trace buffer is very large. (Note, however, that
15783 @code{target tfile} can only read from files accessible to the host.)
15784 By default, this command will save trace frame in tfile format.
15785 You can supply the optional argument @code{-ctf} to save data in CTF
15786 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15787 that can be shared by multiple debugging and tracing tools. Please go to
15788 @indicateurl{http://www.efficios.com/ctf} to get more information.
15789
15790 @kindex target tfile
15791 @kindex tfile
15792 @kindex target ctf
15793 @kindex ctf
15794 @item target tfile @var{filename}
15795 @itemx target ctf @var{dirname}
15796 Use the file named @var{filename} or directory named @var{dirname} as
15797 a source of trace data. Commands that examine data work as they do with
15798 a live target, but it is not possible to run any new trace experiments.
15799 @code{tstatus} will report the state of the trace run at the moment
15800 the data was saved, as well as the current trace frame you are examining.
15801 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15802 the host.
15803
15804 @smallexample
15805 (@value{GDBP}) target ctf ctf.ctf
15806 (@value{GDBP}) tfind
15807 Found trace frame 0, tracepoint 2
15808 39 ++a; /* set tracepoint 1 here */
15809 (@value{GDBP}) tdump
15810 Data collected at tracepoint 2, trace frame 0:
15811 i = 0
15812 a = 0
15813 b = 1 '\001'
15814 c = @{"123", "456", "789", "123", "456", "789"@}
15815 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15816 (@value{GDBP}) p b
15817 $1 = 1
15818 @end smallexample
15819
15820 @end table
15821
15822 @node Overlays
15823 @chapter Debugging Programs That Use Overlays
15824 @cindex overlays
15825
15826 If your program is too large to fit completely in your target system's
15827 memory, you can sometimes use @dfn{overlays} to work around this
15828 problem. @value{GDBN} provides some support for debugging programs that
15829 use overlays.
15830
15831 @menu
15832 * How Overlays Work:: A general explanation of overlays.
15833 * Overlay Commands:: Managing overlays in @value{GDBN}.
15834 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15835 mapped by asking the inferior.
15836 * Overlay Sample Program:: A sample program using overlays.
15837 @end menu
15838
15839 @node How Overlays Work
15840 @section How Overlays Work
15841 @cindex mapped overlays
15842 @cindex unmapped overlays
15843 @cindex load address, overlay's
15844 @cindex mapped address
15845 @cindex overlay area
15846
15847 Suppose you have a computer whose instruction address space is only 64
15848 kilobytes long, but which has much more memory which can be accessed by
15849 other means: special instructions, segment registers, or memory
15850 management hardware, for example. Suppose further that you want to
15851 adapt a program which is larger than 64 kilobytes to run on this system.
15852
15853 One solution is to identify modules of your program which are relatively
15854 independent, and need not call each other directly; call these modules
15855 @dfn{overlays}. Separate the overlays from the main program, and place
15856 their machine code in the larger memory. Place your main program in
15857 instruction memory, but leave at least enough space there to hold the
15858 largest overlay as well.
15859
15860 Now, to call a function located in an overlay, you must first copy that
15861 overlay's machine code from the large memory into the space set aside
15862 for it in the instruction memory, and then jump to its entry point
15863 there.
15864
15865 @c NB: In the below the mapped area's size is greater or equal to the
15866 @c size of all overlays. This is intentional to remind the developer
15867 @c that overlays don't necessarily need to be the same size.
15868
15869 @smallexample
15870 @group
15871 Data Instruction Larger
15872 Address Space Address Space Address Space
15873 +-----------+ +-----------+ +-----------+
15874 | | | | | |
15875 +-----------+ +-----------+ +-----------+<-- overlay 1
15876 | program | | main | .----| overlay 1 | load address
15877 | variables | | program | | +-----------+
15878 | and heap | | | | | |
15879 +-----------+ | | | +-----------+<-- overlay 2
15880 | | +-----------+ | | | load address
15881 +-----------+ | | | .-| overlay 2 |
15882 | | | | | |
15883 mapped --->+-----------+ | | +-----------+
15884 address | | | | | |
15885 | overlay | <-' | | |
15886 | area | <---' +-----------+<-- overlay 3
15887 | | <---. | | load address
15888 +-----------+ `--| overlay 3 |
15889 | | | |
15890 +-----------+ | |
15891 +-----------+
15892 | |
15893 +-----------+
15894
15895 @anchor{A code overlay}A code overlay
15896 @end group
15897 @end smallexample
15898
15899 The diagram (@pxref{A code overlay}) shows a system with separate data
15900 and instruction address spaces. To map an overlay, the program copies
15901 its code from the larger address space to the instruction address space.
15902 Since the overlays shown here all use the same mapped address, only one
15903 may be mapped at a time. For a system with a single address space for
15904 data and instructions, the diagram would be similar, except that the
15905 program variables and heap would share an address space with the main
15906 program and the overlay area.
15907
15908 An overlay loaded into instruction memory and ready for use is called a
15909 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15910 instruction memory. An overlay not present (or only partially present)
15911 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15912 is its address in the larger memory. The mapped address is also called
15913 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15914 called the @dfn{load memory address}, or @dfn{LMA}.
15915
15916 Unfortunately, overlays are not a completely transparent way to adapt a
15917 program to limited instruction memory. They introduce a new set of
15918 global constraints you must keep in mind as you design your program:
15919
15920 @itemize @bullet
15921
15922 @item
15923 Before calling or returning to a function in an overlay, your program
15924 must make sure that overlay is actually mapped. Otherwise, the call or
15925 return will transfer control to the right address, but in the wrong
15926 overlay, and your program will probably crash.
15927
15928 @item
15929 If the process of mapping an overlay is expensive on your system, you
15930 will need to choose your overlays carefully to minimize their effect on
15931 your program's performance.
15932
15933 @item
15934 The executable file you load onto your system must contain each
15935 overlay's instructions, appearing at the overlay's load address, not its
15936 mapped address. However, each overlay's instructions must be relocated
15937 and its symbols defined as if the overlay were at its mapped address.
15938 You can use GNU linker scripts to specify different load and relocation
15939 addresses for pieces of your program; see @ref{Overlay Description,,,
15940 ld.info, Using ld: the GNU linker}.
15941
15942 @item
15943 The procedure for loading executable files onto your system must be able
15944 to load their contents into the larger address space as well as the
15945 instruction and data spaces.
15946
15947 @end itemize
15948
15949 The overlay system described above is rather simple, and could be
15950 improved in many ways:
15951
15952 @itemize @bullet
15953
15954 @item
15955 If your system has suitable bank switch registers or memory management
15956 hardware, you could use those facilities to make an overlay's load area
15957 contents simply appear at their mapped address in instruction space.
15958 This would probably be faster than copying the overlay to its mapped
15959 area in the usual way.
15960
15961 @item
15962 If your overlays are small enough, you could set aside more than one
15963 overlay area, and have more than one overlay mapped at a time.
15964
15965 @item
15966 You can use overlays to manage data, as well as instructions. In
15967 general, data overlays are even less transparent to your design than
15968 code overlays: whereas code overlays only require care when you call or
15969 return to functions, data overlays require care every time you access
15970 the data. Also, if you change the contents of a data overlay, you
15971 must copy its contents back out to its load address before you can copy a
15972 different data overlay into the same mapped area.
15973
15974 @end itemize
15975
15976
15977 @node Overlay Commands
15978 @section Overlay Commands
15979
15980 To use @value{GDBN}'s overlay support, each overlay in your program must
15981 correspond to a separate section of the executable file. The section's
15982 virtual memory address and load memory address must be the overlay's
15983 mapped and load addresses. Identifying overlays with sections allows
15984 @value{GDBN} to determine the appropriate address of a function or
15985 variable, depending on whether the overlay is mapped or not.
15986
15987 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15988 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15989
15990 @table @code
15991 @item overlay off
15992 @kindex overlay
15993 Disable @value{GDBN}'s overlay support. When overlay support is
15994 disabled, @value{GDBN} assumes that all functions and variables are
15995 always present at their mapped addresses. By default, @value{GDBN}'s
15996 overlay support is disabled.
15997
15998 @item overlay manual
15999 @cindex manual overlay debugging
16000 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
16001 relies on you to tell it which overlays are mapped, and which are not,
16002 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
16003 commands described below.
16004
16005 @item overlay map-overlay @var{overlay}
16006 @itemx overlay map @var{overlay}
16007 @cindex map an overlay
16008 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
16009 be the name of the object file section containing the overlay. When an
16010 overlay is mapped, @value{GDBN} assumes it can find the overlay's
16011 functions and variables at their mapped addresses. @value{GDBN} assumes
16012 that any other overlays whose mapped ranges overlap that of
16013 @var{overlay} are now unmapped.
16014
16015 @item overlay unmap-overlay @var{overlay}
16016 @itemx overlay unmap @var{overlay}
16017 @cindex unmap an overlay
16018 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
16019 must be the name of the object file section containing the overlay.
16020 When an overlay is unmapped, @value{GDBN} assumes it can find the
16021 overlay's functions and variables at their load addresses.
16022
16023 @item overlay auto
16024 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
16025 consults a data structure the overlay manager maintains in the inferior
16026 to see which overlays are mapped. For details, see @ref{Automatic
16027 Overlay Debugging}.
16028
16029 @item overlay load-target
16030 @itemx overlay load
16031 @cindex reloading the overlay table
16032 Re-read the overlay table from the inferior. Normally, @value{GDBN}
16033 re-reads the table @value{GDBN} automatically each time the inferior
16034 stops, so this command should only be necessary if you have changed the
16035 overlay mapping yourself using @value{GDBN}. This command is only
16036 useful when using automatic overlay debugging.
16037
16038 @item overlay list-overlays
16039 @itemx overlay list
16040 @cindex listing mapped overlays
16041 Display a list of the overlays currently mapped, along with their mapped
16042 addresses, load addresses, and sizes.
16043
16044 @end table
16045
16046 Normally, when @value{GDBN} prints a code address, it includes the name
16047 of the function the address falls in:
16048
16049 @smallexample
16050 (@value{GDBP}) print main
16051 $3 = @{int ()@} 0x11a0 <main>
16052 @end smallexample
16053 @noindent
16054 When overlay debugging is enabled, @value{GDBN} recognizes code in
16055 unmapped overlays, and prints the names of unmapped functions with
16056 asterisks around them. For example, if @code{foo} is a function in an
16057 unmapped overlay, @value{GDBN} prints it this way:
16058
16059 @smallexample
16060 (@value{GDBP}) overlay list
16061 No sections are mapped.
16062 (@value{GDBP}) print foo
16063 $5 = @{int (int)@} 0x100000 <*foo*>
16064 @end smallexample
16065 @noindent
16066 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
16067 name normally:
16068
16069 @smallexample
16070 (@value{GDBP}) overlay list
16071 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
16072 mapped at 0x1016 - 0x104a
16073 (@value{GDBP}) print foo
16074 $6 = @{int (int)@} 0x1016 <foo>
16075 @end smallexample
16076
16077 When overlay debugging is enabled, @value{GDBN} can find the correct
16078 address for functions and variables in an overlay, whether or not the
16079 overlay is mapped. This allows most @value{GDBN} commands, like
16080 @code{break} and @code{disassemble}, to work normally, even on unmapped
16081 code. However, @value{GDBN}'s breakpoint support has some limitations:
16082
16083 @itemize @bullet
16084 @item
16085 @cindex breakpoints in overlays
16086 @cindex overlays, setting breakpoints in
16087 You can set breakpoints in functions in unmapped overlays, as long as
16088 @value{GDBN} can write to the overlay at its load address.
16089 @item
16090 @value{GDBN} can not set hardware or simulator-based breakpoints in
16091 unmapped overlays. However, if you set a breakpoint at the end of your
16092 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
16093 you are using manual overlay management), @value{GDBN} will re-set its
16094 breakpoints properly.
16095 @end itemize
16096
16097
16098 @node Automatic Overlay Debugging
16099 @section Automatic Overlay Debugging
16100 @cindex automatic overlay debugging
16101
16102 @value{GDBN} can automatically track which overlays are mapped and which
16103 are not, given some simple co-operation from the overlay manager in the
16104 inferior. If you enable automatic overlay debugging with the
16105 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
16106 looks in the inferior's memory for certain variables describing the
16107 current state of the overlays.
16108
16109 Here are the variables your overlay manager must define to support
16110 @value{GDBN}'s automatic overlay debugging:
16111
16112 @table @asis
16113
16114 @item @code{_ovly_table}:
16115 This variable must be an array of the following structures:
16116
16117 @smallexample
16118 struct
16119 @{
16120 /* The overlay's mapped address. */
16121 unsigned long vma;
16122
16123 /* The size of the overlay, in bytes. */
16124 unsigned long size;
16125
16126 /* The overlay's load address. */
16127 unsigned long lma;
16128
16129 /* Non-zero if the overlay is currently mapped;
16130 zero otherwise. */
16131 unsigned long mapped;
16132 @}
16133 @end smallexample
16134
16135 @item @code{_novlys}:
16136 This variable must be a four-byte signed integer, holding the total
16137 number of elements in @code{_ovly_table}.
16138
16139 @end table
16140
16141 To decide whether a particular overlay is mapped or not, @value{GDBN}
16142 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
16143 @code{lma} members equal the VMA and LMA of the overlay's section in the
16144 executable file. When @value{GDBN} finds a matching entry, it consults
16145 the entry's @code{mapped} member to determine whether the overlay is
16146 currently mapped.
16147
16148 In addition, your overlay manager may define a function called
16149 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
16150 will silently set a breakpoint there. If the overlay manager then
16151 calls this function whenever it has changed the overlay table, this
16152 will enable @value{GDBN} to accurately keep track of which overlays
16153 are in program memory, and update any breakpoints that may be set
16154 in overlays. This will allow breakpoints to work even if the
16155 overlays are kept in ROM or other non-writable memory while they
16156 are not being executed.
16157
16158 @node Overlay Sample Program
16159 @section Overlay Sample Program
16160 @cindex overlay example program
16161
16162 When linking a program which uses overlays, you must place the overlays
16163 at their load addresses, while relocating them to run at their mapped
16164 addresses. To do this, you must write a linker script (@pxref{Overlay
16165 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
16166 since linker scripts are specific to a particular host system, target
16167 architecture, and target memory layout, this manual cannot provide
16168 portable sample code demonstrating @value{GDBN}'s overlay support.
16169
16170 However, the @value{GDBN} source distribution does contain an overlaid
16171 program, with linker scripts for a few systems, as part of its test
16172 suite. The program consists of the following files from
16173 @file{gdb/testsuite/gdb.base}:
16174
16175 @table @file
16176 @item overlays.c
16177 The main program file.
16178 @item ovlymgr.c
16179 A simple overlay manager, used by @file{overlays.c}.
16180 @item foo.c
16181 @itemx bar.c
16182 @itemx baz.c
16183 @itemx grbx.c
16184 Overlay modules, loaded and used by @file{overlays.c}.
16185 @item d10v.ld
16186 @itemx m32r.ld
16187 Linker scripts for linking the test program on the @code{d10v-elf}
16188 and @code{m32r-elf} targets.
16189 @end table
16190
16191 You can build the test program using the @code{d10v-elf} GCC
16192 cross-compiler like this:
16193
16194 @smallexample
16195 $ d10v-elf-gcc -g -c overlays.c
16196 $ d10v-elf-gcc -g -c ovlymgr.c
16197 $ d10v-elf-gcc -g -c foo.c
16198 $ d10v-elf-gcc -g -c bar.c
16199 $ d10v-elf-gcc -g -c baz.c
16200 $ d10v-elf-gcc -g -c grbx.c
16201 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
16202 baz.o grbx.o -Wl,-Td10v.ld -o overlays
16203 @end smallexample
16204
16205 The build process is identical for any other architecture, except that
16206 you must substitute the appropriate compiler and linker script for the
16207 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
16208
16209
16210 @node Languages
16211 @chapter Using @value{GDBN} with Different Languages
16212 @cindex languages
16213
16214 Although programming languages generally have common aspects, they are
16215 rarely expressed in the same manner. For instance, in ANSI C,
16216 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
16217 Modula-2, it is accomplished by @code{p^}. Values can also be
16218 represented (and displayed) differently. Hex numbers in C appear as
16219 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
16220
16221 @cindex working language
16222 Language-specific information is built into @value{GDBN} for some languages,
16223 allowing you to express operations like the above in your program's
16224 native language, and allowing @value{GDBN} to output values in a manner
16225 consistent with the syntax of your program's native language. The
16226 language you use to build expressions is called the @dfn{working
16227 language}.
16228
16229 @menu
16230 * Setting:: Switching between source languages
16231 * Show:: Displaying the language
16232 * Checks:: Type and range checks
16233 * Supported Languages:: Supported languages
16234 * Unsupported Languages:: Unsupported languages
16235 @end menu
16236
16237 @node Setting
16238 @section Switching Between Source Languages
16239
16240 There are two ways to control the working language---either have @value{GDBN}
16241 set it automatically, or select it manually yourself. You can use the
16242 @code{set language} command for either purpose. On startup, @value{GDBN}
16243 defaults to setting the language automatically. The working language is
16244 used to determine how expressions you type are interpreted, how values
16245 are printed, etc.
16246
16247 In addition to the working language, every source file that
16248 @value{GDBN} knows about has its own working language. For some object
16249 file formats, the compiler might indicate which language a particular
16250 source file is in. However, most of the time @value{GDBN} infers the
16251 language from the name of the file. The language of a source file
16252 controls whether C@t{++} names are demangled---this way @code{backtrace} can
16253 show each frame appropriately for its own language. There is no way to
16254 set the language of a source file from within @value{GDBN}, but you can
16255 set the language associated with a filename extension. @xref{Show, ,
16256 Displaying the Language}.
16257
16258 This is most commonly a problem when you use a program, such
16259 as @code{cfront} or @code{f2c}, that generates C but is written in
16260 another language. In that case, make the
16261 program use @code{#line} directives in its C output; that way
16262 @value{GDBN} will know the correct language of the source code of the original
16263 program, and will display that source code, not the generated C code.
16264
16265 @menu
16266 * Filenames:: Filename extensions and languages.
16267 * Manually:: Setting the working language manually
16268 * Automatically:: Having @value{GDBN} infer the source language
16269 @end menu
16270
16271 @node Filenames
16272 @subsection List of Filename Extensions and Languages
16273
16274 If a source file name ends in one of the following extensions, then
16275 @value{GDBN} infers that its language is the one indicated.
16276
16277 @table @file
16278 @item .ada
16279 @itemx .ads
16280 @itemx .adb
16281 @itemx .a
16282 Ada source file.
16283
16284 @item .c
16285 C source file
16286
16287 @item .C
16288 @itemx .cc
16289 @itemx .cp
16290 @itemx .cpp
16291 @itemx .cxx
16292 @itemx .c++
16293 C@t{++} source file
16294
16295 @item .d
16296 D source file
16297
16298 @item .m
16299 Objective-C source file
16300
16301 @item .f
16302 @itemx .F
16303 Fortran source file
16304
16305 @item .mod
16306 Modula-2 source file
16307
16308 @item .s
16309 @itemx .S
16310 Assembler source file. This actually behaves almost like C, but
16311 @value{GDBN} does not skip over function prologues when stepping.
16312 @end table
16313
16314 In addition, you may set the language associated with a filename
16315 extension. @xref{Show, , Displaying the Language}.
16316
16317 @node Manually
16318 @subsection Setting the Working Language
16319
16320 If you allow @value{GDBN} to set the language automatically,
16321 expressions are interpreted the same way in your debugging session and
16322 your program.
16323
16324 @kindex set language
16325 If you wish, you may set the language manually. To do this, issue the
16326 command @samp{set language @var{lang}}, where @var{lang} is the name of
16327 a language, such as
16328 @code{c} or @code{modula-2}.
16329 For a list of the supported languages, type @samp{set language}.
16330
16331 Setting the language manually prevents @value{GDBN} from updating the working
16332 language automatically. This can lead to confusion if you try
16333 to debug a program when the working language is not the same as the
16334 source language, when an expression is acceptable to both
16335 languages---but means different things. For instance, if the current
16336 source file were written in C, and @value{GDBN} was parsing Modula-2, a
16337 command such as:
16338
16339 @smallexample
16340 print a = b + c
16341 @end smallexample
16342
16343 @noindent
16344 might not have the effect you intended. In C, this means to add
16345 @code{b} and @code{c} and place the result in @code{a}. The result
16346 printed would be the value of @code{a}. In Modula-2, this means to compare
16347 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
16348
16349 @node Automatically
16350 @subsection Having @value{GDBN} Infer the Source Language
16351
16352 To have @value{GDBN} set the working language automatically, use
16353 @samp{set language local} or @samp{set language auto}. @value{GDBN}
16354 then infers the working language. That is, when your program stops in a
16355 frame (usually by encountering a breakpoint), @value{GDBN} sets the
16356 working language to the language recorded for the function in that
16357 frame. If the language for a frame is unknown (that is, if the function
16358 or block corresponding to the frame was defined in a source file that
16359 does not have a recognized extension), the current working language is
16360 not changed, and @value{GDBN} issues a warning.
16361
16362 This may not seem necessary for most programs, which are written
16363 entirely in one source language. However, program modules and libraries
16364 written in one source language can be used by a main program written in
16365 a different source language. Using @samp{set language auto} in this
16366 case frees you from having to set the working language manually.
16367
16368 @node Show
16369 @section Displaying the Language
16370
16371 The following commands help you find out which language is the
16372 working language, and also what language source files were written in.
16373
16374 @table @code
16375 @item show language
16376 @anchor{show language}
16377 @kindex show language
16378 Display the current working language. This is the
16379 language you can use with commands such as @code{print} to
16380 build and compute expressions that may involve variables in your program.
16381
16382 @item info frame
16383 @kindex info frame@r{, show the source language}
16384 Display the source language for this frame. This language becomes the
16385 working language if you use an identifier from this frame.
16386 @xref{Frame Info, ,Information about a Frame}, to identify the other
16387 information listed here.
16388
16389 @item info source
16390 @kindex info source@r{, show the source language}
16391 Display the source language of this source file.
16392 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16393 information listed here.
16394 @end table
16395
16396 In unusual circumstances, you may have source files with extensions
16397 not in the standard list. You can then set the extension associated
16398 with a language explicitly:
16399
16400 @table @code
16401 @item set extension-language @var{ext} @var{language}
16402 @kindex set extension-language
16403 Tell @value{GDBN} that source files with extension @var{ext} are to be
16404 assumed as written in the source language @var{language}.
16405
16406 @item info extensions
16407 @kindex info extensions
16408 List all the filename extensions and the associated languages.
16409 @end table
16410
16411 @node Checks
16412 @section Type and Range Checking
16413
16414 Some languages are designed to guard you against making seemingly common
16415 errors through a series of compile- and run-time checks. These include
16416 checking the type of arguments to functions and operators and making
16417 sure mathematical overflows are caught at run time. Checks such as
16418 these help to ensure a program's correctness once it has been compiled
16419 by eliminating type mismatches and providing active checks for range
16420 errors when your program is running.
16421
16422 By default @value{GDBN} checks for these errors according to the
16423 rules of the current source language. Although @value{GDBN} does not check
16424 the statements in your program, it can check expressions entered directly
16425 into @value{GDBN} for evaluation via the @code{print} command, for example.
16426
16427 @menu
16428 * Type Checking:: An overview of type checking
16429 * Range Checking:: An overview of range checking
16430 @end menu
16431
16432 @cindex type checking
16433 @cindex checks, type
16434 @node Type Checking
16435 @subsection An Overview of Type Checking
16436
16437 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16438 arguments to operators and functions have to be of the correct type,
16439 otherwise an error occurs. These checks prevent type mismatch
16440 errors from ever causing any run-time problems. For example,
16441
16442 @smallexample
16443 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16444
16445 (@value{GDBP}) print obj.my_method (0)
16446 $1 = 2
16447 @exdent but
16448 (@value{GDBP}) print obj.my_method (0x1234)
16449 Cannot resolve method klass::my_method to any overloaded instance
16450 @end smallexample
16451
16452 The second example fails because in C@t{++} the integer constant
16453 @samp{0x1234} is not type-compatible with the pointer parameter type.
16454
16455 For the expressions you use in @value{GDBN} commands, you can tell
16456 @value{GDBN} to not enforce strict type checking or
16457 to treat any mismatches as errors and abandon the expression;
16458 When type checking is disabled, @value{GDBN} successfully evaluates
16459 expressions like the second example above.
16460
16461 Even if type checking is off, there may be other reasons
16462 related to type that prevent @value{GDBN} from evaluating an expression.
16463 For instance, @value{GDBN} does not know how to add an @code{int} and
16464 a @code{struct foo}. These particular type errors have nothing to do
16465 with the language in use and usually arise from expressions which make
16466 little sense to evaluate anyway.
16467
16468 @value{GDBN} provides some additional commands for controlling type checking:
16469
16470 @kindex set check type
16471 @kindex show check type
16472 @table @code
16473 @item set check type on
16474 @itemx set check type off
16475 Set strict type checking on or off. If any type mismatches occur in
16476 evaluating an expression while type checking is on, @value{GDBN} prints a
16477 message and aborts evaluation of the expression.
16478
16479 @item show check type
16480 Show the current setting of type checking and whether @value{GDBN}
16481 is enforcing strict type checking rules.
16482 @end table
16483
16484 @cindex range checking
16485 @cindex checks, range
16486 @node Range Checking
16487 @subsection An Overview of Range Checking
16488
16489 In some languages (such as Modula-2), it is an error to exceed the
16490 bounds of a type; this is enforced with run-time checks. Such range
16491 checking is meant to ensure program correctness by making sure
16492 computations do not overflow, or indices on an array element access do
16493 not exceed the bounds of the array.
16494
16495 For expressions you use in @value{GDBN} commands, you can tell
16496 @value{GDBN} to treat range errors in one of three ways: ignore them,
16497 always treat them as errors and abandon the expression, or issue
16498 warnings but evaluate the expression anyway.
16499
16500 A range error can result from numerical overflow, from exceeding an
16501 array index bound, or when you type a constant that is not a member
16502 of any type. Some languages, however, do not treat overflows as an
16503 error. In many implementations of C, mathematical overflow causes the
16504 result to ``wrap around'' to lower values---for example, if @var{m} is
16505 the largest integer value, and @var{s} is the smallest, then
16506
16507 @smallexample
16508 @var{m} + 1 @result{} @var{s}
16509 @end smallexample
16510
16511 This, too, is specific to individual languages, and in some cases
16512 specific to individual compilers or machines. @xref{Supported Languages, ,
16513 Supported Languages}, for further details on specific languages.
16514
16515 @value{GDBN} provides some additional commands for controlling the range checker:
16516
16517 @kindex set check range
16518 @kindex show check range
16519 @table @code
16520 @item set check range auto
16521 Set range checking on or off based on the current working language.
16522 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16523 each language.
16524
16525 @item set check range on
16526 @itemx set check range off
16527 Set range checking on or off, overriding the default setting for the
16528 current working language. A warning is issued if the setting does not
16529 match the language default. If a range error occurs and range checking is on,
16530 then a message is printed and evaluation of the expression is aborted.
16531
16532 @item set check range warn
16533 Output messages when the @value{GDBN} range checker detects a range error,
16534 but attempt to evaluate the expression anyway. Evaluating the
16535 expression may still be impossible for other reasons, such as accessing
16536 memory that the process does not own (a typical example from many Unix
16537 systems).
16538
16539 @item show check range
16540 Show the current setting of the range checker, and whether or not it is
16541 being set automatically by @value{GDBN}.
16542 @end table
16543
16544 @node Supported Languages
16545 @section Supported Languages
16546
16547 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16548 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16549 @c This is false ...
16550 Some @value{GDBN} features may be used in expressions regardless of the
16551 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16552 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16553 ,Expressions}) can be used with the constructs of any supported
16554 language.
16555
16556 The following sections detail to what degree each source language is
16557 supported by @value{GDBN}. These sections are not meant to be language
16558 tutorials or references, but serve only as a reference guide to what the
16559 @value{GDBN} expression parser accepts, and what input and output
16560 formats should look like for different languages. There are many good
16561 books written on each of these languages; please look to these for a
16562 language reference or tutorial.
16563
16564 @menu
16565 * C:: C and C@t{++}
16566 * D:: D
16567 * Go:: Go
16568 * Objective-C:: Objective-C
16569 * OpenCL C:: OpenCL C
16570 * Fortran:: Fortran
16571 * Pascal:: Pascal
16572 * Rust:: Rust
16573 * Modula-2:: Modula-2
16574 * Ada:: Ada
16575 @end menu
16576
16577 @node C
16578 @subsection C and C@t{++}
16579
16580 @cindex C and C@t{++}
16581 @cindex expressions in C or C@t{++}
16582
16583 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16584 to both languages. Whenever this is the case, we discuss those languages
16585 together.
16586
16587 @cindex C@t{++}
16588 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16589 @cindex @sc{gnu} C@t{++}
16590 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16591 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16592 effectively, you must compile your C@t{++} programs with a supported
16593 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16594 compiler (@code{aCC}).
16595
16596 @menu
16597 * C Operators:: C and C@t{++} operators
16598 * C Constants:: C and C@t{++} constants
16599 * C Plus Plus Expressions:: C@t{++} expressions
16600 * C Defaults:: Default settings for C and C@t{++}
16601 * C Checks:: C and C@t{++} type and range checks
16602 * Debugging C:: @value{GDBN} and C
16603 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16604 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16605 @end menu
16606
16607 @node C Operators
16608 @subsubsection C and C@t{++} Operators
16609
16610 @cindex C and C@t{++} operators
16611
16612 Operators must be defined on values of specific types. For instance,
16613 @code{+} is defined on numbers, but not on structures. Operators are
16614 often defined on groups of types.
16615
16616 For the purposes of C and C@t{++}, the following definitions hold:
16617
16618 @itemize @bullet
16619
16620 @item
16621 @emph{Integral types} include @code{int} with any of its storage-class
16622 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16623
16624 @item
16625 @emph{Floating-point types} include @code{float}, @code{double}, and
16626 @code{long double} (if supported by the target platform).
16627
16628 @item
16629 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16630
16631 @item
16632 @emph{Scalar types} include all of the above.
16633
16634 @end itemize
16635
16636 @noindent
16637 The following operators are supported. They are listed here
16638 in order of increasing precedence:
16639
16640 @table @code
16641 @item ,
16642 The comma or sequencing operator. Expressions in a comma-separated list
16643 are evaluated from left to right, with the result of the entire
16644 expression being the last expression evaluated.
16645
16646 @item =
16647 Assignment. The value of an assignment expression is the value
16648 assigned. Defined on scalar types.
16649
16650 @item @var{op}=
16651 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16652 and translated to @w{@code{@var{a} = @var{a op b}}}.
16653 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16654 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16655 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16656
16657 @item ?:
16658 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16659 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16660 should be of an integral type.
16661
16662 @item ||
16663 Logical @sc{or}. Defined on integral types.
16664
16665 @item &&
16666 Logical @sc{and}. Defined on integral types.
16667
16668 @item |
16669 Bitwise @sc{or}. Defined on integral types.
16670
16671 @item ^
16672 Bitwise exclusive-@sc{or}. Defined on integral types.
16673
16674 @item &
16675 Bitwise @sc{and}. Defined on integral types.
16676
16677 @item ==@r{, }!=
16678 Equality and inequality. Defined on scalar types. The value of these
16679 expressions is 0 for false and non-zero for true.
16680
16681 @item <@r{, }>@r{, }<=@r{, }>=
16682 Less than, greater than, less than or equal, greater than or equal.
16683 Defined on scalar types. The value of these expressions is 0 for false
16684 and non-zero for true.
16685
16686 @item <<@r{, }>>
16687 left shift, and right shift. Defined on integral types.
16688
16689 @item @@
16690 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16691
16692 @item +@r{, }-
16693 Addition and subtraction. Defined on integral types, floating-point types and
16694 pointer types.
16695
16696 @item *@r{, }/@r{, }%
16697 Multiplication, division, and modulus. Multiplication and division are
16698 defined on integral and floating-point types. Modulus is defined on
16699 integral types.
16700
16701 @item ++@r{, }--
16702 Increment and decrement. When appearing before a variable, the
16703 operation is performed before the variable is used in an expression;
16704 when appearing after it, the variable's value is used before the
16705 operation takes place.
16706
16707 @item *
16708 Pointer dereferencing. Defined on pointer types. Same precedence as
16709 @code{++}.
16710
16711 @item &
16712 Address operator. Defined on variables. Same precedence as @code{++}.
16713
16714 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16715 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16716 to examine the address
16717 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16718 stored.
16719
16720 @item -
16721 Negative. Defined on integral and floating-point types. Same
16722 precedence as @code{++}.
16723
16724 @item !
16725 Logical negation. Defined on integral types. Same precedence as
16726 @code{++}.
16727
16728 @item ~
16729 Bitwise complement operator. Defined on integral types. Same precedence as
16730 @code{++}.
16731
16732
16733 @item .@r{, }->
16734 Structure member, and pointer-to-structure member. For convenience,
16735 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16736 pointer based on the stored type information.
16737 Defined on @code{struct} and @code{union} data.
16738
16739 @item .*@r{, }->*
16740 Dereferences of pointers to members.
16741
16742 @item []
16743 Array indexing. @code{@var{a}[@var{i}]} is defined as
16744 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16745
16746 @item ()
16747 Function parameter list. Same precedence as @code{->}.
16748
16749 @item ::
16750 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16751 and @code{class} types.
16752
16753 @item ::
16754 Doubled colons also represent the @value{GDBN} scope operator
16755 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16756 above.
16757 @end table
16758
16759 If an operator is redefined in the user code, @value{GDBN} usually
16760 attempts to invoke the redefined version instead of using the operator's
16761 predefined meaning.
16762
16763 @node C Constants
16764 @subsubsection C and C@t{++} Constants
16765
16766 @cindex C and C@t{++} constants
16767
16768 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16769 following ways:
16770
16771 @itemize @bullet
16772 @item
16773 Integer constants are a sequence of digits. Octal constants are
16774 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16775 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16776 @samp{l}, specifying that the constant should be treated as a
16777 @code{long} value.
16778
16779 @item
16780 Floating point constants are a sequence of digits, followed by a decimal
16781 point, followed by a sequence of digits, and optionally followed by an
16782 exponent. An exponent is of the form:
16783 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16784 sequence of digits. The @samp{+} is optional for positive exponents.
16785 A floating-point constant may also end with a letter @samp{f} or
16786 @samp{F}, specifying that the constant should be treated as being of
16787 the @code{float} (as opposed to the default @code{double}) type; or with
16788 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16789 constant.
16790
16791 @item
16792 Enumerated constants consist of enumerated identifiers, or their
16793 integral equivalents.
16794
16795 @item
16796 Character constants are a single character surrounded by single quotes
16797 (@code{'}), or a number---the ordinal value of the corresponding character
16798 (usually its @sc{ascii} value). Within quotes, the single character may
16799 be represented by a letter or by @dfn{escape sequences}, which are of
16800 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16801 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16802 @samp{@var{x}} is a predefined special character---for example,
16803 @samp{\n} for newline.
16804
16805 Wide character constants can be written by prefixing a character
16806 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16807 form of @samp{x}. The target wide character set is used when
16808 computing the value of this constant (@pxref{Character Sets}).
16809
16810 @item
16811 String constants are a sequence of character constants surrounded by
16812 double quotes (@code{"}). Any valid character constant (as described
16813 above) may appear. Double quotes within the string must be preceded by
16814 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16815 characters.
16816
16817 Wide string constants can be written by prefixing a string constant
16818 with @samp{L}, as in C. The target wide character set is used when
16819 computing the value of this constant (@pxref{Character Sets}).
16820
16821 @item
16822 Pointer constants are an integral value. You can also write pointers
16823 to constants using the C operator @samp{&}.
16824
16825 @item
16826 Array constants are comma-separated lists surrounded by braces @samp{@{}
16827 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16828 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16829 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16830 @end itemize
16831
16832 @node C Plus Plus Expressions
16833 @subsubsection C@t{++} Expressions
16834
16835 @cindex expressions in C@t{++}
16836 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16837
16838 @cindex debugging C@t{++} programs
16839 @cindex C@t{++} compilers
16840 @cindex debug formats and C@t{++}
16841 @cindex @value{NGCC} and C@t{++}
16842 @quotation
16843 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16844 the proper compiler and the proper debug format. Currently,
16845 @value{GDBN} works best when debugging C@t{++} code that is compiled
16846 with the most recent version of @value{NGCC} possible. The DWARF
16847 debugging format is preferred; @value{NGCC} defaults to this on most
16848 popular platforms. Other compilers and/or debug formats are likely to
16849 work badly or not at all when using @value{GDBN} to debug C@t{++}
16850 code. @xref{Compilation}.
16851 @end quotation
16852
16853 @enumerate
16854
16855 @cindex member functions
16856 @item
16857 Member function calls are allowed; you can use expressions like
16858
16859 @smallexample
16860 count = aml->GetOriginal(x, y)
16861 @end smallexample
16862
16863 @vindex this@r{, inside C@t{++} member functions}
16864 @cindex namespace in C@t{++}
16865 @item
16866 While a member function is active (in the selected stack frame), your
16867 expressions have the same namespace available as the member function;
16868 that is, @value{GDBN} allows implicit references to the class instance
16869 pointer @code{this} following the same rules as C@t{++}. @code{using}
16870 declarations in the current scope are also respected by @value{GDBN}.
16871
16872 @cindex call overloaded functions
16873 @cindex overloaded functions, calling
16874 @cindex type conversions in C@t{++}
16875 @item
16876 You can call overloaded functions; @value{GDBN} resolves the function
16877 call to the right definition, with some restrictions. @value{GDBN} does not
16878 perform overload resolution involving user-defined type conversions,
16879 calls to constructors, or instantiations of templates that do not exist
16880 in the program. It also cannot handle ellipsis argument lists or
16881 default arguments.
16882
16883 It does perform integral conversions and promotions, floating-point
16884 promotions, arithmetic conversions, pointer conversions, conversions of
16885 class objects to base classes, and standard conversions such as those of
16886 functions or arrays to pointers; it requires an exact match on the
16887 number of function arguments.
16888
16889 Overload resolution is always performed, unless you have specified
16890 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16891 ,@value{GDBN} Features for C@t{++}}.
16892
16893 You must specify @code{set overload-resolution off} in order to use an
16894 explicit function signature to call an overloaded function, as in
16895 @smallexample
16896 p 'foo(char,int)'('x', 13)
16897 @end smallexample
16898
16899 The @value{GDBN} command-completion facility can simplify this;
16900 see @ref{Completion, ,Command Completion}.
16901
16902 @cindex reference declarations
16903 @item
16904 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16905 references; you can use them in expressions just as you do in C@t{++}
16906 source---they are automatically dereferenced.
16907
16908 In the parameter list shown when @value{GDBN} displays a frame, the values of
16909 reference variables are not displayed (unlike other variables); this
16910 avoids clutter, since references are often used for large structures.
16911 The @emph{address} of a reference variable is always shown, unless
16912 you have specified @samp{set print address off}.
16913
16914 @item
16915 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16916 expressions can use it just as expressions in your program do. Since
16917 one scope may be defined in another, you can use @code{::} repeatedly if
16918 necessary, for example in an expression like
16919 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16920 resolving name scope by reference to source files, in both C and C@t{++}
16921 debugging (@pxref{Variables, ,Program Variables}).
16922
16923 @item
16924 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16925 specification.
16926 @end enumerate
16927
16928 @node C Defaults
16929 @subsubsection C and C@t{++} Defaults
16930
16931 @cindex C and C@t{++} defaults
16932
16933 If you allow @value{GDBN} to set range checking automatically, it
16934 defaults to @code{off} whenever the working language changes to
16935 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16936 selects the working language.
16937
16938 If you allow @value{GDBN} to set the language automatically, it
16939 recognizes source files whose names end with @file{.c}, @file{.C}, or
16940 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16941 these files, it sets the working language to C or C@t{++}.
16942 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16943 for further details.
16944
16945 @node C Checks
16946 @subsubsection C and C@t{++} Type and Range Checks
16947
16948 @cindex C and C@t{++} checks
16949
16950 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16951 checking is used. However, if you turn type checking off, @value{GDBN}
16952 will allow certain non-standard conversions, such as promoting integer
16953 constants to pointers.
16954
16955 Range checking, if turned on, is done on mathematical operations. Array
16956 indices are not checked, since they are often used to index a pointer
16957 that is not itself an array.
16958
16959 @node Debugging C
16960 @subsubsection @value{GDBN} and C
16961
16962 The @code{set print union} and @code{show print union} commands apply to
16963 the @code{union} type. When set to @samp{on}, any @code{union} that is
16964 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16965 appears as @samp{@{...@}}.
16966
16967 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16968 with pointers and a memory allocation function. @xref{Expressions,
16969 ,Expressions}.
16970
16971 @node Debugging C Plus Plus
16972 @subsubsection @value{GDBN} Features for C@t{++}
16973
16974 @cindex commands for C@t{++}
16975
16976 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16977 designed specifically for use with C@t{++}. Here is a summary:
16978
16979 @table @code
16980 @cindex break in overloaded functions
16981 @item @r{breakpoint menus}
16982 When you want a breakpoint in a function whose name is overloaded,
16983 @value{GDBN} has the capability to display a menu of possible breakpoint
16984 locations to help you specify which function definition you want.
16985 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16986
16987 @cindex overloading in C@t{++}
16988 @item rbreak @var{regex}
16989 Setting breakpoints using regular expressions is helpful for setting
16990 breakpoints on overloaded functions that are not members of any special
16991 classes.
16992 @xref{Set Breaks, ,Setting Breakpoints}.
16993
16994 @cindex C@t{++} exception handling
16995 @item catch throw
16996 @itemx catch rethrow
16997 @itemx catch catch
16998 Debug C@t{++} exception handling using these commands. @xref{Set
16999 Catchpoints, , Setting Catchpoints}.
17000
17001 @cindex inheritance
17002 @item ptype @var{typename}
17003 Print inheritance relationships as well as other information for type
17004 @var{typename}.
17005 @xref{Symbols, ,Examining the Symbol Table}.
17006
17007 @item info vtbl @var{expression}.
17008 The @code{info vtbl} command can be used to display the virtual
17009 method tables of the object computed by @var{expression}. This shows
17010 one entry per virtual table; there may be multiple virtual tables when
17011 multiple inheritance is in use.
17012
17013 @cindex C@t{++} demangling
17014 @item demangle @var{name}
17015 Demangle @var{name}.
17016 @xref{Symbols}, for a more complete description of the @code{demangle} command.
17017
17018 @cindex C@t{++} symbol display
17019 @item set print demangle
17020 @itemx show print demangle
17021 @itemx set print asm-demangle
17022 @itemx show print asm-demangle
17023 Control whether C@t{++} symbols display in their source form, both when
17024 displaying code as C@t{++} source and when displaying disassemblies.
17025 @xref{Print Settings, ,Print Settings}.
17026
17027 @item set print object
17028 @itemx show print object
17029 Choose whether to print derived (actual) or declared types of objects.
17030 @xref{Print Settings, ,Print Settings}.
17031
17032 @item set print vtbl
17033 @itemx show print vtbl
17034 Control the format for printing virtual function tables.
17035 @xref{Print Settings, ,Print Settings}.
17036 (The @code{vtbl} commands do not work on programs compiled with the HP
17037 ANSI C@t{++} compiler (@code{aCC}).)
17038
17039 @kindex set overload-resolution
17040 @cindex overloaded functions, overload resolution
17041 @item set overload-resolution on
17042 Enable overload resolution for C@t{++} expression evaluation. The default
17043 is on. For overloaded functions, @value{GDBN} evaluates the arguments
17044 and searches for a function whose signature matches the argument types,
17045 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
17046 Expressions, ,C@t{++} Expressions}, for details).
17047 If it cannot find a match, it emits a message.
17048
17049 @item set overload-resolution off
17050 Disable overload resolution for C@t{++} expression evaluation. For
17051 overloaded functions that are not class member functions, @value{GDBN}
17052 chooses the first function of the specified name that it finds in the
17053 symbol table, whether or not its arguments are of the correct type. For
17054 overloaded functions that are class member functions, @value{GDBN}
17055 searches for a function whose signature @emph{exactly} matches the
17056 argument types.
17057
17058 @kindex show overload-resolution
17059 @item show overload-resolution
17060 Show the current setting of overload resolution.
17061
17062 @item @r{Overloaded symbol names}
17063 You can specify a particular definition of an overloaded symbol, using
17064 the same notation that is used to declare such symbols in C@t{++}: type
17065 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
17066 also use the @value{GDBN} command-line word completion facilities to list the
17067 available choices, or to finish the type list for you.
17068 @xref{Completion,, Command Completion}, for details on how to do this.
17069
17070 @item @r{Breakpoints in template functions}
17071
17072 Similar to how overloaded symbols are handled, @value{GDBN} will ignore
17073 template parameter lists when it encounters a symbol which includes a
17074 C@t{++} template. This permits setting breakpoints on families of template functions
17075 or functions whose parameters include template types.
17076
17077 The @kbd{-qualified} flag may be used to override this behavior, causing
17078 @value{GDBN} to search for a specific function or type.
17079
17080 The @value{GDBN} command-line word completion facility also understands
17081 template parameters and may be used to list available choices or finish
17082 template parameter lists for you. @xref{Completion,, Command Completion}, for
17083 details on how to do this.
17084
17085 @item @r{Breakpoints in functions with ABI tags}
17086
17087 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
17088 correspond to changes in the ABI of a type, function, or variable that
17089 would not otherwise be reflected in a mangled name. See
17090 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
17091 for more detail.
17092
17093 The ABI tags are visible in C@t{++} demangled names. For example, a
17094 function that returns a std::string:
17095
17096 @smallexample
17097 std::string function(int);
17098 @end smallexample
17099
17100 @noindent
17101 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
17102 tag, and @value{GDBN} displays the symbol like this:
17103
17104 @smallexample
17105 function[abi:cxx11](int)
17106 @end smallexample
17107
17108 You can set a breakpoint on such functions simply as if they had no
17109 tag. For example:
17110
17111 @smallexample
17112 (gdb) b function(int)
17113 Breakpoint 2 at 0x40060d: file main.cc, line 10.
17114 (gdb) info breakpoints
17115 Num Type Disp Enb Address What
17116 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
17117 at main.cc:10
17118 @end smallexample
17119
17120 On the rare occasion you need to disambiguate between different ABI
17121 tags, you can do so by simply including the ABI tag in the function
17122 name, like:
17123
17124 @smallexample
17125 (@value{GDBP}) b ambiguous[abi:other_tag](int)
17126 @end smallexample
17127 @end table
17128
17129 @node Decimal Floating Point
17130 @subsubsection Decimal Floating Point format
17131 @cindex decimal floating point format
17132
17133 @value{GDBN} can examine, set and perform computations with numbers in
17134 decimal floating point format, which in the C language correspond to the
17135 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
17136 specified by the extension to support decimal floating-point arithmetic.
17137
17138 There are two encodings in use, depending on the architecture: BID (Binary
17139 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
17140 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
17141 configured target.
17142
17143 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
17144 to manipulate decimal floating point numbers, it is not possible to convert
17145 (using a cast, for example) integers wider than 32-bit to decimal float.
17146
17147 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
17148 point computations, error checking in decimal float operations ignores
17149 underflow, overflow and divide by zero exceptions.
17150
17151 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
17152 to inspect @code{_Decimal128} values stored in floating point registers.
17153 See @ref{PowerPC,,PowerPC} for more details.
17154
17155 @node D
17156 @subsection D
17157
17158 @cindex D
17159 @value{GDBN} can be used to debug programs written in D and compiled with
17160 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
17161 specific feature --- dynamic arrays.
17162
17163 @node Go
17164 @subsection Go
17165
17166 @cindex Go (programming language)
17167 @value{GDBN} can be used to debug programs written in Go and compiled with
17168 @file{gccgo} or @file{6g} compilers.
17169
17170 Here is a summary of the Go-specific features and restrictions:
17171
17172 @table @code
17173 @cindex current Go package
17174 @item The current Go package
17175 The name of the current package does not need to be specified when
17176 specifying global variables and functions.
17177
17178 For example, given the program:
17179
17180 @example
17181 package main
17182 var myglob = "Shall we?"
17183 func main () @{
17184 // ...
17185 @}
17186 @end example
17187
17188 When stopped inside @code{main} either of these work:
17189
17190 @example
17191 (gdb) p myglob
17192 (gdb) p main.myglob
17193 @end example
17194
17195 @cindex builtin Go types
17196 @item Builtin Go types
17197 The @code{string} type is recognized by @value{GDBN} and is printed
17198 as a string.
17199
17200 @cindex builtin Go functions
17201 @item Builtin Go functions
17202 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
17203 function and handles it internally.
17204
17205 @cindex restrictions on Go expressions
17206 @item Restrictions on Go expressions
17207 All Go operators are supported except @code{&^}.
17208 The Go @code{_} ``blank identifier'' is not supported.
17209 Automatic dereferencing of pointers is not supported.
17210 @end table
17211
17212 @node Objective-C
17213 @subsection Objective-C
17214
17215 @cindex Objective-C
17216 This section provides information about some commands and command
17217 options that are useful for debugging Objective-C code. See also
17218 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
17219 few more commands specific to Objective-C support.
17220
17221 @menu
17222 * Method Names in Commands::
17223 * The Print Command with Objective-C::
17224 @end menu
17225
17226 @node Method Names in Commands
17227 @subsubsection Method Names in Commands
17228
17229 The following commands have been extended to accept Objective-C method
17230 names as line specifications:
17231
17232 @kindex clear@r{, and Objective-C}
17233 @kindex break@r{, and Objective-C}
17234 @kindex info line@r{, and Objective-C}
17235 @kindex jump@r{, and Objective-C}
17236 @kindex list@r{, and Objective-C}
17237 @itemize
17238 @item @code{clear}
17239 @item @code{break}
17240 @item @code{info line}
17241 @item @code{jump}
17242 @item @code{list}
17243 @end itemize
17244
17245 A fully qualified Objective-C method name is specified as
17246
17247 @smallexample
17248 -[@var{Class} @var{methodName}]
17249 @end smallexample
17250
17251 where the minus sign is used to indicate an instance method and a
17252 plus sign (not shown) is used to indicate a class method. The class
17253 name @var{Class} and method name @var{methodName} are enclosed in
17254 brackets, similar to the way messages are specified in Objective-C
17255 source code. For example, to set a breakpoint at the @code{create}
17256 instance method of class @code{Fruit} in the program currently being
17257 debugged, enter:
17258
17259 @smallexample
17260 break -[Fruit create]
17261 @end smallexample
17262
17263 To list ten program lines around the @code{initialize} class method,
17264 enter:
17265
17266 @smallexample
17267 list +[NSText initialize]
17268 @end smallexample
17269
17270 In the current version of @value{GDBN}, the plus or minus sign is
17271 required. In future versions of @value{GDBN}, the plus or minus
17272 sign will be optional, but you can use it to narrow the search. It
17273 is also possible to specify just a method name:
17274
17275 @smallexample
17276 break create
17277 @end smallexample
17278
17279 You must specify the complete method name, including any colons. If
17280 your program's source files contain more than one @code{create} method,
17281 you'll be presented with a numbered list of classes that implement that
17282 method. Indicate your choice by number, or type @samp{0} to exit if
17283 none apply.
17284
17285 As another example, to clear a breakpoint established at the
17286 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
17287
17288 @smallexample
17289 clear -[NSWindow makeKeyAndOrderFront:]
17290 @end smallexample
17291
17292 @node The Print Command with Objective-C
17293 @subsubsection The Print Command With Objective-C
17294 @cindex Objective-C, print objects
17295 @kindex print-object
17296 @kindex po @r{(@code{print-object})}
17297
17298 The print command has also been extended to accept methods. For example:
17299
17300 @smallexample
17301 print -[@var{object} hash]
17302 @end smallexample
17303
17304 @cindex print an Objective-C object description
17305 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
17306 @noindent
17307 will tell @value{GDBN} to send the @code{hash} message to @var{object}
17308 and print the result. Also, an additional command has been added,
17309 @code{print-object} or @code{po} for short, which is meant to print
17310 the description of an object. However, this command may only work
17311 with certain Objective-C libraries that have a particular hook
17312 function, @code{_NSPrintForDebugger}, defined.
17313
17314 @node OpenCL C
17315 @subsection OpenCL C
17316
17317 @cindex OpenCL C
17318 This section provides information about @value{GDBN}s OpenCL C support.
17319
17320 @menu
17321 * OpenCL C Datatypes::
17322 * OpenCL C Expressions::
17323 * OpenCL C Operators::
17324 @end menu
17325
17326 @node OpenCL C Datatypes
17327 @subsubsection OpenCL C Datatypes
17328
17329 @cindex OpenCL C Datatypes
17330 @value{GDBN} supports the builtin scalar and vector datatypes specified
17331 by OpenCL 1.1. In addition the half- and double-precision floating point
17332 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
17333 extensions are also known to @value{GDBN}.
17334
17335 @node OpenCL C Expressions
17336 @subsubsection OpenCL C Expressions
17337
17338 @cindex OpenCL C Expressions
17339 @value{GDBN} supports accesses to vector components including the access as
17340 lvalue where possible. Since OpenCL C is based on C99 most C expressions
17341 supported by @value{GDBN} can be used as well.
17342
17343 @node OpenCL C Operators
17344 @subsubsection OpenCL C Operators
17345
17346 @cindex OpenCL C Operators
17347 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
17348 vector data types.
17349
17350 @node Fortran
17351 @subsection Fortran
17352 @cindex Fortran-specific support in @value{GDBN}
17353
17354 @value{GDBN} can be used to debug programs written in Fortran. Note, that not
17355 all Fortran language features are available yet.
17356
17357 @cindex trailing underscore, in Fortran symbols
17358 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
17359 among them) append an underscore to the names of variables and
17360 functions. When you debug programs compiled by those compilers, you
17361 will need to refer to variables and functions with a trailing
17362 underscore.
17363
17364 @cindex Fortran Defaults
17365 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17366 default uses case-insensitive matching for Fortran symbols. You can
17367 change that with the @samp{set case-insensitive} command, see
17368 @ref{Symbols}, for the details.
17369
17370 @menu
17371 * Fortran Types:: Fortran builtin types
17372 * Fortran Operators:: Fortran operators and expressions
17373 * Fortran Intrinsics:: Fortran intrinsic functions
17374 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
17375 @end menu
17376
17377 @node Fortran Types
17378 @subsubsection Fortran Types
17379
17380 @cindex Fortran Types
17381
17382 In Fortran the primitive data-types have an associated @code{KIND} type
17383 parameter, written as @samp{@var{type}*@var{kindparam}},
17384 @samp{@var{type}*@var{kindparam}}, or in the @value{GDBN}-only dialect
17385 @samp{@var{type}_@var{kindparam}}. A concrete example would be
17386 @samp{@code{Real*4}}, @samp{@code{Real(kind=4)}}, and @samp{@code{Real_4}}.
17387 The kind of a type can be retrieved by using the intrinsic function
17388 @code{KIND}, see @ref{Fortran Intrinsics}.
17389
17390 Generally, the actual implementation of the @code{KIND} type parameter is
17391 compiler specific. In @value{GDBN} the kind parameter is implemented in
17392 accordance with its use in the @sc{gnu} @command{gfortran} compiler. Here, the
17393 kind parameter for a given @var{type} specifies its size in memory --- a
17394 Fortran @code{Integer*4} or @code{Integer(kind=4)} would be an integer type
17395 occupying 4 bytes of memory. An exception to this rule is the @code{Complex}
17396 type for which the kind of the type does not specify its entire size, but
17397 the size of each of the two @code{Real}'s it is composed of. A
17398 @code{Complex*4} would thus consist of two @code{Real*4}s and occupy 8 bytes
17399 of memory.
17400
17401 For every type there is also a default kind associated with it, e.g.@
17402 @code{Integer} in @value{GDBN} will internally be an @code{Integer*4} (see the
17403 table below for default types). The default types are the same as in @sc{gnu}
17404 compilers but note, that the @sc{gnu} default types can actually be changed by
17405 compiler flags such as @option{-fdefault-integer-8} and
17406 @option{-fdefault-real-8}.
17407
17408 Not every kind parameter is valid for every type and in @value{GDBN} the
17409 following type kinds are available.
17410
17411 @table @code
17412 @item Integer
17413 @code{Integer*1}, @code{Integer*2}, @code{Integer*4}, @code{Integer*8}, and
17414 @code{Integer} = @code{Integer*4}.
17415
17416 @item Logical
17417 @code{Logical*1}, @code{Logical*2}, @code{Logical*4}, @code{Logical*8}, and
17418 @code{Logical} = @code{Logical*4}.
17419
17420 @item Real
17421 @code{Real*4}, @code{Real*8}, @code{Real*16}, and @code{Real} = @code{Real*4}.
17422
17423 @item Complex
17424 @code{Complex*4}, @code{Complex*8}, @code{Complex*16}, and @code{Complex} =
17425 @code{Complex*4}.
17426
17427 @end table
17428
17429 @node Fortran Operators
17430 @subsubsection Fortran Operators and Expressions
17431
17432 @cindex Fortran operators and expressions
17433
17434 Operators must be defined on values of specific types. For instance,
17435 @code{+} is defined on numbers, but not on characters or other non-
17436 arithmetic types. Operators are often defined on groups of types.
17437
17438 @table @code
17439 @item **
17440 The exponentiation operator. It raises the first operand to the power
17441 of the second one.
17442
17443 @item :
17444 The range operator. Normally used in the form of array(low:high) to
17445 represent a section of array.
17446
17447 @item %
17448 The access component operator. Normally used to access elements in derived
17449 types. Also suitable for unions. As unions aren't part of regular Fortran,
17450 this can only happen when accessing a register that uses a gdbarch-defined
17451 union type.
17452 @item ::
17453 The scope operator. Normally used to access variables in modules or
17454 to set breakpoints on subroutines nested in modules or in other
17455 subroutines (internal subroutines).
17456 @end table
17457
17458 @node Fortran Intrinsics
17459 @subsubsection Fortran Intrinsics
17460
17461 @cindex Fortran Intrinsics
17462
17463 Fortran provides a large set of intrinsic procedures. @value{GDBN} implements
17464 an incomplete subset of those procedures and their overloads. Some of these
17465 procedures take an optional @code{KIND} parameter, see @ref{Fortran Types}.
17466
17467 @table @code
17468 @item ABS(@var{a})
17469 Computes the absolute value of its argument @var{a}. Currently not supported
17470 for @code{Complex} arguments.
17471
17472 @item ALLOCATE(@var{array})
17473 Returns whether @var{array} is allocated or not.
17474
17475 @item ASSOCIATED(@var{pointer} [, @var{target}])
17476 Returns the association status of the pointer @var{pointer} or, if @var{target}
17477 is present, whether @var{pointer} is associated with the target @var{target}.
17478
17479 @item CEILING(@var{a} [, @var{kind}])
17480 Computes the least integer greater than or equal to @var{a}. The optional
17481 parameter @var{kind} specifies the kind of the return type
17482 @code{Integer(@var{kind})}.
17483
17484 @item CMPLX(@var{x} [, @var{y} [, @var{kind}]])
17485 Returns a complex number where @var{x} is converted to the real component. If
17486 @var{y} is present it is converted to the imaginary component. If @var{y} is
17487 not present then the imaginary component is set to @code{0.0} except if @var{x}
17488 itself is of @code{Complex} type. The optional parameter @var{kind} specifies
17489 the kind of the return type @code{Complex(@var{kind})}.
17490
17491 @item FLOOR(@var{a} [, @var{kind}])
17492 Computes the greatest integer less than or equal to @var{a}. The optional
17493 parameter @var{kind} specifies the kind of the return type
17494 @code{Integer(@var{kind})}.
17495
17496 @item KIND(@var{a})
17497 Returns the kind value of the argument @var{a}, see @ref{Fortran Types}.
17498
17499 @item LBOUND(@var{array} [, @var{dim} [, @var{kind}]])
17500 Returns the lower bounds of an @var{array}, or a single lower bound along the
17501 @var{dim} dimension if present. The optional parameter @var{kind} specifies
17502 the kind of the return type @code{Integer(@var{kind})}.
17503
17504 @item LOC(@var{x})
17505 Returns the address of @var{x} as an @code{Integer}.
17506
17507 @item MOD(@var{a}, @var{p})
17508 Computes the remainder of the division of @var{a} by @var{p}.
17509
17510 @item MODULO(@var{a}, @var{p})
17511 Computes the @var{a} modulo @var{p}.
17512
17513 @item RANK(@var{a})
17514 Returns the rank of a scalar or array (scalars have rank @code{0}).
17515
17516 @item SHAPE(@var{a})
17517 Returns the shape of a scalar or array (scalars have shape @samp{()}).
17518
17519 @item SIZE(@var{array}[, @var{dim} [, @var{kind}]])
17520 Returns the extent of @var{array} along a specified dimension @var{dim}, or the
17521 total number of elements in @var{array} if @var{dim} is absent. The optional
17522 parameter @var{kind} specifies the kind of the return type
17523 @code{Integer(@var{kind})}.
17524
17525 @item UBOUND(@var{array} [, @var{dim} [, @var{kind}]])
17526 Returns the upper bounds of an @var{array}, or a single upper bound along the
17527 @var{dim} dimension if present. The optional parameter @var{kind} specifies
17528 the kind of the return type @code{Integer(@var{kind})}.
17529
17530 @end table
17531
17532 @node Special Fortran Commands
17533 @subsubsection Special Fortran Commands
17534
17535 @cindex Special Fortran commands
17536
17537 @value{GDBN} has some commands to support Fortran-specific features,
17538 such as displaying common blocks.
17539
17540 @table @code
17541 @cindex @code{COMMON} blocks, Fortran
17542 @kindex info common
17543 @item info common @r{[}@var{common-name}@r{]}
17544 This command prints the values contained in the Fortran @code{COMMON}
17545 block whose name is @var{common-name}. With no argument, the names of
17546 all @code{COMMON} blocks visible at the current program location are
17547 printed.
17548 @cindex arrays slices (Fortran)
17549 @kindex set fortran repack-array-slices
17550 @kindex show fortran repack-array-slices
17551 @item set fortran repack-array-slices [on|off]
17552 @item show fortran repack-array-slices
17553 When taking a slice from an array, a Fortran compiler can choose to
17554 either produce an array descriptor that describes the slice in place,
17555 or it may repack the slice, copying the elements of the slice into a
17556 new region of memory.
17557
17558 When this setting is on, then @value{GDBN} will also repack array
17559 slices in some situations. When this setting is off, then
17560 @value{GDBN} will create array descriptors for slices that reference
17561 the original data in place.
17562
17563 @value{GDBN} will never repack an array slice if the data for the
17564 slice is contiguous within the original array.
17565
17566 @value{GDBN} will always repack string slices if the data for the
17567 slice is non-contiguous within the original string as @value{GDBN}
17568 does not support printing non-contiguous strings.
17569
17570 The default for this setting is @code{off}.
17571 @end table
17572
17573 @node Pascal
17574 @subsection Pascal
17575
17576 @cindex Pascal support in @value{GDBN}, limitations
17577 Debugging Pascal programs which use sets, subranges, file variables, or
17578 nested functions does not currently work. @value{GDBN} does not support
17579 entering expressions, printing values, or similar features using Pascal
17580 syntax.
17581
17582 The Pascal-specific command @code{set print pascal_static-members}
17583 controls whether static members of Pascal objects are displayed.
17584 @xref{Print Settings, pascal_static-members}.
17585
17586 @node Rust
17587 @subsection Rust
17588
17589 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17590 Programming Language}. Type- and value-printing, and expression
17591 parsing, are reasonably complete. However, there are a few
17592 peculiarities and holes to be aware of.
17593
17594 @itemize @bullet
17595 @item
17596 Linespecs (@pxref{Location Specifications}) are never relative to the
17597 current crate. Instead, they act as if there were a global namespace
17598 of crates, somewhat similar to the way @code{extern crate} behaves.
17599
17600 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17601 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17602 to set a breakpoint in a function named @samp{f} in a crate named
17603 @samp{B}.
17604
17605 As a consequence of this approach, linespecs also cannot refer to
17606 items using @samp{self::} or @samp{super::}.
17607
17608 @item
17609 Because @value{GDBN} implements Rust name-lookup semantics in
17610 expressions, it will sometimes prepend the current crate to a name.
17611 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17612 @samp{K}, then @code{print ::x::y} will try to find the symbol
17613 @samp{K::x::y}.
17614
17615 However, since it is useful to be able to refer to other crates when
17616 debugging, @value{GDBN} provides the @code{extern} extension to
17617 circumvent this. To use the extension, just put @code{extern} before
17618 a path expression to refer to the otherwise unavailable ``global''
17619 scope.
17620
17621 In the above example, if you wanted to refer to the symbol @samp{y} in
17622 the crate @samp{x}, you would use @code{print extern x::y}.
17623
17624 @item
17625 The Rust expression evaluator does not support ``statement-like''
17626 expressions such as @code{if} or @code{match}, or lambda expressions.
17627
17628 @item
17629 Tuple expressions are not implemented.
17630
17631 @item
17632 The Rust expression evaluator does not currently implement the
17633 @code{Drop} trait. Objects that may be created by the evaluator will
17634 never be destroyed.
17635
17636 @item
17637 @value{GDBN} does not implement type inference for generics. In order
17638 to call generic functions or otherwise refer to generic items, you
17639 will have to specify the type parameters manually.
17640
17641 @item
17642 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17643 cases this does not cause any problems. However, in an expression
17644 context, completing a generic function name will give syntactically
17645 invalid results. This happens because Rust requires the @samp{::}
17646 operator between the function name and its generic arguments. For
17647 example, @value{GDBN} might provide a completion like
17648 @code{crate::f<u32>}, where the parser would require
17649 @code{crate::f::<u32>}.
17650
17651 @item
17652 As of this writing, the Rust compiler (version 1.8) has a few holes in
17653 the debugging information it generates. These holes prevent certain
17654 features from being implemented by @value{GDBN}:
17655 @itemize @bullet
17656
17657 @item
17658 Method calls cannot be made via traits.
17659
17660 @item
17661 Operator overloading is not implemented.
17662
17663 @item
17664 When debugging in a monomorphized function, you cannot use the generic
17665 type names.
17666
17667 @item
17668 The type @code{Self} is not available.
17669
17670 @item
17671 @code{use} statements are not available, so some names may not be
17672 available in the crate.
17673 @end itemize
17674 @end itemize
17675
17676 @node Modula-2
17677 @subsection Modula-2
17678
17679 @cindex Modula-2, @value{GDBN} support
17680
17681 The extensions made to @value{GDBN} to support Modula-2 only support
17682 output from the @sc{gnu} Modula-2 compiler (which is currently being
17683 developed). Other Modula-2 compilers are not currently supported, and
17684 attempting to debug executables produced by them is most likely
17685 to give an error as @value{GDBN} reads in the executable's symbol
17686 table.
17687
17688 @cindex expressions in Modula-2
17689 @menu
17690 * M2 Operators:: Built-in operators
17691 * Built-In Func/Proc:: Built-in functions and procedures
17692 * M2 Constants:: Modula-2 constants
17693 * M2 Types:: Modula-2 types
17694 * M2 Defaults:: Default settings for Modula-2
17695 * Deviations:: Deviations from standard Modula-2
17696 * M2 Checks:: Modula-2 type and range checks
17697 * M2 Scope:: The scope operators @code{::} and @code{.}
17698 * GDB/M2:: @value{GDBN} and Modula-2
17699 @end menu
17700
17701 @node M2 Operators
17702 @subsubsection Operators
17703 @cindex Modula-2 operators
17704
17705 Operators must be defined on values of specific types. For instance,
17706 @code{+} is defined on numbers, but not on structures. Operators are
17707 often defined on groups of types. For the purposes of Modula-2, the
17708 following definitions hold:
17709
17710 @itemize @bullet
17711
17712 @item
17713 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17714 their subranges.
17715
17716 @item
17717 @emph{Character types} consist of @code{CHAR} and its subranges.
17718
17719 @item
17720 @emph{Floating-point types} consist of @code{REAL}.
17721
17722 @item
17723 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17724 @var{type}}.
17725
17726 @item
17727 @emph{Scalar types} consist of all of the above.
17728
17729 @item
17730 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17731
17732 @item
17733 @emph{Boolean types} consist of @code{BOOLEAN}.
17734 @end itemize
17735
17736 @noindent
17737 The following operators are supported, and appear in order of
17738 increasing precedence:
17739
17740 @table @code
17741 @item ,
17742 Function argument or array index separator.
17743
17744 @item :=
17745 Assignment. The value of @var{var} @code{:=} @var{value} is
17746 @var{value}.
17747
17748 @item <@r{, }>
17749 Less than, greater than on integral, floating-point, or enumerated
17750 types.
17751
17752 @item <=@r{, }>=
17753 Less than or equal to, greater than or equal to
17754 on integral, floating-point and enumerated types, or set inclusion on
17755 set types. Same precedence as @code{<}.
17756
17757 @item =@r{, }<>@r{, }#
17758 Equality and two ways of expressing inequality, valid on scalar types.
17759 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17760 available for inequality, since @code{#} conflicts with the script
17761 comment character.
17762
17763 @item IN
17764 Set membership. Defined on set types and the types of their members.
17765 Same precedence as @code{<}.
17766
17767 @item OR
17768 Boolean disjunction. Defined on boolean types.
17769
17770 @item AND@r{, }&
17771 Boolean conjunction. Defined on boolean types.
17772
17773 @item @@
17774 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17775
17776 @item +@r{, }-
17777 Addition and subtraction on integral and floating-point types, or union
17778 and difference on set types.
17779
17780 @item *
17781 Multiplication on integral and floating-point types, or set intersection
17782 on set types.
17783
17784 @item /
17785 Division on floating-point types, or symmetric set difference on set
17786 types. Same precedence as @code{*}.
17787
17788 @item DIV@r{, }MOD
17789 Integer division and remainder. Defined on integral types. Same
17790 precedence as @code{*}.
17791
17792 @item -
17793 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17794
17795 @item ^
17796 Pointer dereferencing. Defined on pointer types.
17797
17798 @item NOT
17799 Boolean negation. Defined on boolean types. Same precedence as
17800 @code{^}.
17801
17802 @item .
17803 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17804 precedence as @code{^}.
17805
17806 @item []
17807 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17808
17809 @item ()
17810 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17811 as @code{^}.
17812
17813 @item ::@r{, }.
17814 @value{GDBN} and Modula-2 scope operators.
17815 @end table
17816
17817 @quotation
17818 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17819 treats the use of the operator @code{IN}, or the use of operators
17820 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17821 @code{<=}, and @code{>=} on sets as an error.
17822 @end quotation
17823
17824
17825 @node Built-In Func/Proc
17826 @subsubsection Built-in Functions and Procedures
17827 @cindex Modula-2 built-ins
17828
17829 Modula-2 also makes available several built-in procedures and functions.
17830 In describing these, the following metavariables are used:
17831
17832 @table @var
17833
17834 @item a
17835 represents an @code{ARRAY} variable.
17836
17837 @item c
17838 represents a @code{CHAR} constant or variable.
17839
17840 @item i
17841 represents a variable or constant of integral type.
17842
17843 @item m
17844 represents an identifier that belongs to a set. Generally used in the
17845 same function with the metavariable @var{s}. The type of @var{s} should
17846 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17847
17848 @item n
17849 represents a variable or constant of integral or floating-point type.
17850
17851 @item r
17852 represents a variable or constant of floating-point type.
17853
17854 @item t
17855 represents a type.
17856
17857 @item v
17858 represents a variable.
17859
17860 @item x
17861 represents a variable or constant of one of many types. See the
17862 explanation of the function for details.
17863 @end table
17864
17865 All Modula-2 built-in procedures also return a result, described below.
17866
17867 @table @code
17868 @item ABS(@var{n})
17869 Returns the absolute value of @var{n}.
17870
17871 @item CAP(@var{c})
17872 If @var{c} is a lower case letter, it returns its upper case
17873 equivalent, otherwise it returns its argument.
17874
17875 @item CHR(@var{i})
17876 Returns the character whose ordinal value is @var{i}.
17877
17878 @item DEC(@var{v})
17879 Decrements the value in the variable @var{v} by one. Returns the new value.
17880
17881 @item DEC(@var{v},@var{i})
17882 Decrements the value in the variable @var{v} by @var{i}. Returns the
17883 new value.
17884
17885 @item EXCL(@var{m},@var{s})
17886 Removes the element @var{m} from the set @var{s}. Returns the new
17887 set.
17888
17889 @item FLOAT(@var{i})
17890 Returns the floating point equivalent of the integer @var{i}.
17891
17892 @item HIGH(@var{a})
17893 Returns the index of the last member of @var{a}.
17894
17895 @item INC(@var{v})
17896 Increments the value in the variable @var{v} by one. Returns the new value.
17897
17898 @item INC(@var{v},@var{i})
17899 Increments the value in the variable @var{v} by @var{i}. Returns the
17900 new value.
17901
17902 @item INCL(@var{m},@var{s})
17903 Adds the element @var{m} to the set @var{s} if it is not already
17904 there. Returns the new set.
17905
17906 @item MAX(@var{t})
17907 Returns the maximum value of the type @var{t}.
17908
17909 @item MIN(@var{t})
17910 Returns the minimum value of the type @var{t}.
17911
17912 @item ODD(@var{i})
17913 Returns boolean TRUE if @var{i} is an odd number.
17914
17915 @item ORD(@var{x})
17916 Returns the ordinal value of its argument. For example, the ordinal
17917 value of a character is its @sc{ascii} value (on machines supporting
17918 the @sc{ascii} character set). The argument @var{x} must be of an
17919 ordered type, which include integral, character and enumerated types.
17920
17921 @item SIZE(@var{x})
17922 Returns the size of its argument. The argument @var{x} can be a
17923 variable or a type.
17924
17925 @item TRUNC(@var{r})
17926 Returns the integral part of @var{r}.
17927
17928 @item TSIZE(@var{x})
17929 Returns the size of its argument. The argument @var{x} can be a
17930 variable or a type.
17931
17932 @item VAL(@var{t},@var{i})
17933 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17934 @end table
17935
17936 @quotation
17937 @emph{Warning:} Sets and their operations are not yet supported, so
17938 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17939 an error.
17940 @end quotation
17941
17942 @cindex Modula-2 constants
17943 @node M2 Constants
17944 @subsubsection Constants
17945
17946 @value{GDBN} allows you to express the constants of Modula-2 in the following
17947 ways:
17948
17949 @itemize @bullet
17950
17951 @item
17952 Integer constants are simply a sequence of digits. When used in an
17953 expression, a constant is interpreted to be type-compatible with the
17954 rest of the expression. Hexadecimal integers are specified by a
17955 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17956
17957 @item
17958 Floating point constants appear as a sequence of digits, followed by a
17959 decimal point and another sequence of digits. An optional exponent can
17960 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17961 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17962 digits of the floating point constant must be valid decimal (base 10)
17963 digits.
17964
17965 @item
17966 Character constants consist of a single character enclosed by a pair of
17967 like quotes, either single (@code{'}) or double (@code{"}). They may
17968 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17969 followed by a @samp{C}.
17970
17971 @item
17972 String constants consist of a sequence of characters enclosed by a
17973 pair of like quotes, either single (@code{'}) or double (@code{"}).
17974 Escape sequences in the style of C are also allowed. @xref{C
17975 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17976 sequences.
17977
17978 @item
17979 Enumerated constants consist of an enumerated identifier.
17980
17981 @item
17982 Boolean constants consist of the identifiers @code{TRUE} and
17983 @code{FALSE}.
17984
17985 @item
17986 Pointer constants consist of integral values only.
17987
17988 @item
17989 Set constants are not yet supported.
17990 @end itemize
17991
17992 @node M2 Types
17993 @subsubsection Modula-2 Types
17994 @cindex Modula-2 types
17995
17996 Currently @value{GDBN} can print the following data types in Modula-2
17997 syntax: array types, record types, set types, pointer types, procedure
17998 types, enumerated types, subrange types and base types. You can also
17999 print the contents of variables declared using these type.
18000 This section gives a number of simple source code examples together with
18001 sample @value{GDBN} sessions.
18002
18003 The first example contains the following section of code:
18004
18005 @smallexample
18006 VAR
18007 s: SET OF CHAR ;
18008 r: [20..40] ;
18009 @end smallexample
18010
18011 @noindent
18012 and you can request @value{GDBN} to interrogate the type and value of
18013 @code{r} and @code{s}.
18014
18015 @smallexample
18016 (@value{GDBP}) print s
18017 @{'A'..'C', 'Z'@}
18018 (@value{GDBP}) ptype s
18019 SET OF CHAR
18020 (@value{GDBP}) print r
18021 21
18022 (@value{GDBP}) ptype r
18023 [20..40]
18024 @end smallexample
18025
18026 @noindent
18027 Likewise if your source code declares @code{s} as:
18028
18029 @smallexample
18030 VAR
18031 s: SET ['A'..'Z'] ;
18032 @end smallexample
18033
18034 @noindent
18035 then you may query the type of @code{s} by:
18036
18037 @smallexample
18038 (@value{GDBP}) ptype s
18039 type = SET ['A'..'Z']
18040 @end smallexample
18041
18042 @noindent
18043 Note that at present you cannot interactively manipulate set
18044 expressions using the debugger.
18045
18046 The following example shows how you might declare an array in Modula-2
18047 and how you can interact with @value{GDBN} to print its type and contents:
18048
18049 @smallexample
18050 VAR
18051 s: ARRAY [-10..10] OF CHAR ;
18052 @end smallexample
18053
18054 @smallexample
18055 (@value{GDBP}) ptype s
18056 ARRAY [-10..10] OF CHAR
18057 @end smallexample
18058
18059 Note that the array handling is not yet complete and although the type
18060 is printed correctly, expression handling still assumes that all
18061 arrays have a lower bound of zero and not @code{-10} as in the example
18062 above.
18063
18064 Here are some more type related Modula-2 examples:
18065
18066 @smallexample
18067 TYPE
18068 colour = (blue, red, yellow, green) ;
18069 t = [blue..yellow] ;
18070 VAR
18071 s: t ;
18072 BEGIN
18073 s := blue ;
18074 @end smallexample
18075
18076 @noindent
18077 The @value{GDBN} interaction shows how you can query the data type
18078 and value of a variable.
18079
18080 @smallexample
18081 (@value{GDBP}) print s
18082 $1 = blue
18083 (@value{GDBP}) ptype t
18084 type = [blue..yellow]
18085 @end smallexample
18086
18087 @noindent
18088 In this example a Modula-2 array is declared and its contents
18089 displayed. Observe that the contents are written in the same way as
18090 their @code{C} counterparts.
18091
18092 @smallexample
18093 VAR
18094 s: ARRAY [1..5] OF CARDINAL ;
18095 BEGIN
18096 s[1] := 1 ;
18097 @end smallexample
18098
18099 @smallexample
18100 (@value{GDBP}) print s
18101 $1 = @{1, 0, 0, 0, 0@}
18102 (@value{GDBP}) ptype s
18103 type = ARRAY [1..5] OF CARDINAL
18104 @end smallexample
18105
18106 The Modula-2 language interface to @value{GDBN} also understands
18107 pointer types as shown in this example:
18108
18109 @smallexample
18110 VAR
18111 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
18112 BEGIN
18113 NEW(s) ;
18114 s^[1] := 1 ;
18115 @end smallexample
18116
18117 @noindent
18118 and you can request that @value{GDBN} describes the type of @code{s}.
18119
18120 @smallexample
18121 (@value{GDBP}) ptype s
18122 type = POINTER TO ARRAY [1..5] OF CARDINAL
18123 @end smallexample
18124
18125 @value{GDBN} handles compound types as we can see in this example.
18126 Here we combine array types, record types, pointer types and subrange
18127 types:
18128
18129 @smallexample
18130 TYPE
18131 foo = RECORD
18132 f1: CARDINAL ;
18133 f2: CHAR ;
18134 f3: myarray ;
18135 END ;
18136
18137 myarray = ARRAY myrange OF CARDINAL ;
18138 myrange = [-2..2] ;
18139 VAR
18140 s: POINTER TO ARRAY myrange OF foo ;
18141 @end smallexample
18142
18143 @noindent
18144 and you can ask @value{GDBN} to describe the type of @code{s} as shown
18145 below.
18146
18147 @smallexample
18148 (@value{GDBP}) ptype s
18149 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
18150 f1 : CARDINAL;
18151 f2 : CHAR;
18152 f3 : ARRAY [-2..2] OF CARDINAL;
18153 END
18154 @end smallexample
18155
18156 @node M2 Defaults
18157 @subsubsection Modula-2 Defaults
18158 @cindex Modula-2 defaults
18159
18160 If type and range checking are set automatically by @value{GDBN}, they
18161 both default to @code{on} whenever the working language changes to
18162 Modula-2. This happens regardless of whether you or @value{GDBN}
18163 selected the working language.
18164
18165 If you allow @value{GDBN} to set the language automatically, then entering
18166 code compiled from a file whose name ends with @file{.mod} sets the
18167 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
18168 Infer the Source Language}, for further details.
18169
18170 @node Deviations
18171 @subsubsection Deviations from Standard Modula-2
18172 @cindex Modula-2, deviations from
18173
18174 A few changes have been made to make Modula-2 programs easier to debug.
18175 This is done primarily via loosening its type strictness:
18176
18177 @itemize @bullet
18178 @item
18179 Unlike in standard Modula-2, pointer constants can be formed by
18180 integers. This allows you to modify pointer variables during
18181 debugging. (In standard Modula-2, the actual address contained in a
18182 pointer variable is hidden from you; it can only be modified
18183 through direct assignment to another pointer variable or expression that
18184 returned a pointer.)
18185
18186 @item
18187 C escape sequences can be used in strings and characters to represent
18188 non-printable characters. @value{GDBN} prints out strings with these
18189 escape sequences embedded. Single non-printable characters are
18190 printed using the @samp{CHR(@var{nnn})} format.
18191
18192 @item
18193 The assignment operator (@code{:=}) returns the value of its right-hand
18194 argument.
18195
18196 @item
18197 All built-in procedures both modify @emph{and} return their argument.
18198 @end itemize
18199
18200 @node M2 Checks
18201 @subsubsection Modula-2 Type and Range Checks
18202 @cindex Modula-2 checks
18203
18204 @quotation
18205 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
18206 range checking.
18207 @end quotation
18208 @c FIXME remove warning when type/range checks added
18209
18210 @value{GDBN} considers two Modula-2 variables type equivalent if:
18211
18212 @itemize @bullet
18213 @item
18214 They are of types that have been declared equivalent via a @code{TYPE
18215 @var{t1} = @var{t2}} statement
18216
18217 @item
18218 They have been declared on the same line. (Note: This is true of the
18219 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
18220 @end itemize
18221
18222 As long as type checking is enabled, any attempt to combine variables
18223 whose types are not equivalent is an error.
18224
18225 Range checking is done on all mathematical operations, assignment, array
18226 index bounds, and all built-in functions and procedures.
18227
18228 @node M2 Scope
18229 @subsubsection The Scope Operators @code{::} and @code{.}
18230 @cindex scope
18231 @cindex @code{.}, Modula-2 scope operator
18232 @cindex colon, doubled as scope operator
18233 @ifinfo
18234 @vindex colon-colon@r{, in Modula-2}
18235 @c Info cannot handle :: but TeX can.
18236 @end ifinfo
18237 @ifnotinfo
18238 @vindex ::@r{, in Modula-2}
18239 @end ifnotinfo
18240
18241 There are a few subtle differences between the Modula-2 scope operator
18242 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
18243 similar syntax:
18244
18245 @smallexample
18246
18247 @var{module} . @var{id}
18248 @var{scope} :: @var{id}
18249 @end smallexample
18250
18251 @noindent
18252 where @var{scope} is the name of a module or a procedure,
18253 @var{module} the name of a module, and @var{id} is any declared
18254 identifier within your program, except another module.
18255
18256 Using the @code{::} operator makes @value{GDBN} search the scope
18257 specified by @var{scope} for the identifier @var{id}. If it is not
18258 found in the specified scope, then @value{GDBN} searches all scopes
18259 enclosing the one specified by @var{scope}.
18260
18261 Using the @code{.} operator makes @value{GDBN} search the current scope for
18262 the identifier specified by @var{id} that was imported from the
18263 definition module specified by @var{module}. With this operator, it is
18264 an error if the identifier @var{id} was not imported from definition
18265 module @var{module}, or if @var{id} is not an identifier in
18266 @var{module}.
18267
18268 @node GDB/M2
18269 @subsubsection @value{GDBN} and Modula-2
18270
18271 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
18272 Five subcommands of @code{set print} and @code{show print} apply
18273 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
18274 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
18275 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
18276 analogue in Modula-2.
18277
18278 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
18279 with any language, is not useful with Modula-2. Its
18280 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
18281 created in Modula-2 as they can in C or C@t{++}. However, because an
18282 address can be specified by an integral constant, the construct
18283 @samp{@{@var{type}@}@var{adrexp}} is still useful.
18284
18285 @cindex @code{#} in Modula-2
18286 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
18287 interpreted as the beginning of a comment. Use @code{<>} instead.
18288
18289 @node Ada
18290 @subsection Ada
18291 @cindex Ada
18292
18293 The extensions made to @value{GDBN} for Ada only support
18294 output from the @sc{gnu} Ada (GNAT) compiler.
18295 Other Ada compilers are not currently supported, and
18296 attempting to debug executables produced by them is most likely
18297 to be difficult.
18298
18299
18300 @cindex expressions in Ada
18301 @menu
18302 * Ada Mode Intro:: General remarks on the Ada syntax
18303 and semantics supported by Ada mode
18304 in @value{GDBN}.
18305 * Omissions from Ada:: Restrictions on the Ada expression syntax.
18306 * Additions to Ada:: Extensions of the Ada expression syntax.
18307 * Overloading support for Ada:: Support for expressions involving overloaded
18308 subprograms.
18309 * Stopping Before Main Program:: Debugging the program during elaboration.
18310 * Ada Exceptions:: Ada Exceptions
18311 * Ada Tasks:: Listing and setting breakpoints in tasks.
18312 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
18313 * Ravenscar Profile:: Tasking Support when using the Ravenscar
18314 Profile
18315 * Ada Source Character Set:: Character set of Ada source files.
18316 * Ada Glitches:: Known peculiarities of Ada mode.
18317 @end menu
18318
18319 @node Ada Mode Intro
18320 @subsubsection Introduction
18321 @cindex Ada mode, general
18322
18323 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
18324 syntax, with some extensions.
18325 The philosophy behind the design of this subset is
18326
18327 @itemize @bullet
18328 @item
18329 That @value{GDBN} should provide basic literals and access to operations for
18330 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
18331 leaving more sophisticated computations to subprograms written into the
18332 program (which therefore may be called from @value{GDBN}).
18333
18334 @item
18335 That type safety and strict adherence to Ada language restrictions
18336 are not particularly important to the @value{GDBN} user.
18337
18338 @item
18339 That brevity is important to the @value{GDBN} user.
18340 @end itemize
18341
18342 Thus, for brevity, the debugger acts as if all names declared in
18343 user-written packages are directly visible, even if they are not visible
18344 according to Ada rules, thus making it unnecessary to fully qualify most
18345 names with their packages, regardless of context. Where this causes
18346 ambiguity, @value{GDBN} asks the user's intent.
18347
18348 The debugger will start in Ada mode if it detects an Ada main program.
18349 As for other languages, it will enter Ada mode when stopped in a program that
18350 was translated from an Ada source file.
18351
18352 While in Ada mode, you may use `@t{--}' for comments. This is useful
18353 mostly for documenting command files. The standard @value{GDBN} comment
18354 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
18355 middle (to allow based literals).
18356
18357 @node Omissions from Ada
18358 @subsubsection Omissions from Ada
18359 @cindex Ada, omissions from
18360
18361 Here are the notable omissions from the subset:
18362
18363 @itemize @bullet
18364 @item
18365 Only a subset of the attributes are supported:
18366
18367 @itemize @minus
18368 @item
18369 @t{'First}, @t{'Last}, and @t{'Length}
18370 on array objects (not on types and subtypes).
18371
18372 @item
18373 @t{'Min} and @t{'Max}.
18374
18375 @item
18376 @t{'Pos} and @t{'Val}.
18377
18378 @item
18379 @t{'Tag}.
18380
18381 @item
18382 @t{'Range} on array objects (not subtypes), but only as the right
18383 operand of the membership (@code{in}) operator.
18384
18385 @item
18386 @t{'Access}, @t{'Unchecked_Access}, and
18387 @t{'Unrestricted_Access} (a GNAT extension).
18388
18389 @item
18390 @t{'Address}.
18391 @end itemize
18392
18393 @item
18394 The names in @code{Characters.Latin_1} are not available.
18395
18396 @item
18397 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
18398 equality of representations. They will generally work correctly
18399 for strings and arrays whose elements have integer or enumeration types.
18400 They may not work correctly for arrays whose element
18401 types have user-defined equality, for arrays of real values
18402 (in particular, IEEE-conformant floating point, because of negative
18403 zeroes and NaNs), and for arrays whose elements contain unused bits with
18404 indeterminate values.
18405
18406 @item
18407 The other component-by-component array operations (@code{and}, @code{or},
18408 @code{xor}, @code{not}, and relational tests other than equality)
18409 are not implemented.
18410
18411 @item
18412 @cindex array aggregates (Ada)
18413 @cindex record aggregates (Ada)
18414 @cindex aggregates (Ada)
18415 There is limited support for array and record aggregates. They are
18416 permitted only on the right sides of assignments, as in these examples:
18417
18418 @smallexample
18419 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
18420 (@value{GDBP}) set An_Array := (1, others => 0)
18421 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
18422 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
18423 (@value{GDBP}) set A_Record := (1, "Peter", True);
18424 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
18425 @end smallexample
18426
18427 Changing a
18428 discriminant's value by assigning an aggregate has an
18429 undefined effect if that discriminant is used within the record.
18430 However, you can first modify discriminants by directly assigning to
18431 them (which normally would not be allowed in Ada), and then performing an
18432 aggregate assignment. For example, given a variable @code{A_Rec}
18433 declared to have a type such as:
18434
18435 @smallexample
18436 type Rec (Len : Small_Integer := 0) is record
18437 Id : Integer;
18438 Vals : IntArray (1 .. Len);
18439 end record;
18440 @end smallexample
18441
18442 you can assign a value with a different size of @code{Vals} with two
18443 assignments:
18444
18445 @smallexample
18446 (@value{GDBP}) set A_Rec.Len := 4
18447 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
18448 @end smallexample
18449
18450 As this example also illustrates, @value{GDBN} is very loose about the usual
18451 rules concerning aggregates. You may leave out some of the
18452 components of an array or record aggregate (such as the @code{Len}
18453 component in the assignment to @code{A_Rec} above); they will retain their
18454 original values upon assignment. You may freely use dynamic values as
18455 indices in component associations. You may even use overlapping or
18456 redundant component associations, although which component values are
18457 assigned in such cases is not defined.
18458
18459 @item
18460 Calls to dispatching subprograms are not implemented.
18461
18462 @item
18463 The overloading algorithm is much more limited (i.e., less selective)
18464 than that of real Ada. It makes only limited use of the context in
18465 which a subexpression appears to resolve its meaning, and it is much
18466 looser in its rules for allowing type matches. As a result, some
18467 function calls will be ambiguous, and the user will be asked to choose
18468 the proper resolution.
18469
18470 @item
18471 The @code{new} operator is not implemented.
18472
18473 @item
18474 Entry calls are not implemented.
18475
18476 @item
18477 Aside from printing, arithmetic operations on the native VAX floating-point
18478 formats are not supported.
18479
18480 @item
18481 It is not possible to slice a packed array.
18482
18483 @item
18484 The names @code{True} and @code{False}, when not part of a qualified name,
18485 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
18486 context.
18487 Should your program
18488 redefine these names in a package or procedure (at best a dubious practice),
18489 you will have to use fully qualified names to access their new definitions.
18490
18491 @item
18492 Based real literals are not implemented.
18493 @end itemize
18494
18495 @node Additions to Ada
18496 @subsubsection Additions to Ada
18497 @cindex Ada, deviations from
18498
18499 As it does for other languages, @value{GDBN} makes certain generic
18500 extensions to Ada (@pxref{Expressions}):
18501
18502 @itemize @bullet
18503 @item
18504 If the expression @var{E} is a variable residing in memory (typically
18505 a local variable or array element) and @var{N} is a positive integer,
18506 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18507 @var{N}-1 adjacent variables following it in memory as an array. In
18508 Ada, this operator is generally not necessary, since its prime use is
18509 in displaying parts of an array, and slicing will usually do this in
18510 Ada. However, there are occasional uses when debugging programs in
18511 which certain debugging information has been optimized away.
18512
18513 @item
18514 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18515 appears in function or file @var{B}.'' When @var{B} is a file name,
18516 you must typically surround it in single quotes.
18517
18518 @item
18519 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18520 @var{type} that appears at address @var{addr}.''
18521
18522 @item
18523 A name starting with @samp{$} is a convenience variable
18524 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18525 @end itemize
18526
18527 In addition, @value{GDBN} provides a few other shortcuts and outright
18528 additions specific to Ada:
18529
18530 @itemize @bullet
18531 @item
18532 The assignment statement is allowed as an expression, returning
18533 its right-hand operand as its value. Thus, you may enter
18534
18535 @smallexample
18536 (@value{GDBP}) set x := y + 3
18537 (@value{GDBP}) print A(tmp := y + 1)
18538 @end smallexample
18539
18540 @item
18541 The semicolon is allowed as an ``operator,'' returning as its value
18542 the value of its right-hand operand.
18543 This allows, for example,
18544 complex conditional breaks:
18545
18546 @smallexample
18547 (@value{GDBP}) break f
18548 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18549 @end smallexample
18550
18551 @item
18552 An extension to based literals can be used to specify the exact byte
18553 contents of a floating-point literal. After the base, you can use
18554 from zero to two @samp{l} characters, followed by an @samp{f}. The
18555 number of @samp{l} characters controls the width of the resulting real
18556 constant: zero means @code{Float} is used, one means
18557 @code{Long_Float}, and two means @code{Long_Long_Float}.
18558
18559 @smallexample
18560 (@value{GDBP}) print 16f#41b80000#
18561 $1 = 23.0
18562 @end smallexample
18563
18564 @item
18565 Rather than use catenation and symbolic character names to introduce special
18566 characters into strings, one may instead use a special bracket notation,
18567 which is also used to print strings. A sequence of characters of the form
18568 @samp{["@var{XX}"]} within a string or character literal denotes the
18569 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18570 sequence of characters @samp{["""]} also denotes a single quotation mark
18571 in strings. For example,
18572 @smallexample
18573 "One line.["0a"]Next line.["0a"]"
18574 @end smallexample
18575 @noindent
18576 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18577 after each period.
18578
18579 @item
18580 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18581 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18582 to write
18583
18584 @smallexample
18585 (@value{GDBP}) print 'max(x, y)
18586 @end smallexample
18587
18588 @item
18589 When printing arrays, @value{GDBN} uses positional notation when the
18590 array has a lower bound of 1, and uses a modified named notation otherwise.
18591 For example, a one-dimensional array of three integers with a lower bound
18592 of 3 might print as
18593
18594 @smallexample
18595 (3 => 10, 17, 1)
18596 @end smallexample
18597
18598 @noindent
18599 That is, in contrast to valid Ada, only the first component has a @code{=>}
18600 clause.
18601
18602 @item
18603 You may abbreviate attributes in expressions with any unique,
18604 multi-character subsequence of
18605 their names (an exact match gets preference).
18606 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18607 in place of @t{a'length}.
18608
18609 @item
18610 @cindex quoting Ada internal identifiers
18611 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18612 to lower case. The GNAT compiler uses upper-case characters for
18613 some of its internal identifiers, which are normally of no interest to users.
18614 For the rare occasions when you actually have to look at them,
18615 enclose them in angle brackets to avoid the lower-case mapping.
18616 For example,
18617 @smallexample
18618 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18619 @end smallexample
18620
18621 @item
18622 Printing an object of class-wide type or dereferencing an
18623 access-to-class-wide value will display all the components of the object's
18624 specific type (as indicated by its run-time tag). Likewise, component
18625 selection on such a value will operate on the specific type of the
18626 object.
18627
18628 @end itemize
18629
18630 @node Overloading support for Ada
18631 @subsubsection Overloading support for Ada
18632 @cindex overloading, Ada
18633
18634 The debugger supports limited overloading. Given a subprogram call in which
18635 the function symbol has multiple definitions, it will use the number of
18636 actual parameters and some information about their types to attempt to narrow
18637 the set of definitions. It also makes very limited use of context, preferring
18638 procedures to functions in the context of the @code{call} command, and
18639 functions to procedures elsewhere.
18640
18641 If, after narrowing, the set of matching definitions still contains more than
18642 one definition, @value{GDBN} will display a menu to query which one it should
18643 use, for instance:
18644
18645 @smallexample
18646 (@value{GDBP}) print f(1)
18647 Multiple matches for f
18648 [0] cancel
18649 [1] foo.f (integer) return boolean at foo.adb:23
18650 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18651 >
18652 @end smallexample
18653
18654 In this case, just select one menu entry either to cancel expression evaluation
18655 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18656 instance (type the corresponding number and press @key{RET}).
18657
18658 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18659 case:
18660
18661 @table @code
18662
18663 @kindex set ada print-signatures
18664 @item set ada print-signatures
18665 Control whether parameter types and return types are displayed in overloads
18666 selection menus. It is @code{on} by default.
18667 @xref{Overloading support for Ada}.
18668
18669 @kindex show ada print-signatures
18670 @item show ada print-signatures
18671 Show the current setting for displaying parameter types and return types in
18672 overloads selection menu.
18673 @xref{Overloading support for Ada}.
18674
18675 @end table
18676
18677 @node Stopping Before Main Program
18678 @subsubsection Stopping at the Very Beginning
18679
18680 @cindex breakpointing Ada elaboration code
18681 It is sometimes necessary to debug the program during elaboration, and
18682 before reaching the main procedure.
18683 As defined in the Ada Reference
18684 Manual, the elaboration code is invoked from a procedure called
18685 @code{adainit}. To run your program up to the beginning of
18686 elaboration, simply use the following two commands:
18687 @code{tbreak adainit} and @code{run}.
18688
18689 @node Ada Exceptions
18690 @subsubsection Ada Exceptions
18691
18692 A command is provided to list all Ada exceptions:
18693
18694 @table @code
18695 @kindex info exceptions
18696 @item info exceptions
18697 @itemx info exceptions @var{regexp}
18698 The @code{info exceptions} command allows you to list all Ada exceptions
18699 defined within the program being debugged, as well as their addresses.
18700 With a regular expression, @var{regexp}, as argument, only those exceptions
18701 whose names match @var{regexp} are listed.
18702 @end table
18703
18704 Below is a small example, showing how the command can be used, first
18705 without argument, and next with a regular expression passed as an
18706 argument.
18707
18708 @smallexample
18709 (@value{GDBP}) info exceptions
18710 All defined Ada exceptions:
18711 constraint_error: 0x613da0
18712 program_error: 0x613d20
18713 storage_error: 0x613ce0
18714 tasking_error: 0x613ca0
18715 const.aint_global_e: 0x613b00
18716 (@value{GDBP}) info exceptions const.aint
18717 All Ada exceptions matching regular expression "const.aint":
18718 constraint_error: 0x613da0
18719 const.aint_global_e: 0x613b00
18720 @end smallexample
18721
18722 It is also possible to ask @value{GDBN} to stop your program's execution
18723 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18724
18725 @node Ada Tasks
18726 @subsubsection Extensions for Ada Tasks
18727 @cindex Ada, tasking
18728
18729 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18730 @value{GDBN} provides the following task-related commands:
18731
18732 @table @code
18733 @kindex info tasks
18734 @item info tasks
18735 This command shows a list of current Ada tasks, as in the following example:
18736
18737
18738 @smallexample
18739 @iftex
18740 @leftskip=0.5cm
18741 @end iftex
18742 (@value{GDBP}) info tasks
18743 ID TID P-ID Pri State Name
18744 1 8088000 0 15 Child Activation Wait main_task
18745 2 80a4000 1 15 Accept Statement b
18746 3 809a800 1 15 Child Activation Wait a
18747 * 4 80ae800 3 15 Runnable c
18748
18749 @end smallexample
18750
18751 @noindent
18752 In this listing, the asterisk before the last task indicates it to be the
18753 task currently being inspected.
18754
18755 @table @asis
18756 @item ID
18757 Represents @value{GDBN}'s internal task number.
18758
18759 @item TID
18760 The Ada task ID.
18761
18762 @item P-ID
18763 The parent's task ID (@value{GDBN}'s internal task number).
18764
18765 @item Pri
18766 The base priority of the task.
18767
18768 @item State
18769 Current state of the task.
18770
18771 @table @code
18772 @item Unactivated
18773 The task has been created but has not been activated. It cannot be
18774 executing.
18775
18776 @item Runnable
18777 The task is not blocked for any reason known to Ada. (It may be waiting
18778 for a mutex, though.) It is conceptually "executing" in normal mode.
18779
18780 @item Terminated
18781 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18782 that were waiting on terminate alternatives have been awakened and have
18783 terminated themselves.
18784
18785 @item Child Activation Wait
18786 The task is waiting for created tasks to complete activation.
18787
18788 @item Accept Statement
18789 The task is waiting on an accept or selective wait statement.
18790
18791 @item Waiting on entry call
18792 The task is waiting on an entry call.
18793
18794 @item Async Select Wait
18795 The task is waiting to start the abortable part of an asynchronous
18796 select statement.
18797
18798 @item Delay Sleep
18799 The task is waiting on a select statement with only a delay
18800 alternative open.
18801
18802 @item Child Termination Wait
18803 The task is sleeping having completed a master within itself, and is
18804 waiting for the tasks dependent on that master to become terminated or
18805 waiting on a terminate Phase.
18806
18807 @item Wait Child in Term Alt
18808 The task is sleeping waiting for tasks on terminate alternatives to
18809 finish terminating.
18810
18811 @item Accepting RV with @var{taskno}
18812 The task is accepting a rendez-vous with the task @var{taskno}.
18813 @end table
18814
18815 @item Name
18816 Name of the task in the program.
18817
18818 @end table
18819
18820 @kindex info task @var{taskno}
18821 @item info task @var{taskno}
18822 This command shows detailed informations on the specified task, as in
18823 the following example:
18824 @smallexample
18825 @iftex
18826 @leftskip=0.5cm
18827 @end iftex
18828 (@value{GDBP}) info tasks
18829 ID TID P-ID Pri State Name
18830 1 8077880 0 15 Child Activation Wait main_task
18831 * 2 807c468 1 15 Runnable task_1
18832 (@value{GDBP}) info task 2
18833 Ada Task: 0x807c468
18834 Name: "task_1"
18835 Thread: 0
18836 LWP: 0x1fac
18837 Parent: 1 ("main_task")
18838 Base Priority: 15
18839 State: Runnable
18840 @end smallexample
18841
18842 @item task
18843 @kindex task@r{ (Ada)}
18844 @cindex current Ada task ID
18845 This command prints the ID and name of the current task.
18846
18847 @smallexample
18848 @iftex
18849 @leftskip=0.5cm
18850 @end iftex
18851 (@value{GDBP}) info tasks
18852 ID TID P-ID Pri State Name
18853 1 8077870 0 15 Child Activation Wait main_task
18854 * 2 807c458 1 15 Runnable some_task
18855 (@value{GDBP}) task
18856 [Current task is 2 "some_task"]
18857 @end smallexample
18858
18859 @item task @var{taskno}
18860 @cindex Ada task switching
18861 This command is like the @code{thread @var{thread-id}}
18862 command (@pxref{Threads}). It switches the context of debugging
18863 from the current task to the given task.
18864
18865 @smallexample
18866 @iftex
18867 @leftskip=0.5cm
18868 @end iftex
18869 (@value{GDBP}) info tasks
18870 ID TID P-ID Pri State Name
18871 1 8077870 0 15 Child Activation Wait main_task
18872 * 2 807c458 1 15 Runnable some_task
18873 (@value{GDBP}) task 1
18874 [Switching to task 1 "main_task"]
18875 #0 0x8067726 in pthread_cond_wait ()
18876 (@value{GDBP}) bt
18877 #0 0x8067726 in pthread_cond_wait ()
18878 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18879 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18880 #3 0x806153e in system.tasking.stages.activate_tasks ()
18881 #4 0x804aacc in un () at un.adb:5
18882 @end smallexample
18883
18884 @item task apply [@var{task-id-list} | all] [@var{flag}]@dots{} @var{command}
18885 The @code{task apply} command is the Ada tasking analogue of
18886 @code{thread apply} (@pxref{Threads}). It allows you to apply the
18887 named @var{command} to one or more tasks. Specify the tasks that you
18888 want affected using a list of task IDs, or specify @code{all} to apply
18889 to all tasks.
18890
18891 The @var{flag} arguments control what output to produce and how to
18892 handle errors raised when applying @var{command} to a task.
18893 @var{flag} must start with a @code{-} directly followed by one letter
18894 in @code{qcs}. If several flags are provided, they must be given
18895 individually, such as @code{-c -q}.
18896
18897 By default, @value{GDBN} displays some task information before the
18898 output produced by @var{command}, and an error raised during the
18899 execution of a @var{command} will abort @code{task apply}. The
18900 following flags can be used to fine-tune this behavior:
18901
18902 @table @code
18903 @item -c
18904 The flag @code{-c}, which stands for @samp{continue}, causes any
18905 errors in @var{command} to be displayed, and the execution of
18906 @code{task apply} then continues.
18907 @item -s
18908 The flag @code{-s}, which stands for @samp{silent}, causes any errors
18909 or empty output produced by a @var{command} to be silently ignored.
18910 That is, the execution continues, but the task information and errors
18911 are not printed.
18912 @item -q
18913 The flag @code{-q} (@samp{quiet}) disables printing the task
18914 information.
18915 @end table
18916
18917 Flags @code{-c} and @code{-s} cannot be used together.
18918
18919 @item break @var{locspec} task @var{taskno}
18920 @itemx break @var{locspec} task @var{taskno} if @dots{}
18921 @cindex breakpoints and tasks, in Ada
18922 @cindex task breakpoints, in Ada
18923 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18924 These commands are like the @code{break @dots{} thread @dots{}}
18925 command (@pxref{Thread Stops}). @xref{Location Specifications}, for
18926 the various forms of @var{locspec}.
18927
18928 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18929 to specify that you only want @value{GDBN} to stop the program when a
18930 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18931 numeric task identifiers assigned by @value{GDBN}, shown in the first
18932 column of the @samp{info tasks} display.
18933
18934 If you do not specify @samp{task @var{taskno}} when you set a
18935 breakpoint, the breakpoint applies to @emph{all} tasks of your
18936 program.
18937
18938 You can use the @code{task} qualifier on conditional breakpoints as
18939 well; in this case, place @samp{task @var{taskno}} before the
18940 breakpoint condition (before the @code{if}).
18941
18942 For example,
18943
18944 @smallexample
18945 @iftex
18946 @leftskip=0.5cm
18947 @end iftex
18948 (@value{GDBP}) info tasks
18949 ID TID P-ID Pri State Name
18950 1 140022020 0 15 Child Activation Wait main_task
18951 2 140045060 1 15 Accept/Select Wait t2
18952 3 140044840 1 15 Runnable t1
18953 * 4 140056040 1 15 Runnable t3
18954 (@value{GDBP}) b 15 task 2
18955 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18956 (@value{GDBP}) cont
18957 Continuing.
18958 task # 1 running
18959 task # 2 running
18960
18961 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18962 15 flush;
18963 (@value{GDBP}) info tasks
18964 ID TID P-ID Pri State Name
18965 1 140022020 0 15 Child Activation Wait main_task
18966 * 2 140045060 1 15 Runnable t2
18967 3 140044840 1 15 Runnable t1
18968 4 140056040 1 15 Delay Sleep t3
18969 @end smallexample
18970 @end table
18971
18972 @node Ada Tasks and Core Files
18973 @subsubsection Tasking Support when Debugging Core Files
18974 @cindex Ada tasking and core file debugging
18975
18976 When inspecting a core file, as opposed to debugging a live program,
18977 tasking support may be limited or even unavailable, depending on
18978 the platform being used.
18979 For instance, on x86-linux, the list of tasks is available, but task
18980 switching is not supported.
18981
18982 On certain platforms, the debugger needs to perform some
18983 memory writes in order to provide Ada tasking support. When inspecting
18984 a core file, this means that the core file must be opened with read-write
18985 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18986 Under these circumstances, you should make a backup copy of the core
18987 file before inspecting it with @value{GDBN}.
18988
18989 @node Ravenscar Profile
18990 @subsubsection Tasking Support when using the Ravenscar Profile
18991 @cindex Ravenscar Profile
18992
18993 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18994 specifically designed for systems with safety-critical real-time
18995 requirements.
18996
18997 @table @code
18998 @kindex set ravenscar task-switching on
18999 @cindex task switching with program using Ravenscar Profile
19000 @item set ravenscar task-switching on
19001 Allows task switching when debugging a program that uses the Ravenscar
19002 Profile. This is the default.
19003
19004 @kindex set ravenscar task-switching off
19005 @item set ravenscar task-switching off
19006 Turn off task switching when debugging a program that uses the Ravenscar
19007 Profile. This is mostly intended to disable the code that adds support
19008 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
19009 the Ravenscar runtime is preventing @value{GDBN} from working properly.
19010 To be effective, this command should be run before the program is started.
19011
19012 @kindex show ravenscar task-switching
19013 @item show ravenscar task-switching
19014 Show whether it is possible to switch from task to task in a program
19015 using the Ravenscar Profile.
19016
19017 @end table
19018
19019 @cindex Ravenscar thread
19020 When Ravenscar task-switching is enabled, Ravenscar tasks are
19021 announced by @value{GDBN} as if they were threads:
19022
19023 @smallexample
19024 (gdb) continue
19025 [New Ravenscar Thread 0x2b8f0]
19026 @end smallexample
19027
19028 Both Ravenscar tasks and the underlying CPU threads will show up in
19029 the output of @code{info threads}:
19030
19031 @smallexample
19032 (gdb) info threads
19033 Id Target Id Frame
19034 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
19035 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
19036 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
19037 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
19038 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
19039 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
19040 @end smallexample
19041
19042 One known limitation of the Ravenscar support in @value{GDBN} is that
19043 it isn't currently possible to single-step through the runtime
19044 initialization sequence. If you need to debug this code, you should
19045 use @code{set ravenscar task-switching off}.
19046
19047 @node Ada Source Character Set
19048 @subsubsection Ada Source Character Set
19049 @cindex Ada, source character set
19050
19051 The GNAT compiler supports a number of character sets for source
19052 files. @xref{Character Set Control, , Character Set Control,
19053 gnat_ugn}. @value{GDBN} includes support for this as well.
19054
19055 @table @code
19056 @item set ada source-charset @var{charset}
19057 @kindex set ada source-charset
19058 Set the source character set for Ada. The character set must be
19059 supported by GNAT. Because this setting affects the decoding of
19060 symbols coming from the debug information in your program, the setting
19061 should be set as early as possible. The default is @code{ISO-8859-1},
19062 because that is also GNAT's default.
19063
19064 @item show ada source-charset
19065 @kindex show ada source-charset
19066 Show the current source character set for Ada.
19067 @end table
19068
19069 @node Ada Glitches
19070 @subsubsection Known Peculiarities of Ada Mode
19071 @cindex Ada, problems
19072
19073 Besides the omissions listed previously (@pxref{Omissions from Ada}),
19074 we know of several problems with and limitations of Ada mode in
19075 @value{GDBN},
19076 some of which will be fixed with planned future releases of the debugger
19077 and the GNU Ada compiler.
19078
19079 @itemize @bullet
19080 @item
19081 Static constants that the compiler chooses not to materialize as objects in
19082 storage are invisible to the debugger.
19083
19084 @item
19085 Named parameter associations in function argument lists are ignored (the
19086 argument lists are treated as positional).
19087
19088 @item
19089 Many useful library packages are currently invisible to the debugger.
19090
19091 @item
19092 Fixed-point arithmetic, conversions, input, and output is carried out using
19093 floating-point arithmetic, and may give results that only approximate those on
19094 the host machine.
19095
19096 @item
19097 The GNAT compiler never generates the prefix @code{Standard} for any of
19098 the standard symbols defined by the Ada language. @value{GDBN} knows about
19099 this: it will strip the prefix from names when you use it, and will never
19100 look for a name you have so qualified among local symbols, nor match against
19101 symbols in other packages or subprograms. If you have
19102 defined entities anywhere in your program other than parameters and
19103 local variables whose simple names match names in @code{Standard},
19104 GNAT's lack of qualification here can cause confusion. When this happens,
19105 you can usually resolve the confusion
19106 by qualifying the problematic names with package
19107 @code{Standard} explicitly.
19108 @end itemize
19109
19110 Older versions of the compiler sometimes generate erroneous debugging
19111 information, resulting in the debugger incorrectly printing the value
19112 of affected entities. In some cases, the debugger is able to work
19113 around an issue automatically. In other cases, the debugger is able
19114 to work around the issue, but the work-around has to be specifically
19115 enabled.
19116
19117 @kindex set ada trust-PAD-over-XVS
19118 @kindex show ada trust-PAD-over-XVS
19119 @table @code
19120
19121 @item set ada trust-PAD-over-XVS on
19122 Configure GDB to strictly follow the GNAT encoding when computing the
19123 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
19124 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
19125 a complete description of the encoding used by the GNAT compiler).
19126 This is the default.
19127
19128 @item set ada trust-PAD-over-XVS off
19129 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
19130 sometimes prints the wrong value for certain entities, changing @code{ada
19131 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
19132 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
19133 @code{off}, but this incurs a slight performance penalty, so it is
19134 recommended to leave this setting to @code{on} unless necessary.
19135
19136 @end table
19137
19138 @cindex GNAT descriptive types
19139 @cindex GNAT encoding
19140 Internally, the debugger also relies on the compiler following a number
19141 of conventions known as the @samp{GNAT Encoding}, all documented in
19142 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
19143 how the debugging information should be generated for certain types.
19144 In particular, this convention makes use of @dfn{descriptive types},
19145 which are artificial types generated purely to help the debugger.
19146
19147 These encodings were defined at a time when the debugging information
19148 format used was not powerful enough to describe some of the more complex
19149 types available in Ada. Since DWARF allows us to express nearly all
19150 Ada features, the long-term goal is to slowly replace these descriptive
19151 types by their pure DWARF equivalent. To facilitate that transition,
19152 a new maintenance option is available to force the debugger to ignore
19153 those descriptive types. It allows the user to quickly evaluate how
19154 well @value{GDBN} works without them.
19155
19156 @table @code
19157
19158 @kindex maint ada set ignore-descriptive-types
19159 @item maintenance ada set ignore-descriptive-types [on|off]
19160 Control whether the debugger should ignore descriptive types.
19161 The default is not to ignore descriptives types (@code{off}).
19162
19163 @kindex maint ada show ignore-descriptive-types
19164 @item maintenance ada show ignore-descriptive-types
19165 Show if descriptive types are ignored by @value{GDBN}.
19166
19167 @end table
19168
19169 @node Unsupported Languages
19170 @section Unsupported Languages
19171
19172 @cindex unsupported languages
19173 @cindex minimal language
19174 In addition to the other fully-supported programming languages,
19175 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
19176 It does not represent a real programming language, but provides a set
19177 of capabilities close to what the C or assembly languages provide.
19178 This should allow most simple operations to be performed while debugging
19179 an application that uses a language currently not supported by @value{GDBN}.
19180
19181 If the language is set to @code{auto}, @value{GDBN} will automatically
19182 select this language if the current frame corresponds to an unsupported
19183 language.
19184
19185 @node Symbols
19186 @chapter Examining the Symbol Table
19187
19188 The commands described in this chapter allow you to inquire about the
19189 symbols (names of variables, functions and types) defined in your
19190 program. This information is inherent in the text of your program and
19191 does not change as your program executes. @value{GDBN} finds it in your
19192 program's symbol table, in the file indicated when you started @value{GDBN}
19193 (@pxref{File Options, ,Choosing Files}), or by one of the
19194 file-management commands (@pxref{Files, ,Commands to Specify Files}).
19195
19196 @cindex symbol names
19197 @cindex names of symbols
19198 @cindex quoting names
19199 @anchor{quoting names}
19200 Occasionally, you may need to refer to symbols that contain unusual
19201 characters, which @value{GDBN} ordinarily treats as word delimiters. The
19202 most frequent case is in referring to static variables in other
19203 source files (@pxref{Variables,,Program Variables}). File names
19204 are recorded in object files as debugging symbols, but @value{GDBN} would
19205 ordinarily parse a typical file name, like @file{foo.c}, as the three words
19206 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
19207 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
19208
19209 @smallexample
19210 p 'foo.c'::x
19211 @end smallexample
19212
19213 @noindent
19214 looks up the value of @code{x} in the scope of the file @file{foo.c}.
19215
19216 @table @code
19217 @cindex case-insensitive symbol names
19218 @cindex case sensitivity in symbol names
19219 @kindex set case-sensitive
19220 @item set case-sensitive on
19221 @itemx set case-sensitive off
19222 @itemx set case-sensitive auto
19223 Normally, when @value{GDBN} looks up symbols, it matches their names
19224 with case sensitivity determined by the current source language.
19225 Occasionally, you may wish to control that. The command @code{set
19226 case-sensitive} lets you do that by specifying @code{on} for
19227 case-sensitive matches or @code{off} for case-insensitive ones. If
19228 you specify @code{auto}, case sensitivity is reset to the default
19229 suitable for the source language. The default is case-sensitive
19230 matches for all languages except for Fortran, for which the default is
19231 case-insensitive matches.
19232
19233 @kindex show case-sensitive
19234 @item show case-sensitive
19235 This command shows the current setting of case sensitivity for symbols
19236 lookups.
19237
19238 @kindex set print type methods
19239 @item set print type methods
19240 @itemx set print type methods on
19241 @itemx set print type methods off
19242 Normally, when @value{GDBN} prints a class, it displays any methods
19243 declared in that class. You can control this behavior either by
19244 passing the appropriate flag to @code{ptype}, or using @command{set
19245 print type methods}. Specifying @code{on} will cause @value{GDBN} to
19246 display the methods; this is the default. Specifying @code{off} will
19247 cause @value{GDBN} to omit the methods.
19248
19249 @kindex show print type methods
19250 @item show print type methods
19251 This command shows the current setting of method display when printing
19252 classes.
19253
19254 @kindex set print type nested-type-limit
19255 @item set print type nested-type-limit @var{limit}
19256 @itemx set print type nested-type-limit unlimited
19257 Set the limit of displayed nested types that the type printer will
19258 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
19259 nested definitions. By default, the type printer will not show any nested
19260 types defined in classes.
19261
19262 @kindex show print type nested-type-limit
19263 @item show print type nested-type-limit
19264 This command shows the current display limit of nested types when
19265 printing classes.
19266
19267 @kindex set print type typedefs
19268 @item set print type typedefs
19269 @itemx set print type typedefs on
19270 @itemx set print type typedefs off
19271
19272 Normally, when @value{GDBN} prints a class, it displays any typedefs
19273 defined in that class. You can control this behavior either by
19274 passing the appropriate flag to @code{ptype}, or using @command{set
19275 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
19276 display the typedef definitions; this is the default. Specifying
19277 @code{off} will cause @value{GDBN} to omit the typedef definitions.
19278 Note that this controls whether the typedef definition itself is
19279 printed, not whether typedef names are substituted when printing other
19280 types.
19281
19282 @kindex show print type typedefs
19283 @item show print type typedefs
19284 This command shows the current setting of typedef display when
19285 printing classes.
19286
19287 @kindex set print type hex
19288 @item set print type hex
19289 @itemx set print type hex on
19290 @itemx set print type hex off
19291
19292 When @value{GDBN} prints sizes and offsets of struct members, it can use
19293 either the decimal or hexadecimal notation. You can select one or the
19294 other either by passing the appropriate flag to @code{ptype}, or by using
19295 the @command{set print type hex} command.
19296
19297 @kindex show print type hex
19298 @item show print type hex
19299 This command shows whether the sizes and offsets of struct members are
19300 printed in decimal or hexadecimal notation.
19301
19302 @kindex info address
19303 @cindex address of a symbol
19304 @item info address @var{symbol}
19305 Describe where the data for @var{symbol} is stored. For a register
19306 variable, this says which register it is kept in. For a non-register
19307 local variable, this prints the stack-frame offset at which the variable
19308 is always stored.
19309
19310 Note the contrast with @samp{print &@var{symbol}}, which does not work
19311 at all for a register variable, and for a stack local variable prints
19312 the exact address of the current instantiation of the variable.
19313
19314 @kindex info symbol
19315 @cindex symbol from address
19316 @cindex closest symbol and offset for an address
19317 @item info symbol @var{addr}
19318 Print the name of a symbol which is stored at the address @var{addr}.
19319 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
19320 nearest symbol and an offset from it:
19321
19322 @smallexample
19323 (@value{GDBP}) info symbol 0x54320
19324 _initialize_vx + 396 in section .text
19325 @end smallexample
19326
19327 @noindent
19328 This is the opposite of the @code{info address} command. You can use
19329 it to find out the name of a variable or a function given its address.
19330
19331 For dynamically linked executables, the name of executable or shared
19332 library containing the symbol is also printed:
19333
19334 @smallexample
19335 (@value{GDBP}) info symbol 0x400225
19336 _start + 5 in section .text of /tmp/a.out
19337 (@value{GDBP}) info symbol 0x2aaaac2811cf
19338 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
19339 @end smallexample
19340
19341 @kindex demangle
19342 @cindex demangle
19343 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
19344 Demangle @var{name}.
19345 If @var{language} is provided it is the name of the language to demangle
19346 @var{name} in. Otherwise @var{name} is demangled in the current language.
19347
19348 The @samp{--} option specifies the end of options,
19349 and is useful when @var{name} begins with a dash.
19350
19351 The parameter @code{demangle-style} specifies how to interpret the kind
19352 of mangling used. @xref{Print Settings}.
19353
19354 @kindex whatis
19355 @item whatis[/@var{flags}] [@var{arg}]
19356 Print the data type of @var{arg}, which can be either an expression
19357 or a name of a data type. With no argument, print the data type of
19358 @code{$}, the last value in the value history.
19359
19360 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
19361 is not actually evaluated, and any side-effecting operations (such as
19362 assignments or function calls) inside it do not take place.
19363
19364 If @var{arg} is a variable or an expression, @code{whatis} prints its
19365 literal type as it is used in the source code. If the type was
19366 defined using a @code{typedef}, @code{whatis} will @emph{not} print
19367 the data type underlying the @code{typedef}. If the type of the
19368 variable or the expression is a compound data type, such as
19369 @code{struct} or @code{class}, @code{whatis} never prints their
19370 fields or methods. It just prints the @code{struct}/@code{class}
19371 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
19372 such a compound data type, use @code{ptype}.
19373
19374 If @var{arg} is a type name that was defined using @code{typedef},
19375 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
19376 Unrolling means that @code{whatis} will show the underlying type used
19377 in the @code{typedef} declaration of @var{arg}. However, if that
19378 underlying type is also a @code{typedef}, @code{whatis} will not
19379 unroll it.
19380
19381 For C code, the type names may also have the form @samp{class
19382 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
19383 @var{union-tag}} or @samp{enum @var{enum-tag}}.
19384
19385 @var{flags} can be used to modify how the type is displayed.
19386 Available flags are:
19387
19388 @table @code
19389 @item r
19390 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
19391 parameters and typedefs defined in a class when printing the class'
19392 members. The @code{/r} flag disables this.
19393
19394 @item m
19395 Do not print methods defined in the class.
19396
19397 @item M
19398 Print methods defined in the class. This is the default, but the flag
19399 exists in case you change the default with @command{set print type methods}.
19400
19401 @item t
19402 Do not print typedefs defined in the class. Note that this controls
19403 whether the typedef definition itself is printed, not whether typedef
19404 names are substituted when printing other types.
19405
19406 @item T
19407 Print typedefs defined in the class. This is the default, but the flag
19408 exists in case you change the default with @command{set print type typedefs}.
19409
19410 @item o
19411 Print the offsets and sizes of fields in a struct, similar to what the
19412 @command{pahole} tool does. This option implies the @code{/tm} flags.
19413
19414 @item x
19415 Use hexadecimal notation when printing offsets and sizes of fields in a
19416 struct.
19417
19418 @item d
19419 Use decimal notation when printing offsets and sizes of fields in a
19420 struct.
19421
19422 For example, given the following declarations:
19423
19424 @smallexample
19425 struct tuv
19426 @{
19427 int a1;
19428 char *a2;
19429 int a3;
19430 @};
19431
19432 struct xyz
19433 @{
19434 int f1;
19435 char f2;
19436 void *f3;
19437 struct tuv f4;
19438 @};
19439
19440 union qwe
19441 @{
19442 struct tuv fff1;
19443 struct xyz fff2;
19444 @};
19445
19446 struct tyu
19447 @{
19448 int a1 : 1;
19449 int a2 : 3;
19450 int a3 : 23;
19451 char a4 : 2;
19452 int64_t a5;
19453 int a6 : 5;
19454 int64_t a7 : 3;
19455 @};
19456 @end smallexample
19457
19458 Issuing a @kbd{ptype /o struct tuv} command would print:
19459
19460 @smallexample
19461 (@value{GDBP}) ptype /o struct tuv
19462 /* offset | size */ type = struct tuv @{
19463 /* 0 | 4 */ int a1;
19464 /* XXX 4-byte hole */
19465 /* 8 | 8 */ char *a2;
19466 /* 16 | 4 */ int a3;
19467
19468 /* total size (bytes): 24 */
19469 @}
19470 @end smallexample
19471
19472 Notice the format of the first column of comments. There, you can
19473 find two parts separated by the @samp{|} character: the @emph{offset},
19474 which indicates where the field is located inside the struct, in
19475 bytes, and the @emph{size} of the field. Another interesting line is
19476 the marker of a @emph{hole} in the struct, indicating that it may be
19477 possible to pack the struct and make it use less space by reorganizing
19478 its fields.
19479
19480 It is also possible to print offsets inside an union:
19481
19482 @smallexample
19483 (@value{GDBP}) ptype /o union qwe
19484 /* offset | size */ type = union qwe @{
19485 /* 24 */ struct tuv @{
19486 /* 0 | 4 */ int a1;
19487 /* XXX 4-byte hole */
19488 /* 8 | 8 */ char *a2;
19489 /* 16 | 4 */ int a3;
19490
19491 /* total size (bytes): 24 */
19492 @} fff1;
19493 /* 40 */ struct xyz @{
19494 /* 0 | 4 */ int f1;
19495 /* 4 | 1 */ char f2;
19496 /* XXX 3-byte hole */
19497 /* 8 | 8 */ void *f3;
19498 /* 16 | 24 */ struct tuv @{
19499 /* 16 | 4 */ int a1;
19500 /* XXX 4-byte hole */
19501 /* 24 | 8 */ char *a2;
19502 /* 32 | 4 */ int a3;
19503
19504 /* total size (bytes): 24 */
19505 @} f4;
19506
19507 /* total size (bytes): 40 */
19508 @} fff2;
19509
19510 /* total size (bytes): 40 */
19511 @}
19512 @end smallexample
19513
19514 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
19515 same space (because we are dealing with an union), the offset is not
19516 printed for them. However, you can still examine the offset of each
19517 of these structures' fields.
19518
19519 Another useful scenario is printing the offsets of a struct containing
19520 bitfields:
19521
19522 @smallexample
19523 (@value{GDBP}) ptype /o struct tyu
19524 /* offset | size */ type = struct tyu @{
19525 /* 0:31 | 4 */ int a1 : 1;
19526 /* 0:28 | 4 */ int a2 : 3;
19527 /* 0: 5 | 4 */ int a3 : 23;
19528 /* 3: 3 | 1 */ signed char a4 : 2;
19529 /* XXX 3-bit hole */
19530 /* XXX 4-byte hole */
19531 /* 8 | 8 */ int64_t a5;
19532 /* 16: 0 | 4 */ int a6 : 5;
19533 /* 16: 5 | 8 */ int64_t a7 : 3;
19534 /* XXX 7-byte padding */
19535
19536 /* total size (bytes): 24 */
19537 @}
19538 @end smallexample
19539
19540 Note how the offset information is now extended to also include the
19541 first bit of the bitfield.
19542 @end table
19543
19544 @kindex ptype
19545 @item ptype[/@var{flags}] [@var{arg}]
19546 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
19547 detailed description of the type, instead of just the name of the type.
19548 @xref{Expressions, ,Expressions}.
19549
19550 Contrary to @code{whatis}, @code{ptype} always unrolls any
19551 @code{typedef}s in its argument declaration, whether the argument is
19552 a variable, expression, or a data type. This means that @code{ptype}
19553 of a variable or an expression will not print literally its type as
19554 present in the source code---use @code{whatis} for that. @code{typedef}s at
19555 the pointer or reference targets are also unrolled. Only @code{typedef}s of
19556 fields, methods and inner @code{class typedef}s of @code{struct}s,
19557 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
19558
19559 For example, for this variable declaration:
19560
19561 @smallexample
19562 typedef double real_t;
19563 struct complex @{ real_t real; double imag; @};
19564 typedef struct complex complex_t;
19565 complex_t var;
19566 real_t *real_pointer_var;
19567 @end smallexample
19568
19569 @noindent
19570 the two commands give this output:
19571
19572 @smallexample
19573 @group
19574 (@value{GDBP}) whatis var
19575 type = complex_t
19576 (@value{GDBP}) ptype var
19577 type = struct complex @{
19578 real_t real;
19579 double imag;
19580 @}
19581 (@value{GDBP}) whatis complex_t
19582 type = struct complex
19583 (@value{GDBP}) whatis struct complex
19584 type = struct complex
19585 (@value{GDBP}) ptype struct complex
19586 type = struct complex @{
19587 real_t real;
19588 double imag;
19589 @}
19590 (@value{GDBP}) whatis real_pointer_var
19591 type = real_t *
19592 (@value{GDBP}) ptype real_pointer_var
19593 type = double *
19594 @end group
19595 @end smallexample
19596
19597 @noindent
19598 As with @code{whatis}, using @code{ptype} without an argument refers to
19599 the type of @code{$}, the last value in the value history.
19600
19601 @cindex incomplete type
19602 Sometimes, programs use opaque data types or incomplete specifications
19603 of complex data structure. If the debug information included in the
19604 program does not allow @value{GDBN} to display a full declaration of
19605 the data type, it will say @samp{<incomplete type>}. For example,
19606 given these declarations:
19607
19608 @smallexample
19609 struct foo;
19610 struct foo *fooptr;
19611 @end smallexample
19612
19613 @noindent
19614 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19615
19616 @smallexample
19617 (@value{GDBP}) ptype foo
19618 $1 = <incomplete type>
19619 @end smallexample
19620
19621 @noindent
19622 ``Incomplete type'' is C terminology for data types that are not
19623 completely specified.
19624
19625 @cindex unknown type
19626 Othertimes, information about a variable's type is completely absent
19627 from the debug information included in the program. This most often
19628 happens when the program or library where the variable is defined
19629 includes no debug information at all. @value{GDBN} knows the variable
19630 exists from inspecting the linker/loader symbol table (e.g., the ELF
19631 dynamic symbol table), but such symbols do not contain type
19632 information. Inspecting the type of a (global) variable for which
19633 @value{GDBN} has no type information shows:
19634
19635 @smallexample
19636 (@value{GDBP}) ptype var
19637 type = <data variable, no debug info>
19638 @end smallexample
19639
19640 @xref{Variables, no debug info variables}, for how to print the values
19641 of such variables.
19642
19643 @kindex info types
19644 @item info types [-q] [@var{regexp}]
19645 Print a brief description of all types whose names match the regular
19646 expression @var{regexp} (or all types in your program, if you supply
19647 no argument). Each complete typename is matched as though it were a
19648 complete line; thus, @samp{i type value} gives information on all
19649 types in your program whose names include the string @code{value}, but
19650 @samp{i type ^value$} gives information only on types whose complete
19651 name is @code{value}.
19652
19653 In programs using different languages, @value{GDBN} chooses the syntax
19654 to print the type description according to the
19655 @samp{set language} value: using @samp{set language auto}
19656 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19657 language of the type, other values mean to use
19658 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19659
19660 This command differs from @code{ptype} in two ways: first, like
19661 @code{whatis}, it does not print a detailed description; second, it
19662 lists all source files and line numbers where a type is defined.
19663
19664 The output from @samp{into types} is proceeded with a header line
19665 describing what types are being listed. The optional flag @samp{-q},
19666 which stands for @samp{quiet}, disables printing this header
19667 information.
19668
19669 @kindex info type-printers
19670 @item info type-printers
19671 Versions of @value{GDBN} that ship with Python scripting enabled may
19672 have ``type printers'' available. When using @command{ptype} or
19673 @command{whatis}, these printers are consulted when the name of a type
19674 is needed. @xref{Type Printing API}, for more information on writing
19675 type printers.
19676
19677 @code{info type-printers} displays all the available type printers.
19678
19679 @kindex enable type-printer
19680 @kindex disable type-printer
19681 @item enable type-printer @var{name}@dots{}
19682 @item disable type-printer @var{name}@dots{}
19683 These commands can be used to enable or disable type printers.
19684
19685 @kindex info scope
19686 @cindex local variables
19687 @item info scope @var{locspec}
19688 List all the variables local to the lexical scope of the code location
19689 that results from resolving @var{locspec}. @xref{Location
19690 Specifications}, for details about supported forms of @var{locspec}.
19691 For example:
19692
19693 @smallexample
19694 (@value{GDBP}) @b{info scope command_line_handler}
19695 Scope for command_line_handler:
19696 Symbol rl is an argument at stack/frame offset 8, length 4.
19697 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19698 Symbol linelength is in static storage at address 0x150a1c, length 4.
19699 Symbol p is a local variable in register $esi, length 4.
19700 Symbol p1 is a local variable in register $ebx, length 4.
19701 Symbol nline is a local variable in register $edx, length 4.
19702 Symbol repeat is a local variable at frame offset -8, length 4.
19703 @end smallexample
19704
19705 @noindent
19706 This command is especially useful for determining what data to collect
19707 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19708 collect}.
19709
19710 @kindex info source
19711 @item info source
19712 Show information about the current source file---that is, the source file for
19713 the function containing the current point of execution:
19714 @itemize @bullet
19715 @item
19716 the name of the source file, and the directory containing it,
19717 @item
19718 the directory it was compiled in,
19719 @item
19720 its length, in lines,
19721 @item
19722 which programming language it is written in,
19723 @item
19724 if the debug information provides it, the program that compiled the file
19725 (which may include, e.g., the compiler version and command line arguments),
19726 @item
19727 whether the executable includes debugging information for that file, and
19728 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19729 @item
19730 whether the debugging information includes information about
19731 preprocessor macros.
19732 @end itemize
19733
19734
19735 @kindex info sources
19736 @item info sources @r{[}-dirname | -basename@r{]} @r{[}--@r{]} @r{[}@var{regexp}@r{]}
19737
19738
19739 With no options @samp{info sources} prints the names of all source
19740 files in your program for which there is debugging information. The
19741 source files are presented based on a list of object files
19742 (executables and libraries) currently loaded into @value{GDBN}. For
19743 each object file all of the associated source files are listed.
19744
19745 Each source file will only be printed once for each object file, but a
19746 single source file can be repeated in the output if it is part of
19747 multiple object files.
19748
19749 If the optional @var{regexp} is provided, then only source files that
19750 match the regular expression will be printed. The matching is
19751 case-sensitive, except on operating systems that have case-insensitive
19752 filesystem (e.g., MS-Windows). @samp{--} can be used before
19753 @var{regexp} to prevent @value{GDBN} interpreting @var{regexp} as a
19754 command option (e.g. if @var{regexp} starts with @samp{-}).
19755
19756 By default, the @var{regexp} is used to match anywhere in the
19757 filename. If @code{-dirname}, only files having a dirname matching
19758 @var{regexp} are shown. If @code{-basename}, only files having a
19759 basename matching @var{regexp} are shown.
19760
19761 It is possible that an object file may be printed in the list with no
19762 associated source files. This can happen when either no source files
19763 match @var{regexp}, or, the object file was compiled without debug
19764 information and so @value{GDBN} is unable to find any source file
19765 names.
19766
19767 @kindex info functions
19768 @item info functions [-q] [-n]
19769 Print the names and data types of all defined functions.
19770 Similarly to @samp{info types}, this command groups its output by source
19771 files and annotates each function definition with its source line
19772 number.
19773
19774 In programs using different languages, @value{GDBN} chooses the syntax
19775 to print the function name and type according to the
19776 @samp{set language} value: using @samp{set language auto}
19777 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19778 language of the function, other values mean to use
19779 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19780
19781 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19782 results. A non-debugging symbol is a symbol that comes from the
19783 executable's symbol table, not from the debug information (for
19784 example, DWARF) associated with the executable.
19785
19786 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19787 printing header information and messages explaining why no functions
19788 have been printed.
19789
19790 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19791 Like @samp{info functions}, but only print the names and data types
19792 of the functions selected with the provided regexp(s).
19793
19794 If @var{regexp} is provided, print only the functions whose names
19795 match the regular expression @var{regexp}.
19796 Thus, @samp{info fun step} finds all functions whose
19797 names include @code{step}; @samp{info fun ^step} finds those whose names
19798 start with @code{step}. If a function name contains characters that
19799 conflict with the regular expression language (e.g.@:
19800 @samp{operator*()}), they may be quoted with a backslash.
19801
19802 If @var{type_regexp} is provided, print only the functions whose
19803 types, as printed by the @code{whatis} command, match
19804 the regular expression @var{type_regexp}.
19805 If @var{type_regexp} contains space(s), it should be enclosed in
19806 quote characters. If needed, use backslash to escape the meaning
19807 of special characters or quotes.
19808 Thus, @samp{info fun -t '^int ('} finds the functions that return
19809 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19810 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19811 finds the functions whose names start with @code{step} and that return
19812 int.
19813
19814 If both @var{regexp} and @var{type_regexp} are provided, a function
19815 is printed only if its name matches @var{regexp} and its type matches
19816 @var{type_regexp}.
19817
19818
19819 @kindex info variables
19820 @item info variables [-q] [-n]
19821 Print the names and data types of all variables that are defined
19822 outside of functions (i.e.@: excluding local variables).
19823 The printed variables are grouped by source files and annotated with
19824 their respective source line numbers.
19825
19826 In programs using different languages, @value{GDBN} chooses the syntax
19827 to print the variable name and type according to the
19828 @samp{set language} value: using @samp{set language auto}
19829 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19830 language of the variable, other values mean to use
19831 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19832
19833 The @samp{-n} flag excludes non-debugging symbols from the results.
19834
19835 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19836 printing header information and messages explaining why no variables
19837 have been printed.
19838
19839 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19840 Like @kbd{info variables}, but only print the variables selected
19841 with the provided regexp(s).
19842
19843 If @var{regexp} is provided, print only the variables whose names
19844 match the regular expression @var{regexp}.
19845
19846 If @var{type_regexp} is provided, print only the variables whose
19847 types, as printed by the @code{whatis} command, match
19848 the regular expression @var{type_regexp}.
19849 If @var{type_regexp} contains space(s), it should be enclosed in
19850 quote characters. If needed, use backslash to escape the meaning
19851 of special characters or quotes.
19852
19853 If both @var{regexp} and @var{type_regexp} are provided, an argument
19854 is printed only if its name matches @var{regexp} and its type matches
19855 @var{type_regexp}.
19856
19857 @kindex info modules
19858 @cindex modules
19859 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19860 List all Fortran modules in the program, or all modules matching the
19861 optional regular expression @var{regexp}.
19862
19863 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19864 printing header information and messages explaining why no modules
19865 have been printed.
19866
19867 @kindex info module
19868 @cindex Fortran modules, information about
19869 @cindex functions and variables by Fortran module
19870 @cindex module functions and variables
19871 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19872 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19873 List all functions or variables within all Fortran modules. The set
19874 of functions or variables listed can be limited by providing some or
19875 all of the optional regular expressions. If @var{module-regexp} is
19876 provided, then only Fortran modules matching @var{module-regexp} will
19877 be searched. Only functions or variables whose type matches the
19878 optional regular expression @var{type-regexp} will be listed. And
19879 only functions or variables whose name matches the optional regular
19880 expression @var{regexp} will be listed.
19881
19882 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19883 printing header information and messages explaining why no functions
19884 or variables have been printed.
19885
19886 @kindex info classes
19887 @cindex Objective-C, classes and selectors
19888 @item info classes
19889 @itemx info classes @var{regexp}
19890 Display all Objective-C classes in your program, or
19891 (with the @var{regexp} argument) all those matching a particular regular
19892 expression.
19893
19894 @kindex info selectors
19895 @item info selectors
19896 @itemx info selectors @var{regexp}
19897 Display all Objective-C selectors in your program, or
19898 (with the @var{regexp} argument) all those matching a particular regular
19899 expression.
19900
19901 @ignore
19902 This was never implemented.
19903 @kindex info methods
19904 @item info methods
19905 @itemx info methods @var{regexp}
19906 The @code{info methods} command permits the user to examine all defined
19907 methods within C@t{++} program, or (with the @var{regexp} argument) a
19908 specific set of methods found in the various C@t{++} classes. Many
19909 C@t{++} classes provide a large number of methods. Thus, the output
19910 from the @code{ptype} command can be overwhelming and hard to use. The
19911 @code{info-methods} command filters the methods, printing only those
19912 which match the regular-expression @var{regexp}.
19913 @end ignore
19914
19915 @cindex opaque data types
19916 @kindex set opaque-type-resolution
19917 @item set opaque-type-resolution on
19918 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19919 declared as a pointer to a @code{struct}, @code{class}, or
19920 @code{union}---for example, @code{struct MyType *}---that is used in one
19921 source file although the full declaration of @code{struct MyType} is in
19922 another source file. The default is on.
19923
19924 A change in the setting of this subcommand will not take effect until
19925 the next time symbols for a file are loaded.
19926
19927 @item set opaque-type-resolution off
19928 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19929 is printed as follows:
19930 @smallexample
19931 @{<no data fields>@}
19932 @end smallexample
19933
19934 @kindex show opaque-type-resolution
19935 @item show opaque-type-resolution
19936 Show whether opaque types are resolved or not.
19937
19938 @kindex set print symbol-loading
19939 @cindex print messages when symbols are loaded
19940 @item set print symbol-loading
19941 @itemx set print symbol-loading full
19942 @itemx set print symbol-loading brief
19943 @itemx set print symbol-loading off
19944 The @code{set print symbol-loading} command allows you to control the
19945 printing of messages when @value{GDBN} loads symbol information.
19946 By default a message is printed for the executable and one for each
19947 shared library, and normally this is what you want. However, when
19948 debugging apps with large numbers of shared libraries these messages
19949 can be annoying.
19950 When set to @code{brief} a message is printed for each executable,
19951 and when @value{GDBN} loads a collection of shared libraries at once
19952 it will only print one message regardless of the number of shared
19953 libraries. When set to @code{off} no messages are printed.
19954
19955 @kindex show print symbol-loading
19956 @item show print symbol-loading
19957 Show whether messages will be printed when a @value{GDBN} command
19958 entered from the keyboard causes symbol information to be loaded.
19959
19960 @kindex maint print symbols
19961 @cindex symbol dump
19962 @kindex maint print psymbols
19963 @cindex partial symbol dump
19964 @kindex maint print msymbols
19965 @cindex minimal symbol dump
19966 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19967 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19968 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19969 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19970 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19971 Write a dump of debugging symbol data into the file @var{filename} or
19972 the terminal if @var{filename} is unspecified.
19973 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19974 that objfile.
19975 If @code{-pc @var{address}} is specified, only dump symbols for the file
19976 with code at that address. Note that @var{address} may be a symbol like
19977 @code{main}.
19978 If @code{-source @var{source}} is specified, only dump symbols for that
19979 source file.
19980
19981 These commands are used to debug the @value{GDBN} symbol-reading code.
19982 These commands do not modify internal @value{GDBN} state, therefore
19983 @samp{maint print symbols} will only print symbols for already expanded symbol
19984 tables.
19985 You can use the command @code{info sources} to find out which files these are.
19986 If you use @samp{maint print psymbols} instead, the dump shows information
19987 about symbols that @value{GDBN} only knows partially---that is, symbols
19988 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19989 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19990 ``ELF symbols''.
19991
19992 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19993 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19994
19995 @kindex maint info symtabs
19996 @kindex maint info psymtabs
19997 @cindex listing @value{GDBN}'s internal symbol tables
19998 @cindex symbol tables, listing @value{GDBN}'s internal
19999 @cindex full symbol tables, listing @value{GDBN}'s internal
20000 @cindex partial symbol tables, listing @value{GDBN}'s internal
20001 @item maint info symtabs @r{[} @var{regexp} @r{]}
20002 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
20003
20004 List the @code{struct symtab} or @code{struct partial_symtab}
20005 structures whose names match @var{regexp}. If @var{regexp} is not
20006 given, list them all. The output includes expressions which you can
20007 copy into a @value{GDBN} debugging this one to examine a particular
20008 structure in more detail. For example:
20009
20010 @smallexample
20011 (@value{GDBP}) maint info psymtabs dwarf2read
20012 @{ objfile /home/gnu/build/gdb/gdb
20013 ((struct objfile *) 0x82e69d0)
20014 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
20015 ((struct partial_symtab *) 0x8474b10)
20016 readin no
20017 fullname (null)
20018 text addresses 0x814d3c8 -- 0x8158074
20019 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
20020 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
20021 dependencies (none)
20022 @}
20023 @}
20024 (@value{GDBP}) maint info symtabs
20025 (@value{GDBP})
20026 @end smallexample
20027 @noindent
20028 We see that there is one partial symbol table whose filename contains
20029 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
20030 and we see that @value{GDBN} has not read in any symtabs yet at all.
20031 If we set a breakpoint on a function, that will cause @value{GDBN} to
20032 read the symtab for the compilation unit containing that function:
20033
20034 @smallexample
20035 (@value{GDBP}) break dwarf2_psymtab_to_symtab
20036 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
20037 line 1574.
20038 (@value{GDBP}) maint info symtabs
20039 @{ objfile /home/gnu/build/gdb/gdb
20040 ((struct objfile *) 0x82e69d0)
20041 @{ symtab /home/gnu/src/gdb/dwarf2read.c
20042 ((struct symtab *) 0x86c1f38)
20043 dirname (null)
20044 fullname (null)
20045 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
20046 linetable ((struct linetable *) 0x8370fa0)
20047 debugformat DWARF 2
20048 @}
20049 @}
20050 (@value{GDBP})
20051 @end smallexample
20052
20053 @kindex maint info line-table
20054 @cindex listing @value{GDBN}'s internal line tables
20055 @cindex line tables, listing @value{GDBN}'s internal
20056 @item maint info line-table @r{[} @var{regexp} @r{]}
20057
20058 List the @code{struct linetable} from all @code{struct symtab}
20059 instances whose name matches @var{regexp}. If @var{regexp} is not
20060 given, list the @code{struct linetable} from all @code{struct symtab}.
20061 For example:
20062
20063 @smallexample
20064 (@value{GDBP}) maint info line-table
20065 objfile: /home/gnu/build/a.out ((struct objfile *) 0x6120000e0d40)
20066 compunit_symtab: simple.cpp ((struct compunit_symtab *) 0x6210000ff450)
20067 symtab: /home/gnu/src/simple.cpp ((struct symtab *) 0x6210000ff4d0)
20068 linetable: ((struct linetable *) 0x62100012b760):
20069 INDEX LINE ADDRESS IS-STMT PROLOGUE-END
20070 0 3 0x0000000000401110 Y
20071 1 4 0x0000000000401114 Y Y
20072 2 9 0x0000000000401120 Y
20073 3 10 0x0000000000401124 Y Y
20074 4 10 0x0000000000401129
20075 5 15 0x0000000000401130 Y
20076 6 16 0x0000000000401134 Y Y
20077 7 16 0x0000000000401139
20078 8 21 0x0000000000401140 Y
20079 9 22 0x000000000040114f Y Y
20080 10 22 0x0000000000401154
20081 11 END 0x000000000040115a Y
20082 @end smallexample
20083 @noindent
20084 The @samp{IS-STMT} column indicates if the address is a recommended breakpoint
20085 location to represent a line or a statement. The @samp{PROLOGUE-END} column
20086 indicates that a given address is an adequate place to set a breakpoint at the
20087 first instruction following a function prologue.
20088
20089 @kindex maint set symbol-cache-size
20090 @cindex symbol cache size
20091 @item maint set symbol-cache-size @var{size}
20092 Set the size of the symbol cache to @var{size}.
20093 The default size is intended to be good enough for debugging
20094 most applications. This option exists to allow for experimenting
20095 with different sizes.
20096
20097 @kindex maint show symbol-cache-size
20098 @item maint show symbol-cache-size
20099 Show the size of the symbol cache.
20100
20101 @kindex maint print symbol-cache
20102 @cindex symbol cache, printing its contents
20103 @item maint print symbol-cache
20104 Print the contents of the symbol cache.
20105 This is useful when debugging symbol cache issues.
20106
20107 @kindex maint print symbol-cache-statistics
20108 @cindex symbol cache, printing usage statistics
20109 @item maint print symbol-cache-statistics
20110 Print symbol cache usage statistics.
20111 This helps determine how well the cache is being utilized.
20112
20113 @kindex maint flush symbol-cache
20114 @kindex maint flush-symbol-cache
20115 @cindex symbol cache, flushing
20116 @item maint flush symbol-cache
20117 @itemx maint flush-symbol-cache
20118 Flush the contents of the symbol cache, all entries are removed. This
20119 command is useful when debugging the symbol cache. It is also useful
20120 when collecting performance data. The command @code{maint
20121 flush-symbol-cache} is deprecated in favor of @code{maint flush
20122 symbol-cache}..
20123
20124 @kindex maint set ignore-prologue-end-flag
20125 @cindex prologue-end
20126 @item maint set ignore-prologue-end-flag [on|off]
20127 Enable or disable the use of the @samp{PROLOGUE-END} flag from the line-table.
20128 When @samp{off} (the default), @value{GDBN} uses the @samp{PROLOGUE-END} flag
20129 to place breakpoints past the end of a function prologue. When @samp{on},
20130 @value{GDBN} ignores the flag and relies on prologue analyzers to skip function
20131 prologues.
20132
20133 @kindex maint show ignore-prologue-end-flag
20134 @item maint show ignore-prologue-end-flag
20135 Show whether @value{GDBN} will ignore the @samp{PROLOGUE-END} flag.
20136
20137 @end table
20138
20139 @node Altering
20140 @chapter Altering Execution
20141
20142 Once you think you have found an error in your program, you might want to
20143 find out for certain whether correcting the apparent error would lead to
20144 correct results in the rest of the run. You can find the answer by
20145 experiment, using the @value{GDBN} features for altering execution of the
20146 program.
20147
20148 For example, you can store new values into variables or memory
20149 locations, give your program a signal, restart it at a different
20150 address, or even return prematurely from a function.
20151
20152 @menu
20153 * Assignment:: Assignment to variables
20154 * Jumping:: Continuing at a different address
20155 * Signaling:: Giving your program a signal
20156 * Returning:: Returning from a function
20157 * Calling:: Calling your program's functions
20158 * Patching:: Patching your program
20159 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
20160 @end menu
20161
20162 @node Assignment
20163 @section Assignment to Variables
20164
20165 @cindex assignment
20166 @cindex setting variables
20167 To alter the value of a variable, evaluate an assignment expression.
20168 @xref{Expressions, ,Expressions}. For example,
20169
20170 @smallexample
20171 print x=4
20172 @end smallexample
20173
20174 @noindent
20175 stores the value 4 into the variable @code{x}, and then prints the
20176 value of the assignment expression (which is 4).
20177 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
20178 information on operators in supported languages.
20179
20180 @kindex set variable
20181 @cindex variables, setting
20182 If you are not interested in seeing the value of the assignment, use the
20183 @code{set} command instead of the @code{print} command. @code{set} is
20184 really the same as @code{print} except that the expression's value is
20185 not printed and is not put in the value history (@pxref{Value History,
20186 ,Value History}). The expression is evaluated only for its effects.
20187
20188 If the beginning of the argument string of the @code{set} command
20189 appears identical to a @code{set} subcommand, use the @code{set
20190 variable} command instead of just @code{set}. This command is identical
20191 to @code{set} except for its lack of subcommands. For example, if your
20192 program has a variable @code{width}, you get an error if you try to set
20193 a new value with just @samp{set width=13}, because @value{GDBN} has the
20194 command @code{set width}:
20195
20196 @smallexample
20197 (@value{GDBP}) whatis width
20198 type = double
20199 (@value{GDBP}) p width
20200 $4 = 13
20201 (@value{GDBP}) set width=47
20202 Invalid syntax in expression.
20203 @end smallexample
20204
20205 @noindent
20206 The invalid expression, of course, is @samp{=47}. In
20207 order to actually set the program's variable @code{width}, use
20208
20209 @smallexample
20210 (@value{GDBP}) set var width=47
20211 @end smallexample
20212
20213 Because the @code{set} command has many subcommands that can conflict
20214 with the names of program variables, it is a good idea to use the
20215 @code{set variable} command instead of just @code{set}. For example, if
20216 your program has a variable @code{g}, you run into problems if you try
20217 to set a new value with just @samp{set g=4}, because @value{GDBN} has
20218 the command @code{set gnutarget}, abbreviated @code{set g}:
20219
20220 @smallexample
20221 @group
20222 (@value{GDBP}) whatis g
20223 type = double
20224 (@value{GDBP}) p g
20225 $1 = 1
20226 (@value{GDBP}) set g=4
20227 (@value{GDBP}) p g
20228 $2 = 1
20229 (@value{GDBP}) r
20230 The program being debugged has been started already.
20231 Start it from the beginning? (y or n) y
20232 Starting program: /home/smith/cc_progs/a.out
20233 "/home/smith/cc_progs/a.out": can't open to read symbols:
20234 Invalid bfd target.
20235 (@value{GDBP}) show g
20236 The current BFD target is "=4".
20237 @end group
20238 @end smallexample
20239
20240 @noindent
20241 The program variable @code{g} did not change, and you silently set the
20242 @code{gnutarget} to an invalid value. In order to set the variable
20243 @code{g}, use
20244
20245 @smallexample
20246 (@value{GDBP}) set var g=4
20247 @end smallexample
20248
20249 @value{GDBN} allows more implicit conversions in assignments than C; you can
20250 freely store an integer value into a pointer variable or vice versa,
20251 and you can convert any structure to any other structure that is the
20252 same length or shorter.
20253 @comment FIXME: how do structs align/pad in these conversions?
20254 @comment /doc@cygnus.com 18dec1990
20255
20256 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
20257 construct to generate a value of specified type at a specified address
20258 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
20259 to memory location @code{0x83040} as an integer (which implies a certain size
20260 and representation in memory), and
20261
20262 @smallexample
20263 set @{int@}0x83040 = 4
20264 @end smallexample
20265
20266 @noindent
20267 stores the value 4 into that memory location.
20268
20269 @node Jumping
20270 @section Continuing at a Different Address
20271
20272 Ordinarily, when you continue your program, you do so at the place where
20273 it stopped, with the @code{continue} command. You can instead continue at
20274 an address of your own choosing, with the following commands:
20275
20276 @table @code
20277 @kindex jump
20278 @kindex j @r{(@code{jump})}
20279 @item jump @var{locspec}
20280 @itemx j @var{locspec}
20281 Resume execution at the address of the code location that results from
20282 resolving @var{locspec}.
20283 @xref{Location Specifications}, for a description of the different
20284 forms of @var{locspec}. If @var{locspec} resolves to more than one
20285 address, the command aborts before jumping.
20286 Execution stops again immediately if there is a breakpoint there. It
20287 is common practice to use the @code{tbreak} command in conjunction
20288 with @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
20289
20290 The @code{jump} command does not change the current stack frame, or
20291 the stack pointer, or the contents of any memory location or any
20292 register other than the program counter. If @var{locspec} resolves to
20293 an address in a different function from the one currently executing, the
20294 results may be bizarre if the two functions expect different patterns
20295 of arguments or of local variables. For this reason, the @code{jump}
20296 command requests confirmation if the jump address is not in the
20297 function currently executing. However, even bizarre results are
20298 predictable if you are well acquainted with the machine-language code
20299 of your program.
20300 @end table
20301
20302 On many systems, you can get much the same effect as the @code{jump}
20303 command by storing a new value into the register @code{$pc}. The
20304 difference is that this does not start your program running; it only
20305 changes the address of where it @emph{will} run when you continue. For
20306 example,
20307
20308 @smallexample
20309 set $pc = 0x485
20310 @end smallexample
20311
20312 @noindent
20313 makes the next @code{continue} command or stepping command execute at
20314 address @code{0x485}, rather than at the address where your program stopped.
20315 @xref{Continuing and Stepping, ,Continuing and Stepping}.
20316
20317 The most common occasion to use the @code{jump} command is to back
20318 up---perhaps with more breakpoints set---over a portion of a program
20319 that has already executed, in order to examine its execution in more
20320 detail.
20321
20322 @c @group
20323 @node Signaling
20324 @section Giving your Program a Signal
20325 @cindex deliver a signal to a program
20326
20327 @table @code
20328 @kindex signal
20329 @item signal @var{signal}
20330 Resume execution where your program is stopped, but immediately give it the
20331 signal @var{signal}. The @var{signal} can be the name or the number of a
20332 signal. For example, on many systems @code{signal 2} and @code{signal
20333 SIGINT} are both ways of sending an interrupt signal.
20334
20335 Alternatively, if @var{signal} is zero, continue execution without
20336 giving a signal. This is useful when your program stopped on account of
20337 a signal and would ordinarily see the signal when resumed with the
20338 @code{continue} command; @samp{signal 0} causes it to resume without a
20339 signal.
20340
20341 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
20342 delivered to the currently selected thread, not the thread that last
20343 reported a stop. This includes the situation where a thread was
20344 stopped due to a signal. So if you want to continue execution
20345 suppressing the signal that stopped a thread, you should select that
20346 same thread before issuing the @samp{signal 0} command. If you issue
20347 the @samp{signal 0} command with another thread as the selected one,
20348 @value{GDBN} detects that and asks for confirmation.
20349
20350 Invoking the @code{signal} command is not the same as invoking the
20351 @code{kill} utility from the shell. Sending a signal with @code{kill}
20352 causes @value{GDBN} to decide what to do with the signal depending on
20353 the signal handling tables (@pxref{Signals}). The @code{signal} command
20354 passes the signal directly to your program.
20355
20356 @code{signal} does not repeat when you press @key{RET} a second time
20357 after executing the command.
20358
20359 @kindex queue-signal
20360 @item queue-signal @var{signal}
20361 Queue @var{signal} to be delivered immediately to the current thread
20362 when execution of the thread resumes. The @var{signal} can be the name or
20363 the number of a signal. For example, on many systems @code{signal 2} and
20364 @code{signal SIGINT} are both ways of sending an interrupt signal.
20365 The handling of the signal must be set to pass the signal to the program,
20366 otherwise @value{GDBN} will report an error.
20367 You can control the handling of signals from @value{GDBN} with the
20368 @code{handle} command (@pxref{Signals}).
20369
20370 Alternatively, if @var{signal} is zero, any currently queued signal
20371 for the current thread is discarded and when execution resumes no signal
20372 will be delivered. This is useful when your program stopped on account
20373 of a signal and would ordinarily see the signal when resumed with the
20374 @code{continue} command.
20375
20376 This command differs from the @code{signal} command in that the signal
20377 is just queued, execution is not resumed. And @code{queue-signal} cannot
20378 be used to pass a signal whose handling state has been set to @code{nopass}
20379 (@pxref{Signals}).
20380 @end table
20381 @c @end group
20382
20383 @xref{stepping into signal handlers}, for information on how stepping
20384 commands behave when the thread has a signal queued.
20385
20386 @node Returning
20387 @section Returning from a Function
20388
20389 @table @code
20390 @cindex returning from a function
20391 @kindex return
20392 @item return
20393 @itemx return @var{expression}
20394 You can cancel execution of a function call with the @code{return}
20395 command. If you give an
20396 @var{expression} argument, its value is used as the function's return
20397 value.
20398 @end table
20399
20400 When you use @code{return}, @value{GDBN} discards the selected stack frame
20401 (and all frames within it). You can think of this as making the
20402 discarded frame return prematurely. If you wish to specify a value to
20403 be returned, give that value as the argument to @code{return}.
20404
20405 This pops the selected stack frame (@pxref{Selection, ,Selecting a
20406 Frame}), and any other frames inside of it, leaving its caller as the
20407 innermost remaining frame. That frame becomes selected. The
20408 specified value is stored in the registers used for returning values
20409 of functions.
20410
20411 The @code{return} command does not resume execution; it leaves the
20412 program stopped in the state that would exist if the function had just
20413 returned. In contrast, the @code{finish} command (@pxref{Continuing
20414 and Stepping, ,Continuing and Stepping}) resumes execution until the
20415 selected stack frame returns naturally.
20416
20417 @value{GDBN} needs to know how the @var{expression} argument should be set for
20418 the inferior. The concrete registers assignment depends on the OS ABI and the
20419 type being returned by the selected stack frame. For example it is common for
20420 OS ABI to return floating point values in FPU registers while integer values in
20421 CPU registers. Still some ABIs return even floating point values in CPU
20422 registers. Larger integer widths (such as @code{long long int}) also have
20423 specific placement rules. @value{GDBN} already knows the OS ABI from its
20424 current target so it needs to find out also the type being returned to make the
20425 assignment into the right register(s).
20426
20427 Normally, the selected stack frame has debug info. @value{GDBN} will always
20428 use the debug info instead of the implicit type of @var{expression} when the
20429 debug info is available. For example, if you type @kbd{return -1}, and the
20430 function in the current stack frame is declared to return a @code{long long
20431 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
20432 into a @code{long long int}:
20433
20434 @smallexample
20435 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
20436 29 return 31;
20437 (@value{GDBP}) return -1
20438 Make func return now? (y or n) y
20439 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
20440 43 printf ("result=%lld\n", func ());
20441 (@value{GDBP})
20442 @end smallexample
20443
20444 However, if the selected stack frame does not have a debug info, e.g., if the
20445 function was compiled without debug info, @value{GDBN} has to find out the type
20446 to return from user. Specifying a different type by mistake may set the value
20447 in different inferior registers than the caller code expects. For example,
20448 typing @kbd{return -1} with its implicit type @code{int} would set only a part
20449 of a @code{long long int} result for a debug info less function (on 32-bit
20450 architectures). Therefore the user is required to specify the return type by
20451 an appropriate cast explicitly:
20452
20453 @smallexample
20454 Breakpoint 2, 0x0040050b in func ()
20455 (@value{GDBP}) return -1
20456 Return value type not available for selected stack frame.
20457 Please use an explicit cast of the value to return.
20458 (@value{GDBP}) return (long long int) -1
20459 Make selected stack frame return now? (y or n) y
20460 #0 0x00400526 in main ()
20461 (@value{GDBP})
20462 @end smallexample
20463
20464 @node Calling
20465 @section Calling Program Functions
20466
20467 @table @code
20468 @cindex calling functions
20469 @cindex inferior functions, calling
20470 @item print @var{expr}
20471 Evaluate the expression @var{expr} and display the resulting value.
20472 The expression may include calls to functions in the program being
20473 debugged.
20474
20475 @kindex call
20476 @item call @var{expr}
20477 Evaluate the expression @var{expr} without displaying @code{void}
20478 returned values.
20479
20480 You can use this variant of the @code{print} command if you want to
20481 execute a function from your program that does not return anything
20482 (a.k.a.@: @dfn{a void function}), but without cluttering the output
20483 with @code{void} returned values that @value{GDBN} will otherwise
20484 print. If the result is not void, it is printed and saved in the
20485 value history.
20486 @end table
20487
20488 It is possible for the function you call via the @code{print} or
20489 @code{call} command to generate a signal (e.g., if there's a bug in
20490 the function, or if you passed it incorrect arguments). What happens
20491 in that case is controlled by the @code{set unwindonsignal} command.
20492
20493 Similarly, with a C@t{++} program it is possible for the function you
20494 call via the @code{print} or @code{call} command to generate an
20495 exception that is not handled due to the constraints of the dummy
20496 frame. In this case, any exception that is raised in the frame, but has
20497 an out-of-frame exception handler will not be found. GDB builds a
20498 dummy-frame for the inferior function call, and the unwinder cannot
20499 seek for exception handlers outside of this dummy-frame. What happens
20500 in that case is controlled by the
20501 @code{set unwind-on-terminating-exception} command.
20502
20503 @table @code
20504 @item set unwindonsignal
20505 @kindex set unwindonsignal
20506 @cindex unwind stack in called functions
20507 @cindex call dummy stack unwinding
20508 Set unwinding of the stack if a signal is received while in a function
20509 that @value{GDBN} called in the program being debugged. If set to on,
20510 @value{GDBN} unwinds the stack it created for the call and restores
20511 the context to what it was before the call. If set to off (the
20512 default), @value{GDBN} stops in the frame where the signal was
20513 received.
20514
20515 @item show unwindonsignal
20516 @kindex show unwindonsignal
20517 Show the current setting of stack unwinding in the functions called by
20518 @value{GDBN}.
20519
20520 @item set unwind-on-terminating-exception
20521 @kindex set unwind-on-terminating-exception
20522 @cindex unwind stack in called functions with unhandled exceptions
20523 @cindex call dummy stack unwinding on unhandled exception.
20524 Set unwinding of the stack if a C@t{++} exception is raised, but left
20525 unhandled while in a function that @value{GDBN} called in the program being
20526 debugged. If set to on (the default), @value{GDBN} unwinds the stack
20527 it created for the call and restores the context to what it was before
20528 the call. If set to off, @value{GDBN} the exception is delivered to
20529 the default C@t{++} exception handler and the inferior terminated.
20530
20531 @item show unwind-on-terminating-exception
20532 @kindex show unwind-on-terminating-exception
20533 Show the current setting of stack unwinding in the functions called by
20534 @value{GDBN}.
20535
20536 @item set may-call-functions
20537 @kindex set may-call-functions
20538 @cindex disabling calling functions in the program
20539 @cindex calling functions in the program, disabling
20540 Set permission to call functions in the program.
20541 This controls whether @value{GDBN} will attempt to call functions in
20542 the program, such as with expressions in the @code{print} command. It
20543 defaults to @code{on}.
20544
20545 To call a function in the program, @value{GDBN} has to temporarily
20546 modify the state of the inferior. This has potentially undesired side
20547 effects. Also, having @value{GDBN} call nested functions is likely to
20548 be erroneous and may even crash the program being debugged. You can
20549 avoid such hazards by forbidding @value{GDBN} from calling functions
20550 in the program being debugged. If calling functions in the program
20551 is forbidden, GDB will throw an error when a command (such as printing
20552 an expression) starts a function call in the program.
20553
20554 @item show may-call-functions
20555 @kindex show may-call-functions
20556 Show permission to call functions in the program.
20557
20558 @end table
20559
20560 @subsection Calling functions with no debug info
20561
20562 @cindex no debug info functions
20563 Sometimes, a function you wish to call is missing debug information.
20564 In such case, @value{GDBN} does not know the type of the function,
20565 including the types of the function's parameters. To avoid calling
20566 the inferior function incorrectly, which could result in the called
20567 function functioning erroneously and even crash, @value{GDBN} refuses
20568 to call the function unless you tell it the type of the function.
20569
20570 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
20571 to do that. The simplest is to cast the call to the function's
20572 declared return type. For example:
20573
20574 @smallexample
20575 (@value{GDBP}) p getenv ("PATH")
20576 'getenv' has unknown return type; cast the call to its declared return type
20577 (@value{GDBP}) p (char *) getenv ("PATH")
20578 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
20579 @end smallexample
20580
20581 Casting the return type of a no-debug function is equivalent to
20582 casting the function to a pointer to a prototyped function that has a
20583 prototype that matches the types of the passed-in arguments, and
20584 calling that. I.e., the call above is equivalent to:
20585
20586 @smallexample
20587 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
20588 @end smallexample
20589
20590 @noindent
20591 and given this prototyped C or C++ function with float parameters:
20592
20593 @smallexample
20594 float multiply (float v1, float v2) @{ return v1 * v2; @}
20595 @end smallexample
20596
20597 @noindent
20598 these calls are equivalent:
20599
20600 @smallexample
20601 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
20602 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
20603 @end smallexample
20604
20605 If the function you wish to call is declared as unprototyped (i.e.@:
20606 old K&R style), you must use the cast-to-function-pointer syntax, so
20607 that @value{GDBN} knows that it needs to apply default argument
20608 promotions (promote float arguments to double). @xref{ABI, float
20609 promotion}. For example, given this unprototyped C function with
20610 float parameters, and no debug info:
20611
20612 @smallexample
20613 float
20614 multiply_noproto (v1, v2)
20615 float v1, v2;
20616 @{
20617 return v1 * v2;
20618 @}
20619 @end smallexample
20620
20621 @noindent
20622 you call it like this:
20623
20624 @smallexample
20625 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20626 @end smallexample
20627
20628 @node Patching
20629 @section Patching Programs
20630
20631 @cindex patching binaries
20632 @cindex writing into executables
20633 @cindex writing into corefiles
20634
20635 By default, @value{GDBN} opens the file containing your program's
20636 executable code (or the corefile) read-only. This prevents accidental
20637 alterations to machine code; but it also prevents you from intentionally
20638 patching your program's binary.
20639
20640 If you'd like to be able to patch the binary, you can specify that
20641 explicitly with the @code{set write} command. For example, you might
20642 want to turn on internal debugging flags, or even to make emergency
20643 repairs.
20644
20645 @table @code
20646 @kindex set write
20647 @item set write on
20648 @itemx set write off
20649 If you specify @samp{set write on}, @value{GDBN} opens executable and
20650 core files for both reading and writing; if you specify @kbd{set write
20651 off} (the default), @value{GDBN} opens them read-only.
20652
20653 If you have already loaded a file, you must load it again (using the
20654 @code{exec-file} or @code{core-file} command) after changing @code{set
20655 write}, for your new setting to take effect.
20656
20657 @item show write
20658 @kindex show write
20659 Display whether executable files and core files are opened for writing
20660 as well as reading.
20661 @end table
20662
20663 @node Compiling and Injecting Code
20664 @section Compiling and injecting code in @value{GDBN}
20665 @cindex injecting code
20666 @cindex writing into executables
20667 @cindex compiling code
20668
20669 @value{GDBN} supports on-demand compilation and code injection into
20670 programs running under @value{GDBN}. GCC 5.0 or higher built with
20671 @file{libcc1.so} must be installed for this functionality to be enabled.
20672 This functionality is implemented with the following commands.
20673
20674 @table @code
20675 @kindex compile code
20676 @item compile code @var{source-code}
20677 @itemx compile code -raw @var{--} @var{source-code}
20678 Compile @var{source-code} with the compiler language found as the current
20679 language in @value{GDBN} (@pxref{Languages}). If compilation and
20680 injection is not supported with the current language specified in
20681 @value{GDBN}, or the compiler does not support this feature, an error
20682 message will be printed. If @var{source-code} compiles and links
20683 successfully, @value{GDBN} will load the object-code emitted,
20684 and execute it within the context of the currently selected inferior.
20685 It is important to note that the compiled code is executed immediately.
20686 After execution, the compiled code is removed from @value{GDBN} and any
20687 new types or variables you have defined will be deleted.
20688
20689 The command allows you to specify @var{source-code} in two ways.
20690 The simplest method is to provide a single line of code to the command.
20691 E.g.:
20692
20693 @smallexample
20694 compile code printf ("hello world\n");
20695 @end smallexample
20696
20697 If you specify options on the command line as well as source code, they
20698 may conflict. The @samp{--} delimiter can be used to separate options
20699 from actual source code. E.g.:
20700
20701 @smallexample
20702 compile code -r -- printf ("hello world\n");
20703 @end smallexample
20704
20705 Alternatively you can enter source code as multiple lines of text. To
20706 enter this mode, invoke the @samp{compile code} command without any text
20707 following the command. This will start the multiple-line editor and
20708 allow you to type as many lines of source code as required. When you
20709 have completed typing, enter @samp{end} on its own line to exit the
20710 editor.
20711
20712 @smallexample
20713 compile code
20714 >printf ("hello\n");
20715 >printf ("world\n");
20716 >end
20717 @end smallexample
20718
20719 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20720 provided @var{source-code} in a callable scope. In this case, you must
20721 specify the entry point of the code by defining a function named
20722 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20723 inferior. Using @samp{-raw} option may be needed for example when
20724 @var{source-code} requires @samp{#include} lines which may conflict with
20725 inferior symbols otherwise.
20726
20727 @kindex compile file
20728 @item compile file @var{filename}
20729 @itemx compile file -raw @var{filename}
20730 Like @code{compile code}, but take the source code from @var{filename}.
20731
20732 @smallexample
20733 compile file /home/user/example.c
20734 @end smallexample
20735 @end table
20736
20737 @table @code
20738 @item compile print [[@var{options}] --] @var{expr}
20739 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
20740 Compile and execute @var{expr} with the compiler language found as the
20741 current language in @value{GDBN} (@pxref{Languages}). By default the
20742 value of @var{expr} is printed in a format appropriate to its data type;
20743 you can choose a different format by specifying @samp{/@var{f}}, where
20744 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
20745 Formats}. The @code{compile print} command accepts the same options
20746 as the @code{print} command; see @ref{print options}.
20747
20748 @item compile print [[@var{options}] --]
20749 @itemx compile print [[@var{options}] --] /@var{f}
20750 @cindex reprint the last value
20751 Alternatively you can enter the expression (source code producing it) as
20752 multiple lines of text. To enter this mode, invoke the @samp{compile print}
20753 command without any text following the command. This will start the
20754 multiple-line editor.
20755 @end table
20756
20757 @noindent
20758 The process of compiling and injecting the code can be inspected using:
20759
20760 @table @code
20761 @anchor{set debug compile}
20762 @item set debug compile
20763 @cindex compile command debugging info
20764 Turns on or off display of @value{GDBN} process of compiling and
20765 injecting the code. The default is off.
20766
20767 @item show debug compile
20768 Displays the current state of displaying @value{GDBN} process of
20769 compiling and injecting the code.
20770
20771 @anchor{set debug compile-cplus-types}
20772 @item set debug compile-cplus-types
20773 @cindex compile C@t{++} type conversion
20774 Turns on or off the display of C@t{++} type conversion debugging information.
20775 The default is off.
20776
20777 @item show debug compile-cplus-types
20778 Displays the current state of displaying debugging information for
20779 C@t{++} type conversion.
20780 @end table
20781
20782 @subsection Compilation options for the @code{compile} command
20783
20784 @value{GDBN} needs to specify the right compilation options for the code
20785 to be injected, in part to make its ABI compatible with the inferior
20786 and in part to make the injected code compatible with @value{GDBN}'s
20787 injecting process.
20788
20789 @noindent
20790 The options used, in increasing precedence:
20791
20792 @table @asis
20793 @item target architecture and OS options (@code{gdbarch})
20794 These options depend on target processor type and target operating
20795 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20796 (@code{-m64}) compilation option.
20797
20798 @item compilation options recorded in the target
20799 @value{NGCC} (since version 4.7) stores the options used for compilation
20800 into @code{DW_AT_producer} part of DWARF debugging information according
20801 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20802 explicitly specify @code{-g} during inferior compilation otherwise
20803 @value{NGCC} produces no DWARF. This feature is only relevant for
20804 platforms where @code{-g} produces DWARF by default, otherwise one may
20805 try to enforce DWARF by using @code{-gdwarf-4}.
20806
20807 @item compilation options set by @code{set compile-args}
20808 @end table
20809
20810 @noindent
20811 You can override compilation options using the following command:
20812
20813 @table @code
20814 @item set compile-args
20815 @cindex compile command options override
20816 Set compilation options used for compiling and injecting code with the
20817 @code{compile} commands. These options override any conflicting ones
20818 from the target architecture and/or options stored during inferior
20819 compilation.
20820
20821 @item show compile-args
20822 Displays the current state of compilation options override.
20823 This does not show all the options actually used during compilation,
20824 use @ref{set debug compile} for that.
20825 @end table
20826
20827 @subsection Caveats when using the @code{compile} command
20828
20829 There are a few caveats to keep in mind when using the @code{compile}
20830 command. As the caveats are different per language, the table below
20831 highlights specific issues on a per language basis.
20832
20833 @table @asis
20834 @item C code examples and caveats
20835 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20836 attempt to compile the source code with a @samp{C} compiler. The source
20837 code provided to the @code{compile} command will have much the same
20838 access to variables and types as it normally would if it were part of
20839 the program currently being debugged in @value{GDBN}.
20840
20841 Below is a sample program that forms the basis of the examples that
20842 follow. This program has been compiled and loaded into @value{GDBN},
20843 much like any other normal debugging session.
20844
20845 @smallexample
20846 void function1 (void)
20847 @{
20848 int i = 42;
20849 printf ("function 1\n");
20850 @}
20851
20852 void function2 (void)
20853 @{
20854 int j = 12;
20855 function1 ();
20856 @}
20857
20858 int main(void)
20859 @{
20860 int k = 6;
20861 int *p;
20862 function2 ();
20863 return 0;
20864 @}
20865 @end smallexample
20866
20867 For the purposes of the examples in this section, the program above has
20868 been compiled, loaded into @value{GDBN}, stopped at the function
20869 @code{main}, and @value{GDBN} is awaiting input from the user.
20870
20871 To access variables and types for any program in @value{GDBN}, the
20872 program must be compiled and packaged with debug information. The
20873 @code{compile} command is not an exception to this rule. Without debug
20874 information, you can still use the @code{compile} command, but you will
20875 be very limited in what variables and types you can access.
20876
20877 So with that in mind, the example above has been compiled with debug
20878 information enabled. The @code{compile} command will have access to
20879 all variables and types (except those that may have been optimized
20880 out). Currently, as @value{GDBN} has stopped the program in the
20881 @code{main} function, the @code{compile} command would have access to
20882 the variable @code{k}. You could invoke the @code{compile} command
20883 and type some source code to set the value of @code{k}. You can also
20884 read it, or do anything with that variable you would normally do in
20885 @code{C}. Be aware that changes to inferior variables in the
20886 @code{compile} command are persistent. In the following example:
20887
20888 @smallexample
20889 compile code k = 3;
20890 @end smallexample
20891
20892 @noindent
20893 the variable @code{k} is now 3. It will retain that value until
20894 something else in the example program changes it, or another
20895 @code{compile} command changes it.
20896
20897 Normal scope and access rules apply to source code compiled and
20898 injected by the @code{compile} command. In the example, the variables
20899 @code{j} and @code{k} are not accessible yet, because the program is
20900 currently stopped in the @code{main} function, where these variables
20901 are not in scope. Therefore, the following command
20902
20903 @smallexample
20904 compile code j = 3;
20905 @end smallexample
20906
20907 @noindent
20908 will result in a compilation error message.
20909
20910 Once the program is continued, execution will bring these variables in
20911 scope, and they will become accessible; then the code you specify via
20912 the @code{compile} command will be able to access them.
20913
20914 You can create variables and types with the @code{compile} command as
20915 part of your source code. Variables and types that are created as part
20916 of the @code{compile} command are not visible to the rest of the program for
20917 the duration of its run. This example is valid:
20918
20919 @smallexample
20920 compile code int ff = 5; printf ("ff is %d\n", ff);
20921 @end smallexample
20922
20923 However, if you were to type the following into @value{GDBN} after that
20924 command has completed:
20925
20926 @smallexample
20927 compile code printf ("ff is %d\n'', ff);
20928 @end smallexample
20929
20930 @noindent
20931 a compiler error would be raised as the variable @code{ff} no longer
20932 exists. Object code generated and injected by the @code{compile}
20933 command is removed when its execution ends. Caution is advised
20934 when assigning to program variables values of variables created by the
20935 code submitted to the @code{compile} command. This example is valid:
20936
20937 @smallexample
20938 compile code int ff = 5; k = ff;
20939 @end smallexample
20940
20941 The value of the variable @code{ff} is assigned to @code{k}. The variable
20942 @code{k} does not require the existence of @code{ff} to maintain the value
20943 it has been assigned. However, pointers require particular care in
20944 assignment. If the source code compiled with the @code{compile} command
20945 changed the address of a pointer in the example program, perhaps to a
20946 variable created in the @code{compile} command, that pointer would point
20947 to an invalid location when the command exits. The following example
20948 would likely cause issues with your debugged program:
20949
20950 @smallexample
20951 compile code int ff = 5; p = &ff;
20952 @end smallexample
20953
20954 In this example, @code{p} would point to @code{ff} when the
20955 @code{compile} command is executing the source code provided to it.
20956 However, as variables in the (example) program persist with their
20957 assigned values, the variable @code{p} would point to an invalid
20958 location when the command exists. A general rule should be followed
20959 in that you should either assign @code{NULL} to any assigned pointers,
20960 or restore a valid location to the pointer before the command exits.
20961
20962 Similar caution must be exercised with any structs, unions, and typedefs
20963 defined in @code{compile} command. Types defined in the @code{compile}
20964 command will no longer be available in the next @code{compile} command.
20965 Therefore, if you cast a variable to a type defined in the
20966 @code{compile} command, care must be taken to ensure that any future
20967 need to resolve the type can be achieved.
20968
20969 @smallexample
20970 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20971 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20972 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20973 Compilation failed.
20974 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20975 42
20976 @end smallexample
20977
20978 Variables that have been optimized away by the compiler are not
20979 accessible to the code submitted to the @code{compile} command.
20980 Access to those variables will generate a compiler error which @value{GDBN}
20981 will print to the console.
20982 @end table
20983
20984 @subsection Compiler search for the @code{compile} command
20985
20986 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20987 which may not be obvious for remote targets of different architecture
20988 than where @value{GDBN} is running. Environment variable @env{PATH} on
20989 @value{GDBN} host is searched for @value{NGCC} binary matching the
20990 target architecture and operating system. This search can be overriden
20991 by @code{set compile-gcc} @value{GDBN} command below. @env{PATH} is
20992 taken from shell that executed @value{GDBN}, it is not the value set by
20993 @value{GDBN} command @code{set environment}). @xref{Environment}.
20994
20995
20996 Specifically @env{PATH} is searched for binaries matching regular expression
20997 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20998 debugged. @var{arch} is processor name --- multiarch is supported, so for
20999 example both @code{i386} and @code{x86_64} targets look for pattern
21000 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
21001 for pattern @code{s390x?}. @var{os} is currently supported only for
21002 pattern @code{linux(-gnu)?}.
21003
21004 On Posix hosts the compiler driver @value{GDBN} needs to find also
21005 shared library @file{libcc1.so} from the compiler. It is searched in
21006 default shared library search path (overridable with usual environment
21007 variable @env{LD_LIBRARY_PATH}), unrelated to @env{PATH} or @code{set
21008 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
21009 according to the installation of the found compiler --- as possibly
21010 specified by the @code{set compile-gcc} command.
21011
21012 @table @code
21013 @item set compile-gcc
21014 @cindex compile command driver filename override
21015 Set compilation command used for compiling and injecting code with the
21016 @code{compile} commands. If this option is not set (it is set to
21017 an empty string), the search described above will occur --- that is the
21018 default.
21019
21020 @item show compile-gcc
21021 Displays the current compile command @value{NGCC} driver filename.
21022 If set, it is the main command @command{gcc}, found usually for example
21023 under name @file{x86_64-linux-gnu-gcc}.
21024 @end table
21025
21026 @node GDB Files
21027 @chapter @value{GDBN} Files
21028
21029 @value{GDBN} needs to know the file name of the program to be debugged,
21030 both in order to read its symbol table and in order to start your
21031 program. To debug a core dump of a previous run, you must also tell
21032 @value{GDBN} the name of the core dump file.
21033
21034 @menu
21035 * Files:: Commands to specify files
21036 * File Caching:: Information about @value{GDBN}'s file caching
21037 * Separate Debug Files:: Debugging information in separate files
21038 * MiniDebugInfo:: Debugging information in a special section
21039 * Index Files:: Index files speed up GDB
21040 * Symbol Errors:: Errors reading symbol files
21041 * Data Files:: GDB data files
21042 @end menu
21043
21044 @node Files
21045 @section Commands to Specify Files
21046
21047 @cindex symbol table
21048 @cindex core dump file
21049
21050 You may want to specify executable and core dump file names. The usual
21051 way to do this is at start-up time, using the arguments to
21052 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
21053 Out of @value{GDBN}}).
21054
21055 Occasionally it is necessary to change to a different file during a
21056 @value{GDBN} session. Or you may run @value{GDBN} and forget to
21057 specify a file you want to use. Or you are debugging a remote target
21058 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
21059 Program}). In these situations the @value{GDBN} commands to specify
21060 new files are useful.
21061
21062 @table @code
21063 @cindex executable file
21064 @kindex file
21065 @item file @var{filename}
21066 Use @var{filename} as the program to be debugged. It is read for its
21067 symbols and for the contents of pure memory. It is also the program
21068 executed when you use the @code{run} command. If you do not specify a
21069 directory and the file is not found in the @value{GDBN} working directory,
21070 @value{GDBN} uses the environment variable @env{PATH} as a list of
21071 directories to search, just as the shell does when looking for a program
21072 to run. You can change the value of this variable, for both @value{GDBN}
21073 and your program, using the @code{path} command.
21074
21075 @cindex unlinked object files
21076 @cindex patching object files
21077 You can load unlinked object @file{.o} files into @value{GDBN} using
21078 the @code{file} command. You will not be able to ``run'' an object
21079 file, but you can disassemble functions and inspect variables. Also,
21080 if the underlying BFD functionality supports it, you could use
21081 @kbd{gdb -write} to patch object files using this technique. Note
21082 that @value{GDBN} can neither interpret nor modify relocations in this
21083 case, so branches and some initialized variables will appear to go to
21084 the wrong place. But this feature is still handy from time to time.
21085
21086 @item file
21087 @code{file} with no argument makes @value{GDBN} discard any information it
21088 has on both executable file and the symbol table.
21089
21090 @kindex exec-file
21091 @item exec-file @r{[} @var{filename} @r{]}
21092 Specify that the program to be run (but not the symbol table) is found
21093 in @var{filename}. @value{GDBN} searches the environment variable @env{PATH}
21094 if necessary to locate your program. Omitting @var{filename} means to
21095 discard information on the executable file.
21096
21097 @kindex symbol-file
21098 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
21099 Read symbol table information from file @var{filename}. @env{PATH} is
21100 searched when necessary. Use the @code{file} command to get both symbol
21101 table and program to run from the same file.
21102
21103 If an optional @var{offset} is specified, it is added to the start
21104 address of each section in the symbol file. This is useful if the
21105 program is relocated at runtime, such as the Linux kernel with kASLR
21106 enabled.
21107
21108 @code{symbol-file} with no argument clears out @value{GDBN} information on your
21109 program's symbol table.
21110
21111 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
21112 some breakpoints and auto-display expressions. This is because they may
21113 contain pointers to the internal data recording symbols and data types,
21114 which are part of the old symbol table data being discarded inside
21115 @value{GDBN}.
21116
21117 @code{symbol-file} does not repeat if you press @key{RET} again after
21118 executing it once.
21119
21120 When @value{GDBN} is configured for a particular environment, it
21121 understands debugging information in whatever format is the standard
21122 generated for that environment; you may use either a @sc{gnu} compiler, or
21123 other compilers that adhere to the local conventions.
21124 Best results are usually obtained from @sc{gnu} compilers; for example,
21125 using @code{@value{NGCC}} you can generate debugging information for
21126 optimized code.
21127
21128 For most kinds of object files, with the exception of old SVR3 systems
21129 using COFF, the @code{symbol-file} command does not normally read the
21130 symbol table in full right away. Instead, it scans the symbol table
21131 quickly to find which source files and which symbols are present. The
21132 details are read later, one source file at a time, as they are needed.
21133
21134 The purpose of this two-stage reading strategy is to make @value{GDBN}
21135 start up faster. For the most part, it is invisible except for
21136 occasional pauses while the symbol table details for a particular source
21137 file are being read. (The @code{set verbose} command can turn these
21138 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
21139 Warnings and Messages}.)
21140
21141 We have not implemented the two-stage strategy for COFF yet. When the
21142 symbol table is stored in COFF format, @code{symbol-file} reads the
21143 symbol table data in full right away. Note that ``stabs-in-COFF''
21144 still does the two-stage strategy, since the debug info is actually
21145 in stabs format.
21146
21147 @kindex readnow
21148 @cindex reading symbols immediately
21149 @cindex symbols, reading immediately
21150 @item symbol-file @r{[} -readnow @r{]} @var{filename}
21151 @itemx file @r{[} -readnow @r{]} @var{filename}
21152 You can override the @value{GDBN} two-stage strategy for reading symbol
21153 tables by using the @samp{-readnow} option with any of the commands that
21154 load symbol table information, if you want to be sure @value{GDBN} has the
21155 entire symbol table available.
21156
21157 @cindex @code{-readnever}, option for symbol-file command
21158 @cindex never read symbols
21159 @cindex symbols, never read
21160 @item symbol-file @r{[} -readnever @r{]} @var{filename}
21161 @itemx file @r{[} -readnever @r{]} @var{filename}
21162 You can instruct @value{GDBN} to never read the symbolic information
21163 contained in @var{filename} by using the @samp{-readnever} option.
21164 @xref{--readnever}.
21165
21166 @c FIXME: for now no mention of directories, since this seems to be in
21167 @c flux. 13mar1992 status is that in theory GDB would look either in
21168 @c current dir or in same dir as myprog; but issues like competing
21169 @c GDB's, or clutter in system dirs, mean that in practice right now
21170 @c only current dir is used. FFish says maybe a special GDB hierarchy
21171 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
21172 @c files.
21173
21174 @kindex core-file
21175 @item core-file @r{[}@var{filename}@r{]}
21176 @itemx core
21177 Specify the whereabouts of a core dump file to be used as the ``contents
21178 of memory''. Traditionally, core files contain only some parts of the
21179 address space of the process that generated them; @value{GDBN} can access the
21180 executable file itself for other parts.
21181
21182 @code{core-file} with no argument specifies that no core file is
21183 to be used.
21184
21185 Note that the core file is ignored when your program is actually running
21186 under @value{GDBN}. So, if you have been running your program and you
21187 wish to debug a core file instead, you must kill the subprocess in which
21188 the program is running. To do this, use the @code{kill} command
21189 (@pxref{Kill Process, ,Killing the Child Process}).
21190
21191 @kindex add-symbol-file
21192 @cindex dynamic linking
21193 @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{]}
21194 The @code{add-symbol-file} command reads additional symbol table
21195 information from the file @var{filename}. You would use this command
21196 when @var{filename} has been dynamically loaded (by some other means)
21197 into the program that is running. The @var{textaddress} parameter gives
21198 the memory address at which the file's text section has been loaded.
21199 You can additionally specify the base address of other sections using
21200 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
21201 If a section is omitted, @value{GDBN} will use its default addresses
21202 as found in @var{filename}. Any @var{address} or @var{textaddress}
21203 can be given as an expression.
21204
21205 If an optional @var{offset} is specified, it is added to the start
21206 address of each section, except those for which the address was
21207 specified explicitly.
21208
21209 The symbol table of the file @var{filename} is added to the symbol table
21210 originally read with the @code{symbol-file} command. You can use the
21211 @code{add-symbol-file} command any number of times; the new symbol data
21212 thus read is kept in addition to the old.
21213
21214 Changes can be reverted using the command @code{remove-symbol-file}.
21215
21216 @cindex relocatable object files, reading symbols from
21217 @cindex object files, relocatable, reading symbols from
21218 @cindex reading symbols from relocatable object files
21219 @cindex symbols, reading from relocatable object files
21220 @cindex @file{.o} files, reading symbols from
21221 Although @var{filename} is typically a shared library file, an
21222 executable file, or some other object file which has been fully
21223 relocated for loading into a process, you can also load symbolic
21224 information from relocatable @file{.o} files, as long as:
21225
21226 @itemize @bullet
21227 @item
21228 the file's symbolic information refers only to linker symbols defined in
21229 that file, not to symbols defined by other object files,
21230 @item
21231 every section the file's symbolic information refers to has actually
21232 been loaded into the inferior, as it appears in the file, and
21233 @item
21234 you can determine the address at which every section was loaded, and
21235 provide these to the @code{add-symbol-file} command.
21236 @end itemize
21237
21238 @noindent
21239 Some embedded operating systems, like Sun Chorus and VxWorks, can load
21240 relocatable files into an already running program; such systems
21241 typically make the requirements above easy to meet. However, it's
21242 important to recognize that many native systems use complex link
21243 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
21244 assembly, for example) that make the requirements difficult to meet. In
21245 general, one cannot assume that using @code{add-symbol-file} to read a
21246 relocatable object file's symbolic information will have the same effect
21247 as linking the relocatable object file into the program in the normal
21248 way.
21249
21250 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
21251
21252 @kindex remove-symbol-file
21253 @item remove-symbol-file @var{filename}
21254 @item remove-symbol-file -a @var{address}
21255 Remove a symbol file added via the @code{add-symbol-file} command. The
21256 file to remove can be identified by its @var{filename} or by an @var{address}
21257 that lies within the boundaries of this symbol file in memory. Example:
21258
21259 @smallexample
21260 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
21261 add symbol table from file "/home/user/gdb/mylib.so" at
21262 .text_addr = 0x7ffff7ff9480
21263 (y or n) y
21264 Reading symbols from /home/user/gdb/mylib.so...
21265 (gdb) remove-symbol-file -a 0x7ffff7ff9480
21266 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
21267 (gdb)
21268 @end smallexample
21269
21270
21271 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
21272
21273 @kindex add-symbol-file-from-memory
21274 @cindex @code{syscall DSO}
21275 @cindex load symbols from memory
21276 @item add-symbol-file-from-memory @var{address}
21277 Load symbols from the given @var{address} in a dynamically loaded
21278 object file whose image is mapped directly into the inferior's memory.
21279 For example, the Linux kernel maps a @code{syscall DSO} into each
21280 process's address space; this DSO provides kernel-specific code for
21281 some system calls. The argument can be any expression whose
21282 evaluation yields the address of the file's shared object file header.
21283 For this command to work, you must have used @code{symbol-file} or
21284 @code{exec-file} commands in advance.
21285
21286 @kindex section
21287 @item section @var{section} @var{addr}
21288 The @code{section} command changes the base address of the named
21289 @var{section} of the exec file to @var{addr}. This can be used if the
21290 exec file does not contain section addresses, (such as in the
21291 @code{a.out} format), or when the addresses specified in the file
21292 itself are wrong. Each section must be changed separately. The
21293 @code{info files} command, described below, lists all the sections and
21294 their addresses.
21295
21296 @kindex info files
21297 @kindex info target
21298 @item info files
21299 @itemx info target
21300 @code{info files} and @code{info target} are synonymous; both print the
21301 current target (@pxref{Targets, ,Specifying a Debugging Target}),
21302 including the names of the executable and core dump files currently in
21303 use by @value{GDBN}, and the files from which symbols were loaded. The
21304 command @code{help target} lists all possible targets rather than
21305 current ones.
21306
21307 @kindex maint info sections
21308 @item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
21309 Another command that can give you extra information about program sections
21310 is @code{maint info sections}. In addition to the section information
21311 displayed by @code{info files}, this command displays the flags and file
21312 offset of each section in the executable and core dump files.
21313
21314 When @samp{-all-objects} is passed then sections from all loaded object
21315 files, including shared libraries, are printed.
21316
21317 The optional @var{filter-list} is a space separated list of filter
21318 keywords. Sections that match any one of the filter criteria will be
21319 printed. There are two types of filter:
21320
21321 @table @code
21322 @item @var{section-name}
21323 Display information about any section named @var{section-name}.
21324 @item @var{section-flag}
21325 Display information for any section with @var{section-flag}. The
21326 section flags that @value{GDBN} currently knows about are:
21327 @table @code
21328 @item ALLOC
21329 Section will have space allocated in the process when loaded.
21330 Set for all sections except those containing debug information.
21331 @item LOAD
21332 Section will be loaded from the file into the child process memory.
21333 Set for pre-initialized code and data, clear for @code{.bss} sections.
21334 @item RELOC
21335 Section needs to be relocated before loading.
21336 @item READONLY
21337 Section cannot be modified by the child process.
21338 @item CODE
21339 Section contains executable code only.
21340 @item DATA
21341 Section contains data only (no executable code).
21342 @item ROM
21343 Section will reside in ROM.
21344 @item CONSTRUCTOR
21345 Section contains data for constructor/destructor lists.
21346 @item HAS_CONTENTS
21347 Section is not empty.
21348 @item NEVER_LOAD
21349 An instruction to the linker to not output the section.
21350 @item COFF_SHARED_LIBRARY
21351 A notification to the linker that the section contains
21352 COFF shared library information.
21353 @item IS_COMMON
21354 Section contains common symbols.
21355 @end table
21356 @end table
21357
21358 @kindex maint info target-sections
21359 @item maint info target-sections
21360 This command prints @value{GDBN}'s internal section table. For each
21361 target @value{GDBN} maintains a table containing the allocatable
21362 sections from all currently mapped objects, along with information
21363 about where the section is mapped.
21364
21365 @kindex set trust-readonly-sections
21366 @cindex read-only sections
21367 @item set trust-readonly-sections on
21368 Tell @value{GDBN} that readonly sections in your object file
21369 really are read-only (i.e.@: that their contents will not change).
21370 In that case, @value{GDBN} can fetch values from these sections
21371 out of the object file, rather than from the target program.
21372 For some targets (notably embedded ones), this can be a significant
21373 enhancement to debugging performance.
21374
21375 The default is off.
21376
21377 @item set trust-readonly-sections off
21378 Tell @value{GDBN} not to trust readonly sections. This means that
21379 the contents of the section might change while the program is running,
21380 and must therefore be fetched from the target when needed.
21381
21382 @item show trust-readonly-sections
21383 Show the current setting of trusting readonly sections.
21384 @end table
21385
21386 All file-specifying commands allow both absolute and relative file names
21387 as arguments. @value{GDBN} always converts the file name to an absolute file
21388 name and remembers it that way.
21389
21390 @cindex shared libraries
21391 @anchor{Shared Libraries}
21392 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
21393 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
21394 DSBT (TIC6X) shared libraries.
21395
21396 On MS-Windows @value{GDBN} must be linked with the Expat library to support
21397 shared libraries. @xref{Expat}.
21398
21399 @value{GDBN} automatically loads symbol definitions from shared libraries
21400 when you use the @code{run} command, or when you examine a core file.
21401 (Before you issue the @code{run} command, @value{GDBN} does not understand
21402 references to a function in a shared library, however---unless you are
21403 debugging a core file).
21404
21405 @c FIXME: some @value{GDBN} release may permit some refs to undef
21406 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
21407 @c FIXME...lib; check this from time to time when updating manual
21408
21409 There are times, however, when you may wish to not automatically load
21410 symbol definitions from shared libraries, such as when they are
21411 particularly large or there are many of them.
21412
21413 To control the automatic loading of shared library symbols, use the
21414 commands:
21415
21416 @table @code
21417 @kindex set auto-solib-add
21418 @item set auto-solib-add @var{mode}
21419 If @var{mode} is @code{on}, symbols from all shared object libraries
21420 will be loaded automatically when the inferior begins execution, you
21421 attach to an independently started inferior, or when the dynamic linker
21422 informs @value{GDBN} that a new library has been loaded. If @var{mode}
21423 is @code{off}, symbols must be loaded manually, using the
21424 @code{sharedlibrary} command. The default value is @code{on}.
21425
21426 @cindex memory used for symbol tables
21427 If your program uses lots of shared libraries with debug info that
21428 takes large amounts of memory, you can decrease the @value{GDBN}
21429 memory footprint by preventing it from automatically loading the
21430 symbols from shared libraries. To that end, type @kbd{set
21431 auto-solib-add off} before running the inferior, then load each
21432 library whose debug symbols you do need with @kbd{sharedlibrary
21433 @var{regexp}}, where @var{regexp} is a regular expression that matches
21434 the libraries whose symbols you want to be loaded.
21435
21436 @kindex show auto-solib-add
21437 @item show auto-solib-add
21438 Display the current autoloading mode.
21439 @end table
21440
21441 @cindex load shared library
21442 To explicitly load shared library symbols, use the @code{sharedlibrary}
21443 command:
21444
21445 @table @code
21446 @kindex info sharedlibrary
21447 @kindex info share
21448 @item info share @var{regex}
21449 @itemx info sharedlibrary @var{regex}
21450 Print the names of the shared libraries which are currently loaded
21451 that match @var{regex}. If @var{regex} is omitted then print
21452 all shared libraries that are loaded.
21453
21454 @kindex info dll
21455 @item info dll @var{regex}
21456 This is an alias of @code{info sharedlibrary}.
21457
21458 @kindex sharedlibrary
21459 @kindex share
21460 @item sharedlibrary @var{regex}
21461 @itemx share @var{regex}
21462 Load shared object library symbols for files matching a
21463 Unix regular expression.
21464 As with files loaded automatically, it only loads shared libraries
21465 required by your program for a core file or after typing @code{run}. If
21466 @var{regex} is omitted all shared libraries required by your program are
21467 loaded.
21468
21469 @item nosharedlibrary
21470 @kindex nosharedlibrary
21471 @cindex unload symbols from shared libraries
21472 Unload all shared object library symbols. This discards all symbols
21473 that have been loaded from all shared libraries. Symbols from shared
21474 libraries that were loaded by explicit user requests are not
21475 discarded.
21476 @end table
21477
21478 Sometimes you may wish that @value{GDBN} stops and gives you control
21479 when any of shared library events happen. The best way to do this is
21480 to use @code{catch load} and @code{catch unload} (@pxref{Set
21481 Catchpoints}).
21482
21483 @value{GDBN} also supports the @code{set stop-on-solib-events}
21484 command for this. This command exists for historical reasons. It is
21485 less useful than setting a catchpoint, because it does not allow for
21486 conditions or commands as a catchpoint does.
21487
21488 @table @code
21489 @item set stop-on-solib-events
21490 @kindex set stop-on-solib-events
21491 This command controls whether @value{GDBN} should give you control
21492 when the dynamic linker notifies it about some shared library event.
21493 The most common event of interest is loading or unloading of a new
21494 shared library.
21495
21496 @item show stop-on-solib-events
21497 @kindex show stop-on-solib-events
21498 Show whether @value{GDBN} stops and gives you control when shared
21499 library events happen.
21500 @end table
21501
21502 Shared libraries are also supported in many cross or remote debugging
21503 configurations. @value{GDBN} needs to have access to the target's libraries;
21504 this can be accomplished either by providing copies of the libraries
21505 on the host system, or by asking @value{GDBN} to automatically retrieve the
21506 libraries from the target. If copies of the target libraries are
21507 provided, they need to be the same as the target libraries, although the
21508 copies on the target can be stripped as long as the copies on the host are
21509 not.
21510
21511 @cindex where to look for shared libraries
21512 For remote debugging, you need to tell @value{GDBN} where the target
21513 libraries are, so that it can load the correct copies---otherwise, it
21514 may try to load the host's libraries. @value{GDBN} has two variables
21515 to specify the search directories for target libraries.
21516
21517 @table @code
21518 @cindex prefix for executable and shared library file names
21519 @cindex system root, alternate
21520 @kindex set solib-absolute-prefix
21521 @kindex set sysroot
21522 @item set sysroot @var{path}
21523 Use @var{path} as the system root for the program being debugged. Any
21524 absolute shared library paths will be prefixed with @var{path}; many
21525 runtime loaders store the absolute paths to the shared library in the
21526 target program's memory. When starting processes remotely, and when
21527 attaching to already-running processes (local or remote), their
21528 executable filenames will be prefixed with @var{path} if reported to
21529 @value{GDBN} as absolute by the operating system. If you use
21530 @code{set sysroot} to find executables and shared libraries, they need
21531 to be laid out in the same way that they are on the target, with
21532 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
21533 @var{path}.
21534
21535 If @var{path} starts with the sequence @file{target:} and the target
21536 system is remote then @value{GDBN} will retrieve the target binaries
21537 from the remote system. This is only supported when using a remote
21538 target that supports the @code{remote get} command (@pxref{File
21539 Transfer,,Sending files to a remote system}). The part of @var{path}
21540 following the initial @file{target:} (if present) is used as system
21541 root prefix on the remote file system. If @var{path} starts with the
21542 sequence @file{remote:} this is converted to the sequence
21543 @file{target:} by @code{set sysroot}@footnote{Historically the
21544 functionality to retrieve binaries from the remote system was
21545 provided by prefixing @var{path} with @file{remote:}}. If you want
21546 to specify a local system root using a directory that happens to be
21547 named @file{target:} or @file{remote:}, you need to use some
21548 equivalent variant of the name like @file{./target:}.
21549
21550 For targets with an MS-DOS based filesystem, such as MS-Windows,
21551 @value{GDBN} tries prefixing a few variants of the target
21552 absolute file name with @var{path}. But first, on Unix hosts,
21553 @value{GDBN} converts all backslash directory separators into forward
21554 slashes, because the backslash is not a directory separator on Unix:
21555
21556 @smallexample
21557 c:\foo\bar.dll @result{} c:/foo/bar.dll
21558 @end smallexample
21559
21560 Then, @value{GDBN} attempts prefixing the target file name with
21561 @var{path}, and looks for the resulting file name in the host file
21562 system:
21563
21564 @smallexample
21565 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
21566 @end smallexample
21567
21568 If that does not find the binary, @value{GDBN} tries removing
21569 the @samp{:} character from the drive spec, both for convenience, and,
21570 for the case of the host file system not supporting file names with
21571 colons:
21572
21573 @smallexample
21574 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
21575 @end smallexample
21576
21577 This makes it possible to have a system root that mirrors a target
21578 with more than one drive. E.g., you may want to setup your local
21579 copies of the target system shared libraries like so (note @samp{c} vs
21580 @samp{z}):
21581
21582 @smallexample
21583 @file{/path/to/sysroot/c/sys/bin/foo.dll}
21584 @file{/path/to/sysroot/c/sys/bin/bar.dll}
21585 @file{/path/to/sysroot/z/sys/bin/bar.dll}
21586 @end smallexample
21587
21588 @noindent
21589 and point the system root at @file{/path/to/sysroot}, so that
21590 @value{GDBN} can find the correct copies of both
21591 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
21592
21593 If that still does not find the binary, @value{GDBN} tries
21594 removing the whole drive spec from the target file name:
21595
21596 @smallexample
21597 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
21598 @end smallexample
21599
21600 This last lookup makes it possible to not care about the drive name,
21601 if you don't want or need to.
21602
21603 The @code{set solib-absolute-prefix} command is an alias for @code{set
21604 sysroot}.
21605
21606 @cindex default system root
21607 @cindex @samp{--with-sysroot}
21608 You can set the default system root by using the configure-time
21609 @samp{--with-sysroot} option. If the system root is inside
21610 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21611 @samp{--exec-prefix}), then the default system root will be updated
21612 automatically if the installed @value{GDBN} is moved to a new
21613 location.
21614
21615 @kindex show sysroot
21616 @item show sysroot
21617 Display the current executable and shared library prefix.
21618
21619 @kindex set solib-search-path
21620 @item set solib-search-path @var{path}
21621 If this variable is set, @var{path} is a colon-separated list of
21622 directories to search for shared libraries. @samp{solib-search-path}
21623 is used after @samp{sysroot} fails to locate the library, or if the
21624 path to the library is relative instead of absolute. If you want to
21625 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
21626 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
21627 finding your host's libraries. @samp{sysroot} is preferred; setting
21628 it to a nonexistent directory may interfere with automatic loading
21629 of shared library symbols.
21630
21631 @kindex show solib-search-path
21632 @item show solib-search-path
21633 Display the current shared library search path.
21634
21635 @cindex DOS file-name semantics of file names.
21636 @kindex set target-file-system-kind (unix|dos-based|auto)
21637 @kindex show target-file-system-kind
21638 @item set target-file-system-kind @var{kind}
21639 Set assumed file system kind for target reported file names.
21640
21641 Shared library file names as reported by the target system may not
21642 make sense as is on the system @value{GDBN} is running on. For
21643 example, when remote debugging a target that has MS-DOS based file
21644 system semantics, from a Unix host, the target may be reporting to
21645 @value{GDBN} a list of loaded shared libraries with file names such as
21646 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21647 drive letters, so the @samp{c:\} prefix is not normally understood as
21648 indicating an absolute file name, and neither is the backslash
21649 normally considered a directory separator character. In that case,
21650 the native file system would interpret this whole absolute file name
21651 as a relative file name with no directory components. This would make
21652 it impossible to point @value{GDBN} at a copy of the remote target's
21653 shared libraries on the host using @code{set sysroot}, and impractical
21654 with @code{set solib-search-path}. Setting
21655 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21656 to interpret such file names similarly to how the target would, and to
21657 map them to file names valid on @value{GDBN}'s native file system
21658 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21659 to one of the supported file system kinds. In that case, @value{GDBN}
21660 tries to determine the appropriate file system variant based on the
21661 current target's operating system (@pxref{ABI, ,Configuring the
21662 Current ABI}). The supported file system settings are:
21663
21664 @table @code
21665 @item unix
21666 Instruct @value{GDBN} to assume the target file system is of Unix
21667 kind. Only file names starting the forward slash (@samp{/}) character
21668 are considered absolute, and the directory separator character is also
21669 the forward slash.
21670
21671 @item dos-based
21672 Instruct @value{GDBN} to assume the target file system is DOS based.
21673 File names starting with either a forward slash, or a drive letter
21674 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21675 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21676 considered directory separators.
21677
21678 @item auto
21679 Instruct @value{GDBN} to use the file system kind associated with the
21680 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21681 This is the default.
21682 @end table
21683 @end table
21684
21685 @cindex file name canonicalization
21686 @cindex base name differences
21687 When processing file names provided by the user, @value{GDBN}
21688 frequently needs to compare them to the file names recorded in the
21689 program's debug info. Normally, @value{GDBN} compares just the
21690 @dfn{base names} of the files as strings, which is reasonably fast
21691 even for very large programs. (The base name of a file is the last
21692 portion of its name, after stripping all the leading directories.)
21693 This shortcut in comparison is based upon the assumption that files
21694 cannot have more than one base name. This is usually true, but
21695 references to files that use symlinks or similar filesystem
21696 facilities violate that assumption. If your program records files
21697 using such facilities, or if you provide file names to @value{GDBN}
21698 using symlinks etc., you can set @code{basenames-may-differ} to
21699 @code{true} to instruct @value{GDBN} to completely canonicalize each
21700 pair of file names it needs to compare. This will make file-name
21701 comparisons accurate, but at a price of a significant slowdown.
21702
21703 @table @code
21704 @item set basenames-may-differ
21705 @kindex set basenames-may-differ
21706 Set whether a source file may have multiple base names.
21707
21708 @item show basenames-may-differ
21709 @kindex show basenames-may-differ
21710 Show whether a source file may have multiple base names.
21711 @end table
21712
21713 @node File Caching
21714 @section File Caching
21715 @cindex caching of opened files
21716 @cindex caching of bfd objects
21717
21718 To speed up file loading, and reduce memory usage, @value{GDBN} will
21719 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21720 BFD, bfd, The Binary File Descriptor Library}. The following commands
21721 allow visibility and control of the caching behavior.
21722
21723 @table @code
21724 @kindex maint info bfds
21725 @item maint info bfds
21726 This prints information about each @code{bfd} object that is known to
21727 @value{GDBN}.
21728
21729 @kindex maint set bfd-sharing
21730 @kindex maint show bfd-sharing
21731 @kindex bfd caching
21732 @item maint set bfd-sharing
21733 @item maint show bfd-sharing
21734 Control whether @code{bfd} objects can be shared. When sharing is
21735 enabled @value{GDBN} reuses already open @code{bfd} objects rather
21736 than reopening the same file. Turning sharing off does not cause
21737 already shared @code{bfd} objects to be unshared, but all future files
21738 that are opened will create a new @code{bfd} object. Similarly,
21739 re-enabling sharing does not cause multiple existing @code{bfd}
21740 objects to be collapsed into a single shared @code{bfd} object.
21741
21742 @kindex set debug bfd-cache @var{level}
21743 @kindex bfd caching
21744 @item set debug bfd-cache @var{level}
21745 Turns on debugging of the bfd cache, setting the level to @var{level}.
21746
21747 @kindex show debug bfd-cache
21748 @kindex bfd caching
21749 @item show debug bfd-cache
21750 Show the current debugging level of the bfd cache.
21751 @end table
21752
21753 @node Separate Debug Files
21754 @section Debugging Information in Separate Files
21755 @cindex separate debugging information files
21756 @cindex debugging information in separate files
21757 @cindex @file{.debug} subdirectories
21758 @cindex debugging information directory, global
21759 @cindex global debugging information directories
21760 @cindex build ID, and separate debugging files
21761 @cindex @file{.build-id} directory
21762
21763 @value{GDBN} allows you to put a program's debugging information in a
21764 file separate from the executable itself, in a way that allows
21765 @value{GDBN} to find and load the debugging information automatically.
21766 Since debugging information can be very large---sometimes larger
21767 than the executable code itself---some systems distribute debugging
21768 information for their executables in separate files, which users can
21769 install only when they need to debug a problem.
21770
21771 @value{GDBN} supports two ways of specifying the separate debug info
21772 file:
21773
21774 @itemize @bullet
21775 @item
21776 The executable contains a @dfn{debug link} that specifies the name of
21777 the separate debug info file. The separate debug file's name is
21778 usually @file{@var{executable}.debug}, where @var{executable} is the
21779 name of the corresponding executable file without leading directories
21780 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
21781 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21782 checksum for the debug file, which @value{GDBN} uses to validate that
21783 the executable and the debug file came from the same build.
21784
21785 @item
21786 @anchor{build ID}
21787 The executable contains a @dfn{build ID}, a unique bit string that is
21788 also present in the corresponding debug info file. (This is supported
21789 only on some operating systems, when using the ELF or PE file formats
21790 for binary files and the @sc{gnu} Binutils.) For more details about
21791 this feature, see the description of the @option{--build-id}
21792 command-line option in @ref{Options, , Command Line Options, ld,
21793 The GNU Linker}. The debug info file's name is not specified
21794 explicitly by the build ID, but can be computed from the build ID, see
21795 below.
21796 @end itemize
21797
21798 Depending on the way the debug info file is specified, @value{GDBN}
21799 uses two different methods of looking for the debug file:
21800
21801 @itemize @bullet
21802 @item
21803 For the ``debug link'' method, @value{GDBN} looks up the named file in
21804 the directory of the executable file, then in a subdirectory of that
21805 directory named @file{.debug}, and finally under each one of the
21806 global debug directories, in a subdirectory whose name is identical to
21807 the leading directories of the executable's absolute file name. (On
21808 MS-Windows/MS-DOS, the drive letter of the executable's leading
21809 directories is converted to a one-letter subdirectory, i.e.@:
21810 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21811 filesystems disallow colons in file names.)
21812
21813 @item
21814 For the ``build ID'' method, @value{GDBN} looks in the
21815 @file{.build-id} subdirectory of each one of the global debug directories for
21816 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21817 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21818 are the rest of the bit string. (Real build ID strings are 32 or more
21819 hex characters, not 10.) @value{GDBN} can automatically query
21820 @code{debuginfod} servers using build IDs in order to download separate debug
21821 files that cannot be found locally. For more information see @ref{Debuginfod}.
21822 @end itemize
21823
21824 So, for example, suppose you ask @value{GDBN} to debug
21825 @file{/usr/bin/ls}, which has a debug link that specifies the
21826 file @file{ls.debug}, and a build ID whose value in hex is
21827 @code{abcdef1234}. If the list of the global debug directories includes
21828 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21829 debug information files, in the indicated order:
21830
21831 @itemize @minus
21832 @item
21833 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21834 @item
21835 @file{/usr/bin/ls.debug}
21836 @item
21837 @file{/usr/bin/.debug/ls.debug}
21838 @item
21839 @file{/usr/lib/debug/usr/bin/ls.debug}.
21840 @end itemize
21841
21842 If the debug file still has not been found and @code{debuginfod}
21843 (@pxref{Debuginfod}) is enabled, @value{GDBN} will attempt to download the
21844 file from @code{debuginfod} servers.
21845
21846 @anchor{debug-file-directory}
21847 Global debugging info directories default to what is set by @value{GDBN}
21848 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21849 you can also set the global debugging info directories, and view the list
21850 @value{GDBN} is currently using.
21851
21852 @table @code
21853
21854 @kindex set debug-file-directory
21855 @item set debug-file-directory @var{directories}
21856 Set the directories which @value{GDBN} searches for separate debugging
21857 information files to @var{directory}. Multiple path components can be set
21858 concatenating them by a path separator.
21859
21860 @kindex show debug-file-directory
21861 @item show debug-file-directory
21862 Show the directories @value{GDBN} searches for separate debugging
21863 information files.
21864
21865 @end table
21866
21867 @cindex @code{.gnu_debuglink} sections
21868 @cindex debug link sections
21869 A debug link is a special section of the executable file named
21870 @code{.gnu_debuglink}. The section must contain:
21871
21872 @itemize
21873 @item
21874 A filename, with any leading directory components removed, followed by
21875 a zero byte,
21876 @item
21877 zero to three bytes of padding, as needed to reach the next four-byte
21878 boundary within the section, and
21879 @item
21880 a four-byte CRC checksum, stored in the same endianness used for the
21881 executable file itself. The checksum is computed on the debugging
21882 information file's full contents by the function given below, passing
21883 zero as the @var{crc} argument.
21884 @end itemize
21885
21886 Any executable file format can carry a debug link, as long as it can
21887 contain a section named @code{.gnu_debuglink} with the contents
21888 described above.
21889
21890 @cindex @code{.note.gnu.build-id} sections
21891 @cindex build ID sections
21892 The build ID is a special section in the executable file (and in other
21893 ELF binary files that @value{GDBN} may consider). This section is
21894 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21895 It contains unique identification for the built files---the ID remains
21896 the same across multiple builds of the same build tree. The default
21897 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21898 content for the build ID string. The same section with an identical
21899 value is present in the original built binary with symbols, in its
21900 stripped variant, and in the separate debugging information file.
21901
21902 The debugging information file itself should be an ordinary
21903 executable, containing a full set of linker symbols, sections, and
21904 debugging information. The sections of the debugging information file
21905 should have the same names, addresses, and sizes as the original file,
21906 but they need not contain any data---much like a @code{.bss} section
21907 in an ordinary executable.
21908
21909 The @sc{gnu} binary utilities (Binutils) package includes the
21910 @samp{objcopy} utility that can produce
21911 the separated executable / debugging information file pairs using the
21912 following commands:
21913
21914 @smallexample
21915 @kbd{objcopy --only-keep-debug foo foo.debug}
21916 @kbd{strip -g foo}
21917 @end smallexample
21918
21919 @noindent
21920 These commands remove the debugging
21921 information from the executable file @file{foo} and place it in the file
21922 @file{foo.debug}. You can use the first, second or both methods to link the
21923 two files:
21924
21925 @itemize @bullet
21926 @item
21927 The debug link method needs the following additional command to also leave
21928 behind a debug link in @file{foo}:
21929
21930 @smallexample
21931 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21932 @end smallexample
21933
21934 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21935 a version of the @code{strip} command such that the command @kbd{strip foo -f
21936 foo.debug} has the same functionality as the two @code{objcopy} commands and
21937 the @code{ln -s} command above, together.
21938
21939 @item
21940 Build ID gets embedded into the main executable using @code{ld --build-id} or
21941 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21942 compatibility fixes for debug files separation are present in @sc{gnu} binary
21943 utilities (Binutils) package since version 2.18.
21944 @end itemize
21945
21946 @noindent
21947
21948 @cindex CRC algorithm definition
21949 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21950 IEEE 802.3 using the polynomial:
21951
21952 @c TexInfo requires naked braces for multi-digit exponents for Tex
21953 @c output, but this causes HTML output to barf. HTML has to be set using
21954 @c raw commands. So we end up having to specify this equation in 2
21955 @c different ways!
21956 @ifhtml
21957 @display
21958 @html
21959 <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>
21960 + <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
21961 @end html
21962 @end display
21963 @end ifhtml
21964 @ifnothtml
21965 @display
21966 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21967 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21968 @end display
21969 @end ifnothtml
21970
21971 The function is computed byte at a time, taking the least
21972 significant bit of each byte first. The initial pattern
21973 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21974 the final result is inverted to ensure trailing zeros also affect the
21975 CRC.
21976
21977 @emph{Note:} This is the same CRC polynomial as used in handling the
21978 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21979 However in the case of the Remote Serial Protocol, the CRC is computed
21980 @emph{most} significant bit first, and the result is not inverted, so
21981 trailing zeros have no effect on the CRC value.
21982
21983 To complete the description, we show below the code of the function
21984 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21985 initially supplied @code{crc} argument means that an initial call to
21986 this function passing in zero will start computing the CRC using
21987 @code{0xffffffff}.
21988
21989 @kindex gnu_debuglink_crc32
21990 @smallexample
21991 unsigned long
21992 gnu_debuglink_crc32 (unsigned long crc,
21993 unsigned char *buf, size_t len)
21994 @{
21995 static const unsigned long crc32_table[256] =
21996 @{
21997 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21998 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21999 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
22000 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
22001 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
22002 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
22003 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
22004 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
22005 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
22006 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
22007 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
22008 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
22009 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
22010 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
22011 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
22012 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
22013 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
22014 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
22015 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
22016 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
22017 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
22018 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
22019 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
22020 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
22021 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
22022 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
22023 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
22024 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
22025 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
22026 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
22027 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
22028 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
22029 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
22030 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
22031 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
22032 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
22033 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
22034 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
22035 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
22036 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
22037 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
22038 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
22039 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
22040 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
22041 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
22042 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
22043 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
22044 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
22045 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
22046 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
22047 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
22048 0x2d02ef8d
22049 @};
22050 unsigned char *end;
22051
22052 crc = ~crc & 0xffffffff;
22053 for (end = buf + len; buf < end; ++buf)
22054 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
22055 return ~crc & 0xffffffff;
22056 @}
22057 @end smallexample
22058
22059 @noindent
22060 This computation does not apply to the ``build ID'' method.
22061
22062 @node MiniDebugInfo
22063 @section Debugging information in a special section
22064 @cindex separate debug sections
22065 @cindex @samp{.gnu_debugdata} section
22066
22067 Some systems ship pre-built executables and libraries that have a
22068 special @samp{.gnu_debugdata} section. This feature is called
22069 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
22070 is used to supply extra symbols for backtraces.
22071
22072 The intent of this section is to provide extra minimal debugging
22073 information for use in simple backtraces. It is not intended to be a
22074 replacement for full separate debugging information (@pxref{Separate
22075 Debug Files}). The example below shows the intended use; however,
22076 @value{GDBN} does not currently put restrictions on what sort of
22077 debugging information might be included in the section.
22078
22079 @value{GDBN} has support for this extension. If the section exists,
22080 then it is used provided that no other source of debugging information
22081 can be found, and that @value{GDBN} was configured with LZMA support.
22082
22083 This section can be easily created using @command{objcopy} and other
22084 standard utilities:
22085
22086 @smallexample
22087 # Extract the dynamic symbols from the main binary, there is no need
22088 # to also have these in the normal symbol table.
22089 nm -D @var{binary} --format=posix --defined-only \
22090 | awk '@{ print $1 @}' | sort > dynsyms
22091
22092 # Extract all the text (i.e. function) symbols from the debuginfo.
22093 # (Note that we actually also accept "D" symbols, for the benefit
22094 # of platforms like PowerPC64 that use function descriptors.)
22095 nm @var{binary} --format=posix --defined-only \
22096 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
22097 | sort > funcsyms
22098
22099 # Keep all the function symbols not already in the dynamic symbol
22100 # table.
22101 comm -13 dynsyms funcsyms > keep_symbols
22102
22103 # Separate full debug info into debug binary.
22104 objcopy --only-keep-debug @var{binary} debug
22105
22106 # Copy the full debuginfo, keeping only a minimal set of symbols and
22107 # removing some unnecessary sections.
22108 objcopy -S --remove-section .gdb_index --remove-section .comment \
22109 --keep-symbols=keep_symbols debug mini_debuginfo
22110
22111 # Drop the full debug info from the original binary.
22112 strip --strip-all -R .comment @var{binary}
22113
22114 # Inject the compressed data into the .gnu_debugdata section of the
22115 # original binary.
22116 xz mini_debuginfo
22117 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
22118 @end smallexample
22119
22120 @node Index Files
22121 @section Index Files Speed Up @value{GDBN}
22122 @cindex index files
22123 @cindex @samp{.gdb_index} section
22124
22125 When @value{GDBN} finds a symbol file, it scans the symbols in the
22126 file in order to construct an internal symbol table. This lets most
22127 @value{GDBN} operations work quickly---at the cost of a delay early
22128 on. For large programs, this delay can be quite lengthy, so
22129 @value{GDBN} provides a way to build an index, which speeds up
22130 startup.
22131
22132 For convenience, @value{GDBN} comes with a program,
22133 @command{gdb-add-index}, which can be used to add the index to a
22134 symbol file. It takes the symbol file as its only argument:
22135
22136 @smallexample
22137 $ gdb-add-index symfile
22138 @end smallexample
22139
22140 @xref{gdb-add-index}.
22141
22142 It is also possible to do the work manually. Here is what
22143 @command{gdb-add-index} does behind the curtains.
22144
22145 The index is stored as a section in the symbol file. @value{GDBN} can
22146 write the index to a file, then you can put it into the symbol file
22147 using @command{objcopy}.
22148
22149 To create an index file, use the @code{save gdb-index} command:
22150
22151 @table @code
22152 @item save gdb-index [-dwarf-5] @var{directory}
22153 @kindex save gdb-index
22154 Create index files for all symbol files currently known by
22155 @value{GDBN}. For each known @var{symbol-file}, this command by
22156 default creates it produces a single file
22157 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
22158 the @option{-dwarf-5} option, it produces 2 files:
22159 @file{@var{symbol-file}.debug_names} and
22160 @file{@var{symbol-file}.debug_str}. The files are created in the
22161 given @var{directory}.
22162 @end table
22163
22164 Once you have created an index file you can merge it into your symbol
22165 file, here named @file{symfile}, using @command{objcopy}:
22166
22167 @smallexample
22168 $ objcopy --add-section .gdb_index=symfile.gdb-index \
22169 --set-section-flags .gdb_index=readonly symfile symfile
22170 @end smallexample
22171
22172 Or for @code{-dwarf-5}:
22173
22174 @smallexample
22175 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
22176 $ cat symfile.debug_str >>symfile.debug_str.new
22177 $ objcopy --add-section .debug_names=symfile.gdb-index \
22178 --set-section-flags .debug_names=readonly \
22179 --update-section .debug_str=symfile.debug_str.new symfile symfile
22180 @end smallexample
22181
22182 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
22183 sections that have been deprecated. Usually they are deprecated because
22184 they are missing a new feature or have performance issues.
22185 To tell @value{GDBN} to use a deprecated index section anyway
22186 specify @code{set use-deprecated-index-sections on}.
22187 The default is @code{off}.
22188 This can speed up startup, but may result in some functionality being lost.
22189 @xref{Index Section Format}.
22190
22191 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
22192 must be done before gdb reads the file. The following will not work:
22193
22194 @smallexample
22195 $ gdb -ex "set use-deprecated-index-sections on" <program>
22196 @end smallexample
22197
22198 Instead you must do, for example,
22199
22200 @smallexample
22201 $ gdb -iex "set use-deprecated-index-sections on" <program>
22202 @end smallexample
22203
22204 Indices only work when using DWARF debugging information, not stabs.
22205
22206 @subsection Automatic symbol index cache
22207
22208 @cindex automatic symbol index cache
22209 It is possible for @value{GDBN} to automatically save a copy of this index in a
22210 cache on disk and retrieve it from there when loading the same binary in the
22211 future. This feature can be turned on with @kbd{set index-cache enabled on}.
22212 The following commands can be used to tweak the behavior of the index cache.
22213
22214 @table @code
22215
22216 @kindex set index-cache
22217 @item set index-cache enabled on
22218 @itemx set index-cache enabled off
22219 Enable or disable the use of the symbol index cache.
22220
22221 @item set index-cache directory @var{directory}
22222 @kindex show index-cache
22223 @itemx show index-cache directory
22224 Set/show the directory where index files will be saved.
22225
22226 The default value for this directory depends on the host platform. On
22227 most systems, the index is cached in the @file{gdb} subdirectory of
22228 the directory pointed to by the @env{XDG_CACHE_HOME} environment
22229 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
22230 of your home directory. However, on some systems, the default may
22231 differ according to local convention.
22232
22233 There is no limit on the disk space used by index cache. It is perfectly safe
22234 to delete the content of that directory to free up disk space.
22235
22236 @item show index-cache stats
22237 Print the number of cache hits and misses since the launch of @value{GDBN}.
22238
22239 @end table
22240
22241 @node Symbol Errors
22242 @section Errors Reading Symbol Files
22243
22244 While reading a symbol file, @value{GDBN} occasionally encounters problems,
22245 such as symbol types it does not recognize, or known bugs in compiler
22246 output. By default, @value{GDBN} does not notify you of such problems, since
22247 they are relatively common and primarily of interest to people
22248 debugging compilers. If you are interested in seeing information
22249 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
22250 only one message about each such type of problem, no matter how many
22251 times the problem occurs; or you can ask @value{GDBN} to print more messages,
22252 to see how many times the problems occur, with the @code{set
22253 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
22254 Messages}).
22255
22256 The messages currently printed, and their meanings, include:
22257
22258 @table @code
22259 @item inner block not inside outer block in @var{symbol}
22260
22261 The symbol information shows where symbol scopes begin and end
22262 (such as at the start of a function or a block of statements). This
22263 error indicates that an inner scope block is not fully contained
22264 in its outer scope blocks.
22265
22266 @value{GDBN} circumvents the problem by treating the inner block as if it had
22267 the same scope as the outer block. In the error message, @var{symbol}
22268 may be shown as ``@code{(don't know)}'' if the outer block is not a
22269 function.
22270
22271 @item block at @var{address} out of order
22272
22273 The symbol information for symbol scope blocks should occur in
22274 order of increasing addresses. This error indicates that it does not
22275 do so.
22276
22277 @value{GDBN} does not circumvent this problem, and has trouble
22278 locating symbols in the source file whose symbols it is reading. (You
22279 can often determine what source file is affected by specifying
22280 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
22281 Messages}.)
22282
22283 @item bad block start address patched
22284
22285 The symbol information for a symbol scope block has a start address
22286 smaller than the address of the preceding source line. This is known
22287 to occur in the SunOS 4.1.1 (and earlier) C compiler.
22288
22289 @value{GDBN} circumvents the problem by treating the symbol scope block as
22290 starting on the previous source line.
22291
22292 @item bad string table offset in symbol @var{n}
22293
22294 @cindex foo
22295 Symbol number @var{n} contains a pointer into the string table which is
22296 larger than the size of the string table.
22297
22298 @value{GDBN} circumvents the problem by considering the symbol to have the
22299 name @code{foo}, which may cause other problems if many symbols end up
22300 with this name.
22301
22302 @item unknown symbol type @code{0x@var{nn}}
22303
22304 The symbol information contains new data types that @value{GDBN} does
22305 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
22306 uncomprehended information, in hexadecimal.
22307
22308 @value{GDBN} circumvents the error by ignoring this symbol information.
22309 This usually allows you to debug your program, though certain symbols
22310 are not accessible. If you encounter such a problem and feel like
22311 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
22312 on @code{complain}, then go up to the function @code{read_dbx_symtab}
22313 and examine @code{*bufp} to see the symbol.
22314
22315 @item stub type has NULL name
22316
22317 @value{GDBN} could not find the full definition for a struct or class.
22318
22319 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
22320 The symbol information for a C@t{++} member function is missing some
22321 information that recent versions of the compiler should have output for
22322 it.
22323
22324 @item info mismatch between compiler and debugger
22325
22326 @value{GDBN} could not parse a type specification output by the compiler.
22327
22328 @end table
22329
22330 @node Data Files
22331 @section GDB Data Files
22332
22333 @cindex prefix for data files
22334 @value{GDBN} will sometimes read an auxiliary data file. These files
22335 are kept in a directory known as the @dfn{data directory}.
22336
22337 You can set the data directory's name, and view the name @value{GDBN}
22338 is currently using.
22339
22340 @table @code
22341 @kindex set data-directory
22342 @item set data-directory @var{directory}
22343 Set the directory which @value{GDBN} searches for auxiliary data files
22344 to @var{directory}.
22345
22346 @kindex show data-directory
22347 @item show data-directory
22348 Show the directory @value{GDBN} searches for auxiliary data files.
22349 @end table
22350
22351 @cindex default data directory
22352 @cindex @samp{--with-gdb-datadir}
22353 You can set the default data directory by using the configure-time
22354 @samp{--with-gdb-datadir} option. If the data directory is inside
22355 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
22356 @samp{--exec-prefix}), then the default data directory will be updated
22357 automatically if the installed @value{GDBN} is moved to a new
22358 location.
22359
22360 The data directory may also be specified with the
22361 @code{--data-directory} command line option.
22362 @xref{Mode Options}.
22363
22364 @node Targets
22365 @chapter Specifying a Debugging Target
22366
22367 @cindex debugging target
22368 A @dfn{target} is the execution environment occupied by your program.
22369
22370 Often, @value{GDBN} runs in the same host environment as your program;
22371 in that case, the debugging target is specified as a side effect when
22372 you use the @code{file} or @code{core} commands. When you need more
22373 flexibility---for example, running @value{GDBN} on a physically separate
22374 host, or controlling a standalone system over a serial port or a
22375 realtime system over a TCP/IP connection---you can use the @code{target}
22376 command to specify one of the target types configured for @value{GDBN}
22377 (@pxref{Target Commands, ,Commands for Managing Targets}).
22378
22379 @cindex target architecture
22380 It is possible to build @value{GDBN} for several different @dfn{target
22381 architectures}. When @value{GDBN} is built like that, you can choose
22382 one of the available architectures with the @kbd{set architecture}
22383 command.
22384
22385 @table @code
22386 @kindex set architecture
22387 @kindex show architecture
22388 @item set architecture @var{arch}
22389 This command sets the current target architecture to @var{arch}. The
22390 value of @var{arch} can be @code{"auto"}, in addition to one of the
22391 supported architectures.
22392
22393 @item show architecture
22394 Show the current target architecture.
22395
22396 @item set processor
22397 @itemx processor
22398 @kindex set processor
22399 @kindex show processor
22400 These are alias commands for, respectively, @code{set architecture}
22401 and @code{show architecture}.
22402 @end table
22403
22404 @menu
22405 * Active Targets:: Active targets
22406 * Target Commands:: Commands for managing targets
22407 * Byte Order:: Choosing target byte order
22408 @end menu
22409
22410 @node Active Targets
22411 @section Active Targets
22412
22413 @cindex stacking targets
22414 @cindex active targets
22415 @cindex multiple targets
22416
22417 There are multiple classes of targets such as: processes, executable files or
22418 recording sessions. Core files belong to the process class, making core file
22419 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
22420 on multiple active targets, one in each class. This allows you to (for
22421 example) start a process and inspect its activity, while still having access to
22422 the executable file after the process finishes. Or if you start process
22423 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
22424 presented a virtual layer of the recording target, while the process target
22425 remains stopped at the chronologically last point of the process execution.
22426
22427 Use the @code{core-file} and @code{exec-file} commands to select a new core
22428 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
22429 specify as a target a process that is already running, use the @code{attach}
22430 command (@pxref{Attach, ,Debugging an Already-running Process}).
22431
22432 @node Target Commands
22433 @section Commands for Managing Targets
22434
22435 @table @code
22436 @item target @var{type} @var{parameters}
22437 Connects the @value{GDBN} host environment to a target machine or
22438 process. A target is typically a protocol for talking to debugging
22439 facilities. You use the argument @var{type} to specify the type or
22440 protocol of the target machine.
22441
22442 Further @var{parameters} are interpreted by the target protocol, but
22443 typically include things like device names or host names to connect
22444 with, process numbers, and baud rates.
22445
22446 The @code{target} command does not repeat if you press @key{RET} again
22447 after executing the command.
22448
22449 @kindex help target
22450 @item help target
22451 Displays the names of all targets available. To display targets
22452 currently selected, use either @code{info target} or @code{info files}
22453 (@pxref{Files, ,Commands to Specify Files}).
22454
22455 @item help target @var{name}
22456 Describe a particular target, including any parameters necessary to
22457 select it.
22458
22459 @kindex set gnutarget
22460 @item set gnutarget @var{args}
22461 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
22462 knows whether it is reading an @dfn{executable},
22463 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
22464 with the @code{set gnutarget} command. Unlike most @code{target} commands,
22465 with @code{gnutarget} the @code{target} refers to a program, not a machine.
22466
22467 @quotation
22468 @emph{Warning:} To specify a file format with @code{set gnutarget},
22469 you must know the actual BFD name.
22470 @end quotation
22471
22472 @noindent
22473 @xref{Files, , Commands to Specify Files}.
22474
22475 @kindex show gnutarget
22476 @item show gnutarget
22477 Use the @code{show gnutarget} command to display what file format
22478 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
22479 @value{GDBN} will determine the file format for each file automatically,
22480 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
22481 @end table
22482
22483 @cindex common targets
22484 Here are some common targets (available, or not, depending on the GDB
22485 configuration):
22486
22487 @table @code
22488 @kindex target
22489 @item target exec @var{program}
22490 @cindex executable file target
22491 An executable file. @samp{target exec @var{program}} is the same as
22492 @samp{exec-file @var{program}}.
22493
22494 @item target core @var{filename}
22495 @cindex core dump file target
22496 A core dump file. @samp{target core @var{filename}} is the same as
22497 @samp{core-file @var{filename}}.
22498
22499 @item target remote @var{medium}
22500 @cindex remote target
22501 A remote system connected to @value{GDBN} via a serial line or network
22502 connection. This command tells @value{GDBN} to use its own remote
22503 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
22504
22505 For example, if you have a board connected to @file{/dev/ttya} on the
22506 machine running @value{GDBN}, you could say:
22507
22508 @smallexample
22509 target remote /dev/ttya
22510 @end smallexample
22511
22512 @code{target remote} supports the @code{load} command. This is only
22513 useful if you have some other way of getting the stub to the target
22514 system, and you can put it somewhere in memory where it won't get
22515 clobbered by the download.
22516
22517 @item target sim @r{[}@var{simargs}@r{]} @dots{}
22518 @cindex built-in simulator target
22519 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
22520 In general,
22521 @smallexample
22522 target sim
22523 load
22524 run
22525 @end smallexample
22526 @noindent
22527 works; however, you cannot assume that a specific memory map, device
22528 drivers, or even basic I/O is available, although some simulators do
22529 provide these. For info about any processor-specific simulator details,
22530 see the appropriate section in @ref{Embedded Processors, ,Embedded
22531 Processors}.
22532
22533 @item target native
22534 @cindex native target
22535 Setup for local/native process debugging. Useful to make the
22536 @code{run} command spawn native processes (likewise @code{attach},
22537 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
22538 (@pxref{set auto-connect-native-target}).
22539
22540 @end table
22541
22542 Different targets are available on different configurations of @value{GDBN};
22543 your configuration may have more or fewer targets.
22544
22545 Many remote targets require you to download the executable's code once
22546 you've successfully established a connection. You may wish to control
22547 various aspects of this process.
22548
22549 @table @code
22550
22551 @item set hash
22552 @kindex set hash@r{, for remote monitors}
22553 @cindex hash mark while downloading
22554 This command controls whether a hash mark @samp{#} is displayed while
22555 downloading a file to the remote monitor. If on, a hash mark is
22556 displayed after each S-record is successfully downloaded to the
22557 monitor.
22558
22559 @item show hash
22560 @kindex show hash@r{, for remote monitors}
22561 Show the current status of displaying the hash mark.
22562
22563 @item set debug monitor
22564 @kindex set debug monitor
22565 @cindex display remote monitor communications
22566 Enable or disable display of communications messages between
22567 @value{GDBN} and the remote monitor.
22568
22569 @item show debug monitor
22570 @kindex show debug monitor
22571 Show the current status of displaying communications between
22572 @value{GDBN} and the remote monitor.
22573 @end table
22574
22575 @table @code
22576
22577 @kindex load @var{filename} @var{offset}
22578 @item load @var{filename} @var{offset}
22579 @anchor{load}
22580 Depending on what remote debugging facilities are configured into
22581 @value{GDBN}, the @code{load} command may be available. Where it exists, it
22582 is meant to make @var{filename} (an executable) available for debugging
22583 on the remote system---by downloading, or dynamic linking, for example.
22584 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
22585 the @code{add-symbol-file} command.
22586
22587 If your @value{GDBN} does not have a @code{load} command, attempting to
22588 execute it gets the error message ``@code{You can't do that when your
22589 target is @dots{}}''
22590
22591 The file is loaded at whatever address is specified in the executable.
22592 For some object file formats, you can specify the load address when you
22593 link the program; for other formats, like a.out, the object file format
22594 specifies a fixed address.
22595 @c FIXME! This would be a good place for an xref to the GNU linker doc.
22596
22597 It is also possible to tell @value{GDBN} to load the executable file at a
22598 specific offset described by the optional argument @var{offset}. When
22599 @var{offset} is provided, @var{filename} must also be provided.
22600
22601 Depending on the remote side capabilities, @value{GDBN} may be able to
22602 load programs into flash memory.
22603
22604 @code{load} does not repeat if you press @key{RET} again after using it.
22605 @end table
22606
22607 @table @code
22608
22609 @kindex flash-erase
22610 @item flash-erase
22611 @anchor{flash-erase}
22612
22613 Erases all known flash memory regions on the target.
22614
22615 @end table
22616
22617 @node Byte Order
22618 @section Choosing Target Byte Order
22619
22620 @cindex choosing target byte order
22621 @cindex target byte order
22622
22623 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
22624 offer the ability to run either big-endian or little-endian byte
22625 orders. Usually the executable or symbol will include a bit to
22626 designate the endian-ness, and you will not need to worry about
22627 which to use. However, you may still find it useful to adjust
22628 @value{GDBN}'s idea of processor endian-ness manually.
22629
22630 @table @code
22631 @kindex set endian
22632 @item set endian big
22633 Instruct @value{GDBN} to assume the target is big-endian.
22634
22635 @item set endian little
22636 Instruct @value{GDBN} to assume the target is little-endian.
22637
22638 @item set endian auto
22639 Instruct @value{GDBN} to use the byte order associated with the
22640 executable.
22641
22642 @item show endian
22643 Display @value{GDBN}'s current idea of the target byte order.
22644
22645 @end table
22646
22647 If the @code{set endian auto} mode is in effect and no executable has
22648 been selected, then the endianness used is the last one chosen either
22649 by one of the @code{set endian big} and @code{set endian little}
22650 commands or by inferring from the last executable used. If no
22651 endianness has been previously chosen, then the default for this mode
22652 is inferred from the target @value{GDBN} has been built for, and is
22653 @code{little} if the name of the target CPU has an @code{el} suffix
22654 and @code{big} otherwise.
22655
22656 Note that these commands merely adjust interpretation of symbolic
22657 data on the host, and that they have absolutely no effect on the
22658 target system.
22659
22660
22661 @node Remote Debugging
22662 @chapter Debugging Remote Programs
22663 @cindex remote debugging
22664
22665 If you are trying to debug a program running on a machine that cannot run
22666 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22667 For example, you might use remote debugging on an operating system kernel,
22668 or on a small system which does not have a general purpose operating system
22669 powerful enough to run a full-featured debugger.
22670
22671 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22672 to make this work with particular debugging targets. In addition,
22673 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22674 but not specific to any particular target system) which you can use if you
22675 write the remote stubs---the code that runs on the remote system to
22676 communicate with @value{GDBN}.
22677
22678 Other remote targets may be available in your
22679 configuration of @value{GDBN}; use @code{help target} to list them.
22680
22681 @menu
22682 * Connecting:: Connecting to a remote target
22683 * File Transfer:: Sending files to a remote system
22684 * Server:: Using the gdbserver program
22685 * Remote Configuration:: Remote configuration
22686 * Remote Stub:: Implementing a remote stub
22687 @end menu
22688
22689 @node Connecting
22690 @section Connecting to a Remote Target
22691 @cindex remote debugging, connecting
22692 @cindex @code{gdbserver}, connecting
22693 @cindex remote debugging, types of connections
22694 @cindex @code{gdbserver}, types of connections
22695 @cindex @code{gdbserver}, @code{target remote} mode
22696 @cindex @code{gdbserver}, @code{target extended-remote} mode
22697
22698 This section describes how to connect to a remote target, including the
22699 types of connections and their differences, how to set up executable and
22700 symbol files on the host and target, and the commands used for
22701 connecting to and disconnecting from the remote target.
22702
22703 @subsection Types of Remote Connections
22704
22705 @value{GDBN} supports two types of remote connections, @code{target remote}
22706 mode and @code{target extended-remote} mode. Note that many remote targets
22707 support only @code{target remote} mode. There are several major
22708 differences between the two types of connections, enumerated here:
22709
22710 @table @asis
22711
22712 @cindex remote debugging, detach and program exit
22713 @item Result of detach or program exit
22714 @strong{With target remote mode:} When the debugged program exits or you
22715 detach from it, @value{GDBN} disconnects from the target. When using
22716 @code{gdbserver}, @code{gdbserver} will exit.
22717
22718 @strong{With target extended-remote mode:} When the debugged program exits or
22719 you detach from it, @value{GDBN} remains connected to the target, even
22720 though no program is running. You can rerun the program, attach to a
22721 running program, or use @code{monitor} commands specific to the target.
22722
22723 When using @code{gdbserver} in this case, it does not exit unless it was
22724 invoked using the @option{--once} option. If the @option{--once} option
22725 was not used, you can ask @code{gdbserver} to exit using the
22726 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22727
22728 @item Specifying the program to debug
22729 For both connection types you use the @code{file} command to specify the
22730 program on the host system. If you are using @code{gdbserver} there are
22731 some differences in how to specify the location of the program on the
22732 target.
22733
22734 @strong{With target remote mode:} You must either specify the program to debug
22735 on the @code{gdbserver} command line or use the @option{--attach} option
22736 (@pxref{Attaching to a program,,Attaching to a Running Program}).
22737
22738 @cindex @option{--multi}, @code{gdbserver} option
22739 @strong{With target extended-remote mode:} You may specify the program to debug
22740 on the @code{gdbserver} command line, or you can load the program or attach
22741 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22742
22743 @anchor{--multi Option in Types of Remote Connnections}
22744 You can start @code{gdbserver} without supplying an initial command to run
22745 or process ID to attach. To do this, use the @option{--multi} command line
22746 option. Then you can connect using @code{target extended-remote} and start
22747 the program you want to debug (see below for details on using the
22748 @code{run} command in this scenario). Note that the conditions under which
22749 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
22750 (@code{target remote} or @code{target extended-remote}). The
22751 @option{--multi} option to @code{gdbserver} has no influence on that.
22752
22753 @item The @code{run} command
22754 @strong{With target remote mode:} The @code{run} command is not
22755 supported. Once a connection has been established, you can use all
22756 the usual @value{GDBN} commands to examine and change data. The
22757 remote program is already running, so you can use commands like
22758 @kbd{step} and @kbd{continue}.
22759
22760 @strong{With target extended-remote mode:} The @code{run} command is
22761 supported. The @code{run} command uses the value set by
22762 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
22763 the program to run. Command line arguments are supported, except for
22764 wildcard expansion and I/O redirection (@pxref{Arguments}).
22765
22766 If you specify the program to debug on the command line, then the
22767 @code{run} command is not required to start execution, and you can
22768 resume using commands like @kbd{step} and @kbd{continue} as with
22769 @code{target remote} mode.
22770
22771 @anchor{Attaching in Types of Remote Connections}
22772 @item Attaching
22773 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22774 not supported. To attach to a running program using @code{gdbserver}, you
22775 must use the @option{--attach} option (@pxref{Running gdbserver}).
22776
22777 @strong{With target extended-remote mode:} To attach to a running program,
22778 you may use the @code{attach} command after the connection has been
22779 established. If you are using @code{gdbserver}, you may also invoke
22780 @code{gdbserver} using the @option{--attach} option
22781 (@pxref{Running gdbserver}).
22782
22783 Some remote targets allow @value{GDBN} to determine the executable file running
22784 in the process the debugger is attaching to. In such a case, @value{GDBN}
22785 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22786 between the executable file name running in the process and the name of the
22787 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22788
22789 @end table
22790
22791 @anchor{Host and target files}
22792 @subsection Host and Target Files
22793 @cindex remote debugging, symbol files
22794 @cindex symbol files, remote debugging
22795
22796 @value{GDBN}, running on the host, needs access to symbol and debugging
22797 information for your program running on the target. This requires
22798 access to an unstripped copy of your program, and possibly any associated
22799 symbol files. Note that this section applies equally to both @code{target
22800 remote} mode and @code{target extended-remote} mode.
22801
22802 Some remote targets (@pxref{qXfer executable filename read}, and
22803 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22804 the same connection used to communicate with @value{GDBN}. With such a
22805 target, if the remote program is unstripped, the only command you need is
22806 @code{target remote} (or @code{target extended-remote}).
22807
22808 If the remote program is stripped, or the target does not support remote
22809 program file access, start up @value{GDBN} using the name of the local
22810 unstripped copy of your program as the first argument, or use the
22811 @code{file} command. Use @code{set sysroot} to specify the location (on
22812 the host) of target libraries (unless your @value{GDBN} was compiled with
22813 the correct sysroot using @code{--with-sysroot}). Alternatively, you
22814 may use @code{set solib-search-path} to specify how @value{GDBN} locates
22815 target libraries.
22816
22817 The symbol file and target libraries must exactly match the executable
22818 and libraries on the target, with one exception: the files on the host
22819 system should not be stripped, even if the files on the target system
22820 are. Mismatched or missing files will lead to confusing results
22821 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22822 files may also prevent @code{gdbserver} from debugging multi-threaded
22823 programs.
22824
22825 @subsection Remote Connection Commands
22826 @cindex remote connection commands
22827 @value{GDBN} can communicate with the target over a serial line, a
22828 local Unix domain socket, or
22829 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22830 each case, @value{GDBN} uses the same protocol for debugging your
22831 program; only the medium carrying the debugging packets varies. The
22832 @code{target remote} and @code{target extended-remote} commands
22833 establish a connection to the target. Both commands accept the same
22834 arguments, which indicate the medium to use:
22835
22836 @table @code
22837
22838 @item target remote @var{serial-device}
22839 @itemx target extended-remote @var{serial-device}
22840 @cindex serial line, @code{target remote}
22841 Use @var{serial-device} to communicate with the target. For example,
22842 to use a serial line connected to the device named @file{/dev/ttyb}:
22843
22844 @smallexample
22845 target remote /dev/ttyb
22846 @end smallexample
22847
22848 If you're using a serial line, you may want to give @value{GDBN} the
22849 @samp{--baud} option, or use the @code{set serial baud} command
22850 (@pxref{Remote Configuration, set serial baud}) before the
22851 @code{target} command.
22852
22853 @item target remote @var{local-socket}
22854 @itemx target extended-remote @var{local-socket}
22855 @cindex local socket, @code{target remote}
22856 @cindex Unix domain socket
22857 Use @var{local-socket} to communicate with the target. For example,
22858 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22859
22860 @smallexample
22861 target remote /tmp/gdb-socket0
22862 @end smallexample
22863
22864 Note that this command has the same form as the command to connect
22865 to a serial line. @value{GDBN} will automatically determine which
22866 kind of file you have specified and will make the appropriate kind
22867 of connection.
22868 This feature is not available if the host system does not support
22869 Unix domain sockets.
22870
22871 @item target remote @code{@var{host}:@var{port}}
22872 @itemx target remote @code{[@var{host}]:@var{port}}
22873 @itemx target remote @code{tcp:@var{host}:@var{port}}
22874 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22875 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22876 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22877 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22878 @itemx target extended-remote @code{@var{host}:@var{port}}
22879 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22880 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22881 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22882 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22883 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22884 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22885 @cindex @acronym{TCP} port, @code{target remote}
22886 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22887 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22888 address, or a numeric @acronym{IPv6} address (with or without the
22889 square brackets to separate the address from the port); @var{port}
22890 must be a decimal number. The @var{host} could be the target machine
22891 itself, if it is directly connected to the net, or it might be a
22892 terminal server which in turn has a serial line to the target.
22893
22894 For example, to connect to port 2828 on a terminal server named
22895 @code{manyfarms}:
22896
22897 @smallexample
22898 target remote manyfarms:2828
22899 @end smallexample
22900
22901 To connect to port 2828 on a terminal server whose address is
22902 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22903 square bracket syntax:
22904
22905 @smallexample
22906 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22907 @end smallexample
22908
22909 @noindent
22910 or explicitly specify the @acronym{IPv6} protocol:
22911
22912 @smallexample
22913 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22914 @end smallexample
22915
22916 This last example may be confusing to the reader, because there is no
22917 visible separation between the hostname and the port number.
22918 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22919 using square brackets for clarity. However, it is important to
22920 mention that for @value{GDBN} there is no ambiguity: the number after
22921 the last colon is considered to be the port number.
22922
22923 If your remote target is actually running on the same machine as your
22924 debugger session (e.g.@: a simulator for your target running on the
22925 same host), you can omit the hostname. For example, to connect to
22926 port 1234 on your local machine:
22927
22928 @smallexample
22929 target remote :1234
22930 @end smallexample
22931 @noindent
22932
22933 Note that the colon is still required here.
22934
22935 @item target remote @code{udp:@var{host}:@var{port}}
22936 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22937 @itemx target remote @code{udp4:@var{host}:@var{port}}
22938 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22939 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22940 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22941 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22942 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22943 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22944 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22945 @cindex @acronym{UDP} port, @code{target remote}
22946 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22947 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22948
22949 @smallexample
22950 target remote udp:manyfarms:2828
22951 @end smallexample
22952
22953 When using a @acronym{UDP} connection for remote debugging, you should
22954 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22955 can silently drop packets on busy or unreliable networks, which will
22956 cause havoc with your debugging session.
22957
22958 @item target remote | @var{command}
22959 @itemx target extended-remote | @var{command}
22960 @cindex pipe, @code{target remote} to
22961 Run @var{command} in the background and communicate with it using a
22962 pipe. The @var{command} is a shell command, to be parsed and expanded
22963 by the system's command shell, @code{/bin/sh}; it should expect remote
22964 protocol packets on its standard input, and send replies on its
22965 standard output. You could use this to run a stand-alone simulator
22966 that speaks the remote debugging protocol, to make net connections
22967 using programs like @code{ssh}, or for other similar tricks.
22968
22969 If @var{command} closes its standard output (perhaps by exiting),
22970 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22971 program has already exited, this will have no effect.)
22972
22973 @end table
22974
22975 @cindex interrupting remote programs
22976 @cindex remote programs, interrupting
22977 Whenever @value{GDBN} is waiting for the remote program, if you type the
22978 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22979 program. This may or may not succeed, depending in part on the hardware
22980 and the serial drivers the remote system uses. If you type the
22981 interrupt character once again, @value{GDBN} displays this prompt:
22982
22983 @smallexample
22984 Interrupted while waiting for the program.
22985 Give up (and stop debugging it)? (y or n)
22986 @end smallexample
22987
22988 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22989 the remote debugging session. (If you decide you want to try again later,
22990 you can use @kbd{target remote} again to connect once more.) If you type
22991 @kbd{n}, @value{GDBN} goes back to waiting.
22992
22993 In @code{target extended-remote} mode, typing @kbd{n} will leave
22994 @value{GDBN} connected to the target.
22995
22996 @table @code
22997 @kindex detach (remote)
22998 @item detach
22999 When you have finished debugging the remote program, you can use the
23000 @code{detach} command to release it from @value{GDBN} control.
23001 Detaching from the target normally resumes its execution, but the results
23002 will depend on your particular remote stub. After the @code{detach}
23003 command in @code{target remote} mode, @value{GDBN} is free to connect to
23004 another target. In @code{target extended-remote} mode, @value{GDBN} is
23005 still connected to the target.
23006
23007 @kindex disconnect
23008 @item disconnect
23009 The @code{disconnect} command closes the connection to the target, and
23010 the target is generally not resumed. It will wait for @value{GDBN}
23011 (this instance or another one) to connect and continue debugging. After
23012 the @code{disconnect} command, @value{GDBN} is again free to connect to
23013 another target.
23014
23015 @cindex send command to remote monitor
23016 @cindex extend @value{GDBN} for remote targets
23017 @cindex add new commands for external monitor
23018 @kindex monitor
23019 @item monitor @var{cmd}
23020 This command allows you to send arbitrary commands directly to the
23021 remote monitor. Since @value{GDBN} doesn't care about the commands it
23022 sends like this, this command is the way to extend @value{GDBN}---you
23023 can add new commands that only the external monitor will understand
23024 and implement.
23025 @end table
23026
23027 @node File Transfer
23028 @section Sending files to a remote system
23029 @cindex remote target, file transfer
23030 @cindex file transfer
23031 @cindex sending files to remote systems
23032
23033 Some remote targets offer the ability to transfer files over the same
23034 connection used to communicate with @value{GDBN}. This is convenient
23035 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
23036 running @code{gdbserver} over a network interface. For other targets,
23037 e.g.@: embedded devices with only a single serial port, this may be
23038 the only way to upload or download files.
23039
23040 Not all remote targets support these commands.
23041
23042 @table @code
23043 @kindex remote put
23044 @item remote put @var{hostfile} @var{targetfile}
23045 Copy file @var{hostfile} from the host system (the machine running
23046 @value{GDBN}) to @var{targetfile} on the target system.
23047
23048 @kindex remote get
23049 @item remote get @var{targetfile} @var{hostfile}
23050 Copy file @var{targetfile} from the target system to @var{hostfile}
23051 on the host system.
23052
23053 @kindex remote delete
23054 @item remote delete @var{targetfile}
23055 Delete @var{targetfile} from the target system.
23056
23057 @end table
23058
23059 @node Server
23060 @section Using the @code{gdbserver} Program
23061
23062 @kindex gdbserver
23063 @cindex remote connection without stubs
23064 @code{gdbserver} is a control program for Unix-like systems, which
23065 allows you to connect your program with a remote @value{GDBN} via
23066 @code{target remote} or @code{target extended-remote}---but without
23067 linking in the usual debugging stub.
23068
23069 @code{gdbserver} is not a complete replacement for the debugging stubs,
23070 because it requires essentially the same operating-system facilities
23071 that @value{GDBN} itself does. In fact, a system that can run
23072 @code{gdbserver} to connect to a remote @value{GDBN} could also run
23073 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
23074 because it is a much smaller program than @value{GDBN} itself. It is
23075 also easier to port than all of @value{GDBN}, so you may be able to get
23076 started more quickly on a new system by using @code{gdbserver}.
23077 Finally, if you develop code for real-time systems, you may find that
23078 the tradeoffs involved in real-time operation make it more convenient to
23079 do as much development work as possible on another system, for example
23080 by cross-compiling. You can use @code{gdbserver} to make a similar
23081 choice for debugging.
23082
23083 @value{GDBN} and @code{gdbserver} communicate via either a serial line
23084 or a TCP connection, using the standard @value{GDBN} remote serial
23085 protocol.
23086
23087 @quotation
23088 @emph{Warning:} @code{gdbserver} does not have any built-in security.
23089 Do not run @code{gdbserver} connected to any public network; a
23090 @value{GDBN} connection to @code{gdbserver} provides access to the
23091 target system with the same privileges as the user running
23092 @code{gdbserver}.
23093 @end quotation
23094
23095 @anchor{Running gdbserver}
23096 @subsection Running @code{gdbserver}
23097 @cindex arguments, to @code{gdbserver}
23098 @cindex @code{gdbserver}, command-line arguments
23099
23100 Run @code{gdbserver} on the target system. You need a copy of the
23101 program you want to debug, including any libraries it requires.
23102 @code{gdbserver} does not need your program's symbol table, so you can
23103 strip the program if necessary to save space. @value{GDBN} on the host
23104 system does all the symbol handling.
23105
23106 To use the server, you must tell it how to communicate with @value{GDBN};
23107 the name of your program; and the arguments for your program. The usual
23108 syntax is:
23109
23110 @smallexample
23111 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
23112 @end smallexample
23113
23114 @var{comm} is either a device name (to use a serial line), or a TCP
23115 hostname and portnumber, or @code{-} or @code{stdio} to use
23116 stdin/stdout of @code{gdbserver}.
23117 For example, to debug Emacs with the argument
23118 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
23119 @file{/dev/com1}:
23120
23121 @smallexample
23122 target> gdbserver /dev/com1 emacs foo.txt
23123 @end smallexample
23124
23125 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
23126 with it.
23127
23128 To use a TCP connection instead of a serial line:
23129
23130 @smallexample
23131 target> gdbserver host:2345 emacs foo.txt
23132 @end smallexample
23133
23134 The only difference from the previous example is the first argument,
23135 specifying that you are communicating with the host @value{GDBN} via
23136 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
23137 expect a TCP connection from machine @samp{host} to local TCP port 2345.
23138 (Currently, the @samp{host} part is ignored.) You can choose any number
23139 you want for the port number as long as it does not conflict with any
23140 TCP ports already in use on the target system (for example, @code{23} is
23141 reserved for @code{telnet}).@footnote{If you choose a port number that
23142 conflicts with another service, @code{gdbserver} prints an error message
23143 and exits.} You must use the same port number with the host @value{GDBN}
23144 @code{target remote} command.
23145
23146 The @code{stdio} connection is useful when starting @code{gdbserver}
23147 with ssh:
23148
23149 @smallexample
23150 (gdb) target remote | ssh -T hostname gdbserver - hello
23151 @end smallexample
23152
23153 The @samp{-T} option to ssh is provided because we don't need a remote pty,
23154 and we don't want escape-character handling. Ssh does this by default when
23155 a command is provided, the flag is provided to make it explicit.
23156 You could elide it if you want to.
23157
23158 Programs started with stdio-connected gdbserver have @file{/dev/null} for
23159 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
23160 display through a pipe connected to gdbserver.
23161 Both @code{stdout} and @code{stderr} use the same pipe.
23162
23163 @anchor{Attaching to a program}
23164 @subsubsection Attaching to a Running Program
23165 @cindex attach to a program, @code{gdbserver}
23166 @cindex @option{--attach}, @code{gdbserver} option
23167
23168 On some targets, @code{gdbserver} can also attach to running programs.
23169 This is accomplished via the @code{--attach} argument. The syntax is:
23170
23171 @smallexample
23172 target> gdbserver --attach @var{comm} @var{pid}
23173 @end smallexample
23174
23175 @var{pid} is the process ID of a currently running process. It isn't
23176 necessary to point @code{gdbserver} at a binary for the running process.
23177
23178 In @code{target extended-remote} mode, you can also attach using the
23179 @value{GDBN} attach command
23180 (@pxref{Attaching in Types of Remote Connections}).
23181
23182 @pindex pidof
23183 You can debug processes by name instead of process ID if your target has the
23184 @code{pidof} utility:
23185
23186 @smallexample
23187 target> gdbserver --attach @var{comm} `pidof @var{program}`
23188 @end smallexample
23189
23190 In case more than one copy of @var{program} is running, or @var{program}
23191 has multiple threads, most versions of @code{pidof} support the
23192 @code{-s} option to only return the first process ID.
23193
23194 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
23195
23196 This section applies only when @code{gdbserver} is run to listen on a TCP
23197 port.
23198
23199 @code{gdbserver} normally terminates after all of its debugged processes have
23200 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
23201 extended-remote}, @code{gdbserver} stays running even with no processes left.
23202 @value{GDBN} normally terminates the spawned debugged process on its exit,
23203 which normally also terminates @code{gdbserver} in the @kbd{target remote}
23204 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
23205 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
23206 stays running even in the @kbd{target remote} mode.
23207
23208 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
23209 Such reconnecting is useful for features like @ref{disconnected tracing}. For
23210 completeness, at most one @value{GDBN} can be connected at a time.
23211
23212 @cindex @option{--once}, @code{gdbserver} option
23213 By default, @code{gdbserver} keeps the listening TCP port open, so that
23214 subsequent connections are possible. However, if you start @code{gdbserver}
23215 with the @option{--once} option, it will stop listening for any further
23216 connection attempts after connecting to the first @value{GDBN} session. This
23217 means no further connections to @code{gdbserver} will be possible after the
23218 first one. It also means @code{gdbserver} will terminate after the first
23219 connection with remote @value{GDBN} has closed, even for unexpectedly closed
23220 connections and even in the @kbd{target extended-remote} mode. The
23221 @option{--once} option allows reusing the same port number for connecting to
23222 multiple instances of @code{gdbserver} running on the same host, since each
23223 instance closes its port after the first connection.
23224
23225 @anchor{Other Command-Line Arguments for gdbserver}
23226 @subsubsection Other Command-Line Arguments for @code{gdbserver}
23227
23228 You can use the @option{--multi} option to start @code{gdbserver} without
23229 specifying a program to debug or a process to attach to. Then you can
23230 attach in @code{target extended-remote} mode and run or attach to a
23231 program. For more information,
23232 @pxref{--multi Option in Types of Remote Connnections}.
23233
23234 @cindex @option{--debug}, @code{gdbserver} option
23235 The @option{--debug} option tells @code{gdbserver} to display extra
23236 status information about the debugging process.
23237 @cindex @option{--remote-debug}, @code{gdbserver} option
23238 The @option{--remote-debug} option tells @code{gdbserver} to display
23239 remote protocol debug output.
23240 @cindex @option{--debug-file}, @code{gdbserver} option
23241 @cindex @code{gdbserver}, send all debug output to a single file
23242 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
23243 write any debug output to the given @var{filename}. These options are intended
23244 for @code{gdbserver} development and for bug reports to the developers.
23245
23246 @cindex @option{--debug-format}, @code{gdbserver} option
23247 The @option{--debug-format=option1[,option2,...]} option tells
23248 @code{gdbserver} to include additional information in each output.
23249 Possible options are:
23250
23251 @table @code
23252 @item none
23253 Turn off all extra information in debugging output.
23254 @item all
23255 Turn on all extra information in debugging output.
23256 @item timestamps
23257 Include a timestamp in each line of debugging output.
23258 @end table
23259
23260 Options are processed in order. Thus, for example, if @option{none}
23261 appears last then no additional information is added to debugging output.
23262
23263 @cindex @option{--wrapper}, @code{gdbserver} option
23264 The @option{--wrapper} option specifies a wrapper to launch programs
23265 for debugging. The option should be followed by the name of the
23266 wrapper, then any command-line arguments to pass to the wrapper, then
23267 @kbd{--} indicating the end of the wrapper arguments.
23268
23269 @code{gdbserver} runs the specified wrapper program with a combined
23270 command line including the wrapper arguments, then the name of the
23271 program to debug, then any arguments to the program. The wrapper
23272 runs until it executes your program, and then @value{GDBN} gains control.
23273
23274 You can use any program that eventually calls @code{execve} with
23275 its arguments as a wrapper. Several standard Unix utilities do
23276 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
23277 with @code{exec "$@@"} will also work.
23278
23279 For example, you can use @code{env} to pass an environment variable to
23280 the debugged program, without setting the variable in @code{gdbserver}'s
23281 environment:
23282
23283 @smallexample
23284 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
23285 @end smallexample
23286
23287 @cindex @option{--selftest}
23288 The @option{--selftest} option runs the self tests in @code{gdbserver}:
23289
23290 @smallexample
23291 $ gdbserver --selftest
23292 Ran 2 unit tests, 0 failed
23293 @end smallexample
23294
23295 These tests are disabled in release.
23296 @subsection Connecting to @code{gdbserver}
23297
23298 The basic procedure for connecting to the remote target is:
23299 @itemize
23300
23301 @item
23302 Run @value{GDBN} on the host system.
23303
23304 @item
23305 Make sure you have the necessary symbol files
23306 (@pxref{Host and target files}).
23307 Load symbols for your application using the @code{file} command before you
23308 connect. Use @code{set sysroot} to locate target libraries (unless your
23309 @value{GDBN} was compiled with the correct sysroot using
23310 @code{--with-sysroot}).
23311
23312 @item
23313 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
23314 For TCP connections, you must start up @code{gdbserver} prior to using
23315 the @code{target} command. Otherwise you may get an error whose
23316 text depends on the host system, but which usually looks something like
23317 @samp{Connection refused}. Don't use the @code{load}
23318 command in @value{GDBN} when using @code{target remote} mode, since the
23319 program is already on the target.
23320
23321 @end itemize
23322
23323 @anchor{Monitor Commands for gdbserver}
23324 @subsection Monitor Commands for @code{gdbserver}
23325 @cindex monitor commands, for @code{gdbserver}
23326
23327 During a @value{GDBN} session using @code{gdbserver}, you can use the
23328 @code{monitor} command to send special requests to @code{gdbserver}.
23329 Here are the available commands.
23330
23331 @table @code
23332 @item monitor help
23333 List the available monitor commands.
23334
23335 @item monitor set debug 0
23336 @itemx monitor set debug 1
23337 Disable or enable general debugging messages.
23338
23339 @item monitor set remote-debug 0
23340 @itemx monitor set remote-debug 1
23341 Disable or enable specific debugging messages associated with the remote
23342 protocol (@pxref{Remote Protocol}).
23343
23344 @item monitor set debug-file filename
23345 @itemx monitor set debug-file
23346 Send any debug output to the given file, or to stderr.
23347
23348 @item monitor set debug-format option1@r{[},option2,...@r{]}
23349 Specify additional text to add to debugging messages.
23350 Possible options are:
23351
23352 @table @code
23353 @item none
23354 Turn off all extra information in debugging output.
23355 @item all
23356 Turn on all extra information in debugging output.
23357 @item timestamps
23358 Include a timestamp in each line of debugging output.
23359 @end table
23360
23361 Options are processed in order. Thus, for example, if @option{none}
23362 appears last then no additional information is added to debugging output.
23363
23364 @item monitor set libthread-db-search-path [PATH]
23365 @cindex gdbserver, search path for @code{libthread_db}
23366 When this command is issued, @var{path} is a colon-separated list of
23367 directories to search for @code{libthread_db} (@pxref{Threads,,set
23368 libthread-db-search-path}). If you omit @var{path},
23369 @samp{libthread-db-search-path} will be reset to its default value.
23370
23371 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
23372 not supported in @code{gdbserver}.
23373
23374 @item monitor exit
23375 Tell gdbserver to exit immediately. This command should be followed by
23376 @code{disconnect} to close the debugging session. @code{gdbserver} will
23377 detach from any attached processes and kill any processes it created.
23378 Use @code{monitor exit} to terminate @code{gdbserver} at the end
23379 of a multi-process mode debug session.
23380
23381 @end table
23382
23383 @subsection Tracepoints support in @code{gdbserver}
23384 @cindex tracepoints support in @code{gdbserver}
23385
23386 On some targets, @code{gdbserver} supports tracepoints, fast
23387 tracepoints and static tracepoints.
23388
23389 For fast or static tracepoints to work, a special library called the
23390 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
23391 This library is built and distributed as an integral part of
23392 @code{gdbserver}. In addition, support for static tracepoints
23393 requires building the in-process agent library with static tracepoints
23394 support. At present, the UST (LTTng Userspace Tracer,
23395 @url{http://lttng.org/ust}) tracing engine is supported. This support
23396 is automatically available if UST development headers are found in the
23397 standard include path when @code{gdbserver} is built, or if
23398 @code{gdbserver} was explicitly configured using @option{--with-ust}
23399 to point at such headers. You can explicitly disable the support
23400 using @option{--with-ust=no}.
23401
23402 There are several ways to load the in-process agent in your program:
23403
23404 @table @code
23405 @item Specifying it as dependency at link time
23406
23407 You can link your program dynamically with the in-process agent
23408 library. On most systems, this is accomplished by adding
23409 @code{-linproctrace} to the link command.
23410
23411 @item Using the system's preloading mechanisms
23412
23413 You can force loading the in-process agent at startup time by using
23414 your system's support for preloading shared libraries. Many Unixes
23415 support the concept of preloading user defined libraries. In most
23416 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
23417 in the environment. See also the description of @code{gdbserver}'s
23418 @option{--wrapper} command line option.
23419
23420 @item Using @value{GDBN} to force loading the agent at run time
23421
23422 On some systems, you can force the inferior to load a shared library,
23423 by calling a dynamic loader function in the inferior that takes care
23424 of dynamically looking up and loading a shared library. On most Unix
23425 systems, the function is @code{dlopen}. You'll use the @code{call}
23426 command for that. For example:
23427
23428 @smallexample
23429 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
23430 @end smallexample
23431
23432 Note that on most Unix systems, for the @code{dlopen} function to be
23433 available, the program needs to be linked with @code{-ldl}.
23434 @end table
23435
23436 On systems that have a userspace dynamic loader, like most Unix
23437 systems, when you connect to @code{gdbserver} using @code{target
23438 remote}, you'll find that the program is stopped at the dynamic
23439 loader's entry point, and no shared library has been loaded in the
23440 program's address space yet, including the in-process agent. In that
23441 case, before being able to use any of the fast or static tracepoints
23442 features, you need to let the loader run and load the shared
23443 libraries. The simplest way to do that is to run the program to the
23444 main procedure. E.g., if debugging a C or C@t{++} program, start
23445 @code{gdbserver} like so:
23446
23447 @smallexample
23448 $ gdbserver :9999 myprogram
23449 @end smallexample
23450
23451 Start GDB and connect to @code{gdbserver} like so, and run to main:
23452
23453 @smallexample
23454 $ gdb myprogram
23455 (@value{GDBP}) target remote myhost:9999
23456 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
23457 (@value{GDBP}) b main
23458 (@value{GDBP}) continue
23459 @end smallexample
23460
23461 The in-process tracing agent library should now be loaded into the
23462 process; you can confirm it with the @code{info sharedlibrary}
23463 command, which will list @file{libinproctrace.so} as loaded in the
23464 process. You are now ready to install fast tracepoints, list static
23465 tracepoint markers, probe static tracepoints markers, and start
23466 tracing.
23467
23468 @node Remote Configuration
23469 @section Remote Configuration
23470
23471 @kindex set remote
23472 @kindex show remote
23473 This section documents the configuration options available when
23474 debugging remote programs. For the options related to the File I/O
23475 extensions of the remote protocol, see @ref{system,
23476 system-call-allowed}.
23477
23478 @table @code
23479 @item set remoteaddresssize @var{bits}
23480 @cindex address size for remote targets
23481 @cindex bits in remote address
23482 Set the maximum size of address in a memory packet to the specified
23483 number of bits. @value{GDBN} will mask off the address bits above
23484 that number, when it passes addresses to the remote target. The
23485 default value is the number of bits in the target's address.
23486
23487 @item show remoteaddresssize
23488 Show the current value of remote address size in bits.
23489
23490 @item set serial baud @var{n}
23491 @cindex baud rate for remote targets
23492 Set the baud rate for the remote serial I/O to @var{n} baud. The
23493 value is used to set the speed of the serial port used for debugging
23494 remote targets.
23495
23496 @item show serial baud
23497 Show the current speed of the remote connection.
23498
23499 @item set serial parity @var{parity}
23500 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
23501 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
23502
23503 @item show serial parity
23504 Show the current parity of the serial port.
23505
23506 @item set remotebreak
23507 @cindex interrupt remote programs
23508 @cindex BREAK signal instead of Ctrl-C
23509 @anchor{set remotebreak}
23510 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
23511 when you type @kbd{Ctrl-c} to interrupt the program running
23512 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
23513 character instead. The default is off, since most remote systems
23514 expect to see @samp{Ctrl-C} as the interrupt signal.
23515
23516 @item show remotebreak
23517 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
23518 interrupt the remote program.
23519
23520 @item set remoteflow on
23521 @itemx set remoteflow off
23522 @kindex set remoteflow
23523 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
23524 on the serial port used to communicate to the remote target.
23525
23526 @item show remoteflow
23527 @kindex show remoteflow
23528 Show the current setting of hardware flow control.
23529
23530 @item set remotelogbase @var{base}
23531 Set the base (a.k.a.@: radix) of logging serial protocol
23532 communications to @var{base}. Supported values of @var{base} are:
23533 @code{ascii}, @code{octal}, and @code{hex}. The default is
23534 @code{ascii}.
23535
23536 @item show remotelogbase
23537 Show the current setting of the radix for logging remote serial
23538 protocol.
23539
23540 @item set remotelogfile @var{file}
23541 @cindex record serial communications on file
23542 Record remote serial communications on the named @var{file}. The
23543 default is not to record at all.
23544
23545 @item show remotelogfile
23546 Show the current setting of the file name on which to record the
23547 serial communications.
23548
23549 @item set remotetimeout @var{num}
23550 @cindex timeout for serial communications
23551 @cindex remote timeout
23552 Set the timeout limit to wait for the remote target to respond to
23553 @var{num} seconds. The default is 2 seconds.
23554
23555 @item show remotetimeout
23556 Show the current number of seconds to wait for the remote target
23557 responses.
23558
23559 @cindex limit hardware breakpoints and watchpoints
23560 @cindex remote target, limit break- and watchpoints
23561 @anchor{set remote hardware-watchpoint-limit}
23562 @anchor{set remote hardware-breakpoint-limit}
23563 @item set remote hardware-watchpoint-limit @var{limit}
23564 @itemx set remote hardware-breakpoint-limit @var{limit}
23565 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
23566 or breakpoints. The @var{limit} can be set to 0 to disable hardware
23567 watchpoints or breakpoints, and @code{unlimited} for unlimited
23568 watchpoints or breakpoints.
23569
23570 @item show remote hardware-watchpoint-limit
23571 @itemx show remote hardware-breakpoint-limit
23572 Show the current limit for the number of hardware watchpoints or
23573 breakpoints that @value{GDBN} can use.
23574
23575 @cindex limit hardware watchpoints length
23576 @cindex remote target, limit watchpoints length
23577 @anchor{set remote hardware-watchpoint-length-limit}
23578 @item set remote hardware-watchpoint-length-limit @var{limit}
23579 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
23580 length of a remote hardware watchpoint. A @var{limit} of 0 disables
23581 hardware watchpoints and @code{unlimited} allows watchpoints of any
23582 length.
23583
23584 @item show remote hardware-watchpoint-length-limit
23585 Show the current limit (in bytes) of the maximum length of
23586 a remote hardware watchpoint.
23587
23588 @item set remote exec-file @var{filename}
23589 @itemx show remote exec-file
23590 @anchor{set remote exec-file}
23591 @cindex executable file, for remote target
23592 Select the file used for @code{run} with @code{target
23593 extended-remote}. This should be set to a filename valid on the
23594 target system. If it is not set, the target will use a default
23595 filename (e.g.@: the last program run).
23596
23597 @item set remote interrupt-sequence
23598 @cindex interrupt remote programs
23599 @cindex select Ctrl-C, BREAK or BREAK-g
23600 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
23601 @samp{BREAK-g} as the
23602 sequence to the remote target in order to interrupt the execution.
23603 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
23604 is high level of serial line for some certain time.
23605 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
23606 It is @code{BREAK} signal followed by character @code{g}.
23607
23608 @item show remote interrupt-sequence
23609 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
23610 is sent by @value{GDBN} to interrupt the remote program.
23611 @code{BREAK-g} is BREAK signal followed by @code{g} and
23612 also known as Magic SysRq g.
23613
23614 @item set remote interrupt-on-connect
23615 @cindex send interrupt-sequence on start
23616 Specify whether interrupt-sequence is sent to remote target when
23617 @value{GDBN} connects to it. This is mostly needed when you debug
23618 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
23619 which is known as Magic SysRq g in order to connect @value{GDBN}.
23620
23621 @item show remote interrupt-on-connect
23622 Show whether interrupt-sequence is sent
23623 to remote target when @value{GDBN} connects to it.
23624
23625 @kindex set tcp
23626 @kindex show tcp
23627 @item set tcp auto-retry on
23628 @cindex auto-retry, for remote TCP target
23629 Enable auto-retry for remote TCP connections. This is useful if the remote
23630 debugging agent is launched in parallel with @value{GDBN}; there is a race
23631 condition because the agent may not become ready to accept the connection
23632 before @value{GDBN} attempts to connect. When auto-retry is
23633 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
23634 to establish the connection using the timeout specified by
23635 @code{set tcp connect-timeout}.
23636
23637 @item set tcp auto-retry off
23638 Do not auto-retry failed TCP connections.
23639
23640 @item show tcp auto-retry
23641 Show the current auto-retry setting.
23642
23643 @item set tcp connect-timeout @var{seconds}
23644 @itemx set tcp connect-timeout unlimited
23645 @cindex connection timeout, for remote TCP target
23646 @cindex timeout, for remote target connection
23647 Set the timeout for establishing a TCP connection to the remote target to
23648 @var{seconds}. The timeout affects both polling to retry failed connections
23649 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23650 that are merely slow to complete, and represents an approximate cumulative
23651 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23652 @value{GDBN} will keep attempting to establish a connection forever,
23653 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23654
23655 @item show tcp connect-timeout
23656 Show the current connection timeout setting.
23657 @end table
23658
23659 @cindex remote packets, enabling and disabling
23660 The @value{GDBN} remote protocol autodetects the packets supported by
23661 your debugging stub. If you need to override the autodetection, you
23662 can use these commands to enable or disable individual packets. Each
23663 packet can be set to @samp{on} (the remote target supports this
23664 packet), @samp{off} (the remote target does not support this packet),
23665 or @samp{auto} (detect remote target support for this packet). They
23666 all default to @samp{auto}. For more information about each packet,
23667 see @ref{Remote Protocol}.
23668
23669 During normal use, you should not have to use any of these commands.
23670 If you do, that may be a bug in your remote debugging stub, or a bug
23671 in @value{GDBN}. You may want to report the problem to the
23672 @value{GDBN} developers.
23673
23674 For each packet @var{name}, the command to enable or disable the
23675 packet is @code{set remote @var{name}-packet}. The available settings
23676 are:
23677
23678 @multitable @columnfractions 0.28 0.32 0.25
23679 @item Command Name
23680 @tab Remote Packet
23681 @tab Related Features
23682
23683 @item @code{fetch-register}
23684 @tab @code{p}
23685 @tab @code{info registers}
23686
23687 @item @code{set-register}
23688 @tab @code{P}
23689 @tab @code{set}
23690
23691 @item @code{binary-download}
23692 @tab @code{X}
23693 @tab @code{load}, @code{set}
23694
23695 @item @code{read-aux-vector}
23696 @tab @code{qXfer:auxv:read}
23697 @tab @code{info auxv}
23698
23699 @item @code{symbol-lookup}
23700 @tab @code{qSymbol}
23701 @tab Detecting multiple threads
23702
23703 @item @code{attach}
23704 @tab @code{vAttach}
23705 @tab @code{attach}
23706
23707 @item @code{verbose-resume}
23708 @tab @code{vCont}
23709 @tab Stepping or resuming multiple threads
23710
23711 @item @code{run}
23712 @tab @code{vRun}
23713 @tab @code{run}
23714
23715 @item @code{software-breakpoint}
23716 @tab @code{Z0}
23717 @tab @code{break}
23718
23719 @item @code{hardware-breakpoint}
23720 @tab @code{Z1}
23721 @tab @code{hbreak}
23722
23723 @item @code{write-watchpoint}
23724 @tab @code{Z2}
23725 @tab @code{watch}
23726
23727 @item @code{read-watchpoint}
23728 @tab @code{Z3}
23729 @tab @code{rwatch}
23730
23731 @item @code{access-watchpoint}
23732 @tab @code{Z4}
23733 @tab @code{awatch}
23734
23735 @item @code{pid-to-exec-file}
23736 @tab @code{qXfer:exec-file:read}
23737 @tab @code{attach}, @code{run}
23738
23739 @item @code{target-features}
23740 @tab @code{qXfer:features:read}
23741 @tab @code{set architecture}
23742
23743 @item @code{library-info}
23744 @tab @code{qXfer:libraries:read}
23745 @tab @code{info sharedlibrary}
23746
23747 @item @code{memory-map}
23748 @tab @code{qXfer:memory-map:read}
23749 @tab @code{info mem}
23750
23751 @item @code{read-sdata-object}
23752 @tab @code{qXfer:sdata:read}
23753 @tab @code{print $_sdata}
23754
23755 @item @code{read-siginfo-object}
23756 @tab @code{qXfer:siginfo:read}
23757 @tab @code{print $_siginfo}
23758
23759 @item @code{write-siginfo-object}
23760 @tab @code{qXfer:siginfo:write}
23761 @tab @code{set $_siginfo}
23762
23763 @item @code{threads}
23764 @tab @code{qXfer:threads:read}
23765 @tab @code{info threads}
23766
23767 @item @code{get-thread-local-@*storage-address}
23768 @tab @code{qGetTLSAddr}
23769 @tab Displaying @code{__thread} variables
23770
23771 @item @code{get-thread-information-block-address}
23772 @tab @code{qGetTIBAddr}
23773 @tab Display MS-Windows Thread Information Block.
23774
23775 @item @code{search-memory}
23776 @tab @code{qSearch:memory}
23777 @tab @code{find}
23778
23779 @item @code{supported-packets}
23780 @tab @code{qSupported}
23781 @tab Remote communications parameters
23782
23783 @item @code{catch-syscalls}
23784 @tab @code{QCatchSyscalls}
23785 @tab @code{catch syscall}
23786
23787 @item @code{pass-signals}
23788 @tab @code{QPassSignals}
23789 @tab @code{handle @var{signal}}
23790
23791 @item @code{program-signals}
23792 @tab @code{QProgramSignals}
23793 @tab @code{handle @var{signal}}
23794
23795 @item @code{hostio-close-packet}
23796 @tab @code{vFile:close}
23797 @tab @code{remote get}, @code{remote put}
23798
23799 @item @code{hostio-open-packet}
23800 @tab @code{vFile:open}
23801 @tab @code{remote get}, @code{remote put}
23802
23803 @item @code{hostio-pread-packet}
23804 @tab @code{vFile:pread}
23805 @tab @code{remote get}, @code{remote put}
23806
23807 @item @code{hostio-pwrite-packet}
23808 @tab @code{vFile:pwrite}
23809 @tab @code{remote get}, @code{remote put}
23810
23811 @item @code{hostio-unlink-packet}
23812 @tab @code{vFile:unlink}
23813 @tab @code{remote delete}
23814
23815 @item @code{hostio-readlink-packet}
23816 @tab @code{vFile:readlink}
23817 @tab Host I/O
23818
23819 @item @code{hostio-fstat-packet}
23820 @tab @code{vFile:fstat}
23821 @tab Host I/O
23822
23823 @item @code{hostio-setfs-packet}
23824 @tab @code{vFile:setfs}
23825 @tab Host I/O
23826
23827 @item @code{noack-packet}
23828 @tab @code{QStartNoAckMode}
23829 @tab Packet acknowledgment
23830
23831 @item @code{osdata}
23832 @tab @code{qXfer:osdata:read}
23833 @tab @code{info os}
23834
23835 @item @code{query-attached}
23836 @tab @code{qAttached}
23837 @tab Querying remote process attach state.
23838
23839 @item @code{trace-buffer-size}
23840 @tab @code{QTBuffer:size}
23841 @tab @code{set trace-buffer-size}
23842
23843 @item @code{trace-status}
23844 @tab @code{qTStatus}
23845 @tab @code{tstatus}
23846
23847 @item @code{traceframe-info}
23848 @tab @code{qXfer:traceframe-info:read}
23849 @tab Traceframe info
23850
23851 @item @code{install-in-trace}
23852 @tab @code{InstallInTrace}
23853 @tab Install tracepoint in tracing
23854
23855 @item @code{disable-randomization}
23856 @tab @code{QDisableRandomization}
23857 @tab @code{set disable-randomization}
23858
23859 @item @code{startup-with-shell}
23860 @tab @code{QStartupWithShell}
23861 @tab @code{set startup-with-shell}
23862
23863 @item @code{environment-hex-encoded}
23864 @tab @code{QEnvironmentHexEncoded}
23865 @tab @code{set environment}
23866
23867 @item @code{environment-unset}
23868 @tab @code{QEnvironmentUnset}
23869 @tab @code{unset environment}
23870
23871 @item @code{environment-reset}
23872 @tab @code{QEnvironmentReset}
23873 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23874
23875 @item @code{set-working-dir}
23876 @tab @code{QSetWorkingDir}
23877 @tab @code{set cwd}
23878
23879 @item @code{conditional-breakpoints-packet}
23880 @tab @code{Z0 and Z1}
23881 @tab @code{Support for target-side breakpoint condition evaluation}
23882
23883 @item @code{multiprocess-extensions}
23884 @tab @code{multiprocess extensions}
23885 @tab Debug multiple processes and remote process PID awareness
23886
23887 @item @code{swbreak-feature}
23888 @tab @code{swbreak stop reason}
23889 @tab @code{break}
23890
23891 @item @code{hwbreak-feature}
23892 @tab @code{hwbreak stop reason}
23893 @tab @code{hbreak}
23894
23895 @item @code{fork-event-feature}
23896 @tab @code{fork stop reason}
23897 @tab @code{fork}
23898
23899 @item @code{vfork-event-feature}
23900 @tab @code{vfork stop reason}
23901 @tab @code{vfork}
23902
23903 @item @code{exec-event-feature}
23904 @tab @code{exec stop reason}
23905 @tab @code{exec}
23906
23907 @item @code{thread-events}
23908 @tab @code{QThreadEvents}
23909 @tab Tracking thread lifetime.
23910
23911 @item @code{no-resumed-stop-reply}
23912 @tab @code{no resumed thread left stop reply}
23913 @tab Tracking thread lifetime.
23914
23915 @end multitable
23916
23917 @node Remote Stub
23918 @section Implementing a Remote Stub
23919
23920 @cindex debugging stub, example
23921 @cindex remote stub, example
23922 @cindex stub example, remote debugging
23923 The stub files provided with @value{GDBN} implement the target side of the
23924 communication protocol, and the @value{GDBN} side is implemented in the
23925 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23926 these subroutines to communicate, and ignore the details. (If you're
23927 implementing your own stub file, you can still ignore the details: start
23928 with one of the existing stub files. @file{sparc-stub.c} is the best
23929 organized, and therefore the easiest to read.)
23930
23931 @cindex remote serial debugging, overview
23932 To debug a program running on another machine (the debugging
23933 @dfn{target} machine), you must first arrange for all the usual
23934 prerequisites for the program to run by itself. For example, for a C
23935 program, you need:
23936
23937 @enumerate
23938 @item
23939 A startup routine to set up the C runtime environment; these usually
23940 have a name like @file{crt0}. The startup routine may be supplied by
23941 your hardware supplier, or you may have to write your own.
23942
23943 @item
23944 A C subroutine library to support your program's
23945 subroutine calls, notably managing input and output.
23946
23947 @item
23948 A way of getting your program to the other machine---for example, a
23949 download program. These are often supplied by the hardware
23950 manufacturer, but you may have to write your own from hardware
23951 documentation.
23952 @end enumerate
23953
23954 The next step is to arrange for your program to use a serial port to
23955 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23956 machine). In general terms, the scheme looks like this:
23957
23958 @table @emph
23959 @item On the host,
23960 @value{GDBN} already understands how to use this protocol; when everything
23961 else is set up, you can simply use the @samp{target remote} command
23962 (@pxref{Targets,,Specifying a Debugging Target}).
23963
23964 @item On the target,
23965 you must link with your program a few special-purpose subroutines that
23966 implement the @value{GDBN} remote serial protocol. The file containing these
23967 subroutines is called a @dfn{debugging stub}.
23968
23969 On certain remote targets, you can use an auxiliary program
23970 @code{gdbserver} instead of linking a stub into your program.
23971 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23972 @end table
23973
23974 The debugging stub is specific to the architecture of the remote
23975 machine; for example, use @file{sparc-stub.c} to debug programs on
23976 @sc{sparc} boards.
23977
23978 @cindex remote serial stub list
23979 These working remote stubs are distributed with @value{GDBN}:
23980
23981 @table @code
23982
23983 @item i386-stub.c
23984 @cindex @file{i386-stub.c}
23985 @cindex Intel
23986 @cindex i386
23987 For Intel 386 and compatible architectures.
23988
23989 @item m68k-stub.c
23990 @cindex @file{m68k-stub.c}
23991 @cindex Motorola 680x0
23992 @cindex m680x0
23993 For Motorola 680x0 architectures.
23994
23995 @item sh-stub.c
23996 @cindex @file{sh-stub.c}
23997 @cindex Renesas
23998 @cindex SH
23999 For Renesas SH architectures.
24000
24001 @item sparc-stub.c
24002 @cindex @file{sparc-stub.c}
24003 @cindex Sparc
24004 For @sc{sparc} architectures.
24005
24006 @item sparcl-stub.c
24007 @cindex @file{sparcl-stub.c}
24008 @cindex Fujitsu
24009 @cindex SparcLite
24010 For Fujitsu @sc{sparclite} architectures.
24011
24012 @end table
24013
24014 The @file{README} file in the @value{GDBN} distribution may list other
24015 recently added stubs.
24016
24017 @menu
24018 * Stub Contents:: What the stub can do for you
24019 * Bootstrapping:: What you must do for the stub
24020 * Debug Session:: Putting it all together
24021 @end menu
24022
24023 @node Stub Contents
24024 @subsection What the Stub Can Do for You
24025
24026 @cindex remote serial stub
24027 The debugging stub for your architecture supplies these three
24028 subroutines:
24029
24030 @table @code
24031 @item set_debug_traps
24032 @findex set_debug_traps
24033 @cindex remote serial stub, initialization
24034 This routine arranges for @code{handle_exception} to run when your
24035 program stops. You must call this subroutine explicitly in your
24036 program's startup code.
24037
24038 @item handle_exception
24039 @findex handle_exception
24040 @cindex remote serial stub, main routine
24041 This is the central workhorse, but your program never calls it
24042 explicitly---the setup code arranges for @code{handle_exception} to
24043 run when a trap is triggered.
24044
24045 @code{handle_exception} takes control when your program stops during
24046 execution (for example, on a breakpoint), and mediates communications
24047 with @value{GDBN} on the host machine. This is where the communications
24048 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
24049 representative on the target machine. It begins by sending summary
24050 information on the state of your program, then continues to execute,
24051 retrieving and transmitting any information @value{GDBN} needs, until you
24052 execute a @value{GDBN} command that makes your program resume; at that point,
24053 @code{handle_exception} returns control to your own code on the target
24054 machine.
24055
24056 @item breakpoint
24057 @cindex @code{breakpoint} subroutine, remote
24058 Use this auxiliary subroutine to make your program contain a
24059 breakpoint. Depending on the particular situation, this may be the only
24060 way for @value{GDBN} to get control. For instance, if your target
24061 machine has some sort of interrupt button, you won't need to call this;
24062 pressing the interrupt button transfers control to
24063 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
24064 simply receiving characters on the serial port may also trigger a trap;
24065 again, in that situation, you don't need to call @code{breakpoint} from
24066 your own program---simply running @samp{target remote} from the host
24067 @value{GDBN} session gets control.
24068
24069 Call @code{breakpoint} if none of these is true, or if you simply want
24070 to make certain your program stops at a predetermined point for the
24071 start of your debugging session.
24072 @end table
24073
24074 @node Bootstrapping
24075 @subsection What You Must Do for the Stub
24076
24077 @cindex remote stub, support routines
24078 The debugging stubs that come with @value{GDBN} are set up for a particular
24079 chip architecture, but they have no information about the rest of your
24080 debugging target machine.
24081
24082 First of all you need to tell the stub how to communicate with the
24083 serial port.
24084
24085 @table @code
24086 @item int getDebugChar()
24087 @findex getDebugChar
24088 Write this subroutine to read a single character from the serial port.
24089 It may be identical to @code{getchar} for your target system; a
24090 different name is used to allow you to distinguish the two if you wish.
24091
24092 @item void putDebugChar(int)
24093 @findex putDebugChar
24094 Write this subroutine to write a single character to the serial port.
24095 It may be identical to @code{putchar} for your target system; a
24096 different name is used to allow you to distinguish the two if you wish.
24097 @end table
24098
24099 @cindex control C, and remote debugging
24100 @cindex interrupting remote targets
24101 If you want @value{GDBN} to be able to stop your program while it is
24102 running, you need to use an interrupt-driven serial driver, and arrange
24103 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
24104 character). That is the character which @value{GDBN} uses to tell the
24105 remote system to stop.
24106
24107 Getting the debugging target to return the proper status to @value{GDBN}
24108 probably requires changes to the standard stub; one quick and dirty way
24109 is to just execute a breakpoint instruction (the ``dirty'' part is that
24110 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
24111
24112 Other routines you need to supply are:
24113
24114 @table @code
24115 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
24116 @findex exceptionHandler
24117 Write this function to install @var{exception_address} in the exception
24118 handling tables. You need to do this because the stub does not have any
24119 way of knowing what the exception handling tables on your target system
24120 are like (for example, the processor's table might be in @sc{rom},
24121 containing entries which point to a table in @sc{ram}).
24122 The @var{exception_number} specifies the exception which should be changed;
24123 its meaning is architecture-dependent (for example, different numbers
24124 might represent divide by zero, misaligned access, etc). When this
24125 exception occurs, control should be transferred directly to
24126 @var{exception_address}, and the processor state (stack, registers,
24127 and so on) should be just as it is when a processor exception occurs. So if
24128 you want to use a jump instruction to reach @var{exception_address}, it
24129 should be a simple jump, not a jump to subroutine.
24130
24131 For the 386, @var{exception_address} should be installed as an interrupt
24132 gate so that interrupts are masked while the handler runs. The gate
24133 should be at privilege level 0 (the most privileged level). The
24134 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
24135 help from @code{exceptionHandler}.
24136
24137 @item void flush_i_cache()
24138 @findex flush_i_cache
24139 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
24140 instruction cache, if any, on your target machine. If there is no
24141 instruction cache, this subroutine may be a no-op.
24142
24143 On target machines that have instruction caches, @value{GDBN} requires this
24144 function to make certain that the state of your program is stable.
24145 @end table
24146
24147 @noindent
24148 You must also make sure this library routine is available:
24149
24150 @table @code
24151 @item void *memset(void *, int, int)
24152 @findex memset
24153 This is the standard library function @code{memset} that sets an area of
24154 memory to a known value. If you have one of the free versions of
24155 @code{libc.a}, @code{memset} can be found there; otherwise, you must
24156 either obtain it from your hardware manufacturer, or write your own.
24157 @end table
24158
24159 If you do not use the GNU C compiler, you may need other standard
24160 library subroutines as well; this varies from one stub to another,
24161 but in general the stubs are likely to use any of the common library
24162 subroutines which @code{@value{NGCC}} generates as inline code.
24163
24164
24165 @node Debug Session
24166 @subsection Putting it All Together
24167
24168 @cindex remote serial debugging summary
24169 In summary, when your program is ready to debug, you must follow these
24170 steps.
24171
24172 @enumerate
24173 @item
24174 Make sure you have defined the supporting low-level routines
24175 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
24176 @display
24177 @code{getDebugChar}, @code{putDebugChar},
24178 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
24179 @end display
24180
24181 @item
24182 Insert these lines in your program's startup code, before the main
24183 procedure is called:
24184
24185 @smallexample
24186 set_debug_traps();
24187 breakpoint();
24188 @end smallexample
24189
24190 On some machines, when a breakpoint trap is raised, the hardware
24191 automatically makes the PC point to the instruction after the
24192 breakpoint. If your machine doesn't do that, you may need to adjust
24193 @code{handle_exception} to arrange for it to return to the instruction
24194 after the breakpoint on this first invocation, so that your program
24195 doesn't keep hitting the initial breakpoint instead of making
24196 progress.
24197
24198 @item
24199 For the 680x0 stub only, you need to provide a variable called
24200 @code{exceptionHook}. Normally you just use:
24201
24202 @smallexample
24203 void (*exceptionHook)() = 0;
24204 @end smallexample
24205
24206 @noindent
24207 but if before calling @code{set_debug_traps}, you set it to point to a
24208 function in your program, that function is called when
24209 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
24210 error). The function indicated by @code{exceptionHook} is called with
24211 one parameter: an @code{int} which is the exception number.
24212
24213 @item
24214 Compile and link together: your program, the @value{GDBN} debugging stub for
24215 your target architecture, and the supporting subroutines.
24216
24217 @item
24218 Make sure you have a serial connection between your target machine and
24219 the @value{GDBN} host, and identify the serial port on the host.
24220
24221 @item
24222 @c The "remote" target now provides a `load' command, so we should
24223 @c document that. FIXME.
24224 Download your program to your target machine (or get it there by
24225 whatever means the manufacturer provides), and start it.
24226
24227 @item
24228 Start @value{GDBN} on the host, and connect to the target
24229 (@pxref{Connecting,,Connecting to a Remote Target}).
24230
24231 @end enumerate
24232
24233 @node Configurations
24234 @chapter Configuration-Specific Information
24235
24236 While nearly all @value{GDBN} commands are available for all native and
24237 cross versions of the debugger, there are some exceptions. This chapter
24238 describes things that are only available in certain configurations.
24239
24240 There are three major categories of configurations: native
24241 configurations, where the host and target are the same, embedded
24242 operating system configurations, which are usually the same for several
24243 different processor architectures, and bare embedded processors, which
24244 are quite different from each other.
24245
24246 @menu
24247 * Native::
24248 * Embedded OS::
24249 * Embedded Processors::
24250 * Architectures::
24251 @end menu
24252
24253 @node Native
24254 @section Native
24255
24256 This section describes details specific to particular native
24257 configurations.
24258
24259 @menu
24260 * BSD libkvm Interface:: Debugging BSD kernel memory images
24261 * Process Information:: Process information
24262 * DJGPP Native:: Features specific to the DJGPP port
24263 * Cygwin Native:: Features specific to the Cygwin port
24264 * Hurd Native:: Features specific to @sc{gnu} Hurd
24265 * Darwin:: Features specific to Darwin
24266 * FreeBSD:: Features specific to FreeBSD
24267 @end menu
24268
24269 @node BSD libkvm Interface
24270 @subsection BSD libkvm Interface
24271
24272 @cindex libkvm
24273 @cindex kernel memory image
24274 @cindex kernel crash dump
24275
24276 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
24277 interface that provides a uniform interface for accessing kernel virtual
24278 memory images, including live systems and crash dumps. @value{GDBN}
24279 uses this interface to allow you to debug live kernels and kernel crash
24280 dumps on many native BSD configurations. This is implemented as a
24281 special @code{kvm} debugging target. For debugging a live system, load
24282 the currently running kernel into @value{GDBN} and connect to the
24283 @code{kvm} target:
24284
24285 @smallexample
24286 (@value{GDBP}) @b{target kvm}
24287 @end smallexample
24288
24289 For debugging crash dumps, provide the file name of the crash dump as an
24290 argument:
24291
24292 @smallexample
24293 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
24294 @end smallexample
24295
24296 Once connected to the @code{kvm} target, the following commands are
24297 available:
24298
24299 @table @code
24300 @kindex kvm
24301 @item kvm pcb
24302 Set current context from the @dfn{Process Control Block} (PCB) address.
24303
24304 @item kvm proc
24305 Set current context from proc address. This command isn't available on
24306 modern FreeBSD systems.
24307 @end table
24308
24309 @node Process Information
24310 @subsection Process Information
24311 @cindex /proc
24312 @cindex examine process image
24313 @cindex process info via @file{/proc}
24314
24315 Some operating systems provide interfaces to fetch additional
24316 information about running processes beyond memory and per-thread
24317 register state. If @value{GDBN} is configured for an operating system
24318 with a supported interface, the command @code{info proc} is available
24319 to report information about the process running your program, or about
24320 any process running on your system.
24321
24322 One supported interface is a facility called @samp{/proc} that can be
24323 used to examine the image of a running process using file-system
24324 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
24325 systems.
24326
24327 On FreeBSD and NetBSD systems, system control nodes are used to query
24328 process information.
24329
24330 In addition, some systems may provide additional process information
24331 in core files. Note that a core file may include a subset of the
24332 information available from a live process. Process information is
24333 currently available from cores created on @sc{gnu}/Linux and FreeBSD
24334 systems.
24335
24336 @table @code
24337 @kindex info proc
24338 @cindex process ID
24339 @item info proc
24340 @itemx info proc @var{process-id}
24341 Summarize available information about a process. If a
24342 process ID is specified by @var{process-id}, display information about
24343 that process; otherwise display information about the program being
24344 debugged. The summary includes the debugged process ID, the command
24345 line used to invoke it, its current working directory, and its
24346 executable file's absolute file name.
24347
24348 On some systems, @var{process-id} can be of the form
24349 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
24350 within a process. If the optional @var{pid} part is missing, it means
24351 a thread from the process being debugged (the leading @samp{/} still
24352 needs to be present, or else @value{GDBN} will interpret the number as
24353 a process ID rather than a thread ID).
24354
24355 @item info proc cmdline
24356 @cindex info proc cmdline
24357 Show the original command line of the process. This command is
24358 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24359
24360 @item info proc cwd
24361 @cindex info proc cwd
24362 Show the current working directory of the process. This command is
24363 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24364
24365 @item info proc exe
24366 @cindex info proc exe
24367 Show the name of executable of the process. This command is supported
24368 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24369
24370 @item info proc files
24371 @cindex info proc files
24372 Show the file descriptors open by the process. For each open file
24373 descriptor, @value{GDBN} shows its number, type (file, directory,
24374 character device, socket), file pointer offset, and the name of the
24375 resource open on the descriptor. The resource name can be a file name
24376 (for files, directories, and devices) or a protocol followed by socket
24377 address (for network connections). This command is supported on
24378 FreeBSD.
24379
24380 This example shows the open file descriptors for a process using a
24381 tty for standard input and output as well as two network sockets:
24382
24383 @smallexample
24384 (gdb) info proc files 22136
24385 process 22136
24386 Open files:
24387
24388 FD Type Offset Flags Name
24389 text file - r-------- /usr/bin/ssh
24390 ctty chr - rw------- /dev/pts/20
24391 cwd dir - r-------- /usr/home/john
24392 root dir - r-------- /
24393 0 chr 0x32933a4 rw------- /dev/pts/20
24394 1 chr 0x32933a4 rw------- /dev/pts/20
24395 2 chr 0x32933a4 rw------- /dev/pts/20
24396 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
24397 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
24398 @end smallexample
24399
24400 @item info proc mappings
24401 @cindex memory address space mappings
24402 Report the memory address space ranges accessible in a process. On
24403 Solaris, FreeBSD and NetBSD systems, each memory range includes information
24404 on whether the process has read, write, or execute access rights to each
24405 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
24406 includes the object file which is mapped to that range.
24407
24408 @item info proc stat
24409 @itemx info proc status
24410 @cindex process detailed status information
24411 Show additional process-related information, including the user ID and
24412 group ID; virtual memory usage; the signals that are pending, blocked,
24413 and ignored; its TTY; its consumption of system and user time; its
24414 stack size; its @samp{nice} value; etc. These commands are supported
24415 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24416
24417 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
24418 information (type @kbd{man 5 proc} from your shell prompt).
24419
24420 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
24421 @code{info proc status}.
24422
24423 @item info proc all
24424 Show all the information about the process described under all of the
24425 above @code{info proc} subcommands.
24426
24427 @ignore
24428 @comment These sub-options of 'info proc' were not included when
24429 @comment procfs.c was re-written. Keep their descriptions around
24430 @comment against the day when someone finds the time to put them back in.
24431 @kindex info proc times
24432 @item info proc times
24433 Starting time, user CPU time, and system CPU time for your program and
24434 its children.
24435
24436 @kindex info proc id
24437 @item info proc id
24438 Report on the process IDs related to your program: its own process ID,
24439 the ID of its parent, the process group ID, and the session ID.
24440 @end ignore
24441
24442 @item set procfs-trace
24443 @kindex set procfs-trace
24444 @cindex @code{procfs} API calls
24445 This command enables and disables tracing of @code{procfs} API calls.
24446
24447 @item show procfs-trace
24448 @kindex show procfs-trace
24449 Show the current state of @code{procfs} API call tracing.
24450
24451 @item set procfs-file @var{file}
24452 @kindex set procfs-file
24453 Tell @value{GDBN} to write @code{procfs} API trace to the named
24454 @var{file}. @value{GDBN} appends the trace info to the previous
24455 contents of the file. The default is to display the trace on the
24456 standard output.
24457
24458 @item show procfs-file
24459 @kindex show procfs-file
24460 Show the file to which @code{procfs} API trace is written.
24461
24462 @item proc-trace-entry
24463 @itemx proc-trace-exit
24464 @itemx proc-untrace-entry
24465 @itemx proc-untrace-exit
24466 @kindex proc-trace-entry
24467 @kindex proc-trace-exit
24468 @kindex proc-untrace-entry
24469 @kindex proc-untrace-exit
24470 These commands enable and disable tracing of entries into and exits
24471 from the @code{syscall} interface.
24472
24473 @item info pidlist
24474 @kindex info pidlist
24475 @cindex process list, QNX Neutrino
24476 For QNX Neutrino only, this command displays the list of all the
24477 processes and all the threads within each process.
24478
24479 @item info meminfo
24480 @kindex info meminfo
24481 @cindex mapinfo list, QNX Neutrino
24482 For QNX Neutrino only, this command displays the list of all mapinfos.
24483 @end table
24484
24485 @node DJGPP Native
24486 @subsection Features for Debugging @sc{djgpp} Programs
24487 @cindex @sc{djgpp} debugging
24488 @cindex native @sc{djgpp} debugging
24489 @cindex MS-DOS-specific commands
24490
24491 @cindex DPMI
24492 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
24493 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
24494 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
24495 top of real-mode DOS systems and their emulations.
24496
24497 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
24498 defines a few commands specific to the @sc{djgpp} port. This
24499 subsection describes those commands.
24500
24501 @table @code
24502 @kindex info dos
24503 @item info dos
24504 This is a prefix of @sc{djgpp}-specific commands which print
24505 information about the target system and important OS structures.
24506
24507 @kindex sysinfo
24508 @cindex MS-DOS system info
24509 @cindex free memory information (MS-DOS)
24510 @item info dos sysinfo
24511 This command displays assorted information about the underlying
24512 platform: the CPU type and features, the OS version and flavor, the
24513 DPMI version, and the available conventional and DPMI memory.
24514
24515 @cindex GDT
24516 @cindex LDT
24517 @cindex IDT
24518 @cindex segment descriptor tables
24519 @cindex descriptor tables display
24520 @item info dos gdt
24521 @itemx info dos ldt
24522 @itemx info dos idt
24523 These 3 commands display entries from, respectively, Global, Local,
24524 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
24525 tables are data structures which store a descriptor for each segment
24526 that is currently in use. The segment's selector is an index into a
24527 descriptor table; the table entry for that index holds the
24528 descriptor's base address and limit, and its attributes and access
24529 rights.
24530
24531 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
24532 segment (used for both data and the stack), and a DOS segment (which
24533 allows access to DOS/BIOS data structures and absolute addresses in
24534 conventional memory). However, the DPMI host will usually define
24535 additional segments in order to support the DPMI environment.
24536
24537 @cindex garbled pointers
24538 These commands allow to display entries from the descriptor tables.
24539 Without an argument, all entries from the specified table are
24540 displayed. An argument, which should be an integer expression, means
24541 display a single entry whose index is given by the argument. For
24542 example, here's a convenient way to display information about the
24543 debugged program's data segment:
24544
24545 @smallexample
24546 @exdent @code{(@value{GDBP}) info dos ldt $ds}
24547 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
24548 @end smallexample
24549
24550 @noindent
24551 This comes in handy when you want to see whether a pointer is outside
24552 the data segment's limit (i.e.@: @dfn{garbled}).
24553
24554 @cindex page tables display (MS-DOS)
24555 @item info dos pde
24556 @itemx info dos pte
24557 These two commands display entries from, respectively, the Page
24558 Directory and the Page Tables. Page Directories and Page Tables are
24559 data structures which control how virtual memory addresses are mapped
24560 into physical addresses. A Page Table includes an entry for every
24561 page of memory that is mapped into the program's address space; there
24562 may be several Page Tables, each one holding up to 4096 entries. A
24563 Page Directory has up to 4096 entries, one each for every Page Table
24564 that is currently in use.
24565
24566 Without an argument, @kbd{info dos pde} displays the entire Page
24567 Directory, and @kbd{info dos pte} displays all the entries in all of
24568 the Page Tables. An argument, an integer expression, given to the
24569 @kbd{info dos pde} command means display only that entry from the Page
24570 Directory table. An argument given to the @kbd{info dos pte} command
24571 means display entries from a single Page Table, the one pointed to by
24572 the specified entry in the Page Directory.
24573
24574 @cindex direct memory access (DMA) on MS-DOS
24575 These commands are useful when your program uses @dfn{DMA} (Direct
24576 Memory Access), which needs physical addresses to program the DMA
24577 controller.
24578
24579 These commands are supported only with some DPMI servers.
24580
24581 @cindex physical address from linear address
24582 @item info dos address-pte @var{addr}
24583 This command displays the Page Table entry for a specified linear
24584 address. The argument @var{addr} is a linear address which should
24585 already have the appropriate segment's base address added to it,
24586 because this command accepts addresses which may belong to @emph{any}
24587 segment. For example, here's how to display the Page Table entry for
24588 the page where a variable @code{i} is stored:
24589
24590 @smallexample
24591 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
24592 @exdent @code{Page Table entry for address 0x11a00d30:}
24593 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
24594 @end smallexample
24595
24596 @noindent
24597 This says that @code{i} is stored at offset @code{0xd30} from the page
24598 whose physical base address is @code{0x02698000}, and shows all the
24599 attributes of that page.
24600
24601 Note that you must cast the addresses of variables to a @code{char *},
24602 since otherwise the value of @code{__djgpp_base_address}, the base
24603 address of all variables and functions in a @sc{djgpp} program, will
24604 be added using the rules of C pointer arithmetics: if @code{i} is
24605 declared an @code{int}, @value{GDBN} will add 4 times the value of
24606 @code{__djgpp_base_address} to the address of @code{i}.
24607
24608 Here's another example, it displays the Page Table entry for the
24609 transfer buffer:
24610
24611 @smallexample
24612 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
24613 @exdent @code{Page Table entry for address 0x29110:}
24614 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
24615 @end smallexample
24616
24617 @noindent
24618 (The @code{+ 3} offset is because the transfer buffer's address is the
24619 3rd member of the @code{_go32_info_block} structure.) The output
24620 clearly shows that this DPMI server maps the addresses in conventional
24621 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
24622 linear (@code{0x29110}) addresses are identical.
24623
24624 This command is supported only with some DPMI servers.
24625 @end table
24626
24627 @cindex DOS serial data link, remote debugging
24628 In addition to native debugging, the DJGPP port supports remote
24629 debugging via a serial data link. The following commands are specific
24630 to remote serial debugging in the DJGPP port of @value{GDBN}.
24631
24632 @table @code
24633 @kindex set com1base
24634 @kindex set com1irq
24635 @kindex set com2base
24636 @kindex set com2irq
24637 @kindex set com3base
24638 @kindex set com3irq
24639 @kindex set com4base
24640 @kindex set com4irq
24641 @item set com1base @var{addr}
24642 This command sets the base I/O port address of the @file{COM1} serial
24643 port.
24644
24645 @item set com1irq @var{irq}
24646 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24647 for the @file{COM1} serial port.
24648
24649 There are similar commands @samp{set com2base}, @samp{set com3irq},
24650 etc.@: for setting the port address and the @code{IRQ} lines for the
24651 other 3 COM ports.
24652
24653 @kindex show com1base
24654 @kindex show com1irq
24655 @kindex show com2base
24656 @kindex show com2irq
24657 @kindex show com3base
24658 @kindex show com3irq
24659 @kindex show com4base
24660 @kindex show com4irq
24661 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24662 display the current settings of the base address and the @code{IRQ}
24663 lines used by the COM ports.
24664
24665 @item info serial
24666 @kindex info serial
24667 @cindex DOS serial port status
24668 This command prints the status of the 4 DOS serial ports. For each
24669 port, it prints whether it's active or not, its I/O base address and
24670 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24671 counts of various errors encountered so far.
24672 @end table
24673
24674
24675 @node Cygwin Native
24676 @subsection Features for Debugging MS Windows PE Executables
24677 @cindex MS Windows debugging
24678 @cindex native Cygwin debugging
24679 @cindex Cygwin-specific commands
24680
24681 @value{GDBN} supports native debugging of MS Windows programs, including
24682 DLLs with and without symbolic debugging information.
24683
24684 @cindex Ctrl-BREAK, MS-Windows
24685 @cindex interrupt debuggee on MS-Windows
24686 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24687 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24688 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24689 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24690 sequence, which can be used to interrupt the debuggee even if it
24691 ignores @kbd{C-c}.
24692
24693 There are various additional Cygwin-specific commands, described in
24694 this section. Working with DLLs that have no debugging symbols is
24695 described in @ref{Non-debug DLL Symbols}.
24696
24697 @table @code
24698 @kindex info w32
24699 @item info w32
24700 This is a prefix of MS Windows-specific commands which print
24701 information about the target system and important OS structures.
24702
24703 @item info w32 selector
24704 This command displays information returned by
24705 the Win32 API @code{GetThreadSelectorEntry} function.
24706 It takes an optional argument that is evaluated to
24707 a long value to give the information about this given selector.
24708 Without argument, this command displays information
24709 about the six segment registers.
24710
24711 @item info w32 thread-information-block
24712 This command displays thread specific information stored in the
24713 Thread Information Block (readable on the X86 CPU family using @code{$fs}
24714 selector for 32-bit programs and @code{$gs} for 64-bit programs).
24715
24716 @kindex signal-event
24717 @item signal-event @var{id}
24718 This command signals an event with user-provided @var{id}. Used to resume
24719 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24720
24721 To use it, create or edit the following keys in
24722 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24723 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24724 (for x86_64 versions):
24725
24726 @itemize @minus
24727 @item
24728 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
24729 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24730 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
24731
24732 The first @code{%ld} will be replaced by the process ID of the
24733 crashing process, the second @code{%ld} will be replaced by the ID of
24734 the event that blocks the crashing process, waiting for @value{GDBN}
24735 to attach.
24736
24737 @item
24738 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24739 make the system run debugger specified by the Debugger key
24740 automatically, @code{0} will cause a dialog box with ``OK'' and
24741 ``Cancel'' buttons to appear, which allows the user to either
24742 terminate the crashing process (OK) or debug it (Cancel).
24743 @end itemize
24744
24745 @kindex set cygwin-exceptions
24746 @cindex debugging the Cygwin DLL
24747 @cindex Cygwin DLL, debugging
24748 @item set cygwin-exceptions @var{mode}
24749 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24750 happen inside the Cygwin DLL. If @var{mode} is @code{off},
24751 @value{GDBN} will delay recognition of exceptions, and may ignore some
24752 exceptions which seem to be caused by internal Cygwin DLL
24753 ``bookkeeping''. This option is meant primarily for debugging the
24754 Cygwin DLL itself; the default value is @code{off} to avoid annoying
24755 @value{GDBN} users with false @code{SIGSEGV} signals.
24756
24757 @kindex show cygwin-exceptions
24758 @item show cygwin-exceptions
24759 Displays whether @value{GDBN} will break on exceptions that happen
24760 inside the Cygwin DLL itself.
24761
24762 @kindex set new-console
24763 @item set new-console @var{mode}
24764 If @var{mode} is @code{on} the debuggee will
24765 be started in a new console on next start.
24766 If @var{mode} is @code{off}, the debuggee will
24767 be started in the same console as the debugger.
24768
24769 @kindex show new-console
24770 @item show new-console
24771 Displays whether a new console is used
24772 when the debuggee is started.
24773
24774 @kindex set new-group
24775 @item set new-group @var{mode}
24776 This boolean value controls whether the debuggee should
24777 start a new group or stay in the same group as the debugger.
24778 This affects the way the Windows OS handles
24779 @samp{Ctrl-C}.
24780
24781 @kindex show new-group
24782 @item show new-group
24783 Displays current value of new-group boolean.
24784
24785 @kindex set debugevents
24786 @item set debugevents
24787 This boolean value adds debug output concerning kernel events related
24788 to the debuggee seen by the debugger. This includes events that
24789 signal thread and process creation and exit, DLL loading and
24790 unloading, console interrupts, and debugging messages produced by the
24791 Windows @code{OutputDebugString} API call.
24792
24793 @kindex set debugexec
24794 @item set debugexec
24795 This boolean value adds debug output concerning execute events
24796 (such as resume thread) seen by the debugger.
24797
24798 @kindex set debugexceptions
24799 @item set debugexceptions
24800 This boolean value adds debug output concerning exceptions in the
24801 debuggee seen by the debugger.
24802
24803 @kindex set debugmemory
24804 @item set debugmemory
24805 This boolean value adds debug output concerning debuggee memory reads
24806 and writes by the debugger.
24807
24808 @kindex set shell
24809 @item set shell
24810 This boolean values specifies whether the debuggee is called
24811 via a shell or directly (default value is on).
24812
24813 @kindex show shell
24814 @item show shell
24815 Displays if the debuggee will be started with a shell.
24816
24817 @end table
24818
24819 @menu
24820 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
24821 @end menu
24822
24823 @node Non-debug DLL Symbols
24824 @subsubsection Support for DLLs without Debugging Symbols
24825 @cindex DLLs with no debugging symbols
24826 @cindex Minimal symbols and DLLs
24827
24828 Very often on windows, some of the DLLs that your program relies on do
24829 not include symbolic debugging information (for example,
24830 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24831 symbols in a DLL, it relies on the minimal amount of symbolic
24832 information contained in the DLL's export table. This section
24833 describes working with such symbols, known internally to @value{GDBN} as
24834 ``minimal symbols''.
24835
24836 Note that before the debugged program has started execution, no DLLs
24837 will have been loaded. The easiest way around this problem is simply to
24838 start the program --- either by setting a breakpoint or letting the
24839 program run once to completion.
24840
24841 @subsubsection DLL Name Prefixes
24842
24843 In keeping with the naming conventions used by the Microsoft debugging
24844 tools, DLL export symbols are made available with a prefix based on the
24845 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24846 also entered into the symbol table, so @code{CreateFileA} is often
24847 sufficient. In some cases there will be name clashes within a program
24848 (particularly if the executable itself includes full debugging symbols)
24849 necessitating the use of the fully qualified name when referring to the
24850 contents of the DLL. Use single-quotes around the name to avoid the
24851 exclamation mark (``!'') being interpreted as a language operator.
24852
24853 Note that the internal name of the DLL may be all upper-case, even
24854 though the file name of the DLL is lower-case, or vice-versa. Since
24855 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24856 some confusion. If in doubt, try the @code{info functions} and
24857 @code{info variables} commands or even @code{maint print msymbols}
24858 (@pxref{Symbols}). Here's an example:
24859
24860 @smallexample
24861 (@value{GDBP}) info function CreateFileA
24862 All functions matching regular expression "CreateFileA":
24863
24864 Non-debugging symbols:
24865 0x77e885f4 CreateFileA
24866 0x77e885f4 KERNEL32!CreateFileA
24867 @end smallexample
24868
24869 @smallexample
24870 (@value{GDBP}) info function !
24871 All functions matching regular expression "!":
24872
24873 Non-debugging symbols:
24874 0x6100114c cygwin1!__assert
24875 0x61004034 cygwin1!_dll_crt0@@0
24876 0x61004240 cygwin1!dll_crt0(per_process *)
24877 [etc...]
24878 @end smallexample
24879
24880 @subsubsection Working with Minimal Symbols
24881
24882 Symbols extracted from a DLL's export table do not contain very much
24883 type information. All that @value{GDBN} can do is guess whether a symbol
24884 refers to a function or variable depending on the linker section that
24885 contains the symbol. Also note that the actual contents of the memory
24886 contained in a DLL are not available unless the program is running. This
24887 means that you cannot examine the contents of a variable or disassemble
24888 a function within a DLL without a running program.
24889
24890 Variables are generally treated as pointers and dereferenced
24891 automatically. For this reason, it is often necessary to prefix a
24892 variable name with the address-of operator (``&'') and provide explicit
24893 type information in the command. Here's an example of the type of
24894 problem:
24895
24896 @smallexample
24897 (@value{GDBP}) print 'cygwin1!__argv'
24898 'cygwin1!__argv' has unknown type; cast it to its declared type
24899 @end smallexample
24900
24901 @smallexample
24902 (@value{GDBP}) x 'cygwin1!__argv'
24903 'cygwin1!__argv' has unknown type; cast it to its declared type
24904 @end smallexample
24905
24906 And two possible solutions:
24907
24908 @smallexample
24909 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24910 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24911 @end smallexample
24912
24913 @smallexample
24914 (@value{GDBP}) x/2x &'cygwin1!__argv'
24915 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24916 (@value{GDBP}) x/x 0x10021608
24917 0x10021608: 0x0022fd98
24918 (@value{GDBP}) x/s 0x0022fd98
24919 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24920 @end smallexample
24921
24922 Setting a break point within a DLL is possible even before the program
24923 starts execution. However, under these circumstances, @value{GDBN} can't
24924 examine the initial instructions of the function in order to skip the
24925 function's frame set-up code. You can work around this by using ``*&''
24926 to set the breakpoint at a raw memory address:
24927
24928 @smallexample
24929 (@value{GDBP}) break *&'python22!PyOS_Readline'
24930 Breakpoint 1 at 0x1e04eff0
24931 @end smallexample
24932
24933 The author of these extensions is not entirely convinced that setting a
24934 break point within a shared DLL like @file{kernel32.dll} is completely
24935 safe.
24936
24937 @node Hurd Native
24938 @subsection Commands Specific to @sc{gnu} Hurd Systems
24939 @cindex @sc{gnu} Hurd debugging
24940
24941 This subsection describes @value{GDBN} commands specific to the
24942 @sc{gnu} Hurd native debugging.
24943
24944 @table @code
24945 @item set signals
24946 @itemx set sigs
24947 @kindex set signals@r{, Hurd command}
24948 @kindex set sigs@r{, Hurd command}
24949 This command toggles the state of inferior signal interception by
24950 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24951 affected by this command. @code{sigs} is a shorthand alias for
24952 @code{signals}.
24953
24954 @item show signals
24955 @itemx show sigs
24956 @kindex show signals@r{, Hurd command}
24957 @kindex show sigs@r{, Hurd command}
24958 Show the current state of intercepting inferior's signals.
24959
24960 @item set signal-thread
24961 @itemx set sigthread
24962 @kindex set signal-thread
24963 @kindex set sigthread
24964 This command tells @value{GDBN} which thread is the @code{libc} signal
24965 thread. That thread is run when a signal is delivered to a running
24966 process. @code{set sigthread} is the shorthand alias of @code{set
24967 signal-thread}.
24968
24969 @item show signal-thread
24970 @itemx show sigthread
24971 @kindex show signal-thread
24972 @kindex show sigthread
24973 These two commands show which thread will run when the inferior is
24974 delivered a signal.
24975
24976 @item set stopped
24977 @kindex set stopped@r{, Hurd command}
24978 This commands tells @value{GDBN} that the inferior process is stopped,
24979 as with the @code{SIGSTOP} signal. The stopped process can be
24980 continued by delivering a signal to it.
24981
24982 @item show stopped
24983 @kindex show stopped@r{, Hurd command}
24984 This command shows whether @value{GDBN} thinks the debuggee is
24985 stopped.
24986
24987 @item set exceptions
24988 @kindex set exceptions@r{, Hurd command}
24989 Use this command to turn off trapping of exceptions in the inferior.
24990 When exception trapping is off, neither breakpoints nor
24991 single-stepping will work. To restore the default, set exception
24992 trapping on.
24993
24994 @item show exceptions
24995 @kindex show exceptions@r{, Hurd command}
24996 Show the current state of trapping exceptions in the inferior.
24997
24998 @item set task pause
24999 @kindex set task@r{, Hurd commands}
25000 @cindex task attributes (@sc{gnu} Hurd)
25001 @cindex pause current task (@sc{gnu} Hurd)
25002 This command toggles task suspension when @value{GDBN} has control.
25003 Setting it to on takes effect immediately, and the task is suspended
25004 whenever @value{GDBN} gets control. Setting it to off will take
25005 effect the next time the inferior is continued. If this option is set
25006 to off, you can use @code{set thread default pause on} or @code{set
25007 thread pause on} (see below) to pause individual threads.
25008
25009 @item show task pause
25010 @kindex show task@r{, Hurd commands}
25011 Show the current state of task suspension.
25012
25013 @item set task detach-suspend-count
25014 @cindex task suspend count
25015 @cindex detach from task, @sc{gnu} Hurd
25016 This command sets the suspend count the task will be left with when
25017 @value{GDBN} detaches from it.
25018
25019 @item show task detach-suspend-count
25020 Show the suspend count the task will be left with when detaching.
25021
25022 @item set task exception-port
25023 @itemx set task excp
25024 @cindex task exception port, @sc{gnu} Hurd
25025 This command sets the task exception port to which @value{GDBN} will
25026 forward exceptions. The argument should be the value of the @dfn{send
25027 rights} of the task. @code{set task excp} is a shorthand alias.
25028
25029 @item set noninvasive
25030 @cindex noninvasive task options
25031 This command switches @value{GDBN} to a mode that is the least
25032 invasive as far as interfering with the inferior is concerned. This
25033 is the same as using @code{set task pause}, @code{set exceptions}, and
25034 @code{set signals} to values opposite to the defaults.
25035
25036 @item info send-rights
25037 @itemx info receive-rights
25038 @itemx info port-rights
25039 @itemx info port-sets
25040 @itemx info dead-names
25041 @itemx info ports
25042 @itemx info psets
25043 @cindex send rights, @sc{gnu} Hurd
25044 @cindex receive rights, @sc{gnu} Hurd
25045 @cindex port rights, @sc{gnu} Hurd
25046 @cindex port sets, @sc{gnu} Hurd
25047 @cindex dead names, @sc{gnu} Hurd
25048 These commands display information about, respectively, send rights,
25049 receive rights, port rights, port sets, and dead names of a task.
25050 There are also shorthand aliases: @code{info ports} for @code{info
25051 port-rights} and @code{info psets} for @code{info port-sets}.
25052
25053 @item set thread pause
25054 @kindex set thread@r{, Hurd command}
25055 @cindex thread properties, @sc{gnu} Hurd
25056 @cindex pause current thread (@sc{gnu} Hurd)
25057 This command toggles current thread suspension when @value{GDBN} has
25058 control. Setting it to on takes effect immediately, and the current
25059 thread is suspended whenever @value{GDBN} gets control. Setting it to
25060 off will take effect the next time the inferior is continued.
25061 Normally, this command has no effect, since when @value{GDBN} has
25062 control, the whole task is suspended. However, if you used @code{set
25063 task pause off} (see above), this command comes in handy to suspend
25064 only the current thread.
25065
25066 @item show thread pause
25067 @kindex show thread@r{, Hurd command}
25068 This command shows the state of current thread suspension.
25069
25070 @item set thread run
25071 This command sets whether the current thread is allowed to run.
25072
25073 @item show thread run
25074 Show whether the current thread is allowed to run.
25075
25076 @item set thread detach-suspend-count
25077 @cindex thread suspend count, @sc{gnu} Hurd
25078 @cindex detach from thread, @sc{gnu} Hurd
25079 This command sets the suspend count @value{GDBN} will leave on a
25080 thread when detaching. This number is relative to the suspend count
25081 found by @value{GDBN} when it notices the thread; use @code{set thread
25082 takeover-suspend-count} to force it to an absolute value.
25083
25084 @item show thread detach-suspend-count
25085 Show the suspend count @value{GDBN} will leave on the thread when
25086 detaching.
25087
25088 @item set thread exception-port
25089 @itemx set thread excp
25090 Set the thread exception port to which to forward exceptions. This
25091 overrides the port set by @code{set task exception-port} (see above).
25092 @code{set thread excp} is the shorthand alias.
25093
25094 @item set thread takeover-suspend-count
25095 Normally, @value{GDBN}'s thread suspend counts are relative to the
25096 value @value{GDBN} finds when it notices each thread. This command
25097 changes the suspend counts to be absolute instead.
25098
25099 @item set thread default
25100 @itemx show thread default
25101 @cindex thread default settings, @sc{gnu} Hurd
25102 Each of the above @code{set thread} commands has a @code{set thread
25103 default} counterpart (e.g., @code{set thread default pause}, @code{set
25104 thread default exception-port}, etc.). The @code{thread default}
25105 variety of commands sets the default thread properties for all
25106 threads; you can then change the properties of individual threads with
25107 the non-default commands.
25108 @end table
25109
25110 @node Darwin
25111 @subsection Darwin
25112 @cindex Darwin
25113
25114 @value{GDBN} provides the following commands specific to the Darwin target:
25115
25116 @table @code
25117 @item set debug darwin @var{num}
25118 @kindex set debug darwin
25119 When set to a non zero value, enables debugging messages specific to
25120 the Darwin support. Higher values produce more verbose output.
25121
25122 @item show debug darwin
25123 @kindex show debug darwin
25124 Show the current state of Darwin messages.
25125
25126 @item set debug mach-o @var{num}
25127 @kindex set debug mach-o
25128 When set to a non zero value, enables debugging messages while
25129 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
25130 file format used on Darwin for object and executable files.) Higher
25131 values produce more verbose output. This is a command to diagnose
25132 problems internal to @value{GDBN} and should not be needed in normal
25133 usage.
25134
25135 @item show debug mach-o
25136 @kindex show debug mach-o
25137 Show the current state of Mach-O file messages.
25138
25139 @item set mach-exceptions on
25140 @itemx set mach-exceptions off
25141 @kindex set mach-exceptions
25142 On Darwin, faults are first reported as a Mach exception and are then
25143 mapped to a Posix signal. Use this command to turn on trapping of
25144 Mach exceptions in the inferior. This might be sometimes useful to
25145 better understand the cause of a fault. The default is off.
25146
25147 @item show mach-exceptions
25148 @kindex show mach-exceptions
25149 Show the current state of exceptions trapping.
25150 @end table
25151
25152 @node FreeBSD
25153 @subsection FreeBSD
25154 @cindex FreeBSD
25155
25156 When the ABI of a system call is changed in the FreeBSD kernel, this
25157 is implemented by leaving a compatibility system call using the old
25158 ABI at the existing number and allocating a new system call number for
25159 the version using the new ABI. As a convenience, when a system call
25160 is caught by name (@pxref{catch syscall}), compatibility system calls
25161 are also caught.
25162
25163 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
25164 system call and catching the @code{kevent} system call by name catches
25165 both variants:
25166
25167 @smallexample
25168 (@value{GDBP}) catch syscall kevent
25169 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
25170 (@value{GDBP})
25171 @end smallexample
25172
25173
25174 @node Embedded OS
25175 @section Embedded Operating Systems
25176
25177 This section describes configurations involving the debugging of
25178 embedded operating systems that are available for several different
25179 architectures.
25180
25181 @value{GDBN} includes the ability to debug programs running on
25182 various real-time operating systems.
25183
25184 @node Embedded Processors
25185 @section Embedded Processors
25186
25187 This section goes into details specific to particular embedded
25188 configurations.
25189
25190 @cindex send command to simulator
25191 Whenever a specific embedded processor has a simulator, @value{GDBN}
25192 allows to send an arbitrary command to the simulator.
25193
25194 @table @code
25195 @item sim @var{command}
25196 @kindex sim@r{, a command}
25197 Send an arbitrary @var{command} string to the simulator. Consult the
25198 documentation for the specific simulator in use for information about
25199 acceptable commands.
25200 @end table
25201
25202
25203 @menu
25204 * ARC:: Synopsys ARC
25205 * ARM:: ARM
25206 * BPF:: eBPF
25207 * M68K:: Motorola M68K
25208 * MicroBlaze:: Xilinx MicroBlaze
25209 * MIPS Embedded:: MIPS Embedded
25210 * OpenRISC 1000:: OpenRISC 1000 (or1k)
25211 * PowerPC Embedded:: PowerPC Embedded
25212 * AVR:: Atmel AVR
25213 * CRIS:: CRIS
25214 * Super-H:: Renesas Super-H
25215 @end menu
25216
25217 @node ARC
25218 @subsection Synopsys ARC
25219 @cindex Synopsys ARC
25220 @cindex ARC specific commands
25221 @cindex ARC600
25222 @cindex ARC700
25223 @cindex ARC EM
25224 @cindex ARC HS
25225
25226 @value{GDBN} provides the following ARC-specific commands:
25227
25228 @table @code
25229 @item set debug arc
25230 @kindex set debug arc
25231 Control the level of ARC specific debug messages. Use 0 for no messages (the
25232 default), 1 for debug messages, and 2 for even more debug messages.
25233
25234 @item show debug arc
25235 @kindex show debug arc
25236 Show the level of ARC specific debugging in operation.
25237
25238 @item maint print arc arc-instruction @var{address}
25239 @kindex maint print arc arc-instruction
25240 Print internal disassembler information about instruction at a given address.
25241
25242 @end table
25243
25244 @node ARM
25245 @subsection ARM
25246
25247 @value{GDBN} provides the following ARM-specific commands:
25248
25249 @table @code
25250 @item set arm disassembler
25251 @kindex set arm
25252 This commands selects from a list of disassembly styles. The
25253 @code{"std"} style is the standard style.
25254
25255 @item show arm disassembler
25256 @kindex show arm
25257 Show the current disassembly style.
25258
25259 @item set arm apcs32
25260 @cindex ARM 32-bit mode
25261 This command toggles ARM operation mode between 32-bit and 26-bit.
25262
25263 @item show arm apcs32
25264 Display the current usage of the ARM 32-bit mode.
25265
25266 @item set arm fpu @var{fputype}
25267 This command sets the ARM floating-point unit (FPU) type. The
25268 argument @var{fputype} can be one of these:
25269
25270 @table @code
25271 @item auto
25272 Determine the FPU type by querying the OS ABI.
25273 @item softfpa
25274 Software FPU, with mixed-endian doubles on little-endian ARM
25275 processors.
25276 @item fpa
25277 GCC-compiled FPA co-processor.
25278 @item softvfp
25279 Software FPU with pure-endian doubles.
25280 @item vfp
25281 VFP co-processor.
25282 @end table
25283
25284 @item show arm fpu
25285 Show the current type of the FPU.
25286
25287 @item set arm abi
25288 This command forces @value{GDBN} to use the specified ABI.
25289
25290 @item show arm abi
25291 Show the currently used ABI.
25292
25293 @item set arm fallback-mode (arm|thumb|auto)
25294 @value{GDBN} uses the symbol table, when available, to determine
25295 whether instructions are ARM or Thumb. This command controls
25296 @value{GDBN}'s default behavior when the symbol table is not
25297 available. The default is @samp{auto}, which causes @value{GDBN} to
25298 use the current execution mode (from the @code{T} bit in the @code{CPSR}
25299 register).
25300
25301 @item show arm fallback-mode
25302 Show the current fallback instruction mode.
25303
25304 @item set arm force-mode (arm|thumb|auto)
25305 This command overrides use of the symbol table to determine whether
25306 instructions are ARM or Thumb. The default is @samp{auto}, which
25307 causes @value{GDBN} to use the symbol table and then the setting
25308 of @samp{set arm fallback-mode}.
25309
25310 @item show arm force-mode
25311 Show the current forced instruction mode.
25312
25313 @item set arm unwind-secure-frames
25314 This command enables unwinding from Non-secure to Secure mode on
25315 Cortex-M with Security extension.
25316 This can trigger security exceptions when unwinding the exception
25317 stack.
25318 It is enabled by default.
25319
25320 @item show arm unwind-secure-frames
25321 Show whether unwinding from Non-secure to Secure mode is enabled.
25322
25323 @item set debug arm
25324 Toggle whether to display ARM-specific debugging messages from the ARM
25325 target support subsystem.
25326
25327 @item show debug arm
25328 Show whether ARM-specific debugging messages are enabled.
25329 @end table
25330
25331 @table @code
25332 @item target sim @r{[}@var{simargs}@r{]} @dots{}
25333 The @value{GDBN} ARM simulator accepts the following optional arguments.
25334
25335 @table @code
25336 @item --swi-support=@var{type}
25337 Tell the simulator which SWI interfaces to support. The argument
25338 @var{type} may be a comma separated list of the following values.
25339 The default value is @code{all}.
25340
25341 @table @code
25342 @item none
25343 @item demon
25344 @item angel
25345 @item redboot
25346 @item all
25347 @end table
25348 @end table
25349 @end table
25350
25351 @node BPF
25352 @subsection BPF
25353
25354 @table @code
25355 @item target sim @r{[}@var{simargs}@r{]} @dots{}
25356 The @value{GDBN} BPF simulator accepts the following optional arguments.
25357
25358 @table @code
25359 @item --skb-data-offset=@var{offset}
25360 Tell the simulator the offset, measured in bytes, of the
25361 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
25362 This offset is used by some BPF specific-purpose load/store
25363 instructions. Defaults to 0.
25364 @end table
25365 @end table
25366
25367 @node M68K
25368 @subsection M68k
25369
25370 The Motorola m68k configuration includes ColdFire support.
25371
25372 @node MicroBlaze
25373 @subsection MicroBlaze
25374 @cindex Xilinx MicroBlaze
25375 @cindex XMD, Xilinx Microprocessor Debugger
25376
25377 The MicroBlaze is a soft-core processor supported on various Xilinx
25378 FPGAs, such as Spartan or Virtex series. Boards with these processors
25379 usually have JTAG ports which connect to a host system running the Xilinx
25380 Embedded Development Kit (EDK) or Software Development Kit (SDK).
25381 This host system is used to download the configuration bitstream to
25382 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
25383 communicates with the target board using the JTAG interface and
25384 presents a @code{gdbserver} interface to the board. By default
25385 @code{xmd} uses port @code{1234}. (While it is possible to change
25386 this default port, it requires the use of undocumented @code{xmd}
25387 commands. Contact Xilinx support if you need to do this.)
25388
25389 Use these GDB commands to connect to the MicroBlaze target processor.
25390
25391 @table @code
25392 @item target remote :1234
25393 Use this command to connect to the target if you are running @value{GDBN}
25394 on the same system as @code{xmd}.
25395
25396 @item target remote @var{xmd-host}:1234
25397 Use this command to connect to the target if it is connected to @code{xmd}
25398 running on a different system named @var{xmd-host}.
25399
25400 @item load
25401 Use this command to download a program to the MicroBlaze target.
25402
25403 @item set debug microblaze @var{n}
25404 Enable MicroBlaze-specific debugging messages if non-zero.
25405
25406 @item show debug microblaze @var{n}
25407 Show MicroBlaze-specific debugging level.
25408 @end table
25409
25410 @node MIPS Embedded
25411 @subsection @acronym{MIPS} Embedded
25412
25413 @noindent
25414 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
25415
25416 @table @code
25417 @item set mipsfpu double
25418 @itemx set mipsfpu single
25419 @itemx set mipsfpu none
25420 @itemx set mipsfpu auto
25421 @itemx show mipsfpu
25422 @kindex set mipsfpu
25423 @kindex show mipsfpu
25424 @cindex @acronym{MIPS} remote floating point
25425 @cindex floating point, @acronym{MIPS} remote
25426 If your target board does not support the @acronym{MIPS} floating point
25427 coprocessor, you should use the command @samp{set mipsfpu none} (if you
25428 need this, you may wish to put the command in your @value{GDBN} init
25429 file). This tells @value{GDBN} how to find the return value of
25430 functions which return floating point values. It also allows
25431 @value{GDBN} to avoid saving the floating point registers when calling
25432 functions on the board. If you are using a floating point coprocessor
25433 with only single precision floating point support, as on the @sc{r4650}
25434 processor, use the command @samp{set mipsfpu single}. The default
25435 double precision floating point coprocessor may be selected using
25436 @samp{set mipsfpu double}.
25437
25438 In previous versions the only choices were double precision or no
25439 floating point, so @samp{set mipsfpu on} will select double precision
25440 and @samp{set mipsfpu off} will select no floating point.
25441
25442 As usual, you can inquire about the @code{mipsfpu} variable with
25443 @samp{show mipsfpu}.
25444 @end table
25445
25446 @node OpenRISC 1000
25447 @subsection OpenRISC 1000
25448 @cindex OpenRISC 1000
25449
25450 @noindent
25451 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
25452 mainly provided as a soft-core which can run on Xilinx, Altera and other
25453 FPGA's.
25454
25455 @value{GDBN} for OpenRISC supports the below commands when connecting to
25456 a target:
25457
25458 @table @code
25459
25460 @kindex target sim
25461 @item target sim
25462
25463 Runs the builtin CPU simulator which can run very basic
25464 programs but does not support most hardware functions like MMU.
25465 For more complex use cases the user is advised to run an external
25466 target, and connect using @samp{target remote}.
25467
25468 Example: @code{target sim}
25469
25470 @item set debug or1k
25471 Toggle whether to display OpenRISC-specific debugging messages from the
25472 OpenRISC target support subsystem.
25473
25474 @item show debug or1k
25475 Show whether OpenRISC-specific debugging messages are enabled.
25476 @end table
25477
25478 @node PowerPC Embedded
25479 @subsection PowerPC Embedded
25480
25481 @cindex DVC register
25482 @value{GDBN} supports using the DVC (Data Value Compare) register to
25483 implement in hardware simple hardware watchpoint conditions of the form:
25484
25485 @smallexample
25486 (@value{GDBP}) watch @var{address|variable} \
25487 if @var{address|variable} == @var{constant expression}
25488 @end smallexample
25489
25490 The DVC register will be automatically used when @value{GDBN} detects
25491 such pattern in a condition expression, and the created watchpoint uses one
25492 debug register (either the @code{exact-watchpoints} option is on and the
25493 variable is scalar, or the variable has a length of one byte). This feature
25494 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
25495 or newer.
25496
25497 When running on PowerPC embedded processors, @value{GDBN} automatically uses
25498 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
25499 in which case watchpoints using only one debug register are created when
25500 watching variables of scalar types.
25501
25502 You can create an artificial array to watch an arbitrary memory
25503 region using one of the following commands (@pxref{Expressions}):
25504
25505 @smallexample
25506 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
25507 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
25508 @end smallexample
25509
25510 PowerPC embedded processors support masked watchpoints. See the discussion
25511 about the @code{mask} argument in @ref{Set Watchpoints}.
25512
25513 @cindex ranged breakpoint
25514 PowerPC embedded processors support hardware accelerated
25515 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
25516 the inferior whenever it executes an instruction at any address within
25517 the range it was set at. To set a ranged breakpoint in @value{GDBN},
25518 use the @code{break-range} command.
25519
25520 @value{GDBN} provides the following PowerPC-specific commands:
25521
25522 @table @code
25523 @kindex break-range
25524 @item break-range @var{start-locspec}, @var{end-locspec}
25525 Set a breakpoint for an address range given by @var{start-locspec} and
25526 @var{end-locspec}, which are location specs. @xref{Location
25527 Specifications}, for a list of all the possible forms of location
25528 specs. @value{GDBN} resolves both @var{start-locspec} and
25529 @var{end-locspec}, and uses the addresses of the resolved code
25530 locations as start and end addresses of the range to break at. The
25531 breakpoint will stop execution of the inferior whenever it executes an
25532 instruction at any address between the start and end addresses,
25533 inclusive. If either @var{start-locspec} or @var{end-locspec} resolve
25534 to multiple code locations in the program, then the command aborts
25535 with an error without creating a breakpoint.
25536
25537 @kindex set powerpc
25538 @item set powerpc soft-float
25539 @itemx show powerpc soft-float
25540 Force @value{GDBN} to use (or not use) a software floating point calling
25541 convention. By default, @value{GDBN} selects the calling convention based
25542 on the selected architecture and the provided executable file.
25543
25544 @item set powerpc vector-abi
25545 @itemx show powerpc vector-abi
25546 Force @value{GDBN} to use the specified calling convention for vector
25547 arguments and return values. The valid options are @samp{auto};
25548 @samp{generic}, to avoid vector registers even if they are present;
25549 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
25550 registers. By default, @value{GDBN} selects the calling convention
25551 based on the selected architecture and the provided executable file.
25552
25553 @item set powerpc exact-watchpoints
25554 @itemx show powerpc exact-watchpoints
25555 Allow @value{GDBN} to use only one debug register when watching a variable
25556 of scalar type, thus assuming that the variable is accessed through the
25557 address of its first byte.
25558
25559 @end table
25560
25561 @node AVR
25562 @subsection Atmel AVR
25563 @cindex AVR
25564
25565 When configured for debugging the Atmel AVR, @value{GDBN} supports the
25566 following AVR-specific commands:
25567
25568 @table @code
25569 @item info io_registers
25570 @kindex info io_registers@r{, AVR}
25571 @cindex I/O registers (Atmel AVR)
25572 This command displays information about the AVR I/O registers. For
25573 each register, @value{GDBN} prints its number and value.
25574 @end table
25575
25576 @node CRIS
25577 @subsection CRIS
25578 @cindex CRIS
25579
25580 When configured for debugging CRIS, @value{GDBN} provides the
25581 following CRIS-specific commands:
25582
25583 @table @code
25584 @item set cris-version @var{ver}
25585 @cindex CRIS version
25586 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
25587 The CRIS version affects register names and sizes. This command is useful in
25588 case autodetection of the CRIS version fails.
25589
25590 @item show cris-version
25591 Show the current CRIS version.
25592
25593 @item set cris-dwarf2-cfi
25594 @cindex DWARF-2 CFI and CRIS
25595 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
25596 Change to @samp{off} when using @code{gcc-cris} whose version is below
25597 @code{R59}.
25598
25599 @item show cris-dwarf2-cfi
25600 Show the current state of using DWARF-2 CFI.
25601
25602 @item set cris-mode @var{mode}
25603 @cindex CRIS mode
25604 Set the current CRIS mode to @var{mode}. It should only be changed when
25605 debugging in guru mode, in which case it should be set to
25606 @samp{guru} (the default is @samp{normal}).
25607
25608 @item show cris-mode
25609 Show the current CRIS mode.
25610 @end table
25611
25612 @node Super-H
25613 @subsection Renesas Super-H
25614 @cindex Super-H
25615
25616 For the Renesas Super-H processor, @value{GDBN} provides these
25617 commands:
25618
25619 @table @code
25620 @item set sh calling-convention @var{convention}
25621 @kindex set sh calling-convention
25622 Set the calling-convention used when calling functions from @value{GDBN}.
25623 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
25624 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
25625 convention. If the DWARF-2 information of the called function specifies
25626 that the function follows the Renesas calling convention, the function
25627 is called using the Renesas calling convention. If the calling convention
25628 is set to @samp{renesas}, the Renesas calling convention is always used,
25629 regardless of the DWARF-2 information. This can be used to override the
25630 default of @samp{gcc} if debug information is missing, or the compiler
25631 does not emit the DWARF-2 calling convention entry for a function.
25632
25633 @item show sh calling-convention
25634 @kindex show sh calling-convention
25635 Show the current calling convention setting.
25636
25637 @end table
25638
25639
25640 @node Architectures
25641 @section Architectures
25642
25643 This section describes characteristics of architectures that affect
25644 all uses of @value{GDBN} with the architecture, both native and cross.
25645
25646 @menu
25647 * AArch64::
25648 * i386::
25649 * Alpha::
25650 * MIPS::
25651 * HPPA:: HP PA architecture
25652 * PowerPC::
25653 * Nios II::
25654 * Sparc64::
25655 * S12Z::
25656 @end menu
25657
25658 @node AArch64
25659 @subsection AArch64
25660 @cindex AArch64 support
25661
25662 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25663 following special commands:
25664
25665 @table @code
25666 @item set debug aarch64
25667 @kindex set debug aarch64
25668 This command determines whether AArch64 architecture-specific debugging
25669 messages are to be displayed.
25670
25671 @item show debug aarch64
25672 Show whether AArch64 debugging messages are displayed.
25673
25674 @end table
25675
25676 @subsubsection AArch64 SVE.
25677 @cindex AArch64 SVE.
25678
25679 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25680 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25681 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25682 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25683 @code{$vg} will be provided. This is the vector granule for the current thread
25684 and represents the number of 64-bit chunks in an SVE @code{z} register.
25685
25686 If the vector length changes, then the @code{$vg} register will be updated,
25687 but the lengths of the @code{z} and @code{p} registers will not change. This
25688 is a known limitation of @value{GDBN} and does not affect the execution of the
25689 target process.
25690
25691 @subsubsection AArch64 Pointer Authentication.
25692 @cindex AArch64 Pointer Authentication.
25693 @anchor{AArch64 PAC}
25694
25695 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25696 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25697 register @code{$lr} is pointing to an PAC function its value will be masked.
25698 When GDB prints a backtrace, any addresses that required unmasking will be
25699 postfixed with the marker [PAC]. When using the MI, this is printed as part
25700 of the @code{addr_flags} field.
25701
25702 @subsubsection AArch64 Memory Tagging Extension.
25703 @cindex AArch64 Memory Tagging Extension.
25704
25705 When @value{GDBN} is debugging the AArch64 architecture, the program is
25706 using the v8.5-A feature Memory Tagging Extension (MTE) and there is support
25707 in the kernel for MTE, @value{GDBN} will make memory tagging functionality
25708 available for inspection and editing of logical and allocation tags.
25709 @xref{Memory Tagging}.
25710
25711 To aid debugging, @value{GDBN} will output additional information when SIGSEGV
25712 signals are generated as a result of memory tag failures.
25713
25714 If the tag violation is synchronous, the following will be shown:
25715
25716 @smallexample
25717 Program received signal SIGSEGV, Segmentation fault
25718 Memory tag violation while accessing address 0x0500fffff7ff8000
25719 Allocation tag 0x1
25720 Logical tag 0x5.
25721 @end smallexample
25722
25723 If the tag violation is asynchronous, the fault address is not available.
25724 In this case @value{GDBN} will show the following:
25725
25726 @smallexample
25727 Program received signal SIGSEGV, Segmentation fault
25728 Memory tag violation
25729 Fault address unavailable.
25730 @end smallexample
25731
25732 A special register, @code{tag_ctl}, is made available through the
25733 @code{org.gnu.gdb.aarch64.mte} feature. This register exposes some
25734 options that can be controlled at runtime and emulates the @code{prctl}
25735 option @code{PR_SET_TAGGED_ADDR_CTRL}. For further information, see the
25736 documentation in the Linux kernel.
25737
25738 @node i386
25739 @subsection x86 Architecture-specific Issues
25740
25741 @table @code
25742 @item set struct-convention @var{mode}
25743 @kindex set struct-convention
25744 @cindex struct return convention
25745 @cindex struct/union returned in registers
25746 Set the convention used by the inferior to return @code{struct}s and
25747 @code{union}s from functions to @var{mode}. Possible values of
25748 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25749 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25750 are returned on the stack, while @code{"reg"} means that a
25751 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25752 be returned in a register.
25753
25754 @item show struct-convention
25755 @kindex show struct-convention
25756 Show the current setting of the convention to return @code{struct}s
25757 from functions.
25758 @end table
25759
25760
25761 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25762 @cindex Intel Memory Protection Extensions (MPX).
25763
25764 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25765 @footnote{The register named with capital letters represent the architecture
25766 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25767 which are the lower bound and upper bound. Bounds are effective addresses or
25768 memory locations. The upper bounds are architecturally represented in 1's
25769 complement form. A bound having lower bound = 0, and upper bound = 0
25770 (1's complement of all bits set) will allow access to the entire address space.
25771
25772 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25773 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25774 display the upper bound performing the complement of one operation on the
25775 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25776 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25777 can also be noted that the upper bounds are inclusive.
25778
25779 As an example, assume that the register BND0 holds bounds for a pointer having
25780 access allowed for the range between 0x32 and 0x71. The values present on
25781 bnd0raw and bnd registers are presented as follows:
25782
25783 @smallexample
25784 bnd0raw = @{0x32, 0xffffffff8e@}
25785 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25786 @end smallexample
25787
25788 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25789 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25790 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25791 Python, the display includes the memory size, in bits, accessible to
25792 the pointer.
25793
25794 Bounds can also be stored in bounds tables, which are stored in
25795 application memory. These tables store bounds for pointers by specifying
25796 the bounds pointer's value along with its bounds. Evaluating and changing
25797 bounds located in bound tables is therefore interesting while investigating
25798 bugs on MPX context. @value{GDBN} provides commands for this purpose:
25799
25800 @table @code
25801 @item show mpx bound @var{pointer}
25802 @kindex show mpx bound
25803 Display bounds of the given @var{pointer}.
25804
25805 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25806 @kindex set mpx bound
25807 Set the bounds of a pointer in the bound table.
25808 This command takes three parameters: @var{pointer} is the pointers
25809 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25810 for lower and upper bounds respectively.
25811 @end table
25812
25813 When you call an inferior function on an Intel MPX enabled program,
25814 GDB sets the inferior's bound registers to the init (disabled) state
25815 before calling the function. As a consequence, bounds checks for the
25816 pointer arguments passed to the function will always pass.
25817
25818 This is necessary because when you call an inferior function, the
25819 program is usually in the middle of the execution of other function.
25820 Since at that point bound registers are in an arbitrary state, not
25821 clearing them would lead to random bound violations in the called
25822 function.
25823
25824 You can still examine the influence of the bound registers on the
25825 execution of the called function by stopping the execution of the
25826 called function at its prologue, setting bound registers, and
25827 continuing the execution. For example:
25828
25829 @smallexample
25830 $ break *upper
25831 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25832 $ print upper (a, b, c, d, 1)
25833 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25834 $ print $bnd0
25835 @{lbound = 0x0, ubound = ffffffff@} : size -1
25836 @end smallexample
25837
25838 At this last step the value of bnd0 can be changed for investigation of bound
25839 violations caused along the execution of the call. In order to know how to
25840 set the bound registers or bound table for the call consult the ABI.
25841
25842 @node Alpha
25843 @subsection Alpha
25844
25845 See the following section.
25846
25847 @node MIPS
25848 @subsection @acronym{MIPS}
25849
25850 @cindex stack on Alpha
25851 @cindex stack on @acronym{MIPS}
25852 @cindex Alpha stack
25853 @cindex @acronym{MIPS} stack
25854 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25855 sometimes requires @value{GDBN} to search backward in the object code to
25856 find the beginning of a function.
25857
25858 @cindex response time, @acronym{MIPS} debugging
25859 To improve response time (especially for embedded applications, where
25860 @value{GDBN} may be restricted to a slow serial line for this search)
25861 you may want to limit the size of this search, using one of these
25862 commands:
25863
25864 @table @code
25865 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25866 @item set heuristic-fence-post @var{limit}
25867 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25868 search for the beginning of a function. A value of @var{0} (the
25869 default) means there is no limit. However, except for @var{0}, the
25870 larger the limit the more bytes @code{heuristic-fence-post} must search
25871 and therefore the longer it takes to run. You should only need to use
25872 this command when debugging a stripped executable.
25873
25874 @item show heuristic-fence-post
25875 Display the current limit.
25876 @end table
25877
25878 @noindent
25879 These commands are available @emph{only} when @value{GDBN} is configured
25880 for debugging programs on Alpha or @acronym{MIPS} processors.
25881
25882 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25883 programs:
25884
25885 @table @code
25886 @item set mips abi @var{arg}
25887 @kindex set mips abi
25888 @cindex set ABI for @acronym{MIPS}
25889 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
25890 values of @var{arg} are:
25891
25892 @table @samp
25893 @item auto
25894 The default ABI associated with the current binary (this is the
25895 default).
25896 @item o32
25897 @item o64
25898 @item n32
25899 @item n64
25900 @item eabi32
25901 @item eabi64
25902 @end table
25903
25904 @item show mips abi
25905 @kindex show mips abi
25906 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25907
25908 @item set mips compression @var{arg}
25909 @kindex set mips compression
25910 @cindex code compression, @acronym{MIPS}
25911 Tell @value{GDBN} which @acronym{MIPS} compressed
25912 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25913 inferior. @value{GDBN} uses this for code disassembly and other
25914 internal interpretation purposes. This setting is only referred to
25915 when no executable has been associated with the debugging session or
25916 the executable does not provide information about the encoding it uses.
25917 Otherwise this setting is automatically updated from information
25918 provided by the executable.
25919
25920 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25921 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25922 executables containing @acronym{MIPS16} code frequently are not
25923 identified as such.
25924
25925 This setting is ``sticky''; that is, it retains its value across
25926 debugging sessions until reset either explicitly with this command or
25927 implicitly from an executable.
25928
25929 The compiler and/or assembler typically add symbol table annotations to
25930 identify functions compiled for the @acronym{MIPS16} or
25931 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25932 are present, @value{GDBN} uses them in preference to the global
25933 compressed @acronym{ISA} encoding setting.
25934
25935 @item show mips compression
25936 @kindex show mips compression
25937 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25938 @value{GDBN} to debug the inferior.
25939
25940 @item set mipsfpu
25941 @itemx show mipsfpu
25942 @xref{MIPS Embedded, set mipsfpu}.
25943
25944 @item set mips mask-address @var{arg}
25945 @kindex set mips mask-address
25946 @cindex @acronym{MIPS} addresses, masking
25947 This command determines whether the most-significant 32 bits of 64-bit
25948 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25949 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25950 setting, which lets @value{GDBN} determine the correct value.
25951
25952 @item show mips mask-address
25953 @kindex show mips mask-address
25954 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25955 not.
25956
25957 @item set remote-mips64-transfers-32bit-regs
25958 @kindex set remote-mips64-transfers-32bit-regs
25959 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25960 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25961 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25962 and 64 bits for other registers, set this option to @samp{on}.
25963
25964 @item show remote-mips64-transfers-32bit-regs
25965 @kindex show remote-mips64-transfers-32bit-regs
25966 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25967
25968 @item set debug mips
25969 @kindex set debug mips
25970 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25971 target code in @value{GDBN}.
25972
25973 @item show debug mips
25974 @kindex show debug mips
25975 Show the current setting of @acronym{MIPS} debugging messages.
25976 @end table
25977
25978
25979 @node HPPA
25980 @subsection HPPA
25981 @cindex HPPA support
25982
25983 When @value{GDBN} is debugging the HP PA architecture, it provides the
25984 following special commands:
25985
25986 @table @code
25987 @item set debug hppa
25988 @kindex set debug hppa
25989 This command determines whether HPPA architecture-specific debugging
25990 messages are to be displayed.
25991
25992 @item show debug hppa
25993 Show whether HPPA debugging messages are displayed.
25994
25995 @item maint print unwind @var{address}
25996 @kindex maint print unwind@r{, HPPA}
25997 This command displays the contents of the unwind table entry at the
25998 given @var{address}.
25999
26000 @end table
26001
26002
26003 @node PowerPC
26004 @subsection PowerPC
26005 @cindex PowerPC architecture
26006
26007 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
26008 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
26009 numbers stored in the floating point registers. These values must be stored
26010 in two consecutive registers, always starting at an even register like
26011 @code{f0} or @code{f2}.
26012
26013 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
26014 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
26015 @code{f2} and @code{f3} for @code{$dl1} and so on.
26016
26017 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
26018 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
26019
26020 @node Nios II
26021 @subsection Nios II
26022 @cindex Nios II architecture
26023
26024 When @value{GDBN} is debugging the Nios II architecture,
26025 it provides the following special commands:
26026
26027 @table @code
26028
26029 @item set debug nios2
26030 @kindex set debug nios2
26031 This command turns on and off debugging messages for the Nios II
26032 target code in @value{GDBN}.
26033
26034 @item show debug nios2
26035 @kindex show debug nios2
26036 Show the current setting of Nios II debugging messages.
26037 @end table
26038
26039 @node Sparc64
26040 @subsection Sparc64
26041 @cindex Sparc64 support
26042 @cindex Application Data Integrity
26043 @subsubsection ADI Support
26044
26045 The M7 processor supports an Application Data Integrity (ADI) feature that
26046 detects invalid data accesses. When software allocates memory and enables
26047 ADI on the allocated memory, it chooses a 4-bit version number, sets the
26048 version in the upper 4 bits of the 64-bit pointer to that data, and stores
26049 the 4-bit version in every cacheline of that data. Hardware saves the latter
26050 in spare bits in the cache and memory hierarchy. On each load and store,
26051 the processor compares the upper 4 VA (virtual address) bits to the
26052 cacheline's version. If there is a mismatch, the processor generates a
26053 version mismatch trap which can be either precise or disrupting. The trap
26054 is an error condition which the kernel delivers to the process as a SIGSEGV
26055 signal.
26056
26057 Note that only 64-bit applications can use ADI and need to be built with
26058 ADI-enabled.
26059
26060 Values of the ADI version tags, which are in granularity of a
26061 cacheline (64 bytes), can be viewed or modified.
26062
26063
26064 @table @code
26065 @kindex adi examine
26066 @item adi (examine | x) [ / @var{n} ] @var{addr}
26067
26068 The @code{adi examine} command displays the value of one ADI version tag per
26069 cacheline.
26070
26071 @var{n} is a decimal integer specifying the number in bytes; the default
26072 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
26073 block size, to display.
26074
26075 @var{addr} is the address in user address space where you want @value{GDBN}
26076 to begin displaying the ADI version tags.
26077
26078 Below is an example of displaying ADI versions of variable "shmaddr".
26079
26080 @smallexample
26081 (@value{GDBP}) adi x/100 shmaddr
26082 0xfff800010002c000: 0 0
26083 @end smallexample
26084
26085 @kindex adi assign
26086 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
26087
26088 The @code{adi assign} command is used to assign new ADI version tag
26089 to an address.
26090
26091 @var{n} is a decimal integer specifying the number in bytes;
26092 the default is 1. It specifies how much ADI version information, at the
26093 ratio of 1:ADI block size, to modify.
26094
26095 @var{addr} is the address in user address space where you want @value{GDBN}
26096 to begin modifying the ADI version tags.
26097
26098 @var{tag} is the new ADI version tag.
26099
26100 For example, do the following to modify then verify ADI versions of
26101 variable "shmaddr":
26102
26103 @smallexample
26104 (@value{GDBP}) adi a/100 shmaddr = 7
26105 (@value{GDBP}) adi x/100 shmaddr
26106 0xfff800010002c000: 7 7
26107 @end smallexample
26108
26109 @end table
26110
26111 @node S12Z
26112 @subsection S12Z
26113 @cindex S12Z support
26114
26115 When @value{GDBN} is debugging the S12Z architecture,
26116 it provides the following special command:
26117
26118 @table @code
26119 @item maint info bdccsr
26120 @kindex maint info bdccsr@r{, S12Z}
26121 This command displays the current value of the microprocessor's
26122 BDCCSR register.
26123 @end table
26124
26125
26126 @node Controlling GDB
26127 @chapter Controlling @value{GDBN}
26128
26129 You can alter the way @value{GDBN} interacts with you by using the
26130 @code{set} command. For commands controlling how @value{GDBN} displays
26131 data, see @ref{Print Settings, ,Print Settings}. Other settings are
26132 described here.
26133
26134 @menu
26135 * Prompt:: Prompt
26136 * Editing:: Command editing
26137 * Command History:: Command history
26138 * Screen Size:: Screen size
26139 * Output Styling:: Output styling
26140 * Numbers:: Numbers
26141 * ABI:: Configuring the current ABI
26142 * Auto-loading:: Automatically loading associated files
26143 * Messages/Warnings:: Optional warnings and messages
26144 * Debugging Output:: Optional messages about internal happenings
26145 * Other Misc Settings:: Other Miscellaneous Settings
26146 @end menu
26147
26148 @node Prompt
26149 @section Prompt
26150
26151 @cindex prompt
26152
26153 @value{GDBN} indicates its readiness to read a command by printing a string
26154 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
26155 can change the prompt string with the @code{set prompt} command. For
26156 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
26157 the prompt in one of the @value{GDBN} sessions so that you can always tell
26158 which one you are talking to.
26159
26160 @emph{Note:} @code{set prompt} does not add a space for you after the
26161 prompt you set. This allows you to set a prompt which ends in a space
26162 or a prompt that does not.
26163
26164 @table @code
26165 @kindex set prompt
26166 @item set prompt @var{newprompt}
26167 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
26168
26169 @kindex show prompt
26170 @item show prompt
26171 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
26172 @end table
26173
26174 Versions of @value{GDBN} that ship with Python scripting enabled have
26175 prompt extensions. The commands for interacting with these extensions
26176 are:
26177
26178 @table @code
26179 @kindex set extended-prompt
26180 @item set extended-prompt @var{prompt}
26181 Set an extended prompt that allows for substitutions.
26182 @xref{gdb.prompt}, for a list of escape sequences that can be used for
26183 substitution. Any escape sequences specified as part of the prompt
26184 string are replaced with the corresponding strings each time the prompt
26185 is displayed.
26186
26187 For example:
26188
26189 @smallexample
26190 set extended-prompt Current working directory: \w (gdb)
26191 @end smallexample
26192
26193 Note that when an extended-prompt is set, it takes control of the
26194 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
26195
26196 @kindex show extended-prompt
26197 @item show extended-prompt
26198 Prints the extended prompt. Any escape sequences specified as part of
26199 the prompt string with @code{set extended-prompt}, are replaced with the
26200 corresponding strings each time the prompt is displayed.
26201 @end table
26202
26203 @node Editing
26204 @section Command Editing
26205 @cindex readline
26206 @cindex command line editing
26207
26208 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
26209 @sc{gnu} library provides consistent behavior for programs which provide a
26210 command line interface to the user. Advantages are @sc{gnu} Emacs-style
26211 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
26212 substitution, and a storage and recall of command history across
26213 debugging sessions.
26214
26215 You may control the behavior of command line editing in @value{GDBN} with the
26216 command @code{set}.
26217
26218 @table @code
26219 @kindex set editing
26220 @cindex editing
26221 @item set editing
26222 @itemx set editing on
26223 Enable command line editing (enabled by default).
26224
26225 @item set editing off
26226 Disable command line editing.
26227
26228 @kindex show editing
26229 @item show editing
26230 Show whether command line editing is enabled.
26231 @end table
26232
26233 @ifset SYSTEM_READLINE
26234 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
26235 @end ifset
26236 @ifclear SYSTEM_READLINE
26237 @xref{Command Line Editing},
26238 @end ifclear
26239 for more details about the Readline
26240 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
26241 encouraged to read that chapter.
26242
26243 @cindex Readline application name
26244 @value{GDBN} sets the Readline application name to @samp{gdb}. This
26245 is useful for conditions in @file{.inputrc}.
26246
26247 @cindex operate-and-get-next
26248 @value{GDBN} defines a bindable Readline command,
26249 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
26250 This command accepts the current line for execution and fetches the
26251 next line relative to the current line from the history for editing.
26252 Any argument is ignored.
26253
26254 @node Command History
26255 @section Command History
26256 @cindex command history
26257
26258 @value{GDBN} can keep track of the commands you type during your
26259 debugging sessions, so that you can be certain of precisely what
26260 happened. Use these commands to manage the @value{GDBN} command
26261 history facility.
26262
26263 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
26264 package, to provide the history facility.
26265 @ifset SYSTEM_READLINE
26266 @xref{Using History Interactively, , , history, GNU History Library},
26267 @end ifset
26268 @ifclear SYSTEM_READLINE
26269 @xref{Using History Interactively},
26270 @end ifclear
26271 for the detailed description of the History library.
26272
26273 To issue a command to @value{GDBN} without affecting certain aspects of
26274 the state which is seen by users, prefix it with @samp{server }
26275 (@pxref{Server Prefix}). This
26276 means that this command will not affect the command history, nor will it
26277 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
26278 pressed on a line by itself.
26279
26280 @cindex @code{server}, command prefix
26281 The server prefix does not affect the recording of values into the value
26282 history; to print a value without recording it into the value history,
26283 use the @code{output} command instead of the @code{print} command.
26284
26285 Here is the description of @value{GDBN} commands related to command
26286 history.
26287
26288 @table @code
26289 @cindex history substitution
26290 @cindex history file
26291 @kindex set history filename
26292 @cindex @env{GDBHISTFILE}, environment variable
26293 @item set history filename @r{[}@var{fname}@r{]}
26294 Set the name of the @value{GDBN} command history file to @var{fname}.
26295 This is the file where @value{GDBN} reads an initial command history
26296 list, and where it writes the command history from this session when it
26297 exits. You can access this list through history expansion or through
26298 the history command editing characters listed below. This file defaults
26299 to the value of the environment variable @env{GDBHISTFILE}, or to
26300 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
26301 is not set.
26302
26303 The @env{GDBHISTFILE} environment variable is read after processing
26304 any @value{GDBN} initialization files (@pxref{Startup}) and after
26305 processing any commands passed using command line options (for
26306 example, @code{-ex}).
26307
26308 If the @var{fname} argument is not given, or if the @env{GDBHISTFILE}
26309 is the empty string then @value{GDBN} will neither try to load an
26310 existing history file, nor will it try to save the history on exit.
26311
26312 @cindex save command history
26313 @kindex set history save
26314 @item set history save
26315 @itemx set history save on
26316 Record command history in a file, whose name may be specified with the
26317 @code{set history filename} command. By default, this option is
26318 disabled. The command history will be recorded when @value{GDBN}
26319 exits. If @code{set history filename} is set to the empty string then
26320 history saving is disabled, even when @code{set history save} is
26321 @code{on}.
26322
26323 @item set history save off
26324 Don't record the command history into the file specified by @code{set
26325 history filename} when @value{GDBN} exits.
26326
26327 @cindex history size
26328 @kindex set history size
26329 @cindex @env{GDBHISTSIZE}, environment variable
26330 @item set history size @var{size}
26331 @itemx set history size unlimited
26332 Set the number of commands which @value{GDBN} keeps in its history list.
26333 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
26334 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
26335 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
26336 either a negative number or the empty string, then the number of commands
26337 @value{GDBN} keeps in the history list is unlimited.
26338
26339 The @env{GDBHISTSIZE} environment variable is read after processing
26340 any @value{GDBN} initialization files (@pxref{Startup}) and after
26341 processing any commands passed using command line options (for
26342 example, @code{-ex}).
26343
26344 @cindex remove duplicate history
26345 @kindex set history remove-duplicates
26346 @item set history remove-duplicates @var{count}
26347 @itemx set history remove-duplicates unlimited
26348 Control the removal of duplicate history entries in the command history list.
26349 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
26350 history entries and remove the first entry that is a duplicate of the current
26351 entry being added to the command history list. If @var{count} is
26352 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
26353 removal of duplicate history entries is disabled.
26354
26355 Only history entries added during the current session are considered for
26356 removal. This option is set to 0 by default.
26357
26358 @end table
26359
26360 History expansion assigns special meaning to the character @kbd{!}.
26361 @ifset SYSTEM_READLINE
26362 @xref{Event Designators, , , history, GNU History Library},
26363 @end ifset
26364 @ifclear SYSTEM_READLINE
26365 @xref{Event Designators},
26366 @end ifclear
26367 for more details.
26368
26369 @cindex history expansion, turn on/off
26370 Since @kbd{!} is also the logical not operator in C, history expansion
26371 is off by default. If you decide to enable history expansion with the
26372 @code{set history expansion on} command, you may sometimes need to
26373 follow @kbd{!} (when it is used as logical not, in an expression) with
26374 a space or a tab to prevent it from being expanded. The readline
26375 history facilities do not attempt substitution on the strings
26376 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
26377
26378 The commands to control history expansion are:
26379
26380 @table @code
26381 @item set history expansion on
26382 @itemx set history expansion
26383 @kindex set history expansion
26384 Enable history expansion. History expansion is off by default.
26385
26386 @item set history expansion off
26387 Disable history expansion.
26388
26389 @c @group
26390 @kindex show history
26391 @item show history
26392 @itemx show history filename
26393 @itemx show history save
26394 @itemx show history size
26395 @itemx show history expansion
26396 These commands display the state of the @value{GDBN} history parameters.
26397 @code{show history} by itself displays all four states.
26398 @c @end group
26399 @end table
26400
26401 @table @code
26402 @kindex show commands
26403 @cindex show last commands
26404 @cindex display command history
26405 @item show commands
26406 Display the last ten commands in the command history.
26407
26408 @item show commands @var{n}
26409 Print ten commands centered on command number @var{n}.
26410
26411 @item show commands +
26412 Print ten commands just after the commands last printed.
26413 @end table
26414
26415 @node Screen Size
26416 @section Screen Size
26417 @cindex size of screen
26418 @cindex screen size
26419 @cindex pagination
26420 @cindex page size
26421 @cindex pauses in output
26422
26423 Certain commands to @value{GDBN} may produce large amounts of
26424 information output to the screen. To help you read all of it,
26425 @value{GDBN} pauses and asks you for input at the end of each page of
26426 output. Type @key{RET} when you want to see one more page of output,
26427 @kbd{q} to discard the remaining output, or @kbd{c} to continue
26428 without paging for the rest of the current command. Also, the screen
26429 width setting determines when to wrap lines of output. Depending on
26430 what is being printed, @value{GDBN} tries to break the line at a
26431 readable place, rather than simply letting it overflow onto the
26432 following line.
26433
26434 Normally @value{GDBN} knows the size of the screen from the terminal
26435 driver software. For example, on Unix @value{GDBN} uses the termcap data base
26436 together with the value of the @env{TERM} environment variable and the
26437 @code{stty rows} and @code{stty cols} settings. If this is not correct,
26438 you can override it with the @code{set height} and @code{set
26439 width} commands:
26440
26441 @table @code
26442 @kindex set height
26443 @kindex set width
26444 @kindex show width
26445 @kindex show height
26446 @item set height @var{lpp}
26447 @itemx set height unlimited
26448 @itemx show height
26449 @itemx set width @var{cpl}
26450 @itemx set width unlimited
26451 @itemx show width
26452 These @code{set} commands specify a screen height of @var{lpp} lines and
26453 a screen width of @var{cpl} characters. The associated @code{show}
26454 commands display the current settings.
26455
26456 If you specify a height of either @code{unlimited} or zero lines,
26457 @value{GDBN} does not pause during output no matter how long the
26458 output is. This is useful if output is to a file or to an editor
26459 buffer.
26460
26461 Likewise, you can specify @samp{set width unlimited} or @samp{set
26462 width 0} to prevent @value{GDBN} from wrapping its output.
26463
26464 @item set pagination on
26465 @itemx set pagination off
26466 @kindex set pagination
26467 Turn the output pagination on or off; the default is on. Turning
26468 pagination off is the alternative to @code{set height unlimited}. Note that
26469 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
26470 Options, -batch}) also automatically disables pagination.
26471
26472 @item show pagination
26473 @kindex show pagination
26474 Show the current pagination mode.
26475 @end table
26476
26477 @node Output Styling
26478 @section Output Styling
26479 @cindex styling
26480 @cindex colors
26481
26482 @kindex set style
26483 @kindex show style
26484 @value{GDBN} can style its output on a capable terminal. This is
26485 enabled by default on most systems, but disabled by default when in
26486 batch mode (@pxref{Mode Options}). Various style settings are available;
26487 and styles can also be disabled entirely.
26488
26489 @table @code
26490 @item set style enabled @samp{on|off}
26491 Enable or disable all styling. The default is host-dependent, with
26492 most hosts defaulting to @samp{on}.
26493
26494 @item show style enabled
26495 Show the current state of styling.
26496
26497 @item set style sources @samp{on|off}
26498 Enable or disable source code styling. This affects whether source
26499 code, such as the output of the @code{list} command, is styled. The
26500 default is @samp{on}. Note that source styling only works if styling
26501 in general is enabled, and if a source highlighting library is
26502 available to @value{GDBN}.
26503
26504 There are two ways that highlighting can be done. First, if
26505 @value{GDBN} was linked with the GNU Source Highlight library, then it
26506 is used. Otherwise, if @value{GDBN} was configured with Python
26507 scripting support, and if the Python Pygments package is available,
26508 then it will be used.
26509
26510 @item show style sources
26511 Show the current state of source code styling.
26512
26513 @item set style disassembler enabled @samp{on|off}
26514 Enable or disable disassembler styling. This affects whether
26515 disassembler output, such as the output of the @code{disassemble}
26516 command, is styled. Disassembler styling only works if styling in
26517 general is enabled (with @code{set style enabled on}), and if a source
26518 highlighting library is available to @value{GDBN}.
26519
26520 To highlight disassembler output, @value{GDBN} must be compiled with
26521 Python support, and the Python Pygments package must be available. If
26522 these requirements are not met then @value{GDBN} will not highlight
26523 disassembler output, even when this option is @samp{on}.
26524
26525 @item show style disassembler enabled
26526 Show the current state of disassembler styling.
26527 @end table
26528
26529 Subcommands of @code{set style} control specific forms of styling.
26530 These subcommands all follow the same pattern: each style-able object
26531 can be styled with a foreground color, a background color, and an
26532 intensity.
26533
26534 For example, the style of file names can be controlled using the
26535 @code{set style filename} group of commands:
26536
26537 @table @code
26538 @item set style filename background @var{color}
26539 Set the background to @var{color}. Valid colors are @samp{none}
26540 (meaning the terminal's default color), @samp{black}, @samp{red},
26541 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26542 and@samp{white}.
26543
26544 @item set style filename foreground @var{color}
26545 Set the foreground to @var{color}. Valid colors are @samp{none}
26546 (meaning the terminal's default color), @samp{black}, @samp{red},
26547 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26548 and@samp{white}.
26549
26550 @item set style filename intensity @var{value}
26551 Set the intensity to @var{value}. Valid intensities are @samp{normal}
26552 (the default), @samp{bold}, and @samp{dim}.
26553 @end table
26554
26555 The @code{show style} command and its subcommands are styling
26556 a style name in their output using its own style.
26557 So, use @command{show style} to see the complete list of styles,
26558 their characteristics and the visual aspect of each style.
26559
26560 The style-able objects are:
26561 @table @code
26562 @item filename
26563 Control the styling of file names and URLs. By default, this style's
26564 foreground color is green.
26565
26566 @item function
26567 Control the styling of function names. These are managed with the
26568 @code{set style function} family of commands. By default, this
26569 style's foreground color is yellow.
26570
26571 @item variable
26572 Control the styling of variable names. These are managed with the
26573 @code{set style variable} family of commands. By default, this style's
26574 foreground color is cyan.
26575
26576 @item address
26577 Control the styling of addresses. These are managed with the
26578 @code{set style address} family of commands. By default, this style's
26579 foreground color is blue.
26580
26581 @item version
26582 Control the styling of @value{GDBN}'s version number text. By
26583 default, this style's foreground color is magenta and it has bold
26584 intensity. The version number is displayed in two places, the output
26585 of @command{show version}, and when @value{GDBN} starts up.
26586
26587 In order to control how @value{GDBN} styles the version number at
26588 startup, add the @code{set style version} family of commands to the
26589 early initialization command file (@pxref{Initialization
26590 Files}).
26591
26592 @item title
26593 Control the styling of titles. These are managed with the
26594 @code{set style title} family of commands. By default, this style's
26595 intensity is bold. Commands are using the title style to improve
26596 the readability of large output. For example, the commands
26597 @command{apropos} and @command{help} are using the title style
26598 for the command names.
26599
26600 @item highlight
26601 Control the styling of highlightings. These are managed with the
26602 @code{set style highlight} family of commands. By default, this style's
26603 foreground color is red. Commands are using the highlight style to draw
26604 the user attention to some specific parts of their output. For example,
26605 the command @command{apropos -v REGEXP} uses the highlight style to
26606 mark the documentation parts matching @var{regexp}.
26607
26608 @item metadata
26609 Control the styling of data annotations added by @value{GDBN} to data
26610 it displays. By default, this style's intensity is dim. Metadata
26611 annotations include the @samp{repeats @var{n} times} annotation for
26612 suppressed display of repeated array elements (@pxref{Print Settings}),
26613 @samp{<unavailable>} and @w{@samp{<error @var{descr}>}} annotations
26614 for errors and @samp{<optimized-out>} annotations for optimized-out
26615 values in displaying stack frame information in backtraces
26616 (@pxref{Backtrace}), etc.
26617
26618 @item tui-border
26619 Control the styling of the TUI border. Note that, unlike other
26620 styling options, only the color of the border can be controlled via
26621 @code{set style}. This was done for compatibility reasons, as TUI
26622 controls to set the border's intensity predated the addition of
26623 general styling to @value{GDBN}. @xref{TUI Configuration}.
26624
26625 @item tui-active-border
26626 Control the styling of the active TUI border; that is, the TUI window
26627 that has the focus.
26628
26629 @end table
26630
26631 @node Numbers
26632 @section Numbers
26633 @cindex number representation
26634 @cindex entering numbers
26635
26636 You can always enter numbers in octal, decimal, or hexadecimal in
26637 @value{GDBN} by the usual conventions: octal numbers begin with
26638 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
26639 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
26640 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
26641 10; likewise, the default display for numbers---when no particular
26642 format is specified---is base 10. You can change the default base for
26643 both input and output with the commands described below.
26644
26645 @table @code
26646 @kindex set input-radix
26647 @item set input-radix @var{base}
26648 Set the default base for numeric input. Supported choices
26649 for @var{base} are decimal 8, 10, or 16. The base must itself be
26650 specified either unambiguously or using the current input radix; for
26651 example, any of
26652
26653 @smallexample
26654 set input-radix 012
26655 set input-radix 10.
26656 set input-radix 0xa
26657 @end smallexample
26658
26659 @noindent
26660 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
26661 leaves the input radix unchanged, no matter what it was, since
26662 @samp{10}, being without any leading or trailing signs of its base, is
26663 interpreted in the current radix. Thus, if the current radix is 16,
26664 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
26665 change the radix.
26666
26667 @kindex set output-radix
26668 @item set output-radix @var{base}
26669 Set the default base for numeric display. Supported choices
26670 for @var{base} are decimal 8, 10, or 16. The base must itself be
26671 specified either unambiguously or using the current input radix.
26672
26673 @kindex show input-radix
26674 @item show input-radix
26675 Display the current default base for numeric input.
26676
26677 @kindex show output-radix
26678 @item show output-radix
26679 Display the current default base for numeric display.
26680
26681 @item set radix @r{[}@var{base}@r{]}
26682 @itemx show radix
26683 @kindex set radix
26684 @kindex show radix
26685 These commands set and show the default base for both input and output
26686 of numbers. @code{set radix} sets the radix of input and output to
26687 the same base; without an argument, it resets the radix back to its
26688 default value of 10.
26689
26690 @end table
26691
26692 @node ABI
26693 @section Configuring the Current ABI
26694
26695 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
26696 application automatically. However, sometimes you need to override its
26697 conclusions. Use these commands to manage @value{GDBN}'s view of the
26698 current ABI.
26699
26700 @cindex OS ABI
26701 @kindex set osabi
26702 @kindex show osabi
26703 @cindex Newlib OS ABI and its influence on the longjmp handling
26704
26705 One @value{GDBN} configuration can debug binaries for multiple operating
26706 system targets, either via remote debugging or native emulation.
26707 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
26708 but you can override its conclusion using the @code{set osabi} command.
26709 One example where this is useful is in debugging of binaries which use
26710 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
26711 not have the same identifying marks that the standard C library for your
26712 platform provides.
26713
26714 When @value{GDBN} is debugging the AArch64 architecture, it provides a
26715 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
26716 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
26717 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
26718
26719 @table @code
26720 @item show osabi
26721 Show the OS ABI currently in use.
26722
26723 @item set osabi
26724 With no argument, show the list of registered available OS ABI's.
26725
26726 @item set osabi @var{abi}
26727 Set the current OS ABI to @var{abi}.
26728 @end table
26729
26730 @cindex float promotion
26731
26732 Generally, the way that an argument of type @code{float} is passed to a
26733 function depends on whether the function is prototyped. For a prototyped
26734 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26735 according to the architecture's convention for @code{float}. For unprototyped
26736 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26737 @code{double} and then passed.
26738
26739 Unfortunately, some forms of debug information do not reliably indicate whether
26740 a function is prototyped. If @value{GDBN} calls a function that is not marked
26741 as prototyped, it consults @kbd{set coerce-float-to-double}.
26742
26743 @table @code
26744 @kindex set coerce-float-to-double
26745 @item set coerce-float-to-double
26746 @itemx set coerce-float-to-double on
26747 Arguments of type @code{float} will be promoted to @code{double} when passed
26748 to an unprototyped function. This is the default setting.
26749
26750 @item set coerce-float-to-double off
26751 Arguments of type @code{float} will be passed directly to unprototyped
26752 functions.
26753
26754 @kindex show coerce-float-to-double
26755 @item show coerce-float-to-double
26756 Show the current setting of promoting @code{float} to @code{double}.
26757 @end table
26758
26759 @kindex set cp-abi
26760 @kindex show cp-abi
26761 @value{GDBN} needs to know the ABI used for your program's C@t{++}
26762 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26763 used to build your application. @value{GDBN} only fully supports
26764 programs with a single C@t{++} ABI; if your program contains code using
26765 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26766 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26767 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26768 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26769 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26770 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26771 ``auto''.
26772
26773 @table @code
26774 @item show cp-abi
26775 Show the C@t{++} ABI currently in use.
26776
26777 @item set cp-abi
26778 With no argument, show the list of supported C@t{++} ABI's.
26779
26780 @item set cp-abi @var{abi}
26781 @itemx set cp-abi auto
26782 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26783 @end table
26784
26785 @node Auto-loading
26786 @section Automatically loading associated files
26787 @cindex auto-loading
26788
26789 @value{GDBN} sometimes reads files with commands and settings automatically,
26790 without being explicitly told so by the user. We call this feature
26791 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
26792 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
26793 results or introduce security risks (e.g., if the file comes from untrusted
26794 sources).
26795
26796 There are various kinds of files @value{GDBN} can automatically load.
26797 In addition to these files, @value{GDBN} supports auto-loading code written
26798 in various extension languages. @xref{Auto-loading extensions}.
26799
26800 Note that loading of these associated files (including the local @file{.gdbinit}
26801 file) requires accordingly configured @code{auto-load safe-path}
26802 (@pxref{Auto-loading safe path}).
26803
26804 For these reasons, @value{GDBN} includes commands and options to let you
26805 control when to auto-load files and which files should be auto-loaded.
26806
26807 @table @code
26808 @anchor{set auto-load off}
26809 @kindex set auto-load off
26810 @item set auto-load off
26811 Globally disable loading of all auto-loaded files.
26812 You may want to use this command with the @samp{-iex} option
26813 (@pxref{Option -init-eval-command}) such as:
26814 @smallexample
26815 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26816 @end smallexample
26817
26818 Be aware that system init file (@pxref{System-wide configuration})
26819 and init files from your home directory (@pxref{Home Directory Init File})
26820 still get read (as they come from generally trusted directories).
26821 To prevent @value{GDBN} from auto-loading even those init files, use the
26822 @option{-nx} option (@pxref{Mode Options}), in addition to
26823 @code{set auto-load no}.
26824
26825 @anchor{show auto-load}
26826 @kindex show auto-load
26827 @item show auto-load
26828 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26829 or disabled.
26830
26831 @smallexample
26832 (gdb) show auto-load
26833 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26834 libthread-db: Auto-loading of inferior specific libthread_db is on.
26835 local-gdbinit: Auto-loading of .gdbinit script from current directory
26836 is on.
26837 python-scripts: Auto-loading of Python scripts is on.
26838 safe-path: List of directories from which it is safe to auto-load files
26839 is $debugdir:$datadir/auto-load.
26840 scripts-directory: List of directories from which to load auto-loaded scripts
26841 is $debugdir:$datadir/auto-load.
26842 @end smallexample
26843
26844 @anchor{info auto-load}
26845 @kindex info auto-load
26846 @item info auto-load
26847 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26848 not.
26849
26850 @smallexample
26851 (gdb) info auto-load
26852 gdb-scripts:
26853 Loaded Script
26854 Yes /home/user/gdb/gdb-gdb.gdb
26855 libthread-db: No auto-loaded libthread-db.
26856 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26857 loaded.
26858 python-scripts:
26859 Loaded Script
26860 Yes /home/user/gdb/gdb-gdb.py
26861 @end smallexample
26862 @end table
26863
26864 These are @value{GDBN} control commands for the auto-loading:
26865
26866 @multitable @columnfractions .5 .5
26867 @item @xref{set auto-load off}.
26868 @tab Disable auto-loading globally.
26869 @item @xref{show auto-load}.
26870 @tab Show setting of all kinds of files.
26871 @item @xref{info auto-load}.
26872 @tab Show state of all kinds of files.
26873 @item @xref{set auto-load gdb-scripts}.
26874 @tab Control for @value{GDBN} command scripts.
26875 @item @xref{show auto-load gdb-scripts}.
26876 @tab Show setting of @value{GDBN} command scripts.
26877 @item @xref{info auto-load gdb-scripts}.
26878 @tab Show state of @value{GDBN} command scripts.
26879 @item @xref{set auto-load python-scripts}.
26880 @tab Control for @value{GDBN} Python scripts.
26881 @item @xref{show auto-load python-scripts}.
26882 @tab Show setting of @value{GDBN} Python scripts.
26883 @item @xref{info auto-load python-scripts}.
26884 @tab Show state of @value{GDBN} Python scripts.
26885 @item @xref{set auto-load guile-scripts}.
26886 @tab Control for @value{GDBN} Guile scripts.
26887 @item @xref{show auto-load guile-scripts}.
26888 @tab Show setting of @value{GDBN} Guile scripts.
26889 @item @xref{info auto-load guile-scripts}.
26890 @tab Show state of @value{GDBN} Guile scripts.
26891 @item @xref{set auto-load scripts-directory}.
26892 @tab Control for @value{GDBN} auto-loaded scripts location.
26893 @item @xref{show auto-load scripts-directory}.
26894 @tab Show @value{GDBN} auto-loaded scripts location.
26895 @item @xref{add-auto-load-scripts-directory}.
26896 @tab Add directory for auto-loaded scripts location list.
26897 @item @xref{set auto-load local-gdbinit}.
26898 @tab Control for init file in the current directory.
26899 @item @xref{show auto-load local-gdbinit}.
26900 @tab Show setting of init file in the current directory.
26901 @item @xref{info auto-load local-gdbinit}.
26902 @tab Show state of init file in the current directory.
26903 @item @xref{set auto-load libthread-db}.
26904 @tab Control for thread debugging library.
26905 @item @xref{show auto-load libthread-db}.
26906 @tab Show setting of thread debugging library.
26907 @item @xref{info auto-load libthread-db}.
26908 @tab Show state of thread debugging library.
26909 @item @xref{set auto-load safe-path}.
26910 @tab Control directories trusted for automatic loading.
26911 @item @xref{show auto-load safe-path}.
26912 @tab Show directories trusted for automatic loading.
26913 @item @xref{add-auto-load-safe-path}.
26914 @tab Add directory trusted for automatic loading.
26915 @end multitable
26916
26917 @menu
26918 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26919 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26920
26921 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26922 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
26923 @end menu
26924
26925 @node Init File in the Current Directory
26926 @subsection Automatically loading init file in the current directory
26927 @cindex auto-loading init file in the current directory
26928
26929 By default, @value{GDBN} reads and executes the canned sequences of commands
26930 from init file (if any) in the current working directory,
26931 see @ref{Init File in the Current Directory during Startup}.
26932
26933 Note that loading of this local @file{.gdbinit} file also requires accordingly
26934 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26935
26936 @table @code
26937 @anchor{set auto-load local-gdbinit}
26938 @kindex set auto-load local-gdbinit
26939 @item set auto-load local-gdbinit [on|off]
26940 Enable or disable the auto-loading of canned sequences of commands
26941 (@pxref{Sequences}) found in init file in the current directory.
26942
26943 @anchor{show auto-load local-gdbinit}
26944 @kindex show auto-load local-gdbinit
26945 @item show auto-load local-gdbinit
26946 Show whether auto-loading of canned sequences of commands from init file in the
26947 current directory is enabled or disabled.
26948
26949 @anchor{info auto-load local-gdbinit}
26950 @kindex info auto-load local-gdbinit
26951 @item info auto-load local-gdbinit
26952 Print whether canned sequences of commands from init file in the
26953 current directory have been auto-loaded.
26954 @end table
26955
26956 @node libthread_db.so.1 file
26957 @subsection Automatically loading thread debugging library
26958 @cindex auto-loading libthread_db.so.1
26959
26960 This feature is currently present only on @sc{gnu}/Linux native hosts.
26961
26962 @value{GDBN} reads in some cases thread debugging library from places specific
26963 to the inferior (@pxref{set libthread-db-search-path}).
26964
26965 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26966 without checking this @samp{set auto-load libthread-db} switch as system
26967 libraries have to be trusted in general. In all other cases of
26968 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26969 auto-load libthread-db} is enabled before trying to open such thread debugging
26970 library.
26971
26972 Note that loading of this debugging library also requires accordingly configured
26973 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26974
26975 @table @code
26976 @anchor{set auto-load libthread-db}
26977 @kindex set auto-load libthread-db
26978 @item set auto-load libthread-db [on|off]
26979 Enable or disable the auto-loading of inferior specific thread debugging library.
26980
26981 @anchor{show auto-load libthread-db}
26982 @kindex show auto-load libthread-db
26983 @item show auto-load libthread-db
26984 Show whether auto-loading of inferior specific thread debugging library is
26985 enabled or disabled.
26986
26987 @anchor{info auto-load libthread-db}
26988 @kindex info auto-load libthread-db
26989 @item info auto-load libthread-db
26990 Print the list of all loaded inferior specific thread debugging libraries and
26991 for each such library print list of inferior @var{pid}s using it.
26992 @end table
26993
26994 @node Auto-loading safe path
26995 @subsection Security restriction for auto-loading
26996 @cindex auto-loading safe-path
26997
26998 As the files of inferior can come from untrusted source (such as submitted by
26999 an application user) @value{GDBN} does not always load any files automatically.
27000 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
27001 directories trusted for loading files not explicitly requested by user.
27002 Each directory can also be a shell wildcard pattern.
27003
27004 If the path is not set properly you will see a warning and the file will not
27005 get loaded:
27006
27007 @smallexample
27008 $ ./gdb -q ./gdb
27009 Reading symbols from /home/user/gdb/gdb...
27010 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
27011 declined by your `auto-load safe-path' set
27012 to "$debugdir:$datadir/auto-load".
27013 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
27014 declined by your `auto-load safe-path' set
27015 to "$debugdir:$datadir/auto-load".
27016 @end smallexample
27017
27018 @noindent
27019 To instruct @value{GDBN} to go ahead and use the init files anyway,
27020 invoke @value{GDBN} like this:
27021
27022 @smallexample
27023 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
27024 @end smallexample
27025
27026 The list of trusted directories is controlled by the following commands:
27027
27028 @table @code
27029 @anchor{set auto-load safe-path}
27030 @kindex set auto-load safe-path
27031 @item set auto-load safe-path @r{[}@var{directories}@r{]}
27032 Set the list of directories (and their subdirectories) trusted for automatic
27033 loading and execution of scripts. You can also enter a specific trusted file.
27034 Each directory can also be a shell wildcard pattern; wildcards do not match
27035 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
27036 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
27037 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
27038 its default value as specified during @value{GDBN} compilation.
27039
27040 The list of directories uses path separator (@samp{:} on GNU and Unix
27041 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27042 to the @env{PATH} environment variable.
27043
27044 @anchor{show auto-load safe-path}
27045 @kindex show auto-load safe-path
27046 @item show auto-load safe-path
27047 Show the list of directories trusted for automatic loading and execution of
27048 scripts.
27049
27050 @anchor{add-auto-load-safe-path}
27051 @kindex add-auto-load-safe-path
27052 @item add-auto-load-safe-path
27053 Add an entry (or list of entries) to the list of directories trusted for
27054 automatic loading and execution of scripts. Multiple entries may be delimited
27055 by the host platform path separator in use.
27056 @end table
27057
27058 This variable defaults to what @code{--with-auto-load-dir} has been configured
27059 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
27060 substitution applies the same as for @ref{set auto-load scripts-directory}.
27061 The default @code{set auto-load safe-path} value can be also overriden by
27062 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
27063
27064 Setting this variable to @file{/} disables this security protection,
27065 corresponding @value{GDBN} configuration option is
27066 @option{--without-auto-load-safe-path}.
27067 This variable is supposed to be set to the system directories writable by the
27068 system superuser only. Users can add their source directories in init files in
27069 their home directories (@pxref{Home Directory Init File}). See also deprecated
27070 init file in the current directory
27071 (@pxref{Init File in the Current Directory during Startup}).
27072
27073 To force @value{GDBN} to load the files it declined to load in the previous
27074 example, you could use one of the following ways:
27075
27076 @table @asis
27077 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
27078 Specify this trusted directory (or a file) as additional component of the list.
27079 You have to specify also any existing directories displayed by
27080 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
27081
27082 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
27083 Specify this directory as in the previous case but just for a single
27084 @value{GDBN} session.
27085
27086 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
27087 Disable auto-loading safety for a single @value{GDBN} session.
27088 This assumes all the files you debug during this @value{GDBN} session will come
27089 from trusted sources.
27090
27091 @item @kbd{./configure --without-auto-load-safe-path}
27092 During compilation of @value{GDBN} you may disable any auto-loading safety.
27093 This assumes all the files you will ever debug with this @value{GDBN} come from
27094 trusted sources.
27095 @end table
27096
27097 On the other hand you can also explicitly forbid automatic files loading which
27098 also suppresses any such warning messages:
27099
27100 @table @asis
27101 @item @kbd{gdb -iex "set auto-load no" @dots{}}
27102 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
27103
27104 @item @file{~/.gdbinit}: @samp{set auto-load no}
27105 Disable auto-loading globally for the user
27106 (@pxref{Home Directory Init File}). While it is improbable, you could also
27107 use system init file instead (@pxref{System-wide configuration}).
27108 @end table
27109
27110 This setting applies to the file names as entered by user. If no entry matches
27111 @value{GDBN} tries as a last resort to also resolve all the file names into
27112 their canonical form (typically resolving symbolic links) and compare the
27113 entries again. @value{GDBN} already canonicalizes most of the filenames on its
27114 own before starting the comparison so a canonical form of directories is
27115 recommended to be entered.
27116
27117 @node Auto-loading verbose mode
27118 @subsection Displaying files tried for auto-load
27119 @cindex auto-loading verbose mode
27120
27121 For better visibility of all the file locations where you can place scripts to
27122 be auto-loaded with inferior --- or to protect yourself against accidental
27123 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
27124 all the files attempted to be loaded. Both existing and non-existing files may
27125 be printed.
27126
27127 For example the list of directories from which it is safe to auto-load files
27128 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
27129 may not be too obvious while setting it up.
27130
27131 @smallexample
27132 (gdb) set debug auto-load on
27133 (gdb) file ~/src/t/true
27134 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
27135 for objfile "/tmp/true".
27136 auto-load: Updating directories of "/usr:/opt".
27137 auto-load: Using directory "/usr".
27138 auto-load: Using directory "/opt".
27139 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
27140 by your `auto-load safe-path' set to "/usr:/opt".
27141 @end smallexample
27142
27143 @table @code
27144 @anchor{set debug auto-load}
27145 @kindex set debug auto-load
27146 @item set debug auto-load [on|off]
27147 Set whether to print the filenames attempted to be auto-loaded.
27148
27149 @anchor{show debug auto-load}
27150 @kindex show debug auto-load
27151 @item show debug auto-load
27152 Show whether printing of the filenames attempted to be auto-loaded is turned
27153 on or off.
27154 @end table
27155
27156 @node Messages/Warnings
27157 @section Optional Warnings and Messages
27158
27159 @cindex verbose operation
27160 @cindex optional warnings
27161 By default, @value{GDBN} is silent about its inner workings. If you are
27162 running on a slow machine, you may want to use the @code{set verbose}
27163 command. This makes @value{GDBN} tell you when it does a lengthy
27164 internal operation, so you will not think it has crashed.
27165
27166 Currently, the messages controlled by @code{set verbose} are those
27167 which announce that the symbol table for a source file is being read;
27168 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
27169
27170 @table @code
27171 @kindex set verbose
27172 @item set verbose on
27173 Enables @value{GDBN} output of certain informational messages.
27174
27175 @item set verbose off
27176 Disables @value{GDBN} output of certain informational messages.
27177
27178 @kindex show verbose
27179 @item show verbose
27180 Displays whether @code{set verbose} is on or off.
27181 @end table
27182
27183 By default, if @value{GDBN} encounters bugs in the symbol table of an
27184 object file, it is silent; but if you are debugging a compiler, you may
27185 find this information useful (@pxref{Symbol Errors, ,Errors Reading
27186 Symbol Files}).
27187
27188 @table @code
27189
27190 @kindex set complaints
27191 @item set complaints @var{limit}
27192 Permits @value{GDBN} to output @var{limit} complaints about each type of
27193 unusual symbols before becoming silent about the problem. Set
27194 @var{limit} to zero to suppress all complaints; set it to a large number
27195 to prevent complaints from being suppressed.
27196
27197 @kindex show complaints
27198 @item show complaints
27199 Displays how many symbol complaints @value{GDBN} is permitted to produce.
27200
27201 @end table
27202
27203 @anchor{confirmation requests}
27204 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
27205 lot of stupid questions to confirm certain commands. For example, if
27206 you try to run a program which is already running:
27207
27208 @smallexample
27209 (@value{GDBP}) run
27210 The program being debugged has been started already.
27211 Start it from the beginning? (y or n)
27212 @end smallexample
27213
27214 If you are willing to unflinchingly face the consequences of your own
27215 commands, you can disable this ``feature'':
27216
27217 @table @code
27218
27219 @kindex set confirm
27220 @cindex flinching
27221 @cindex confirmation
27222 @cindex stupid questions
27223 @item set confirm off
27224 Disables confirmation requests. Note that running @value{GDBN} with
27225 the @option{--batch} option (@pxref{Mode Options, -batch}) also
27226 automatically disables confirmation requests.
27227
27228 @item set confirm on
27229 Enables confirmation requests (the default).
27230
27231 @kindex show confirm
27232 @item show confirm
27233 Displays state of confirmation requests.
27234
27235 @end table
27236
27237 @cindex command tracing
27238 If you need to debug user-defined commands or sourced files you may find it
27239 useful to enable @dfn{command tracing}. In this mode each command will be
27240 printed as it is executed, prefixed with one or more @samp{+} symbols, the
27241 quantity denoting the call depth of each command.
27242
27243 @table @code
27244 @kindex set trace-commands
27245 @cindex command scripts, debugging
27246 @item set trace-commands on
27247 Enable command tracing.
27248 @item set trace-commands off
27249 Disable command tracing.
27250 @item show trace-commands
27251 Display the current state of command tracing.
27252 @end table
27253
27254 @node Debugging Output
27255 @section Optional Messages about Internal Happenings
27256 @cindex optional debugging messages
27257
27258 @value{GDBN} has commands that enable optional debugging messages from
27259 various @value{GDBN} subsystems; normally these commands are of
27260 interest to @value{GDBN} maintainers, or when reporting a bug. This
27261 section documents those commands.
27262
27263 @table @code
27264 @kindex set exec-done-display
27265 @item set exec-done-display
27266 Turns on or off the notification of asynchronous commands'
27267 completion. When on, @value{GDBN} will print a message when an
27268 asynchronous command finishes its execution. The default is off.
27269 @kindex show exec-done-display
27270 @item show exec-done-display
27271 Displays the current setting of asynchronous command completion
27272 notification.
27273
27274 @kindex set debug
27275 @cindex ARM AArch64
27276 @item set debug aarch64
27277 Turns on or off display of debugging messages related to ARM AArch64.
27278 The default is off.
27279 @kindex show debug
27280 @item show debug aarch64
27281 Displays the current state of displaying debugging messages related to
27282 ARM AArch64.
27283
27284 @cindex gdbarch debugging info
27285 @cindex architecture debugging info
27286 @item set debug arch
27287 Turns on or off display of gdbarch debugging info. The default is off
27288 @item show debug arch
27289 Displays the current state of displaying gdbarch debugging info.
27290
27291 @item set debug aix-solib
27292 @cindex AIX shared library debugging
27293 Control display of debugging messages from the AIX shared library
27294 support module. The default is off.
27295 @item show debug aix-solib
27296 Show the current state of displaying AIX shared library debugging messages.
27297
27298 @item set debug aix-thread
27299 @cindex AIX threads
27300 Display debugging messages about inner workings of the AIX thread
27301 module.
27302 @item show debug aix-thread
27303 Show the current state of AIX thread debugging info display.
27304
27305 @item set debug check-physname
27306 @cindex physname
27307 Check the results of the ``physname'' computation. When reading DWARF
27308 debugging information for C@t{++}, @value{GDBN} attempts to compute
27309 each entity's name. @value{GDBN} can do this computation in two
27310 different ways, depending on exactly what information is present.
27311 When enabled, this setting causes @value{GDBN} to compute the names
27312 both ways and display any discrepancies.
27313 @item show debug check-physname
27314 Show the current state of ``physname'' checking.
27315
27316 @item set debug coff-pe-read
27317 @cindex COFF/PE exported symbols
27318 Control display of debugging messages related to reading of COFF/PE
27319 exported symbols. The default is off.
27320 @item show debug coff-pe-read
27321 Displays the current state of displaying debugging messages related to
27322 reading of COFF/PE exported symbols.
27323
27324 @item set debug dwarf-die
27325 @cindex DWARF DIEs
27326 Dump DWARF DIEs after they are read in.
27327 The value is the number of nesting levels to print.
27328 A value of zero turns off the display.
27329 @item show debug dwarf-die
27330 Show the current state of DWARF DIE debugging.
27331
27332 @item set debug dwarf-line
27333 @cindex DWARF Line Tables
27334 Turns on or off display of debugging messages related to reading
27335 DWARF line tables. The default is 0 (off).
27336 A value of 1 provides basic information.
27337 A value greater than 1 provides more verbose information.
27338 @item show debug dwarf-line
27339 Show the current state of DWARF line table debugging.
27340
27341 @item set debug dwarf-read
27342 @cindex DWARF Reading
27343 Turns on or off display of debugging messages related to reading
27344 DWARF debug info. The default is 0 (off).
27345 A value of 1 provides basic information.
27346 A value greater than 1 provides more verbose information.
27347 @item show debug dwarf-read
27348 Show the current state of DWARF reader debugging.
27349
27350 @item set debug displaced
27351 @cindex displaced stepping debugging info
27352 Turns on or off display of @value{GDBN} debugging info for the
27353 displaced stepping support. The default is off.
27354 @item show debug displaced
27355 Displays the current state of displaying @value{GDBN} debugging info
27356 related to displaced stepping.
27357
27358 @item set debug event
27359 @cindex event debugging info
27360 Turns on or off display of @value{GDBN} event debugging info. The
27361 default is off.
27362 @item show debug event
27363 Displays the current state of displaying @value{GDBN} event debugging
27364 info.
27365
27366 @item set debug event-loop
27367 @cindex event-loop debugging
27368 Controls output of debugging info about the event loop. The possible
27369 values are @samp{off}, @samp{all} (shows all debugging info) and
27370 @samp{all-except-ui} (shows all debugging info except those about
27371 UI-related events).
27372 @item show debug event-loop
27373 Shows the current state of displaying debugging info about the event
27374 loop.
27375
27376 @item set debug expression
27377 @cindex expression debugging info
27378 Turns on or off display of debugging info about @value{GDBN}
27379 expression parsing. The default is off.
27380 @item show debug expression
27381 Displays the current state of displaying debugging info about
27382 @value{GDBN} expression parsing.
27383
27384 @item set debug fbsd-lwp
27385 @cindex FreeBSD LWP debug messages
27386 Turns on or off debugging messages from the FreeBSD LWP debug support.
27387 @item show debug fbsd-lwp
27388 Show the current state of FreeBSD LWP debugging messages.
27389
27390 @item set debug fbsd-nat
27391 @cindex FreeBSD native target debug messages
27392 Turns on or off debugging messages from the FreeBSD native target.
27393 @item show debug fbsd-nat
27394 Show the current state of FreeBSD native target debugging messages.
27395
27396 @item set debug fortran-array-slicing
27397 @cindex fortran array slicing debugging info
27398 Turns on or off display of @value{GDBN} Fortran array slicing
27399 debugging info. The default is off.
27400
27401 @item show debug fortran-array-slicing
27402 Displays the current state of displaying @value{GDBN} Fortran array
27403 slicing debugging info.
27404
27405 @item set debug frame
27406 @cindex frame debugging info
27407 Turns on or off display of @value{GDBN} frame debugging info. The
27408 default is off.
27409 @item show debug frame
27410 Displays the current state of displaying @value{GDBN} frame debugging
27411 info.
27412
27413 @item set debug gnu-nat
27414 @cindex @sc{gnu}/Hurd debug messages
27415 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
27416 @item show debug gnu-nat
27417 Show the current state of @sc{gnu}/Hurd debugging messages.
27418
27419 @item set debug infrun
27420 @cindex inferior debugging info
27421 Turns on or off display of @value{GDBN} debugging info for running the inferior.
27422 The default is off. @file{infrun.c} contains GDB's runtime state machine used
27423 for implementing operations such as single-stepping the inferior.
27424 @item show debug infrun
27425 Displays the current state of @value{GDBN} inferior debugging.
27426
27427 @item set debug jit
27428 @cindex just-in-time compilation, debugging messages
27429 Turn on or off debugging messages from JIT debug support.
27430 @item show debug jit
27431 Displays the current state of @value{GDBN} JIT debugging.
27432
27433 @item set debug linux-nat @r{[}on@r{|}off@r{]}
27434 @cindex @sc{gnu}/Linux native target debug messages
27435 @cindex Linux native targets
27436 Turn on or off debugging messages from the Linux native target debug support.
27437 @item show debug linux-nat
27438 Show the current state of Linux native target debugging messages.
27439
27440 @item set debug linux-namespaces
27441 @cindex @sc{gnu}/Linux namespaces debug messages
27442 Turn on or off debugging messages from the Linux namespaces debug support.
27443 @item show debug linux-namespaces
27444 Show the current state of Linux namespaces debugging messages.
27445
27446 @item set debug mach-o
27447 @cindex Mach-O symbols processing
27448 Control display of debugging messages related to Mach-O symbols
27449 processing. The default is off.
27450 @item show debug mach-o
27451 Displays the current state of displaying debugging messages related to
27452 reading of COFF/PE exported symbols.
27453
27454 @item set debug notification
27455 @cindex remote async notification debugging info
27456 Turn on or off debugging messages about remote async notification.
27457 The default is off.
27458 @item show debug notification
27459 Displays the current state of remote async notification debugging messages.
27460
27461 @item set debug observer
27462 @cindex observer debugging info
27463 Turns on or off display of @value{GDBN} observer debugging. This
27464 includes info such as the notification of observable events.
27465 @item show debug observer
27466 Displays the current state of observer debugging.
27467
27468 @item set debug overload
27469 @cindex C@t{++} overload debugging info
27470 Turns on or off display of @value{GDBN} C@t{++} overload debugging
27471 info. This includes info such as ranking of functions, etc. The default
27472 is off.
27473 @item show debug overload
27474 Displays the current state of displaying @value{GDBN} C@t{++} overload
27475 debugging info.
27476
27477 @cindex expression parser, debugging info
27478 @cindex debug expression parser
27479 @item set debug parser
27480 Turns on or off the display of expression parser debugging output.
27481 Internally, this sets the @code{yydebug} variable in the expression
27482 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
27483 details. The default is off.
27484 @item show debug parser
27485 Show the current state of expression parser debugging.
27486
27487 @cindex packets, reporting on stdout
27488 @cindex serial connections, debugging
27489 @cindex debug remote protocol
27490 @cindex remote protocol debugging
27491 @cindex display remote packets
27492 @item set debug remote
27493 Turns on or off display of reports on all packets sent back and forth across
27494 the serial line to the remote machine. The info is printed on the
27495 @value{GDBN} standard output stream. The default is off.
27496 @item show debug remote
27497 Displays the state of display of remote packets.
27498
27499 @item set debug remote-packet-max-chars
27500 Sets the maximum number of characters to display for each remote packet when
27501 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
27502 displaying lengthy remote packets and polluting the console.
27503
27504 The default value is @code{512}, which means @value{GDBN} will truncate each
27505 remote packet after 512 bytes.
27506
27507 Setting this option to @code{unlimited} will disable truncation and will output
27508 the full length of the remote packets.
27509 @item show debug remote-packet-max-chars
27510 Displays the number of bytes to output for remote packet debugging.
27511
27512 @item set debug separate-debug-file
27513 Turns on or off display of debug output about separate debug file search.
27514 @item show debug separate-debug-file
27515 Displays the state of separate debug file search debug output.
27516
27517 @item set debug serial
27518 Turns on or off display of @value{GDBN} serial debugging info. The
27519 default is off.
27520 @item show debug serial
27521 Displays the current state of displaying @value{GDBN} serial debugging
27522 info.
27523
27524 @item set debug solib-frv
27525 @cindex FR-V shared-library debugging
27526 Turn on or off debugging messages for FR-V shared-library code.
27527 @item show debug solib-frv
27528 Display the current state of FR-V shared-library code debugging
27529 messages.
27530
27531 @item set debug symbol-lookup
27532 @cindex symbol lookup
27533 Turns on or off display of debugging messages related to symbol lookup.
27534 The default is 0 (off).
27535 A value of 1 provides basic information.
27536 A value greater than 1 provides more verbose information.
27537 @item show debug symbol-lookup
27538 Show the current state of symbol lookup debugging messages.
27539
27540 @item set debug symfile
27541 @cindex symbol file functions
27542 Turns on or off display of debugging messages related to symbol file functions.
27543 The default is off. @xref{Files}.
27544 @item show debug symfile
27545 Show the current state of symbol file debugging messages.
27546
27547 @item set debug symtab-create
27548 @cindex symbol table creation
27549 Turns on or off display of debugging messages related to symbol table creation.
27550 The default is 0 (off).
27551 A value of 1 provides basic information.
27552 A value greater than 1 provides more verbose information.
27553 @item show debug symtab-create
27554 Show the current state of symbol table creation debugging.
27555
27556 @item set debug target
27557 @cindex target debugging info
27558 Turns on or off display of @value{GDBN} target debugging info. This info
27559 includes what is going on at the target level of GDB, as it happens. The
27560 default is 0. Set it to 1 to track events, and to 2 to also track the
27561 value of large memory transfers.
27562 @item show debug target
27563 Displays the current state of displaying @value{GDBN} target debugging
27564 info.
27565
27566 @item set debug timestamp
27567 @cindex timestamping debugging info
27568 Turns on or off display of timestamps with @value{GDBN} debugging info.
27569 When enabled, seconds and microseconds are displayed before each debugging
27570 message.
27571 @item show debug timestamp
27572 Displays the current state of displaying timestamps with @value{GDBN}
27573 debugging info.
27574
27575 @item set debug varobj
27576 @cindex variable object debugging info
27577 Turns on or off display of @value{GDBN} variable object debugging
27578 info. The default is off.
27579 @item show debug varobj
27580 Displays the current state of displaying @value{GDBN} variable object
27581 debugging info.
27582
27583 @item set debug xml
27584 @cindex XML parser debugging
27585 Turn on or off debugging messages for built-in XML parsers.
27586 @item show debug xml
27587 Displays the current state of XML debugging messages.
27588 @end table
27589
27590 @node Other Misc Settings
27591 @section Other Miscellaneous Settings
27592 @cindex miscellaneous settings
27593
27594 @table @code
27595 @kindex set interactive-mode
27596 @item set interactive-mode
27597 If @code{on}, forces @value{GDBN} to assume that GDB was started
27598 in a terminal. In practice, this means that @value{GDBN} should wait
27599 for the user to answer queries generated by commands entered at
27600 the command prompt. If @code{off}, forces @value{GDBN} to operate
27601 in the opposite mode, and it uses the default answers to all queries.
27602 If @code{auto} (the default), @value{GDBN} tries to determine whether
27603 its standard input is a terminal, and works in interactive-mode if it
27604 is, non-interactively otherwise.
27605
27606 In the vast majority of cases, the debugger should be able to guess
27607 correctly which mode should be used. But this setting can be useful
27608 in certain specific cases, such as running a MinGW @value{GDBN}
27609 inside a cygwin window.
27610
27611 @kindex show interactive-mode
27612 @item show interactive-mode
27613 Displays whether the debugger is operating in interactive mode or not.
27614 @end table
27615
27616 @table @code
27617 @kindex set suppress-cli-notifications
27618 @item set suppress-cli-notifications
27619 If @code{on}, command-line-interface (CLI) notifications that are
27620 printed by @value{GDBN} are suppressed. If @code{off}, the
27621 notifications are printed as usual. The default value is @code{off}.
27622 CLI notifications occur when you change the selected context or when
27623 the program being debugged stops, as detailed below.
27624
27625 @table @emph
27626 @item User-selected context changes:
27627 When you change the selected context (i.e.@: the current inferior,
27628 thread and/or the frame), @value{GDBN} prints information about the
27629 new context. For example, the default behavior is below:
27630
27631 @smallexample
27632 (gdb) inferior 1
27633 [Switching to inferior 1 [process 634] (/tmp/test)]
27634 [Switching to thread 1 (process 634)]
27635 #0 main () at test.c:3
27636 3 return 0;
27637 (gdb)
27638 @end smallexample
27639
27640 When the notifications are suppressed, the new context is not printed:
27641
27642 @smallexample
27643 (gdb) set suppress-cli-notifications on
27644 (gdb) inferior 1
27645 (gdb)
27646 @end smallexample
27647
27648 @item The program being debugged stops:
27649 When the program you are debugging stops (e.g.@: because of hitting a
27650 breakpoint, completing source-stepping, an interrupt, etc.),
27651 @value{GDBN} prints information about the stop event. For example,
27652 below is a breakpoint hit:
27653
27654 @smallexample
27655 (gdb) break test.c:3
27656 Breakpoint 2 at 0x555555555155: file test.c, line 3.
27657 (gdb) continue
27658 Continuing.
27659
27660 Breakpoint 2, main () at test.c:3
27661 3 return 0;
27662 (gdb)
27663 @end smallexample
27664
27665 When the notifications are suppressed, the output becomes:
27666
27667 @smallexample
27668 (gdb) break test.c:3
27669 Breakpoint 2 at 0x555555555155: file test.c, line 3.
27670 (gdb) set suppress-cli-notifications on
27671 (gdb) continue
27672 Continuing.
27673 (gdb)
27674 @end smallexample
27675
27676 Suppressing CLI notifications may be useful in scripts to obtain a
27677 reduced output from a list of commands.
27678 @end table
27679
27680 @kindex show suppress-cli-notifications
27681 @item show suppress-cli-notifications
27682 Displays whether printing CLI notifications is suppressed or not.
27683 @end table
27684
27685 @node Extending GDB
27686 @chapter Extending @value{GDBN}
27687 @cindex extending GDB
27688
27689 @value{GDBN} provides several mechanisms for extension.
27690 @value{GDBN} also provides the ability to automatically load
27691 extensions when it reads a file for debugging. This allows the
27692 user to automatically customize @value{GDBN} for the program
27693 being debugged.
27694
27695 To facilitate the use of extension languages, @value{GDBN} is capable
27696 of evaluating the contents of a file. When doing so, @value{GDBN}
27697 can recognize which extension language is being used by looking at
27698 the filename extension. Files with an unrecognized filename extension
27699 are always treated as a @value{GDBN} Command Files.
27700 @xref{Command Files,, Command files}.
27701
27702 You can control how @value{GDBN} evaluates these files with the following
27703 setting:
27704
27705 @table @code
27706 @kindex set script-extension
27707 @kindex show script-extension
27708 @item set script-extension off
27709 All scripts are always evaluated as @value{GDBN} Command Files.
27710
27711 @item set script-extension soft
27712 The debugger determines the scripting language based on filename
27713 extension. If this scripting language is supported, @value{GDBN}
27714 evaluates the script using that language. Otherwise, it evaluates
27715 the file as a @value{GDBN} Command File.
27716
27717 @item set script-extension strict
27718 The debugger determines the scripting language based on filename
27719 extension, and evaluates the script using that language. If the
27720 language is not supported, then the evaluation fails.
27721
27722 @item show script-extension
27723 Display the current value of the @code{script-extension} option.
27724
27725 @end table
27726
27727 @ifset SYSTEM_GDBINIT_DIR
27728 This setting is not used for files in the system-wide gdbinit directory.
27729 Files in that directory must have an extension matching their language,
27730 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
27731 commands. @xref{Startup}.
27732 @end ifset
27733
27734 @menu
27735 * Sequences:: Canned Sequences of @value{GDBN} Commands
27736 * Aliases:: Command Aliases
27737 * Python:: Extending @value{GDBN} using Python
27738 * Guile:: Extending @value{GDBN} using Guile
27739 * Auto-loading extensions:: Automatically loading extensions
27740 * Multiple Extension Languages:: Working with multiple extension languages
27741 @end menu
27742
27743 @node Sequences
27744 @section Canned Sequences of Commands
27745
27746 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
27747 Command Lists}), @value{GDBN} provides two ways to store sequences of
27748 commands for execution as a unit: user-defined commands and command
27749 files.
27750
27751 @menu
27752 * Define:: How to define your own commands
27753 * Hooks:: Hooks for user-defined commands
27754 * Command Files:: How to write scripts of commands to be stored in a file
27755 * Output:: Commands for controlled output
27756 * Auto-loading sequences:: Controlling auto-loaded command files
27757 @end menu
27758
27759 @node Define
27760 @subsection User-defined Commands
27761
27762 @cindex user-defined command
27763 @cindex arguments, to user-defined commands
27764 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
27765 which you assign a new name as a command. This is done with the
27766 @code{define} command. User commands may accept an unlimited number of arguments
27767 separated by whitespace. Arguments are accessed within the user command
27768 via @code{$arg0@dots{}$argN}. A trivial example:
27769
27770 @smallexample
27771 define adder
27772 print $arg0 + $arg1 + $arg2
27773 end
27774 @end smallexample
27775
27776 @noindent
27777 To execute the command use:
27778
27779 @smallexample
27780 adder 1 2 3
27781 @end smallexample
27782
27783 @noindent
27784 This defines the command @code{adder}, which prints the sum of
27785 its three arguments. Note the arguments are text substitutions, so they may
27786 reference variables, use complex expressions, or even perform inferior
27787 functions calls.
27788
27789 @cindex argument count in user-defined commands
27790 @cindex how many arguments (user-defined commands)
27791 In addition, @code{$argc} may be used to find out how many arguments have
27792 been passed.
27793
27794 @smallexample
27795 define adder
27796 if $argc == 2
27797 print $arg0 + $arg1
27798 end
27799 if $argc == 3
27800 print $arg0 + $arg1 + $arg2
27801 end
27802 end
27803 @end smallexample
27804
27805 Combining with the @code{eval} command (@pxref{eval}) makes it easier
27806 to process a variable number of arguments:
27807
27808 @smallexample
27809 define adder
27810 set $i = 0
27811 set $sum = 0
27812 while $i < $argc
27813 eval "set $sum = $sum + $arg%d", $i
27814 set $i = $i + 1
27815 end
27816 print $sum
27817 end
27818 @end smallexample
27819
27820 @table @code
27821
27822 @kindex define
27823 @item define @var{commandname}
27824 Define a command named @var{commandname}. If there is already a command
27825 by that name, you are asked to confirm that you want to redefine it.
27826 The argument @var{commandname} may be a bare command name consisting of letters,
27827 numbers, dashes, dots, and underscores. It may also start with any
27828 predefined or user-defined prefix command.
27829 For example, @samp{define target my-target} creates
27830 a user-defined @samp{target my-target} command.
27831
27832 The definition of the command is made up of other @value{GDBN} command lines,
27833 which are given following the @code{define} command. The end of these
27834 commands is marked by a line containing @code{end}.
27835
27836 @kindex document
27837 @kindex end@r{ (user-defined commands)}
27838 @item document @var{commandname}
27839 Document the user-defined command @var{commandname}, so that it can be
27840 accessed by @code{help}. The command @var{commandname} must already be
27841 defined. This command reads lines of documentation just as @code{define}
27842 reads the lines of the command definition, ending with @code{end}.
27843 After the @code{document} command is finished, @code{help} on command
27844 @var{commandname} displays the documentation you have written.
27845
27846 You may use the @code{document} command again to change the
27847 documentation of a command. Redefining the command with @code{define}
27848 does not change the documentation.
27849
27850 @kindex define-prefix
27851 @item define-prefix @var{commandname}
27852 Define or mark the command @var{commandname} as a user-defined prefix
27853 command. Once marked, @var{commandname} can be used as prefix command
27854 by the @code{define} command.
27855 Note that @code{define-prefix} can be used with a not yet defined
27856 @var{commandname}. In such a case, @var{commandname} is defined as
27857 an empty user-defined command.
27858 In case you redefine a command that was marked as a user-defined
27859 prefix command, the subcommands of the redefined command are kept
27860 (and @value{GDBN} indicates so to the user).
27861
27862 Example:
27863 @example
27864 (gdb) define-prefix abc
27865 (gdb) define-prefix abc def
27866 (gdb) define abc def
27867 Type commands for definition of "abc def".
27868 End with a line saying just "end".
27869 >echo command initial def\n
27870 >end
27871 (gdb) define abc def ghi
27872 Type commands for definition of "abc def ghi".
27873 End with a line saying just "end".
27874 >echo command ghi\n
27875 >end
27876 (gdb) define abc def
27877 Keeping subcommands of prefix command "def".
27878 Redefine command "def"? (y or n) y
27879 Type commands for definition of "abc def".
27880 End with a line saying just "end".
27881 >echo command def\n
27882 >end
27883 (gdb) abc def ghi
27884 command ghi
27885 (gdb) abc def
27886 command def
27887 (gdb)
27888 @end example
27889
27890 @kindex dont-repeat
27891 @cindex don't repeat command
27892 @item dont-repeat
27893 Used inside a user-defined command, this tells @value{GDBN} that this
27894 command should not be repeated when the user hits @key{RET}
27895 (@pxref{Command Syntax, repeat last command}).
27896
27897 @kindex help user-defined
27898 @item help user-defined
27899 List all user-defined commands and all python commands defined in class
27900 COMMAND_USER. The first line of the documentation or docstring is
27901 included (if any).
27902
27903 @kindex show user
27904 @item show user
27905 @itemx show user @var{commandname}
27906 Display the @value{GDBN} commands used to define @var{commandname} (but
27907 not its documentation). If no @var{commandname} is given, display the
27908 definitions for all user-defined commands.
27909 This does not work for user-defined python commands.
27910
27911 @cindex infinite recursion in user-defined commands
27912 @kindex show max-user-call-depth
27913 @kindex set max-user-call-depth
27914 @item show max-user-call-depth
27915 @itemx set max-user-call-depth
27916 The value of @code{max-user-call-depth} controls how many recursion
27917 levels are allowed in user-defined commands before @value{GDBN} suspects an
27918 infinite recursion and aborts the command.
27919 This does not apply to user-defined python commands.
27920 @end table
27921
27922 In addition to the above commands, user-defined commands frequently
27923 use control flow commands, described in @ref{Command Files}.
27924
27925 When user-defined commands are executed, the
27926 commands of the definition are not printed. An error in any command
27927 stops execution of the user-defined command.
27928
27929 If used interactively, commands that would ask for confirmation proceed
27930 without asking when used inside a user-defined command. Many @value{GDBN}
27931 commands that normally print messages to say what they are doing omit the
27932 messages when used in a user-defined command.
27933
27934 @node Hooks
27935 @subsection User-defined Command Hooks
27936 @cindex command hooks
27937 @cindex hooks, for commands
27938 @cindex hooks, pre-command
27939
27940 @kindex hook
27941 You may define @dfn{hooks}, which are a special kind of user-defined
27942 command. Whenever you run the command @samp{foo}, if the user-defined
27943 command @samp{hook-foo} exists, it is executed (with no arguments)
27944 before that command.
27945
27946 @cindex hooks, post-command
27947 @kindex hookpost
27948 A hook may also be defined which is run after the command you executed.
27949 Whenever you run the command @samp{foo}, if the user-defined command
27950 @samp{hookpost-foo} exists, it is executed (with no arguments) after
27951 that command. Post-execution hooks may exist simultaneously with
27952 pre-execution hooks, for the same command.
27953
27954 It is valid for a hook to call the command which it hooks. If this
27955 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
27956
27957 @c It would be nice if hookpost could be passed a parameter indicating
27958 @c if the command it hooks executed properly or not. FIXME!
27959
27960 @kindex stop@r{, a pseudo-command}
27961 In addition, a pseudo-command, @samp{stop} exists. Defining
27962 (@samp{hook-stop}) makes the associated commands execute every time
27963 execution stops in your program: before breakpoint commands are run,
27964 displays are printed, or the stack frame is printed.
27965
27966 For example, to ignore @code{SIGALRM} signals while
27967 single-stepping, but treat them normally during normal execution,
27968 you could define:
27969
27970 @smallexample
27971 define hook-stop
27972 handle SIGALRM nopass
27973 end
27974
27975 define hook-run
27976 handle SIGALRM pass
27977 end
27978
27979 define hook-continue
27980 handle SIGALRM pass
27981 end
27982 @end smallexample
27983
27984 As a further example, to hook at the beginning and end of the @code{echo}
27985 command, and to add extra text to the beginning and end of the message,
27986 you could define:
27987
27988 @smallexample
27989 define hook-echo
27990 echo <<<---
27991 end
27992
27993 define hookpost-echo
27994 echo --->>>\n
27995 end
27996
27997 (@value{GDBP}) echo Hello World
27998 <<<---Hello World--->>>
27999 (@value{GDBP})
28000
28001 @end smallexample
28002
28003 You can define a hook for any single-word command in @value{GDBN}, but
28004 not for command aliases; you should define a hook for the basic command
28005 name, e.g.@: @code{backtrace} rather than @code{bt}.
28006 @c FIXME! So how does Joe User discover whether a command is an alias
28007 @c or not?
28008 You can hook a multi-word command by adding @code{hook-} or
28009 @code{hookpost-} to the last word of the command, e.g.@:
28010 @samp{define target hook-remote} to add a hook to @samp{target remote}.
28011
28012 If an error occurs during the execution of your hook, execution of
28013 @value{GDBN} commands stops and @value{GDBN} issues a prompt
28014 (before the command that you actually typed had a chance to run).
28015
28016 If you try to define a hook which does not match any known command, you
28017 get a warning from the @code{define} command.
28018
28019 @node Command Files
28020 @subsection Command Files
28021
28022 @cindex command files
28023 @cindex scripting commands
28024 A command file for @value{GDBN} is a text file made of lines that are
28025 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
28026 also be included. An empty line in a command file does nothing; it
28027 does not mean to repeat the last command, as it would from the
28028 terminal.
28029
28030 You can request the execution of a command file with the @code{source}
28031 command. Note that the @code{source} command is also used to evaluate
28032 scripts that are not Command Files. The exact behavior can be configured
28033 using the @code{script-extension} setting.
28034 @xref{Extending GDB,, Extending GDB}.
28035
28036 @table @code
28037 @kindex source
28038 @cindex execute commands from a file
28039 @item source [-s] [-v] @var{filename}
28040 Execute the command file @var{filename}.
28041 @end table
28042
28043 The lines in a command file are generally executed sequentially,
28044 unless the order of execution is changed by one of the
28045 @emph{flow-control commands} described below. The commands are not
28046 printed as they are executed. An error in any command terminates
28047 execution of the command file and control is returned to the console.
28048
28049 @value{GDBN} first searches for @var{filename} in the current directory.
28050 If the file is not found there, and @var{filename} does not specify a
28051 directory, then @value{GDBN} also looks for the file on the source search path
28052 (specified with the @samp{directory} command);
28053 except that @file{$cdir} is not searched because the compilation directory
28054 is not relevant to scripts.
28055
28056 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
28057 on the search path even if @var{filename} specifies a directory.
28058 The search is done by appending @var{filename} to each element of the
28059 search path. So, for example, if @var{filename} is @file{mylib/myscript}
28060 and the search path contains @file{/home/user} then @value{GDBN} will
28061 look for the script @file{/home/user/mylib/myscript}.
28062 The search is also done if @var{filename} is an absolute path.
28063 For example, if @var{filename} is @file{/tmp/myscript} and
28064 the search path contains @file{/home/user} then @value{GDBN} will
28065 look for the script @file{/home/user/tmp/myscript}.
28066 For DOS-like systems, if @var{filename} contains a drive specification,
28067 it is stripped before concatenation. For example, if @var{filename} is
28068 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
28069 will look for the script @file{c:/tmp/myscript}.
28070
28071 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
28072 each command as it is executed. The option must be given before
28073 @var{filename}, and is interpreted as part of the filename anywhere else.
28074
28075 Commands that would ask for confirmation if used interactively proceed
28076 without asking when used in a command file. Many @value{GDBN} commands that
28077 normally print messages to say what they are doing omit the messages
28078 when called from command files.
28079
28080 @value{GDBN} also accepts command input from standard input. In this
28081 mode, normal output goes to standard output and error output goes to
28082 standard error. Errors in a command file supplied on standard input do
28083 not terminate execution of the command file---execution continues with
28084 the next command.
28085
28086 @smallexample
28087 gdb < cmds > log 2>&1
28088 @end smallexample
28089
28090 (The syntax above will vary depending on the shell used.) This example
28091 will execute commands from the file @file{cmds}. All output and errors
28092 would be directed to @file{log}.
28093
28094 Since commands stored on command files tend to be more general than
28095 commands typed interactively, they frequently need to deal with
28096 complicated situations, such as different or unexpected values of
28097 variables and symbols, changes in how the program being debugged is
28098 built, etc. @value{GDBN} provides a set of flow-control commands to
28099 deal with these complexities. Using these commands, you can write
28100 complex scripts that loop over data structures, execute commands
28101 conditionally, etc.
28102
28103 @table @code
28104 @kindex if
28105 @kindex else
28106 @item if
28107 @itemx else
28108 This command allows to include in your script conditionally executed
28109 commands. The @code{if} command takes a single argument, which is an
28110 expression to evaluate. It is followed by a series of commands that
28111 are executed only if the expression is true (its value is nonzero).
28112 There can then optionally be an @code{else} line, followed by a series
28113 of commands that are only executed if the expression was false. The
28114 end of the list is marked by a line containing @code{end}.
28115
28116 @kindex while
28117 @item while
28118 This command allows to write loops. Its syntax is similar to
28119 @code{if}: the command takes a single argument, which is an expression
28120 to evaluate, and must be followed by the commands to execute, one per
28121 line, terminated by an @code{end}. These commands are called the
28122 @dfn{body} of the loop. The commands in the body of @code{while} are
28123 executed repeatedly as long as the expression evaluates to true.
28124
28125 @kindex loop_break
28126 @item loop_break
28127 This command exits the @code{while} loop in whose body it is included.
28128 Execution of the script continues after that @code{while}s @code{end}
28129 line.
28130
28131 @kindex loop_continue
28132 @item loop_continue
28133 This command skips the execution of the rest of the body of commands
28134 in the @code{while} loop in whose body it is included. Execution
28135 branches to the beginning of the @code{while} loop, where it evaluates
28136 the controlling expression.
28137
28138 @kindex end@r{ (if/else/while commands)}
28139 @item end
28140 Terminate the block of commands that are the body of @code{if},
28141 @code{else}, or @code{while} flow-control commands.
28142 @end table
28143
28144
28145 @node Output
28146 @subsection Commands for Controlled Output
28147
28148 During the execution of a command file or a user-defined command, normal
28149 @value{GDBN} output is suppressed; the only output that appears is what is
28150 explicitly printed by the commands in the definition. This section
28151 describes three commands useful for generating exactly the output you
28152 want.
28153
28154 @table @code
28155 @kindex echo
28156 @item echo @var{text}
28157 @c I do not consider backslash-space a standard C escape sequence
28158 @c because it is not in ANSI.
28159 Print @var{text}. Nonprinting characters can be included in
28160 @var{text} using C escape sequences, such as @samp{\n} to print a
28161 newline. @strong{No newline is printed unless you specify one.}
28162 In addition to the standard C escape sequences, a backslash followed
28163 by a space stands for a space. This is useful for displaying a
28164 string with spaces at the beginning or the end, since leading and
28165 trailing spaces are otherwise trimmed from all arguments.
28166 To print @samp{@w{ }and foo =@w{ }}, use the command
28167 @samp{echo \@w{ }and foo = \@w{ }}.
28168
28169 A backslash at the end of @var{text} can be used, as in C, to continue
28170 the command onto subsequent lines. For example,
28171
28172 @smallexample
28173 echo This is some text\n\
28174 which is continued\n\
28175 onto several lines.\n
28176 @end smallexample
28177
28178 produces the same output as
28179
28180 @smallexample
28181 echo This is some text\n
28182 echo which is continued\n
28183 echo onto several lines.\n
28184 @end smallexample
28185
28186 @kindex output
28187 @item output @var{expression}
28188 Print the value of @var{expression} and nothing but that value: no
28189 newlines, no @samp{$@var{nn} = }. The value is not entered in the
28190 value history either. @xref{Expressions, ,Expressions}, for more information
28191 on expressions.
28192
28193 @item output/@var{fmt} @var{expression}
28194 Print the value of @var{expression} in format @var{fmt}. You can use
28195 the same formats as for @code{print}. @xref{Output Formats,,Output
28196 Formats}, for more information.
28197
28198 @kindex printf
28199 @item printf @var{template}, @var{expressions}@dots{}
28200 Print the values of one or more @var{expressions} under the control of
28201 the string @var{template}. To print several values, make
28202 @var{expressions} be a comma-separated list of individual expressions,
28203 which may be either numbers or pointers. Their values are printed as
28204 specified by @var{template}, exactly as a C program would do by
28205 executing the code below:
28206
28207 @smallexample
28208 printf (@var{template}, @var{expressions}@dots{});
28209 @end smallexample
28210
28211 As in @code{C} @code{printf}, ordinary characters in @var{template}
28212 are printed verbatim, while @dfn{conversion specification} introduced
28213 by the @samp{%} character cause subsequent @var{expressions} to be
28214 evaluated, their values converted and formatted according to type and
28215 style information encoded in the conversion specifications, and then
28216 printed.
28217
28218 For example, you can print two values in hex like this:
28219
28220 @smallexample
28221 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
28222 @end smallexample
28223
28224 @code{printf} supports all the standard @code{C} conversion
28225 specifications, including the flags and modifiers between the @samp{%}
28226 character and the conversion letter, with the following exceptions:
28227
28228 @itemize @bullet
28229 @item
28230 The argument-ordering modifiers, such as @samp{2$}, are not supported.
28231
28232 @item
28233 The modifier @samp{*} is not supported for specifying precision or
28234 width.
28235
28236 @item
28237 The @samp{'} flag (for separation of digits into groups according to
28238 @code{LC_NUMERIC'}) is not supported.
28239
28240 @item
28241 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
28242 supported.
28243
28244 @item
28245 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
28246
28247 @item
28248 The conversion letters @samp{a} and @samp{A} are not supported.
28249 @end itemize
28250
28251 @noindent
28252 Note that the @samp{ll} type modifier is supported only if the
28253 underlying @code{C} implementation used to build @value{GDBN} supports
28254 the @code{long long int} type, and the @samp{L} type modifier is
28255 supported only if @code{long double} type is available.
28256
28257 As in @code{C}, @code{printf} supports simple backslash-escape
28258 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
28259 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
28260 single character. Octal and hexadecimal escape sequences are not
28261 supported.
28262
28263 Additionally, @code{printf} supports conversion specifications for DFP
28264 (@dfn{Decimal Floating Point}) types using the following length modifiers
28265 together with a floating point specifier.
28266 letters:
28267
28268 @itemize @bullet
28269 @item
28270 @samp{H} for printing @code{Decimal32} types.
28271
28272 @item
28273 @samp{D} for printing @code{Decimal64} types.
28274
28275 @item
28276 @samp{DD} for printing @code{Decimal128} types.
28277 @end itemize
28278
28279 If the underlying @code{C} implementation used to build @value{GDBN} has
28280 support for the three length modifiers for DFP types, other modifiers
28281 such as width and precision will also be available for @value{GDBN} to use.
28282
28283 In case there is no such @code{C} support, no additional modifiers will be
28284 available and the value will be printed in the standard way.
28285
28286 Here's an example of printing DFP types using the above conversion letters:
28287 @smallexample
28288 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
28289 @end smallexample
28290
28291 @anchor{eval}
28292 @kindex eval
28293 @item eval @var{template}, @var{expressions}@dots{}
28294 Convert the values of one or more @var{expressions} under the control of
28295 the string @var{template} to a command line, and call it.
28296
28297 @end table
28298
28299 @node Auto-loading sequences
28300 @subsection Controlling auto-loading native @value{GDBN} scripts
28301 @cindex native script auto-loading
28302
28303 When a new object file is read (for example, due to the @code{file}
28304 command, or because the inferior has loaded a shared library),
28305 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
28306 @xref{Auto-loading extensions}.
28307
28308 Auto-loading can be enabled or disabled,
28309 and the list of auto-loaded scripts can be printed.
28310
28311 @table @code
28312 @anchor{set auto-load gdb-scripts}
28313 @kindex set auto-load gdb-scripts
28314 @item set auto-load gdb-scripts [on|off]
28315 Enable or disable the auto-loading of canned sequences of commands scripts.
28316
28317 @anchor{show auto-load gdb-scripts}
28318 @kindex show auto-load gdb-scripts
28319 @item show auto-load gdb-scripts
28320 Show whether auto-loading of canned sequences of commands scripts is enabled or
28321 disabled.
28322
28323 @anchor{info auto-load gdb-scripts}
28324 @kindex info auto-load gdb-scripts
28325 @cindex print list of auto-loaded canned sequences of commands scripts
28326 @item info auto-load gdb-scripts [@var{regexp}]
28327 Print the list of all canned sequences of commands scripts that @value{GDBN}
28328 auto-loaded.
28329 @end table
28330
28331 If @var{regexp} is supplied only canned sequences of commands scripts with
28332 matching names are printed.
28333
28334 @node Aliases
28335 @section Command Aliases
28336 @cindex aliases for commands
28337
28338 Aliases allow you to define alternate spellings for existing commands.
28339 For example, if a new @value{GDBN} command defined in Python
28340 (@pxref{Python}) has a long name, it is handy to have an abbreviated
28341 version of it that involves less typing.
28342
28343 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
28344 of the @samp{step} command even though it is otherwise an ambiguous
28345 abbreviation of other commands like @samp{set} and @samp{show}.
28346
28347 Aliases are also used to provide shortened or more common versions
28348 of multi-word commands. For example, @value{GDBN} provides the
28349 @samp{tty} alias of the @samp{set inferior-tty} command.
28350
28351 You can define a new alias with the @samp{alias} command.
28352
28353 @table @code
28354
28355 @kindex alias
28356 @item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
28357
28358 @end table
28359
28360 @var{alias} specifies the name of the new alias. Each word of
28361 @var{alias} must consist of letters, numbers, dashes and underscores.
28362
28363 @var{command} specifies the name of an existing command
28364 that is being aliased.
28365
28366 @var{command} can also be the name of an existing alias. In this
28367 case, @var{command} cannot be an alias that has default arguments.
28368
28369 The @samp{-a} option specifies that the new alias is an abbreviation
28370 of the command. Abbreviations are not used in command completion.
28371
28372 The @samp{--} option specifies the end of options,
28373 and is useful when @var{alias} begins with a dash.
28374
28375 You can specify @var{default-args} for your alias. These
28376 @var{default-args} will be automatically added before the alias
28377 arguments typed explicitly on the command line.
28378
28379 For example, the below defines an alias @code{btfullall} that shows all local
28380 variables and all frame arguments:
28381 @smallexample
28382 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
28383 @end smallexample
28384
28385 For more information about @var{default-args}, see @ref{Command
28386 aliases default args, ,Default Arguments}.
28387
28388 Here is a simple example showing how to make an abbreviation of a
28389 command so that there is less to type. Suppose you were tired of
28390 typing @samp{disas}, the current shortest unambiguous abbreviation of
28391 the @samp{disassemble} command and you wanted an even shorter version
28392 named @samp{di}. The following will accomplish this.
28393
28394 @smallexample
28395 (gdb) alias -a di = disas
28396 @end smallexample
28397
28398 Note that aliases are different from user-defined commands. With a
28399 user-defined command, you also need to write documentation for it with
28400 the @samp{document} command. An alias automatically picks up the
28401 documentation of the existing command.
28402
28403 Here is an example where we make @samp{elms} an abbreviation of
28404 @samp{elements} in the @samp{set print elements} command.
28405 This is to show that you can make an abbreviation of any part
28406 of a command.
28407
28408 @smallexample
28409 (gdb) alias -a set print elms = set print elements
28410 (gdb) alias -a show print elms = show print elements
28411 (gdb) set p elms 200
28412 (gdb) show p elms
28413 Limit on string chars or array elements to print is 200.
28414 @end smallexample
28415
28416 Note that if you are defining an alias of a @samp{set} command,
28417 and you want to have an alias for the corresponding @samp{show}
28418 command, then you need to define the latter separately.
28419
28420 Unambiguously abbreviated commands are allowed in @var{command} and
28421 @var{alias}, just as they are normally.
28422
28423 @smallexample
28424 (gdb) alias -a set pr elms = set p ele
28425 @end smallexample
28426
28427 Finally, here is an example showing the creation of a one word
28428 alias for a more complex command.
28429 This creates alias @samp{spe} of the command @samp{set print elements}.
28430
28431 @smallexample
28432 (gdb) alias spe = set print elements
28433 (gdb) spe 20
28434 @end smallexample
28435
28436 @menu
28437 * Command aliases default args:: Default arguments for aliases
28438 @end menu
28439
28440 @node Command aliases default args
28441 @subsection Default Arguments
28442 @cindex aliases for commands, default arguments
28443
28444 You can tell @value{GDBN} to always prepend some default arguments to
28445 the list of arguments provided explicitly by the user when using a
28446 user-defined alias.
28447
28448 If you repeatedly use the same arguments or options for a command, you
28449 can define an alias for this command and tell @value{GDBN} to
28450 automatically prepend these arguments or options to the list of
28451 arguments you type explicitly when using the alias@footnote{@value{GDBN}
28452 could easily accept default arguments for pre-defined commands and aliases,
28453 but it was deemed this would be confusing, and so is not allowed.}.
28454
28455 For example, if you often use the command @code{thread apply all}
28456 specifying to work on the threads in ascending order and to continue in case it
28457 encounters an error, you can tell @value{GDBN} to automatically preprend
28458 the @code{-ascending} and @code{-c} options by using:
28459
28460 @smallexample
28461 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
28462 @end smallexample
28463
28464 Once you have defined this alias with its default args, any time you type
28465 the @code{thread apply asc-all} followed by @code{some arguments},
28466 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
28467
28468 To have even less to type, you can also define a one word alias:
28469 @smallexample
28470 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
28471 @end smallexample
28472
28473 As usual, unambiguous abbreviations can be used for @var{alias}
28474 and @var{default-args}.
28475
28476 The different aliases of a command do not share their default args.
28477 For example, you define a new alias @code{bt_ALL} showing all possible
28478 information and another alias @code{bt_SMALL} showing very limited information
28479 using:
28480 @smallexample
28481 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
28482 -past-main -past-entry -full
28483 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
28484 -past-main off -past-entry off
28485 @end smallexample
28486
28487 (For more on using the @code{alias} command, see @ref{Aliases}.)
28488
28489 Default args are not limited to the arguments and options of @var{command},
28490 but can specify nested commands if @var{command} accepts such a nested command
28491 as argument.
28492 For example, the below defines @code{faalocalsoftype} that lists the
28493 frames having locals of a certain type, together with the matching
28494 local vars:
28495 @smallexample
28496 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
28497 (@value{GDBP}) faalocalsoftype int
28498 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
28499 i = 0
28500 ret = 21845
28501 @end smallexample
28502
28503 This is also very useful to define an alias for a set of nested @code{with}
28504 commands to have a particular combination of temporary settings. For example,
28505 the below defines the alias @code{pp10} that pretty prints an expression
28506 argument, with a maximum of 10 elements if the expression is a string or
28507 an array:
28508 @smallexample
28509 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
28510 @end smallexample
28511 This defines the alias @code{pp10} as being a sequence of 3 commands.
28512 The first part @code{with print pretty --} temporarily activates the setting
28513 @code{set print pretty}, then launches the command that follows the separator
28514 @code{--}.
28515 The command following the first part is also a @code{with} command that
28516 temporarily changes the setting @code{set print elements} to 10, then
28517 launches the command that follows the second separator @code{--}.
28518 The third part @code{print} is the command the @code{pp10} alias will launch,
28519 using the temporary values of the settings and the arguments explicitly given
28520 by the user.
28521 For more information about the @code{with} command usage,
28522 see @ref{Command Settings}.
28523
28524 @c Python docs live in a separate file.
28525 @include python.texi
28526
28527 @c Guile docs live in a separate file.
28528 @include guile.texi
28529
28530 @node Auto-loading extensions
28531 @section Auto-loading extensions
28532 @cindex auto-loading extensions
28533
28534 @value{GDBN} provides two mechanisms for automatically loading
28535 extensions when a new object file is read (for example, due to the
28536 @code{file} command, or because the inferior has loaded a shared
28537 library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
28538 file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
28539 @code{.debug_gdb_scripts} section of modern file formats like ELF
28540 (@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
28541 section}). For a discussion of the differences between these two
28542 approaches see @ref{Which flavor to choose?}.
28543
28544 The auto-loading feature is useful for supplying application-specific
28545 debugging commands and features.
28546
28547 Auto-loading can be enabled or disabled,
28548 and the list of auto-loaded scripts can be printed.
28549 See the @samp{auto-loading} section of each extension language
28550 for more information.
28551 For @value{GDBN} command files see @ref{Auto-loading sequences}.
28552 For Python files see @ref{Python Auto-loading}.
28553
28554 Note that loading of this script file also requires accordingly configured
28555 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28556
28557 @menu
28558 * objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
28559 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
28560 * Which flavor to choose?:: Choosing between these approaches
28561 @end menu
28562
28563 @node objfile-gdbdotext file
28564 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
28565 @cindex @file{@var{objfile}-gdb.gdb}
28566 @cindex @file{@var{objfile}-gdb.py}
28567 @cindex @file{@var{objfile}-gdb.scm}
28568
28569 When a new object file is read, @value{GDBN} looks for a file named
28570 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
28571 where @var{objfile} is the object file's name and
28572 where @var{ext} is the file extension for the extension language:
28573
28574 @table @code
28575 @item @file{@var{objfile}-gdb.gdb}
28576 GDB's own command language
28577 @item @file{@var{objfile}-gdb.py}
28578 Python
28579 @item @file{@var{objfile}-gdb.scm}
28580 Guile
28581 @end table
28582
28583 @var{script-name} is formed by ensuring that the file name of @var{objfile}
28584 is absolute, following all symlinks, and resolving @code{.} and @code{..}
28585 components, and appending the @file{-gdb.@var{ext}} suffix.
28586 If this file exists and is readable, @value{GDBN} will evaluate it as a
28587 script in the specified extension language.
28588
28589 If this file does not exist, then @value{GDBN} will look for
28590 @var{script-name} file in all of the directories as specified below.
28591 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
28592 directories is converted to a one-letter subdirectory, i.e.@:
28593 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
28594 filesystems disallow colons in file names.)
28595
28596 Note that loading of these files requires an accordingly configured
28597 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28598
28599 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
28600 scripts normally according to its @file{.exe} filename. But if no scripts are
28601 found @value{GDBN} also tries script filenames matching the object file without
28602 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
28603 is attempted on any platform. This makes the script filenames compatible
28604 between Unix and MS-Windows hosts.
28605
28606 @table @code
28607 @anchor{set auto-load scripts-directory}
28608 @kindex set auto-load scripts-directory
28609 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
28610 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
28611 may be delimited by the host platform path separator in use
28612 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
28613
28614 Each entry here needs to be covered also by the security setting
28615 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
28616
28617 @anchor{with-auto-load-dir}
28618 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
28619 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
28620 configuration option @option{--with-auto-load-dir}.
28621
28622 Any reference to @file{$debugdir} will get replaced by
28623 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
28624 reference to @file{$datadir} will get replaced by @var{data-directory} which is
28625 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
28626 @file{$datadir} must be placed as a directory component --- either alone or
28627 delimited by @file{/} or @file{\} directory separators, depending on the host
28628 platform.
28629
28630 The list of directories uses path separator (@samp{:} on GNU and Unix
28631 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
28632 to the @env{PATH} environment variable.
28633
28634 @anchor{show auto-load scripts-directory}
28635 @kindex show auto-load scripts-directory
28636 @item show auto-load scripts-directory
28637 Show @value{GDBN} auto-loaded scripts location.
28638
28639 @anchor{add-auto-load-scripts-directory}
28640 @kindex add-auto-load-scripts-directory
28641 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
28642 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
28643 Multiple entries may be delimited by the host platform path separator in use.
28644 @end table
28645
28646 @value{GDBN} does not track which files it has already auto-loaded this way.
28647 @value{GDBN} will load the associated script every time the corresponding
28648 @var{objfile} is opened.
28649 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
28650 is evaluated more than once.
28651
28652 @node dotdebug_gdb_scripts section
28653 @subsection The @code{.debug_gdb_scripts} section
28654 @cindex @code{.debug_gdb_scripts} section
28655
28656 For systems using file formats like ELF and COFF,
28657 when @value{GDBN} loads a new object file
28658 it will look for a special section named @code{.debug_gdb_scripts}.
28659 If this section exists, its contents is a list of null-terminated entries
28660 specifying scripts to load. Each entry begins with a non-null prefix byte that
28661 specifies the kind of entry, typically the extension language and whether the
28662 script is in a file or inlined in @code{.debug_gdb_scripts}.
28663
28664 The following entries are supported:
28665
28666 @table @code
28667 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
28668 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
28669 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
28670 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
28671 @end table
28672
28673 @subsubsection Script File Entries
28674
28675 If the entry specifies a file, @value{GDBN} will look for the file first
28676 in the current directory and then along the source search path
28677 (@pxref{Source Path, ,Specifying Source Directories}),
28678 except that @file{$cdir} is not searched, since the compilation
28679 directory is not relevant to scripts.
28680
28681 File entries can be placed in section @code{.debug_gdb_scripts} with,
28682 for example, this GCC macro for Python scripts.
28683
28684 @example
28685 /* Note: The "MS" section flags are to remove duplicates. */
28686 #define DEFINE_GDB_PY_SCRIPT(script_name) \
28687 asm("\
28688 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
28689 .byte 1 /* Python */\n\
28690 .asciz \"" script_name "\"\n\
28691 .popsection \n\
28692 ");
28693 @end example
28694
28695 @noindent
28696 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
28697 Then one can reference the macro in a header or source file like this:
28698
28699 @example
28700 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
28701 @end example
28702
28703 The script name may include directories if desired.
28704
28705 Note that loading of this script file also requires accordingly configured
28706 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28707
28708 If the macro invocation is put in a header, any application or library
28709 using this header will get a reference to the specified script,
28710 and with the use of @code{"MS"} attributes on the section, the linker
28711 will remove duplicates.
28712
28713 @subsubsection Script Text Entries
28714
28715 Script text entries allow to put the executable script in the entry
28716 itself instead of loading it from a file.
28717 The first line of the entry, everything after the prefix byte and up to
28718 the first newline (@code{0xa}) character, is the script name, and must not
28719 contain any kind of space character, e.g., spaces or tabs.
28720 The rest of the entry, up to the trailing null byte, is the script to
28721 execute in the specified language. The name needs to be unique among
28722 all script names, as @value{GDBN} executes each script only once based
28723 on its name.
28724
28725 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
28726 testsuite.
28727
28728 @example
28729 #include "symcat.h"
28730 #include "gdb/section-scripts.h"
28731 asm(
28732 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
28733 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
28734 ".ascii \"gdb.inlined-script\\n\"\n"
28735 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
28736 ".ascii \" def __init__ (self):\\n\"\n"
28737 ".ascii \" super (test_cmd, self).__init__ ("
28738 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
28739 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
28740 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
28741 ".ascii \"test_cmd ()\\n\"\n"
28742 ".byte 0\n"
28743 ".popsection\n"
28744 );
28745 @end example
28746
28747 Loading of inlined scripts requires a properly configured
28748 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28749 The path to specify in @code{auto-load safe-path} is the path of the file
28750 containing the @code{.debug_gdb_scripts} section.
28751
28752 @node Which flavor to choose?
28753 @subsection Which flavor to choose?
28754
28755 Given the multiple ways of auto-loading extensions, it might not always
28756 be clear which one to choose. This section provides some guidance.
28757
28758 @noindent
28759 Benefits of the @file{-gdb.@var{ext}} way:
28760
28761 @itemize @bullet
28762 @item
28763 Can be used with file formats that don't support multiple sections.
28764
28765 @item
28766 Ease of finding scripts for public libraries.
28767
28768 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
28769 in the source search path.
28770 For publicly installed libraries, e.g., @file{libstdc++}, there typically
28771 isn't a source directory in which to find the script.
28772
28773 @item
28774 Doesn't require source code additions.
28775 @end itemize
28776
28777 @noindent
28778 Benefits of the @code{.debug_gdb_scripts} way:
28779
28780 @itemize @bullet
28781 @item
28782 Works with static linking.
28783
28784 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
28785 trigger their loading. When an application is statically linked the only
28786 objfile available is the executable, and it is cumbersome to attach all the
28787 scripts from all the input libraries to the executable's
28788 @file{-gdb.@var{ext}} script.
28789
28790 @item
28791 Works with classes that are entirely inlined.
28792
28793 Some classes can be entirely inlined, and thus there may not be an associated
28794 shared library to attach a @file{-gdb.@var{ext}} script to.
28795
28796 @item
28797 Scripts needn't be copied out of the source tree.
28798
28799 In some circumstances, apps can be built out of large collections of internal
28800 libraries, and the build infrastructure necessary to install the
28801 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
28802 cumbersome. It may be easier to specify the scripts in the
28803 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
28804 top of the source tree to the source search path.
28805 @end itemize
28806
28807 @node Multiple Extension Languages
28808 @section Multiple Extension Languages
28809
28810 The Guile and Python extension languages do not share any state,
28811 and generally do not interfere with each other.
28812 There are some things to be aware of, however.
28813
28814 @subsection Python comes first
28815
28816 Python was @value{GDBN}'s first extension language, and to avoid breaking
28817 existing behaviour Python comes first. This is generally solved by the
28818 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
28819 extension languages, and when it makes a call to an extension language,
28820 (say to pretty-print a value), it tries each in turn until an extension
28821 language indicates it has performed the request (e.g., has returned the
28822 pretty-printed form of a value).
28823 This extends to errors while performing such requests: If an error happens
28824 while, for example, trying to pretty-print an object then the error is
28825 reported and any following extension languages are not tried.
28826
28827 @node Interpreters
28828 @chapter Command Interpreters
28829 @cindex command interpreters
28830
28831 @value{GDBN} supports multiple command interpreters, and some command
28832 infrastructure to allow users or user interface writers to switch
28833 between interpreters or run commands in other interpreters.
28834
28835 @value{GDBN} currently supports two command interpreters, the console
28836 interpreter (sometimes called the command-line interpreter or @sc{cli})
28837 and the machine interface interpreter (or @sc{gdb/mi}). This manual
28838 describes both of these interfaces in great detail.
28839
28840 By default, @value{GDBN} will start with the console interpreter.
28841 However, the user may choose to start @value{GDBN} with another
28842 interpreter by specifying the @option{-i} or @option{--interpreter}
28843 startup options. Defined interpreters include:
28844
28845 @table @code
28846 @item console
28847 @cindex console interpreter
28848 The traditional console or command-line interpreter. This is the most often
28849 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
28850 @value{GDBN} will use this interpreter.
28851
28852 @item mi
28853 @cindex mi interpreter
28854 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
28855 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
28856 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
28857 Interface}.
28858
28859 @item mi3
28860 @cindex mi3 interpreter
28861 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
28862
28863 @item mi2
28864 @cindex mi2 interpreter
28865 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
28866
28867 @item mi1
28868 @cindex mi1 interpreter
28869 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
28870
28871 @end table
28872
28873 @cindex invoke another interpreter
28874
28875 @kindex interpreter-exec
28876 You may execute commands in any interpreter from the current
28877 interpreter using the appropriate command. If you are running the
28878 console interpreter, simply use the @code{interpreter-exec} command:
28879
28880 @smallexample
28881 interpreter-exec mi "-data-list-register-names"
28882 @end smallexample
28883
28884 @sc{gdb/mi} has a similar command, although it is only available in versions of
28885 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28886
28887 Note that @code{interpreter-exec} only changes the interpreter for the
28888 duration of the specified command. It does not change the interpreter
28889 permanently.
28890
28891 @cindex start a new independent interpreter
28892
28893 Although you may only choose a single interpreter at startup, it is
28894 possible to run an independent interpreter on a specified input/output
28895 device (usually a tty).
28896
28897 For example, consider a debugger GUI or IDE that wants to provide a
28898 @value{GDBN} console view. It may do so by embedding a terminal
28899 emulator widget in its GUI, starting @value{GDBN} in the traditional
28900 command-line mode with stdin/stdout/stderr redirected to that
28901 terminal, and then creating an MI interpreter running on a specified
28902 input/output device. The console interpreter created by @value{GDBN}
28903 at startup handles commands the user types in the terminal widget,
28904 while the GUI controls and synchronizes state with @value{GDBN} using
28905 the separate MI interpreter.
28906
28907 To start a new secondary @dfn{user interface} running MI, use the
28908 @code{new-ui} command:
28909
28910 @kindex new-ui
28911 @cindex new user interface
28912 @smallexample
28913 new-ui @var{interpreter} @var{tty}
28914 @end smallexample
28915
28916 The @var{interpreter} parameter specifies the interpreter to run.
28917 This accepts the same values as the @code{interpreter-exec} command.
28918 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28919 @var{tty} parameter specifies the name of the bidirectional file the
28920 interpreter uses for input/output, usually the name of a
28921 pseudoterminal slave on Unix systems. For example:
28922
28923 @smallexample
28924 (@value{GDBP}) new-ui mi /dev/pts/9
28925 @end smallexample
28926
28927 @noindent
28928 runs an MI interpreter on @file{/dev/pts/9}.
28929
28930 @node TUI
28931 @chapter @value{GDBN} Text User Interface
28932 @cindex TUI
28933 @cindex Text User Interface
28934
28935 The @value{GDBN} Text User Interface (TUI) is a terminal
28936 interface which uses the @code{curses} library to show the source
28937 file, the assembly output, the program registers and @value{GDBN}
28938 commands in separate text windows. The TUI mode is supported only
28939 on platforms where a suitable version of the @code{curses} library
28940 is available.
28941
28942 The TUI mode is enabled by default when you invoke @value{GDBN} as
28943 @samp{@value{GDBP} -tui}.
28944 You can also switch in and out of TUI mode while @value{GDBN} runs by
28945 using various TUI commands and key bindings, such as @command{tui
28946 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
28947 @ref{TUI Keys, ,TUI Key Bindings}.
28948
28949 @menu
28950 * TUI Overview:: TUI overview
28951 * TUI Keys:: TUI key bindings
28952 * TUI Single Key Mode:: TUI single key mode
28953 * TUI Mouse Support:: TUI mouse support
28954 * TUI Commands:: TUI-specific commands
28955 * TUI Configuration:: TUI configuration variables
28956 @end menu
28957
28958 @node TUI Overview
28959 @section TUI Overview
28960
28961 In TUI mode, @value{GDBN} can display several text windows:
28962
28963 @table @emph
28964 @item command
28965 This window is the @value{GDBN} command window with the @value{GDBN}
28966 prompt and the @value{GDBN} output. The @value{GDBN} input is still
28967 managed using readline.
28968
28969 @item source
28970 The source window shows the source file of the program. The current
28971 line and active breakpoints are displayed in this window.
28972
28973 @item assembly
28974 The assembly window shows the disassembly output of the program.
28975
28976 @item register
28977 This window shows the processor registers. Registers are highlighted
28978 when their values change.
28979 @end table
28980
28981 The source and assembly windows show the current program position
28982 by highlighting the current line and marking it with a @samp{>} marker.
28983 Breakpoints are indicated with two markers. The first marker
28984 indicates the breakpoint type:
28985
28986 @table @code
28987 @item B
28988 Breakpoint which was hit at least once.
28989
28990 @item b
28991 Breakpoint which was never hit.
28992
28993 @item H
28994 Hardware breakpoint which was hit at least once.
28995
28996 @item h
28997 Hardware breakpoint which was never hit.
28998 @end table
28999
29000 The second marker indicates whether the breakpoint is enabled or not:
29001
29002 @table @code
29003 @item +
29004 Breakpoint is enabled.
29005
29006 @item -
29007 Breakpoint is disabled.
29008 @end table
29009
29010 The source, assembly and register windows are updated when the current
29011 thread changes, when the frame changes, or when the program counter
29012 changes.
29013
29014 These windows are not all visible at the same time. The command
29015 window is always visible. The others can be arranged in several
29016 layouts:
29017
29018 @itemize @bullet
29019 @item
29020 source only,
29021
29022 @item
29023 assembly only,
29024
29025 @item
29026 source and assembly,
29027
29028 @item
29029 source and registers, or
29030
29031 @item
29032 assembly and registers.
29033 @end itemize
29034
29035 These are the standard layouts, but other layouts can be defined.
29036
29037 A status line above the command window shows the following information:
29038
29039 @table @emph
29040 @item target
29041 Indicates the current @value{GDBN} target.
29042 (@pxref{Targets, ,Specifying a Debugging Target}).
29043
29044 @item process
29045 Gives the current process or thread number.
29046 When no process is being debugged, this field is set to @code{No process}.
29047
29048 @item function
29049 Gives the current function name for the selected frame.
29050 The name is demangled if demangling is turned on (@pxref{Print Settings}).
29051 When there is no symbol corresponding to the current program counter,
29052 the string @code{??} is displayed.
29053
29054 @item line
29055 Indicates the current line number for the selected frame.
29056 When the current line number is not known, the string @code{??} is displayed.
29057
29058 @item pc
29059 Indicates the current program counter address.
29060 @end table
29061
29062 @node TUI Keys
29063 @section TUI Key Bindings
29064 @cindex TUI key bindings
29065
29066 The TUI installs several key bindings in the readline keymaps
29067 @ifset SYSTEM_READLINE
29068 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
29069 @end ifset
29070 @ifclear SYSTEM_READLINE
29071 (@pxref{Command Line Editing}).
29072 @end ifclear
29073 The following key bindings are installed for both TUI mode and the
29074 @value{GDBN} standard mode.
29075
29076 @table @kbd
29077 @kindex C-x C-a
29078 @item C-x C-a
29079 @kindex C-x a
29080 @itemx C-x a
29081 @kindex C-x A
29082 @itemx C-x A
29083 Enter or leave the TUI mode. When leaving the TUI mode,
29084 the curses window management stops and @value{GDBN} operates using
29085 its standard mode, writing on the terminal directly. When reentering
29086 the TUI mode, control is given back to the curses windows.
29087 The screen is then refreshed.
29088
29089 This key binding uses the bindable Readline function
29090 @code{tui-switch-mode}.
29091
29092 @kindex C-x 1
29093 @item C-x 1
29094 Use a TUI layout with only one window. The layout will
29095 either be @samp{source} or @samp{assembly}. When the TUI mode
29096 is not active, it will switch to the TUI mode.
29097
29098 Think of this key binding as the Emacs @kbd{C-x 1} binding.
29099
29100 This key binding uses the bindable Readline function
29101 @code{tui-delete-other-windows}.
29102
29103 @kindex C-x 2
29104 @item C-x 2
29105 Use a TUI layout with at least two windows. When the current
29106 layout already has two windows, the next layout with two windows is used.
29107 When a new layout is chosen, one window will always be common to the
29108 previous layout and the new one.
29109
29110 Think of it as the Emacs @kbd{C-x 2} binding.
29111
29112 This key binding uses the bindable Readline function
29113 @code{tui-change-windows}.
29114
29115 @kindex C-x o
29116 @item C-x o
29117 Change the active window. The TUI associates several key bindings
29118 (like scrolling and arrow keys) with the active window. This command
29119 gives the focus to the next TUI window.
29120
29121 Think of it as the Emacs @kbd{C-x o} binding.
29122
29123 This key binding uses the bindable Readline function
29124 @code{tui-other-window}.
29125
29126 @kindex C-x s
29127 @item C-x s
29128 Switch in and out of the TUI SingleKey mode that binds single
29129 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
29130
29131 This key binding uses the bindable Readline function
29132 @code{next-keymap}.
29133 @end table
29134
29135 The following key bindings only work in the TUI mode:
29136
29137 @table @asis
29138 @kindex PgUp
29139 @item @key{PgUp}
29140 Scroll the active window one page up.
29141
29142 @kindex PgDn
29143 @item @key{PgDn}
29144 Scroll the active window one page down.
29145
29146 @kindex Up
29147 @item @key{Up}
29148 Scroll the active window one line up.
29149
29150 @kindex Down
29151 @item @key{Down}
29152 Scroll the active window one line down.
29153
29154 @kindex Left
29155 @item @key{Left}
29156 Scroll the active window one column left.
29157
29158 @kindex Right
29159 @item @key{Right}
29160 Scroll the active window one column right.
29161
29162 @kindex C-L
29163 @item @kbd{C-L}
29164 Refresh the screen.
29165 @end table
29166
29167 Because the arrow keys scroll the active window in the TUI mode, they
29168 are not available for their normal use by readline unless the command
29169 window has the focus. When another window is active, you must use
29170 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
29171 and @kbd{C-f} to control the command window.
29172
29173 @node TUI Single Key Mode
29174 @section TUI Single Key Mode
29175 @cindex TUI single key mode
29176
29177 The TUI also provides a @dfn{SingleKey} mode, which binds several
29178 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
29179 switch into this mode, where the following key bindings are used:
29180
29181 @table @kbd
29182 @kindex c @r{(SingleKey TUI key)}
29183 @item c
29184 continue
29185
29186 @kindex d @r{(SingleKey TUI key)}
29187 @item d
29188 down
29189
29190 @kindex f @r{(SingleKey TUI key)}
29191 @item f
29192 finish
29193
29194 @kindex n @r{(SingleKey TUI key)}
29195 @item n
29196 next
29197
29198 @kindex o @r{(SingleKey TUI key)}
29199 @item o
29200 nexti. The shortcut letter @samp{o} stands for ``step Over''.
29201
29202 @kindex q @r{(SingleKey TUI key)}
29203 @item q
29204 exit the SingleKey mode.
29205
29206 @kindex r @r{(SingleKey TUI key)}
29207 @item r
29208 run
29209
29210 @kindex s @r{(SingleKey TUI key)}
29211 @item s
29212 step
29213
29214 @kindex i @r{(SingleKey TUI key)}
29215 @item i
29216 stepi. The shortcut letter @samp{i} stands for ``step Into''.
29217
29218 @kindex u @r{(SingleKey TUI key)}
29219 @item u
29220 up
29221
29222 @kindex v @r{(SingleKey TUI key)}
29223 @item v
29224 info locals
29225
29226 @kindex w @r{(SingleKey TUI key)}
29227 @item w
29228 where
29229 @end table
29230
29231 Other keys temporarily switch to the @value{GDBN} command prompt.
29232 The key that was pressed is inserted in the editing buffer so that
29233 it is possible to type most @value{GDBN} commands without interaction
29234 with the TUI SingleKey mode. Once the command is entered the TUI
29235 SingleKey mode is restored. The only way to permanently leave
29236 this mode is by typing @kbd{q} or @kbd{C-x s}.
29237
29238 @cindex SingleKey keymap name
29239 If @value{GDBN} was built with Readline 8.0 or later, the TUI
29240 SingleKey keymap will be named @samp{SingleKey}. This can be used in
29241 @file{.inputrc} to add additional bindings to this keymap.
29242
29243 @node TUI Mouse Support
29244 @section TUI Mouse Support
29245 @cindex TUI mouse support
29246
29247 If the curses library supports the mouse, the TUI supports mouse
29248 actions.
29249
29250 The mouse wheel scrolls the appropriate window under the mouse cursor.
29251
29252 The TUI itself does not directly support copying/pasting with the
29253 mouse. However, on Unix terminals, you can typically press and hold
29254 the @key{SHIFT} key on your keyboard to temporarily bypass
29255 @value{GDBN}'s TUI and access the terminal's native mouse copy/paste
29256 functionality (commonly, click-drag-release or double-click to select
29257 text, middle-click to paste). This copy/paste works with the
29258 terminal's selection buffer, as opposed to the TUI's buffer.
29259
29260 @node TUI Commands
29261 @section TUI-specific Commands
29262 @cindex TUI commands
29263
29264 The TUI has specific commands to control the text windows.
29265 These commands are always available, even when @value{GDBN} is not in
29266 the TUI mode. When @value{GDBN} is in the standard mode, most
29267 of these commands will automatically switch to the TUI mode.
29268
29269 Note that if @value{GDBN}'s @code{stdout} is not connected to a
29270 terminal, or @value{GDBN} has been started with the machine interface
29271 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
29272 these commands will fail with an error, because it would not be
29273 possible or desirable to enable curses window management.
29274
29275 @table @code
29276 @item tui enable
29277 @kindex tui enable
29278 Activate TUI mode. The last active TUI window layout will be used if
29279 TUI mode has previously been used in the current debugging session,
29280 otherwise a default layout is used.
29281
29282 @item tui disable
29283 @kindex tui disable
29284 Disable TUI mode, returning to the console interpreter.
29285
29286 @anchor{info_win_command}
29287 @item info win
29288 @kindex info win
29289 List the names and sizes of all currently displayed windows.
29290
29291 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
29292 @kindex tui new-layout
29293 Create a new TUI layout. The new layout will be named @var{name}, and
29294 can be accessed using the @code{layout} command (see below).
29295
29296 Each @var{window} parameter is either the name of a window to display,
29297 or a window description. The windows will be displayed from top to
29298 bottom in the order listed.
29299
29300 The names of the windows are the same as the ones given to the
29301 @code{focus} command (see below); additional, the @code{status}
29302 window can be specified. Note that, because it is of fixed height,
29303 the weight assigned to the status window is of no importance. It is
29304 conventional to use @samp{0} here.
29305
29306 A window description looks a bit like an invocation of @code{tui
29307 new-layout}, and is of the form
29308 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
29309
29310 This specifies a sub-layout. If @code{-horizontal} is given, the
29311 windows in this description will be arranged side-by-side, rather than
29312 top-to-bottom.
29313
29314 Each @var{weight} is an integer. It is the weight of this window
29315 relative to all the other windows in the layout. These numbers are
29316 used to calculate how much of the screen is given to each window.
29317
29318 For example:
29319
29320 @example
29321 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
29322 @end example
29323
29324 Here, the new layout is called @samp{example}. It shows the source
29325 and register windows, followed by the status window, and then finally
29326 the command window. The non-status windows all have the same weight,
29327 so the terminal will be split into three roughly equal sections.
29328
29329 Here is a more complex example, showing a horizontal layout:
29330
29331 @example
29332 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
29333 @end example
29334
29335 This will result in side-by-side source and assembly windows; with the
29336 status and command window being beneath these, filling the entire
29337 width of the terminal. Because they have weight 2, the source and
29338 assembly windows will be twice the height of the command window.
29339
29340 @kindex tui layout
29341 @kindex layout
29342 @item tui layout @var{name}
29343 @itemx layout @var{name}
29344 Changes which TUI windows are displayed. The @var{name} parameter
29345 controls which layout is shown. It can be either one of the built-in
29346 layout names, or the name of a layout defined by the user using
29347 @code{tui new-layout}.
29348
29349 The built-in layouts are as follows:
29350
29351 @table @code
29352 @item next
29353 Display the next layout.
29354
29355 @item prev
29356 Display the previous layout.
29357
29358 @item src
29359 Display the source and command windows.
29360
29361 @item asm
29362 Display the assembly and command windows.
29363
29364 @item split
29365 Display the source, assembly, and command windows.
29366
29367 @item regs
29368 When in @code{src} layout display the register, source, and command
29369 windows. When in @code{asm} or @code{split} layout display the
29370 register, assembler, and command windows.
29371 @end table
29372
29373 @kindex focus
29374 @item tui focus @var{name}
29375 @itemx focus @var{name}
29376 Changes which TUI window is currently active for scrolling. The
29377 @var{name} parameter can be any of the following:
29378
29379 @table @code
29380 @item next
29381 Make the next window active for scrolling.
29382
29383 @item prev
29384 Make the previous window active for scrolling.
29385
29386 @item src
29387 Make the source window active for scrolling.
29388
29389 @item asm
29390 Make the assembly window active for scrolling.
29391
29392 @item regs
29393 Make the register window active for scrolling.
29394
29395 @item cmd
29396 Make the command window active for scrolling.
29397 @end table
29398
29399 @kindex tui refresh
29400 @kindex refresh
29401 @item tui refresh
29402 @itemx refresh
29403 Refresh the screen. This is similar to typing @kbd{C-L}.
29404
29405 @item tui reg @var{group}
29406 @kindex tui reg
29407 Changes the register group displayed in the tui register window to
29408 @var{group}. If the register window is not currently displayed this
29409 command will cause the register window to be displayed. The list of
29410 register groups, as well as their order is target specific. The
29411 following groups are available on most targets:
29412 @table @code
29413 @item next
29414 Repeatedly selecting this group will cause the display to cycle
29415 through all of the available register groups.
29416
29417 @item prev
29418 Repeatedly selecting this group will cause the display to cycle
29419 through all of the available register groups in the reverse order to
29420 @var{next}.
29421
29422 @item general
29423 Display the general registers.
29424 @item float
29425 Display the floating point registers.
29426 @item system
29427 Display the system registers.
29428 @item vector
29429 Display the vector registers.
29430 @item all
29431 Display all registers.
29432 @end table
29433
29434 @item update
29435 @kindex update
29436 Update the source window and the current execution point.
29437
29438 @kindex tui window height
29439 @kindex winheight
29440 @item tui window height @var{name} +@var{count}
29441 @itemx tui window height @var{name} -@var{count}
29442 @itemx winheight @var{name} +@var{count}
29443 @itemx winheight @var{name} -@var{count}
29444 Change the height of the window @var{name} by @var{count} lines.
29445 Positive counts increase the height, while negative counts decrease
29446 it. The @var{name} parameter can be the name of any currently visible
29447 window. The names of the currently visible windows can be discovered
29448 using @kbd{info win} (@pxref{info_win_command,,info win}).
29449
29450 The set of currently visible windows must always fill the terminal,
29451 and so, it is only possible to resize on window if there are other
29452 visible windows that can either give or receive the extra terminal
29453 space.
29454
29455 @kindex tui window width
29456 @kindex winwidth
29457 @item tui window width @var{name} +@var{count}
29458 @itemx tui window width @var{name} -@var{count}
29459 @itemx winwidth @var{name} +@var{count}
29460 @itemx winwidth @var{name} -@var{count}
29461 Change the width of the window @var{name} by @var{count} columns.
29462 Positive counts increase the width, while negative counts decrease it.
29463 The @var{name} parameter can be the name of any currently visible
29464 window. The names of the currently visible windows can be discovered
29465 using @code{info win} (@pxref{info_win_command,,info win}).
29466
29467 The set of currently visible windows must always fill the terminal,
29468 and so, it is only possible to resize on window if there are other
29469 visible windows that can either give or receive the extra terminal
29470 space.
29471 @end table
29472
29473 @node TUI Configuration
29474 @section TUI Configuration Variables
29475 @cindex TUI configuration variables
29476
29477 Several configuration variables control the appearance of TUI windows.
29478
29479 @table @code
29480 @item set tui border-kind @var{kind}
29481 @kindex set tui border-kind
29482 Select the border appearance for the source, assembly and register windows.
29483 The possible values are the following:
29484 @table @code
29485 @item space
29486 Use a space character to draw the border.
29487
29488 @item ascii
29489 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
29490
29491 @item acs
29492 Use the Alternate Character Set to draw the border. The border is
29493 drawn using character line graphics if the terminal supports them.
29494 @end table
29495
29496 @item set tui border-mode @var{mode}
29497 @kindex set tui border-mode
29498 @itemx set tui active-border-mode @var{mode}
29499 @kindex set tui active-border-mode
29500 Select the display attributes for the borders of the inactive windows
29501 or the active window. The @var{mode} can be one of the following:
29502 @table @code
29503 @item normal
29504 Use normal attributes to display the border.
29505
29506 @item standout
29507 Use standout mode.
29508
29509 @item reverse
29510 Use reverse video mode.
29511
29512 @item half
29513 Use half bright mode.
29514
29515 @item half-standout
29516 Use half bright and standout mode.
29517
29518 @item bold
29519 Use extra bright or bold mode.
29520
29521 @item bold-standout
29522 Use extra bright or bold and standout mode.
29523 @end table
29524
29525 @item set tui tab-width @var{nchars}
29526 @kindex set tui tab-width
29527 @kindex tabset
29528 Set the width of tab stops to be @var{nchars} characters. This
29529 setting affects the display of TAB characters in the source and
29530 assembly windows.
29531
29532 @item set tui compact-source @r{[}on@r{|}off@r{]}
29533 @kindex set tui compact-source
29534 Set whether the TUI source window is displayed in ``compact'' form.
29535 The default display uses more space for line numbers and starts the
29536 source text at the next tab stop; the compact display uses only as
29537 much space as is needed for the line numbers in the current file, and
29538 only a single space to separate the line numbers from the source.
29539
29540 @kindex set debug tui
29541 @item set debug tui @r{[}on|off@r{]}
29542 Turn on or off display of @value{GDBN} internal debug messages relating
29543 to the TUI.
29544
29545 @kindex show debug tui
29546 @item show debug tui
29547 Show the current status of displaying @value{GDBN} internal debug
29548 messages relating to the TUI.
29549
29550 @end table
29551
29552 Note that the colors of the TUI borders can be controlled using the
29553 appropriate @code{set style} commands. @xref{Output Styling}.
29554
29555 @node Emacs
29556 @chapter Using @value{GDBN} under @sc{gnu} Emacs
29557
29558 @cindex Emacs
29559 @cindex @sc{gnu} Emacs
29560 A special interface allows you to use @sc{gnu} Emacs to view (and
29561 edit) the source files for the program you are debugging with
29562 @value{GDBN}.
29563
29564 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
29565 executable file you want to debug as an argument. This command starts
29566 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
29567 created Emacs buffer.
29568 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
29569
29570 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
29571 things:
29572
29573 @itemize @bullet
29574 @item
29575 All ``terminal'' input and output goes through an Emacs buffer, called
29576 the GUD buffer.
29577
29578 This applies both to @value{GDBN} commands and their output, and to the input
29579 and output done by the program you are debugging.
29580
29581 This is useful because it means that you can copy the text of previous
29582 commands and input them again; you can even use parts of the output
29583 in this way.
29584
29585 All the facilities of Emacs' Shell mode are available for interacting
29586 with your program. In particular, you can send signals the usual
29587 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
29588 stop.
29589
29590 @item
29591 @value{GDBN} displays source code through Emacs.
29592
29593 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
29594 source file for that frame and puts an arrow (@samp{=>}) at the
29595 left margin of the current line. Emacs uses a separate buffer for
29596 source display, and splits the screen to show both your @value{GDBN} session
29597 and the source.
29598
29599 Explicit @value{GDBN} @code{list} or search commands still produce output as
29600 usual, but you probably have no reason to use them from Emacs.
29601 @end itemize
29602
29603 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
29604 a graphical mode, enabled by default, which provides further buffers
29605 that can control the execution and describe the state of your program.
29606 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
29607
29608 If you specify an absolute file name when prompted for the @kbd{M-x
29609 gdb} argument, then Emacs sets your current working directory to where
29610 your program resides. If you only specify the file name, then Emacs
29611 sets your current working directory to the directory associated
29612 with the previous buffer. In this case, @value{GDBN} may find your
29613 program by searching your environment's @env{PATH} variable, but on
29614 some operating systems it might not find the source. So, although the
29615 @value{GDBN} input and output session proceeds normally, the auxiliary
29616 buffer does not display the current source and line of execution.
29617
29618 The initial working directory of @value{GDBN} is printed on the top
29619 line of the GUD buffer and this serves as a default for the commands
29620 that specify files for @value{GDBN} to operate on. @xref{Files,
29621 ,Commands to Specify Files}.
29622
29623 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
29624 need to call @value{GDBN} by a different name (for example, if you
29625 keep several configurations around, with different names) you can
29626 customize the Emacs variable @code{gud-gdb-command-name} to run the
29627 one you want.
29628
29629 In the GUD buffer, you can use these special Emacs commands in
29630 addition to the standard Shell mode commands:
29631
29632 @table @kbd
29633 @item C-h m
29634 Describe the features of Emacs' GUD Mode.
29635
29636 @item C-c C-s
29637 Execute to another source line, like the @value{GDBN} @code{step} command; also
29638 update the display window to show the current file and location.
29639
29640 @item C-c C-n
29641 Execute to next source line in this function, skipping all function
29642 calls, like the @value{GDBN} @code{next} command. Then update the display window
29643 to show the current file and location.
29644
29645 @item C-c C-i
29646 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
29647 display window accordingly.
29648
29649 @item C-c C-f
29650 Execute until exit from the selected stack frame, like the @value{GDBN}
29651 @code{finish} command.
29652
29653 @item C-c C-r
29654 Continue execution of your program, like the @value{GDBN} @code{continue}
29655 command.
29656
29657 @item C-c <
29658 Go up the number of frames indicated by the numeric argument
29659 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
29660 like the @value{GDBN} @code{up} command.
29661
29662 @item C-c >
29663 Go down the number of frames indicated by the numeric argument, like the
29664 @value{GDBN} @code{down} command.
29665 @end table
29666
29667 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
29668 tells @value{GDBN} to set a breakpoint on the source line point is on.
29669
29670 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
29671 separate frame which shows a backtrace when the GUD buffer is current.
29672 Move point to any frame in the stack and type @key{RET} to make it
29673 become the current frame and display the associated source in the
29674 source buffer. Alternatively, click @kbd{Mouse-2} to make the
29675 selected frame become the current one. In graphical mode, the
29676 speedbar displays watch expressions.
29677
29678 If you accidentally delete the source-display buffer, an easy way to get
29679 it back is to type the command @code{f} in the @value{GDBN} buffer, to
29680 request a frame display; when you run under Emacs, this recreates
29681 the source buffer if necessary to show you the context of the current
29682 frame.
29683
29684 The source files displayed in Emacs are in ordinary Emacs buffers
29685 which are visiting the source files in the usual way. You can edit
29686 the files with these buffers if you wish; but keep in mind that @value{GDBN}
29687 communicates with Emacs in terms of line numbers. If you add or
29688 delete lines from the text, the line numbers that @value{GDBN} knows cease
29689 to correspond properly with the code.
29690
29691 A more detailed description of Emacs' interaction with @value{GDBN} is
29692 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
29693 Emacs Manual}).
29694
29695 @node GDB/MI
29696 @chapter The @sc{gdb/mi} Interface
29697
29698 @unnumberedsec Function and Purpose
29699
29700 @cindex @sc{gdb/mi}, its purpose
29701 @sc{gdb/mi} is a line based machine oriented text interface to
29702 @value{GDBN} and is activated by specifying using the
29703 @option{--interpreter} command line option (@pxref{Mode Options}). It
29704 is specifically intended to support the development of systems which
29705 use the debugger as just one small component of a larger system.
29706
29707 This chapter is a specification of the @sc{gdb/mi} interface. It is written
29708 in the form of a reference manual.
29709
29710 Note that @sc{gdb/mi} is still under construction, so some of the
29711 features described below are incomplete and subject to change
29712 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
29713
29714 @unnumberedsec Notation and Terminology
29715
29716 @cindex notational conventions, for @sc{gdb/mi}
29717 This chapter uses the following notation:
29718
29719 @itemize @bullet
29720 @item
29721 @code{|} separates two alternatives.
29722
29723 @item
29724 @code{[ @var{something} ]} indicates that @var{something} is optional:
29725 it may or may not be given.
29726
29727 @item
29728 @code{( @var{group} )*} means that @var{group} inside the parentheses
29729 may repeat zero or more times.
29730
29731 @item
29732 @code{( @var{group} )+} means that @var{group} inside the parentheses
29733 may repeat one or more times.
29734
29735 @item
29736 @code{"@var{string}"} means a literal @var{string}.
29737 @end itemize
29738
29739 @ignore
29740 @heading Dependencies
29741 @end ignore
29742
29743 @menu
29744 * GDB/MI General Design::
29745 * GDB/MI Command Syntax::
29746 * GDB/MI Compatibility with CLI::
29747 * GDB/MI Development and Front Ends::
29748 * GDB/MI Output Records::
29749 * GDB/MI Simple Examples::
29750 * GDB/MI Command Description Format::
29751 * GDB/MI Breakpoint Commands::
29752 * GDB/MI Catchpoint Commands::
29753 * GDB/MI Program Context::
29754 * GDB/MI Thread Commands::
29755 * GDB/MI Ada Tasking Commands::
29756 * GDB/MI Program Execution::
29757 * GDB/MI Stack Manipulation::
29758 * GDB/MI Variable Objects::
29759 * GDB/MI Data Manipulation::
29760 * GDB/MI Tracepoint Commands::
29761 * GDB/MI Symbol Query::
29762 * GDB/MI File Commands::
29763 @ignore
29764 * GDB/MI Kod Commands::
29765 * GDB/MI Memory Overlay Commands::
29766 * GDB/MI Signal Handling Commands::
29767 @end ignore
29768 * GDB/MI Target Manipulation::
29769 * GDB/MI File Transfer Commands::
29770 * GDB/MI Ada Exceptions Commands::
29771 * GDB/MI Support Commands::
29772 * GDB/MI Miscellaneous Commands::
29773 @end menu
29774
29775 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29776 @node GDB/MI General Design
29777 @section @sc{gdb/mi} General Design
29778 @cindex GDB/MI General Design
29779
29780 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
29781 parts---commands sent to @value{GDBN}, responses to those commands
29782 and notifications. Each command results in exactly one response,
29783 indicating either successful completion of the command, or an error.
29784 For the commands that do not resume the target, the response contains the
29785 requested information. For the commands that resume the target, the
29786 response only indicates whether the target was successfully resumed.
29787 Notifications is the mechanism for reporting changes in the state of the
29788 target, or in @value{GDBN} state, that cannot conveniently be associated with
29789 a command and reported as part of that command response.
29790
29791 The important examples of notifications are:
29792 @itemize @bullet
29793
29794 @item
29795 Exec notifications. These are used to report changes in
29796 target state---when a target is resumed, or stopped. It would not
29797 be feasible to include this information in response of resuming
29798 commands, because one resume commands can result in multiple events in
29799 different threads. Also, quite some time may pass before any event
29800 happens in the target, while a frontend needs to know whether the resuming
29801 command itself was successfully executed.
29802
29803 @item
29804 Console output, and status notifications. Console output
29805 notifications are used to report output of CLI commands, as well as
29806 diagnostics for other commands. Status notifications are used to
29807 report the progress of a long-running operation. Naturally, including
29808 this information in command response would mean no output is produced
29809 until the command is finished, which is undesirable.
29810
29811 @item
29812 General notifications. Commands may have various side effects on
29813 the @value{GDBN} or target state beyond their official purpose. For example,
29814 a command may change the selected thread. Although such changes can
29815 be included in command response, using notification allows for more
29816 orthogonal frontend design.
29817
29818 @end itemize
29819
29820 There's no guarantee that whenever an MI command reports an error,
29821 @value{GDBN} or the target are in any specific state, and especially,
29822 the state is not reverted to the state before the MI command was
29823 processed. Therefore, whenever an MI command results in an error,
29824 we recommend that the frontend refreshes all the information shown in
29825 the user interface.
29826
29827
29828 @menu
29829 * Context management::
29830 * Asynchronous and non-stop modes::
29831 * Thread groups::
29832 @end menu
29833
29834 @node Context management
29835 @subsection Context management
29836
29837 @subsubsection Threads and Frames
29838
29839 In most cases when @value{GDBN} accesses the target, this access is
29840 done in context of a specific thread and frame (@pxref{Frames}).
29841 Often, even when accessing global data, the target requires that a thread
29842 be specified. The CLI interface maintains the selected thread and frame,
29843 and supplies them to target on each command. This is convenient,
29844 because a command line user would not want to specify that information
29845 explicitly on each command, and because user interacts with
29846 @value{GDBN} via a single terminal, so no confusion is possible as
29847 to what thread and frame are the current ones.
29848
29849 In the case of MI, the concept of selected thread and frame is less
29850 useful. First, a frontend can easily remember this information
29851 itself. Second, a graphical frontend can have more than one window,
29852 each one used for debugging a different thread, and the frontend might
29853 want to access additional threads for internal purposes. This
29854 increases the risk that by relying on implicitly selected thread, the
29855 frontend may be operating on a wrong one. Therefore, each MI command
29856 should explicitly specify which thread and frame to operate on. To
29857 make it possible, each MI command accepts the @samp{--thread} and
29858 @samp{--frame} options, the value to each is @value{GDBN} global
29859 identifier for thread and frame to operate on.
29860
29861 Usually, each top-level window in a frontend allows the user to select
29862 a thread and a frame, and remembers the user selection for further
29863 operations. However, in some cases @value{GDBN} may suggest that the
29864 current thread or frame be changed. For example, when stopping on a
29865 breakpoint it is reasonable to switch to the thread where breakpoint is
29866 hit. For another example, if the user issues the CLI @samp{thread} or
29867 @samp{frame} commands via the frontend, it is desirable to change the
29868 frontend's selection to the one specified by user. @value{GDBN}
29869 communicates the suggestion to change current thread and frame using the
29870 @samp{=thread-selected} notification.
29871
29872 Note that historically, MI shares the selected thread with CLI, so
29873 frontends used the @code{-thread-select} to execute commands in the
29874 right context. However, getting this to work right is cumbersome. The
29875 simplest way is for frontend to emit @code{-thread-select} command
29876 before every command. This doubles the number of commands that need
29877 to be sent. The alternative approach is to suppress @code{-thread-select}
29878 if the selected thread in @value{GDBN} is supposed to be identical to the
29879 thread the frontend wants to operate on. However, getting this
29880 optimization right can be tricky. In particular, if the frontend
29881 sends several commands to @value{GDBN}, and one of the commands changes the
29882 selected thread, then the behaviour of subsequent commands will
29883 change. So, a frontend should either wait for response from such
29884 problematic commands, or explicitly add @code{-thread-select} for
29885 all subsequent commands. No frontend is known to do this exactly
29886 right, so it is suggested to just always pass the @samp{--thread} and
29887 @samp{--frame} options.
29888
29889 @subsubsection Language
29890
29891 The execution of several commands depends on which language is selected.
29892 By default, the current language (@pxref{show language}) is used.
29893 But for commands known to be language-sensitive, it is recommended
29894 to use the @samp{--language} option. This option takes one argument,
29895 which is the name of the language to use while executing the command.
29896 For instance:
29897
29898 @smallexample
29899 -data-evaluate-expression --language c "sizeof (void*)"
29900 ^done,value="4"
29901 (gdb)
29902 @end smallexample
29903
29904 The valid language names are the same names accepted by the
29905 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
29906 @samp{local} or @samp{unknown}.
29907
29908 @node Asynchronous and non-stop modes
29909 @subsection Asynchronous command execution and non-stop mode
29910
29911 On some targets, @value{GDBN} is capable of processing MI commands
29912 even while the target is running. This is called @dfn{asynchronous
29913 command execution} (@pxref{Background Execution}). The frontend may
29914 specify a preference for asynchronous execution using the
29915 @code{-gdb-set mi-async 1} command, which should be emitted before
29916 either running the executable or attaching to the target. After the
29917 frontend has started the executable or attached to the target, it can
29918 find if asynchronous execution is enabled using the
29919 @code{-list-target-features} command.
29920
29921 @table @code
29922 @cindex foreground execution
29923 @cindex background execution
29924 @cindex asynchronous execution
29925 @cindex execution, foreground, background and asynchronous
29926 @kindex set mi-async
29927 @item -gdb-set mi-async @r{[}on@r{|}off@r{]}
29928 Set whether MI is in asynchronous mode.
29929
29930 When @code{off}, which is the default, MI execution commands (e.g.,
29931 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
29932 for the program to stop before processing further commands.
29933
29934 When @code{on}, MI execution commands are background execution
29935 commands (e.g., @code{-exec-continue} becomes the equivalent of the
29936 @code{c&} CLI command), and so @value{GDBN} is capable of processing
29937 MI commands even while the target is running.
29938
29939 @kindex show mi-async
29940 @item -gdb-show mi-async
29941 Show whether MI asynchronous mode is enabled.
29942 @end table
29943
29944 Note: In @value{GDBN} version 7.7 and earlier, this option was called
29945 @code{target-async} instead of @code{mi-async}, and it had the effect
29946 of both putting MI in asynchronous mode and making CLI background
29947 commands possible. CLI background commands are now always possible
29948 ``out of the box'' if the target supports them. The old spelling is
29949 kept as a deprecated alias for backwards compatibility.
29950
29951 Even if @value{GDBN} can accept a command while target is running,
29952 many commands that access the target do not work when the target is
29953 running. Therefore, asynchronous command execution is most useful
29954 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29955 it is possible to examine the state of one thread, while other threads
29956 are running.
29957
29958 When a given thread is running, MI commands that try to access the
29959 target in the context of that thread may not work, or may work only on
29960 some targets. In particular, commands that try to operate on thread's
29961 stack will not work, on any target. Commands that read memory, or
29962 modify breakpoints, may work or not work, depending on the target. Note
29963 that even commands that operate on global state, such as @code{print},
29964 @code{set}, and breakpoint commands, still access the target in the
29965 context of a specific thread, so frontend should try to find a
29966 stopped thread and perform the operation on that thread (using the
29967 @samp{--thread} option).
29968
29969 Which commands will work in the context of a running thread is
29970 highly target dependent. However, the two commands
29971 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29972 to find the state of a thread, will always work.
29973
29974 @node Thread groups
29975 @subsection Thread groups
29976 @value{GDBN} may be used to debug several processes at the same time.
29977 On some platforms, @value{GDBN} may support debugging of several
29978 hardware systems, each one having several cores with several different
29979 processes running on each core. This section describes the MI
29980 mechanism to support such debugging scenarios.
29981
29982 The key observation is that regardless of the structure of the
29983 target, MI can have a global list of threads, because most commands that
29984 accept the @samp{--thread} option do not need to know what process that
29985 thread belongs to. Therefore, it is not necessary to introduce
29986 neither additional @samp{--process} option, nor an notion of the
29987 current process in the MI interface. The only strictly new feature
29988 that is required is the ability to find how the threads are grouped
29989 into processes.
29990
29991 To allow the user to discover such grouping, and to support arbitrary
29992 hierarchy of machines/cores/processes, MI introduces the concept of a
29993 @dfn{thread group}. Thread group is a collection of threads and other
29994 thread groups. A thread group always has a string identifier, a type,
29995 and may have additional attributes specific to the type. A new
29996 command, @code{-list-thread-groups}, returns the list of top-level
29997 thread groups, which correspond to processes that @value{GDBN} is
29998 debugging at the moment. By passing an identifier of a thread group
29999 to the @code{-list-thread-groups} command, it is possible to obtain
30000 the members of specific thread group.
30001
30002 To allow the user to easily discover processes, and other objects, he
30003 wishes to debug, a concept of @dfn{available thread group} is
30004 introduced. Available thread group is an thread group that
30005 @value{GDBN} is not debugging, but that can be attached to, using the
30006 @code{-target-attach} command. The list of available top-level thread
30007 groups can be obtained using @samp{-list-thread-groups --available}.
30008 In general, the content of a thread group may be only retrieved only
30009 after attaching to that thread group.
30010
30011 Thread groups are related to inferiors (@pxref{Inferiors Connections and
30012 Programs}). Each inferior corresponds to a thread group of a special
30013 type @samp{process}, and some additional operations are permitted on
30014 such thread groups.
30015
30016 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30017 @node GDB/MI Command Syntax
30018 @section @sc{gdb/mi} Command Syntax
30019
30020 @menu
30021 * GDB/MI Input Syntax::
30022 * GDB/MI Output Syntax::
30023 @end menu
30024
30025 @node GDB/MI Input Syntax
30026 @subsection @sc{gdb/mi} Input Syntax
30027
30028 @cindex input syntax for @sc{gdb/mi}
30029 @cindex @sc{gdb/mi}, input syntax
30030 @table @code
30031 @item @var{command} @expansion{}
30032 @code{@var{cli-command} | @var{mi-command}}
30033
30034 @item @var{cli-command} @expansion{}
30035 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
30036 @var{cli-command} is any existing @value{GDBN} CLI command.
30037
30038 @item @var{mi-command} @expansion{}
30039 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
30040 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
30041
30042 @item @var{token} @expansion{}
30043 "any sequence of digits"
30044
30045 @item @var{option} @expansion{}
30046 @code{"-" @var{parameter} [ " " @var{parameter} ]}
30047
30048 @item @var{parameter} @expansion{}
30049 @code{@var{non-blank-sequence} | @var{c-string}}
30050
30051 @item @var{operation} @expansion{}
30052 @emph{any of the operations described in this chapter}
30053
30054 @item @var{non-blank-sequence} @expansion{}
30055 @emph{anything, provided it doesn't contain special characters such as
30056 "-", @var{nl}, """ and of course " "}
30057
30058 @item @var{c-string} @expansion{}
30059 @code{""" @var{seven-bit-iso-c-string-content} """}
30060
30061 @item @var{nl} @expansion{}
30062 @code{CR | CR-LF}
30063 @end table
30064
30065 @noindent
30066 Notes:
30067
30068 @itemize @bullet
30069 @item
30070 The CLI commands are still handled by the @sc{mi} interpreter; their
30071 output is described below.
30072
30073 @item
30074 The @code{@var{token}}, when present, is passed back when the command
30075 finishes.
30076
30077 @item
30078 Some @sc{mi} commands accept optional arguments as part of the parameter
30079 list. Each option is identified by a leading @samp{-} (dash) and may be
30080 followed by an optional argument parameter. Options occur first in the
30081 parameter list and can be delimited from normal parameters using
30082 @samp{--} (this is useful when some parameters begin with a dash).
30083 @end itemize
30084
30085 Pragmatics:
30086
30087 @itemize @bullet
30088 @item
30089 We want easy access to the existing CLI syntax (for debugging).
30090
30091 @item
30092 We want it to be easy to spot a @sc{mi} operation.
30093 @end itemize
30094
30095 @node GDB/MI Output Syntax
30096 @subsection @sc{gdb/mi} Output Syntax
30097
30098 @cindex output syntax of @sc{gdb/mi}
30099 @cindex @sc{gdb/mi}, output syntax
30100 The output from @sc{gdb/mi} consists of zero or more out-of-band records
30101 followed, optionally, by a single result record. This result record
30102 is for the most recent command. The sequence of output records is
30103 terminated by @samp{(gdb)}.
30104
30105 If an input command was prefixed with a @code{@var{token}} then the
30106 corresponding output for that command will also be prefixed by that same
30107 @var{token}.
30108
30109 @table @code
30110 @item @var{output} @expansion{}
30111 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
30112
30113 @item @var{result-record} @expansion{}
30114 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
30115
30116 @item @var{out-of-band-record} @expansion{}
30117 @code{@var{async-record} | @var{stream-record}}
30118
30119 @item @var{async-record} @expansion{}
30120 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
30121
30122 @item @var{exec-async-output} @expansion{}
30123 @code{[ @var{token} ] "*" @var{async-output nl}}
30124
30125 @item @var{status-async-output} @expansion{}
30126 @code{[ @var{token} ] "+" @var{async-output nl}}
30127
30128 @item @var{notify-async-output} @expansion{}
30129 @code{[ @var{token} ] "=" @var{async-output nl}}
30130
30131 @item @var{async-output} @expansion{}
30132 @code{@var{async-class} ( "," @var{result} )*}
30133
30134 @item @var{result-class} @expansion{}
30135 @code{"done" | "running" | "connected" | "error" | "exit"}
30136
30137 @item @var{async-class} @expansion{}
30138 @code{"stopped" | @var{others}} (where @var{others} will be added
30139 depending on the needs---this is still in development).
30140
30141 @item @var{result} @expansion{}
30142 @code{ @var{variable} "=" @var{value}}
30143
30144 @item @var{variable} @expansion{}
30145 @code{ @var{string} }
30146
30147 @item @var{value} @expansion{}
30148 @code{ @var{const} | @var{tuple} | @var{list} }
30149
30150 @item @var{const} @expansion{}
30151 @code{@var{c-string}}
30152
30153 @item @var{tuple} @expansion{}
30154 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
30155
30156 @item @var{list} @expansion{}
30157 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
30158 @var{result} ( "," @var{result} )* "]" }
30159
30160 @item @var{stream-record} @expansion{}
30161 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
30162
30163 @item @var{console-stream-output} @expansion{}
30164 @code{"~" @var{c-string nl}}
30165
30166 @item @var{target-stream-output} @expansion{}
30167 @code{"@@" @var{c-string nl}}
30168
30169 @item @var{log-stream-output} @expansion{}
30170 @code{"&" @var{c-string nl}}
30171
30172 @item @var{nl} @expansion{}
30173 @code{CR | CR-LF}
30174
30175 @item @var{token} @expansion{}
30176 @emph{any sequence of digits}.
30177 @end table
30178
30179 @noindent
30180 Notes:
30181
30182 @itemize @bullet
30183 @item
30184 All output sequences end in a single line containing a period.
30185
30186 @item
30187 The @code{@var{token}} is from the corresponding request. Note that
30188 for all async output, while the token is allowed by the grammar and
30189 may be output by future versions of @value{GDBN} for select async
30190 output messages, it is generally omitted. Frontends should treat
30191 all async output as reporting general changes in the state of the
30192 target and there should be no need to associate async output to any
30193 prior command.
30194
30195 @item
30196 @cindex status output in @sc{gdb/mi}
30197 @var{status-async-output} contains on-going status information about the
30198 progress of a slow operation. It can be discarded. All status output is
30199 prefixed by @samp{+}.
30200
30201 @item
30202 @cindex async output in @sc{gdb/mi}
30203 @var{exec-async-output} contains asynchronous state change on the target
30204 (stopped, started, disappeared). All async output is prefixed by
30205 @samp{*}.
30206
30207 @item
30208 @cindex notify output in @sc{gdb/mi}
30209 @var{notify-async-output} contains supplementary information that the
30210 client should handle (e.g., a new breakpoint information). All notify
30211 output is prefixed by @samp{=}.
30212
30213 @item
30214 @cindex console output in @sc{gdb/mi}
30215 @var{console-stream-output} is output that should be displayed as is in the
30216 console. It is the textual response to a CLI command. All the console
30217 output is prefixed by @samp{~}.
30218
30219 @item
30220 @cindex target output in @sc{gdb/mi}
30221 @var{target-stream-output} is the output produced by the target program.
30222 All the target output is prefixed by @samp{@@}.
30223
30224 @item
30225 @cindex log output in @sc{gdb/mi}
30226 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
30227 instance messages that should be displayed as part of an error log. All
30228 the log output is prefixed by @samp{&}.
30229
30230 @item
30231 @cindex list output in @sc{gdb/mi}
30232 New @sc{gdb/mi} commands should only output @var{lists} containing
30233 @var{values}.
30234
30235
30236 @end itemize
30237
30238 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
30239 details about the various output records.
30240
30241 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30242 @node GDB/MI Compatibility with CLI
30243 @section @sc{gdb/mi} Compatibility with CLI
30244
30245 @cindex compatibility, @sc{gdb/mi} and CLI
30246 @cindex @sc{gdb/mi}, compatibility with CLI
30247
30248 For the developers convenience CLI commands can be entered directly,
30249 but there may be some unexpected behaviour. For example, commands
30250 that query the user will behave as if the user replied yes, breakpoint
30251 command lists are not executed and some CLI commands, such as
30252 @code{if}, @code{when} and @code{define}, prompt for further input with
30253 @samp{>}, which is not valid MI output.
30254
30255 This feature may be removed at some stage in the future and it is
30256 recommended that front ends use the @code{-interpreter-exec} command
30257 (@pxref{-interpreter-exec}).
30258
30259 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30260 @node GDB/MI Development and Front Ends
30261 @section @sc{gdb/mi} Development and Front Ends
30262 @cindex @sc{gdb/mi} development
30263
30264 The application which takes the MI output and presents the state of the
30265 program being debugged to the user is called a @dfn{front end}.
30266
30267 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
30268 to the MI interface may break existing usage. This section describes how the
30269 protocol changes and how to request previous version of the protocol when it
30270 does.
30271
30272 Some changes in MI need not break a carefully designed front end, and
30273 for these the MI version will remain unchanged. The following is a
30274 list of changes that may occur within one level, so front ends should
30275 parse MI output in a way that can handle them:
30276
30277 @itemize @bullet
30278 @item
30279 New MI commands may be added.
30280
30281 @item
30282 New fields may be added to the output of any MI command.
30283
30284 @item
30285 The range of values for fields with specified values, e.g.,
30286 @code{in_scope} (@pxref{-var-update}) may be extended.
30287
30288 @c The format of field's content e.g type prefix, may change so parse it
30289 @c at your own risk. Yes, in general?
30290
30291 @c The order of fields may change? Shouldn't really matter but it might
30292 @c resolve inconsistencies.
30293 @end itemize
30294
30295 If the changes are likely to break front ends, the MI version level
30296 will be increased by one. The new versions of the MI protocol are not compatible
30297 with the old versions. Old versions of MI remain available, allowing front ends
30298 to keep using them until they are modified to use the latest MI version.
30299
30300 Since @code{--interpreter=mi} always points to the latest MI version, it is
30301 recommended that front ends request a specific version of MI when launching
30302 @value{GDBN} (e.g.@: @code{--interpreter=mi2}) to make sure they get an
30303 interpreter with the MI version they expect.
30304
30305 The following table gives a summary of the released versions of the MI
30306 interface: the version number, the version of GDB in which it first appeared
30307 and the breaking changes compared to the previous version.
30308
30309 @multitable @columnfractions .05 .05 .9
30310 @headitem MI version @tab GDB version @tab Breaking changes
30311
30312 @item
30313 @center 1
30314 @tab
30315 @center 5.1
30316 @tab
30317 None
30318
30319 @item
30320 @center 2
30321 @tab
30322 @center 6.0
30323 @tab
30324
30325 @itemize
30326 @item
30327 The @code{-environment-pwd}, @code{-environment-directory} and
30328 @code{-environment-path} commands now returns values using the MI output
30329 syntax, rather than CLI output syntax.
30330
30331 @item
30332 @code{-var-list-children}'s @code{children} result field is now a list, rather
30333 than a tuple.
30334
30335 @item
30336 @code{-var-update}'s @code{changelist} result field is now a list, rather than
30337 a tuple.
30338 @end itemize
30339
30340 @item
30341 @center 3
30342 @tab
30343 @center 9.1
30344 @tab
30345
30346 @itemize
30347 @item
30348 The output of information about multi-location breakpoints has changed in the
30349 responses to the @code{-break-insert} and @code{-break-info} commands, as well
30350 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
30351 The multiple locations are now placed in a @code{locations} field, whose value
30352 is a list.
30353 @end itemize
30354
30355 @end multitable
30356
30357 If your front end cannot yet migrate to a more recent version of the
30358 MI protocol, you can nevertheless selectively enable specific features
30359 available in those recent MI versions, using the following commands:
30360
30361 @table @code
30362
30363 @item -fix-multi-location-breakpoint-output
30364 Use the output for multi-location breakpoints which was introduced by
30365 MI 3, even when using MI versions 2 or 1. This command has no
30366 effect when using MI version 3 or later.
30367
30368 @end table
30369
30370 The best way to avoid unexpected changes in MI that might break your front
30371 end is to make your project known to @value{GDBN} developers and
30372 follow development on @email{gdb@@sourceware.org} and
30373 @email{gdb-patches@@sourceware.org}.
30374 @cindex mailing lists
30375
30376 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30377 @node GDB/MI Output Records
30378 @section @sc{gdb/mi} Output Records
30379
30380 @menu
30381 * GDB/MI Result Records::
30382 * GDB/MI Stream Records::
30383 * GDB/MI Async Records::
30384 * GDB/MI Breakpoint Information::
30385 * GDB/MI Frame Information::
30386 * GDB/MI Thread Information::
30387 * GDB/MI Ada Exception Information::
30388 @end menu
30389
30390 @node GDB/MI Result Records
30391 @subsection @sc{gdb/mi} Result Records
30392
30393 @cindex result records in @sc{gdb/mi}
30394 @cindex @sc{gdb/mi}, result records
30395 In addition to a number of out-of-band notifications, the response to a
30396 @sc{gdb/mi} command includes one of the following result indications:
30397
30398 @table @code
30399 @findex ^done
30400 @item "^done" [ "," @var{results} ]
30401 The synchronous operation was successful, @code{@var{results}} are the return
30402 values.
30403
30404 @item "^running"
30405 @findex ^running
30406 This result record is equivalent to @samp{^done}. Historically, it
30407 was output instead of @samp{^done} if the command has resumed the
30408 target. This behaviour is maintained for backward compatibility, but
30409 all frontends should treat @samp{^done} and @samp{^running}
30410 identically and rely on the @samp{*running} output record to determine
30411 which threads are resumed.
30412
30413 @item "^connected"
30414 @findex ^connected
30415 @value{GDBN} has connected to a remote target.
30416
30417 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
30418 @findex ^error
30419 The operation failed. The @code{msg=@var{c-string}} variable contains
30420 the corresponding error message.
30421
30422 If present, the @code{code=@var{c-string}} variable provides an error
30423 code on which consumers can rely on to detect the corresponding
30424 error condition. At present, only one error code is defined:
30425
30426 @table @samp
30427 @item "undefined-command"
30428 Indicates that the command causing the error does not exist.
30429 @end table
30430
30431 @item "^exit"
30432 @findex ^exit
30433 @value{GDBN} has terminated.
30434
30435 @end table
30436
30437 @node GDB/MI Stream Records
30438 @subsection @sc{gdb/mi} Stream Records
30439
30440 @cindex @sc{gdb/mi}, stream records
30441 @cindex stream records in @sc{gdb/mi}
30442 @value{GDBN} internally maintains a number of output streams: the console, the
30443 target, and the log. The output intended for each of these streams is
30444 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
30445
30446 Each stream record begins with a unique @dfn{prefix character} which
30447 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
30448 Syntax}). In addition to the prefix, each stream record contains a
30449 @code{@var{string-output}}. This is either raw text (with an implicit new
30450 line) or a quoted C string (which does not contain an implicit newline).
30451
30452 @table @code
30453 @item "~" @var{string-output}
30454 The console output stream contains text that should be displayed in the
30455 CLI console window. It contains the textual responses to CLI commands.
30456
30457 @item "@@" @var{string-output}
30458 The target output stream contains any textual output from the running
30459 target. This is only present when GDB's event loop is truly
30460 asynchronous, which is currently only the case for remote targets.
30461
30462 @item "&" @var{string-output}
30463 The log stream contains debugging messages being produced by @value{GDBN}'s
30464 internals.
30465 @end table
30466
30467 @node GDB/MI Async Records
30468 @subsection @sc{gdb/mi} Async Records
30469
30470 @cindex async records in @sc{gdb/mi}
30471 @cindex @sc{gdb/mi}, async records
30472 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
30473 additional changes that have occurred. Those changes can either be a
30474 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
30475 target activity (e.g., target stopped).
30476
30477 The following is the list of possible async records:
30478
30479 @table @code
30480
30481 @item *running,thread-id="@var{thread}"
30482 The target is now running. The @var{thread} field can be the global
30483 thread ID of the thread that is now running, and it can be
30484 @samp{all} if all threads are running. The frontend should assume
30485 that no interaction with a running thread is possible after this
30486 notification is produced. The frontend should not assume that this
30487 notification is output only once for any command. @value{GDBN} may
30488 emit this notification several times, either for different threads,
30489 because it cannot resume all threads together, or even for a single
30490 thread, if the thread must be stepped though some code before letting
30491 it run freely.
30492
30493 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
30494 The target has stopped. The @var{reason} field can have one of the
30495 following values:
30496
30497 @table @code
30498 @item breakpoint-hit
30499 A breakpoint was reached.
30500 @item watchpoint-trigger
30501 A watchpoint was triggered.
30502 @item read-watchpoint-trigger
30503 A read watchpoint was triggered.
30504 @item access-watchpoint-trigger
30505 An access watchpoint was triggered.
30506 @item function-finished
30507 An -exec-finish or similar CLI command was accomplished.
30508 @item location-reached
30509 An -exec-until or similar CLI command was accomplished.
30510 @item watchpoint-scope
30511 A watchpoint has gone out of scope.
30512 @item end-stepping-range
30513 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
30514 similar CLI command was accomplished.
30515 @item exited-signalled
30516 The inferior exited because of a signal.
30517 @item exited
30518 The inferior exited.
30519 @item exited-normally
30520 The inferior exited normally.
30521 @item signal-received
30522 A signal was received by the inferior.
30523 @item solib-event
30524 The inferior has stopped due to a library being loaded or unloaded.
30525 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
30526 set or when a @code{catch load} or @code{catch unload} catchpoint is
30527 in use (@pxref{Set Catchpoints}).
30528 @item fork
30529 The inferior has forked. This is reported when @code{catch fork}
30530 (@pxref{Set Catchpoints}) has been used.
30531 @item vfork
30532 The inferior has vforked. This is reported in when @code{catch vfork}
30533 (@pxref{Set Catchpoints}) has been used.
30534 @item syscall-entry
30535 The inferior entered a system call. This is reported when @code{catch
30536 syscall} (@pxref{Set Catchpoints}) has been used.
30537 @item syscall-return
30538 The inferior returned from a system call. This is reported when
30539 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
30540 @item exec
30541 The inferior called @code{exec}. This is reported when @code{catch exec}
30542 (@pxref{Set Catchpoints}) has been used.
30543 @end table
30544
30545 The @var{id} field identifies the global thread ID of the thread
30546 that directly caused the stop -- for example by hitting a breakpoint.
30547 Depending on whether all-stop
30548 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
30549 stop all threads, or only the thread that directly triggered the stop.
30550 If all threads are stopped, the @var{stopped} field will have the
30551 value of @code{"all"}. Otherwise, the value of the @var{stopped}
30552 field will be a list of thread identifiers. Presently, this list will
30553 always include a single thread, but frontend should be prepared to see
30554 several threads in the list. The @var{core} field reports the
30555 processor core on which the stop event has happened. This field may be absent
30556 if such information is not available.
30557
30558 @item =thread-group-added,id="@var{id}"
30559 @itemx =thread-group-removed,id="@var{id}"
30560 A thread group was either added or removed. The @var{id} field
30561 contains the @value{GDBN} identifier of the thread group. When a thread
30562 group is added, it generally might not be associated with a running
30563 process. When a thread group is removed, its id becomes invalid and
30564 cannot be used in any way.
30565
30566 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
30567 A thread group became associated with a running program,
30568 either because the program was just started or the thread group
30569 was attached to a program. The @var{id} field contains the
30570 @value{GDBN} identifier of the thread group. The @var{pid} field
30571 contains process identifier, specific to the operating system.
30572
30573 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
30574 A thread group is no longer associated with a running program,
30575 either because the program has exited, or because it was detached
30576 from. The @var{id} field contains the @value{GDBN} identifier of the
30577 thread group. The @var{code} field is the exit code of the inferior; it exists
30578 only when the inferior exited with some code.
30579
30580 @item =thread-created,id="@var{id}",group-id="@var{gid}"
30581 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
30582 A thread either was created, or has exited. The @var{id} field
30583 contains the global @value{GDBN} identifier of the thread. The @var{gid}
30584 field identifies the thread group this thread belongs to.
30585
30586 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
30587 Informs that the selected thread or frame were changed. This notification
30588 is not emitted as result of the @code{-thread-select} or
30589 @code{-stack-select-frame} commands, but is emitted whenever an MI command
30590 that is not documented to change the selected thread and frame actually
30591 changes them. In particular, invoking, directly or indirectly
30592 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
30593 will generate this notification. Changing the thread or frame from another
30594 user interface (see @ref{Interpreters}) will also generate this notification.
30595
30596 The @var{frame} field is only present if the newly selected thread is
30597 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
30598
30599 We suggest that in response to this notification, front ends
30600 highlight the selected thread and cause subsequent commands to apply to
30601 that thread.
30602
30603 @item =library-loaded,...
30604 Reports that a new library file was loaded by the program. This
30605 notification has 5 fields---@var{id}, @var{target-name},
30606 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
30607 opaque identifier of the library. For remote debugging case,
30608 @var{target-name} and @var{host-name} fields give the name of the
30609 library file on the target, and on the host respectively. For native
30610 debugging, both those fields have the same value. The
30611 @var{symbols-loaded} field is emitted only for backward compatibility
30612 and should not be relied on to convey any useful information. The
30613 @var{thread-group} field, if present, specifies the id of the thread
30614 group in whose context the library was loaded. If the field is
30615 absent, it means the library was loaded in the context of all present
30616 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
30617 to this library.
30618
30619 @item =library-unloaded,...
30620 Reports that a library was unloaded by the program. This notification
30621 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
30622 the same meaning as for the @code{=library-loaded} notification.
30623 The @var{thread-group} field, if present, specifies the id of the
30624 thread group in whose context the library was unloaded. If the field is
30625 absent, it means the library was unloaded in the context of all present
30626 thread groups.
30627
30628 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
30629 @itemx =traceframe-changed,end
30630 Reports that the trace frame was changed and its new number is
30631 @var{tfnum}. The number of the tracepoint associated with this trace
30632 frame is @var{tpnum}.
30633
30634 @item =tsv-created,name=@var{name},initial=@var{initial}
30635 Reports that the new trace state variable @var{name} is created with
30636 initial value @var{initial}.
30637
30638 @item =tsv-deleted,name=@var{name}
30639 @itemx =tsv-deleted
30640 Reports that the trace state variable @var{name} is deleted or all
30641 trace state variables are deleted.
30642
30643 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
30644 Reports that the trace state variable @var{name} is modified with
30645 the initial value @var{initial}. The current value @var{current} of
30646 trace state variable is optional and is reported if the current
30647 value of trace state variable is known.
30648
30649 @item =breakpoint-created,bkpt=@{...@}
30650 @itemx =breakpoint-modified,bkpt=@{...@}
30651 @itemx =breakpoint-deleted,id=@var{number}
30652 Reports that a breakpoint was created, modified, or deleted,
30653 respectively. Only user-visible breakpoints are reported to the MI
30654 user.
30655
30656 The @var{bkpt} argument is of the same form as returned by the various
30657 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
30658 @var{number} is the ordinal number of the breakpoint.
30659
30660 Note that if a breakpoint is emitted in the result record of a
30661 command, then it will not also be emitted in an async record.
30662
30663 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
30664 @itemx =record-stopped,thread-group="@var{id}"
30665 Execution log recording was either started or stopped on an
30666 inferior. The @var{id} is the @value{GDBN} identifier of the thread
30667 group corresponding to the affected inferior.
30668
30669 The @var{method} field indicates the method used to record execution. If the
30670 method in use supports multiple recording formats, @var{format} will be present
30671 and contain the currently used format. @xref{Process Record and Replay},
30672 for existing method and format values.
30673
30674 @item =cmd-param-changed,param=@var{param},value=@var{value}
30675 Reports that a parameter of the command @code{set @var{param}} is
30676 changed to @var{value}. In the multi-word @code{set} command,
30677 the @var{param} is the whole parameter list to @code{set} command.
30678 For example, In command @code{set check type on}, @var{param}
30679 is @code{check type} and @var{value} is @code{on}.
30680
30681 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
30682 Reports that bytes from @var{addr} to @var{data} + @var{len} were
30683 written in an inferior. The @var{id} is the identifier of the
30684 thread group corresponding to the affected inferior. The optional
30685 @code{type="code"} part is reported if the memory written to holds
30686 executable code.
30687 @end table
30688
30689 @node GDB/MI Breakpoint Information
30690 @subsection @sc{gdb/mi} Breakpoint Information
30691
30692 When @value{GDBN} reports information about a breakpoint, a
30693 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
30694 following fields:
30695
30696 @table @code
30697 @item number
30698 The breakpoint number.
30699
30700 @item type
30701 The type of the breakpoint. For ordinary breakpoints this will be
30702 @samp{breakpoint}, but many values are possible.
30703
30704 @item catch-type
30705 If the type of the breakpoint is @samp{catchpoint}, then this
30706 indicates the exact type of catchpoint.
30707
30708 @item disp
30709 This is the breakpoint disposition---either @samp{del}, meaning that
30710 the breakpoint will be deleted at the next stop, or @samp{keep},
30711 meaning that the breakpoint will not be deleted.
30712
30713 @item enabled
30714 This indicates whether the breakpoint is enabled, in which case the
30715 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30716 Note that this is not the same as the field @code{enable}.
30717
30718 @item addr
30719 The address of the breakpoint. This may be a hexidecimal number,
30720 giving the address; or the string @samp{<PENDING>}, for a pending
30721 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
30722 multiple locations. This field will not be present if no address can
30723 be determined. For example, a watchpoint does not have an address.
30724
30725 @item addr_flags
30726 Optional field containing any flags related to the address. These flags are
30727 architecture-dependent; see @ref{Architectures} for their meaning for a
30728 particular CPU.
30729
30730 @item func
30731 If known, the function in which the breakpoint appears.
30732 If not known, this field is not present.
30733
30734 @item filename
30735 The name of the source file which contains this function, if known.
30736 If not known, this field is not present.
30737
30738 @item fullname
30739 The full file name of the source file which contains this function, if
30740 known. If not known, this field is not present.
30741
30742 @item line
30743 The line number at which this breakpoint appears, if known.
30744 If not known, this field is not present.
30745
30746 @item at
30747 If the source file is not known, this field may be provided. If
30748 provided, this holds the address of the breakpoint, possibly followed
30749 by a symbol name.
30750
30751 @item pending
30752 If this breakpoint is pending, this field is present and holds the
30753 text used to set the breakpoint, as entered by the user.
30754
30755 @item evaluated-by
30756 Where this breakpoint's condition is evaluated, either @samp{host} or
30757 @samp{target}.
30758
30759 @item thread
30760 If this is a thread-specific breakpoint, then this identifies the
30761 thread in which the breakpoint can trigger.
30762
30763 @item task
30764 If this breakpoint is restricted to a particular Ada task, then this
30765 field will hold the task identifier.
30766
30767 @item cond
30768 If the breakpoint is conditional, this is the condition expression.
30769
30770 @item ignore
30771 The ignore count of the breakpoint.
30772
30773 @item enable
30774 The enable count of the breakpoint.
30775
30776 @item traceframe-usage
30777 FIXME.
30778
30779 @item static-tracepoint-marker-string-id
30780 For a static tracepoint, the name of the static tracepoint marker.
30781
30782 @item mask
30783 For a masked watchpoint, this is the mask.
30784
30785 @item pass
30786 A tracepoint's pass count.
30787
30788 @item original-location
30789 The location of the breakpoint as originally specified by the user.
30790 This field is optional.
30791
30792 @item times
30793 The number of times the breakpoint has been hit.
30794
30795 @item installed
30796 This field is only given for tracepoints. This is either @samp{y},
30797 meaning that the tracepoint is installed, or @samp{n}, meaning that it
30798 is not.
30799
30800 @item what
30801 Some extra data, the exact contents of which are type-dependent.
30802
30803 @item locations
30804 This field is present if the breakpoint has multiple locations. It is also
30805 exceptionally present if the breakpoint is enabled and has a single, disabled
30806 location.
30807
30808 The value is a list of locations. The format of a location is described below.
30809
30810 @end table
30811
30812 A location in a multi-location breakpoint is represented as a tuple with the
30813 following fields:
30814
30815 @table @code
30816
30817 @item number
30818 The location number as a dotted pair, like @samp{1.2}. The first digit is the
30819 number of the parent breakpoint. The second digit is the number of the
30820 location within that breakpoint.
30821
30822 @item enabled
30823 There are three possible values, with the following meanings:
30824 @table @code
30825 @item y
30826 The location is enabled.
30827 @item n
30828 The location is disabled by the user.
30829 @item N
30830 The location is disabled because the breakpoint condition is invalid
30831 at this location.
30832 @end table
30833
30834 @item addr
30835 The address of this location as an hexidecimal number.
30836
30837 @item addr_flags
30838 Optional field containing any flags related to the address. These flags are
30839 architecture-dependent; see @ref{Architectures} for their meaning for a
30840 particular CPU.
30841
30842 @item func
30843 If known, the function in which the location appears.
30844 If not known, this field is not present.
30845
30846 @item file
30847 The name of the source file which contains this location, if known.
30848 If not known, this field is not present.
30849
30850 @item fullname
30851 The full file name of the source file which contains this location, if
30852 known. If not known, this field is not present.
30853
30854 @item line
30855 The line number at which this location appears, if known.
30856 If not known, this field is not present.
30857
30858 @item thread-groups
30859 The thread groups this location is in.
30860
30861 @end table
30862
30863 For example, here is what the output of @code{-break-insert}
30864 (@pxref{GDB/MI Breakpoint Commands}) might be:
30865
30866 @smallexample
30867 -> -break-insert main
30868 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30869 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30870 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30871 times="0"@}
30872 <- (gdb)
30873 @end smallexample
30874
30875 @node GDB/MI Frame Information
30876 @subsection @sc{gdb/mi} Frame Information
30877
30878 Response from many MI commands includes an information about stack
30879 frame. This information is a tuple that may have the following
30880 fields:
30881
30882 @table @code
30883 @item level
30884 The level of the stack frame. The innermost frame has the level of
30885 zero. This field is always present.
30886
30887 @item func
30888 The name of the function corresponding to the frame. This field may
30889 be absent if @value{GDBN} is unable to determine the function name.
30890
30891 @item addr
30892 The code address for the frame. This field is always present.
30893
30894 @item addr_flags
30895 Optional field containing any flags related to the address. These flags are
30896 architecture-dependent; see @ref{Architectures} for their meaning for a
30897 particular CPU.
30898
30899 @item file
30900 The name of the source files that correspond to the frame's code
30901 address. This field may be absent.
30902
30903 @item line
30904 The source line corresponding to the frames' code address. This field
30905 may be absent.
30906
30907 @item from
30908 The name of the binary file (either executable or shared library) the
30909 corresponds to the frame's code address. This field may be absent.
30910
30911 @end table
30912
30913 @node GDB/MI Thread Information
30914 @subsection @sc{gdb/mi} Thread Information
30915
30916 Whenever @value{GDBN} has to report an information about a thread, it
30917 uses a tuple with the following fields. The fields are always present unless
30918 stated otherwise.
30919
30920 @table @code
30921 @item id
30922 The global numeric id assigned to the thread by @value{GDBN}.
30923
30924 @item target-id
30925 The target-specific string identifying the thread.
30926
30927 @item details
30928 Additional information about the thread provided by the target.
30929 It is supposed to be human-readable and not interpreted by the
30930 frontend. This field is optional.
30931
30932 @item name
30933 The name of the thread. If the user specified a name using the
30934 @code{thread name} command, then this name is given. Otherwise, if
30935 @value{GDBN} can extract the thread name from the target, then that
30936 name is given. If @value{GDBN} cannot find the thread name, then this
30937 field is omitted.
30938
30939 @item state
30940 The execution state of the thread, either @samp{stopped} or @samp{running},
30941 depending on whether the thread is presently running.
30942
30943 @item frame
30944 The stack frame currently executing in the thread. This field is only present
30945 if the thread is stopped. Its format is documented in
30946 @ref{GDB/MI Frame Information}.
30947
30948 @item core
30949 The value of this field is an integer number of the processor core the
30950 thread was last seen on. This field is optional.
30951 @end table
30952
30953 @node GDB/MI Ada Exception Information
30954 @subsection @sc{gdb/mi} Ada Exception Information
30955
30956 Whenever a @code{*stopped} record is emitted because the program
30957 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30958 @value{GDBN} provides the name of the exception that was raised via
30959 the @code{exception-name} field. Also, for exceptions that were raised
30960 with an exception message, @value{GDBN} provides that message via
30961 the @code{exception-message} field.
30962
30963 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30964 @node GDB/MI Simple Examples
30965 @section Simple Examples of @sc{gdb/mi} Interaction
30966 @cindex @sc{gdb/mi}, simple examples
30967
30968 This subsection presents several simple examples of interaction using
30969 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30970 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30971 the output received from @sc{gdb/mi}.
30972
30973 Note the line breaks shown in the examples are here only for
30974 readability, they don't appear in the real output.
30975
30976 @subheading Setting a Breakpoint
30977
30978 Setting a breakpoint generates synchronous output which contains detailed
30979 information of the breakpoint.
30980
30981 @smallexample
30982 -> -break-insert main
30983 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30984 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30985 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30986 times="0"@}
30987 <- (gdb)
30988 @end smallexample
30989
30990 @subheading Program Execution
30991
30992 Program execution generates asynchronous records and MI gives the
30993 reason that execution stopped.
30994
30995 @smallexample
30996 -> -exec-run
30997 <- ^running
30998 <- (gdb)
30999 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
31000 frame=@{addr="0x08048564",func="main",
31001 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
31002 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
31003 arch="i386:x86_64"@}
31004 <- (gdb)
31005 -> -exec-continue
31006 <- ^running
31007 <- (gdb)
31008 <- *stopped,reason="exited-normally"
31009 <- (gdb)
31010 @end smallexample
31011
31012 @subheading Quitting @value{GDBN}
31013
31014 Quitting @value{GDBN} just prints the result class @samp{^exit}.
31015
31016 @smallexample
31017 -> (gdb)
31018 <- -gdb-exit
31019 <- ^exit
31020 @end smallexample
31021
31022 Please note that @samp{^exit} is printed immediately, but it might
31023 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
31024 performs necessary cleanups, including killing programs being debugged
31025 or disconnecting from debug hardware, so the frontend should wait till
31026 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
31027 fails to exit in reasonable time.
31028
31029 @subheading A Bad Command
31030
31031 Here's what happens if you pass a non-existent command:
31032
31033 @smallexample
31034 -> -rubbish
31035 <- ^error,msg="Undefined MI command: rubbish"
31036 <- (gdb)
31037 @end smallexample
31038
31039
31040 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31041 @node GDB/MI Command Description Format
31042 @section @sc{gdb/mi} Command Description Format
31043
31044 The remaining sections describe blocks of commands. Each block of
31045 commands is laid out in a fashion similar to this section.
31046
31047 @subheading Motivation
31048
31049 The motivation for this collection of commands.
31050
31051 @subheading Introduction
31052
31053 A brief introduction to this collection of commands as a whole.
31054
31055 @subheading Commands
31056
31057 For each command in the block, the following is described:
31058
31059 @subsubheading Synopsis
31060
31061 @smallexample
31062 -command @var{args}@dots{}
31063 @end smallexample
31064
31065 @subsubheading Result
31066
31067 @subsubheading @value{GDBN} Command
31068
31069 The corresponding @value{GDBN} CLI command(s), if any.
31070
31071 @subsubheading Example
31072
31073 Example(s) formatted for readability. Some of the described commands have
31074 not been implemented yet and these are labeled N.A.@: (not available).
31075
31076
31077 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31078 @node GDB/MI Breakpoint Commands
31079 @section @sc{gdb/mi} Breakpoint Commands
31080
31081 @cindex breakpoint commands for @sc{gdb/mi}
31082 @cindex @sc{gdb/mi}, breakpoint commands
31083 This section documents @sc{gdb/mi} commands for manipulating
31084 breakpoints.
31085
31086 @subheading The @code{-break-after} Command
31087 @findex -break-after
31088
31089 @subsubheading Synopsis
31090
31091 @smallexample
31092 -break-after @var{number} @var{count}
31093 @end smallexample
31094
31095 The breakpoint number @var{number} is not in effect until it has been
31096 hit @var{count} times. To see how this is reflected in the output of
31097 the @samp{-break-list} command, see the description of the
31098 @samp{-break-list} command below.
31099
31100 @subsubheading @value{GDBN} Command
31101
31102 The corresponding @value{GDBN} command is @samp{ignore}.
31103
31104 @subsubheading Example
31105
31106 @smallexample
31107 (gdb)
31108 -break-insert main
31109 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31110 enabled="y",addr="0x000100d0",func="main",file="hello.c",
31111 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
31112 times="0"@}
31113 (gdb)
31114 -break-after 1 3
31115 ~
31116 ^done
31117 (gdb)
31118 -break-list
31119 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31120 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31121 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31122 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31123 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31124 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31125 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31126 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31127 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31128 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
31129 (gdb)
31130 @end smallexample
31131
31132 @ignore
31133 @subheading The @code{-break-catch} Command
31134 @findex -break-catch
31135 @end ignore
31136
31137 @subheading The @code{-break-commands} Command
31138 @findex -break-commands
31139
31140 @subsubheading Synopsis
31141
31142 @smallexample
31143 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
31144 @end smallexample
31145
31146 Specifies the CLI commands that should be executed when breakpoint
31147 @var{number} is hit. The parameters @var{command1} to @var{commandN}
31148 are the commands. If no command is specified, any previously-set
31149 commands are cleared. @xref{Break Commands}. Typical use of this
31150 functionality is tracing a program, that is, printing of values of
31151 some variables whenever breakpoint is hit and then continuing.
31152
31153 @subsubheading @value{GDBN} Command
31154
31155 The corresponding @value{GDBN} command is @samp{commands}.
31156
31157 @subsubheading Example
31158
31159 @smallexample
31160 (gdb)
31161 -break-insert main
31162 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
31163 enabled="y",addr="0x000100d0",func="main",file="hello.c",
31164 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
31165 times="0"@}
31166 (gdb)
31167 -break-commands 1 "print v" "continue"
31168 ^done
31169 (gdb)
31170 @end smallexample
31171
31172 @subheading The @code{-break-condition} Command
31173 @findex -break-condition
31174
31175 @subsubheading Synopsis
31176
31177 @smallexample
31178 -break-condition [ --force ] @var{number} [ @var{expr} ]
31179 @end smallexample
31180
31181 Breakpoint @var{number} will stop the program only if the condition in
31182 @var{expr} is true. The condition becomes part of the
31183 @samp{-break-list} output (see the description of the @samp{-break-list}
31184 command below). If the @samp{--force} flag is passed, the condition
31185 is forcibly defined even when it is invalid for all locations of
31186 breakpoint @var{number}. If the @var{expr} argument is omitted,
31187 breakpoint @var{number} becomes unconditional.
31188
31189 @subsubheading @value{GDBN} Command
31190
31191 The corresponding @value{GDBN} command is @samp{condition}.
31192
31193 @subsubheading Example
31194
31195 @smallexample
31196 (gdb)
31197 -break-condition 1 1
31198 ^done
31199 (gdb)
31200 -break-list
31201 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31202 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31203 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31204 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31205 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31206 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31207 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31208 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31209 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31210 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
31211 (gdb)
31212 @end smallexample
31213
31214 @subheading The @code{-break-delete} Command
31215 @findex -break-delete
31216
31217 @subsubheading Synopsis
31218
31219 @smallexample
31220 -break-delete ( @var{breakpoint} )+
31221 @end smallexample
31222
31223 Delete the breakpoint(s) whose number(s) are specified in the argument
31224 list. This is obviously reflected in the breakpoint list.
31225
31226 @subsubheading @value{GDBN} Command
31227
31228 The corresponding @value{GDBN} command is @samp{delete}.
31229
31230 @subsubheading Example
31231
31232 @smallexample
31233 (gdb)
31234 -break-delete 1
31235 ^done
31236 (gdb)
31237 -break-list
31238 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
31239 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31240 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31241 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31242 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31243 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31244 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31245 body=[]@}
31246 (gdb)
31247 @end smallexample
31248
31249 @subheading The @code{-break-disable} Command
31250 @findex -break-disable
31251
31252 @subsubheading Synopsis
31253
31254 @smallexample
31255 -break-disable ( @var{breakpoint} )+
31256 @end smallexample
31257
31258 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
31259 break list is now set to @samp{n} for the named @var{breakpoint}(s).
31260
31261 @subsubheading @value{GDBN} Command
31262
31263 The corresponding @value{GDBN} command is @samp{disable}.
31264
31265 @subsubheading Example
31266
31267 @smallexample
31268 (gdb)
31269 -break-disable 2
31270 ^done
31271 (gdb)
31272 -break-list
31273 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31274 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31275 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31276 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31277 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31278 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31279 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31280 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
31281 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31282 line="5",thread-groups=["i1"],times="0"@}]@}
31283 (gdb)
31284 @end smallexample
31285
31286 @subheading The @code{-break-enable} Command
31287 @findex -break-enable
31288
31289 @subsubheading Synopsis
31290
31291 @smallexample
31292 -break-enable ( @var{breakpoint} )+
31293 @end smallexample
31294
31295 Enable (previously disabled) @var{breakpoint}(s).
31296
31297 @subsubheading @value{GDBN} Command
31298
31299 The corresponding @value{GDBN} command is @samp{enable}.
31300
31301 @subsubheading Example
31302
31303 @smallexample
31304 (gdb)
31305 -break-enable 2
31306 ^done
31307 (gdb)
31308 -break-list
31309 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31310 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31311 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31312 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31313 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31314 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31315 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31316 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
31317 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
31318 line="5",thread-groups=["i1"],times="0"@}]@}
31319 (gdb)
31320 @end smallexample
31321
31322 @subheading The @code{-break-info} Command
31323 @findex -break-info
31324
31325 @subsubheading Synopsis
31326
31327 @smallexample
31328 -break-info @var{breakpoint}
31329 @end smallexample
31330
31331 @c REDUNDANT???
31332 Get information about a single breakpoint.
31333
31334 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
31335 Information}, for details on the format of each breakpoint in the
31336 table.
31337
31338 @subsubheading @value{GDBN} Command
31339
31340 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
31341
31342 @subsubheading Example
31343 N.A.
31344
31345 @subheading The @code{-break-insert} Command
31346 @findex -break-insert
31347 @anchor{-break-insert}
31348
31349 @subsubheading Synopsis
31350
31351 @smallexample
31352 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
31353 [ -c @var{condition} ] [ --force-condition ] [ -i @var{ignore-count} ]
31354 [ -p @var{thread-id} ] [ @var{locspec} ]
31355 @end smallexample
31356
31357 @noindent
31358 If specified, @var{locspec}, can be one of:
31359
31360 @table @var
31361 @item linespec location
31362 A linespec location. @xref{Linespec Locations}.
31363
31364 @item explicit location
31365 An explicit location. @sc{gdb/mi} explicit locations are
31366 analogous to the CLI's explicit locations using the option names
31367 listed below. @xref{Explicit Locations}.
31368
31369 @table @samp
31370 @item --source @var{filename}
31371 The source file name of the location. This option requires the use
31372 of either @samp{--function} or @samp{--line}.
31373
31374 @item --function @var{function}
31375 The name of a function or method.
31376
31377 @item --label @var{label}
31378 The name of a label.
31379
31380 @item --line @var{lineoffset}
31381 An absolute or relative line offset from the start of the location.
31382 @end table
31383
31384 @item address location
31385 An address location, *@var{address}. @xref{Address Locations}.
31386 @end table
31387
31388 @noindent
31389 The possible optional parameters of this command are:
31390
31391 @table @samp
31392 @item -t
31393 Insert a temporary breakpoint.
31394 @item -h
31395 Insert a hardware breakpoint.
31396 @item -f
31397 If @var{locspec} cannot be resolved (for example if it
31398 refers to unknown files or functions), create a pending
31399 breakpoint. Without this flag, @value{GDBN} will report
31400 an error, and won't create a breakpoint, if @var{locspec}
31401 cannot be parsed.
31402 @item -d
31403 Create a disabled breakpoint.
31404 @item -a
31405 Create a tracepoint. @xref{Tracepoints}. When this parameter
31406 is used together with @samp{-h}, a fast tracepoint is created.
31407 @item -c @var{condition}
31408 Make the breakpoint conditional on @var{condition}.
31409 @item --force-condition
31410 Forcibly define the breakpoint even if the condition is invalid at
31411 all of the breakpoint locations.
31412 @item -i @var{ignore-count}
31413 Initialize the @var{ignore-count}.
31414 @item -p @var{thread-id}
31415 Restrict the breakpoint to the thread with the specified global
31416 @var{thread-id}.
31417 @item --qualified
31418 This option makes @value{GDBN} interpret a function name specified as
31419 a complete fully-qualified name.
31420 @end table
31421
31422 @subsubheading Result
31423
31424 @xref{GDB/MI Breakpoint Information}, for details on the format of the
31425 resulting breakpoint.
31426
31427 Note: this format is open to change.
31428 @c An out-of-band breakpoint instead of part of the result?
31429
31430 @subsubheading @value{GDBN} Command
31431
31432 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
31433 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
31434
31435 @subsubheading Example
31436
31437 @smallexample
31438 (gdb)
31439 -break-insert main
31440 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
31441 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
31442 times="0"@}
31443 (gdb)
31444 -break-insert -t foo
31445 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
31446 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
31447 times="0"@}
31448 (gdb)
31449 -break-list
31450 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31451 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31452 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31453 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31454 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31455 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31456 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31457 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31458 addr="0x0001072c", func="main",file="recursive2.c",
31459 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
31460 times="0"@},
31461 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
31462 addr="0x00010774",func="foo",file="recursive2.c",
31463 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
31464 times="0"@}]@}
31465 (gdb)
31466 @end smallexample
31467
31468 @subheading The @code{-dprintf-insert} Command
31469 @findex -dprintf-insert
31470
31471 @subsubheading Synopsis
31472
31473 @smallexample
31474 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
31475 [ -c @var{condition} ] [--force-condition] [ -i @var{ignore-count} ]
31476 [ -p @var{thread-id} ] [ @var{locspec} ] [ @var{format} ]
31477 [ @var{argument} ]
31478 @end smallexample
31479
31480 @noindent
31481 If supplied, @var{locspec} and @code{--qualified} may be specified
31482 the same way as for the @code{-break-insert} command.
31483 @xref{-break-insert}.
31484
31485 The possible optional parameters of this command are:
31486
31487 @table @samp
31488 @item -t
31489 Insert a temporary breakpoint.
31490 @item -f
31491 If @var{locspec} cannot be parsed (for example, if it
31492 refers to unknown files or functions), create a pending
31493 breakpoint. Without this flag, @value{GDBN} will report
31494 an error, and won't create a breakpoint, if @var{locspec}
31495 cannot be parsed.
31496 @item -d
31497 Create a disabled breakpoint.
31498 @item -c @var{condition}
31499 Make the breakpoint conditional on @var{condition}.
31500 @item --force-condition
31501 Forcibly define the breakpoint even if the condition is invalid at
31502 all of the breakpoint locations.
31503 @item -i @var{ignore-count}
31504 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
31505 to @var{ignore-count}.
31506 @item -p @var{thread-id}
31507 Restrict the breakpoint to the thread with the specified global
31508 @var{thread-id}.
31509 @end table
31510
31511 @subsubheading Result
31512
31513 @xref{GDB/MI Breakpoint Information}, for details on the format of the
31514 resulting breakpoint.
31515
31516 @c An out-of-band breakpoint instead of part of the result?
31517
31518 @subsubheading @value{GDBN} Command
31519
31520 The corresponding @value{GDBN} command is @samp{dprintf}.
31521
31522 @subsubheading Example
31523
31524 @smallexample
31525 (gdb)
31526 4-dprintf-insert foo "At foo entry\n"
31527 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
31528 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
31529 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
31530 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
31531 original-location="foo"@}
31532 (gdb)
31533 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
31534 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
31535 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
31536 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
31537 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
31538 original-location="mi-dprintf.c:26"@}
31539 (gdb)
31540 @end smallexample
31541
31542 @subheading The @code{-break-list} Command
31543 @findex -break-list
31544
31545 @subsubheading Synopsis
31546
31547 @smallexample
31548 -break-list
31549 @end smallexample
31550
31551 Displays the list of inserted breakpoints, showing the following fields:
31552
31553 @table @samp
31554 @item Number
31555 number of the breakpoint
31556 @item Type
31557 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
31558 @item Disposition
31559 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
31560 or @samp{nokeep}
31561 @item Enabled
31562 is the breakpoint enabled or no: @samp{y} or @samp{n}
31563 @item Address
31564 memory location at which the breakpoint is set
31565 @item What
31566 logical location of the breakpoint, expressed by function name, file
31567 name, line number
31568 @item Thread-groups
31569 list of thread groups to which this breakpoint applies
31570 @item Times
31571 number of times the breakpoint has been hit
31572 @end table
31573
31574 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
31575 @code{body} field is an empty list.
31576
31577 @subsubheading @value{GDBN} Command
31578
31579 The corresponding @value{GDBN} command is @samp{info break}.
31580
31581 @subsubheading Example
31582
31583 @smallexample
31584 (gdb)
31585 -break-list
31586 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31587 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31588 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31589 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31590 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31591 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31592 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31593 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31594 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
31595 times="0"@},
31596 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
31597 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
31598 line="13",thread-groups=["i1"],times="0"@}]@}
31599 (gdb)
31600 @end smallexample
31601
31602 Here's an example of the result when there are no breakpoints:
31603
31604 @smallexample
31605 (gdb)
31606 -break-list
31607 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
31608 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31609 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31610 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31611 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31612 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31613 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31614 body=[]@}
31615 (gdb)
31616 @end smallexample
31617
31618 @subheading The @code{-break-passcount} Command
31619 @findex -break-passcount
31620
31621 @subsubheading Synopsis
31622
31623 @smallexample
31624 -break-passcount @var{tracepoint-number} @var{passcount}
31625 @end smallexample
31626
31627 Set the passcount for tracepoint @var{tracepoint-number} to
31628 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
31629 is not a tracepoint, error is emitted. This corresponds to CLI
31630 command @samp{passcount}.
31631
31632 @subheading The @code{-break-watch} Command
31633 @findex -break-watch
31634
31635 @subsubheading Synopsis
31636
31637 @smallexample
31638 -break-watch [ -a | -r ]
31639 @end smallexample
31640
31641 Create a watchpoint. With the @samp{-a} option it will create an
31642 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
31643 read from or on a write to the memory location. With the @samp{-r}
31644 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
31645 trigger only when the memory location is accessed for reading. Without
31646 either of the options, the watchpoint created is a regular watchpoint,
31647 i.e., it will trigger when the memory location is accessed for writing.
31648 @xref{Set Watchpoints, , Setting Watchpoints}.
31649
31650 Note that @samp{-break-list} will report a single list of watchpoints and
31651 breakpoints inserted.
31652
31653 @subsubheading @value{GDBN} Command
31654
31655 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
31656 @samp{rwatch}.
31657
31658 @subsubheading Example
31659
31660 Setting a watchpoint on a variable in the @code{main} function:
31661
31662 @smallexample
31663 (gdb)
31664 -break-watch x
31665 ^done,wpt=@{number="2",exp="x"@}
31666 (gdb)
31667 -exec-continue
31668 ^running
31669 (gdb)
31670 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
31671 value=@{old="-268439212",new="55"@},
31672 frame=@{func="main",args=[],file="recursive2.c",
31673 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
31674 (gdb)
31675 @end smallexample
31676
31677 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
31678 the program execution twice: first for the variable changing value, then
31679 for the watchpoint going out of scope.
31680
31681 @smallexample
31682 (gdb)
31683 -break-watch C
31684 ^done,wpt=@{number="5",exp="C"@}
31685 (gdb)
31686 -exec-continue
31687 ^running
31688 (gdb)
31689 *stopped,reason="watchpoint-trigger",
31690 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
31691 frame=@{func="callee4",args=[],
31692 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31693 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31694 arch="i386:x86_64"@}
31695 (gdb)
31696 -exec-continue
31697 ^running
31698 (gdb)
31699 *stopped,reason="watchpoint-scope",wpnum="5",
31700 frame=@{func="callee3",args=[@{name="strarg",
31701 value="0x11940 \"A string argument.\""@}],
31702 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31703 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31704 arch="i386:x86_64"@}
31705 (gdb)
31706 @end smallexample
31707
31708 Listing breakpoints and watchpoints, at different points in the program
31709 execution. Note that once the watchpoint goes out of scope, it is
31710 deleted.
31711
31712 @smallexample
31713 (gdb)
31714 -break-watch C
31715 ^done,wpt=@{number="2",exp="C"@}
31716 (gdb)
31717 -break-list
31718 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31719 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31720 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31721 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31722 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31723 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31724 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31725 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31726 addr="0x00010734",func="callee4",
31727 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31728 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
31729 times="1"@},
31730 bkpt=@{number="2",type="watchpoint",disp="keep",
31731 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
31732 (gdb)
31733 -exec-continue
31734 ^running
31735 (gdb)
31736 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
31737 value=@{old="-276895068",new="3"@},
31738 frame=@{func="callee4",args=[],
31739 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31740 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31741 arch="i386:x86_64"@}
31742 (gdb)
31743 -break-list
31744 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31745 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31746 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31747 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31748 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31749 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31750 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31751 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31752 addr="0x00010734",func="callee4",
31753 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31754 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
31755 times="1"@},
31756 bkpt=@{number="2",type="watchpoint",disp="keep",
31757 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
31758 (gdb)
31759 -exec-continue
31760 ^running
31761 ^done,reason="watchpoint-scope",wpnum="2",
31762 frame=@{func="callee3",args=[@{name="strarg",
31763 value="0x11940 \"A string argument.\""@}],
31764 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31765 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31766 arch="i386:x86_64"@}
31767 (gdb)
31768 -break-list
31769 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31770 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31771 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31772 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31773 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31774 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31775 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31776 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31777 addr="0x00010734",func="callee4",
31778 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31779 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31780 thread-groups=["i1"],times="1"@}]@}
31781 (gdb)
31782 @end smallexample
31783
31784
31785 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31786 @node GDB/MI Catchpoint Commands
31787 @section @sc{gdb/mi} Catchpoint Commands
31788
31789 This section documents @sc{gdb/mi} commands for manipulating
31790 catchpoints.
31791
31792 @menu
31793 * Shared Library GDB/MI Catchpoint Commands::
31794 * Ada Exception GDB/MI Catchpoint Commands::
31795 * C++ Exception GDB/MI Catchpoint Commands::
31796 @end menu
31797
31798 @node Shared Library GDB/MI Catchpoint Commands
31799 @subsection Shared Library @sc{gdb/mi} Catchpoints
31800
31801 @subheading The @code{-catch-load} Command
31802 @findex -catch-load
31803
31804 @subsubheading Synopsis
31805
31806 @smallexample
31807 -catch-load [ -t ] [ -d ] @var{regexp}
31808 @end smallexample
31809
31810 Add a catchpoint for library load events. If the @samp{-t} option is used,
31811 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31812 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
31813 in a disabled state. The @samp{regexp} argument is a regular
31814 expression used to match the name of the loaded library.
31815
31816
31817 @subsubheading @value{GDBN} Command
31818
31819 The corresponding @value{GDBN} command is @samp{catch load}.
31820
31821 @subsubheading Example
31822
31823 @smallexample
31824 -catch-load -t foo.so
31825 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
31826 what="load of library matching foo.so",catch-type="load",times="0"@}
31827 (gdb)
31828 @end smallexample
31829
31830
31831 @subheading The @code{-catch-unload} Command
31832 @findex -catch-unload
31833
31834 @subsubheading Synopsis
31835
31836 @smallexample
31837 -catch-unload [ -t ] [ -d ] @var{regexp}
31838 @end smallexample
31839
31840 Add a catchpoint for library unload events. If the @samp{-t} option is
31841 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31842 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
31843 created in a disabled state. The @samp{regexp} argument is a regular
31844 expression used to match the name of the unloaded library.
31845
31846 @subsubheading @value{GDBN} Command
31847
31848 The corresponding @value{GDBN} command is @samp{catch unload}.
31849
31850 @subsubheading Example
31851
31852 @smallexample
31853 -catch-unload -d bar.so
31854 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
31855 what="load of library matching bar.so",catch-type="unload",times="0"@}
31856 (gdb)
31857 @end smallexample
31858
31859 @node Ada Exception GDB/MI Catchpoint Commands
31860 @subsection Ada Exception @sc{gdb/mi} Catchpoints
31861
31862 The following @sc{gdb/mi} commands can be used to create catchpoints
31863 that stop the execution when Ada exceptions are being raised.
31864
31865 @subheading The @code{-catch-assert} Command
31866 @findex -catch-assert
31867
31868 @subsubheading Synopsis
31869
31870 @smallexample
31871 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
31872 @end smallexample
31873
31874 Add a catchpoint for failed Ada assertions.
31875
31876 The possible optional parameters for this command are:
31877
31878 @table @samp
31879 @item -c @var{condition}
31880 Make the catchpoint conditional on @var{condition}.
31881 @item -d
31882 Create a disabled catchpoint.
31883 @item -t
31884 Create a temporary catchpoint.
31885 @end table
31886
31887 @subsubheading @value{GDBN} Command
31888
31889 The corresponding @value{GDBN} command is @samp{catch assert}.
31890
31891 @subsubheading Example
31892
31893 @smallexample
31894 -catch-assert
31895 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
31896 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
31897 thread-groups=["i1"],times="0",
31898 original-location="__gnat_debug_raise_assert_failure"@}
31899 (gdb)
31900 @end smallexample
31901
31902 @subheading The @code{-catch-exception} Command
31903 @findex -catch-exception
31904
31905 @subsubheading Synopsis
31906
31907 @smallexample
31908 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31909 [ -t ] [ -u ]
31910 @end smallexample
31911
31912 Add a catchpoint stopping when Ada exceptions are raised.
31913 By default, the command stops the program when any Ada exception
31914 gets raised. But it is also possible, by using some of the
31915 optional parameters described below, to create more selective
31916 catchpoints.
31917
31918 The possible optional parameters for this command are:
31919
31920 @table @samp
31921 @item -c @var{condition}
31922 Make the catchpoint conditional on @var{condition}.
31923 @item -d
31924 Create a disabled catchpoint.
31925 @item -e @var{exception-name}
31926 Only stop when @var{exception-name} is raised. This option cannot
31927 be used combined with @samp{-u}.
31928 @item -t
31929 Create a temporary catchpoint.
31930 @item -u
31931 Stop only when an unhandled exception gets raised. This option
31932 cannot be used combined with @samp{-e}.
31933 @end table
31934
31935 @subsubheading @value{GDBN} Command
31936
31937 The corresponding @value{GDBN} commands are @samp{catch exception}
31938 and @samp{catch exception unhandled}.
31939
31940 @subsubheading Example
31941
31942 @smallexample
31943 -catch-exception -e Program_Error
31944 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31945 enabled="y",addr="0x0000000000404874",
31946 what="`Program_Error' Ada exception", thread-groups=["i1"],
31947 times="0",original-location="__gnat_debug_raise_exception"@}
31948 (gdb)
31949 @end smallexample
31950
31951 @subheading The @code{-catch-handlers} Command
31952 @findex -catch-handlers
31953
31954 @subsubheading Synopsis
31955
31956 @smallexample
31957 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31958 [ -t ]
31959 @end smallexample
31960
31961 Add a catchpoint stopping when Ada exceptions are handled.
31962 By default, the command stops the program when any Ada exception
31963 gets handled. But it is also possible, by using some of the
31964 optional parameters described below, to create more selective
31965 catchpoints.
31966
31967 The possible optional parameters for this command are:
31968
31969 @table @samp
31970 @item -c @var{condition}
31971 Make the catchpoint conditional on @var{condition}.
31972 @item -d
31973 Create a disabled catchpoint.
31974 @item -e @var{exception-name}
31975 Only stop when @var{exception-name} is handled.
31976 @item -t
31977 Create a temporary catchpoint.
31978 @end table
31979
31980 @subsubheading @value{GDBN} Command
31981
31982 The corresponding @value{GDBN} command is @samp{catch handlers}.
31983
31984 @subsubheading Example
31985
31986 @smallexample
31987 -catch-handlers -e Constraint_Error
31988 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31989 enabled="y",addr="0x0000000000402f68",
31990 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31991 times="0",original-location="__gnat_begin_handler"@}
31992 (gdb)
31993 @end smallexample
31994
31995 @node C++ Exception GDB/MI Catchpoint Commands
31996 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31997
31998 The following @sc{gdb/mi} commands can be used to create catchpoints
31999 that stop the execution when C@t{++} exceptions are being throw, rethrown,
32000 or caught.
32001
32002 @subheading The @code{-catch-throw} Command
32003 @findex -catch-throw
32004
32005 @subsubheading Synopsis
32006
32007 @smallexample
32008 -catch-throw [ -t ] [ -r @var{regexp}]
32009 @end smallexample
32010
32011 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
32012 given, then only exceptions whose type matches the regular expression
32013 will be caught.
32014
32015 If @samp{-t} is given, then the catchpoint is enabled only for one
32016 stop, the catchpoint is automatically deleted after stopping once for
32017 the event.
32018
32019 @subsubheading @value{GDBN} Command
32020
32021 The corresponding @value{GDBN} commands are @samp{catch throw}
32022 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
32023
32024 @subsubheading Example
32025
32026 @smallexample
32027 -catch-throw -r exception_type
32028 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32029 what="exception throw",catch-type="throw",
32030 thread-groups=["i1"],
32031 regexp="exception_type",times="0"@}
32032 (gdb)
32033 -exec-run
32034 ^running
32035 (gdb)
32036 ~"\n"
32037 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
32038 in __cxa_throw () from /lib64/libstdc++.so.6\n"
32039 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32040 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
32041 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32042 thread-id="1",stopped-threads="all",core="6"
32043 (gdb)
32044 @end smallexample
32045
32046 @subheading The @code{-catch-rethrow} Command
32047 @findex -catch-rethrow
32048
32049 @subsubheading Synopsis
32050
32051 @smallexample
32052 -catch-rethrow [ -t ] [ -r @var{regexp}]
32053 @end smallexample
32054
32055 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
32056 then only exceptions whose type matches the regular expression will be
32057 caught.
32058
32059 If @samp{-t} is given, then the catchpoint is enabled only for one
32060 stop, the catchpoint is automatically deleted after the first event is
32061 caught.
32062
32063 @subsubheading @value{GDBN} Command
32064
32065 The corresponding @value{GDBN} commands are @samp{catch rethrow}
32066 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
32067
32068 @subsubheading Example
32069
32070 @smallexample
32071 -catch-rethrow -r exception_type
32072 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32073 what="exception rethrow",catch-type="rethrow",
32074 thread-groups=["i1"],
32075 regexp="exception_type",times="0"@}
32076 (gdb)
32077 -exec-run
32078 ^running
32079 (gdb)
32080 ~"\n"
32081 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
32082 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
32083 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32084 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
32085 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32086 thread-id="1",stopped-threads="all",core="6"
32087 (gdb)
32088 @end smallexample
32089
32090 @subheading The @code{-catch-catch} Command
32091 @findex -catch-catch
32092
32093 @subsubheading Synopsis
32094
32095 @smallexample
32096 -catch-catch [ -t ] [ -r @var{regexp}]
32097 @end smallexample
32098
32099 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
32100 is given, then only exceptions whose type matches the regular
32101 expression will be caught.
32102
32103 If @samp{-t} is given, then the catchpoint is enabled only for one
32104 stop, the catchpoint is automatically deleted after the first event is
32105 caught.
32106
32107 @subsubheading @value{GDBN} Command
32108
32109 The corresponding @value{GDBN} commands are @samp{catch catch}
32110 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
32111
32112 @subsubheading Example
32113
32114 @smallexample
32115 -catch-catch -r exception_type
32116 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
32117 what="exception catch",catch-type="catch",
32118 thread-groups=["i1"],
32119 regexp="exception_type",times="0"@}
32120 (gdb)
32121 -exec-run
32122 ^running
32123 (gdb)
32124 ~"\n"
32125 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
32126 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
32127 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
32128 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
32129 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
32130 thread-id="1",stopped-threads="all",core="6"
32131 (gdb)
32132 @end smallexample
32133
32134 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32135 @node GDB/MI Program Context
32136 @section @sc{gdb/mi} Program Context
32137
32138 @subheading The @code{-exec-arguments} Command
32139 @findex -exec-arguments
32140
32141
32142 @subsubheading Synopsis
32143
32144 @smallexample
32145 -exec-arguments @var{args}
32146 @end smallexample
32147
32148 Set the inferior program arguments, to be used in the next
32149 @samp{-exec-run}.
32150
32151 @subsubheading @value{GDBN} Command
32152
32153 The corresponding @value{GDBN} command is @samp{set args}.
32154
32155 @subsubheading Example
32156
32157 @smallexample
32158 (gdb)
32159 -exec-arguments -v word
32160 ^done
32161 (gdb)
32162 @end smallexample
32163
32164
32165 @ignore
32166 @subheading The @code{-exec-show-arguments} Command
32167 @findex -exec-show-arguments
32168
32169 @subsubheading Synopsis
32170
32171 @smallexample
32172 -exec-show-arguments
32173 @end smallexample
32174
32175 Print the arguments of the program.
32176
32177 @subsubheading @value{GDBN} Command
32178
32179 The corresponding @value{GDBN} command is @samp{show args}.
32180
32181 @subsubheading Example
32182 N.A.
32183 @end ignore
32184
32185
32186 @subheading The @code{-environment-cd} Command
32187 @findex -environment-cd
32188
32189 @subsubheading Synopsis
32190
32191 @smallexample
32192 -environment-cd @var{pathdir}
32193 @end smallexample
32194
32195 Set @value{GDBN}'s working directory.
32196
32197 @subsubheading @value{GDBN} Command
32198
32199 The corresponding @value{GDBN} command is @samp{cd}.
32200
32201 @subsubheading Example
32202
32203 @smallexample
32204 (gdb)
32205 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
32206 ^done
32207 (gdb)
32208 @end smallexample
32209
32210
32211 @subheading The @code{-environment-directory} Command
32212 @findex -environment-directory
32213
32214 @subsubheading Synopsis
32215
32216 @smallexample
32217 -environment-directory [ -r ] [ @var{pathdir} ]+
32218 @end smallexample
32219
32220 Add directories @var{pathdir} to beginning of search path for source files.
32221 If the @samp{-r} option is used, the search path is reset to the default
32222 search path. If directories @var{pathdir} are supplied in addition to the
32223 @samp{-r} option, the search path is first reset and then addition
32224 occurs as normal.
32225 Multiple directories may be specified, separated by blanks. Specifying
32226 multiple directories in a single command
32227 results in the directories added to the beginning of the
32228 search path in the same order they were presented in the command.
32229 If blanks are needed as
32230 part of a directory name, double-quotes should be used around
32231 the name. In the command output, the path will show up separated
32232 by the system directory-separator character. The directory-separator
32233 character must not be used
32234 in any directory name.
32235 If no directories are specified, the current search path is displayed.
32236
32237 @subsubheading @value{GDBN} Command
32238
32239 The corresponding @value{GDBN} command is @samp{dir}.
32240
32241 @subsubheading Example
32242
32243 @smallexample
32244 (gdb)
32245 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
32246 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
32247 (gdb)
32248 -environment-directory ""
32249 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
32250 (gdb)
32251 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
32252 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
32253 (gdb)
32254 -environment-directory -r
32255 ^done,source-path="$cdir:$cwd"
32256 (gdb)
32257 @end smallexample
32258
32259
32260 @subheading The @code{-environment-path} Command
32261 @findex -environment-path
32262
32263 @subsubheading Synopsis
32264
32265 @smallexample
32266 -environment-path [ -r ] [ @var{pathdir} ]+
32267 @end smallexample
32268
32269 Add directories @var{pathdir} to beginning of search path for object files.
32270 If the @samp{-r} option is used, the search path is reset to the original
32271 search path that existed at gdb start-up. If directories @var{pathdir} are
32272 supplied in addition to the
32273 @samp{-r} option, the search path is first reset and then addition
32274 occurs as normal.
32275 Multiple directories may be specified, separated by blanks. Specifying
32276 multiple directories in a single command
32277 results in the directories added to the beginning of the
32278 search path in the same order they were presented in the command.
32279 If blanks are needed as
32280 part of a directory name, double-quotes should be used around
32281 the name. In the command output, the path will show up separated
32282 by the system directory-separator character. The directory-separator
32283 character must not be used
32284 in any directory name.
32285 If no directories are specified, the current path is displayed.
32286
32287
32288 @subsubheading @value{GDBN} Command
32289
32290 The corresponding @value{GDBN} command is @samp{path}.
32291
32292 @subsubheading Example
32293
32294 @smallexample
32295 (gdb)
32296 -environment-path
32297 ^done,path="/usr/bin"
32298 (gdb)
32299 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
32300 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
32301 (gdb)
32302 -environment-path -r /usr/local/bin
32303 ^done,path="/usr/local/bin:/usr/bin"
32304 (gdb)
32305 @end smallexample
32306
32307
32308 @subheading The @code{-environment-pwd} Command
32309 @findex -environment-pwd
32310
32311 @subsubheading Synopsis
32312
32313 @smallexample
32314 -environment-pwd
32315 @end smallexample
32316
32317 Show the current working directory.
32318
32319 @subsubheading @value{GDBN} Command
32320
32321 The corresponding @value{GDBN} command is @samp{pwd}.
32322
32323 @subsubheading Example
32324
32325 @smallexample
32326 (gdb)
32327 -environment-pwd
32328 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
32329 (gdb)
32330 @end smallexample
32331
32332 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32333 @node GDB/MI Thread Commands
32334 @section @sc{gdb/mi} Thread Commands
32335
32336
32337 @subheading The @code{-thread-info} Command
32338 @findex -thread-info
32339
32340 @subsubheading Synopsis
32341
32342 @smallexample
32343 -thread-info [ @var{thread-id} ]
32344 @end smallexample
32345
32346 Reports information about either a specific thread, if the
32347 @var{thread-id} parameter is present, or about all threads.
32348 @var{thread-id} is the thread's global thread ID. When printing
32349 information about all threads, also reports the global ID of the
32350 current thread.
32351
32352 @subsubheading @value{GDBN} Command
32353
32354 The @samp{info thread} command prints the same information
32355 about all threads.
32356
32357 @subsubheading Result
32358
32359 The result contains the following attributes:
32360
32361 @table @samp
32362 @item threads
32363 A list of threads. The format of the elements of the list is described in
32364 @ref{GDB/MI Thread Information}.
32365
32366 @item current-thread-id
32367 The global id of the currently selected thread. This field is omitted if there
32368 is no selected thread (for example, when the selected inferior is not running,
32369 and therefore has no threads) or if a @var{thread-id} argument was passed to
32370 the command.
32371
32372 @end table
32373
32374 @subsubheading Example
32375
32376 @smallexample
32377 -thread-info
32378 ^done,threads=[
32379 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
32380 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
32381 args=[]@},state="running"@},
32382 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
32383 frame=@{level="0",addr="0x0804891f",func="foo",
32384 args=[@{name="i",value="10"@}],
32385 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
32386 state="running"@}],
32387 current-thread-id="1"
32388 (gdb)
32389 @end smallexample
32390
32391 @subheading The @code{-thread-list-ids} Command
32392 @findex -thread-list-ids
32393
32394 @subsubheading Synopsis
32395
32396 @smallexample
32397 -thread-list-ids
32398 @end smallexample
32399
32400 Produces a list of the currently known global @value{GDBN} thread ids.
32401 At the end of the list it also prints the total number of such
32402 threads.
32403
32404 This command is retained for historical reasons, the
32405 @code{-thread-info} command should be used instead.
32406
32407 @subsubheading @value{GDBN} Command
32408
32409 Part of @samp{info threads} supplies the same information.
32410
32411 @subsubheading Example
32412
32413 @smallexample
32414 (gdb)
32415 -thread-list-ids
32416 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
32417 current-thread-id="1",number-of-threads="3"
32418 (gdb)
32419 @end smallexample
32420
32421
32422 @subheading The @code{-thread-select} Command
32423 @findex -thread-select
32424
32425 @subsubheading Synopsis
32426
32427 @smallexample
32428 -thread-select @var{thread-id}
32429 @end smallexample
32430
32431 Make thread with global thread number @var{thread-id} the current
32432 thread. It prints the number of the new current thread, and the
32433 topmost frame for that thread.
32434
32435 This command is deprecated in favor of explicitly using the
32436 @samp{--thread} option to each command.
32437
32438 @subsubheading @value{GDBN} Command
32439
32440 The corresponding @value{GDBN} command is @samp{thread}.
32441
32442 @subsubheading Example
32443
32444 @smallexample
32445 (gdb)
32446 -exec-next
32447 ^running
32448 (gdb)
32449 *stopped,reason="end-stepping-range",thread-id="2",line="187",
32450 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
32451 (gdb)
32452 -thread-list-ids
32453 ^done,
32454 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
32455 number-of-threads="3"
32456 (gdb)
32457 -thread-select 3
32458 ^done,new-thread-id="3",
32459 frame=@{level="0",func="vprintf",
32460 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
32461 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
32462 (gdb)
32463 @end smallexample
32464
32465 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32466 @node GDB/MI Ada Tasking Commands
32467 @section @sc{gdb/mi} Ada Tasking Commands
32468
32469 @subheading The @code{-ada-task-info} Command
32470 @findex -ada-task-info
32471
32472 @subsubheading Synopsis
32473
32474 @smallexample
32475 -ada-task-info [ @var{task-id} ]
32476 @end smallexample
32477
32478 Reports information about either a specific Ada task, if the
32479 @var{task-id} parameter is present, or about all Ada tasks.
32480
32481 @subsubheading @value{GDBN} Command
32482
32483 The @samp{info tasks} command prints the same information
32484 about all Ada tasks (@pxref{Ada Tasks}).
32485
32486 @subsubheading Result
32487
32488 The result is a table of Ada tasks. The following columns are
32489 defined for each Ada task:
32490
32491 @table @samp
32492 @item current
32493 This field exists only for the current thread. It has the value @samp{*}.
32494
32495 @item id
32496 The identifier that @value{GDBN} uses to refer to the Ada task.
32497
32498 @item task-id
32499 The identifier that the target uses to refer to the Ada task.
32500
32501 @item thread-id
32502 The global thread identifier of the thread corresponding to the Ada
32503 task.
32504
32505 This field should always exist, as Ada tasks are always implemented
32506 on top of a thread. But if @value{GDBN} cannot find this corresponding
32507 thread for any reason, the field is omitted.
32508
32509 @item parent-id
32510 This field exists only when the task was created by another task.
32511 In this case, it provides the ID of the parent task.
32512
32513 @item priority
32514 The base priority of the task.
32515
32516 @item state
32517 The current state of the task. For a detailed description of the
32518 possible states, see @ref{Ada Tasks}.
32519
32520 @item name
32521 The name of the task.
32522
32523 @end table
32524
32525 @subsubheading Example
32526
32527 @smallexample
32528 -ada-task-info
32529 ^done,tasks=@{nr_rows="3",nr_cols="8",
32530 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
32531 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
32532 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
32533 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
32534 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
32535 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
32536 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
32537 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
32538 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
32539 state="Child Termination Wait",name="main_task"@}]@}
32540 (gdb)
32541 @end smallexample
32542
32543 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32544 @node GDB/MI Program Execution
32545 @section @sc{gdb/mi} Program Execution
32546
32547 These are the asynchronous commands which generate the out-of-band
32548 record @samp{*stopped}. Currently @value{GDBN} only really executes
32549 asynchronously with remote targets and this interaction is mimicked in
32550 other cases.
32551
32552 @subheading The @code{-exec-continue} Command
32553 @findex -exec-continue
32554
32555 @subsubheading Synopsis
32556
32557 @smallexample
32558 -exec-continue [--reverse] [--all|--thread-group N]
32559 @end smallexample
32560
32561 Resumes the execution of the inferior program, which will continue
32562 to execute until it reaches a debugger stop event. If the
32563 @samp{--reverse} option is specified, execution resumes in reverse until
32564 it reaches a stop event. Stop events may include
32565 @itemize @bullet
32566 @item
32567 breakpoints or watchpoints
32568 @item
32569 signals or exceptions
32570 @item
32571 the end of the process (or its beginning under @samp{--reverse})
32572 @item
32573 the end or beginning of a replay log if one is being used.
32574 @end itemize
32575 In all-stop mode (@pxref{All-Stop
32576 Mode}), may resume only one thread, or all threads, depending on the
32577 value of the @samp{scheduler-locking} variable. If @samp{--all} is
32578 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
32579 ignored in all-stop mode. If the @samp{--thread-group} options is
32580 specified, then all threads in that thread group are resumed.
32581
32582 @subsubheading @value{GDBN} Command
32583
32584 The corresponding @value{GDBN} corresponding is @samp{continue}.
32585
32586 @subsubheading Example
32587
32588 @smallexample
32589 -exec-continue
32590 ^running
32591 (gdb)
32592 @@Hello world
32593 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
32594 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
32595 line="13",arch="i386:x86_64"@}
32596 (gdb)
32597 @end smallexample
32598
32599
32600 @subheading The @code{-exec-finish} Command
32601 @findex -exec-finish
32602
32603 @subsubheading Synopsis
32604
32605 @smallexample
32606 -exec-finish [--reverse]
32607 @end smallexample
32608
32609 Resumes the execution of the inferior program until the current
32610 function is exited. Displays the results returned by the function.
32611 If the @samp{--reverse} option is specified, resumes the reverse
32612 execution of the inferior program until the point where current
32613 function was called.
32614
32615 @subsubheading @value{GDBN} Command
32616
32617 The corresponding @value{GDBN} command is @samp{finish}.
32618
32619 @subsubheading Example
32620
32621 Function returning @code{void}.
32622
32623 @smallexample
32624 -exec-finish
32625 ^running
32626 (gdb)
32627 @@hello from foo
32628 *stopped,reason="function-finished",frame=@{func="main",args=[],
32629 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
32630 (gdb)
32631 @end smallexample
32632
32633 Function returning other than @code{void}. The name of the internal
32634 @value{GDBN} variable storing the result is printed, together with the
32635 value itself.
32636
32637 @smallexample
32638 -exec-finish
32639 ^running
32640 (gdb)
32641 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
32642 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
32643 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32644 arch="i386:x86_64"@},
32645 gdb-result-var="$1",return-value="0"
32646 (gdb)
32647 @end smallexample
32648
32649
32650 @subheading The @code{-exec-interrupt} Command
32651 @findex -exec-interrupt
32652
32653 @subsubheading Synopsis
32654
32655 @smallexample
32656 -exec-interrupt [--all|--thread-group N]
32657 @end smallexample
32658
32659 Interrupts the background execution of the target. Note how the token
32660 associated with the stop message is the one for the execution command
32661 that has been interrupted. The token for the interrupt itself only
32662 appears in the @samp{^done} output. If the user is trying to
32663 interrupt a non-running program, an error message will be printed.
32664
32665 Note that when asynchronous execution is enabled, this command is
32666 asynchronous just like other execution commands. That is, first the
32667 @samp{^done} response will be printed, and the target stop will be
32668 reported after that using the @samp{*stopped} notification.
32669
32670 In non-stop mode, only the context thread is interrupted by default.
32671 All threads (in all inferiors) will be interrupted if the
32672 @samp{--all} option is specified. If the @samp{--thread-group}
32673 option is specified, all threads in that group will be interrupted.
32674
32675 @subsubheading @value{GDBN} Command
32676
32677 The corresponding @value{GDBN} command is @samp{interrupt}.
32678
32679 @subsubheading Example
32680
32681 @smallexample
32682 (gdb)
32683 111-exec-continue
32684 111^running
32685
32686 (gdb)
32687 222-exec-interrupt
32688 222^done
32689 (gdb)
32690 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
32691 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
32692 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
32693 (gdb)
32694
32695 (gdb)
32696 -exec-interrupt
32697 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
32698 (gdb)
32699 @end smallexample
32700
32701 @subheading The @code{-exec-jump} Command
32702 @findex -exec-jump
32703
32704 @subsubheading Synopsis
32705
32706 @smallexample
32707 -exec-jump @var{locspec}
32708 @end smallexample
32709
32710 Resumes execution of the inferior program at the address to
32711 which @var{locspec} resolves. @xref{Location Specifications},
32712 for a description of the different forms of @var{locspec}.
32713
32714 @subsubheading @value{GDBN} Command
32715
32716 The corresponding @value{GDBN} command is @samp{jump}.
32717
32718 @subsubheading Example
32719
32720 @smallexample
32721 -exec-jump foo.c:10
32722 *running,thread-id="all"
32723 ^running
32724 @end smallexample
32725
32726
32727 @subheading The @code{-exec-next} Command
32728 @findex -exec-next
32729
32730 @subsubheading Synopsis
32731
32732 @smallexample
32733 -exec-next [--reverse]
32734 @end smallexample
32735
32736 Resumes execution of the inferior program, stopping when the beginning
32737 of the next source line is reached.
32738
32739 If the @samp{--reverse} option is specified, resumes reverse execution
32740 of the inferior program, stopping at the beginning of the previous
32741 source line. If you issue this command on the first line of a
32742 function, it will take you back to the caller of that function, to the
32743 source line where the function was called.
32744
32745
32746 @subsubheading @value{GDBN} Command
32747
32748 The corresponding @value{GDBN} command is @samp{next}.
32749
32750 @subsubheading Example
32751
32752 @smallexample
32753 -exec-next
32754 ^running
32755 (gdb)
32756 *stopped,reason="end-stepping-range",line="8",file="hello.c"
32757 (gdb)
32758 @end smallexample
32759
32760
32761 @subheading The @code{-exec-next-instruction} Command
32762 @findex -exec-next-instruction
32763
32764 @subsubheading Synopsis
32765
32766 @smallexample
32767 -exec-next-instruction [--reverse]
32768 @end smallexample
32769
32770 Executes one machine instruction. If the instruction is a function
32771 call, continues until the function returns. If the program stops at an
32772 instruction in the middle of a source line, the address will be
32773 printed as well.
32774
32775 If the @samp{--reverse} option is specified, resumes reverse execution
32776 of the inferior program, stopping at the previous instruction. If the
32777 previously executed instruction was a return from another function,
32778 it will continue to execute in reverse until the call to that function
32779 (from the current stack frame) is reached.
32780
32781 @subsubheading @value{GDBN} Command
32782
32783 The corresponding @value{GDBN} command is @samp{nexti}.
32784
32785 @subsubheading Example
32786
32787 @smallexample
32788 (gdb)
32789 -exec-next-instruction
32790 ^running
32791
32792 (gdb)
32793 *stopped,reason="end-stepping-range",
32794 addr="0x000100d4",line="5",file="hello.c"
32795 (gdb)
32796 @end smallexample
32797
32798
32799 @subheading The @code{-exec-return} Command
32800 @findex -exec-return
32801
32802 @subsubheading Synopsis
32803
32804 @smallexample
32805 -exec-return
32806 @end smallexample
32807
32808 Makes current function return immediately. Doesn't execute the inferior.
32809 Displays the new current frame.
32810
32811 @subsubheading @value{GDBN} Command
32812
32813 The corresponding @value{GDBN} command is @samp{return}.
32814
32815 @subsubheading Example
32816
32817 @smallexample
32818 (gdb)
32819 200-break-insert callee4
32820 200^done,bkpt=@{number="1",addr="0x00010734",
32821 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
32822 (gdb)
32823 000-exec-run
32824 000^running
32825 (gdb)
32826 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32827 frame=@{func="callee4",args=[],
32828 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32829 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32830 arch="i386:x86_64"@}
32831 (gdb)
32832 205-break-delete
32833 205^done
32834 (gdb)
32835 111-exec-return
32836 111^done,frame=@{level="0",func="callee3",
32837 args=[@{name="strarg",
32838 value="0x11940 \"A string argument.\""@}],
32839 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32840 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32841 arch="i386:x86_64"@}
32842 (gdb)
32843 @end smallexample
32844
32845
32846 @subheading The @code{-exec-run} Command
32847 @findex -exec-run
32848
32849 @subsubheading Synopsis
32850
32851 @smallexample
32852 -exec-run [ --all | --thread-group N ] [ --start ]
32853 @end smallexample
32854
32855 Starts execution of the inferior from the beginning. The inferior
32856 executes until either a breakpoint is encountered or the program
32857 exits. In the latter case the output will include an exit code, if
32858 the program has exited exceptionally.
32859
32860 When neither the @samp{--all} nor the @samp{--thread-group} option
32861 is specified, the current inferior is started. If the
32862 @samp{--thread-group} option is specified, it should refer to a thread
32863 group of type @samp{process}, and that thread group will be started.
32864 If the @samp{--all} option is specified, then all inferiors will be started.
32865
32866 Using the @samp{--start} option instructs the debugger to stop
32867 the execution at the start of the inferior's main subprogram,
32868 following the same behavior as the @code{start} command
32869 (@pxref{Starting}).
32870
32871 @subsubheading @value{GDBN} Command
32872
32873 The corresponding @value{GDBN} command is @samp{run}.
32874
32875 @subsubheading Examples
32876
32877 @smallexample
32878 (gdb)
32879 -break-insert main
32880 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
32881 (gdb)
32882 -exec-run
32883 ^running
32884 (gdb)
32885 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32886 frame=@{func="main",args=[],file="recursive2.c",
32887 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
32888 (gdb)
32889 @end smallexample
32890
32891 @noindent
32892 Program exited normally:
32893
32894 @smallexample
32895 (gdb)
32896 -exec-run
32897 ^running
32898 (gdb)
32899 x = 55
32900 *stopped,reason="exited-normally"
32901 (gdb)
32902 @end smallexample
32903
32904 @noindent
32905 Program exited exceptionally:
32906
32907 @smallexample
32908 (gdb)
32909 -exec-run
32910 ^running
32911 (gdb)
32912 x = 55
32913 *stopped,reason="exited",exit-code="01"
32914 (gdb)
32915 @end smallexample
32916
32917 Another way the program can terminate is if it receives a signal such as
32918 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
32919
32920 @smallexample
32921 (gdb)
32922 *stopped,reason="exited-signalled",signal-name="SIGINT",
32923 signal-meaning="Interrupt"
32924 @end smallexample
32925
32926
32927 @c @subheading -exec-signal
32928
32929
32930 @subheading The @code{-exec-step} Command
32931 @findex -exec-step
32932
32933 @subsubheading Synopsis
32934
32935 @smallexample
32936 -exec-step [--reverse]
32937 @end smallexample
32938
32939 Resumes execution of the inferior program, stopping when the beginning
32940 of the next source line is reached, if the next source line is not a
32941 function call. If it is, stop at the first instruction of the called
32942 function. If the @samp{--reverse} option is specified, resumes reverse
32943 execution of the inferior program, stopping at the beginning of the
32944 previously executed source line.
32945
32946 @subsubheading @value{GDBN} Command
32947
32948 The corresponding @value{GDBN} command is @samp{step}.
32949
32950 @subsubheading Example
32951
32952 Stepping into a function:
32953
32954 @smallexample
32955 -exec-step
32956 ^running
32957 (gdb)
32958 *stopped,reason="end-stepping-range",
32959 frame=@{func="foo",args=[@{name="a",value="10"@},
32960 @{name="b",value="0"@}],file="recursive2.c",
32961 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
32962 (gdb)
32963 @end smallexample
32964
32965 Regular stepping:
32966
32967 @smallexample
32968 -exec-step
32969 ^running
32970 (gdb)
32971 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
32972 (gdb)
32973 @end smallexample
32974
32975
32976 @subheading The @code{-exec-step-instruction} Command
32977 @findex -exec-step-instruction
32978
32979 @subsubheading Synopsis
32980
32981 @smallexample
32982 -exec-step-instruction [--reverse]
32983 @end smallexample
32984
32985 Resumes the inferior which executes one machine instruction. If the
32986 @samp{--reverse} option is specified, resumes reverse execution of the
32987 inferior program, stopping at the previously executed instruction.
32988 The output, once @value{GDBN} has stopped, will vary depending on
32989 whether we have stopped in the middle of a source line or not. In the
32990 former case, the address at which the program stopped will be printed
32991 as well.
32992
32993 @subsubheading @value{GDBN} Command
32994
32995 The corresponding @value{GDBN} command is @samp{stepi}.
32996
32997 @subsubheading Example
32998
32999 @smallexample
33000 (gdb)
33001 -exec-step-instruction
33002 ^running
33003
33004 (gdb)
33005 *stopped,reason="end-stepping-range",
33006 frame=@{func="foo",args=[],file="try.c",
33007 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
33008 (gdb)
33009 -exec-step-instruction
33010 ^running
33011
33012 (gdb)
33013 *stopped,reason="end-stepping-range",
33014 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
33015 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
33016 (gdb)
33017 @end smallexample
33018
33019
33020 @subheading The @code{-exec-until} Command
33021 @findex -exec-until
33022
33023 @subsubheading Synopsis
33024
33025 @smallexample
33026 -exec-until [ @var{locspec} ]
33027 @end smallexample
33028
33029 Executes the inferior until it reaches the address to which
33030 @var{locspec} resolves. If there is no argument, the inferior
33031 executes until it reaches a source line greater than the current one.
33032 The reason for stopping in this case will be @samp{location-reached}.
33033
33034 @subsubheading @value{GDBN} Command
33035
33036 The corresponding @value{GDBN} command is @samp{until}.
33037
33038 @subsubheading Example
33039
33040 @smallexample
33041 (gdb)
33042 -exec-until recursive2.c:6
33043 ^running
33044 (gdb)
33045 x = 55
33046 *stopped,reason="location-reached",frame=@{func="main",args=[],
33047 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
33048 arch="i386:x86_64"@}
33049 (gdb)
33050 @end smallexample
33051
33052 @ignore
33053 @subheading -file-clear
33054 Is this going away????
33055 @end ignore
33056
33057 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33058 @node GDB/MI Stack Manipulation
33059 @section @sc{gdb/mi} Stack Manipulation Commands
33060
33061 @subheading The @code{-enable-frame-filters} Command
33062 @findex -enable-frame-filters
33063
33064 @smallexample
33065 -enable-frame-filters
33066 @end smallexample
33067
33068 @value{GDBN} allows Python-based frame filters to affect the output of
33069 the MI commands relating to stack traces. As there is no way to
33070 implement this in a fully backward-compatible way, a front end must
33071 request that this functionality be enabled.
33072
33073 Once enabled, this feature cannot be disabled.
33074
33075 Note that if Python support has not been compiled into @value{GDBN},
33076 this command will still succeed (and do nothing).
33077
33078 @subheading The @code{-stack-info-frame} Command
33079 @findex -stack-info-frame
33080
33081 @subsubheading Synopsis
33082
33083 @smallexample
33084 -stack-info-frame
33085 @end smallexample
33086
33087 Get info on the selected frame.
33088
33089 @subsubheading @value{GDBN} Command
33090
33091 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
33092 (without arguments).
33093
33094 @subsubheading Example
33095
33096 @smallexample
33097 (gdb)
33098 -stack-info-frame
33099 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
33100 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33101 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
33102 arch="i386:x86_64"@}
33103 (gdb)
33104 @end smallexample
33105
33106 @subheading The @code{-stack-info-depth} Command
33107 @findex -stack-info-depth
33108
33109 @subsubheading Synopsis
33110
33111 @smallexample
33112 -stack-info-depth [ @var{max-depth} ]
33113 @end smallexample
33114
33115 Return the depth of the stack. If the integer argument @var{max-depth}
33116 is specified, do not count beyond @var{max-depth} frames.
33117
33118 @subsubheading @value{GDBN} Command
33119
33120 There's no equivalent @value{GDBN} command.
33121
33122 @subsubheading Example
33123
33124 For a stack with frame levels 0 through 11:
33125
33126 @smallexample
33127 (gdb)
33128 -stack-info-depth
33129 ^done,depth="12"
33130 (gdb)
33131 -stack-info-depth 4
33132 ^done,depth="4"
33133 (gdb)
33134 -stack-info-depth 12
33135 ^done,depth="12"
33136 (gdb)
33137 -stack-info-depth 11
33138 ^done,depth="11"
33139 (gdb)
33140 -stack-info-depth 13
33141 ^done,depth="12"
33142 (gdb)
33143 @end smallexample
33144
33145 @anchor{-stack-list-arguments}
33146 @subheading The @code{-stack-list-arguments} Command
33147 @findex -stack-list-arguments
33148
33149 @subsubheading Synopsis
33150
33151 @smallexample
33152 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33153 [ @var{low-frame} @var{high-frame} ]
33154 @end smallexample
33155
33156 Display a list of the arguments for the frames between @var{low-frame}
33157 and @var{high-frame} (inclusive). If @var{low-frame} and
33158 @var{high-frame} are not provided, list the arguments for the whole
33159 call stack. If the two arguments are equal, show the single frame
33160 at the corresponding level. It is an error if @var{low-frame} is
33161 larger than the actual number of frames. On the other hand,
33162 @var{high-frame} may be larger than the actual number of frames, in
33163 which case only existing frames will be returned.
33164
33165 If @var{print-values} is 0 or @code{--no-values}, print only the names of
33166 the variables; if it is 1 or @code{--all-values}, print also their
33167 values; and if it is 2 or @code{--simple-values}, print the name,
33168 type and value for simple data types, and the name and type for arrays,
33169 structures and unions. If the option @code{--no-frame-filters} is
33170 supplied, then Python frame filters will not be executed.
33171
33172 If the @code{--skip-unavailable} option is specified, arguments that
33173 are not available are not listed. Partially available arguments
33174 are still displayed, however.
33175
33176 Use of this command to obtain arguments in a single frame is
33177 deprecated in favor of the @samp{-stack-list-variables} command.
33178
33179 @subsubheading @value{GDBN} Command
33180
33181 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
33182 @samp{gdb_get_args} command which partially overlaps with the
33183 functionality of @samp{-stack-list-arguments}.
33184
33185 @subsubheading Example
33186
33187 @smallexample
33188 (gdb)
33189 -stack-list-frames
33190 ^done,
33191 stack=[
33192 frame=@{level="0",addr="0x00010734",func="callee4",
33193 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33194 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
33195 arch="i386:x86_64"@},
33196 frame=@{level="1",addr="0x0001076c",func="callee3",
33197 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33198 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
33199 arch="i386:x86_64"@},
33200 frame=@{level="2",addr="0x0001078c",func="callee2",
33201 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33202 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
33203 arch="i386:x86_64"@},
33204 frame=@{level="3",addr="0x000107b4",func="callee1",
33205 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33206 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
33207 arch="i386:x86_64"@},
33208 frame=@{level="4",addr="0x000107e0",func="main",
33209 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
33210 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
33211 arch="i386:x86_64"@}]
33212 (gdb)
33213 -stack-list-arguments 0
33214 ^done,
33215 stack-args=[
33216 frame=@{level="0",args=[]@},
33217 frame=@{level="1",args=[name="strarg"]@},
33218 frame=@{level="2",args=[name="intarg",name="strarg"]@},
33219 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
33220 frame=@{level="4",args=[]@}]
33221 (gdb)
33222 -stack-list-arguments 1
33223 ^done,
33224 stack-args=[
33225 frame=@{level="0",args=[]@},
33226 frame=@{level="1",
33227 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
33228 frame=@{level="2",args=[
33229 @{name="intarg",value="2"@},
33230 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
33231 @{frame=@{level="3",args=[
33232 @{name="intarg",value="2"@},
33233 @{name="strarg",value="0x11940 \"A string argument.\""@},
33234 @{name="fltarg",value="3.5"@}]@},
33235 frame=@{level="4",args=[]@}]
33236 (gdb)
33237 -stack-list-arguments 0 2 2
33238 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
33239 (gdb)
33240 -stack-list-arguments 1 2 2
33241 ^done,stack-args=[frame=@{level="2",
33242 args=[@{name="intarg",value="2"@},
33243 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
33244 (gdb)
33245 @end smallexample
33246
33247 @c @subheading -stack-list-exception-handlers
33248
33249
33250 @anchor{-stack-list-frames}
33251 @subheading The @code{-stack-list-frames} Command
33252 @findex -stack-list-frames
33253
33254 @subsubheading Synopsis
33255
33256 @smallexample
33257 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
33258 @end smallexample
33259
33260 List the frames currently on the stack. For each frame it displays the
33261 following info:
33262
33263 @table @samp
33264 @item @var{level}
33265 The frame number, 0 being the topmost frame, i.e., the innermost function.
33266 @item @var{addr}
33267 The @code{$pc} value for that frame.
33268 @item @var{func}
33269 Function name.
33270 @item @var{file}
33271 File name of the source file where the function lives.
33272 @item @var{fullname}
33273 The full file name of the source file where the function lives.
33274 @item @var{line}
33275 Line number corresponding to the @code{$pc}.
33276 @item @var{from}
33277 The shared library where this function is defined. This is only given
33278 if the frame's function is not known.
33279 @item @var{arch}
33280 Frame's architecture.
33281 @end table
33282
33283 If invoked without arguments, this command prints a backtrace for the
33284 whole stack. If given two integer arguments, it shows the frames whose
33285 levels are between the two arguments (inclusive). If the two arguments
33286 are equal, it shows the single frame at the corresponding level. It is
33287 an error if @var{low-frame} is larger than the actual number of
33288 frames. On the other hand, @var{high-frame} may be larger than the
33289 actual number of frames, in which case only existing frames will be
33290 returned. If the option @code{--no-frame-filters} is supplied, then
33291 Python frame filters will not be executed.
33292
33293 @subsubheading @value{GDBN} Command
33294
33295 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
33296
33297 @subsubheading Example
33298
33299 Full stack backtrace:
33300
33301 @smallexample
33302 (gdb)
33303 -stack-list-frames
33304 ^done,stack=
33305 [frame=@{level="0",addr="0x0001076c",func="foo",
33306 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
33307 arch="i386:x86_64"@},
33308 frame=@{level="1",addr="0x000107a4",func="foo",
33309 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33310 arch="i386:x86_64"@},
33311 frame=@{level="2",addr="0x000107a4",func="foo",
33312 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33313 arch="i386:x86_64"@},
33314 frame=@{level="3",addr="0x000107a4",func="foo",
33315 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33316 arch="i386:x86_64"@},
33317 frame=@{level="4",addr="0x000107a4",func="foo",
33318 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33319 arch="i386:x86_64"@},
33320 frame=@{level="5",addr="0x000107a4",func="foo",
33321 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33322 arch="i386:x86_64"@},
33323 frame=@{level="6",addr="0x000107a4",func="foo",
33324 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33325 arch="i386:x86_64"@},
33326 frame=@{level="7",addr="0x000107a4",func="foo",
33327 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33328 arch="i386:x86_64"@},
33329 frame=@{level="8",addr="0x000107a4",func="foo",
33330 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33331 arch="i386:x86_64"@},
33332 frame=@{level="9",addr="0x000107a4",func="foo",
33333 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33334 arch="i386:x86_64"@},
33335 frame=@{level="10",addr="0x000107a4",func="foo",
33336 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33337 arch="i386:x86_64"@},
33338 frame=@{level="11",addr="0x00010738",func="main",
33339 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
33340 arch="i386:x86_64"@}]
33341 (gdb)
33342 @end smallexample
33343
33344 Show frames between @var{low_frame} and @var{high_frame}:
33345
33346 @smallexample
33347 (gdb)
33348 -stack-list-frames 3 5
33349 ^done,stack=
33350 [frame=@{level="3",addr="0x000107a4",func="foo",
33351 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33352 arch="i386:x86_64"@},
33353 frame=@{level="4",addr="0x000107a4",func="foo",
33354 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33355 arch="i386:x86_64"@},
33356 frame=@{level="5",addr="0x000107a4",func="foo",
33357 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33358 arch="i386:x86_64"@}]
33359 (gdb)
33360 @end smallexample
33361
33362 Show a single frame:
33363
33364 @smallexample
33365 (gdb)
33366 -stack-list-frames 3 3
33367 ^done,stack=
33368 [frame=@{level="3",addr="0x000107a4",func="foo",
33369 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
33370 arch="i386:x86_64"@}]
33371 (gdb)
33372 @end smallexample
33373
33374
33375 @subheading The @code{-stack-list-locals} Command
33376 @findex -stack-list-locals
33377 @anchor{-stack-list-locals}
33378
33379 @subsubheading Synopsis
33380
33381 @smallexample
33382 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33383 @end smallexample
33384
33385 Display the local variable names for the selected frame. If
33386 @var{print-values} is 0 or @code{--no-values}, print only the names of
33387 the variables; if it is 1 or @code{--all-values}, print also their
33388 values; and if it is 2 or @code{--simple-values}, print the name,
33389 type and value for simple data types, and the name and type for arrays,
33390 structures and unions. In this last case, a frontend can immediately
33391 display the value of simple data types and create variable objects for
33392 other data types when the user wishes to explore their values in
33393 more detail. If the option @code{--no-frame-filters} is supplied, then
33394 Python frame filters will not be executed.
33395
33396 If the @code{--skip-unavailable} option is specified, local variables
33397 that are not available are not listed. Partially available local
33398 variables are still displayed, however.
33399
33400 This command is deprecated in favor of the
33401 @samp{-stack-list-variables} command.
33402
33403 @subsubheading @value{GDBN} Command
33404
33405 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
33406
33407 @subsubheading Example
33408
33409 @smallexample
33410 (gdb)
33411 -stack-list-locals 0
33412 ^done,locals=[name="A",name="B",name="C"]
33413 (gdb)
33414 -stack-list-locals --all-values
33415 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
33416 @{name="C",value="@{1, 2, 3@}"@}]
33417 -stack-list-locals --simple-values
33418 ^done,locals=[@{name="A",type="int",value="1"@},
33419 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
33420 (gdb)
33421 @end smallexample
33422
33423 @anchor{-stack-list-variables}
33424 @subheading The @code{-stack-list-variables} Command
33425 @findex -stack-list-variables
33426
33427 @subsubheading Synopsis
33428
33429 @smallexample
33430 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33431 @end smallexample
33432
33433 Display the names of local variables and function arguments for the selected frame. If
33434 @var{print-values} is 0 or @code{--no-values}, print only the names of
33435 the variables; if it is 1 or @code{--all-values}, print also their
33436 values; and if it is 2 or @code{--simple-values}, print the name,
33437 type and value for simple data types, and the name and type for arrays,
33438 structures and unions. If the option @code{--no-frame-filters} is
33439 supplied, then Python frame filters will not be executed.
33440
33441 If the @code{--skip-unavailable} option is specified, local variables
33442 and arguments that are not available are not listed. Partially
33443 available arguments and local variables are still displayed, however.
33444
33445 @subsubheading Example
33446
33447 @smallexample
33448 (gdb)
33449 -stack-list-variables --thread 1 --frame 0 --all-values
33450 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
33451 (gdb)
33452 @end smallexample
33453
33454
33455 @subheading The @code{-stack-select-frame} Command
33456 @findex -stack-select-frame
33457
33458 @subsubheading Synopsis
33459
33460 @smallexample
33461 -stack-select-frame @var{framenum}
33462 @end smallexample
33463
33464 Change the selected frame. Select a different frame @var{framenum} on
33465 the stack.
33466
33467 This command in deprecated in favor of passing the @samp{--frame}
33468 option to every command.
33469
33470 @subsubheading @value{GDBN} Command
33471
33472 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
33473 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
33474
33475 @subsubheading Example
33476
33477 @smallexample
33478 (gdb)
33479 -stack-select-frame 2
33480 ^done
33481 (gdb)
33482 @end smallexample
33483
33484 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33485 @node GDB/MI Variable Objects
33486 @section @sc{gdb/mi} Variable Objects
33487
33488 @ignore
33489
33490 @subheading Motivation for Variable Objects in @sc{gdb/mi}
33491
33492 For the implementation of a variable debugger window (locals, watched
33493 expressions, etc.), we are proposing the adaptation of the existing code
33494 used by @code{Insight}.
33495
33496 The two main reasons for that are:
33497
33498 @enumerate 1
33499 @item
33500 It has been proven in practice (it is already on its second generation).
33501
33502 @item
33503 It will shorten development time (needless to say how important it is
33504 now).
33505 @end enumerate
33506
33507 The original interface was designed to be used by Tcl code, so it was
33508 slightly changed so it could be used through @sc{gdb/mi}. This section
33509 describes the @sc{gdb/mi} operations that will be available and gives some
33510 hints about their use.
33511
33512 @emph{Note}: In addition to the set of operations described here, we
33513 expect the @sc{gui} implementation of a variable window to require, at
33514 least, the following operations:
33515
33516 @itemize @bullet
33517 @item @code{-gdb-show} @code{output-radix}
33518 @item @code{-stack-list-arguments}
33519 @item @code{-stack-list-locals}
33520 @item @code{-stack-select-frame}
33521 @end itemize
33522
33523 @end ignore
33524
33525 @subheading Introduction to Variable Objects
33526
33527 @cindex variable objects in @sc{gdb/mi}
33528
33529 Variable objects are "object-oriented" MI interface for examining and
33530 changing values of expressions. Unlike some other MI interfaces that
33531 work with expressions, variable objects are specifically designed for
33532 simple and efficient presentation in the frontend. A variable object
33533 is identified by string name. When a variable object is created, the
33534 frontend specifies the expression for that variable object. The
33535 expression can be a simple variable, or it can be an arbitrary complex
33536 expression, and can even involve CPU registers. After creating a
33537 variable object, the frontend can invoke other variable object
33538 operations---for example to obtain or change the value of a variable
33539 object, or to change display format.
33540
33541 Variable objects have hierarchical tree structure. Any variable object
33542 that corresponds to a composite type, such as structure in C, has
33543 a number of child variable objects, for example corresponding to each
33544 element of a structure. A child variable object can itself have
33545 children, recursively. Recursion ends when we reach
33546 leaf variable objects, which always have built-in types. Child variable
33547 objects are created only by explicit request, so if a frontend
33548 is not interested in the children of a particular variable object, no
33549 child will be created.
33550
33551 For a leaf variable object it is possible to obtain its value as a
33552 string, or set the value from a string. String value can be also
33553 obtained for a non-leaf variable object, but it's generally a string
33554 that only indicates the type of the object, and does not list its
33555 contents. Assignment to a non-leaf variable object is not allowed.
33556
33557 A frontend does not need to read the values of all variable objects each time
33558 the program stops. Instead, MI provides an update command that lists all
33559 variable objects whose values has changed since the last update
33560 operation. This considerably reduces the amount of data that must
33561 be transferred to the frontend. As noted above, children variable
33562 objects are created on demand, and only leaf variable objects have a
33563 real value. As result, gdb will read target memory only for leaf
33564 variables that frontend has created.
33565
33566 The automatic update is not always desirable. For example, a frontend
33567 might want to keep a value of some expression for future reference,
33568 and never update it. For another example, fetching memory is
33569 relatively slow for embedded targets, so a frontend might want
33570 to disable automatic update for the variables that are either not
33571 visible on the screen, or ``closed''. This is possible using so
33572 called ``frozen variable objects''. Such variable objects are never
33573 implicitly updated.
33574
33575 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
33576 fixed variable object, the expression is parsed when the variable
33577 object is created, including associating identifiers to specific
33578 variables. The meaning of expression never changes. For a floating
33579 variable object the values of variables whose names appear in the
33580 expressions are re-evaluated every time in the context of the current
33581 frame. Consider this example:
33582
33583 @smallexample
33584 void do_work(...)
33585 @{
33586 struct work_state state;
33587
33588 if (...)
33589 do_work(...);
33590 @}
33591 @end smallexample
33592
33593 If a fixed variable object for the @code{state} variable is created in
33594 this function, and we enter the recursive call, the variable
33595 object will report the value of @code{state} in the top-level
33596 @code{do_work} invocation. On the other hand, a floating variable
33597 object will report the value of @code{state} in the current frame.
33598
33599 If an expression specified when creating a fixed variable object
33600 refers to a local variable, the variable object becomes bound to the
33601 thread and frame in which the variable object is created. When such
33602 variable object is updated, @value{GDBN} makes sure that the
33603 thread/frame combination the variable object is bound to still exists,
33604 and re-evaluates the variable object in context of that thread/frame.
33605
33606 The following is the complete set of @sc{gdb/mi} operations defined to
33607 access this functionality:
33608
33609 @multitable @columnfractions .4 .6
33610 @item @strong{Operation}
33611 @tab @strong{Description}
33612
33613 @item @code{-enable-pretty-printing}
33614 @tab enable Python-based pretty-printing
33615 @item @code{-var-create}
33616 @tab create a variable object
33617 @item @code{-var-delete}
33618 @tab delete the variable object and/or its children
33619 @item @code{-var-set-format}
33620 @tab set the display format of this variable
33621 @item @code{-var-show-format}
33622 @tab show the display format of this variable
33623 @item @code{-var-info-num-children}
33624 @tab tells how many children this object has
33625 @item @code{-var-list-children}
33626 @tab return a list of the object's children
33627 @item @code{-var-info-type}
33628 @tab show the type of this variable object
33629 @item @code{-var-info-expression}
33630 @tab print parent-relative expression that this variable object represents
33631 @item @code{-var-info-path-expression}
33632 @tab print full expression that this variable object represents
33633 @item @code{-var-show-attributes}
33634 @tab is this variable editable? does it exist here?
33635 @item @code{-var-evaluate-expression}
33636 @tab get the value of this variable
33637 @item @code{-var-assign}
33638 @tab set the value of this variable
33639 @item @code{-var-update}
33640 @tab update the variable and its children
33641 @item @code{-var-set-frozen}
33642 @tab set frozenness attribute
33643 @item @code{-var-set-update-range}
33644 @tab set range of children to display on update
33645 @end multitable
33646
33647 In the next subsection we describe each operation in detail and suggest
33648 how it can be used.
33649
33650 @subheading Description And Use of Operations on Variable Objects
33651
33652 @subheading The @code{-enable-pretty-printing} Command
33653 @findex -enable-pretty-printing
33654
33655 @smallexample
33656 -enable-pretty-printing
33657 @end smallexample
33658
33659 @value{GDBN} allows Python-based visualizers to affect the output of the
33660 MI variable object commands. However, because there was no way to
33661 implement this in a fully backward-compatible way, a front end must
33662 request that this functionality be enabled.
33663
33664 Once enabled, this feature cannot be disabled.
33665
33666 Note that if Python support has not been compiled into @value{GDBN},
33667 this command will still succeed (and do nothing).
33668
33669 @subheading The @code{-var-create} Command
33670 @findex -var-create
33671
33672 @subsubheading Synopsis
33673
33674 @smallexample
33675 -var-create @{@var{name} | "-"@}
33676 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
33677 @end smallexample
33678
33679 This operation creates a variable object, which allows the monitoring of
33680 a variable, the result of an expression, a memory cell or a CPU
33681 register.
33682
33683 The @var{name} parameter is the string by which the object can be
33684 referenced. It must be unique. If @samp{-} is specified, the varobj
33685 system will generate a string ``varNNNNNN'' automatically. It will be
33686 unique provided that one does not specify @var{name} of that format.
33687 The command fails if a duplicate name is found.
33688
33689 The frame under which the expression should be evaluated can be
33690 specified by @var{frame-addr}. A @samp{*} indicates that the current
33691 frame should be used. A @samp{@@} indicates that a floating variable
33692 object must be created.
33693
33694 @var{expression} is any expression valid on the current language set (must not
33695 begin with a @samp{*}), or one of the following:
33696
33697 @itemize @bullet
33698 @item
33699 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
33700
33701 @item
33702 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
33703
33704 @item
33705 @samp{$@var{regname}} --- a CPU register name
33706 @end itemize
33707
33708 @cindex dynamic varobj
33709 A varobj's contents may be provided by a Python-based pretty-printer. In this
33710 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
33711 have slightly different semantics in some cases. If the
33712 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
33713 will never create a dynamic varobj. This ensures backward
33714 compatibility for existing clients.
33715
33716 @subsubheading Result
33717
33718 This operation returns attributes of the newly-created varobj. These
33719 are:
33720
33721 @table @samp
33722 @item name
33723 The name of the varobj.
33724
33725 @item numchild
33726 The number of children of the varobj. This number is not necessarily
33727 reliable for a dynamic varobj. Instead, you must examine the
33728 @samp{has_more} attribute.
33729
33730 @item value
33731 The varobj's scalar value. For a varobj whose type is some sort of
33732 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
33733 will not be interesting.
33734
33735 @item type
33736 The varobj's type. This is a string representation of the type, as
33737 would be printed by the @value{GDBN} CLI. If @samp{print object}
33738 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33739 @emph{actual} (derived) type of the object is shown rather than the
33740 @emph{declared} one.
33741
33742 @item thread-id
33743 If a variable object is bound to a specific thread, then this is the
33744 thread's global identifier.
33745
33746 @item has_more
33747 For a dynamic varobj, this indicates whether there appear to be any
33748 children available. For a non-dynamic varobj, this will be 0.
33749
33750 @item dynamic
33751 This attribute will be present and have the value @samp{1} if the
33752 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33753 then this attribute will not be present.
33754
33755 @item displayhint
33756 A dynamic varobj can supply a display hint to the front end. The
33757 value comes directly from the Python pretty-printer object's
33758 @code{display_hint} method. @xref{Pretty Printing API}.
33759 @end table
33760
33761 Typical output will look like this:
33762
33763 @smallexample
33764 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
33765 has_more="@var{has_more}"
33766 @end smallexample
33767
33768
33769 @subheading The @code{-var-delete} Command
33770 @findex -var-delete
33771
33772 @subsubheading Synopsis
33773
33774 @smallexample
33775 -var-delete [ -c ] @var{name}
33776 @end smallexample
33777
33778 Deletes a previously created variable object and all of its children.
33779 With the @samp{-c} option, just deletes the children.
33780
33781 Returns an error if the object @var{name} is not found.
33782
33783
33784 @subheading The @code{-var-set-format} Command
33785 @findex -var-set-format
33786
33787 @subsubheading Synopsis
33788
33789 @smallexample
33790 -var-set-format @var{name} @var{format-spec}
33791 @end smallexample
33792
33793 Sets the output format for the value of the object @var{name} to be
33794 @var{format-spec}.
33795
33796 @anchor{-var-set-format}
33797 The syntax for the @var{format-spec} is as follows:
33798
33799 @smallexample
33800 @var{format-spec} @expansion{}
33801 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
33802 @end smallexample
33803
33804 The natural format is the default format choosen automatically
33805 based on the variable type (like decimal for an @code{int}, hex
33806 for pointers, etc.).
33807
33808 The zero-hexadecimal format has a representation similar to hexadecimal
33809 but with padding zeroes to the left of the value. For example, a 32-bit
33810 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
33811 zero-hexadecimal format.
33812
33813 For a variable with children, the format is set only on the
33814 variable itself, and the children are not affected.
33815
33816 @subheading The @code{-var-show-format} Command
33817 @findex -var-show-format
33818
33819 @subsubheading Synopsis
33820
33821 @smallexample
33822 -var-show-format @var{name}
33823 @end smallexample
33824
33825 Returns the format used to display the value of the object @var{name}.
33826
33827 @smallexample
33828 @var{format} @expansion{}
33829 @var{format-spec}
33830 @end smallexample
33831
33832
33833 @subheading The @code{-var-info-num-children} Command
33834 @findex -var-info-num-children
33835
33836 @subsubheading Synopsis
33837
33838 @smallexample
33839 -var-info-num-children @var{name}
33840 @end smallexample
33841
33842 Returns the number of children of a variable object @var{name}:
33843
33844 @smallexample
33845 numchild=@var{n}
33846 @end smallexample
33847
33848 Note that this number is not completely reliable for a dynamic varobj.
33849 It will return the current number of children, but more children may
33850 be available.
33851
33852
33853 @subheading The @code{-var-list-children} Command
33854 @findex -var-list-children
33855
33856 @subsubheading Synopsis
33857
33858 @smallexample
33859 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
33860 @end smallexample
33861 @anchor{-var-list-children}
33862
33863 Return a list of the children of the specified variable object and
33864 create variable objects for them, if they do not already exist. With
33865 a single argument or if @var{print-values} has a value of 0 or
33866 @code{--no-values}, print only the names of the variables; if
33867 @var{print-values} is 1 or @code{--all-values}, also print their
33868 values; and if it is 2 or @code{--simple-values} print the name and
33869 value for simple data types and just the name for arrays, structures
33870 and unions.
33871
33872 @var{from} and @var{to}, if specified, indicate the range of children
33873 to report. If @var{from} or @var{to} is less than zero, the range is
33874 reset and all children will be reported. Otherwise, children starting
33875 at @var{from} (zero-based) and up to and excluding @var{to} will be
33876 reported.
33877
33878 If a child range is requested, it will only affect the current call to
33879 @code{-var-list-children}, but not future calls to @code{-var-update}.
33880 For this, you must instead use @code{-var-set-update-range}. The
33881 intent of this approach is to enable a front end to implement any
33882 update approach it likes; for example, scrolling a view may cause the
33883 front end to request more children with @code{-var-list-children}, and
33884 then the front end could call @code{-var-set-update-range} with a
33885 different range to ensure that future updates are restricted to just
33886 the visible items.
33887
33888 For each child the following results are returned:
33889
33890 @table @var
33891
33892 @item name
33893 Name of the variable object created for this child.
33894
33895 @item exp
33896 The expression to be shown to the user by the front end to designate this child.
33897 For example this may be the name of a structure member.
33898
33899 For a dynamic varobj, this value cannot be used to form an
33900 expression. There is no way to do this at all with a dynamic varobj.
33901
33902 For C/C@t{++} structures there are several pseudo children returned to
33903 designate access qualifiers. For these pseudo children @var{exp} is
33904 @samp{public}, @samp{private}, or @samp{protected}. In this case the
33905 type and value are not present.
33906
33907 A dynamic varobj will not report the access qualifying
33908 pseudo-children, regardless of the language. This information is not
33909 available at all with a dynamic varobj.
33910
33911 @item numchild
33912 Number of children this child has. For a dynamic varobj, this will be
33913 0.
33914
33915 @item type
33916 The type of the child. If @samp{print object}
33917 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33918 @emph{actual} (derived) type of the object is shown rather than the
33919 @emph{declared} one.
33920
33921 @item value
33922 If values were requested, this is the value.
33923
33924 @item thread-id
33925 If this variable object is associated with a thread, this is the
33926 thread's global thread id. Otherwise this result is not present.
33927
33928 @item frozen
33929 If the variable object is frozen, this variable will be present with a value of 1.
33930
33931 @item displayhint
33932 A dynamic varobj can supply a display hint to the front end. The
33933 value comes directly from the Python pretty-printer object's
33934 @code{display_hint} method. @xref{Pretty Printing API}.
33935
33936 @item dynamic
33937 This attribute will be present and have the value @samp{1} if the
33938 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33939 then this attribute will not be present.
33940
33941 @end table
33942
33943 The result may have its own attributes:
33944
33945 @table @samp
33946 @item displayhint
33947 A dynamic varobj can supply a display hint to the front end. The
33948 value comes directly from the Python pretty-printer object's
33949 @code{display_hint} method. @xref{Pretty Printing API}.
33950
33951 @item has_more
33952 This is an integer attribute which is nonzero if there are children
33953 remaining after the end of the selected range.
33954 @end table
33955
33956 @subsubheading Example
33957
33958 @smallexample
33959 (gdb)
33960 -var-list-children n
33961 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33962 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
33963 (gdb)
33964 -var-list-children --all-values n
33965 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33966 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
33967 @end smallexample
33968
33969
33970 @subheading The @code{-var-info-type} Command
33971 @findex -var-info-type
33972
33973 @subsubheading Synopsis
33974
33975 @smallexample
33976 -var-info-type @var{name}
33977 @end smallexample
33978
33979 Returns the type of the specified variable @var{name}. The type is
33980 returned as a string in the same format as it is output by the
33981 @value{GDBN} CLI:
33982
33983 @smallexample
33984 type=@var{typename}
33985 @end smallexample
33986
33987
33988 @subheading The @code{-var-info-expression} Command
33989 @findex -var-info-expression
33990
33991 @subsubheading Synopsis
33992
33993 @smallexample
33994 -var-info-expression @var{name}
33995 @end smallexample
33996
33997 Returns a string that is suitable for presenting this
33998 variable object in user interface. The string is generally
33999 not valid expression in the current language, and cannot be evaluated.
34000
34001 For example, if @code{a} is an array, and variable object
34002 @code{A} was created for @code{a}, then we'll get this output:
34003
34004 @smallexample
34005 (gdb) -var-info-expression A.1
34006 ^done,lang="C",exp="1"
34007 @end smallexample
34008
34009 @noindent
34010 Here, the value of @code{lang} is the language name, which can be
34011 found in @ref{Supported Languages}.
34012
34013 Note that the output of the @code{-var-list-children} command also
34014 includes those expressions, so the @code{-var-info-expression} command
34015 is of limited use.
34016
34017 @subheading The @code{-var-info-path-expression} Command
34018 @findex -var-info-path-expression
34019
34020 @subsubheading Synopsis
34021
34022 @smallexample
34023 -var-info-path-expression @var{name}
34024 @end smallexample
34025
34026 Returns an expression that can be evaluated in the current
34027 context and will yield the same value that a variable object has.
34028 Compare this with the @code{-var-info-expression} command, which
34029 result can be used only for UI presentation. Typical use of
34030 the @code{-var-info-path-expression} command is creating a
34031 watchpoint from a variable object.
34032
34033 This command is currently not valid for children of a dynamic varobj,
34034 and will give an error when invoked on one.
34035
34036 For example, suppose @code{C} is a C@t{++} class, derived from class
34037 @code{Base}, and that the @code{Base} class has a member called
34038 @code{m_size}. Assume a variable @code{c} is has the type of
34039 @code{C} and a variable object @code{C} was created for variable
34040 @code{c}. Then, we'll get this output:
34041 @smallexample
34042 (gdb) -var-info-path-expression C.Base.public.m_size
34043 ^done,path_expr=((Base)c).m_size)
34044 @end smallexample
34045
34046 @subheading The @code{-var-show-attributes} Command
34047 @findex -var-show-attributes
34048
34049 @subsubheading Synopsis
34050
34051 @smallexample
34052 -var-show-attributes @var{name}
34053 @end smallexample
34054
34055 List attributes of the specified variable object @var{name}:
34056
34057 @smallexample
34058 status=@var{attr} [ ( ,@var{attr} )* ]
34059 @end smallexample
34060
34061 @noindent
34062 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
34063
34064 @subheading The @code{-var-evaluate-expression} Command
34065 @findex -var-evaluate-expression
34066
34067 @subsubheading Synopsis
34068
34069 @smallexample
34070 -var-evaluate-expression [-f @var{format-spec}] @var{name}
34071 @end smallexample
34072
34073 Evaluates the expression that is represented by the specified variable
34074 object and returns its value as a string. The format of the string
34075 can be specified with the @samp{-f} option. The possible values of
34076 this option are the same as for @code{-var-set-format}
34077 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
34078 the current display format will be used. The current display format
34079 can be changed using the @code{-var-set-format} command.
34080
34081 @smallexample
34082 value=@var{value}
34083 @end smallexample
34084
34085 Note that one must invoke @code{-var-list-children} for a variable
34086 before the value of a child variable can be evaluated.
34087
34088 @subheading The @code{-var-assign} Command
34089 @findex -var-assign
34090
34091 @subsubheading Synopsis
34092
34093 @smallexample
34094 -var-assign @var{name} @var{expression}
34095 @end smallexample
34096
34097 Assigns the value of @var{expression} to the variable object specified
34098 by @var{name}. The object must be @samp{editable}. If the variable's
34099 value is altered by the assign, the variable will show up in any
34100 subsequent @code{-var-update} list.
34101
34102 @subsubheading Example
34103
34104 @smallexample
34105 (gdb)
34106 -var-assign var1 3
34107 ^done,value="3"
34108 (gdb)
34109 -var-update *
34110 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
34111 (gdb)
34112 @end smallexample
34113
34114 @subheading The @code{-var-update} Command
34115 @findex -var-update
34116
34117 @subsubheading Synopsis
34118
34119 @smallexample
34120 -var-update [@var{print-values}] @{@var{name} | "*"@}
34121 @end smallexample
34122
34123 Reevaluate the expressions corresponding to the variable object
34124 @var{name} and all its direct and indirect children, and return the
34125 list of variable objects whose values have changed; @var{name} must
34126 be a root variable object. Here, ``changed'' means that the result of
34127 @code{-var-evaluate-expression} before and after the
34128 @code{-var-update} is different. If @samp{*} is used as the variable
34129 object names, all existing variable objects are updated, except
34130 for frozen ones (@pxref{-var-set-frozen}). The option
34131 @var{print-values} determines whether both names and values, or just
34132 names are printed. The possible values of this option are the same
34133 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
34134 recommended to use the @samp{--all-values} option, to reduce the
34135 number of MI commands needed on each program stop.
34136
34137 With the @samp{*} parameter, if a variable object is bound to a
34138 currently running thread, it will not be updated, without any
34139 diagnostic.
34140
34141 If @code{-var-set-update-range} was previously used on a varobj, then
34142 only the selected range of children will be reported.
34143
34144 @code{-var-update} reports all the changed varobjs in a tuple named
34145 @samp{changelist}.
34146
34147 Each item in the change list is itself a tuple holding:
34148
34149 @table @samp
34150 @item name
34151 The name of the varobj.
34152
34153 @item value
34154 If values were requested for this update, then this field will be
34155 present and will hold the value of the varobj.
34156
34157 @item in_scope
34158 @anchor{-var-update}
34159 This field is a string which may take one of three values:
34160
34161 @table @code
34162 @item "true"
34163 The variable object's current value is valid.
34164
34165 @item "false"
34166 The variable object does not currently hold a valid value but it may
34167 hold one in the future if its associated expression comes back into
34168 scope.
34169
34170 @item "invalid"
34171 The variable object no longer holds a valid value.
34172 This can occur when the executable file being debugged has changed,
34173 either through recompilation or by using the @value{GDBN} @code{file}
34174 command. The front end should normally choose to delete these variable
34175 objects.
34176 @end table
34177
34178 In the future new values may be added to this list so the front should
34179 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
34180
34181 @item type_changed
34182 This is only present if the varobj is still valid. If the type
34183 changed, then this will be the string @samp{true}; otherwise it will
34184 be @samp{false}.
34185
34186 When a varobj's type changes, its children are also likely to have
34187 become incorrect. Therefore, the varobj's children are automatically
34188 deleted when this attribute is @samp{true}. Also, the varobj's update
34189 range, when set using the @code{-var-set-update-range} command, is
34190 unset.
34191
34192 @item new_type
34193 If the varobj's type changed, then this field will be present and will
34194 hold the new type.
34195
34196 @item new_num_children
34197 For a dynamic varobj, if the number of children changed, or if the
34198 type changed, this will be the new number of children.
34199
34200 The @samp{numchild} field in other varobj responses is generally not
34201 valid for a dynamic varobj -- it will show the number of children that
34202 @value{GDBN} knows about, but because dynamic varobjs lazily
34203 instantiate their children, this will not reflect the number of
34204 children which may be available.
34205
34206 The @samp{new_num_children} attribute only reports changes to the
34207 number of children known by @value{GDBN}. This is the only way to
34208 detect whether an update has removed children (which necessarily can
34209 only happen at the end of the update range).
34210
34211 @item displayhint
34212 The display hint, if any.
34213
34214 @item has_more
34215 This is an integer value, which will be 1 if there are more children
34216 available outside the varobj's update range.
34217
34218 @item dynamic
34219 This attribute will be present and have the value @samp{1} if the
34220 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
34221 then this attribute will not be present.
34222
34223 @item new_children
34224 If new children were added to a dynamic varobj within the selected
34225 update range (as set by @code{-var-set-update-range}), then they will
34226 be listed in this attribute.
34227 @end table
34228
34229 @subsubheading Example
34230
34231 @smallexample
34232 (gdb)
34233 -var-assign var1 3
34234 ^done,value="3"
34235 (gdb)
34236 -var-update --all-values var1
34237 ^done,changelist=[@{name="var1",value="3",in_scope="true",
34238 type_changed="false"@}]
34239 (gdb)
34240 @end smallexample
34241
34242 @subheading The @code{-var-set-frozen} Command
34243 @findex -var-set-frozen
34244 @anchor{-var-set-frozen}
34245
34246 @subsubheading Synopsis
34247
34248 @smallexample
34249 -var-set-frozen @var{name} @var{flag}
34250 @end smallexample
34251
34252 Set the frozenness flag on the variable object @var{name}. The
34253 @var{flag} parameter should be either @samp{1} to make the variable
34254 frozen or @samp{0} to make it unfrozen. If a variable object is
34255 frozen, then neither itself, nor any of its children, are
34256 implicitly updated by @code{-var-update} of
34257 a parent variable or by @code{-var-update *}. Only
34258 @code{-var-update} of the variable itself will update its value and
34259 values of its children. After a variable object is unfrozen, it is
34260 implicitly updated by all subsequent @code{-var-update} operations.
34261 Unfreezing a variable does not update it, only subsequent
34262 @code{-var-update} does.
34263
34264 @subsubheading Example
34265
34266 @smallexample
34267 (gdb)
34268 -var-set-frozen V 1
34269 ^done
34270 (gdb)
34271 @end smallexample
34272
34273 @subheading The @code{-var-set-update-range} command
34274 @findex -var-set-update-range
34275 @anchor{-var-set-update-range}
34276
34277 @subsubheading Synopsis
34278
34279 @smallexample
34280 -var-set-update-range @var{name} @var{from} @var{to}
34281 @end smallexample
34282
34283 Set the range of children to be returned by future invocations of
34284 @code{-var-update}.
34285
34286 @var{from} and @var{to} indicate the range of children to report. If
34287 @var{from} or @var{to} is less than zero, the range is reset and all
34288 children will be reported. Otherwise, children starting at @var{from}
34289 (zero-based) and up to and excluding @var{to} will be reported.
34290
34291 @subsubheading Example
34292
34293 @smallexample
34294 (gdb)
34295 -var-set-update-range V 1 2
34296 ^done
34297 @end smallexample
34298
34299 @subheading The @code{-var-set-visualizer} command
34300 @findex -var-set-visualizer
34301 @anchor{-var-set-visualizer}
34302
34303 @subsubheading Synopsis
34304
34305 @smallexample
34306 -var-set-visualizer @var{name} @var{visualizer}
34307 @end smallexample
34308
34309 Set a visualizer for the variable object @var{name}.
34310
34311 @var{visualizer} is the visualizer to use. The special value
34312 @samp{None} means to disable any visualizer in use.
34313
34314 If not @samp{None}, @var{visualizer} must be a Python expression.
34315 This expression must evaluate to a callable object which accepts a
34316 single argument. @value{GDBN} will call this object with the value of
34317 the varobj @var{name} as an argument (this is done so that the same
34318 Python pretty-printing code can be used for both the CLI and MI).
34319 When called, this object must return an object which conforms to the
34320 pretty-printing interface (@pxref{Pretty Printing API}).
34321
34322 The pre-defined function @code{gdb.default_visualizer} may be used to
34323 select a visualizer by following the built-in process
34324 (@pxref{Selecting Pretty-Printers}). This is done automatically when
34325 a varobj is created, and so ordinarily is not needed.
34326
34327 This feature is only available if Python support is enabled. The MI
34328 command @code{-list-features} (@pxref{GDB/MI Support Commands})
34329 can be used to check this.
34330
34331 @subsubheading Example
34332
34333 Resetting the visualizer:
34334
34335 @smallexample
34336 (gdb)
34337 -var-set-visualizer V None
34338 ^done
34339 @end smallexample
34340
34341 Reselecting the default (type-based) visualizer:
34342
34343 @smallexample
34344 (gdb)
34345 -var-set-visualizer V gdb.default_visualizer
34346 ^done
34347 @end smallexample
34348
34349 Suppose @code{SomeClass} is a visualizer class. A lambda expression
34350 can be used to instantiate this class for a varobj:
34351
34352 @smallexample
34353 (gdb)
34354 -var-set-visualizer V "lambda val: SomeClass()"
34355 ^done
34356 @end smallexample
34357
34358 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34359 @node GDB/MI Data Manipulation
34360 @section @sc{gdb/mi} Data Manipulation
34361
34362 @cindex data manipulation, in @sc{gdb/mi}
34363 @cindex @sc{gdb/mi}, data manipulation
34364 This section describes the @sc{gdb/mi} commands that manipulate data:
34365 examine memory and registers, evaluate expressions, etc.
34366
34367 For details about what an addressable memory unit is,
34368 @pxref{addressable memory unit}.
34369
34370 @c REMOVED FROM THE INTERFACE.
34371 @c @subheading -data-assign
34372 @c Change the value of a program variable. Plenty of side effects.
34373 @c @subsubheading GDB Command
34374 @c set variable
34375 @c @subsubheading Example
34376 @c N.A.
34377
34378 @subheading The @code{-data-disassemble} Command
34379 @findex -data-disassemble
34380
34381 @subsubheading Synopsis
34382
34383 @smallexample
34384 -data-disassemble
34385 [ -s @var{start-addr} -e @var{end-addr} ]
34386 | [ -a @var{addr} ]
34387 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
34388 -- @var{mode}
34389 @end smallexample
34390
34391 @noindent
34392 Where:
34393
34394 @table @samp
34395 @item @var{start-addr}
34396 is the beginning address (or @code{$pc})
34397 @item @var{end-addr}
34398 is the end address
34399 @item @var{addr}
34400 is an address anywhere within (or the name of) the function to
34401 disassemble. If an address is specified, the whole function
34402 surrounding that address will be disassembled. If a name is
34403 specified, the whole function with that name will be disassembled.
34404 @item @var{filename}
34405 is the name of the file to disassemble
34406 @item @var{linenum}
34407 is the line number to disassemble around
34408 @item @var{lines}
34409 is the number of disassembly lines to be produced. If it is -1,
34410 the whole function will be disassembled, in case no @var{end-addr} is
34411 specified. If @var{end-addr} is specified as a non-zero value, and
34412 @var{lines} is lower than the number of disassembly lines between
34413 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
34414 displayed; if @var{lines} is higher than the number of lines between
34415 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
34416 are displayed.
34417 @item @var{mode}
34418 is one of:
34419 @itemize @bullet
34420 @item 0 disassembly only
34421 @item 1 mixed source and disassembly (deprecated)
34422 @item 2 disassembly with raw opcodes
34423 @item 3 mixed source and disassembly with raw opcodes (deprecated)
34424 @item 4 mixed source and disassembly
34425 @item 5 mixed source and disassembly with raw opcodes
34426 @end itemize
34427
34428 Modes 1 and 3 are deprecated. The output is ``source centric''
34429 which hasn't proved useful in practice.
34430 @xref{Machine Code}, for a discussion of the difference between
34431 @code{/m} and @code{/s} output of the @code{disassemble} command.
34432 @end table
34433
34434 @subsubheading Result
34435
34436 The result of the @code{-data-disassemble} command will be a list named
34437 @samp{asm_insns}, the contents of this list depend on the @var{mode}
34438 used with the @code{-data-disassemble} command.
34439
34440 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
34441 following fields:
34442
34443 @table @code
34444 @item address
34445 The address at which this instruction was disassembled.
34446
34447 @item func-name
34448 The name of the function this instruction is within.
34449
34450 @item offset
34451 The decimal offset in bytes from the start of @samp{func-name}.
34452
34453 @item inst
34454 The text disassembly for this @samp{address}.
34455
34456 @item opcodes
34457 This field is only present for modes 2, 3 and 5. This contains the raw opcode
34458 bytes for the @samp{inst} field.
34459
34460 @end table
34461
34462 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
34463 @samp{src_and_asm_line}, each of which has the following fields:
34464
34465 @table @code
34466 @item line
34467 The line number within @samp{file}.
34468
34469 @item file
34470 The file name from the compilation unit. This might be an absolute
34471 file name or a relative file name depending on the compile command
34472 used.
34473
34474 @item fullname
34475 Absolute file name of @samp{file}. It is converted to a canonical form
34476 using the source file search path
34477 (@pxref{Source Path, ,Specifying Source Directories})
34478 and after resolving all the symbolic links.
34479
34480 If the source file is not found this field will contain the path as
34481 present in the debug information.
34482
34483 @item line_asm_insn
34484 This is a list of tuples containing the disassembly for @samp{line} in
34485 @samp{file}. The fields of each tuple are the same as for
34486 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
34487 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
34488 @samp{opcodes}.
34489
34490 @end table
34491
34492 Note that whatever included in the @samp{inst} field, is not
34493 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
34494 adjust its format.
34495
34496 @subsubheading @value{GDBN} Command
34497
34498 The corresponding @value{GDBN} command is @samp{disassemble}.
34499
34500 @subsubheading Example
34501
34502 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
34503
34504 @smallexample
34505 (gdb)
34506 -data-disassemble -s $pc -e "$pc + 20" -- 0
34507 ^done,
34508 asm_insns=[
34509 @{address="0x000107c0",func-name="main",offset="4",
34510 inst="mov 2, %o0"@},
34511 @{address="0x000107c4",func-name="main",offset="8",
34512 inst="sethi %hi(0x11800), %o2"@},
34513 @{address="0x000107c8",func-name="main",offset="12",
34514 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
34515 @{address="0x000107cc",func-name="main",offset="16",
34516 inst="sethi %hi(0x11800), %o2"@},
34517 @{address="0x000107d0",func-name="main",offset="20",
34518 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
34519 (gdb)
34520 @end smallexample
34521
34522 Disassemble the whole @code{main} function. Line 32 is part of
34523 @code{main}.
34524
34525 @smallexample
34526 -data-disassemble -f basics.c -l 32 -- 0
34527 ^done,asm_insns=[
34528 @{address="0x000107bc",func-name="main",offset="0",
34529 inst="save %sp, -112, %sp"@},
34530 @{address="0x000107c0",func-name="main",offset="4",
34531 inst="mov 2, %o0"@},
34532 @{address="0x000107c4",func-name="main",offset="8",
34533 inst="sethi %hi(0x11800), %o2"@},
34534 [@dots{}]
34535 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
34536 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
34537 (gdb)
34538 @end smallexample
34539
34540 Disassemble 3 instructions from the start of @code{main}:
34541
34542 @smallexample
34543 (gdb)
34544 -data-disassemble -f basics.c -l 32 -n 3 -- 0
34545 ^done,asm_insns=[
34546 @{address="0x000107bc",func-name="main",offset="0",
34547 inst="save %sp, -112, %sp"@},
34548 @{address="0x000107c0",func-name="main",offset="4",
34549 inst="mov 2, %o0"@},
34550 @{address="0x000107c4",func-name="main",offset="8",
34551 inst="sethi %hi(0x11800), %o2"@}]
34552 (gdb)
34553 @end smallexample
34554
34555 Disassemble 3 instructions from the start of @code{main} in mixed mode:
34556
34557 @smallexample
34558 (gdb)
34559 -data-disassemble -f basics.c -l 32 -n 3 -- 1
34560 ^done,asm_insns=[
34561 src_and_asm_line=@{line="31",
34562 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
34563 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
34564 line_asm_insn=[@{address="0x000107bc",
34565 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
34566 src_and_asm_line=@{line="32",
34567 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
34568 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
34569 line_asm_insn=[@{address="0x000107c0",
34570 func-name="main",offset="4",inst="mov 2, %o0"@},
34571 @{address="0x000107c4",func-name="main",offset="8",
34572 inst="sethi %hi(0x11800), %o2"@}]@}]
34573 (gdb)
34574 @end smallexample
34575
34576
34577 @subheading The @code{-data-evaluate-expression} Command
34578 @findex -data-evaluate-expression
34579
34580 @subsubheading Synopsis
34581
34582 @smallexample
34583 -data-evaluate-expression @var{expr}
34584 @end smallexample
34585
34586 Evaluate @var{expr} as an expression. The expression could contain an
34587 inferior function call. The function call will execute synchronously.
34588 If the expression contains spaces, it must be enclosed in double quotes.
34589
34590 @subsubheading @value{GDBN} Command
34591
34592 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
34593 @samp{call}. In @code{gdbtk} only, there's a corresponding
34594 @samp{gdb_eval} command.
34595
34596 @subsubheading Example
34597
34598 In the following example, the numbers that precede the commands are the
34599 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
34600 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
34601 output.
34602
34603 @smallexample
34604 211-data-evaluate-expression A
34605 211^done,value="1"
34606 (gdb)
34607 311-data-evaluate-expression &A
34608 311^done,value="0xefffeb7c"
34609 (gdb)
34610 411-data-evaluate-expression A+3
34611 411^done,value="4"
34612 (gdb)
34613 511-data-evaluate-expression "A + 3"
34614 511^done,value="4"
34615 (gdb)
34616 @end smallexample
34617
34618
34619 @subheading The @code{-data-list-changed-registers} Command
34620 @findex -data-list-changed-registers
34621
34622 @subsubheading Synopsis
34623
34624 @smallexample
34625 -data-list-changed-registers
34626 @end smallexample
34627
34628 Display a list of the registers that have changed.
34629
34630 @subsubheading @value{GDBN} Command
34631
34632 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
34633 has the corresponding command @samp{gdb_changed_register_list}.
34634
34635 @subsubheading Example
34636
34637 On a PPC MBX board:
34638
34639 @smallexample
34640 (gdb)
34641 -exec-continue
34642 ^running
34643
34644 (gdb)
34645 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
34646 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
34647 line="5",arch="powerpc"@}
34648 (gdb)
34649 -data-list-changed-registers
34650 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
34651 "10","11","13","14","15","16","17","18","19","20","21","22","23",
34652 "24","25","26","27","28","30","31","64","65","66","67","69"]
34653 (gdb)
34654 @end smallexample
34655
34656
34657 @subheading The @code{-data-list-register-names} Command
34658 @findex -data-list-register-names
34659
34660 @subsubheading Synopsis
34661
34662 @smallexample
34663 -data-list-register-names [ ( @var{regno} )+ ]
34664 @end smallexample
34665
34666 Show a list of register names for the current target. If no arguments
34667 are given, it shows a list of the names of all the registers. If
34668 integer numbers are given as arguments, it will print a list of the
34669 names of the registers corresponding to the arguments. To ensure
34670 consistency between a register name and its number, the output list may
34671 include empty register names.
34672
34673 @subsubheading @value{GDBN} Command
34674
34675 @value{GDBN} does not have a command which corresponds to
34676 @samp{-data-list-register-names}. In @code{gdbtk} there is a
34677 corresponding command @samp{gdb_regnames}.
34678
34679 @subsubheading Example
34680
34681 For the PPC MBX board:
34682 @smallexample
34683 (gdb)
34684 -data-list-register-names
34685 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
34686 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
34687 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
34688 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
34689 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
34690 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
34691 "", "pc","ps","cr","lr","ctr","xer"]
34692 (gdb)
34693 -data-list-register-names 1 2 3
34694 ^done,register-names=["r1","r2","r3"]
34695 (gdb)
34696 @end smallexample
34697
34698 @subheading The @code{-data-list-register-values} Command
34699 @findex -data-list-register-values
34700
34701 @subsubheading Synopsis
34702
34703 @smallexample
34704 -data-list-register-values
34705 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
34706 @end smallexample
34707
34708 Display the registers' contents. The format according to which the
34709 registers' contents are to be returned is given by @var{fmt}, followed
34710 by an optional list of numbers specifying the registers to display. A
34711 missing list of numbers indicates that the contents of all the
34712 registers must be returned. The @code{--skip-unavailable} option
34713 indicates that only the available registers are to be returned.
34714
34715 Allowed formats for @var{fmt} are:
34716
34717 @table @code
34718 @item x
34719 Hexadecimal
34720 @item o
34721 Octal
34722 @item t
34723 Binary
34724 @item d
34725 Decimal
34726 @item r
34727 Raw
34728 @item N
34729 Natural
34730 @end table
34731
34732 @subsubheading @value{GDBN} Command
34733
34734 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
34735 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
34736
34737 @subsubheading Example
34738
34739 For a PPC MBX board (note: line breaks are for readability only, they
34740 don't appear in the actual output):
34741
34742 @smallexample
34743 (gdb)
34744 -data-list-register-values r 64 65
34745 ^done,register-values=[@{number="64",value="0xfe00a300"@},
34746 @{number="65",value="0x00029002"@}]
34747 (gdb)
34748 -data-list-register-values x
34749 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
34750 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
34751 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
34752 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
34753 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
34754 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
34755 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
34756 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
34757 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
34758 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
34759 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
34760 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
34761 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
34762 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
34763 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
34764 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
34765 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
34766 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
34767 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
34768 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
34769 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
34770 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
34771 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
34772 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
34773 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
34774 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
34775 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
34776 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
34777 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
34778 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
34779 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
34780 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
34781 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
34782 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
34783 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
34784 @{number="69",value="0x20002b03"@}]
34785 (gdb)
34786 @end smallexample
34787
34788
34789 @subheading The @code{-data-read-memory} Command
34790 @findex -data-read-memory
34791
34792 This command is deprecated, use @code{-data-read-memory-bytes} instead.
34793
34794 @subsubheading Synopsis
34795
34796 @smallexample
34797 -data-read-memory [ -o @var{byte-offset} ]
34798 @var{address} @var{word-format} @var{word-size}
34799 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
34800 @end smallexample
34801
34802 @noindent
34803 where:
34804
34805 @table @samp
34806 @item @var{address}
34807 An expression specifying the address of the first memory word to be
34808 read. Complex expressions containing embedded white space should be
34809 quoted using the C convention.
34810
34811 @item @var{word-format}
34812 The format to be used to print the memory words. The notation is the
34813 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
34814 ,Output Formats}).
34815
34816 @item @var{word-size}
34817 The size of each memory word in bytes.
34818
34819 @item @var{nr-rows}
34820 The number of rows in the output table.
34821
34822 @item @var{nr-cols}
34823 The number of columns in the output table.
34824
34825 @item @var{aschar}
34826 If present, indicates that each row should include an @sc{ascii} dump. The
34827 value of @var{aschar} is used as a padding character when a byte is not a
34828 member of the printable @sc{ascii} character set (printable @sc{ascii}
34829 characters are those whose code is between 32 and 126, inclusively).
34830
34831 @item @var{byte-offset}
34832 An offset to add to the @var{address} before fetching memory.
34833 @end table
34834
34835 This command displays memory contents as a table of @var{nr-rows} by
34836 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
34837 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
34838 (returned as @samp{total-bytes}). Should less than the requested number
34839 of bytes be returned by the target, the missing words are identified
34840 using @samp{N/A}. The number of bytes read from the target is returned
34841 in @samp{nr-bytes} and the starting address used to read memory in
34842 @samp{addr}.
34843
34844 The address of the next/previous row or page is available in
34845 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
34846 @samp{prev-page}.
34847
34848 @subsubheading @value{GDBN} Command
34849
34850 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
34851 @samp{gdb_get_mem} memory read command.
34852
34853 @subsubheading Example
34854
34855 Read six bytes of memory starting at @code{bytes+6} but then offset by
34856 @code{-6} bytes. Format as three rows of two columns. One byte per
34857 word. Display each word in hex.
34858
34859 @smallexample
34860 (gdb)
34861 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
34862 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
34863 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
34864 prev-page="0x0000138a",memory=[
34865 @{addr="0x00001390",data=["0x00","0x01"]@},
34866 @{addr="0x00001392",data=["0x02","0x03"]@},
34867 @{addr="0x00001394",data=["0x04","0x05"]@}]
34868 (gdb)
34869 @end smallexample
34870
34871 Read two bytes of memory starting at address @code{shorts + 64} and
34872 display as a single word formatted in decimal.
34873
34874 @smallexample
34875 (gdb)
34876 5-data-read-memory shorts+64 d 2 1 1
34877 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
34878 next-row="0x00001512",prev-row="0x0000150e",
34879 next-page="0x00001512",prev-page="0x0000150e",memory=[
34880 @{addr="0x00001510",data=["128"]@}]
34881 (gdb)
34882 @end smallexample
34883
34884 Read thirty two bytes of memory starting at @code{bytes+16} and format
34885 as eight rows of four columns. Include a string encoding with @samp{x}
34886 used as the non-printable character.
34887
34888 @smallexample
34889 (gdb)
34890 4-data-read-memory bytes+16 x 1 8 4 x
34891 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
34892 next-row="0x000013c0",prev-row="0x0000139c",
34893 next-page="0x000013c0",prev-page="0x00001380",memory=[
34894 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
34895 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
34896 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
34897 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
34898 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
34899 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
34900 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
34901 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
34902 (gdb)
34903 @end smallexample
34904
34905 @subheading The @code{-data-read-memory-bytes} Command
34906 @findex -data-read-memory-bytes
34907
34908 @subsubheading Synopsis
34909
34910 @smallexample
34911 -data-read-memory-bytes [ -o @var{offset} ]
34912 @var{address} @var{count}
34913 @end smallexample
34914
34915 @noindent
34916 where:
34917
34918 @table @samp
34919 @item @var{address}
34920 An expression specifying the address of the first addressable memory unit
34921 to be read. Complex expressions containing embedded white space should be
34922 quoted using the C convention.
34923
34924 @item @var{count}
34925 The number of addressable memory units to read. This should be an integer
34926 literal.
34927
34928 @item @var{offset}
34929 The offset relative to @var{address} at which to start reading. This
34930 should be an integer literal. This option is provided so that a frontend
34931 is not required to first evaluate address and then perform address
34932 arithmetics itself.
34933
34934 @end table
34935
34936 This command attempts to read all accessible memory regions in the
34937 specified range. First, all regions marked as unreadable in the memory
34938 map (if one is defined) will be skipped. @xref{Memory Region
34939 Attributes}. Second, @value{GDBN} will attempt to read the remaining
34940 regions. For each one, if reading full region results in an errors,
34941 @value{GDBN} will try to read a subset of the region.
34942
34943 In general, every single memory unit in the region may be readable or not,
34944 and the only way to read every readable unit is to try a read at
34945 every address, which is not practical. Therefore, @value{GDBN} will
34946 attempt to read all accessible memory units at either beginning or the end
34947 of the region, using a binary division scheme. This heuristic works
34948 well for reading across a memory map boundary. Note that if a region
34949 has a readable range that is neither at the beginning or the end,
34950 @value{GDBN} will not read it.
34951
34952 The result record (@pxref{GDB/MI Result Records}) that is output of
34953 the command includes a field named @samp{memory} whose content is a
34954 list of tuples. Each tuple represent a successfully read memory block
34955 and has the following fields:
34956
34957 @table @code
34958 @item begin
34959 The start address of the memory block, as hexadecimal literal.
34960
34961 @item end
34962 The end address of the memory block, as hexadecimal literal.
34963
34964 @item offset
34965 The offset of the memory block, as hexadecimal literal, relative to
34966 the start address passed to @code{-data-read-memory-bytes}.
34967
34968 @item contents
34969 The contents of the memory block, in hex.
34970
34971 @end table
34972
34973
34974
34975 @subsubheading @value{GDBN} Command
34976
34977 The corresponding @value{GDBN} command is @samp{x}.
34978
34979 @subsubheading Example
34980
34981 @smallexample
34982 (gdb)
34983 -data-read-memory-bytes &a 10
34984 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34985 end="0xbffff15e",
34986 contents="01000000020000000300"@}]
34987 (gdb)
34988 @end smallexample
34989
34990
34991 @subheading The @code{-data-write-memory-bytes} Command
34992 @findex -data-write-memory-bytes
34993
34994 @subsubheading Synopsis
34995
34996 @smallexample
34997 -data-write-memory-bytes @var{address} @var{contents}
34998 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
34999 @end smallexample
35000
35001 @noindent
35002 where:
35003
35004 @table @samp
35005 @item @var{address}
35006 An expression specifying the address of the first addressable memory unit
35007 to be written. Complex expressions containing embedded white space should
35008 be quoted using the C convention.
35009
35010 @item @var{contents}
35011 The hex-encoded data to write. It is an error if @var{contents} does
35012 not represent an integral number of addressable memory units.
35013
35014 @item @var{count}
35015 Optional argument indicating the number of addressable memory units to be
35016 written. If @var{count} is greater than @var{contents}' length,
35017 @value{GDBN} will repeatedly write @var{contents} until it fills
35018 @var{count} memory units.
35019
35020 @end table
35021
35022 @subsubheading @value{GDBN} Command
35023
35024 There's no corresponding @value{GDBN} command.
35025
35026 @subsubheading Example
35027
35028 @smallexample
35029 (gdb)
35030 -data-write-memory-bytes &a "aabbccdd"
35031 ^done
35032 (gdb)
35033 @end smallexample
35034
35035 @smallexample
35036 (gdb)
35037 -data-write-memory-bytes &a "aabbccdd" 16e
35038 ^done
35039 (gdb)
35040 @end smallexample
35041
35042 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35043 @node GDB/MI Tracepoint Commands
35044 @section @sc{gdb/mi} Tracepoint Commands
35045
35046 The commands defined in this section implement MI support for
35047 tracepoints. For detailed introduction, see @ref{Tracepoints}.
35048
35049 @subheading The @code{-trace-find} Command
35050 @findex -trace-find
35051
35052 @subsubheading Synopsis
35053
35054 @smallexample
35055 -trace-find @var{mode} [@var{parameters}@dots{}]
35056 @end smallexample
35057
35058 Find a trace frame using criteria defined by @var{mode} and
35059 @var{parameters}. The following table lists permissible
35060 modes and their parameters. For details of operation, see @ref{tfind}.
35061
35062 @table @samp
35063
35064 @item none
35065 No parameters are required. Stops examining trace frames.
35066
35067 @item frame-number
35068 An integer is required as parameter. Selects tracepoint frame with
35069 that index.
35070
35071 @item tracepoint-number
35072 An integer is required as parameter. Finds next
35073 trace frame that corresponds to tracepoint with the specified number.
35074
35075 @item pc
35076 An address is required as parameter. Finds
35077 next trace frame that corresponds to any tracepoint at the specified
35078 address.
35079
35080 @item pc-inside-range
35081 Two addresses are required as parameters. Finds next trace
35082 frame that corresponds to a tracepoint at an address inside the
35083 specified range. Both bounds are considered to be inside the range.
35084
35085 @item pc-outside-range
35086 Two addresses are required as parameters. Finds
35087 next trace frame that corresponds to a tracepoint at an address outside
35088 the specified range. Both bounds are considered to be inside the range.
35089
35090 @item line
35091 Location specification is required as parameter. @xref{Location Specifications}.
35092 Finds next trace frame that corresponds to a tracepoint at
35093 the specified location.
35094
35095 @end table
35096
35097 If @samp{none} was passed as @var{mode}, the response does not
35098 have fields. Otherwise, the response may have the following fields:
35099
35100 @table @samp
35101 @item found
35102 This field has either @samp{0} or @samp{1} as the value, depending
35103 on whether a matching tracepoint was found.
35104
35105 @item traceframe
35106 The index of the found traceframe. This field is present iff
35107 the @samp{found} field has value of @samp{1}.
35108
35109 @item tracepoint
35110 The index of the found tracepoint. This field is present iff
35111 the @samp{found} field has value of @samp{1}.
35112
35113 @item frame
35114 The information about the frame corresponding to the found trace
35115 frame. This field is present only if a trace frame was found.
35116 @xref{GDB/MI Frame Information}, for description of this field.
35117
35118 @end table
35119
35120 @subsubheading @value{GDBN} Command
35121
35122 The corresponding @value{GDBN} command is @samp{tfind}.
35123
35124 @subheading -trace-define-variable
35125 @findex -trace-define-variable
35126
35127 @subsubheading Synopsis
35128
35129 @smallexample
35130 -trace-define-variable @var{name} [ @var{value} ]
35131 @end smallexample
35132
35133 Create trace variable @var{name} if it does not exist. If
35134 @var{value} is specified, sets the initial value of the specified
35135 trace variable to that value. Note that the @var{name} should start
35136 with the @samp{$} character.
35137
35138 @subsubheading @value{GDBN} Command
35139
35140 The corresponding @value{GDBN} command is @samp{tvariable}.
35141
35142 @subheading The @code{-trace-frame-collected} Command
35143 @findex -trace-frame-collected
35144
35145 @subsubheading Synopsis
35146
35147 @smallexample
35148 -trace-frame-collected
35149 [--var-print-values @var{var_pval}]
35150 [--comp-print-values @var{comp_pval}]
35151 [--registers-format @var{regformat}]
35152 [--memory-contents]
35153 @end smallexample
35154
35155 This command returns the set of collected objects, register names,
35156 trace state variable names, memory ranges and computed expressions
35157 that have been collected at a particular trace frame. The optional
35158 parameters to the command affect the output format in different ways.
35159 See the output description table below for more details.
35160
35161 The reported names can be used in the normal manner to create
35162 varobjs and inspect the objects themselves. The items returned by
35163 this command are categorized so that it is clear which is a variable,
35164 which is a register, which is a trace state variable, which is a
35165 memory range and which is a computed expression.
35166
35167 For instance, if the actions were
35168 @smallexample
35169 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
35170 collect *(int*)0xaf02bef0@@40
35171 @end smallexample
35172
35173 @noindent
35174 the object collected in its entirety would be @code{myVar}. The
35175 object @code{myArray} would be partially collected, because only the
35176 element at index @code{myIndex} would be collected. The remaining
35177 objects would be computed expressions.
35178
35179 An example output would be:
35180
35181 @smallexample
35182 (gdb)
35183 -trace-frame-collected
35184 ^done,
35185 explicit-variables=[@{name="myVar",value="1"@}],
35186 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
35187 @{name="myObj.field",value="0"@},
35188 @{name="myPtr->field",value="1"@},
35189 @{name="myCount + 2",value="3"@},
35190 @{name="$tvar1 + 1",value="43970027"@}],
35191 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
35192 @{number="1",value="0x0"@},
35193 @{number="2",value="0x4"@},
35194 ...
35195 @{number="125",value="0x0"@}],
35196 tvars=[@{name="$tvar1",current="43970026"@}],
35197 memory=[@{address="0x0000000000602264",length="4"@},
35198 @{address="0x0000000000615bc0",length="4"@}]
35199 (gdb)
35200 @end smallexample
35201
35202 Where:
35203
35204 @table @code
35205 @item explicit-variables
35206 The set of objects that have been collected in their entirety (as
35207 opposed to collecting just a few elements of an array or a few struct
35208 members). For each object, its name and value are printed.
35209 The @code{--var-print-values} option affects how or whether the value
35210 field is output. If @var{var_pval} is 0, then print only the names;
35211 if it is 1, print also their values; and if it is 2, print the name,
35212 type and value for simple data types, and the name and type for
35213 arrays, structures and unions.
35214
35215 @item computed-expressions
35216 The set of computed expressions that have been collected at the
35217 current trace frame. The @code{--comp-print-values} option affects
35218 this set like the @code{--var-print-values} option affects the
35219 @code{explicit-variables} set. See above.
35220
35221 @item registers
35222 The registers that have been collected at the current trace frame.
35223 For each register collected, the name and current value are returned.
35224 The value is formatted according to the @code{--registers-format}
35225 option. See the @command{-data-list-register-values} command for a
35226 list of the allowed formats. The default is @samp{x}.
35227
35228 @item tvars
35229 The trace state variables that have been collected at the current
35230 trace frame. For each trace state variable collected, the name and
35231 current value are returned.
35232
35233 @item memory
35234 The set of memory ranges that have been collected at the current trace
35235 frame. Its content is a list of tuples. Each tuple represents a
35236 collected memory range and has the following fields:
35237
35238 @table @code
35239 @item address
35240 The start address of the memory range, as hexadecimal literal.
35241
35242 @item length
35243 The length of the memory range, as decimal literal.
35244
35245 @item contents
35246 The contents of the memory block, in hex. This field is only present
35247 if the @code{--memory-contents} option is specified.
35248
35249 @end table
35250
35251 @end table
35252
35253 @subsubheading @value{GDBN} Command
35254
35255 There is no corresponding @value{GDBN} command.
35256
35257 @subsubheading Example
35258
35259 @subheading -trace-list-variables
35260 @findex -trace-list-variables
35261
35262 @subsubheading Synopsis
35263
35264 @smallexample
35265 -trace-list-variables
35266 @end smallexample
35267
35268 Return a table of all defined trace variables. Each element of the
35269 table has the following fields:
35270
35271 @table @samp
35272 @item name
35273 The name of the trace variable. This field is always present.
35274
35275 @item initial
35276 The initial value. This is a 64-bit signed integer. This
35277 field is always present.
35278
35279 @item current
35280 The value the trace variable has at the moment. This is a 64-bit
35281 signed integer. This field is absent iff current value is
35282 not defined, for example if the trace was never run, or is
35283 presently running.
35284
35285 @end table
35286
35287 @subsubheading @value{GDBN} Command
35288
35289 The corresponding @value{GDBN} command is @samp{tvariables}.
35290
35291 @subsubheading Example
35292
35293 @smallexample
35294 (gdb)
35295 -trace-list-variables
35296 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
35297 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
35298 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
35299 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
35300 body=[variable=@{name="$trace_timestamp",initial="0"@}
35301 variable=@{name="$foo",initial="10",current="15"@}]@}
35302 (gdb)
35303 @end smallexample
35304
35305 @subheading -trace-save
35306 @findex -trace-save
35307
35308 @subsubheading Synopsis
35309
35310 @smallexample
35311 -trace-save [ -r ] [ -ctf ] @var{filename}
35312 @end smallexample
35313
35314 Saves the collected trace data to @var{filename}. Without the
35315 @samp{-r} option, the data is downloaded from the target and saved
35316 in a local file. With the @samp{-r} option the target is asked
35317 to perform the save.
35318
35319 By default, this command will save the trace in the tfile format. You can
35320 supply the optional @samp{-ctf} argument to save it the CTF format. See
35321 @ref{Trace Files} for more information about CTF.
35322
35323 @subsubheading @value{GDBN} Command
35324
35325 The corresponding @value{GDBN} command is @samp{tsave}.
35326
35327
35328 @subheading -trace-start
35329 @findex -trace-start
35330
35331 @subsubheading Synopsis
35332
35333 @smallexample
35334 -trace-start
35335 @end smallexample
35336
35337 Starts a tracing experiment. The result of this command does not
35338 have any fields.
35339
35340 @subsubheading @value{GDBN} Command
35341
35342 The corresponding @value{GDBN} command is @samp{tstart}.
35343
35344 @subheading -trace-status
35345 @findex -trace-status
35346
35347 @subsubheading Synopsis
35348
35349 @smallexample
35350 -trace-status
35351 @end smallexample
35352
35353 Obtains the status of a tracing experiment. The result may include
35354 the following fields:
35355
35356 @table @samp
35357
35358 @item supported
35359 May have a value of either @samp{0}, when no tracing operations are
35360 supported, @samp{1}, when all tracing operations are supported, or
35361 @samp{file} when examining trace file. In the latter case, examining
35362 of trace frame is possible but new tracing experiement cannot be
35363 started. This field is always present.
35364
35365 @item running
35366 May have a value of either @samp{0} or @samp{1} depending on whether
35367 tracing experiement is in progress on target. This field is present
35368 if @samp{supported} field is not @samp{0}.
35369
35370 @item stop-reason
35371 Report the reason why the tracing was stopped last time. This field
35372 may be absent iff tracing was never stopped on target yet. The
35373 value of @samp{request} means the tracing was stopped as result of
35374 the @code{-trace-stop} command. The value of @samp{overflow} means
35375 the tracing buffer is full. The value of @samp{disconnection} means
35376 tracing was automatically stopped when @value{GDBN} has disconnected.
35377 The value of @samp{passcount} means tracing was stopped when a
35378 tracepoint was passed a maximal number of times for that tracepoint.
35379 This field is present if @samp{supported} field is not @samp{0}.
35380
35381 @item stopping-tracepoint
35382 The number of tracepoint whose passcount as exceeded. This field is
35383 present iff the @samp{stop-reason} field has the value of
35384 @samp{passcount}.
35385
35386 @item frames
35387 @itemx frames-created
35388 The @samp{frames} field is a count of the total number of trace frames
35389 in the trace buffer, while @samp{frames-created} is the total created
35390 during the run, including ones that were discarded, such as when a
35391 circular trace buffer filled up. Both fields are optional.
35392
35393 @item buffer-size
35394 @itemx buffer-free
35395 These fields tell the current size of the tracing buffer and the
35396 remaining space. These fields are optional.
35397
35398 @item circular
35399 The value of the circular trace buffer flag. @code{1} means that the
35400 trace buffer is circular and old trace frames will be discarded if
35401 necessary to make room, @code{0} means that the trace buffer is linear
35402 and may fill up.
35403
35404 @item disconnected
35405 The value of the disconnected tracing flag. @code{1} means that
35406 tracing will continue after @value{GDBN} disconnects, @code{0} means
35407 that the trace run will stop.
35408
35409 @item trace-file
35410 The filename of the trace file being examined. This field is
35411 optional, and only present when examining a trace file.
35412
35413 @end table
35414
35415 @subsubheading @value{GDBN} Command
35416
35417 The corresponding @value{GDBN} command is @samp{tstatus}.
35418
35419 @subheading -trace-stop
35420 @findex -trace-stop
35421
35422 @subsubheading Synopsis
35423
35424 @smallexample
35425 -trace-stop
35426 @end smallexample
35427
35428 Stops a tracing experiment. The result of this command has the same
35429 fields as @code{-trace-status}, except that the @samp{supported} and
35430 @samp{running} fields are not output.
35431
35432 @subsubheading @value{GDBN} Command
35433
35434 The corresponding @value{GDBN} command is @samp{tstop}.
35435
35436
35437 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35438 @node GDB/MI Symbol Query
35439 @section @sc{gdb/mi} Symbol Query Commands
35440
35441
35442 @ignore
35443 @subheading The @code{-symbol-info-address} Command
35444 @findex -symbol-info-address
35445
35446 @subsubheading Synopsis
35447
35448 @smallexample
35449 -symbol-info-address @var{symbol}
35450 @end smallexample
35451
35452 Describe where @var{symbol} is stored.
35453
35454 @subsubheading @value{GDBN} Command
35455
35456 The corresponding @value{GDBN} command is @samp{info address}.
35457
35458 @subsubheading Example
35459 N.A.
35460
35461
35462 @subheading The @code{-symbol-info-file} Command
35463 @findex -symbol-info-file
35464
35465 @subsubheading Synopsis
35466
35467 @smallexample
35468 -symbol-info-file
35469 @end smallexample
35470
35471 Show the file for the symbol.
35472
35473 @subsubheading @value{GDBN} Command
35474
35475 There's no equivalent @value{GDBN} command. @code{gdbtk} has
35476 @samp{gdb_find_file}.
35477
35478 @subsubheading Example
35479 N.A.
35480 @end ignore
35481
35482 @subheading The @code{-symbol-info-functions} Command
35483 @findex -symbol-info-functions
35484 @anchor{-symbol-info-functions}
35485
35486 @subsubheading Synopsis
35487
35488 @smallexample
35489 -symbol-info-functions [--include-nondebug]
35490 [--type @var{type_regexp}]
35491 [--name @var{name_regexp}]
35492 [--max-results @var{limit}]
35493 @end smallexample
35494
35495 @noindent
35496 Return a list containing the names and types for all global functions
35497 taken from the debug information. The functions are grouped by source
35498 file, and shown with the line number on which each function is
35499 defined.
35500
35501 The @code{--include-nondebug} option causes the output to include
35502 code symbols from the symbol table.
35503
35504 The options @code{--type} and @code{--name} allow the symbols returned
35505 to be filtered based on either the name of the function, or the type
35506 signature of the function.
35507
35508 The option @code{--max-results} restricts the command to return no
35509 more than @var{limit} results. If exactly @var{limit} results are
35510 returned then there might be additional results available if a higher
35511 limit is used.
35512
35513 @subsubheading @value{GDBN} Command
35514
35515 The corresponding @value{GDBN} command is @samp{info functions}.
35516
35517 @subsubheading Example
35518 @smallexample
35519 @group
35520 (gdb)
35521 -symbol-info-functions
35522 ^done,symbols=
35523 @{debug=
35524 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35525 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35526 symbols=[@{line="36", name="f4", type="void (int *)",
35527 description="void f4(int *);"@},
35528 @{line="42", name="main", type="int ()",
35529 description="int main();"@},
35530 @{line="30", name="f1", type="my_int_t (int, int)",
35531 description="static my_int_t f1(int, int);"@}]@},
35532 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35533 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35534 symbols=[@{line="33", name="f2", type="float (another_float_t)",
35535 description="float f2(another_float_t);"@},
35536 @{line="39", name="f3", type="int (another_int_t)",
35537 description="int f3(another_int_t);"@},
35538 @{line="27", name="f1", type="another_float_t (int)",
35539 description="static another_float_t f1(int);"@}]@}]@}
35540 @end group
35541 @group
35542 (gdb)
35543 -symbol-info-functions --name f1
35544 ^done,symbols=
35545 @{debug=
35546 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35547 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35548 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
35549 description="static my_int_t f1(int, int);"@}]@},
35550 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35551 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35552 symbols=[@{line="27", name="f1", type="another_float_t (int)",
35553 description="static another_float_t f1(int);"@}]@}]@}
35554 @end group
35555 @group
35556 (gdb)
35557 -symbol-info-functions --type void
35558 ^done,symbols=
35559 @{debug=
35560 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35561 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35562 symbols=[@{line="36", name="f4", type="void (int *)",
35563 description="void f4(int *);"@}]@}]@}
35564 @end group
35565 @group
35566 (gdb)
35567 -symbol-info-functions --include-nondebug
35568 ^done,symbols=
35569 @{debug=
35570 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35571 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35572 symbols=[@{line="36", name="f4", type="void (int *)",
35573 description="void f4(int *);"@},
35574 @{line="42", name="main", type="int ()",
35575 description="int main();"@},
35576 @{line="30", name="f1", type="my_int_t (int, int)",
35577 description="static my_int_t f1(int, int);"@}]@},
35578 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35579 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35580 symbols=[@{line="33", name="f2", type="float (another_float_t)",
35581 description="float f2(another_float_t);"@},
35582 @{line="39", name="f3", type="int (another_int_t)",
35583 description="int f3(another_int_t);"@},
35584 @{line="27", name="f1", type="another_float_t (int)",
35585 description="static another_float_t f1(int);"@}]@}],
35586 nondebug=
35587 [@{address="0x0000000000400398",name="_init"@},
35588 @{address="0x00000000004003b0",name="_start"@},
35589 ...
35590 ]@}
35591 @end group
35592 @end smallexample
35593
35594 @subheading The @code{-symbol-info-module-functions} Command
35595 @findex -symbol-info-module-functions
35596 @anchor{-symbol-info-module-functions}
35597
35598 @subsubheading Synopsis
35599
35600 @smallexample
35601 -symbol-info-module-functions [--module @var{module_regexp}]
35602 [--name @var{name_regexp}]
35603 [--type @var{type_regexp}]
35604 @end smallexample
35605
35606 @noindent
35607 Return a list containing the names of all known functions within all
35608 know Fortran modules. The functions are grouped by source file and
35609 containing module, and shown with the line number on which each
35610 function is defined.
35611
35612 The option @code{--module} only returns results for modules matching
35613 @var{module_regexp}. The option @code{--name} only returns functions
35614 whose name matches @var{name_regexp}, and @code{--type} only returns
35615 functions whose type matches @var{type_regexp}.
35616
35617 @subsubheading @value{GDBN} Command
35618
35619 The corresponding @value{GDBN} command is @samp{info module functions}.
35620
35621 @subsubheading Example
35622
35623 @smallexample
35624 @group
35625 (gdb)
35626 -symbol-info-module-functions
35627 ^done,symbols=
35628 [@{module="mod1",
35629 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35630 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35631 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
35632 description="void mod1::check_all(void);"@}]@}]@},
35633 @{module="mod2",
35634 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35635 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35636 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
35637 description="void mod2::check_var_i(void);"@}]@}]@},
35638 @{module="mod3",
35639 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35640 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35641 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
35642 description="void mod3::check_all(void);"@},
35643 @{line="27",name="mod3::check_mod2",type="void (void)",
35644 description="void mod3::check_mod2(void);"@}]@}]@},
35645 @{module="modmany",
35646 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35647 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35648 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
35649 description="void modmany::check_some(void);"@}]@}]@},
35650 @{module="moduse",
35651 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35652 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35653 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
35654 description="void moduse::check_all(void);"@},
35655 @{line="49",name="moduse::check_var_x",type="void (void)",
35656 description="void moduse::check_var_x(void);"@}]@}]@}]
35657 @end group
35658 @end smallexample
35659
35660 @subheading The @code{-symbol-info-module-variables} Command
35661 @findex -symbol-info-module-variables
35662 @anchor{-symbol-info-module-variables}
35663
35664 @subsubheading Synopsis
35665
35666 @smallexample
35667 -symbol-info-module-variables [--module @var{module_regexp}]
35668 [--name @var{name_regexp}]
35669 [--type @var{type_regexp}]
35670 @end smallexample
35671
35672 @noindent
35673 Return a list containing the names of all known variables within all
35674 know Fortran modules. The variables are grouped by source file and
35675 containing module, and shown with the line number on which each
35676 variable is defined.
35677
35678 The option @code{--module} only returns results for modules matching
35679 @var{module_regexp}. The option @code{--name} only returns variables
35680 whose name matches @var{name_regexp}, and @code{--type} only returns
35681 variables whose type matches @var{type_regexp}.
35682
35683 @subsubheading @value{GDBN} Command
35684
35685 The corresponding @value{GDBN} command is @samp{info module variables}.
35686
35687 @subsubheading Example
35688
35689 @smallexample
35690 @group
35691 (gdb)
35692 -symbol-info-module-variables
35693 ^done,symbols=
35694 [@{module="mod1",
35695 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35696 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35697 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
35698 description="integer(kind=4) mod1::var_const;"@},
35699 @{line="17",name="mod1::var_i",type="integer(kind=4)",
35700 description="integer(kind=4) mod1::var_i;"@}]@}]@},
35701 @{module="mod2",
35702 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35703 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35704 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
35705 description="integer(kind=4) mod2::var_i;"@}]@}]@},
35706 @{module="mod3",
35707 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35708 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35709 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
35710 description="integer(kind=4) mod3::mod1;"@},
35711 @{line="17",name="mod3::mod2",type="integer(kind=4)",
35712 description="integer(kind=4) mod3::mod2;"@},
35713 @{line="19",name="mod3::var_i",type="integer(kind=4)",
35714 description="integer(kind=4) mod3::var_i;"@}]@}]@},
35715 @{module="modmany",
35716 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35717 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35718 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
35719 description="integer(kind=4) modmany::var_a;"@},
35720 @{line="33",name="modmany::var_b",type="integer(kind=4)",
35721 description="integer(kind=4) modmany::var_b;"@},
35722 @{line="33",name="modmany::var_c",type="integer(kind=4)",
35723 description="integer(kind=4) modmany::var_c;"@},
35724 @{line="33",name="modmany::var_i",type="integer(kind=4)",
35725 description="integer(kind=4) modmany::var_i;"@}]@}]@},
35726 @{module="moduse",
35727 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35728 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35729 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
35730 description="integer(kind=4) moduse::var_x;"@},
35731 @{line="42",name="moduse::var_y",type="integer(kind=4)",
35732 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
35733 @end group
35734 @end smallexample
35735
35736 @subheading The @code{-symbol-info-modules} Command
35737 @findex -symbol-info-modules
35738 @anchor{-symbol-info-modules}
35739
35740 @subsubheading Synopsis
35741
35742 @smallexample
35743 -symbol-info-modules [--name @var{name_regexp}]
35744 [--max-results @var{limit}]
35745
35746 @end smallexample
35747
35748 @noindent
35749 Return a list containing the names of all known Fortran modules. The
35750 modules are grouped by source file, and shown with the line number on
35751 which each modules is defined.
35752
35753 The option @code{--name} allows the modules returned to be filtered
35754 based the name of the module.
35755
35756 The option @code{--max-results} restricts the command to return no
35757 more than @var{limit} results. If exactly @var{limit} results are
35758 returned then there might be additional results available if a higher
35759 limit is used.
35760
35761 @subsubheading @value{GDBN} Command
35762
35763 The corresponding @value{GDBN} command is @samp{info modules}.
35764
35765 @subsubheading Example
35766 @smallexample
35767 @group
35768 (gdb)
35769 -symbol-info-modules
35770 ^done,symbols=
35771 @{debug=
35772 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35773 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35774 symbols=[@{line="16",name="mod1"@},
35775 @{line="22",name="mod2"@}]@},
35776 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35777 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35778 symbols=[@{line="16",name="mod3"@},
35779 @{line="22",name="modmany"@},
35780 @{line="26",name="moduse"@}]@}]@}
35781 @end group
35782 @group
35783 (gdb)
35784 -symbol-info-modules --name mod[123]
35785 ^done,symbols=
35786 @{debug=
35787 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35788 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35789 symbols=[@{line="16",name="mod1"@},
35790 @{line="22",name="mod2"@}]@},
35791 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35792 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35793 symbols=[@{line="16",name="mod3"@}]@}]@}
35794 @end group
35795 @end smallexample
35796
35797 @subheading The @code{-symbol-info-types} Command
35798 @findex -symbol-info-types
35799 @anchor{-symbol-info-types}
35800
35801 @subsubheading Synopsis
35802
35803 @smallexample
35804 -symbol-info-types [--name @var{name_regexp}]
35805 [--max-results @var{limit}]
35806
35807 @end smallexample
35808
35809 @noindent
35810 Return a list of all defined types. The types are grouped by source
35811 file, and shown with the line number on which each user defined type
35812 is defined. Some base types are not defined in the source code but
35813 are added to the debug information by the compiler, for example
35814 @code{int}, @code{float}, etc.; these types do not have an associated
35815 line number.
35816
35817 The option @code{--name} allows the list of types returned to be
35818 filtered by name.
35819
35820 The option @code{--max-results} restricts the command to return no
35821 more than @var{limit} results. If exactly @var{limit} results are
35822 returned then there might be additional results available if a higher
35823 limit is used.
35824
35825 @subsubheading @value{GDBN} Command
35826
35827 The corresponding @value{GDBN} command is @samp{info types}.
35828
35829 @subsubheading Example
35830 @smallexample
35831 @group
35832 (gdb)
35833 -symbol-info-types
35834 ^done,symbols=
35835 @{debug=
35836 [@{filename="gdb.mi/mi-sym-info-1.c",
35837 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35838 symbols=[@{name="float"@},
35839 @{name="int"@},
35840 @{line="27",name="typedef int my_int_t;"@}]@},
35841 @{filename="gdb.mi/mi-sym-info-2.c",
35842 fullname="/project/gdb.mi/mi-sym-info-2.c",
35843 symbols=[@{line="24",name="typedef float another_float_t;"@},
35844 @{line="23",name="typedef int another_int_t;"@},
35845 @{name="float"@},
35846 @{name="int"@}]@}]@}
35847 @end group
35848 @group
35849 (gdb)
35850 -symbol-info-types --name _int_
35851 ^done,symbols=
35852 @{debug=
35853 [@{filename="gdb.mi/mi-sym-info-1.c",
35854 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35855 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
35856 @{filename="gdb.mi/mi-sym-info-2.c",
35857 fullname="/project/gdb.mi/mi-sym-info-2.c",
35858 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
35859 @end group
35860 @end smallexample
35861
35862 @subheading The @code{-symbol-info-variables} Command
35863 @findex -symbol-info-variables
35864 @anchor{-symbol-info-variables}
35865
35866 @subsubheading Synopsis
35867
35868 @smallexample
35869 -symbol-info-variables [--include-nondebug]
35870 [--type @var{type_regexp}]
35871 [--name @var{name_regexp}]
35872 [--max-results @var{limit}]
35873
35874 @end smallexample
35875
35876 @noindent
35877 Return a list containing the names and types for all global variables
35878 taken from the debug information. The variables are grouped by source
35879 file, and shown with the line number on which each variable is
35880 defined.
35881
35882 The @code{--include-nondebug} option causes the output to include
35883 data symbols from the symbol table.
35884
35885 The options @code{--type} and @code{--name} allow the symbols returned
35886 to be filtered based on either the name of the variable, or the type
35887 of the variable.
35888
35889 The option @code{--max-results} restricts the command to return no
35890 more than @var{limit} results. If exactly @var{limit} results are
35891 returned then there might be additional results available if a higher
35892 limit is used.
35893
35894 @subsubheading @value{GDBN} Command
35895
35896 The corresponding @value{GDBN} command is @samp{info variables}.
35897
35898 @subsubheading Example
35899 @smallexample
35900 @group
35901 (gdb)
35902 -symbol-info-variables
35903 ^done,symbols=
35904 @{debug=
35905 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35906 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35907 symbols=[@{line="25",name="global_f1",type="float",
35908 description="static float global_f1;"@},
35909 @{line="24",name="global_i1",type="int",
35910 description="static int global_i1;"@}]@},
35911 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35912 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35913 symbols=[@{line="21",name="global_f2",type="int",
35914 description="int global_f2;"@},
35915 @{line="20",name="global_i2",type="int",
35916 description="int global_i2;"@},
35917 @{line="19",name="global_f1",type="float",
35918 description="static float global_f1;"@},
35919 @{line="18",name="global_i1",type="int",
35920 description="static int global_i1;"@}]@}]@}
35921 @end group
35922 @group
35923 (gdb)
35924 -symbol-info-variables --name f1
35925 ^done,symbols=
35926 @{debug=
35927 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35928 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35929 symbols=[@{line="25",name="global_f1",type="float",
35930 description="static float global_f1;"@}]@},
35931 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35932 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35933 symbols=[@{line="19",name="global_f1",type="float",
35934 description="static float global_f1;"@}]@}]@}
35935 @end group
35936 @group
35937 (gdb)
35938 -symbol-info-variables --type float
35939 ^done,symbols=
35940 @{debug=
35941 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35942 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35943 symbols=[@{line="25",name="global_f1",type="float",
35944 description="static float global_f1;"@}]@},
35945 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35946 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35947 symbols=[@{line="19",name="global_f1",type="float",
35948 description="static float global_f1;"@}]@}]@}
35949 @end group
35950 @group
35951 (gdb)
35952 -symbol-info-variables --include-nondebug
35953 ^done,symbols=
35954 @{debug=
35955 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35956 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35957 symbols=[@{line="25",name="global_f1",type="float",
35958 description="static float global_f1;"@},
35959 @{line="24",name="global_i1",type="int",
35960 description="static int global_i1;"@}]@},
35961 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35962 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35963 symbols=[@{line="21",name="global_f2",type="int",
35964 description="int global_f2;"@},
35965 @{line="20",name="global_i2",type="int",
35966 description="int global_i2;"@},
35967 @{line="19",name="global_f1",type="float",
35968 description="static float global_f1;"@},
35969 @{line="18",name="global_i1",type="int",
35970 description="static int global_i1;"@}]@}],
35971 nondebug=
35972 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35973 @{address="0x00000000004005d8",name="__dso_handle"@}
35974 ...
35975 ]@}
35976 @end group
35977 @end smallexample
35978
35979 @ignore
35980 @subheading The @code{-symbol-info-line} Command
35981 @findex -symbol-info-line
35982
35983 @subsubheading Synopsis
35984
35985 @smallexample
35986 -symbol-info-line
35987 @end smallexample
35988
35989 Show the core addresses of the code for a source line.
35990
35991 @subsubheading @value{GDBN} Command
35992
35993 The corresponding @value{GDBN} command is @samp{info line}.
35994 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
35995
35996 @subsubheading Example
35997 N.A.
35998
35999
36000 @subheading The @code{-symbol-info-symbol} Command
36001 @findex -symbol-info-symbol
36002
36003 @subsubheading Synopsis
36004
36005 @smallexample
36006 -symbol-info-symbol @var{addr}
36007 @end smallexample
36008
36009 Describe what symbol is at location @var{addr}.
36010
36011 @subsubheading @value{GDBN} Command
36012
36013 The corresponding @value{GDBN} command is @samp{info symbol}.
36014
36015 @subsubheading Example
36016 N.A.
36017
36018
36019 @subheading The @code{-symbol-list-functions} Command
36020 @findex -symbol-list-functions
36021
36022 @subsubheading Synopsis
36023
36024 @smallexample
36025 -symbol-list-functions
36026 @end smallexample
36027
36028 List the functions in the executable.
36029
36030 @subsubheading @value{GDBN} Command
36031
36032 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
36033 @samp{gdb_search} in @code{gdbtk}.
36034
36035 @subsubheading Example
36036 N.A.
36037 @end ignore
36038
36039
36040 @subheading The @code{-symbol-list-lines} Command
36041 @findex -symbol-list-lines
36042
36043 @subsubheading Synopsis
36044
36045 @smallexample
36046 -symbol-list-lines @var{filename}
36047 @end smallexample
36048
36049 Print the list of lines that contain code and their associated program
36050 addresses for the given source filename. The entries are sorted in
36051 ascending PC order.
36052
36053 @subsubheading @value{GDBN} Command
36054
36055 There is no corresponding @value{GDBN} command.
36056
36057 @subsubheading Example
36058 @smallexample
36059 (gdb)
36060 -symbol-list-lines basics.c
36061 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
36062 (gdb)
36063 @end smallexample
36064
36065
36066 @ignore
36067 @subheading The @code{-symbol-list-types} Command
36068 @findex -symbol-list-types
36069
36070 @subsubheading Synopsis
36071
36072 @smallexample
36073 -symbol-list-types
36074 @end smallexample
36075
36076 List all the type names.
36077
36078 @subsubheading @value{GDBN} Command
36079
36080 The corresponding commands are @samp{info types} in @value{GDBN},
36081 @samp{gdb_search} in @code{gdbtk}.
36082
36083 @subsubheading Example
36084 N.A.
36085
36086
36087 @subheading The @code{-symbol-list-variables} Command
36088 @findex -symbol-list-variables
36089
36090 @subsubheading Synopsis
36091
36092 @smallexample
36093 -symbol-list-variables
36094 @end smallexample
36095
36096 List all the global and static variable names.
36097
36098 @subsubheading @value{GDBN} Command
36099
36100 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
36101
36102 @subsubheading Example
36103 N.A.
36104
36105
36106 @subheading The @code{-symbol-locate} Command
36107 @findex -symbol-locate
36108
36109 @subsubheading Synopsis
36110
36111 @smallexample
36112 -symbol-locate
36113 @end smallexample
36114
36115 @subsubheading @value{GDBN} Command
36116
36117 @samp{gdb_loc} in @code{gdbtk}.
36118
36119 @subsubheading Example
36120 N.A.
36121
36122
36123 @subheading The @code{-symbol-type} Command
36124 @findex -symbol-type
36125
36126 @subsubheading Synopsis
36127
36128 @smallexample
36129 -symbol-type @var{variable}
36130 @end smallexample
36131
36132 Show type of @var{variable}.
36133
36134 @subsubheading @value{GDBN} Command
36135
36136 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
36137 @samp{gdb_obj_variable}.
36138
36139 @subsubheading Example
36140 N.A.
36141 @end ignore
36142
36143
36144 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36145 @node GDB/MI File Commands
36146 @section @sc{gdb/mi} File Commands
36147
36148 This section describes the GDB/MI commands to specify executable file names
36149 and to read in and obtain symbol table information.
36150
36151 @subheading The @code{-file-exec-and-symbols} Command
36152 @findex -file-exec-and-symbols
36153
36154 @subsubheading Synopsis
36155
36156 @smallexample
36157 -file-exec-and-symbols @var{file}
36158 @end smallexample
36159
36160 Specify the executable file to be debugged. This file is the one from
36161 which the symbol table is also read. If no file is specified, the
36162 command clears the executable and symbol information. If breakpoints
36163 are set when using this command with no arguments, @value{GDBN} will produce
36164 error messages. Otherwise, no output is produced, except a completion
36165 notification.
36166
36167 @subsubheading @value{GDBN} Command
36168
36169 The corresponding @value{GDBN} command is @samp{file}.
36170
36171 @subsubheading Example
36172
36173 @smallexample
36174 (gdb)
36175 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
36176 ^done
36177 (gdb)
36178 @end smallexample
36179
36180
36181 @subheading The @code{-file-exec-file} Command
36182 @findex -file-exec-file
36183
36184 @subsubheading Synopsis
36185
36186 @smallexample
36187 -file-exec-file @var{file}
36188 @end smallexample
36189
36190 Specify the executable file to be debugged. Unlike
36191 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
36192 from this file. If used without argument, @value{GDBN} clears the information
36193 about the executable file. No output is produced, except a completion
36194 notification.
36195
36196 @subsubheading @value{GDBN} Command
36197
36198 The corresponding @value{GDBN} command is @samp{exec-file}.
36199
36200 @subsubheading Example
36201
36202 @smallexample
36203 (gdb)
36204 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
36205 ^done
36206 (gdb)
36207 @end smallexample
36208
36209
36210 @ignore
36211 @subheading The @code{-file-list-exec-sections} Command
36212 @findex -file-list-exec-sections
36213
36214 @subsubheading Synopsis
36215
36216 @smallexample
36217 -file-list-exec-sections
36218 @end smallexample
36219
36220 List the sections of the current executable file.
36221
36222 @subsubheading @value{GDBN} Command
36223
36224 The @value{GDBN} command @samp{info file} shows, among the rest, the same
36225 information as this command. @code{gdbtk} has a corresponding command
36226 @samp{gdb_load_info}.
36227
36228 @subsubheading Example
36229 N.A.
36230 @end ignore
36231
36232
36233 @subheading The @code{-file-list-exec-source-file} Command
36234 @findex -file-list-exec-source-file
36235
36236 @subsubheading Synopsis
36237
36238 @smallexample
36239 -file-list-exec-source-file
36240 @end smallexample
36241
36242 List the line number, the current source file, and the absolute path
36243 to the current source file for the current executable. The macro
36244 information field has a value of @samp{1} or @samp{0} depending on
36245 whether or not the file includes preprocessor macro information.
36246
36247 @subsubheading @value{GDBN} Command
36248
36249 The @value{GDBN} equivalent is @samp{info source}
36250
36251 @subsubheading Example
36252
36253 @smallexample
36254 (gdb)
36255 123-file-list-exec-source-file
36256 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
36257 (gdb)
36258 @end smallexample
36259
36260
36261 @subheading The @code{-file-list-exec-source-files} Command
36262 @kindex info sources
36263 @findex -file-list-exec-source-files
36264
36265 @subsubheading Synopsis
36266
36267 @smallexample
36268 -file-list-exec-source-files @r{[} @var{--group-by-objfile} @r{]}
36269 @r{[} @var{--dirname} @r{|} @var{--basename} @r{]}
36270 @r{[} -- @r{]}
36271 @r{[} @var{regexp} @r{]}
36272 @end smallexample
36273
36274 This command returns information about the source files @value{GDBN}
36275 knows about, it will output both the filename and fullname (absolute
36276 file name) of a source file, though the fullname can be elided if this
36277 information is not known to @value{GDBN}.
36278
36279 With no arguments this command returns a list of source files. Each
36280 source file is represented by a tuple with the fields; @var{file},
36281 @var{fullname}, and @var{debug-fully-read}. The @var{file} is the
36282 display name for the file, while @var{fullname} is the absolute name
36283 of the file. The @var{fullname} field can be elided if the absolute
36284 name of the source file can't be computed. The field
36285 @var{debug-fully-read} will be a string, either @code{true} or
36286 @code{false}. When @code{true}, this indicates the full debug
36287 information for the compilation unit describing this file has been
36288 read in. When @code{false}, the full debug information has not yet
36289 been read in. While reading in the full debug information it is
36290 possible that @value{GDBN} could become aware of additional source
36291 files.
36292
36293 The optional @var{regexp} can be used to filter the list of source
36294 files returned. The @var{regexp} will be matched against the full
36295 source file name. The matching is case-sensitive, except on operating
36296 systems that have case-insensitive filesystem (e.g.,
36297 MS-Windows). @samp{--} can be used before @var{regexp} to prevent
36298 @value{GDBN} interpreting @var{regexp} as a command option (e.g.@: if
36299 @var{regexp} starts with @samp{-}).
36300
36301 If @code{--dirname} is provided, then @var{regexp} is matched only
36302 against the directory name of each source file. If @code{--basename}
36303 is provided, then @var{regexp} is matched against the basename of each
36304 source file. Only one of @code{--dirname} or @code{--basename} may be
36305 given, and if either is given then @var{regexp} is required.
36306
36307 If @code{--group-by-objfile} is used then the format of the results is
36308 changed. The results will now be a list of tuples, with each tuple
36309 representing an object file (executable or shared library) loaded into
36310 @value{GDBN}. The fields of these tuples are; @var{filename},
36311 @var{debug-info}, and @var{sources}. The @var{filename} is the
36312 absolute name of the object file, @var{debug-info} is a string with
36313 one of the following values:
36314
36315 @table @code
36316 @item none
36317 This object file has no debug information.
36318 @item partially-read
36319 This object file has debug information, but it is not fully read in
36320 yet. When it is read in later, GDB might become aware of additional
36321 source files.
36322 @item fully-read
36323 This object file has debug information, and this information is fully
36324 read into GDB. The list of source files is complete.
36325 @end table
36326
36327 The @var{sources} is a list or tuples, with each tuple describing a
36328 single source file with the same fields as described previously. The
36329 @var{sources} list can be empty for object files that have no debug
36330 information.
36331
36332 @subsubheading @value{GDBN} Command
36333
36334 The @value{GDBN} equivalent is @samp{info sources}.
36335 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
36336
36337 @subsubheading Example
36338 @smallexample
36339 (@value{GDBP})
36340 -file-list-exec-source-files
36341 ^done,files=[@{file="foo.c",fullname="/home/foo.c",debug-fully-read="true"@},
36342 @{file="/home/bar.c",fullname="/home/bar.c",debug-fully-read="true"@},
36343 @{file="gdb_could_not_find_fullpath.c",debug-fully-read="true"@}]
36344 (@value{GDBP})
36345 -file-list-exec-source-files
36346 ^done,files=[@{file="test.c",
36347 fullname="/tmp/info-sources/test.c",
36348 debug-fully-read="true"@},
36349 @{file="/usr/include/stdc-predef.h",
36350 fullname="/usr/include/stdc-predef.h",
36351 debug-fully-read="true"@},
36352 @{file="header.h",
36353 fullname="/tmp/info-sources/header.h",
36354 debug-fully-read="true"@},
36355 @{file="helper.c",
36356 fullname="/tmp/info-sources/helper.c",
36357 debug-fully-read="true"@}]
36358 (@value{GDBP})
36359 -file-list-exec-source-files -- \\.c
36360 ^done,files=[@{file="test.c",
36361 fullname="/tmp/info-sources/test.c",
36362 debug-fully-read="true"@},
36363 @{file="helper.c",
36364 fullname="/tmp/info-sources/helper.c",
36365 debug-fully-read="true"@}]
36366 (@value{GDBP})
36367 -file-list-exec-source-files --group-by-objfile
36368 ^done,files=[@{filename="/tmp/info-sources/test.x",
36369 debug-info="fully-read",
36370 sources=[@{file="test.c",
36371 fullname="/tmp/info-sources/test.c",
36372 debug-fully-read="true"@},
36373 @{file="/usr/include/stdc-predef.h",
36374 fullname="/usr/include/stdc-predef.h",
36375 debug-fully-read="true"@},
36376 @{file="header.h",
36377 fullname="/tmp/info-sources/header.h",
36378 debug-fully-read="true"@}]@},
36379 @{filename="/lib64/ld-linux-x86-64.so.2",
36380 debug-info="none",
36381 sources=[]@},
36382 @{filename="system-supplied DSO at 0x7ffff7fcf000",
36383 debug-info="none",
36384 sources=[]@},
36385 @{filename="/tmp/info-sources/libhelper.so",
36386 debug-info="fully-read",
36387 sources=[@{file="helper.c",
36388 fullname="/tmp/info-sources/helper.c",
36389 debug-fully-read="true"@},
36390 @{file="/usr/include/stdc-predef.h",
36391 fullname="/usr/include/stdc-predef.h",
36392 debug-fully-read="true"@},
36393 @{file="header.h",
36394 fullname="/tmp/info-sources/header.h",
36395 debug-fully-read="true"@}]@},
36396 @{filename="/lib64/libc.so.6",
36397 debug-info="none",
36398 sources=[]@}]
36399 @end smallexample
36400
36401 @subheading The @code{-file-list-shared-libraries} Command
36402 @findex -file-list-shared-libraries
36403
36404 @subsubheading Synopsis
36405
36406 @smallexample
36407 -file-list-shared-libraries [ @var{regexp} ]
36408 @end smallexample
36409
36410 List the shared libraries in the program.
36411 With a regular expression @var{regexp}, only those libraries whose
36412 names match @var{regexp} are listed.
36413
36414 @subsubheading @value{GDBN} Command
36415
36416 The corresponding @value{GDBN} command is @samp{info shared}. The fields
36417 have a similar meaning to the @code{=library-loaded} notification.
36418 The @code{ranges} field specifies the multiple segments belonging to this
36419 library. Each range has the following fields:
36420
36421 @table @samp
36422 @item from
36423 The address defining the inclusive lower bound of the segment.
36424 @item to
36425 The address defining the exclusive upper bound of the segment.
36426 @end table
36427
36428 @subsubheading Example
36429 @smallexample
36430 (gdb)
36431 -file-list-exec-source-files
36432 ^done,shared-libraries=[
36433 @{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"@}]@},
36434 @{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"@}]@}]
36435 (gdb)
36436 @end smallexample
36437
36438
36439 @ignore
36440 @subheading The @code{-file-list-symbol-files} Command
36441 @findex -file-list-symbol-files
36442
36443 @subsubheading Synopsis
36444
36445 @smallexample
36446 -file-list-symbol-files
36447 @end smallexample
36448
36449 List symbol files.
36450
36451 @subsubheading @value{GDBN} Command
36452
36453 The corresponding @value{GDBN} command is @samp{info file} (part of it).
36454
36455 @subsubheading Example
36456 N.A.
36457 @end ignore
36458
36459
36460 @subheading The @code{-file-symbol-file} Command
36461 @findex -file-symbol-file
36462
36463 @subsubheading Synopsis
36464
36465 @smallexample
36466 -file-symbol-file @var{file}
36467 @end smallexample
36468
36469 Read symbol table info from the specified @var{file} argument. When
36470 used without arguments, clears @value{GDBN}'s symbol table info. No output is
36471 produced, except for a completion notification.
36472
36473 @subsubheading @value{GDBN} Command
36474
36475 The corresponding @value{GDBN} command is @samp{symbol-file}.
36476
36477 @subsubheading Example
36478
36479 @smallexample
36480 (gdb)
36481 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
36482 ^done
36483 (gdb)
36484 @end smallexample
36485
36486 @ignore
36487 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36488 @node GDB/MI Memory Overlay Commands
36489 @section @sc{gdb/mi} Memory Overlay Commands
36490
36491 The memory overlay commands are not implemented.
36492
36493 @c @subheading -overlay-auto
36494
36495 @c @subheading -overlay-list-mapping-state
36496
36497 @c @subheading -overlay-list-overlays
36498
36499 @c @subheading -overlay-map
36500
36501 @c @subheading -overlay-off
36502
36503 @c @subheading -overlay-on
36504
36505 @c @subheading -overlay-unmap
36506
36507 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36508 @node GDB/MI Signal Handling Commands
36509 @section @sc{gdb/mi} Signal Handling Commands
36510
36511 Signal handling commands are not implemented.
36512
36513 @c @subheading -signal-handle
36514
36515 @c @subheading -signal-list-handle-actions
36516
36517 @c @subheading -signal-list-signal-types
36518 @end ignore
36519
36520
36521 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36522 @node GDB/MI Target Manipulation
36523 @section @sc{gdb/mi} Target Manipulation Commands
36524
36525
36526 @subheading The @code{-target-attach} Command
36527 @findex -target-attach
36528
36529 @subsubheading Synopsis
36530
36531 @smallexample
36532 -target-attach @var{pid} | @var{gid} | @var{file}
36533 @end smallexample
36534
36535 Attach to a process @var{pid} or a file @var{file} outside of
36536 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
36537 group, the id previously returned by
36538 @samp{-list-thread-groups --available} must be used.
36539
36540 @subsubheading @value{GDBN} Command
36541
36542 The corresponding @value{GDBN} command is @samp{attach}.
36543
36544 @subsubheading Example
36545 @smallexample
36546 (gdb)
36547 -target-attach 34
36548 =thread-created,id="1"
36549 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
36550 ^done
36551 (gdb)
36552 @end smallexample
36553
36554 @ignore
36555 @subheading The @code{-target-compare-sections} Command
36556 @findex -target-compare-sections
36557
36558 @subsubheading Synopsis
36559
36560 @smallexample
36561 -target-compare-sections [ @var{section} ]
36562 @end smallexample
36563
36564 Compare data of section @var{section} on target to the exec file.
36565 Without the argument, all sections are compared.
36566
36567 @subsubheading @value{GDBN} Command
36568
36569 The @value{GDBN} equivalent is @samp{compare-sections}.
36570
36571 @subsubheading Example
36572 N.A.
36573 @end ignore
36574
36575
36576 @subheading The @code{-target-detach} Command
36577 @findex -target-detach
36578
36579 @subsubheading Synopsis
36580
36581 @smallexample
36582 -target-detach [ @var{pid} | @var{gid} ]
36583 @end smallexample
36584
36585 Detach from the remote target which normally resumes its execution.
36586 If either @var{pid} or @var{gid} is specified, detaches from either
36587 the specified process, or specified thread group. There's no output.
36588
36589 @subsubheading @value{GDBN} Command
36590
36591 The corresponding @value{GDBN} command is @samp{detach}.
36592
36593 @subsubheading Example
36594
36595 @smallexample
36596 (gdb)
36597 -target-detach
36598 ^done
36599 (gdb)
36600 @end smallexample
36601
36602
36603 @subheading The @code{-target-disconnect} Command
36604 @findex -target-disconnect
36605
36606 @subsubheading Synopsis
36607
36608 @smallexample
36609 -target-disconnect
36610 @end smallexample
36611
36612 Disconnect from the remote target. There's no output and the target is
36613 generally not resumed.
36614
36615 @subsubheading @value{GDBN} Command
36616
36617 The corresponding @value{GDBN} command is @samp{disconnect}.
36618
36619 @subsubheading Example
36620
36621 @smallexample
36622 (gdb)
36623 -target-disconnect
36624 ^done
36625 (gdb)
36626 @end smallexample
36627
36628
36629 @subheading The @code{-target-download} Command
36630 @findex -target-download
36631
36632 @subsubheading Synopsis
36633
36634 @smallexample
36635 -target-download
36636 @end smallexample
36637
36638 Loads the executable onto the remote target.
36639 It prints out an update message every half second, which includes the fields:
36640
36641 @table @samp
36642 @item section
36643 The name of the section.
36644 @item section-sent
36645 The size of what has been sent so far for that section.
36646 @item section-size
36647 The size of the section.
36648 @item total-sent
36649 The total size of what was sent so far (the current and the previous sections).
36650 @item total-size
36651 The size of the overall executable to download.
36652 @end table
36653
36654 @noindent
36655 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
36656 @sc{gdb/mi} Output Syntax}).
36657
36658 In addition, it prints the name and size of the sections, as they are
36659 downloaded. These messages include the following fields:
36660
36661 @table @samp
36662 @item section
36663 The name of the section.
36664 @item section-size
36665 The size of the section.
36666 @item total-size
36667 The size of the overall executable to download.
36668 @end table
36669
36670 @noindent
36671 At the end, a summary is printed.
36672
36673 @subsubheading @value{GDBN} Command
36674
36675 The corresponding @value{GDBN} command is @samp{load}.
36676
36677 @subsubheading Example
36678
36679 Note: each status message appears on a single line. Here the messages
36680 have been broken down so that they can fit onto a page.
36681
36682 @smallexample
36683 (gdb)
36684 -target-download
36685 +download,@{section=".text",section-size="6668",total-size="9880"@}
36686 +download,@{section=".text",section-sent="512",section-size="6668",
36687 total-sent="512",total-size="9880"@}
36688 +download,@{section=".text",section-sent="1024",section-size="6668",
36689 total-sent="1024",total-size="9880"@}
36690 +download,@{section=".text",section-sent="1536",section-size="6668",
36691 total-sent="1536",total-size="9880"@}
36692 +download,@{section=".text",section-sent="2048",section-size="6668",
36693 total-sent="2048",total-size="9880"@}
36694 +download,@{section=".text",section-sent="2560",section-size="6668",
36695 total-sent="2560",total-size="9880"@}
36696 +download,@{section=".text",section-sent="3072",section-size="6668",
36697 total-sent="3072",total-size="9880"@}
36698 +download,@{section=".text",section-sent="3584",section-size="6668",
36699 total-sent="3584",total-size="9880"@}
36700 +download,@{section=".text",section-sent="4096",section-size="6668",
36701 total-sent="4096",total-size="9880"@}
36702 +download,@{section=".text",section-sent="4608",section-size="6668",
36703 total-sent="4608",total-size="9880"@}
36704 +download,@{section=".text",section-sent="5120",section-size="6668",
36705 total-sent="5120",total-size="9880"@}
36706 +download,@{section=".text",section-sent="5632",section-size="6668",
36707 total-sent="5632",total-size="9880"@}
36708 +download,@{section=".text",section-sent="6144",section-size="6668",
36709 total-sent="6144",total-size="9880"@}
36710 +download,@{section=".text",section-sent="6656",section-size="6668",
36711 total-sent="6656",total-size="9880"@}
36712 +download,@{section=".init",section-size="28",total-size="9880"@}
36713 +download,@{section=".fini",section-size="28",total-size="9880"@}
36714 +download,@{section=".data",section-size="3156",total-size="9880"@}
36715 +download,@{section=".data",section-sent="512",section-size="3156",
36716 total-sent="7236",total-size="9880"@}
36717 +download,@{section=".data",section-sent="1024",section-size="3156",
36718 total-sent="7748",total-size="9880"@}
36719 +download,@{section=".data",section-sent="1536",section-size="3156",
36720 total-sent="8260",total-size="9880"@}
36721 +download,@{section=".data",section-sent="2048",section-size="3156",
36722 total-sent="8772",total-size="9880"@}
36723 +download,@{section=".data",section-sent="2560",section-size="3156",
36724 total-sent="9284",total-size="9880"@}
36725 +download,@{section=".data",section-sent="3072",section-size="3156",
36726 total-sent="9796",total-size="9880"@}
36727 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
36728 write-rate="429"
36729 (gdb)
36730 @end smallexample
36731
36732
36733 @ignore
36734 @subheading The @code{-target-exec-status} Command
36735 @findex -target-exec-status
36736
36737 @subsubheading Synopsis
36738
36739 @smallexample
36740 -target-exec-status
36741 @end smallexample
36742
36743 Provide information on the state of the target (whether it is running or
36744 not, for instance).
36745
36746 @subsubheading @value{GDBN} Command
36747
36748 There's no equivalent @value{GDBN} command.
36749
36750 @subsubheading Example
36751 N.A.
36752
36753
36754 @subheading The @code{-target-list-available-targets} Command
36755 @findex -target-list-available-targets
36756
36757 @subsubheading Synopsis
36758
36759 @smallexample
36760 -target-list-available-targets
36761 @end smallexample
36762
36763 List the possible targets to connect to.
36764
36765 @subsubheading @value{GDBN} Command
36766
36767 The corresponding @value{GDBN} command is @samp{help target}.
36768
36769 @subsubheading Example
36770 N.A.
36771
36772
36773 @subheading The @code{-target-list-current-targets} Command
36774 @findex -target-list-current-targets
36775
36776 @subsubheading Synopsis
36777
36778 @smallexample
36779 -target-list-current-targets
36780 @end smallexample
36781
36782 Describe the current target.
36783
36784 @subsubheading @value{GDBN} Command
36785
36786 The corresponding information is printed by @samp{info file} (among
36787 other things).
36788
36789 @subsubheading Example
36790 N.A.
36791
36792
36793 @subheading The @code{-target-list-parameters} Command
36794 @findex -target-list-parameters
36795
36796 @subsubheading Synopsis
36797
36798 @smallexample
36799 -target-list-parameters
36800 @end smallexample
36801
36802 @c ????
36803 @end ignore
36804
36805 @subsubheading @value{GDBN} Command
36806
36807 No equivalent.
36808
36809 @subsubheading Example
36810 N.A.
36811
36812 @subheading The @code{-target-flash-erase} Command
36813 @findex -target-flash-erase
36814
36815 @subsubheading Synopsis
36816
36817 @smallexample
36818 -target-flash-erase
36819 @end smallexample
36820
36821 Erases all known flash memory regions on the target.
36822
36823 The corresponding @value{GDBN} command is @samp{flash-erase}.
36824
36825 The output is a list of flash regions that have been erased, with starting
36826 addresses and memory region sizes.
36827
36828 @smallexample
36829 (gdb)
36830 -target-flash-erase
36831 ^done,erased-regions=@{address="0x0",size="0x40000"@}
36832 (gdb)
36833 @end smallexample
36834
36835 @subheading The @code{-target-select} Command
36836 @findex -target-select
36837
36838 @subsubheading Synopsis
36839
36840 @smallexample
36841 -target-select @var{type} @var{parameters @dots{}}
36842 @end smallexample
36843
36844 Connect @value{GDBN} to the remote target. This command takes two args:
36845
36846 @table @samp
36847 @item @var{type}
36848 The type of target, for instance @samp{remote}, etc.
36849 @item @var{parameters}
36850 Device names, host names and the like. @xref{Target Commands, ,
36851 Commands for Managing Targets}, for more details.
36852 @end table
36853
36854 The output is a connection notification, followed by the address at
36855 which the target program is, in the following form:
36856
36857 @smallexample
36858 ^connected,addr="@var{address}",func="@var{function name}",
36859 args=[@var{arg list}]
36860 @end smallexample
36861
36862 @subsubheading @value{GDBN} Command
36863
36864 The corresponding @value{GDBN} command is @samp{target}.
36865
36866 @subsubheading Example
36867
36868 @smallexample
36869 (gdb)
36870 -target-select remote /dev/ttya
36871 ^connected,addr="0xfe00a300",func="??",args=[]
36872 (gdb)
36873 @end smallexample
36874
36875 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36876 @node GDB/MI File Transfer Commands
36877 @section @sc{gdb/mi} File Transfer Commands
36878
36879
36880 @subheading The @code{-target-file-put} Command
36881 @findex -target-file-put
36882
36883 @subsubheading Synopsis
36884
36885 @smallexample
36886 -target-file-put @var{hostfile} @var{targetfile}
36887 @end smallexample
36888
36889 Copy file @var{hostfile} from the host system (the machine running
36890 @value{GDBN}) to @var{targetfile} on the target system.
36891
36892 @subsubheading @value{GDBN} Command
36893
36894 The corresponding @value{GDBN} command is @samp{remote put}.
36895
36896 @subsubheading Example
36897
36898 @smallexample
36899 (gdb)
36900 -target-file-put localfile remotefile
36901 ^done
36902 (gdb)
36903 @end smallexample
36904
36905
36906 @subheading The @code{-target-file-get} Command
36907 @findex -target-file-get
36908
36909 @subsubheading Synopsis
36910
36911 @smallexample
36912 -target-file-get @var{targetfile} @var{hostfile}
36913 @end smallexample
36914
36915 Copy file @var{targetfile} from the target system to @var{hostfile}
36916 on the host system.
36917
36918 @subsubheading @value{GDBN} Command
36919
36920 The corresponding @value{GDBN} command is @samp{remote get}.
36921
36922 @subsubheading Example
36923
36924 @smallexample
36925 (gdb)
36926 -target-file-get remotefile localfile
36927 ^done
36928 (gdb)
36929 @end smallexample
36930
36931
36932 @subheading The @code{-target-file-delete} Command
36933 @findex -target-file-delete
36934
36935 @subsubheading Synopsis
36936
36937 @smallexample
36938 -target-file-delete @var{targetfile}
36939 @end smallexample
36940
36941 Delete @var{targetfile} from the target system.
36942
36943 @subsubheading @value{GDBN} Command
36944
36945 The corresponding @value{GDBN} command is @samp{remote delete}.
36946
36947 @subsubheading Example
36948
36949 @smallexample
36950 (gdb)
36951 -target-file-delete remotefile
36952 ^done
36953 (gdb)
36954 @end smallexample
36955
36956
36957 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36958 @node GDB/MI Ada Exceptions Commands
36959 @section Ada Exceptions @sc{gdb/mi} Commands
36960
36961 @subheading The @code{-info-ada-exceptions} Command
36962 @findex -info-ada-exceptions
36963
36964 @subsubheading Synopsis
36965
36966 @smallexample
36967 -info-ada-exceptions [ @var{regexp}]
36968 @end smallexample
36969
36970 List all Ada exceptions defined within the program being debugged.
36971 With a regular expression @var{regexp}, only those exceptions whose
36972 names match @var{regexp} are listed.
36973
36974 @subsubheading @value{GDBN} Command
36975
36976 The corresponding @value{GDBN} command is @samp{info exceptions}.
36977
36978 @subsubheading Result
36979
36980 The result is a table of Ada exceptions. The following columns are
36981 defined for each exception:
36982
36983 @table @samp
36984 @item name
36985 The name of the exception.
36986
36987 @item address
36988 The address of the exception.
36989
36990 @end table
36991
36992 @subsubheading Example
36993
36994 @smallexample
36995 -info-ada-exceptions aint
36996 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
36997 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
36998 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
36999 body=[@{name="constraint_error",address="0x0000000000613da0"@},
37000 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
37001 @end smallexample
37002
37003 @subheading Catching Ada Exceptions
37004
37005 The commands describing how to ask @value{GDBN} to stop when a program
37006 raises an exception are described at @ref{Ada Exception GDB/MI
37007 Catchpoint Commands}.
37008
37009
37010 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37011 @node GDB/MI Support Commands
37012 @section @sc{gdb/mi} Support Commands
37013
37014 Since new commands and features get regularly added to @sc{gdb/mi},
37015 some commands are available to help front-ends query the debugger
37016 about support for these capabilities. Similarly, it is also possible
37017 to query @value{GDBN} about target support of certain features.
37018
37019 @subheading The @code{-info-gdb-mi-command} Command
37020 @cindex @code{-info-gdb-mi-command}
37021 @findex -info-gdb-mi-command
37022
37023 @subsubheading Synopsis
37024
37025 @smallexample
37026 -info-gdb-mi-command @var{cmd_name}
37027 @end smallexample
37028
37029 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
37030
37031 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
37032 is technically not part of the command name (@pxref{GDB/MI Input
37033 Syntax}), and thus should be omitted in @var{cmd_name}. However,
37034 for ease of use, this command also accepts the form with the leading
37035 dash.
37036
37037 @subsubheading @value{GDBN} Command
37038
37039 There is no corresponding @value{GDBN} command.
37040
37041 @subsubheading Result
37042
37043 The result is a tuple. There is currently only one field:
37044
37045 @table @samp
37046 @item exists
37047 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
37048 @code{"false"} otherwise.
37049
37050 @end table
37051
37052 @subsubheading Example
37053
37054 Here is an example where the @sc{gdb/mi} command does not exist:
37055
37056 @smallexample
37057 -info-gdb-mi-command unsupported-command
37058 ^done,command=@{exists="false"@}
37059 @end smallexample
37060
37061 @noindent
37062 And here is an example where the @sc{gdb/mi} command is known
37063 to the debugger:
37064
37065 @smallexample
37066 -info-gdb-mi-command symbol-list-lines
37067 ^done,command=@{exists="true"@}
37068 @end smallexample
37069
37070 @subheading The @code{-list-features} Command
37071 @findex -list-features
37072 @cindex supported @sc{gdb/mi} features, list
37073
37074 Returns a list of particular features of the MI protocol that
37075 this version of gdb implements. A feature can be a command,
37076 or a new field in an output of some command, or even an
37077 important bugfix. While a frontend can sometimes detect presence
37078 of a feature at runtime, it is easier to perform detection at debugger
37079 startup.
37080
37081 The command returns a list of strings, with each string naming an
37082 available feature. Each returned string is just a name, it does not
37083 have any internal structure. The list of possible feature names
37084 is given below.
37085
37086 Example output:
37087
37088 @smallexample
37089 (gdb) -list-features
37090 ^done,result=["feature1","feature2"]
37091 @end smallexample
37092
37093 The current list of features is:
37094
37095 @ftable @samp
37096 @item frozen-varobjs
37097 Indicates support for the @code{-var-set-frozen} command, as well
37098 as possible presence of the @code{frozen} field in the output
37099 of @code{-varobj-create}.
37100 @item pending-breakpoints
37101 Indicates support for the @option{-f} option to the @code{-break-insert}
37102 command.
37103 @item python
37104 Indicates Python scripting support, Python-based
37105 pretty-printing commands, and possible presence of the
37106 @samp{display_hint} field in the output of @code{-var-list-children}
37107 @item thread-info
37108 Indicates support for the @code{-thread-info} command.
37109 @item data-read-memory-bytes
37110 Indicates support for the @code{-data-read-memory-bytes} and the
37111 @code{-data-write-memory-bytes} commands.
37112 @item breakpoint-notifications
37113 Indicates that changes to breakpoints and breakpoints created via the
37114 CLI will be announced via async records.
37115 @item ada-task-info
37116 Indicates support for the @code{-ada-task-info} command.
37117 @item language-option
37118 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
37119 option (@pxref{Context management}).
37120 @item info-gdb-mi-command
37121 Indicates support for the @code{-info-gdb-mi-command} command.
37122 @item undefined-command-error-code
37123 Indicates support for the "undefined-command" error code in error result
37124 records, produced when trying to execute an undefined @sc{gdb/mi} command
37125 (@pxref{GDB/MI Result Records}).
37126 @item exec-run-start-option
37127 Indicates that the @code{-exec-run} command supports the @option{--start}
37128 option (@pxref{GDB/MI Program Execution}).
37129 @item data-disassemble-a-option
37130 Indicates that the @code{-data-disassemble} command supports the @option{-a}
37131 option (@pxref{GDB/MI Data Manipulation}).
37132 @end ftable
37133
37134 @subheading The @code{-list-target-features} Command
37135 @findex -list-target-features
37136
37137 Returns a list of particular features that are supported by the
37138 target. Those features affect the permitted MI commands, but
37139 unlike the features reported by the @code{-list-features} command, the
37140 features depend on which target GDB is using at the moment. Whenever
37141 a target can change, due to commands such as @code{-target-select},
37142 @code{-target-attach} or @code{-exec-run}, the list of target features
37143 may change, and the frontend should obtain it again.
37144 Example output:
37145
37146 @smallexample
37147 (gdb) -list-target-features
37148 ^done,result=["async"]
37149 @end smallexample
37150
37151 The current list of features is:
37152
37153 @table @samp
37154 @item async
37155 Indicates that the target is capable of asynchronous command
37156 execution, which means that @value{GDBN} will accept further commands
37157 while the target is running.
37158
37159 @item reverse
37160 Indicates that the target is capable of reverse execution.
37161 @xref{Reverse Execution}, for more information.
37162
37163 @end table
37164
37165 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37166 @node GDB/MI Miscellaneous Commands
37167 @section Miscellaneous @sc{gdb/mi} Commands
37168
37169 @c @subheading -gdb-complete
37170
37171 @subheading The @code{-gdb-exit} Command
37172 @findex -gdb-exit
37173
37174 @subsubheading Synopsis
37175
37176 @smallexample
37177 -gdb-exit
37178 @end smallexample
37179
37180 Exit @value{GDBN} immediately.
37181
37182 @subsubheading @value{GDBN} Command
37183
37184 Approximately corresponds to @samp{quit}.
37185
37186 @subsubheading Example
37187
37188 @smallexample
37189 (gdb)
37190 -gdb-exit
37191 ^exit
37192 @end smallexample
37193
37194
37195 @ignore
37196 @subheading The @code{-exec-abort} Command
37197 @findex -exec-abort
37198
37199 @subsubheading Synopsis
37200
37201 @smallexample
37202 -exec-abort
37203 @end smallexample
37204
37205 Kill the inferior running program.
37206
37207 @subsubheading @value{GDBN} Command
37208
37209 The corresponding @value{GDBN} command is @samp{kill}.
37210
37211 @subsubheading Example
37212 N.A.
37213 @end ignore
37214
37215
37216 @subheading The @code{-gdb-set} Command
37217 @findex -gdb-set
37218
37219 @subsubheading Synopsis
37220
37221 @smallexample
37222 -gdb-set
37223 @end smallexample
37224
37225 Set an internal @value{GDBN} variable.
37226 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
37227
37228 @subsubheading @value{GDBN} Command
37229
37230 The corresponding @value{GDBN} command is @samp{set}.
37231
37232 @subsubheading Example
37233
37234 @smallexample
37235 (gdb)
37236 -gdb-set $foo=3
37237 ^done
37238 (gdb)
37239 @end smallexample
37240
37241
37242 @subheading The @code{-gdb-show} Command
37243 @findex -gdb-show
37244
37245 @subsubheading Synopsis
37246
37247 @smallexample
37248 -gdb-show
37249 @end smallexample
37250
37251 Show the current value of a @value{GDBN} variable.
37252
37253 @subsubheading @value{GDBN} Command
37254
37255 The corresponding @value{GDBN} command is @samp{show}.
37256
37257 @subsubheading Example
37258
37259 @smallexample
37260 (gdb)
37261 -gdb-show annotate
37262 ^done,value="0"
37263 (gdb)
37264 @end smallexample
37265
37266 @c @subheading -gdb-source
37267
37268
37269 @subheading The @code{-gdb-version} Command
37270 @findex -gdb-version
37271
37272 @subsubheading Synopsis
37273
37274 @smallexample
37275 -gdb-version
37276 @end smallexample
37277
37278 Show version information for @value{GDBN}. Used mostly in testing.
37279
37280 @subsubheading @value{GDBN} Command
37281
37282 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
37283 default shows this information when you start an interactive session.
37284
37285 @subsubheading Example
37286
37287 @c This example modifies the actual output from GDB to avoid overfull
37288 @c box in TeX.
37289 @smallexample
37290 (gdb)
37291 -gdb-version
37292 ~GNU gdb 5.2.1
37293 ~Copyright 2000 Free Software Foundation, Inc.
37294 ~GDB is free software, covered by the GNU General Public License, and
37295 ~you are welcome to change it and/or distribute copies of it under
37296 ~ certain conditions.
37297 ~Type "show copying" to see the conditions.
37298 ~There is absolutely no warranty for GDB. Type "show warranty" for
37299 ~ details.
37300 ~This GDB was configured as
37301 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
37302 ^done
37303 (gdb)
37304 @end smallexample
37305
37306 @subheading The @code{-list-thread-groups} Command
37307 @findex -list-thread-groups
37308
37309 @subheading Synopsis
37310
37311 @smallexample
37312 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
37313 @end smallexample
37314
37315 Lists thread groups (@pxref{Thread groups}). When a single thread
37316 group is passed as the argument, lists the children of that group.
37317 When several thread group are passed, lists information about those
37318 thread groups. Without any parameters, lists information about all
37319 top-level thread groups.
37320
37321 Normally, thread groups that are being debugged are reported.
37322 With the @samp{--available} option, @value{GDBN} reports thread groups
37323 available on the target.
37324
37325 The output of this command may have either a @samp{threads} result or
37326 a @samp{groups} result. The @samp{thread} result has a list of tuples
37327 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
37328 Information}). The @samp{groups} result has a list of tuples as value,
37329 each tuple describing a thread group. If top-level groups are
37330 requested (that is, no parameter is passed), or when several groups
37331 are passed, the output always has a @samp{groups} result. The format
37332 of the @samp{group} result is described below.
37333
37334 To reduce the number of roundtrips it's possible to list thread groups
37335 together with their children, by passing the @samp{--recurse} option
37336 and the recursion depth. Presently, only recursion depth of 1 is
37337 permitted. If this option is present, then every reported thread group
37338 will also include its children, either as @samp{group} or
37339 @samp{threads} field.
37340
37341 In general, any combination of option and parameters is permitted, with
37342 the following caveats:
37343
37344 @itemize @bullet
37345 @item
37346 When a single thread group is passed, the output will typically
37347 be the @samp{threads} result. Because threads may not contain
37348 anything, the @samp{recurse} option will be ignored.
37349
37350 @item
37351 When the @samp{--available} option is passed, limited information may
37352 be available. In particular, the list of threads of a process might
37353 be inaccessible. Further, specifying specific thread groups might
37354 not give any performance advantage over listing all thread groups.
37355 The frontend should assume that @samp{-list-thread-groups --available}
37356 is always an expensive operation and cache the results.
37357
37358 @end itemize
37359
37360 The @samp{groups} result is a list of tuples, where each tuple may
37361 have the following fields:
37362
37363 @table @code
37364 @item id
37365 Identifier of the thread group. This field is always present.
37366 The identifier is an opaque string; frontends should not try to
37367 convert it to an integer, even though it might look like one.
37368
37369 @item type
37370 The type of the thread group. At present, only @samp{process} is a
37371 valid type.
37372
37373 @item pid
37374 The target-specific process identifier. This field is only present
37375 for thread groups of type @samp{process} and only if the process exists.
37376
37377 @item exit-code
37378 The exit code of this group's last exited thread, formatted in octal.
37379 This field is only present for thread groups of type @samp{process} and
37380 only if the process is not running.
37381
37382 @item num_children
37383 The number of children this thread group has. This field may be
37384 absent for an available thread group.
37385
37386 @item threads
37387 This field has a list of tuples as value, each tuple describing a
37388 thread. It may be present if the @samp{--recurse} option is
37389 specified, and it's actually possible to obtain the threads.
37390
37391 @item cores
37392 This field is a list of integers, each identifying a core that one
37393 thread of the group is running on. This field may be absent if
37394 such information is not available.
37395
37396 @item executable
37397 The name of the executable file that corresponds to this thread group.
37398 The field is only present for thread groups of type @samp{process},
37399 and only if there is a corresponding executable file.
37400
37401 @end table
37402
37403 @subheading Example
37404
37405 @smallexample
37406 (@value{GDBP})
37407 -list-thread-groups
37408 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
37409 -list-thread-groups 17
37410 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
37411 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
37412 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
37413 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
37414 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
37415 -list-thread-groups --available
37416 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
37417 -list-thread-groups --available --recurse 1
37418 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
37419 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
37420 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
37421 -list-thread-groups --available --recurse 1 17 18
37422 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
37423 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
37424 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
37425 @end smallexample
37426
37427 @subheading The @code{-info-os} Command
37428 @findex -info-os
37429
37430 @subsubheading Synopsis
37431
37432 @smallexample
37433 -info-os [ @var{type} ]
37434 @end smallexample
37435
37436 If no argument is supplied, the command returns a table of available
37437 operating-system-specific information types. If one of these types is
37438 supplied as an argument @var{type}, then the command returns a table
37439 of data of that type.
37440
37441 The types of information available depend on the target operating
37442 system.
37443
37444 @subsubheading @value{GDBN} Command
37445
37446 The corresponding @value{GDBN} command is @samp{info os}.
37447
37448 @subsubheading Example
37449
37450 When run on a @sc{gnu}/Linux system, the output will look something
37451 like this:
37452
37453 @smallexample
37454 (@value{GDBP})
37455 -info-os
37456 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
37457 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
37458 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
37459 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
37460 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
37461 col2="CPUs"@},
37462 item=@{col0="files",col1="Listing of all file descriptors",
37463 col2="File descriptors"@},
37464 item=@{col0="modules",col1="Listing of all loaded kernel modules",
37465 col2="Kernel modules"@},
37466 item=@{col0="msg",col1="Listing of all message queues",
37467 col2="Message queues"@},
37468 item=@{col0="processes",col1="Listing of all processes",
37469 col2="Processes"@},
37470 item=@{col0="procgroups",col1="Listing of all process groups",
37471 col2="Process groups"@},
37472 item=@{col0="semaphores",col1="Listing of all semaphores",
37473 col2="Semaphores"@},
37474 item=@{col0="shm",col1="Listing of all shared-memory regions",
37475 col2="Shared-memory regions"@},
37476 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
37477 col2="Sockets"@},
37478 item=@{col0="threads",col1="Listing of all threads",
37479 col2="Threads"@}]
37480 (@value{GDBP})
37481 -info-os processes
37482 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
37483 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
37484 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
37485 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
37486 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
37487 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
37488 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
37489 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
37490 ...
37491 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
37492 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
37493 (@value{GDBP})
37494 @end smallexample
37495
37496 (Note that the MI output here includes a @code{"Title"} column that
37497 does not appear in command-line @code{info os}; this column is useful
37498 for MI clients that want to enumerate the types of data, such as in a
37499 popup menu, but is needless clutter on the command line, and
37500 @code{info os} omits it.)
37501
37502 @subheading The @code{-add-inferior} Command
37503 @findex -add-inferior
37504
37505 @subheading Synopsis
37506
37507 @smallexample
37508 -add-inferior [ --no-connection ]
37509 @end smallexample
37510
37511 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
37512 inferior is not associated with any executable. Such association may
37513 be established with the @samp{-file-exec-and-symbols} command
37514 (@pxref{GDB/MI File Commands}).
37515
37516 By default, the new inferior begins connected to the same target
37517 connection as the current inferior. For example, if the current
37518 inferior was connected to @code{gdbserver} with @code{target remote},
37519 then the new inferior will be connected to the same @code{gdbserver}
37520 instance. The @samp{--no-connection} option starts the new inferior
37521 with no connection yet. You can then for example use the
37522 @code{-target-select remote} command to connect to some other
37523 @code{gdbserver} instance, use @code{-exec-run} to spawn a local
37524 program, etc.
37525
37526 The command response always has a field, @var{inferior}, whose value
37527 is the identifier of the thread group corresponding to the new
37528 inferior.
37529
37530 An additional section field, @var{connection}, is optional. This
37531 field will only exist if the new inferior has a target connection. If
37532 this field exists, then its value will be a tuple containing the
37533 following fields:
37534
37535 @table @samp
37536 @item number
37537 The number of the connection used for the new inferior.
37538
37539 @item name
37540 The name of the connection type used for the new inferior.
37541 @end table
37542
37543 @subheading @value{GDBN} Command
37544
37545 The corresponding @value{GDBN} command is @samp{add-inferior}
37546 (@pxref{add_inferior_cli,,@samp{add-inferior}}).
37547
37548 @subheading Example
37549
37550 @smallexample
37551 (@value{GDBP})
37552 -add-inferior
37553 ^done,inferior="i3"
37554 @end smallexample
37555
37556 @subheading The @code{-interpreter-exec} Command
37557 @findex -interpreter-exec
37558
37559 @subheading Synopsis
37560
37561 @smallexample
37562 -interpreter-exec @var{interpreter} @var{command}
37563 @end smallexample
37564 @anchor{-interpreter-exec}
37565
37566 Execute the specified @var{command} in the given @var{interpreter}.
37567
37568 @subheading @value{GDBN} Command
37569
37570 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
37571
37572 @subheading Example
37573
37574 @smallexample
37575 (gdb)
37576 -interpreter-exec console "break main"
37577 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
37578 &"During symbol reading, bad structure-type format.\n"
37579 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
37580 ^done
37581 (gdb)
37582 @end smallexample
37583
37584 @subheading The @code{-inferior-tty-set} Command
37585 @findex -inferior-tty-set
37586
37587 @subheading Synopsis
37588
37589 @smallexample
37590 -inferior-tty-set /dev/pts/1
37591 @end smallexample
37592
37593 Set terminal for future runs of the program being debugged.
37594
37595 @subheading @value{GDBN} Command
37596
37597 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
37598
37599 @subheading Example
37600
37601 @smallexample
37602 (gdb)
37603 -inferior-tty-set /dev/pts/1
37604 ^done
37605 (gdb)
37606 @end smallexample
37607
37608 @subheading The @code{-inferior-tty-show} Command
37609 @findex -inferior-tty-show
37610
37611 @subheading Synopsis
37612
37613 @smallexample
37614 -inferior-tty-show
37615 @end smallexample
37616
37617 Show terminal for future runs of program being debugged.
37618
37619 @subheading @value{GDBN} Command
37620
37621 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
37622
37623 @subheading Example
37624
37625 @smallexample
37626 (gdb)
37627 -inferior-tty-set /dev/pts/1
37628 ^done
37629 (gdb)
37630 -inferior-tty-show
37631 ^done,inferior_tty_terminal="/dev/pts/1"
37632 (gdb)
37633 @end smallexample
37634
37635 @subheading The @code{-enable-timings} Command
37636 @findex -enable-timings
37637
37638 @subheading Synopsis
37639
37640 @smallexample
37641 -enable-timings [yes | no]
37642 @end smallexample
37643
37644 Toggle the printing of the wallclock, user and system times for an MI
37645 command as a field in its output. This command is to help frontend
37646 developers optimize the performance of their code. No argument is
37647 equivalent to @samp{yes}.
37648
37649 @subheading @value{GDBN} Command
37650
37651 No equivalent.
37652
37653 @subheading Example
37654
37655 @smallexample
37656 (gdb)
37657 -enable-timings
37658 ^done
37659 (gdb)
37660 -break-insert main
37661 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
37662 addr="0x080484ed",func="main",file="myprog.c",
37663 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
37664 times="0"@},
37665 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
37666 (gdb)
37667 -enable-timings no
37668 ^done
37669 (gdb)
37670 -exec-run
37671 ^running
37672 (gdb)
37673 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
37674 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
37675 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
37676 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
37677 (gdb)
37678 @end smallexample
37679
37680 @subheading The @code{-complete} Command
37681 @findex -complete
37682
37683 @subheading Synopsis
37684
37685 @smallexample
37686 -complete @var{command}
37687 @end smallexample
37688
37689 Show a list of completions for partially typed CLI @var{command}.
37690
37691 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
37692 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
37693 because @value{GDBN} is used remotely via a SSH connection.
37694
37695 @subheading Result
37696
37697 The result consists of two or three fields:
37698
37699 @table @samp
37700 @item completion
37701 This field contains the completed @var{command}. If @var{command}
37702 has no known completions, this field is omitted.
37703
37704 @item matches
37705 This field contains a (possibly empty) array of matches. It is always present.
37706
37707 @item max_completions_reached
37708 This field contains @code{1} if number of known completions is above
37709 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
37710 @code{0}. It is always present.
37711
37712 @end table
37713
37714 @subheading @value{GDBN} Command
37715
37716 The corresponding @value{GDBN} command is @samp{complete}.
37717
37718 @subheading Example
37719
37720 @smallexample
37721 (gdb)
37722 -complete br
37723 ^done,completion="break",
37724 matches=["break","break-range"],
37725 max_completions_reached="0"
37726 (gdb)
37727 -complete "b ma"
37728 ^done,completion="b ma",
37729 matches=["b madvise","b main"],max_completions_reached="0"
37730 (gdb)
37731 -complete "b push_b"
37732 ^done,completion="b push_back(",
37733 matches=[
37734 "b A::push_back(void*)",
37735 "b std::string::push_back(char)",
37736 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
37737 max_completions_reached="0"
37738 (gdb)
37739 -complete "nonexist"
37740 ^done,matches=[],max_completions_reached="0"
37741 (gdb)
37742
37743 @end smallexample
37744
37745 @node Annotations
37746 @chapter @value{GDBN} Annotations
37747
37748 This chapter describes annotations in @value{GDBN}. Annotations were
37749 designed to interface @value{GDBN} to graphical user interfaces or other
37750 similar programs which want to interact with @value{GDBN} at a
37751 relatively high level.
37752
37753 The annotation mechanism has largely been superseded by @sc{gdb/mi}
37754 (@pxref{GDB/MI}).
37755
37756 @ignore
37757 This is Edition @value{EDITION}, @value{DATE}.
37758 @end ignore
37759
37760 @menu
37761 * Annotations Overview:: What annotations are; the general syntax.
37762 * Server Prefix:: Issuing a command without affecting user state.
37763 * Prompting:: Annotations marking @value{GDBN}'s need for input.
37764 * Errors:: Annotations for error messages.
37765 * Invalidation:: Some annotations describe things now invalid.
37766 * Annotations for Running::
37767 Whether the program is running, how it stopped, etc.
37768 * Source Annotations:: Annotations describing source code.
37769 @end menu
37770
37771 @node Annotations Overview
37772 @section What is an Annotation?
37773 @cindex annotations
37774
37775 Annotations start with a newline character, two @samp{control-z}
37776 characters, and the name of the annotation. If there is no additional
37777 information associated with this annotation, the name of the annotation
37778 is followed immediately by a newline. If there is additional
37779 information, the name of the annotation is followed by a space, the
37780 additional information, and a newline. The additional information
37781 cannot contain newline characters.
37782
37783 Any output not beginning with a newline and two @samp{control-z}
37784 characters denotes literal output from @value{GDBN}. Currently there is
37785 no need for @value{GDBN} to output a newline followed by two
37786 @samp{control-z} characters, but if there was such a need, the
37787 annotations could be extended with an @samp{escape} annotation which
37788 means those three characters as output.
37789
37790 The annotation @var{level}, which is specified using the
37791 @option{--annotate} command line option (@pxref{Mode Options}), controls
37792 how much information @value{GDBN} prints together with its prompt,
37793 values of expressions, source lines, and other types of output. Level 0
37794 is for no annotations, level 1 is for use when @value{GDBN} is run as a
37795 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
37796 for programs that control @value{GDBN}, and level 2 annotations have
37797 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
37798 Interface, annotate, GDB's Obsolete Annotations}).
37799
37800 @table @code
37801 @kindex set annotate
37802 @item set annotate @var{level}
37803 The @value{GDBN} command @code{set annotate} sets the level of
37804 annotations to the specified @var{level}.
37805
37806 @item show annotate
37807 @kindex show annotate
37808 Show the current annotation level.
37809 @end table
37810
37811 This chapter describes level 3 annotations.
37812
37813 A simple example of starting up @value{GDBN} with annotations is:
37814
37815 @smallexample
37816 $ @kbd{gdb --annotate=3}
37817 GNU gdb 6.0
37818 Copyright 2003 Free Software Foundation, Inc.
37819 GDB is free software, covered by the GNU General Public License,
37820 and you are welcome to change it and/or distribute copies of it
37821 under certain conditions.
37822 Type "show copying" to see the conditions.
37823 There is absolutely no warranty for GDB. Type "show warranty"
37824 for details.
37825 This GDB was configured as "i386-pc-linux-gnu"
37826
37827 ^Z^Zpre-prompt
37828 (@value{GDBP})
37829 ^Z^Zprompt
37830 @kbd{quit}
37831
37832 ^Z^Zpost-prompt
37833 $
37834 @end smallexample
37835
37836 Here @samp{quit} is input to @value{GDBN}; the rest is output from
37837 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
37838 denotes a @samp{control-z} character) are annotations; the rest is
37839 output from @value{GDBN}.
37840
37841 @node Server Prefix
37842 @section The Server Prefix
37843 @cindex server prefix
37844
37845 If you prefix a command with @samp{server } then it will not affect
37846 the command history, nor will it affect @value{GDBN}'s notion of which
37847 command to repeat if @key{RET} is pressed on a line by itself. This
37848 means that commands can be run behind a user's back by a front-end in
37849 a transparent manner.
37850
37851 The @code{server } prefix does not affect the recording of values into
37852 the value history; to print a value without recording it into the
37853 value history, use the @code{output} command instead of the
37854 @code{print} command.
37855
37856 Using this prefix also disables confirmation requests
37857 (@pxref{confirmation requests}).
37858
37859 @node Prompting
37860 @section Annotation for @value{GDBN} Input
37861
37862 @cindex annotations for prompts
37863 When @value{GDBN} prompts for input, it annotates this fact so it is possible
37864 to know when to send output, when the output from a given command is
37865 over, etc.
37866
37867 Different kinds of input each have a different @dfn{input type}. Each
37868 input type has three annotations: a @code{pre-} annotation, which
37869 denotes the beginning of any prompt which is being output, a plain
37870 annotation, which denotes the end of the prompt, and then a @code{post-}
37871 annotation which denotes the end of any echo which may (or may not) be
37872 associated with the input. For example, the @code{prompt} input type
37873 features the following annotations:
37874
37875 @smallexample
37876 ^Z^Zpre-prompt
37877 ^Z^Zprompt
37878 ^Z^Zpost-prompt
37879 @end smallexample
37880
37881 The input types are
37882
37883 @table @code
37884 @findex pre-prompt annotation
37885 @findex prompt annotation
37886 @findex post-prompt annotation
37887 @item prompt
37888 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
37889
37890 @findex pre-commands annotation
37891 @findex commands annotation
37892 @findex post-commands annotation
37893 @item commands
37894 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
37895 command. The annotations are repeated for each command which is input.
37896
37897 @findex pre-overload-choice annotation
37898 @findex overload-choice annotation
37899 @findex post-overload-choice annotation
37900 @item overload-choice
37901 When @value{GDBN} wants the user to select between various overloaded functions.
37902
37903 @findex pre-query annotation
37904 @findex query annotation
37905 @findex post-query annotation
37906 @item query
37907 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
37908
37909 @findex pre-prompt-for-continue annotation
37910 @findex prompt-for-continue annotation
37911 @findex post-prompt-for-continue annotation
37912 @item prompt-for-continue
37913 When @value{GDBN} is asking the user to press return to continue. Note: Don't
37914 expect this to work well; instead use @code{set height 0} to disable
37915 prompting. This is because the counting of lines is buggy in the
37916 presence of annotations.
37917 @end table
37918
37919 @node Errors
37920 @section Errors
37921 @cindex annotations for errors, warnings and interrupts
37922
37923 @findex quit annotation
37924 @smallexample
37925 ^Z^Zquit
37926 @end smallexample
37927
37928 This annotation occurs right before @value{GDBN} responds to an interrupt.
37929
37930 @findex error annotation
37931 @smallexample
37932 ^Z^Zerror
37933 @end smallexample
37934
37935 This annotation occurs right before @value{GDBN} responds to an error.
37936
37937 Quit and error annotations indicate that any annotations which @value{GDBN} was
37938 in the middle of may end abruptly. For example, if a
37939 @code{value-history-begin} annotation is followed by a @code{error}, one
37940 cannot expect to receive the matching @code{value-history-end}. One
37941 cannot expect not to receive it either, however; an error annotation
37942 does not necessarily mean that @value{GDBN} is immediately returning all the way
37943 to the top level.
37944
37945 @findex error-begin annotation
37946 A quit or error annotation may be preceded by
37947
37948 @smallexample
37949 ^Z^Zerror-begin
37950 @end smallexample
37951
37952 Any output between that and the quit or error annotation is the error
37953 message.
37954
37955 Warning messages are not yet annotated.
37956 @c If we want to change that, need to fix warning(), type_error(),
37957 @c range_error(), and possibly other places.
37958
37959 @node Invalidation
37960 @section Invalidation Notices
37961
37962 @cindex annotations for invalidation messages
37963 The following annotations say that certain pieces of state may have
37964 changed.
37965
37966 @table @code
37967 @findex frames-invalid annotation
37968 @item ^Z^Zframes-invalid
37969
37970 The frames (for example, output from the @code{backtrace} command) may
37971 have changed.
37972
37973 @findex breakpoints-invalid annotation
37974 @item ^Z^Zbreakpoints-invalid
37975
37976 The breakpoints may have changed. For example, the user just added or
37977 deleted a breakpoint.
37978 @end table
37979
37980 @node Annotations for Running
37981 @section Running the Program
37982 @cindex annotations for running programs
37983
37984 @findex starting annotation
37985 @findex stopping annotation
37986 When the program starts executing due to a @value{GDBN} command such as
37987 @code{step} or @code{continue},
37988
37989 @smallexample
37990 ^Z^Zstarting
37991 @end smallexample
37992
37993 is output. When the program stops,
37994
37995 @smallexample
37996 ^Z^Zstopped
37997 @end smallexample
37998
37999 is output. Before the @code{stopped} annotation, a variety of
38000 annotations describe how the program stopped.
38001
38002 @table @code
38003 @findex exited annotation
38004 @item ^Z^Zexited @var{exit-status}
38005 The program exited, and @var{exit-status} is the exit status (zero for
38006 successful exit, otherwise nonzero).
38007
38008 @findex signalled annotation
38009 @findex signal-name annotation
38010 @findex signal-name-end annotation
38011 @findex signal-string annotation
38012 @findex signal-string-end annotation
38013 @item ^Z^Zsignalled
38014 The program exited with a signal. After the @code{^Z^Zsignalled}, the
38015 annotation continues:
38016
38017 @smallexample
38018 @var{intro-text}
38019 ^Z^Zsignal-name
38020 @var{name}
38021 ^Z^Zsignal-name-end
38022 @var{middle-text}
38023 ^Z^Zsignal-string
38024 @var{string}
38025 ^Z^Zsignal-string-end
38026 @var{end-text}
38027 @end smallexample
38028
38029 @noindent
38030 where @var{name} is the name of the signal, such as @code{SIGILL} or
38031 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
38032 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
38033 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
38034 user's benefit and have no particular format.
38035
38036 @findex signal annotation
38037 @item ^Z^Zsignal
38038 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
38039 just saying that the program received the signal, not that it was
38040 terminated with it.
38041
38042 @findex breakpoint annotation
38043 @item ^Z^Zbreakpoint @var{number}
38044 The program hit breakpoint number @var{number}.
38045
38046 @findex watchpoint annotation
38047 @item ^Z^Zwatchpoint @var{number}
38048 The program hit watchpoint number @var{number}.
38049 @end table
38050
38051 @node Source Annotations
38052 @section Displaying Source
38053 @cindex annotations for source display
38054
38055 @findex source annotation
38056 The following annotation is used instead of displaying source code:
38057
38058 @smallexample
38059 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
38060 @end smallexample
38061
38062 where @var{filename} is an absolute file name indicating which source
38063 file, @var{line} is the line number within that file (where 1 is the
38064 first line in the file), @var{character} is the character position
38065 within the file (where 0 is the first character in the file) (for most
38066 debug formats this will necessarily point to the beginning of a line),
38067 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
38068 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
38069 @var{addr} is the address in the target program associated with the
38070 source which is being displayed. The @var{addr} is in the form @samp{0x}
38071 followed by one or more lowercase hex digits (note that this does not
38072 depend on the language).
38073
38074 @node JIT Interface
38075 @chapter JIT Compilation Interface
38076 @cindex just-in-time compilation
38077 @cindex JIT compilation interface
38078
38079 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
38080 interface. A JIT compiler is a program or library that generates native
38081 executable code at runtime and executes it, usually in order to achieve good
38082 performance while maintaining platform independence.
38083
38084 Programs that use JIT compilation are normally difficult to debug because
38085 portions of their code are generated at runtime, instead of being loaded from
38086 object files, which is where @value{GDBN} normally finds the program's symbols
38087 and debug information. In order to debug programs that use JIT compilation,
38088 @value{GDBN} has an interface that allows the program to register in-memory
38089 symbol files with @value{GDBN} at runtime.
38090
38091 If you are using @value{GDBN} to debug a program that uses this interface, then
38092 it should work transparently so long as you have not stripped the binary. If
38093 you are developing a JIT compiler, then the interface is documented in the rest
38094 of this chapter. At this time, the only known client of this interface is the
38095 LLVM JIT.
38096
38097 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
38098 JIT compiler communicates with @value{GDBN} by writing data into a global
38099 variable and calling a function at a well-known symbol. When @value{GDBN}
38100 attaches, it reads a linked list of symbol files from the global variable to
38101 find existing code, and puts a breakpoint in the function so that it can find
38102 out about additional code.
38103
38104 @menu
38105 * Declarations:: Relevant C struct declarations
38106 * Registering Code:: Steps to register code
38107 * Unregistering Code:: Steps to unregister code
38108 * Custom Debug Info:: Emit debug information in a custom format
38109 @end menu
38110
38111 @node Declarations
38112 @section JIT Declarations
38113
38114 These are the relevant struct declarations that a C program should include to
38115 implement the interface:
38116
38117 @smallexample
38118 typedef enum
38119 @{
38120 JIT_NOACTION = 0,
38121 JIT_REGISTER_FN,
38122 JIT_UNREGISTER_FN
38123 @} jit_actions_t;
38124
38125 struct jit_code_entry
38126 @{
38127 struct jit_code_entry *next_entry;
38128 struct jit_code_entry *prev_entry;
38129 const char *symfile_addr;
38130 uint64_t symfile_size;
38131 @};
38132
38133 struct jit_descriptor
38134 @{
38135 uint32_t version;
38136 /* This type should be jit_actions_t, but we use uint32_t
38137 to be explicit about the bitwidth. */
38138 uint32_t action_flag;
38139 struct jit_code_entry *relevant_entry;
38140 struct jit_code_entry *first_entry;
38141 @};
38142
38143 /* GDB puts a breakpoint in this function. */
38144 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
38145
38146 /* Make sure to specify the version statically, because the
38147 debugger may check the version before we can set it. */
38148 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
38149 @end smallexample
38150
38151 If the JIT is multi-threaded, then it is important that the JIT synchronize any
38152 modifications to this global data properly, which can easily be done by putting
38153 a global mutex around modifications to these structures.
38154
38155 @node Registering Code
38156 @section Registering Code
38157
38158 To register code with @value{GDBN}, the JIT should follow this protocol:
38159
38160 @itemize @bullet
38161 @item
38162 Generate an object file in memory with symbols and other desired debug
38163 information. The file must include the virtual addresses of the sections.
38164
38165 @item
38166 Create a code entry for the file, which gives the start and size of the symbol
38167 file.
38168
38169 @item
38170 Add it to the linked list in the JIT descriptor.
38171
38172 @item
38173 Point the relevant_entry field of the descriptor at the entry.
38174
38175 @item
38176 Set @code{action_flag} to @code{JIT_REGISTER} and call
38177 @code{__jit_debug_register_code}.
38178 @end itemize
38179
38180 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
38181 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
38182 new code. However, the linked list must still be maintained in order to allow
38183 @value{GDBN} to attach to a running process and still find the symbol files.
38184
38185 @node Unregistering Code
38186 @section Unregistering Code
38187
38188 If code is freed, then the JIT should use the following protocol:
38189
38190 @itemize @bullet
38191 @item
38192 Remove the code entry corresponding to the code from the linked list.
38193
38194 @item
38195 Point the @code{relevant_entry} field of the descriptor at the code entry.
38196
38197 @item
38198 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
38199 @code{__jit_debug_register_code}.
38200 @end itemize
38201
38202 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
38203 and the JIT will leak the memory used for the associated symbol files.
38204
38205 @node Custom Debug Info
38206 @section Custom Debug Info
38207 @cindex custom JIT debug info
38208 @cindex JIT debug info reader
38209
38210 Generating debug information in platform-native file formats (like ELF
38211 or COFF) may be an overkill for JIT compilers; especially if all the
38212 debug info is used for is displaying a meaningful backtrace. The
38213 issue can be resolved by having the JIT writers decide on a debug info
38214 format and also provide a reader that parses the debug info generated
38215 by the JIT compiler. This section gives a brief overview on writing
38216 such a parser. More specific details can be found in the source file
38217 @file{gdb/jit-reader.in}, which is also installed as a header at
38218 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
38219
38220 The reader is implemented as a shared object (so this functionality is
38221 not available on platforms which don't allow loading shared objects at
38222 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
38223 @code{jit-reader-unload} are provided, to be used to load and unload
38224 the readers from a preconfigured directory. Once loaded, the shared
38225 object is used the parse the debug information emitted by the JIT
38226 compiler.
38227
38228 @menu
38229 * Using JIT Debug Info Readers:: How to use supplied readers correctly
38230 * Writing JIT Debug Info Readers:: Creating a debug-info reader
38231 @end menu
38232
38233 @node Using JIT Debug Info Readers
38234 @subsection Using JIT Debug Info Readers
38235 @kindex jit-reader-load
38236 @kindex jit-reader-unload
38237
38238 Readers can be loaded and unloaded using the @code{jit-reader-load}
38239 and @code{jit-reader-unload} commands.
38240
38241 @table @code
38242 @item jit-reader-load @var{reader}
38243 Load the JIT reader named @var{reader}, which is a shared
38244 object specified as either an absolute or a relative file name. In
38245 the latter case, @value{GDBN} will try to load the reader from a
38246 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
38247 system (here @var{libdir} is the system library directory, often
38248 @file{/usr/local/lib}).
38249
38250 Only one reader can be active at a time; trying to load a second
38251 reader when one is already loaded will result in @value{GDBN}
38252 reporting an error. A new JIT reader can be loaded by first unloading
38253 the current one using @code{jit-reader-unload} and then invoking
38254 @code{jit-reader-load}.
38255
38256 @item jit-reader-unload
38257 Unload the currently loaded JIT reader.
38258
38259 @end table
38260
38261 @node Writing JIT Debug Info Readers
38262 @subsection Writing JIT Debug Info Readers
38263 @cindex writing JIT debug info readers
38264
38265 As mentioned, a reader is essentially a shared object conforming to a
38266 certain ABI. This ABI is described in @file{jit-reader.h}.
38267
38268 @file{jit-reader.h} defines the structures, macros and functions
38269 required to write a reader. It is installed (along with
38270 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
38271 the system include directory.
38272
38273 Readers need to be released under a GPL compatible license. A reader
38274 can be declared as released under such a license by placing the macro
38275 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
38276
38277 The entry point for readers is the symbol @code{gdb_init_reader},
38278 which is expected to be a function with the prototype
38279
38280 @findex gdb_init_reader
38281 @smallexample
38282 extern struct gdb_reader_funcs *gdb_init_reader (void);
38283 @end smallexample
38284
38285 @cindex @code{struct gdb_reader_funcs}
38286
38287 @code{struct gdb_reader_funcs} contains a set of pointers to callback
38288 functions. These functions are executed to read the debug info
38289 generated by the JIT compiler (@code{read}), to unwind stack frames
38290 (@code{unwind}) and to create canonical frame IDs
38291 (@code{get_frame_id}). It also has a callback that is called when the
38292 reader is being unloaded (@code{destroy}). The struct looks like this
38293
38294 @smallexample
38295 struct gdb_reader_funcs
38296 @{
38297 /* Must be set to GDB_READER_INTERFACE_VERSION. */
38298 int reader_version;
38299
38300 /* For use by the reader. */
38301 void *priv_data;
38302
38303 gdb_read_debug_info *read;
38304 gdb_unwind_frame *unwind;
38305 gdb_get_frame_id *get_frame_id;
38306 gdb_destroy_reader *destroy;
38307 @};
38308 @end smallexample
38309
38310 @cindex @code{struct gdb_symbol_callbacks}
38311 @cindex @code{struct gdb_unwind_callbacks}
38312
38313 The callbacks are provided with another set of callbacks by
38314 @value{GDBN} to do their job. For @code{read}, these callbacks are
38315 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
38316 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
38317 @code{struct gdb_symbol_callbacks} has callbacks to create new object
38318 files and new symbol tables inside those object files. @code{struct
38319 gdb_unwind_callbacks} has callbacks to read registers off the current
38320 frame and to write out the values of the registers in the previous
38321 frame. Both have a callback (@code{target_read}) to read bytes off the
38322 target's address space.
38323
38324 @node In-Process Agent
38325 @chapter In-Process Agent
38326 @cindex debugging agent
38327 The traditional debugging model is conceptually low-speed, but works fine,
38328 because most bugs can be reproduced in debugging-mode execution. However,
38329 as multi-core or many-core processors are becoming mainstream, and
38330 multi-threaded programs become more and more popular, there should be more
38331 and more bugs that only manifest themselves at normal-mode execution, for
38332 example, thread races, because debugger's interference with the program's
38333 timing may conceal the bugs. On the other hand, in some applications,
38334 it is not feasible for the debugger to interrupt the program's execution
38335 long enough for the developer to learn anything helpful about its behavior.
38336 If the program's correctness depends on its real-time behavior, delays
38337 introduced by a debugger might cause the program to fail, even when the
38338 code itself is correct. It is useful to be able to observe the program's
38339 behavior without interrupting it.
38340
38341 Therefore, traditional debugging model is too intrusive to reproduce
38342 some bugs. In order to reduce the interference with the program, we can
38343 reduce the number of operations performed by debugger. The
38344 @dfn{In-Process Agent}, a shared library, is running within the same
38345 process with inferior, and is able to perform some debugging operations
38346 itself. As a result, debugger is only involved when necessary, and
38347 performance of debugging can be improved accordingly. Note that
38348 interference with program can be reduced but can't be removed completely,
38349 because the in-process agent will still stop or slow down the program.
38350
38351 The in-process agent can interpret and execute Agent Expressions
38352 (@pxref{Agent Expressions}) during performing debugging operations. The
38353 agent expressions can be used for different purposes, such as collecting
38354 data in tracepoints, and condition evaluation in breakpoints.
38355
38356 @anchor{Control Agent}
38357 You can control whether the in-process agent is used as an aid for
38358 debugging with the following commands:
38359
38360 @table @code
38361 @kindex set agent on
38362 @item set agent on
38363 Causes the in-process agent to perform some operations on behalf of the
38364 debugger. Just which operations requested by the user will be done
38365 by the in-process agent depends on the its capabilities. For example,
38366 if you request to evaluate breakpoint conditions in the in-process agent,
38367 and the in-process agent has such capability as well, then breakpoint
38368 conditions will be evaluated in the in-process agent.
38369
38370 @kindex set agent off
38371 @item set agent off
38372 Disables execution of debugging operations by the in-process agent. All
38373 of the operations will be performed by @value{GDBN}.
38374
38375 @kindex show agent
38376 @item show agent
38377 Display the current setting of execution of debugging operations by
38378 the in-process agent.
38379 @end table
38380
38381 @menu
38382 * In-Process Agent Protocol::
38383 @end menu
38384
38385 @node In-Process Agent Protocol
38386 @section In-Process Agent Protocol
38387 @cindex in-process agent protocol
38388
38389 The in-process agent is able to communicate with both @value{GDBN} and
38390 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
38391 used for communications between @value{GDBN} or GDBserver and the IPA.
38392 In general, @value{GDBN} or GDBserver sends commands
38393 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
38394 in-process agent replies back with the return result of the command, or
38395 some other information. The data sent to in-process agent is composed
38396 of primitive data types, such as 4-byte or 8-byte type, and composite
38397 types, which are called objects (@pxref{IPA Protocol Objects}).
38398
38399 @menu
38400 * IPA Protocol Objects::
38401 * IPA Protocol Commands::
38402 @end menu
38403
38404 @node IPA Protocol Objects
38405 @subsection IPA Protocol Objects
38406 @cindex ipa protocol objects
38407
38408 The commands sent to and results received from agent may contain some
38409 complex data types called @dfn{objects}.
38410
38411 The in-process agent is running on the same machine with @value{GDBN}
38412 or GDBserver, so it doesn't have to handle as much differences between
38413 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
38414 However, there are still some differences of two ends in two processes:
38415
38416 @enumerate
38417 @item
38418 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
38419 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
38420 @item
38421 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
38422 GDBserver is compiled with one, and in-process agent is compiled with
38423 the other one.
38424 @end enumerate
38425
38426 Here are the IPA Protocol Objects:
38427
38428 @enumerate
38429 @item
38430 agent expression object. It represents an agent expression
38431 (@pxref{Agent Expressions}).
38432 @anchor{agent expression object}
38433 @item
38434 tracepoint action object. It represents a tracepoint action
38435 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
38436 memory, static trace data and to evaluate expression.
38437 @anchor{tracepoint action object}
38438 @item
38439 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
38440 @anchor{tracepoint object}
38441
38442 @end enumerate
38443
38444 The following table describes important attributes of each IPA protocol
38445 object:
38446
38447 @multitable @columnfractions .30 .20 .50
38448 @headitem Name @tab Size @tab Description
38449 @item @emph{agent expression object} @tab @tab
38450 @item length @tab 4 @tab length of bytes code
38451 @item byte code @tab @var{length} @tab contents of byte code
38452 @item @emph{tracepoint action for collecting memory} @tab @tab
38453 @item 'M' @tab 1 @tab type of tracepoint action
38454 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
38455 address of the lowest byte to collect, otherwise @var{addr} is the offset
38456 of @var{basereg} for memory collecting.
38457 @item len @tab 8 @tab length of memory for collecting
38458 @item basereg @tab 4 @tab the register number containing the starting
38459 memory address for collecting.
38460 @item @emph{tracepoint action for collecting registers} @tab @tab
38461 @item 'R' @tab 1 @tab type of tracepoint action
38462 @item @emph{tracepoint action for collecting static trace data} @tab @tab
38463 @item 'L' @tab 1 @tab type of tracepoint action
38464 @item @emph{tracepoint action for expression evaluation} @tab @tab
38465 @item 'X' @tab 1 @tab type of tracepoint action
38466 @item agent expression @tab length of @tab @ref{agent expression object}
38467 @item @emph{tracepoint object} @tab @tab
38468 @item number @tab 4 @tab number of tracepoint
38469 @item address @tab 8 @tab address of tracepoint inserted on
38470 @item type @tab 4 @tab type of tracepoint
38471 @item enabled @tab 1 @tab enable or disable of tracepoint
38472 @item step_count @tab 8 @tab step
38473 @item pass_count @tab 8 @tab pass
38474 @item numactions @tab 4 @tab number of tracepoint actions
38475 @item hit count @tab 8 @tab hit count
38476 @item trace frame usage @tab 8 @tab trace frame usage
38477 @item compiled_cond @tab 8 @tab compiled condition
38478 @item orig_size @tab 8 @tab orig size
38479 @item condition @tab 4 if condition is NULL otherwise length of
38480 @ref{agent expression object}
38481 @tab zero if condition is NULL, otherwise is
38482 @ref{agent expression object}
38483 @item actions @tab variable
38484 @tab numactions number of @ref{tracepoint action object}
38485 @end multitable
38486
38487 @node IPA Protocol Commands
38488 @subsection IPA Protocol Commands
38489 @cindex ipa protocol commands
38490
38491 The spaces in each command are delimiters to ease reading this commands
38492 specification. They don't exist in real commands.
38493
38494 @table @samp
38495
38496 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
38497 Installs a new fast tracepoint described by @var{tracepoint_object}
38498 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
38499 head of @dfn{jumppad}, which is used to jump to data collection routine
38500 in IPA finally.
38501
38502 Replies:
38503 @table @samp
38504 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
38505 @var{target_address} is address of tracepoint in the inferior.
38506 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
38507 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
38508 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
38509 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
38510 @item E @var{NN}
38511 for an error
38512
38513 @end table
38514
38515 @item close
38516 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
38517 is about to kill inferiors.
38518
38519 @item qTfSTM
38520 @xref{qTfSTM}.
38521 @item qTsSTM
38522 @xref{qTsSTM}.
38523 @item qTSTMat
38524 @xref{qTSTMat}.
38525 @item probe_marker_at:@var{address}
38526 Asks in-process agent to probe the marker at @var{address}.
38527
38528 Replies:
38529 @table @samp
38530 @item E @var{NN}
38531 for an error
38532 @end table
38533 @item unprobe_marker_at:@var{address}
38534 Asks in-process agent to unprobe the marker at @var{address}.
38535 @end table
38536
38537 @node GDB Bugs
38538 @chapter Reporting Bugs in @value{GDBN}
38539 @cindex bugs in @value{GDBN}
38540 @cindex reporting bugs in @value{GDBN}
38541
38542 Your bug reports play an essential role in making @value{GDBN} reliable.
38543
38544 Reporting a bug may help you by bringing a solution to your problem, or it
38545 may not. But in any case the principal function of a bug report is to help
38546 the entire community by making the next version of @value{GDBN} work better. Bug
38547 reports are your contribution to the maintenance of @value{GDBN}.
38548
38549 In order for a bug report to serve its purpose, you must include the
38550 information that enables us to fix the bug.
38551
38552 @menu
38553 * Bug Criteria:: Have you found a bug?
38554 * Bug Reporting:: How to report bugs
38555 @end menu
38556
38557 @node Bug Criteria
38558 @section Have You Found a Bug?
38559 @cindex bug criteria
38560
38561 If you are not sure whether you have found a bug, here are some guidelines:
38562
38563 @itemize @bullet
38564 @cindex fatal signal
38565 @cindex debugger crash
38566 @cindex crash of debugger
38567 @item
38568 If the debugger gets a fatal signal, for any input whatever, that is a
38569 @value{GDBN} bug. Reliable debuggers never crash.
38570
38571 @cindex error on valid input
38572 @item
38573 If @value{GDBN} produces an error message for valid input, that is a
38574 bug. (Note that if you're cross debugging, the problem may also be
38575 somewhere in the connection to the target.)
38576
38577 @cindex invalid input
38578 @item
38579 If @value{GDBN} does not produce an error message for invalid input,
38580 that is a bug. However, you should note that your idea of
38581 ``invalid input'' might be our idea of ``an extension'' or ``support
38582 for traditional practice''.
38583
38584 @item
38585 If you are an experienced user of debugging tools, your suggestions
38586 for improvement of @value{GDBN} are welcome in any case.
38587 @end itemize
38588
38589 @node Bug Reporting
38590 @section How to Report Bugs
38591 @cindex bug reports
38592 @cindex @value{GDBN} bugs, reporting
38593
38594 A number of companies and individuals offer support for @sc{gnu} products.
38595 If you obtained @value{GDBN} from a support organization, we recommend you
38596 contact that organization first.
38597
38598 You can find contact information for many support companies and
38599 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
38600 distribution.
38601 @c should add a web page ref...
38602
38603 @ifset BUGURL
38604 @ifset BUGURL_DEFAULT
38605 In any event, we also recommend that you submit bug reports for
38606 @value{GDBN}. The preferred method is to submit them directly using
38607 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
38608 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
38609 be used.
38610
38611 @strong{Do not send bug reports to @samp{info-gdb}, or to
38612 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
38613 not want to receive bug reports. Those that do have arranged to receive
38614 @samp{bug-gdb}.
38615
38616 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
38617 serves as a repeater. The mailing list and the newsgroup carry exactly
38618 the same messages. Often people think of posting bug reports to the
38619 newsgroup instead of mailing them. This appears to work, but it has one
38620 problem which can be crucial: a newsgroup posting often lacks a mail
38621 path back to the sender. Thus, if we need to ask for more information,
38622 we may be unable to reach you. For this reason, it is better to send
38623 bug reports to the mailing list.
38624 @end ifset
38625 @ifclear BUGURL_DEFAULT
38626 In any event, we also recommend that you submit bug reports for
38627 @value{GDBN} to @value{BUGURL}.
38628 @end ifclear
38629 @end ifset
38630
38631 The fundamental principle of reporting bugs usefully is this:
38632 @strong{report all the facts}. If you are not sure whether to state a
38633 fact or leave it out, state it!
38634
38635 Often people omit facts because they think they know what causes the
38636 problem and assume that some details do not matter. Thus, you might
38637 assume that the name of the variable you use in an example does not matter.
38638 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
38639 stray memory reference which happens to fetch from the location where that
38640 name is stored in memory; perhaps, if the name were different, the contents
38641 of that location would fool the debugger into doing the right thing despite
38642 the bug. Play it safe and give a specific, complete example. That is the
38643 easiest thing for you to do, and the most helpful.
38644
38645 Keep in mind that the purpose of a bug report is to enable us to fix the
38646 bug. It may be that the bug has been reported previously, but neither
38647 you nor we can know that unless your bug report is complete and
38648 self-contained.
38649
38650 Sometimes people give a few sketchy facts and ask, ``Does this ring a
38651 bell?'' Those bug reports are useless, and we urge everyone to
38652 @emph{refuse to respond to them} except to chide the sender to report
38653 bugs properly.
38654
38655 To enable us to fix the bug, you should include all these things:
38656
38657 @itemize @bullet
38658 @item
38659 The version of @value{GDBN}. @value{GDBN} announces it if you start
38660 with no arguments; you can also print it at any time using @code{show
38661 version}.
38662
38663 Without this, we will not know whether there is any point in looking for
38664 the bug in the current version of @value{GDBN}.
38665
38666 @item
38667 The type of machine you are using, and the operating system name and
38668 version number.
38669
38670 @item
38671 The details of the @value{GDBN} build-time configuration.
38672 @value{GDBN} shows these details if you invoke it with the
38673 @option{--configuration} command-line option, or if you type
38674 @code{show configuration} at @value{GDBN}'s prompt.
38675
38676 @item
38677 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
38678 ``@value{GCC}--2.8.1''.
38679
38680 @item
38681 What compiler (and its version) was used to compile the program you are
38682 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
38683 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
38684 to get this information; for other compilers, see the documentation for
38685 those compilers.
38686
38687 @item
38688 The command arguments you gave the compiler to compile your example and
38689 observe the bug. For example, did you use @samp{-O}? To guarantee
38690 you will not omit something important, list them all. A copy of the
38691 Makefile (or the output from make) is sufficient.
38692
38693 If we were to try to guess the arguments, we would probably guess wrong
38694 and then we might not encounter the bug.
38695
38696 @item
38697 A complete input script, and all necessary source files, that will
38698 reproduce the bug.
38699
38700 @item
38701 A description of what behavior you observe that you believe is
38702 incorrect. For example, ``It gets a fatal signal.''
38703
38704 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
38705 will certainly notice it. But if the bug is incorrect output, we might
38706 not notice unless it is glaringly wrong. You might as well not give us
38707 a chance to make a mistake.
38708
38709 Even if the problem you experience is a fatal signal, you should still
38710 say so explicitly. Suppose something strange is going on, such as, your
38711 copy of @value{GDBN} is out of synch, or you have encountered a bug in
38712 the C library on your system. (This has happened!) Your copy might
38713 crash and ours would not. If you told us to expect a crash, then when
38714 ours fails to crash, we would know that the bug was not happening for
38715 us. If you had not told us to expect a crash, then we would not be able
38716 to draw any conclusion from our observations.
38717
38718 @pindex script
38719 @cindex recording a session script
38720 To collect all this information, you can use a session recording program
38721 such as @command{script}, which is available on many Unix systems.
38722 Just run your @value{GDBN} session inside @command{script} and then
38723 include the @file{typescript} file with your bug report.
38724
38725 Another way to record a @value{GDBN} session is to run @value{GDBN}
38726 inside Emacs and then save the entire buffer to a file.
38727
38728 @item
38729 If you wish to suggest changes to the @value{GDBN} source, send us context
38730 diffs. If you even discuss something in the @value{GDBN} source, refer to
38731 it by context, not by line number.
38732
38733 The line numbers in our development sources will not match those in your
38734 sources. Your line numbers would convey no useful information to us.
38735
38736 @end itemize
38737
38738 Here are some things that are not necessary:
38739
38740 @itemize @bullet
38741 @item
38742 A description of the envelope of the bug.
38743
38744 Often people who encounter a bug spend a lot of time investigating
38745 which changes to the input file will make the bug go away and which
38746 changes will not affect it.
38747
38748 This is often time consuming and not very useful, because the way we
38749 will find the bug is by running a single example under the debugger
38750 with breakpoints, not by pure deduction from a series of examples.
38751 We recommend that you save your time for something else.
38752
38753 Of course, if you can find a simpler example to report @emph{instead}
38754 of the original one, that is a convenience for us. Errors in the
38755 output will be easier to spot, running under the debugger will take
38756 less time, and so on.
38757
38758 However, simplification is not vital; if you do not want to do this,
38759 report the bug anyway and send us the entire test case you used.
38760
38761 @item
38762 A patch for the bug.
38763
38764 A patch for the bug does help us if it is a good one. But do not omit
38765 the necessary information, such as the test case, on the assumption that
38766 a patch is all we need. We might see problems with your patch and decide
38767 to fix the problem another way, or we might not understand it at all.
38768
38769 Sometimes with a program as complicated as @value{GDBN} it is very hard to
38770 construct an example that will make the program follow a certain path
38771 through the code. If you do not send us the example, we will not be able
38772 to construct one, so we will not be able to verify that the bug is fixed.
38773
38774 And if we cannot understand what bug you are trying to fix, or why your
38775 patch should be an improvement, we will not install it. A test case will
38776 help us to understand.
38777
38778 @item
38779 A guess about what the bug is or what it depends on.
38780
38781 Such guesses are usually wrong. Even we cannot guess right about such
38782 things without first using the debugger to find the facts.
38783 @end itemize
38784
38785 @c The readline documentation is distributed with the readline code
38786 @c and consists of the two following files:
38787 @c rluser.texi
38788 @c hsuser.texi
38789 @c Use -I with makeinfo to point to the appropriate directory,
38790 @c environment var TEXINPUTS with TeX.
38791 @ifclear SYSTEM_READLINE
38792 @include rluser.texi
38793 @include hsuser.texi
38794 @end ifclear
38795
38796 @node In Memoriam
38797 @appendix In Memoriam
38798
38799 The @value{GDBN} project mourns the loss of the following long-time
38800 contributors:
38801
38802 @table @code
38803 @item Fred Fish
38804 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
38805 to Free Software in general. Outside of @value{GDBN}, he was known in
38806 the Amiga world for his series of Fish Disks, and the GeekGadget project.
38807
38808 @item Michael Snyder
38809 Michael was one of the Global Maintainers of the @value{GDBN} project,
38810 with contributions recorded as early as 1996, until 2011. In addition
38811 to his day to day participation, he was a large driving force behind
38812 adding Reverse Debugging to @value{GDBN}.
38813 @end table
38814
38815 Beyond their technical contributions to the project, they were also
38816 enjoyable members of the Free Software Community. We will miss them.
38817
38818 @node Formatting Documentation
38819 @appendix Formatting Documentation
38820
38821 @cindex @value{GDBN} reference card
38822 @cindex reference card
38823 The @value{GDBN} 4 release includes an already-formatted reference card, ready
38824 for printing with PostScript or Ghostscript, in the @file{gdb}
38825 subdirectory of the main source directory@footnote{In
38826 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
38827 release.}. If you can use PostScript or Ghostscript with your printer,
38828 you can print the reference card immediately with @file{refcard.ps}.
38829
38830 The release also includes the source for the reference card. You
38831 can format it, using @TeX{}, by typing:
38832
38833 @smallexample
38834 make refcard.dvi
38835 @end smallexample
38836
38837 The @value{GDBN} reference card is designed to print in @dfn{landscape}
38838 mode on US ``letter'' size paper;
38839 that is, on a sheet 11 inches wide by 8.5 inches
38840 high. You will need to specify this form of printing as an option to
38841 your @sc{dvi} output program.
38842
38843 @cindex documentation
38844
38845 All the documentation for @value{GDBN} comes as part of the machine-readable
38846 distribution. The documentation is written in Texinfo format, which is
38847 a documentation system that uses a single source file to produce both
38848 on-line information and a printed manual. You can use one of the Info
38849 formatting commands to create the on-line version of the documentation
38850 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
38851
38852 @value{GDBN} includes an already formatted copy of the on-line Info
38853 version of this manual in the @file{gdb} subdirectory. The main Info
38854 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
38855 subordinate files matching @samp{gdb.info*} in the same directory. If
38856 necessary, you can print out these files, or read them with any editor;
38857 but they are easier to read using the @code{info} subsystem in @sc{gnu}
38858 Emacs or the standalone @code{info} program, available as part of the
38859 @sc{gnu} Texinfo distribution.
38860
38861 If you want to format these Info files yourself, you need one of the
38862 Info formatting programs, such as @code{texinfo-format-buffer} or
38863 @code{makeinfo}.
38864
38865 If you have @code{makeinfo} installed, and are in the top level
38866 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
38867 version @value{GDBVN}), you can make the Info file by typing:
38868
38869 @smallexample
38870 cd gdb
38871 make gdb.info
38872 @end smallexample
38873
38874 If you want to typeset and print copies of this manual, you need @TeX{},
38875 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
38876 Texinfo definitions file.
38877
38878 @TeX{} is a typesetting program; it does not print files directly, but
38879 produces output files called @sc{dvi} files. To print a typeset
38880 document, you need a program to print @sc{dvi} files. If your system
38881 has @TeX{} installed, chances are it has such a program. The precise
38882 command to use depends on your system; @kbd{lpr -d} is common; another
38883 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
38884 require a file name without any extension or a @samp{.dvi} extension.
38885
38886 @TeX{} also requires a macro definitions file called
38887 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
38888 written in Texinfo format. On its own, @TeX{} cannot either read or
38889 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
38890 and is located in the @file{gdb-@var{version-number}/texinfo}
38891 directory.
38892
38893 If you have @TeX{} and a @sc{dvi} printer program installed, you can
38894 typeset and print this manual. First switch to the @file{gdb}
38895 subdirectory of the main source directory (for example, to
38896 @file{gdb-@value{GDBVN}/gdb}) and type:
38897
38898 @smallexample
38899 make gdb.dvi
38900 @end smallexample
38901
38902 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
38903
38904 @node Installing GDB
38905 @appendix Installing @value{GDBN}
38906 @cindex installation
38907
38908 @menu
38909 * Requirements:: Requirements for building @value{GDBN}
38910 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
38911 * Separate Objdir:: Compiling @value{GDBN} in another directory
38912 * Config Names:: Specifying names for hosts and targets
38913 * Configure Options:: Summary of options for configure
38914 * System-wide configuration:: Having a system-wide init file
38915 @end menu
38916
38917 @node Requirements
38918 @section Requirements for Building @value{GDBN}
38919 @cindex building @value{GDBN}, requirements for
38920
38921 Building @value{GDBN} requires various tools and packages to be available.
38922 Other packages will be used only if they are found.
38923
38924 @heading Tools/Packages Necessary for Building @value{GDBN}
38925 @table @asis
38926 @item C@t{++}11 compiler
38927 @value{GDBN} is written in C@t{++}11. It should be buildable with any
38928 recent C@t{++}11 compiler, e.g.@: GCC.
38929
38930 @item GNU make
38931 @value{GDBN}'s build system relies on features only found in the GNU
38932 make program. Other variants of @code{make} will not work.
38933
38934 @item GMP (The GNU Multiple Precision Arithmetic Library)
38935 @value{GDBN} now uses GMP to perform some of its arithmetics.
38936 This library may be included with your operating system distribution;
38937 if it is not, you can get the latest version from
38938 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
38939 you can use the @option{--with-libgmp-prefix} option to specify
38940 its location.
38941
38942 @end table
38943
38944 @heading Tools/Packages Optional for Building @value{GDBN}
38945 @table @asis
38946 @item Expat
38947 @anchor{Expat}
38948 @value{GDBN} can use the Expat XML parsing library. This library may be
38949 included with your operating system distribution; if it is not, you
38950 can get the latest version from @url{http://expat.sourceforge.net}.
38951 The @file{configure} script will search for this library in several
38952 standard locations; if it is installed in an unusual path, you can
38953 use the @option{--with-libexpat-prefix} option to specify its location.
38954
38955 Expat is used for:
38956
38957 @itemize @bullet
38958 @item
38959 Remote protocol memory maps (@pxref{Memory Map Format})
38960 @item
38961 Target descriptions (@pxref{Target Descriptions})
38962 @item
38963 Remote shared library lists (@xref{Library List Format},
38964 or alternatively @pxref{Library List Format for SVR4 Targets})
38965 @item
38966 MS-Windows shared libraries (@pxref{Shared Libraries})
38967 @item
38968 Traceframe info (@pxref{Traceframe Info Format})
38969 @item
38970 Branch trace (@pxref{Branch Trace Format},
38971 @pxref{Branch Trace Configuration Format})
38972 @end itemize
38973
38974 @item Guile
38975 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
38976 default, @value{GDBN} will be compiled if the Guile libraries are
38977 installed and are found by @file{configure}. You can use the
38978 @code{--with-guile} option to request Guile, and pass either the Guile
38979 version number or the file name of the relevant @code{pkg-config}
38980 program to choose a particular version of Guile.
38981
38982 @item iconv
38983 @value{GDBN}'s features related to character sets (@pxref{Character
38984 Sets}) require a functioning @code{iconv} implementation. If you are
38985 on a GNU system, then this is provided by the GNU C Library. Some
38986 other systems also provide a working @code{iconv}.
38987
38988 If @value{GDBN} is using the @code{iconv} program which is installed
38989 in a non-standard place, you will need to tell @value{GDBN} where to
38990 find it. This is done with @option{--with-iconv-bin} which specifies
38991 the directory that contains the @code{iconv} program. This program is
38992 run in order to make a list of the available character sets.
38993
38994 On systems without @code{iconv}, you can install GNU Libiconv. If
38995 Libiconv is installed in a standard place, @value{GDBN} will
38996 automatically use it if it is needed. If you have previously
38997 installed Libiconv in a non-standard place, you can use the
38998 @option{--with-libiconv-prefix} option to @file{configure}.
38999
39000 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
39001 arrange to build Libiconv if a directory named @file{libiconv} appears
39002 in the top-most source directory. If Libiconv is built this way, and
39003 if the operating system does not provide a suitable @code{iconv}
39004 implementation, then the just-built library will automatically be used
39005 by @value{GDBN}. One easy way to set this up is to download GNU
39006 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
39007 source tree, and then rename the directory holding the Libiconv source
39008 code to @samp{libiconv}.
39009
39010 @item lzma
39011 @value{GDBN} can support debugging sections that are compressed with
39012 the LZMA library. @xref{MiniDebugInfo}. If this library is not
39013 included with your operating system, you can find it in the xz package
39014 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
39015 the usual place, then the @file{configure} script will use it
39016 automatically. If it is installed in an unusual path, you can use the
39017 @option{--with-liblzma-prefix} option to specify its location.
39018
39019 @item MPFR
39020 @anchor{MPFR}
39021 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
39022 library. This library may be included with your operating system
39023 distribution; if it is not, you can get the latest version from
39024 @url{http://www.mpfr.org}. The @file{configure} script will search
39025 for this library in several standard locations; if it is installed
39026 in an unusual path, you can use the @option{--with-libmpfr-prefix}
39027 option to specify its location.
39028
39029 GNU MPFR is used to emulate target floating-point arithmetic during
39030 expression evaluation when the target uses different floating-point
39031 formats than the host. If GNU MPFR it is not available, @value{GDBN}
39032 will fall back to using host floating-point arithmetic.
39033
39034 @item Python
39035 @value{GDBN} can be scripted using Python language. @xref{Python}.
39036 By default, @value{GDBN} will be compiled if the Python libraries are
39037 installed and are found by @file{configure}. You can use the
39038 @code{--with-python} option to request Python, and pass either the
39039 file name of the relevant @code{python} executable, or the name of the
39040 directory in which Python is installed, to choose a particular
39041 installation of Python.
39042
39043 @item zlib
39044 @cindex compressed debug sections
39045 @value{GDBN} will use the @samp{zlib} library, if available, to read
39046 compressed debug sections. Some linkers, such as GNU gold, are capable
39047 of producing binaries with compressed debug sections. If @value{GDBN}
39048 is compiled with @samp{zlib}, it will be able to read the debug
39049 information in such binaries.
39050
39051 The @samp{zlib} library is likely included with your operating system
39052 distribution; if it is not, you can get the latest version from
39053 @url{http://zlib.net}.
39054 @end table
39055
39056 @node Running Configure
39057 @section Invoking the @value{GDBN} @file{configure} Script
39058 @cindex configuring @value{GDBN}
39059 @value{GDBN} comes with a @file{configure} script that automates the process
39060 of preparing @value{GDBN} for installation; you can then use @code{make} to
39061 build the @code{gdb} program.
39062 @iftex
39063 @c irrelevant in info file; it's as current as the code it lives with.
39064 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
39065 look at the @file{README} file in the sources; we may have improved the
39066 installation procedures since publishing this manual.}
39067 @end iftex
39068
39069 The @value{GDBN} distribution includes all the source code you need for
39070 @value{GDBN} in a single directory, whose name is usually composed by
39071 appending the version number to @samp{gdb}.
39072
39073 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
39074 @file{gdb-@value{GDBVN}} directory. That directory contains:
39075
39076 @table @code
39077 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
39078 script for configuring @value{GDBN} and all its supporting libraries
39079
39080 @item gdb-@value{GDBVN}/gdb
39081 the source specific to @value{GDBN} itself
39082
39083 @item gdb-@value{GDBVN}/bfd
39084 source for the Binary File Descriptor library
39085
39086 @item gdb-@value{GDBVN}/include
39087 @sc{gnu} include files
39088
39089 @item gdb-@value{GDBVN}/libiberty
39090 source for the @samp{-liberty} free software library
39091
39092 @item gdb-@value{GDBVN}/opcodes
39093 source for the library of opcode tables and disassemblers
39094
39095 @item gdb-@value{GDBVN}/readline
39096 source for the @sc{gnu} command-line interface
39097 @end table
39098
39099 There may be other subdirectories as well.
39100
39101 The simplest way to configure and build @value{GDBN} is to run @file{configure}
39102 from the @file{gdb-@var{version-number}} source directory, which in
39103 this example is the @file{gdb-@value{GDBVN}} directory.
39104
39105 First switch to the @file{gdb-@var{version-number}} source directory
39106 if you are not already in it; then run @file{configure}. Pass the
39107 identifier for the platform on which @value{GDBN} will run as an
39108 argument.
39109
39110 For example:
39111
39112 @smallexample
39113 cd gdb-@value{GDBVN}
39114 ./configure
39115 make
39116 @end smallexample
39117
39118 Running @samp{configure} and then running @code{make} builds the
39119 included supporting libraries, then @code{gdb} itself. The configured
39120 source files, and the binaries, are left in the corresponding source
39121 directories.
39122
39123 @need 750
39124 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
39125 system does not recognize this automatically when you run a different
39126 shell, you may need to run @code{sh} on it explicitly:
39127
39128 @smallexample
39129 sh configure
39130 @end smallexample
39131
39132 You should run the @file{configure} script from the top directory in the
39133 source tree, the @file{gdb-@var{version-number}} directory. If you run
39134 @file{configure} from one of the subdirectories, you will configure only
39135 that subdirectory. That is usually not what you want. In particular,
39136 if you run the first @file{configure} from the @file{gdb} subdirectory
39137 of the @file{gdb-@var{version-number}} directory, you will omit the
39138 configuration of @file{bfd}, @file{readline}, and other sibling
39139 directories of the @file{gdb} subdirectory. This leads to build errors
39140 about missing include files such as @file{bfd/bfd.h}.
39141
39142 You can install @code{@value{GDBN}} anywhere. The best way to do this
39143 is to pass the @code{--prefix} option to @code{configure}, and then
39144 install it with @code{make install}.
39145
39146 @node Separate Objdir
39147 @section Compiling @value{GDBN} in Another Directory
39148
39149 If you want to run @value{GDBN} versions for several host or target machines,
39150 you need a different @code{gdb} compiled for each combination of
39151 host and target. @file{configure} is designed to make this easy by
39152 allowing you to generate each configuration in a separate subdirectory,
39153 rather than in the source directory. If your @code{make} program
39154 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
39155 @code{make} in each of these directories builds the @code{gdb}
39156 program specified there.
39157
39158 To build @code{gdb} in a separate directory, run @file{configure}
39159 with the @samp{--srcdir} option to specify where to find the source.
39160 (You also need to specify a path to find @file{configure}
39161 itself from your working directory. If the path to @file{configure}
39162 would be the same as the argument to @samp{--srcdir}, you can leave out
39163 the @samp{--srcdir} option; it is assumed.)
39164
39165 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
39166 separate directory for a Sun 4 like this:
39167
39168 @smallexample
39169 @group
39170 cd gdb-@value{GDBVN}
39171 mkdir ../gdb-sun4
39172 cd ../gdb-sun4
39173 ../gdb-@value{GDBVN}/configure
39174 make
39175 @end group
39176 @end smallexample
39177
39178 When @file{configure} builds a configuration using a remote source
39179 directory, it creates a tree for the binaries with the same structure
39180 (and using the same names) as the tree under the source directory. In
39181 the example, you'd find the Sun 4 library @file{libiberty.a} in the
39182 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
39183 @file{gdb-sun4/gdb}.
39184
39185 Make sure that your path to the @file{configure} script has just one
39186 instance of @file{gdb} in it. If your path to @file{configure} looks
39187 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
39188 one subdirectory of @value{GDBN}, not the whole package. This leads to
39189 build errors about missing include files such as @file{bfd/bfd.h}.
39190
39191 One popular reason to build several @value{GDBN} configurations in separate
39192 directories is to configure @value{GDBN} for cross-compiling (where
39193 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
39194 programs that run on another machine---the @dfn{target}).
39195 You specify a cross-debugging target by
39196 giving the @samp{--target=@var{target}} option to @file{configure}.
39197
39198 When you run @code{make} to build a program or library, you must run
39199 it in a configured directory---whatever directory you were in when you
39200 called @file{configure} (or one of its subdirectories).
39201
39202 The @code{Makefile} that @file{configure} generates in each source
39203 directory also runs recursively. If you type @code{make} in a source
39204 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
39205 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
39206 will build all the required libraries, and then build GDB.
39207
39208 When you have multiple hosts or targets configured in separate
39209 directories, you can run @code{make} on them in parallel (for example,
39210 if they are NFS-mounted on each of the hosts); they will not interfere
39211 with each other.
39212
39213 @node Config Names
39214 @section Specifying Names for Hosts and Targets
39215
39216 The specifications used for hosts and targets in the @file{configure}
39217 script are based on a three-part naming scheme, but some short predefined
39218 aliases are also supported. The full naming scheme encodes three pieces
39219 of information in the following pattern:
39220
39221 @smallexample
39222 @var{architecture}-@var{vendor}-@var{os}
39223 @end smallexample
39224
39225 For example, you can use the alias @code{sun4} as a @var{host} argument,
39226 or as the value for @var{target} in a @code{--target=@var{target}}
39227 option. The equivalent full name is @samp{sparc-sun-sunos4}.
39228
39229 The @file{configure} script accompanying @value{GDBN} does not provide
39230 any query facility to list all supported host and target names or
39231 aliases. @file{configure} calls the Bourne shell script
39232 @code{config.sub} to map abbreviations to full names; you can read the
39233 script, if you wish, or you can use it to test your guesses on
39234 abbreviations---for example:
39235
39236 @smallexample
39237 % sh config.sub i386-linux
39238 i386-pc-linux-gnu
39239 % sh config.sub alpha-linux
39240 alpha-unknown-linux-gnu
39241 % sh config.sub hp9k700
39242 hppa1.1-hp-hpux
39243 % sh config.sub sun4
39244 sparc-sun-sunos4.1.1
39245 % sh config.sub sun3
39246 m68k-sun-sunos4.1.1
39247 % sh config.sub i986v
39248 Invalid configuration `i986v': machine `i986v' not recognized
39249 @end smallexample
39250
39251 @noindent
39252 @code{config.sub} is also distributed in the @value{GDBN} source
39253 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
39254
39255 @node Configure Options
39256 @section @file{configure} Options
39257
39258 Here is a summary of the @file{configure} options and arguments that
39259 are most often useful for building @value{GDBN}. @file{configure}
39260 also has several other options not listed here. @xref{Running
39261 configure Scripts,,,autoconf}, for a full
39262 explanation of @file{configure}.
39263
39264 @smallexample
39265 configure @r{[}--help@r{]}
39266 @r{[}--prefix=@var{dir}@r{]}
39267 @r{[}--exec-prefix=@var{dir}@r{]}
39268 @r{[}--srcdir=@var{dirname}@r{]}
39269 @r{[}--target=@var{target}@r{]}
39270 @end smallexample
39271
39272 @noindent
39273 You may introduce options with a single @samp{-} rather than
39274 @samp{--} if you prefer; but you may abbreviate option names if you use
39275 @samp{--}.
39276
39277 @table @code
39278 @item --help
39279 Display a quick summary of how to invoke @file{configure}.
39280
39281 @item --prefix=@var{dir}
39282 Configure the source to install programs and files under directory
39283 @file{@var{dir}}.
39284
39285 @item --exec-prefix=@var{dir}
39286 Configure the source to install programs under directory
39287 @file{@var{dir}}.
39288
39289 @c avoid splitting the warning from the explanation:
39290 @need 2000
39291 @item --srcdir=@var{dirname}
39292 Use this option to make configurations in directories separate from the
39293 @value{GDBN} source directories. Among other things, you can use this to
39294 build (or maintain) several configurations simultaneously, in separate
39295 directories. @file{configure} writes configuration-specific files in
39296 the current directory, but arranges for them to use the source in the
39297 directory @var{dirname}. @file{configure} creates directories under
39298 the working directory in parallel to the source directories below
39299 @var{dirname}.
39300
39301 @item --target=@var{target}
39302 Configure @value{GDBN} for cross-debugging programs running on the specified
39303 @var{target}. Without this option, @value{GDBN} is configured to debug
39304 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
39305
39306 There is no convenient way to generate a list of all available
39307 targets. Also see the @code{--enable-targets} option, below.
39308 @end table
39309
39310 There are many other options that are specific to @value{GDBN}. This
39311 lists just the most common ones; there are some very specialized
39312 options not described here.
39313
39314 @table @code
39315 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
39316 @itemx --enable-targets=all
39317 Configure @value{GDBN} for cross-debugging programs running on the
39318 specified list of targets. The special value @samp{all} configures
39319 @value{GDBN} for debugging programs running on any target it supports.
39320
39321 @item --with-gdb-datadir=@var{path}
39322 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
39323 here for certain supporting files or scripts. This defaults to the
39324 @file{gdb} subdirectory of @samp{datadir} (which can be set using
39325 @code{--datadir}).
39326
39327 @item --with-relocated-sources=@var{dir}
39328 Sets up the default source path substitution rule so that directory
39329 names recorded in debug information will be automatically adjusted for
39330 any directory under @var{dir}. @var{dir} should be a subdirectory of
39331 @value{GDBN}'s configured prefix, the one mentioned in the
39332 @code{--prefix} or @code{--exec-prefix} options to configure. This
39333 option is useful if GDB is supposed to be moved to a different place
39334 after it is built.
39335
39336 @item --enable-64-bit-bfd
39337 Enable 64-bit support in BFD on 32-bit hosts.
39338
39339 @item --disable-gdbmi
39340 Build @value{GDBN} without the GDB/MI machine interface
39341 (@pxref{GDB/MI}).
39342
39343 @item --enable-tui
39344 Build @value{GDBN} with the text-mode full-screen user interface
39345 (TUI). Requires a curses library (ncurses and cursesX are also
39346 supported).
39347
39348 @item --with-curses
39349 Use the curses library instead of the termcap library, for text-mode
39350 terminal operations.
39351
39352 @item --with-debuginfod
39353 Build @value{GDBN} with @file{libdebuginfod}, the @code{debuginfod} client
39354 library. Used to automatically fetch ELF, DWARF and source files from
39355 @code{debuginfod} servers using build IDs associated with any missing
39356 files. Enabled by default if @file{libdebuginfod} is installed and found
39357 at configure time. For more information regarding @code{debuginfod} see
39358 @ref{Debuginfod}.
39359
39360 @item --with-libunwind-ia64
39361 Use the libunwind library for unwinding function call stack on ia64
39362 target platforms. See http://www.nongnu.org/libunwind/index.html for
39363 details.
39364
39365 @item --with-system-readline
39366 Use the readline library installed on the host, rather than the
39367 library supplied as part of @value{GDBN}. Readline 7 or newer is
39368 required; this is enforced by the build system.
39369
39370 @item --with-system-zlib
39371 Use the zlib library installed on the host, rather than the library
39372 supplied as part of @value{GDBN}.
39373
39374 @item --with-expat
39375 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
39376 default if libexpat is installed and found at configure time.) This
39377 library is used to read XML files supplied with @value{GDBN}. If it
39378 is unavailable, some features, such as remote protocol memory maps,
39379 target descriptions, and shared library lists, that are based on XML
39380 files, will not be available in @value{GDBN}. If your host does not
39381 have libexpat installed, you can get the latest version from
39382 `http://expat.sourceforge.net'.
39383
39384 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
39385
39386 Build @value{GDBN} with GNU libiconv, a character set encoding
39387 conversion library. This is not done by default, as on GNU systems
39388 the @code{iconv} that is built in to the C library is sufficient. If
39389 your host does not have a working @code{iconv}, you can get the latest
39390 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
39391
39392 @value{GDBN}'s build system also supports building GNU libiconv as
39393 part of the overall build. @xref{Requirements}.
39394
39395 @item --with-lzma
39396 Build @value{GDBN} with LZMA, a compression library. (Done by default
39397 if liblzma is installed and found at configure time.) LZMA is used by
39398 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
39399 platforms using the ELF object file format. If your host does not
39400 have liblzma installed, you can get the latest version from
39401 `https://tukaani.org/xz/'.
39402
39403 @item --with-mpfr
39404 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
39405 floating-point computation with correct rounding. (Done by default if
39406 GNU MPFR is installed and found at configure time.) This library is
39407 used to emulate target floating-point arithmetic during expression
39408 evaluation when the target uses different floating-point formats than
39409 the host. If GNU MPFR is not available, @value{GDBN} will fall back
39410 to using host floating-point arithmetic. If your host does not have
39411 GNU MPFR installed, you can get the latest version from
39412 `http://www.mpfr.org'.
39413
39414 @item --with-python@r{[}=@var{python}@r{]}
39415 Build @value{GDBN} with Python scripting support. (Done by default if
39416 libpython is present and found at configure time.) Python makes
39417 @value{GDBN} scripting much more powerful than the restricted CLI
39418 scripting language. If your host does not have Python installed, you
39419 can find it on `http://www.python.org/download/'. The oldest version
39420 of Python supported by GDB is 2.6. The optional argument @var{python}
39421 is used to find the Python headers and libraries. It can be either
39422 the name of a Python executable, or the name of the directory in which
39423 Python is installed.
39424
39425 @item --with-guile[=GUILE]'
39426 Build @value{GDBN} with GNU Guile scripting support. (Done by default
39427 if libguile is present and found at configure time.) If your host
39428 does not have Guile installed, you can find it at
39429 `https://www.gnu.org/software/guile/'. The optional argument GUILE
39430 can be a version number, which will cause @code{configure} to try to
39431 use that version of Guile; or the file name of a @code{pkg-config}
39432 executable, which will be queried to find the information needed to
39433 compile and link against Guile.
39434
39435 @item --without-included-regex
39436 Don't use the regex library included with @value{GDBN} (as part of the
39437 libiberty library). This is the default on hosts with version 2 of
39438 the GNU C library.
39439
39440 @item --with-sysroot=@var{dir}
39441 Use @var{dir} as the default system root directory for libraries whose
39442 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
39443 @var{dir} can be modified at run time by using the @command{set
39444 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
39445 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
39446 default system root will be automatically adjusted if and when
39447 @value{GDBN} is moved to a different location.
39448
39449 @item --with-system-gdbinit=@var{file}
39450 Configure @value{GDBN} to automatically load a system-wide init file.
39451 @var{file} should be an absolute file name. If @var{file} is in a
39452 directory under the configured prefix, and @value{GDBN} is moved to
39453 another location after being built, the location of the system-wide
39454 init file will be adjusted accordingly.
39455
39456 @item --with-system-gdbinit-dir=@var{directory}
39457 Configure @value{GDBN} to automatically load init files from a
39458 system-wide directory. @var{directory} should be an absolute directory
39459 name. If @var{directory} is in a directory under the configured
39460 prefix, and @value{GDBN} is moved to another location after being
39461 built, the location of the system-wide init directory will be
39462 adjusted accordingly.
39463
39464 @item --enable-build-warnings
39465 When building the @value{GDBN} sources, ask the compiler to warn about
39466 any code which looks even vaguely suspicious. It passes many
39467 different warning flags, depending on the exact version of the
39468 compiler you are using.
39469
39470 @item --enable-werror
39471 Treat compiler warnings as errors. It adds the @code{-Werror} flag
39472 to the compiler, which will fail the compilation if the compiler
39473 outputs any warning messages.
39474
39475 @item --enable-ubsan
39476 Enable the GCC undefined behavior sanitizer. This is disabled by
39477 default, but passing @code{--enable-ubsan=yes} or
39478 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
39479 undefined behavior sanitizer checks for C@t{++} undefined behavior.
39480 It has a performance cost, so if you are looking at @value{GDBN}'s
39481 performance, you should disable it. The undefined behavior sanitizer
39482 was first introduced in GCC 4.9.
39483 @end table
39484
39485 @node System-wide configuration
39486 @section System-wide configuration and settings
39487 @cindex system-wide init file
39488
39489 @value{GDBN} can be configured to have a system-wide init file and a
39490 system-wide init file directory; this file and files in that directory
39491 (if they have a recognized file extension) will be read and executed at
39492 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
39493
39494 Here are the corresponding configure options:
39495
39496 @table @code
39497 @item --with-system-gdbinit=@var{file}
39498 Specify that the default location of the system-wide init file is
39499 @var{file}.
39500 @item --with-system-gdbinit-dir=@var{directory}
39501 Specify that the default location of the system-wide init file directory
39502 is @var{directory}.
39503 @end table
39504
39505 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
39506 they may be subject to relocation. Two possible cases:
39507
39508 @itemize @bullet
39509 @item
39510 If the default location of this init file/directory contains @file{$prefix},
39511 it will be subject to relocation. Suppose that the configure options
39512 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
39513 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
39514 init file is looked for as @file{$install/etc/gdbinit} instead of
39515 @file{$prefix/etc/gdbinit}.
39516
39517 @item
39518 By contrast, if the default location does not contain the prefix,
39519 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
39520 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
39521 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
39522 wherever @value{GDBN} is installed.
39523 @end itemize
39524
39525 If the configured location of the system-wide init file (as given by the
39526 @option{--with-system-gdbinit} option at configure time) is in the
39527 data-directory (as specified by @option{--with-gdb-datadir} at configure
39528 time) or in one of its subdirectories, then @value{GDBN} will look for the
39529 system-wide init file in the directory specified by the
39530 @option{--data-directory} command-line option.
39531 Note that the system-wide init file is only read once, during @value{GDBN}
39532 initialization. If the data-directory is changed after @value{GDBN} has
39533 started with the @code{set data-directory} command, the file will not be
39534 reread.
39535
39536 This applies similarly to the system-wide directory specified in
39537 @option{--with-system-gdbinit-dir}.
39538
39539 Any supported scripting language can be used for these init files, as long
39540 as the file extension matches the scripting language. To be interpreted
39541 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
39542 extension.
39543
39544 @menu
39545 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
39546 @end menu
39547
39548 @node System-wide Configuration Scripts
39549 @subsection Installed System-wide Configuration Scripts
39550 @cindex system-wide configuration scripts
39551
39552 The @file{system-gdbinit} directory, located inside the data-directory
39553 (as specified by @option{--with-gdb-datadir} at configure time) contains
39554 a number of scripts which can be used as system-wide init files. To
39555 automatically source those scripts at startup, @value{GDBN} should be
39556 configured with @option{--with-system-gdbinit}. Otherwise, any user
39557 should be able to source them by hand as needed.
39558
39559 The following scripts are currently available:
39560 @itemize @bullet
39561
39562 @item @file{elinos.py}
39563 @pindex elinos.py
39564 @cindex ELinOS system-wide configuration script
39565 This script is useful when debugging a program on an ELinOS target.
39566 It takes advantage of the environment variables defined in a standard
39567 ELinOS environment in order to determine the location of the system
39568 shared libraries, and then sets the @samp{solib-absolute-prefix}
39569 and @samp{solib-search-path} variables appropriately.
39570
39571 @item @file{wrs-linux.py}
39572 @pindex wrs-linux.py
39573 @cindex Wind River Linux system-wide configuration script
39574 This script is useful when debugging a program on a target running
39575 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
39576 the host-side sysroot used by the target system.
39577
39578 @end itemize
39579
39580 @node Maintenance Commands
39581 @appendix Maintenance Commands
39582 @cindex maintenance commands
39583 @cindex internal commands
39584
39585 In addition to commands intended for @value{GDBN} users, @value{GDBN}
39586 includes a number of commands intended for @value{GDBN} developers,
39587 that are not documented elsewhere in this manual. These commands are
39588 provided here for reference. (For commands that turn on debugging
39589 messages, see @ref{Debugging Output}.)
39590
39591 @table @code
39592 @kindex maint agent
39593 @kindex maint agent-eval
39594 @item maint agent @r{[}-at @var{linespec}@r{,}@r{]} @var{expression}
39595 @itemx maint agent-eval @r{[}-at @var{linespec}@r{,}@r{]} @var{expression}
39596 Translate the given @var{expression} into remote agent bytecodes.
39597 This command is useful for debugging the Agent Expression mechanism
39598 (@pxref{Agent Expressions}). The @samp{agent} version produces an
39599 expression useful for data collection, such as by tracepoints, while
39600 @samp{maint agent-eval} produces an expression that evaluates directly
39601 to a result. For instance, a collection expression for @code{globa +
39602 globb} will include bytecodes to record four bytes of memory at each
39603 of the addresses of @code{globa} and @code{globb}, while discarding
39604 the result of the addition, while an evaluation expression will do the
39605 addition and return the sum.
39606 If @code{-at} is given, generate remote agent bytecode for all the
39607 addresses to which @var{linespec} resolves (@pxref{Linespec
39608 Locations}).
39609 If not, generate remote agent bytecode for current frame PC address.
39610
39611 @kindex maint agent-printf
39612 @item maint agent-printf @var{format},@var{expr},...
39613 Translate the given format string and list of argument expressions
39614 into remote agent bytecodes and display them as a disassembled list.
39615 This command is useful for debugging the agent version of dynamic
39616 printf (@pxref{Dynamic Printf}).
39617
39618 @kindex maint info breakpoints
39619 @item @anchor{maint info breakpoints}maint info breakpoints
39620 Using the same format as @samp{info breakpoints}, display both the
39621 breakpoints you've set explicitly, and those @value{GDBN} is using for
39622 internal purposes. Internal breakpoints are shown with negative
39623 breakpoint numbers. The type column identifies what kind of breakpoint
39624 is shown:
39625
39626 @table @code
39627 @item breakpoint
39628 Normal, explicitly set breakpoint.
39629
39630 @item watchpoint
39631 Normal, explicitly set watchpoint.
39632
39633 @item longjmp
39634 Internal breakpoint, used to handle correctly stepping through
39635 @code{longjmp} calls.
39636
39637 @item longjmp resume
39638 Internal breakpoint at the target of a @code{longjmp}.
39639
39640 @item until
39641 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
39642
39643 @item finish
39644 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
39645
39646 @item shlib events
39647 Shared library events.
39648
39649 @end table
39650
39651 @kindex maint info btrace
39652 @item maint info btrace
39653 Pint information about raw branch tracing data.
39654
39655 @kindex maint btrace packet-history
39656 @item maint btrace packet-history
39657 Print the raw branch trace packets that are used to compute the
39658 execution history for the @samp{record btrace} command. Both the
39659 information and the format in which it is printed depend on the btrace
39660 recording format.
39661
39662 @table @code
39663 @item bts
39664 For the BTS recording format, print a list of blocks of sequential
39665 code. For each block, the following information is printed:
39666
39667 @table @asis
39668 @item Block number
39669 Newer blocks have higher numbers. The oldest block has number zero.
39670 @item Lowest @samp{PC}
39671 @item Highest @samp{PC}
39672 @end table
39673
39674 @item pt
39675 For the Intel Processor Trace recording format, print a list of
39676 Intel Processor Trace packets. For each packet, the following
39677 information is printed:
39678
39679 @table @asis
39680 @item Packet number
39681 Newer packets have higher numbers. The oldest packet has number zero.
39682 @item Trace offset
39683 The packet's offset in the trace stream.
39684 @item Packet opcode and payload
39685 @end table
39686 @end table
39687
39688 @kindex maint btrace clear-packet-history
39689 @item maint btrace clear-packet-history
39690 Discards the cached packet history printed by the @samp{maint btrace
39691 packet-history} command. The history will be computed again when
39692 needed.
39693
39694 @kindex maint btrace clear
39695 @item maint btrace clear
39696 Discard the branch trace data. The data will be fetched anew and the
39697 branch trace will be recomputed when needed.
39698
39699 This implicitly truncates the branch trace to a single branch trace
39700 buffer. When updating branch trace incrementally, the branch trace
39701 available to @value{GDBN} may be bigger than a single branch trace
39702 buffer.
39703
39704 @kindex maint set btrace pt skip-pad
39705 @item maint set btrace pt skip-pad
39706 @kindex maint show btrace pt skip-pad
39707 @item maint show btrace pt skip-pad
39708 Control whether @value{GDBN} will skip PAD packets when computing the
39709 packet history.
39710
39711 @kindex maint info jit
39712 @item maint info jit
39713 Print information about JIT code objects loaded in the current inferior.
39714
39715 @anchor{maint info python-disassemblers}
39716 @kindex maint info python-disassemblers
39717 @item maint info python-disassemblers
39718 This command is defined within the @code{gdb.disassembler} Python
39719 module (@pxref{Disassembly In Python}), and will only be present after
39720 that module has been imported. To force the module to be imported do
39721 the following:
39722
39723 @smallexample
39724 (@value{GDBP}) python import gdb.disassembler
39725 @end smallexample
39726
39727 This command lists all the architectures for which a disassembler is
39728 currently registered, and the name of the disassembler. If a
39729 disassembler is registered for all architectures, then this is listed
39730 last against the @samp{GLOBAL} architecture.
39731
39732 If one of the disassemblers would be selected for the architecture of
39733 the current inferior, then this disassembler will be marked.
39734
39735 The following example shows a situation in which two disassemblers are
39736 registered, initially the @samp{i386} disassembler matches the current
39737 architecture, then the architecture is changed, now the @samp{GLOBAL}
39738 disassembler matches.
39739
39740 @smallexample
39741 @group
39742 (@value{GDBP}) show architecture
39743 The target architecture is set to "auto" (currently "i386").
39744 (@value{GDBP}) maint info python-disassemblers
39745 Architecture Disassember Name
39746 i386 Disassembler_1 (Matches current architecture)
39747 GLOBAL Disassembler_2
39748 @end group
39749 @group
39750 (@value{GDBP}) set architecture arm
39751 The target architecture is set to "arm".
39752 (@value{GDBP}) maint info python-disassemblers
39753 quit
39754 Architecture Disassember Name
39755 i386 Disassembler_1
39756 GLOBAL Disassembler_2 (Matches current architecture)
39757 @end group
39758 @end smallexample
39759
39760 @kindex set displaced-stepping
39761 @kindex show displaced-stepping
39762 @cindex displaced stepping support
39763 @cindex out-of-line single-stepping
39764 @item set displaced-stepping
39765 @itemx show displaced-stepping
39766 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
39767 if the target supports it. Displaced stepping is a way to single-step
39768 over breakpoints without removing them from the inferior, by executing
39769 an out-of-line copy of the instruction that was originally at the
39770 breakpoint location. It is also known as out-of-line single-stepping.
39771
39772 @table @code
39773 @item set displaced-stepping on
39774 If the target architecture supports it, @value{GDBN} will use
39775 displaced stepping to step over breakpoints.
39776
39777 @item set displaced-stepping off
39778 @value{GDBN} will not use displaced stepping to step over breakpoints,
39779 even if such is supported by the target architecture.
39780
39781 @cindex non-stop mode, and @samp{set displaced-stepping}
39782 @item set displaced-stepping auto
39783 This is the default mode. @value{GDBN} will use displaced stepping
39784 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
39785 architecture supports displaced stepping.
39786 @end table
39787
39788 @kindex maint check-psymtabs
39789 @item maint check-psymtabs
39790 Check the consistency of currently expanded psymtabs versus symtabs.
39791 Use this to check, for example, whether a symbol is in one but not the other.
39792
39793 @kindex maint check-symtabs
39794 @item maint check-symtabs
39795 Check the consistency of currently expanded symtabs.
39796
39797 @kindex maint expand-symtabs
39798 @item maint expand-symtabs [@var{regexp}]
39799 Expand symbol tables.
39800 If @var{regexp} is specified, only expand symbol tables for file
39801 names matching @var{regexp}.
39802
39803 @kindex maint set catch-demangler-crashes
39804 @kindex maint show catch-demangler-crashes
39805 @cindex demangler crashes
39806 @item maint set catch-demangler-crashes [on|off]
39807 @itemx maint show catch-demangler-crashes
39808 Control whether @value{GDBN} should attempt to catch crashes in the
39809 symbol name demangler. The default is to attempt to catch crashes.
39810 If enabled, the first time a crash is caught, a core file is created,
39811 the offending symbol is displayed and the user is presented with the
39812 option to terminate the current session.
39813
39814 @kindex maint cplus first_component
39815 @item maint cplus first_component @var{name}
39816 Print the first C@t{++} class/namespace component of @var{name}.
39817
39818 @kindex maint cplus namespace
39819 @item maint cplus namespace
39820 Print the list of possible C@t{++} namespaces.
39821
39822 @kindex maint deprecate
39823 @kindex maint undeprecate
39824 @cindex deprecated commands
39825 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
39826 @itemx maint undeprecate @var{command}
39827 Deprecate or undeprecate the named @var{command}. Deprecated commands
39828 cause @value{GDBN} to issue a warning when you use them. The optional
39829 argument @var{replacement} says which newer command should be used in
39830 favor of the deprecated one; if it is given, @value{GDBN} will mention
39831 the replacement as part of the warning.
39832
39833 @kindex maint dump-me
39834 @item maint dump-me
39835 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
39836 Cause a fatal signal in the debugger and force it to dump its core.
39837 This is supported only on systems which support aborting a program
39838 with the @code{SIGQUIT} signal.
39839
39840 @kindex maint internal-error
39841 @kindex maint internal-warning
39842 @kindex maint demangler-warning
39843 @cindex demangler crashes
39844 @item maint internal-error @r{[}@var{message-text}@r{]}
39845 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
39846 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
39847
39848 Cause @value{GDBN} to call the internal function @code{internal_error},
39849 @code{internal_warning} or @code{demangler_warning} and hence behave
39850 as though an internal problem has been detected. In addition to
39851 reporting the internal problem, these functions give the user the
39852 opportunity to either quit @value{GDBN} or (for @code{internal_error}
39853 and @code{internal_warning}) create a core file of the current
39854 @value{GDBN} session.
39855
39856 These commands take an optional parameter @var{message-text} that is
39857 used as the text of the error or warning message.
39858
39859 Here's an example of using @code{internal-error}:
39860
39861 @smallexample
39862 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
39863 @dots{}/maint.c:121: internal-error: testing, 1, 2
39864 A problem internal to GDB has been detected. Further
39865 debugging may prove unreliable.
39866 Quit this debugging session? (y or n) @kbd{n}
39867 Create a core file? (y or n) @kbd{n}
39868 (@value{GDBP})
39869 @end smallexample
39870
39871 @cindex @value{GDBN} internal error
39872 @cindex internal errors, control of @value{GDBN} behavior
39873 @cindex demangler crashes
39874
39875 @kindex maint set internal-error
39876 @kindex maint show internal-error
39877 @kindex maint set internal-warning
39878 @kindex maint show internal-warning
39879 @kindex maint set demangler-warning
39880 @kindex maint show demangler-warning
39881 @item maint set internal-error @var{action} [ask|yes|no]
39882 @itemx maint show internal-error @var{action}
39883 @itemx maint set internal-warning @var{action} [ask|yes|no]
39884 @itemx maint show internal-warning @var{action}
39885 @itemx maint set demangler-warning @var{action} [ask|yes|no]
39886 @itemx maint show demangler-warning @var{action}
39887 When @value{GDBN} reports an internal problem (error or warning) it
39888 gives the user the opportunity to both quit @value{GDBN} and create a
39889 core file of the current @value{GDBN} session. These commands let you
39890 override the default behaviour for each particular @var{action},
39891 described in the table below.
39892
39893 @table @samp
39894 @item quit
39895 You can specify that @value{GDBN} should always (yes) or never (no)
39896 quit. The default is to ask the user what to do.
39897
39898 @item corefile
39899 You can specify that @value{GDBN} should always (yes) or never (no)
39900 create a core file. The default is to ask the user what to do. Note
39901 that there is no @code{corefile} option for @code{demangler-warning}:
39902 demangler warnings always create a core file and this cannot be
39903 disabled.
39904 @end table
39905
39906 @kindex maint set internal-error
39907 @kindex maint show internal-error
39908 @kindex maint set internal-warning
39909 @kindex maint show internal-warning
39910 @item maint set internal-error backtrace @r{[}on|off@r{]}
39911 @itemx maint show internal-error backtrace
39912 @itemx maint set internal-warning backtrace @r{[}on|off@r{]}
39913 @itemx maint show internal-warning backtrace
39914 When @value{GDBN} reports an internal problem (error or warning) it is
39915 possible to have a backtrace of @value{GDBN} printed to the standard
39916 error stream. This is @samp{on} by default for @code{internal-error}
39917 and @samp{off} by default for @code{internal-warning}.
39918
39919 @anchor{maint packet}
39920 @kindex maint packet
39921 @item maint packet @var{text}
39922 If @value{GDBN} is talking to an inferior via the serial protocol,
39923 then this command sends the string @var{text} to the inferior, and
39924 displays the response packet. @value{GDBN} supplies the initial
39925 @samp{$} character, the terminating @samp{#} character, and the
39926 checksum.
39927
39928 Any non-printable characters in the reply are printed as escaped hex,
39929 e.g. @samp{\x00}, @samp{\x01}, etc.
39930
39931 @kindex maint print architecture
39932 @item maint print architecture @r{[}@var{file}@r{]}
39933 Print the entire architecture configuration. The optional argument
39934 @var{file} names the file where the output goes.
39935
39936 @kindex maint print c-tdesc
39937 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
39938 Print the target description (@pxref{Target Descriptions}) as
39939 a C source file. By default, the target description is for the current
39940 target, but if the optional argument @var{file} is provided, that file
39941 is used to produce the description. The @var{file} should be an XML
39942 document, of the form described in @ref{Target Description Format}.
39943 The created source file is built into @value{GDBN} when @value{GDBN} is
39944 built again. This command is used by developers after they add or
39945 modify XML target descriptions.
39946
39947 When the optional flag @samp{-single-feature} is provided then the
39948 target description being processed (either the default, or from
39949 @var{file}) must only contain a single feature. The source file
39950 produced is different in this case.
39951
39952 @kindex maint print xml-tdesc
39953 @item maint print xml-tdesc @r{[}@var{file}@r{]}
39954 Print the target description (@pxref{Target Descriptions}) as an XML
39955 file. By default print the target description for the current target,
39956 but if the optional argument @var{file} is provided, then that file is
39957 read in by GDB and then used to produce the description. The
39958 @var{file} should be an XML document, of the form described in
39959 @ref{Target Description Format}.
39960
39961 @kindex maint check xml-descriptions
39962 @item maint check xml-descriptions @var{dir}
39963 Check that the target descriptions dynamically created by @value{GDBN}
39964 equal the descriptions created from XML files found in @var{dir}.
39965
39966 @anchor{maint check libthread-db}
39967 @kindex maint check libthread-db
39968 @item maint check libthread-db
39969 Run integrity checks on the current inferior's thread debugging
39970 library. This exercises all @code{libthread_db} functionality used by
39971 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
39972 @code{proc_service} functions provided by @value{GDBN} that
39973 @code{libthread_db} uses. Note that parts of the test may be skipped
39974 on some platforms when debugging core files.
39975
39976 @kindex maint print core-file-backed-mappings
39977 @cindex memory address space mappings
39978 @item maint print core-file-backed-mappings
39979 Print the file-backed mappings which were loaded from a core file note.
39980 This output represents state internal to @value{GDBN} and should be
39981 similar to the mappings displayed by the @code{info proc mappings}
39982 command.
39983
39984 @kindex maint print dummy-frames
39985 @item maint print dummy-frames
39986 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
39987
39988 @smallexample
39989 (@value{GDBP}) @kbd{b add}
39990 @dots{}
39991 (@value{GDBP}) @kbd{print add(2,3)}
39992 Breakpoint 2, add (a=2, b=3) at @dots{}
39993 58 return (a + b);
39994 The program being debugged stopped while in a function called from GDB.
39995 @dots{}
39996 (@value{GDBP}) @kbd{maint print dummy-frames}
39997 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
39998 (@value{GDBP})
39999 @end smallexample
40000
40001 Takes an optional file parameter.
40002
40003 @kindex maint print registers
40004 @kindex maint print raw-registers
40005 @kindex maint print cooked-registers
40006 @kindex maint print register-groups
40007 @kindex maint print remote-registers
40008 @item maint print registers @r{[}@var{file}@r{]}
40009 @itemx maint print raw-registers @r{[}@var{file}@r{]}
40010 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
40011 @itemx maint print register-groups @r{[}@var{file}@r{]}
40012 @itemx maint print remote-registers @r{[}@var{file}@r{]}
40013 Print @value{GDBN}'s internal register data structures.
40014
40015 The command @code{maint print raw-registers} includes the contents of
40016 the raw register cache; the command @code{maint print
40017 cooked-registers} includes the (cooked) value of all registers,
40018 including registers which aren't available on the target nor visible
40019 to user; the command @code{maint print register-groups} includes the
40020 groups that each register is a member of; and the command @code{maint
40021 print remote-registers} includes the remote target's register numbers
40022 and offsets in the `G' packets.
40023
40024 These commands take an optional parameter, a file name to which to
40025 write the information.
40026
40027 @kindex maint print reggroups
40028 @item maint print reggroups @r{[}@var{file}@r{]}
40029 Print @value{GDBN}'s internal register group data structures. The
40030 optional argument @var{file} tells to what file to write the
40031 information.
40032
40033 The register groups info looks like this:
40034
40035 @smallexample
40036 (@value{GDBP}) @kbd{maint print reggroups}
40037 Group Type
40038 general user
40039 float user
40040 all user
40041 vector user
40042 system user
40043 save internal
40044 restore internal
40045 @end smallexample
40046
40047 @kindex maint flush register-cache
40048 @kindex flushregs
40049 @cindex register cache, flushing
40050 @item maint flush register-cache
40051 @itemx flushregs
40052 Flush the contents of the register cache and as a consequence the
40053 frame cache. This command is useful when debugging issues related to
40054 register fetching, or frame unwinding. The command @code{flushregs}
40055 is deprecated in favor of @code{maint flush register-cache}.
40056
40057 @kindex maint flush source-cache
40058 @cindex source code, caching
40059 @item maint flush source-cache
40060 Flush @value{GDBN}'s cache of source code file contents. After
40061 @value{GDBN} reads a source file, and optionally applies styling
40062 (@pxref{Output Styling}), the file contents are cached. This command
40063 clears that cache. The next time @value{GDBN} wants to show lines
40064 from a source file, the content will be re-read.
40065
40066 This command is useful when debugging issues related to source code
40067 styling. After flushing the cache any source code displayed by
40068 @value{GDBN} will be re-read and re-styled.
40069
40070 @kindex maint print objfiles
40071 @cindex info for known object files
40072 @item maint print objfiles @r{[}@var{regexp}@r{]}
40073 Print a dump of all known object files.
40074 If @var{regexp} is specified, only print object files whose names
40075 match @var{regexp}. For each object file, this command prints its name,
40076 address in memory, and all of its psymtabs and symtabs.
40077
40078 @kindex maint print user-registers
40079 @cindex user registers
40080 @item maint print user-registers
40081 List all currently available @dfn{user registers}. User registers
40082 typically provide alternate names for actual hardware registers. They
40083 include the four ``standard'' registers @code{$fp}, @code{$pc},
40084 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
40085 registers can be used in expressions in the same way as the canonical
40086 register names, but only the latter are listed by the @code{info
40087 registers} and @code{maint print registers} commands.
40088
40089 @kindex maint print section-scripts
40090 @cindex info for known .debug_gdb_scripts-loaded scripts
40091 @item maint print section-scripts [@var{regexp}]
40092 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
40093 If @var{regexp} is specified, only print scripts loaded by object files
40094 matching @var{regexp}.
40095 For each script, this command prints its name as specified in the objfile,
40096 and the full path if known.
40097 @xref{dotdebug_gdb_scripts section}.
40098
40099 @kindex maint print statistics
40100 @cindex bcache statistics
40101 @item maint print statistics
40102 This command prints, for each object file in the program, various data
40103 about that object file followed by the byte cache (@dfn{bcache})
40104 statistics for the object file. The objfile data includes the number
40105 of minimal, partial, full, and stabs symbols, the number of types
40106 defined by the objfile, the number of as yet unexpanded psym tables,
40107 the number of line tables and string tables, and the amount of memory
40108 used by the various tables. The bcache statistics include the counts,
40109 sizes, and counts of duplicates of all and unique objects, max,
40110 average, and median entry size, total memory used and its overhead and
40111 savings, and various measures of the hash table size and chain
40112 lengths.
40113
40114 @kindex maint print target-stack
40115 @cindex target stack description
40116 @item maint print target-stack
40117 A @dfn{target} is an interface between the debugger and a particular
40118 kind of file or process. Targets can be stacked in @dfn{strata},
40119 so that more than one target can potentially respond to a request.
40120 In particular, memory accesses will walk down the stack of targets
40121 until they find a target that is interested in handling that particular
40122 address.
40123
40124 This command prints a short description of each layer that was pushed on
40125 the @dfn{target stack}, starting from the top layer down to the bottom one.
40126
40127 @kindex maint print type
40128 @cindex type chain of a data type
40129 @item maint print type @var{expr}
40130 Print the type chain for a type specified by @var{expr}. The argument
40131 can be either a type name or a symbol. If it is a symbol, the type of
40132 that symbol is described. The type chain produced by this command is
40133 a recursive definition of the data type as stored in @value{GDBN}'s
40134 data structures, including its flags and contained types.
40135
40136 @kindex maint selftest
40137 @cindex self tests
40138 @item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}
40139 Run any self tests that were compiled in to @value{GDBN}. This will
40140 print a message showing how many tests were run, and how many failed.
40141 If a @var{filter} is passed, only the tests with @var{filter} in their
40142 name will be ran. If @code{-verbose} is passed, the self tests can be
40143 more verbose.
40144
40145 @kindex maint set selftest verbose
40146 @kindex maint show selftest verbose
40147 @cindex self tests
40148 @item maint set selftest verbose
40149 @item maint show selftest verbose
40150 Control whether self tests are run verbosely or not.
40151
40152 @kindex maint info selftests
40153 @cindex self tests
40154 @item maint info selftests
40155 List the selftests compiled in to @value{GDBN}.
40156
40157 @kindex maint set dwarf always-disassemble
40158 @kindex maint show dwarf always-disassemble
40159 @item maint set dwarf always-disassemble
40160 @item maint show dwarf always-disassemble
40161 Control the behavior of @code{info address} when using DWARF debugging
40162 information.
40163
40164 The default is @code{off}, which means that @value{GDBN} should try to
40165 describe a variable's location in an easily readable format. When
40166 @code{on}, @value{GDBN} will instead display the DWARF location
40167 expression in an assembly-like format. Note that some locations are
40168 too complex for @value{GDBN} to describe simply; in this case you will
40169 always see the disassembly form.
40170
40171 Here is an example of the resulting disassembly:
40172
40173 @smallexample
40174 (gdb) info addr argc
40175 Symbol "argc" is a complex DWARF expression:
40176 1: DW_OP_fbreg 0
40177 @end smallexample
40178
40179 For more information on these expressions, see
40180 @uref{http://www.dwarfstd.org/, the DWARF standard}.
40181
40182 @kindex maint set dwarf max-cache-age
40183 @kindex maint show dwarf max-cache-age
40184 @item maint set dwarf max-cache-age
40185 @itemx maint show dwarf max-cache-age
40186 Control the DWARF compilation unit cache.
40187
40188 @cindex DWARF compilation units cache
40189 In object files with inter-compilation-unit references, such as those
40190 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
40191 reader needs to frequently refer to previously read compilation units.
40192 This setting controls how long a compilation unit will remain in the
40193 cache if it is not referenced. A higher limit means that cached
40194 compilation units will be stored in memory longer, and more total
40195 memory will be used. Setting it to zero disables caching, which will
40196 slow down @value{GDBN} startup, but reduce memory consumption.
40197
40198 @kindex maint set dwarf unwinders
40199 @kindex maint show dwarf unwinders
40200 @item maint set dwarf unwinders
40201 @itemx maint show dwarf unwinders
40202 Control use of the DWARF frame unwinders.
40203
40204 @cindex DWARF frame unwinders
40205 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
40206 frame unwinders to build the backtrace. Many of these targets will
40207 also have a second mechanism for building the backtrace for use in
40208 cases where DWARF information is not available, this second mechanism
40209 is often an analysis of a function's prologue.
40210
40211 In order to extend testing coverage of the second level stack
40212 unwinding mechanisms it is helpful to be able to disable the DWARF
40213 stack unwinders, this can be done with this switch.
40214
40215 In normal use of @value{GDBN} disabling the DWARF unwinders is not
40216 advisable, there are cases that are better handled through DWARF than
40217 prologue analysis, and the debug experience is likely to be better
40218 with the DWARF frame unwinders enabled.
40219
40220 If DWARF frame unwinders are not supported for a particular target
40221 architecture, then enabling this flag does not cause them to be used.
40222
40223 @kindex maint set worker-threads
40224 @kindex maint show worker-threads
40225 @item maint set worker-threads
40226 @item maint show worker-threads
40227 Control the number of worker threads that may be used by @value{GDBN}.
40228 On capable hosts, @value{GDBN} may use multiple threads to speed up
40229 certain CPU-intensive operations, such as demangling symbol names.
40230 While the number of threads used by @value{GDBN} may vary, this
40231 command can be used to set an upper bound on this number. The default
40232 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
40233 number. Note that this only controls worker threads started by
40234 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
40235 of their own.
40236
40237 @kindex maint set profile
40238 @kindex maint show profile
40239 @cindex profiling GDB
40240 @item maint set profile
40241 @itemx maint show profile
40242 Control profiling of @value{GDBN}.
40243
40244 Profiling will be disabled until you use the @samp{maint set profile}
40245 command to enable it. When you enable profiling, the system will begin
40246 collecting timing and execution count data; when you disable profiling or
40247 exit @value{GDBN}, the results will be written to a log file. Remember that
40248 if you use profiling, @value{GDBN} will overwrite the profiling log file
40249 (often called @file{gmon.out}). If you have a record of important profiling
40250 data in a @file{gmon.out} file, be sure to move it to a safe location.
40251
40252 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
40253 compiled with the @samp{-pg} compiler option.
40254
40255 @kindex maint set show-debug-regs
40256 @kindex maint show show-debug-regs
40257 @cindex hardware debug registers
40258 @item maint set show-debug-regs
40259 @itemx maint show show-debug-regs
40260 Control whether to show variables that mirror the hardware debug
40261 registers. Use @code{on} to enable, @code{off} to disable. If
40262 enabled, the debug registers values are shown when @value{GDBN} inserts or
40263 removes a hardware breakpoint or watchpoint, and when the inferior
40264 triggers a hardware-assisted breakpoint or watchpoint.
40265
40266 @kindex maint set show-all-tib
40267 @kindex maint show show-all-tib
40268 @item maint set show-all-tib
40269 @itemx maint show show-all-tib
40270 Control whether to show all non zero areas within a 1k block starting
40271 at thread local base, when using the @samp{info w32 thread-information-block}
40272 command.
40273
40274 @kindex maint set target-async
40275 @kindex maint show target-async
40276 @item maint set target-async
40277 @itemx maint show target-async
40278 This controls whether @value{GDBN} targets operate in synchronous or
40279 asynchronous mode (@pxref{Background Execution}). Normally the
40280 default is asynchronous, if it is available; but this can be changed
40281 to more easily debug problems occurring only in synchronous mode.
40282
40283 @kindex maint set target-non-stop @var{mode} [on|off|auto]
40284 @kindex maint show target-non-stop
40285 @item maint set target-non-stop
40286 @itemx maint show target-non-stop
40287
40288 This controls whether @value{GDBN} targets always operate in non-stop
40289 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
40290 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
40291 if supported by the target.
40292
40293 @table @code
40294 @item maint set target-non-stop auto
40295 This is the default mode. @value{GDBN} controls the target in
40296 non-stop mode if the target supports it.
40297
40298 @item maint set target-non-stop on
40299 @value{GDBN} controls the target in non-stop mode even if the target
40300 does not indicate support.
40301
40302 @item maint set target-non-stop off
40303 @value{GDBN} does not control the target in non-stop mode even if the
40304 target supports it.
40305 @end table
40306
40307 @kindex maint set tui-resize-message
40308 @kindex maint show tui-resize-message
40309 @item maint set tui-resize-message
40310 @item maint show tui-resize-message
40311 Control whether @value{GDBN} displays a message each time the terminal
40312 is resized when in TUI mode. The default is @code{off}, which means
40313 that @value{GDBN} is silent during resizes. When @code{on},
40314 @value{GDBN} will display a message after a resize is completed; the
40315 message will include a number indicating how many times the terminal
40316 has been resized. This setting is intended for use by the test suite,
40317 where it would otherwise be difficult to determine when a resize and
40318 refresh has been completed.
40319
40320 @kindex maint set per-command
40321 @kindex maint show per-command
40322 @item maint set per-command
40323 @itemx maint show per-command
40324 @cindex resources used by commands
40325
40326 @value{GDBN} can display the resources used by each command.
40327 This is useful in debugging performance problems.
40328
40329 @table @code
40330 @item maint set per-command space [on|off]
40331 @itemx maint show per-command space
40332 Enable or disable the printing of the memory used by GDB for each command.
40333 If enabled, @value{GDBN} will display how much memory each command
40334 took, following the command's own output.
40335 This can also be requested by invoking @value{GDBN} with the
40336 @option{--statistics} command-line switch (@pxref{Mode Options}).
40337
40338 @item maint set per-command time [on|off]
40339 @itemx maint show per-command time
40340 Enable or disable the printing of the execution time of @value{GDBN}
40341 for each command.
40342 If enabled, @value{GDBN} will display how much time it
40343 took to execute each command, following the command's own output.
40344 Both CPU time and wallclock time are printed.
40345 Printing both is useful when trying to determine whether the cost is
40346 CPU or, e.g., disk/network latency.
40347 Note that the CPU time printed is for @value{GDBN} only, it does not include
40348 the execution time of the inferior because there's no mechanism currently
40349 to compute how much time was spent by @value{GDBN} and how much time was
40350 spent by the program been debugged.
40351 This can also be requested by invoking @value{GDBN} with the
40352 @option{--statistics} command-line switch (@pxref{Mode Options}).
40353
40354 @item maint set per-command symtab [on|off]
40355 @itemx maint show per-command symtab
40356 Enable or disable the printing of basic symbol table statistics
40357 for each command.
40358 If enabled, @value{GDBN} will display the following information:
40359
40360 @enumerate a
40361 @item
40362 number of symbol tables
40363 @item
40364 number of primary symbol tables
40365 @item
40366 number of blocks in the blockvector
40367 @end enumerate
40368 @end table
40369
40370 @kindex maint set check-libthread-db
40371 @kindex maint show check-libthread-db
40372 @item maint set check-libthread-db [on|off]
40373 @itemx maint show check-libthread-db
40374 Control whether @value{GDBN} should run integrity checks on inferior
40375 specific thread debugging libraries as they are loaded. The default
40376 is not to perform such checks. If any check fails @value{GDBN} will
40377 unload the library and continue searching for a suitable candidate as
40378 described in @ref{set libthread-db-search-path}. For more information
40379 about the tests, see @ref{maint check libthread-db}.
40380
40381 @kindex maint set gnu-source-highlight enabled
40382 @kindex maint show gnu-source-highlight enabled
40383 @item maint set gnu-source-highlight enabled @r{[}on|off@r{]}
40384 @itemx maint show gnu-source-highlight enabled
40385 Control whether @value{GDBN} should use the GNU Source Highlight
40386 library for applying styling to source code (@pxref{Output Styling}).
40387 This will be @samp{on} by default if the GNU Source Highlight library
40388 is available. If the GNU Source Highlight library is not available,
40389 then this will be @samp{off} by default, and attempting to change this
40390 value to @samp{on} will give an error.
40391
40392 If the GNU Source Highlight library is not being used, then
40393 @value{GDBN} will use the Python Pygments package for source code
40394 styling, if it is available.
40395
40396 This option is useful for debugging @value{GDBN}'s use of the Pygments
40397 library when @value{GDBN} is linked against the GNU Source Highlight
40398 library.
40399
40400 @kindex maint space
40401 @cindex memory used by commands
40402 @item maint space @var{value}
40403 An alias for @code{maint set per-command space}.
40404 A non-zero value enables it, zero disables it.
40405
40406 @kindex maint time
40407 @cindex time of command execution
40408 @item maint time @var{value}
40409 An alias for @code{maint set per-command time}.
40410 A non-zero value enables it, zero disables it.
40411
40412 @kindex maint translate-address
40413 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
40414 Find the symbol stored at the location specified by the address
40415 @var{addr} and an optional section name @var{section}. If found,
40416 @value{GDBN} prints the name of the closest symbol and an offset from
40417 the symbol's location to the specified address. This is similar to
40418 the @code{info address} command (@pxref{Symbols}), except that this
40419 command also allows to find symbols in other sections.
40420
40421 If section was not specified, the section in which the symbol was found
40422 is also printed. For dynamically linked executables, the name of
40423 executable or shared library containing the symbol is printed as well.
40424
40425 @kindex maint test-options
40426 @item maint test-options require-delimiter
40427 @itemx maint test-options unknown-is-error
40428 @itemx maint test-options unknown-is-operand
40429 These commands are used by the testsuite to validate the command
40430 options framework. The @code{require-delimiter} variant requires a
40431 double-dash delimiter to indicate end of options. The
40432 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
40433 @code{unknown-is-error} variant throws an error on unknown option,
40434 while @code{unknown-is-operand} treats unknown options as the start of
40435 the command's operands. When run, the commands output the result of
40436 the processed options. When completed, the commands store the
40437 internal result of completion in a variable exposed by the @code{maint
40438 show test-options-completion-result} command.
40439
40440 @kindex maint show test-options-completion-result
40441 @item maint show test-options-completion-result
40442 Shows the result of completing the @code{maint test-options}
40443 subcommands. This is used by the testsuite to validate completion
40444 support in the command options framework.
40445
40446 @kindex maint set test-settings
40447 @kindex maint show test-settings
40448 @item maint set test-settings @var{kind}
40449 @itemx maint show test-settings @var{kind}
40450 These are representative commands for each @var{kind} of setting type
40451 @value{GDBN} supports. They are used by the testsuite for exercising
40452 the settings infrastructure.
40453
40454 @kindex maint set backtrace-on-fatal-signal
40455 @kindex maint show backtrace-on-fatal-signal
40456 @item maint set backtrace-on-fatal-signal [on|off]
40457 @itemx maint show backtrace-on-fatal-signal
40458 When this setting is @code{on}, if @value{GDBN} itself terminates with
40459 a fatal signal (e.g.@: SIGSEGV), then a limited backtrace will be
40460 printed to the standard error stream. This backtrace can be used to
40461 help diagnose crashes within @value{GDBN} in situations where a user
40462 is unable to share a corefile with the @value{GDBN} developers.
40463
40464 If the functionality to provide this backtrace is not available for
40465 the platform on which GDB is running then this feature will be
40466 @code{off} by default, and attempting to turn this feature on will
40467 give an error.
40468
40469 For platforms that do support creating the backtrace this feature is
40470 @code{on} by default.
40471
40472 @kindex maint with
40473 @item maint with @var{setting} [@var{value}] [-- @var{command}]
40474 Like the @code{with} command, but works with @code{maintenance set}
40475 variables. This is used by the testsuite to exercise the @code{with}
40476 command's infrastructure.
40477
40478 @end table
40479
40480 The following command is useful for non-interactive invocations of
40481 @value{GDBN}, such as in the test suite.
40482
40483 @table @code
40484 @item set watchdog @var{nsec}
40485 @kindex set watchdog
40486 @cindex watchdog timer
40487 @cindex timeout for commands
40488 Set the maximum number of seconds @value{GDBN} will wait for the
40489 target operation to finish. If this time expires, @value{GDBN}
40490 reports and error and the command is aborted.
40491
40492 @item show watchdog
40493 Show the current setting of the target wait timeout.
40494 @end table
40495
40496 @node Remote Protocol
40497 @appendix @value{GDBN} Remote Serial Protocol
40498
40499 @menu
40500 * Overview::
40501 * Packets::
40502 * Stop Reply Packets::
40503 * General Query Packets::
40504 * Architecture-Specific Protocol Details::
40505 * Tracepoint Packets::
40506 * Host I/O Packets::
40507 * Interrupts::
40508 * Notification Packets::
40509 * Remote Non-Stop::
40510 * Packet Acknowledgment::
40511 * Examples::
40512 * File-I/O Remote Protocol Extension::
40513 * Library List Format::
40514 * Library List Format for SVR4 Targets::
40515 * Memory Map Format::
40516 * Thread List Format::
40517 * Traceframe Info Format::
40518 * Branch Trace Format::
40519 * Branch Trace Configuration Format::
40520 @end menu
40521
40522 @node Overview
40523 @section Overview
40524
40525 There may be occasions when you need to know something about the
40526 protocol---for example, if there is only one serial port to your target
40527 machine, you might want your program to do something special if it
40528 recognizes a packet meant for @value{GDBN}.
40529
40530 In the examples below, @samp{->} and @samp{<-} are used to indicate
40531 transmitted and received data, respectively.
40532
40533 @cindex protocol, @value{GDBN} remote serial
40534 @cindex serial protocol, @value{GDBN} remote
40535 @cindex remote serial protocol
40536 All @value{GDBN} commands and responses (other than acknowledgments
40537 and notifications, see @ref{Notification Packets}) are sent as a
40538 @var{packet}. A @var{packet} is introduced with the character
40539 @samp{$}, the actual @var{packet-data}, and the terminating character
40540 @samp{#} followed by a two-digit @var{checksum}:
40541
40542 @smallexample
40543 @code{$}@var{packet-data}@code{#}@var{checksum}
40544 @end smallexample
40545 @noindent
40546
40547 @cindex checksum, for @value{GDBN} remote
40548 @noindent
40549 The two-digit @var{checksum} is computed as the modulo 256 sum of all
40550 characters between the leading @samp{$} and the trailing @samp{#} (an
40551 eight bit unsigned checksum).
40552
40553 Implementors should note that prior to @value{GDBN} 5.0 the protocol
40554 specification also included an optional two-digit @var{sequence-id}:
40555
40556 @smallexample
40557 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
40558 @end smallexample
40559
40560 @cindex sequence-id, for @value{GDBN} remote
40561 @noindent
40562 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
40563 has never output @var{sequence-id}s. Stubs that handle packets added
40564 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
40565
40566 When either the host or the target machine receives a packet, the first
40567 response expected is an acknowledgment: either @samp{+} (to indicate
40568 the package was received correctly) or @samp{-} (to request
40569 retransmission):
40570
40571 @smallexample
40572 -> @code{$}@var{packet-data}@code{#}@var{checksum}
40573 <- @code{+}
40574 @end smallexample
40575 @noindent
40576
40577 The @samp{+}/@samp{-} acknowledgments can be disabled
40578 once a connection is established.
40579 @xref{Packet Acknowledgment}, for details.
40580
40581 The host (@value{GDBN}) sends @var{command}s, and the target (the
40582 debugging stub incorporated in your program) sends a @var{response}. In
40583 the case of step and continue @var{command}s, the response is only sent
40584 when the operation has completed, and the target has again stopped all
40585 threads in all attached processes. This is the default all-stop mode
40586 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
40587 execution mode; see @ref{Remote Non-Stop}, for details.
40588
40589 @var{packet-data} consists of a sequence of characters with the
40590 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
40591 exceptions).
40592
40593 @cindex remote protocol, field separator
40594 Fields within the packet should be separated using @samp{,} @samp{;} or
40595 @samp{:}. Except where otherwise noted all numbers are represented in
40596 @sc{hex} with leading zeros suppressed.
40597
40598 Implementors should note that prior to @value{GDBN} 5.0, the character
40599 @samp{:} could not appear as the third character in a packet (as it
40600 would potentially conflict with the @var{sequence-id}).
40601
40602 @cindex remote protocol, binary data
40603 @anchor{Binary Data}
40604 Binary data in most packets is encoded either as two hexadecimal
40605 digits per byte of binary data. This allowed the traditional remote
40606 protocol to work over connections which were only seven-bit clean.
40607 Some packets designed more recently assume an eight-bit clean
40608 connection, and use a more efficient encoding to send and receive
40609 binary data.
40610
40611 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
40612 as an escape character. Any escaped byte is transmitted as the escape
40613 character followed by the original character XORed with @code{0x20}.
40614 For example, the byte @code{0x7d} would be transmitted as the two
40615 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
40616 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
40617 @samp{@}}) must always be escaped. Responses sent by the stub
40618 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
40619 is not interpreted as the start of a run-length encoded sequence
40620 (described next).
40621
40622 Response @var{data} can be run-length encoded to save space.
40623 Run-length encoding replaces runs of identical characters with one
40624 instance of the repeated character, followed by a @samp{*} and a
40625 repeat count. The repeat count is itself sent encoded, to avoid
40626 binary characters in @var{data}: a value of @var{n} is sent as
40627 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
40628 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
40629 code 32) for a repeat count of 3. (This is because run-length
40630 encoding starts to win for counts 3 or more.) Thus, for example,
40631 @samp{0* } is a run-length encoding of ``0000'': the space character
40632 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
40633 3}} more times.
40634
40635 The printable characters @samp{#} and @samp{$} or with a numeric value
40636 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
40637 seven repeats (@samp{$}) can be expanded using a repeat count of only
40638 five (@samp{"}). For example, @samp{00000000} can be encoded as
40639 @samp{0*"00}.
40640
40641 The error response returned for some packets includes a two character
40642 error number. That number is not well defined.
40643
40644 @cindex empty response, for unsupported packets
40645 For any @var{command} not supported by the stub, an empty response
40646 (@samp{$#00}) should be returned. That way it is possible to extend the
40647 protocol. A newer @value{GDBN} can tell if a packet is supported based
40648 on that response.
40649
40650 At a minimum, a stub is required to support the @samp{?} command to
40651 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
40652 commands for register access, and the @samp{m} and @samp{M} commands
40653 for memory access. Stubs that only control single-threaded targets
40654 can implement run control with the @samp{c} (continue) command, and if
40655 the target architecture supports hardware-assisted single-stepping,
40656 the @samp{s} (step) command. Stubs that support multi-threading
40657 targets should support the @samp{vCont} command. All other commands
40658 are optional.
40659
40660 @node Packets
40661 @section Packets
40662
40663 The following table provides a complete list of all currently defined
40664 @var{command}s and their corresponding response @var{data}.
40665 @xref{File-I/O Remote Protocol Extension}, for details about the File
40666 I/O extension of the remote protocol.
40667
40668 Each packet's description has a template showing the packet's overall
40669 syntax, followed by an explanation of the packet's meaning. We
40670 include spaces in some of the templates for clarity; these are not
40671 part of the packet's syntax. No @value{GDBN} packet uses spaces to
40672 separate its components. For example, a template like @samp{foo
40673 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
40674 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
40675 @var{baz}. @value{GDBN} does not transmit a space character between the
40676 @samp{foo} and the @var{bar}, or between the @var{bar} and the
40677 @var{baz}.
40678
40679 @cindex @var{thread-id}, in remote protocol
40680 @anchor{thread-id syntax}
40681 Several packets and replies include a @var{thread-id} field to identify
40682 a thread. Normally these are positive numbers with a target-specific
40683 interpretation, formatted as big-endian hex strings. A @var{thread-id}
40684 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
40685 pick any thread.
40686
40687 In addition, the remote protocol supports a multiprocess feature in
40688 which the @var{thread-id} syntax is extended to optionally include both
40689 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
40690 The @var{pid} (process) and @var{tid} (thread) components each have the
40691 format described above: a positive number with target-specific
40692 interpretation formatted as a big-endian hex string, literal @samp{-1}
40693 to indicate all processes or threads (respectively), or @samp{0} to
40694 indicate an arbitrary process or thread. Specifying just a process, as
40695 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
40696 error to specify all processes but a specific thread, such as
40697 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
40698 for those packets and replies explicitly documented to include a process
40699 ID, rather than a @var{thread-id}.
40700
40701 The multiprocess @var{thread-id} syntax extensions are only used if both
40702 @value{GDBN} and the stub report support for the @samp{multiprocess}
40703 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
40704 more information.
40705
40706 Note that all packet forms beginning with an upper- or lower-case
40707 letter, other than those described here, are reserved for future use.
40708
40709 Here are the packet descriptions.
40710
40711 @table @samp
40712
40713 @item !
40714 @cindex @samp{!} packet
40715 @anchor{extended mode}
40716 Enable extended mode. In extended mode, the remote server is made
40717 persistent. The @samp{R} packet is used to restart the program being
40718 debugged.
40719
40720 Reply:
40721 @table @samp
40722 @item OK
40723 The remote target both supports and has enabled extended mode.
40724 @end table
40725
40726 @item ?
40727 @cindex @samp{?} packet
40728 @anchor{? packet}
40729 This is sent when connection is first established to query the reason
40730 the target halted. The reply is the same as for step and continue.
40731 This packet has a special interpretation when the target is in
40732 non-stop mode; see @ref{Remote Non-Stop}.
40733
40734 Reply:
40735 @xref{Stop Reply Packets}, for the reply specifications.
40736
40737 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
40738 @cindex @samp{A} packet
40739 Initialized @code{argv[]} array passed into program. @var{arglen}
40740 specifies the number of bytes in the hex encoded byte stream
40741 @var{arg}. See @code{gdbserver} for more details.
40742
40743 Reply:
40744 @table @samp
40745 @item OK
40746 The arguments were set.
40747 @item E @var{NN}
40748 An error occurred.
40749 @end table
40750
40751 @item b @var{baud}
40752 @cindex @samp{b} packet
40753 (Don't use this packet; its behavior is not well-defined.)
40754 Change the serial line speed to @var{baud}.
40755
40756 JTC: @emph{When does the transport layer state change? When it's
40757 received, or after the ACK is transmitted. In either case, there are
40758 problems if the command or the acknowledgment packet is dropped.}
40759
40760 Stan: @emph{If people really wanted to add something like this, and get
40761 it working for the first time, they ought to modify ser-unix.c to send
40762 some kind of out-of-band message to a specially-setup stub and have the
40763 switch happen "in between" packets, so that from remote protocol's point
40764 of view, nothing actually happened.}
40765
40766 @item B @var{addr},@var{mode}
40767 @cindex @samp{B} packet
40768 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
40769 breakpoint at @var{addr}.
40770
40771 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
40772 (@pxref{insert breakpoint or watchpoint packet}).
40773
40774 @cindex @samp{bc} packet
40775 @anchor{bc}
40776 @item bc
40777 Backward continue. Execute the target system in reverse. No parameter.
40778 @xref{Reverse Execution}, for more information.
40779
40780 Reply:
40781 @xref{Stop Reply Packets}, for the reply specifications.
40782
40783 @cindex @samp{bs} packet
40784 @anchor{bs}
40785 @item bs
40786 Backward single step. Execute one instruction in reverse. No parameter.
40787 @xref{Reverse Execution}, for more information.
40788
40789 Reply:
40790 @xref{Stop Reply Packets}, for the reply specifications.
40791
40792 @item c @r{[}@var{addr}@r{]}
40793 @cindex @samp{c} packet
40794 Continue at @var{addr}, which is the address to resume. If @var{addr}
40795 is omitted, resume at current address.
40796
40797 This packet is deprecated for multi-threading support. @xref{vCont
40798 packet}.
40799
40800 Reply:
40801 @xref{Stop Reply Packets}, for the reply specifications.
40802
40803 @item C @var{sig}@r{[};@var{addr}@r{]}
40804 @cindex @samp{C} packet
40805 Continue with signal @var{sig} (hex signal number). If
40806 @samp{;@var{addr}} is omitted, resume at same address.
40807
40808 This packet is deprecated for multi-threading support. @xref{vCont
40809 packet}.
40810
40811 Reply:
40812 @xref{Stop Reply Packets}, for the reply specifications.
40813
40814 @item d
40815 @cindex @samp{d} packet
40816 Toggle debug flag.
40817
40818 Don't use this packet; instead, define a general set packet
40819 (@pxref{General Query Packets}).
40820
40821 @item D
40822 @itemx D;@var{pid}
40823 @cindex @samp{D} packet
40824 The first form of the packet is used to detach @value{GDBN} from the
40825 remote system. It is sent to the remote target
40826 before @value{GDBN} disconnects via the @code{detach} command.
40827
40828 The second form, including a process ID, is used when multiprocess
40829 protocol extensions are enabled (@pxref{multiprocess extensions}), to
40830 detach only a specific process. The @var{pid} is specified as a
40831 big-endian hex string.
40832
40833 Reply:
40834 @table @samp
40835 @item OK
40836 for success
40837 @item E @var{NN}
40838 for an error
40839 @end table
40840
40841 @item F @var{RC},@var{EE},@var{CF};@var{XX}
40842 @cindex @samp{F} packet
40843 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
40844 This is part of the File-I/O protocol extension. @xref{File-I/O
40845 Remote Protocol Extension}, for the specification.
40846
40847 @item g
40848 @anchor{read registers packet}
40849 @cindex @samp{g} packet
40850 Read general registers.
40851
40852 Reply:
40853 @table @samp
40854 @item @var{XX@dots{}}
40855 Each byte of register data is described by two hex digits. The bytes
40856 with the register are transmitted in target byte order. The size of
40857 each register and their position within the @samp{g} packet are
40858 determined by the @value{GDBN} internal gdbarch functions
40859 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
40860
40861 When reading registers from a trace frame (@pxref{Analyze Collected
40862 Data,,Using the Collected Data}), the stub may also return a string of
40863 literal @samp{x}'s in place of the register data digits, to indicate
40864 that the corresponding register has not been collected, thus its value
40865 is unavailable. For example, for an architecture with 4 registers of
40866 4 bytes each, the following reply indicates to @value{GDBN} that
40867 registers 0 and 2 have not been collected, while registers 1 and 3
40868 have been collected, and both have zero value:
40869
40870 @smallexample
40871 -> @code{g}
40872 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
40873 @end smallexample
40874
40875 @item E @var{NN}
40876 for an error.
40877 @end table
40878
40879 @item G @var{XX@dots{}}
40880 @cindex @samp{G} packet
40881 Write general registers. @xref{read registers packet}, for a
40882 description of the @var{XX@dots{}} data.
40883
40884 Reply:
40885 @table @samp
40886 @item OK
40887 for success
40888 @item E @var{NN}
40889 for an error
40890 @end table
40891
40892 @item H @var{op} @var{thread-id}
40893 @cindex @samp{H} packet
40894 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
40895 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
40896 should be @samp{c} for step and continue operations (note that this
40897 is deprecated, supporting the @samp{vCont} command is a better
40898 option), and @samp{g} for other operations. The thread designator
40899 @var{thread-id} has the format and interpretation described in
40900 @ref{thread-id syntax}.
40901
40902 Reply:
40903 @table @samp
40904 @item OK
40905 for success
40906 @item E @var{NN}
40907 for an error
40908 @end table
40909
40910 @c FIXME: JTC:
40911 @c 'H': How restrictive (or permissive) is the thread model. If a
40912 @c thread is selected and stopped, are other threads allowed
40913 @c to continue to execute? As I mentioned above, I think the
40914 @c semantics of each command when a thread is selected must be
40915 @c described. For example:
40916 @c
40917 @c 'g': If the stub supports threads and a specific thread is
40918 @c selected, returns the register block from that thread;
40919 @c otherwise returns current registers.
40920 @c
40921 @c 'G' If the stub supports threads and a specific thread is
40922 @c selected, sets the registers of the register block of
40923 @c that thread; otherwise sets current registers.
40924
40925 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
40926 @anchor{cycle step packet}
40927 @cindex @samp{i} packet
40928 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
40929 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
40930 step starting at that address.
40931
40932 @item I
40933 @cindex @samp{I} packet
40934 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
40935 step packet}.
40936
40937 @item k
40938 @cindex @samp{k} packet
40939 Kill request.
40940
40941 The exact effect of this packet is not specified.
40942
40943 For a bare-metal target, it may power cycle or reset the target
40944 system. For that reason, the @samp{k} packet has no reply.
40945
40946 For a single-process target, it may kill that process if possible.
40947
40948 A multiple-process target may choose to kill just one process, or all
40949 that are under @value{GDBN}'s control. For more precise control, use
40950 the vKill packet (@pxref{vKill packet}).
40951
40952 If the target system immediately closes the connection in response to
40953 @samp{k}, @value{GDBN} does not consider the lack of packet
40954 acknowledgment to be an error, and assumes the kill was successful.
40955
40956 If connected using @kbd{target extended-remote}, and the target does
40957 not close the connection in response to a kill request, @value{GDBN}
40958 probes the target state as if a new connection was opened
40959 (@pxref{? packet}).
40960
40961 @item m @var{addr},@var{length}
40962 @cindex @samp{m} packet
40963 Read @var{length} addressable memory units starting at address @var{addr}
40964 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
40965 any particular boundary.
40966
40967 The stub need not use any particular size or alignment when gathering
40968 data from memory for the response; even if @var{addr} is word-aligned
40969 and @var{length} is a multiple of the word size, the stub is free to
40970 use byte accesses, or not. For this reason, this packet may not be
40971 suitable for accessing memory-mapped I/O devices.
40972 @cindex alignment of remote memory accesses
40973 @cindex size of remote memory accesses
40974 @cindex memory, alignment and size of remote accesses
40975
40976 Reply:
40977 @table @samp
40978 @item @var{XX@dots{}}
40979 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
40980 The reply may contain fewer addressable memory units than requested if the
40981 server was able to read only part of the region of memory.
40982 @item E @var{NN}
40983 @var{NN} is errno
40984 @end table
40985
40986 @item M @var{addr},@var{length}:@var{XX@dots{}}
40987 @cindex @samp{M} packet
40988 Write @var{length} addressable memory units starting at address @var{addr}
40989 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
40990 byte is transmitted as a two-digit hexadecimal number.
40991
40992 Reply:
40993 @table @samp
40994 @item OK
40995 for success
40996 @item E @var{NN}
40997 for an error (this includes the case where only part of the data was
40998 written).
40999 @end table
41000
41001 @item p @var{n}
41002 @cindex @samp{p} packet
41003 Read the value of register @var{n}; @var{n} is in hex.
41004 @xref{read registers packet}, for a description of how the returned
41005 register value is encoded.
41006
41007 Reply:
41008 @table @samp
41009 @item @var{XX@dots{}}
41010 the register's value
41011 @item E @var{NN}
41012 for an error
41013 @item @w{}
41014 Indicating an unrecognized @var{query}.
41015 @end table
41016
41017 @item P @var{n@dots{}}=@var{r@dots{}}
41018 @anchor{write register packet}
41019 @cindex @samp{P} packet
41020 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
41021 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
41022 digits for each byte in the register (target byte order).
41023
41024 Reply:
41025 @table @samp
41026 @item OK
41027 for success
41028 @item E @var{NN}
41029 for an error
41030 @end table
41031
41032 @item q @var{name} @var{params}@dots{}
41033 @itemx Q @var{name} @var{params}@dots{}
41034 @cindex @samp{q} packet
41035 @cindex @samp{Q} packet
41036 General query (@samp{q}) and set (@samp{Q}). These packets are
41037 described fully in @ref{General Query Packets}.
41038
41039 @item r
41040 @cindex @samp{r} packet
41041 Reset the entire system.
41042
41043 Don't use this packet; use the @samp{R} packet instead.
41044
41045 @item R @var{XX}
41046 @cindex @samp{R} packet
41047 Restart the program being debugged. The @var{XX}, while needed, is ignored.
41048 This packet is only available in extended mode (@pxref{extended mode}).
41049
41050 The @samp{R} packet has no reply.
41051
41052 @item s @r{[}@var{addr}@r{]}
41053 @cindex @samp{s} packet
41054 Single step, resuming at @var{addr}. If
41055 @var{addr} is omitted, resume at same address.
41056
41057 This packet is deprecated for multi-threading support. @xref{vCont
41058 packet}.
41059
41060 Reply:
41061 @xref{Stop Reply Packets}, for the reply specifications.
41062
41063 @item S @var{sig}@r{[};@var{addr}@r{]}
41064 @anchor{step with signal packet}
41065 @cindex @samp{S} packet
41066 Step with signal. This is analogous to the @samp{C} packet, but
41067 requests a single-step, rather than a normal resumption of execution.
41068
41069 This packet is deprecated for multi-threading support. @xref{vCont
41070 packet}.
41071
41072 Reply:
41073 @xref{Stop Reply Packets}, for the reply specifications.
41074
41075 @item t @var{addr}:@var{PP},@var{MM}
41076 @cindex @samp{t} packet
41077 Search backwards starting at address @var{addr} for a match with pattern
41078 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
41079 There must be at least 3 digits in @var{addr}.
41080
41081 @item T @var{thread-id}
41082 @cindex @samp{T} packet
41083 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
41084
41085 Reply:
41086 @table @samp
41087 @item OK
41088 thread is still alive
41089 @item E @var{NN}
41090 thread is dead
41091 @end table
41092
41093 @item v
41094 Packets starting with @samp{v} are identified by a multi-letter name,
41095 up to the first @samp{;} or @samp{?} (or the end of the packet).
41096
41097 @item vAttach;@var{pid}
41098 @cindex @samp{vAttach} packet
41099 Attach to a new process with the specified process ID @var{pid}.
41100 The process ID is a
41101 hexadecimal integer identifying the process. In all-stop mode, all
41102 threads in the attached process are stopped; in non-stop mode, it may be
41103 attached without being stopped if that is supported by the target.
41104
41105 @c In non-stop mode, on a successful vAttach, the stub should set the
41106 @c current thread to a thread of the newly-attached process. After
41107 @c attaching, GDB queries for the attached process's thread ID with qC.
41108 @c Also note that, from a user perspective, whether or not the
41109 @c target is stopped on attach in non-stop mode depends on whether you
41110 @c use the foreground or background version of the attach command, not
41111 @c on what vAttach does; GDB does the right thing with respect to either
41112 @c stopping or restarting threads.
41113
41114 This packet is only available in extended mode (@pxref{extended mode}).
41115
41116 Reply:
41117 @table @samp
41118 @item E @var{nn}
41119 for an error
41120 @item @r{Any stop packet}
41121 for success in all-stop mode (@pxref{Stop Reply Packets})
41122 @item OK
41123 for success in non-stop mode (@pxref{Remote Non-Stop})
41124 @end table
41125
41126 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
41127 @cindex @samp{vCont} packet
41128 @anchor{vCont packet}
41129 Resume the inferior, specifying different actions for each thread.
41130
41131 For each inferior thread, the leftmost action with a matching
41132 @var{thread-id} is applied. Threads that don't match any action
41133 remain in their current state. Thread IDs are specified using the
41134 syntax described in @ref{thread-id syntax}. If multiprocess
41135 extensions (@pxref{multiprocess extensions}) are supported, actions
41136 can be specified to match all threads in a process by using the
41137 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
41138 @var{thread-id} matches all threads. Specifying no actions is an
41139 error.
41140
41141 Currently supported actions are:
41142
41143 @table @samp
41144 @item c
41145 Continue.
41146 @item C @var{sig}
41147 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
41148 @item s
41149 Step.
41150 @item S @var{sig}
41151 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
41152 @item t
41153 Stop.
41154 @item r @var{start},@var{end}
41155 Step once, and then keep stepping as long as the thread stops at
41156 addresses between @var{start} (inclusive) and @var{end} (exclusive).
41157 The remote stub reports a stop reply when either the thread goes out
41158 of the range or is stopped due to an unrelated reason, such as hitting
41159 a breakpoint. @xref{range stepping}.
41160
41161 If the range is empty (@var{start} == @var{end}), then the action
41162 becomes equivalent to the @samp{s} action. In other words,
41163 single-step once, and report the stop (even if the stepped instruction
41164 jumps to @var{start}).
41165
41166 (A stop reply may be sent at any point even if the PC is still within
41167 the stepping range; for example, it is valid to implement this packet
41168 in a degenerate way as a single instruction step operation.)
41169
41170 @end table
41171
41172 The optional argument @var{addr} normally associated with the
41173 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
41174 not supported in @samp{vCont}.
41175
41176 The @samp{t} action is only relevant in non-stop mode
41177 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
41178 A stop reply should be generated for any affected thread not already stopped.
41179 When a thread is stopped by means of a @samp{t} action,
41180 the corresponding stop reply should indicate that the thread has stopped with
41181 signal @samp{0}, regardless of whether the target uses some other signal
41182 as an implementation detail.
41183
41184 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
41185 @samp{r} actions for threads that are already running. Conversely,
41186 the server must ignore @samp{t} actions for threads that are already
41187 stopped.
41188
41189 @emph{Note:} In non-stop mode, a thread is considered running until
41190 @value{GDBN} acknowledges an asynchronous stop notification for it with
41191 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
41192
41193 The stub must support @samp{vCont} if it reports support for
41194 multiprocess extensions (@pxref{multiprocess extensions}).
41195
41196 Reply:
41197 @xref{Stop Reply Packets}, for the reply specifications.
41198
41199 @item vCont?
41200 @cindex @samp{vCont?} packet
41201 Request a list of actions supported by the @samp{vCont} packet.
41202
41203 Reply:
41204 @table @samp
41205 @item vCont@r{[};@var{action}@dots{}@r{]}
41206 The @samp{vCont} packet is supported. Each @var{action} is a supported
41207 command in the @samp{vCont} packet.
41208 @item @w{}
41209 The @samp{vCont} packet is not supported.
41210 @end table
41211
41212 @anchor{vCtrlC packet}
41213 @item vCtrlC
41214 @cindex @samp{vCtrlC} packet
41215 Interrupt remote target as if a control-C was pressed on the remote
41216 terminal. This is the equivalent to reacting to the @code{^C}
41217 (@samp{\003}, the control-C character) character in all-stop mode
41218 while the target is running, except this works in non-stop mode.
41219 @xref{interrupting remote targets}, for more info on the all-stop
41220 variant.
41221
41222 Reply:
41223 @table @samp
41224 @item E @var{nn}
41225 for an error
41226 @item OK
41227 for success
41228 @end table
41229
41230 @item vFile:@var{operation}:@var{parameter}@dots{}
41231 @cindex @samp{vFile} packet
41232 Perform a file operation on the target system. For details,
41233 see @ref{Host I/O Packets}.
41234
41235 @item vFlashErase:@var{addr},@var{length}
41236 @cindex @samp{vFlashErase} packet
41237 Direct the stub to erase @var{length} bytes of flash starting at
41238 @var{addr}. The region may enclose any number of flash blocks, but
41239 its start and end must fall on block boundaries, as indicated by the
41240 flash block size appearing in the memory map (@pxref{Memory Map
41241 Format}). @value{GDBN} groups flash memory programming operations
41242 together, and sends a @samp{vFlashDone} request after each group; the
41243 stub is allowed to delay erase operation until the @samp{vFlashDone}
41244 packet is received.
41245
41246 Reply:
41247 @table @samp
41248 @item OK
41249 for success
41250 @item E @var{NN}
41251 for an error
41252 @end table
41253
41254 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
41255 @cindex @samp{vFlashWrite} packet
41256 Direct the stub to write data to flash address @var{addr}. The data
41257 is passed in binary form using the same encoding as for the @samp{X}
41258 packet (@pxref{Binary Data}). The memory ranges specified by
41259 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
41260 not overlap, and must appear in order of increasing addresses
41261 (although @samp{vFlashErase} packets for higher addresses may already
41262 have been received; the ordering is guaranteed only between
41263 @samp{vFlashWrite} packets). If a packet writes to an address that was
41264 neither erased by a preceding @samp{vFlashErase} packet nor by some other
41265 target-specific method, the results are unpredictable.
41266
41267
41268 Reply:
41269 @table @samp
41270 @item OK
41271 for success
41272 @item E.memtype
41273 for vFlashWrite addressing non-flash memory
41274 @item E @var{NN}
41275 for an error
41276 @end table
41277
41278 @item vFlashDone
41279 @cindex @samp{vFlashDone} packet
41280 Indicate to the stub that flash programming operation is finished.
41281 The stub is permitted to delay or batch the effects of a group of
41282 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
41283 @samp{vFlashDone} packet is received. The contents of the affected
41284 regions of flash memory are unpredictable until the @samp{vFlashDone}
41285 request is completed.
41286
41287 @item vKill;@var{pid}
41288 @cindex @samp{vKill} packet
41289 @anchor{vKill packet}
41290 Kill the process with the specified process ID @var{pid}, which is a
41291 hexadecimal integer identifying the process. This packet is used in
41292 preference to @samp{k} when multiprocess protocol extensions are
41293 supported; see @ref{multiprocess extensions}.
41294
41295 Reply:
41296 @table @samp
41297 @item E @var{nn}
41298 for an error
41299 @item OK
41300 for success
41301 @end table
41302
41303 @item vMustReplyEmpty
41304 @cindex @samp{vMustReplyEmpty} packet
41305 The correct reply to an unknown @samp{v} packet is to return the empty
41306 string, however, some older versions of @command{gdbserver} would
41307 incorrectly return @samp{OK} for unknown @samp{v} packets.
41308
41309 The @samp{vMustReplyEmpty} is used as a feature test to check how
41310 @command{gdbserver} handles unknown packets, it is important that this
41311 packet be handled in the same way as other unknown @samp{v} packets.
41312 If this packet is handled differently to other unknown @samp{v}
41313 packets then it is possible that @value{GDBN} may run into problems in
41314 other areas, specifically around use of @samp{vFile:setfs:}.
41315
41316 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
41317 @cindex @samp{vRun} packet
41318 Run the program @var{filename}, passing it each @var{argument} on its
41319 command line. The file and arguments are hex-encoded strings. If
41320 @var{filename} is an empty string, the stub may use a default program
41321 (e.g.@: the last program run). The program is created in the stopped
41322 state.
41323
41324 @c FIXME: What about non-stop mode?
41325
41326 This packet is only available in extended mode (@pxref{extended mode}).
41327
41328 Reply:
41329 @table @samp
41330 @item E @var{nn}
41331 for an error
41332 @item @r{Any stop packet}
41333 for success (@pxref{Stop Reply Packets})
41334 @end table
41335
41336 @item vStopped
41337 @cindex @samp{vStopped} packet
41338 @xref{Notification Packets}.
41339
41340 @item X @var{addr},@var{length}:@var{XX@dots{}}
41341 @anchor{X packet}
41342 @cindex @samp{X} packet
41343 Write data to memory, where the data is transmitted in binary.
41344 Memory is specified by its address @var{addr} and number of addressable memory
41345 units @var{length} (@pxref{addressable memory unit});
41346 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
41347
41348 Reply:
41349 @table @samp
41350 @item OK
41351 for success
41352 @item E @var{NN}
41353 for an error
41354 @end table
41355
41356 @item z @var{type},@var{addr},@var{kind}
41357 @itemx Z @var{type},@var{addr},@var{kind}
41358 @anchor{insert breakpoint or watchpoint packet}
41359 @cindex @samp{z} packet
41360 @cindex @samp{Z} packets
41361 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
41362 watchpoint starting at address @var{address} of kind @var{kind}.
41363
41364 Each breakpoint and watchpoint packet @var{type} is documented
41365 separately.
41366
41367 @emph{Implementation notes: A remote target shall return an empty string
41368 for an unrecognized breakpoint or watchpoint packet @var{type}. A
41369 remote target shall support either both or neither of a given
41370 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
41371 avoid potential problems with duplicate packets, the operations should
41372 be implemented in an idempotent way.}
41373
41374 @item z0,@var{addr},@var{kind}
41375 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
41376 @cindex @samp{z0} packet
41377 @cindex @samp{Z0} packet
41378 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
41379 @var{addr} of type @var{kind}.
41380
41381 A software breakpoint is implemented by replacing the instruction at
41382 @var{addr} with a software breakpoint or trap instruction. The
41383 @var{kind} is target-specific and typically indicates the size of the
41384 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
41385 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
41386 architectures have additional meanings for @var{kind}
41387 (@pxref{Architecture-Specific Protocol Details}); if no
41388 architecture-specific value is being used, it should be @samp{0}.
41389 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
41390 conditional expressions in bytecode form that should be evaluated on
41391 the target's side. These are the conditions that should be taken into
41392 consideration when deciding if the breakpoint trigger should be
41393 reported back to @value{GDBN}.
41394
41395 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
41396 for how to best report a software breakpoint event to @value{GDBN}.
41397
41398 The @var{cond_list} parameter is comprised of a series of expressions,
41399 concatenated without separators. Each expression has the following form:
41400
41401 @table @samp
41402
41403 @item X @var{len},@var{expr}
41404 @var{len} is the length of the bytecode expression and @var{expr} is the
41405 actual conditional expression in bytecode form.
41406
41407 @end table
41408
41409 The optional @var{cmd_list} parameter introduces commands that may be
41410 run on the target, rather than being reported back to @value{GDBN}.
41411 The parameter starts with a numeric flag @var{persist}; if the flag is
41412 nonzero, then the breakpoint may remain active and the commands
41413 continue to be run even when @value{GDBN} disconnects from the target.
41414 Following this flag is a series of expressions concatenated with no
41415 separators. Each expression has the following form:
41416
41417 @table @samp
41418
41419 @item X @var{len},@var{expr}
41420 @var{len} is the length of the bytecode expression and @var{expr} is the
41421 actual commands expression in bytecode form.
41422
41423 @end table
41424
41425 @emph{Implementation note: It is possible for a target to copy or move
41426 code that contains software breakpoints (e.g., when implementing
41427 overlays). The behavior of this packet, in the presence of such a
41428 target, is not defined.}
41429
41430 Reply:
41431 @table @samp
41432 @item OK
41433 success
41434 @item @w{}
41435 not supported
41436 @item E @var{NN}
41437 for an error
41438 @end table
41439
41440 @item z1,@var{addr},@var{kind}
41441 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
41442 @cindex @samp{z1} packet
41443 @cindex @samp{Z1} packet
41444 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
41445 address @var{addr}.
41446
41447 A hardware breakpoint is implemented using a mechanism that is not
41448 dependent on being able to modify the target's memory. The
41449 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
41450 same meaning as in @samp{Z0} packets.
41451
41452 @emph{Implementation note: A hardware breakpoint is not affected by code
41453 movement.}
41454
41455 Reply:
41456 @table @samp
41457 @item OK
41458 success
41459 @item @w{}
41460 not supported
41461 @item E @var{NN}
41462 for an error
41463 @end table
41464
41465 @item z2,@var{addr},@var{kind}
41466 @itemx Z2,@var{addr},@var{kind}
41467 @cindex @samp{z2} packet
41468 @cindex @samp{Z2} packet
41469 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
41470 The number of bytes to watch is specified by @var{kind}.
41471
41472 Reply:
41473 @table @samp
41474 @item OK
41475 success
41476 @item @w{}
41477 not supported
41478 @item E @var{NN}
41479 for an error
41480 @end table
41481
41482 @item z3,@var{addr},@var{kind}
41483 @itemx Z3,@var{addr},@var{kind}
41484 @cindex @samp{z3} packet
41485 @cindex @samp{Z3} packet
41486 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
41487 The number of bytes to watch is specified by @var{kind}.
41488
41489 Reply:
41490 @table @samp
41491 @item OK
41492 success
41493 @item @w{}
41494 not supported
41495 @item E @var{NN}
41496 for an error
41497 @end table
41498
41499 @item z4,@var{addr},@var{kind}
41500 @itemx Z4,@var{addr},@var{kind}
41501 @cindex @samp{z4} packet
41502 @cindex @samp{Z4} packet
41503 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
41504 The number of bytes to watch is specified by @var{kind}.
41505
41506 Reply:
41507 @table @samp
41508 @item OK
41509 success
41510 @item @w{}
41511 not supported
41512 @item E @var{NN}
41513 for an error
41514 @end table
41515
41516 @end table
41517
41518 @node Stop Reply Packets
41519 @section Stop Reply Packets
41520 @cindex stop reply packets
41521
41522 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
41523 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
41524 receive any of the below as a reply. Except for @samp{?}
41525 and @samp{vStopped}, that reply is only returned
41526 when the target halts. In the below the exact meaning of @dfn{signal
41527 number} is defined by the header @file{include/gdb/signals.h} in the
41528 @value{GDBN} source code.
41529
41530 In non-stop mode, the server will simply reply @samp{OK} to commands
41531 such as @samp{vCont}; any stop will be the subject of a future
41532 notification. @xref{Remote Non-Stop}.
41533
41534 As in the description of request packets, we include spaces in the
41535 reply templates for clarity; these are not part of the reply packet's
41536 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
41537 components.
41538
41539 @table @samp
41540
41541 @item S @var{AA}
41542 The program received signal number @var{AA} (a two-digit hexadecimal
41543 number). This is equivalent to a @samp{T} response with no
41544 @var{n}:@var{r} pairs.
41545
41546 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
41547 @cindex @samp{T} packet reply
41548 The program received signal number @var{AA} (a two-digit hexadecimal
41549 number). This is equivalent to an @samp{S} response, except that the
41550 @samp{@var{n}:@var{r}} pairs can carry values of important registers
41551 and other information directly in the stop reply packet, reducing
41552 round-trip latency. Single-step and breakpoint traps are reported
41553 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
41554
41555 @itemize @bullet
41556 @item
41557 If @var{n} is a hexadecimal number, it is a register number, and the
41558 corresponding @var{r} gives that register's value. The data @var{r} is a
41559 series of bytes in target byte order, with each byte given by a
41560 two-digit hex number.
41561
41562 @item
41563 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
41564 the stopped thread, as specified in @ref{thread-id syntax}.
41565
41566 @item
41567 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
41568 the core on which the stop event was detected.
41569
41570 @item
41571 If @var{n} is a recognized @dfn{stop reason}, it describes a more
41572 specific event that stopped the target. The currently defined stop
41573 reasons are listed below. The @var{aa} should be @samp{05}, the trap
41574 signal. At most one stop reason should be present.
41575
41576 @item
41577 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
41578 and go on to the next; this allows us to extend the protocol in the
41579 future.
41580 @end itemize
41581
41582 The currently defined stop reasons are:
41583
41584 @table @samp
41585 @item watch
41586 @itemx rwatch
41587 @itemx awatch
41588 The packet indicates a watchpoint hit, and @var{r} is the data address, in
41589 hex.
41590
41591 @item syscall_entry
41592 @itemx syscall_return
41593 The packet indicates a syscall entry or return, and @var{r} is the
41594 syscall number, in hex.
41595
41596 @cindex shared library events, remote reply
41597 @item library
41598 The packet indicates that the loaded libraries have changed.
41599 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
41600 list of loaded libraries. The @var{r} part is ignored.
41601
41602 @cindex replay log events, remote reply
41603 @item replaylog
41604 The packet indicates that the target cannot continue replaying
41605 logged execution events, because it has reached the end (or the
41606 beginning when executing backward) of the log. The value of @var{r}
41607 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
41608 for more information.
41609
41610 @item swbreak
41611 @anchor{swbreak stop reason}
41612 The packet indicates a software breakpoint instruction was executed,
41613 irrespective of whether it was @value{GDBN} that planted the
41614 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
41615 part must be left empty.
41616
41617 On some architectures, such as x86, at the architecture level, when a
41618 breakpoint instruction executes the program counter points at the
41619 breakpoint address plus an offset. On such targets, the stub is
41620 responsible for adjusting the PC to point back at the breakpoint
41621 address.
41622
41623 This packet should not be sent by default; older @value{GDBN} versions
41624 did not support it. @value{GDBN} requests it, by supplying an
41625 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41626 remote stub must also supply the appropriate @samp{qSupported} feature
41627 indicating support.
41628
41629 This packet is required for correct non-stop mode operation.
41630
41631 @item hwbreak
41632 The packet indicates the target stopped for a hardware breakpoint.
41633 The @var{r} part must be left empty.
41634
41635 The same remarks about @samp{qSupported} and non-stop mode above
41636 apply.
41637
41638 @cindex fork events, remote reply
41639 @item fork
41640 The packet indicates that @code{fork} was called, and @var{r}
41641 is the thread ID of the new child process. Refer to
41642 @ref{thread-id syntax} for the format of the @var{thread-id}
41643 field. This packet is only applicable to targets that support
41644 fork events.
41645
41646 This packet should not be sent by default; older @value{GDBN} versions
41647 did not support it. @value{GDBN} requests it, by supplying an
41648 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41649 remote stub must also supply the appropriate @samp{qSupported} feature
41650 indicating support.
41651
41652 @cindex vfork events, remote reply
41653 @item vfork
41654 The packet indicates that @code{vfork} was called, and @var{r}
41655 is the thread ID of the new child process. Refer to
41656 @ref{thread-id syntax} for the format of the @var{thread-id}
41657 field. This packet is only applicable to targets that support
41658 vfork events.
41659
41660 This packet should not be sent by default; older @value{GDBN} versions
41661 did not support it. @value{GDBN} requests it, by supplying an
41662 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41663 remote stub must also supply the appropriate @samp{qSupported} feature
41664 indicating support.
41665
41666 @cindex vforkdone events, remote reply
41667 @item vforkdone
41668 The packet indicates that a child process created by a vfork
41669 has either called @code{exec} or terminated, so that the
41670 address spaces of the parent and child process are no longer
41671 shared. The @var{r} part is ignored. This packet is only
41672 applicable to targets that support vforkdone events.
41673
41674 This packet should not be sent by default; older @value{GDBN} versions
41675 did not support it. @value{GDBN} requests it, by supplying an
41676 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41677 remote stub must also supply the appropriate @samp{qSupported} feature
41678 indicating support.
41679
41680 @cindex exec events, remote reply
41681 @item exec
41682 The packet indicates that @code{execve} was called, and @var{r}
41683 is the absolute pathname of the file that was executed, in hex.
41684 This packet is only applicable to targets that support exec events.
41685
41686 This packet should not be sent by default; older @value{GDBN} versions
41687 did not support it. @value{GDBN} requests it, by supplying an
41688 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41689 remote stub must also supply the appropriate @samp{qSupported} feature
41690 indicating support.
41691
41692 @cindex thread create event, remote reply
41693 @anchor{thread create event}
41694 @item create
41695 The packet indicates that the thread was just created. The new thread
41696 is stopped until @value{GDBN} sets it running with a resumption packet
41697 (@pxref{vCont packet}). This packet should not be sent by default;
41698 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
41699 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
41700 @var{r} part is ignored.
41701
41702 @end table
41703
41704 @item W @var{AA}
41705 @itemx W @var{AA} ; process:@var{pid}
41706 The process exited, and @var{AA} is the exit status. This is only
41707 applicable to certain targets.
41708
41709 The second form of the response, including the process ID of the
41710 exited process, can be used only when @value{GDBN} has reported
41711 support for multiprocess protocol extensions; see @ref{multiprocess
41712 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
41713 hex strings.
41714
41715 @item X @var{AA}
41716 @itemx X @var{AA} ; process:@var{pid}
41717 The process terminated with signal @var{AA}.
41718
41719 The second form of the response, including the process ID of the
41720 terminated process, can be used only when @value{GDBN} has reported
41721 support for multiprocess protocol extensions; see @ref{multiprocess
41722 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
41723 hex strings.
41724
41725 @anchor{thread exit event}
41726 @cindex thread exit event, remote reply
41727 @item w @var{AA} ; @var{tid}
41728
41729 The thread exited, and @var{AA} is the exit status. This response
41730 should not be sent by default; @value{GDBN} requests it with the
41731 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
41732 @var{AA} is formatted as a big-endian hex string.
41733
41734 @item N
41735 There are no resumed threads left in the target. In other words, even
41736 though the process is alive, the last resumed thread has exited. For
41737 example, say the target process has two threads: thread 1 and thread
41738 2. The client leaves thread 1 stopped, and resumes thread 2, which
41739 subsequently exits. At this point, even though the process is still
41740 alive, and thus no @samp{W} stop reply is sent, no thread is actually
41741 executing either. The @samp{N} stop reply thus informs the client
41742 that it can stop waiting for stop replies. This packet should not be
41743 sent by default; older @value{GDBN} versions did not support it.
41744 @value{GDBN} requests it, by supplying an appropriate
41745 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
41746 also supply the appropriate @samp{qSupported} feature indicating
41747 support.
41748
41749 @item O @var{XX}@dots{}
41750 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
41751 written as the program's console output. This can happen at any time
41752 while the program is running and the debugger should continue to wait
41753 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
41754
41755 @item F @var{call-id},@var{parameter}@dots{}
41756 @var{call-id} is the identifier which says which host system call should
41757 be called. This is just the name of the function. Translation into the
41758 correct system call is only applicable as it's defined in @value{GDBN}.
41759 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
41760 system calls.
41761
41762 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
41763 this very system call.
41764
41765 The target replies with this packet when it expects @value{GDBN} to
41766 call a host system call on behalf of the target. @value{GDBN} replies
41767 with an appropriate @samp{F} packet and keeps up waiting for the next
41768 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
41769 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
41770 Protocol Extension}, for more details.
41771
41772 @end table
41773
41774 @node General Query Packets
41775 @section General Query Packets
41776 @cindex remote query requests
41777
41778 Packets starting with @samp{q} are @dfn{general query packets};
41779 packets starting with @samp{Q} are @dfn{general set packets}. General
41780 query and set packets are a semi-unified form for retrieving and
41781 sending information to and from the stub.
41782
41783 The initial letter of a query or set packet is followed by a name
41784 indicating what sort of thing the packet applies to. For example,
41785 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
41786 definitions with the stub. These packet names follow some
41787 conventions:
41788
41789 @itemize @bullet
41790 @item
41791 The name must not contain commas, colons or semicolons.
41792 @item
41793 Most @value{GDBN} query and set packets have a leading upper case
41794 letter.
41795 @item
41796 The names of custom vendor packets should use a company prefix, in
41797 lower case, followed by a period. For example, packets designed at
41798 the Acme Corporation might begin with @samp{qacme.foo} (for querying
41799 foos) or @samp{Qacme.bar} (for setting bars).
41800 @end itemize
41801
41802 The name of a query or set packet should be separated from any
41803 parameters by a @samp{:}; the parameters themselves should be
41804 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
41805 full packet name, and check for a separator or the end of the packet,
41806 in case two packet names share a common prefix. New packets should not begin
41807 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
41808 packets predate these conventions, and have arguments without any terminator
41809 for the packet name; we suspect they are in widespread use in places that
41810 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
41811 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
41812 packet.}.
41813
41814 Like the descriptions of the other packets, each description here
41815 has a template showing the packet's overall syntax, followed by an
41816 explanation of the packet's meaning. We include spaces in some of the
41817 templates for clarity; these are not part of the packet's syntax. No
41818 @value{GDBN} packet uses spaces to separate its components.
41819
41820 Here are the currently defined query and set packets:
41821
41822 @table @samp
41823
41824 @item QAgent:1
41825 @itemx QAgent:0
41826 Turn on or off the agent as a helper to perform some debugging operations
41827 delegated from @value{GDBN} (@pxref{Control Agent}).
41828
41829 @item QAllow:@var{op}:@var{val}@dots{}
41830 @cindex @samp{QAllow} packet
41831 Specify which operations @value{GDBN} expects to request of the
41832 target, as a semicolon-separated list of operation name and value
41833 pairs. Possible values for @var{op} include @samp{WriteReg},
41834 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
41835 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
41836 indicating that @value{GDBN} will not request the operation, or 1,
41837 indicating that it may. (The target can then use this to set up its
41838 own internals optimally, for instance if the debugger never expects to
41839 insert breakpoints, it may not need to install its own trap handler.)
41840
41841 @item qC
41842 @cindex current thread, remote request
41843 @cindex @samp{qC} packet
41844 Return the current thread ID.
41845
41846 Reply:
41847 @table @samp
41848 @item QC @var{thread-id}
41849 Where @var{thread-id} is a thread ID as documented in
41850 @ref{thread-id syntax}.
41851 @item @r{(anything else)}
41852 Any other reply implies the old thread ID.
41853 @end table
41854
41855 @item qCRC:@var{addr},@var{length}
41856 @cindex CRC of memory block, remote request
41857 @cindex @samp{qCRC} packet
41858 @anchor{qCRC packet}
41859 Compute the CRC checksum of a block of memory using CRC-32 defined in
41860 IEEE 802.3. The CRC is computed byte at a time, taking the most
41861 significant bit of each byte first. The initial pattern code
41862 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
41863
41864 @emph{Note:} This is the same CRC used in validating separate debug
41865 files (@pxref{Separate Debug Files, , Debugging Information in Separate
41866 Files}). However the algorithm is slightly different. When validating
41867 separate debug files, the CRC is computed taking the @emph{least}
41868 significant bit of each byte first, and the final result is inverted to
41869 detect trailing zeros.
41870
41871 Reply:
41872 @table @samp
41873 @item E @var{NN}
41874 An error (such as memory fault)
41875 @item C @var{crc32}
41876 The specified memory region's checksum is @var{crc32}.
41877 @end table
41878
41879 @item QDisableRandomization:@var{value}
41880 @cindex disable address space randomization, remote request
41881 @cindex @samp{QDisableRandomization} packet
41882 Some target operating systems will randomize the virtual address space
41883 of the inferior process as a security feature, but provide a feature
41884 to disable such randomization, e.g.@: to allow for a more deterministic
41885 debugging experience. On such systems, this packet with a @var{value}
41886 of 1 directs the target to disable address space randomization for
41887 processes subsequently started via @samp{vRun} packets, while a packet
41888 with a @var{value} of 0 tells the target to enable address space
41889 randomization.
41890
41891 This packet is only available in extended mode (@pxref{extended mode}).
41892
41893 Reply:
41894 @table @samp
41895 @item OK
41896 The request succeeded.
41897
41898 @item E @var{nn}
41899 An error occurred. The error number @var{nn} is given as hex digits.
41900
41901 @item @w{}
41902 An empty reply indicates that @samp{QDisableRandomization} is not supported
41903 by the stub.
41904 @end table
41905
41906 This packet is not probed by default; the remote stub must request it,
41907 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41908 This should only be done on targets that actually support disabling
41909 address space randomization.
41910
41911 @item QStartupWithShell:@var{value}
41912 @cindex startup with shell, remote request
41913 @cindex @samp{QStartupWithShell} packet
41914 On UNIX-like targets, it is possible to start the inferior using a
41915 shell program. This is the default behavior on both @value{GDBN} and
41916 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
41917 used to inform @command{gdbserver} whether it should start the
41918 inferior using a shell or not.
41919
41920 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
41921 to start the inferior. If @var{value} is @samp{1},
41922 @command{gdbserver} will use a shell to start the inferior. All other
41923 values are considered an error.
41924
41925 This packet is only available in extended mode (@pxref{extended
41926 mode}).
41927
41928 Reply:
41929 @table @samp
41930 @item OK
41931 The request succeeded.
41932
41933 @item E @var{nn}
41934 An error occurred. The error number @var{nn} is given as hex digits.
41935 @end table
41936
41937 This packet is not probed by default; the remote stub must request it,
41938 by supplying an appropriate @samp{qSupported} response
41939 (@pxref{qSupported}). This should only be done on targets that
41940 actually support starting the inferior using a shell.
41941
41942 Use of this packet is controlled by the @code{set startup-with-shell}
41943 command; @pxref{set startup-with-shell}.
41944
41945 @item QEnvironmentHexEncoded:@var{hex-value}
41946 @anchor{QEnvironmentHexEncoded}
41947 @cindex set environment variable, remote request
41948 @cindex @samp{QEnvironmentHexEncoded} packet
41949 On UNIX-like targets, it is possible to set environment variables that
41950 will be passed to the inferior during the startup process. This
41951 packet is used to inform @command{gdbserver} of an environment
41952 variable that has been defined by the user on @value{GDBN} (@pxref{set
41953 environment}).
41954
41955 The packet is composed by @var{hex-value}, an hex encoded
41956 representation of the @var{name=value} format representing an
41957 environment variable. The name of the environment variable is
41958 represented by @var{name}, and the value to be assigned to the
41959 environment variable is represented by @var{value}. If the variable
41960 has no value (i.e., the value is @code{null}), then @var{value} will
41961 not be present.
41962
41963 This packet is only available in extended mode (@pxref{extended
41964 mode}).
41965
41966 Reply:
41967 @table @samp
41968 @item OK
41969 The request succeeded.
41970 @end table
41971
41972 This packet is not probed by default; the remote stub must request it,
41973 by supplying an appropriate @samp{qSupported} response
41974 (@pxref{qSupported}). This should only be done on targets that
41975 actually support passing environment variables to the starting
41976 inferior.
41977
41978 This packet is related to the @code{set environment} command;
41979 @pxref{set environment}.
41980
41981 @item QEnvironmentUnset:@var{hex-value}
41982 @anchor{QEnvironmentUnset}
41983 @cindex unset environment variable, remote request
41984 @cindex @samp{QEnvironmentUnset} packet
41985 On UNIX-like targets, it is possible to unset environment variables
41986 before starting the inferior in the remote target. This packet is
41987 used to inform @command{gdbserver} of an environment variable that has
41988 been unset by the user on @value{GDBN} (@pxref{unset environment}).
41989
41990 The packet is composed by @var{hex-value}, an hex encoded
41991 representation of the name of the environment variable to be unset.
41992
41993 This packet is only available in extended mode (@pxref{extended
41994 mode}).
41995
41996 Reply:
41997 @table @samp
41998 @item OK
41999 The request succeeded.
42000 @end table
42001
42002 This packet is not probed by default; the remote stub must request it,
42003 by supplying an appropriate @samp{qSupported} response
42004 (@pxref{qSupported}). This should only be done on targets that
42005 actually support passing environment variables to the starting
42006 inferior.
42007
42008 This packet is related to the @code{unset environment} command;
42009 @pxref{unset environment}.
42010
42011 @item QEnvironmentReset
42012 @anchor{QEnvironmentReset}
42013 @cindex reset environment, remote request
42014 @cindex @samp{QEnvironmentReset} packet
42015 On UNIX-like targets, this packet is used to reset the state of
42016 environment variables in the remote target before starting the
42017 inferior. In this context, reset means unsetting all environment
42018 variables that were previously set by the user (i.e., were not
42019 initially present in the environment). It is sent to
42020 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
42021 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
42022 (@pxref{QEnvironmentUnset}) packets.
42023
42024 This packet is only available in extended mode (@pxref{extended
42025 mode}).
42026
42027 Reply:
42028 @table @samp
42029 @item OK
42030 The request succeeded.
42031 @end table
42032
42033 This packet is not probed by default; the remote stub must request it,
42034 by supplying an appropriate @samp{qSupported} response
42035 (@pxref{qSupported}). This should only be done on targets that
42036 actually support passing environment variables to the starting
42037 inferior.
42038
42039 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
42040 @anchor{QSetWorkingDir packet}
42041 @cindex set working directory, remote request
42042 @cindex @samp{QSetWorkingDir} packet
42043 This packet is used to inform the remote server of the intended
42044 current working directory for programs that are going to be executed.
42045
42046 The packet is composed by @var{directory}, an hex encoded
42047 representation of the directory that the remote inferior will use as
42048 its current working directory. If @var{directory} is an empty string,
42049 the remote server should reset the inferior's current working
42050 directory to its original, empty value.
42051
42052 This packet is only available in extended mode (@pxref{extended
42053 mode}).
42054
42055 Reply:
42056 @table @samp
42057 @item OK
42058 The request succeeded.
42059 @end table
42060
42061 @item qfThreadInfo
42062 @itemx qsThreadInfo
42063 @cindex list active threads, remote request
42064 @cindex @samp{qfThreadInfo} packet
42065 @cindex @samp{qsThreadInfo} packet
42066 Obtain a list of all active thread IDs from the target (OS). Since there
42067 may be too many active threads to fit into one reply packet, this query
42068 works iteratively: it may require more than one query/reply sequence to
42069 obtain the entire list of threads. The first query of the sequence will
42070 be the @samp{qfThreadInfo} query; subsequent queries in the
42071 sequence will be the @samp{qsThreadInfo} query.
42072
42073 NOTE: This packet replaces the @samp{qL} query (see below).
42074
42075 Reply:
42076 @table @samp
42077 @item m @var{thread-id}
42078 A single thread ID
42079 @item m @var{thread-id},@var{thread-id}@dots{}
42080 a comma-separated list of thread IDs
42081 @item l
42082 (lower case letter @samp{L}) denotes end of list.
42083 @end table
42084
42085 In response to each query, the target will reply with a list of one or
42086 more thread IDs, separated by commas.
42087 @value{GDBN} will respond to each reply with a request for more thread
42088 ids (using the @samp{qs} form of the query), until the target responds
42089 with @samp{l} (lower-case ell, for @dfn{last}).
42090 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
42091 fields.
42092
42093 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
42094 initial connection with the remote target, and the very first thread ID
42095 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
42096 message. Therefore, the stub should ensure that the first thread ID in
42097 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
42098
42099 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
42100 @cindex get thread-local storage address, remote request
42101 @cindex @samp{qGetTLSAddr} packet
42102 Fetch the address associated with thread local storage specified
42103 by @var{thread-id}, @var{offset}, and @var{lm}.
42104
42105 @var{thread-id} is the thread ID associated with the
42106 thread for which to fetch the TLS address. @xref{thread-id syntax}.
42107
42108 @var{offset} is the (big endian, hex encoded) offset associated with the
42109 thread local variable. (This offset is obtained from the debug
42110 information associated with the variable.)
42111
42112 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
42113 load module associated with the thread local storage. For example,
42114 a @sc{gnu}/Linux system will pass the link map address of the shared
42115 object associated with the thread local storage under consideration.
42116 Other operating environments may choose to represent the load module
42117 differently, so the precise meaning of this parameter will vary.
42118
42119 Reply:
42120 @table @samp
42121 @item @var{XX}@dots{}
42122 Hex encoded (big endian) bytes representing the address of the thread
42123 local storage requested.
42124
42125 @item E @var{nn}
42126 An error occurred. The error number @var{nn} is given as hex digits.
42127
42128 @item @w{}
42129 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
42130 @end table
42131
42132 @item qGetTIBAddr:@var{thread-id}
42133 @cindex get thread information block address
42134 @cindex @samp{qGetTIBAddr} packet
42135 Fetch address of the Windows OS specific Thread Information Block.
42136
42137 @var{thread-id} is the thread ID associated with the thread.
42138
42139 Reply:
42140 @table @samp
42141 @item @var{XX}@dots{}
42142 Hex encoded (big endian) bytes representing the linear address of the
42143 thread information block.
42144
42145 @item E @var{nn}
42146 An error occured. This means that either the thread was not found, or the
42147 address could not be retrieved.
42148
42149 @item @w{}
42150 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
42151 @end table
42152
42153 @item qL @var{startflag} @var{threadcount} @var{nextthread}
42154 Obtain thread information from RTOS. Where: @var{startflag} (one hex
42155 digit) is one to indicate the first query and zero to indicate a
42156 subsequent query; @var{threadcount} (two hex digits) is the maximum
42157 number of threads the response packet can contain; and @var{nextthread}
42158 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
42159 returned in the response as @var{argthread}.
42160
42161 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
42162
42163 Reply:
42164 @table @samp
42165 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
42166 Where: @var{count} (two hex digits) is the number of threads being
42167 returned; @var{done} (one hex digit) is zero to indicate more threads
42168 and one indicates no further threads; @var{argthreadid} (eight hex
42169 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
42170 is a sequence of thread IDs, @var{threadid} (eight hex
42171 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
42172 @end table
42173
42174 @item qMemTags:@var{start address},@var{length}:@var{type}
42175 @anchor{qMemTags}
42176 @cindex fetch memory tags
42177 @cindex @samp{qMemTags} packet
42178 Fetch memory tags of type @var{type} from the address range
42179 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
42180 target is responsible for calculating how many tags will be returned, as this
42181 is architecture-specific.
42182
42183 @var{start address} is the starting address of the memory range.
42184
42185 @var{length} is the length, in bytes, of the memory range.
42186
42187 @var{type} is the type of tag the request wants to fetch. The type is a signed
42188 integer.
42189
42190 Reply:
42191 @table @samp
42192 @item @var{mxx}@dots{}
42193 Hex encoded sequence of uninterpreted bytes, @var{xx}@dots{}, representing the
42194 tags found in the requested memory range.
42195
42196 @item E @var{nn}
42197 An error occured. This means that fetching of memory tags failed for some
42198 reason.
42199
42200 @item @w{}
42201 An empty reply indicates that @samp{qMemTags} is not supported by the stub,
42202 although this should not happen given @value{GDBN} will only send this packet
42203 if the stub has advertised support for memory tagging via @samp{qSupported}.
42204 @end table
42205
42206 @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes}
42207 @anchor{QMemTags}
42208 @cindex store memory tags
42209 @cindex @samp{QMemTags} packet
42210 Store memory tags of type @var{type} to the address range
42211 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
42212 target is responsible for interpreting the type, the tag bytes and modifying
42213 the memory tag granules accordingly, given this is architecture-specific.
42214
42215 The interpretation of how many tags (@var{nt}) should be written to how many
42216 memory tag granules (@var{ng}) is also architecture-specific. The behavior is
42217 implementation-specific, but the following is suggested.
42218
42219 If the number of memory tags, @var{nt}, is greater than or equal to the
42220 number of memory tag granules, @var{ng}, only @var{ng} tags will be
42221 stored.
42222
42223 If @var{nt} is less than @var{ng}, the behavior is that of a fill operation,
42224 and the tag bytes will be used as a pattern that will get repeated until
42225 @var{ng} tags are stored.
42226
42227 @var{start address} is the starting address of the memory range. The address
42228 does not have any restriction on alignment or size.
42229
42230 @var{length} is the length, in bytes, of the memory range.
42231
42232 @var{type} is the type of tag the request wants to fetch. The type is a signed
42233 integer.
42234
42235 @var{tag bytes} is a sequence of hex encoded uninterpreted bytes which will be
42236 interpreted by the target. Each pair of hex digits is interpreted as a
42237 single byte.
42238
42239 Reply:
42240 @table @samp
42241 @item OK
42242 The request was successful and the memory tag granules were modified
42243 accordingly.
42244
42245 @item E @var{nn}
42246 An error occured. This means that modifying the memory tag granules failed
42247 for some reason.
42248
42249 @item @w{}
42250 An empty reply indicates that @samp{QMemTags} is not supported by the stub,
42251 although this should not happen given @value{GDBN} will only send this packet
42252 if the stub has advertised support for memory tagging via @samp{qSupported}.
42253 @end table
42254
42255 @item qOffsets
42256 @cindex section offsets, remote request
42257 @cindex @samp{qOffsets} packet
42258 Get section offsets that the target used when relocating the downloaded
42259 image.
42260
42261 Reply:
42262 @table @samp
42263 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
42264 Relocate the @code{Text} section by @var{xxx} from its original address.
42265 Relocate the @code{Data} section by @var{yyy} from its original address.
42266 If the object file format provides segment information (e.g.@: @sc{elf}
42267 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
42268 segments by the supplied offsets.
42269
42270 @emph{Note: while a @code{Bss} offset may be included in the response,
42271 @value{GDBN} ignores this and instead applies the @code{Data} offset
42272 to the @code{Bss} section.}
42273
42274 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
42275 Relocate the first segment of the object file, which conventionally
42276 contains program code, to a starting address of @var{xxx}. If
42277 @samp{DataSeg} is specified, relocate the second segment, which
42278 conventionally contains modifiable data, to a starting address of
42279 @var{yyy}. @value{GDBN} will report an error if the object file
42280 does not contain segment information, or does not contain at least
42281 as many segments as mentioned in the reply. Extra segments are
42282 kept at fixed offsets relative to the last relocated segment.
42283 @end table
42284
42285 @item qP @var{mode} @var{thread-id}
42286 @cindex thread information, remote request
42287 @cindex @samp{qP} packet
42288 Returns information on @var{thread-id}. Where: @var{mode} is a hex
42289 encoded 32 bit mode; @var{thread-id} is a thread ID
42290 (@pxref{thread-id syntax}).
42291
42292 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
42293 (see below).
42294
42295 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
42296
42297 @item QNonStop:1
42298 @itemx QNonStop:0
42299 @cindex non-stop mode, remote request
42300 @cindex @samp{QNonStop} packet
42301 @anchor{QNonStop}
42302 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
42303 @xref{Remote Non-Stop}, for more information.
42304
42305 Reply:
42306 @table @samp
42307 @item OK
42308 The request succeeded.
42309
42310 @item E @var{nn}
42311 An error occurred. The error number @var{nn} is given as hex digits.
42312
42313 @item @w{}
42314 An empty reply indicates that @samp{QNonStop} is not supported by
42315 the stub.
42316 @end table
42317
42318 This packet is not probed by default; the remote stub must request it,
42319 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42320 Use of this packet is controlled by the @code{set non-stop} command;
42321 @pxref{Non-Stop Mode}.
42322
42323 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
42324 @itemx QCatchSyscalls:0
42325 @cindex catch syscalls from inferior, remote request
42326 @cindex @samp{QCatchSyscalls} packet
42327 @anchor{QCatchSyscalls}
42328 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
42329 catching syscalls from the inferior process.
42330
42331 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
42332 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
42333 is listed, every system call should be reported.
42334
42335 Note that if a syscall not in the list is reported, @value{GDBN} will
42336 still filter the event according to its own list from all corresponding
42337 @code{catch syscall} commands. However, it is more efficient to only
42338 report the requested syscalls.
42339
42340 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
42341 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
42342
42343 If the inferior process execs, the state of @samp{QCatchSyscalls} is
42344 kept for the new process too. On targets where exec may affect syscall
42345 numbers, for example with exec between 32 and 64-bit processes, the
42346 client should send a new packet with the new syscall list.
42347
42348 Reply:
42349 @table @samp
42350 @item OK
42351 The request succeeded.
42352
42353 @item E @var{nn}
42354 An error occurred. @var{nn} are hex digits.
42355
42356 @item @w{}
42357 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
42358 the stub.
42359 @end table
42360
42361 Use of this packet is controlled by the @code{set remote catch-syscalls}
42362 command (@pxref{Remote Configuration, set remote catch-syscalls}).
42363 This packet is not probed by default; the remote stub must request it,
42364 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42365
42366 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
42367 @cindex pass signals to inferior, remote request
42368 @cindex @samp{QPassSignals} packet
42369 @anchor{QPassSignals}
42370 Each listed @var{signal} should be passed directly to the inferior process.
42371 Signals are numbered identically to continue packets and stop replies
42372 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
42373 strictly greater than the previous item. These signals do not need to stop
42374 the inferior, or be reported to @value{GDBN}. All other signals should be
42375 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
42376 combine; any earlier @samp{QPassSignals} list is completely replaced by the
42377 new list. This packet improves performance when using @samp{handle
42378 @var{signal} nostop noprint pass}.
42379
42380 Reply:
42381 @table @samp
42382 @item OK
42383 The request succeeded.
42384
42385 @item E @var{nn}
42386 An error occurred. The error number @var{nn} is given as hex digits.
42387
42388 @item @w{}
42389 An empty reply indicates that @samp{QPassSignals} is not supported by
42390 the stub.
42391 @end table
42392
42393 Use of this packet is controlled by the @code{set remote pass-signals}
42394 command (@pxref{Remote Configuration, set remote pass-signals}).
42395 This packet is not probed by default; the remote stub must request it,
42396 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42397
42398 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
42399 @cindex signals the inferior may see, remote request
42400 @cindex @samp{QProgramSignals} packet
42401 @anchor{QProgramSignals}
42402 Each listed @var{signal} may be delivered to the inferior process.
42403 Others should be silently discarded.
42404
42405 In some cases, the remote stub may need to decide whether to deliver a
42406 signal to the program or not without @value{GDBN} involvement. One
42407 example of that is while detaching --- the program's threads may have
42408 stopped for signals that haven't yet had a chance of being reported to
42409 @value{GDBN}, and so the remote stub can use the signal list specified
42410 by this packet to know whether to deliver or ignore those pending
42411 signals.
42412
42413 This does not influence whether to deliver a signal as requested by a
42414 resumption packet (@pxref{vCont packet}).
42415
42416 Signals are numbered identically to continue packets and stop replies
42417 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
42418 strictly greater than the previous item. Multiple
42419 @samp{QProgramSignals} packets do not combine; any earlier
42420 @samp{QProgramSignals} list is completely replaced by the new list.
42421
42422 Reply:
42423 @table @samp
42424 @item OK
42425 The request succeeded.
42426
42427 @item E @var{nn}
42428 An error occurred. The error number @var{nn} is given as hex digits.
42429
42430 @item @w{}
42431 An empty reply indicates that @samp{QProgramSignals} is not supported
42432 by the stub.
42433 @end table
42434
42435 Use of this packet is controlled by the @code{set remote program-signals}
42436 command (@pxref{Remote Configuration, set remote program-signals}).
42437 This packet is not probed by default; the remote stub must request it,
42438 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42439
42440 @anchor{QThreadEvents}
42441 @item QThreadEvents:1
42442 @itemx QThreadEvents:0
42443 @cindex thread create/exit events, remote request
42444 @cindex @samp{QThreadEvents} packet
42445
42446 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
42447 reporting of thread create and exit events. @xref{thread create
42448 event}, for the reply specifications. For example, this is used in
42449 non-stop mode when @value{GDBN} stops a set of threads and
42450 synchronously waits for the their corresponding stop replies. Without
42451 exit events, if one of the threads exits, @value{GDBN} would hang
42452 forever not knowing that it should no longer expect a stop for that
42453 same thread. @value{GDBN} does not enable this feature unless the
42454 stub reports that it supports it by including @samp{QThreadEvents+} in
42455 its @samp{qSupported} reply.
42456
42457 Reply:
42458 @table @samp
42459 @item OK
42460 The request succeeded.
42461
42462 @item E @var{nn}
42463 An error occurred. The error number @var{nn} is given as hex digits.
42464
42465 @item @w{}
42466 An empty reply indicates that @samp{QThreadEvents} is not supported by
42467 the stub.
42468 @end table
42469
42470 Use of this packet is controlled by the @code{set remote thread-events}
42471 command (@pxref{Remote Configuration, set remote thread-events}).
42472
42473 @item qRcmd,@var{command}
42474 @cindex execute remote command, remote request
42475 @cindex @samp{qRcmd} packet
42476 @var{command} (hex encoded) is passed to the local interpreter for
42477 execution. Invalid commands should be reported using the output
42478 string. Before the final result packet, the target may also respond
42479 with a number of intermediate @samp{O@var{output}} console output
42480 packets. @emph{Implementors should note that providing access to a
42481 stubs's interpreter may have security implications}.
42482
42483 Reply:
42484 @table @samp
42485 @item OK
42486 A command response with no output.
42487 @item @var{OUTPUT}
42488 A command response with the hex encoded output string @var{OUTPUT}.
42489 @item E @var{NN}
42490 Indicate a badly formed request. The error number @var{NN} is given as
42491 hex digits.
42492 @item @w{}
42493 An empty reply indicates that @samp{qRcmd} is not recognized.
42494 @end table
42495
42496 (Note that the @code{qRcmd} packet's name is separated from the
42497 command by a @samp{,}, not a @samp{:}, contrary to the naming
42498 conventions above. Please don't use this packet as a model for new
42499 packets.)
42500
42501 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
42502 @cindex searching memory, in remote debugging
42503 @ifnotinfo
42504 @cindex @samp{qSearch:memory} packet
42505 @end ifnotinfo
42506 @cindex @samp{qSearch memory} packet
42507 @anchor{qSearch memory}
42508 Search @var{length} bytes at @var{address} for @var{search-pattern}.
42509 Both @var{address} and @var{length} are encoded in hex;
42510 @var{search-pattern} is a sequence of bytes, also hex encoded.
42511
42512 Reply:
42513 @table @samp
42514 @item 0
42515 The pattern was not found.
42516 @item 1,address
42517 The pattern was found at @var{address}.
42518 @item E @var{NN}
42519 A badly formed request or an error was encountered while searching memory.
42520 @item @w{}
42521 An empty reply indicates that @samp{qSearch:memory} is not recognized.
42522 @end table
42523
42524 @item QStartNoAckMode
42525 @cindex @samp{QStartNoAckMode} packet
42526 @anchor{QStartNoAckMode}
42527 Request that the remote stub disable the normal @samp{+}/@samp{-}
42528 protocol acknowledgments (@pxref{Packet Acknowledgment}).
42529
42530 Reply:
42531 @table @samp
42532 @item OK
42533 The stub has switched to no-acknowledgment mode.
42534 @value{GDBN} acknowledges this response,
42535 but neither the stub nor @value{GDBN} shall send or expect further
42536 @samp{+}/@samp{-} acknowledgments in the current connection.
42537 @item @w{}
42538 An empty reply indicates that the stub does not support no-acknowledgment mode.
42539 @end table
42540
42541 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
42542 @cindex supported packets, remote query
42543 @cindex features of the remote protocol
42544 @cindex @samp{qSupported} packet
42545 @anchor{qSupported}
42546 Tell the remote stub about features supported by @value{GDBN}, and
42547 query the stub for features it supports. This packet allows
42548 @value{GDBN} and the remote stub to take advantage of each others'
42549 features. @samp{qSupported} also consolidates multiple feature probes
42550 at startup, to improve @value{GDBN} performance---a single larger
42551 packet performs better than multiple smaller probe packets on
42552 high-latency links. Some features may enable behavior which must not
42553 be on by default, e.g.@: because it would confuse older clients or
42554 stubs. Other features may describe packets which could be
42555 automatically probed for, but are not. These features must be
42556 reported before @value{GDBN} will use them. This ``default
42557 unsupported'' behavior is not appropriate for all packets, but it
42558 helps to keep the initial connection time under control with new
42559 versions of @value{GDBN} which support increasing numbers of packets.
42560
42561 Reply:
42562 @table @samp
42563 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
42564 The stub supports or does not support each returned @var{stubfeature},
42565 depending on the form of each @var{stubfeature} (see below for the
42566 possible forms).
42567 @item @w{}
42568 An empty reply indicates that @samp{qSupported} is not recognized,
42569 or that no features needed to be reported to @value{GDBN}.
42570 @end table
42571
42572 The allowed forms for each feature (either a @var{gdbfeature} in the
42573 @samp{qSupported} packet, or a @var{stubfeature} in the response)
42574 are:
42575
42576 @table @samp
42577 @item @var{name}=@var{value}
42578 The remote protocol feature @var{name} is supported, and associated
42579 with the specified @var{value}. The format of @var{value} depends
42580 on the feature, but it must not include a semicolon.
42581 @item @var{name}+
42582 The remote protocol feature @var{name} is supported, and does not
42583 need an associated value.
42584 @item @var{name}-
42585 The remote protocol feature @var{name} is not supported.
42586 @item @var{name}?
42587 The remote protocol feature @var{name} may be supported, and
42588 @value{GDBN} should auto-detect support in some other way when it is
42589 needed. This form will not be used for @var{gdbfeature} notifications,
42590 but may be used for @var{stubfeature} responses.
42591 @end table
42592
42593 Whenever the stub receives a @samp{qSupported} request, the
42594 supplied set of @value{GDBN} features should override any previous
42595 request. This allows @value{GDBN} to put the stub in a known
42596 state, even if the stub had previously been communicating with
42597 a different version of @value{GDBN}.
42598
42599 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
42600 are defined:
42601
42602 @table @samp
42603 @item multiprocess
42604 This feature indicates whether @value{GDBN} supports multiprocess
42605 extensions to the remote protocol. @value{GDBN} does not use such
42606 extensions unless the stub also reports that it supports them by
42607 including @samp{multiprocess+} in its @samp{qSupported} reply.
42608 @xref{multiprocess extensions}, for details.
42609
42610 @item xmlRegisters
42611 This feature indicates that @value{GDBN} supports the XML target
42612 description. If the stub sees @samp{xmlRegisters=} with target
42613 specific strings separated by a comma, it will report register
42614 description.
42615
42616 @item qRelocInsn
42617 This feature indicates whether @value{GDBN} supports the
42618 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
42619 instruction reply packet}).
42620
42621 @item swbreak
42622 This feature indicates whether @value{GDBN} supports the swbreak stop
42623 reason in stop replies. @xref{swbreak stop reason}, for details.
42624
42625 @item hwbreak
42626 This feature indicates whether @value{GDBN} supports the hwbreak stop
42627 reason in stop replies. @xref{swbreak stop reason}, for details.
42628
42629 @item fork-events
42630 This feature indicates whether @value{GDBN} supports fork event
42631 extensions to the remote protocol. @value{GDBN} does not use such
42632 extensions unless the stub also reports that it supports them by
42633 including @samp{fork-events+} in its @samp{qSupported} reply.
42634
42635 @item vfork-events
42636 This feature indicates whether @value{GDBN} supports vfork event
42637 extensions to the remote protocol. @value{GDBN} does not use such
42638 extensions unless the stub also reports that it supports them by
42639 including @samp{vfork-events+} in its @samp{qSupported} reply.
42640
42641 @item exec-events
42642 This feature indicates whether @value{GDBN} supports exec event
42643 extensions to the remote protocol. @value{GDBN} does not use such
42644 extensions unless the stub also reports that it supports them by
42645 including @samp{exec-events+} in its @samp{qSupported} reply.
42646
42647 @item vContSupported
42648 This feature indicates whether @value{GDBN} wants to know the
42649 supported actions in the reply to @samp{vCont?} packet.
42650 @end table
42651
42652 Stubs should ignore any unknown values for
42653 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
42654 packet supports receiving packets of unlimited length (earlier
42655 versions of @value{GDBN} may reject overly long responses). Additional values
42656 for @var{gdbfeature} may be defined in the future to let the stub take
42657 advantage of new features in @value{GDBN}, e.g.@: incompatible
42658 improvements in the remote protocol---the @samp{multiprocess} feature is
42659 an example of such a feature. The stub's reply should be independent
42660 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
42661 describes all the features it supports, and then the stub replies with
42662 all the features it supports.
42663
42664 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
42665 responses, as long as each response uses one of the standard forms.
42666
42667 Some features are flags. A stub which supports a flag feature
42668 should respond with a @samp{+} form response. Other features
42669 require values, and the stub should respond with an @samp{=}
42670 form response.
42671
42672 Each feature has a default value, which @value{GDBN} will use if
42673 @samp{qSupported} is not available or if the feature is not mentioned
42674 in the @samp{qSupported} response. The default values are fixed; a
42675 stub is free to omit any feature responses that match the defaults.
42676
42677 Not all features can be probed, but for those which can, the probing
42678 mechanism is useful: in some cases, a stub's internal
42679 architecture may not allow the protocol layer to know some information
42680 about the underlying target in advance. This is especially common in
42681 stubs which may be configured for multiple targets.
42682
42683 These are the currently defined stub features and their properties:
42684
42685 @multitable @columnfractions 0.35 0.2 0.12 0.2
42686 @c NOTE: The first row should be @headitem, but we do not yet require
42687 @c a new enough version of Texinfo (4.7) to use @headitem.
42688 @item Feature Name
42689 @tab Value Required
42690 @tab Default
42691 @tab Probe Allowed
42692
42693 @item @samp{PacketSize}
42694 @tab Yes
42695 @tab @samp{-}
42696 @tab No
42697
42698 @item @samp{qXfer:auxv:read}
42699 @tab No
42700 @tab @samp{-}
42701 @tab Yes
42702
42703 @item @samp{qXfer:btrace:read}
42704 @tab No
42705 @tab @samp{-}
42706 @tab Yes
42707
42708 @item @samp{qXfer:btrace-conf:read}
42709 @tab No
42710 @tab @samp{-}
42711 @tab Yes
42712
42713 @item @samp{qXfer:exec-file:read}
42714 @tab No
42715 @tab @samp{-}
42716 @tab Yes
42717
42718 @item @samp{qXfer:features:read}
42719 @tab No
42720 @tab @samp{-}
42721 @tab Yes
42722
42723 @item @samp{qXfer:libraries:read}
42724 @tab No
42725 @tab @samp{-}
42726 @tab Yes
42727
42728 @item @samp{qXfer:libraries-svr4:read}
42729 @tab No
42730 @tab @samp{-}
42731 @tab Yes
42732
42733 @item @samp{augmented-libraries-svr4-read}
42734 @tab No
42735 @tab @samp{-}
42736 @tab No
42737
42738 @item @samp{qXfer:memory-map:read}
42739 @tab No
42740 @tab @samp{-}
42741 @tab Yes
42742
42743 @item @samp{qXfer:sdata:read}
42744 @tab No
42745 @tab @samp{-}
42746 @tab Yes
42747
42748 @item @samp{qXfer:siginfo:read}
42749 @tab No
42750 @tab @samp{-}
42751 @tab Yes
42752
42753 @item @samp{qXfer:siginfo:write}
42754 @tab No
42755 @tab @samp{-}
42756 @tab Yes
42757
42758 @item @samp{qXfer:threads:read}
42759 @tab No
42760 @tab @samp{-}
42761 @tab Yes
42762
42763 @item @samp{qXfer:traceframe-info:read}
42764 @tab No
42765 @tab @samp{-}
42766 @tab Yes
42767
42768 @item @samp{qXfer:uib:read}
42769 @tab No
42770 @tab @samp{-}
42771 @tab Yes
42772
42773 @item @samp{qXfer:fdpic:read}
42774 @tab No
42775 @tab @samp{-}
42776 @tab Yes
42777
42778 @item @samp{Qbtrace:off}
42779 @tab Yes
42780 @tab @samp{-}
42781 @tab Yes
42782
42783 @item @samp{Qbtrace:bts}
42784 @tab Yes
42785 @tab @samp{-}
42786 @tab Yes
42787
42788 @item @samp{Qbtrace:pt}
42789 @tab Yes
42790 @tab @samp{-}
42791 @tab Yes
42792
42793 @item @samp{Qbtrace-conf:bts:size}
42794 @tab Yes
42795 @tab @samp{-}
42796 @tab Yes
42797
42798 @item @samp{Qbtrace-conf:pt:size}
42799 @tab Yes
42800 @tab @samp{-}
42801 @tab Yes
42802
42803 @item @samp{QNonStop}
42804 @tab No
42805 @tab @samp{-}
42806 @tab Yes
42807
42808 @item @samp{QCatchSyscalls}
42809 @tab No
42810 @tab @samp{-}
42811 @tab Yes
42812
42813 @item @samp{QPassSignals}
42814 @tab No
42815 @tab @samp{-}
42816 @tab Yes
42817
42818 @item @samp{QStartNoAckMode}
42819 @tab No
42820 @tab @samp{-}
42821 @tab Yes
42822
42823 @item @samp{multiprocess}
42824 @tab No
42825 @tab @samp{-}
42826 @tab No
42827
42828 @item @samp{ConditionalBreakpoints}
42829 @tab No
42830 @tab @samp{-}
42831 @tab No
42832
42833 @item @samp{ConditionalTracepoints}
42834 @tab No
42835 @tab @samp{-}
42836 @tab No
42837
42838 @item @samp{ReverseContinue}
42839 @tab No
42840 @tab @samp{-}
42841 @tab No
42842
42843 @item @samp{ReverseStep}
42844 @tab No
42845 @tab @samp{-}
42846 @tab No
42847
42848 @item @samp{TracepointSource}
42849 @tab No
42850 @tab @samp{-}
42851 @tab No
42852
42853 @item @samp{QAgent}
42854 @tab No
42855 @tab @samp{-}
42856 @tab No
42857
42858 @item @samp{QAllow}
42859 @tab No
42860 @tab @samp{-}
42861 @tab No
42862
42863 @item @samp{QDisableRandomization}
42864 @tab No
42865 @tab @samp{-}
42866 @tab No
42867
42868 @item @samp{EnableDisableTracepoints}
42869 @tab No
42870 @tab @samp{-}
42871 @tab No
42872
42873 @item @samp{QTBuffer:size}
42874 @tab No
42875 @tab @samp{-}
42876 @tab No
42877
42878 @item @samp{tracenz}
42879 @tab No
42880 @tab @samp{-}
42881 @tab No
42882
42883 @item @samp{BreakpointCommands}
42884 @tab No
42885 @tab @samp{-}
42886 @tab No
42887
42888 @item @samp{swbreak}
42889 @tab No
42890 @tab @samp{-}
42891 @tab No
42892
42893 @item @samp{hwbreak}
42894 @tab No
42895 @tab @samp{-}
42896 @tab No
42897
42898 @item @samp{fork-events}
42899 @tab No
42900 @tab @samp{-}
42901 @tab No
42902
42903 @item @samp{vfork-events}
42904 @tab No
42905 @tab @samp{-}
42906 @tab No
42907
42908 @item @samp{exec-events}
42909 @tab No
42910 @tab @samp{-}
42911 @tab No
42912
42913 @item @samp{QThreadEvents}
42914 @tab No
42915 @tab @samp{-}
42916 @tab No
42917
42918 @item @samp{no-resumed}
42919 @tab No
42920 @tab @samp{-}
42921 @tab No
42922
42923 @item @samp{memory-tagging}
42924 @tab No
42925 @tab @samp{-}
42926 @tab No
42927
42928 @end multitable
42929
42930 These are the currently defined stub features, in more detail:
42931
42932 @table @samp
42933 @cindex packet size, remote protocol
42934 @item PacketSize=@var{bytes}
42935 The remote stub can accept packets up to at least @var{bytes} in
42936 length. @value{GDBN} will send packets up to this size for bulk
42937 transfers, and will never send larger packets. This is a limit on the
42938 data characters in the packet, including the frame and checksum.
42939 There is no trailing NUL byte in a remote protocol packet; if the stub
42940 stores packets in a NUL-terminated format, it should allow an extra
42941 byte in its buffer for the NUL. If this stub feature is not supported,
42942 @value{GDBN} guesses based on the size of the @samp{g} packet response.
42943
42944 @item qXfer:auxv:read
42945 The remote stub understands the @samp{qXfer:auxv:read} packet
42946 (@pxref{qXfer auxiliary vector read}).
42947
42948 @item qXfer:btrace:read
42949 The remote stub understands the @samp{qXfer:btrace:read}
42950 packet (@pxref{qXfer btrace read}).
42951
42952 @item qXfer:btrace-conf:read
42953 The remote stub understands the @samp{qXfer:btrace-conf:read}
42954 packet (@pxref{qXfer btrace-conf read}).
42955
42956 @item qXfer:exec-file:read
42957 The remote stub understands the @samp{qXfer:exec-file:read} packet
42958 (@pxref{qXfer executable filename read}).
42959
42960 @item qXfer:features:read
42961 The remote stub understands the @samp{qXfer:features:read} packet
42962 (@pxref{qXfer target description read}).
42963
42964 @item qXfer:libraries:read
42965 The remote stub understands the @samp{qXfer:libraries:read} packet
42966 (@pxref{qXfer library list read}).
42967
42968 @item qXfer:libraries-svr4:read
42969 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
42970 (@pxref{qXfer svr4 library list read}).
42971
42972 @item augmented-libraries-svr4-read
42973 The remote stub understands the augmented form of the
42974 @samp{qXfer:libraries-svr4:read} packet
42975 (@pxref{qXfer svr4 library list read}).
42976
42977 @item qXfer:memory-map:read
42978 The remote stub understands the @samp{qXfer:memory-map:read} packet
42979 (@pxref{qXfer memory map read}).
42980
42981 @item qXfer:sdata:read
42982 The remote stub understands the @samp{qXfer:sdata:read} packet
42983 (@pxref{qXfer sdata read}).
42984
42985 @item qXfer:siginfo:read
42986 The remote stub understands the @samp{qXfer:siginfo:read} packet
42987 (@pxref{qXfer siginfo read}).
42988
42989 @item qXfer:siginfo:write
42990 The remote stub understands the @samp{qXfer:siginfo:write} packet
42991 (@pxref{qXfer siginfo write}).
42992
42993 @item qXfer:threads:read
42994 The remote stub understands the @samp{qXfer:threads:read} packet
42995 (@pxref{qXfer threads read}).
42996
42997 @item qXfer:traceframe-info:read
42998 The remote stub understands the @samp{qXfer:traceframe-info:read}
42999 packet (@pxref{qXfer traceframe info read}).
43000
43001 @item qXfer:uib:read
43002 The remote stub understands the @samp{qXfer:uib:read}
43003 packet (@pxref{qXfer unwind info block}).
43004
43005 @item qXfer:fdpic:read
43006 The remote stub understands the @samp{qXfer:fdpic:read}
43007 packet (@pxref{qXfer fdpic loadmap read}).
43008
43009 @item QNonStop
43010 The remote stub understands the @samp{QNonStop} packet
43011 (@pxref{QNonStop}).
43012
43013 @item QCatchSyscalls
43014 The remote stub understands the @samp{QCatchSyscalls} packet
43015 (@pxref{QCatchSyscalls}).
43016
43017 @item QPassSignals
43018 The remote stub understands the @samp{QPassSignals} packet
43019 (@pxref{QPassSignals}).
43020
43021 @item QStartNoAckMode
43022 The remote stub understands the @samp{QStartNoAckMode} packet and
43023 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
43024
43025 @item multiprocess
43026 @anchor{multiprocess extensions}
43027 @cindex multiprocess extensions, in remote protocol
43028 The remote stub understands the multiprocess extensions to the remote
43029 protocol syntax. The multiprocess extensions affect the syntax of
43030 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
43031 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
43032 replies. Note that reporting this feature indicates support for the
43033 syntactic extensions only, not that the stub necessarily supports
43034 debugging of more than one process at a time. The stub must not use
43035 multiprocess extensions in packet replies unless @value{GDBN} has also
43036 indicated it supports them in its @samp{qSupported} request.
43037
43038 @item qXfer:osdata:read
43039 The remote stub understands the @samp{qXfer:osdata:read} packet
43040 ((@pxref{qXfer osdata read}).
43041
43042 @item ConditionalBreakpoints
43043 The target accepts and implements evaluation of conditional expressions
43044 defined for breakpoints. The target will only report breakpoint triggers
43045 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
43046
43047 @item ConditionalTracepoints
43048 The remote stub accepts and implements conditional expressions defined
43049 for tracepoints (@pxref{Tracepoint Conditions}).
43050
43051 @item ReverseContinue
43052 The remote stub accepts and implements the reverse continue packet
43053 (@pxref{bc}).
43054
43055 @item ReverseStep
43056 The remote stub accepts and implements the reverse step packet
43057 (@pxref{bs}).
43058
43059 @item TracepointSource
43060 The remote stub understands the @samp{QTDPsrc} packet that supplies
43061 the source form of tracepoint definitions.
43062
43063 @item QAgent
43064 The remote stub understands the @samp{QAgent} packet.
43065
43066 @item QAllow
43067 The remote stub understands the @samp{QAllow} packet.
43068
43069 @item QDisableRandomization
43070 The remote stub understands the @samp{QDisableRandomization} packet.
43071
43072 @item StaticTracepoint
43073 @cindex static tracepoints, in remote protocol
43074 The remote stub supports static tracepoints.
43075
43076 @item InstallInTrace
43077 @anchor{install tracepoint in tracing}
43078 The remote stub supports installing tracepoint in tracing.
43079
43080 @item EnableDisableTracepoints
43081 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
43082 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
43083 to be enabled and disabled while a trace experiment is running.
43084
43085 @item QTBuffer:size
43086 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
43087 packet that allows to change the size of the trace buffer.
43088
43089 @item tracenz
43090 @cindex string tracing, in remote protocol
43091 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
43092 See @ref{Bytecode Descriptions} for details about the bytecode.
43093
43094 @item BreakpointCommands
43095 @cindex breakpoint commands, in remote protocol
43096 The remote stub supports running a breakpoint's command list itself,
43097 rather than reporting the hit to @value{GDBN}.
43098
43099 @item Qbtrace:off
43100 The remote stub understands the @samp{Qbtrace:off} packet.
43101
43102 @item Qbtrace:bts
43103 The remote stub understands the @samp{Qbtrace:bts} packet.
43104
43105 @item Qbtrace:pt
43106 The remote stub understands the @samp{Qbtrace:pt} packet.
43107
43108 @item Qbtrace-conf:bts:size
43109 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
43110
43111 @item Qbtrace-conf:pt:size
43112 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
43113
43114 @item swbreak
43115 The remote stub reports the @samp{swbreak} stop reason for memory
43116 breakpoints.
43117
43118 @item hwbreak
43119 The remote stub reports the @samp{hwbreak} stop reason for hardware
43120 breakpoints.
43121
43122 @item fork-events
43123 The remote stub reports the @samp{fork} stop reason for fork events.
43124
43125 @item vfork-events
43126 The remote stub reports the @samp{vfork} stop reason for vfork events
43127 and vforkdone events.
43128
43129 @item exec-events
43130 The remote stub reports the @samp{exec} stop reason for exec events.
43131
43132 @item vContSupported
43133 The remote stub reports the supported actions in the reply to
43134 @samp{vCont?} packet.
43135
43136 @item QThreadEvents
43137 The remote stub understands the @samp{QThreadEvents} packet.
43138
43139 @item no-resumed
43140 The remote stub reports the @samp{N} stop reply.
43141
43142
43143 @item memory-tagging
43144 The remote stub supports and implements the required memory tagging
43145 functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and
43146 @samp{QMemTags} (@pxref{QMemTags}) packets.
43147
43148 For AArch64 GNU/Linux systems, this feature also requires access to the
43149 @file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected.
43150 This is done via the @samp{vFile} requests.
43151
43152 @end table
43153
43154 @item qSymbol::
43155 @cindex symbol lookup, remote request
43156 @cindex @samp{qSymbol} packet
43157 Notify the target that @value{GDBN} is prepared to serve symbol lookup
43158 requests. Accept requests from the target for the values of symbols.
43159
43160 Reply:
43161 @table @samp
43162 @item OK
43163 The target does not need to look up any (more) symbols.
43164 @item qSymbol:@var{sym_name}
43165 The target requests the value of symbol @var{sym_name} (hex encoded).
43166 @value{GDBN} may provide the value by using the
43167 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
43168 below.
43169 @end table
43170
43171 @item qSymbol:@var{sym_value}:@var{sym_name}
43172 Set the value of @var{sym_name} to @var{sym_value}.
43173
43174 @var{sym_name} (hex encoded) is the name of a symbol whose value the
43175 target has previously requested.
43176
43177 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
43178 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
43179 will be empty.
43180
43181 Reply:
43182 @table @samp
43183 @item OK
43184 The target does not need to look up any (more) symbols.
43185 @item qSymbol:@var{sym_name}
43186 The target requests the value of a new symbol @var{sym_name} (hex
43187 encoded). @value{GDBN} will continue to supply the values of symbols
43188 (if available), until the target ceases to request them.
43189 @end table
43190
43191 @item qTBuffer
43192 @itemx QTBuffer
43193 @itemx QTDisconnected
43194 @itemx QTDP
43195 @itemx QTDPsrc
43196 @itemx QTDV
43197 @itemx qTfP
43198 @itemx qTfV
43199 @itemx QTFrame
43200 @itemx qTMinFTPILen
43201
43202 @xref{Tracepoint Packets}.
43203
43204 @anchor{qThreadExtraInfo}
43205 @item qThreadExtraInfo,@var{thread-id}
43206 @cindex thread attributes info, remote request
43207 @cindex @samp{qThreadExtraInfo} packet
43208 Obtain from the target OS a printable string description of thread
43209 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
43210 for the forms of @var{thread-id}. This
43211 string may contain anything that the target OS thinks is interesting
43212 for @value{GDBN} to tell the user about the thread. The string is
43213 displayed in @value{GDBN}'s @code{info threads} display. Some
43214 examples of possible thread extra info strings are @samp{Runnable}, or
43215 @samp{Blocked on Mutex}.
43216
43217 Reply:
43218 @table @samp
43219 @item @var{XX}@dots{}
43220 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
43221 comprising the printable string containing the extra information about
43222 the thread's attributes.
43223 @end table
43224
43225 (Note that the @code{qThreadExtraInfo} packet's name is separated from
43226 the command by a @samp{,}, not a @samp{:}, contrary to the naming
43227 conventions above. Please don't use this packet as a model for new
43228 packets.)
43229
43230 @item QTNotes
43231 @itemx qTP
43232 @itemx QTSave
43233 @itemx qTsP
43234 @itemx qTsV
43235 @itemx QTStart
43236 @itemx QTStop
43237 @itemx QTEnable
43238 @itemx QTDisable
43239 @itemx QTinit
43240 @itemx QTro
43241 @itemx qTStatus
43242 @itemx qTV
43243 @itemx qTfSTM
43244 @itemx qTsSTM
43245 @itemx qTSTMat
43246 @xref{Tracepoint Packets}.
43247
43248 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
43249 @cindex read special object, remote request
43250 @cindex @samp{qXfer} packet
43251 @anchor{qXfer read}
43252 Read uninterpreted bytes from the target's special data area
43253 identified by the keyword @var{object}. Request @var{length} bytes
43254 starting at @var{offset} bytes into the data. The content and
43255 encoding of @var{annex} is specific to @var{object}; it can supply
43256 additional details about what data to access.
43257
43258 Reply:
43259 @table @samp
43260 @item m @var{data}
43261 Data @var{data} (@pxref{Binary Data}) has been read from the
43262 target. There may be more data at a higher address (although
43263 it is permitted to return @samp{m} even for the last valid
43264 block of data, as long as at least one byte of data was read).
43265 It is possible for @var{data} to have fewer bytes than the @var{length} in the
43266 request.
43267
43268 @item l @var{data}
43269 Data @var{data} (@pxref{Binary Data}) has been read from the target.
43270 There is no more data to be read. It is possible for @var{data} to
43271 have fewer bytes than the @var{length} in the request.
43272
43273 @item l
43274 The @var{offset} in the request is at the end of the data.
43275 There is no more data to be read.
43276
43277 @item E00
43278 The request was malformed, or @var{annex} was invalid.
43279
43280 @item E @var{nn}
43281 The offset was invalid, or there was an error encountered reading the data.
43282 The @var{nn} part is a hex-encoded @code{errno} value.
43283
43284 @item @w{}
43285 An empty reply indicates the @var{object} string was not recognized by
43286 the stub, or that the object does not support reading.
43287 @end table
43288
43289 Here are the specific requests of this form defined so far. All the
43290 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
43291 formats, listed above.
43292
43293 @table @samp
43294 @item qXfer:auxv:read::@var{offset},@var{length}
43295 @anchor{qXfer auxiliary vector read}
43296 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
43297 auxiliary vector}. Note @var{annex} must be empty.
43298
43299 This packet is not probed by default; the remote stub must request it,
43300 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43301
43302 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
43303 @anchor{qXfer btrace read}
43304
43305 Return a description of the current branch trace.
43306 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
43307 packet may have one of the following values:
43308
43309 @table @code
43310 @item all
43311 Returns all available branch trace.
43312
43313 @item new
43314 Returns all available branch trace if the branch trace changed since
43315 the last read request.
43316
43317 @item delta
43318 Returns the new branch trace since the last read request. Adds a new
43319 block to the end of the trace that begins at zero and ends at the source
43320 location of the first branch in the trace buffer. This extra block is
43321 used to stitch traces together.
43322
43323 If the trace buffer overflowed, returns an error indicating the overflow.
43324 @end table
43325
43326 This packet is not probed by default; the remote stub must request it
43327 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43328
43329 @item qXfer:btrace-conf:read::@var{offset},@var{length}
43330 @anchor{qXfer btrace-conf read}
43331
43332 Return a description of the current branch trace configuration.
43333 @xref{Branch Trace Configuration Format}.
43334
43335 This packet is not probed by default; the remote stub must request it
43336 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43337
43338 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
43339 @anchor{qXfer executable filename read}
43340 Return the full absolute name of the file that was executed to create
43341 a process running on the remote system. The annex specifies the
43342 numeric process ID of the process to query, encoded as a hexadecimal
43343 number. If the annex part is empty the remote stub should return the
43344 filename corresponding to the currently executing process.
43345
43346 This packet is not probed by default; the remote stub must request it,
43347 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43348
43349 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
43350 @anchor{qXfer target description read}
43351 Access the @dfn{target description}. @xref{Target Descriptions}. The
43352 annex specifies which XML document to access. The main description is
43353 always loaded from the @samp{target.xml} annex.
43354
43355 This packet is not probed by default; the remote stub must request it,
43356 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43357
43358 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
43359 @anchor{qXfer library list read}
43360 Access the target's list of loaded libraries. @xref{Library List Format}.
43361 The annex part of the generic @samp{qXfer} packet must be empty
43362 (@pxref{qXfer read}).
43363
43364 Targets which maintain a list of libraries in the program's memory do
43365 not need to implement this packet; it is designed for platforms where
43366 the operating system manages the list of loaded libraries.
43367
43368 This packet is not probed by default; the remote stub must request it,
43369 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43370
43371 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
43372 @anchor{qXfer svr4 library list read}
43373 Access the target's list of loaded libraries when the target is an SVR4
43374 platform. @xref{Library List Format for SVR4 Targets}. The annex part
43375 of the generic @samp{qXfer} packet must be empty unless the remote
43376 stub indicated it supports the augmented form of this packet
43377 by supplying an appropriate @samp{qSupported} response
43378 (@pxref{qXfer read}, @ref{qSupported}).
43379
43380 This packet is optional for better performance on SVR4 targets.
43381 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
43382
43383 This packet is not probed by default; the remote stub must request it,
43384 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43385
43386 If the remote stub indicates it supports the augmented form of this
43387 packet then the annex part of the generic @samp{qXfer} packet may
43388 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
43389 arguments. The currently supported arguments are:
43390
43391 @table @code
43392 @item start=@var{address}
43393 A hexadecimal number specifying the address of the @samp{struct
43394 link_map} to start reading the library list from. If unset or zero
43395 then the first @samp{struct link_map} in the library list will be
43396 chosen as the starting point.
43397
43398 @item prev=@var{address}
43399 A hexadecimal number specifying the address of the @samp{struct
43400 link_map} immediately preceding the @samp{struct link_map}
43401 specified by the @samp{start} argument. If unset or zero then
43402 the remote stub will expect that no @samp{struct link_map}
43403 exists prior to the starting point.
43404
43405 @end table
43406
43407 Arguments that are not understood by the remote stub will be silently
43408 ignored.
43409
43410 @item qXfer:memory-map:read::@var{offset},@var{length}
43411 @anchor{qXfer memory map read}
43412 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
43413 annex part of the generic @samp{qXfer} packet must be empty
43414 (@pxref{qXfer read}).
43415
43416 This packet is not probed by default; the remote stub must request it,
43417 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43418
43419 @item qXfer:sdata:read::@var{offset},@var{length}
43420 @anchor{qXfer sdata read}
43421
43422 Read contents of the extra collected static tracepoint marker
43423 information. The annex part of the generic @samp{qXfer} packet must
43424 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
43425 Action Lists}.
43426
43427 This packet is not probed by default; the remote stub must request it,
43428 by supplying an appropriate @samp{qSupported} response
43429 (@pxref{qSupported}).
43430
43431 @item qXfer:siginfo:read::@var{offset},@var{length}
43432 @anchor{qXfer siginfo read}
43433 Read contents of the extra signal information on the target
43434 system. The annex part of the generic @samp{qXfer} packet must be
43435 empty (@pxref{qXfer read}).
43436
43437 This packet is not probed by default; the remote stub must request it,
43438 by supplying an appropriate @samp{qSupported} response
43439 (@pxref{qSupported}).
43440
43441 @item qXfer:threads:read::@var{offset},@var{length}
43442 @anchor{qXfer threads read}
43443 Access the list of threads on target. @xref{Thread List Format}. The
43444 annex part of the generic @samp{qXfer} packet must be empty
43445 (@pxref{qXfer read}).
43446
43447 This packet is not probed by default; the remote stub must request it,
43448 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43449
43450 @item qXfer:traceframe-info:read::@var{offset},@var{length}
43451 @anchor{qXfer traceframe info read}
43452
43453 Return a description of the current traceframe's contents.
43454 @xref{Traceframe Info Format}. The annex part of the generic
43455 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
43456
43457 This packet is not probed by default; the remote stub must request it,
43458 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43459
43460 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
43461 @anchor{qXfer unwind info block}
43462
43463 Return the unwind information block for @var{pc}. This packet is used
43464 on OpenVMS/ia64 to ask the kernel unwind information.
43465
43466 This packet is not probed by default.
43467
43468 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
43469 @anchor{qXfer fdpic loadmap read}
43470 Read contents of @code{loadmap}s on the target system. The
43471 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
43472 executable @code{loadmap} or interpreter @code{loadmap} to read.
43473
43474 This packet is not probed by default; the remote stub must request it,
43475 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43476
43477 @item qXfer:osdata:read::@var{offset},@var{length}
43478 @anchor{qXfer osdata read}
43479 Access the target's @dfn{operating system information}.
43480 @xref{Operating System Information}.
43481
43482 @end table
43483
43484 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
43485 @cindex write data into object, remote request
43486 @anchor{qXfer write}
43487 Write uninterpreted bytes into the target's special data area
43488 identified by the keyword @var{object}, starting at @var{offset} bytes
43489 into the data. The binary-encoded data (@pxref{Binary Data}) to be
43490 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
43491 is specific to @var{object}; it can supply additional details about what data
43492 to access.
43493
43494 Reply:
43495 @table @samp
43496 @item @var{nn}
43497 @var{nn} (hex encoded) is the number of bytes written.
43498 This may be fewer bytes than supplied in the request.
43499
43500 @item E00
43501 The request was malformed, or @var{annex} was invalid.
43502
43503 @item E @var{nn}
43504 The offset was invalid, or there was an error encountered writing the data.
43505 The @var{nn} part is a hex-encoded @code{errno} value.
43506
43507 @item @w{}
43508 An empty reply indicates the @var{object} string was not
43509 recognized by the stub, or that the object does not support writing.
43510 @end table
43511
43512 Here are the specific requests of this form defined so far. All the
43513 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
43514 formats, listed above.
43515
43516 @table @samp
43517 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
43518 @anchor{qXfer siginfo write}
43519 Write @var{data} to the extra signal information on the target system.
43520 The annex part of the generic @samp{qXfer} packet must be
43521 empty (@pxref{qXfer write}).
43522
43523 This packet is not probed by default; the remote stub must request it,
43524 by supplying an appropriate @samp{qSupported} response
43525 (@pxref{qSupported}).
43526 @end table
43527
43528 @item qXfer:@var{object}:@var{operation}:@dots{}
43529 Requests of this form may be added in the future. When a stub does
43530 not recognize the @var{object} keyword, or its support for
43531 @var{object} does not recognize the @var{operation} keyword, the stub
43532 must respond with an empty packet.
43533
43534 @item qAttached:@var{pid}
43535 @cindex query attached, remote request
43536 @cindex @samp{qAttached} packet
43537 Return an indication of whether the remote server attached to an
43538 existing process or created a new process. When the multiprocess
43539 protocol extensions are supported (@pxref{multiprocess extensions}),
43540 @var{pid} is an integer in hexadecimal format identifying the target
43541 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
43542 the query packet will be simplified as @samp{qAttached}.
43543
43544 This query is used, for example, to know whether the remote process
43545 should be detached or killed when a @value{GDBN} session is ended with
43546 the @code{quit} command.
43547
43548 Reply:
43549 @table @samp
43550 @item 1
43551 The remote server attached to an existing process.
43552 @item 0
43553 The remote server created a new process.
43554 @item E @var{NN}
43555 A badly formed request or an error was encountered.
43556 @end table
43557
43558 @item Qbtrace:bts
43559 Enable branch tracing for the current thread using Branch Trace Store.
43560
43561 Reply:
43562 @table @samp
43563 @item OK
43564 Branch tracing has been enabled.
43565 @item E.errtext
43566 A badly formed request or an error was encountered.
43567 @end table
43568
43569 @item Qbtrace:pt
43570 Enable branch tracing for the current thread using Intel Processor Trace.
43571
43572 Reply:
43573 @table @samp
43574 @item OK
43575 Branch tracing has been enabled.
43576 @item E.errtext
43577 A badly formed request or an error was encountered.
43578 @end table
43579
43580 @item Qbtrace:off
43581 Disable branch tracing for the current thread.
43582
43583 Reply:
43584 @table @samp
43585 @item OK
43586 Branch tracing has been disabled.
43587 @item E.errtext
43588 A badly formed request or an error was encountered.
43589 @end table
43590
43591 @item Qbtrace-conf:bts:size=@var{value}
43592 Set the requested ring buffer size for new threads that use the
43593 btrace recording method in bts format.
43594
43595 Reply:
43596 @table @samp
43597 @item OK
43598 The ring buffer size has been set.
43599 @item E.errtext
43600 A badly formed request or an error was encountered.
43601 @end table
43602
43603 @item Qbtrace-conf:pt:size=@var{value}
43604 Set the requested ring buffer size for new threads that use the
43605 btrace recording method in pt format.
43606
43607 Reply:
43608 @table @samp
43609 @item OK
43610 The ring buffer size has been set.
43611 @item E.errtext
43612 A badly formed request or an error was encountered.
43613 @end table
43614
43615 @end table
43616
43617 @node Architecture-Specific Protocol Details
43618 @section Architecture-Specific Protocol Details
43619
43620 This section describes how the remote protocol is applied to specific
43621 target architectures. Also see @ref{Standard Target Features}, for
43622 details of XML target descriptions for each architecture.
43623
43624 @menu
43625 * ARM-Specific Protocol Details::
43626 * MIPS-Specific Protocol Details::
43627 @end menu
43628
43629 @node ARM-Specific Protocol Details
43630 @subsection @acronym{ARM}-specific Protocol Details
43631
43632 @menu
43633 * ARM Breakpoint Kinds::
43634 * ARM Memory Tag Types::
43635 @end menu
43636
43637 @node ARM Breakpoint Kinds
43638 @subsubsection @acronym{ARM} Breakpoint Kinds
43639 @cindex breakpoint kinds, @acronym{ARM}
43640
43641 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
43642
43643 @table @r
43644
43645 @item 2
43646 16-bit Thumb mode breakpoint.
43647
43648 @item 3
43649 32-bit Thumb mode (Thumb-2) breakpoint.
43650
43651 @item 4
43652 32-bit @acronym{ARM} mode breakpoint.
43653
43654 @end table
43655
43656 @node ARM Memory Tag Types
43657 @subsubsection @acronym{ARM} Memory Tag Types
43658 @cindex memory tag types, @acronym{ARM}
43659
43660 These memory tag types are defined for the @samp{qMemTag} and @samp{QMemTag}
43661 packets.
43662
43663 @table @r
43664
43665 @item 0
43666 MTE logical tag
43667
43668 @item 1
43669 MTE allocation tag
43670
43671 @end table
43672
43673 @node MIPS-Specific Protocol Details
43674 @subsection @acronym{MIPS}-specific Protocol Details
43675
43676 @menu
43677 * MIPS Register packet Format::
43678 * MIPS Breakpoint Kinds::
43679 @end menu
43680
43681 @node MIPS Register packet Format
43682 @subsubsection @acronym{MIPS} Register Packet Format
43683 @cindex register packet format, @acronym{MIPS}
43684
43685 The following @code{g}/@code{G} packets have previously been defined.
43686 In the below, some thirty-two bit registers are transferred as
43687 sixty-four bits. Those registers should be zero/sign extended (which?)
43688 to fill the space allocated. Register bytes are transferred in target
43689 byte order. The two nibbles within a register byte are transferred
43690 most-significant -- least-significant.
43691
43692 @table @r
43693
43694 @item MIPS32
43695 All registers are transferred as thirty-two bit quantities in the order:
43696 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
43697 registers; fsr; fir; fp.
43698
43699 @item MIPS64
43700 All registers are transferred as sixty-four bit quantities (including
43701 thirty-two bit registers such as @code{sr}). The ordering is the same
43702 as @code{MIPS32}.
43703
43704 @end table
43705
43706 @node MIPS Breakpoint Kinds
43707 @subsubsection @acronym{MIPS} Breakpoint Kinds
43708 @cindex breakpoint kinds, @acronym{MIPS}
43709
43710 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
43711
43712 @table @r
43713
43714 @item 2
43715 16-bit @acronym{MIPS16} mode breakpoint.
43716
43717 @item 3
43718 16-bit @acronym{microMIPS} mode breakpoint.
43719
43720 @item 4
43721 32-bit standard @acronym{MIPS} mode breakpoint.
43722
43723 @item 5
43724 32-bit @acronym{microMIPS} mode breakpoint.
43725
43726 @end table
43727
43728 @node Tracepoint Packets
43729 @section Tracepoint Packets
43730 @cindex tracepoint packets
43731 @cindex packets, tracepoint
43732
43733 Here we describe the packets @value{GDBN} uses to implement
43734 tracepoints (@pxref{Tracepoints}).
43735
43736 @table @samp
43737
43738 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
43739 @cindex @samp{QTDP} packet
43740 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
43741 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
43742 the tracepoint is disabled. The @var{step} gives the tracepoint's step
43743 count, and @var{pass} gives its pass count. If an @samp{F} is present,
43744 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
43745 the number of bytes that the target should copy elsewhere to make room
43746 for the tracepoint. If an @samp{X} is present, it introduces a
43747 tracepoint condition, which consists of a hexadecimal length, followed
43748 by a comma and hex-encoded bytes, in a manner similar to action
43749 encodings as described below. If the trailing @samp{-} is present,
43750 further @samp{QTDP} packets will follow to specify this tracepoint's
43751 actions.
43752
43753 Replies:
43754 @table @samp
43755 @item OK
43756 The packet was understood and carried out.
43757 @item qRelocInsn
43758 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
43759 @item @w{}
43760 The packet was not recognized.
43761 @end table
43762
43763 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
43764 Define actions to be taken when a tracepoint is hit. The @var{n} and
43765 @var{addr} must be the same as in the initial @samp{QTDP} packet for
43766 this tracepoint. This packet may only be sent immediately after
43767 another @samp{QTDP} packet that ended with a @samp{-}. If the
43768 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
43769 specifying more actions for this tracepoint.
43770
43771 In the series of action packets for a given tracepoint, at most one
43772 can have an @samp{S} before its first @var{action}. If such a packet
43773 is sent, it and the following packets define ``while-stepping''
43774 actions. Any prior packets define ordinary actions --- that is, those
43775 taken when the tracepoint is first hit. If no action packet has an
43776 @samp{S}, then all the packets in the series specify ordinary
43777 tracepoint actions.
43778
43779 The @samp{@var{action}@dots{}} portion of the packet is a series of
43780 actions, concatenated without separators. Each action has one of the
43781 following forms:
43782
43783 @table @samp
43784
43785 @item R @var{mask}
43786 Collect the registers whose bits are set in @var{mask},
43787 a hexadecimal number whose @var{i}'th bit is set if register number
43788 @var{i} should be collected. (The least significant bit is numbered
43789 zero.) Note that @var{mask} may be any number of digits long; it may
43790 not fit in a 32-bit word.
43791
43792 @item M @var{basereg},@var{offset},@var{len}
43793 Collect @var{len} bytes of memory starting at the address in register
43794 number @var{basereg}, plus @var{offset}. If @var{basereg} is
43795 @samp{-1}, then the range has a fixed address: @var{offset} is the
43796 address of the lowest byte to collect. The @var{basereg},
43797 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
43798 values (the @samp{-1} value for @var{basereg} is a special case).
43799
43800 @item X @var{len},@var{expr}
43801 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
43802 it directs. The agent expression @var{expr} is as described in
43803 @ref{Agent Expressions}. Each byte of the expression is encoded as a
43804 two-digit hex number in the packet; @var{len} is the number of bytes
43805 in the expression (and thus one-half the number of hex digits in the
43806 packet).
43807
43808 @end table
43809
43810 Any number of actions may be packed together in a single @samp{QTDP}
43811 packet, as long as the packet does not exceed the maximum packet
43812 length (400 bytes, for many stubs). There may be only one @samp{R}
43813 action per tracepoint, and it must precede any @samp{M} or @samp{X}
43814 actions. Any registers referred to by @samp{M} and @samp{X} actions
43815 must be collected by a preceding @samp{R} action. (The
43816 ``while-stepping'' actions are treated as if they were attached to a
43817 separate tracepoint, as far as these restrictions are concerned.)
43818
43819 Replies:
43820 @table @samp
43821 @item OK
43822 The packet was understood and carried out.
43823 @item qRelocInsn
43824 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
43825 @item @w{}
43826 The packet was not recognized.
43827 @end table
43828
43829 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
43830 @cindex @samp{QTDPsrc} packet
43831 Specify a source string of tracepoint @var{n} at address @var{addr}.
43832 This is useful to get accurate reproduction of the tracepoints
43833 originally downloaded at the beginning of the trace run. The @var{type}
43834 is the name of the tracepoint part, such as @samp{cond} for the
43835 tracepoint's conditional expression (see below for a list of types), while
43836 @var{bytes} is the string, encoded in hexadecimal.
43837
43838 @var{start} is the offset of the @var{bytes} within the overall source
43839 string, while @var{slen} is the total length of the source string.
43840 This is intended for handling source strings that are longer than will
43841 fit in a single packet.
43842 @c Add detailed example when this info is moved into a dedicated
43843 @c tracepoint descriptions section.
43844
43845 The available string types are @samp{at} for the location,
43846 @samp{cond} for the conditional, and @samp{cmd} for an action command.
43847 @value{GDBN} sends a separate packet for each command in the action
43848 list, in the same order in which the commands are stored in the list.
43849
43850 The target does not need to do anything with source strings except
43851 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
43852 query packets.
43853
43854 Although this packet is optional, and @value{GDBN} will only send it
43855 if the target replies with @samp{TracepointSource} @xref{General
43856 Query Packets}, it makes both disconnected tracing and trace files
43857 much easier to use. Otherwise the user must be careful that the
43858 tracepoints in effect while looking at trace frames are identical to
43859 the ones in effect during the trace run; even a small discrepancy
43860 could cause @samp{tdump} not to work, or a particular trace frame not
43861 be found.
43862
43863 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
43864 @cindex define trace state variable, remote request
43865 @cindex @samp{QTDV} packet
43866 Create a new trace state variable, number @var{n}, with an initial
43867 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
43868 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
43869 the option of not using this packet for initial values of zero; the
43870 target should simply create the trace state variables as they are
43871 mentioned in expressions. The value @var{builtin} should be 1 (one)
43872 if the trace state variable is builtin and 0 (zero) if it is not builtin.
43873 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
43874 @samp{qTsV} packet had it set. The contents of @var{name} is the
43875 hex-encoded name (without the leading @samp{$}) of the trace state
43876 variable.
43877
43878 @item QTFrame:@var{n}
43879 @cindex @samp{QTFrame} packet
43880 Select the @var{n}'th tracepoint frame from the buffer, and use the
43881 register and memory contents recorded there to answer subsequent
43882 request packets from @value{GDBN}.
43883
43884 A successful reply from the stub indicates that the stub has found the
43885 requested frame. The response is a series of parts, concatenated
43886 without separators, describing the frame we selected. Each part has
43887 one of the following forms:
43888
43889 @table @samp
43890 @item F @var{f}
43891 The selected frame is number @var{n} in the trace frame buffer;
43892 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
43893 was no frame matching the criteria in the request packet.
43894
43895 @item T @var{t}
43896 The selected trace frame records a hit of tracepoint number @var{t};
43897 @var{t} is a hexadecimal number.
43898
43899 @end table
43900
43901 @item QTFrame:pc:@var{addr}
43902 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43903 currently selected frame whose PC is @var{addr};
43904 @var{addr} is a hexadecimal number.
43905
43906 @item QTFrame:tdp:@var{t}
43907 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43908 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
43909 is a hexadecimal number.
43910
43911 @item QTFrame:range:@var{start}:@var{end}
43912 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43913 currently selected frame whose PC is between @var{start} (inclusive)
43914 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
43915 numbers.
43916
43917 @item QTFrame:outside:@var{start}:@var{end}
43918 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
43919 frame @emph{outside} the given range of addresses (exclusive).
43920
43921 @item qTMinFTPILen
43922 @cindex @samp{qTMinFTPILen} packet
43923 This packet requests the minimum length of instruction at which a fast
43924 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
43925 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
43926 it depends on the target system being able to create trampolines in
43927 the first 64K of memory, which might or might not be possible for that
43928 system. So the reply to this packet will be 4 if it is able to
43929 arrange for that.
43930
43931 Replies:
43932
43933 @table @samp
43934 @item 0
43935 The minimum instruction length is currently unknown.
43936 @item @var{length}
43937 The minimum instruction length is @var{length}, where @var{length}
43938 is a hexadecimal number greater or equal to 1. A reply
43939 of 1 means that a fast tracepoint may be placed on any instruction
43940 regardless of size.
43941 @item E
43942 An error has occurred.
43943 @item @w{}
43944 An empty reply indicates that the request is not supported by the stub.
43945 @end table
43946
43947 @item QTStart
43948 @cindex @samp{QTStart} packet
43949 Begin the tracepoint experiment. Begin collecting data from
43950 tracepoint hits in the trace frame buffer. This packet supports the
43951 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
43952 instruction reply packet}).
43953
43954 @item QTStop
43955 @cindex @samp{QTStop} packet
43956 End the tracepoint experiment. Stop collecting trace frames.
43957
43958 @item QTEnable:@var{n}:@var{addr}
43959 @anchor{QTEnable}
43960 @cindex @samp{QTEnable} packet
43961 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
43962 experiment. If the tracepoint was previously disabled, then collection
43963 of data from it will resume.
43964
43965 @item QTDisable:@var{n}:@var{addr}
43966 @anchor{QTDisable}
43967 @cindex @samp{QTDisable} packet
43968 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
43969 experiment. No more data will be collected from the tracepoint unless
43970 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
43971
43972 @item QTinit
43973 @cindex @samp{QTinit} packet
43974 Clear the table of tracepoints, and empty the trace frame buffer.
43975
43976 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
43977 @cindex @samp{QTro} packet
43978 Establish the given ranges of memory as ``transparent''. The stub
43979 will answer requests for these ranges from memory's current contents,
43980 if they were not collected as part of the tracepoint hit.
43981
43982 @value{GDBN} uses this to mark read-only regions of memory, like those
43983 containing program code. Since these areas never change, they should
43984 still have the same contents they did when the tracepoint was hit, so
43985 there's no reason for the stub to refuse to provide their contents.
43986
43987 @item QTDisconnected:@var{value}
43988 @cindex @samp{QTDisconnected} packet
43989 Set the choice to what to do with the tracing run when @value{GDBN}
43990 disconnects from the target. A @var{value} of 1 directs the target to
43991 continue the tracing run, while 0 tells the target to stop tracing if
43992 @value{GDBN} is no longer in the picture.
43993
43994 @item qTStatus
43995 @cindex @samp{qTStatus} packet
43996 Ask the stub if there is a trace experiment running right now.
43997
43998 The reply has the form:
43999
44000 @table @samp
44001
44002 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
44003 @var{running} is a single digit @code{1} if the trace is presently
44004 running, or @code{0} if not. It is followed by semicolon-separated
44005 optional fields that an agent may use to report additional status.
44006
44007 @end table
44008
44009 If the trace is not running, the agent may report any of several
44010 explanations as one of the optional fields:
44011
44012 @table @samp
44013
44014 @item tnotrun:0
44015 No trace has been run yet.
44016
44017 @item tstop[:@var{text}]:0
44018 The trace was stopped by a user-originated stop command. The optional
44019 @var{text} field is a user-supplied string supplied as part of the
44020 stop command (for instance, an explanation of why the trace was
44021 stopped manually). It is hex-encoded.
44022
44023 @item tfull:0
44024 The trace stopped because the trace buffer filled up.
44025
44026 @item tdisconnected:0
44027 The trace stopped because @value{GDBN} disconnected from the target.
44028
44029 @item tpasscount:@var{tpnum}
44030 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
44031
44032 @item terror:@var{text}:@var{tpnum}
44033 The trace stopped because tracepoint @var{tpnum} had an error. The
44034 string @var{text} is available to describe the nature of the error
44035 (for instance, a divide by zero in the condition expression); it
44036 is hex encoded.
44037
44038 @item tunknown:0
44039 The trace stopped for some other reason.
44040
44041 @end table
44042
44043 Additional optional fields supply statistical and other information.
44044 Although not required, they are extremely useful for users monitoring
44045 the progress of a trace run. If a trace has stopped, and these
44046 numbers are reported, they must reflect the state of the just-stopped
44047 trace.
44048
44049 @table @samp
44050
44051 @item tframes:@var{n}
44052 The number of trace frames in the buffer.
44053
44054 @item tcreated:@var{n}
44055 The total number of trace frames created during the run. This may
44056 be larger than the trace frame count, if the buffer is circular.
44057
44058 @item tsize:@var{n}
44059 The total size of the trace buffer, in bytes.
44060
44061 @item tfree:@var{n}
44062 The number of bytes still unused in the buffer.
44063
44064 @item circular:@var{n}
44065 The value of the circular trace buffer flag. @code{1} means that the
44066 trace buffer is circular and old trace frames will be discarded if
44067 necessary to make room, @code{0} means that the trace buffer is linear
44068 and may fill up.
44069
44070 @item disconn:@var{n}
44071 The value of the disconnected tracing flag. @code{1} means that
44072 tracing will continue after @value{GDBN} disconnects, @code{0} means
44073 that the trace run will stop.
44074
44075 @end table
44076
44077 @item qTP:@var{tp}:@var{addr}
44078 @cindex tracepoint status, remote request
44079 @cindex @samp{qTP} packet
44080 Ask the stub for the current state of tracepoint number @var{tp} at
44081 address @var{addr}.
44082
44083 Replies:
44084 @table @samp
44085 @item V@var{hits}:@var{usage}
44086 The tracepoint has been hit @var{hits} times so far during the trace
44087 run, and accounts for @var{usage} in the trace buffer. Note that
44088 @code{while-stepping} steps are not counted as separate hits, but the
44089 steps' space consumption is added into the usage number.
44090
44091 @end table
44092
44093 @item qTV:@var{var}
44094 @cindex trace state variable value, remote request
44095 @cindex @samp{qTV} packet
44096 Ask the stub for the value of the trace state variable number @var{var}.
44097
44098 Replies:
44099 @table @samp
44100 @item V@var{value}
44101 The value of the variable is @var{value}. This will be the current
44102 value of the variable if the user is examining a running target, or a
44103 saved value if the variable was collected in the trace frame that the
44104 user is looking at. Note that multiple requests may result in
44105 different reply values, such as when requesting values while the
44106 program is running.
44107
44108 @item U
44109 The value of the variable is unknown. This would occur, for example,
44110 if the user is examining a trace frame in which the requested variable
44111 was not collected.
44112 @end table
44113
44114 @item qTfP
44115 @cindex @samp{qTfP} packet
44116 @itemx qTsP
44117 @cindex @samp{qTsP} packet
44118 These packets request data about tracepoints that are being used by
44119 the target. @value{GDBN} sends @code{qTfP} to get the first piece
44120 of data, and multiple @code{qTsP} to get additional pieces. Replies
44121 to these packets generally take the form of the @code{QTDP} packets
44122 that define tracepoints. (FIXME add detailed syntax)
44123
44124 @item qTfV
44125 @cindex @samp{qTfV} packet
44126 @itemx qTsV
44127 @cindex @samp{qTsV} packet
44128 These packets request data about trace state variables that are on the
44129 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
44130 and multiple @code{qTsV} to get additional variables. Replies to
44131 these packets follow the syntax of the @code{QTDV} packets that define
44132 trace state variables.
44133
44134 @item qTfSTM
44135 @itemx qTsSTM
44136 @anchor{qTfSTM}
44137 @anchor{qTsSTM}
44138 @cindex @samp{qTfSTM} packet
44139 @cindex @samp{qTsSTM} packet
44140 These packets request data about static tracepoint markers that exist
44141 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
44142 first piece of data, and multiple @code{qTsSTM} to get additional
44143 pieces. Replies to these packets take the following form:
44144
44145 Reply:
44146 @table @samp
44147 @item m @var{address}:@var{id}:@var{extra}
44148 A single marker
44149 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
44150 a comma-separated list of markers
44151 @item l
44152 (lower case letter @samp{L}) denotes end of list.
44153 @item E @var{nn}
44154 An error occurred. The error number @var{nn} is given as hex digits.
44155 @item @w{}
44156 An empty reply indicates that the request is not supported by the
44157 stub.
44158 @end table
44159
44160 The @var{address} is encoded in hex;
44161 @var{id} and @var{extra} are strings encoded in hex.
44162
44163 In response to each query, the target will reply with a list of one or
44164 more markers, separated by commas. @value{GDBN} will respond to each
44165 reply with a request for more markers (using the @samp{qs} form of the
44166 query), until the target responds with @samp{l} (lower-case ell, for
44167 @dfn{last}).
44168
44169 @item qTSTMat:@var{address}
44170 @anchor{qTSTMat}
44171 @cindex @samp{qTSTMat} packet
44172 This packets requests data about static tracepoint markers in the
44173 target program at @var{address}. Replies to this packet follow the
44174 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
44175 tracepoint markers.
44176
44177 @item QTSave:@var{filename}
44178 @cindex @samp{QTSave} packet
44179 This packet directs the target to save trace data to the file name
44180 @var{filename} in the target's filesystem. The @var{filename} is encoded
44181 as a hex string; the interpretation of the file name (relative vs
44182 absolute, wild cards, etc) is up to the target.
44183
44184 @item qTBuffer:@var{offset},@var{len}
44185 @cindex @samp{qTBuffer} packet
44186 Return up to @var{len} bytes of the current contents of trace buffer,
44187 starting at @var{offset}. The trace buffer is treated as if it were
44188 a contiguous collection of traceframes, as per the trace file format.
44189 The reply consists as many hex-encoded bytes as the target can deliver
44190 in a packet; it is not an error to return fewer than were asked for.
44191 A reply consisting of just @code{l} indicates that no bytes are
44192 available.
44193
44194 @item QTBuffer:circular:@var{value}
44195 This packet directs the target to use a circular trace buffer if
44196 @var{value} is 1, or a linear buffer if the value is 0.
44197
44198 @item QTBuffer:size:@var{size}
44199 @anchor{QTBuffer-size}
44200 @cindex @samp{QTBuffer size} packet
44201 This packet directs the target to make the trace buffer be of size
44202 @var{size} if possible. A value of @code{-1} tells the target to
44203 use whatever size it prefers.
44204
44205 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
44206 @cindex @samp{QTNotes} packet
44207 This packet adds optional textual notes to the trace run. Allowable
44208 types include @code{user}, @code{notes}, and @code{tstop}, the
44209 @var{text} fields are arbitrary strings, hex-encoded.
44210
44211 @end table
44212
44213 @subsection Relocate instruction reply packet
44214 When installing fast tracepoints in memory, the target may need to
44215 relocate the instruction currently at the tracepoint address to a
44216 different address in memory. For most instructions, a simple copy is
44217 enough, but, for example, call instructions that implicitly push the
44218 return address on the stack, and relative branches or other
44219 PC-relative instructions require offset adjustment, so that the effect
44220 of executing the instruction at a different address is the same as if
44221 it had executed in the original location.
44222
44223 In response to several of the tracepoint packets, the target may also
44224 respond with a number of intermediate @samp{qRelocInsn} request
44225 packets before the final result packet, to have @value{GDBN} handle
44226 this relocation operation. If a packet supports this mechanism, its
44227 documentation will explicitly say so. See for example the above
44228 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
44229 format of the request is:
44230
44231 @table @samp
44232 @item qRelocInsn:@var{from};@var{to}
44233
44234 This requests @value{GDBN} to copy instruction at address @var{from}
44235 to address @var{to}, possibly adjusted so that executing the
44236 instruction at @var{to} has the same effect as executing it at
44237 @var{from}. @value{GDBN} writes the adjusted instruction to target
44238 memory starting at @var{to}.
44239 @end table
44240
44241 Replies:
44242 @table @samp
44243 @item qRelocInsn:@var{adjusted_size}
44244 Informs the stub the relocation is complete. The @var{adjusted_size} is
44245 the length in bytes of resulting relocated instruction sequence.
44246 @item E @var{NN}
44247 A badly formed request was detected, or an error was encountered while
44248 relocating the instruction.
44249 @end table
44250
44251 @node Host I/O Packets
44252 @section Host I/O Packets
44253 @cindex Host I/O, remote protocol
44254 @cindex file transfer, remote protocol
44255
44256 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
44257 operations on the far side of a remote link. For example, Host I/O is
44258 used to upload and download files to a remote target with its own
44259 filesystem. Host I/O uses the same constant values and data structure
44260 layout as the target-initiated File-I/O protocol. However, the
44261 Host I/O packets are structured differently. The target-initiated
44262 protocol relies on target memory to store parameters and buffers.
44263 Host I/O requests are initiated by @value{GDBN}, and the
44264 target's memory is not involved. @xref{File-I/O Remote Protocol
44265 Extension}, for more details on the target-initiated protocol.
44266
44267 The Host I/O request packets all encode a single operation along with
44268 its arguments. They have this format:
44269
44270 @table @samp
44271
44272 @item vFile:@var{operation}: @var{parameter}@dots{}
44273 @var{operation} is the name of the particular request; the target
44274 should compare the entire packet name up to the second colon when checking
44275 for a supported operation. The format of @var{parameter} depends on
44276 the operation. Numbers are always passed in hexadecimal. Negative
44277 numbers have an explicit minus sign (i.e.@: two's complement is not
44278 used). Strings (e.g.@: filenames) are encoded as a series of
44279 hexadecimal bytes. The last argument to a system call may be a
44280 buffer of escaped binary data (@pxref{Binary Data}).
44281
44282 @end table
44283
44284 The valid responses to Host I/O packets are:
44285
44286 @table @samp
44287
44288 @item F @var{result} [, @var{errno}] [; @var{attachment}]
44289 @var{result} is the integer value returned by this operation, usually
44290 non-negative for success and -1 for errors. If an error has occured,
44291 @var{errno} will be included in the result specifying a
44292 value defined by the File-I/O protocol (@pxref{Errno Values}). For
44293 operations which return data, @var{attachment} supplies the data as a
44294 binary buffer. Binary buffers in response packets are escaped in the
44295 normal way (@pxref{Binary Data}). See the individual packet
44296 documentation for the interpretation of @var{result} and
44297 @var{attachment}.
44298
44299 @item @w{}
44300 An empty response indicates that this operation is not recognized.
44301
44302 @end table
44303
44304 These are the supported Host I/O operations:
44305
44306 @table @samp
44307 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
44308 Open a file at @var{filename} and return a file descriptor for it, or
44309 return -1 if an error occurs. The @var{filename} is a string,
44310 @var{flags} is an integer indicating a mask of open flags
44311 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
44312 of mode bits to use if the file is created (@pxref{mode_t Values}).
44313 @xref{open}, for details of the open flags and mode values.
44314
44315 @item vFile:close: @var{fd}
44316 Close the open file corresponding to @var{fd} and return 0, or
44317 -1 if an error occurs.
44318
44319 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
44320 Read data from the open file corresponding to @var{fd}. Up to
44321 @var{count} bytes will be read from the file, starting at @var{offset}
44322 relative to the start of the file. The target may read fewer bytes;
44323 common reasons include packet size limits and an end-of-file
44324 condition. The number of bytes read is returned. Zero should only be
44325 returned for a successful read at the end of the file, or if
44326 @var{count} was zero.
44327
44328 The data read should be returned as a binary attachment on success.
44329 If zero bytes were read, the response should include an empty binary
44330 attachment (i.e.@: a trailing semicolon). The return value is the
44331 number of target bytes read; the binary attachment may be longer if
44332 some characters were escaped.
44333
44334 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
44335 Write @var{data} (a binary buffer) to the open file corresponding
44336 to @var{fd}. Start the write at @var{offset} from the start of the
44337 file. Unlike many @code{write} system calls, there is no
44338 separate @var{count} argument; the length of @var{data} in the
44339 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
44340 which may be shorter than the length of @var{data}, or -1 if an
44341 error occurred.
44342
44343 @item vFile:fstat: @var{fd}
44344 Get information about the open file corresponding to @var{fd}.
44345 On success the information is returned as a binary attachment
44346 and the return value is the size of this attachment in bytes.
44347 If an error occurs the return value is -1. The format of the
44348 returned binary attachment is as described in @ref{struct stat}.
44349
44350 @item vFile:unlink: @var{filename}
44351 Delete the file at @var{filename} on the target. Return 0,
44352 or -1 if an error occurs. The @var{filename} is a string.
44353
44354 @item vFile:readlink: @var{filename}
44355 Read value of symbolic link @var{filename} on the target. Return
44356 the number of bytes read, or -1 if an error occurs.
44357
44358 The data read should be returned as a binary attachment on success.
44359 If zero bytes were read, the response should include an empty binary
44360 attachment (i.e.@: a trailing semicolon). The return value is the
44361 number of target bytes read; the binary attachment may be longer if
44362 some characters were escaped.
44363
44364 @item vFile:setfs: @var{pid}
44365 Select the filesystem on which @code{vFile} operations with
44366 @var{filename} arguments will operate. This is required for
44367 @value{GDBN} to be able to access files on remote targets where
44368 the remote stub does not share a common filesystem with the
44369 inferior(s).
44370
44371 If @var{pid} is nonzero, select the filesystem as seen by process
44372 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
44373 the remote stub. Return 0 on success, or -1 if an error occurs.
44374 If @code{vFile:setfs:} indicates success, the selected filesystem
44375 remains selected until the next successful @code{vFile:setfs:}
44376 operation.
44377
44378 @end table
44379
44380 @node Interrupts
44381 @section Interrupts
44382 @cindex interrupts (remote protocol)
44383 @anchor{interrupting remote targets}
44384
44385 In all-stop mode, when a program on the remote target is running,
44386 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
44387 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
44388 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
44389
44390 The precise meaning of @code{BREAK} is defined by the transport
44391 mechanism and may, in fact, be undefined. @value{GDBN} does not
44392 currently define a @code{BREAK} mechanism for any of the network
44393 interfaces except for TCP, in which case @value{GDBN} sends the
44394 @code{telnet} BREAK sequence.
44395
44396 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
44397 transport mechanisms. It is represented by sending the single byte
44398 @code{0x03} without any of the usual packet overhead described in
44399 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
44400 transmitted as part of a packet, it is considered to be packet data
44401 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
44402 (@pxref{X packet}), used for binary downloads, may include an unescaped
44403 @code{0x03} as part of its packet.
44404
44405 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
44406 When Linux kernel receives this sequence from serial port,
44407 it stops execution and connects to gdb.
44408
44409 In non-stop mode, because packet resumptions are asynchronous
44410 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
44411 command to the remote stub, even when the target is running. For that
44412 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
44413 packet}) with the usual packet framing instead of the single byte
44414 @code{0x03}.
44415
44416 Stubs are not required to recognize these interrupt mechanisms and the
44417 precise meaning associated with receipt of the interrupt is
44418 implementation defined. If the target supports debugging of multiple
44419 threads and/or processes, it should attempt to interrupt all
44420 currently-executing threads and processes.
44421 If the stub is successful at interrupting the
44422 running program, it should send one of the stop
44423 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
44424 of successfully stopping the program in all-stop mode, and a stop reply
44425 for each stopped thread in non-stop mode.
44426 Interrupts received while the
44427 program is stopped are queued and the program will be interrupted when
44428 it is resumed next time.
44429
44430 @node Notification Packets
44431 @section Notification Packets
44432 @cindex notification packets
44433 @cindex packets, notification
44434
44435 The @value{GDBN} remote serial protocol includes @dfn{notifications},
44436 packets that require no acknowledgment. Both the GDB and the stub
44437 may send notifications (although the only notifications defined at
44438 present are sent by the stub). Notifications carry information
44439 without incurring the round-trip latency of an acknowledgment, and so
44440 are useful for low-impact communications where occasional packet loss
44441 is not a problem.
44442
44443 A notification packet has the form @samp{% @var{data} #
44444 @var{checksum}}, where @var{data} is the content of the notification,
44445 and @var{checksum} is a checksum of @var{data}, computed and formatted
44446 as for ordinary @value{GDBN} packets. A notification's @var{data}
44447 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
44448 receiving a notification, the recipient sends no @samp{+} or @samp{-}
44449 to acknowledge the notification's receipt or to report its corruption.
44450
44451 Every notification's @var{data} begins with a name, which contains no
44452 colon characters, followed by a colon character.
44453
44454 Recipients should silently ignore corrupted notifications and
44455 notifications they do not understand. Recipients should restart
44456 timeout periods on receipt of a well-formed notification, whether or
44457 not they understand it.
44458
44459 Senders should only send the notifications described here when this
44460 protocol description specifies that they are permitted. In the
44461 future, we may extend the protocol to permit existing notifications in
44462 new contexts; this rule helps older senders avoid confusing newer
44463 recipients.
44464
44465 (Older versions of @value{GDBN} ignore bytes received until they see
44466 the @samp{$} byte that begins an ordinary packet, so new stubs may
44467 transmit notifications without fear of confusing older clients. There
44468 are no notifications defined for @value{GDBN} to send at the moment, but we
44469 assume that most older stubs would ignore them, as well.)
44470
44471 Each notification is comprised of three parts:
44472 @table @samp
44473 @item @var{name}:@var{event}
44474 The notification packet is sent by the side that initiates the
44475 exchange (currently, only the stub does that), with @var{event}
44476 carrying the specific information about the notification, and
44477 @var{name} specifying the name of the notification.
44478 @item @var{ack}
44479 The acknowledge sent by the other side, usually @value{GDBN}, to
44480 acknowledge the exchange and request the event.
44481 @end table
44482
44483 The purpose of an asynchronous notification mechanism is to report to
44484 @value{GDBN} that something interesting happened in the remote stub.
44485
44486 The remote stub may send notification @var{name}:@var{event}
44487 at any time, but @value{GDBN} acknowledges the notification when
44488 appropriate. The notification event is pending before @value{GDBN}
44489 acknowledges. Only one notification at a time may be pending; if
44490 additional events occur before @value{GDBN} has acknowledged the
44491 previous notification, they must be queued by the stub for later
44492 synchronous transmission in response to @var{ack} packets from
44493 @value{GDBN}. Because the notification mechanism is unreliable,
44494 the stub is permitted to resend a notification if it believes
44495 @value{GDBN} may not have received it.
44496
44497 Specifically, notifications may appear when @value{GDBN} is not
44498 otherwise reading input from the stub, or when @value{GDBN} is
44499 expecting to read a normal synchronous response or a
44500 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
44501 Notification packets are distinct from any other communication from
44502 the stub so there is no ambiguity.
44503
44504 After receiving a notification, @value{GDBN} shall acknowledge it by
44505 sending a @var{ack} packet as a regular, synchronous request to the
44506 stub. Such acknowledgment is not required to happen immediately, as
44507 @value{GDBN} is permitted to send other, unrelated packets to the
44508 stub first, which the stub should process normally.
44509
44510 Upon receiving a @var{ack} packet, if the stub has other queued
44511 events to report to @value{GDBN}, it shall respond by sending a
44512 normal @var{event}. @value{GDBN} shall then send another @var{ack}
44513 packet to solicit further responses; again, it is permitted to send
44514 other, unrelated packets as well which the stub should process
44515 normally.
44516
44517 If the stub receives a @var{ack} packet and there are no additional
44518 @var{event} to report, the stub shall return an @samp{OK} response.
44519 At this point, @value{GDBN} has finished processing a notification
44520 and the stub has completed sending any queued events. @value{GDBN}
44521 won't accept any new notifications until the final @samp{OK} is
44522 received . If further notification events occur, the stub shall send
44523 a new notification, @value{GDBN} shall accept the notification, and
44524 the process shall be repeated.
44525
44526 The process of asynchronous notification can be illustrated by the
44527 following example:
44528 @smallexample
44529 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
44530 @code{...}
44531 -> @code{vStopped}
44532 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
44533 -> @code{vStopped}
44534 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
44535 -> @code{vStopped}
44536 <- @code{OK}
44537 @end smallexample
44538
44539 The following notifications are defined:
44540 @multitable @columnfractions 0.12 0.12 0.38 0.38
44541
44542 @item Notification
44543 @tab Ack
44544 @tab Event
44545 @tab Description
44546
44547 @item Stop
44548 @tab vStopped
44549 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
44550 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
44551 for information on how these notifications are acknowledged by
44552 @value{GDBN}.
44553 @tab Report an asynchronous stop event in non-stop mode.
44554
44555 @end multitable
44556
44557 @node Remote Non-Stop
44558 @section Remote Protocol Support for Non-Stop Mode
44559
44560 @value{GDBN}'s remote protocol supports non-stop debugging of
44561 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
44562 supports non-stop mode, it should report that to @value{GDBN} by including
44563 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
44564
44565 @value{GDBN} typically sends a @samp{QNonStop} packet only when
44566 establishing a new connection with the stub. Entering non-stop mode
44567 does not alter the state of any currently-running threads, but targets
44568 must stop all threads in any already-attached processes when entering
44569 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
44570 probe the target state after a mode change.
44571
44572 In non-stop mode, when an attached process encounters an event that
44573 would otherwise be reported with a stop reply, it uses the
44574 asynchronous notification mechanism (@pxref{Notification Packets}) to
44575 inform @value{GDBN}. In contrast to all-stop mode, where all threads
44576 in all processes are stopped when a stop reply is sent, in non-stop
44577 mode only the thread reporting the stop event is stopped. That is,
44578 when reporting a @samp{S} or @samp{T} response to indicate completion
44579 of a step operation, hitting a breakpoint, or a fault, only the
44580 affected thread is stopped; any other still-running threads continue
44581 to run. When reporting a @samp{W} or @samp{X} response, all running
44582 threads belonging to other attached processes continue to run.
44583
44584 In non-stop mode, the target shall respond to the @samp{?} packet as
44585 follows. First, any incomplete stop reply notification/@samp{vStopped}
44586 sequence in progress is abandoned. The target must begin a new
44587 sequence reporting stop events for all stopped threads, whether or not
44588 it has previously reported those events to @value{GDBN}. The first
44589 stop reply is sent as a synchronous reply to the @samp{?} packet, and
44590 subsequent stop replies are sent as responses to @samp{vStopped} packets
44591 using the mechanism described above. The target must not send
44592 asynchronous stop reply notifications until the sequence is complete.
44593 If all threads are running when the target receives the @samp{?} packet,
44594 or if the target is not attached to any process, it shall respond
44595 @samp{OK}.
44596
44597 If the stub supports non-stop mode, it should also support the
44598 @samp{swbreak} stop reason if software breakpoints are supported, and
44599 the @samp{hwbreak} stop reason if hardware breakpoints are supported
44600 (@pxref{swbreak stop reason}). This is because given the asynchronous
44601 nature of non-stop mode, between the time a thread hits a breakpoint
44602 and the time the event is finally processed by @value{GDBN}, the
44603 breakpoint may have already been removed from the target. Due to
44604 this, @value{GDBN} needs to be able to tell whether a trap stop was
44605 caused by a delayed breakpoint event, which should be ignored, as
44606 opposed to a random trap signal, which should be reported to the user.
44607 Note the @samp{swbreak} feature implies that the target is responsible
44608 for adjusting the PC when a software breakpoint triggers, if
44609 necessary, such as on the x86 architecture.
44610
44611 @node Packet Acknowledgment
44612 @section Packet Acknowledgment
44613
44614 @cindex acknowledgment, for @value{GDBN} remote
44615 @cindex packet acknowledgment, for @value{GDBN} remote
44616 By default, when either the host or the target machine receives a packet,
44617 the first response expected is an acknowledgment: either @samp{+} (to indicate
44618 the package was received correctly) or @samp{-} (to request retransmission).
44619 This mechanism allows the @value{GDBN} remote protocol to operate over
44620 unreliable transport mechanisms, such as a serial line.
44621
44622 In cases where the transport mechanism is itself reliable (such as a pipe or
44623 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
44624 It may be desirable to disable them in that case to reduce communication
44625 overhead, or for other reasons. This can be accomplished by means of the
44626 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
44627
44628 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
44629 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
44630 and response format still includes the normal checksum, as described in
44631 @ref{Overview}, but the checksum may be ignored by the receiver.
44632
44633 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
44634 no-acknowledgment mode, it should report that to @value{GDBN}
44635 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
44636 @pxref{qSupported}.
44637 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
44638 disabled via the @code{set remote noack-packet off} command
44639 (@pxref{Remote Configuration}),
44640 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
44641 Only then may the stub actually turn off packet acknowledgments.
44642 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
44643 response, which can be safely ignored by the stub.
44644
44645 Note that @code{set remote noack-packet} command only affects negotiation
44646 between @value{GDBN} and the stub when subsequent connections are made;
44647 it does not affect the protocol acknowledgment state for any current
44648 connection.
44649 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
44650 new connection is established,
44651 there is also no protocol request to re-enable the acknowledgments
44652 for the current connection, once disabled.
44653
44654 @node Examples
44655 @section Examples
44656
44657 Example sequence of a target being re-started. Notice how the restart
44658 does not get any direct output:
44659
44660 @smallexample
44661 -> @code{R00}
44662 <- @code{+}
44663 @emph{target restarts}
44664 -> @code{?}
44665 <- @code{+}
44666 <- @code{T001:1234123412341234}
44667 -> @code{+}
44668 @end smallexample
44669
44670 Example sequence of a target being stepped by a single instruction:
44671
44672 @smallexample
44673 -> @code{G1445@dots{}}
44674 <- @code{+}
44675 -> @code{s}
44676 <- @code{+}
44677 @emph{time passes}
44678 <- @code{T001:1234123412341234}
44679 -> @code{+}
44680 -> @code{g}
44681 <- @code{+}
44682 <- @code{1455@dots{}}
44683 -> @code{+}
44684 @end smallexample
44685
44686 @node File-I/O Remote Protocol Extension
44687 @section File-I/O Remote Protocol Extension
44688 @cindex File-I/O remote protocol extension
44689
44690 @menu
44691 * File-I/O Overview::
44692 * Protocol Basics::
44693 * The F Request Packet::
44694 * The F Reply Packet::
44695 * The Ctrl-C Message::
44696 * Console I/O::
44697 * List of Supported Calls::
44698 * Protocol-specific Representation of Datatypes::
44699 * Constants::
44700 * File-I/O Examples::
44701 @end menu
44702
44703 @node File-I/O Overview
44704 @subsection File-I/O Overview
44705 @cindex file-i/o overview
44706
44707 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
44708 target to use the host's file system and console I/O to perform various
44709 system calls. System calls on the target system are translated into a
44710 remote protocol packet to the host system, which then performs the needed
44711 actions and returns a response packet to the target system.
44712 This simulates file system operations even on targets that lack file systems.
44713
44714 The protocol is defined to be independent of both the host and target systems.
44715 It uses its own internal representation of datatypes and values. Both
44716 @value{GDBN} and the target's @value{GDBN} stub are responsible for
44717 translating the system-dependent value representations into the internal
44718 protocol representations when data is transmitted.
44719
44720 The communication is synchronous. A system call is possible only when
44721 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
44722 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
44723 the target is stopped to allow deterministic access to the target's
44724 memory. Therefore File-I/O is not interruptible by target signals. On
44725 the other hand, it is possible to interrupt File-I/O by a user interrupt
44726 (@samp{Ctrl-C}) within @value{GDBN}.
44727
44728 The target's request to perform a host system call does not finish
44729 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
44730 after finishing the system call, the target returns to continuing the
44731 previous activity (continue, step). No additional continue or step
44732 request from @value{GDBN} is required.
44733
44734 @smallexample
44735 (@value{GDBP}) continue
44736 <- target requests 'system call X'
44737 target is stopped, @value{GDBN} executes system call
44738 -> @value{GDBN} returns result
44739 ... target continues, @value{GDBN} returns to wait for the target
44740 <- target hits breakpoint and sends a Txx packet
44741 @end smallexample
44742
44743 The protocol only supports I/O on the console and to regular files on
44744 the host file system. Character or block special devices, pipes,
44745 named pipes, sockets or any other communication method on the host
44746 system are not supported by this protocol.
44747
44748 File I/O is not supported in non-stop mode.
44749
44750 @node Protocol Basics
44751 @subsection Protocol Basics
44752 @cindex protocol basics, file-i/o
44753
44754 The File-I/O protocol uses the @code{F} packet as the request as well
44755 as reply packet. Since a File-I/O system call can only occur when
44756 @value{GDBN} is waiting for a response from the continuing or stepping target,
44757 the File-I/O request is a reply that @value{GDBN} has to expect as a result
44758 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
44759 This @code{F} packet contains all information needed to allow @value{GDBN}
44760 to call the appropriate host system call:
44761
44762 @itemize @bullet
44763 @item
44764 A unique identifier for the requested system call.
44765
44766 @item
44767 All parameters to the system call. Pointers are given as addresses
44768 in the target memory address space. Pointers to strings are given as
44769 pointer/length pair. Numerical values are given as they are.
44770 Numerical control flags are given in a protocol-specific representation.
44771
44772 @end itemize
44773
44774 At this point, @value{GDBN} has to perform the following actions.
44775
44776 @itemize @bullet
44777 @item
44778 If the parameters include pointer values to data needed as input to a
44779 system call, @value{GDBN} requests this data from the target with a
44780 standard @code{m} packet request. This additional communication has to be
44781 expected by the target implementation and is handled as any other @code{m}
44782 packet.
44783
44784 @item
44785 @value{GDBN} translates all value from protocol representation to host
44786 representation as needed. Datatypes are coerced into the host types.
44787
44788 @item
44789 @value{GDBN} calls the system call.
44790
44791 @item
44792 It then coerces datatypes back to protocol representation.
44793
44794 @item
44795 If the system call is expected to return data in buffer space specified
44796 by pointer parameters to the call, the data is transmitted to the
44797 target using a @code{M} or @code{X} packet. This packet has to be expected
44798 by the target implementation and is handled as any other @code{M} or @code{X}
44799 packet.
44800
44801 @end itemize
44802
44803 Eventually @value{GDBN} replies with another @code{F} packet which contains all
44804 necessary information for the target to continue. This at least contains
44805
44806 @itemize @bullet
44807 @item
44808 Return value.
44809
44810 @item
44811 @code{errno}, if has been changed by the system call.
44812
44813 @item
44814 ``Ctrl-C'' flag.
44815
44816 @end itemize
44817
44818 After having done the needed type and value coercion, the target continues
44819 the latest continue or step action.
44820
44821 @node The F Request Packet
44822 @subsection The @code{F} Request Packet
44823 @cindex file-i/o request packet
44824 @cindex @code{F} request packet
44825
44826 The @code{F} request packet has the following format:
44827
44828 @table @samp
44829 @item F@var{call-id},@var{parameter@dots{}}
44830
44831 @var{call-id} is the identifier to indicate the host system call to be called.
44832 This is just the name of the function.
44833
44834 @var{parameter@dots{}} are the parameters to the system call.
44835 Parameters are hexadecimal integer values, either the actual values in case
44836 of scalar datatypes, pointers to target buffer space in case of compound
44837 datatypes and unspecified memory areas, or pointer/length pairs in case
44838 of string parameters. These are appended to the @var{call-id} as a
44839 comma-delimited list. All values are transmitted in ASCII
44840 string representation, pointer/length pairs separated by a slash.
44841
44842 @end table
44843
44844
44845
44846 @node The F Reply Packet
44847 @subsection The @code{F} Reply Packet
44848 @cindex file-i/o reply packet
44849 @cindex @code{F} reply packet
44850
44851 The @code{F} reply packet has the following format:
44852
44853 @table @samp
44854
44855 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
44856
44857 @var{retcode} is the return code of the system call as hexadecimal value.
44858
44859 @var{errno} is the @code{errno} set by the call, in protocol-specific
44860 representation.
44861 This parameter can be omitted if the call was successful.
44862
44863 @var{Ctrl-C flag} is only sent if the user requested a break. In this
44864 case, @var{errno} must be sent as well, even if the call was successful.
44865 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
44866
44867 @smallexample
44868 F0,0,C
44869 @end smallexample
44870
44871 @noindent
44872 or, if the call was interrupted before the host call has been performed:
44873
44874 @smallexample
44875 F-1,4,C
44876 @end smallexample
44877
44878 @noindent
44879 assuming 4 is the protocol-specific representation of @code{EINTR}.
44880
44881 @end table
44882
44883
44884 @node The Ctrl-C Message
44885 @subsection The @samp{Ctrl-C} Message
44886 @cindex ctrl-c message, in file-i/o protocol
44887
44888 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
44889 reply packet (@pxref{The F Reply Packet}),
44890 the target should behave as if it had
44891 gotten a break message. The meaning for the target is ``system call
44892 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
44893 (as with a break message) and return to @value{GDBN} with a @code{T02}
44894 packet.
44895
44896 It's important for the target to know in which
44897 state the system call was interrupted. There are two possible cases:
44898
44899 @itemize @bullet
44900 @item
44901 The system call hasn't been performed on the host yet.
44902
44903 @item
44904 The system call on the host has been finished.
44905
44906 @end itemize
44907
44908 These two states can be distinguished by the target by the value of the
44909 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
44910 call hasn't been performed. This is equivalent to the @code{EINTR} handling
44911 on POSIX systems. In any other case, the target may presume that the
44912 system call has been finished --- successfully or not --- and should behave
44913 as if the break message arrived right after the system call.
44914
44915 @value{GDBN} must behave reliably. If the system call has not been called
44916 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
44917 @code{errno} in the packet. If the system call on the host has been finished
44918 before the user requests a break, the full action must be finished by
44919 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
44920 The @code{F} packet may only be sent when either nothing has happened
44921 or the full action has been completed.
44922
44923 @node Console I/O
44924 @subsection Console I/O
44925 @cindex console i/o as part of file-i/o
44926
44927 By default and if not explicitly closed by the target system, the file
44928 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
44929 on the @value{GDBN} console is handled as any other file output operation
44930 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
44931 by @value{GDBN} so that after the target read request from file descriptor
44932 0 all following typing is buffered until either one of the following
44933 conditions is met:
44934
44935 @itemize @bullet
44936 @item
44937 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
44938 @code{read}
44939 system call is treated as finished.
44940
44941 @item
44942 The user presses @key{RET}. This is treated as end of input with a trailing
44943 newline.
44944
44945 @item
44946 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
44947 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
44948
44949 @end itemize
44950
44951 If the user has typed more characters than fit in the buffer given to
44952 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
44953 either another @code{read(0, @dots{})} is requested by the target, or debugging
44954 is stopped at the user's request.
44955
44956
44957 @node List of Supported Calls
44958 @subsection List of Supported Calls
44959 @cindex list of supported file-i/o calls
44960
44961 @menu
44962 * open::
44963 * close::
44964 * read::
44965 * write::
44966 * lseek::
44967 * rename::
44968 * unlink::
44969 * stat/fstat::
44970 * gettimeofday::
44971 * isatty::
44972 * system::
44973 @end menu
44974
44975 @node open
44976 @unnumberedsubsubsec open
44977 @cindex open, file-i/o system call
44978
44979 @table @asis
44980 @item Synopsis:
44981 @smallexample
44982 int open(const char *pathname, int flags);
44983 int open(const char *pathname, int flags, mode_t mode);
44984 @end smallexample
44985
44986 @item Request:
44987 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
44988
44989 @noindent
44990 @var{flags} is the bitwise @code{OR} of the following values:
44991
44992 @table @code
44993 @item O_CREAT
44994 If the file does not exist it will be created. The host
44995 rules apply as far as file ownership and time stamps
44996 are concerned.
44997
44998 @item O_EXCL
44999 When used with @code{O_CREAT}, if the file already exists it is
45000 an error and open() fails.
45001
45002 @item O_TRUNC
45003 If the file already exists and the open mode allows
45004 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
45005 truncated to zero length.
45006
45007 @item O_APPEND
45008 The file is opened in append mode.
45009
45010 @item O_RDONLY
45011 The file is opened for reading only.
45012
45013 @item O_WRONLY
45014 The file is opened for writing only.
45015
45016 @item O_RDWR
45017 The file is opened for reading and writing.
45018 @end table
45019
45020 @noindent
45021 Other bits are silently ignored.
45022
45023
45024 @noindent
45025 @var{mode} is the bitwise @code{OR} of the following values:
45026
45027 @table @code
45028 @item S_IRUSR
45029 User has read permission.
45030
45031 @item S_IWUSR
45032 User has write permission.
45033
45034 @item S_IRGRP
45035 Group has read permission.
45036
45037 @item S_IWGRP
45038 Group has write permission.
45039
45040 @item S_IROTH
45041 Others have read permission.
45042
45043 @item S_IWOTH
45044 Others have write permission.
45045 @end table
45046
45047 @noindent
45048 Other bits are silently ignored.
45049
45050
45051 @item Return value:
45052 @code{open} returns the new file descriptor or -1 if an error
45053 occurred.
45054
45055 @item Errors:
45056
45057 @table @code
45058 @item EEXIST
45059 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
45060
45061 @item EISDIR
45062 @var{pathname} refers to a directory.
45063
45064 @item EACCES
45065 The requested access is not allowed.
45066
45067 @item ENAMETOOLONG
45068 @var{pathname} was too long.
45069
45070 @item ENOENT
45071 A directory component in @var{pathname} does not exist.
45072
45073 @item ENODEV
45074 @var{pathname} refers to a device, pipe, named pipe or socket.
45075
45076 @item EROFS
45077 @var{pathname} refers to a file on a read-only filesystem and
45078 write access was requested.
45079
45080 @item EFAULT
45081 @var{pathname} is an invalid pointer value.
45082
45083 @item ENOSPC
45084 No space on device to create the file.
45085
45086 @item EMFILE
45087 The process already has the maximum number of files open.
45088
45089 @item ENFILE
45090 The limit on the total number of files open on the system
45091 has been reached.
45092
45093 @item EINTR
45094 The call was interrupted by the user.
45095 @end table
45096
45097 @end table
45098
45099 @node close
45100 @unnumberedsubsubsec close
45101 @cindex close, file-i/o system call
45102
45103 @table @asis
45104 @item Synopsis:
45105 @smallexample
45106 int close(int fd);
45107 @end smallexample
45108
45109 @item Request:
45110 @samp{Fclose,@var{fd}}
45111
45112 @item Return value:
45113 @code{close} returns zero on success, or -1 if an error occurred.
45114
45115 @item Errors:
45116
45117 @table @code
45118 @item EBADF
45119 @var{fd} isn't a valid open file descriptor.
45120
45121 @item EINTR
45122 The call was interrupted by the user.
45123 @end table
45124
45125 @end table
45126
45127 @node read
45128 @unnumberedsubsubsec read
45129 @cindex read, file-i/o system call
45130
45131 @table @asis
45132 @item Synopsis:
45133 @smallexample
45134 int read(int fd, void *buf, unsigned int count);
45135 @end smallexample
45136
45137 @item Request:
45138 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
45139
45140 @item Return value:
45141 On success, the number of bytes read is returned.
45142 Zero indicates end of file. If count is zero, read
45143 returns zero as well. On error, -1 is returned.
45144
45145 @item Errors:
45146
45147 @table @code
45148 @item EBADF
45149 @var{fd} is not a valid file descriptor or is not open for
45150 reading.
45151
45152 @item EFAULT
45153 @var{bufptr} is an invalid pointer value.
45154
45155 @item EINTR
45156 The call was interrupted by the user.
45157 @end table
45158
45159 @end table
45160
45161 @node write
45162 @unnumberedsubsubsec write
45163 @cindex write, file-i/o system call
45164
45165 @table @asis
45166 @item Synopsis:
45167 @smallexample
45168 int write(int fd, const void *buf, unsigned int count);
45169 @end smallexample
45170
45171 @item Request:
45172 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
45173
45174 @item Return value:
45175 On success, the number of bytes written are returned.
45176 Zero indicates nothing was written. On error, -1
45177 is returned.
45178
45179 @item Errors:
45180
45181 @table @code
45182 @item EBADF
45183 @var{fd} is not a valid file descriptor or is not open for
45184 writing.
45185
45186 @item EFAULT
45187 @var{bufptr} is an invalid pointer value.
45188
45189 @item EFBIG
45190 An attempt was made to write a file that exceeds the
45191 host-specific maximum file size allowed.
45192
45193 @item ENOSPC
45194 No space on device to write the data.
45195
45196 @item EINTR
45197 The call was interrupted by the user.
45198 @end table
45199
45200 @end table
45201
45202 @node lseek
45203 @unnumberedsubsubsec lseek
45204 @cindex lseek, file-i/o system call
45205
45206 @table @asis
45207 @item Synopsis:
45208 @smallexample
45209 long lseek (int fd, long offset, int flag);
45210 @end smallexample
45211
45212 @item Request:
45213 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
45214
45215 @var{flag} is one of:
45216
45217 @table @code
45218 @item SEEK_SET
45219 The offset is set to @var{offset} bytes.
45220
45221 @item SEEK_CUR
45222 The offset is set to its current location plus @var{offset}
45223 bytes.
45224
45225 @item SEEK_END
45226 The offset is set to the size of the file plus @var{offset}
45227 bytes.
45228 @end table
45229
45230 @item Return value:
45231 On success, the resulting unsigned offset in bytes from
45232 the beginning of the file is returned. Otherwise, a
45233 value of -1 is returned.
45234
45235 @item Errors:
45236
45237 @table @code
45238 @item EBADF
45239 @var{fd} is not a valid open file descriptor.
45240
45241 @item ESPIPE
45242 @var{fd} is associated with the @value{GDBN} console.
45243
45244 @item EINVAL
45245 @var{flag} is not a proper value.
45246
45247 @item EINTR
45248 The call was interrupted by the user.
45249 @end table
45250
45251 @end table
45252
45253 @node rename
45254 @unnumberedsubsubsec rename
45255 @cindex rename, file-i/o system call
45256
45257 @table @asis
45258 @item Synopsis:
45259 @smallexample
45260 int rename(const char *oldpath, const char *newpath);
45261 @end smallexample
45262
45263 @item Request:
45264 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
45265
45266 @item Return value:
45267 On success, zero is returned. On error, -1 is returned.
45268
45269 @item Errors:
45270
45271 @table @code
45272 @item EISDIR
45273 @var{newpath} is an existing directory, but @var{oldpath} is not a
45274 directory.
45275
45276 @item EEXIST
45277 @var{newpath} is a non-empty directory.
45278
45279 @item EBUSY
45280 @var{oldpath} or @var{newpath} is a directory that is in use by some
45281 process.
45282
45283 @item EINVAL
45284 An attempt was made to make a directory a subdirectory
45285 of itself.
45286
45287 @item ENOTDIR
45288 A component used as a directory in @var{oldpath} or new
45289 path is not a directory. Or @var{oldpath} is a directory
45290 and @var{newpath} exists but is not a directory.
45291
45292 @item EFAULT
45293 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
45294
45295 @item EACCES
45296 No access to the file or the path of the file.
45297
45298 @item ENAMETOOLONG
45299
45300 @var{oldpath} or @var{newpath} was too long.
45301
45302 @item ENOENT
45303 A directory component in @var{oldpath} or @var{newpath} does not exist.
45304
45305 @item EROFS
45306 The file is on a read-only filesystem.
45307
45308 @item ENOSPC
45309 The device containing the file has no room for the new
45310 directory entry.
45311
45312 @item EINTR
45313 The call was interrupted by the user.
45314 @end table
45315
45316 @end table
45317
45318 @node unlink
45319 @unnumberedsubsubsec unlink
45320 @cindex unlink, file-i/o system call
45321
45322 @table @asis
45323 @item Synopsis:
45324 @smallexample
45325 int unlink(const char *pathname);
45326 @end smallexample
45327
45328 @item Request:
45329 @samp{Funlink,@var{pathnameptr}/@var{len}}
45330
45331 @item Return value:
45332 On success, zero is returned. On error, -1 is returned.
45333
45334 @item Errors:
45335
45336 @table @code
45337 @item EACCES
45338 No access to the file or the path of the file.
45339
45340 @item EPERM
45341 The system does not allow unlinking of directories.
45342
45343 @item EBUSY
45344 The file @var{pathname} cannot be unlinked because it's
45345 being used by another process.
45346
45347 @item EFAULT
45348 @var{pathnameptr} is an invalid pointer value.
45349
45350 @item ENAMETOOLONG
45351 @var{pathname} was too long.
45352
45353 @item ENOENT
45354 A directory component in @var{pathname} does not exist.
45355
45356 @item ENOTDIR
45357 A component of the path is not a directory.
45358
45359 @item EROFS
45360 The file is on a read-only filesystem.
45361
45362 @item EINTR
45363 The call was interrupted by the user.
45364 @end table
45365
45366 @end table
45367
45368 @node stat/fstat
45369 @unnumberedsubsubsec stat/fstat
45370 @cindex fstat, file-i/o system call
45371 @cindex stat, file-i/o system call
45372
45373 @table @asis
45374 @item Synopsis:
45375 @smallexample
45376 int stat(const char *pathname, struct stat *buf);
45377 int fstat(int fd, struct stat *buf);
45378 @end smallexample
45379
45380 @item Request:
45381 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
45382 @samp{Ffstat,@var{fd},@var{bufptr}}
45383
45384 @item Return value:
45385 On success, zero is returned. On error, -1 is returned.
45386
45387 @item Errors:
45388
45389 @table @code
45390 @item EBADF
45391 @var{fd} is not a valid open file.
45392
45393 @item ENOENT
45394 A directory component in @var{pathname} does not exist or the
45395 path is an empty string.
45396
45397 @item ENOTDIR
45398 A component of the path is not a directory.
45399
45400 @item EFAULT
45401 @var{pathnameptr} is an invalid pointer value.
45402
45403 @item EACCES
45404 No access to the file or the path of the file.
45405
45406 @item ENAMETOOLONG
45407 @var{pathname} was too long.
45408
45409 @item EINTR
45410 The call was interrupted by the user.
45411 @end table
45412
45413 @end table
45414
45415 @node gettimeofday
45416 @unnumberedsubsubsec gettimeofday
45417 @cindex gettimeofday, file-i/o system call
45418
45419 @table @asis
45420 @item Synopsis:
45421 @smallexample
45422 int gettimeofday(struct timeval *tv, void *tz);
45423 @end smallexample
45424
45425 @item Request:
45426 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
45427
45428 @item Return value:
45429 On success, 0 is returned, -1 otherwise.
45430
45431 @item Errors:
45432
45433 @table @code
45434 @item EINVAL
45435 @var{tz} is a non-NULL pointer.
45436
45437 @item EFAULT
45438 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
45439 @end table
45440
45441 @end table
45442
45443 @node isatty
45444 @unnumberedsubsubsec isatty
45445 @cindex isatty, file-i/o system call
45446
45447 @table @asis
45448 @item Synopsis:
45449 @smallexample
45450 int isatty(int fd);
45451 @end smallexample
45452
45453 @item Request:
45454 @samp{Fisatty,@var{fd}}
45455
45456 @item Return value:
45457 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
45458
45459 @item Errors:
45460
45461 @table @code
45462 @item EINTR
45463 The call was interrupted by the user.
45464 @end table
45465
45466 @end table
45467
45468 Note that the @code{isatty} call is treated as a special case: it returns
45469 1 to the target if the file descriptor is attached
45470 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
45471 would require implementing @code{ioctl} and would be more complex than
45472 needed.
45473
45474
45475 @node system
45476 @unnumberedsubsubsec system
45477 @cindex system, file-i/o system call
45478
45479 @table @asis
45480 @item Synopsis:
45481 @smallexample
45482 int system(const char *command);
45483 @end smallexample
45484
45485 @item Request:
45486 @samp{Fsystem,@var{commandptr}/@var{len}}
45487
45488 @item Return value:
45489 If @var{len} is zero, the return value indicates whether a shell is
45490 available. A zero return value indicates a shell is not available.
45491 For non-zero @var{len}, the value returned is -1 on error and the
45492 return status of the command otherwise. Only the exit status of the
45493 command is returned, which is extracted from the host's @code{system}
45494 return value by calling @code{WEXITSTATUS(retval)}. In case
45495 @file{/bin/sh} could not be executed, 127 is returned.
45496
45497 @item Errors:
45498
45499 @table @code
45500 @item EINTR
45501 The call was interrupted by the user.
45502 @end table
45503
45504 @end table
45505
45506 @value{GDBN} takes over the full task of calling the necessary host calls
45507 to perform the @code{system} call. The return value of @code{system} on
45508 the host is simplified before it's returned
45509 to the target. Any termination signal information from the child process
45510 is discarded, and the return value consists
45511 entirely of the exit status of the called command.
45512
45513 Due to security concerns, the @code{system} call is by default refused
45514 by @value{GDBN}. The user has to allow this call explicitly with the
45515 @code{set remote system-call-allowed 1} command.
45516
45517 @table @code
45518 @item set remote system-call-allowed
45519 @kindex set remote system-call-allowed
45520 Control whether to allow the @code{system} calls in the File I/O
45521 protocol for the remote target. The default is zero (disabled).
45522
45523 @item show remote system-call-allowed
45524 @kindex show remote system-call-allowed
45525 Show whether the @code{system} calls are allowed in the File I/O
45526 protocol.
45527 @end table
45528
45529 @node Protocol-specific Representation of Datatypes
45530 @subsection Protocol-specific Representation of Datatypes
45531 @cindex protocol-specific representation of datatypes, in file-i/o protocol
45532
45533 @menu
45534 * Integral Datatypes::
45535 * Pointer Values::
45536 * Memory Transfer::
45537 * struct stat::
45538 * struct timeval::
45539 @end menu
45540
45541 @node Integral Datatypes
45542 @unnumberedsubsubsec Integral Datatypes
45543 @cindex integral datatypes, in file-i/o protocol
45544
45545 The integral datatypes used in the system calls are @code{int},
45546 @code{unsigned int}, @code{long}, @code{unsigned long},
45547 @code{mode_t}, and @code{time_t}.
45548
45549 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
45550 implemented as 32 bit values in this protocol.
45551
45552 @code{long} and @code{unsigned long} are implemented as 64 bit types.
45553
45554 @xref{Limits}, for corresponding MIN and MAX values (similar to those
45555 in @file{limits.h}) to allow range checking on host and target.
45556
45557 @code{time_t} datatypes are defined as seconds since the Epoch.
45558
45559 All integral datatypes transferred as part of a memory read or write of a
45560 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
45561 byte order.
45562
45563 @node Pointer Values
45564 @unnumberedsubsubsec Pointer Values
45565 @cindex pointer values, in file-i/o protocol
45566
45567 Pointers to target data are transmitted as they are. An exception
45568 is made for pointers to buffers for which the length isn't
45569 transmitted as part of the function call, namely strings. Strings
45570 are transmitted as a pointer/length pair, both as hex values, e.g.@:
45571
45572 @smallexample
45573 @code{1aaf/12}
45574 @end smallexample
45575
45576 @noindent
45577 which is a pointer to data of length 18 bytes at position 0x1aaf.
45578 The length is defined as the full string length in bytes, including
45579 the trailing null byte. For example, the string @code{"hello world"}
45580 at address 0x123456 is transmitted as
45581
45582 @smallexample
45583 @code{123456/d}
45584 @end smallexample
45585
45586 @node Memory Transfer
45587 @unnumberedsubsubsec Memory Transfer
45588 @cindex memory transfer, in file-i/o protocol
45589
45590 Structured data which is transferred using a memory read or write (for
45591 example, a @code{struct stat}) is expected to be in a protocol-specific format
45592 with all scalar multibyte datatypes being big endian. Translation to
45593 this representation needs to be done both by the target before the @code{F}
45594 packet is sent, and by @value{GDBN} before
45595 it transfers memory to the target. Transferred pointers to structured
45596 data should point to the already-coerced data at any time.
45597
45598
45599 @node struct stat
45600 @unnumberedsubsubsec struct stat
45601 @cindex struct stat, in file-i/o protocol
45602
45603 The buffer of type @code{struct stat} used by the target and @value{GDBN}
45604 is defined as follows:
45605
45606 @smallexample
45607 struct stat @{
45608 unsigned int st_dev; /* device */
45609 unsigned int st_ino; /* inode */
45610 mode_t st_mode; /* protection */
45611 unsigned int st_nlink; /* number of hard links */
45612 unsigned int st_uid; /* user ID of owner */
45613 unsigned int st_gid; /* group ID of owner */
45614 unsigned int st_rdev; /* device type (if inode device) */
45615 unsigned long st_size; /* total size, in bytes */
45616 unsigned long st_blksize; /* blocksize for filesystem I/O */
45617 unsigned long st_blocks; /* number of blocks allocated */
45618 time_t st_atime; /* time of last access */
45619 time_t st_mtime; /* time of last modification */
45620 time_t st_ctime; /* time of last change */
45621 @};
45622 @end smallexample
45623
45624 The integral datatypes conform to the definitions given in the
45625 appropriate section (see @ref{Integral Datatypes}, for details) so this
45626 structure is of size 64 bytes.
45627
45628 The values of several fields have a restricted meaning and/or
45629 range of values.
45630
45631 @table @code
45632
45633 @item st_dev
45634 A value of 0 represents a file, 1 the console.
45635
45636 @item st_ino
45637 No valid meaning for the target. Transmitted unchanged.
45638
45639 @item st_mode
45640 Valid mode bits are described in @ref{Constants}. Any other
45641 bits have currently no meaning for the target.
45642
45643 @item st_uid
45644 @itemx st_gid
45645 @itemx st_rdev
45646 No valid meaning for the target. Transmitted unchanged.
45647
45648 @item st_atime
45649 @itemx st_mtime
45650 @itemx st_ctime
45651 These values have a host and file system dependent
45652 accuracy. Especially on Windows hosts, the file system may not
45653 support exact timing values.
45654 @end table
45655
45656 The target gets a @code{struct stat} of the above representation and is
45657 responsible for coercing it to the target representation before
45658 continuing.
45659
45660 Note that due to size differences between the host, target, and protocol
45661 representations of @code{struct stat} members, these members could eventually
45662 get truncated on the target.
45663
45664 @node struct timeval
45665 @unnumberedsubsubsec struct timeval
45666 @cindex struct timeval, in file-i/o protocol
45667
45668 The buffer of type @code{struct timeval} used by the File-I/O protocol
45669 is defined as follows:
45670
45671 @smallexample
45672 struct timeval @{
45673 time_t tv_sec; /* second */
45674 long tv_usec; /* microsecond */
45675 @};
45676 @end smallexample
45677
45678 The integral datatypes conform to the definitions given in the
45679 appropriate section (see @ref{Integral Datatypes}, for details) so this
45680 structure is of size 8 bytes.
45681
45682 @node Constants
45683 @subsection Constants
45684 @cindex constants, in file-i/o protocol
45685
45686 The following values are used for the constants inside of the
45687 protocol. @value{GDBN} and target are responsible for translating these
45688 values before and after the call as needed.
45689
45690 @menu
45691 * Open Flags::
45692 * mode_t Values::
45693 * Errno Values::
45694 * Lseek Flags::
45695 * Limits::
45696 @end menu
45697
45698 @node Open Flags
45699 @unnumberedsubsubsec Open Flags
45700 @cindex open flags, in file-i/o protocol
45701
45702 All values are given in hexadecimal representation.
45703
45704 @smallexample
45705 O_RDONLY 0x0
45706 O_WRONLY 0x1
45707 O_RDWR 0x2
45708 O_APPEND 0x8
45709 O_CREAT 0x200
45710 O_TRUNC 0x400
45711 O_EXCL 0x800
45712 @end smallexample
45713
45714 @node mode_t Values
45715 @unnumberedsubsubsec mode_t Values
45716 @cindex mode_t values, in file-i/o protocol
45717
45718 All values are given in octal representation.
45719
45720 @smallexample
45721 S_IFREG 0100000
45722 S_IFDIR 040000
45723 S_IRUSR 0400
45724 S_IWUSR 0200
45725 S_IXUSR 0100
45726 S_IRGRP 040
45727 S_IWGRP 020
45728 S_IXGRP 010
45729 S_IROTH 04
45730 S_IWOTH 02
45731 S_IXOTH 01
45732 @end smallexample
45733
45734 @node Errno Values
45735 @unnumberedsubsubsec Errno Values
45736 @cindex errno values, in file-i/o protocol
45737
45738 All values are given in decimal representation.
45739
45740 @smallexample
45741 EPERM 1
45742 ENOENT 2
45743 EINTR 4
45744 EBADF 9
45745 EACCES 13
45746 EFAULT 14
45747 EBUSY 16
45748 EEXIST 17
45749 ENODEV 19
45750 ENOTDIR 20
45751 EISDIR 21
45752 EINVAL 22
45753 ENFILE 23
45754 EMFILE 24
45755 EFBIG 27
45756 ENOSPC 28
45757 ESPIPE 29
45758 EROFS 30
45759 ENAMETOOLONG 91
45760 EUNKNOWN 9999
45761 @end smallexample
45762
45763 @code{EUNKNOWN} is used as a fallback error value if a host system returns
45764 any error value not in the list of supported error numbers.
45765
45766 @node Lseek Flags
45767 @unnumberedsubsubsec Lseek Flags
45768 @cindex lseek flags, in file-i/o protocol
45769
45770 @smallexample
45771 SEEK_SET 0
45772 SEEK_CUR 1
45773 SEEK_END 2
45774 @end smallexample
45775
45776 @node Limits
45777 @unnumberedsubsubsec Limits
45778 @cindex limits, in file-i/o protocol
45779
45780 All values are given in decimal representation.
45781
45782 @smallexample
45783 INT_MIN -2147483648
45784 INT_MAX 2147483647
45785 UINT_MAX 4294967295
45786 LONG_MIN -9223372036854775808
45787 LONG_MAX 9223372036854775807
45788 ULONG_MAX 18446744073709551615
45789 @end smallexample
45790
45791 @node File-I/O Examples
45792 @subsection File-I/O Examples
45793 @cindex file-i/o examples
45794
45795 Example sequence of a write call, file descriptor 3, buffer is at target
45796 address 0x1234, 6 bytes should be written:
45797
45798 @smallexample
45799 <- @code{Fwrite,3,1234,6}
45800 @emph{request memory read from target}
45801 -> @code{m1234,6}
45802 <- XXXXXX
45803 @emph{return "6 bytes written"}
45804 -> @code{F6}
45805 @end smallexample
45806
45807 Example sequence of a read call, file descriptor 3, buffer is at target
45808 address 0x1234, 6 bytes should be read:
45809
45810 @smallexample
45811 <- @code{Fread,3,1234,6}
45812 @emph{request memory write to target}
45813 -> @code{X1234,6:XXXXXX}
45814 @emph{return "6 bytes read"}
45815 -> @code{F6}
45816 @end smallexample
45817
45818 Example sequence of a read call, call fails on the host due to invalid
45819 file descriptor (@code{EBADF}):
45820
45821 @smallexample
45822 <- @code{Fread,3,1234,6}
45823 -> @code{F-1,9}
45824 @end smallexample
45825
45826 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
45827 host is called:
45828
45829 @smallexample
45830 <- @code{Fread,3,1234,6}
45831 -> @code{F-1,4,C}
45832 <- @code{T02}
45833 @end smallexample
45834
45835 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
45836 host is called:
45837
45838 @smallexample
45839 <- @code{Fread,3,1234,6}
45840 -> @code{X1234,6:XXXXXX}
45841 <- @code{T02}
45842 @end smallexample
45843
45844 @node Library List Format
45845 @section Library List Format
45846 @cindex library list format, remote protocol
45847
45848 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
45849 same process as your application to manage libraries. In this case,
45850 @value{GDBN} can use the loader's symbol table and normal memory
45851 operations to maintain a list of shared libraries. On other
45852 platforms, the operating system manages loaded libraries.
45853 @value{GDBN} can not retrieve the list of currently loaded libraries
45854 through memory operations, so it uses the @samp{qXfer:libraries:read}
45855 packet (@pxref{qXfer library list read}) instead. The remote stub
45856 queries the target's operating system and reports which libraries
45857 are loaded.
45858
45859 The @samp{qXfer:libraries:read} packet returns an XML document which
45860 lists loaded libraries and their offsets. Each library has an
45861 associated name and one or more segment or section base addresses,
45862 which report where the library was loaded in memory.
45863
45864 For the common case of libraries that are fully linked binaries, the
45865 library should have a list of segments. If the target supports
45866 dynamic linking of a relocatable object file, its library XML element
45867 should instead include a list of allocated sections. The segment or
45868 section bases are start addresses, not relocation offsets; they do not
45869 depend on the library's link-time base addresses.
45870
45871 @value{GDBN} must be linked with the Expat library to support XML
45872 library lists. @xref{Expat}.
45873
45874 A simple memory map, with one loaded library relocated by a single
45875 offset, looks like this:
45876
45877 @smallexample
45878 <library-list>
45879 <library name="/lib/libc.so.6">
45880 <segment address="0x10000000"/>
45881 </library>
45882 </library-list>
45883 @end smallexample
45884
45885 Another simple memory map, with one loaded library with three
45886 allocated sections (.text, .data, .bss), looks like this:
45887
45888 @smallexample
45889 <library-list>
45890 <library name="sharedlib.o">
45891 <section address="0x10000000"/>
45892 <section address="0x20000000"/>
45893 <section address="0x30000000"/>
45894 </library>
45895 </library-list>
45896 @end smallexample
45897
45898 The format of a library list is described by this DTD:
45899
45900 @smallexample
45901 <!-- library-list: Root element with versioning -->
45902 <!ELEMENT library-list (library)*>
45903 <!ATTLIST library-list version CDATA #FIXED "1.0">
45904 <!ELEMENT library (segment*, section*)>
45905 <!ATTLIST library name CDATA #REQUIRED>
45906 <!ELEMENT segment EMPTY>
45907 <!ATTLIST segment address CDATA #REQUIRED>
45908 <!ELEMENT section EMPTY>
45909 <!ATTLIST section address CDATA #REQUIRED>
45910 @end smallexample
45911
45912 In addition, segments and section descriptors cannot be mixed within a
45913 single library element, and you must supply at least one segment or
45914 section for each library.
45915
45916 @node Library List Format for SVR4 Targets
45917 @section Library List Format for SVR4 Targets
45918 @cindex library list format, remote protocol
45919
45920 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
45921 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
45922 shared libraries. Still a special library list provided by this packet is
45923 more efficient for the @value{GDBN} remote protocol.
45924
45925 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
45926 loaded libraries and their SVR4 linker parameters. For each library on SVR4
45927 target, the following parameters are reported:
45928
45929 @itemize @minus
45930 @item
45931 @code{name}, the absolute file name from the @code{l_name} field of
45932 @code{struct link_map}.
45933 @item
45934 @code{lm} with address of @code{struct link_map} used for TLS
45935 (Thread Local Storage) access.
45936 @item
45937 @code{l_addr}, the displacement as read from the field @code{l_addr} of
45938 @code{struct link_map}. For prelinked libraries this is not an absolute
45939 memory address. It is a displacement of absolute memory address against
45940 address the file was prelinked to during the library load.
45941 @item
45942 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
45943 @end itemize
45944
45945 Additionally the single @code{main-lm} attribute specifies address of
45946 @code{struct link_map} used for the main executable. This parameter is used
45947 for TLS access and its presence is optional.
45948
45949 @value{GDBN} must be linked with the Expat library to support XML
45950 SVR4 library lists. @xref{Expat}.
45951
45952 A simple memory map, with two loaded libraries (which do not use prelink),
45953 looks like this:
45954
45955 @smallexample
45956 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
45957 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
45958 l_ld="0xe4eefc"/>
45959 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
45960 l_ld="0x152350"/>
45961 </library-list-svr>
45962 @end smallexample
45963
45964 The format of an SVR4 library list is described by this DTD:
45965
45966 @smallexample
45967 <!-- library-list-svr4: Root element with versioning -->
45968 <!ELEMENT library-list-svr4 (library)*>
45969 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
45970 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
45971 <!ELEMENT library EMPTY>
45972 <!ATTLIST library name CDATA #REQUIRED>
45973 <!ATTLIST library lm CDATA #REQUIRED>
45974 <!ATTLIST library l_addr CDATA #REQUIRED>
45975 <!ATTLIST library l_ld CDATA #REQUIRED>
45976 @end smallexample
45977
45978 @node Memory Map Format
45979 @section Memory Map Format
45980 @cindex memory map format
45981
45982 To be able to write into flash memory, @value{GDBN} needs to obtain a
45983 memory map from the target. This section describes the format of the
45984 memory map.
45985
45986 The memory map is obtained using the @samp{qXfer:memory-map:read}
45987 (@pxref{qXfer memory map read}) packet and is an XML document that
45988 lists memory regions.
45989
45990 @value{GDBN} must be linked with the Expat library to support XML
45991 memory maps. @xref{Expat}.
45992
45993 The top-level structure of the document is shown below:
45994
45995 @smallexample
45996 <?xml version="1.0"?>
45997 <!DOCTYPE memory-map
45998 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45999 "http://sourceware.org/gdb/gdb-memory-map.dtd">
46000 <memory-map>
46001 region...
46002 </memory-map>
46003 @end smallexample
46004
46005 Each region can be either:
46006
46007 @itemize
46008
46009 @item
46010 A region of RAM starting at @var{addr} and extending for @var{length}
46011 bytes from there:
46012
46013 @smallexample
46014 <memory type="ram" start="@var{addr}" length="@var{length}"/>
46015 @end smallexample
46016
46017
46018 @item
46019 A region of read-only memory:
46020
46021 @smallexample
46022 <memory type="rom" start="@var{addr}" length="@var{length}"/>
46023 @end smallexample
46024
46025
46026 @item
46027 A region of flash memory, with erasure blocks @var{blocksize}
46028 bytes in length:
46029
46030 @smallexample
46031 <memory type="flash" start="@var{addr}" length="@var{length}">
46032 <property name="blocksize">@var{blocksize}</property>
46033 </memory>
46034 @end smallexample
46035
46036 @end itemize
46037
46038 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
46039 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
46040 packets to write to addresses in such ranges.
46041
46042 The formal DTD for memory map format is given below:
46043
46044 @smallexample
46045 <!-- ................................................... -->
46046 <!-- Memory Map XML DTD ................................ -->
46047 <!-- File: memory-map.dtd .............................. -->
46048 <!-- .................................... .............. -->
46049 <!-- memory-map.dtd -->
46050 <!-- memory-map: Root element with versioning -->
46051 <!ELEMENT memory-map (memory)*>
46052 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
46053 <!ELEMENT memory (property)*>
46054 <!-- memory: Specifies a memory region,
46055 and its type, or device. -->
46056 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
46057 start CDATA #REQUIRED
46058 length CDATA #REQUIRED>
46059 <!-- property: Generic attribute tag -->
46060 <!ELEMENT property (#PCDATA | property)*>
46061 <!ATTLIST property name (blocksize) #REQUIRED>
46062 @end smallexample
46063
46064 @node Thread List Format
46065 @section Thread List Format
46066 @cindex thread list format
46067
46068 To efficiently update the list of threads and their attributes,
46069 @value{GDBN} issues the @samp{qXfer:threads:read} packet
46070 (@pxref{qXfer threads read}) and obtains the XML document with
46071 the following structure:
46072
46073 @smallexample
46074 <?xml version="1.0"?>
46075 <threads>
46076 <thread id="id" core="0" name="name">
46077 ... description ...
46078 </thread>
46079 </threads>
46080 @end smallexample
46081
46082 Each @samp{thread} element must have the @samp{id} attribute that
46083 identifies the thread (@pxref{thread-id syntax}). The
46084 @samp{core} attribute, if present, specifies which processor core
46085 the thread was last executing on. The @samp{name} attribute, if
46086 present, specifies the human-readable name of the thread. The content
46087 of the of @samp{thread} element is interpreted as human-readable
46088 auxiliary information. The @samp{handle} attribute, if present,
46089 is a hex encoded representation of the thread handle.
46090
46091
46092 @node Traceframe Info Format
46093 @section Traceframe Info Format
46094 @cindex traceframe info format
46095
46096 To be able to know which objects in the inferior can be examined when
46097 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
46098 memory ranges, registers and trace state variables that have been
46099 collected in a traceframe.
46100
46101 This list is obtained using the @samp{qXfer:traceframe-info:read}
46102 (@pxref{qXfer traceframe info read}) packet and is an XML document.
46103
46104 @value{GDBN} must be linked with the Expat library to support XML
46105 traceframe info discovery. @xref{Expat}.
46106
46107 The top-level structure of the document is shown below:
46108
46109 @smallexample
46110 <?xml version="1.0"?>
46111 <!DOCTYPE traceframe-info
46112 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
46113 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
46114 <traceframe-info>
46115 block...
46116 </traceframe-info>
46117 @end smallexample
46118
46119 Each traceframe block can be either:
46120
46121 @itemize
46122
46123 @item
46124 A region of collected memory starting at @var{addr} and extending for
46125 @var{length} bytes from there:
46126
46127 @smallexample
46128 <memory start="@var{addr}" length="@var{length}"/>
46129 @end smallexample
46130
46131 @item
46132 A block indicating trace state variable numbered @var{number} has been
46133 collected:
46134
46135 @smallexample
46136 <tvar id="@var{number}"/>
46137 @end smallexample
46138
46139 @end itemize
46140
46141 The formal DTD for the traceframe info format is given below:
46142
46143 @smallexample
46144 <!ELEMENT traceframe-info (memory | tvar)* >
46145 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
46146
46147 <!ELEMENT memory EMPTY>
46148 <!ATTLIST memory start CDATA #REQUIRED
46149 length CDATA #REQUIRED>
46150 <!ELEMENT tvar>
46151 <!ATTLIST tvar id CDATA #REQUIRED>
46152 @end smallexample
46153
46154 @node Branch Trace Format
46155 @section Branch Trace Format
46156 @cindex branch trace format
46157
46158 In order to display the branch trace of an inferior thread,
46159 @value{GDBN} needs to obtain the list of branches. This list is
46160 represented as list of sequential code blocks that are connected via
46161 branches. The code in each block has been executed sequentially.
46162
46163 This list is obtained using the @samp{qXfer:btrace:read}
46164 (@pxref{qXfer btrace read}) packet and is an XML document.
46165
46166 @value{GDBN} must be linked with the Expat library to support XML
46167 traceframe info discovery. @xref{Expat}.
46168
46169 The top-level structure of the document is shown below:
46170
46171 @smallexample
46172 <?xml version="1.0"?>
46173 <!DOCTYPE btrace
46174 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
46175 "http://sourceware.org/gdb/gdb-btrace.dtd">
46176 <btrace>
46177 block...
46178 </btrace>
46179 @end smallexample
46180
46181 @itemize
46182
46183 @item
46184 A block of sequentially executed instructions starting at @var{begin}
46185 and ending at @var{end}:
46186
46187 @smallexample
46188 <block begin="@var{begin}" end="@var{end}"/>
46189 @end smallexample
46190
46191 @end itemize
46192
46193 The formal DTD for the branch trace format is given below:
46194
46195 @smallexample
46196 <!ELEMENT btrace (block* | pt) >
46197 <!ATTLIST btrace version CDATA #FIXED "1.0">
46198
46199 <!ELEMENT block EMPTY>
46200 <!ATTLIST block begin CDATA #REQUIRED
46201 end CDATA #REQUIRED>
46202
46203 <!ELEMENT pt (pt-config?, raw?)>
46204
46205 <!ELEMENT pt-config (cpu?)>
46206
46207 <!ELEMENT cpu EMPTY>
46208 <!ATTLIST cpu vendor CDATA #REQUIRED
46209 family CDATA #REQUIRED
46210 model CDATA #REQUIRED
46211 stepping CDATA #REQUIRED>
46212
46213 <!ELEMENT raw (#PCDATA)>
46214 @end smallexample
46215
46216 @node Branch Trace Configuration Format
46217 @section Branch Trace Configuration Format
46218 @cindex branch trace configuration format
46219
46220 For each inferior thread, @value{GDBN} can obtain the branch trace
46221 configuration using the @samp{qXfer:btrace-conf:read}
46222 (@pxref{qXfer btrace-conf read}) packet.
46223
46224 The configuration describes the branch trace format and configuration
46225 settings for that format. The following information is described:
46226
46227 @table @code
46228 @item bts
46229 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
46230 @table @code
46231 @item size
46232 The size of the @acronym{BTS} ring buffer in bytes.
46233 @end table
46234 @item pt
46235 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
46236 PT}) format.
46237 @table @code
46238 @item size
46239 The size of the @acronym{Intel PT} ring buffer in bytes.
46240 @end table
46241 @end table
46242
46243 @value{GDBN} must be linked with the Expat library to support XML
46244 branch trace configuration discovery. @xref{Expat}.
46245
46246 The formal DTD for the branch trace configuration format is given below:
46247
46248 @smallexample
46249 <!ELEMENT btrace-conf (bts?, pt?)>
46250 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
46251
46252 <!ELEMENT bts EMPTY>
46253 <!ATTLIST bts size CDATA #IMPLIED>
46254
46255 <!ELEMENT pt EMPTY>
46256 <!ATTLIST pt size CDATA #IMPLIED>
46257 @end smallexample
46258
46259 @include agentexpr.texi
46260
46261 @node Target Descriptions
46262 @appendix Target Descriptions
46263 @cindex target descriptions
46264
46265 One of the challenges of using @value{GDBN} to debug embedded systems
46266 is that there are so many minor variants of each processor
46267 architecture in use. It is common practice for vendors to start with
46268 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
46269 and then make changes to adapt it to a particular market niche. Some
46270 architectures have hundreds of variants, available from dozens of
46271 vendors. This leads to a number of problems:
46272
46273 @itemize @bullet
46274 @item
46275 With so many different customized processors, it is difficult for
46276 the @value{GDBN} maintainers to keep up with the changes.
46277 @item
46278 Since individual variants may have short lifetimes or limited
46279 audiences, it may not be worthwhile to carry information about every
46280 variant in the @value{GDBN} source tree.
46281 @item
46282 When @value{GDBN} does support the architecture of the embedded system
46283 at hand, the task of finding the correct architecture name to give the
46284 @command{set architecture} command can be error-prone.
46285 @end itemize
46286
46287 To address these problems, the @value{GDBN} remote protocol allows a
46288 target system to not only identify itself to @value{GDBN}, but to
46289 actually describe its own features. This lets @value{GDBN} support
46290 processor variants it has never seen before --- to the extent that the
46291 descriptions are accurate, and that @value{GDBN} understands them.
46292
46293 @value{GDBN} must be linked with the Expat library to support XML
46294 target descriptions. @xref{Expat}.
46295
46296 @menu
46297 * Retrieving Descriptions:: How descriptions are fetched from a target.
46298 * Target Description Format:: The contents of a target description.
46299 * Predefined Target Types:: Standard types available for target
46300 descriptions.
46301 * Enum Target Types:: How to define enum target types.
46302 * Standard Target Features:: Features @value{GDBN} knows about.
46303 @end menu
46304
46305 @node Retrieving Descriptions
46306 @section Retrieving Descriptions
46307
46308 Target descriptions can be read from the target automatically, or
46309 specified by the user manually. The default behavior is to read the
46310 description from the target. @value{GDBN} retrieves it via the remote
46311 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
46312 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
46313 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
46314 XML document, of the form described in @ref{Target Description
46315 Format}.
46316
46317 Alternatively, you can specify a file to read for the target description.
46318 If a file is set, the target will not be queried. The commands to
46319 specify a file are:
46320
46321 @table @code
46322 @cindex set tdesc filename
46323 @item set tdesc filename @var{path}
46324 Read the target description from @var{path}.
46325
46326 @cindex unset tdesc filename
46327 @item unset tdesc filename
46328 Do not read the XML target description from a file. @value{GDBN}
46329 will use the description supplied by the current target.
46330
46331 @cindex show tdesc filename
46332 @item show tdesc filename
46333 Show the filename to read for a target description, if any.
46334 @end table
46335
46336
46337 @node Target Description Format
46338 @section Target Description Format
46339 @cindex target descriptions, XML format
46340
46341 A target description annex is an @uref{http://www.w3.org/XML/, XML}
46342 document which complies with the Document Type Definition provided in
46343 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
46344 means you can use generally available tools like @command{xmllint} to
46345 check that your feature descriptions are well-formed and valid.
46346 However, to help people unfamiliar with XML write descriptions for
46347 their targets, we also describe the grammar here.
46348
46349 Target descriptions can identify the architecture of the remote target
46350 and (for some architectures) provide information about custom register
46351 sets. They can also identify the OS ABI of the remote target.
46352 @value{GDBN} can use this information to autoconfigure for your
46353 target, or to warn you if you connect to an unsupported target.
46354
46355 Here is a simple target description:
46356
46357 @smallexample
46358 <target version="1.0">
46359 <architecture>i386:x86-64</architecture>
46360 </target>
46361 @end smallexample
46362
46363 @noindent
46364 This minimal description only says that the target uses
46365 the x86-64 architecture.
46366
46367 A target description has the following overall form, with [ ] marking
46368 optional elements and @dots{} marking repeatable elements. The elements
46369 are explained further below.
46370
46371 @smallexample
46372 <?xml version="1.0"?>
46373 <!DOCTYPE target SYSTEM "gdb-target.dtd">
46374 <target version="1.0">
46375 @r{[}@var{architecture}@r{]}
46376 @r{[}@var{osabi}@r{]}
46377 @r{[}@var{compatible}@r{]}
46378 @r{[}@var{feature}@dots{}@r{]}
46379 </target>
46380 @end smallexample
46381
46382 @noindent
46383 The description is generally insensitive to whitespace and line
46384 breaks, under the usual common-sense rules. The XML version
46385 declaration and document type declaration can generally be omitted
46386 (@value{GDBN} does not require them), but specifying them may be
46387 useful for XML validation tools. The @samp{version} attribute for
46388 @samp{<target>} may also be omitted, but we recommend
46389 including it; if future versions of @value{GDBN} use an incompatible
46390 revision of @file{gdb-target.dtd}, they will detect and report
46391 the version mismatch.
46392
46393 @subsection Inclusion
46394 @cindex target descriptions, inclusion
46395 @cindex XInclude
46396 @ifnotinfo
46397 @cindex <xi:include>
46398 @end ifnotinfo
46399
46400 It can sometimes be valuable to split a target description up into
46401 several different annexes, either for organizational purposes, or to
46402 share files between different possible target descriptions. You can
46403 divide a description into multiple files by replacing any element of
46404 the target description with an inclusion directive of the form:
46405
46406 @smallexample
46407 <xi:include href="@var{document}"/>
46408 @end smallexample
46409
46410 @noindent
46411 When @value{GDBN} encounters an element of this form, it will retrieve
46412 the named XML @var{document}, and replace the inclusion directive with
46413 the contents of that document. If the current description was read
46414 using @samp{qXfer}, then so will be the included document;
46415 @var{document} will be interpreted as the name of an annex. If the
46416 current description was read from a file, @value{GDBN} will look for
46417 @var{document} as a file in the same directory where it found the
46418 original description.
46419
46420 @subsection Architecture
46421 @cindex <architecture>
46422
46423 An @samp{<architecture>} element has this form:
46424
46425 @smallexample
46426 <architecture>@var{arch}</architecture>
46427 @end smallexample
46428
46429 @var{arch} is one of the architectures from the set accepted by
46430 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
46431
46432 @subsection OS ABI
46433 @cindex @code{<osabi>}
46434
46435 This optional field was introduced in @value{GDBN} version 7.0.
46436 Previous versions of @value{GDBN} ignore it.
46437
46438 An @samp{<osabi>} element has this form:
46439
46440 @smallexample
46441 <osabi>@var{abi-name}</osabi>
46442 @end smallexample
46443
46444 @var{abi-name} is an OS ABI name from the same selection accepted by
46445 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
46446
46447 @subsection Compatible Architecture
46448 @cindex @code{<compatible>}
46449
46450 This optional field was introduced in @value{GDBN} version 7.0.
46451 Previous versions of @value{GDBN} ignore it.
46452
46453 A @samp{<compatible>} element has this form:
46454
46455 @smallexample
46456 <compatible>@var{arch}</compatible>
46457 @end smallexample
46458
46459 @var{arch} is one of the architectures from the set accepted by
46460 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
46461
46462 A @samp{<compatible>} element is used to specify that the target
46463 is able to run binaries in some other than the main target architecture
46464 given by the @samp{<architecture>} element. For example, on the
46465 Cell Broadband Engine, the main architecture is @code{powerpc:common}
46466 or @code{powerpc:common64}, but the system is able to run binaries
46467 in the @code{spu} architecture as well. The way to describe this
46468 capability with @samp{<compatible>} is as follows:
46469
46470 @smallexample
46471 <architecture>powerpc:common</architecture>
46472 <compatible>spu</compatible>
46473 @end smallexample
46474
46475 @subsection Features
46476 @cindex <feature>
46477
46478 Each @samp{<feature>} describes some logical portion of the target
46479 system. Features are currently used to describe available CPU
46480 registers and the types of their contents. A @samp{<feature>} element
46481 has this form:
46482
46483 @smallexample
46484 <feature name="@var{name}">
46485 @r{[}@var{type}@dots{}@r{]}
46486 @var{reg}@dots{}
46487 </feature>
46488 @end smallexample
46489
46490 @noindent
46491 Each feature's name should be unique within the description. The name
46492 of a feature does not matter unless @value{GDBN} has some special
46493 knowledge of the contents of that feature; if it does, the feature
46494 should have its standard name. @xref{Standard Target Features}.
46495
46496 @subsection Types
46497
46498 Any register's value is a collection of bits which @value{GDBN} must
46499 interpret. The default interpretation is a two's complement integer,
46500 but other types can be requested by name in the register description.
46501 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
46502 Target Types}), and the description can define additional composite
46503 and enum types.
46504
46505 Each type element must have an @samp{id} attribute, which gives
46506 a unique (within the containing @samp{<feature>}) name to the type.
46507 Types must be defined before they are used.
46508
46509 @cindex <vector>
46510 Some targets offer vector registers, which can be treated as arrays
46511 of scalar elements. These types are written as @samp{<vector>} elements,
46512 specifying the array element type, @var{type}, and the number of elements,
46513 @var{count}:
46514
46515 @smallexample
46516 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
46517 @end smallexample
46518
46519 @cindex <union>
46520 If a register's value is usefully viewed in multiple ways, define it
46521 with a union type containing the useful representations. The
46522 @samp{<union>} element contains one or more @samp{<field>} elements,
46523 each of which has a @var{name} and a @var{type}:
46524
46525 @smallexample
46526 <union id="@var{id}">
46527 <field name="@var{name}" type="@var{type}"/>
46528 @dots{}
46529 </union>
46530 @end smallexample
46531
46532 @cindex <struct>
46533 @cindex <flags>
46534 If a register's value is composed from several separate values, define
46535 it with either a structure type or a flags type.
46536 A flags type may only contain bitfields.
46537 A structure type may either contain only bitfields or contain no bitfields.
46538 If the value contains only bitfields, its total size in bytes must be
46539 specified.
46540
46541 Non-bitfield values have a @var{name} and @var{type}.
46542
46543 @smallexample
46544 <struct id="@var{id}">
46545 <field name="@var{name}" type="@var{type}"/>
46546 @dots{}
46547 </struct>
46548 @end smallexample
46549
46550 Both @var{name} and @var{type} values are required.
46551 No implicit padding is added.
46552
46553 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
46554
46555 @smallexample
46556 <struct id="@var{id}" size="@var{size}">
46557 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
46558 @dots{}
46559 </struct>
46560 @end smallexample
46561
46562 @smallexample
46563 <flags id="@var{id}" size="@var{size}">
46564 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
46565 @dots{}
46566 </flags>
46567 @end smallexample
46568
46569 The @var{name} value is required.
46570 Bitfield values may be named with the empty string, @samp{""},
46571 in which case the field is ``filler'' and its value is not printed.
46572 Not all bits need to be specified, so ``filler'' fields are optional.
46573
46574 The @var{start} and @var{end} values are required, and @var{type}
46575 is optional.
46576 The field's @var{start} must be less than or equal to its @var{end},
46577 and zero represents the least significant bit.
46578
46579 The default value of @var{type} is @code{bool} for single bit fields,
46580 and an unsigned integer otherwise.
46581
46582 Which to choose? Structures or flags?
46583
46584 Registers defined with @samp{flags} have these advantages over
46585 defining them with @samp{struct}:
46586
46587 @itemize @bullet
46588 @item
46589 Arithmetic may be performed on them as if they were integers.
46590 @item
46591 They are printed in a more readable fashion.
46592 @end itemize
46593
46594 Registers defined with @samp{struct} have one advantage over
46595 defining them with @samp{flags}:
46596
46597 @itemize @bullet
46598 @item
46599 One can fetch individual fields like in @samp{C}.
46600
46601 @smallexample
46602 (gdb) print $my_struct_reg.field3
46603 $1 = 42
46604 @end smallexample
46605
46606 @end itemize
46607
46608 @subsection Registers
46609 @cindex <reg>
46610
46611 Each register is represented as an element with this form:
46612
46613 @smallexample
46614 <reg name="@var{name}"
46615 bitsize="@var{size}"
46616 @r{[}regnum="@var{num}"@r{]}
46617 @r{[}save-restore="@var{save-restore}"@r{]}
46618 @r{[}type="@var{type}"@r{]}
46619 @r{[}group="@var{group}"@r{]}/>
46620 @end smallexample
46621
46622 @noindent
46623 The components are as follows:
46624
46625 @table @var
46626
46627 @item name
46628 The register's name; it must be unique within the target description.
46629
46630 @item bitsize
46631 The register's size, in bits.
46632
46633 @item regnum
46634 The register's number. If omitted, a register's number is one greater
46635 than that of the previous register (either in the current feature or in
46636 a preceding feature); the first register in the target description
46637 defaults to zero. This register number is used to read or write
46638 the register; e.g.@: it is used in the remote @code{p} and @code{P}
46639 packets, and registers appear in the @code{g} and @code{G} packets
46640 in order of increasing register number.
46641
46642 @item save-restore
46643 Whether the register should be preserved across inferior function
46644 calls; this must be either @code{yes} or @code{no}. The default is
46645 @code{yes}, which is appropriate for most registers except for
46646 some system control registers; this is not related to the target's
46647 ABI.
46648
46649 @item type
46650 The type of the register. It may be a predefined type, a type
46651 defined in the current feature, or one of the special types @code{int}
46652 and @code{float}. @code{int} is an integer type of the correct size
46653 for @var{bitsize}, and @code{float} is a floating point type (in the
46654 architecture's normal floating point format) of the correct size for
46655 @var{bitsize}. The default is @code{int}.
46656
46657 @item group
46658 The register group to which this register belongs. It can be one of the
46659 standard register groups @code{general}, @code{float}, @code{vector} or an
46660 arbitrary string. Group names should be limited to alphanumeric characters.
46661 If a group name is made up of multiple words the words may be separated by
46662 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
46663 @var{group} is specified, @value{GDBN} will not display the register in
46664 @code{info registers}.
46665
46666 @end table
46667
46668 @node Predefined Target Types
46669 @section Predefined Target Types
46670 @cindex target descriptions, predefined types
46671
46672 Type definitions in the self-description can build up composite types
46673 from basic building blocks, but can not define fundamental types. Instead,
46674 standard identifiers are provided by @value{GDBN} for the fundamental
46675 types. The currently supported types are:
46676
46677 @table @code
46678
46679 @item bool
46680 Boolean type, occupying a single bit.
46681
46682 @item int8
46683 @itemx int16
46684 @itemx int24
46685 @itemx int32
46686 @itemx int64
46687 @itemx int128
46688 Signed integer types holding the specified number of bits.
46689
46690 @item uint8
46691 @itemx uint16
46692 @itemx uint24
46693 @itemx uint32
46694 @itemx uint64
46695 @itemx uint128
46696 Unsigned integer types holding the specified number of bits.
46697
46698 @item code_ptr
46699 @itemx data_ptr
46700 Pointers to unspecified code and data. The program counter and
46701 any dedicated return address register may be marked as code
46702 pointers; printing a code pointer converts it into a symbolic
46703 address. The stack pointer and any dedicated address registers
46704 may be marked as data pointers.
46705
46706 @item ieee_half
46707 Half precision IEEE floating point.
46708
46709 @item ieee_single
46710 Single precision IEEE floating point.
46711
46712 @item ieee_double
46713 Double precision IEEE floating point.
46714
46715 @item bfloat16
46716 The 16-bit @dfn{brain floating point} format used e.g.@: by x86 and ARM.
46717
46718 @item arm_fpa_ext
46719 The 12-byte extended precision format used by ARM FPA registers.
46720
46721 @item i387_ext
46722 The 10-byte extended precision format used by x87 registers.
46723
46724 @item i386_eflags
46725 32bit @sc{eflags} register used by x86.
46726
46727 @item i386_mxcsr
46728 32bit @sc{mxcsr} register used by x86.
46729
46730 @end table
46731
46732 @node Enum Target Types
46733 @section Enum Target Types
46734 @cindex target descriptions, enum types
46735
46736 Enum target types are useful in @samp{struct} and @samp{flags}
46737 register descriptions. @xref{Target Description Format}.
46738
46739 Enum types have a name, size and a list of name/value pairs.
46740
46741 @smallexample
46742 <enum id="@var{id}" size="@var{size}">
46743 <evalue name="@var{name}" value="@var{value}"/>
46744 @dots{}
46745 </enum>
46746 @end smallexample
46747
46748 Enums must be defined before they are used.
46749
46750 @smallexample
46751 <enum id="levels_type" size="4">
46752 <evalue name="low" value="0"/>
46753 <evalue name="high" value="1"/>
46754 </enum>
46755 <flags id="flags_type" size="4">
46756 <field name="X" start="0"/>
46757 <field name="LEVEL" start="1" end="1" type="levels_type"/>
46758 </flags>
46759 <reg name="flags" bitsize="32" type="flags_type"/>
46760 @end smallexample
46761
46762 Given that description, a value of 3 for the @samp{flags} register
46763 would be printed as:
46764
46765 @smallexample
46766 (gdb) info register flags
46767 flags 0x3 [ X LEVEL=high ]
46768 @end smallexample
46769
46770 @node Standard Target Features
46771 @section Standard Target Features
46772 @cindex target descriptions, standard features
46773
46774 A target description must contain either no registers or all the
46775 target's registers. If the description contains no registers, then
46776 @value{GDBN} will assume a default register layout, selected based on
46777 the architecture. If the description contains any registers, the
46778 default layout will not be used; the standard registers must be
46779 described in the target description, in such a way that @value{GDBN}
46780 can recognize them.
46781
46782 This is accomplished by giving specific names to feature elements
46783 which contain standard registers. @value{GDBN} will look for features
46784 with those names and verify that they contain the expected registers;
46785 if any known feature is missing required registers, or if any required
46786 feature is missing, @value{GDBN} will reject the target
46787 description. You can add additional registers to any of the
46788 standard features --- @value{GDBN} will display them just as if
46789 they were added to an unrecognized feature.
46790
46791 This section lists the known features and their expected contents.
46792 Sample XML documents for these features are included in the
46793 @value{GDBN} source tree, in the directory @file{gdb/features}.
46794
46795 Names recognized by @value{GDBN} should include the name of the
46796 company or organization which selected the name, and the overall
46797 architecture to which the feature applies; so e.g.@: the feature
46798 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
46799
46800 The names of registers are not case sensitive for the purpose
46801 of recognizing standard features, but @value{GDBN} will only display
46802 registers using the capitalization used in the description.
46803
46804 @menu
46805 * AArch64 Features::
46806 * ARC Features::
46807 * ARM Features::
46808 * i386 Features::
46809 * LoongArch Features::
46810 * MicroBlaze Features::
46811 * MIPS Features::
46812 * M68K Features::
46813 * NDS32 Features::
46814 * Nios II Features::
46815 * OpenRISC 1000 Features::
46816 * PowerPC Features::
46817 * RISC-V Features::
46818 * RX Features::
46819 * S/390 and System z Features::
46820 * Sparc Features::
46821 * TIC6x Features::
46822 @end menu
46823
46824
46825 @node AArch64 Features
46826 @subsection AArch64 Features
46827 @cindex target descriptions, AArch64 features
46828
46829 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
46830 targets. It should contain registers @samp{x0} through @samp{x30},
46831 @samp{sp}, @samp{pc}, and @samp{cpsr}.
46832
46833 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
46834 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
46835 and @samp{fpcr}.
46836
46837 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
46838 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
46839 through @samp{p15}, @samp{ffr} and @samp{vg}.
46840
46841 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
46842 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
46843
46844 @node ARC Features
46845 @subsection ARC Features
46846 @cindex target descriptions, ARC Features
46847
46848 ARC processors are so configurable that even core registers and their numbers
46849 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
46850 registers, which are important to @value{GDBN}, are not ``core'' registers in
46851 ARC. Therefore, there are two features that their presence is mandatory:
46852 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
46853
46854 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
46855 contain registers:
46856
46857 @itemize @minus
46858 @item
46859 @samp{r0} through @samp{r25} for normal register file targets.
46860 @item
46861 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
46862 register file targets.
46863 @item
46864 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
46865 @samp{blink}, @samp{lp_count}, @samp{pcl}.
46866 @end itemize
46867
46868 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
46869 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
46870 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
46871 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
46872 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
46873 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
46874 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
46875 because of their inaccessibility during user space debugging sessions.
46876
46877 Extension core registers @samp{r32} through @samp{r59} are optional and their
46878 existence depends on the configuration. When debugging GNU/Linux applications,
46879 i.e.@: user space debugging, these core registers are not available.
46880
46881 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
46882 is the list of registers pertinent to this feature:
46883
46884 @itemize @minus
46885 @item
46886 mandatory: @samp{pc} and @samp{status32}.
46887 @item
46888 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
46889 @end itemize
46890
46891 @node ARM Features
46892 @subsection ARM Features
46893 @cindex target descriptions, ARM features
46894
46895 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
46896 ARM targets.
46897 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
46898 @samp{lr}, @samp{pc}, and @samp{cpsr}.
46899
46900 For M-profile targets (e.g.@: Cortex-M3), the @samp{org.gnu.gdb.arm.core}
46901 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
46902 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
46903 and @samp{xpsr}.
46904
46905 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
46906 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
46907
46908 The @samp{org.gnu.gdb.arm.m-profile-mve} feature is optional. If present, it
46909 must contain register @samp{vpr}.
46910
46911 If the @samp{org.gnu.gdb.arm.m-profile-mve} feature is available, @value{GDBN}
46912 will synthesize the @samp{p0} pseudo register from @samp{vpr} contents.
46913
46914 If the @samp{org.gnu.gdb.arm.vfp} feature is available alongside the
46915 @samp{org.gnu.gdb.arm.m-profile-mve} feature, @value{GDBN} will
46916 synthesize the @samp{q} pseudo registers from @samp{d} register
46917 contents.
46918
46919 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
46920 it should contain at least registers @samp{wR0} through @samp{wR15} and
46921 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
46922 @samp{wCSSF}, and @samp{wCASF} registers are optional.
46923
46924 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
46925 should contain at least registers @samp{d0} through @samp{d15}. If
46926 they are present, @samp{d16} through @samp{d31} should also be included.
46927 @value{GDBN} will synthesize the single-precision registers from
46928 halves of the double-precision registers.
46929
46930 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
46931 need to contain registers; it instructs @value{GDBN} to display the
46932 VFP double-precision registers as vectors and to synthesize the
46933 quad-precision registers from pairs of double-precision registers.
46934 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
46935 be present and include 32 double-precision registers.
46936
46937 The @samp{org.gnu.gdb.arm.m-profile-pacbti} feature is optional, and
46938 acknowledges support for the ARMv8.1-m PACBTI extensions. @value{GDBN}
46939 will track return address signing states and will decorate backtraces using
46940 the [PAC] marker, similar to AArch64's PAC extension.
46941 @xref{AArch64 PAC}.
46942
46943 @node i386 Features
46944 @subsection i386 Features
46945 @cindex target descriptions, i386 features
46946
46947 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
46948 targets. It should describe the following registers:
46949
46950 @itemize @minus
46951 @item
46952 @samp{eax} through @samp{edi} plus @samp{eip} for i386
46953 @item
46954 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
46955 @item
46956 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
46957 @samp{fs}, @samp{gs}
46958 @item
46959 @samp{st0} through @samp{st7}
46960 @item
46961 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
46962 @samp{foseg}, @samp{fooff} and @samp{fop}
46963 @end itemize
46964
46965 The register sets may be different, depending on the target.
46966
46967 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
46968 describe registers:
46969
46970 @itemize @minus
46971 @item
46972 @samp{xmm0} through @samp{xmm7} for i386
46973 @item
46974 @samp{xmm0} through @samp{xmm15} for amd64
46975 @item
46976 @samp{mxcsr}
46977 @end itemize
46978
46979 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
46980 @samp{org.gnu.gdb.i386.sse} feature. It should
46981 describe the upper 128 bits of @sc{ymm} registers:
46982
46983 @itemize @minus
46984 @item
46985 @samp{ymm0h} through @samp{ymm7h} for i386
46986 @item
46987 @samp{ymm0h} through @samp{ymm15h} for amd64
46988 @end itemize
46989
46990 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
46991 Memory Protection Extension (MPX). It should describe the following registers:
46992
46993 @itemize @minus
46994 @item
46995 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
46996 @item
46997 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
46998 @end itemize
46999
47000 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
47001 describe a single register, @samp{orig_eax}.
47002
47003 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
47004 describe two system registers: @samp{fs_base} and @samp{gs_base}.
47005
47006 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
47007 @samp{org.gnu.gdb.i386.avx} feature. It should
47008 describe additional @sc{xmm} registers:
47009
47010 @itemize @minus
47011 @item
47012 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
47013 @end itemize
47014
47015 It should describe the upper 128 bits of additional @sc{ymm} registers:
47016
47017 @itemize @minus
47018 @item
47019 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
47020 @end itemize
47021
47022 It should
47023 describe the upper 256 bits of @sc{zmm} registers:
47024
47025 @itemize @minus
47026 @item
47027 @samp{zmm0h} through @samp{zmm7h} for i386.
47028 @item
47029 @samp{zmm0h} through @samp{zmm15h} for amd64.
47030 @end itemize
47031
47032 It should
47033 describe the additional @sc{zmm} registers:
47034
47035 @itemize @minus
47036 @item
47037 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
47038 @end itemize
47039
47040 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
47041 describe a single register, @samp{pkru}. It is a 32-bit register
47042 valid for i386 and amd64.
47043
47044 @node LoongArch Features
47045 @subsection LoongArch Features
47046 @cindex target descriptions, LoongArch Features
47047
47048 The @samp{org.gnu.gdb.loongarch.base} feature is required for LoongArch
47049 targets. It should contain the registers @samp{r0} through @samp{r31},
47050 @samp{pc}, and @samp{badv}. Either the architectural names (@samp{r0},
47051 @samp{r1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra}, etc).
47052
47053 @node MicroBlaze Features
47054 @subsection MicroBlaze Features
47055 @cindex target descriptions, MicroBlaze features
47056
47057 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
47058 targets. It should contain registers @samp{r0} through @samp{r31},
47059 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
47060 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
47061 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
47062
47063 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
47064 If present, it should contain registers @samp{rshr} and @samp{rslr}
47065
47066 @node MIPS Features
47067 @subsection @acronym{MIPS} Features
47068 @cindex target descriptions, @acronym{MIPS} features
47069
47070 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
47071 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
47072 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
47073 on the target.
47074
47075 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
47076 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
47077 registers. They may be 32-bit or 64-bit depending on the target.
47078
47079 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
47080 it may be optional in a future version of @value{GDBN}. It should
47081 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
47082 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
47083
47084 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
47085 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
47086 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
47087 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
47088
47089 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
47090 contain a single register, @samp{restart}, which is used by the
47091 Linux kernel to control restartable syscalls.
47092
47093 @node M68K Features
47094 @subsection M68K Features
47095 @cindex target descriptions, M68K features
47096
47097 @table @code
47098 @item @samp{org.gnu.gdb.m68k.core}
47099 @itemx @samp{org.gnu.gdb.coldfire.core}
47100 @itemx @samp{org.gnu.gdb.fido.core}
47101 One of those features must be always present.
47102 The feature that is present determines which flavor of m68k is
47103 used. The feature that is present should contain registers
47104 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
47105 @samp{sp}, @samp{ps} and @samp{pc}.
47106
47107 @item @samp{org.gnu.gdb.coldfire.fp}
47108 This feature is optional. If present, it should contain registers
47109 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
47110 @samp{fpiaddr}.
47111
47112 Note that, despite the fact that this feature's name says
47113 @samp{coldfire}, it is used to describe any floating point registers.
47114 The size of the registers must match the main m68k flavor; so, for
47115 example, if the primary feature is reported as @samp{coldfire}, then
47116 64-bit floating point registers are required.
47117 @end table
47118
47119 @node NDS32 Features
47120 @subsection NDS32 Features
47121 @cindex target descriptions, NDS32 features
47122
47123 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
47124 targets. It should contain at least registers @samp{r0} through
47125 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
47126 and @samp{pc}.
47127
47128 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
47129 it should contain 64-bit double-precision floating-point registers
47130 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
47131 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
47132
47133 @emph{Note:} The first sixteen 64-bit double-precision floating-point
47134 registers are overlapped with the thirty-two 32-bit single-precision
47135 floating-point registers. The 32-bit single-precision registers, if
47136 not being listed explicitly, will be synthesized from halves of the
47137 overlapping 64-bit double-precision registers. Listing 32-bit
47138 single-precision registers explicitly is deprecated, and the
47139 support to it could be totally removed some day.
47140
47141 @node Nios II Features
47142 @subsection Nios II Features
47143 @cindex target descriptions, Nios II features
47144
47145 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
47146 targets. It should contain the 32 core registers (@samp{zero},
47147 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
47148 @samp{pc}, and the 16 control registers (@samp{status} through
47149 @samp{mpuacc}).
47150
47151 @node OpenRISC 1000 Features
47152 @subsection Openrisc 1000 Features
47153 @cindex target descriptions, OpenRISC 1000 features
47154
47155 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
47156 targets. It should contain the 32 general purpose registers (@samp{r0}
47157 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
47158
47159 @node PowerPC Features
47160 @subsection PowerPC Features
47161 @cindex target descriptions, PowerPC features
47162
47163 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
47164 targets. It should contain registers @samp{r0} through @samp{r31},
47165 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
47166 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
47167
47168 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
47169 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
47170
47171 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
47172 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
47173 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
47174 through @samp{v31} as aliases for the corresponding @samp{vrX}
47175 registers.
47176
47177 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
47178 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
47179 combine these registers with the floating point registers (@samp{f0}
47180 through @samp{f31}) and the altivec registers (@samp{vr0} through
47181 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
47182 @samp{vs63}, the set of vector-scalar registers for POWER7.
47183 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
47184 @samp{org.gnu.gdb.power.altivec}.
47185
47186 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
47187 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
47188 @samp{spefscr}. SPE targets should provide 32-bit registers in
47189 @samp{org.gnu.gdb.power.core} and provide the upper halves in
47190 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
47191 these to present registers @samp{ev0} through @samp{ev31} to the
47192 user.
47193
47194 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
47195 contain the 64-bit register @samp{ppr}.
47196
47197 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
47198 contain the 64-bit register @samp{dscr}.
47199
47200 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
47201 contain the 64-bit register @samp{tar}.
47202
47203 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
47204 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
47205 64-bit wide.
47206
47207 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
47208 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
47209 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
47210 server PMU registers provided by @sc{gnu}/Linux.
47211
47212 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
47213 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
47214 64-bit wide.
47215
47216 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
47217 contain the checkpointed general-purpose registers @samp{cr0} through
47218 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
47219 @samp{cctr}. These registers may all be either 32-bit or 64-bit
47220 depending on the target. It should also contain the checkpointed
47221 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
47222 wide.
47223
47224 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
47225 contain the checkpointed 64-bit floating-point registers @samp{cf0}
47226 through @samp{cf31}, as well as the checkpointed 64-bit register
47227 @samp{cfpscr}.
47228
47229 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
47230 should contain the checkpointed altivec registers @samp{cvr0} through
47231 @samp{cvr31}, all 128-bit wide. It should also contain the
47232 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
47233 wide.
47234
47235 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
47236 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
47237 will combine these registers with the checkpointed floating point
47238 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
47239 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
47240 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
47241 @samp{cvs63}. Therefore, this feature requires both
47242 @samp{org.gnu.gdb.power.htm.altivec} and
47243 @samp{org.gnu.gdb.power.htm.fpu}.
47244
47245 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
47246 contain the 64-bit checkpointed register @samp{cppr}.
47247
47248 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
47249 contain the 64-bit checkpointed register @samp{cdscr}.
47250
47251 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
47252 contain the 64-bit checkpointed register @samp{ctar}.
47253
47254
47255 @node RISC-V Features
47256 @subsection RISC-V Features
47257 @cindex target descriptions, RISC-V Features
47258
47259 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
47260 targets. It should contain the registers @samp{x0} through
47261 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
47262 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
47263 etc).
47264
47265 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
47266 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
47267 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
47268 architectural register names, or the ABI names can be used.
47269
47270 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
47271 it should contain registers that are not backed by real registers on
47272 the target, but are instead virtual, where the register value is
47273 derived from other target state. In many ways these are like
47274 @value{GDBN}s pseudo-registers, except implemented by the target.
47275 Currently the only register expected in this set is the one byte
47276 @samp{priv} register that contains the target's privilege level in the
47277 least significant two bits.
47278
47279 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
47280 should contain all of the target's standard CSRs. Standard CSRs are
47281 those defined in the RISC-V specification documents. There is some
47282 overlap between this feature and the fpu feature; the @samp{fflags},
47283 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
47284 expectation is that these registers will be in the fpu feature if the
47285 target has floating point hardware, but can be moved into the csr
47286 feature if the target has the floating point control registers, but no
47287 other floating point hardware.
47288
47289 The @samp{org.gnu.gdb.riscv.vector} feature is optional. If present,
47290 it should contain registers @samp{v0} through @samp{v31}, all of which
47291 must be the same size. These requirements are based on the v0.10
47292 draft vector extension, as the vector extension is not yet final. In
47293 the event that the register set of the vector extension changes for
47294 the final specification, the requirements given here could change for
47295 future releases of @value{GDBN}.
47296
47297 @node RX Features
47298 @subsection RX Features
47299 @cindex target descriptions, RX Features
47300
47301 The @samp{org.gnu.gdb.rx.core} feature is required for RX
47302 targets. It should contain the registers @samp{r0} through
47303 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
47304 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
47305
47306 @node S/390 and System z Features
47307 @subsection S/390 and System z Features
47308 @cindex target descriptions, S/390 features
47309 @cindex target descriptions, System z features
47310
47311 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
47312 System z targets. It should contain the PSW and the 16 general
47313 registers. In particular, System z targets should provide the 64-bit
47314 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
47315 S/390 targets should provide the 32-bit versions of these registers.
47316 A System z target that runs in 31-bit addressing mode should provide
47317 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
47318 register's upper halves @samp{r0h} through @samp{r15h}, and their
47319 lower halves @samp{r0l} through @samp{r15l}.
47320
47321 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
47322 contain the 64-bit registers @samp{f0} through @samp{f15}, and
47323 @samp{fpc}.
47324
47325 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
47326 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
47327
47328 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
47329 contain the register @samp{orig_r2}, which is 64-bit wide on System z
47330 targets and 32-bit otherwise. In addition, the feature may contain
47331 the @samp{last_break} register, whose width depends on the addressing
47332 mode, as well as the @samp{system_call} register, which is always
47333 32-bit wide.
47334
47335 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
47336 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
47337 @samp{atia}, and @samp{tr0} through @samp{tr15}.
47338
47339 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
47340 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
47341 combined by @value{GDBN} with the floating point registers @samp{f0}
47342 through @samp{f15} to present the 128-bit wide vector registers
47343 @samp{v0} through @samp{v15}. In addition, this feature should
47344 contain the 128-bit wide vector registers @samp{v16} through
47345 @samp{v31}.
47346
47347 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
47348 the 64-bit wide guarded-storage-control registers @samp{gsd},
47349 @samp{gssm}, and @samp{gsepla}.
47350
47351 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
47352 the 64-bit wide guarded-storage broadcast control registers
47353 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
47354
47355 @node Sparc Features
47356 @subsection Sparc Features
47357 @cindex target descriptions, sparc32 features
47358 @cindex target descriptions, sparc64 features
47359 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
47360 targets. It should describe the following registers:
47361
47362 @itemize @minus
47363 @item
47364 @samp{g0} through @samp{g7}
47365 @item
47366 @samp{o0} through @samp{o7}
47367 @item
47368 @samp{l0} through @samp{l7}
47369 @item
47370 @samp{i0} through @samp{i7}
47371 @end itemize
47372
47373 They may be 32-bit or 64-bit depending on the target.
47374
47375 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
47376 targets. It should describe the following registers:
47377
47378 @itemize @minus
47379 @item
47380 @samp{f0} through @samp{f31}
47381 @item
47382 @samp{f32} through @samp{f62} for sparc64
47383 @end itemize
47384
47385 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
47386 targets. It should describe the following registers:
47387
47388 @itemize @minus
47389 @item
47390 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
47391 @samp{fsr}, and @samp{csr} for sparc32
47392 @item
47393 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
47394 for sparc64
47395 @end itemize
47396
47397 @node TIC6x Features
47398 @subsection TMS320C6x Features
47399 @cindex target descriptions, TIC6x features
47400 @cindex target descriptions, TMS320C6x features
47401 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
47402 targets. It should contain registers @samp{A0} through @samp{A15},
47403 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
47404
47405 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
47406 contain registers @samp{A16} through @samp{A31} and @samp{B16}
47407 through @samp{B31}.
47408
47409 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
47410 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
47411
47412 @node Operating System Information
47413 @appendix Operating System Information
47414 @cindex operating system information
47415
47416 Users of @value{GDBN} often wish to obtain information about the state of
47417 the operating system running on the target---for example the list of
47418 processes, or the list of open files. This section describes the
47419 mechanism that makes it possible. This mechanism is similar to the
47420 target features mechanism (@pxref{Target Descriptions}), but focuses
47421 on a different aspect of target.
47422
47423 Operating system information is retrieved from the target via the
47424 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
47425 read}). The object name in the request should be @samp{osdata}, and
47426 the @var{annex} identifies the data to be fetched.
47427
47428 @menu
47429 * Process list::
47430 @end menu
47431
47432 @node Process list
47433 @appendixsection Process list
47434 @cindex operating system information, process list
47435
47436 When requesting the process list, the @var{annex} field in the
47437 @samp{qXfer} request should be @samp{processes}. The returned data is
47438 an XML document. The formal syntax of this document is defined in
47439 @file{gdb/features/osdata.dtd}.
47440
47441 An example document is:
47442
47443 @smallexample
47444 <?xml version="1.0"?>
47445 <!DOCTYPE target SYSTEM "osdata.dtd">
47446 <osdata type="processes">
47447 <item>
47448 <column name="pid">1</column>
47449 <column name="user">root</column>
47450 <column name="command">/sbin/init</column>
47451 <column name="cores">1,2,3</column>
47452 </item>
47453 </osdata>
47454 @end smallexample
47455
47456 Each item should include a column whose name is @samp{pid}. The value
47457 of that column should identify the process on the target. The
47458 @samp{user} and @samp{command} columns are optional, and will be
47459 displayed by @value{GDBN}. The @samp{cores} column, if present,
47460 should contain a comma-separated list of cores that this process
47461 is running on. Target may provide additional columns,
47462 which @value{GDBN} currently ignores.
47463
47464 @node Trace File Format
47465 @appendix Trace File Format
47466 @cindex trace file format
47467
47468 The trace file comes in three parts: a header, a textual description
47469 section, and a trace frame section with binary data.
47470
47471 The header has the form @code{\x7fTRACE0\n}. The first byte is
47472 @code{0x7f} so as to indicate that the file contains binary data,
47473 while the @code{0} is a version number that may have different values
47474 in the future.
47475
47476 The description section consists of multiple lines of @sc{ascii} text
47477 separated by newline characters (@code{0xa}). The lines may include a
47478 variety of optional descriptive or context-setting information, such
47479 as tracepoint definitions or register set size. @value{GDBN} will
47480 ignore any line that it does not recognize. An empty line marks the end
47481 of this section.
47482
47483 @table @code
47484 @item R @var{size}
47485 Specifies the size of a register block in bytes. This is equal to the
47486 size of a @code{g} packet payload in the remote protocol. @var{size}
47487 is an ascii decimal number. There should be only one such line in
47488 a single trace file.
47489
47490 @item status @var{status}
47491 Trace status. @var{status} has the same format as a @code{qTStatus}
47492 remote packet reply. There should be only one such line in a single trace
47493 file.
47494
47495 @item tp @var{payload}
47496 Tracepoint definition. The @var{payload} has the same format as
47497 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
47498 may take multiple lines of definition, corresponding to the multiple
47499 reply packets.
47500
47501 @item tsv @var{payload}
47502 Trace state variable definition. The @var{payload} has the same format as
47503 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
47504 may take multiple lines of definition, corresponding to the multiple
47505 reply packets.
47506
47507 @item tdesc @var{payload}
47508 Target description in XML format. The @var{payload} is a single line of
47509 the XML file. All such lines should be concatenated together to get
47510 the original XML file. This file is in the same format as @code{qXfer}
47511 @code{features} payload, and corresponds to the main @code{target.xml}
47512 file. Includes are not allowed.
47513
47514 @end table
47515
47516 The trace frame section consists of a number of consecutive frames.
47517 Each frame begins with a two-byte tracepoint number, followed by a
47518 four-byte size giving the amount of data in the frame. The data in
47519 the frame consists of a number of blocks, each introduced by a
47520 character indicating its type (at least register, memory, and trace
47521 state variable). The data in this section is raw binary, not a
47522 hexadecimal or other encoding; its endianness matches the target's
47523 endianness.
47524
47525 @c FIXME bi-arch may require endianness/arch info in description section
47526
47527 @table @code
47528 @item R @var{bytes}
47529 Register block. The number and ordering of bytes matches that of a
47530 @code{g} packet in the remote protocol. Note that these are the
47531 actual bytes, in target order, not a hexadecimal encoding.
47532
47533 @item M @var{address} @var{length} @var{bytes}...
47534 Memory block. This is a contiguous block of memory, at the 8-byte
47535 address @var{address}, with a 2-byte length @var{length}, followed by
47536 @var{length} bytes.
47537
47538 @item V @var{number} @var{value}
47539 Trace state variable block. This records the 8-byte signed value
47540 @var{value} of trace state variable numbered @var{number}.
47541
47542 @end table
47543
47544 Future enhancements of the trace file format may include additional types
47545 of blocks.
47546
47547 @node Index Section Format
47548 @appendix @code{.gdb_index} section format
47549 @cindex .gdb_index section format
47550 @cindex index section format
47551
47552 This section documents the index section that is created by @code{save
47553 gdb-index} (@pxref{Index Files}). The index section is
47554 DWARF-specific; some knowledge of DWARF is assumed in this
47555 description.
47556
47557 The mapped index file format is designed to be directly
47558 @code{mmap}able on any architecture. In most cases, a datum is
47559 represented using a little-endian 32-bit integer value, called an
47560 @code{offset_type}. Big endian machines must byte-swap the values
47561 before using them. Exceptions to this rule are noted. The data is
47562 laid out such that alignment is always respected.
47563
47564 A mapped index consists of several areas, laid out in order.
47565
47566 @enumerate
47567 @item
47568 The file header. This is a sequence of values, of @code{offset_type}
47569 unless otherwise noted:
47570
47571 @enumerate
47572 @item
47573 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
47574 Version 4 uses a different hashing function from versions 5 and 6.
47575 Version 6 includes symbols for inlined functions, whereas versions 4
47576 and 5 do not. Version 7 adds attributes to the CU indices in the
47577 symbol table. Version 8 specifies that symbols from DWARF type units
47578 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
47579 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
47580
47581 @value{GDBN} will only read version 4, 5, or 6 indices
47582 by specifying @code{set use-deprecated-index-sections on}.
47583 GDB has a workaround for potentially broken version 7 indices so it is
47584 currently not flagged as deprecated.
47585
47586 @item
47587 The offset, from the start of the file, of the CU list.
47588
47589 @item
47590 The offset, from the start of the file, of the types CU list. Note
47591 that this area can be empty, in which case this offset will be equal
47592 to the next offset.
47593
47594 @item
47595 The offset, from the start of the file, of the address area.
47596
47597 @item
47598 The offset, from the start of the file, of the symbol table.
47599
47600 @item
47601 The offset, from the start of the file, of the constant pool.
47602 @end enumerate
47603
47604 @item
47605 The CU list. This is a sequence of pairs of 64-bit little-endian
47606 values, sorted by the CU offset. The first element in each pair is
47607 the offset of a CU in the @code{.debug_info} section. The second
47608 element in each pair is the length of that CU. References to a CU
47609 elsewhere in the map are done using a CU index, which is just the
47610 0-based index into this table. Note that if there are type CUs, then
47611 conceptually CUs and type CUs form a single list for the purposes of
47612 CU indices.
47613
47614 @item
47615 The types CU list. This is a sequence of triplets of 64-bit
47616 little-endian values. In a triplet, the first value is the CU offset,
47617 the second value is the type offset in the CU, and the third value is
47618 the type signature. The types CU list is not sorted.
47619
47620 @item
47621 The address area. The address area consists of a sequence of address
47622 entries. Each address entry has three elements:
47623
47624 @enumerate
47625 @item
47626 The low address. This is a 64-bit little-endian value.
47627
47628 @item
47629 The high address. This is a 64-bit little-endian value. Like
47630 @code{DW_AT_high_pc}, the value is one byte beyond the end.
47631
47632 @item
47633 The CU index. This is an @code{offset_type} value.
47634 @end enumerate
47635
47636 @item
47637 The symbol table. This is an open-addressed hash table. The size of
47638 the hash table is always a power of 2.
47639
47640 Each slot in the hash table consists of a pair of @code{offset_type}
47641 values. The first value is the offset of the symbol's name in the
47642 constant pool. The second value is the offset of the CU vector in the
47643 constant pool.
47644
47645 If both values are 0, then this slot in the hash table is empty. This
47646 is ok because while 0 is a valid constant pool index, it cannot be a
47647 valid index for both a string and a CU vector.
47648
47649 The hash value for a table entry is computed by applying an
47650 iterative hash function to the symbol's name. Starting with an
47651 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
47652 the string is incorporated into the hash using the formula depending on the
47653 index version:
47654
47655 @table @asis
47656 @item Version 4
47657 The formula is @code{r = r * 67 + c - 113}.
47658
47659 @item Versions 5 to 7
47660 The formula is @code{r = r * 67 + tolower (c) - 113}.
47661 @end table
47662
47663 The terminating @samp{\0} is not incorporated into the hash.
47664
47665 The step size used in the hash table is computed via
47666 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
47667 value, and @samp{size} is the size of the hash table. The step size
47668 is used to find the next candidate slot when handling a hash
47669 collision.
47670
47671 The names of C@t{++} symbols in the hash table are canonicalized. We
47672 don't currently have a simple description of the canonicalization
47673 algorithm; if you intend to create new index sections, you must read
47674 the code.
47675
47676 @item
47677 The constant pool. This is simply a bunch of bytes. It is organized
47678 so that alignment is correct: CU vectors are stored first, followed by
47679 strings.
47680
47681 A CU vector in the constant pool is a sequence of @code{offset_type}
47682 values. The first value is the number of CU indices in the vector.
47683 Each subsequent value is the index and symbol attributes of a CU in
47684 the CU list. This element in the hash table is used to indicate which
47685 CUs define the symbol and how the symbol is used.
47686 See below for the format of each CU index+attributes entry.
47687
47688 A string in the constant pool is zero-terminated.
47689 @end enumerate
47690
47691 Attributes were added to CU index values in @code{.gdb_index} version 7.
47692 If a symbol has multiple uses within a CU then there is one
47693 CU index+attributes value for each use.
47694
47695 The format of each CU index+attributes entry is as follows
47696 (bit 0 = LSB):
47697
47698 @table @asis
47699
47700 @item Bits 0-23
47701 This is the index of the CU in the CU list.
47702 @item Bits 24-27
47703 These bits are reserved for future purposes and must be zero.
47704 @item Bits 28-30
47705 The kind of the symbol in the CU.
47706
47707 @table @asis
47708 @item 0
47709 This value is reserved and should not be used.
47710 By reserving zero the full @code{offset_type} value is backwards compatible
47711 with previous versions of the index.
47712 @item 1
47713 The symbol is a type.
47714 @item 2
47715 The symbol is a variable or an enum value.
47716 @item 3
47717 The symbol is a function.
47718 @item 4
47719 Any other kind of symbol.
47720 @item 5,6,7
47721 These values are reserved.
47722 @end table
47723
47724 @item Bit 31
47725 This bit is zero if the value is global and one if it is static.
47726
47727 The determination of whether a symbol is global or static is complicated.
47728 The authorative reference is the file @file{dwarf2read.c} in
47729 @value{GDBN} sources.
47730
47731 @end table
47732
47733 This pseudo-code describes the computation of a symbol's kind and
47734 global/static attributes in the index.
47735
47736 @smallexample
47737 is_external = get_attribute (die, DW_AT_external);
47738 language = get_attribute (cu_die, DW_AT_language);
47739 switch (die->tag)
47740 @{
47741 case DW_TAG_typedef:
47742 case DW_TAG_base_type:
47743 case DW_TAG_subrange_type:
47744 kind = TYPE;
47745 is_static = 1;
47746 break;
47747 case DW_TAG_enumerator:
47748 kind = VARIABLE;
47749 is_static = language != CPLUS;
47750 break;
47751 case DW_TAG_subprogram:
47752 kind = FUNCTION;
47753 is_static = ! (is_external || language == ADA);
47754 break;
47755 case DW_TAG_constant:
47756 kind = VARIABLE;
47757 is_static = ! is_external;
47758 break;
47759 case DW_TAG_variable:
47760 kind = VARIABLE;
47761 is_static = ! is_external;
47762 break;
47763 case DW_TAG_namespace:
47764 kind = TYPE;
47765 is_static = 0;
47766 break;
47767 case DW_TAG_class_type:
47768 case DW_TAG_interface_type:
47769 case DW_TAG_structure_type:
47770 case DW_TAG_union_type:
47771 case DW_TAG_enumeration_type:
47772 kind = TYPE;
47773 is_static = language != CPLUS;
47774 break;
47775 default:
47776 assert (0);
47777 @}
47778 @end smallexample
47779
47780 @node Debuginfod
47781 @appendix Download debugging resources with Debuginfod
47782 @cindex debuginfod
47783
47784 @code{debuginfod} is an HTTP server for distributing ELF, DWARF and source
47785 files.
47786
47787 With the @code{debuginfod} client library, @file{libdebuginfod}, @value{GDBN}
47788 can query servers using the build IDs associated with missing debug info,
47789 executables and source files in order to download them on demand.
47790
47791 For instructions on building @value{GDBN} with @file{libdebuginfod},
47792 @pxref{Configure Options,,--with-debuginfod}. @code{debuginfod} is packaged
47793 with @code{elfutils}, starting with version 0.178. See
47794 @uref{https://sourceware.org/elfutils/Debuginfod.html} for more information
47795 regarding @code{debuginfod}.
47796
47797 @menu
47798 * Debuginfod Settings:: Configuring debuginfod with @value{GDBN}
47799 @end menu
47800
47801 @node Debuginfod Settings
47802 @section Debuginfod Settings
47803
47804 @value{GDBN} provides the following commands for configuring @code{debuginfod}.
47805
47806 @table @code
47807 @kindex set debuginfod enabled
47808 @anchor{set debuginfod enabled}
47809 @item set debuginfod enabled
47810 @itemx set debuginfod enabled on
47811 @cindex enable debuginfod
47812 @value{GDBN} will attempt to query @code{debuginfod} servers when missing debug
47813 info or source files.
47814
47815 @item set debuginfod enabled off
47816 @value{GDBN} will not attempt to query @code{debuginfod} servers when missing
47817 debug info or source files. By default, @code{debuginfod enabled} is set to
47818 @code{off} for non-interactive sessions.
47819
47820 @item set debuginfod enabled ask
47821 @value{GDBN} will prompt the user to enable or disable @code{debuginfod} before
47822 attempting to perform the next query. By default, @code{debuginfod enabled}
47823 is set to @code{ask} for interactive sessions.
47824
47825 @kindex show debuginfod enabled
47826 @item show debuginfod enabled
47827 Display whether @code{debuginfod enabled} is set to @code{on}, @code{off} or
47828 @code{ask}.
47829
47830 @kindex set debuginfod urls
47831 @cindex configure debuginfod URLs
47832 @item set debuginfod urls
47833 @itemx set debuginfod urls @var{urls}
47834 Set the space-separated list of URLs that @code{debuginfod} will attempt to
47835 query. Only @code{http://}, @code{https://} and @code{file://} protocols
47836 should be used. The default value of @code{debuginfod urls} is copied from
47837 the @var{DEBUGINFOD_URLS} environment variable.
47838
47839 @kindex show debuginfod urls
47840 @item show debuginfod urls
47841 Display the list of URLs that @code{debuginfod} will attempt to query.
47842
47843 @kindex set debuginfod verbose
47844 @cindex debuginfod verbosity
47845 @item set debuginfod verbose
47846 @itemx set debuginfod verbose @var{n}
47847 Enable or disable @code{debuginfod}-related output. Use a non-zero value
47848 to enable and @code{0} to disable. @code{debuginfod} output is shown by
47849 default.
47850
47851 @kindex show debuginfod verbose
47852 @item show debuginfod verbose
47853 Show the current verbosity setting.
47854
47855 @end table
47856
47857 @node Man Pages
47858 @appendix Manual pages
47859 @cindex Man pages
47860
47861 @menu
47862 * gdb man:: The GNU Debugger man page
47863 * gdbserver man:: Remote Server for the GNU Debugger man page
47864 * gcore man:: Generate a core file of a running program
47865 * gdbinit man:: gdbinit scripts
47866 * gdb-add-index man:: Add index files to speed up GDB
47867 @end menu
47868
47869 @node gdb man
47870 @heading gdb man
47871
47872 @c man title gdb The GNU Debugger
47873
47874 @c man begin SYNOPSIS gdb
47875 gdb [OPTIONS] [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
47876 @c man end
47877
47878 @c man begin DESCRIPTION gdb
47879 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
47880 going on ``inside'' another program while it executes -- or what another
47881 program was doing at the moment it crashed.
47882
47883 @value{GDBN} can do four main kinds of things (plus other things in support of
47884 these) to help you catch bugs in the act:
47885
47886 @itemize @bullet
47887 @item
47888 Start your program, specifying anything that might affect its behavior.
47889
47890 @item
47891 Make your program stop on specified conditions.
47892
47893 @item
47894 Examine what has happened, when your program has stopped.
47895
47896 @item
47897 Change things in your program, so you can experiment with correcting the
47898 effects of one bug and go on to learn about another.
47899 @end itemize
47900
47901 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
47902 Modula-2.
47903
47904 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
47905 commands from the terminal until you tell it to exit with the @value{GDBN}
47906 command @code{quit} or @code{exit}. You can get online help from @value{GDBN} itself
47907 by using the command @code{help}.
47908
47909 You can run @code{gdb} with no arguments or options; but the most
47910 usual way to start @value{GDBN} is with one argument or two, specifying an
47911 executable program as the argument:
47912
47913 @smallexample
47914 gdb program
47915 @end smallexample
47916
47917 You can also start with both an executable program and a core file specified:
47918
47919 @smallexample
47920 gdb program core
47921 @end smallexample
47922
47923 You can, instead, specify a process ID as a second argument or use option
47924 @code{-p}, if you want to debug a running process:
47925
47926 @smallexample
47927 gdb program 1234
47928 gdb -p 1234
47929 @end smallexample
47930
47931 @noindent
47932 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
47933 can omit the @var{program} filename.
47934
47935 Here are some of the most frequently needed @value{GDBN} commands:
47936
47937 @c pod2man highlights the right hand side of the @item lines.
47938 @table @env
47939 @item break [@var{file}:][@var{function}|@var{line}]
47940 Set a breakpoint at @var{function} or @var{line} (in @var{file}).
47941
47942 @item run [@var{arglist}]
47943 Start your program (with @var{arglist}, if specified).
47944
47945 @item bt
47946 Backtrace: display the program stack.
47947
47948 @item print @var{expr}
47949 Display the value of an expression.
47950
47951 @item c
47952 Continue running your program (after stopping, e.g.@: at a breakpoint).
47953
47954 @item next
47955 Execute next program line (after stopping); step @emph{over} any
47956 function calls in the line.
47957
47958 @item edit [@var{file}:]@var{function}
47959 look at the program line where it is presently stopped.
47960
47961 @item list [@var{file}:]@var{function}
47962 type the text of the program in the vicinity of where it is presently stopped.
47963
47964 @item step
47965 Execute next program line (after stopping); step @emph{into} any
47966 function calls in the line.
47967
47968 @item help [@var{name}]
47969 Show information about @value{GDBN} command @var{name}, or general information
47970 about using @value{GDBN}.
47971
47972 @item quit
47973 @itemx exit
47974 Exit from @value{GDBN}.
47975 @end table
47976
47977 @ifset man
47978 For full details on @value{GDBN},
47979 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47980 by Richard M. Stallman and Roland H. Pesch. The same text is available online
47981 as the @code{gdb} entry in the @code{info} program.
47982 @end ifset
47983 @c man end
47984
47985 @c man begin OPTIONS gdb
47986 Any arguments other than options specify an executable
47987 file and core file (or process ID); that is, the first argument
47988 encountered with no
47989 associated option flag is equivalent to a @option{--se} option, and the second,
47990 if any, is equivalent to a @option{-c} option if it's the name of a file.
47991 Many options have
47992 both long and abbreviated forms; both are shown here. The long forms are also
47993 recognized if you truncate them, so long as enough of the option is
47994 present to be unambiguous.
47995
47996 The abbreviated forms are shown here with @samp{-} and long forms are shown
47997 with @samp{--} to reflect how they are shown in @option{--help}. However,
47998 @value{GDBN} recognizes all of the following conventions for most options:
47999
48000 @table @code
48001 @item --option=@var{value}
48002 @item --option @var{value}
48003 @item -option=@var{value}
48004 @item -option @var{value}
48005 @item --o=@var{value}
48006 @item --o @var{value}
48007 @item -o=@var{value}
48008 @item -o @var{value}
48009 @end table
48010
48011 All the options and command line arguments you give are processed
48012 in sequential order. The order makes a difference when the @option{-x}
48013 option is used.
48014
48015 @table @env
48016 @item --help
48017 @itemx -h
48018 List all options, with brief explanations.
48019
48020 @item --symbols=@var{file}
48021 @itemx -s @var{file}
48022 Read symbol table from @var{file}.
48023
48024 @item --write
48025 Enable writing into executable and core files.
48026
48027 @item --exec=@var{file}
48028 @itemx -e @var{file}
48029 Use @var{file} as the executable file to execute when
48030 appropriate, and for examining pure data in conjunction with a core
48031 dump.
48032
48033 @item --se=@var{file}
48034 Read symbol table from @var{file} and use it as the executable
48035 file.
48036
48037 @item --core=@var{file}
48038 @itemx -c @var{file}
48039 Use @var{file} as a core dump to examine.
48040
48041 @item --command=@var{file}
48042 @itemx -x @var{file}
48043 Execute @value{GDBN} commands from @var{file}.
48044
48045 @item --eval-command=@var{command}
48046 @item -ex @var{command}
48047 Execute given @value{GDBN} @var{command}.
48048
48049 @item --init-eval-command=@var{command}
48050 @item -iex
48051 Execute @value{GDBN} @var{command} before loading the inferior.
48052
48053 @item --directory=@var{directory}
48054 @itemx -d @var{directory}
48055 Add @var{directory} to the path to search for source files.
48056
48057 @item --nh
48058 Do not execute commands from @file{~/.config/gdb/gdbinit},
48059 @file{~/.gdbinit}, @file{~/.config/gdb/gdbearlyinit}, or
48060 @file{~/.gdbearlyinit}
48061
48062 @item --nx
48063 @itemx -n
48064 Do not execute commands from any @file{.gdbinit} or
48065 @file{.gdbearlyinit} initialization files.
48066
48067 @item --quiet
48068 @item --silent
48069 @itemx -q
48070 ``Quiet''. Do not print the introductory and copyright messages. These
48071 messages are also suppressed in batch mode.
48072
48073 @item --batch
48074 Run in batch mode. Exit with status @code{0} after processing all the command
48075 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
48076 Exit with nonzero status if an error occurs in executing the @value{GDBN}
48077 commands in the command files.
48078
48079 Batch mode may be useful for running @value{GDBN} as a filter, for example to
48080 download and run a program on another computer; in order to make this
48081 more useful, the message
48082
48083 @smallexample
48084 Program exited normally.
48085 @end smallexample
48086
48087 @noindent
48088 (which is ordinarily issued whenever a program running under @value{GDBN} control
48089 terminates) is not issued when running in batch mode.
48090
48091 @item --batch-silent
48092 Run in batch mode, just like @option{--batch}, but totally silent. All @value{GDBN}
48093 output is supressed (stderr is unaffected). This is much quieter than
48094 @option{--silent} and would be useless for an interactive session.
48095
48096 This is particularly useful when using targets that give @samp{Loading section}
48097 messages, for example.
48098
48099 Note that targets that give their output via @value{GDBN}, as opposed to writing
48100 directly to @code{stdout}, will also be made silent.
48101
48102 @item --args @var{prog} [@var{arglist}]
48103 Change interpretation of command line so that arguments following this
48104 option are passed as arguments to the inferior. As an example, take
48105 the following command:
48106
48107 @smallexample
48108 gdb ./a.out -q
48109 @end smallexample
48110
48111 @noindent
48112 It would start @value{GDBN} with @option{-q}, not printing the introductory message. On
48113 the other hand, using:
48114
48115 @smallexample
48116 gdb --args ./a.out -q
48117 @end smallexample
48118
48119 @noindent
48120 starts @value{GDBN} with the introductory message, and passes the option to the inferior.
48121
48122 @item --pid=@var{pid}
48123 Attach @value{GDBN} to an already running program, with the PID @var{pid}.
48124
48125 @item --tui
48126 Open the terminal user interface.
48127
48128 @item --readnow
48129 Read all symbols from the given symfile on the first access.
48130
48131 @item --readnever
48132 Do not read symbol files.
48133
48134 @item --return-child-result
48135 @value{GDBN}'s exit code will be the same as the child's exit code.
48136
48137 @item --configuration
48138 Print details about GDB configuration and then exit.
48139
48140 @item --version
48141 Print version information and then exit.
48142
48143 @item --cd=@var{directory}
48144 Run @value{GDBN} using @var{directory} as its working directory,
48145 instead of the current directory.
48146
48147 @item --data-directory=@var{directory}
48148 @item -D
48149 Run @value{GDBN} using @var{directory} as its data directory. The data
48150 directory is where @value{GDBN} searches for its auxiliary files.
48151
48152 @item --fullname
48153 @itemx -f
48154 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
48155 @value{GDBN} to output the full file name and line number in a standard,
48156 recognizable fashion each time a stack frame is displayed (which
48157 includes each time the program stops). This recognizable format looks
48158 like two @samp{\032} characters, followed by the file name, line number
48159 and character position separated by colons, and a newline. The
48160 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
48161 characters as a signal to display the source code for the frame.
48162
48163 @item -b @var{baudrate}
48164 Set the line speed (baud rate or bits per second) of any serial
48165 interface used by @value{GDBN} for remote debugging.
48166
48167 @item -l @var{timeout}
48168 Set timeout, in seconds, for remote debugging.
48169
48170 @item --tty=@var{device}
48171 Run using @var{device} for your program's standard input and output.
48172 @end table
48173 @c man end
48174
48175 @c man begin SEEALSO gdb
48176 @ifset man
48177 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48178 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48179 documentation are properly installed at your site, the command
48180
48181 @smallexample
48182 info gdb
48183 @end smallexample
48184
48185 @noindent
48186 should give you access to the complete manual.
48187
48188 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48189 Richard M. Stallman and Roland H. Pesch, July 1991.
48190 @end ifset
48191 @c man end
48192
48193 @node gdbserver man
48194 @heading gdbserver man
48195
48196 @c man title gdbserver Remote Server for the GNU Debugger
48197 @format
48198 @c man begin SYNOPSIS gdbserver
48199 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
48200
48201 gdbserver --attach @var{comm} @var{pid}
48202
48203 gdbserver --multi @var{comm}
48204 @c man end
48205 @end format
48206
48207 @c man begin DESCRIPTION gdbserver
48208 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
48209 than the one which is running the program being debugged.
48210
48211 @ifclear man
48212 @subheading Usage (server (target) side)
48213 @end ifclear
48214 @ifset man
48215 Usage (server (target) side):
48216 @end ifset
48217
48218 First, you need to have a copy of the program you want to debug put onto
48219 the target system. The program can be stripped to save space if needed, as
48220 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
48221 the @value{GDBN} running on the host system.
48222
48223 To use the server, you log on to the target system, and run the @command{gdbserver}
48224 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
48225 your program, and (c) its arguments. The general syntax is:
48226
48227 @smallexample
48228 target> gdbserver @var{comm} @var{program} [@var{args} ...]
48229 @end smallexample
48230
48231 For example, using a serial port, you might say:
48232
48233 @smallexample
48234 @ifset man
48235 @c @file would wrap it as F</dev/com1>.
48236 target> gdbserver /dev/com1 emacs foo.txt
48237 @end ifset
48238 @ifclear man
48239 target> gdbserver @file{/dev/com1} emacs foo.txt
48240 @end ifclear
48241 @end smallexample
48242
48243 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
48244 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
48245 waits patiently for the host @value{GDBN} to communicate with it.
48246
48247 To use a TCP connection, you could say:
48248
48249 @smallexample
48250 target> gdbserver host:2345 emacs foo.txt
48251 @end smallexample
48252
48253 This says pretty much the same thing as the last example, except that we are
48254 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
48255 that we are expecting to see a TCP connection from @code{host} to local TCP port
48256 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
48257 want for the port number as long as it does not conflict with any existing TCP
48258 ports on the target system. This same port number must be used in the host
48259 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
48260 you chose a port number that conflicts with another service, @command{gdbserver} will
48261 print an error message and exit.
48262
48263 @command{gdbserver} can also attach to running programs.
48264 This is accomplished via the @option{--attach} argument. The syntax is:
48265
48266 @smallexample
48267 target> gdbserver --attach @var{comm} @var{pid}
48268 @end smallexample
48269
48270 @var{pid} is the process ID of a currently running process. It isn't
48271 necessary to point @command{gdbserver} at a binary for the running process.
48272
48273 To start @code{gdbserver} without supplying an initial command to run
48274 or process ID to attach, use the @option{--multi} command line option.
48275 In such case you should connect using @kbd{target extended-remote} to start
48276 the program you want to debug.
48277
48278 @smallexample
48279 target> gdbserver --multi @var{comm}
48280 @end smallexample
48281
48282 @ifclear man
48283 @subheading Usage (host side)
48284 @end ifclear
48285 @ifset man
48286 Usage (host side):
48287 @end ifset
48288
48289 You need an unstripped copy of the target program on your host system, since
48290 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
48291 would, with the target program as the first argument. (You may need to use the
48292 @option{--baud} option if the serial line is running at anything except 9600 baud.)
48293 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
48294 new command you need to know about is @code{target remote}
48295 (or @code{target extended-remote}). Its argument is either
48296 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
48297 descriptor. For example:
48298
48299 @smallexample
48300 @ifset man
48301 @c @file would wrap it as F</dev/ttyb>.
48302 (gdb) target remote /dev/ttyb
48303 @end ifset
48304 @ifclear man
48305 (gdb) target remote @file{/dev/ttyb}
48306 @end ifclear
48307 @end smallexample
48308
48309 @noindent
48310 communicates with the server via serial line @file{/dev/ttyb}, and:
48311
48312 @smallexample
48313 (gdb) target remote the-target:2345
48314 @end smallexample
48315
48316 @noindent
48317 communicates via a TCP connection to port 2345 on host `the-target', where
48318 you previously started up @command{gdbserver} with the same port number. Note that for
48319 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
48320 command, otherwise you may get an error that looks something like
48321 `Connection refused'.
48322
48323 @command{gdbserver} can also debug multiple inferiors at once,
48324 described in
48325 @ifset man
48326 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
48327 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
48328 @end ifset
48329 @ifclear man
48330 @ref{Inferiors Connections and Programs}.
48331 @end ifclear
48332 In such case use the @code{extended-remote} @value{GDBN} command variant:
48333
48334 @smallexample
48335 (gdb) target extended-remote the-target:2345
48336 @end smallexample
48337
48338 The @command{gdbserver} option @option{--multi} may or may not be used in such
48339 case.
48340 @c man end
48341
48342 @c man begin OPTIONS gdbserver
48343 There are three different modes for invoking @command{gdbserver}:
48344
48345 @itemize @bullet
48346
48347 @item
48348 Debug a specific program specified by its program name:
48349
48350 @smallexample
48351 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
48352 @end smallexample
48353
48354 The @var{comm} parameter specifies how should the server communicate
48355 with @value{GDBN}; it is either a device name (to use a serial line),
48356 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
48357 stdin/stdout of @code{gdbserver}. Specify the name of the program to
48358 debug in @var{prog}. Any remaining arguments will be passed to the
48359 program verbatim. When the program exits, @value{GDBN} will close the
48360 connection, and @code{gdbserver} will exit.
48361
48362 @item
48363 Debug a specific program by specifying the process ID of a running
48364 program:
48365
48366 @smallexample
48367 gdbserver --attach @var{comm} @var{pid}
48368 @end smallexample
48369
48370 The @var{comm} parameter is as described above. Supply the process ID
48371 of a running program in @var{pid}; @value{GDBN} will do everything
48372 else. Like with the previous mode, when the process @var{pid} exits,
48373 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
48374
48375 @item
48376 Multi-process mode -- debug more than one program/process:
48377
48378 @smallexample
48379 gdbserver --multi @var{comm}
48380 @end smallexample
48381
48382 In this mode, @value{GDBN} can instruct @command{gdbserver} which
48383 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
48384 close the connection when a process being debugged exits, so you can
48385 debug several processes in the same session.
48386 @end itemize
48387
48388 In each of the modes you may specify these options:
48389
48390 @table @env
48391
48392 @item --help
48393 List all options, with brief explanations.
48394
48395 @item --version
48396 This option causes @command{gdbserver} to print its version number and exit.
48397
48398 @item --attach
48399 @command{gdbserver} will attach to a running program. The syntax is:
48400
48401 @smallexample
48402 target> gdbserver --attach @var{comm} @var{pid}
48403 @end smallexample
48404
48405 @var{pid} is the process ID of a currently running process. It isn't
48406 necessary to point @command{gdbserver} at a binary for the running process.
48407
48408 @item --multi
48409 To start @code{gdbserver} without supplying an initial command to run
48410 or process ID to attach, use this command line option.
48411 Then you can connect using @kbd{target extended-remote} and start
48412 the program you want to debug. The syntax is:
48413
48414 @smallexample
48415 target> gdbserver --multi @var{comm}
48416 @end smallexample
48417
48418 @item --debug
48419 Instruct @code{gdbserver} to display extra status information about the debugging
48420 process.
48421 This option is intended for @code{gdbserver} development and for bug reports to
48422 the developers.
48423
48424 @item --remote-debug
48425 Instruct @code{gdbserver} to display remote protocol debug output.
48426 This option is intended for @code{gdbserver} development and for bug reports to
48427 the developers.
48428
48429 @item --debug-file=@var{filename}
48430 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
48431 This option is intended for @code{gdbserver} development and for bug reports to
48432 the developers.
48433
48434 @item --debug-format=option1@r{[},option2,...@r{]}
48435 Instruct @code{gdbserver} to include extra information in each line
48436 of debugging output.
48437 @xref{Other Command-Line Arguments for gdbserver}.
48438
48439 @item --wrapper
48440 Specify a wrapper to launch programs
48441 for debugging. The option should be followed by the name of the
48442 wrapper, then any command-line arguments to pass to the wrapper, then
48443 @kbd{--} indicating the end of the wrapper arguments.
48444
48445 @item --once
48446 By default, @command{gdbserver} keeps the listening TCP port open, so that
48447 additional connections are possible. However, if you start @code{gdbserver}
48448 with the @option{--once} option, it will stop listening for any further
48449 connection attempts after connecting to the first @value{GDBN} session.
48450
48451 @c --disable-packet is not documented for users.
48452
48453 @c --disable-randomization and --no-disable-randomization are superseded by
48454 @c QDisableRandomization.
48455
48456 @end table
48457 @c man end
48458
48459 @c man begin SEEALSO gdbserver
48460 @ifset man
48461 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48462 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48463 documentation are properly installed at your site, the command
48464
48465 @smallexample
48466 info gdb
48467 @end smallexample
48468
48469 should give you access to the complete manual.
48470
48471 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48472 Richard M. Stallman and Roland H. Pesch, July 1991.
48473 @end ifset
48474 @c man end
48475
48476 @node gcore man
48477 @heading gcore
48478
48479 @c man title gcore Generate a core file of a running program
48480
48481 @format
48482 @c man begin SYNOPSIS gcore
48483 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
48484 @c man end
48485 @end format
48486
48487 @c man begin DESCRIPTION gcore
48488 Generate core dumps of one or more running programs with process IDs
48489 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
48490 is equivalent to one produced by the kernel when the process crashes
48491 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
48492 limit). However, unlike after a crash, after @command{gcore} finishes
48493 its job the program remains running without any change.
48494 @c man end
48495
48496 @c man begin OPTIONS gcore
48497 @table @env
48498 @item -a
48499 Dump all memory mappings. The actual effect of this option depends on
48500 the Operating System. On @sc{gnu}/Linux, it will disable
48501 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
48502 enable @code{dump-excluded-mappings} (@pxref{set
48503 dump-excluded-mappings}).
48504
48505 @item -o @var{prefix}
48506 The optional argument @var{prefix} specifies the prefix to be used
48507 when composing the file names of the core dumps. The file name is
48508 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
48509 process ID of the running program being analyzed by @command{gcore}.
48510 If not specified, @var{prefix} defaults to @var{gcore}.
48511 @end table
48512 @c man end
48513
48514 @c man begin SEEALSO gcore
48515 @ifset man
48516 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48517 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48518 documentation are properly installed at your site, the command
48519
48520 @smallexample
48521 info gdb
48522 @end smallexample
48523
48524 @noindent
48525 should give you access to the complete manual.
48526
48527 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48528 Richard M. Stallman and Roland H. Pesch, July 1991.
48529 @end ifset
48530 @c man end
48531
48532 @node gdbinit man
48533 @heading gdbinit
48534
48535 @c man title gdbinit GDB initialization scripts
48536
48537 @format
48538 @c man begin SYNOPSIS gdbinit
48539 @ifset SYSTEM_GDBINIT
48540 @value{SYSTEM_GDBINIT}
48541 @end ifset
48542
48543 @ifset SYSTEM_GDBINIT_DIR
48544 @value{SYSTEM_GDBINIT_DIR}/*
48545 @end ifset
48546
48547 ~/.config/gdb/gdbinit
48548
48549 ~/.gdbinit
48550
48551 ./.gdbinit
48552 @c man end
48553 @end format
48554
48555 @c man begin DESCRIPTION gdbinit
48556 These files contain @value{GDBN} commands to automatically execute during
48557 @value{GDBN} startup. The lines of contents are canned sequences of commands,
48558 described in
48559 @ifset man
48560 the @value{GDBN} manual in node @code{Sequences}
48561 -- shell command @code{info -f gdb -n Sequences}.
48562 @end ifset
48563 @ifclear man
48564 @ref{Sequences}.
48565 @end ifclear
48566
48567 Please read more in
48568 @ifset man
48569 the @value{GDBN} manual in node @code{Startup}
48570 -- shell command @code{info -f gdb -n Startup}.
48571 @end ifset
48572 @ifclear man
48573 @ref{Startup}.
48574 @end ifclear
48575
48576 @table @env
48577 @ifset SYSTEM_GDBINIT
48578 @item @value{SYSTEM_GDBINIT}
48579 @end ifset
48580 @ifclear SYSTEM_GDBINIT
48581 @item (not enabled with @code{--with-system-gdbinit} during compilation)
48582 @end ifclear
48583 System-wide initialization file. It is executed unless user specified
48584 @value{GDBN} option @code{-nx} or @code{-n}.
48585 See more in
48586 @ifset man
48587 the @value{GDBN} manual in node @code{System-wide configuration}
48588 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
48589 @end ifset
48590 @ifset SYSTEM_GDBINIT_DIR
48591 @item @value{SYSTEM_GDBINIT_DIR}
48592 @end ifset
48593 @ifclear SYSTEM_GDBINIT_DIR
48594 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
48595 @end ifclear
48596 System-wide initialization directory. All files in this directory are
48597 executed on startup unless user specified @value{GDBN} option @code{-nx} or
48598 @code{-n}, as long as they have a recognized file extension.
48599 See more in
48600 @ifset man
48601 the @value{GDBN} manual in node @code{System-wide configuration}
48602 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
48603 @end ifset
48604 @ifclear man
48605 @ref{System-wide configuration}.
48606 @end ifclear
48607
48608 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
48609 User initialization file. It is executed unless user specified
48610 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
48611
48612 @item @file{.gdbinit}
48613 Initialization file for current directory. It may need to be enabled with
48614 @value{GDBN} security command @code{set auto-load local-gdbinit}.
48615 See more in
48616 @ifset man
48617 the @value{GDBN} manual in node @code{Init File in the Current Directory}
48618 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
48619 @end ifset
48620 @ifclear man
48621 @ref{Init File in the Current Directory}.
48622 @end ifclear
48623 @end table
48624 @c man end
48625
48626 @c man begin SEEALSO gdbinit
48627 @ifset man
48628 gdb(1), @code{info -f gdb -n Startup}
48629
48630 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48631 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48632 documentation are properly installed at your site, the command
48633
48634 @smallexample
48635 info gdb
48636 @end smallexample
48637
48638 should give you access to the complete manual.
48639
48640 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48641 Richard M. Stallman and Roland H. Pesch, July 1991.
48642 @end ifset
48643 @c man end
48644
48645 @node gdb-add-index man
48646 @heading gdb-add-index
48647 @pindex gdb-add-index
48648 @anchor{gdb-add-index}
48649
48650 @c man title gdb-add-index Add index files to speed up GDB
48651
48652 @c man begin SYNOPSIS gdb-add-index
48653 gdb-add-index @var{filename}
48654 @c man end
48655
48656 @c man begin DESCRIPTION gdb-add-index
48657 When @value{GDBN} finds a symbol file, it scans the symbols in the
48658 file in order to construct an internal symbol table. This lets most
48659 @value{GDBN} operations work quickly--at the cost of a delay early on.
48660 For large programs, this delay can be quite lengthy, so @value{GDBN}
48661 provides a way to build an index, which speeds up startup.
48662
48663 To determine whether a file contains such an index, use the command
48664 @kbd{readelf -S filename}: the index is stored in a section named
48665 @code{.gdb_index}. The index file can only be produced on systems
48666 which use ELF binaries and DWARF debug information (i.e., sections
48667 named @code{.debug_*}).
48668
48669 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
48670 in the @env{PATH} environment variable. If you want to use different
48671 versions of these programs, you can specify them through the
48672 @env{GDB} and @env{OBJDUMP} environment variables.
48673
48674 See more in
48675 @ifset man
48676 the @value{GDBN} manual in node @code{Index Files}
48677 -- shell command @kbd{info -f gdb -n "Index Files"}.
48678 @end ifset
48679 @ifclear man
48680 @ref{Index Files}.
48681 @end ifclear
48682 @c man end
48683
48684 @c man begin SEEALSO gdb-add-index
48685 @ifset man
48686 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48687 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48688 documentation are properly installed at your site, the command
48689
48690 @smallexample
48691 info gdb
48692 @end smallexample
48693
48694 should give you access to the complete manual.
48695
48696 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48697 Richard M. Stallman and Roland H. Pesch, July 1991.
48698 @end ifset
48699 @c man end
48700
48701 @include gpl.texi
48702
48703 @node GNU Free Documentation License
48704 @appendix GNU Free Documentation License
48705 @include fdl.texi
48706
48707 @node Concept Index
48708 @unnumbered Concept Index
48709
48710 @printindex cp
48711
48712 @node Command and Variable Index
48713 @unnumbered Command, Variable, and Function Index
48714
48715 @printindex fn
48716
48717 @tex
48718 % I think something like @@colophon should be in texinfo. In the
48719 % meantime:
48720 \long\def\colophon{\hbox to0pt{}\vfill
48721 \centerline{The body of this manual is set in}
48722 \centerline{\fontname\tenrm,}
48723 \centerline{with headings in {\bf\fontname\tenbf}}
48724 \centerline{and examples in {\tt\fontname\tentt}.}
48725 \centerline{{\it\fontname\tenit\/},}
48726 \centerline{{\bf\fontname\tenbf}, and}
48727 \centerline{{\sl\fontname\tensl\/}}
48728 \centerline{are used for emphasis.}\vfill}
48729 \page\colophon
48730 % Blame: doc@@cygnus.com, 1991.
48731 @end tex
48732
48733 @bye