8f3301259afed6aae968d9247cb2f7605e3308fd
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2020 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-2020 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, (dir), (dir)
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-2020 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 * Man Pages:: Manual pages
188 * Copying:: GNU General Public License says
189 how you can copy and share GDB
190 * GNU Free Documentation License:: The license for this documentation
191 * Concept Index:: Index of @value{GDBN} concepts
192 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
194 @end menu
195
196 @end ifnottex
197
198 @contents
199
200 @node Summary
201 @unnumbered Summary of @value{GDBN}
202
203 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204 going on ``inside'' another program while it executes---or what another
205 program was doing at the moment it crashed.
206
207 @value{GDBN} can do four main kinds of things (plus other things in support of
208 these) to help you catch bugs in the act:
209
210 @itemize @bullet
211 @item
212 Start your program, specifying anything that might affect its behavior.
213
214 @item
215 Make your program stop on specified conditions.
216
217 @item
218 Examine what has happened, when your program has stopped.
219
220 @item
221 Change things in your program, so you can experiment with correcting the
222 effects of one bug and go on to learn about another.
223 @end itemize
224
225 You can use @value{GDBN} to debug programs written in C and C@t{++}.
226 For more information, see @ref{Supported Languages,,Supported Languages}.
227 For more information, see @ref{C,,C and C++}.
228
229 Support for D is partial. For information on D, see
230 @ref{D,,D}.
231
232 @cindex Modula-2
233 Support for Modula-2 is partial. For information on Modula-2, see
234 @ref{Modula-2,,Modula-2}.
235
236 Support for OpenCL C is partial. For information on OpenCL C, see
237 @ref{OpenCL C,,OpenCL C}.
238
239 @cindex Pascal
240 Debugging Pascal programs which use sets, subranges, file variables, or
241 nested functions does not currently work. @value{GDBN} does not support
242 entering expressions, printing values, or similar features using Pascal
243 syntax.
244
245 @cindex Fortran
246 @value{GDBN} can be used to debug programs written in Fortran, although
247 it may be necessary to refer to some variables with a trailing
248 underscore.
249
250 @value{GDBN} can be used to debug programs written in Objective-C,
251 using either the Apple/NeXT or the GNU Objective-C runtime.
252
253 @menu
254 * Free Software:: Freely redistributable software
255 * Free Documentation:: Free Software Needs Free Documentation
256 * Contributors:: Contributors to GDB
257 @end menu
258
259 @node Free Software
260 @unnumberedsec Free Software
261
262 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
263 General Public License
264 (GPL). The GPL gives you the freedom to copy or adapt a licensed
265 program---but every person getting a copy also gets with it the
266 freedom to modify that copy (which means that they must get access to
267 the source code), and the freedom to distribute further copies.
268 Typical software companies use copyrights to limit your freedoms; the
269 Free Software Foundation uses the GPL to preserve these freedoms.
270
271 Fundamentally, the General Public License is a license which says that
272 you have these freedoms and that you cannot take these freedoms away
273 from anyone else.
274
275 @node Free Documentation
276 @unnumberedsec Free Software Needs Free Documentation
277
278 The biggest deficiency in the free software community today is not in
279 the software---it is the lack of good free documentation that we can
280 include with the free software. Many of our most important
281 programs do not come with free reference manuals and free introductory
282 texts. Documentation is an essential part of any software package;
283 when an important free software package does not come with a free
284 manual and a free tutorial, that is a major gap. We have many such
285 gaps today.
286
287 Consider Perl, for instance. The tutorial manuals that people
288 normally use are non-free. How did this come about? Because the
289 authors of those manuals published them with restrictive terms---no
290 copying, no modification, source files not available---which exclude
291 them from the free software world.
292
293 That wasn't the first time this sort of thing happened, and it was far
294 from the last. Many times we have heard a GNU user eagerly describe a
295 manual that he is writing, his intended contribution to the community,
296 only to learn that he had ruined everything by signing a publication
297 contract to make it non-free.
298
299 Free documentation, like free software, is a matter of freedom, not
300 price. The problem with the non-free manual is not that publishers
301 charge a price for printed copies---that in itself is fine. (The Free
302 Software Foundation sells printed copies of manuals, too.) The
303 problem is the restrictions on the use of the manual. Free manuals
304 are available in source code form, and give you permission to copy and
305 modify. Non-free manuals do not allow this.
306
307 The criteria of freedom for a free manual are roughly the same as for
308 free software. Redistribution (including the normal kinds of
309 commercial redistribution) must be permitted, so that the manual can
310 accompany every copy of the program, both on-line and on paper.
311
312 Permission for modification of the technical content is crucial too.
313 When people modify the software, adding or changing features, if they
314 are conscientious they will change the manual too---so they can
315 provide accurate and clear documentation for the modified program. A
316 manual that leaves you no choice but to write a new manual to document
317 a changed version of the program is not really available to our
318 community.
319
320 Some kinds of limits on the way modification is handled are
321 acceptable. For example, requirements to preserve the original
322 author's copyright notice, the distribution terms, or the list of
323 authors, are ok. It is also no problem to require modified versions
324 to include notice that they were modified. Even entire sections that
325 may not be deleted or changed are acceptable, as long as they deal
326 with nontechnical topics (like this one). These kinds of restrictions
327 are acceptable because they don't obstruct the community's normal use
328 of the manual.
329
330 However, it must be possible to modify all the @emph{technical}
331 content of the manual, and then distribute the result in all the usual
332 media, through all the usual channels. Otherwise, the restrictions
333 obstruct the use of the manual, it is not free, and we need another
334 manual to replace it.
335
336 Please spread the word about this issue. Our community continues to
337 lose manuals to proprietary publishing. If we spread the word that
338 free software needs free reference manuals and free tutorials, perhaps
339 the next person who wants to contribute by writing documentation will
340 realize, before it is too late, that only free manuals contribute to
341 the free software community.
342
343 If you are writing documentation, please insist on publishing it under
344 the GNU Free Documentation License or another free documentation
345 license. Remember that this decision requires your approval---you
346 don't have to let the publisher decide. Some commercial publishers
347 will use a free license if you insist, but they will not propose the
348 option; it is up to you to raise the issue and say firmly that this is
349 what you want. If the publisher you are dealing with refuses, please
350 try other publishers. If you're not sure whether a proposed license
351 is free, write to @email{licensing@@gnu.org}.
352
353 You can encourage commercial publishers to sell more free, copylefted
354 manuals and tutorials by buying them, and particularly by buying
355 copies from the publishers that paid for their writing or for major
356 improvements. Meanwhile, try to avoid buying non-free documentation
357 at all. Check the distribution terms of a manual before you buy it,
358 and insist that whoever seeks your business must respect your freedom.
359 Check the history of the book, and try to reward the publishers that
360 have paid or pay the authors to work on it.
361
362 The Free Software Foundation maintains a list of free documentation
363 published by other publishers, at
364 @url{http://www.fsf.org/doc/other-free-books.html}.
365
366 @node Contributors
367 @unnumberedsec Contributors to @value{GDBN}
368
369 Richard Stallman was the original author of @value{GDBN}, and of many
370 other @sc{gnu} programs. Many others have contributed to its
371 development. This section attempts to credit major contributors. One
372 of the virtues of free software is that everyone is free to contribute
373 to it; with regret, we cannot actually acknowledge everyone here. The
374 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
375 blow-by-blow account.
376
377 Changes much prior to version 2.0 are lost in the mists of time.
378
379 @quotation
380 @emph{Plea:} Additions to this section are particularly welcome. If you
381 or your friends (or enemies, to be evenhanded) have been unfairly
382 omitted from this list, we would like to add your names!
383 @end quotation
384
385 So that they may not regard their many labors as thankless, we
386 particularly thank those who shepherded @value{GDBN} through major
387 releases:
388 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
389 Jim Blandy (release 4.18);
390 Jason Molenda (release 4.17);
391 Stan Shebs (release 4.14);
392 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395 Jim Kingdon (releases 3.5, 3.4, and 3.3);
396 and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398 Richard Stallman, assisted at various times by Peter TerMaat, Chris
399 Hanson, and Richard Mlynarik, handled releases through 2.8.
400
401 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402 in @value{GDBN}, with significant additional contributions from Per
403 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405 much general update work leading to release 3.0).
406
407 @value{GDBN} uses the BFD subroutine library to examine multiple
408 object-file formats; BFD was a joint project of David V.
409 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411 David Johnson wrote the original COFF support; Pace Willison did
412 the original support for encapsulated COFF.
413
414 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
415
416 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418 support.
419 Jean-Daniel Fekete contributed Sun 386i support.
420 Chris Hanson improved the HP9000 support.
421 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422 David Johnson contributed Encore Umax support.
423 Jyrki Kuoppala contributed Altos 3068 support.
424 Jeff Law contributed HP PA and SOM support.
425 Keith Packard contributed NS32K support.
426 Doug Rabson contributed Acorn Risc Machine support.
427 Bob Rusk contributed Harris Nighthawk CX-UX support.
428 Chris Smith contributed Convex support (and Fortran debugging).
429 Jonathan Stone contributed Pyramid support.
430 Michael Tiemann contributed SPARC support.
431 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432 Pace Willison contributed Intel 386 support.
433 Jay Vosburgh contributed Symmetry support.
434 Marko Mlinar contributed OpenRISC 1000 support.
435
436 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
437
438 Rich Schaefer and Peter Schauer helped with support of SunOS shared
439 libraries.
440
441 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442 about several machine instruction sets.
443
444 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447 and RDI targets, respectively.
448
449 Brian Fox is the author of the readline libraries providing
450 command-line editing and command history.
451
452 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453 Modula-2 support, and contributed the Languages chapter of this manual.
454
455 Fred Fish wrote most of the support for Unix System Vr4.
456 He also enhanced the command-completion support to cover C@t{++} overloaded
457 symbols.
458
459 Hitachi America (now Renesas America), Ltd. sponsored the support for
460 H8/300, H8/500, and Super-H processors.
461
462 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
464 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465 processors.
466
467 Toshiba sponsored the support for the TX39 Mips processor.
468
469 Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
471 Fujitsu sponsored the support for SPARClite and FR30 processors.
472
473 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474 watchpoints.
475
476 Michael Snyder added support for tracepoints.
477
478 Stu Grossman wrote gdbserver.
479
480 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
481 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
482
483 The following people at the Hewlett-Packard Company contributed
484 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
485 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
486 compiler, and the Text User Interface (nee Terminal User Interface):
487 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489 provided HP-specific information in this manual.
490
491 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492 Robert Hoehne made significant contributions to the DJGPP port.
493
494 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495 development since 1991. Cygnus engineers who have worked on @value{GDBN}
496 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508 Zuhn have made contributions both large and small.
509
510 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
513 Jim Blandy added support for preprocessor macros, while working for Red
514 Hat.
515
516 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521 with the migration of old architectures to this new framework.
522
523 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524 unwinder framework, this consisting of a fresh new design featuring
525 frame IDs, independent frame sniffers, and the sentinel frame. Mark
526 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
528 trad unwinders. The architecture-specific changes, each involving a
529 complete rewrite of the architecture's frame code, were carried out by
530 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534 Weigand.
535
536 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537 Tensilica, Inc.@: contributed support for Xtensa processors. Others
538 who have worked on the Xtensa port of @value{GDBN} in the past include
539 Steve Tjiang, John Newlin, and Scott Foehner.
540
541 Michael Eager and staff of Xilinx, Inc., contributed support for the
542 Xilinx MicroBlaze architecture.
543
544 Initial support for the FreeBSD/mips target and native configuration
545 was developed by SRI International and the University of Cambridge
546 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547 ("CTSRD"), as part of the DARPA CRASH research programme.
548
549 Initial support for the FreeBSD/riscv target and native configuration
550 was developed by SRI International and the University of Cambridge
551 Computer Laboratory (Department of Computer Science and Technology)
552 under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553 SSITH research programme.
554
555 The original port to the OpenRISC 1000 is believed to be due to
556 Alessandro Forin and Per Bothner. More recent ports have been the work
557 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558 Stafford Horne.
559
560 @node Sample Session
561 @chapter A Sample @value{GDBN} Session
562
563 You can use this manual at your leisure to read all about @value{GDBN}.
564 However, a handful of commands are enough to get started using the
565 debugger. This chapter illustrates those commands.
566
567 @iftex
568 In this sample session, we emphasize user input like this: @b{input},
569 to make it easier to pick out from the surrounding output.
570 @end iftex
571
572 @c FIXME: this example may not be appropriate for some configs, where
573 @c FIXME...primary interest is in remote use.
574
575 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
576 processor) exhibits the following bug: sometimes, when we change its
577 quote strings from the default, the commands used to capture one macro
578 definition within another stop working. In the following short @code{m4}
579 session, we define a macro @code{foo} which expands to @code{0000}; we
580 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
581 same thing. However, when we change the open quote string to
582 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
583 procedure fails to define a new synonym @code{baz}:
584
585 @smallexample
586 $ @b{cd gnu/m4}
587 $ @b{./m4}
588 @b{define(foo,0000)}
589
590 @b{foo}
591 0000
592 @b{define(bar,defn(`foo'))}
593
594 @b{bar}
595 0000
596 @b{changequote(<QUOTE>,<UNQUOTE>)}
597
598 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
599 @b{baz}
600 @b{Ctrl-d}
601 m4: End of input: 0: fatal error: EOF in string
602 @end smallexample
603
604 @noindent
605 Let us use @value{GDBN} to try to see what is going on.
606
607 @smallexample
608 $ @b{@value{GDBP} m4}
609 @c FIXME: this falsifies the exact text played out, to permit smallbook
610 @c FIXME... format to come out better.
611 @value{GDBN} is free software and you are welcome to distribute copies
612 of it under certain conditions; type "show copying" to see
613 the conditions.
614 There is absolutely no warranty for @value{GDBN}; type "show warranty"
615 for details.
616
617 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
618 (@value{GDBP})
619 @end smallexample
620
621 @noindent
622 @value{GDBN} reads only enough symbol data to know where to find the
623 rest when needed; as a result, the first prompt comes up very quickly.
624 We now tell @value{GDBN} to use a narrower display width than usual, so
625 that examples fit in this manual.
626
627 @smallexample
628 (@value{GDBP}) @b{set width 70}
629 @end smallexample
630
631 @noindent
632 We need to see how the @code{m4} built-in @code{changequote} works.
633 Having looked at the source, we know the relevant subroutine is
634 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
635 @code{break} command.
636
637 @smallexample
638 (@value{GDBP}) @b{break m4_changequote}
639 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
640 @end smallexample
641
642 @noindent
643 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
644 control; as long as control does not reach the @code{m4_changequote}
645 subroutine, the program runs as usual:
646
647 @smallexample
648 (@value{GDBP}) @b{run}
649 Starting program: /work/Editorial/gdb/gnu/m4/m4
650 @b{define(foo,0000)}
651
652 @b{foo}
653 0000
654 @end smallexample
655
656 @noindent
657 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
658 suspends execution of @code{m4}, displaying information about the
659 context where it stops.
660
661 @smallexample
662 @b{changequote(<QUOTE>,<UNQUOTE>)}
663
664 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
665 at builtin.c:879
666 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
667 @end smallexample
668
669 @noindent
670 Now we use the command @code{n} (@code{next}) to advance execution to
671 the next line of the current function.
672
673 @smallexample
674 (@value{GDBP}) @b{n}
675 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
676 : nil,
677 @end smallexample
678
679 @noindent
680 @code{set_quotes} looks like a promising subroutine. We can go into it
681 by using the command @code{s} (@code{step}) instead of @code{next}.
682 @code{step} goes to the next line to be executed in @emph{any}
683 subroutine, so it steps into @code{set_quotes}.
684
685 @smallexample
686 (@value{GDBP}) @b{s}
687 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
688 at input.c:530
689 530 if (lquote != def_lquote)
690 @end smallexample
691
692 @noindent
693 The display that shows the subroutine where @code{m4} is now
694 suspended (and its arguments) is called a stack frame display. It
695 shows a summary of the stack. We can use the @code{backtrace}
696 command (which can also be spelled @code{bt}), to see where we are
697 in the stack as a whole: the @code{backtrace} command displays a
698 stack frame for each active subroutine.
699
700 @smallexample
701 (@value{GDBP}) @b{bt}
702 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
703 at input.c:530
704 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
705 at builtin.c:882
706 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
707 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
708 at macro.c:71
709 #4 0x79dc in expand_input () at macro.c:40
710 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
711 @end smallexample
712
713 @noindent
714 We step through a few more lines to see what happens. The first two
715 times, we can use @samp{s}; the next two times we use @code{n} to avoid
716 falling into the @code{xstrdup} subroutine.
717
718 @smallexample
719 (@value{GDBP}) @b{s}
720 0x3b5c 532 if (rquote != def_rquote)
721 (@value{GDBP}) @b{s}
722 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
723 def_lquote : xstrdup(lq);
724 (@value{GDBP}) @b{n}
725 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
726 : xstrdup(rq);
727 (@value{GDBP}) @b{n}
728 538 len_lquote = strlen(rquote);
729 @end smallexample
730
731 @noindent
732 The last line displayed looks a little odd; we can examine the variables
733 @code{lquote} and @code{rquote} to see if they are in fact the new left
734 and right quotes we specified. We use the command @code{p}
735 (@code{print}) to see their values.
736
737 @smallexample
738 (@value{GDBP}) @b{p lquote}
739 $1 = 0x35d40 "<QUOTE>"
740 (@value{GDBP}) @b{p rquote}
741 $2 = 0x35d50 "<UNQUOTE>"
742 @end smallexample
743
744 @noindent
745 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
746 To look at some context, we can display ten lines of source
747 surrounding the current line with the @code{l} (@code{list}) command.
748
749 @smallexample
750 (@value{GDBP}) @b{l}
751 533 xfree(rquote);
752 534
753 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
754 : xstrdup (lq);
755 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
756 : xstrdup (rq);
757 537
758 538 len_lquote = strlen(rquote);
759 539 len_rquote = strlen(lquote);
760 540 @}
761 541
762 542 void
763 @end smallexample
764
765 @noindent
766 Let us step past the two lines that set @code{len_lquote} and
767 @code{len_rquote}, and then examine the values of those variables.
768
769 @smallexample
770 (@value{GDBP}) @b{n}
771 539 len_rquote = strlen(lquote);
772 (@value{GDBP}) @b{n}
773 540 @}
774 (@value{GDBP}) @b{p len_lquote}
775 $3 = 9
776 (@value{GDBP}) @b{p len_rquote}
777 $4 = 7
778 @end smallexample
779
780 @noindent
781 That certainly looks wrong, assuming @code{len_lquote} and
782 @code{len_rquote} are meant to be the lengths of @code{lquote} and
783 @code{rquote} respectively. We can set them to better values using
784 the @code{p} command, since it can print the value of
785 any expression---and that expression can include subroutine calls and
786 assignments.
787
788 @smallexample
789 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
790 $5 = 7
791 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
792 $6 = 9
793 @end smallexample
794
795 @noindent
796 Is that enough to fix the problem of using the new quotes with the
797 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
798 executing with the @code{c} (@code{continue}) command, and then try the
799 example that caused trouble initially:
800
801 @smallexample
802 (@value{GDBP}) @b{c}
803 Continuing.
804
805 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
806
807 baz
808 0000
809 @end smallexample
810
811 @noindent
812 Success! The new quotes now work just as well as the default ones. The
813 problem seems to have been just the two typos defining the wrong
814 lengths. We allow @code{m4} exit by giving it an EOF as input:
815
816 @smallexample
817 @b{Ctrl-d}
818 Program exited normally.
819 @end smallexample
820
821 @noindent
822 The message @samp{Program exited normally.} is from @value{GDBN}; it
823 indicates @code{m4} has finished executing. We can end our @value{GDBN}
824 session with the @value{GDBN} @code{quit} command.
825
826 @smallexample
827 (@value{GDBP}) @b{quit}
828 @end smallexample
829
830 @node Invocation
831 @chapter Getting In and Out of @value{GDBN}
832
833 This chapter discusses how to start @value{GDBN}, and how to get out of it.
834 The essentials are:
835 @itemize @bullet
836 @item
837 type @samp{@value{GDBP}} to start @value{GDBN}.
838 @item
839 type @kbd{quit} or @kbd{Ctrl-d} to exit.
840 @end itemize
841
842 @menu
843 * Invoking GDB:: How to start @value{GDBN}
844 * Quitting GDB:: How to quit @value{GDBN}
845 * Shell Commands:: How to use shell commands inside @value{GDBN}
846 * Logging Output:: How to log @value{GDBN}'s output to a file
847 @end menu
848
849 @node Invoking GDB
850 @section Invoking @value{GDBN}
851
852 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
853 @value{GDBN} reads commands from the terminal until you tell it to exit.
854
855 You can also run @code{@value{GDBP}} with a variety of arguments and options,
856 to specify more of your debugging environment at the outset.
857
858 The command-line options described here are designed
859 to cover a variety of situations; in some environments, some of these
860 options may effectively be unavailable.
861
862 The most usual way to start @value{GDBN} is with one argument,
863 specifying an executable program:
864
865 @smallexample
866 @value{GDBP} @var{program}
867 @end smallexample
868
869 @noindent
870 You can also start with both an executable program and a core file
871 specified:
872
873 @smallexample
874 @value{GDBP} @var{program} @var{core}
875 @end smallexample
876
877 You can, instead, specify a process ID as a second argument or use option
878 @code{-p}, if you want to debug a running process:
879
880 @smallexample
881 @value{GDBP} @var{program} 1234
882 @value{GDBP} -p 1234
883 @end smallexample
884
885 @noindent
886 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
887 can omit the @var{program} filename.
888
889 Taking advantage of the second command-line argument requires a fairly
890 complete operating system; when you use @value{GDBN} as a remote
891 debugger attached to a bare board, there may not be any notion of
892 ``process'', and there is often no way to get a core dump. @value{GDBN}
893 will warn you if it is unable to attach or to read core dumps.
894
895 You can optionally have @code{@value{GDBP}} pass any arguments after the
896 executable file to the inferior using @code{--args}. This option stops
897 option processing.
898 @smallexample
899 @value{GDBP} --args gcc -O2 -c foo.c
900 @end smallexample
901 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
902 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
903
904 You can run @code{@value{GDBP}} without printing the front material, which describes
905 @value{GDBN}'s non-warranty, by specifying @code{--silent}
906 (or @code{-q}/@code{--quiet}):
907
908 @smallexample
909 @value{GDBP} --silent
910 @end smallexample
911
912 @noindent
913 You can further control how @value{GDBN} starts up by using command-line
914 options. @value{GDBN} itself can remind you of the options available.
915
916 @noindent
917 Type
918
919 @smallexample
920 @value{GDBP} -help
921 @end smallexample
922
923 @noindent
924 to display all available options and briefly describe their use
925 (@samp{@value{GDBP} -h} is a shorter equivalent).
926
927 All options and command line arguments you give are processed
928 in sequential order. The order makes a difference when the
929 @samp{-x} option is used.
930
931
932 @menu
933 * File Options:: Choosing files
934 * Mode Options:: Choosing modes
935 * Startup:: What @value{GDBN} does during startup
936 @end menu
937
938 @node File Options
939 @subsection Choosing Files
940
941 When @value{GDBN} starts, it reads any arguments other than options as
942 specifying an executable file and core file (or process ID). This is
943 the same as if the arguments were specified by the @samp{-se} and
944 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
945 first argument that does not have an associated option flag as
946 equivalent to the @samp{-se} option followed by that argument; and the
947 second argument that does not have an associated option flag, if any, as
948 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
949 If the second argument begins with a decimal digit, @value{GDBN} will
950 first attempt to attach to it as a process, and if that fails, attempt
951 to open it as a corefile. If you have a corefile whose name begins with
952 a digit, you can prevent @value{GDBN} from treating it as a pid by
953 prefixing it with @file{./}, e.g.@: @file{./12345}.
954
955 If @value{GDBN} has not been configured to included core file support,
956 such as for most embedded targets, then it will complain about a second
957 argument and ignore it.
958
959 Many options have both long and short forms; both are shown in the
960 following list. @value{GDBN} also recognizes the long forms if you truncate
961 them, so long as enough of the option is present to be unambiguous.
962 (If you prefer, you can flag option arguments with @samp{--} rather
963 than @samp{-}, though we illustrate the more usual convention.)
964
965 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
966 @c way, both those who look for -foo and --foo in the index, will find
967 @c it.
968
969 @table @code
970 @item -symbols @var{file}
971 @itemx -s @var{file}
972 @cindex @code{--symbols}
973 @cindex @code{-s}
974 Read symbol table from file @var{file}.
975
976 @item -exec @var{file}
977 @itemx -e @var{file}
978 @cindex @code{--exec}
979 @cindex @code{-e}
980 Use file @var{file} as the executable file to execute when appropriate,
981 and for examining pure data in conjunction with a core dump.
982
983 @item -se @var{file}
984 @cindex @code{--se}
985 Read symbol table from file @var{file} and use it as the executable
986 file.
987
988 @item -core @var{file}
989 @itemx -c @var{file}
990 @cindex @code{--core}
991 @cindex @code{-c}
992 Use file @var{file} as a core dump to examine.
993
994 @item -pid @var{number}
995 @itemx -p @var{number}
996 @cindex @code{--pid}
997 @cindex @code{-p}
998 Connect to process ID @var{number}, as with the @code{attach} command.
999
1000 @item -command @var{file}
1001 @itemx -x @var{file}
1002 @cindex @code{--command}
1003 @cindex @code{-x}
1004 Execute commands from file @var{file}. The contents of this file is
1005 evaluated exactly as the @code{source} command would.
1006 @xref{Command Files,, Command files}.
1007
1008 @item -eval-command @var{command}
1009 @itemx -ex @var{command}
1010 @cindex @code{--eval-command}
1011 @cindex @code{-ex}
1012 Execute a single @value{GDBN} command.
1013
1014 This option may be used multiple times to call multiple commands. It may
1015 also be interleaved with @samp{-command} as required.
1016
1017 @smallexample
1018 @value{GDBP} -ex 'target sim' -ex 'load' \
1019 -x setbreakpoints -ex 'run' a.out
1020 @end smallexample
1021
1022 @item -init-command @var{file}
1023 @itemx -ix @var{file}
1024 @cindex @code{--init-command}
1025 @cindex @code{-ix}
1026 Execute commands from file @var{file} before loading the inferior (but
1027 after loading gdbinit files).
1028 @xref{Startup}.
1029
1030 @item -init-eval-command @var{command}
1031 @itemx -iex @var{command}
1032 @cindex @code{--init-eval-command}
1033 @cindex @code{-iex}
1034 Execute a single @value{GDBN} command before loading the inferior (but
1035 after loading gdbinit files).
1036 @xref{Startup}.
1037
1038 @item -directory @var{directory}
1039 @itemx -d @var{directory}
1040 @cindex @code{--directory}
1041 @cindex @code{-d}
1042 Add @var{directory} to the path to search for source and script files.
1043
1044 @item -r
1045 @itemx -readnow
1046 @cindex @code{--readnow}
1047 @cindex @code{-r}
1048 Read each symbol file's entire symbol table immediately, rather than
1049 the default, which is to read it incrementally as it is needed.
1050 This makes startup slower, but makes future operations faster.
1051
1052 @item --readnever
1053 @anchor{--readnever}
1054 @cindex @code{--readnever}, command-line option
1055 Do not read each symbol file's symbolic debug information. This makes
1056 startup faster but at the expense of not being able to perform
1057 symbolic debugging. DWARF unwind information is also not read,
1058 meaning backtraces may become incomplete or inaccurate. One use of
1059 this is when a user simply wants to do the following sequence: attach,
1060 dump core, detach. Loading the debugging information in this case is
1061 an unnecessary cause of delay.
1062 @end table
1063
1064 @node Mode Options
1065 @subsection Choosing Modes
1066
1067 You can run @value{GDBN} in various alternative modes---for example, in
1068 batch mode or quiet mode.
1069
1070 @table @code
1071 @anchor{-nx}
1072 @item -nx
1073 @itemx -n
1074 @cindex @code{--nx}
1075 @cindex @code{-n}
1076 Do not execute commands found in any initialization file.
1077 There are three init files, loaded in the following order:
1078
1079 @table @code
1080 @item @file{system.gdbinit}
1081 This is the system-wide init file.
1082 Its location is specified with the @code{--with-system-gdbinit}
1083 configure option (@pxref{System-wide configuration}).
1084 It is loaded first when @value{GDBN} starts, before command line options
1085 have been processed.
1086 @item @file{system.gdbinit.d}
1087 This is the system-wide init directory.
1088 Its location is specified with the @code{--with-system-gdbinit-dir}
1089 configure option (@pxref{System-wide configuration}).
1090 Files in this directory are loaded in alphabetical order immediately after
1091 system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1092 options have been processed. Files need to have a recognized scripting
1093 language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1094 extension to be interpreted as regular @value{GDBN} commands. @value{GDBN}
1095 will not recurse into any subdirectories of this directory.
1096 @item @file{~/.gdbinit}
1097 This is the init file in your home directory.
1098 It is loaded next, after @file{system.gdbinit}, and before
1099 command options have been processed.
1100 @item @file{./.gdbinit}
1101 This is the init file in the current directory.
1102 It is loaded last, after command line options other than @code{-x} and
1103 @code{-ex} have been processed. Command line options @code{-x} and
1104 @code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1105 @end table
1106
1107 For further documentation on startup processing, @xref{Startup}.
1108 For documentation on how to write command files,
1109 @xref{Command Files,,Command Files}.
1110
1111 @anchor{-nh}
1112 @item -nh
1113 @cindex @code{--nh}
1114 Do not execute commands found in @file{~/.gdbinit}, the init file
1115 in your home directory.
1116 @xref{Startup}.
1117
1118 @item -quiet
1119 @itemx -silent
1120 @itemx -q
1121 @cindex @code{--quiet}
1122 @cindex @code{--silent}
1123 @cindex @code{-q}
1124 ``Quiet''. Do not print the introductory and copyright messages. These
1125 messages are also suppressed in batch mode.
1126
1127 @item -batch
1128 @cindex @code{--batch}
1129 Run in batch mode. Exit with status @code{0} after processing all the
1130 command files specified with @samp{-x} (and all commands from
1131 initialization files, if not inhibited with @samp{-n}). Exit with
1132 nonzero status if an error occurs in executing the @value{GDBN} commands
1133 in the command files. Batch mode also disables pagination, sets unlimited
1134 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1135 off} were in effect (@pxref{Messages/Warnings}).
1136
1137 Batch mode may be useful for running @value{GDBN} as a filter, for
1138 example to download and run a program on another computer; in order to
1139 make this more useful, the message
1140
1141 @smallexample
1142 Program exited normally.
1143 @end smallexample
1144
1145 @noindent
1146 (which is ordinarily issued whenever a program running under
1147 @value{GDBN} control terminates) is not issued when running in batch
1148 mode.
1149
1150 @item -batch-silent
1151 @cindex @code{--batch-silent}
1152 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1153 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1154 unaffected). This is much quieter than @samp{-silent} and would be useless
1155 for an interactive session.
1156
1157 This is particularly useful when using targets that give @samp{Loading section}
1158 messages, for example.
1159
1160 Note that targets that give their output via @value{GDBN}, as opposed to
1161 writing directly to @code{stdout}, will also be made silent.
1162
1163 @item -return-child-result
1164 @cindex @code{--return-child-result}
1165 The return code from @value{GDBN} will be the return code from the child
1166 process (the process being debugged), with the following exceptions:
1167
1168 @itemize @bullet
1169 @item
1170 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1171 internal error. In this case the exit code is the same as it would have been
1172 without @samp{-return-child-result}.
1173 @item
1174 The user quits with an explicit value. E.g., @samp{quit 1}.
1175 @item
1176 The child process never runs, or is not allowed to terminate, in which case
1177 the exit code will be -1.
1178 @end itemize
1179
1180 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1181 when @value{GDBN} is being used as a remote program loader or simulator
1182 interface.
1183
1184 @item -nowindows
1185 @itemx -nw
1186 @cindex @code{--nowindows}
1187 @cindex @code{-nw}
1188 ``No windows''. If @value{GDBN} comes with a graphical user interface
1189 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1190 interface. If no GUI is available, this option has no effect.
1191
1192 @item -windows
1193 @itemx -w
1194 @cindex @code{--windows}
1195 @cindex @code{-w}
1196 If @value{GDBN} includes a GUI, then this option requires it to be
1197 used if possible.
1198
1199 @item -cd @var{directory}
1200 @cindex @code{--cd}
1201 Run @value{GDBN} using @var{directory} as its working directory,
1202 instead of the current directory.
1203
1204 @item -data-directory @var{directory}
1205 @itemx -D @var{directory}
1206 @cindex @code{--data-directory}
1207 @cindex @code{-D}
1208 Run @value{GDBN} using @var{directory} as its data directory.
1209 The data directory is where @value{GDBN} searches for its
1210 auxiliary files. @xref{Data Files}.
1211
1212 @item -fullname
1213 @itemx -f
1214 @cindex @code{--fullname}
1215 @cindex @code{-f}
1216 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1217 subprocess. It tells @value{GDBN} to output the full file name and line
1218 number in a standard, recognizable fashion each time a stack frame is
1219 displayed (which includes each time your program stops). This
1220 recognizable format looks like two @samp{\032} characters, followed by
1221 the file name, line number and character position separated by colons,
1222 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1223 @samp{\032} characters as a signal to display the source code for the
1224 frame.
1225
1226 @item -annotate @var{level}
1227 @cindex @code{--annotate}
1228 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1229 effect is identical to using @samp{set annotate @var{level}}
1230 (@pxref{Annotations}). The annotation @var{level} controls how much
1231 information @value{GDBN} prints together with its prompt, values of
1232 expressions, source lines, and other types of output. Level 0 is the
1233 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1234 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1235 that control @value{GDBN}, and level 2 has been deprecated.
1236
1237 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1238 (@pxref{GDB/MI}).
1239
1240 @item --args
1241 @cindex @code{--args}
1242 Change interpretation of command line so that arguments following the
1243 executable file are passed as command line arguments to the inferior.
1244 This option stops option processing.
1245
1246 @item -baud @var{bps}
1247 @itemx -b @var{bps}
1248 @cindex @code{--baud}
1249 @cindex @code{-b}
1250 Set the line speed (baud rate or bits per second) of any serial
1251 interface used by @value{GDBN} for remote debugging.
1252
1253 @item -l @var{timeout}
1254 @cindex @code{-l}
1255 Set the timeout (in seconds) of any communication used by @value{GDBN}
1256 for remote debugging.
1257
1258 @item -tty @var{device}
1259 @itemx -t @var{device}
1260 @cindex @code{--tty}
1261 @cindex @code{-t}
1262 Run using @var{device} for your program's standard input and output.
1263 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1264
1265 @c resolve the situation of these eventually
1266 @item -tui
1267 @cindex @code{--tui}
1268 Activate the @dfn{Text User Interface} when starting. The Text User
1269 Interface manages several text windows on the terminal, showing
1270 source, assembly, registers and @value{GDBN} command outputs
1271 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1272 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1273 Using @value{GDBN} under @sc{gnu} Emacs}).
1274
1275 @item -interpreter @var{interp}
1276 @cindex @code{--interpreter}
1277 Use the interpreter @var{interp} for interface with the controlling
1278 program or device. This option is meant to be set by programs which
1279 communicate with @value{GDBN} using it as a back end.
1280 @xref{Interpreters, , Command Interpreters}.
1281
1282 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1283 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1284 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1285 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1286 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1287 interfaces are no longer supported.
1288
1289 @item -write
1290 @cindex @code{--write}
1291 Open the executable and core files for both reading and writing. This
1292 is equivalent to the @samp{set write on} command inside @value{GDBN}
1293 (@pxref{Patching}).
1294
1295 @item -statistics
1296 @cindex @code{--statistics}
1297 This option causes @value{GDBN} to print statistics about time and
1298 memory usage after it completes each command and returns to the prompt.
1299
1300 @item -version
1301 @cindex @code{--version}
1302 This option causes @value{GDBN} to print its version number and
1303 no-warranty blurb, and exit.
1304
1305 @item -configuration
1306 @cindex @code{--configuration}
1307 This option causes @value{GDBN} to print details about its build-time
1308 configuration parameters, and then exit. These details can be
1309 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1310
1311 @end table
1312
1313 @node Startup
1314 @subsection What @value{GDBN} Does During Startup
1315 @cindex @value{GDBN} startup
1316
1317 Here's the description of what @value{GDBN} does during session startup:
1318
1319 @enumerate
1320 @item
1321 Sets up the command interpreter as specified by the command line
1322 (@pxref{Mode Options, interpreter}).
1323
1324 @item
1325 @cindex init file
1326 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1327 used when building @value{GDBN}; @pxref{System-wide configuration,
1328 ,System-wide configuration and settings}) and the files in the system-wide
1329 gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1330 all the commands in those files. The files need to be named with a @file{.gdb}
1331 extension to be interpreted as @value{GDBN} commands, or they can be written
1332 in a supported scripting language with an appropriate file extension.
1333
1334 @anchor{Home Directory Init File}
1335 @item
1336 Reads the init file (if any) in your home directory@footnote{On
1337 DOS/Windows systems, the home directory is the one pointed to by the
1338 @code{HOME} environment variable.} and executes all the commands in
1339 that file.
1340
1341 @anchor{Option -init-eval-command}
1342 @item
1343 Executes commands and command files specified by the @samp{-iex} and
1344 @samp{-ix} options in their specified order. Usually you should use the
1345 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1346 settings before @value{GDBN} init files get executed and before inferior
1347 gets loaded.
1348
1349 @item
1350 Processes command line options and operands.
1351
1352 @anchor{Init File in the Current Directory during Startup}
1353 @item
1354 Reads and executes the commands from init file (if any) in the current
1355 working directory as long as @samp{set auto-load local-gdbinit} is set to
1356 @samp{on} (@pxref{Init File in the Current Directory}).
1357 This is only done if the current directory is
1358 different from your home directory. Thus, you can have more than one
1359 init file, one generic in your home directory, and another, specific
1360 to the program you are debugging, in the directory where you invoke
1361 @value{GDBN}.
1362
1363 @item
1364 If the command line specified a program to debug, or a process to
1365 attach to, or a core file, @value{GDBN} loads any auto-loaded
1366 scripts provided for the program or for its loaded shared libraries.
1367 @xref{Auto-loading}.
1368
1369 If you wish to disable the auto-loading during startup,
1370 you must do something like the following:
1371
1372 @smallexample
1373 $ gdb -iex "set auto-load python-scripts off" myprogram
1374 @end smallexample
1375
1376 Option @samp{-ex} does not work because the auto-loading is then turned
1377 off too late.
1378
1379 @item
1380 Executes commands and command files specified by the @samp{-ex} and
1381 @samp{-x} options in their specified order. @xref{Command Files}, for
1382 more details about @value{GDBN} command files.
1383
1384 @item
1385 Reads the command history recorded in the @dfn{history file}.
1386 @xref{Command History}, for more details about the command history and the
1387 files where @value{GDBN} records it.
1388 @end enumerate
1389
1390 Init files use the same syntax as @dfn{command files} (@pxref{Command
1391 Files}) and are processed by @value{GDBN} in the same way. The init
1392 file in your home directory can set options (such as @samp{set
1393 complaints}) that affect subsequent processing of command line options
1394 and operands. Init files are not executed if you use the @samp{-nx}
1395 option (@pxref{Mode Options, ,Choosing Modes}).
1396
1397 To display the list of init files loaded by gdb at startup, you
1398 can use @kbd{gdb --help}.
1399
1400 @cindex init file name
1401 @cindex @file{.gdbinit}
1402 @cindex @file{gdb.ini}
1403 The @value{GDBN} init files are normally called @file{.gdbinit}.
1404 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1405 the limitations of file names imposed by DOS filesystems. The Windows
1406 port of @value{GDBN} uses the standard name, but if it finds a
1407 @file{gdb.ini} file in your home directory, it warns you about that
1408 and suggests to rename the file to the standard name.
1409
1410
1411 @node Quitting GDB
1412 @section Quitting @value{GDBN}
1413 @cindex exiting @value{GDBN}
1414 @cindex leaving @value{GDBN}
1415
1416 @table @code
1417 @kindex quit @r{[}@var{expression}@r{]}
1418 @kindex q @r{(@code{quit})}
1419 @item quit @r{[}@var{expression}@r{]}
1420 @itemx q
1421 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1422 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1423 do not supply @var{expression}, @value{GDBN} will terminate normally;
1424 otherwise it will terminate using the result of @var{expression} as the
1425 error code.
1426 @end table
1427
1428 @cindex interrupt
1429 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1430 terminates the action of any @value{GDBN} command that is in progress and
1431 returns to @value{GDBN} command level. It is safe to type the interrupt
1432 character at any time because @value{GDBN} does not allow it to take effect
1433 until a time when it is safe.
1434
1435 If you have been using @value{GDBN} to control an attached process or
1436 device, you can release it with the @code{detach} command
1437 (@pxref{Attach, ,Debugging an Already-running Process}).
1438
1439 @node Shell Commands
1440 @section Shell Commands
1441
1442 If you need to execute occasional shell commands during your
1443 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1444 just use the @code{shell} command.
1445
1446 @table @code
1447 @kindex shell
1448 @kindex !
1449 @cindex shell escape
1450 @item shell @var{command-string}
1451 @itemx !@var{command-string}
1452 Invoke a standard shell to execute @var{command-string}.
1453 Note that no space is needed between @code{!} and @var{command-string}.
1454 If it exists, the environment variable @code{SHELL} determines which
1455 shell to run. Otherwise @value{GDBN} uses the default shell
1456 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1457 @end table
1458
1459 The utility @code{make} is often needed in development environments.
1460 You do not have to use the @code{shell} command for this purpose in
1461 @value{GDBN}:
1462
1463 @table @code
1464 @kindex make
1465 @cindex calling make
1466 @item make @var{make-args}
1467 Execute the @code{make} program with the specified
1468 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1469 @end table
1470
1471 @table @code
1472 @kindex pipe
1473 @kindex |
1474 @cindex send the output of a gdb command to a shell command
1475 @anchor{pipe}
1476 @item pipe [@var{command}] | @var{shell_command}
1477 @itemx | [@var{command}] | @var{shell_command}
1478 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1479 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1480 Executes @var{command} and sends its output to @var{shell_command}.
1481 Note that no space is needed around @code{|}.
1482 If no @var{command} is provided, the last command executed is repeated.
1483
1484 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1485 can be used to specify an alternate delimiter string @var{delim} that separates
1486 the @var{command} from the @var{shell_command}.
1487
1488 Example:
1489 @smallexample
1490 @group
1491 (gdb) p var
1492 $1 = @{
1493 black = 144,
1494 red = 233,
1495 green = 377,
1496 blue = 610,
1497 white = 987
1498 @}
1499 @end group
1500 @group
1501 (gdb) pipe p var|wc
1502 7 19 80
1503 (gdb) |p var|wc -l
1504 7
1505 @end group
1506 @group
1507 (gdb) p /x var
1508 $4 = @{
1509 black = 0x90,
1510 red = 0xe9,
1511 green = 0x179,
1512 blue = 0x262,
1513 white = 0x3db
1514 @}
1515 (gdb) ||grep red
1516 red => 0xe9,
1517 @end group
1518 @group
1519 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1520 this contains a PIPE char
1521 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1522 this contains a PIPE char!
1523 (gdb)
1524 @end group
1525 @end smallexample
1526 @end table
1527
1528 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1529 can be used to examine the exit status of the last shell command launched
1530 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1531 @xref{Convenience Vars,, Convenience Variables}.
1532
1533 @node Logging Output
1534 @section Logging Output
1535 @cindex logging @value{GDBN} output
1536 @cindex save @value{GDBN} output to a file
1537
1538 You may want to save the output of @value{GDBN} commands to a file.
1539 There are several commands to control @value{GDBN}'s logging.
1540
1541 @table @code
1542 @kindex set logging
1543 @item set logging on
1544 Enable logging.
1545 @item set logging off
1546 Disable logging.
1547 @cindex logging file name
1548 @item set logging file @var{file}
1549 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1550 @item set logging overwrite [on|off]
1551 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1552 you want @code{set logging on} to overwrite the logfile instead.
1553 @item set logging redirect [on|off]
1554 By default, @value{GDBN} output will go to both the terminal and the logfile.
1555 Set @code{redirect} if you want output to go only to the log file.
1556 @item set logging debugredirect [on|off]
1557 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1558 Set @code{debugredirect} if you want debug output to go only to the log file.
1559 @kindex show logging
1560 @item show logging
1561 Show the current values of the logging settings.
1562 @end table
1563
1564 You can also redirect the output of a @value{GDBN} command to a
1565 shell command. @xref{pipe}.
1566 @node Commands
1567 @chapter @value{GDBN} Commands
1568
1569 You can abbreviate a @value{GDBN} command to the first few letters of the command
1570 name, if that abbreviation is unambiguous; and you can repeat certain
1571 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1572 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1573 show you the alternatives available, if there is more than one possibility).
1574
1575 @menu
1576 * Command Syntax:: How to give commands to @value{GDBN}
1577 * Command Settings:: How to change default behavior of commands
1578 * Completion:: Command completion
1579 * Command Options:: Command options
1580 * Help:: How to ask @value{GDBN} for help
1581 @end menu
1582
1583 @node Command Syntax
1584 @section Command Syntax
1585
1586 A @value{GDBN} command is a single line of input. There is no limit on
1587 how long it can be. It starts with a command name, which is followed by
1588 arguments whose meaning depends on the command name. For example, the
1589 command @code{step} accepts an argument which is the number of times to
1590 step, as in @samp{step 5}. You can also use the @code{step} command
1591 with no arguments. Some commands do not allow any arguments.
1592
1593 @cindex abbreviation
1594 @value{GDBN} command names may always be truncated if that abbreviation is
1595 unambiguous. Other possible command abbreviations are listed in the
1596 documentation for individual commands. In some cases, even ambiguous
1597 abbreviations are allowed; for example, @code{s} is specially defined as
1598 equivalent to @code{step} even though there are other commands whose
1599 names start with @code{s}. You can test abbreviations by using them as
1600 arguments to the @code{help} command.
1601
1602 @cindex repeating commands
1603 @kindex RET @r{(repeat last command)}
1604 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1605 repeat the previous command. Certain commands (for example, @code{run})
1606 will not repeat this way; these are commands whose unintentional
1607 repetition might cause trouble and which you are unlikely to want to
1608 repeat. User-defined commands can disable this feature; see
1609 @ref{Define, dont-repeat}.
1610
1611 The @code{list} and @code{x} commands, when you repeat them with
1612 @key{RET}, construct new arguments rather than repeating
1613 exactly as typed. This permits easy scanning of source or memory.
1614
1615 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1616 output, in a way similar to the common utility @code{more}
1617 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1618 @key{RET} too many in this situation, @value{GDBN} disables command
1619 repetition after any command that generates this sort of display.
1620
1621 @kindex # @r{(a comment)}
1622 @cindex comment
1623 Any text from a @kbd{#} to the end of the line is a comment; it does
1624 nothing. This is useful mainly in command files (@pxref{Command
1625 Files,,Command Files}).
1626
1627 @cindex repeating command sequences
1628 @kindex Ctrl-o @r{(operate-and-get-next)}
1629 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1630 commands. This command accepts the current line, like @key{RET}, and
1631 then fetches the next line relative to the current line from the history
1632 for editing.
1633
1634
1635 @node Command Settings
1636 @section Command Settings
1637 @cindex default behavior of commands, changing
1638 @cindex default settings, changing
1639
1640 Many commands change their behavior according to command-specific
1641 variables or settings. These settings can be changed with the
1642 @code{set} subcommands. For example, the @code{print} command
1643 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1644 settings changeable with the commands @code{set print elements
1645 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1646
1647 You can change these settings to your preference in the gdbinit files
1648 loaded at @value{GDBN} startup. @xref{Startup}.
1649
1650 The settings can also be changed interactively during the debugging
1651 session. For example, to change the limit of array elements to print,
1652 you can do the following:
1653 @smallexample
1654 (@value{GDBN}) set print elements 10
1655 (@value{GDBN}) print some_array
1656 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1657 @end smallexample
1658
1659 The above @code{set print elements 10} command changes the number of
1660 elements to print from the default of 200 to 10. If you only intend
1661 this limit of 10 to be used for printing @code{some_array}, then you
1662 must restore the limit back to 200, with @code{set print elements
1663 200}.
1664
1665 Some commands allow overriding settings with command options. For
1666 example, the @code{print} command supports a number of options that
1667 allow overriding relevant global print settings as set by @code{set
1668 print} subcommands. @xref{print options}. The example above could be
1669 rewritten as:
1670 @smallexample
1671 (@value{GDBN}) print -elements 10 -- some_array
1672 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1673 @end smallexample
1674
1675 Alternatively, you can use the @code{with} command to change a setting
1676 temporarily, for the duration of a command invocation.
1677
1678 @table @code
1679 @kindex with command
1680 @kindex w @r{(@code{with})}
1681 @cindex settings
1682 @cindex temporarily change settings
1683 @item with @var{setting} [@var{value}] [-- @var{command}]
1684 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1685 Temporarily set @var{setting} to @var{value} for the duration of
1686 @var{command}.
1687
1688 @var{setting} is any setting you can change with the @code{set}
1689 subcommands. @var{value} is the value to assign to @code{setting}
1690 while running @code{command}.
1691
1692 If no @var{command} is provided, the last command executed is
1693 repeated.
1694
1695 If a @var{command} is provided, it must be preceded by a double dash
1696 (@code{--}) separator. This is required because some settings accept
1697 free-form arguments, such as expressions or filenames.
1698
1699 For example, the command
1700 @smallexample
1701 (@value{GDBN}) with print array on -- print some_array
1702 @end smallexample
1703 @noindent
1704 is equivalent to the following 3 commands:
1705 @smallexample
1706 (@value{GDBN}) set print array on
1707 (@value{GDBN}) print some_array
1708 (@value{GDBN}) set print array off
1709 @end smallexample
1710
1711 The @code{with} command is particularly useful when you want to
1712 override a setting while running user-defined commands, or commands
1713 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1714
1715 @smallexample
1716 (@value{GDBN}) with print pretty on -- my_complex_command
1717 @end smallexample
1718
1719 To change several settings for the same command, you can nest
1720 @code{with} commands. For example, @code{with language ada -- with
1721 print elements 10} temporarily changes the language to Ada and sets a
1722 limit of 10 elements to print for arrays and strings.
1723
1724 @end table
1725
1726 @node Completion
1727 @section Command Completion
1728
1729 @cindex completion
1730 @cindex word completion
1731 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1732 only one possibility; it can also show you what the valid possibilities
1733 are for the next word in a command, at any time. This works for @value{GDBN}
1734 commands, @value{GDBN} subcommands, command options, and the names of symbols
1735 in your program.
1736
1737 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1738 of a word. If there is only one possibility, @value{GDBN} fills in the
1739 word, and waits for you to finish the command (or press @key{RET} to
1740 enter it). For example, if you type
1741
1742 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1743 @c complete accuracy in these examples; space introduced for clarity.
1744 @c If texinfo enhancements make it unnecessary, it would be nice to
1745 @c replace " @key" by "@key" in the following...
1746 @smallexample
1747 (@value{GDBP}) info bre @key{TAB}
1748 @end smallexample
1749
1750 @noindent
1751 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1752 the only @code{info} subcommand beginning with @samp{bre}:
1753
1754 @smallexample
1755 (@value{GDBP}) info breakpoints
1756 @end smallexample
1757
1758 @noindent
1759 You can either press @key{RET} at this point, to run the @code{info
1760 breakpoints} command, or backspace and enter something else, if
1761 @samp{breakpoints} does not look like the command you expected. (If you
1762 were sure you wanted @code{info breakpoints} in the first place, you
1763 might as well just type @key{RET} immediately after @samp{info bre},
1764 to exploit command abbreviations rather than command completion).
1765
1766 If there is more than one possibility for the next word when you press
1767 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1768 characters and try again, or just press @key{TAB} a second time;
1769 @value{GDBN} displays all the possible completions for that word. For
1770 example, you might want to set a breakpoint on a subroutine whose name
1771 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1772 just sounds the bell. Typing @key{TAB} again displays all the
1773 function names in your program that begin with those characters, for
1774 example:
1775
1776 @smallexample
1777 (@value{GDBP}) b make_ @key{TAB}
1778 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1779 make_a_section_from_file make_environ
1780 make_abs_section make_function_type
1781 make_blockvector make_pointer_type
1782 make_cleanup make_reference_type
1783 make_command make_symbol_completion_list
1784 (@value{GDBP}) b make_
1785 @end smallexample
1786
1787 @noindent
1788 After displaying the available possibilities, @value{GDBN} copies your
1789 partial input (@samp{b make_} in the example) so you can finish the
1790 command.
1791
1792 If you just want to see the list of alternatives in the first place, you
1793 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1794 means @kbd{@key{META} ?}. You can type this either by holding down a
1795 key designated as the @key{META} shift on your keyboard (if there is
1796 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1797
1798 If the number of possible completions is large, @value{GDBN} will
1799 print as much of the list as it has collected, as well as a message
1800 indicating that the list may be truncated.
1801
1802 @smallexample
1803 (@value{GDBP}) b m@key{TAB}@key{TAB}
1804 main
1805 <... the rest of the possible completions ...>
1806 *** List may be truncated, max-completions reached. ***
1807 (@value{GDBP}) b m
1808 @end smallexample
1809
1810 @noindent
1811 This behavior can be controlled with the following commands:
1812
1813 @table @code
1814 @kindex set max-completions
1815 @item set max-completions @var{limit}
1816 @itemx set max-completions unlimited
1817 Set the maximum number of completion candidates. @value{GDBN} will
1818 stop looking for more completions once it collects this many candidates.
1819 This is useful when completing on things like function names as collecting
1820 all the possible candidates can be time consuming.
1821 The default value is 200. A value of zero disables tab-completion.
1822 Note that setting either no limit or a very large limit can make
1823 completion slow.
1824 @kindex show max-completions
1825 @item show max-completions
1826 Show the maximum number of candidates that @value{GDBN} will collect and show
1827 during completion.
1828 @end table
1829
1830 @cindex quotes in commands
1831 @cindex completion of quoted strings
1832 Sometimes the string you need, while logically a ``word'', may contain
1833 parentheses or other characters that @value{GDBN} normally excludes from
1834 its notion of a word. To permit word completion to work in this
1835 situation, you may enclose words in @code{'} (single quote marks) in
1836 @value{GDBN} commands.
1837
1838 A likely situation where you might need this is in typing an
1839 expression that involves a C@t{++} symbol name with template
1840 parameters. This is because when completing expressions, GDB treats
1841 the @samp{<} character as word delimiter, assuming that it's the
1842 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1843 Operators}).
1844
1845 For example, when you want to call a C@t{++} template function
1846 interactively using the @code{print} or @code{call} commands, you may
1847 need to distinguish whether you mean the version of @code{name} that
1848 was specialized for @code{int}, @code{name<int>()}, or the version
1849 that was specialized for @code{float}, @code{name<float>()}. To use
1850 the word-completion facilities in this situation, type a single quote
1851 @code{'} at the beginning of the function name. This alerts
1852 @value{GDBN} that it may need to consider more information than usual
1853 when you press @key{TAB} or @kbd{M-?} to request word completion:
1854
1855 @smallexample
1856 (@value{GDBP}) p 'func< @kbd{M-?}
1857 func<int>() func<float>()
1858 (@value{GDBP}) p 'func<
1859 @end smallexample
1860
1861 When setting breakpoints however (@pxref{Specify Location}), you don't
1862 usually need to type a quote before the function name, because
1863 @value{GDBN} understands that you want to set a breakpoint on a
1864 function:
1865
1866 @smallexample
1867 (@value{GDBP}) b func< @kbd{M-?}
1868 func<int>() func<float>()
1869 (@value{GDBP}) b func<
1870 @end smallexample
1871
1872 This is true even in the case of typing the name of C@t{++} overloaded
1873 functions (multiple definitions of the same function, distinguished by
1874 argument type). For example, when you want to set a breakpoint you
1875 don't need to distinguish whether you mean the version of @code{name}
1876 that takes an @code{int} parameter, @code{name(int)}, or the version
1877 that takes a @code{float} parameter, @code{name(float)}.
1878
1879 @smallexample
1880 (@value{GDBP}) b bubble( @kbd{M-?}
1881 bubble(int) bubble(double)
1882 (@value{GDBP}) b bubble(dou @kbd{M-?}
1883 bubble(double)
1884 @end smallexample
1885
1886 See @ref{quoting names} for a description of other scenarios that
1887 require quoting.
1888
1889 For more information about overloaded functions, see @ref{C Plus Plus
1890 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1891 overload-resolution off} to disable overload resolution;
1892 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1893
1894 @cindex completion of structure field names
1895 @cindex structure field name completion
1896 @cindex completion of union field names
1897 @cindex union field name completion
1898 When completing in an expression which looks up a field in a
1899 structure, @value{GDBN} also tries@footnote{The completer can be
1900 confused by certain kinds of invalid expressions. Also, it only
1901 examines the static type of the expression, not the dynamic type.} to
1902 limit completions to the field names available in the type of the
1903 left-hand-side:
1904
1905 @smallexample
1906 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1907 magic to_fputs to_rewind
1908 to_data to_isatty to_write
1909 to_delete to_put to_write_async_safe
1910 to_flush to_read
1911 @end smallexample
1912
1913 @noindent
1914 This is because the @code{gdb_stdout} is a variable of the type
1915 @code{struct ui_file} that is defined in @value{GDBN} sources as
1916 follows:
1917
1918 @smallexample
1919 struct ui_file
1920 @{
1921 int *magic;
1922 ui_file_flush_ftype *to_flush;
1923 ui_file_write_ftype *to_write;
1924 ui_file_write_async_safe_ftype *to_write_async_safe;
1925 ui_file_fputs_ftype *to_fputs;
1926 ui_file_read_ftype *to_read;
1927 ui_file_delete_ftype *to_delete;
1928 ui_file_isatty_ftype *to_isatty;
1929 ui_file_rewind_ftype *to_rewind;
1930 ui_file_put_ftype *to_put;
1931 void *to_data;
1932 @}
1933 @end smallexample
1934
1935 @node Command Options
1936 @section Command options
1937
1938 @cindex command options
1939 Some commands accept options starting with a leading dash. For
1940 example, @code{print -pretty}. Similarly to command names, you can
1941 abbreviate a @value{GDBN} option to the first few letters of the
1942 option name, if that abbreviation is unambiguous, and you can also use
1943 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1944 in an option (or to show you the alternatives available, if there is
1945 more than one possibility).
1946
1947 @cindex command options, raw input
1948 Some commands take raw input as argument. For example, the print
1949 command processes arbitrary expressions in any of the languages
1950 supported by @value{GDBN}. With such commands, because raw input may
1951 start with a leading dash that would be confused with an option or any
1952 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1953 -pretty} or printing negative @code{p}?), if you specify any command
1954 option, then you must use a double-dash (@code{--}) delimiter to
1955 indicate the end of options.
1956
1957 @cindex command options, boolean
1958
1959 Some options are described as accepting an argument which can be
1960 either @code{on} or @code{off}. These are known as @dfn{boolean
1961 options}. Similarly to boolean settings commands---@code{on} and
1962 @code{off} are the typical values, but any of @code{1}, @code{yes} and
1963 @code{enable} can also be used as ``true'' value, and any of @code{0},
1964 @code{no} and @code{disable} can also be used as ``false'' value. You
1965 can also omit a ``true'' value, as it is implied by default.
1966
1967 For example, these are equivalent:
1968
1969 @smallexample
1970 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1971 (@value{GDBP}) p -o -p 0 -e u -- *myptr
1972 @end smallexample
1973
1974 You can discover the set of options some command accepts by completing
1975 on @code{-} after the command name. For example:
1976
1977 @smallexample
1978 (@value{GDBP}) print -@key{TAB}@key{TAB}
1979 -address -max-depth -raw-values -union
1980 -array -null-stop -repeats -vtbl
1981 -array-indexes -object -static-members
1982 -elements -pretty -symbol
1983 @end smallexample
1984
1985 Completion will in some cases guide you with a suggestion of what kind
1986 of argument an option expects. For example:
1987
1988 @smallexample
1989 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
1990 NUMBER unlimited
1991 @end smallexample
1992
1993 Here, the option expects a number (e.g., @code{100}), not literal
1994 @code{NUMBER}. Such metasyntactical arguments are always presented in
1995 uppercase.
1996
1997 (For more on using the @code{print} command, see @ref{Data, ,Examining
1998 Data}.)
1999
2000 @node Help
2001 @section Getting Help
2002 @cindex online documentation
2003 @kindex help
2004
2005 You can always ask @value{GDBN} itself for information on its commands,
2006 using the command @code{help}.
2007
2008 @table @code
2009 @kindex h @r{(@code{help})}
2010 @item help
2011 @itemx h
2012 You can use @code{help} (abbreviated @code{h}) with no arguments to
2013 display a short list of named classes of commands:
2014
2015 @smallexample
2016 (@value{GDBP}) help
2017 List of classes of commands:
2018
2019 aliases -- Aliases of other commands
2020 breakpoints -- Making program stop at certain points
2021 data -- Examining data
2022 files -- Specifying and examining files
2023 internals -- Maintenance commands
2024 obscure -- Obscure features
2025 running -- Running the program
2026 stack -- Examining the stack
2027 status -- Status inquiries
2028 support -- Support facilities
2029 tracepoints -- Tracing of program execution without
2030 stopping the program
2031 user-defined -- User-defined commands
2032
2033 Type "help" followed by a class name for a list of
2034 commands in that class.
2035 Type "help" followed by command name for full
2036 documentation.
2037 Command name abbreviations are allowed if unambiguous.
2038 (@value{GDBP})
2039 @end smallexample
2040 @c the above line break eliminates huge line overfull...
2041
2042 @item help @var{class}
2043 Using one of the general help classes as an argument, you can get a
2044 list of the individual commands in that class. If a command has
2045 aliases, the aliases are given after the command name, separated by
2046 commas. For example, here is the help display for the class
2047 @code{status}:
2048
2049 @smallexample
2050 (@value{GDBP}) help status
2051 Status inquiries.
2052
2053 List of commands:
2054
2055 @c Line break in "show" line falsifies real output, but needed
2056 @c to fit in smallbook page size.
2057 info, inf, i -- Generic command for showing things
2058 about the program being debugged
2059 info address -- Describe where symbol SYM is stored.
2060 ...
2061 show, info set -- Generic command for showing things
2062 about the debugger
2063
2064 Type "help" followed by command name for full
2065 documentation.
2066 Command name abbreviations are allowed if unambiguous.
2067 (@value{GDBP})
2068 @end smallexample
2069
2070 @item help @var{command}
2071 With a command name as @code{help} argument, @value{GDBN} displays a
2072 short paragraph on how to use that command. If that command has
2073 one or more aliases, @value{GDBN} will display a first line with
2074 the command name and all its aliases separated by commas.
2075
2076 @kindex apropos
2077 @item apropos [-v] @var{regexp}
2078 The @code{apropos} command searches through all of the @value{GDBN}
2079 commands, and their documentation, for the regular expression specified in
2080 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2081 which stands for @samp{verbose}, indicates to output the full documentation
2082 of the matching commands and highlight the parts of the documentation
2083 matching @var{regexp}. For example:
2084
2085 @smallexample
2086 apropos alias
2087 @end smallexample
2088
2089 @noindent
2090 results in:
2091
2092 @smallexample
2093 @group
2094 alias -- Define a new command that is an alias of an existing command
2095 aliases -- Aliases of other commands
2096 @end group
2097 @end smallexample
2098
2099 @noindent
2100 while
2101
2102 @smallexample
2103 apropos -v cut.*thread apply
2104 @end smallexample
2105
2106 @noindent
2107 results in the below output, where @samp{cut for 'thread apply}
2108 is highlighted if styling is enabled.
2109
2110 @smallexample
2111 @group
2112 taas -- Apply a command to all threads (ignoring errors
2113 and empty output).
2114 Usage: taas COMMAND
2115 shortcut for 'thread apply all -s COMMAND'
2116
2117 tfaas -- Apply a command to all frames of all threads
2118 (ignoring errors and empty output).
2119 Usage: tfaas COMMAND
2120 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2121 @end group
2122 @end smallexample
2123
2124 @kindex complete
2125 @item complete @var{args}
2126 The @code{complete @var{args}} command lists all the possible completions
2127 for the beginning of a command. Use @var{args} to specify the beginning of the
2128 command you want completed. For example:
2129
2130 @smallexample
2131 complete i
2132 @end smallexample
2133
2134 @noindent results in:
2135
2136 @smallexample
2137 @group
2138 if
2139 ignore
2140 info
2141 inspect
2142 @end group
2143 @end smallexample
2144
2145 @noindent This is intended for use by @sc{gnu} Emacs.
2146 @end table
2147
2148 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2149 and @code{show} to inquire about the state of your program, or the state
2150 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2151 manual introduces each of them in the appropriate context. The listings
2152 under @code{info} and under @code{show} in the Command, Variable, and
2153 Function Index point to all the sub-commands. @xref{Command and Variable
2154 Index}.
2155
2156 @c @group
2157 @table @code
2158 @kindex info
2159 @kindex i @r{(@code{info})}
2160 @item info
2161 This command (abbreviated @code{i}) is for describing the state of your
2162 program. For example, you can show the arguments passed to a function
2163 with @code{info args}, list the registers currently in use with @code{info
2164 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2165 You can get a complete list of the @code{info} sub-commands with
2166 @w{@code{help info}}.
2167
2168 @kindex set
2169 @item set
2170 You can assign the result of an expression to an environment variable with
2171 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2172 @code{set prompt $}.
2173
2174 @kindex show
2175 @item show
2176 In contrast to @code{info}, @code{show} is for describing the state of
2177 @value{GDBN} itself.
2178 You can change most of the things you can @code{show}, by using the
2179 related command @code{set}; for example, you can control what number
2180 system is used for displays with @code{set radix}, or simply inquire
2181 which is currently in use with @code{show radix}.
2182
2183 @kindex info set
2184 To display all the settable parameters and their current
2185 values, you can use @code{show} with no arguments; you may also use
2186 @code{info set}. Both commands produce the same display.
2187 @c FIXME: "info set" violates the rule that "info" is for state of
2188 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2189 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2190 @end table
2191 @c @end group
2192
2193 Here are several miscellaneous @code{show} subcommands, all of which are
2194 exceptional in lacking corresponding @code{set} commands:
2195
2196 @table @code
2197 @kindex show version
2198 @cindex @value{GDBN} version number
2199 @item show version
2200 Show what version of @value{GDBN} is running. You should include this
2201 information in @value{GDBN} bug-reports. If multiple versions of
2202 @value{GDBN} are in use at your site, you may need to determine which
2203 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2204 commands are introduced, and old ones may wither away. Also, many
2205 system vendors ship variant versions of @value{GDBN}, and there are
2206 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2207 The version number is the same as the one announced when you start
2208 @value{GDBN}.
2209
2210 @kindex show copying
2211 @kindex info copying
2212 @cindex display @value{GDBN} copyright
2213 @item show copying
2214 @itemx info copying
2215 Display information about permission for copying @value{GDBN}.
2216
2217 @kindex show warranty
2218 @kindex info warranty
2219 @item show warranty
2220 @itemx info warranty
2221 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2222 if your version of @value{GDBN} comes with one.
2223
2224 @kindex show configuration
2225 @item show configuration
2226 Display detailed information about the way @value{GDBN} was configured
2227 when it was built. This displays the optional arguments passed to the
2228 @file{configure} script and also configuration parameters detected
2229 automatically by @command{configure}. When reporting a @value{GDBN}
2230 bug (@pxref{GDB Bugs}), it is important to include this information in
2231 your report.
2232
2233 @end table
2234
2235 @node Running
2236 @chapter Running Programs Under @value{GDBN}
2237
2238 When you run a program under @value{GDBN}, you must first generate
2239 debugging information when you compile it.
2240
2241 You may start @value{GDBN} with its arguments, if any, in an environment
2242 of your choice. If you are doing native debugging, you may redirect
2243 your program's input and output, debug an already running process, or
2244 kill a child process.
2245
2246 @menu
2247 * Compilation:: Compiling for debugging
2248 * Starting:: Starting your program
2249 * Arguments:: Your program's arguments
2250 * Environment:: Your program's environment
2251
2252 * Working Directory:: Your program's working directory
2253 * Input/Output:: Your program's input and output
2254 * Attach:: Debugging an already-running process
2255 * Kill Process:: Killing the child process
2256 * Inferiors Connections and Programs:: Debugging multiple inferiors
2257 connections and programs
2258 * Threads:: Debugging programs with multiple threads
2259 * Forks:: Debugging forks
2260 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2261 @end menu
2262
2263 @node Compilation
2264 @section Compiling for Debugging
2265
2266 In order to debug a program effectively, you need to generate
2267 debugging information when you compile it. This debugging information
2268 is stored in the object file; it describes the data type of each
2269 variable or function and the correspondence between source line numbers
2270 and addresses in the executable code.
2271
2272 To request debugging information, specify the @samp{-g} option when you run
2273 the compiler.
2274
2275 Programs that are to be shipped to your customers are compiled with
2276 optimizations, using the @samp{-O} compiler option. However, some
2277 compilers are unable to handle the @samp{-g} and @samp{-O} options
2278 together. Using those compilers, you cannot generate optimized
2279 executables containing debugging information.
2280
2281 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2282 without @samp{-O}, making it possible to debug optimized code. We
2283 recommend that you @emph{always} use @samp{-g} whenever you compile a
2284 program. You may think your program is correct, but there is no sense
2285 in pushing your luck. For more information, see @ref{Optimized Code}.
2286
2287 Older versions of the @sc{gnu} C compiler permitted a variant option
2288 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2289 format; if your @sc{gnu} C compiler has this option, do not use it.
2290
2291 @value{GDBN} knows about preprocessor macros and can show you their
2292 expansion (@pxref{Macros}). Most compilers do not include information
2293 about preprocessor macros in the debugging information if you specify
2294 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2295 the @sc{gnu} C compiler, provides macro information if you are using
2296 the DWARF debugging format, and specify the option @option{-g3}.
2297
2298 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2299 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2300 information on @value{NGCC} options affecting debug information.
2301
2302 You will have the best debugging experience if you use the latest
2303 version of the DWARF debugging format that your compiler supports.
2304 DWARF is currently the most expressive and best supported debugging
2305 format in @value{GDBN}.
2306
2307 @need 2000
2308 @node Starting
2309 @section Starting your Program
2310 @cindex starting
2311 @cindex running
2312
2313 @table @code
2314 @kindex run
2315 @kindex r @r{(@code{run})}
2316 @item run
2317 @itemx r
2318 Use the @code{run} command to start your program under @value{GDBN}.
2319 You must first specify the program name with an argument to
2320 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2321 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2322 command (@pxref{Files, ,Commands to Specify Files}).
2323
2324 @end table
2325
2326 If you are running your program in an execution environment that
2327 supports processes, @code{run} creates an inferior process and makes
2328 that process run your program. In some environments without processes,
2329 @code{run} jumps to the start of your program. Other targets,
2330 like @samp{remote}, are always running. If you get an error
2331 message like this one:
2332
2333 @smallexample
2334 The "remote" target does not support "run".
2335 Try "help target" or "continue".
2336 @end smallexample
2337
2338 @noindent
2339 then use @code{continue} to run your program. You may need @code{load}
2340 first (@pxref{load}).
2341
2342 The execution of a program is affected by certain information it
2343 receives from its superior. @value{GDBN} provides ways to specify this
2344 information, which you must do @emph{before} starting your program. (You
2345 can change it after starting your program, but such changes only affect
2346 your program the next time you start it.) This information may be
2347 divided into four categories:
2348
2349 @table @asis
2350 @item The @emph{arguments.}
2351 Specify the arguments to give your program as the arguments of the
2352 @code{run} command. If a shell is available on your target, the shell
2353 is used to pass the arguments, so that you may use normal conventions
2354 (such as wildcard expansion or variable substitution) in describing
2355 the arguments.
2356 In Unix systems, you can control which shell is used with the
2357 @code{SHELL} environment variable. If you do not define @code{SHELL},
2358 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2359 use of any shell with the @code{set startup-with-shell} command (see
2360 below for details).
2361
2362 @item The @emph{environment.}
2363 Your program normally inherits its environment from @value{GDBN}, but you can
2364 use the @value{GDBN} commands @code{set environment} and @code{unset
2365 environment} to change parts of the environment that affect
2366 your program. @xref{Environment, ,Your Program's Environment}.
2367
2368 @item The @emph{working directory.}
2369 You can set your program's working directory with the command
2370 @kbd{set cwd}. If you do not set any working directory with this
2371 command, your program will inherit @value{GDBN}'s working directory if
2372 native debugging, or the remote server's working directory if remote
2373 debugging. @xref{Working Directory, ,Your Program's Working
2374 Directory}.
2375
2376 @item The @emph{standard input and output.}
2377 Your program normally uses the same device for standard input and
2378 standard output as @value{GDBN} is using. You can redirect input and output
2379 in the @code{run} command line, or you can use the @code{tty} command to
2380 set a different device for your program.
2381 @xref{Input/Output, ,Your Program's Input and Output}.
2382
2383 @cindex pipes
2384 @emph{Warning:} While input and output redirection work, you cannot use
2385 pipes to pass the output of the program you are debugging to another
2386 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2387 wrong program.
2388 @end table
2389
2390 When you issue the @code{run} command, your program begins to execute
2391 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2392 of how to arrange for your program to stop. Once your program has
2393 stopped, you may call functions in your program, using the @code{print}
2394 or @code{call} commands. @xref{Data, ,Examining Data}.
2395
2396 If the modification time of your symbol file has changed since the last
2397 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2398 table, and reads it again. When it does this, @value{GDBN} tries to retain
2399 your current breakpoints.
2400
2401 @table @code
2402 @kindex start
2403 @item start
2404 @cindex run to main procedure
2405 The name of the main procedure can vary from language to language.
2406 With C or C@t{++}, the main procedure name is always @code{main}, but
2407 other languages such as Ada do not require a specific name for their
2408 main procedure. The debugger provides a convenient way to start the
2409 execution of the program and to stop at the beginning of the main
2410 procedure, depending on the language used.
2411
2412 The @samp{start} command does the equivalent of setting a temporary
2413 breakpoint at the beginning of the main procedure and then invoking
2414 the @samp{run} command.
2415
2416 @cindex elaboration phase
2417 Some programs contain an @dfn{elaboration} phase where some startup code is
2418 executed before the main procedure is called. This depends on the
2419 languages used to write your program. In C@t{++}, for instance,
2420 constructors for static and global objects are executed before
2421 @code{main} is called. It is therefore possible that the debugger stops
2422 before reaching the main procedure. However, the temporary breakpoint
2423 will remain to halt execution.
2424
2425 Specify the arguments to give to your program as arguments to the
2426 @samp{start} command. These arguments will be given verbatim to the
2427 underlying @samp{run} command. Note that the same arguments will be
2428 reused if no argument is provided during subsequent calls to
2429 @samp{start} or @samp{run}.
2430
2431 It is sometimes necessary to debug the program during elaboration. In
2432 these cases, using the @code{start} command would stop the execution
2433 of your program too late, as the program would have already completed
2434 the elaboration phase. Under these circumstances, either insert
2435 breakpoints in your elaboration code before running your program or
2436 use the @code{starti} command.
2437
2438 @kindex starti
2439 @item starti
2440 @cindex run to first instruction
2441 The @samp{starti} command does the equivalent of setting a temporary
2442 breakpoint at the first instruction of a program's execution and then
2443 invoking the @samp{run} command. For programs containing an
2444 elaboration phase, the @code{starti} command will stop execution at
2445 the start of the elaboration phase.
2446
2447 @anchor{set exec-wrapper}
2448 @kindex set exec-wrapper
2449 @item set exec-wrapper @var{wrapper}
2450 @itemx show exec-wrapper
2451 @itemx unset exec-wrapper
2452 When @samp{exec-wrapper} is set, the specified wrapper is used to
2453 launch programs for debugging. @value{GDBN} starts your program
2454 with a shell command of the form @kbd{exec @var{wrapper}
2455 @var{program}}. Quoting is added to @var{program} and its
2456 arguments, but not to @var{wrapper}, so you should add quotes if
2457 appropriate for your shell. The wrapper runs until it executes
2458 your program, and then @value{GDBN} takes control.
2459
2460 You can use any program that eventually calls @code{execve} with
2461 its arguments as a wrapper. Several standard Unix utilities do
2462 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2463 with @code{exec "$@@"} will also work.
2464
2465 For example, you can use @code{env} to pass an environment variable to
2466 the debugged program, without setting the variable in your shell's
2467 environment:
2468
2469 @smallexample
2470 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2471 (@value{GDBP}) run
2472 @end smallexample
2473
2474 This command is available when debugging locally on most targets, excluding
2475 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2476
2477 @kindex set startup-with-shell
2478 @anchor{set startup-with-shell}
2479 @item set startup-with-shell
2480 @itemx set startup-with-shell on
2481 @itemx set startup-with-shell off
2482 @itemx show startup-with-shell
2483 On Unix systems, by default, if a shell is available on your target,
2484 @value{GDBN}) uses it to start your program. Arguments of the
2485 @code{run} command are passed to the shell, which does variable
2486 substitution, expands wildcard characters and performs redirection of
2487 I/O. In some circumstances, it may be useful to disable such use of a
2488 shell, for example, when debugging the shell itself or diagnosing
2489 startup failures such as:
2490
2491 @smallexample
2492 (@value{GDBP}) run
2493 Starting program: ./a.out
2494 During startup program terminated with signal SIGSEGV, Segmentation fault.
2495 @end smallexample
2496
2497 @noindent
2498 which indicates the shell or the wrapper specified with
2499 @samp{exec-wrapper} crashed, not your program. Most often, this is
2500 caused by something odd in your shell's non-interactive mode
2501 initialization file---such as @file{.cshrc} for C-shell,
2502 $@file{.zshenv} for the Z shell, or the file specified in the
2503 @samp{BASH_ENV} environment variable for BASH.
2504
2505 @anchor{set auto-connect-native-target}
2506 @kindex set auto-connect-native-target
2507 @item set auto-connect-native-target
2508 @itemx set auto-connect-native-target on
2509 @itemx set auto-connect-native-target off
2510 @itemx show auto-connect-native-target
2511
2512 By default, if the current inferior is not connected to any target yet
2513 (e.g., with @code{target remote}), the @code{run} command starts your
2514 program as a native process under @value{GDBN}, on your local machine.
2515 If you're sure you don't want to debug programs on your local machine,
2516 you can tell @value{GDBN} to not connect to the native target
2517 automatically with the @code{set auto-connect-native-target off}
2518 command.
2519
2520 If @code{on}, which is the default, and if the current inferior is not
2521 connected to a target already, the @code{run} command automaticaly
2522 connects to the native target, if one is available.
2523
2524 If @code{off}, and if the current inferior is not connected to a
2525 target already, the @code{run} command fails with an error:
2526
2527 @smallexample
2528 (@value{GDBP}) run
2529 Don't know how to run. Try "help target".
2530 @end smallexample
2531
2532 If the current inferior is already connected to a target, @value{GDBN}
2533 always uses it with the @code{run} command.
2534
2535 In any case, you can explicitly connect to the native target with the
2536 @code{target native} command. For example,
2537
2538 @smallexample
2539 (@value{GDBP}) set auto-connect-native-target off
2540 (@value{GDBP}) run
2541 Don't know how to run. Try "help target".
2542 (@value{GDBP}) target native
2543 (@value{GDBP}) run
2544 Starting program: ./a.out
2545 [Inferior 1 (process 10421) exited normally]
2546 @end smallexample
2547
2548 In case you connected explicitly to the @code{native} target,
2549 @value{GDBN} remains connected even if all inferiors exit, ready for
2550 the next @code{run} command. Use the @code{disconnect} command to
2551 disconnect.
2552
2553 Examples of other commands that likewise respect the
2554 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2555 proc}, @code{info os}.
2556
2557 @kindex set disable-randomization
2558 @item set disable-randomization
2559 @itemx set disable-randomization on
2560 This option (enabled by default in @value{GDBN}) will turn off the native
2561 randomization of the virtual address space of the started program. This option
2562 is useful for multiple debugging sessions to make the execution better
2563 reproducible and memory addresses reusable across debugging sessions.
2564
2565 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2566 On @sc{gnu}/Linux you can get the same behavior using
2567
2568 @smallexample
2569 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2570 @end smallexample
2571
2572 @item set disable-randomization off
2573 Leave the behavior of the started executable unchanged. Some bugs rear their
2574 ugly heads only when the program is loaded at certain addresses. If your bug
2575 disappears when you run the program under @value{GDBN}, that might be because
2576 @value{GDBN} by default disables the address randomization on platforms, such
2577 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2578 disable-randomization off} to try to reproduce such elusive bugs.
2579
2580 On targets where it is available, virtual address space randomization
2581 protects the programs against certain kinds of security attacks. In these
2582 cases the attacker needs to know the exact location of a concrete executable
2583 code. Randomizing its location makes it impossible to inject jumps misusing
2584 a code at its expected addresses.
2585
2586 Prelinking shared libraries provides a startup performance advantage but it
2587 makes addresses in these libraries predictable for privileged processes by
2588 having just unprivileged access at the target system. Reading the shared
2589 library binary gives enough information for assembling the malicious code
2590 misusing it. Still even a prelinked shared library can get loaded at a new
2591 random address just requiring the regular relocation process during the
2592 startup. Shared libraries not already prelinked are always loaded at
2593 a randomly chosen address.
2594
2595 Position independent executables (PIE) contain position independent code
2596 similar to the shared libraries and therefore such executables get loaded at
2597 a randomly chosen address upon startup. PIE executables always load even
2598 already prelinked shared libraries at a random address. You can build such
2599 executable using @command{gcc -fPIE -pie}.
2600
2601 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2602 (as long as the randomization is enabled).
2603
2604 @item show disable-randomization
2605 Show the current setting of the explicit disable of the native randomization of
2606 the virtual address space of the started program.
2607
2608 @end table
2609
2610 @node Arguments
2611 @section Your Program's Arguments
2612
2613 @cindex arguments (to your program)
2614 The arguments to your program can be specified by the arguments of the
2615 @code{run} command.
2616 They are passed to a shell, which expands wildcard characters and
2617 performs redirection of I/O, and thence to your program. Your
2618 @code{SHELL} environment variable (if it exists) specifies what shell
2619 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2620 the default shell (@file{/bin/sh} on Unix).
2621
2622 On non-Unix systems, the program is usually invoked directly by
2623 @value{GDBN}, which emulates I/O redirection via the appropriate system
2624 calls, and the wildcard characters are expanded by the startup code of
2625 the program, not by the shell.
2626
2627 @code{run} with no arguments uses the same arguments used by the previous
2628 @code{run}, or those set by the @code{set args} command.
2629
2630 @table @code
2631 @kindex set args
2632 @item set args
2633 Specify the arguments to be used the next time your program is run. If
2634 @code{set args} has no arguments, @code{run} executes your program
2635 with no arguments. Once you have run your program with arguments,
2636 using @code{set args} before the next @code{run} is the only way to run
2637 it again without arguments.
2638
2639 @kindex show args
2640 @item show args
2641 Show the arguments to give your program when it is started.
2642 @end table
2643
2644 @node Environment
2645 @section Your Program's Environment
2646
2647 @cindex environment (of your program)
2648 The @dfn{environment} consists of a set of environment variables and
2649 their values. Environment variables conventionally record such things as
2650 your user name, your home directory, your terminal type, and your search
2651 path for programs to run. Usually you set up environment variables with
2652 the shell and they are inherited by all the other programs you run. When
2653 debugging, it can be useful to try running your program with a modified
2654 environment without having to start @value{GDBN} over again.
2655
2656 @table @code
2657 @kindex path
2658 @item path @var{directory}
2659 Add @var{directory} to the front of the @code{PATH} environment variable
2660 (the search path for executables) that will be passed to your program.
2661 The value of @code{PATH} used by @value{GDBN} does not change.
2662 You may specify several directory names, separated by whitespace or by a
2663 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2664 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2665 is moved to the front, so it is searched sooner.
2666
2667 You can use the string @samp{$cwd} to refer to whatever is the current
2668 working directory at the time @value{GDBN} searches the path. If you
2669 use @samp{.} instead, it refers to the directory where you executed the
2670 @code{path} command. @value{GDBN} replaces @samp{.} in the
2671 @var{directory} argument (with the current path) before adding
2672 @var{directory} to the search path.
2673 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2674 @c document that, since repeating it would be a no-op.
2675
2676 @kindex show paths
2677 @item show paths
2678 Display the list of search paths for executables (the @code{PATH}
2679 environment variable).
2680
2681 @kindex show environment
2682 @item show environment @r{[}@var{varname}@r{]}
2683 Print the value of environment variable @var{varname} to be given to
2684 your program when it starts. If you do not supply @var{varname},
2685 print the names and values of all environment variables to be given to
2686 your program. You can abbreviate @code{environment} as @code{env}.
2687
2688 @kindex set environment
2689 @anchor{set environment}
2690 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2691 Set environment variable @var{varname} to @var{value}. The value
2692 changes for your program (and the shell @value{GDBN} uses to launch
2693 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2694 values of environment variables are just strings, and any
2695 interpretation is supplied by your program itself. The @var{value}
2696 parameter is optional; if it is eliminated, the variable is set to a
2697 null value.
2698 @c "any string" here does not include leading, trailing
2699 @c blanks. Gnu asks: does anyone care?
2700
2701 For example, this command:
2702
2703 @smallexample
2704 set env USER = foo
2705 @end smallexample
2706
2707 @noindent
2708 tells the debugged program, when subsequently run, that its user is named
2709 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2710 are not actually required.)
2711
2712 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2713 which also inherits the environment set with @code{set environment}.
2714 If necessary, you can avoid that by using the @samp{env} program as a
2715 wrapper instead of using @code{set environment}. @xref{set
2716 exec-wrapper}, for an example doing just that.
2717
2718 Environment variables that are set by the user are also transmitted to
2719 @command{gdbserver} to be used when starting the remote inferior.
2720 @pxref{QEnvironmentHexEncoded}.
2721
2722 @kindex unset environment
2723 @anchor{unset environment}
2724 @item unset environment @var{varname}
2725 Remove variable @var{varname} from the environment to be passed to your
2726 program. This is different from @samp{set env @var{varname} =};
2727 @code{unset environment} removes the variable from the environment,
2728 rather than assigning it an empty value.
2729
2730 Environment variables that are unset by the user are also unset on
2731 @command{gdbserver} when starting the remote inferior.
2732 @pxref{QEnvironmentUnset}.
2733 @end table
2734
2735 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2736 the shell indicated by your @code{SHELL} environment variable if it
2737 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2738 names a shell that runs an initialization file when started
2739 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2740 for the Z shell, or the file specified in the @samp{BASH_ENV}
2741 environment variable for BASH---any variables you set in that file
2742 affect your program. You may wish to move setting of environment
2743 variables to files that are only run when you sign on, such as
2744 @file{.login} or @file{.profile}.
2745
2746 @node Working Directory
2747 @section Your Program's Working Directory
2748
2749 @cindex working directory (of your program)
2750 Each time you start your program with @code{run}, the inferior will be
2751 initialized with the current working directory specified by the
2752 @kbd{set cwd} command. If no directory has been specified by this
2753 command, then the inferior will inherit @value{GDBN}'s current working
2754 directory as its working directory if native debugging, or it will
2755 inherit the remote server's current working directory if remote
2756 debugging.
2757
2758 @table @code
2759 @kindex set cwd
2760 @cindex change inferior's working directory
2761 @anchor{set cwd command}
2762 @item set cwd @r{[}@var{directory}@r{]}
2763 Set the inferior's working directory to @var{directory}, which will be
2764 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2765 argument has been specified, the command clears the setting and resets
2766 it to an empty state. This setting has no effect on @value{GDBN}'s
2767 working directory, and it only takes effect the next time you start
2768 the inferior. The @file{~} in @var{directory} is a short for the
2769 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2770 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2771 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2772 fallback.
2773
2774 You can also change @value{GDBN}'s current working directory by using
2775 the @code{cd} command.
2776 @xref{cd command}.
2777
2778 @kindex show cwd
2779 @cindex show inferior's working directory
2780 @item show cwd
2781 Show the inferior's working directory. If no directory has been
2782 specified by @kbd{set cwd}, then the default inferior's working
2783 directory is the same as @value{GDBN}'s working directory.
2784
2785 @kindex cd
2786 @cindex change @value{GDBN}'s working directory
2787 @anchor{cd command}
2788 @item cd @r{[}@var{directory}@r{]}
2789 Set the @value{GDBN} working directory to @var{directory}. If not
2790 given, @var{directory} uses @file{'~'}.
2791
2792 The @value{GDBN} working directory serves as a default for the
2793 commands that specify files for @value{GDBN} to operate on.
2794 @xref{Files, ,Commands to Specify Files}.
2795 @xref{set cwd command}.
2796
2797 @kindex pwd
2798 @item pwd
2799 Print the @value{GDBN} working directory.
2800 @end table
2801
2802 It is generally impossible to find the current working directory of
2803 the process being debugged (since a program can change its directory
2804 during its run). If you work on a system where @value{GDBN} supports
2805 the @code{info proc} command (@pxref{Process Information}), you can
2806 use the @code{info proc} command to find out the
2807 current working directory of the debuggee.
2808
2809 @node Input/Output
2810 @section Your Program's Input and Output
2811
2812 @cindex redirection
2813 @cindex i/o
2814 @cindex terminal
2815 By default, the program you run under @value{GDBN} does input and output to
2816 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2817 to its own terminal modes to interact with you, but it records the terminal
2818 modes your program was using and switches back to them when you continue
2819 running your program.
2820
2821 @table @code
2822 @kindex info terminal
2823 @item info terminal
2824 Displays information recorded by @value{GDBN} about the terminal modes your
2825 program is using.
2826 @end table
2827
2828 You can redirect your program's input and/or output using shell
2829 redirection with the @code{run} command. For example,
2830
2831 @smallexample
2832 run > outfile
2833 @end smallexample
2834
2835 @noindent
2836 starts your program, diverting its output to the file @file{outfile}.
2837
2838 @kindex tty
2839 @cindex controlling terminal
2840 Another way to specify where your program should do input and output is
2841 with the @code{tty} command. This command accepts a file name as
2842 argument, and causes this file to be the default for future @code{run}
2843 commands. It also resets the controlling terminal for the child
2844 process, for future @code{run} commands. For example,
2845
2846 @smallexample
2847 tty /dev/ttyb
2848 @end smallexample
2849
2850 @noindent
2851 directs that processes started with subsequent @code{run} commands
2852 default to do input and output on the terminal @file{/dev/ttyb} and have
2853 that as their controlling terminal.
2854
2855 An explicit redirection in @code{run} overrides the @code{tty} command's
2856 effect on the input/output device, but not its effect on the controlling
2857 terminal.
2858
2859 When you use the @code{tty} command or redirect input in the @code{run}
2860 command, only the input @emph{for your program} is affected. The input
2861 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2862 for @code{set inferior-tty}.
2863
2864 @cindex inferior tty
2865 @cindex set inferior controlling terminal
2866 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2867 display the name of the terminal that will be used for future runs of your
2868 program.
2869
2870 @table @code
2871 @item set inferior-tty [ @var{tty} ]
2872 @kindex set inferior-tty
2873 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2874 restores the default behavior, which is to use the same terminal as
2875 @value{GDBN}.
2876
2877 @item show inferior-tty
2878 @kindex show inferior-tty
2879 Show the current tty for the program being debugged.
2880 @end table
2881
2882 @node Attach
2883 @section Debugging an Already-running Process
2884 @kindex attach
2885 @cindex attach
2886
2887 @table @code
2888 @item attach @var{process-id}
2889 This command attaches to a running process---one that was started
2890 outside @value{GDBN}. (@code{info files} shows your active
2891 targets.) The command takes as argument a process ID. The usual way to
2892 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2893 or with the @samp{jobs -l} shell command.
2894
2895 @code{attach} does not repeat if you press @key{RET} a second time after
2896 executing the command.
2897 @end table
2898
2899 To use @code{attach}, your program must be running in an environment
2900 which supports processes; for example, @code{attach} does not work for
2901 programs on bare-board targets that lack an operating system. You must
2902 also have permission to send the process a signal.
2903
2904 When you use @code{attach}, the debugger finds the program running in
2905 the process first by looking in the current working directory, then (if
2906 the program is not found) by using the source file search path
2907 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2908 the @code{file} command to load the program. @xref{Files, ,Commands to
2909 Specify Files}.
2910
2911 @anchor{set exec-file-mismatch}
2912 If the debugger can determine the name of the executable file running
2913 in the process it is attaching to, and this file name does not match
2914 the name of the current exec-file loaded by @value{GDBN}, the option
2915 @code{exec-file-mismatch} specifies how to handle the mismatch.
2916
2917 @table @code
2918 @kindex exec-file-mismatch
2919 @cindex set exec-file-mismatch
2920 @item set exec-file-mismatch @samp{ask|warn|off}
2921
2922 Whether to detect mismatch between the name of the current executable
2923 file loaded by @value{GDBN} and the name of the executable file used to
2924 start the process. If @samp{ask}, the default, display a warning
2925 and ask the user whether to load the process executable file; if
2926 @samp{warn}, just display a warning; if @samp{off}, don't attempt to
2927 detect a mismatch.
2928
2929 @cindex show exec-file-mismatch
2930 @item show exec-file-mismatch
2931 Show the current value of @code{exec-file-mismatch}.
2932
2933 @end table
2934
2935 The first thing @value{GDBN} does after arranging to debug the specified
2936 process is to stop it. You can examine and modify an attached process
2937 with all the @value{GDBN} commands that are ordinarily available when
2938 you start processes with @code{run}. You can insert breakpoints; you
2939 can step and continue; you can modify storage. If you would rather the
2940 process continue running, you may use the @code{continue} command after
2941 attaching @value{GDBN} to the process.
2942
2943 @table @code
2944 @kindex detach
2945 @item detach
2946 When you have finished debugging the attached process, you can use the
2947 @code{detach} command to release it from @value{GDBN} control. Detaching
2948 the process continues its execution. After the @code{detach} command,
2949 that process and @value{GDBN} become completely independent once more, and you
2950 are ready to @code{attach} another process or start one with @code{run}.
2951 @code{detach} does not repeat if you press @key{RET} again after
2952 executing the command.
2953 @end table
2954
2955 If you exit @value{GDBN} while you have an attached process, you detach
2956 that process. If you use the @code{run} command, you kill that process.
2957 By default, @value{GDBN} asks for confirmation if you try to do either of these
2958 things; you can control whether or not you need to confirm by using the
2959 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2960 Messages}).
2961
2962 @node Kill Process
2963 @section Killing the Child Process
2964
2965 @table @code
2966 @kindex kill
2967 @item kill
2968 Kill the child process in which your program is running under @value{GDBN}.
2969 @end table
2970
2971 This command is useful if you wish to debug a core dump instead of a
2972 running process. @value{GDBN} ignores any core dump file while your program
2973 is running.
2974
2975 On some operating systems, a program cannot be executed outside @value{GDBN}
2976 while you have breakpoints set on it inside @value{GDBN}. You can use the
2977 @code{kill} command in this situation to permit running your program
2978 outside the debugger.
2979
2980 The @code{kill} command is also useful if you wish to recompile and
2981 relink your program, since on many systems it is impossible to modify an
2982 executable file while it is running in a process. In this case, when you
2983 next type @code{run}, @value{GDBN} notices that the file has changed, and
2984 reads the symbol table again (while trying to preserve your current
2985 breakpoint settings).
2986
2987 @node Inferiors Connections and Programs
2988 @section Debugging Multiple Inferiors Connections and Programs
2989
2990 @value{GDBN} lets you run and debug multiple programs in a single
2991 session. In addition, @value{GDBN} on some systems may let you run
2992 several programs simultaneously (otherwise you have to exit from one
2993 before starting another). On some systems @value{GDBN} may even let
2994 you debug several programs simultaneously on different remote systems.
2995 In the most general case, you can have multiple threads of execution
2996 in each of multiple processes, launched from multiple executables,
2997 running on different machines.
2998
2999 @cindex inferior
3000 @value{GDBN} represents the state of each program execution with an
3001 object called an @dfn{inferior}. An inferior typically corresponds to
3002 a process, but is more general and applies also to targets that do not
3003 have processes. Inferiors may be created before a process runs, and
3004 may be retained after a process exits. Inferiors have unique
3005 identifiers that are different from process ids. Usually each
3006 inferior will also have its own distinct address space, although some
3007 embedded targets may have several inferiors running in different parts
3008 of a single address space. Each inferior may in turn have multiple
3009 threads running in it.
3010
3011 To find out what inferiors exist at any moment, use @w{@code{info
3012 inferiors}}:
3013
3014 @table @code
3015 @kindex info inferiors [ @var{id}@dots{} ]
3016 @item info inferiors
3017 Print a list of all inferiors currently being managed by @value{GDBN}.
3018 By default all inferiors are printed, but the argument @var{id}@dots{}
3019 -- a space separated list of inferior numbers -- can be used to limit
3020 the display to just the requested inferiors.
3021
3022 @value{GDBN} displays for each inferior (in this order):
3023
3024 @enumerate
3025 @item
3026 the inferior number assigned by @value{GDBN}
3027
3028 @item
3029 the target system's inferior identifier
3030
3031 @item
3032 the target connection the inferior is bound to, including the unique
3033 connection number assigned by @value{GDBN}, and the protocol used by
3034 the connection.
3035
3036 @item
3037 the name of the executable the inferior is running.
3038
3039 @end enumerate
3040
3041 @noindent
3042 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3043 indicates the current inferior.
3044
3045 For example,
3046 @end table
3047 @c end table here to get a little more width for example
3048
3049 @smallexample
3050 (@value{GDBP}) info inferiors
3051 Num Description Connection Executable
3052 * 1 process 3401 1 (native) goodbye
3053 2 process 2307 2 (extended-remote host:10000) hello
3054 @end smallexample
3055
3056 To find out what open target connections exist at any moment, use
3057 @w{@code{info connections}}:
3058
3059 @table @code
3060 @kindex info connections [ @var{id}@dots{} ]
3061 @item info connections
3062 Print a list of all open target connections currently being managed by
3063 @value{GDBN}. By default all connections are printed, but the
3064 argument @var{id}@dots{} -- a space separated list of connections
3065 numbers -- can be used to limit the display to just the requested
3066 connections.
3067
3068 @value{GDBN} displays for each connection (in this order):
3069
3070 @enumerate
3071 @item
3072 the connection number assigned by @value{GDBN}.
3073
3074 @item
3075 the protocol used by the connection.
3076
3077 @item
3078 a textual description of the protocol used by the connection.
3079
3080 @end enumerate
3081
3082 @noindent
3083 An asterisk @samp{*} preceding the connection number indicates the
3084 connection of the current inferior.
3085
3086 For example,
3087 @end table
3088 @c end table here to get a little more width for example
3089
3090 @smallexample
3091 (@value{GDBP}) info connections
3092 Num What Description
3093 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3094 2 native Native process
3095 3 core Local core dump file
3096 @end smallexample
3097
3098 To switch focus between inferiors, use the @code{inferior} command:
3099
3100 @table @code
3101 @kindex inferior @var{infno}
3102 @item inferior @var{infno}
3103 Make inferior number @var{infno} the current inferior. The argument
3104 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3105 in the first field of the @samp{info inferiors} display.
3106 @end table
3107
3108 @vindex $_inferior@r{, convenience variable}
3109 The debugger convenience variable @samp{$_inferior} contains the
3110 number of the current inferior. You may find this useful in writing
3111 breakpoint conditional expressions, command scripts, and so forth.
3112 @xref{Convenience Vars,, Convenience Variables}, for general
3113 information on convenience variables.
3114
3115 You can get multiple executables into a debugging session via the
3116 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3117 systems @value{GDBN} can add inferiors to the debug session
3118 automatically by following calls to @code{fork} and @code{exec}. To
3119 remove inferiors from the debugging session use the
3120 @w{@code{remove-inferiors}} command.
3121
3122 @table @code
3123 @kindex add-inferior
3124 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3125 Adds @var{n} inferiors to be run using @var{executable} as the
3126 executable; @var{n} defaults to 1. If no executable is specified,
3127 the inferiors begins empty, with no program. You can still assign or
3128 change the program assigned to the inferior at any time by using the
3129 @code{file} command with the executable name as its argument.
3130
3131 By default, the new inferior begins connected to the same target
3132 connection as the current inferior. For example, if the current
3133 inferior was connected to @code{gdbserver} with @code{target remote},
3134 then the new inferior will be connected to the same @code{gdbserver}
3135 instance. The @samp{-no-connection} option starts the new inferior
3136 with no connection yet. You can then for example use the @code{target
3137 remote} command to connect to some other @code{gdbserver} instance,
3138 use @code{run} to spawn a local program, etc.
3139
3140 @kindex clone-inferior
3141 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3142 Adds @var{n} inferiors ready to execute the same program as inferior
3143 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3144 number of the current inferior. This is a convenient command when you
3145 want to run another instance of the inferior you are debugging.
3146
3147 @smallexample
3148 (@value{GDBP}) info inferiors
3149 Num Description Connection Executable
3150 * 1 process 29964 1 (native) helloworld
3151 (@value{GDBP}) clone-inferior
3152 Added inferior 2.
3153 1 inferiors added.
3154 (@value{GDBP}) info inferiors
3155 Num Description Connection Executable
3156 * 1 process 29964 1 (native) helloworld
3157 2 <null> 1 (native) helloworld
3158 @end smallexample
3159
3160 You can now simply switch focus to inferior 2 and run it.
3161
3162 @kindex remove-inferiors
3163 @item remove-inferiors @var{infno}@dots{}
3164 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3165 possible to remove an inferior that is running with this command. For
3166 those, use the @code{kill} or @code{detach} command first.
3167
3168 @end table
3169
3170 To quit debugging one of the running inferiors that is not the current
3171 inferior, you can either detach from it by using the @w{@code{detach
3172 inferior}} command (allowing it to run independently), or kill it
3173 using the @w{@code{kill inferiors}} command:
3174
3175 @table @code
3176 @kindex detach inferiors @var{infno}@dots{}
3177 @item detach inferior @var{infno}@dots{}
3178 Detach from the inferior or inferiors identified by @value{GDBN}
3179 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3180 still stays on the list of inferiors shown by @code{info inferiors},
3181 but its Description will show @samp{<null>}.
3182
3183 @kindex kill inferiors @var{infno}@dots{}
3184 @item kill inferiors @var{infno}@dots{}
3185 Kill the inferior or inferiors identified by @value{GDBN} inferior
3186 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3187 stays on the list of inferiors shown by @code{info inferiors}, but its
3188 Description will show @samp{<null>}.
3189 @end table
3190
3191 After the successful completion of a command such as @code{detach},
3192 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3193 a normal process exit, the inferior is still valid and listed with
3194 @code{info inferiors}, ready to be restarted.
3195
3196
3197 To be notified when inferiors are started or exit under @value{GDBN}'s
3198 control use @w{@code{set print inferior-events}}:
3199
3200 @table @code
3201 @kindex set print inferior-events
3202 @cindex print messages on inferior start and exit
3203 @item set print inferior-events
3204 @itemx set print inferior-events on
3205 @itemx set print inferior-events off
3206 The @code{set print inferior-events} command allows you to enable or
3207 disable printing of messages when @value{GDBN} notices that new
3208 inferiors have started or that inferiors have exited or have been
3209 detached. By default, these messages will not be printed.
3210
3211 @kindex show print inferior-events
3212 @item show print inferior-events
3213 Show whether messages will be printed when @value{GDBN} detects that
3214 inferiors have started, exited or have been detached.
3215 @end table
3216
3217 Many commands will work the same with multiple programs as with a
3218 single program: e.g., @code{print myglobal} will simply display the
3219 value of @code{myglobal} in the current inferior.
3220
3221
3222 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3223 get more info about the relationship of inferiors, programs, address
3224 spaces in a debug session. You can do that with the @w{@code{maint
3225 info program-spaces}} command.
3226
3227 @table @code
3228 @kindex maint info program-spaces
3229 @item maint info program-spaces
3230 Print a list of all program spaces currently being managed by
3231 @value{GDBN}.
3232
3233 @value{GDBN} displays for each program space (in this order):
3234
3235 @enumerate
3236 @item
3237 the program space number assigned by @value{GDBN}
3238
3239 @item
3240 the name of the executable loaded into the program space, with e.g.,
3241 the @code{file} command.
3242
3243 @end enumerate
3244
3245 @noindent
3246 An asterisk @samp{*} preceding the @value{GDBN} program space number
3247 indicates the current program space.
3248
3249 In addition, below each program space line, @value{GDBN} prints extra
3250 information that isn't suitable to display in tabular form. For
3251 example, the list of inferiors bound to the program space.
3252
3253 @smallexample
3254 (@value{GDBP}) maint info program-spaces
3255 Id Executable
3256 * 1 hello
3257 2 goodbye
3258 Bound inferiors: ID 1 (process 21561)
3259 @end smallexample
3260
3261 Here we can see that no inferior is running the program @code{hello},
3262 while @code{process 21561} is running the program @code{goodbye}. On
3263 some targets, it is possible that multiple inferiors are bound to the
3264 same program space. The most common example is that of debugging both
3265 the parent and child processes of a @code{vfork} call. For example,
3266
3267 @smallexample
3268 (@value{GDBP}) maint info program-spaces
3269 Id Executable
3270 * 1 vfork-test
3271 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3272 @end smallexample
3273
3274 Here, both inferior 2 and inferior 1 are running in the same program
3275 space as a result of inferior 1 having executed a @code{vfork} call.
3276 @end table
3277
3278 @node Threads
3279 @section Debugging Programs with Multiple Threads
3280
3281 @cindex threads of execution
3282 @cindex multiple threads
3283 @cindex switching threads
3284 In some operating systems, such as GNU/Linux and Solaris, a single program
3285 may have more than one @dfn{thread} of execution. The precise semantics
3286 of threads differ from one operating system to another, but in general
3287 the threads of a single program are akin to multiple processes---except
3288 that they share one address space (that is, they can all examine and
3289 modify the same variables). On the other hand, each thread has its own
3290 registers and execution stack, and perhaps private memory.
3291
3292 @value{GDBN} provides these facilities for debugging multi-thread
3293 programs:
3294
3295 @itemize @bullet
3296 @item automatic notification of new threads
3297 @item @samp{thread @var{thread-id}}, a command to switch among threads
3298 @item @samp{info threads}, a command to inquire about existing threads
3299 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3300 a command to apply a command to a list of threads
3301 @item thread-specific breakpoints
3302 @item @samp{set print thread-events}, which controls printing of
3303 messages on thread start and exit.
3304 @item @samp{set libthread-db-search-path @var{path}}, which lets
3305 the user specify which @code{libthread_db} to use if the default choice
3306 isn't compatible with the program.
3307 @end itemize
3308
3309 @cindex focus of debugging
3310 @cindex current thread
3311 The @value{GDBN} thread debugging facility allows you to observe all
3312 threads while your program runs---but whenever @value{GDBN} takes
3313 control, one thread in particular is always the focus of debugging.
3314 This thread is called the @dfn{current thread}. Debugging commands show
3315 program information from the perspective of the current thread.
3316
3317 @cindex @code{New} @var{systag} message
3318 @cindex thread identifier (system)
3319 @c FIXME-implementors!! It would be more helpful if the [New...] message
3320 @c included GDB's numeric thread handle, so you could just go to that
3321 @c thread without first checking `info threads'.
3322 Whenever @value{GDBN} detects a new thread in your program, it displays
3323 the target system's identification for the thread with a message in the
3324 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3325 whose form varies depending on the particular system. For example, on
3326 @sc{gnu}/Linux, you might see
3327
3328 @smallexample
3329 [New Thread 0x41e02940 (LWP 25582)]
3330 @end smallexample
3331
3332 @noindent
3333 when @value{GDBN} notices a new thread. In contrast, on other systems,
3334 the @var{systag} is simply something like @samp{process 368}, with no
3335 further qualifier.
3336
3337 @c FIXME!! (1) Does the [New...] message appear even for the very first
3338 @c thread of a program, or does it only appear for the
3339 @c second---i.e.@: when it becomes obvious we have a multithread
3340 @c program?
3341 @c (2) *Is* there necessarily a first thread always? Or do some
3342 @c multithread systems permit starting a program with multiple
3343 @c threads ab initio?
3344
3345 @anchor{thread numbers}
3346 @cindex thread number, per inferior
3347 @cindex thread identifier (GDB)
3348 For debugging purposes, @value{GDBN} associates its own thread number
3349 ---always a single integer---with each thread of an inferior. This
3350 number is unique between all threads of an inferior, but not unique
3351 between threads of different inferiors.
3352
3353 @cindex qualified thread ID
3354 You can refer to a given thread in an inferior using the qualified
3355 @var{inferior-num}.@var{thread-num} syntax, also known as
3356 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3357 number and @var{thread-num} being the thread number of the given
3358 inferior. For example, thread @code{2.3} refers to thread number 3 of
3359 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3360 then @value{GDBN} infers you're referring to a thread of the current
3361 inferior.
3362
3363 Until you create a second inferior, @value{GDBN} does not show the
3364 @var{inferior-num} part of thread IDs, even though you can always use
3365 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3366 of inferior 1, the initial inferior.
3367
3368 @anchor{thread ID lists}
3369 @cindex thread ID lists
3370 Some commands accept a space-separated @dfn{thread ID list} as
3371 argument. A list element can be:
3372
3373 @enumerate
3374 @item
3375 A thread ID as shown in the first field of the @samp{info threads}
3376 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3377 @samp{1}.
3378
3379 @item
3380 A range of thread numbers, again with or without an inferior
3381 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3382 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3383
3384 @item
3385 All threads of an inferior, specified with a star wildcard, with or
3386 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3387 @samp{1.*}) or @code{*}. The former refers to all threads of the
3388 given inferior, and the latter form without an inferior qualifier
3389 refers to all threads of the current inferior.
3390
3391 @end enumerate
3392
3393 For example, if the current inferior is 1, and inferior 7 has one
3394 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3395 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3396 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3397 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3398 7.1}.
3399
3400
3401 @anchor{global thread numbers}
3402 @cindex global thread number
3403 @cindex global thread identifier (GDB)
3404 In addition to a @emph{per-inferior} number, each thread is also
3405 assigned a unique @emph{global} number, also known as @dfn{global
3406 thread ID}, a single integer. Unlike the thread number component of
3407 the thread ID, no two threads have the same global ID, even when
3408 you're debugging multiple inferiors.
3409
3410 From @value{GDBN}'s perspective, a process always has at least one
3411 thread. In other words, @value{GDBN} assigns a thread number to the
3412 program's ``main thread'' even if the program is not multi-threaded.
3413
3414 @vindex $_thread@r{, convenience variable}
3415 @vindex $_gthread@r{, convenience variable}
3416 The debugger convenience variables @samp{$_thread} and
3417 @samp{$_gthread} contain, respectively, the per-inferior thread number
3418 and the global thread number of the current thread. You may find this
3419 useful in writing breakpoint conditional expressions, command scripts,
3420 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3421 general information on convenience variables.
3422
3423 If @value{GDBN} detects the program is multi-threaded, it augments the
3424 usual message about stopping at a breakpoint with the ID and name of
3425 the thread that hit the breakpoint.
3426
3427 @smallexample
3428 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3429 @end smallexample
3430
3431 Likewise when the program receives a signal:
3432
3433 @smallexample
3434 Thread 1 "main" received signal SIGINT, Interrupt.
3435 @end smallexample
3436
3437 @table @code
3438 @kindex info threads
3439 @item info threads @r{[}@var{thread-id-list}@r{]}
3440
3441 Display information about one or more threads. With no arguments
3442 displays information about all threads. You can specify the list of
3443 threads that you want to display using the thread ID list syntax
3444 (@pxref{thread ID lists}).
3445
3446 @value{GDBN} displays for each thread (in this order):
3447
3448 @enumerate
3449 @item
3450 the per-inferior thread number assigned by @value{GDBN}
3451
3452 @item
3453 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3454 option was specified
3455
3456 @item
3457 the target system's thread identifier (@var{systag})
3458
3459 @item
3460 the thread's name, if one is known. A thread can either be named by
3461 the user (see @code{thread name}, below), or, in some cases, by the
3462 program itself.
3463
3464 @item
3465 the current stack frame summary for that thread
3466 @end enumerate
3467
3468 @noindent
3469 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3470 indicates the current thread.
3471
3472 For example,
3473 @end table
3474 @c end table here to get a little more width for example
3475
3476 @smallexample
3477 (@value{GDBP}) info threads
3478 Id Target Id Frame
3479 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3480 2 process 35 thread 23 0x34e5 in sigpause ()
3481 3 process 35 thread 27 0x34e5 in sigpause ()
3482 at threadtest.c:68
3483 @end smallexample
3484
3485 If you're debugging multiple inferiors, @value{GDBN} displays thread
3486 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3487 Otherwise, only @var{thread-num} is shown.
3488
3489 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3490 indicating each thread's global thread ID:
3491
3492 @smallexample
3493 (@value{GDBP}) info threads
3494 Id GId Target Id Frame
3495 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3496 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3497 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3498 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3499 @end smallexample
3500
3501 On Solaris, you can display more information about user threads with a
3502 Solaris-specific command:
3503
3504 @table @code
3505 @item maint info sol-threads
3506 @kindex maint info sol-threads
3507 @cindex thread info (Solaris)
3508 Display info on Solaris user threads.
3509 @end table
3510
3511 @table @code
3512 @kindex thread @var{thread-id}
3513 @item thread @var{thread-id}
3514 Make thread ID @var{thread-id} the current thread. The command
3515 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3516 the first field of the @samp{info threads} display, with or without an
3517 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3518
3519 @value{GDBN} responds by displaying the system identifier of the
3520 thread you selected, and its current stack frame summary:
3521
3522 @smallexample
3523 (@value{GDBP}) thread 2
3524 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3525 #0 some_function (ignore=0x0) at example.c:8
3526 8 printf ("hello\n");
3527 @end smallexample
3528
3529 @noindent
3530 As with the @samp{[New @dots{}]} message, the form of the text after
3531 @samp{Switching to} depends on your system's conventions for identifying
3532 threads.
3533
3534 @anchor{thread apply all}
3535 @kindex thread apply
3536 @cindex apply command to several threads
3537 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3538 The @code{thread apply} command allows you to apply the named
3539 @var{command} to one or more threads. Specify the threads that you
3540 want affected using the thread ID list syntax (@pxref{thread ID
3541 lists}), or specify @code{all} to apply to all threads. To apply a
3542 command to all threads in descending order, type @kbd{thread apply all
3543 @var{command}}. To apply a command to all threads in ascending order,
3544 type @kbd{thread apply all -ascending @var{command}}.
3545
3546 The @var{flag} arguments control what output to produce and how to handle
3547 errors raised when applying @var{command} to a thread. @var{flag}
3548 must start with a @code{-} directly followed by one letter in
3549 @code{qcs}. If several flags are provided, they must be given
3550 individually, such as @code{-c -q}.
3551
3552 By default, @value{GDBN} displays some thread information before the
3553 output produced by @var{command}, and an error raised during the
3554 execution of a @var{command} will abort @code{thread apply}. The
3555 following flags can be used to fine-tune this behavior:
3556
3557 @table @code
3558 @item -c
3559 The flag @code{-c}, which stands for @samp{continue}, causes any
3560 errors in @var{command} to be displayed, and the execution of
3561 @code{thread apply} then continues.
3562 @item -s
3563 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3564 or empty output produced by a @var{command} to be silently ignored.
3565 That is, the execution continues, but the thread information and errors
3566 are not printed.
3567 @item -q
3568 The flag @code{-q} (@samp{quiet}) disables printing the thread
3569 information.
3570 @end table
3571
3572 Flags @code{-c} and @code{-s} cannot be used together.
3573
3574 @kindex taas
3575 @cindex apply command to all threads (ignoring errors and empty output)
3576 @item taas [@var{option}]@dots{} @var{command}
3577 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3578 Applies @var{command} on all threads, ignoring errors and empty output.
3579
3580 The @code{taas} command accepts the same options as the @code{thread
3581 apply all} command. @xref{thread apply all}.
3582
3583 @kindex tfaas
3584 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3585 @item tfaas [@var{option}]@dots{} @var{command}
3586 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3587 Applies @var{command} on all frames of all threads, ignoring errors
3588 and empty output. Note that the flag @code{-s} is specified twice:
3589 The first @code{-s} ensures that @code{thread apply} only shows the thread
3590 information of the threads for which @code{frame apply} produces
3591 some output. The second @code{-s} is needed to ensure that @code{frame
3592 apply} shows the frame information of a frame only if the
3593 @var{command} successfully produced some output.
3594
3595 It can for example be used to print a local variable or a function
3596 argument without knowing the thread or frame where this variable or argument
3597 is, using:
3598 @smallexample
3599 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3600 @end smallexample
3601
3602 The @code{tfaas} command accepts the same options as the @code{frame
3603 apply} command. @xref{frame apply}.
3604
3605 @kindex thread name
3606 @cindex name a thread
3607 @item thread name [@var{name}]
3608 This command assigns a name to the current thread. If no argument is
3609 given, any existing user-specified name is removed. The thread name
3610 appears in the @samp{info threads} display.
3611
3612 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3613 determine the name of the thread as given by the OS. On these
3614 systems, a name specified with @samp{thread name} will override the
3615 system-give name, and removing the user-specified name will cause
3616 @value{GDBN} to once again display the system-specified name.
3617
3618 @kindex thread find
3619 @cindex search for a thread
3620 @item thread find [@var{regexp}]
3621 Search for and display thread ids whose name or @var{systag}
3622 matches the supplied regular expression.
3623
3624 As well as being the complement to the @samp{thread name} command,
3625 this command also allows you to identify a thread by its target
3626 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3627 is the LWP id.
3628
3629 @smallexample
3630 (@value{GDBN}) thread find 26688
3631 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3632 (@value{GDBN}) info thread 4
3633 Id Target Id Frame
3634 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3635 @end smallexample
3636
3637 @kindex set print thread-events
3638 @cindex print messages on thread start and exit
3639 @item set print thread-events
3640 @itemx set print thread-events on
3641 @itemx set print thread-events off
3642 The @code{set print thread-events} command allows you to enable or
3643 disable printing of messages when @value{GDBN} notices that new threads have
3644 started or that threads have exited. By default, these messages will
3645 be printed if detection of these events is supported by the target.
3646 Note that these messages cannot be disabled on all targets.
3647
3648 @kindex show print thread-events
3649 @item show print thread-events
3650 Show whether messages will be printed when @value{GDBN} detects that threads
3651 have started and exited.
3652 @end table
3653
3654 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3655 more information about how @value{GDBN} behaves when you stop and start
3656 programs with multiple threads.
3657
3658 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3659 watchpoints in programs with multiple threads.
3660
3661 @anchor{set libthread-db-search-path}
3662 @table @code
3663 @kindex set libthread-db-search-path
3664 @cindex search path for @code{libthread_db}
3665 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3666 If this variable is set, @var{path} is a colon-separated list of
3667 directories @value{GDBN} will use to search for @code{libthread_db}.
3668 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3669 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3670 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3671 macro.
3672
3673 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3674 @code{libthread_db} library to obtain information about threads in the
3675 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3676 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3677 specific thread debugging library loading is enabled
3678 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3679
3680 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3681 refers to the default system directories that are
3682 normally searched for loading shared libraries. The @samp{$sdir} entry
3683 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3684 (@pxref{libthread_db.so.1 file}).
3685
3686 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3687 refers to the directory from which @code{libpthread}
3688 was loaded in the inferior process.
3689
3690 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3691 @value{GDBN} attempts to initialize it with the current inferior process.
3692 If this initialization fails (which could happen because of a version
3693 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3694 will unload @code{libthread_db}, and continue with the next directory.
3695 If none of @code{libthread_db} libraries initialize successfully,
3696 @value{GDBN} will issue a warning and thread debugging will be disabled.
3697
3698 Setting @code{libthread-db-search-path} is currently implemented
3699 only on some platforms.
3700
3701 @kindex show libthread-db-search-path
3702 @item show libthread-db-search-path
3703 Display current libthread_db search path.
3704
3705 @kindex set debug libthread-db
3706 @kindex show debug libthread-db
3707 @cindex debugging @code{libthread_db}
3708 @item set debug libthread-db
3709 @itemx show debug libthread-db
3710 Turns on or off display of @code{libthread_db}-related events.
3711 Use @code{1} to enable, @code{0} to disable.
3712 @end table
3713
3714 @node Forks
3715 @section Debugging Forks
3716
3717 @cindex fork, debugging programs which call
3718 @cindex multiple processes
3719 @cindex processes, multiple
3720 On most systems, @value{GDBN} has no special support for debugging
3721 programs which create additional processes using the @code{fork}
3722 function. When a program forks, @value{GDBN} will continue to debug the
3723 parent process and the child process will run unimpeded. If you have
3724 set a breakpoint in any code which the child then executes, the child
3725 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3726 will cause it to terminate.
3727
3728 However, if you want to debug the child process there is a workaround
3729 which isn't too painful. Put a call to @code{sleep} in the code which
3730 the child process executes after the fork. It may be useful to sleep
3731 only if a certain environment variable is set, or a certain file exists,
3732 so that the delay need not occur when you don't want to run @value{GDBN}
3733 on the child. While the child is sleeping, use the @code{ps} program to
3734 get its process ID. Then tell @value{GDBN} (a new invocation of
3735 @value{GDBN} if you are also debugging the parent process) to attach to
3736 the child process (@pxref{Attach}). From that point on you can debug
3737 the child process just like any other process which you attached to.
3738
3739 On some systems, @value{GDBN} provides support for debugging programs
3740 that create additional processes using the @code{fork} or @code{vfork}
3741 functions. On @sc{gnu}/Linux platforms, this feature is supported
3742 with kernel version 2.5.46 and later.
3743
3744 The fork debugging commands are supported in native mode and when
3745 connected to @code{gdbserver} in either @code{target remote} mode or
3746 @code{target extended-remote} mode.
3747
3748 By default, when a program forks, @value{GDBN} will continue to debug
3749 the parent process and the child process will run unimpeded.
3750
3751 If you want to follow the child process instead of the parent process,
3752 use the command @w{@code{set follow-fork-mode}}.
3753
3754 @table @code
3755 @kindex set follow-fork-mode
3756 @item set follow-fork-mode @var{mode}
3757 Set the debugger response to a program call of @code{fork} or
3758 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3759 process. The @var{mode} argument can be:
3760
3761 @table @code
3762 @item parent
3763 The original process is debugged after a fork. The child process runs
3764 unimpeded. This is the default.
3765
3766 @item child
3767 The new process is debugged after a fork. The parent process runs
3768 unimpeded.
3769
3770 @end table
3771
3772 @kindex show follow-fork-mode
3773 @item show follow-fork-mode
3774 Display the current debugger response to a @code{fork} or @code{vfork} call.
3775 @end table
3776
3777 @cindex debugging multiple processes
3778 On Linux, if you want to debug both the parent and child processes, use the
3779 command @w{@code{set detach-on-fork}}.
3780
3781 @table @code
3782 @kindex set detach-on-fork
3783 @item set detach-on-fork @var{mode}
3784 Tells gdb whether to detach one of the processes after a fork, or
3785 retain debugger control over them both.
3786
3787 @table @code
3788 @item on
3789 The child process (or parent process, depending on the value of
3790 @code{follow-fork-mode}) will be detached and allowed to run
3791 independently. This is the default.
3792
3793 @item off
3794 Both processes will be held under the control of @value{GDBN}.
3795 One process (child or parent, depending on the value of
3796 @code{follow-fork-mode}) is debugged as usual, while the other
3797 is held suspended.
3798
3799 @end table
3800
3801 @kindex show detach-on-fork
3802 @item show detach-on-fork
3803 Show whether detach-on-fork mode is on/off.
3804 @end table
3805
3806 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3807 will retain control of all forked processes (including nested forks).
3808 You can list the forked processes under the control of @value{GDBN} by
3809 using the @w{@code{info inferiors}} command, and switch from one fork
3810 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3811 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3812
3813 To quit debugging one of the forked processes, you can either detach
3814 from it by using the @w{@code{detach inferiors}} command (allowing it
3815 to run independently), or kill it using the @w{@code{kill inferiors}}
3816 command. @xref{Inferiors Connections and Programs, ,Debugging
3817 Multiple Inferiors Connections and Programs}.
3818
3819 If you ask to debug a child process and a @code{vfork} is followed by an
3820 @code{exec}, @value{GDBN} executes the new target up to the first
3821 breakpoint in the new target. If you have a breakpoint set on
3822 @code{main} in your original program, the breakpoint will also be set on
3823 the child process's @code{main}.
3824
3825 On some systems, when a child process is spawned by @code{vfork}, you
3826 cannot debug the child or parent until an @code{exec} call completes.
3827
3828 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3829 call executes, the new target restarts. To restart the parent
3830 process, use the @code{file} command with the parent executable name
3831 as its argument. By default, after an @code{exec} call executes,
3832 @value{GDBN} discards the symbols of the previous executable image.
3833 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3834 command.
3835
3836 @table @code
3837 @kindex set follow-exec-mode
3838 @item set follow-exec-mode @var{mode}
3839
3840 Set debugger response to a program call of @code{exec}. An
3841 @code{exec} call replaces the program image of a process.
3842
3843 @code{follow-exec-mode} can be:
3844
3845 @table @code
3846 @item new
3847 @value{GDBN} creates a new inferior and rebinds the process to this
3848 new inferior. The program the process was running before the
3849 @code{exec} call can be restarted afterwards by restarting the
3850 original inferior.
3851
3852 For example:
3853
3854 @smallexample
3855 (@value{GDBP}) info inferiors
3856 (gdb) info inferior
3857 Id Description Executable
3858 * 1 <null> prog1
3859 (@value{GDBP}) run
3860 process 12020 is executing new program: prog2
3861 Program exited normally.
3862 (@value{GDBP}) info inferiors
3863 Id Description Executable
3864 1 <null> prog1
3865 * 2 <null> prog2
3866 @end smallexample
3867
3868 @item same
3869 @value{GDBN} keeps the process bound to the same inferior. The new
3870 executable image replaces the previous executable loaded in the
3871 inferior. Restarting the inferior after the @code{exec} call, with
3872 e.g., the @code{run} command, restarts the executable the process was
3873 running after the @code{exec} call. This is the default mode.
3874
3875 For example:
3876
3877 @smallexample
3878 (@value{GDBP}) info inferiors
3879 Id Description Executable
3880 * 1 <null> prog1
3881 (@value{GDBP}) run
3882 process 12020 is executing new program: prog2
3883 Program exited normally.
3884 (@value{GDBP}) info inferiors
3885 Id Description Executable
3886 * 1 <null> prog2
3887 @end smallexample
3888
3889 @end table
3890 @end table
3891
3892 @code{follow-exec-mode} is supported in native mode and
3893 @code{target extended-remote} mode.
3894
3895 You can use the @code{catch} command to make @value{GDBN} stop whenever
3896 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3897 Catchpoints, ,Setting Catchpoints}.
3898
3899 @node Checkpoint/Restart
3900 @section Setting a @emph{Bookmark} to Return to Later
3901
3902 @cindex checkpoint
3903 @cindex restart
3904 @cindex bookmark
3905 @cindex snapshot of a process
3906 @cindex rewind program state
3907
3908 On certain operating systems@footnote{Currently, only
3909 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3910 program's state, called a @dfn{checkpoint}, and come back to it
3911 later.
3912
3913 Returning to a checkpoint effectively undoes everything that has
3914 happened in the program since the @code{checkpoint} was saved. This
3915 includes changes in memory, registers, and even (within some limits)
3916 system state. Effectively, it is like going back in time to the
3917 moment when the checkpoint was saved.
3918
3919 Thus, if you're stepping thru a program and you think you're
3920 getting close to the point where things go wrong, you can save
3921 a checkpoint. Then, if you accidentally go too far and miss
3922 the critical statement, instead of having to restart your program
3923 from the beginning, you can just go back to the checkpoint and
3924 start again from there.
3925
3926 This can be especially useful if it takes a lot of time or
3927 steps to reach the point where you think the bug occurs.
3928
3929 To use the @code{checkpoint}/@code{restart} method of debugging:
3930
3931 @table @code
3932 @kindex checkpoint
3933 @item checkpoint
3934 Save a snapshot of the debugged program's current execution state.
3935 The @code{checkpoint} command takes no arguments, but each checkpoint
3936 is assigned a small integer id, similar to a breakpoint id.
3937
3938 @kindex info checkpoints
3939 @item info checkpoints
3940 List the checkpoints that have been saved in the current debugging
3941 session. For each checkpoint, the following information will be
3942 listed:
3943
3944 @table @code
3945 @item Checkpoint ID
3946 @item Process ID
3947 @item Code Address
3948 @item Source line, or label
3949 @end table
3950
3951 @kindex restart @var{checkpoint-id}
3952 @item restart @var{checkpoint-id}
3953 Restore the program state that was saved as checkpoint number
3954 @var{checkpoint-id}. All program variables, registers, stack frames
3955 etc.@: will be returned to the values that they had when the checkpoint
3956 was saved. In essence, gdb will ``wind back the clock'' to the point
3957 in time when the checkpoint was saved.
3958
3959 Note that breakpoints, @value{GDBN} variables, command history etc.
3960 are not affected by restoring a checkpoint. In general, a checkpoint
3961 only restores things that reside in the program being debugged, not in
3962 the debugger.
3963
3964 @kindex delete checkpoint @var{checkpoint-id}
3965 @item delete checkpoint @var{checkpoint-id}
3966 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3967
3968 @end table
3969
3970 Returning to a previously saved checkpoint will restore the user state
3971 of the program being debugged, plus a significant subset of the system
3972 (OS) state, including file pointers. It won't ``un-write'' data from
3973 a file, but it will rewind the file pointer to the previous location,
3974 so that the previously written data can be overwritten. For files
3975 opened in read mode, the pointer will also be restored so that the
3976 previously read data can be read again.
3977
3978 Of course, characters that have been sent to a printer (or other
3979 external device) cannot be ``snatched back'', and characters received
3980 from eg.@: a serial device can be removed from internal program buffers,
3981 but they cannot be ``pushed back'' into the serial pipeline, ready to
3982 be received again. Similarly, the actual contents of files that have
3983 been changed cannot be restored (at this time).
3984
3985 However, within those constraints, you actually can ``rewind'' your
3986 program to a previously saved point in time, and begin debugging it
3987 again --- and you can change the course of events so as to debug a
3988 different execution path this time.
3989
3990 @cindex checkpoints and process id
3991 Finally, there is one bit of internal program state that will be
3992 different when you return to a checkpoint --- the program's process
3993 id. Each checkpoint will have a unique process id (or @var{pid}),
3994 and each will be different from the program's original @var{pid}.
3995 If your program has saved a local copy of its process id, this could
3996 potentially pose a problem.
3997
3998 @subsection A Non-obvious Benefit of Using Checkpoints
3999
4000 On some systems such as @sc{gnu}/Linux, address space randomization
4001 is performed on new processes for security reasons. This makes it
4002 difficult or impossible to set a breakpoint, or watchpoint, on an
4003 absolute address if you have to restart the program, since the
4004 absolute location of a symbol will change from one execution to the
4005 next.
4006
4007 A checkpoint, however, is an @emph{identical} copy of a process.
4008 Therefore if you create a checkpoint at (eg.@:) the start of main,
4009 and simply return to that checkpoint instead of restarting the
4010 process, you can avoid the effects of address randomization and
4011 your symbols will all stay in the same place.
4012
4013 @node Stopping
4014 @chapter Stopping and Continuing
4015
4016 The principal purposes of using a debugger are so that you can stop your
4017 program before it terminates; or so that, if your program runs into
4018 trouble, you can investigate and find out why.
4019
4020 Inside @value{GDBN}, your program may stop for any of several reasons,
4021 such as a signal, a breakpoint, or reaching a new line after a
4022 @value{GDBN} command such as @code{step}. You may then examine and
4023 change variables, set new breakpoints or remove old ones, and then
4024 continue execution. Usually, the messages shown by @value{GDBN} provide
4025 ample explanation of the status of your program---but you can also
4026 explicitly request this information at any time.
4027
4028 @table @code
4029 @kindex info program
4030 @item info program
4031 Display information about the status of your program: whether it is
4032 running or not, what process it is, and why it stopped.
4033 @end table
4034
4035 @menu
4036 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4037 * Continuing and Stepping:: Resuming execution
4038 * Skipping Over Functions and Files::
4039 Skipping over functions and files
4040 * Signals:: Signals
4041 * Thread Stops:: Stopping and starting multi-thread programs
4042 @end menu
4043
4044 @node Breakpoints
4045 @section Breakpoints, Watchpoints, and Catchpoints
4046
4047 @cindex breakpoints
4048 A @dfn{breakpoint} makes your program stop whenever a certain point in
4049 the program is reached. For each breakpoint, you can add conditions to
4050 control in finer detail whether your program stops. You can set
4051 breakpoints with the @code{break} command and its variants (@pxref{Set
4052 Breaks, ,Setting Breakpoints}), to specify the place where your program
4053 should stop by line number, function name or exact address in the
4054 program.
4055
4056 On some systems, you can set breakpoints in shared libraries before
4057 the executable is run.
4058
4059 @cindex watchpoints
4060 @cindex data breakpoints
4061 @cindex memory tracing
4062 @cindex breakpoint on memory address
4063 @cindex breakpoint on variable modification
4064 A @dfn{watchpoint} is a special breakpoint that stops your program
4065 when the value of an expression changes. The expression may be a value
4066 of a variable, or it could involve values of one or more variables
4067 combined by operators, such as @samp{a + b}. This is sometimes called
4068 @dfn{data breakpoints}. You must use a different command to set
4069 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4070 from that, you can manage a watchpoint like any other breakpoint: you
4071 enable, disable, and delete both breakpoints and watchpoints using the
4072 same commands.
4073
4074 You can arrange to have values from your program displayed automatically
4075 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4076 Automatic Display}.
4077
4078 @cindex catchpoints
4079 @cindex breakpoint on events
4080 A @dfn{catchpoint} is another special breakpoint that stops your program
4081 when a certain kind of event occurs, such as the throwing of a C@t{++}
4082 exception or the loading of a library. As with watchpoints, you use a
4083 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4084 Catchpoints}), but aside from that, you can manage a catchpoint like any
4085 other breakpoint. (To stop when your program receives a signal, use the
4086 @code{handle} command; see @ref{Signals, ,Signals}.)
4087
4088 @cindex breakpoint numbers
4089 @cindex numbers for breakpoints
4090 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4091 catchpoint when you create it; these numbers are successive integers
4092 starting with one. In many of the commands for controlling various
4093 features of breakpoints you use the breakpoint number to say which
4094 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4095 @dfn{disabled}; if disabled, it has no effect on your program until you
4096 enable it again.
4097
4098 @cindex breakpoint ranges
4099 @cindex breakpoint lists
4100 @cindex ranges of breakpoints
4101 @cindex lists of breakpoints
4102 Some @value{GDBN} commands accept a space-separated list of breakpoints
4103 on which to operate. A list element can be either a single breakpoint number,
4104 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4105 When a breakpoint list is given to a command, all breakpoints in that list
4106 are operated on.
4107
4108 @menu
4109 * Set Breaks:: Setting breakpoints
4110 * Set Watchpoints:: Setting watchpoints
4111 * Set Catchpoints:: Setting catchpoints
4112 * Delete Breaks:: Deleting breakpoints
4113 * Disabling:: Disabling breakpoints
4114 * Conditions:: Break conditions
4115 * Break Commands:: Breakpoint command lists
4116 * Dynamic Printf:: Dynamic printf
4117 * Save Breakpoints:: How to save breakpoints in a file
4118 * Static Probe Points:: Listing static probe points
4119 * Error in Breakpoints:: ``Cannot insert breakpoints''
4120 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4121 @end menu
4122
4123 @node Set Breaks
4124 @subsection Setting Breakpoints
4125
4126 @c FIXME LMB what does GDB do if no code on line of breakpt?
4127 @c consider in particular declaration with/without initialization.
4128 @c
4129 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4130
4131 @kindex break
4132 @kindex b @r{(@code{break})}
4133 @vindex $bpnum@r{, convenience variable}
4134 @cindex latest breakpoint
4135 Breakpoints are set with the @code{break} command (abbreviated
4136 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4137 number of the breakpoint you've set most recently; see @ref{Convenience
4138 Vars,, Convenience Variables}, for a discussion of what you can do with
4139 convenience variables.
4140
4141 @table @code
4142 @item break @var{location}
4143 Set a breakpoint at the given @var{location}, which can specify a
4144 function name, a line number, or an address of an instruction.
4145 (@xref{Specify Location}, for a list of all the possible ways to
4146 specify a @var{location}.) The breakpoint will stop your program just
4147 before it executes any of the code in the specified @var{location}.
4148
4149 When using source languages that permit overloading of symbols, such as
4150 C@t{++}, a function name may refer to more than one possible place to break.
4151 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4152 that situation.
4153
4154 It is also possible to insert a breakpoint that will stop the program
4155 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4156 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4157
4158 @item break
4159 When called without any arguments, @code{break} sets a breakpoint at
4160 the next instruction to be executed in the selected stack frame
4161 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4162 innermost, this makes your program stop as soon as control
4163 returns to that frame. This is similar to the effect of a
4164 @code{finish} command in the frame inside the selected frame---except
4165 that @code{finish} does not leave an active breakpoint. If you use
4166 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4167 the next time it reaches the current location; this may be useful
4168 inside loops.
4169
4170 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4171 least one instruction has been executed. If it did not do this, you
4172 would be unable to proceed past a breakpoint without first disabling the
4173 breakpoint. This rule applies whether or not the breakpoint already
4174 existed when your program stopped.
4175
4176 @item break @dots{} if @var{cond}
4177 Set a breakpoint with condition @var{cond}; evaluate the expression
4178 @var{cond} each time the breakpoint is reached, and stop only if the
4179 value is nonzero---that is, if @var{cond} evaluates as true.
4180 @samp{@dots{}} stands for one of the possible arguments described
4181 above (or no argument) specifying where to break. @xref{Conditions,
4182 ,Break Conditions}, for more information on breakpoint conditions.
4183
4184 @kindex tbreak
4185 @item tbreak @var{args}
4186 Set a breakpoint enabled only for one stop. The @var{args} are the
4187 same as for the @code{break} command, and the breakpoint is set in the same
4188 way, but the breakpoint is automatically deleted after the first time your
4189 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4190
4191 @kindex hbreak
4192 @cindex hardware breakpoints
4193 @item hbreak @var{args}
4194 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4195 @code{break} command and the breakpoint is set in the same way, but the
4196 breakpoint requires hardware support and some target hardware may not
4197 have this support. The main purpose of this is EPROM/ROM code
4198 debugging, so you can set a breakpoint at an instruction without
4199 changing the instruction. This can be used with the new trap-generation
4200 provided by SPARClite DSU and most x86-based targets. These targets
4201 will generate traps when a program accesses some data or instruction
4202 address that is assigned to the debug registers. However the hardware
4203 breakpoint registers can take a limited number of breakpoints. For
4204 example, on the DSU, only two data breakpoints can be set at a time, and
4205 @value{GDBN} will reject this command if more than two are used. Delete
4206 or disable unused hardware breakpoints before setting new ones
4207 (@pxref{Disabling, ,Disabling Breakpoints}).
4208 @xref{Conditions, ,Break Conditions}.
4209 For remote targets, you can restrict the number of hardware
4210 breakpoints @value{GDBN} will use, see @ref{set remote
4211 hardware-breakpoint-limit}.
4212
4213 @kindex thbreak
4214 @item thbreak @var{args}
4215 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4216 are the same as for the @code{hbreak} command and the breakpoint is set in
4217 the same way. However, like the @code{tbreak} command,
4218 the breakpoint is automatically deleted after the
4219 first time your program stops there. Also, like the @code{hbreak}
4220 command, the breakpoint requires hardware support and some target hardware
4221 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4222 See also @ref{Conditions, ,Break Conditions}.
4223
4224 @kindex rbreak
4225 @cindex regular expression
4226 @cindex breakpoints at functions matching a regexp
4227 @cindex set breakpoints in many functions
4228 @item rbreak @var{regex}
4229 Set breakpoints on all functions matching the regular expression
4230 @var{regex}. This command sets an unconditional breakpoint on all
4231 matches, printing a list of all breakpoints it set. Once these
4232 breakpoints are set, they are treated just like the breakpoints set with
4233 the @code{break} command. You can delete them, disable them, or make
4234 them conditional the same way as any other breakpoint.
4235
4236 In programs using different languages, @value{GDBN} chooses the syntax
4237 to print the list of all breakpoints it sets according to the
4238 @samp{set language} value: using @samp{set language auto}
4239 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4240 language of the breakpoint's function, other values mean to use
4241 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4242
4243 The syntax of the regular expression is the standard one used with tools
4244 like @file{grep}. Note that this is different from the syntax used by
4245 shells, so for instance @code{foo*} matches all functions that include
4246 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4247 @code{.*} leading and trailing the regular expression you supply, so to
4248 match only functions that begin with @code{foo}, use @code{^foo}.
4249
4250 @cindex non-member C@t{++} functions, set breakpoint in
4251 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4252 breakpoints on overloaded functions that are not members of any special
4253 classes.
4254
4255 @cindex set breakpoints on all functions
4256 The @code{rbreak} command can be used to set breakpoints in
4257 @strong{all} the functions in a program, like this:
4258
4259 @smallexample
4260 (@value{GDBP}) rbreak .
4261 @end smallexample
4262
4263 @item rbreak @var{file}:@var{regex}
4264 If @code{rbreak} is called with a filename qualification, it limits
4265 the search for functions matching the given regular expression to the
4266 specified @var{file}. This can be used, for example, to set breakpoints on
4267 every function in a given file:
4268
4269 @smallexample
4270 (@value{GDBP}) rbreak file.c:.
4271 @end smallexample
4272
4273 The colon separating the filename qualifier from the regex may
4274 optionally be surrounded by spaces.
4275
4276 @kindex info breakpoints
4277 @cindex @code{$_} and @code{info breakpoints}
4278 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4279 @itemx info break @r{[}@var{list}@dots{}@r{]}
4280 Print a table of all breakpoints, watchpoints, and catchpoints set and
4281 not deleted. Optional argument @var{n} means print information only
4282 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4283 For each breakpoint, following columns are printed:
4284
4285 @table @emph
4286 @item Breakpoint Numbers
4287 @item Type
4288 Breakpoint, watchpoint, or catchpoint.
4289 @item Disposition
4290 Whether the breakpoint is marked to be disabled or deleted when hit.
4291 @item Enabled or Disabled
4292 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4293 that are not enabled.
4294 @item Address
4295 Where the breakpoint is in your program, as a memory address. For a
4296 pending breakpoint whose address is not yet known, this field will
4297 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4298 library that has the symbol or line referred by breakpoint is loaded.
4299 See below for details. A breakpoint with several locations will
4300 have @samp{<MULTIPLE>} in this field---see below for details.
4301 @item What
4302 Where the breakpoint is in the source for your program, as a file and
4303 line number. For a pending breakpoint, the original string passed to
4304 the breakpoint command will be listed as it cannot be resolved until
4305 the appropriate shared library is loaded in the future.
4306 @end table
4307
4308 @noindent
4309 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4310 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4311 @value{GDBN} on the host's side. If it is ``target'', then the condition
4312 is evaluated by the target. The @code{info break} command shows
4313 the condition on the line following the affected breakpoint, together with
4314 its condition evaluation mode in between parentheses.
4315
4316 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4317 allowed to have a condition specified for it. The condition is not parsed for
4318 validity until a shared library is loaded that allows the pending
4319 breakpoint to resolve to a valid location.
4320
4321 @noindent
4322 @code{info break} with a breakpoint
4323 number @var{n} as argument lists only that breakpoint. The
4324 convenience variable @code{$_} and the default examining-address for
4325 the @code{x} command are set to the address of the last breakpoint
4326 listed (@pxref{Memory, ,Examining Memory}).
4327
4328 @noindent
4329 @code{info break} displays a count of the number of times the breakpoint
4330 has been hit. This is especially useful in conjunction with the
4331 @code{ignore} command. You can ignore a large number of breakpoint
4332 hits, look at the breakpoint info to see how many times the breakpoint
4333 was hit, and then run again, ignoring one less than that number. This
4334 will get you quickly to the last hit of that breakpoint.
4335
4336 @noindent
4337 For a breakpoints with an enable count (xref) greater than 1,
4338 @code{info break} also displays that count.
4339
4340 @end table
4341
4342 @value{GDBN} allows you to set any number of breakpoints at the same place in
4343 your program. There is nothing silly or meaningless about this. When
4344 the breakpoints are conditional, this is even useful
4345 (@pxref{Conditions, ,Break Conditions}).
4346
4347 @cindex multiple locations, breakpoints
4348 @cindex breakpoints, multiple locations
4349 It is possible that a breakpoint corresponds to several locations
4350 in your program. Examples of this situation are:
4351
4352 @itemize @bullet
4353 @item
4354 Multiple functions in the program may have the same name.
4355
4356 @item
4357 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4358 instances of the function body, used in different cases.
4359
4360 @item
4361 For a C@t{++} template function, a given line in the function can
4362 correspond to any number of instantiations.
4363
4364 @item
4365 For an inlined function, a given source line can correspond to
4366 several places where that function is inlined.
4367 @end itemize
4368
4369 In all those cases, @value{GDBN} will insert a breakpoint at all
4370 the relevant locations.
4371
4372 A breakpoint with multiple locations is displayed in the breakpoint
4373 table using several rows---one header row, followed by one row for
4374 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4375 address column. The rows for individual locations contain the actual
4376 addresses for locations, and show the functions to which those
4377 locations belong. The number column for a location is of the form
4378 @var{breakpoint-number}.@var{location-number}.
4379
4380 For example:
4381
4382 @smallexample
4383 Num Type Disp Enb Address What
4384 1 breakpoint keep y <MULTIPLE>
4385 stop only if i==1
4386 breakpoint already hit 1 time
4387 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4388 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4389 @end smallexample
4390
4391 You cannot delete the individual locations from a breakpoint. However,
4392 each location can be individually enabled or disabled by passing
4393 @var{breakpoint-number}.@var{location-number} as argument to the
4394 @code{enable} and @code{disable} commands. It's also possible to
4395 @code{enable} and @code{disable} a range of @var{location-number}
4396 locations using a @var{breakpoint-number} and two @var{location-number}s,
4397 in increasing order, separated by a hyphen, like
4398 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4399 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4400 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4401 all of the locations that belong to that breakpoint.
4402
4403 @cindex pending breakpoints
4404 It's quite common to have a breakpoint inside a shared library.
4405 Shared libraries can be loaded and unloaded explicitly,
4406 and possibly repeatedly, as the program is executed. To support
4407 this use case, @value{GDBN} updates breakpoint locations whenever
4408 any shared library is loaded or unloaded. Typically, you would
4409 set a breakpoint in a shared library at the beginning of your
4410 debugging session, when the library is not loaded, and when the
4411 symbols from the library are not available. When you try to set
4412 breakpoint, @value{GDBN} will ask you if you want to set
4413 a so called @dfn{pending breakpoint}---breakpoint whose address
4414 is not yet resolved.
4415
4416 After the program is run, whenever a new shared library is loaded,
4417 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4418 shared library contains the symbol or line referred to by some
4419 pending breakpoint, that breakpoint is resolved and becomes an
4420 ordinary breakpoint. When a library is unloaded, all breakpoints
4421 that refer to its symbols or source lines become pending again.
4422
4423 This logic works for breakpoints with multiple locations, too. For
4424 example, if you have a breakpoint in a C@t{++} template function, and
4425 a newly loaded shared library has an instantiation of that template,
4426 a new location is added to the list of locations for the breakpoint.
4427
4428 Except for having unresolved address, pending breakpoints do not
4429 differ from regular breakpoints. You can set conditions or commands,
4430 enable and disable them and perform other breakpoint operations.
4431
4432 @value{GDBN} provides some additional commands for controlling what
4433 happens when the @samp{break} command cannot resolve breakpoint
4434 address specification to an address:
4435
4436 @kindex set breakpoint pending
4437 @kindex show breakpoint pending
4438 @table @code
4439 @item set breakpoint pending auto
4440 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4441 location, it queries you whether a pending breakpoint should be created.
4442
4443 @item set breakpoint pending on
4444 This indicates that an unrecognized breakpoint location should automatically
4445 result in a pending breakpoint being created.
4446
4447 @item set breakpoint pending off
4448 This indicates that pending breakpoints are not to be created. Any
4449 unrecognized breakpoint location results in an error. This setting does
4450 not affect any pending breakpoints previously created.
4451
4452 @item show breakpoint pending
4453 Show the current behavior setting for creating pending breakpoints.
4454 @end table
4455
4456 The settings above only affect the @code{break} command and its
4457 variants. Once breakpoint is set, it will be automatically updated
4458 as shared libraries are loaded and unloaded.
4459
4460 @cindex automatic hardware breakpoints
4461 For some targets, @value{GDBN} can automatically decide if hardware or
4462 software breakpoints should be used, depending on whether the
4463 breakpoint address is read-only or read-write. This applies to
4464 breakpoints set with the @code{break} command as well as to internal
4465 breakpoints set by commands like @code{next} and @code{finish}. For
4466 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4467 breakpoints.
4468
4469 You can control this automatic behaviour with the following commands:
4470
4471 @kindex set breakpoint auto-hw
4472 @kindex show breakpoint auto-hw
4473 @table @code
4474 @item set breakpoint auto-hw on
4475 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4476 will try to use the target memory map to decide if software or hardware
4477 breakpoint must be used.
4478
4479 @item set breakpoint auto-hw off
4480 This indicates @value{GDBN} should not automatically select breakpoint
4481 type. If the target provides a memory map, @value{GDBN} will warn when
4482 trying to set software breakpoint at a read-only address.
4483 @end table
4484
4485 @value{GDBN} normally implements breakpoints by replacing the program code
4486 at the breakpoint address with a special instruction, which, when
4487 executed, given control to the debugger. By default, the program
4488 code is so modified only when the program is resumed. As soon as
4489 the program stops, @value{GDBN} restores the original instructions. This
4490 behaviour guards against leaving breakpoints inserted in the
4491 target should gdb abrubptly disconnect. However, with slow remote
4492 targets, inserting and removing breakpoint can reduce the performance.
4493 This behavior can be controlled with the following commands::
4494
4495 @kindex set breakpoint always-inserted
4496 @kindex show breakpoint always-inserted
4497 @table @code
4498 @item set breakpoint always-inserted off
4499 All breakpoints, including newly added by the user, are inserted in
4500 the target only when the target is resumed. All breakpoints are
4501 removed from the target when it stops. This is the default mode.
4502
4503 @item set breakpoint always-inserted on
4504 Causes all breakpoints to be inserted in the target at all times. If
4505 the user adds a new breakpoint, or changes an existing breakpoint, the
4506 breakpoints in the target are updated immediately. A breakpoint is
4507 removed from the target only when breakpoint itself is deleted.
4508 @end table
4509
4510 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4511 when a breakpoint breaks. If the condition is true, then the process being
4512 debugged stops, otherwise the process is resumed.
4513
4514 If the target supports evaluating conditions on its end, @value{GDBN} may
4515 download the breakpoint, together with its conditions, to it.
4516
4517 This feature can be controlled via the following commands:
4518
4519 @kindex set breakpoint condition-evaluation
4520 @kindex show breakpoint condition-evaluation
4521 @table @code
4522 @item set breakpoint condition-evaluation host
4523 This option commands @value{GDBN} to evaluate the breakpoint
4524 conditions on the host's side. Unconditional breakpoints are sent to
4525 the target which in turn receives the triggers and reports them back to GDB
4526 for condition evaluation. This is the standard evaluation mode.
4527
4528 @item set breakpoint condition-evaluation target
4529 This option commands @value{GDBN} to download breakpoint conditions
4530 to the target at the moment of their insertion. The target
4531 is responsible for evaluating the conditional expression and reporting
4532 breakpoint stop events back to @value{GDBN} whenever the condition
4533 is true. Due to limitations of target-side evaluation, some conditions
4534 cannot be evaluated there, e.g., conditions that depend on local data
4535 that is only known to the host. Examples include
4536 conditional expressions involving convenience variables, complex types
4537 that cannot be handled by the agent expression parser and expressions
4538 that are too long to be sent over to the target, specially when the
4539 target is a remote system. In these cases, the conditions will be
4540 evaluated by @value{GDBN}.
4541
4542 @item set breakpoint condition-evaluation auto
4543 This is the default mode. If the target supports evaluating breakpoint
4544 conditions on its end, @value{GDBN} will download breakpoint conditions to
4545 the target (limitations mentioned previously apply). If the target does
4546 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4547 to evaluating all these conditions on the host's side.
4548 @end table
4549
4550
4551 @cindex negative breakpoint numbers
4552 @cindex internal @value{GDBN} breakpoints
4553 @value{GDBN} itself sometimes sets breakpoints in your program for
4554 special purposes, such as proper handling of @code{longjmp} (in C
4555 programs). These internal breakpoints are assigned negative numbers,
4556 starting with @code{-1}; @samp{info breakpoints} does not display them.
4557 You can see these breakpoints with the @value{GDBN} maintenance command
4558 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4559
4560
4561 @node Set Watchpoints
4562 @subsection Setting Watchpoints
4563
4564 @cindex setting watchpoints
4565 You can use a watchpoint to stop execution whenever the value of an
4566 expression changes, without having to predict a particular place where
4567 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4568 The expression may be as simple as the value of a single variable, or
4569 as complex as many variables combined by operators. Examples include:
4570
4571 @itemize @bullet
4572 @item
4573 A reference to the value of a single variable.
4574
4575 @item
4576 An address cast to an appropriate data type. For example,
4577 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4578 address (assuming an @code{int} occupies 4 bytes).
4579
4580 @item
4581 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4582 expression can use any operators valid in the program's native
4583 language (@pxref{Languages}).
4584 @end itemize
4585
4586 You can set a watchpoint on an expression even if the expression can
4587 not be evaluated yet. For instance, you can set a watchpoint on
4588 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4589 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4590 the expression produces a valid value. If the expression becomes
4591 valid in some other way than changing a variable (e.g.@: if the memory
4592 pointed to by @samp{*global_ptr} becomes readable as the result of a
4593 @code{malloc} call), @value{GDBN} may not stop until the next time
4594 the expression changes.
4595
4596 @cindex software watchpoints
4597 @cindex hardware watchpoints
4598 Depending on your system, watchpoints may be implemented in software or
4599 hardware. @value{GDBN} does software watchpointing by single-stepping your
4600 program and testing the variable's value each time, which is hundreds of
4601 times slower than normal execution. (But this may still be worth it, to
4602 catch errors where you have no clue what part of your program is the
4603 culprit.)
4604
4605 On some systems, such as most PowerPC or x86-based targets,
4606 @value{GDBN} includes support for hardware watchpoints, which do not
4607 slow down the running of your program.
4608
4609 @table @code
4610 @kindex watch
4611 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4612 Set a watchpoint for an expression. @value{GDBN} will break when the
4613 expression @var{expr} is written into by the program and its value
4614 changes. The simplest (and the most popular) use of this command is
4615 to watch the value of a single variable:
4616
4617 @smallexample
4618 (@value{GDBP}) watch foo
4619 @end smallexample
4620
4621 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4622 argument, @value{GDBN} breaks only when the thread identified by
4623 @var{thread-id} changes the value of @var{expr}. If any other threads
4624 change the value of @var{expr}, @value{GDBN} will not break. Note
4625 that watchpoints restricted to a single thread in this way only work
4626 with Hardware Watchpoints.
4627
4628 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4629 (see below). The @code{-location} argument tells @value{GDBN} to
4630 instead watch the memory referred to by @var{expr}. In this case,
4631 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4632 and watch the memory at that address. The type of the result is used
4633 to determine the size of the watched memory. If the expression's
4634 result does not have an address, then @value{GDBN} will print an
4635 error.
4636
4637 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4638 of masked watchpoints, if the current architecture supports this
4639 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4640 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4641 to an address to watch. The mask specifies that some bits of an address
4642 (the bits which are reset in the mask) should be ignored when matching
4643 the address accessed by the inferior against the watchpoint address.
4644 Thus, a masked watchpoint watches many addresses simultaneously---those
4645 addresses whose unmasked bits are identical to the unmasked bits in the
4646 watchpoint address. The @code{mask} argument implies @code{-location}.
4647 Examples:
4648
4649 @smallexample
4650 (@value{GDBP}) watch foo mask 0xffff00ff
4651 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4652 @end smallexample
4653
4654 @kindex rwatch
4655 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4656 Set a watchpoint that will break when the value of @var{expr} is read
4657 by the program.
4658
4659 @kindex awatch
4660 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4661 Set a watchpoint that will break when @var{expr} is either read from
4662 or written into by the program.
4663
4664 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4665 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4666 This command prints a list of watchpoints, using the same format as
4667 @code{info break} (@pxref{Set Breaks}).
4668 @end table
4669
4670 If you watch for a change in a numerically entered address you need to
4671 dereference it, as the address itself is just a constant number which will
4672 never change. @value{GDBN} refuses to create a watchpoint that watches
4673 a never-changing value:
4674
4675 @smallexample
4676 (@value{GDBP}) watch 0x600850
4677 Cannot watch constant value 0x600850.
4678 (@value{GDBP}) watch *(int *) 0x600850
4679 Watchpoint 1: *(int *) 6293584
4680 @end smallexample
4681
4682 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4683 watchpoints execute very quickly, and the debugger reports a change in
4684 value at the exact instruction where the change occurs. If @value{GDBN}
4685 cannot set a hardware watchpoint, it sets a software watchpoint, which
4686 executes more slowly and reports the change in value at the next
4687 @emph{statement}, not the instruction, after the change occurs.
4688
4689 @cindex use only software watchpoints
4690 You can force @value{GDBN} to use only software watchpoints with the
4691 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4692 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4693 the underlying system supports them. (Note that hardware-assisted
4694 watchpoints that were set @emph{before} setting
4695 @code{can-use-hw-watchpoints} to zero will still use the hardware
4696 mechanism of watching expression values.)
4697
4698 @table @code
4699 @item set can-use-hw-watchpoints
4700 @kindex set can-use-hw-watchpoints
4701 Set whether or not to use hardware watchpoints.
4702
4703 @item show can-use-hw-watchpoints
4704 @kindex show can-use-hw-watchpoints
4705 Show the current mode of using hardware watchpoints.
4706 @end table
4707
4708 For remote targets, you can restrict the number of hardware
4709 watchpoints @value{GDBN} will use, see @ref{set remote
4710 hardware-breakpoint-limit}.
4711
4712 When you issue the @code{watch} command, @value{GDBN} reports
4713
4714 @smallexample
4715 Hardware watchpoint @var{num}: @var{expr}
4716 @end smallexample
4717
4718 @noindent
4719 if it was able to set a hardware watchpoint.
4720
4721 Currently, the @code{awatch} and @code{rwatch} commands can only set
4722 hardware watchpoints, because accesses to data that don't change the
4723 value of the watched expression cannot be detected without examining
4724 every instruction as it is being executed, and @value{GDBN} does not do
4725 that currently. If @value{GDBN} finds that it is unable to set a
4726 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4727 will print a message like this:
4728
4729 @smallexample
4730 Expression cannot be implemented with read/access watchpoint.
4731 @end smallexample
4732
4733 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4734 data type of the watched expression is wider than what a hardware
4735 watchpoint on the target machine can handle. For example, some systems
4736 can only watch regions that are up to 4 bytes wide; on such systems you
4737 cannot set hardware watchpoints for an expression that yields a
4738 double-precision floating-point number (which is typically 8 bytes
4739 wide). As a work-around, it might be possible to break the large region
4740 into a series of smaller ones and watch them with separate watchpoints.
4741
4742 If you set too many hardware watchpoints, @value{GDBN} might be unable
4743 to insert all of them when you resume the execution of your program.
4744 Since the precise number of active watchpoints is unknown until such
4745 time as the program is about to be resumed, @value{GDBN} might not be
4746 able to warn you about this when you set the watchpoints, and the
4747 warning will be printed only when the program is resumed:
4748
4749 @smallexample
4750 Hardware watchpoint @var{num}: Could not insert watchpoint
4751 @end smallexample
4752
4753 @noindent
4754 If this happens, delete or disable some of the watchpoints.
4755
4756 Watching complex expressions that reference many variables can also
4757 exhaust the resources available for hardware-assisted watchpoints.
4758 That's because @value{GDBN} needs to watch every variable in the
4759 expression with separately allocated resources.
4760
4761 If you call a function interactively using @code{print} or @code{call},
4762 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4763 kind of breakpoint or the call completes.
4764
4765 @value{GDBN} automatically deletes watchpoints that watch local
4766 (automatic) variables, or expressions that involve such variables, when
4767 they go out of scope, that is, when the execution leaves the block in
4768 which these variables were defined. In particular, when the program
4769 being debugged terminates, @emph{all} local variables go out of scope,
4770 and so only watchpoints that watch global variables remain set. If you
4771 rerun the program, you will need to set all such watchpoints again. One
4772 way of doing that would be to set a code breakpoint at the entry to the
4773 @code{main} function and when it breaks, set all the watchpoints.
4774
4775 @cindex watchpoints and threads
4776 @cindex threads and watchpoints
4777 In multi-threaded programs, watchpoints will detect changes to the
4778 watched expression from every thread.
4779
4780 @quotation
4781 @emph{Warning:} In multi-threaded programs, software watchpoints
4782 have only limited usefulness. If @value{GDBN} creates a software
4783 watchpoint, it can only watch the value of an expression @emph{in a
4784 single thread}. If you are confident that the expression can only
4785 change due to the current thread's activity (and if you are also
4786 confident that no other thread can become current), then you can use
4787 software watchpoints as usual. However, @value{GDBN} may not notice
4788 when a non-current thread's activity changes the expression. (Hardware
4789 watchpoints, in contrast, watch an expression in all threads.)
4790 @end quotation
4791
4792 @xref{set remote hardware-watchpoint-limit}.
4793
4794 @node Set Catchpoints
4795 @subsection Setting Catchpoints
4796 @cindex catchpoints, setting
4797 @cindex exception handlers
4798 @cindex event handling
4799
4800 You can use @dfn{catchpoints} to cause the debugger to stop for certain
4801 kinds of program events, such as C@t{++} exceptions or the loading of a
4802 shared library. Use the @code{catch} command to set a catchpoint.
4803
4804 @table @code
4805 @kindex catch
4806 @item catch @var{event}
4807 Stop when @var{event} occurs. The @var{event} can be any of the following:
4808
4809 @table @code
4810 @item throw @r{[}@var{regexp}@r{]}
4811 @itemx rethrow @r{[}@var{regexp}@r{]}
4812 @itemx catch @r{[}@var{regexp}@r{]}
4813 @kindex catch throw
4814 @kindex catch rethrow
4815 @kindex catch catch
4816 @cindex stop on C@t{++} exceptions
4817 The throwing, re-throwing, or catching of a C@t{++} exception.
4818
4819 If @var{regexp} is given, then only exceptions whose type matches the
4820 regular expression will be caught.
4821
4822 @vindex $_exception@r{, convenience variable}
4823 The convenience variable @code{$_exception} is available at an
4824 exception-related catchpoint, on some systems. This holds the
4825 exception being thrown.
4826
4827 There are currently some limitations to C@t{++} exception handling in
4828 @value{GDBN}:
4829
4830 @itemize @bullet
4831 @item
4832 The support for these commands is system-dependent. Currently, only
4833 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4834 supported.
4835
4836 @item
4837 The regular expression feature and the @code{$_exception} convenience
4838 variable rely on the presence of some SDT probes in @code{libstdc++}.
4839 If these probes are not present, then these features cannot be used.
4840 These probes were first available in the GCC 4.8 release, but whether
4841 or not they are available in your GCC also depends on how it was
4842 built.
4843
4844 @item
4845 The @code{$_exception} convenience variable is only valid at the
4846 instruction at which an exception-related catchpoint is set.
4847
4848 @item
4849 When an exception-related catchpoint is hit, @value{GDBN} stops at a
4850 location in the system library which implements runtime exception
4851 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4852 (@pxref{Selection}) to get to your code.
4853
4854 @item
4855 If you call a function interactively, @value{GDBN} normally returns
4856 control to you when the function has finished executing. If the call
4857 raises an exception, however, the call may bypass the mechanism that
4858 returns control to you and cause your program either to abort or to
4859 simply continue running until it hits a breakpoint, catches a signal
4860 that @value{GDBN} is listening for, or exits. This is the case even if
4861 you set a catchpoint for the exception; catchpoints on exceptions are
4862 disabled within interactive calls. @xref{Calling}, for information on
4863 controlling this with @code{set unwind-on-terminating-exception}.
4864
4865 @item
4866 You cannot raise an exception interactively.
4867
4868 @item
4869 You cannot install an exception handler interactively.
4870 @end itemize
4871
4872 @item exception @r{[}@var{name}@r{]}
4873 @kindex catch exception
4874 @cindex Ada exception catching
4875 @cindex catch Ada exceptions
4876 An Ada exception being raised. If an exception name is specified
4877 at the end of the command (eg @code{catch exception Program_Error}),
4878 the debugger will stop only when this specific exception is raised.
4879 Otherwise, the debugger stops execution when any Ada exception is raised.
4880
4881 When inserting an exception catchpoint on a user-defined exception whose
4882 name is identical to one of the exceptions defined by the language, the
4883 fully qualified name must be used as the exception name. Otherwise,
4884 @value{GDBN} will assume that it should stop on the pre-defined exception
4885 rather than the user-defined one. For instance, assuming an exception
4886 called @code{Constraint_Error} is defined in package @code{Pck}, then
4887 the command to use to catch such exceptions is @kbd{catch exception
4888 Pck.Constraint_Error}.
4889
4890 @vindex $_ada_exception@r{, convenience variable}
4891 The convenience variable @code{$_ada_exception} holds the address of
4892 the exception being thrown. This can be useful when setting a
4893 condition for such a catchpoint.
4894
4895 @item exception unhandled
4896 @kindex catch exception unhandled
4897 An exception that was raised but is not handled by the program. The
4898 convenience variable @code{$_ada_exception} is set as for @code{catch
4899 exception}.
4900
4901 @item handlers @r{[}@var{name}@r{]}
4902 @kindex catch handlers
4903 @cindex Ada exception handlers catching
4904 @cindex catch Ada exceptions when handled
4905 An Ada exception being handled. If an exception name is
4906 specified at the end of the command
4907 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4908 only when this specific exception is handled.
4909 Otherwise, the debugger stops execution when any Ada exception is handled.
4910
4911 When inserting a handlers catchpoint on a user-defined
4912 exception whose name is identical to one of the exceptions
4913 defined by the language, the fully qualified name must be used
4914 as the exception name. Otherwise, @value{GDBN} will assume that it
4915 should stop on the pre-defined exception rather than the
4916 user-defined one. For instance, assuming an exception called
4917 @code{Constraint_Error} is defined in package @code{Pck}, then the
4918 command to use to catch such exceptions handling is
4919 @kbd{catch handlers Pck.Constraint_Error}.
4920
4921 The convenience variable @code{$_ada_exception} is set as for
4922 @code{catch exception}.
4923
4924 @item assert
4925 @kindex catch assert
4926 A failed Ada assertion. Note that the convenience variable
4927 @code{$_ada_exception} is @emph{not} set by this catchpoint.
4928
4929 @item exec
4930 @kindex catch exec
4931 @cindex break on fork/exec
4932 A call to @code{exec}.
4933
4934 @anchor{catch syscall}
4935 @item syscall
4936 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
4937 @kindex catch syscall
4938 @cindex break on a system call.
4939 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4940 syscall is a mechanism for application programs to request a service
4941 from the operating system (OS) or one of the OS system services.
4942 @value{GDBN} can catch some or all of the syscalls issued by the
4943 debuggee, and show the related information for each syscall. If no
4944 argument is specified, calls to and returns from all system calls
4945 will be caught.
4946
4947 @var{name} can be any system call name that is valid for the
4948 underlying OS. Just what syscalls are valid depends on the OS. On
4949 GNU and Unix systems, you can find the full list of valid syscall
4950 names on @file{/usr/include/asm/unistd.h}.
4951
4952 @c For MS-Windows, the syscall names and the corresponding numbers
4953 @c can be found, e.g., on this URL:
4954 @c http://www.metasploit.com/users/opcode/syscalls.html
4955 @c but we don't support Windows syscalls yet.
4956
4957 Normally, @value{GDBN} knows in advance which syscalls are valid for
4958 each OS, so you can use the @value{GDBN} command-line completion
4959 facilities (@pxref{Completion,, command completion}) to list the
4960 available choices.
4961
4962 You may also specify the system call numerically. A syscall's
4963 number is the value passed to the OS's syscall dispatcher to
4964 identify the requested service. When you specify the syscall by its
4965 name, @value{GDBN} uses its database of syscalls to convert the name
4966 into the corresponding numeric code, but using the number directly
4967 may be useful if @value{GDBN}'s database does not have the complete
4968 list of syscalls on your system (e.g., because @value{GDBN} lags
4969 behind the OS upgrades).
4970
4971 You may specify a group of related syscalls to be caught at once using
4972 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
4973 instance, on some platforms @value{GDBN} allows you to catch all
4974 network related syscalls, by passing the argument @code{group:network}
4975 to @code{catch syscall}. Note that not all syscall groups are
4976 available in every system. You can use the command completion
4977 facilities (@pxref{Completion,, command completion}) to list the
4978 syscall groups available on your environment.
4979
4980 The example below illustrates how this command works if you don't provide
4981 arguments to it:
4982
4983 @smallexample
4984 (@value{GDBP}) catch syscall
4985 Catchpoint 1 (syscall)
4986 (@value{GDBP}) r
4987 Starting program: /tmp/catch-syscall
4988
4989 Catchpoint 1 (call to syscall 'close'), \
4990 0xffffe424 in __kernel_vsyscall ()
4991 (@value{GDBP}) c
4992 Continuing.
4993
4994 Catchpoint 1 (returned from syscall 'close'), \
4995 0xffffe424 in __kernel_vsyscall ()
4996 (@value{GDBP})
4997 @end smallexample
4998
4999 Here is an example of catching a system call by name:
5000
5001 @smallexample
5002 (@value{GDBP}) catch syscall chroot
5003 Catchpoint 1 (syscall 'chroot' [61])
5004 (@value{GDBP}) r
5005 Starting program: /tmp/catch-syscall
5006
5007 Catchpoint 1 (call to syscall 'chroot'), \
5008 0xffffe424 in __kernel_vsyscall ()
5009 (@value{GDBP}) c
5010 Continuing.
5011
5012 Catchpoint 1 (returned from syscall 'chroot'), \
5013 0xffffe424 in __kernel_vsyscall ()
5014 (@value{GDBP})
5015 @end smallexample
5016
5017 An example of specifying a system call numerically. In the case
5018 below, the syscall number has a corresponding entry in the XML
5019 file, so @value{GDBN} finds its name and prints it:
5020
5021 @smallexample
5022 (@value{GDBP}) catch syscall 252
5023 Catchpoint 1 (syscall(s) 'exit_group')
5024 (@value{GDBP}) r
5025 Starting program: /tmp/catch-syscall
5026
5027 Catchpoint 1 (call to syscall 'exit_group'), \
5028 0xffffe424 in __kernel_vsyscall ()
5029 (@value{GDBP}) c
5030 Continuing.
5031
5032 Program exited normally.
5033 (@value{GDBP})
5034 @end smallexample
5035
5036 Here is an example of catching a syscall group:
5037
5038 @smallexample
5039 (@value{GDBP}) catch syscall group:process
5040 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5041 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5042 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5043 (@value{GDBP}) r
5044 Starting program: /tmp/catch-syscall
5045
5046 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5047 from /lib64/ld-linux-x86-64.so.2
5048
5049 (@value{GDBP}) c
5050 Continuing.
5051 @end smallexample
5052
5053 However, there can be situations when there is no corresponding name
5054 in XML file for that syscall number. In this case, @value{GDBN} prints
5055 a warning message saying that it was not able to find the syscall name,
5056 but the catchpoint will be set anyway. See the example below:
5057
5058 @smallexample
5059 (@value{GDBP}) catch syscall 764
5060 warning: The number '764' does not represent a known syscall.
5061 Catchpoint 2 (syscall 764)
5062 (@value{GDBP})
5063 @end smallexample
5064
5065 If you configure @value{GDBN} using the @samp{--without-expat} option,
5066 it will not be able to display syscall names. Also, if your
5067 architecture does not have an XML file describing its system calls,
5068 you will not be able to see the syscall names. It is important to
5069 notice that these two features are used for accessing the syscall
5070 name database. In either case, you will see a warning like this:
5071
5072 @smallexample
5073 (@value{GDBP}) catch syscall
5074 warning: Could not open "syscalls/i386-linux.xml"
5075 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5076 GDB will not be able to display syscall names.
5077 Catchpoint 1 (syscall)
5078 (@value{GDBP})
5079 @end smallexample
5080
5081 Of course, the file name will change depending on your architecture and system.
5082
5083 Still using the example above, you can also try to catch a syscall by its
5084 number. In this case, you would see something like:
5085
5086 @smallexample
5087 (@value{GDBP}) catch syscall 252
5088 Catchpoint 1 (syscall(s) 252)
5089 @end smallexample
5090
5091 Again, in this case @value{GDBN} would not be able to display syscall's names.
5092
5093 @item fork
5094 @kindex catch fork
5095 A call to @code{fork}.
5096
5097 @item vfork
5098 @kindex catch vfork
5099 A call to @code{vfork}.
5100
5101 @item load @r{[}@var{regexp}@r{]}
5102 @itemx unload @r{[}@var{regexp}@r{]}
5103 @kindex catch load
5104 @kindex catch unload
5105 The loading or unloading of a shared library. If @var{regexp} is
5106 given, then the catchpoint will stop only if the regular expression
5107 matches one of the affected libraries.
5108
5109 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5110 @kindex catch signal
5111 The delivery of a signal.
5112
5113 With no arguments, this catchpoint will catch any signal that is not
5114 used internally by @value{GDBN}, specifically, all signals except
5115 @samp{SIGTRAP} and @samp{SIGINT}.
5116
5117 With the argument @samp{all}, all signals, including those used by
5118 @value{GDBN}, will be caught. This argument cannot be used with other
5119 signal names.
5120
5121 Otherwise, the arguments are a list of signal names as given to
5122 @code{handle} (@pxref{Signals}). Only signals specified in this list
5123 will be caught.
5124
5125 One reason that @code{catch signal} can be more useful than
5126 @code{handle} is that you can attach commands and conditions to the
5127 catchpoint.
5128
5129 When a signal is caught by a catchpoint, the signal's @code{stop} and
5130 @code{print} settings, as specified by @code{handle}, are ignored.
5131 However, whether the signal is still delivered to the inferior depends
5132 on the @code{pass} setting; this can be changed in the catchpoint's
5133 commands.
5134
5135 @end table
5136
5137 @item tcatch @var{event}
5138 @kindex tcatch
5139 Set a catchpoint that is enabled only for one stop. The catchpoint is
5140 automatically deleted after the first time the event is caught.
5141
5142 @end table
5143
5144 Use the @code{info break} command to list the current catchpoints.
5145
5146
5147 @node Delete Breaks
5148 @subsection Deleting Breakpoints
5149
5150 @cindex clearing breakpoints, watchpoints, catchpoints
5151 @cindex deleting breakpoints, watchpoints, catchpoints
5152 It is often necessary to eliminate a breakpoint, watchpoint, or
5153 catchpoint once it has done its job and you no longer want your program
5154 to stop there. This is called @dfn{deleting} the breakpoint. A
5155 breakpoint that has been deleted no longer exists; it is forgotten.
5156
5157 With the @code{clear} command you can delete breakpoints according to
5158 where they are in your program. With the @code{delete} command you can
5159 delete individual breakpoints, watchpoints, or catchpoints by specifying
5160 their breakpoint numbers.
5161
5162 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5163 automatically ignores breakpoints on the first instruction to be executed
5164 when you continue execution without changing the execution address.
5165
5166 @table @code
5167 @kindex clear
5168 @item clear
5169 Delete any breakpoints at the next instruction to be executed in the
5170 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5171 the innermost frame is selected, this is a good way to delete a
5172 breakpoint where your program just stopped.
5173
5174 @item clear @var{location}
5175 Delete any breakpoints set at the specified @var{location}.
5176 @xref{Specify Location}, for the various forms of @var{location}; the
5177 most useful ones are listed below:
5178
5179 @table @code
5180 @item clear @var{function}
5181 @itemx clear @var{filename}:@var{function}
5182 Delete any breakpoints set at entry to the named @var{function}.
5183
5184 @item clear @var{linenum}
5185 @itemx clear @var{filename}:@var{linenum}
5186 Delete any breakpoints set at or within the code of the specified
5187 @var{linenum} of the specified @var{filename}.
5188 @end table
5189
5190 @cindex delete breakpoints
5191 @kindex delete
5192 @kindex d @r{(@code{delete})}
5193 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5194 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5195 list specified as argument. If no argument is specified, delete all
5196 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5197 confirm off}). You can abbreviate this command as @code{d}.
5198 @end table
5199
5200 @node Disabling
5201 @subsection Disabling Breakpoints
5202
5203 @cindex enable/disable a breakpoint
5204 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5205 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5206 it had been deleted, but remembers the information on the breakpoint so
5207 that you can @dfn{enable} it again later.
5208
5209 You disable and enable breakpoints, watchpoints, and catchpoints with
5210 the @code{enable} and @code{disable} commands, optionally specifying
5211 one or more breakpoint numbers as arguments. Use @code{info break} to
5212 print a list of all breakpoints, watchpoints, and catchpoints if you
5213 do not know which numbers to use.
5214
5215 Disabling and enabling a breakpoint that has multiple locations
5216 affects all of its locations.
5217
5218 A breakpoint, watchpoint, or catchpoint can have any of several
5219 different states of enablement:
5220
5221 @itemize @bullet
5222 @item
5223 Enabled. The breakpoint stops your program. A breakpoint set
5224 with the @code{break} command starts out in this state.
5225 @item
5226 Disabled. The breakpoint has no effect on your program.
5227 @item
5228 Enabled once. The breakpoint stops your program, but then becomes
5229 disabled.
5230 @item
5231 Enabled for a count. The breakpoint stops your program for the next
5232 N times, then becomes disabled.
5233 @item
5234 Enabled for deletion. The breakpoint stops your program, but
5235 immediately after it does so it is deleted permanently. A breakpoint
5236 set with the @code{tbreak} command starts out in this state.
5237 @end itemize
5238
5239 You can use the following commands to enable or disable breakpoints,
5240 watchpoints, and catchpoints:
5241
5242 @table @code
5243 @kindex disable
5244 @kindex dis @r{(@code{disable})}
5245 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5246 Disable the specified breakpoints---or all breakpoints, if none are
5247 listed. A disabled breakpoint has no effect but is not forgotten. All
5248 options such as ignore-counts, conditions and commands are remembered in
5249 case the breakpoint is enabled again later. You may abbreviate
5250 @code{disable} as @code{dis}.
5251
5252 @kindex enable
5253 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5254 Enable the specified breakpoints (or all defined breakpoints). They
5255 become effective once again in stopping your program.
5256
5257 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5258 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5259 of these breakpoints immediately after stopping your program.
5260
5261 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5262 Enable the specified breakpoints temporarily. @value{GDBN} records
5263 @var{count} with each of the specified breakpoints, and decrements a
5264 breakpoint's count when it is hit. When any count reaches 0,
5265 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5266 count (@pxref{Conditions, ,Break Conditions}), that will be
5267 decremented to 0 before @var{count} is affected.
5268
5269 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5270 Enable the specified breakpoints to work once, then die. @value{GDBN}
5271 deletes any of these breakpoints as soon as your program stops there.
5272 Breakpoints set by the @code{tbreak} command start out in this state.
5273 @end table
5274
5275 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5276 @c confusing: tbreak is also initially enabled.
5277 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5278 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5279 subsequently, they become disabled or enabled only when you use one of
5280 the commands above. (The command @code{until} can set and delete a
5281 breakpoint of its own, but it does not change the state of your other
5282 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5283 Stepping}.)
5284
5285 @node Conditions
5286 @subsection Break Conditions
5287 @cindex conditional breakpoints
5288 @cindex breakpoint conditions
5289
5290 @c FIXME what is scope of break condition expr? Context where wanted?
5291 @c in particular for a watchpoint?
5292 The simplest sort of breakpoint breaks every time your program reaches a
5293 specified place. You can also specify a @dfn{condition} for a
5294 breakpoint. A condition is just a Boolean expression in your
5295 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5296 a condition evaluates the expression each time your program reaches it,
5297 and your program stops only if the condition is @emph{true}.
5298
5299 This is the converse of using assertions for program validation; in that
5300 situation, you want to stop when the assertion is violated---that is,
5301 when the condition is false. In C, if you want to test an assertion expressed
5302 by the condition @var{assert}, you should set the condition
5303 @samp{! @var{assert}} on the appropriate breakpoint.
5304
5305 Conditions are also accepted for watchpoints; you may not need them,
5306 since a watchpoint is inspecting the value of an expression anyhow---but
5307 it might be simpler, say, to just set a watchpoint on a variable name,
5308 and specify a condition that tests whether the new value is an interesting
5309 one.
5310
5311 Break conditions can have side effects, and may even call functions in
5312 your program. This can be useful, for example, to activate functions
5313 that log program progress, or to use your own print functions to
5314 format special data structures. The effects are completely predictable
5315 unless there is another enabled breakpoint at the same address. (In
5316 that case, @value{GDBN} might see the other breakpoint first and stop your
5317 program without checking the condition of this one.) Note that
5318 breakpoint commands are usually more convenient and flexible than break
5319 conditions for the
5320 purpose of performing side effects when a breakpoint is reached
5321 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5322
5323 Breakpoint conditions can also be evaluated on the target's side if
5324 the target supports it. Instead of evaluating the conditions locally,
5325 @value{GDBN} encodes the expression into an agent expression
5326 (@pxref{Agent Expressions}) suitable for execution on the target,
5327 independently of @value{GDBN}. Global variables become raw memory
5328 locations, locals become stack accesses, and so forth.
5329
5330 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5331 when its condition evaluates to true. This mechanism may provide faster
5332 response times depending on the performance characteristics of the target
5333 since it does not need to keep @value{GDBN} informed about
5334 every breakpoint trigger, even those with false conditions.
5335
5336 Break conditions can be specified when a breakpoint is set, by using
5337 @samp{if} in the arguments to the @code{break} command. @xref{Set
5338 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5339 with the @code{condition} command.
5340
5341 You can also use the @code{if} keyword with the @code{watch} command.
5342 The @code{catch} command does not recognize the @code{if} keyword;
5343 @code{condition} is the only way to impose a further condition on a
5344 catchpoint.
5345
5346 @table @code
5347 @kindex condition
5348 @item condition @var{bnum} @var{expression}
5349 Specify @var{expression} as the break condition for breakpoint,
5350 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5351 breakpoint @var{bnum} stops your program only if the value of
5352 @var{expression} is true (nonzero, in C). When you use
5353 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5354 syntactic correctness, and to determine whether symbols in it have
5355 referents in the context of your breakpoint. If @var{expression} uses
5356 symbols not referenced in the context of the breakpoint, @value{GDBN}
5357 prints an error message:
5358
5359 @smallexample
5360 No symbol "foo" in current context.
5361 @end smallexample
5362
5363 @noindent
5364 @value{GDBN} does
5365 not actually evaluate @var{expression} at the time the @code{condition}
5366 command (or a command that sets a breakpoint with a condition, like
5367 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5368
5369 @item condition @var{bnum}
5370 Remove the condition from breakpoint number @var{bnum}. It becomes
5371 an ordinary unconditional breakpoint.
5372 @end table
5373
5374 @cindex ignore count (of breakpoint)
5375 A special case of a breakpoint condition is to stop only when the
5376 breakpoint has been reached a certain number of times. This is so
5377 useful that there is a special way to do it, using the @dfn{ignore
5378 count} of the breakpoint. Every breakpoint has an ignore count, which
5379 is an integer. Most of the time, the ignore count is zero, and
5380 therefore has no effect. But if your program reaches a breakpoint whose
5381 ignore count is positive, then instead of stopping, it just decrements
5382 the ignore count by one and continues. As a result, if the ignore count
5383 value is @var{n}, the breakpoint does not stop the next @var{n} times
5384 your program reaches it.
5385
5386 @table @code
5387 @kindex ignore
5388 @item ignore @var{bnum} @var{count}
5389 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5390 The next @var{count} times the breakpoint is reached, your program's
5391 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5392 takes no action.
5393
5394 To make the breakpoint stop the next time it is reached, specify
5395 a count of zero.
5396
5397 When you use @code{continue} to resume execution of your program from a
5398 breakpoint, you can specify an ignore count directly as an argument to
5399 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5400 Stepping,,Continuing and Stepping}.
5401
5402 If a breakpoint has a positive ignore count and a condition, the
5403 condition is not checked. Once the ignore count reaches zero,
5404 @value{GDBN} resumes checking the condition.
5405
5406 You could achieve the effect of the ignore count with a condition such
5407 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5408 is decremented each time. @xref{Convenience Vars, ,Convenience
5409 Variables}.
5410 @end table
5411
5412 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5413
5414
5415 @node Break Commands
5416 @subsection Breakpoint Command Lists
5417
5418 @cindex breakpoint commands
5419 You can give any breakpoint (or watchpoint or catchpoint) a series of
5420 commands to execute when your program stops due to that breakpoint. For
5421 example, you might want to print the values of certain expressions, or
5422 enable other breakpoints.
5423
5424 @table @code
5425 @kindex commands
5426 @kindex end@r{ (breakpoint commands)}
5427 @item commands @r{[}@var{list}@dots{}@r{]}
5428 @itemx @dots{} @var{command-list} @dots{}
5429 @itemx end
5430 Specify a list of commands for the given breakpoints. The commands
5431 themselves appear on the following lines. Type a line containing just
5432 @code{end} to terminate the commands.
5433
5434 To remove all commands from a breakpoint, type @code{commands} and
5435 follow it immediately with @code{end}; that is, give no commands.
5436
5437 With no argument, @code{commands} refers to the last breakpoint,
5438 watchpoint, or catchpoint set (not to the breakpoint most recently
5439 encountered). If the most recent breakpoints were set with a single
5440 command, then the @code{commands} will apply to all the breakpoints
5441 set by that command. This applies to breakpoints set by
5442 @code{rbreak}, and also applies when a single @code{break} command
5443 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5444 Expressions}).
5445 @end table
5446
5447 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5448 disabled within a @var{command-list}.
5449
5450 You can use breakpoint commands to start your program up again. Simply
5451 use the @code{continue} command, or @code{step}, or any other command
5452 that resumes execution.
5453
5454 Any other commands in the command list, after a command that resumes
5455 execution, are ignored. This is because any time you resume execution
5456 (even with a simple @code{next} or @code{step}), you may encounter
5457 another breakpoint---which could have its own command list, leading to
5458 ambiguities about which list to execute.
5459
5460 @kindex silent
5461 If the first command you specify in a command list is @code{silent}, the
5462 usual message about stopping at a breakpoint is not printed. This may
5463 be desirable for breakpoints that are to print a specific message and
5464 then continue. If none of the remaining commands print anything, you
5465 see no sign that the breakpoint was reached. @code{silent} is
5466 meaningful only at the beginning of a breakpoint command list.
5467
5468 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5469 print precisely controlled output, and are often useful in silent
5470 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5471
5472 For example, here is how you could use breakpoint commands to print the
5473 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5474
5475 @smallexample
5476 break foo if x>0
5477 commands
5478 silent
5479 printf "x is %d\n",x
5480 cont
5481 end
5482 @end smallexample
5483
5484 One application for breakpoint commands is to compensate for one bug so
5485 you can test for another. Put a breakpoint just after the erroneous line
5486 of code, give it a condition to detect the case in which something
5487 erroneous has been done, and give it commands to assign correct values
5488 to any variables that need them. End with the @code{continue} command
5489 so that your program does not stop, and start with the @code{silent}
5490 command so that no output is produced. Here is an example:
5491
5492 @smallexample
5493 break 403
5494 commands
5495 silent
5496 set x = y + 4
5497 cont
5498 end
5499 @end smallexample
5500
5501 @node Dynamic Printf
5502 @subsection Dynamic Printf
5503
5504 @cindex dynamic printf
5505 @cindex dprintf
5506 The dynamic printf command @code{dprintf} combines a breakpoint with
5507 formatted printing of your program's data to give you the effect of
5508 inserting @code{printf} calls into your program on-the-fly, without
5509 having to recompile it.
5510
5511 In its most basic form, the output goes to the GDB console. However,
5512 you can set the variable @code{dprintf-style} for alternate handling.
5513 For instance, you can ask to format the output by calling your
5514 program's @code{printf} function. This has the advantage that the
5515 characters go to the program's output device, so they can recorded in
5516 redirects to files and so forth.
5517
5518 If you are doing remote debugging with a stub or agent, you can also
5519 ask to have the printf handled by the remote agent. In addition to
5520 ensuring that the output goes to the remote program's device along
5521 with any other output the program might produce, you can also ask that
5522 the dprintf remain active even after disconnecting from the remote
5523 target. Using the stub/agent is also more efficient, as it can do
5524 everything without needing to communicate with @value{GDBN}.
5525
5526 @table @code
5527 @kindex dprintf
5528 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5529 Whenever execution reaches @var{location}, print the values of one or
5530 more @var{expressions} under the control of the string @var{template}.
5531 To print several values, separate them with commas.
5532
5533 @item set dprintf-style @var{style}
5534 Set the dprintf output to be handled in one of several different
5535 styles enumerated below. A change of style affects all existing
5536 dynamic printfs immediately. (If you need individual control over the
5537 print commands, simply define normal breakpoints with
5538 explicitly-supplied command lists.)
5539
5540 @table @code
5541 @item gdb
5542 @kindex dprintf-style gdb
5543 Handle the output using the @value{GDBN} @code{printf} command.
5544
5545 @item call
5546 @kindex dprintf-style call
5547 Handle the output by calling a function in your program (normally
5548 @code{printf}).
5549
5550 @item agent
5551 @kindex dprintf-style agent
5552 Have the remote debugging agent (such as @code{gdbserver}) handle
5553 the output itself. This style is only available for agents that
5554 support running commands on the target.
5555 @end table
5556
5557 @item set dprintf-function @var{function}
5558 Set the function to call if the dprintf style is @code{call}. By
5559 default its value is @code{printf}. You may set it to any expression.
5560 that @value{GDBN} can evaluate to a function, as per the @code{call}
5561 command.
5562
5563 @item set dprintf-channel @var{channel}
5564 Set a ``channel'' for dprintf. If set to a non-empty value,
5565 @value{GDBN} will evaluate it as an expression and pass the result as
5566 a first argument to the @code{dprintf-function}, in the manner of
5567 @code{fprintf} and similar functions. Otherwise, the dprintf format
5568 string will be the first argument, in the manner of @code{printf}.
5569
5570 As an example, if you wanted @code{dprintf} output to go to a logfile
5571 that is a standard I/O stream assigned to the variable @code{mylog},
5572 you could do the following:
5573
5574 @example
5575 (gdb) set dprintf-style call
5576 (gdb) set dprintf-function fprintf
5577 (gdb) set dprintf-channel mylog
5578 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5579 Dprintf 1 at 0x123456: file main.c, line 25.
5580 (gdb) info break
5581 1 dprintf keep y 0x00123456 in main at main.c:25
5582 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5583 continue
5584 (gdb)
5585 @end example
5586
5587 Note that the @code{info break} displays the dynamic printf commands
5588 as normal breakpoint commands; you can thus easily see the effect of
5589 the variable settings.
5590
5591 @item set disconnected-dprintf on
5592 @itemx set disconnected-dprintf off
5593 @kindex set disconnected-dprintf
5594 Choose whether @code{dprintf} commands should continue to run if
5595 @value{GDBN} has disconnected from the target. This only applies
5596 if the @code{dprintf-style} is @code{agent}.
5597
5598 @item show disconnected-dprintf off
5599 @kindex show disconnected-dprintf
5600 Show the current choice for disconnected @code{dprintf}.
5601
5602 @end table
5603
5604 @value{GDBN} does not check the validity of function and channel,
5605 relying on you to supply values that are meaningful for the contexts
5606 in which they are being used. For instance, the function and channel
5607 may be the values of local variables, but if that is the case, then
5608 all enabled dynamic prints must be at locations within the scope of
5609 those locals. If evaluation fails, @value{GDBN} will report an error.
5610
5611 @node Save Breakpoints
5612 @subsection How to save breakpoints to a file
5613
5614 To save breakpoint definitions to a file use the @w{@code{save
5615 breakpoints}} command.
5616
5617 @table @code
5618 @kindex save breakpoints
5619 @cindex save breakpoints to a file for future sessions
5620 @item save breakpoints [@var{filename}]
5621 This command saves all current breakpoint definitions together with
5622 their commands and ignore counts, into a file @file{@var{filename}}
5623 suitable for use in a later debugging session. This includes all
5624 types of breakpoints (breakpoints, watchpoints, catchpoints,
5625 tracepoints). To read the saved breakpoint definitions, use the
5626 @code{source} command (@pxref{Command Files}). Note that watchpoints
5627 with expressions involving local variables may fail to be recreated
5628 because it may not be possible to access the context where the
5629 watchpoint is valid anymore. Because the saved breakpoint definitions
5630 are simply a sequence of @value{GDBN} commands that recreate the
5631 breakpoints, you can edit the file in your favorite editing program,
5632 and remove the breakpoint definitions you're not interested in, or
5633 that can no longer be recreated.
5634 @end table
5635
5636 @node Static Probe Points
5637 @subsection Static Probe Points
5638
5639 @cindex static probe point, SystemTap
5640 @cindex static probe point, DTrace
5641 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5642 for Statically Defined Tracing, and the probes are designed to have a tiny
5643 runtime code and data footprint, and no dynamic relocations.
5644
5645 Currently, the following types of probes are supported on
5646 ELF-compatible systems:
5647
5648 @itemize @bullet
5649
5650 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5651 @acronym{SDT} probes@footnote{See
5652 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5653 for more information on how to add @code{SystemTap} @acronym{SDT}
5654 probes in your applications.}. @code{SystemTap} probes are usable
5655 from assembly, C and C@t{++} languages@footnote{See
5656 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5657 for a good reference on how the @acronym{SDT} probes are implemented.}.
5658
5659 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5660 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5661 C@t{++} languages.
5662 @end itemize
5663
5664 @cindex semaphores on static probe points
5665 Some @code{SystemTap} probes have an associated semaphore variable;
5666 for instance, this happens automatically if you defined your probe
5667 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5668 @value{GDBN} will automatically enable it when you specify a
5669 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5670 breakpoint at a probe's location by some other method (e.g.,
5671 @code{break file:line}), then @value{GDBN} will not automatically set
5672 the semaphore. @code{DTrace} probes do not support semaphores.
5673
5674 You can examine the available static static probes using @code{info
5675 probes}, with optional arguments:
5676
5677 @table @code
5678 @kindex info probes
5679 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5680 If given, @var{type} is either @code{stap} for listing
5681 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5682 probes. If omitted all probes are listed regardless of their types.
5683
5684 If given, @var{provider} is a regular expression used to match against provider
5685 names when selecting which probes to list. If omitted, probes by all
5686 probes from all providers are listed.
5687
5688 If given, @var{name} is a regular expression to match against probe names
5689 when selecting which probes to list. If omitted, probe names are not
5690 considered when deciding whether to display them.
5691
5692 If given, @var{objfile} is a regular expression used to select which
5693 object files (executable or shared libraries) to examine. If not
5694 given, all object files are considered.
5695
5696 @item info probes all
5697 List the available static probes, from all types.
5698 @end table
5699
5700 @cindex enabling and disabling probes
5701 Some probe points can be enabled and/or disabled. The effect of
5702 enabling or disabling a probe depends on the type of probe being
5703 handled. Some @code{DTrace} probes can be enabled or
5704 disabled, but @code{SystemTap} probes cannot be disabled.
5705
5706 You can enable (or disable) one or more probes using the following
5707 commands, with optional arguments:
5708
5709 @table @code
5710 @kindex enable probes
5711 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5712 If given, @var{provider} is a regular expression used to match against
5713 provider names when selecting which probes to enable. If omitted,
5714 all probes from all providers are enabled.
5715
5716 If given, @var{name} is a regular expression to match against probe
5717 names when selecting which probes to enable. If omitted, probe names
5718 are not considered when deciding whether to enable them.
5719
5720 If given, @var{objfile} is a regular expression used to select which
5721 object files (executable or shared libraries) to examine. If not
5722 given, all object files are considered.
5723
5724 @kindex disable probes
5725 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5726 See the @code{enable probes} command above for a description of the
5727 optional arguments accepted by this command.
5728 @end table
5729
5730 @vindex $_probe_arg@r{, convenience variable}
5731 A probe may specify up to twelve arguments. These are available at the
5732 point at which the probe is defined---that is, when the current PC is
5733 at the probe's location. The arguments are available using the
5734 convenience variables (@pxref{Convenience Vars})
5735 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5736 probes each probe argument is an integer of the appropriate size;
5737 types are not preserved. In @code{DTrace} probes types are preserved
5738 provided that they are recognized as such by @value{GDBN}; otherwise
5739 the value of the probe argument will be a long integer. The
5740 convenience variable @code{$_probe_argc} holds the number of arguments
5741 at the current probe point.
5742
5743 These variables are always available, but attempts to access them at
5744 any location other than a probe point will cause @value{GDBN} to give
5745 an error message.
5746
5747
5748 @c @ifclear BARETARGET
5749 @node Error in Breakpoints
5750 @subsection ``Cannot insert breakpoints''
5751
5752 If you request too many active hardware-assisted breakpoints and
5753 watchpoints, you will see this error message:
5754
5755 @c FIXME: the precise wording of this message may change; the relevant
5756 @c source change is not committed yet (Sep 3, 1999).
5757 @smallexample
5758 Stopped; cannot insert breakpoints.
5759 You may have requested too many hardware breakpoints and watchpoints.
5760 @end smallexample
5761
5762 @noindent
5763 This message is printed when you attempt to resume the program, since
5764 only then @value{GDBN} knows exactly how many hardware breakpoints and
5765 watchpoints it needs to insert.
5766
5767 When this message is printed, you need to disable or remove some of the
5768 hardware-assisted breakpoints and watchpoints, and then continue.
5769
5770 @node Breakpoint-related Warnings
5771 @subsection ``Breakpoint address adjusted...''
5772 @cindex breakpoint address adjusted
5773
5774 Some processor architectures place constraints on the addresses at
5775 which breakpoints may be placed. For architectures thus constrained,
5776 @value{GDBN} will attempt to adjust the breakpoint's address to comply
5777 with the constraints dictated by the architecture.
5778
5779 One example of such an architecture is the Fujitsu FR-V. The FR-V is
5780 a VLIW architecture in which a number of RISC-like instructions may be
5781 bundled together for parallel execution. The FR-V architecture
5782 constrains the location of a breakpoint instruction within such a
5783 bundle to the instruction with the lowest address. @value{GDBN}
5784 honors this constraint by adjusting a breakpoint's address to the
5785 first in the bundle.
5786
5787 It is not uncommon for optimized code to have bundles which contain
5788 instructions from different source statements, thus it may happen that
5789 a breakpoint's address will be adjusted from one source statement to
5790 another. Since this adjustment may significantly alter @value{GDBN}'s
5791 breakpoint related behavior from what the user expects, a warning is
5792 printed when the breakpoint is first set and also when the breakpoint
5793 is hit.
5794
5795 A warning like the one below is printed when setting a breakpoint
5796 that's been subject to address adjustment:
5797
5798 @smallexample
5799 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5800 @end smallexample
5801
5802 Such warnings are printed both for user settable and @value{GDBN}'s
5803 internal breakpoints. If you see one of these warnings, you should
5804 verify that a breakpoint set at the adjusted address will have the
5805 desired affect. If not, the breakpoint in question may be removed and
5806 other breakpoints may be set which will have the desired behavior.
5807 E.g., it may be sufficient to place the breakpoint at a later
5808 instruction. A conditional breakpoint may also be useful in some
5809 cases to prevent the breakpoint from triggering too often.
5810
5811 @value{GDBN} will also issue a warning when stopping at one of these
5812 adjusted breakpoints:
5813
5814 @smallexample
5815 warning: Breakpoint 1 address previously adjusted from 0x00010414
5816 to 0x00010410.
5817 @end smallexample
5818
5819 When this warning is encountered, it may be too late to take remedial
5820 action except in cases where the breakpoint is hit earlier or more
5821 frequently than expected.
5822
5823 @node Continuing and Stepping
5824 @section Continuing and Stepping
5825
5826 @cindex stepping
5827 @cindex continuing
5828 @cindex resuming execution
5829 @dfn{Continuing} means resuming program execution until your program
5830 completes normally. In contrast, @dfn{stepping} means executing just
5831 one more ``step'' of your program, where ``step'' may mean either one
5832 line of source code, or one machine instruction (depending on what
5833 particular command you use). Either when continuing or when stepping,
5834 your program may stop even sooner, due to a breakpoint or a signal. (If
5835 it stops due to a signal, you may want to use @code{handle}, or use
5836 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5837 or you may step into the signal's handler (@pxref{stepping and signal
5838 handlers}).)
5839
5840 @table @code
5841 @kindex continue
5842 @kindex c @r{(@code{continue})}
5843 @kindex fg @r{(resume foreground execution)}
5844 @item continue @r{[}@var{ignore-count}@r{]}
5845 @itemx c @r{[}@var{ignore-count}@r{]}
5846 @itemx fg @r{[}@var{ignore-count}@r{]}
5847 Resume program execution, at the address where your program last stopped;
5848 any breakpoints set at that address are bypassed. The optional argument
5849 @var{ignore-count} allows you to specify a further number of times to
5850 ignore a breakpoint at this location; its effect is like that of
5851 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
5852
5853 The argument @var{ignore-count} is meaningful only when your program
5854 stopped due to a breakpoint. At other times, the argument to
5855 @code{continue} is ignored.
5856
5857 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5858 debugged program is deemed to be the foreground program) are provided
5859 purely for convenience, and have exactly the same behavior as
5860 @code{continue}.
5861 @end table
5862
5863 To resume execution at a different place, you can use @code{return}
5864 (@pxref{Returning, ,Returning from a Function}) to go back to the
5865 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
5866 Different Address}) to go to an arbitrary location in your program.
5867
5868 A typical technique for using stepping is to set a breakpoint
5869 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
5870 beginning of the function or the section of your program where a problem
5871 is believed to lie, run your program until it stops at that breakpoint,
5872 and then step through the suspect area, examining the variables that are
5873 interesting, until you see the problem happen.
5874
5875 @table @code
5876 @kindex step
5877 @kindex s @r{(@code{step})}
5878 @item step
5879 Continue running your program until control reaches a different source
5880 line, then stop it and return control to @value{GDBN}. This command is
5881 abbreviated @code{s}.
5882
5883 @quotation
5884 @c "without debugging information" is imprecise; actually "without line
5885 @c numbers in the debugging information". (gcc -g1 has debugging info but
5886 @c not line numbers). But it seems complex to try to make that
5887 @c distinction here.
5888 @emph{Warning:} If you use the @code{step} command while control is
5889 within a function that was compiled without debugging information,
5890 execution proceeds until control reaches a function that does have
5891 debugging information. Likewise, it will not step into a function which
5892 is compiled without debugging information. To step through functions
5893 without debugging information, use the @code{stepi} command, described
5894 below.
5895 @end quotation
5896
5897 The @code{step} command only stops at the first instruction of a source
5898 line. This prevents the multiple stops that could otherwise occur in
5899 @code{switch} statements, @code{for} loops, etc. @code{step} continues
5900 to stop if a function that has debugging information is called within
5901 the line. In other words, @code{step} @emph{steps inside} any functions
5902 called within the line.
5903
5904 Also, the @code{step} command only enters a function if there is line
5905 number information for the function. Otherwise it acts like the
5906 @code{next} command. This avoids problems when using @code{cc -gl}
5907 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5908 was any debugging information about the routine.
5909
5910 @item step @var{count}
5911 Continue running as in @code{step}, but do so @var{count} times. If a
5912 breakpoint is reached, or a signal not related to stepping occurs before
5913 @var{count} steps, stepping stops right away.
5914
5915 @kindex next
5916 @kindex n @r{(@code{next})}
5917 @item next @r{[}@var{count}@r{]}
5918 Continue to the next source line in the current (innermost) stack frame.
5919 This is similar to @code{step}, but function calls that appear within
5920 the line of code are executed without stopping. Execution stops when
5921 control reaches a different line of code at the original stack level
5922 that was executing when you gave the @code{next} command. This command
5923 is abbreviated @code{n}.
5924
5925 An argument @var{count} is a repeat count, as for @code{step}.
5926
5927
5928 @c FIX ME!! Do we delete this, or is there a way it fits in with
5929 @c the following paragraph? --- Vctoria
5930 @c
5931 @c @code{next} within a function that lacks debugging information acts like
5932 @c @code{step}, but any function calls appearing within the code of the
5933 @c function are executed without stopping.
5934
5935 The @code{next} command only stops at the first instruction of a
5936 source line. This prevents multiple stops that could otherwise occur in
5937 @code{switch} statements, @code{for} loops, etc.
5938
5939 @kindex set step-mode
5940 @item set step-mode
5941 @cindex functions without line info, and stepping
5942 @cindex stepping into functions with no line info
5943 @itemx set step-mode on
5944 The @code{set step-mode on} command causes the @code{step} command to
5945 stop at the first instruction of a function which contains no debug line
5946 information rather than stepping over it.
5947
5948 This is useful in cases where you may be interested in inspecting the
5949 machine instructions of a function which has no symbolic info and do not
5950 want @value{GDBN} to automatically skip over this function.
5951
5952 @item set step-mode off
5953 Causes the @code{step} command to step over any functions which contains no
5954 debug information. This is the default.
5955
5956 @item show step-mode
5957 Show whether @value{GDBN} will stop in or step over functions without
5958 source line debug information.
5959
5960 @kindex finish
5961 @kindex fin @r{(@code{finish})}
5962 @item finish
5963 Continue running until just after function in the selected stack frame
5964 returns. Print the returned value (if any). This command can be
5965 abbreviated as @code{fin}.
5966
5967 Contrast this with the @code{return} command (@pxref{Returning,
5968 ,Returning from a Function}).
5969
5970 @kindex set print finish
5971 @kindex show print finish
5972 @item set print finish @r{[}on|off@r{]}
5973 @itemx show print finish
5974 By default the @code{finish} command will show the value that is
5975 returned by the function. This can be disabled using @code{set print
5976 finish off}. When disabled, the value is still entered into the value
5977 history (@pxref{Value History}), but not displayed.
5978
5979 @kindex until
5980 @kindex u @r{(@code{until})}
5981 @cindex run until specified location
5982 @item until
5983 @itemx u
5984 Continue running until a source line past the current line, in the
5985 current stack frame, is reached. This command is used to avoid single
5986 stepping through a loop more than once. It is like the @code{next}
5987 command, except that when @code{until} encounters a jump, it
5988 automatically continues execution until the program counter is greater
5989 than the address of the jump.
5990
5991 This means that when you reach the end of a loop after single stepping
5992 though it, @code{until} makes your program continue execution until it
5993 exits the loop. In contrast, a @code{next} command at the end of a loop
5994 simply steps back to the beginning of the loop, which forces you to step
5995 through the next iteration.
5996
5997 @code{until} always stops your program if it attempts to exit the current
5998 stack frame.
5999
6000 @code{until} may produce somewhat counterintuitive results if the order
6001 of machine code does not match the order of the source lines. For
6002 example, in the following excerpt from a debugging session, the @code{f}
6003 (@code{frame}) command shows that execution is stopped at line
6004 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6005
6006 @smallexample
6007 (@value{GDBP}) f
6008 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6009 206 expand_input();
6010 (@value{GDBP}) until
6011 195 for ( ; argc > 0; NEXTARG) @{
6012 @end smallexample
6013
6014 This happened because, for execution efficiency, the compiler had
6015 generated code for the loop closure test at the end, rather than the
6016 start, of the loop---even though the test in a C @code{for}-loop is
6017 written before the body of the loop. The @code{until} command appeared
6018 to step back to the beginning of the loop when it advanced to this
6019 expression; however, it has not really gone to an earlier
6020 statement---not in terms of the actual machine code.
6021
6022 @code{until} with no argument works by means of single
6023 instruction stepping, and hence is slower than @code{until} with an
6024 argument.
6025
6026 @item until @var{location}
6027 @itemx u @var{location}
6028 Continue running your program until either the specified @var{location} is
6029 reached, or the current stack frame returns. The location is any of
6030 the forms described in @ref{Specify Location}.
6031 This form of the command uses temporary breakpoints, and
6032 hence is quicker than @code{until} without an argument. The specified
6033 location is actually reached only if it is in the current frame. This
6034 implies that @code{until} can be used to skip over recursive function
6035 invocations. For instance in the code below, if the current location is
6036 line @code{96}, issuing @code{until 99} will execute the program up to
6037 line @code{99} in the same invocation of factorial, i.e., after the inner
6038 invocations have returned.
6039
6040 @smallexample
6041 94 int factorial (int value)
6042 95 @{
6043 96 if (value > 1) @{
6044 97 value *= factorial (value - 1);
6045 98 @}
6046 99 return (value);
6047 100 @}
6048 @end smallexample
6049
6050
6051 @kindex advance @var{location}
6052 @item advance @var{location}
6053 Continue running the program up to the given @var{location}. An argument is
6054 required, which should be of one of the forms described in
6055 @ref{Specify Location}.
6056 Execution will also stop upon exit from the current stack
6057 frame. This command is similar to @code{until}, but @code{advance} will
6058 not skip over recursive function calls, and the target location doesn't
6059 have to be in the same frame as the current one.
6060
6061
6062 @kindex stepi
6063 @kindex si @r{(@code{stepi})}
6064 @item stepi
6065 @itemx stepi @var{arg}
6066 @itemx si
6067 Execute one machine instruction, then stop and return to the debugger.
6068
6069 It is often useful to do @samp{display/i $pc} when stepping by machine
6070 instructions. This makes @value{GDBN} automatically display the next
6071 instruction to be executed, each time your program stops. @xref{Auto
6072 Display,, Automatic Display}.
6073
6074 An argument is a repeat count, as in @code{step}.
6075
6076 @need 750
6077 @kindex nexti
6078 @kindex ni @r{(@code{nexti})}
6079 @item nexti
6080 @itemx nexti @var{arg}
6081 @itemx ni
6082 Execute one machine instruction, but if it is a function call,
6083 proceed until the function returns.
6084
6085 An argument is a repeat count, as in @code{next}.
6086
6087 @end table
6088
6089 @anchor{range stepping}
6090 @cindex range stepping
6091 @cindex target-assisted range stepping
6092 By default, and if available, @value{GDBN} makes use of
6093 target-assisted @dfn{range stepping}. In other words, whenever you
6094 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6095 tells the target to step the corresponding range of instruction
6096 addresses instead of issuing multiple single-steps. This speeds up
6097 line stepping, particularly for remote targets. Ideally, there should
6098 be no reason you would want to turn range stepping off. However, it's
6099 possible that a bug in the debug info, a bug in the remote stub (for
6100 remote targets), or even a bug in @value{GDBN} could make line
6101 stepping behave incorrectly when target-assisted range stepping is
6102 enabled. You can use the following command to turn off range stepping
6103 if necessary:
6104
6105 @table @code
6106 @kindex set range-stepping
6107 @kindex show range-stepping
6108 @item set range-stepping
6109 @itemx show range-stepping
6110 Control whether range stepping is enabled.
6111
6112 If @code{on}, and the target supports it, @value{GDBN} tells the
6113 target to step a range of addresses itself, instead of issuing
6114 multiple single-steps. If @code{off}, @value{GDBN} always issues
6115 single-steps, even if range stepping is supported by the target. The
6116 default is @code{on}.
6117
6118 @end table
6119
6120 @node Skipping Over Functions and Files
6121 @section Skipping Over Functions and Files
6122 @cindex skipping over functions and files
6123
6124 The program you are debugging may contain some functions which are
6125 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6126 skip a function, all functions in a file or a particular function in
6127 a particular file when stepping.
6128
6129 For example, consider the following C function:
6130
6131 @smallexample
6132 101 int func()
6133 102 @{
6134 103 foo(boring());
6135 104 bar(boring());
6136 105 @}
6137 @end smallexample
6138
6139 @noindent
6140 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6141 are not interested in stepping through @code{boring}. If you run @code{step}
6142 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6143 step over both @code{foo} and @code{boring}!
6144
6145 One solution is to @code{step} into @code{boring} and use the @code{finish}
6146 command to immediately exit it. But this can become tedious if @code{boring}
6147 is called from many places.
6148
6149 A more flexible solution is to execute @kbd{skip boring}. This instructs
6150 @value{GDBN} never to step into @code{boring}. Now when you execute
6151 @code{step} at line 103, you'll step over @code{boring} and directly into
6152 @code{foo}.
6153
6154 Functions may be skipped by providing either a function name, linespec
6155 (@pxref{Specify Location}), regular expression that matches the function's
6156 name, file name or a @code{glob}-style pattern that matches the file name.
6157
6158 On Posix systems the form of the regular expression is
6159 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6160 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6161 expression is whatever is provided by the @code{regcomp} function of
6162 the underlying system.
6163 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6164 description of @code{glob}-style patterns.
6165
6166 @table @code
6167 @kindex skip
6168 @item skip @r{[}@var{options}@r{]}
6169 The basic form of the @code{skip} command takes zero or more options
6170 that specify what to skip.
6171 The @var{options} argument is any useful combination of the following:
6172
6173 @table @code
6174 @item -file @var{file}
6175 @itemx -fi @var{file}
6176 Functions in @var{file} will be skipped over when stepping.
6177
6178 @item -gfile @var{file-glob-pattern}
6179 @itemx -gfi @var{file-glob-pattern}
6180 @cindex skipping over files via glob-style patterns
6181 Functions in files matching @var{file-glob-pattern} will be skipped
6182 over when stepping.
6183
6184 @smallexample
6185 (gdb) skip -gfi utils/*.c
6186 @end smallexample
6187
6188 @item -function @var{linespec}
6189 @itemx -fu @var{linespec}
6190 Functions named by @var{linespec} or the function containing the line
6191 named by @var{linespec} will be skipped over when stepping.
6192 @xref{Specify Location}.
6193
6194 @item -rfunction @var{regexp}
6195 @itemx -rfu @var{regexp}
6196 @cindex skipping over functions via regular expressions
6197 Functions whose name matches @var{regexp} will be skipped over when stepping.
6198
6199 This form is useful for complex function names.
6200 For example, there is generally no need to step into C@t{++} @code{std::string}
6201 constructors or destructors. Plus with C@t{++} templates it can be hard to
6202 write out the full name of the function, and often it doesn't matter what
6203 the template arguments are. Specifying the function to be skipped as a
6204 regular expression makes this easier.
6205
6206 @smallexample
6207 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6208 @end smallexample
6209
6210 If you want to skip every templated C@t{++} constructor and destructor
6211 in the @code{std} namespace you can do:
6212
6213 @smallexample
6214 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6215 @end smallexample
6216 @end table
6217
6218 If no options are specified, the function you're currently debugging
6219 will be skipped.
6220
6221 @kindex skip function
6222 @item skip function @r{[}@var{linespec}@r{]}
6223 After running this command, the function named by @var{linespec} or the
6224 function containing the line named by @var{linespec} will be skipped over when
6225 stepping. @xref{Specify Location}.
6226
6227 If you do not specify @var{linespec}, the function you're currently debugging
6228 will be skipped.
6229
6230 (If you have a function called @code{file} that you want to skip, use
6231 @kbd{skip function file}.)
6232
6233 @kindex skip file
6234 @item skip file @r{[}@var{filename}@r{]}
6235 After running this command, any function whose source lives in @var{filename}
6236 will be skipped over when stepping.
6237
6238 @smallexample
6239 (gdb) skip file boring.c
6240 File boring.c will be skipped when stepping.
6241 @end smallexample
6242
6243 If you do not specify @var{filename}, functions whose source lives in the file
6244 you're currently debugging will be skipped.
6245 @end table
6246
6247 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6248 These are the commands for managing your list of skips:
6249
6250 @table @code
6251 @kindex info skip
6252 @item info skip @r{[}@var{range}@r{]}
6253 Print details about the specified skip(s). If @var{range} is not specified,
6254 print a table with details about all functions and files marked for skipping.
6255 @code{info skip} prints the following information about each skip:
6256
6257 @table @emph
6258 @item Identifier
6259 A number identifying this skip.
6260 @item Enabled or Disabled
6261 Enabled skips are marked with @samp{y}.
6262 Disabled skips are marked with @samp{n}.
6263 @item Glob
6264 If the file name is a @samp{glob} pattern this is @samp{y}.
6265 Otherwise it is @samp{n}.
6266 @item File
6267 The name or @samp{glob} pattern of the file to be skipped.
6268 If no file is specified this is @samp{<none>}.
6269 @item RE
6270 If the function name is a @samp{regular expression} this is @samp{y}.
6271 Otherwise it is @samp{n}.
6272 @item Function
6273 The name or regular expression of the function to skip.
6274 If no function is specified this is @samp{<none>}.
6275 @end table
6276
6277 @kindex skip delete
6278 @item skip delete @r{[}@var{range}@r{]}
6279 Delete the specified skip(s). If @var{range} is not specified, delete all
6280 skips.
6281
6282 @kindex skip enable
6283 @item skip enable @r{[}@var{range}@r{]}
6284 Enable the specified skip(s). If @var{range} is not specified, enable all
6285 skips.
6286
6287 @kindex skip disable
6288 @item skip disable @r{[}@var{range}@r{]}
6289 Disable the specified skip(s). If @var{range} is not specified, disable all
6290 skips.
6291
6292 @kindex set debug skip
6293 @item set debug skip @r{[}on|off@r{]}
6294 Set whether to print the debug output about skipping files and functions.
6295
6296 @kindex show debug skip
6297 @item show debug skip
6298 Show whether the debug output about skipping files and functions is printed.
6299
6300 @end table
6301
6302 @node Signals
6303 @section Signals
6304 @cindex signals
6305
6306 A signal is an asynchronous event that can happen in a program. The
6307 operating system defines the possible kinds of signals, and gives each
6308 kind a name and a number. For example, in Unix @code{SIGINT} is the
6309 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6310 @code{SIGSEGV} is the signal a program gets from referencing a place in
6311 memory far away from all the areas in use; @code{SIGALRM} occurs when
6312 the alarm clock timer goes off (which happens only if your program has
6313 requested an alarm).
6314
6315 @cindex fatal signals
6316 Some signals, including @code{SIGALRM}, are a normal part of the
6317 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6318 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6319 program has not specified in advance some other way to handle the signal.
6320 @code{SIGINT} does not indicate an error in your program, but it is normally
6321 fatal so it can carry out the purpose of the interrupt: to kill the program.
6322
6323 @value{GDBN} has the ability to detect any occurrence of a signal in your
6324 program. You can tell @value{GDBN} in advance what to do for each kind of
6325 signal.
6326
6327 @cindex handling signals
6328 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6329 @code{SIGALRM} be silently passed to your program
6330 (so as not to interfere with their role in the program's functioning)
6331 but to stop your program immediately whenever an error signal happens.
6332 You can change these settings with the @code{handle} command.
6333
6334 @table @code
6335 @kindex info signals
6336 @kindex info handle
6337 @item info signals
6338 @itemx info handle
6339 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6340 handle each one. You can use this to see the signal numbers of all
6341 the defined types of signals.
6342
6343 @item info signals @var{sig}
6344 Similar, but print information only about the specified signal number.
6345
6346 @code{info handle} is an alias for @code{info signals}.
6347
6348 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6349 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6350 for details about this command.
6351
6352 @kindex handle
6353 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6354 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6355 can be the number of a signal or its name (with or without the
6356 @samp{SIG} at the beginning); a list of signal numbers of the form
6357 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6358 known signals. Optional arguments @var{keywords}, described below,
6359 say what change to make.
6360 @end table
6361
6362 @c @group
6363 The keywords allowed by the @code{handle} command can be abbreviated.
6364 Their full names are:
6365
6366 @table @code
6367 @item nostop
6368 @value{GDBN} should not stop your program when this signal happens. It may
6369 still print a message telling you that the signal has come in.
6370
6371 @item stop
6372 @value{GDBN} should stop your program when this signal happens. This implies
6373 the @code{print} keyword as well.
6374
6375 @item print
6376 @value{GDBN} should print a message when this signal happens.
6377
6378 @item noprint
6379 @value{GDBN} should not mention the occurrence of the signal at all. This
6380 implies the @code{nostop} keyword as well.
6381
6382 @item pass
6383 @itemx noignore
6384 @value{GDBN} should allow your program to see this signal; your program
6385 can handle the signal, or else it may terminate if the signal is fatal
6386 and not handled. @code{pass} and @code{noignore} are synonyms.
6387
6388 @item nopass
6389 @itemx ignore
6390 @value{GDBN} should not allow your program to see this signal.
6391 @code{nopass} and @code{ignore} are synonyms.
6392 @end table
6393 @c @end group
6394
6395 When a signal stops your program, the signal is not visible to the
6396 program until you
6397 continue. Your program sees the signal then, if @code{pass} is in
6398 effect for the signal in question @emph{at that time}. In other words,
6399 after @value{GDBN} reports a signal, you can use the @code{handle}
6400 command with @code{pass} or @code{nopass} to control whether your
6401 program sees that signal when you continue.
6402
6403 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6404 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6405 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6406 erroneous signals.
6407
6408 You can also use the @code{signal} command to prevent your program from
6409 seeing a signal, or cause it to see a signal it normally would not see,
6410 or to give it any signal at any time. For example, if your program stopped
6411 due to some sort of memory reference error, you might store correct
6412 values into the erroneous variables and continue, hoping to see more
6413 execution; but your program would probably terminate immediately as
6414 a result of the fatal signal once it saw the signal. To prevent this,
6415 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6416 Program a Signal}.
6417
6418 @cindex stepping and signal handlers
6419 @anchor{stepping and signal handlers}
6420
6421 @value{GDBN} optimizes for stepping the mainline code. If a signal
6422 that has @code{handle nostop} and @code{handle pass} set arrives while
6423 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6424 in progress, @value{GDBN} lets the signal handler run and then resumes
6425 stepping the mainline code once the signal handler returns. In other
6426 words, @value{GDBN} steps over the signal handler. This prevents
6427 signals that you've specified as not interesting (with @code{handle
6428 nostop}) from changing the focus of debugging unexpectedly. Note that
6429 the signal handler itself may still hit a breakpoint, stop for another
6430 signal that has @code{handle stop} in effect, or for any other event
6431 that normally results in stopping the stepping command sooner. Also
6432 note that @value{GDBN} still informs you that the program received a
6433 signal if @code{handle print} is set.
6434
6435 @anchor{stepping into signal handlers}
6436
6437 If you set @code{handle pass} for a signal, and your program sets up a
6438 handler for it, then issuing a stepping command, such as @code{step}
6439 or @code{stepi}, when your program is stopped due to the signal will
6440 step @emph{into} the signal handler (if the target supports that).
6441
6442 Likewise, if you use the @code{queue-signal} command to queue a signal
6443 to be delivered to the current thread when execution of the thread
6444 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6445 stepping command will step into the signal handler.
6446
6447 Here's an example, using @code{stepi} to step to the first instruction
6448 of @code{SIGUSR1}'s handler:
6449
6450 @smallexample
6451 (@value{GDBP}) handle SIGUSR1
6452 Signal Stop Print Pass to program Description
6453 SIGUSR1 Yes Yes Yes User defined signal 1
6454 (@value{GDBP}) c
6455 Continuing.
6456
6457 Program received signal SIGUSR1, User defined signal 1.
6458 main () sigusr1.c:28
6459 28 p = 0;
6460 (@value{GDBP}) si
6461 sigusr1_handler () at sigusr1.c:9
6462 9 @{
6463 @end smallexample
6464
6465 The same, but using @code{queue-signal} instead of waiting for the
6466 program to receive the signal first:
6467
6468 @smallexample
6469 (@value{GDBP}) n
6470 28 p = 0;
6471 (@value{GDBP}) queue-signal SIGUSR1
6472 (@value{GDBP}) si
6473 sigusr1_handler () at sigusr1.c:9
6474 9 @{
6475 (@value{GDBP})
6476 @end smallexample
6477
6478 @cindex extra signal information
6479 @anchor{extra signal information}
6480
6481 On some targets, @value{GDBN} can inspect extra signal information
6482 associated with the intercepted signal, before it is actually
6483 delivered to the program being debugged. This information is exported
6484 by the convenience variable @code{$_siginfo}, and consists of data
6485 that is passed by the kernel to the signal handler at the time of the
6486 receipt of a signal. The data type of the information itself is
6487 target dependent. You can see the data type using the @code{ptype
6488 $_siginfo} command. On Unix systems, it typically corresponds to the
6489 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6490 system header.
6491
6492 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6493 referenced address that raised a segmentation fault.
6494
6495 @smallexample
6496 @group
6497 (@value{GDBP}) continue
6498 Program received signal SIGSEGV, Segmentation fault.
6499 0x0000000000400766 in main ()
6500 69 *(int *)p = 0;
6501 (@value{GDBP}) ptype $_siginfo
6502 type = struct @{
6503 int si_signo;
6504 int si_errno;
6505 int si_code;
6506 union @{
6507 int _pad[28];
6508 struct @{...@} _kill;
6509 struct @{...@} _timer;
6510 struct @{...@} _rt;
6511 struct @{...@} _sigchld;
6512 struct @{...@} _sigfault;
6513 struct @{...@} _sigpoll;
6514 @} _sifields;
6515 @}
6516 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6517 type = struct @{
6518 void *si_addr;
6519 @}
6520 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6521 $1 = (void *) 0x7ffff7ff7000
6522 @end group
6523 @end smallexample
6524
6525 Depending on target support, @code{$_siginfo} may also be writable.
6526
6527 @cindex Intel MPX boundary violations
6528 @cindex boundary violations, Intel MPX
6529 On some targets, a @code{SIGSEGV} can be caused by a boundary
6530 violation, i.e., accessing an address outside of the allowed range.
6531 In those cases @value{GDBN} may displays additional information,
6532 depending on how @value{GDBN} has been told to handle the signal.
6533 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6534 kind: "Upper" or "Lower", the memory address accessed and the
6535 bounds, while with @code{handle nostop SIGSEGV} no additional
6536 information is displayed.
6537
6538 The usual output of a segfault is:
6539 @smallexample
6540 Program received signal SIGSEGV, Segmentation fault
6541 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6542 68 value = *(p + len);
6543 @end smallexample
6544
6545 While a bound violation is presented as:
6546 @smallexample
6547 Program received signal SIGSEGV, Segmentation fault
6548 Upper bound violation while accessing address 0x7fffffffc3b3
6549 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6550 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6551 68 value = *(p + len);
6552 @end smallexample
6553
6554 @node Thread Stops
6555 @section Stopping and Starting Multi-thread Programs
6556
6557 @cindex stopped threads
6558 @cindex threads, stopped
6559
6560 @cindex continuing threads
6561 @cindex threads, continuing
6562
6563 @value{GDBN} supports debugging programs with multiple threads
6564 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6565 are two modes of controlling execution of your program within the
6566 debugger. In the default mode, referred to as @dfn{all-stop mode},
6567 when any thread in your program stops (for example, at a breakpoint
6568 or while being stepped), all other threads in the program are also stopped by
6569 @value{GDBN}. On some targets, @value{GDBN} also supports
6570 @dfn{non-stop mode}, in which other threads can continue to run freely while
6571 you examine the stopped thread in the debugger.
6572
6573 @menu
6574 * All-Stop Mode:: All threads stop when GDB takes control
6575 * Non-Stop Mode:: Other threads continue to execute
6576 * Background Execution:: Running your program asynchronously
6577 * Thread-Specific Breakpoints:: Controlling breakpoints
6578 * Interrupted System Calls:: GDB may interfere with system calls
6579 * Observer Mode:: GDB does not alter program behavior
6580 @end menu
6581
6582 @node All-Stop Mode
6583 @subsection All-Stop Mode
6584
6585 @cindex all-stop mode
6586
6587 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6588 @emph{all} threads of execution stop, not just the current thread. This
6589 allows you to examine the overall state of the program, including
6590 switching between threads, without worrying that things may change
6591 underfoot.
6592
6593 Conversely, whenever you restart the program, @emph{all} threads start
6594 executing. @emph{This is true even when single-stepping} with commands
6595 like @code{step} or @code{next}.
6596
6597 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6598 Since thread scheduling is up to your debugging target's operating
6599 system (not controlled by @value{GDBN}), other threads may
6600 execute more than one statement while the current thread completes a
6601 single step. Moreover, in general other threads stop in the middle of a
6602 statement, rather than at a clean statement boundary, when the program
6603 stops.
6604
6605 You might even find your program stopped in another thread after
6606 continuing or even single-stepping. This happens whenever some other
6607 thread runs into a breakpoint, a signal, or an exception before the
6608 first thread completes whatever you requested.
6609
6610 @cindex automatic thread selection
6611 @cindex switching threads automatically
6612 @cindex threads, automatic switching
6613 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6614 signal, it automatically selects the thread where that breakpoint or
6615 signal happened. @value{GDBN} alerts you to the context switch with a
6616 message such as @samp{[Switching to Thread @var{n}]} to identify the
6617 thread.
6618
6619 On some OSes, you can modify @value{GDBN}'s default behavior by
6620 locking the OS scheduler to allow only a single thread to run.
6621
6622 @table @code
6623 @item set scheduler-locking @var{mode}
6624 @cindex scheduler locking mode
6625 @cindex lock scheduler
6626 Set the scheduler locking mode. It applies to normal execution,
6627 record mode, and replay mode. If it is @code{off}, then there is no
6628 locking and any thread may run at any time. If @code{on}, then only
6629 the current thread may run when the inferior is resumed. The
6630 @code{step} mode optimizes for single-stepping; it prevents other
6631 threads from preempting the current thread while you are stepping, so
6632 that the focus of debugging does not change unexpectedly. Other
6633 threads never get a chance to run when you step, and they are
6634 completely free to run when you use commands like @samp{continue},
6635 @samp{until}, or @samp{finish}. However, unless another thread hits a
6636 breakpoint during its timeslice, @value{GDBN} does not change the
6637 current thread away from the thread that you are debugging. The
6638 @code{replay} mode behaves like @code{off} in record mode and like
6639 @code{on} in replay mode.
6640
6641 @item show scheduler-locking
6642 Display the current scheduler locking mode.
6643 @end table
6644
6645 @cindex resume threads of multiple processes simultaneously
6646 By default, when you issue one of the execution commands such as
6647 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6648 threads of the current inferior to run. For example, if @value{GDBN}
6649 is attached to two inferiors, each with two threads, the
6650 @code{continue} command resumes only the two threads of the current
6651 inferior. This is useful, for example, when you debug a program that
6652 forks and you want to hold the parent stopped (so that, for instance,
6653 it doesn't run to exit), while you debug the child. In other
6654 situations, you may not be interested in inspecting the current state
6655 of any of the processes @value{GDBN} is attached to, and you may want
6656 to resume them all until some breakpoint is hit. In the latter case,
6657 you can instruct @value{GDBN} to allow all threads of all the
6658 inferiors to run with the @w{@code{set schedule-multiple}} command.
6659
6660 @table @code
6661 @kindex set schedule-multiple
6662 @item set schedule-multiple
6663 Set the mode for allowing threads of multiple processes to be resumed
6664 when an execution command is issued. When @code{on}, all threads of
6665 all processes are allowed to run. When @code{off}, only the threads
6666 of the current process are resumed. The default is @code{off}. The
6667 @code{scheduler-locking} mode takes precedence when set to @code{on},
6668 or while you are stepping and set to @code{step}.
6669
6670 @item show schedule-multiple
6671 Display the current mode for resuming the execution of threads of
6672 multiple processes.
6673 @end table
6674
6675 @node Non-Stop Mode
6676 @subsection Non-Stop Mode
6677
6678 @cindex non-stop mode
6679
6680 @c This section is really only a place-holder, and needs to be expanded
6681 @c with more details.
6682
6683 For some multi-threaded targets, @value{GDBN} supports an optional
6684 mode of operation in which you can examine stopped program threads in
6685 the debugger while other threads continue to execute freely. This
6686 minimizes intrusion when debugging live systems, such as programs
6687 where some threads have real-time constraints or must continue to
6688 respond to external events. This is referred to as @dfn{non-stop} mode.
6689
6690 In non-stop mode, when a thread stops to report a debugging event,
6691 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6692 threads as well, in contrast to the all-stop mode behavior. Additionally,
6693 execution commands such as @code{continue} and @code{step} apply by default
6694 only to the current thread in non-stop mode, rather than all threads as
6695 in all-stop mode. This allows you to control threads explicitly in
6696 ways that are not possible in all-stop mode --- for example, stepping
6697 one thread while allowing others to run freely, stepping
6698 one thread while holding all others stopped, or stepping several threads
6699 independently and simultaneously.
6700
6701 To enter non-stop mode, use this sequence of commands before you run
6702 or attach to your program:
6703
6704 @smallexample
6705 # If using the CLI, pagination breaks non-stop.
6706 set pagination off
6707
6708 # Finally, turn it on!
6709 set non-stop on
6710 @end smallexample
6711
6712 You can use these commands to manipulate the non-stop mode setting:
6713
6714 @table @code
6715 @kindex set non-stop
6716 @item set non-stop on
6717 Enable selection of non-stop mode.
6718 @item set non-stop off
6719 Disable selection of non-stop mode.
6720 @kindex show non-stop
6721 @item show non-stop
6722 Show the current non-stop enablement setting.
6723 @end table
6724
6725 Note these commands only reflect whether non-stop mode is enabled,
6726 not whether the currently-executing program is being run in non-stop mode.
6727 In particular, the @code{set non-stop} preference is only consulted when
6728 @value{GDBN} starts or connects to the target program, and it is generally
6729 not possible to switch modes once debugging has started. Furthermore,
6730 since not all targets support non-stop mode, even when you have enabled
6731 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6732 default.
6733
6734 In non-stop mode, all execution commands apply only to the current thread
6735 by default. That is, @code{continue} only continues one thread.
6736 To continue all threads, issue @code{continue -a} or @code{c -a}.
6737
6738 You can use @value{GDBN}'s background execution commands
6739 (@pxref{Background Execution}) to run some threads in the background
6740 while you continue to examine or step others from @value{GDBN}.
6741 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6742 always executed asynchronously in non-stop mode.
6743
6744 Suspending execution is done with the @code{interrupt} command when
6745 running in the background, or @kbd{Ctrl-c} during foreground execution.
6746 In all-stop mode, this stops the whole process;
6747 but in non-stop mode the interrupt applies only to the current thread.
6748 To stop the whole program, use @code{interrupt -a}.
6749
6750 Other execution commands do not currently support the @code{-a} option.
6751
6752 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6753 that thread current, as it does in all-stop mode. This is because the
6754 thread stop notifications are asynchronous with respect to @value{GDBN}'s
6755 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6756 changed to a different thread just as you entered a command to operate on the
6757 previously current thread.
6758
6759 @node Background Execution
6760 @subsection Background Execution
6761
6762 @cindex foreground execution
6763 @cindex background execution
6764 @cindex asynchronous execution
6765 @cindex execution, foreground, background and asynchronous
6766
6767 @value{GDBN}'s execution commands have two variants: the normal
6768 foreground (synchronous) behavior, and a background
6769 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
6770 the program to report that some thread has stopped before prompting for
6771 another command. In background execution, @value{GDBN} immediately gives
6772 a command prompt so that you can issue other commands while your program runs.
6773
6774 If the target doesn't support async mode, @value{GDBN} issues an error
6775 message if you attempt to use the background execution commands.
6776
6777 @cindex @code{&}, background execution of commands
6778 To specify background execution, add a @code{&} to the command. For example,
6779 the background form of the @code{continue} command is @code{continue&}, or
6780 just @code{c&}. The execution commands that accept background execution
6781 are:
6782
6783 @table @code
6784 @kindex run&
6785 @item run
6786 @xref{Starting, , Starting your Program}.
6787
6788 @item attach
6789 @kindex attach&
6790 @xref{Attach, , Debugging an Already-running Process}.
6791
6792 @item step
6793 @kindex step&
6794 @xref{Continuing and Stepping, step}.
6795
6796 @item stepi
6797 @kindex stepi&
6798 @xref{Continuing and Stepping, stepi}.
6799
6800 @item next
6801 @kindex next&
6802 @xref{Continuing and Stepping, next}.
6803
6804 @item nexti
6805 @kindex nexti&
6806 @xref{Continuing and Stepping, nexti}.
6807
6808 @item continue
6809 @kindex continue&
6810 @xref{Continuing and Stepping, continue}.
6811
6812 @item finish
6813 @kindex finish&
6814 @xref{Continuing and Stepping, finish}.
6815
6816 @item until
6817 @kindex until&
6818 @xref{Continuing and Stepping, until}.
6819
6820 @end table
6821
6822 Background execution is especially useful in conjunction with non-stop
6823 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6824 However, you can also use these commands in the normal all-stop mode with
6825 the restriction that you cannot issue another execution command until the
6826 previous one finishes. Examples of commands that are valid in all-stop
6827 mode while the program is running include @code{help} and @code{info break}.
6828
6829 You can interrupt your program while it is running in the background by
6830 using the @code{interrupt} command.
6831
6832 @table @code
6833 @kindex interrupt
6834 @item interrupt
6835 @itemx interrupt -a
6836
6837 Suspend execution of the running program. In all-stop mode,
6838 @code{interrupt} stops the whole process, but in non-stop mode, it stops
6839 only the current thread. To stop the whole program in non-stop mode,
6840 use @code{interrupt -a}.
6841 @end table
6842
6843 @node Thread-Specific Breakpoints
6844 @subsection Thread-Specific Breakpoints
6845
6846 When your program has multiple threads (@pxref{Threads,, Debugging
6847 Programs with Multiple Threads}), you can choose whether to set
6848 breakpoints on all threads, or on a particular thread.
6849
6850 @table @code
6851 @cindex breakpoints and threads
6852 @cindex thread breakpoints
6853 @kindex break @dots{} thread @var{thread-id}
6854 @item break @var{location} thread @var{thread-id}
6855 @itemx break @var{location} thread @var{thread-id} if @dots{}
6856 @var{location} specifies source lines; there are several ways of
6857 writing them (@pxref{Specify Location}), but the effect is always to
6858 specify some source line.
6859
6860 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
6861 to specify that you only want @value{GDBN} to stop the program when a
6862 particular thread reaches this breakpoint. The @var{thread-id} specifier
6863 is one of the thread identifiers assigned by @value{GDBN}, shown
6864 in the first column of the @samp{info threads} display.
6865
6866 If you do not specify @samp{thread @var{thread-id}} when you set a
6867 breakpoint, the breakpoint applies to @emph{all} threads of your
6868 program.
6869
6870 You can use the @code{thread} qualifier on conditional breakpoints as
6871 well; in this case, place @samp{thread @var{thread-id}} before or
6872 after the breakpoint condition, like this:
6873
6874 @smallexample
6875 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
6876 @end smallexample
6877
6878 @end table
6879
6880 Thread-specific breakpoints are automatically deleted when
6881 @value{GDBN} detects the corresponding thread is no longer in the
6882 thread list. For example:
6883
6884 @smallexample
6885 (@value{GDBP}) c
6886 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6887 @end smallexample
6888
6889 There are several ways for a thread to disappear, such as a regular
6890 thread exit, but also when you detach from the process with the
6891 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
6892 Process}), or if @value{GDBN} loses the remote connection
6893 (@pxref{Remote Debugging}), etc. Note that with some targets,
6894 @value{GDBN} is only able to detect a thread has exited when the user
6895 explictly asks for the thread list with the @code{info threads}
6896 command.
6897
6898 @node Interrupted System Calls
6899 @subsection Interrupted System Calls
6900
6901 @cindex thread breakpoints and system calls
6902 @cindex system calls and thread breakpoints
6903 @cindex premature return from system calls
6904 There is an unfortunate side effect when using @value{GDBN} to debug
6905 multi-threaded programs. If one thread stops for a
6906 breakpoint, or for some other reason, and another thread is blocked in a
6907 system call, then the system call may return prematurely. This is a
6908 consequence of the interaction between multiple threads and the signals
6909 that @value{GDBN} uses to implement breakpoints and other events that
6910 stop execution.
6911
6912 To handle this problem, your program should check the return value of
6913 each system call and react appropriately. This is good programming
6914 style anyways.
6915
6916 For example, do not write code like this:
6917
6918 @smallexample
6919 sleep (10);
6920 @end smallexample
6921
6922 The call to @code{sleep} will return early if a different thread stops
6923 at a breakpoint or for some other reason.
6924
6925 Instead, write this:
6926
6927 @smallexample
6928 int unslept = 10;
6929 while (unslept > 0)
6930 unslept = sleep (unslept);
6931 @end smallexample
6932
6933 A system call is allowed to return early, so the system is still
6934 conforming to its specification. But @value{GDBN} does cause your
6935 multi-threaded program to behave differently than it would without
6936 @value{GDBN}.
6937
6938 Also, @value{GDBN} uses internal breakpoints in the thread library to
6939 monitor certain events such as thread creation and thread destruction.
6940 When such an event happens, a system call in another thread may return
6941 prematurely, even though your program does not appear to stop.
6942
6943 @node Observer Mode
6944 @subsection Observer Mode
6945
6946 If you want to build on non-stop mode and observe program behavior
6947 without any chance of disruption by @value{GDBN}, you can set
6948 variables to disable all of the debugger's attempts to modify state,
6949 whether by writing memory, inserting breakpoints, etc. These operate
6950 at a low level, intercepting operations from all commands.
6951
6952 When all of these are set to @code{off}, then @value{GDBN} is said to
6953 be @dfn{observer mode}. As a convenience, the variable
6954 @code{observer} can be set to disable these, plus enable non-stop
6955 mode.
6956
6957 Note that @value{GDBN} will not prevent you from making nonsensical
6958 combinations of these settings. For instance, if you have enabled
6959 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
6960 then breakpoints that work by writing trap instructions into the code
6961 stream will still not be able to be placed.
6962
6963 @table @code
6964
6965 @kindex observer
6966 @item set observer on
6967 @itemx set observer off
6968 When set to @code{on}, this disables all the permission variables
6969 below (except for @code{insert-fast-tracepoints}), plus enables
6970 non-stop debugging. Setting this to @code{off} switches back to
6971 normal debugging, though remaining in non-stop mode.
6972
6973 @item show observer
6974 Show whether observer mode is on or off.
6975
6976 @kindex may-write-registers
6977 @item set may-write-registers on
6978 @itemx set may-write-registers off
6979 This controls whether @value{GDBN} will attempt to alter the values of
6980 registers, such as with assignment expressions in @code{print}, or the
6981 @code{jump} command. It defaults to @code{on}.
6982
6983 @item show may-write-registers
6984 Show the current permission to write registers.
6985
6986 @kindex may-write-memory
6987 @item set may-write-memory on
6988 @itemx set may-write-memory off
6989 This controls whether @value{GDBN} will attempt to alter the contents
6990 of memory, such as with assignment expressions in @code{print}. It
6991 defaults to @code{on}.
6992
6993 @item show may-write-memory
6994 Show the current permission to write memory.
6995
6996 @kindex may-insert-breakpoints
6997 @item set may-insert-breakpoints on
6998 @itemx set may-insert-breakpoints off
6999 This controls whether @value{GDBN} will attempt to insert breakpoints.
7000 This affects all breakpoints, including internal breakpoints defined
7001 by @value{GDBN}. It defaults to @code{on}.
7002
7003 @item show may-insert-breakpoints
7004 Show the current permission to insert breakpoints.
7005
7006 @kindex may-insert-tracepoints
7007 @item set may-insert-tracepoints on
7008 @itemx set may-insert-tracepoints off
7009 This controls whether @value{GDBN} will attempt to insert (regular)
7010 tracepoints at the beginning of a tracing experiment. It affects only
7011 non-fast tracepoints, fast tracepoints being under the control of
7012 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7013
7014 @item show may-insert-tracepoints
7015 Show the current permission to insert tracepoints.
7016
7017 @kindex may-insert-fast-tracepoints
7018 @item set may-insert-fast-tracepoints on
7019 @itemx set may-insert-fast-tracepoints off
7020 This controls whether @value{GDBN} will attempt to insert fast
7021 tracepoints at the beginning of a tracing experiment. It affects only
7022 fast tracepoints, regular (non-fast) tracepoints being under the
7023 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7024
7025 @item show may-insert-fast-tracepoints
7026 Show the current permission to insert fast tracepoints.
7027
7028 @kindex may-interrupt
7029 @item set may-interrupt on
7030 @itemx set may-interrupt off
7031 This controls whether @value{GDBN} will attempt to interrupt or stop
7032 program execution. When this variable is @code{off}, the
7033 @code{interrupt} command will have no effect, nor will
7034 @kbd{Ctrl-c}. It defaults to @code{on}.
7035
7036 @item show may-interrupt
7037 Show the current permission to interrupt or stop the program.
7038
7039 @end table
7040
7041 @node Reverse Execution
7042 @chapter Running programs backward
7043 @cindex reverse execution
7044 @cindex running programs backward
7045
7046 When you are debugging a program, it is not unusual to realize that
7047 you have gone too far, and some event of interest has already happened.
7048 If the target environment supports it, @value{GDBN} can allow you to
7049 ``rewind'' the program by running it backward.
7050
7051 A target environment that supports reverse execution should be able
7052 to ``undo'' the changes in machine state that have taken place as the
7053 program was executing normally. Variables, registers etc.@: should
7054 revert to their previous values. Obviously this requires a great
7055 deal of sophistication on the part of the target environment; not
7056 all target environments can support reverse execution.
7057
7058 When a program is executed in reverse, the instructions that
7059 have most recently been executed are ``un-executed'', in reverse
7060 order. The program counter runs backward, following the previous
7061 thread of execution in reverse. As each instruction is ``un-executed'',
7062 the values of memory and/or registers that were changed by that
7063 instruction are reverted to their previous states. After executing
7064 a piece of source code in reverse, all side effects of that code
7065 should be ``undone'', and all variables should be returned to their
7066 prior values@footnote{
7067 Note that some side effects are easier to undo than others. For instance,
7068 memory and registers are relatively easy, but device I/O is hard. Some
7069 targets may be able undo things like device I/O, and some may not.
7070
7071 The contract between @value{GDBN} and the reverse executing target
7072 requires only that the target do something reasonable when
7073 @value{GDBN} tells it to execute backwards, and then report the
7074 results back to @value{GDBN}. Whatever the target reports back to
7075 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7076 assumes that the memory and registers that the target reports are in a
7077 consistent state, but @value{GDBN} accepts whatever it is given.
7078 }.
7079
7080 On some platforms, @value{GDBN} has built-in support for reverse
7081 execution, activated with the @code{record} or @code{record btrace}
7082 commands. @xref{Process Record and Replay}. Some remote targets,
7083 typically full system emulators, support reverse execution directly
7084 without requiring any special command.
7085
7086 If you are debugging in a target environment that supports
7087 reverse execution, @value{GDBN} provides the following commands.
7088
7089 @table @code
7090 @kindex reverse-continue
7091 @kindex rc @r{(@code{reverse-continue})}
7092 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7093 @itemx rc @r{[}@var{ignore-count}@r{]}
7094 Beginning at the point where your program last stopped, start executing
7095 in reverse. Reverse execution will stop for breakpoints and synchronous
7096 exceptions (signals), just like normal execution. Behavior of
7097 asynchronous signals depends on the target environment.
7098
7099 @kindex reverse-step
7100 @kindex rs @r{(@code{step})}
7101 @item reverse-step @r{[}@var{count}@r{]}
7102 Run the program backward until control reaches the start of a
7103 different source line; then stop it, and return control to @value{GDBN}.
7104
7105 Like the @code{step} command, @code{reverse-step} will only stop
7106 at the beginning of a source line. It ``un-executes'' the previously
7107 executed source line. If the previous source line included calls to
7108 debuggable functions, @code{reverse-step} will step (backward) into
7109 the called function, stopping at the beginning of the @emph{last}
7110 statement in the called function (typically a return statement).
7111
7112 Also, as with the @code{step} command, if non-debuggable functions are
7113 called, @code{reverse-step} will run thru them backward without stopping.
7114
7115 @kindex reverse-stepi
7116 @kindex rsi @r{(@code{reverse-stepi})}
7117 @item reverse-stepi @r{[}@var{count}@r{]}
7118 Reverse-execute one machine instruction. Note that the instruction
7119 to be reverse-executed is @emph{not} the one pointed to by the program
7120 counter, but the instruction executed prior to that one. For instance,
7121 if the last instruction was a jump, @code{reverse-stepi} will take you
7122 back from the destination of the jump to the jump instruction itself.
7123
7124 @kindex reverse-next
7125 @kindex rn @r{(@code{reverse-next})}
7126 @item reverse-next @r{[}@var{count}@r{]}
7127 Run backward to the beginning of the previous line executed in
7128 the current (innermost) stack frame. If the line contains function
7129 calls, they will be ``un-executed'' without stopping. Starting from
7130 the first line of a function, @code{reverse-next} will take you back
7131 to the caller of that function, @emph{before} the function was called,
7132 just as the normal @code{next} command would take you from the last
7133 line of a function back to its return to its caller
7134 @footnote{Unless the code is too heavily optimized.}.
7135
7136 @kindex reverse-nexti
7137 @kindex rni @r{(@code{reverse-nexti})}
7138 @item reverse-nexti @r{[}@var{count}@r{]}
7139 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7140 in reverse, except that called functions are ``un-executed'' atomically.
7141 That is, if the previously executed instruction was a return from
7142 another function, @code{reverse-nexti} will continue to execute
7143 in reverse until the call to that function (from the current stack
7144 frame) is reached.
7145
7146 @kindex reverse-finish
7147 @item reverse-finish
7148 Just as the @code{finish} command takes you to the point where the
7149 current function returns, @code{reverse-finish} takes you to the point
7150 where it was called. Instead of ending up at the end of the current
7151 function invocation, you end up at the beginning.
7152
7153 @kindex set exec-direction
7154 @item set exec-direction
7155 Set the direction of target execution.
7156 @item set exec-direction reverse
7157 @cindex execute forward or backward in time
7158 @value{GDBN} will perform all execution commands in reverse, until the
7159 exec-direction mode is changed to ``forward''. Affected commands include
7160 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7161 command cannot be used in reverse mode.
7162 @item set exec-direction forward
7163 @value{GDBN} will perform all execution commands in the normal fashion.
7164 This is the default.
7165 @end table
7166
7167
7168 @node Process Record and Replay
7169 @chapter Recording Inferior's Execution and Replaying It
7170 @cindex process record and replay
7171 @cindex recording inferior's execution and replaying it
7172
7173 On some platforms, @value{GDBN} provides a special @dfn{process record
7174 and replay} target that can record a log of the process execution, and
7175 replay it later with both forward and reverse execution commands.
7176
7177 @cindex replay mode
7178 When this target is in use, if the execution log includes the record
7179 for the next instruction, @value{GDBN} will debug in @dfn{replay
7180 mode}. In the replay mode, the inferior does not really execute code
7181 instructions. Instead, all the events that normally happen during
7182 code execution are taken from the execution log. While code is not
7183 really executed in replay mode, the values of registers (including the
7184 program counter register) and the memory of the inferior are still
7185 changed as they normally would. Their contents are taken from the
7186 execution log.
7187
7188 @cindex record mode
7189 If the record for the next instruction is not in the execution log,
7190 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7191 inferior executes normally, and @value{GDBN} records the execution log
7192 for future replay.
7193
7194 The process record and replay target supports reverse execution
7195 (@pxref{Reverse Execution}), even if the platform on which the
7196 inferior runs does not. However, the reverse execution is limited in
7197 this case by the range of the instructions recorded in the execution
7198 log. In other words, reverse execution on platforms that don't
7199 support it directly can only be done in the replay mode.
7200
7201 When debugging in the reverse direction, @value{GDBN} will work in
7202 replay mode as long as the execution log includes the record for the
7203 previous instruction; otherwise, it will work in record mode, if the
7204 platform supports reverse execution, or stop if not.
7205
7206 Currently, process record and replay is supported on ARM, Aarch64,
7207 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7208 GNU/Linux. Process record and replay can be used both when native
7209 debugging, and when remote debugging via @code{gdbserver}.
7210
7211 For architecture environments that support process record and replay,
7212 @value{GDBN} provides the following commands:
7213
7214 @table @code
7215 @kindex target record
7216 @kindex target record-full
7217 @kindex target record-btrace
7218 @kindex record
7219 @kindex record full
7220 @kindex record btrace
7221 @kindex record btrace bts
7222 @kindex record btrace pt
7223 @kindex record bts
7224 @kindex record pt
7225 @kindex rec
7226 @kindex rec full
7227 @kindex rec btrace
7228 @kindex rec btrace bts
7229 @kindex rec btrace pt
7230 @kindex rec bts
7231 @kindex rec pt
7232 @item record @var{method}
7233 This command starts the process record and replay target. The
7234 recording method can be specified as parameter. Without a parameter
7235 the command uses the @code{full} recording method. The following
7236 recording methods are available:
7237
7238 @table @code
7239 @item full
7240 Full record/replay recording using @value{GDBN}'s software record and
7241 replay implementation. This method allows replaying and reverse
7242 execution.
7243
7244 @item btrace @var{format}
7245 Hardware-supported instruction recording, supported on Intel
7246 processors. This method does not record data. Further, the data is
7247 collected in a ring buffer so old data will be overwritten when the
7248 buffer is full. It allows limited reverse execution. Variables and
7249 registers are not available during reverse execution. In remote
7250 debugging, recording continues on disconnect. Recorded data can be
7251 inspected after reconnecting. The recording may be stopped using
7252 @code{record stop}.
7253
7254 The recording format can be specified as parameter. Without a parameter
7255 the command chooses the recording format. The following recording
7256 formats are available:
7257
7258 @table @code
7259 @item bts
7260 @cindex branch trace store
7261 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7262 this format, the processor stores a from/to record for each executed
7263 branch in the btrace ring buffer.
7264
7265 @item pt
7266 @cindex Intel Processor Trace
7267 Use the @dfn{Intel Processor Trace} recording format. In this
7268 format, the processor stores the execution trace in a compressed form
7269 that is afterwards decoded by @value{GDBN}.
7270
7271 The trace can be recorded with very low overhead. The compressed
7272 trace format also allows small trace buffers to already contain a big
7273 number of instructions compared to @acronym{BTS}.
7274
7275 Decoding the recorded execution trace, on the other hand, is more
7276 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7277 increased number of instructions to process. You should increase the
7278 buffer-size with care.
7279 @end table
7280
7281 Not all recording formats may be available on all processors.
7282 @end table
7283
7284 The process record and replay target can only debug a process that is
7285 already running. Therefore, you need first to start the process with
7286 the @kbd{run} or @kbd{start} commands, and then start the recording
7287 with the @kbd{record @var{method}} command.
7288
7289 @cindex displaced stepping, and process record and replay
7290 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7291 will be automatically disabled when process record and replay target
7292 is started. That's because the process record and replay target
7293 doesn't support displaced stepping.
7294
7295 @cindex non-stop mode, and process record and replay
7296 @cindex asynchronous execution, and process record and replay
7297 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7298 the asynchronous execution mode (@pxref{Background Execution}), not
7299 all recording methods are available. The @code{full} recording method
7300 does not support these two modes.
7301
7302 @kindex record stop
7303 @kindex rec s
7304 @item record stop
7305 Stop the process record and replay target. When process record and
7306 replay target stops, the entire execution log will be deleted and the
7307 inferior will either be terminated, or will remain in its final state.
7308
7309 When you stop the process record and replay target in record mode (at
7310 the end of the execution log), the inferior will be stopped at the
7311 next instruction that would have been recorded. In other words, if
7312 you record for a while and then stop recording, the inferior process
7313 will be left in the same state as if the recording never happened.
7314
7315 On the other hand, if the process record and replay target is stopped
7316 while in replay mode (that is, not at the end of the execution log,
7317 but at some earlier point), the inferior process will become ``live''
7318 at that earlier state, and it will then be possible to continue the
7319 usual ``live'' debugging of the process from that state.
7320
7321 When the inferior process exits, or @value{GDBN} detaches from it,
7322 process record and replay target will automatically stop itself.
7323
7324 @kindex record goto
7325 @item record goto
7326 Go to a specific location in the execution log. There are several
7327 ways to specify the location to go to:
7328
7329 @table @code
7330 @item record goto begin
7331 @itemx record goto start
7332 Go to the beginning of the execution log.
7333
7334 @item record goto end
7335 Go to the end of the execution log.
7336
7337 @item record goto @var{n}
7338 Go to instruction number @var{n} in the execution log.
7339 @end table
7340
7341 @kindex record save
7342 @item record save @var{filename}
7343 Save the execution log to a file @file{@var{filename}}.
7344 Default filename is @file{gdb_record.@var{process_id}}, where
7345 @var{process_id} is the process ID of the inferior.
7346
7347 This command may not be available for all recording methods.
7348
7349 @kindex record restore
7350 @item record restore @var{filename}
7351 Restore the execution log from a file @file{@var{filename}}.
7352 File must have been created with @code{record save}.
7353
7354 @kindex set record full
7355 @item set record full insn-number-max @var{limit}
7356 @itemx set record full insn-number-max unlimited
7357 Set the limit of instructions to be recorded for the @code{full}
7358 recording method. Default value is 200000.
7359
7360 If @var{limit} is a positive number, then @value{GDBN} will start
7361 deleting instructions from the log once the number of the record
7362 instructions becomes greater than @var{limit}. For every new recorded
7363 instruction, @value{GDBN} will delete the earliest recorded
7364 instruction to keep the number of recorded instructions at the limit.
7365 (Since deleting recorded instructions loses information, @value{GDBN}
7366 lets you control what happens when the limit is reached, by means of
7367 the @code{stop-at-limit} option, described below.)
7368
7369 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7370 delete recorded instructions from the execution log. The number of
7371 recorded instructions is limited only by the available memory.
7372
7373 @kindex show record full
7374 @item show record full insn-number-max
7375 Show the limit of instructions to be recorded with the @code{full}
7376 recording method.
7377
7378 @item set record full stop-at-limit
7379 Control the behavior of the @code{full} recording method when the
7380 number of recorded instructions reaches the limit. If ON (the
7381 default), @value{GDBN} will stop when the limit is reached for the
7382 first time and ask you whether you want to stop the inferior or
7383 continue running it and recording the execution log. If you decide
7384 to continue recording, each new recorded instruction will cause the
7385 oldest one to be deleted.
7386
7387 If this option is OFF, @value{GDBN} will automatically delete the
7388 oldest record to make room for each new one, without asking.
7389
7390 @item show record full stop-at-limit
7391 Show the current setting of @code{stop-at-limit}.
7392
7393 @item set record full memory-query
7394 Control the behavior when @value{GDBN} is unable to record memory
7395 changes caused by an instruction for the @code{full} recording method.
7396 If ON, @value{GDBN} will query whether to stop the inferior in that
7397 case.
7398
7399 If this option is OFF (the default), @value{GDBN} will automatically
7400 ignore the effect of such instructions on memory. Later, when
7401 @value{GDBN} replays this execution log, it will mark the log of this
7402 instruction as not accessible, and it will not affect the replay
7403 results.
7404
7405 @item show record full memory-query
7406 Show the current setting of @code{memory-query}.
7407
7408 @kindex set record btrace
7409 The @code{btrace} record target does not trace data. As a
7410 convenience, when replaying, @value{GDBN} reads read-only memory off
7411 the live program directly, assuming that the addresses of the
7412 read-only areas don't change. This for example makes it possible to
7413 disassemble code while replaying, but not to print variables.
7414 In some cases, being able to inspect variables might be useful.
7415 You can use the following command for that:
7416
7417 @item set record btrace replay-memory-access
7418 Control the behavior of the @code{btrace} recording method when
7419 accessing memory during replay. If @code{read-only} (the default),
7420 @value{GDBN} will only allow accesses to read-only memory.
7421 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7422 and to read-write memory. Beware that the accessed memory corresponds
7423 to the live target and not necessarily to the current replay
7424 position.
7425
7426 @item set record btrace cpu @var{identifier}
7427 Set the processor to be used for enabling workarounds for processor
7428 errata when decoding the trace.
7429
7430 Processor errata are defects in processor operation, caused by its
7431 design or manufacture. They can cause a trace not to match the
7432 specification. This, in turn, may cause trace decode to fail.
7433 @value{GDBN} can detect erroneous trace packets and correct them, thus
7434 avoiding the decoding failures. These corrections are known as
7435 @dfn{errata workarounds}, and are enabled based on the processor on
7436 which the trace was recorded.
7437
7438 By default, @value{GDBN} attempts to detect the processor
7439 automatically, and apply the necessary workarounds for it. However,
7440 you may need to specify the processor if @value{GDBN} does not yet
7441 support it. This command allows you to do that, and also allows to
7442 disable the workarounds.
7443
7444 The argument @var{identifier} identifies the @sc{cpu} and is of the
7445 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7446 there are two special identifiers, @code{none} and @code{auto}
7447 (default).
7448
7449 The following vendor identifiers and corresponding processor
7450 identifiers are currently supported:
7451
7452 @multitable @columnfractions .1 .9
7453
7454 @item @code{intel}
7455 @tab @var{family}/@var{model}[/@var{stepping}]
7456
7457 @end multitable
7458
7459 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7460 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7461
7462 If @var{identifier} is @code{auto}, enable errata workarounds for the
7463 processor on which the trace was recorded. If @var{identifier} is
7464 @code{none}, errata workarounds are disabled.
7465
7466 For example, when using an old @value{GDBN} on a new system, decode
7467 may fail because @value{GDBN} does not support the new processor. It
7468 often suffices to specify an older processor that @value{GDBN}
7469 supports.
7470
7471 @smallexample
7472 (gdb) info record
7473 Active record target: record-btrace
7474 Recording format: Intel Processor Trace.
7475 Buffer size: 16kB.
7476 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7477 (gdb) set record btrace cpu intel:6/158
7478 (gdb) info record
7479 Active record target: record-btrace
7480 Recording format: Intel Processor Trace.
7481 Buffer size: 16kB.
7482 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7483 @end smallexample
7484
7485 @kindex show record btrace
7486 @item show record btrace replay-memory-access
7487 Show the current setting of @code{replay-memory-access}.
7488
7489 @item show record btrace cpu
7490 Show the processor to be used for enabling trace decode errata
7491 workarounds.
7492
7493 @kindex set record btrace bts
7494 @item set record btrace bts buffer-size @var{size}
7495 @itemx set record btrace bts buffer-size unlimited
7496 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7497 format. Default is 64KB.
7498
7499 If @var{size} is a positive number, then @value{GDBN} will try to
7500 allocate a buffer of at least @var{size} bytes for each new thread
7501 that uses the btrace recording method and the @acronym{BTS} format.
7502 The actually obtained buffer size may differ from the requested
7503 @var{size}. Use the @code{info record} command to see the actual
7504 buffer size for each thread that uses the btrace recording method and
7505 the @acronym{BTS} format.
7506
7507 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7508 allocate a buffer of 4MB.
7509
7510 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7511 also need longer to process the branch trace data before it can be used.
7512
7513 @item show record btrace bts buffer-size @var{size}
7514 Show the current setting of the requested ring buffer size for branch
7515 tracing in @acronym{BTS} format.
7516
7517 @kindex set record btrace pt
7518 @item set record btrace pt buffer-size @var{size}
7519 @itemx set record btrace pt buffer-size unlimited
7520 Set the requested ring buffer size for branch tracing in Intel
7521 Processor Trace format. Default is 16KB.
7522
7523 If @var{size} is a positive number, then @value{GDBN} will try to
7524 allocate a buffer of at least @var{size} bytes for each new thread
7525 that uses the btrace recording method and the Intel Processor Trace
7526 format. The actually obtained buffer size may differ from the
7527 requested @var{size}. Use the @code{info record} command to see the
7528 actual buffer size for each thread.
7529
7530 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7531 allocate a buffer of 4MB.
7532
7533 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7534 also need longer to process the branch trace data before it can be used.
7535
7536 @item show record btrace pt buffer-size @var{size}
7537 Show the current setting of the requested ring buffer size for branch
7538 tracing in Intel Processor Trace format.
7539
7540 @kindex info record
7541 @item info record
7542 Show various statistics about the recording depending on the recording
7543 method:
7544
7545 @table @code
7546 @item full
7547 For the @code{full} recording method, it shows the state of process
7548 record and its in-memory execution log buffer, including:
7549
7550 @itemize @bullet
7551 @item
7552 Whether in record mode or replay mode.
7553 @item
7554 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7555 @item
7556 Highest recorded instruction number.
7557 @item
7558 Current instruction about to be replayed (if in replay mode).
7559 @item
7560 Number of instructions contained in the execution log.
7561 @item
7562 Maximum number of instructions that may be contained in the execution log.
7563 @end itemize
7564
7565 @item btrace
7566 For the @code{btrace} recording method, it shows:
7567
7568 @itemize @bullet
7569 @item
7570 Recording format.
7571 @item
7572 Number of instructions that have been recorded.
7573 @item
7574 Number of blocks of sequential control-flow formed by the recorded
7575 instructions.
7576 @item
7577 Whether in record mode or replay mode.
7578 @end itemize
7579
7580 For the @code{bts} recording format, it also shows:
7581 @itemize @bullet
7582 @item
7583 Size of the perf ring buffer.
7584 @end itemize
7585
7586 For the @code{pt} recording format, it also shows:
7587 @itemize @bullet
7588 @item
7589 Size of the perf ring buffer.
7590 @end itemize
7591 @end table
7592
7593 @kindex record delete
7594 @kindex rec del
7595 @item record delete
7596 When record target runs in replay mode (``in the past''), delete the
7597 subsequent execution log and begin to record a new execution log starting
7598 from the current address. This means you will abandon the previously
7599 recorded ``future'' and begin recording a new ``future''.
7600
7601 @kindex record instruction-history
7602 @kindex rec instruction-history
7603 @item record instruction-history
7604 Disassembles instructions from the recorded execution log. By
7605 default, ten instructions are disassembled. This can be changed using
7606 the @code{set record instruction-history-size} command. Instructions
7607 are printed in execution order.
7608
7609 It can also print mixed source+disassembly if you specify the the
7610 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7611 as well as in symbolic form by specifying the @code{/r} modifier.
7612
7613 The current position marker is printed for the instruction at the
7614 current program counter value. This instruction can appear multiple
7615 times in the trace and the current position marker will be printed
7616 every time. To omit the current position marker, specify the
7617 @code{/p} modifier.
7618
7619 To better align the printed instructions when the trace contains
7620 instructions from more than one function, the function name may be
7621 omitted by specifying the @code{/f} modifier.
7622
7623 Speculatively executed instructions are prefixed with @samp{?}. This
7624 feature is not available for all recording formats.
7625
7626 There are several ways to specify what part of the execution log to
7627 disassemble:
7628
7629 @table @code
7630 @item record instruction-history @var{insn}
7631 Disassembles ten instructions starting from instruction number
7632 @var{insn}.
7633
7634 @item record instruction-history @var{insn}, +/-@var{n}
7635 Disassembles @var{n} instructions around instruction number
7636 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7637 @var{n} instructions after instruction number @var{insn}. If
7638 @var{n} is preceded with @code{-}, disassembles @var{n}
7639 instructions before instruction number @var{insn}.
7640
7641 @item record instruction-history
7642 Disassembles ten more instructions after the last disassembly.
7643
7644 @item record instruction-history -
7645 Disassembles ten more instructions before the last disassembly.
7646
7647 @item record instruction-history @var{begin}, @var{end}
7648 Disassembles instructions beginning with instruction number
7649 @var{begin} until instruction number @var{end}. The instruction
7650 number @var{end} is included.
7651 @end table
7652
7653 This command may not be available for all recording methods.
7654
7655 @kindex set record
7656 @item set record instruction-history-size @var{size}
7657 @itemx set record instruction-history-size unlimited
7658 Define how many instructions to disassemble in the @code{record
7659 instruction-history} command. The default value is 10.
7660 A @var{size} of @code{unlimited} means unlimited instructions.
7661
7662 @kindex show record
7663 @item show record instruction-history-size
7664 Show how many instructions to disassemble in the @code{record
7665 instruction-history} command.
7666
7667 @kindex record function-call-history
7668 @kindex rec function-call-history
7669 @item record function-call-history
7670 Prints the execution history at function granularity. It prints one
7671 line for each sequence of instructions that belong to the same
7672 function giving the name of that function, the source lines
7673 for this instruction sequence (if the @code{/l} modifier is
7674 specified), and the instructions numbers that form the sequence (if
7675 the @code{/i} modifier is specified). The function names are indented
7676 to reflect the call stack depth if the @code{/c} modifier is
7677 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7678 given together.
7679
7680 @smallexample
7681 (@value{GDBP}) @b{list 1, 10}
7682 1 void foo (void)
7683 2 @{
7684 3 @}
7685 4
7686 5 void bar (void)
7687 6 @{
7688 7 ...
7689 8 foo ();
7690 9 ...
7691 10 @}
7692 (@value{GDBP}) @b{record function-call-history /ilc}
7693 1 bar inst 1,4 at foo.c:6,8
7694 2 foo inst 5,10 at foo.c:2,3
7695 3 bar inst 11,13 at foo.c:9,10
7696 @end smallexample
7697
7698 By default, ten lines are printed. This can be changed using the
7699 @code{set record function-call-history-size} command. Functions are
7700 printed in execution order. There are several ways to specify what
7701 to print:
7702
7703 @table @code
7704 @item record function-call-history @var{func}
7705 Prints ten functions starting from function number @var{func}.
7706
7707 @item record function-call-history @var{func}, +/-@var{n}
7708 Prints @var{n} functions around function number @var{func}. If
7709 @var{n} is preceded with @code{+}, prints @var{n} functions after
7710 function number @var{func}. If @var{n} is preceded with @code{-},
7711 prints @var{n} functions before function number @var{func}.
7712
7713 @item record function-call-history
7714 Prints ten more functions after the last ten-line print.
7715
7716 @item record function-call-history -
7717 Prints ten more functions before the last ten-line print.
7718
7719 @item record function-call-history @var{begin}, @var{end}
7720 Prints functions beginning with function number @var{begin} until
7721 function number @var{end}. The function number @var{end} is included.
7722 @end table
7723
7724 This command may not be available for all recording methods.
7725
7726 @item set record function-call-history-size @var{size}
7727 @itemx set record function-call-history-size unlimited
7728 Define how many lines to print in the
7729 @code{record function-call-history} command. The default value is 10.
7730 A size of @code{unlimited} means unlimited lines.
7731
7732 @item show record function-call-history-size
7733 Show how many lines to print in the
7734 @code{record function-call-history} command.
7735 @end table
7736
7737
7738 @node Stack
7739 @chapter Examining the Stack
7740
7741 When your program has stopped, the first thing you need to know is where it
7742 stopped and how it got there.
7743
7744 @cindex call stack
7745 Each time your program performs a function call, information about the call
7746 is generated.
7747 That information includes the location of the call in your program,
7748 the arguments of the call,
7749 and the local variables of the function being called.
7750 The information is saved in a block of data called a @dfn{stack frame}.
7751 The stack frames are allocated in a region of memory called the @dfn{call
7752 stack}.
7753
7754 When your program stops, the @value{GDBN} commands for examining the
7755 stack allow you to see all of this information.
7756
7757 @cindex selected frame
7758 One of the stack frames is @dfn{selected} by @value{GDBN} and many
7759 @value{GDBN} commands refer implicitly to the selected frame. In
7760 particular, whenever you ask @value{GDBN} for the value of a variable in
7761 your program, the value is found in the selected frame. There are
7762 special @value{GDBN} commands to select whichever frame you are
7763 interested in. @xref{Selection, ,Selecting a Frame}.
7764
7765 When your program stops, @value{GDBN} automatically selects the
7766 currently executing frame and describes it briefly, similar to the
7767 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
7768
7769 @menu
7770 * Frames:: Stack frames
7771 * Backtrace:: Backtraces
7772 * Selection:: Selecting a frame
7773 * Frame Info:: Information on a frame
7774 * Frame Apply:: Applying a command to several frames
7775 * Frame Filter Management:: Managing frame filters
7776
7777 @end menu
7778
7779 @node Frames
7780 @section Stack Frames
7781
7782 @cindex frame, definition
7783 @cindex stack frame
7784 The call stack is divided up into contiguous pieces called @dfn{stack
7785 frames}, or @dfn{frames} for short; each frame is the data associated
7786 with one call to one function. The frame contains the arguments given
7787 to the function, the function's local variables, and the address at
7788 which the function is executing.
7789
7790 @cindex initial frame
7791 @cindex outermost frame
7792 @cindex innermost frame
7793 When your program is started, the stack has only one frame, that of the
7794 function @code{main}. This is called the @dfn{initial} frame or the
7795 @dfn{outermost} frame. Each time a function is called, a new frame is
7796 made. Each time a function returns, the frame for that function invocation
7797 is eliminated. If a function is recursive, there can be many frames for
7798 the same function. The frame for the function in which execution is
7799 actually occurring is called the @dfn{innermost} frame. This is the most
7800 recently created of all the stack frames that still exist.
7801
7802 @cindex frame pointer
7803 Inside your program, stack frames are identified by their addresses. A
7804 stack frame consists of many bytes, each of which has its own address; each
7805 kind of computer has a convention for choosing one byte whose
7806 address serves as the address of the frame. Usually this address is kept
7807 in a register called the @dfn{frame pointer register}
7808 (@pxref{Registers, $fp}) while execution is going on in that frame.
7809
7810 @cindex frame level
7811 @cindex frame number
7812 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
7813 number that is zero for the innermost frame, one for the frame that
7814 called it, and so on upward. These level numbers give you a way of
7815 designating stack frames in @value{GDBN} commands. The terms
7816 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
7817 describe this number.
7818
7819 @c The -fomit-frame-pointer below perennially causes hbox overflow
7820 @c underflow problems.
7821 @cindex frameless execution
7822 Some compilers provide a way to compile functions so that they operate
7823 without stack frames. (For example, the @value{NGCC} option
7824 @smallexample
7825 @samp{-fomit-frame-pointer}
7826 @end smallexample
7827 generates functions without a frame.)
7828 This is occasionally done with heavily used library functions to save
7829 the frame setup time. @value{GDBN} has limited facilities for dealing
7830 with these function invocations. If the innermost function invocation
7831 has no stack frame, @value{GDBN} nevertheless regards it as though
7832 it had a separate frame, which is numbered zero as usual, allowing
7833 correct tracing of the function call chain. However, @value{GDBN} has
7834 no provision for frameless functions elsewhere in the stack.
7835
7836 @node Backtrace
7837 @section Backtraces
7838
7839 @cindex traceback
7840 @cindex call stack traces
7841 A backtrace is a summary of how your program got where it is. It shows one
7842 line per frame, for many frames, starting with the currently executing
7843 frame (frame zero), followed by its caller (frame one), and on up the
7844 stack.
7845
7846 @anchor{backtrace-command}
7847 @kindex backtrace
7848 @kindex bt @r{(@code{backtrace})}
7849 To print a backtrace of the entire stack, use the @code{backtrace}
7850 command, or its alias @code{bt}. This command will print one line per
7851 frame for frames in the stack. By default, all stack frames are
7852 printed. You can stop the backtrace at any time by typing the system
7853 interrupt character, normally @kbd{Ctrl-c}.
7854
7855 @table @code
7856 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7857 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7858 Print the backtrace of the entire stack.
7859
7860 The optional @var{count} can be one of the following:
7861
7862 @table @code
7863 @item @var{n}
7864 @itemx @var{n}
7865 Print only the innermost @var{n} frames, where @var{n} is a positive
7866 number.
7867
7868 @item -@var{n}
7869 @itemx -@var{n}
7870 Print only the outermost @var{n} frames, where @var{n} is a positive
7871 number.
7872 @end table
7873
7874 Options:
7875
7876 @table @code
7877 @item -full
7878 Print the values of the local variables also. This can be combined
7879 with the optional @var{count} to limit the number of frames shown.
7880
7881 @item -no-filters
7882 Do not run Python frame filters on this backtrace. @xref{Frame
7883 Filter API}, for more information. Additionally use @ref{disable
7884 frame-filter all} to turn off all frame filters. This is only
7885 relevant when @value{GDBN} has been configured with @code{Python}
7886 support.
7887
7888 @item -hide
7889 A Python frame filter might decide to ``elide'' some frames. Normally
7890 such elided frames are still printed, but they are indented relative
7891 to the filtered frames that cause them to be elided. The @code{-hide}
7892 option causes elided frames to not be printed at all.
7893 @end table
7894
7895 The @code{backtrace} command also supports a number of options that
7896 allow overriding relevant global print settings as set by @code{set
7897 backtrace} and @code{set print} subcommands:
7898
7899 @table @code
7900 @item -past-main [@code{on}|@code{off}]
7901 Set whether backtraces should continue past @code{main}. Related setting:
7902 @ref{set backtrace past-main}.
7903
7904 @item -past-entry [@code{on}|@code{off}]
7905 Set whether backtraces should continue past the entry point of a program.
7906 Related setting: @ref{set backtrace past-entry}.
7907
7908 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
7909 Set printing of function arguments at function entry.
7910 Related setting: @ref{set print entry-values}.
7911
7912 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
7913 Set printing of non-scalar frame arguments.
7914 Related setting: @ref{set print frame-arguments}.
7915
7916 @item -raw-frame-arguments [@code{on}|@code{off}]
7917 Set whether to print frame arguments in raw form.
7918 Related setting: @ref{set print raw-frame-arguments}.
7919
7920 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
7921 Set printing of frame information.
7922 Related setting: @ref{set print frame-info}.
7923 @end table
7924
7925 The optional @var{qualifier} is maintained for backward compatibility.
7926 It can be one of the following:
7927
7928 @table @code
7929 @item full
7930 Equivalent to the @code{-full} option.
7931
7932 @item no-filters
7933 Equivalent to the @code{-no-filters} option.
7934
7935 @item hide
7936 Equivalent to the @code{-hide} option.
7937 @end table
7938
7939 @end table
7940
7941 @kindex where
7942 @kindex info stack
7943 The names @code{where} and @code{info stack} (abbreviated @code{info s})
7944 are additional aliases for @code{backtrace}.
7945
7946 @cindex multiple threads, backtrace
7947 In a multi-threaded program, @value{GDBN} by default shows the
7948 backtrace only for the current thread. To display the backtrace for
7949 several or all of the threads, use the command @code{thread apply}
7950 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7951 apply all backtrace}, @value{GDBN} will display the backtrace for all
7952 the threads; this is handy when you debug a core dump of a
7953 multi-threaded program.
7954
7955 Each line in the backtrace shows the frame number and the function name.
7956 The program counter value is also shown---unless you use @code{set
7957 print address off}. The backtrace also shows the source file name and
7958 line number, as well as the arguments to the function. The program
7959 counter value is omitted if it is at the beginning of the code for that
7960 line number.
7961
7962 Here is an example of a backtrace. It was made with the command
7963 @samp{bt 3}, so it shows the innermost three frames.
7964
7965 @smallexample
7966 @group
7967 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7968 at builtin.c:993
7969 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
7970 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7971 at macro.c:71
7972 (More stack frames follow...)
7973 @end group
7974 @end smallexample
7975
7976 @noindent
7977 The display for frame zero does not begin with a program counter
7978 value, indicating that your program has stopped at the beginning of the
7979 code for line @code{993} of @code{builtin.c}.
7980
7981 @noindent
7982 The value of parameter @code{data} in frame 1 has been replaced by
7983 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7984 only if it is a scalar (integer, pointer, enumeration, etc). See command
7985 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
7986 on how to configure the way function parameter values are printed.
7987 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
7988 what frame information is printed.
7989
7990 @cindex optimized out, in backtrace
7991 @cindex function call arguments, optimized out
7992 If your program was compiled with optimizations, some compilers will
7993 optimize away arguments passed to functions if those arguments are
7994 never used after the call. Such optimizations generate code that
7995 passes arguments through registers, but doesn't store those arguments
7996 in the stack frame. @value{GDBN} has no way of displaying such
7997 arguments in stack frames other than the innermost one. Here's what
7998 such a backtrace might look like:
7999
8000 @smallexample
8001 @group
8002 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8003 at builtin.c:993
8004 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8005 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8006 at macro.c:71
8007 (More stack frames follow...)
8008 @end group
8009 @end smallexample
8010
8011 @noindent
8012 The values of arguments that were not saved in their stack frames are
8013 shown as @samp{<optimized out>}.
8014
8015 If you need to display the values of such optimized-out arguments,
8016 either deduce that from other variables whose values depend on the one
8017 you are interested in, or recompile without optimizations.
8018
8019 @cindex backtrace beyond @code{main} function
8020 @cindex program entry point
8021 @cindex startup code, and backtrace
8022 Most programs have a standard user entry point---a place where system
8023 libraries and startup code transition into user code. For C this is
8024 @code{main}@footnote{
8025 Note that embedded programs (the so-called ``free-standing''
8026 environment) are not required to have a @code{main} function as the
8027 entry point. They could even have multiple entry points.}.
8028 When @value{GDBN} finds the entry function in a backtrace
8029 it will terminate the backtrace, to avoid tracing into highly
8030 system-specific (and generally uninteresting) code.
8031
8032 If you need to examine the startup code, or limit the number of levels
8033 in a backtrace, you can change this behavior:
8034
8035 @table @code
8036 @item set backtrace past-main
8037 @itemx set backtrace past-main on
8038 @anchor{set backtrace past-main}
8039 @kindex set backtrace
8040 Backtraces will continue past the user entry point.
8041
8042 @item set backtrace past-main off
8043 Backtraces will stop when they encounter the user entry point. This is the
8044 default.
8045
8046 @item show backtrace past-main
8047 @kindex show backtrace
8048 Display the current user entry point backtrace policy.
8049
8050 @item set backtrace past-entry
8051 @itemx set backtrace past-entry on
8052 @anchor{set backtrace past-entry}
8053 Backtraces will continue past the internal entry point of an application.
8054 This entry point is encoded by the linker when the application is built,
8055 and is likely before the user entry point @code{main} (or equivalent) is called.
8056
8057 @item set backtrace past-entry off
8058 Backtraces will stop when they encounter the internal entry point of an
8059 application. This is the default.
8060
8061 @item show backtrace past-entry
8062 Display the current internal entry point backtrace policy.
8063
8064 @item set backtrace limit @var{n}
8065 @itemx set backtrace limit 0
8066 @itemx set backtrace limit unlimited
8067 @anchor{set backtrace limit}
8068 @cindex backtrace limit
8069 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8070 or zero means unlimited levels.
8071
8072 @item show backtrace limit
8073 Display the current limit on backtrace levels.
8074 @end table
8075
8076 You can control how file names are displayed.
8077
8078 @table @code
8079 @item set filename-display
8080 @itemx set filename-display relative
8081 @cindex filename-display
8082 Display file names relative to the compilation directory. This is the default.
8083
8084 @item set filename-display basename
8085 Display only basename of a filename.
8086
8087 @item set filename-display absolute
8088 Display an absolute filename.
8089
8090 @item show filename-display
8091 Show the current way to display filenames.
8092 @end table
8093
8094 @node Selection
8095 @section Selecting a Frame
8096
8097 Most commands for examining the stack and other data in your program work on
8098 whichever stack frame is selected at the moment. Here are the commands for
8099 selecting a stack frame; all of them finish by printing a brief description
8100 of the stack frame just selected.
8101
8102 @table @code
8103 @kindex frame@r{, selecting}
8104 @kindex f @r{(@code{frame})}
8105 @item frame @r{[} @var{frame-selection-spec} @r{]}
8106 @item f @r{[} @var{frame-selection-spec} @r{]}
8107 The @command{frame} command allows different stack frames to be
8108 selected. The @var{frame-selection-spec} can be any of the following:
8109
8110 @table @code
8111 @kindex frame level
8112 @item @var{num}
8113 @item level @var{num}
8114 Select frame level @var{num}. Recall that frame zero is the innermost
8115 (currently executing) frame, frame one is the frame that called the
8116 innermost one, and so on. The highest level frame is usually the one
8117 for @code{main}.
8118
8119 As this is the most common method of navigating the frame stack, the
8120 string @command{level} can be omitted. For example, the following two
8121 commands are equivalent:
8122
8123 @smallexample
8124 (@value{GDBP}) frame 3
8125 (@value{GDBP}) frame level 3
8126 @end smallexample
8127
8128 @kindex frame address
8129 @item address @var{stack-address}
8130 Select the frame with stack address @var{stack-address}. The
8131 @var{stack-address} for a frame can be seen in the output of
8132 @command{info frame}, for example:
8133
8134 @smallexample
8135 (gdb) info frame
8136 Stack level 1, frame at 0x7fffffffda30:
8137 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8138 tail call frame, caller of frame at 0x7fffffffda30
8139 source language c++.
8140 Arglist at unknown address.
8141 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8142 @end smallexample
8143
8144 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8145 indicated by the line:
8146
8147 @smallexample
8148 Stack level 1, frame at 0x7fffffffda30:
8149 @end smallexample
8150
8151 @kindex frame function
8152 @item function @var{function-name}
8153 Select the stack frame for function @var{function-name}. If there are
8154 multiple stack frames for function @var{function-name} then the inner
8155 most stack frame is selected.
8156
8157 @kindex frame view
8158 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8159 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8160 viewed has stack address @var{stack-addr}, and optionally, a program
8161 counter address of @var{pc-addr}.
8162
8163 This is useful mainly if the chaining of stack frames has been
8164 damaged by a bug, making it impossible for @value{GDBN} to assign
8165 numbers properly to all frames. In addition, this can be useful
8166 when your program has multiple stacks and switches between them.
8167
8168 When viewing a frame outside the current backtrace using
8169 @command{frame view} then you can always return to the original
8170 stack using one of the previous stack frame selection instructions,
8171 for example @command{frame level 0}.
8172
8173 @end table
8174
8175 @kindex up
8176 @item up @var{n}
8177 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8178 numbers @var{n}, this advances toward the outermost frame, to higher
8179 frame numbers, to frames that have existed longer.
8180
8181 @kindex down
8182 @kindex do @r{(@code{down})}
8183 @item down @var{n}
8184 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8185 positive numbers @var{n}, this advances toward the innermost frame, to
8186 lower frame numbers, to frames that were created more recently.
8187 You may abbreviate @code{down} as @code{do}.
8188 @end table
8189
8190 All of these commands end by printing two lines of output describing the
8191 frame. The first line shows the frame number, the function name, the
8192 arguments, and the source file and line number of execution in that
8193 frame. The second line shows the text of that source line.
8194
8195 @need 1000
8196 For example:
8197
8198 @smallexample
8199 @group
8200 (@value{GDBP}) up
8201 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8202 at env.c:10
8203 10 read_input_file (argv[i]);
8204 @end group
8205 @end smallexample
8206
8207 After such a printout, the @code{list} command with no arguments
8208 prints ten lines centered on the point of execution in the frame.
8209 You can also edit the program at the point of execution with your favorite
8210 editing program by typing @code{edit}.
8211 @xref{List, ,Printing Source Lines},
8212 for details.
8213
8214 @table @code
8215 @kindex select-frame
8216 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8217 The @code{select-frame} command is a variant of @code{frame} that does
8218 not display the new frame after selecting it. This command is
8219 intended primarily for use in @value{GDBN} command scripts, where the
8220 output might be unnecessary and distracting. The
8221 @var{frame-selection-spec} is as for the @command{frame} command
8222 described in @ref{Selection, ,Selecting a Frame}.
8223
8224 @kindex down-silently
8225 @kindex up-silently
8226 @item up-silently @var{n}
8227 @itemx down-silently @var{n}
8228 These two commands are variants of @code{up} and @code{down},
8229 respectively; they differ in that they do their work silently, without
8230 causing display of the new frame. They are intended primarily for use
8231 in @value{GDBN} command scripts, where the output might be unnecessary and
8232 distracting.
8233 @end table
8234
8235 @node Frame Info
8236 @section Information About a Frame
8237
8238 There are several other commands to print information about the selected
8239 stack frame.
8240
8241 @table @code
8242 @item frame
8243 @itemx f
8244 When used without any argument, this command does not change which
8245 frame is selected, but prints a brief description of the currently
8246 selected stack frame. It can be abbreviated @code{f}. With an
8247 argument, this command is used to select a stack frame.
8248 @xref{Selection, ,Selecting a Frame}.
8249
8250 @kindex info frame
8251 @kindex info f @r{(@code{info frame})}
8252 @item info frame
8253 @itemx info f
8254 This command prints a verbose description of the selected stack frame,
8255 including:
8256
8257 @itemize @bullet
8258 @item
8259 the address of the frame
8260 @item
8261 the address of the next frame down (called by this frame)
8262 @item
8263 the address of the next frame up (caller of this frame)
8264 @item
8265 the language in which the source code corresponding to this frame is written
8266 @item
8267 the address of the frame's arguments
8268 @item
8269 the address of the frame's local variables
8270 @item
8271 the program counter saved in it (the address of execution in the caller frame)
8272 @item
8273 which registers were saved in the frame
8274 @end itemize
8275
8276 @noindent The verbose description is useful when
8277 something has gone wrong that has made the stack format fail to fit
8278 the usual conventions.
8279
8280 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8281 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8282 Print a verbose description of the frame selected by
8283 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8284 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8285 a Frame}). The selected frame remains unchanged by this command.
8286
8287 @kindex info args
8288 @item info args [-q]
8289 Print the arguments of the selected frame, each on a separate line.
8290
8291 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8292 printing header information and messages explaining why no argument
8293 have been printed.
8294
8295 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8296 Like @kbd{info args}, but only print the arguments selected
8297 with the provided regexp(s).
8298
8299 If @var{regexp} is provided, print only the arguments whose names
8300 match the regular expression @var{regexp}.
8301
8302 If @var{type_regexp} is provided, print only the arguments whose
8303 types, as printed by the @code{whatis} command, match
8304 the regular expression @var{type_regexp}.
8305 If @var{type_regexp} contains space(s), it should be enclosed in
8306 quote characters. If needed, use backslash to escape the meaning
8307 of special characters or quotes.
8308
8309 If both @var{regexp} and @var{type_regexp} are provided, an argument
8310 is printed only if its name matches @var{regexp} and its type matches
8311 @var{type_regexp}.
8312
8313 @item info locals [-q]
8314 @kindex info locals
8315 Print the local variables of the selected frame, each on a separate
8316 line. These are all variables (declared either static or automatic)
8317 accessible at the point of execution of the selected frame.
8318
8319 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8320 printing header information and messages explaining why no local variables
8321 have been printed.
8322
8323 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8324 Like @kbd{info locals}, but only print the local variables selected
8325 with the provided regexp(s).
8326
8327 If @var{regexp} is provided, print only the local variables whose names
8328 match the regular expression @var{regexp}.
8329
8330 If @var{type_regexp} is provided, print only the local variables whose
8331 types, as printed by the @code{whatis} command, match
8332 the regular expression @var{type_regexp}.
8333 If @var{type_regexp} contains space(s), it should be enclosed in
8334 quote characters. If needed, use backslash to escape the meaning
8335 of special characters or quotes.
8336
8337 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8338 is printed only if its name matches @var{regexp} and its type matches
8339 @var{type_regexp}.
8340
8341 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8342 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8343 For example, your program might use Resource Acquisition Is
8344 Initialization types (RAII) such as @code{lock_something_t}: each
8345 local variable of type @code{lock_something_t} automatically places a
8346 lock that is destroyed when the variable goes out of scope. You can
8347 then list all acquired locks in your program by doing
8348 @smallexample
8349 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8350 @end smallexample
8351 @noindent
8352 or the equivalent shorter form
8353 @smallexample
8354 tfaas i lo -q -t lock_something_t
8355 @end smallexample
8356
8357 @end table
8358
8359 @node Frame Apply
8360 @section Applying a Command to Several Frames.
8361 @anchor{frame apply}
8362 @kindex frame apply
8363 @cindex apply command to several frames
8364 @table @code
8365 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8366 The @code{frame apply} command allows you to apply the named
8367 @var{command} to one or more frames.
8368
8369 @table @code
8370 @item @code{all}
8371 Specify @code{all} to apply @var{command} to all frames.
8372
8373 @item @var{count}
8374 Use @var{count} to apply @var{command} to the innermost @var{count}
8375 frames, where @var{count} is a positive number.
8376
8377 @item @var{-count}
8378 Use @var{-count} to apply @var{command} to the outermost @var{count}
8379 frames, where @var{count} is a positive number.
8380
8381 @item @code{level}
8382 Use @code{level} to apply @var{command} to the set of frames identified
8383 by the @var{level} list. @var{level} is a frame level or a range of frame
8384 levels as @var{level1}-@var{level2}. The frame level is the number shown
8385 in the first field of the @samp{backtrace} command output.
8386 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8387 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8388
8389 @end table
8390
8391 Note that the frames on which @code{frame apply} applies a command are
8392 also influenced by the @code{set backtrace} settings such as @code{set
8393 backtrace past-main} and @code{set backtrace limit N}.
8394 @xref{Backtrace,,Backtraces}.
8395
8396 The @code{frame apply} command also supports a number of options that
8397 allow overriding relevant @code{set backtrace} settings:
8398
8399 @table @code
8400 @item -past-main [@code{on}|@code{off}]
8401 Whether backtraces should continue past @code{main}.
8402 Related setting: @ref{set backtrace past-main}.
8403
8404 @item -past-entry [@code{on}|@code{off}]
8405 Whether backtraces should continue past the entry point of a program.
8406 Related setting: @ref{set backtrace past-entry}.
8407 @end table
8408
8409 By default, @value{GDBN} displays some frame information before the
8410 output produced by @var{command}, and an error raised during the
8411 execution of a @var{command} will abort @code{frame apply}. The
8412 following options can be used to fine-tune these behaviors:
8413
8414 @table @code
8415 @item -c
8416 The flag @code{-c}, which stands for @samp{continue}, causes any
8417 errors in @var{command} to be displayed, and the execution of
8418 @code{frame apply} then continues.
8419 @item -s
8420 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8421 or empty output produced by a @var{command} to be silently ignored.
8422 That is, the execution continues, but the frame information and errors
8423 are not printed.
8424 @item -q
8425 The flag @code{-q} (@samp{quiet}) disables printing the frame
8426 information.
8427 @end table
8428
8429 The following example shows how the flags @code{-c} and @code{-s} are
8430 working when applying the command @code{p j} to all frames, where
8431 variable @code{j} can only be successfully printed in the outermost
8432 @code{#1 main} frame.
8433
8434 @smallexample
8435 @group
8436 (gdb) frame apply all p j
8437 #0 some_function (i=5) at fun.c:4
8438 No symbol "j" in current context.
8439 (gdb) frame apply all -c p j
8440 #0 some_function (i=5) at fun.c:4
8441 No symbol "j" in current context.
8442 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8443 $1 = 5
8444 (gdb) frame apply all -s p j
8445 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8446 $2 = 5
8447 (gdb)
8448 @end group
8449 @end smallexample
8450
8451 By default, @samp{frame apply}, prints the frame location
8452 information before the command output:
8453
8454 @smallexample
8455 @group
8456 (gdb) frame apply all p $sp
8457 #0 some_function (i=5) at fun.c:4
8458 $4 = (void *) 0xffffd1e0
8459 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8460 $5 = (void *) 0xffffd1f0
8461 (gdb)
8462 @end group
8463 @end smallexample
8464
8465 If the flag @code{-q} is given, no frame information is printed:
8466 @smallexample
8467 @group
8468 (gdb) frame apply all -q p $sp
8469 $12 = (void *) 0xffffd1e0
8470 $13 = (void *) 0xffffd1f0
8471 (gdb)
8472 @end group
8473 @end smallexample
8474
8475 @end table
8476
8477 @table @code
8478
8479 @kindex faas
8480 @cindex apply a command to all frames (ignoring errors and empty output)
8481 @item faas @var{command}
8482 Shortcut for @code{frame apply all -s @var{command}}.
8483 Applies @var{command} on all frames, ignoring errors and empty output.
8484
8485 It can for example be used to print a local variable or a function
8486 argument without knowing the frame where this variable or argument
8487 is, using:
8488 @smallexample
8489 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8490 @end smallexample
8491
8492 The @code{faas} command accepts the same options as the @code{frame
8493 apply} command. @xref{frame apply}.
8494
8495 Note that the command @code{tfaas @var{command}} applies @var{command}
8496 on all frames of all threads. See @xref{Threads,,Threads}.
8497 @end table
8498
8499
8500 @node Frame Filter Management
8501 @section Management of Frame Filters.
8502 @cindex managing frame filters
8503
8504 Frame filters are Python based utilities to manage and decorate the
8505 output of frames. @xref{Frame Filter API}, for further information.
8506
8507 Managing frame filters is performed by several commands available
8508 within @value{GDBN}, detailed here.
8509
8510 @table @code
8511 @kindex info frame-filter
8512 @item info frame-filter
8513 Print a list of installed frame filters from all dictionaries, showing
8514 their name, priority and enabled status.
8515
8516 @kindex disable frame-filter
8517 @anchor{disable frame-filter all}
8518 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8519 Disable a frame filter in the dictionary matching
8520 @var{filter-dictionary} and @var{filter-name}. The
8521 @var{filter-dictionary} may be @code{all}, @code{global},
8522 @code{progspace}, or the name of the object file where the frame filter
8523 dictionary resides. When @code{all} is specified, all frame filters
8524 across all dictionaries are disabled. The @var{filter-name} is the name
8525 of the frame filter and is used when @code{all} is not the option for
8526 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8527 may be enabled again later.
8528
8529 @kindex enable frame-filter
8530 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8531 Enable a frame filter in the dictionary matching
8532 @var{filter-dictionary} and @var{filter-name}. The
8533 @var{filter-dictionary} may be @code{all}, @code{global},
8534 @code{progspace} or the name of the object file where the frame filter
8535 dictionary resides. When @code{all} is specified, all frame filters across
8536 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8537 filter and is used when @code{all} is not the option for
8538 @var{filter-dictionary}.
8539
8540 Example:
8541
8542 @smallexample
8543 (gdb) info frame-filter
8544
8545 global frame-filters:
8546 Priority Enabled Name
8547 1000 No PrimaryFunctionFilter
8548 100 Yes Reverse
8549
8550 progspace /build/test frame-filters:
8551 Priority Enabled Name
8552 100 Yes ProgspaceFilter
8553
8554 objfile /build/test frame-filters:
8555 Priority Enabled Name
8556 999 Yes BuildProgramFilter
8557
8558 (gdb) disable frame-filter /build/test BuildProgramFilter
8559 (gdb) info frame-filter
8560
8561 global frame-filters:
8562 Priority Enabled Name
8563 1000 No PrimaryFunctionFilter
8564 100 Yes Reverse
8565
8566 progspace /build/test frame-filters:
8567 Priority Enabled Name
8568 100 Yes ProgspaceFilter
8569
8570 objfile /build/test frame-filters:
8571 Priority Enabled Name
8572 999 No BuildProgramFilter
8573
8574 (gdb) enable frame-filter global PrimaryFunctionFilter
8575 (gdb) info frame-filter
8576
8577 global frame-filters:
8578 Priority Enabled Name
8579 1000 Yes PrimaryFunctionFilter
8580 100 Yes Reverse
8581
8582 progspace /build/test frame-filters:
8583 Priority Enabled Name
8584 100 Yes ProgspaceFilter
8585
8586 objfile /build/test frame-filters:
8587 Priority Enabled Name
8588 999 No BuildProgramFilter
8589 @end smallexample
8590
8591 @kindex set frame-filter priority
8592 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8593 Set the @var{priority} of a frame filter in the dictionary matching
8594 @var{filter-dictionary}, and the frame filter name matching
8595 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8596 @code{progspace} or the name of the object file where the frame filter
8597 dictionary resides. The @var{priority} is an integer.
8598
8599 @kindex show frame-filter priority
8600 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8601 Show the @var{priority} of a frame filter in the dictionary matching
8602 @var{filter-dictionary}, and the frame filter name matching
8603 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8604 @code{progspace} or the name of the object file where the frame filter
8605 dictionary resides.
8606
8607 Example:
8608
8609 @smallexample
8610 (gdb) info frame-filter
8611
8612 global frame-filters:
8613 Priority Enabled Name
8614 1000 Yes PrimaryFunctionFilter
8615 100 Yes Reverse
8616
8617 progspace /build/test frame-filters:
8618 Priority Enabled Name
8619 100 Yes ProgspaceFilter
8620
8621 objfile /build/test frame-filters:
8622 Priority Enabled Name
8623 999 No BuildProgramFilter
8624
8625 (gdb) set frame-filter priority global Reverse 50
8626 (gdb) info frame-filter
8627
8628 global frame-filters:
8629 Priority Enabled Name
8630 1000 Yes PrimaryFunctionFilter
8631 50 Yes Reverse
8632
8633 progspace /build/test frame-filters:
8634 Priority Enabled Name
8635 100 Yes ProgspaceFilter
8636
8637 objfile /build/test frame-filters:
8638 Priority Enabled Name
8639 999 No BuildProgramFilter
8640 @end smallexample
8641 @end table
8642
8643 @node Source
8644 @chapter Examining Source Files
8645
8646 @value{GDBN} can print parts of your program's source, since the debugging
8647 information recorded in the program tells @value{GDBN} what source files were
8648 used to build it. When your program stops, @value{GDBN} spontaneously prints
8649 the line where it stopped. Likewise, when you select a stack frame
8650 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8651 execution in that frame has stopped. You can print other portions of
8652 source files by explicit command.
8653
8654 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8655 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8656 @value{GDBN} under @sc{gnu} Emacs}.
8657
8658 @menu
8659 * List:: Printing source lines
8660 * Specify Location:: How to specify code locations
8661 * Edit:: Editing source files
8662 * Search:: Searching source files
8663 * Source Path:: Specifying source directories
8664 * Machine Code:: Source and machine code
8665 @end menu
8666
8667 @node List
8668 @section Printing Source Lines
8669
8670 @kindex list
8671 @kindex l @r{(@code{list})}
8672 To print lines from a source file, use the @code{list} command
8673 (abbreviated @code{l}). By default, ten lines are printed.
8674 There are several ways to specify what part of the file you want to
8675 print; see @ref{Specify Location}, for the full list.
8676
8677 Here are the forms of the @code{list} command most commonly used:
8678
8679 @table @code
8680 @item list @var{linenum}
8681 Print lines centered around line number @var{linenum} in the
8682 current source file.
8683
8684 @item list @var{function}
8685 Print lines centered around the beginning of function
8686 @var{function}.
8687
8688 @item list
8689 Print more lines. If the last lines printed were printed with a
8690 @code{list} command, this prints lines following the last lines
8691 printed; however, if the last line printed was a solitary line printed
8692 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8693 Stack}), this prints lines centered around that line.
8694
8695 @item list -
8696 Print lines just before the lines last printed.
8697 @end table
8698
8699 @cindex @code{list}, how many lines to display
8700 By default, @value{GDBN} prints ten source lines with any of these forms of
8701 the @code{list} command. You can change this using @code{set listsize}:
8702
8703 @table @code
8704 @kindex set listsize
8705 @item set listsize @var{count}
8706 @itemx set listsize unlimited
8707 Make the @code{list} command display @var{count} source lines (unless
8708 the @code{list} argument explicitly specifies some other number).
8709 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8710
8711 @kindex show listsize
8712 @item show listsize
8713 Display the number of lines that @code{list} prints.
8714 @end table
8715
8716 Repeating a @code{list} command with @key{RET} discards the argument,
8717 so it is equivalent to typing just @code{list}. This is more useful
8718 than listing the same lines again. An exception is made for an
8719 argument of @samp{-}; that argument is preserved in repetition so that
8720 each repetition moves up in the source file.
8721
8722 In general, the @code{list} command expects you to supply zero, one or two
8723 @dfn{locations}. Locations specify source lines; there are several ways
8724 of writing them (@pxref{Specify Location}), but the effect is always
8725 to specify some source line.
8726
8727 Here is a complete description of the possible arguments for @code{list}:
8728
8729 @table @code
8730 @item list @var{location}
8731 Print lines centered around the line specified by @var{location}.
8732
8733 @item list @var{first},@var{last}
8734 Print lines from @var{first} to @var{last}. Both arguments are
8735 locations. When a @code{list} command has two locations, and the
8736 source file of the second location is omitted, this refers to
8737 the same source file as the first location.
8738
8739 @item list ,@var{last}
8740 Print lines ending with @var{last}.
8741
8742 @item list @var{first},
8743 Print lines starting with @var{first}.
8744
8745 @item list +
8746 Print lines just after the lines last printed.
8747
8748 @item list -
8749 Print lines just before the lines last printed.
8750
8751 @item list
8752 As described in the preceding table.
8753 @end table
8754
8755 @node Specify Location
8756 @section Specifying a Location
8757 @cindex specifying location
8758 @cindex location
8759 @cindex source location
8760
8761 @menu
8762 * Linespec Locations:: Linespec locations
8763 * Explicit Locations:: Explicit locations
8764 * Address Locations:: Address locations
8765 @end menu
8766
8767 Several @value{GDBN} commands accept arguments that specify a location
8768 of your program's code. Since @value{GDBN} is a source-level
8769 debugger, a location usually specifies some line in the source code.
8770 Locations may be specified using three different formats:
8771 linespec locations, explicit locations, or address locations.
8772
8773 @node Linespec Locations
8774 @subsection Linespec Locations
8775 @cindex linespec locations
8776
8777 A @dfn{linespec} is a colon-separated list of source location parameters such
8778 as file name, function name, etc. Here are all the different ways of
8779 specifying a linespec:
8780
8781 @table @code
8782 @item @var{linenum}
8783 Specifies the line number @var{linenum} of the current source file.
8784
8785 @item -@var{offset}
8786 @itemx +@var{offset}
8787 Specifies the line @var{offset} lines before or after the @dfn{current
8788 line}. For the @code{list} command, the current line is the last one
8789 printed; for the breakpoint commands, this is the line at which
8790 execution stopped in the currently selected @dfn{stack frame}
8791 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
8792 used as the second of the two linespecs in a @code{list} command,
8793 this specifies the line @var{offset} lines up or down from the first
8794 linespec.
8795
8796 @item @var{filename}:@var{linenum}
8797 Specifies the line @var{linenum} in the source file @var{filename}.
8798 If @var{filename} is a relative file name, then it will match any
8799 source file name with the same trailing components. For example, if
8800 @var{filename} is @samp{gcc/expr.c}, then it will match source file
8801 name of @file{/build/trunk/gcc/expr.c}, but not
8802 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
8803
8804 @item @var{function}
8805 Specifies the line that begins the body of the function @var{function}.
8806 For example, in C, this is the line with the open brace.
8807
8808 By default, in C@t{++} and Ada, @var{function} is interpreted as
8809 specifying all functions named @var{function} in all scopes. For
8810 C@t{++}, this means in all namespaces and classes. For Ada, this
8811 means in all packages.
8812
8813 For example, assuming a program with C@t{++} symbols named
8814 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8815 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8816
8817 Commands that accept a linespec let you override this with the
8818 @code{-qualified} option. For example, @w{@kbd{break -qualified
8819 func}} sets a breakpoint on a free-function named @code{func} ignoring
8820 any C@t{++} class methods and namespace functions called @code{func}.
8821
8822 @xref{Explicit Locations}.
8823
8824 @item @var{function}:@var{label}
8825 Specifies the line where @var{label} appears in @var{function}.
8826
8827 @item @var{filename}:@var{function}
8828 Specifies the line that begins the body of the function @var{function}
8829 in the file @var{filename}. You only need the file name with a
8830 function name to avoid ambiguity when there are identically named
8831 functions in different source files.
8832
8833 @item @var{label}
8834 Specifies the line at which the label named @var{label} appears
8835 in the function corresponding to the currently selected stack frame.
8836 If there is no current selected stack frame (for instance, if the inferior
8837 is not running), then @value{GDBN} will not search for a label.
8838
8839 @cindex breakpoint at static probe point
8840 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8841 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8842 applications to embed static probes. @xref{Static Probe Points}, for more
8843 information on finding and using static probes. This form of linespec
8844 specifies the location of such a static probe.
8845
8846 If @var{objfile} is given, only probes coming from that shared library
8847 or executable matching @var{objfile} as a regular expression are considered.
8848 If @var{provider} is given, then only probes from that provider are considered.
8849 If several probes match the spec, @value{GDBN} will insert a breakpoint at
8850 each one of those probes.
8851 @end table
8852
8853 @node Explicit Locations
8854 @subsection Explicit Locations
8855 @cindex explicit locations
8856
8857 @dfn{Explicit locations} allow the user to directly specify the source
8858 location's parameters using option-value pairs.
8859
8860 Explicit locations are useful when several functions, labels, or
8861 file names have the same name (base name for files) in the program's
8862 sources. In these cases, explicit locations point to the source
8863 line you meant more accurately and unambiguously. Also, using
8864 explicit locations might be faster in large programs.
8865
8866 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8867 defined in the file named @file{foo} or the label @code{bar} in a function
8868 named @code{foo}. @value{GDBN} must search either the file system or
8869 the symbol table to know.
8870
8871 The list of valid explicit location options is summarized in the
8872 following table:
8873
8874 @table @code
8875 @item -source @var{filename}
8876 The value specifies the source file name. To differentiate between
8877 files with the same base name, prepend as many directories as is necessary
8878 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8879 @value{GDBN} will use the first file it finds with the given base
8880 name. This option requires the use of either @code{-function} or @code{-line}.
8881
8882 @item -function @var{function}
8883 The value specifies the name of a function. Operations
8884 on function locations unmodified by other options (such as @code{-label}
8885 or @code{-line}) refer to the line that begins the body of the function.
8886 In C, for example, this is the line with the open brace.
8887
8888 By default, in C@t{++} and Ada, @var{function} is interpreted as
8889 specifying all functions named @var{function} in all scopes. For
8890 C@t{++}, this means in all namespaces and classes. For Ada, this
8891 means in all packages.
8892
8893 For example, assuming a program with C@t{++} symbols named
8894 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8895 -function func}} and @w{@kbd{break -function B::func}} set a
8896 breakpoint on both symbols.
8897
8898 You can use the @kbd{-qualified} flag to override this (see below).
8899
8900 @item -qualified
8901
8902 This flag makes @value{GDBN} interpret a function name specified with
8903 @kbd{-function} as a complete fully-qualified name.
8904
8905 For example, assuming a C@t{++} program with symbols named
8906 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8907 -function B::func}} command sets a breakpoint on @code{B::func}, only.
8908
8909 (Note: the @kbd{-qualified} option can precede a linespec as well
8910 (@pxref{Linespec Locations}), so the particular example above could be
8911 simplified as @w{@kbd{break -qualified B::func}}.)
8912
8913 @item -label @var{label}
8914 The value specifies the name of a label. When the function
8915 name is not specified, the label is searched in the function of the currently
8916 selected stack frame.
8917
8918 @item -line @var{number}
8919 The value specifies a line offset for the location. The offset may either
8920 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
8921 the command. When specified without any other options, the line offset is
8922 relative to the current line.
8923 @end table
8924
8925 Explicit location options may be abbreviated by omitting any non-unique
8926 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
8927
8928 @node Address Locations
8929 @subsection Address Locations
8930 @cindex address locations
8931
8932 @dfn{Address locations} indicate a specific program address. They have
8933 the generalized form *@var{address}.
8934
8935 For line-oriented commands, such as @code{list} and @code{edit}, this
8936 specifies a source line that contains @var{address}. For @code{break} and
8937 other breakpoint-oriented commands, this can be used to set breakpoints in
8938 parts of your program which do not have debugging information or
8939 source files.
8940
8941 Here @var{address} may be any expression valid in the current working
8942 language (@pxref{Languages, working language}) that specifies a code
8943 address. In addition, as a convenience, @value{GDBN} extends the
8944 semantics of expressions used in locations to cover several situations
8945 that frequently occur during debugging. Here are the various forms
8946 of @var{address}:
8947
8948 @table @code
8949 @item @var{expression}
8950 Any expression valid in the current working language.
8951
8952 @item @var{funcaddr}
8953 An address of a function or procedure derived from its name. In C,
8954 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
8955 simply the function's name @var{function} (and actually a special case
8956 of a valid expression). In Pascal and Modula-2, this is
8957 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
8958 (although the Pascal form also works).
8959
8960 This form specifies the address of the function's first instruction,
8961 before the stack frame and arguments have been set up.
8962
8963 @item '@var{filename}':@var{funcaddr}
8964 Like @var{funcaddr} above, but also specifies the name of the source
8965 file explicitly. This is useful if the name of the function does not
8966 specify the function unambiguously, e.g., if there are several
8967 functions with identical names in different source files.
8968 @end table
8969
8970 @node Edit
8971 @section Editing Source Files
8972 @cindex editing source files
8973
8974 @kindex edit
8975 @kindex e @r{(@code{edit})}
8976 To edit the lines in a source file, use the @code{edit} command.
8977 The editing program of your choice
8978 is invoked with the current line set to
8979 the active line in the program.
8980 Alternatively, there are several ways to specify what part of the file you
8981 want to print if you want to see other parts of the program:
8982
8983 @table @code
8984 @item edit @var{location}
8985 Edit the source file specified by @code{location}. Editing starts at
8986 that @var{location}, e.g., at the specified source line of the
8987 specified file. @xref{Specify Location}, for all the possible forms
8988 of the @var{location} argument; here are the forms of the @code{edit}
8989 command most commonly used:
8990
8991 @table @code
8992 @item edit @var{number}
8993 Edit the current source file with @var{number} as the active line number.
8994
8995 @item edit @var{function}
8996 Edit the file containing @var{function} at the beginning of its definition.
8997 @end table
8998
8999 @end table
9000
9001 @subsection Choosing your Editor
9002 You can customize @value{GDBN} to use any editor you want
9003 @footnote{
9004 The only restriction is that your editor (say @code{ex}), recognizes the
9005 following command-line syntax:
9006 @smallexample
9007 ex +@var{number} file
9008 @end smallexample
9009 The optional numeric value +@var{number} specifies the number of the line in
9010 the file where to start editing.}.
9011 By default, it is @file{@value{EDITOR}}, but you can change this
9012 by setting the environment variable @code{EDITOR} before using
9013 @value{GDBN}. For example, to configure @value{GDBN} to use the
9014 @code{vi} editor, you could use these commands with the @code{sh} shell:
9015 @smallexample
9016 EDITOR=/usr/bin/vi
9017 export EDITOR
9018 gdb @dots{}
9019 @end smallexample
9020 or in the @code{csh} shell,
9021 @smallexample
9022 setenv EDITOR /usr/bin/vi
9023 gdb @dots{}
9024 @end smallexample
9025
9026 @node Search
9027 @section Searching Source Files
9028 @cindex searching source files
9029
9030 There are two commands for searching through the current source file for a
9031 regular expression.
9032
9033 @table @code
9034 @kindex search
9035 @kindex forward-search
9036 @kindex fo @r{(@code{forward-search})}
9037 @item forward-search @var{regexp}
9038 @itemx search @var{regexp}
9039 The command @samp{forward-search @var{regexp}} checks each line,
9040 starting with the one following the last line listed, for a match for
9041 @var{regexp}. It lists the line that is found. You can use the
9042 synonym @samp{search @var{regexp}} or abbreviate the command name as
9043 @code{fo}.
9044
9045 @kindex reverse-search
9046 @item reverse-search @var{regexp}
9047 The command @samp{reverse-search @var{regexp}} checks each line, starting
9048 with the one before the last line listed and going backward, for a match
9049 for @var{regexp}. It lists the line that is found. You can abbreviate
9050 this command as @code{rev}.
9051 @end table
9052
9053 @node Source Path
9054 @section Specifying Source Directories
9055
9056 @cindex source path
9057 @cindex directories for source files
9058 Executable programs sometimes do not record the directories of the source
9059 files from which they were compiled, just the names. Even when they do,
9060 the directories could be moved between the compilation and your debugging
9061 session. @value{GDBN} has a list of directories to search for source files;
9062 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9063 it tries all the directories in the list, in the order they are present
9064 in the list, until it finds a file with the desired name.
9065
9066 For example, suppose an executable references the file
9067 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9068 directory, and the @dfn{source path} is @file{/mnt/cross}.
9069 @value{GDBN} would look for the source file in the following
9070 locations:
9071
9072 @enumerate
9073
9074 @item @file{/usr/src/foo-1.0/lib/foo.c}
9075 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9076 @item @file{/mnt/cross/foo.c}
9077
9078 @end enumerate
9079
9080 If the source file is not present at any of the above locations then
9081 an error is printed. @value{GDBN} does not look up the parts of the
9082 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9083 Likewise, the subdirectories of the source path are not searched: if
9084 the source path is @file{/mnt/cross}, and the binary refers to
9085 @file{foo.c}, @value{GDBN} would not find it under
9086 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9087
9088 Plain file names, relative file names with leading directories, file
9089 names containing dots, etc.@: are all treated as described above,
9090 except that non-absolute file names are not looked up literally. If
9091 the @dfn{source path} is @file{/mnt/cross}, the source file is
9092 recorded as @file{../lib/foo.c}, and no compilation directory is
9093 recorded, then @value{GDBN} will search in the following locations:
9094
9095 @enumerate
9096
9097 @item @file{/mnt/cross/../lib/foo.c}
9098 @item @file{/mnt/cross/foo.c}
9099
9100 @end enumerate
9101
9102 @kindex cdir
9103 @kindex cwd
9104 @vindex $cdir@r{, convenience variable}
9105 @vindex $cwd@r{, convenience variable}
9106 @cindex compilation directory
9107 @cindex current directory
9108 @cindex working directory
9109 @cindex directory, current
9110 @cindex directory, compilation
9111 The @dfn{source path} will always include two special entries
9112 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9113 (if one is recorded) and the current working directory respectively.
9114
9115 @samp{$cdir} causes @value{GDBN} to search within the compilation
9116 directory, if one is recorded in the debug information. If no
9117 compilation directory is recorded in the debug information then
9118 @samp{$cdir} is ignored.
9119
9120 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9121 current working directory as it changes during your @value{GDBN}
9122 session, while the latter is immediately expanded to the current
9123 directory at the time you add an entry to the source path.
9124
9125 If a compilation directory is recorded in the debug information, and
9126 @value{GDBN} has not found the source file after the first search
9127 using @dfn{source path}, then @value{GDBN} will combine the
9128 compilation directory and the filename, and then search for the source
9129 file again using the @dfn{source path}.
9130
9131 For example, if the executable records the source file as
9132 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9133 recorded as @file{/project/build}, and the @dfn{source path} is
9134 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9135 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9136 search for the source file in the following locations:
9137
9138 @enumerate
9139
9140 @item @file{/usr/src/foo-1.0/lib/foo.c}
9141 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9142 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9143 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9144 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9145 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9146 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9147 @item @file{/mnt/cross/foo.c}
9148 @item @file{/project/build/foo.c}
9149 @item @file{/home/user/foo.c}
9150
9151 @end enumerate
9152
9153 If the file name in the previous example had been recorded in the
9154 executable as a relative path rather than an absolute path, then the
9155 first look up would not have occurred, but all of the remaining steps
9156 would be similar.
9157
9158 When searching for source files on MS-DOS and MS-Windows, where
9159 absolute paths start with a drive letter (e.g.
9160 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9161 from the file name before appending it to a search directory from
9162 @dfn{source path}; for instance if the executable references the
9163 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9164 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9165 locations for the source file:
9166
9167 @enumerate
9168
9169 @item @file{C:/project/foo.c}
9170 @item @file{D:/mnt/cross/project/foo.c}
9171 @item @file{D:/mnt/cross/foo.c}
9172
9173 @end enumerate
9174
9175 Note that the executable search path is @emph{not} used to locate the
9176 source files.
9177
9178 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9179 any information it has cached about where source files are found and where
9180 each line is in the file.
9181
9182 @kindex directory
9183 @kindex dir
9184 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9185 and @samp{$cwd}, in that order.
9186 To add other directories, use the @code{directory} command.
9187
9188 The search path is used to find both program source files and @value{GDBN}
9189 script files (read using the @samp{-command} option and @samp{source} command).
9190
9191 In addition to the source path, @value{GDBN} provides a set of commands
9192 that manage a list of source path substitution rules. A @dfn{substitution
9193 rule} specifies how to rewrite source directories stored in the program's
9194 debug information in case the sources were moved to a different
9195 directory between compilation and debugging. A rule is made of
9196 two strings, the first specifying what needs to be rewritten in
9197 the path, and the second specifying how it should be rewritten.
9198 In @ref{set substitute-path}, we name these two parts @var{from} and
9199 @var{to} respectively. @value{GDBN} does a simple string replacement
9200 of @var{from} with @var{to} at the start of the directory part of the
9201 source file name, and uses that result instead of the original file
9202 name to look up the sources.
9203
9204 Using the previous example, suppose the @file{foo-1.0} tree has been
9205 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9206 @value{GDBN} to replace @file{/usr/src} in all source path names with
9207 @file{/mnt/cross}. The first lookup will then be
9208 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9209 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9210 substitution rule, use the @code{set substitute-path} command
9211 (@pxref{set substitute-path}).
9212
9213 To avoid unexpected substitution results, a rule is applied only if the
9214 @var{from} part of the directory name ends at a directory separator.
9215 For instance, a rule substituting @file{/usr/source} into
9216 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9217 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9218 is applied only at the beginning of the directory name, this rule will
9219 not be applied to @file{/root/usr/source/baz.c} either.
9220
9221 In many cases, you can achieve the same result using the @code{directory}
9222 command. However, @code{set substitute-path} can be more efficient in
9223 the case where the sources are organized in a complex tree with multiple
9224 subdirectories. With the @code{directory} command, you need to add each
9225 subdirectory of your project. If you moved the entire tree while
9226 preserving its internal organization, then @code{set substitute-path}
9227 allows you to direct the debugger to all the sources with one single
9228 command.
9229
9230 @code{set substitute-path} is also more than just a shortcut command.
9231 The source path is only used if the file at the original location no
9232 longer exists. On the other hand, @code{set substitute-path} modifies
9233 the debugger behavior to look at the rewritten location instead. So, if
9234 for any reason a source file that is not relevant to your executable is
9235 located at the original location, a substitution rule is the only
9236 method available to point @value{GDBN} at the new location.
9237
9238 @cindex @samp{--with-relocated-sources}
9239 @cindex default source path substitution
9240 You can configure a default source path substitution rule by
9241 configuring @value{GDBN} with the
9242 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9243 should be the name of a directory under @value{GDBN}'s configured
9244 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9245 directory names in debug information under @var{dir} will be adjusted
9246 automatically if the installed @value{GDBN} is moved to a new
9247 location. This is useful if @value{GDBN}, libraries or executables
9248 with debug information and corresponding source code are being moved
9249 together.
9250
9251 @table @code
9252 @item directory @var{dirname} @dots{}
9253 @item dir @var{dirname} @dots{}
9254 Add directory @var{dirname} to the front of the source path. Several
9255 directory names may be given to this command, separated by @samp{:}
9256 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9257 part of absolute file names) or
9258 whitespace. You may specify a directory that is already in the source
9259 path; this moves it forward, so @value{GDBN} searches it sooner.
9260
9261 The special strings @samp{$cdir} (to refer to the compilation
9262 directory, if one is recorded), and @samp{$cwd} (to refer to the
9263 current working directory) can also be included in the list of
9264 directories @var{dirname}. Though these will already be in the source
9265 path they will be moved forward in the list so @value{GDBN} searches
9266 them sooner.
9267
9268 @item directory
9269 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9270
9271 @c RET-repeat for @code{directory} is explicitly disabled, but since
9272 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9273
9274 @item set directories @var{path-list}
9275 @kindex set directories
9276 Set the source path to @var{path-list}.
9277 @samp{$cdir:$cwd} are added if missing.
9278
9279 @item show directories
9280 @kindex show directories
9281 Print the source path: show which directories it contains.
9282
9283 @anchor{set substitute-path}
9284 @item set substitute-path @var{from} @var{to}
9285 @kindex set substitute-path
9286 Define a source path substitution rule, and add it at the end of the
9287 current list of existing substitution rules. If a rule with the same
9288 @var{from} was already defined, then the old rule is also deleted.
9289
9290 For example, if the file @file{/foo/bar/baz.c} was moved to
9291 @file{/mnt/cross/baz.c}, then the command
9292
9293 @smallexample
9294 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9295 @end smallexample
9296
9297 @noindent
9298 will tell @value{GDBN} to replace @samp{/foo/bar} with
9299 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9300 @file{baz.c} even though it was moved.
9301
9302 In the case when more than one substitution rule have been defined,
9303 the rules are evaluated one by one in the order where they have been
9304 defined. The first one matching, if any, is selected to perform
9305 the substitution.
9306
9307 For instance, if we had entered the following commands:
9308
9309 @smallexample
9310 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9311 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9312 @end smallexample
9313
9314 @noindent
9315 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9316 @file{/mnt/include/defs.h} by using the first rule. However, it would
9317 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9318 @file{/mnt/src/lib/foo.c}.
9319
9320
9321 @item unset substitute-path [path]
9322 @kindex unset substitute-path
9323 If a path is specified, search the current list of substitution rules
9324 for a rule that would rewrite that path. Delete that rule if found.
9325 A warning is emitted by the debugger if no rule could be found.
9326
9327 If no path is specified, then all substitution rules are deleted.
9328
9329 @item show substitute-path [path]
9330 @kindex show substitute-path
9331 If a path is specified, then print the source path substitution rule
9332 which would rewrite that path, if any.
9333
9334 If no path is specified, then print all existing source path substitution
9335 rules.
9336
9337 @end table
9338
9339 If your source path is cluttered with directories that are no longer of
9340 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9341 versions of source. You can correct the situation as follows:
9342
9343 @enumerate
9344 @item
9345 Use @code{directory} with no argument to reset the source path to its default value.
9346
9347 @item
9348 Use @code{directory} with suitable arguments to reinstall the
9349 directories you want in the source path. You can add all the
9350 directories in one command.
9351 @end enumerate
9352
9353 @node Machine Code
9354 @section Source and Machine Code
9355 @cindex source line and its code address
9356
9357 You can use the command @code{info line} to map source lines to program
9358 addresses (and vice versa), and the command @code{disassemble} to display
9359 a range of addresses as machine instructions. You can use the command
9360 @code{set disassemble-next-line} to set whether to disassemble next
9361 source line when execution stops. When run under @sc{gnu} Emacs
9362 mode, the @code{info line} command causes the arrow to point to the
9363 line specified. Also, @code{info line} prints addresses in symbolic form as
9364 well as hex.
9365
9366 @table @code
9367 @kindex info line
9368 @item info line
9369 @itemx info line @var{location}
9370 Print the starting and ending addresses of the compiled code for
9371 source line @var{location}. You can specify source lines in any of
9372 the ways documented in @ref{Specify Location}. With no @var{location}
9373 information about the current source line is printed.
9374 @end table
9375
9376 For example, we can use @code{info line} to discover the location of
9377 the object code for the first line of function
9378 @code{m4_changequote}:
9379
9380 @smallexample
9381 (@value{GDBP}) info line m4_changequote
9382 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9383 ends at 0x6350 <m4_changequote+4>.
9384 @end smallexample
9385
9386 @noindent
9387 @cindex code address and its source line
9388 We can also inquire (using @code{*@var{addr}} as the form for
9389 @var{location}) what source line covers a particular address:
9390 @smallexample
9391 (@value{GDBP}) info line *0x63ff
9392 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9393 ends at 0x6404 <m4_changequote+184>.
9394 @end smallexample
9395
9396 @cindex @code{$_} and @code{info line}
9397 @cindex @code{x} command, default address
9398 @kindex x@r{(examine), and} info line
9399 After @code{info line}, the default address for the @code{x} command
9400 is changed to the starting address of the line, so that @samp{x/i} is
9401 sufficient to begin examining the machine code (@pxref{Memory,
9402 ,Examining Memory}). Also, this address is saved as the value of the
9403 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9404 Variables}).
9405
9406 @cindex info line, repeated calls
9407 After @code{info line}, using @code{info line} again without
9408 specifying a location will display information about the next source
9409 line.
9410
9411 @table @code
9412 @kindex disassemble
9413 @cindex assembly instructions
9414 @cindex instructions, assembly
9415 @cindex machine instructions
9416 @cindex listing machine instructions
9417 @item disassemble
9418 @itemx disassemble /m
9419 @itemx disassemble /s
9420 @itemx disassemble /r
9421 This specialized command dumps a range of memory as machine
9422 instructions. It can also print mixed source+disassembly by specifying
9423 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9424 as well as in symbolic form by specifying the @code{/r} modifier.
9425 The default memory range is the function surrounding the
9426 program counter of the selected frame. A single argument to this
9427 command is a program counter value; @value{GDBN} dumps the function
9428 surrounding this value. When two arguments are given, they should
9429 be separated by a comma, possibly surrounded by whitespace. The
9430 arguments specify a range of addresses to dump, in one of two forms:
9431
9432 @table @code
9433 @item @var{start},@var{end}
9434 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9435 @item @var{start},+@var{length}
9436 the addresses from @var{start} (inclusive) to
9437 @code{@var{start}+@var{length}} (exclusive).
9438 @end table
9439
9440 @noindent
9441 When 2 arguments are specified, the name of the function is also
9442 printed (since there could be several functions in the given range).
9443
9444 The argument(s) can be any expression yielding a numeric value, such as
9445 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9446
9447 If the range of memory being disassembled contains current program counter,
9448 the instruction at that location is shown with a @code{=>} marker.
9449 @end table
9450
9451 The following example shows the disassembly of a range of addresses of
9452 HP PA-RISC 2.0 code:
9453
9454 @smallexample
9455 (@value{GDBP}) disas 0x32c4, 0x32e4
9456 Dump of assembler code from 0x32c4 to 0x32e4:
9457 0x32c4 <main+204>: addil 0,dp
9458 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9459 0x32cc <main+212>: ldil 0x3000,r31
9460 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9461 0x32d4 <main+220>: ldo 0(r31),rp
9462 0x32d8 <main+224>: addil -0x800,dp
9463 0x32dc <main+228>: ldo 0x588(r1),r26
9464 0x32e0 <main+232>: ldil 0x3000,r31
9465 End of assembler dump.
9466 @end smallexample
9467
9468 Here is an example showing mixed source+assembly for Intel x86
9469 with @code{/m} or @code{/s}, when the program is stopped just after
9470 function prologue in a non-optimized function with no inline code.
9471
9472 @smallexample
9473 (@value{GDBP}) disas /m main
9474 Dump of assembler code for function main:
9475 5 @{
9476 0x08048330 <+0>: push %ebp
9477 0x08048331 <+1>: mov %esp,%ebp
9478 0x08048333 <+3>: sub $0x8,%esp
9479 0x08048336 <+6>: and $0xfffffff0,%esp
9480 0x08048339 <+9>: sub $0x10,%esp
9481
9482 6 printf ("Hello.\n");
9483 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9484 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9485
9486 7 return 0;
9487 8 @}
9488 0x08048348 <+24>: mov $0x0,%eax
9489 0x0804834d <+29>: leave
9490 0x0804834e <+30>: ret
9491
9492 End of assembler dump.
9493 @end smallexample
9494
9495 The @code{/m} option is deprecated as its output is not useful when
9496 there is either inlined code or re-ordered code.
9497 The @code{/s} option is the preferred choice.
9498 Here is an example for AMD x86-64 showing the difference between
9499 @code{/m} output and @code{/s} output.
9500 This example has one inline function defined in a header file,
9501 and the code is compiled with @samp{-O2} optimization.
9502 Note how the @code{/m} output is missing the disassembly of
9503 several instructions that are present in the @code{/s} output.
9504
9505 @file{foo.h}:
9506
9507 @smallexample
9508 int
9509 foo (int a)
9510 @{
9511 if (a < 0)
9512 return a * 2;
9513 if (a == 0)
9514 return 1;
9515 return a + 10;
9516 @}
9517 @end smallexample
9518
9519 @file{foo.c}:
9520
9521 @smallexample
9522 #include "foo.h"
9523 volatile int x, y;
9524 int
9525 main ()
9526 @{
9527 x = foo (y);
9528 return 0;
9529 @}
9530 @end smallexample
9531
9532 @smallexample
9533 (@value{GDBP}) disas /m main
9534 Dump of assembler code for function main:
9535 5 @{
9536
9537 6 x = foo (y);
9538 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9539 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9540
9541 7 return 0;
9542 8 @}
9543 0x000000000040041d <+29>: xor %eax,%eax
9544 0x000000000040041f <+31>: retq
9545 0x0000000000400420 <+32>: add %eax,%eax
9546 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9547
9548 End of assembler dump.
9549 (@value{GDBP}) disas /s main
9550 Dump of assembler code for function main:
9551 foo.c:
9552 5 @{
9553 6 x = foo (y);
9554 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9555
9556 foo.h:
9557 4 if (a < 0)
9558 0x0000000000400406 <+6>: test %eax,%eax
9559 0x0000000000400408 <+8>: js 0x400420 <main+32>
9560
9561 6 if (a == 0)
9562 7 return 1;
9563 8 return a + 10;
9564 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9565 0x000000000040040d <+13>: test %eax,%eax
9566 0x000000000040040f <+15>: mov $0x1,%eax
9567 0x0000000000400414 <+20>: cmovne %edx,%eax
9568
9569 foo.c:
9570 6 x = foo (y);
9571 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9572
9573 7 return 0;
9574 8 @}
9575 0x000000000040041d <+29>: xor %eax,%eax
9576 0x000000000040041f <+31>: retq
9577
9578 foo.h:
9579 5 return a * 2;
9580 0x0000000000400420 <+32>: add %eax,%eax
9581 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9582 End of assembler dump.
9583 @end smallexample
9584
9585 Here is another example showing raw instructions in hex for AMD x86-64,
9586
9587 @smallexample
9588 (gdb) disas /r 0x400281,+10
9589 Dump of assembler code from 0x400281 to 0x40028b:
9590 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9591 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9592 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9593 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9594 End of assembler dump.
9595 @end smallexample
9596
9597 Addresses cannot be specified as a location (@pxref{Specify Location}).
9598 So, for example, if you want to disassemble function @code{bar}
9599 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9600 and not @samp{disassemble foo.c:bar}.
9601
9602 Some architectures have more than one commonly-used set of instruction
9603 mnemonics or other syntax.
9604
9605 For programs that were dynamically linked and use shared libraries,
9606 instructions that call functions or branch to locations in the shared
9607 libraries might show a seemingly bogus location---it's actually a
9608 location of the relocation table. On some architectures, @value{GDBN}
9609 might be able to resolve these to actual function names.
9610
9611 @table @code
9612 @kindex set disassembler-options
9613 @cindex disassembler options
9614 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9615 This command controls the passing of target specific information to
9616 the disassembler. For a list of valid options, please refer to the
9617 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9618 manual and/or the output of @kbd{objdump --help}
9619 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9620 The default value is the empty string.
9621
9622 If it is necessary to specify more than one disassembler option, then
9623 multiple options can be placed together into a comma separated list.
9624 Currently this command is only supported on targets ARM, MIPS, PowerPC
9625 and S/390.
9626
9627 @kindex show disassembler-options
9628 @item show disassembler-options
9629 Show the current setting of the disassembler options.
9630 @end table
9631
9632 @table @code
9633 @kindex set disassembly-flavor
9634 @cindex Intel disassembly flavor
9635 @cindex AT&T disassembly flavor
9636 @item set disassembly-flavor @var{instruction-set}
9637 Select the instruction set to use when disassembling the
9638 program via the @code{disassemble} or @code{x/i} commands.
9639
9640 Currently this command is only defined for the Intel x86 family. You
9641 can set @var{instruction-set} to either @code{intel} or @code{att}.
9642 The default is @code{att}, the AT&T flavor used by default by Unix
9643 assemblers for x86-based targets.
9644
9645 @kindex show disassembly-flavor
9646 @item show disassembly-flavor
9647 Show the current setting of the disassembly flavor.
9648 @end table
9649
9650 @table @code
9651 @kindex set disassemble-next-line
9652 @kindex show disassemble-next-line
9653 @item set disassemble-next-line
9654 @itemx show disassemble-next-line
9655 Control whether or not @value{GDBN} will disassemble the next source
9656 line or instruction when execution stops. If ON, @value{GDBN} will
9657 display disassembly of the next source line when execution of the
9658 program being debugged stops. This is @emph{in addition} to
9659 displaying the source line itself, which @value{GDBN} always does if
9660 possible. If the next source line cannot be displayed for some reason
9661 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9662 info in the debug info), @value{GDBN} will display disassembly of the
9663 next @emph{instruction} instead of showing the next source line. If
9664 AUTO, @value{GDBN} will display disassembly of next instruction only
9665 if the source line cannot be displayed. This setting causes
9666 @value{GDBN} to display some feedback when you step through a function
9667 with no line info or whose source file is unavailable. The default is
9668 OFF, which means never display the disassembly of the next line or
9669 instruction.
9670 @end table
9671
9672
9673 @node Data
9674 @chapter Examining Data
9675
9676 @cindex printing data
9677 @cindex examining data
9678 @kindex print
9679 @kindex inspect
9680 The usual way to examine data in your program is with the @code{print}
9681 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9682 evaluates and prints the value of an expression of the language your
9683 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9684 Different Languages}). It may also print the expression using a
9685 Python-based pretty-printer (@pxref{Pretty Printing}).
9686
9687 @table @code
9688 @item print [[@var{options}] --] @var{expr}
9689 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9690 @var{expr} is an expression (in the source language). By default the
9691 value of @var{expr} is printed in a format appropriate to its data type;
9692 you can choose a different format by specifying @samp{/@var{f}}, where
9693 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9694 Formats}.
9695
9696 @anchor{print options}
9697 The @code{print} command supports a number of options that allow
9698 overriding relevant global print settings as set by @code{set print}
9699 subcommands:
9700
9701 @table @code
9702 @item -address [@code{on}|@code{off}]
9703 Set printing of addresses.
9704 Related setting: @ref{set print address}.
9705
9706 @item -array [@code{on}|@code{off}]
9707 Pretty formatting of arrays.
9708 Related setting: @ref{set print array}.
9709
9710 @item -array-indexes [@code{on}|@code{off}]
9711 Set printing of array indexes.
9712 Related setting: @ref{set print array-indexes}.
9713
9714 @item -elements @var{number-of-elements}|@code{unlimited}
9715 Set limit on string chars or array elements to print. The value
9716 @code{unlimited} causes there to be no limit. Related setting:
9717 @ref{set print elements}.
9718
9719 @item -max-depth @var{depth}|@code{unlimited}
9720 Set the threshold after which nested structures are replaced with
9721 ellipsis. Related setting: @ref{set print max-depth}.
9722
9723 @item -null-stop [@code{on}|@code{off}]
9724 Set printing of char arrays to stop at first null char. Related
9725 setting: @ref{set print null-stop}.
9726
9727 @item -object [@code{on}|@code{off}]
9728 Set printing C@t{++} virtual function tables. Related setting:
9729 @ref{set print object}.
9730
9731 @item -pretty [@code{on}|@code{off}]
9732 Set pretty formatting of structures. Related setting: @ref{set print
9733 pretty}.
9734
9735 @item -raw-values [@code{on}|@code{off}]
9736 Set whether to print values in raw form, bypassing any
9737 pretty-printers for that value. Related setting: @ref{set print
9738 raw-values}.
9739
9740 @item -repeats @var{number-of-repeats}|@code{unlimited}
9741 Set threshold for repeated print elements. @code{unlimited} causes
9742 all elements to be individually printed. Related setting: @ref{set
9743 print repeats}.
9744
9745 @item -static-members [@code{on}|@code{off}]
9746 Set printing C@t{++} static members. Related setting: @ref{set print
9747 static-members}.
9748
9749 @item -symbol [@code{on}|@code{off}]
9750 Set printing of symbol names when printing pointers. Related setting:
9751 @ref{set print symbol}.
9752
9753 @item -union [@code{on}|@code{off}]
9754 Set printing of unions interior to structures. Related setting:
9755 @ref{set print union}.
9756
9757 @item -vtbl [@code{on}|@code{off}]
9758 Set printing of C++ virtual function tables. Related setting:
9759 @ref{set print vtbl}.
9760 @end table
9761
9762 Because the @code{print} command accepts arbitrary expressions which
9763 may look like options (including abbreviations), if you specify any
9764 command option, then you must use a double dash (@code{--}) to mark
9765 the end of option processing.
9766
9767 For example, this prints the value of the @code{-p} expression:
9768
9769 @smallexample
9770 (@value{GDBP}) print -p
9771 @end smallexample
9772
9773 While this repeats the last value in the value history (see below)
9774 with the @code{-pretty} option in effect:
9775
9776 @smallexample
9777 (@value{GDBP}) print -p --
9778 @end smallexample
9779
9780 Here is an example including both on option and an expression:
9781
9782 @smallexample
9783 @group
9784 (@value{GDBP}) print -pretty -- *myptr
9785 $1 = @{
9786 next = 0x0,
9787 flags = @{
9788 sweet = 1,
9789 sour = 1
9790 @},
9791 meat = 0x54 "Pork"
9792 @}
9793 @end group
9794 @end smallexample
9795
9796 @item print [@var{options}]
9797 @itemx print [@var{options}] /@var{f}
9798 @cindex reprint the last value
9799 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
9800 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
9801 conveniently inspect the same value in an alternative format.
9802 @end table
9803
9804 A more low-level way of examining data is with the @code{x} command.
9805 It examines data in memory at a specified address and prints it in a
9806 specified format. @xref{Memory, ,Examining Memory}.
9807
9808 If you are interested in information about types, or about how the
9809 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9810 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
9811 Table}.
9812
9813 @cindex exploring hierarchical data structures
9814 @kindex explore
9815 Another way of examining values of expressions and type information is
9816 through the Python extension command @code{explore} (available only if
9817 the @value{GDBN} build is configured with @code{--with-python}). It
9818 offers an interactive way to start at the highest level (or, the most
9819 abstract level) of the data type of an expression (or, the data type
9820 itself) and explore all the way down to leaf scalar values/fields
9821 embedded in the higher level data types.
9822
9823 @table @code
9824 @item explore @var{arg}
9825 @var{arg} is either an expression (in the source language), or a type
9826 visible in the current context of the program being debugged.
9827 @end table
9828
9829 The working of the @code{explore} command can be illustrated with an
9830 example. If a data type @code{struct ComplexStruct} is defined in your
9831 C program as
9832
9833 @smallexample
9834 struct SimpleStruct
9835 @{
9836 int i;
9837 double d;
9838 @};
9839
9840 struct ComplexStruct
9841 @{
9842 struct SimpleStruct *ss_p;
9843 int arr[10];
9844 @};
9845 @end smallexample
9846
9847 @noindent
9848 followed by variable declarations as
9849
9850 @smallexample
9851 struct SimpleStruct ss = @{ 10, 1.11 @};
9852 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9853 @end smallexample
9854
9855 @noindent
9856 then, the value of the variable @code{cs} can be explored using the
9857 @code{explore} command as follows.
9858
9859 @smallexample
9860 (gdb) explore cs
9861 The value of `cs' is a struct/class of type `struct ComplexStruct' with
9862 the following fields:
9863
9864 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9865 arr = <Enter 1 to explore this field of type `int [10]'>
9866
9867 Enter the field number of choice:
9868 @end smallexample
9869
9870 @noindent
9871 Since the fields of @code{cs} are not scalar values, you are being
9872 prompted to chose the field you want to explore. Let's say you choose
9873 the field @code{ss_p} by entering @code{0}. Then, since this field is a
9874 pointer, you will be asked if it is pointing to a single value. From
9875 the declaration of @code{cs} above, it is indeed pointing to a single
9876 value, hence you enter @code{y}. If you enter @code{n}, then you will
9877 be asked if it were pointing to an array of values, in which case this
9878 field will be explored as if it were an array.
9879
9880 @smallexample
9881 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9882 Continue exploring it as a pointer to a single value [y/n]: y
9883 The value of `*(cs.ss_p)' is a struct/class of type `struct
9884 SimpleStruct' with the following fields:
9885
9886 i = 10 .. (Value of type `int')
9887 d = 1.1100000000000001 .. (Value of type `double')
9888
9889 Press enter to return to parent value:
9890 @end smallexample
9891
9892 @noindent
9893 If the field @code{arr} of @code{cs} was chosen for exploration by
9894 entering @code{1} earlier, then since it is as array, you will be
9895 prompted to enter the index of the element in the array that you want
9896 to explore.
9897
9898 @smallexample
9899 `cs.arr' is an array of `int'.
9900 Enter the index of the element you want to explore in `cs.arr': 5
9901
9902 `(cs.arr)[5]' is a scalar value of type `int'.
9903
9904 (cs.arr)[5] = 4
9905
9906 Press enter to return to parent value:
9907 @end smallexample
9908
9909 In general, at any stage of exploration, you can go deeper towards the
9910 leaf values by responding to the prompts appropriately, or hit the
9911 return key to return to the enclosing data structure (the @i{higher}
9912 level data structure).
9913
9914 Similar to exploring values, you can use the @code{explore} command to
9915 explore types. Instead of specifying a value (which is typically a
9916 variable name or an expression valid in the current context of the
9917 program being debugged), you specify a type name. If you consider the
9918 same example as above, your can explore the type
9919 @code{struct ComplexStruct} by passing the argument
9920 @code{struct ComplexStruct} to the @code{explore} command.
9921
9922 @smallexample
9923 (gdb) explore struct ComplexStruct
9924 @end smallexample
9925
9926 @noindent
9927 By responding to the prompts appropriately in the subsequent interactive
9928 session, you can explore the type @code{struct ComplexStruct} in a
9929 manner similar to how the value @code{cs} was explored in the above
9930 example.
9931
9932 The @code{explore} command also has two sub-commands,
9933 @code{explore value} and @code{explore type}. The former sub-command is
9934 a way to explicitly specify that value exploration of the argument is
9935 being invoked, while the latter is a way to explicitly specify that type
9936 exploration of the argument is being invoked.
9937
9938 @table @code
9939 @item explore value @var{expr}
9940 @cindex explore value
9941 This sub-command of @code{explore} explores the value of the
9942 expression @var{expr} (if @var{expr} is an expression valid in the
9943 current context of the program being debugged). The behavior of this
9944 command is identical to that of the behavior of the @code{explore}
9945 command being passed the argument @var{expr}.
9946
9947 @item explore type @var{arg}
9948 @cindex explore type
9949 This sub-command of @code{explore} explores the type of @var{arg} (if
9950 @var{arg} is a type visible in the current context of program being
9951 debugged), or the type of the value/expression @var{arg} (if @var{arg}
9952 is an expression valid in the current context of the program being
9953 debugged). If @var{arg} is a type, then the behavior of this command is
9954 identical to that of the @code{explore} command being passed the
9955 argument @var{arg}. If @var{arg} is an expression, then the behavior of
9956 this command will be identical to that of the @code{explore} command
9957 being passed the type of @var{arg} as the argument.
9958 @end table
9959
9960 @menu
9961 * Expressions:: Expressions
9962 * Ambiguous Expressions:: Ambiguous Expressions
9963 * Variables:: Program variables
9964 * Arrays:: Artificial arrays
9965 * Output Formats:: Output formats
9966 * Memory:: Examining memory
9967 * Auto Display:: Automatic display
9968 * Print Settings:: Print settings
9969 * Pretty Printing:: Python pretty printing
9970 * Value History:: Value history
9971 * Convenience Vars:: Convenience variables
9972 * Convenience Funs:: Convenience functions
9973 * Registers:: Registers
9974 * Floating Point Hardware:: Floating point hardware
9975 * Vector Unit:: Vector Unit
9976 * OS Information:: Auxiliary data provided by operating system
9977 * Memory Region Attributes:: Memory region attributes
9978 * Dump/Restore Files:: Copy between memory and a file
9979 * Core File Generation:: Cause a program dump its core
9980 * Character Sets:: Debugging programs that use a different
9981 character set than GDB does
9982 * Caching Target Data:: Data caching for targets
9983 * Searching Memory:: Searching memory for a sequence of bytes
9984 * Value Sizes:: Managing memory allocated for values
9985 @end menu
9986
9987 @node Expressions
9988 @section Expressions
9989
9990 @cindex expressions
9991 @code{print} and many other @value{GDBN} commands accept an expression and
9992 compute its value. Any kind of constant, variable or operator defined
9993 by the programming language you are using is valid in an expression in
9994 @value{GDBN}. This includes conditional expressions, function calls,
9995 casts, and string constants. It also includes preprocessor macros, if
9996 you compiled your program to include this information; see
9997 @ref{Compilation}.
9998
9999 @cindex arrays in expressions
10000 @value{GDBN} supports array constants in expressions input by
10001 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10002 you can use the command @code{print @{1, 2, 3@}} to create an array
10003 of three integers. If you pass an array to a function or assign it
10004 to a program variable, @value{GDBN} copies the array to memory that
10005 is @code{malloc}ed in the target program.
10006
10007 Because C is so widespread, most of the expressions shown in examples in
10008 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10009 Languages}, for information on how to use expressions in other
10010 languages.
10011
10012 In this section, we discuss operators that you can use in @value{GDBN}
10013 expressions regardless of your programming language.
10014
10015 @cindex casts, in expressions
10016 Casts are supported in all languages, not just in C, because it is so
10017 useful to cast a number into a pointer in order to examine a structure
10018 at that address in memory.
10019 @c FIXME: casts supported---Mod2 true?
10020
10021 @value{GDBN} supports these operators, in addition to those common
10022 to programming languages:
10023
10024 @table @code
10025 @item @@
10026 @samp{@@} is a binary operator for treating parts of memory as arrays.
10027 @xref{Arrays, ,Artificial Arrays}, for more information.
10028
10029 @item ::
10030 @samp{::} allows you to specify a variable in terms of the file or
10031 function where it is defined. @xref{Variables, ,Program Variables}.
10032
10033 @cindex @{@var{type}@}
10034 @cindex type casting memory
10035 @cindex memory, viewing as typed object
10036 @cindex casts, to view memory
10037 @item @{@var{type}@} @var{addr}
10038 Refers to an object of type @var{type} stored at address @var{addr} in
10039 memory. The address @var{addr} may be any expression whose value is
10040 an integer or pointer (but parentheses are required around binary
10041 operators, just as in a cast). This construct is allowed regardless
10042 of what kind of data is normally supposed to reside at @var{addr}.
10043 @end table
10044
10045 @node Ambiguous Expressions
10046 @section Ambiguous Expressions
10047 @cindex ambiguous expressions
10048
10049 Expressions can sometimes contain some ambiguous elements. For instance,
10050 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10051 a single function name to be defined several times, for application in
10052 different contexts. This is called @dfn{overloading}. Another example
10053 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10054 templates and is typically instantiated several times, resulting in
10055 the same function name being defined in different contexts.
10056
10057 In some cases and depending on the language, it is possible to adjust
10058 the expression to remove the ambiguity. For instance in C@t{++}, you
10059 can specify the signature of the function you want to break on, as in
10060 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10061 qualified name of your function often makes the expression unambiguous
10062 as well.
10063
10064 When an ambiguity that needs to be resolved is detected, the debugger
10065 has the capability to display a menu of numbered choices for each
10066 possibility, and then waits for the selection with the prompt @samp{>}.
10067 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10068 aborts the current command. If the command in which the expression was
10069 used allows more than one choice to be selected, the next option in the
10070 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10071 choices.
10072
10073 For example, the following session excerpt shows an attempt to set a
10074 breakpoint at the overloaded symbol @code{String::after}.
10075 We choose three particular definitions of that function name:
10076
10077 @c FIXME! This is likely to change to show arg type lists, at least
10078 @smallexample
10079 @group
10080 (@value{GDBP}) b String::after
10081 [0] cancel
10082 [1] all
10083 [2] file:String.cc; line number:867
10084 [3] file:String.cc; line number:860
10085 [4] file:String.cc; line number:875
10086 [5] file:String.cc; line number:853
10087 [6] file:String.cc; line number:846
10088 [7] file:String.cc; line number:735
10089 > 2 4 6
10090 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10091 Breakpoint 2 at 0xb344: file String.cc, line 875.
10092 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10093 Multiple breakpoints were set.
10094 Use the "delete" command to delete unwanted
10095 breakpoints.
10096 (@value{GDBP})
10097 @end group
10098 @end smallexample
10099
10100 @table @code
10101 @kindex set multiple-symbols
10102 @item set multiple-symbols @var{mode}
10103 @cindex multiple-symbols menu
10104
10105 This option allows you to adjust the debugger behavior when an expression
10106 is ambiguous.
10107
10108 By default, @var{mode} is set to @code{all}. If the command with which
10109 the expression is used allows more than one choice, then @value{GDBN}
10110 automatically selects all possible choices. For instance, inserting
10111 a breakpoint on a function using an ambiguous name results in a breakpoint
10112 inserted on each possible match. However, if a unique choice must be made,
10113 then @value{GDBN} uses the menu to help you disambiguate the expression.
10114 For instance, printing the address of an overloaded function will result
10115 in the use of the menu.
10116
10117 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10118 when an ambiguity is detected.
10119
10120 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10121 an error due to the ambiguity and the command is aborted.
10122
10123 @kindex show multiple-symbols
10124 @item show multiple-symbols
10125 Show the current value of the @code{multiple-symbols} setting.
10126 @end table
10127
10128 @node Variables
10129 @section Program Variables
10130
10131 The most common kind of expression to use is the name of a variable
10132 in your program.
10133
10134 Variables in expressions are understood in the selected stack frame
10135 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10136
10137 @itemize @bullet
10138 @item
10139 global (or file-static)
10140 @end itemize
10141
10142 @noindent or
10143
10144 @itemize @bullet
10145 @item
10146 visible according to the scope rules of the
10147 programming language from the point of execution in that frame
10148 @end itemize
10149
10150 @noindent This means that in the function
10151
10152 @smallexample
10153 foo (a)
10154 int a;
10155 @{
10156 bar (a);
10157 @{
10158 int b = test ();
10159 bar (b);
10160 @}
10161 @}
10162 @end smallexample
10163
10164 @noindent
10165 you can examine and use the variable @code{a} whenever your program is
10166 executing within the function @code{foo}, but you can only use or
10167 examine the variable @code{b} while your program is executing inside
10168 the block where @code{b} is declared.
10169
10170 @cindex variable name conflict
10171 There is an exception: you can refer to a variable or function whose
10172 scope is a single source file even if the current execution point is not
10173 in this file. But it is possible to have more than one such variable or
10174 function with the same name (in different source files). If that
10175 happens, referring to that name has unpredictable effects. If you wish,
10176 you can specify a static variable in a particular function or file by
10177 using the colon-colon (@code{::}) notation:
10178
10179 @cindex colon-colon, context for variables/functions
10180 @ifnotinfo
10181 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10182 @cindex @code{::}, context for variables/functions
10183 @end ifnotinfo
10184 @smallexample
10185 @var{file}::@var{variable}
10186 @var{function}::@var{variable}
10187 @end smallexample
10188
10189 @noindent
10190 Here @var{file} or @var{function} is the name of the context for the
10191 static @var{variable}. In the case of file names, you can use quotes to
10192 make sure @value{GDBN} parses the file name as a single word---for example,
10193 to print a global value of @code{x} defined in @file{f2.c}:
10194
10195 @smallexample
10196 (@value{GDBP}) p 'f2.c'::x
10197 @end smallexample
10198
10199 The @code{::} notation is normally used for referring to
10200 static variables, since you typically disambiguate uses of local variables
10201 in functions by selecting the appropriate frame and using the
10202 simple name of the variable. However, you may also use this notation
10203 to refer to local variables in frames enclosing the selected frame:
10204
10205 @smallexample
10206 void
10207 foo (int a)
10208 @{
10209 if (a < 10)
10210 bar (a);
10211 else
10212 process (a); /* Stop here */
10213 @}
10214
10215 int
10216 bar (int a)
10217 @{
10218 foo (a + 5);
10219 @}
10220 @end smallexample
10221
10222 @noindent
10223 For example, if there is a breakpoint at the commented line,
10224 here is what you might see
10225 when the program stops after executing the call @code{bar(0)}:
10226
10227 @smallexample
10228 (@value{GDBP}) p a
10229 $1 = 10
10230 (@value{GDBP}) p bar::a
10231 $2 = 5
10232 (@value{GDBP}) up 2
10233 #2 0x080483d0 in foo (a=5) at foobar.c:12
10234 (@value{GDBP}) p a
10235 $3 = 5
10236 (@value{GDBP}) p bar::a
10237 $4 = 0
10238 @end smallexample
10239
10240 @cindex C@t{++} scope resolution
10241 These uses of @samp{::} are very rarely in conflict with the very
10242 similar use of the same notation in C@t{++}. When they are in
10243 conflict, the C@t{++} meaning takes precedence; however, this can be
10244 overridden by quoting the file or function name with single quotes.
10245
10246 For example, suppose the program is stopped in a method of a class
10247 that has a field named @code{includefile}, and there is also an
10248 include file named @file{includefile} that defines a variable,
10249 @code{some_global}.
10250
10251 @smallexample
10252 (@value{GDBP}) p includefile
10253 $1 = 23
10254 (@value{GDBP}) p includefile::some_global
10255 A syntax error in expression, near `'.
10256 (@value{GDBP}) p 'includefile'::some_global
10257 $2 = 27
10258 @end smallexample
10259
10260 @cindex wrong values
10261 @cindex variable values, wrong
10262 @cindex function entry/exit, wrong values of variables
10263 @cindex optimized code, wrong values of variables
10264 @quotation
10265 @emph{Warning:} Occasionally, a local variable may appear to have the
10266 wrong value at certain points in a function---just after entry to a new
10267 scope, and just before exit.
10268 @end quotation
10269 You may see this problem when you are stepping by machine instructions.
10270 This is because, on most machines, it takes more than one instruction to
10271 set up a stack frame (including local variable definitions); if you are
10272 stepping by machine instructions, variables may appear to have the wrong
10273 values until the stack frame is completely built. On exit, it usually
10274 also takes more than one machine instruction to destroy a stack frame;
10275 after you begin stepping through that group of instructions, local
10276 variable definitions may be gone.
10277
10278 This may also happen when the compiler does significant optimizations.
10279 To be sure of always seeing accurate values, turn off all optimization
10280 when compiling.
10281
10282 @cindex ``No symbol "foo" in current context''
10283 Another possible effect of compiler optimizations is to optimize
10284 unused variables out of existence, or assign variables to registers (as
10285 opposed to memory addresses). Depending on the support for such cases
10286 offered by the debug info format used by the compiler, @value{GDBN}
10287 might not be able to display values for such local variables. If that
10288 happens, @value{GDBN} will print a message like this:
10289
10290 @smallexample
10291 No symbol "foo" in current context.
10292 @end smallexample
10293
10294 To solve such problems, either recompile without optimizations, or use a
10295 different debug info format, if the compiler supports several such
10296 formats. @xref{Compilation}, for more information on choosing compiler
10297 options. @xref{C, ,C and C@t{++}}, for more information about debug
10298 info formats that are best suited to C@t{++} programs.
10299
10300 If you ask to print an object whose contents are unknown to
10301 @value{GDBN}, e.g., because its data type is not completely specified
10302 by the debug information, @value{GDBN} will say @samp{<incomplete
10303 type>}. @xref{Symbols, incomplete type}, for more about this.
10304
10305 @cindex no debug info variables
10306 If you try to examine or use the value of a (global) variable for
10307 which @value{GDBN} has no type information, e.g., because the program
10308 includes no debug information, @value{GDBN} displays an error message.
10309 @xref{Symbols, unknown type}, for more about unknown types. If you
10310 cast the variable to its declared type, @value{GDBN} gets the
10311 variable's value using the cast-to type as the variable's type. For
10312 example, in a C program:
10313
10314 @smallexample
10315 (@value{GDBP}) p var
10316 'var' has unknown type; cast it to its declared type
10317 (@value{GDBP}) p (float) var
10318 $1 = 3.14
10319 @end smallexample
10320
10321 If you append @kbd{@@entry} string to a function parameter name you get its
10322 value at the time the function got called. If the value is not available an
10323 error message is printed. Entry values are available only with some compilers.
10324 Entry values are normally also printed at the function parameter list according
10325 to @ref{set print entry-values}.
10326
10327 @smallexample
10328 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10329 29 i++;
10330 (gdb) next
10331 30 e (i);
10332 (gdb) print i
10333 $1 = 31
10334 (gdb) print i@@entry
10335 $2 = 30
10336 @end smallexample
10337
10338 Strings are identified as arrays of @code{char} values without specified
10339 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10340 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10341 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10342 defines literal string type @code{"char"} as @code{char} without a sign.
10343 For program code
10344
10345 @smallexample
10346 char var0[] = "A";
10347 signed char var1[] = "A";
10348 @end smallexample
10349
10350 You get during debugging
10351 @smallexample
10352 (gdb) print var0
10353 $1 = "A"
10354 (gdb) print var1
10355 $2 = @{65 'A', 0 '\0'@}
10356 @end smallexample
10357
10358 @node Arrays
10359 @section Artificial Arrays
10360
10361 @cindex artificial array
10362 @cindex arrays
10363 @kindex @@@r{, referencing memory as an array}
10364 It is often useful to print out several successive objects of the
10365 same type in memory; a section of an array, or an array of
10366 dynamically determined size for which only a pointer exists in the
10367 program.
10368
10369 You can do this by referring to a contiguous span of memory as an
10370 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10371 operand of @samp{@@} should be the first element of the desired array
10372 and be an individual object. The right operand should be the desired length
10373 of the array. The result is an array value whose elements are all of
10374 the type of the left argument. The first element is actually the left
10375 argument; the second element comes from bytes of memory immediately
10376 following those that hold the first element, and so on. Here is an
10377 example. If a program says
10378
10379 @smallexample
10380 int *array = (int *) malloc (len * sizeof (int));
10381 @end smallexample
10382
10383 @noindent
10384 you can print the contents of @code{array} with
10385
10386 @smallexample
10387 p *array@@len
10388 @end smallexample
10389
10390 The left operand of @samp{@@} must reside in memory. Array values made
10391 with @samp{@@} in this way behave just like other arrays in terms of
10392 subscripting, and are coerced to pointers when used in expressions.
10393 Artificial arrays most often appear in expressions via the value history
10394 (@pxref{Value History, ,Value History}), after printing one out.
10395
10396 Another way to create an artificial array is to use a cast.
10397 This re-interprets a value as if it were an array.
10398 The value need not be in memory:
10399 @smallexample
10400 (@value{GDBP}) p/x (short[2])0x12345678
10401 $1 = @{0x1234, 0x5678@}
10402 @end smallexample
10403
10404 As a convenience, if you leave the array length out (as in
10405 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10406 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10407 @smallexample
10408 (@value{GDBP}) p/x (short[])0x12345678
10409 $2 = @{0x1234, 0x5678@}
10410 @end smallexample
10411
10412 Sometimes the artificial array mechanism is not quite enough; in
10413 moderately complex data structures, the elements of interest may not
10414 actually be adjacent---for example, if you are interested in the values
10415 of pointers in an array. One useful work-around in this situation is
10416 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10417 Variables}) as a counter in an expression that prints the first
10418 interesting value, and then repeat that expression via @key{RET}. For
10419 instance, suppose you have an array @code{dtab} of pointers to
10420 structures, and you are interested in the values of a field @code{fv}
10421 in each structure. Here is an example of what you might type:
10422
10423 @smallexample
10424 set $i = 0
10425 p dtab[$i++]->fv
10426 @key{RET}
10427 @key{RET}
10428 @dots{}
10429 @end smallexample
10430
10431 @node Output Formats
10432 @section Output Formats
10433
10434 @cindex formatted output
10435 @cindex output formats
10436 By default, @value{GDBN} prints a value according to its data type. Sometimes
10437 this is not what you want. For example, you might want to print a number
10438 in hex, or a pointer in decimal. Or you might want to view data in memory
10439 at a certain address as a character string or as an instruction. To do
10440 these things, specify an @dfn{output format} when you print a value.
10441
10442 The simplest use of output formats is to say how to print a value
10443 already computed. This is done by starting the arguments of the
10444 @code{print} command with a slash and a format letter. The format
10445 letters supported are:
10446
10447 @table @code
10448 @item x
10449 Regard the bits of the value as an integer, and print the integer in
10450 hexadecimal.
10451
10452 @item d
10453 Print as integer in signed decimal.
10454
10455 @item u
10456 Print as integer in unsigned decimal.
10457
10458 @item o
10459 Print as integer in octal.
10460
10461 @item t
10462 Print as integer in binary. The letter @samp{t} stands for ``two''.
10463 @footnote{@samp{b} cannot be used because these format letters are also
10464 used with the @code{x} command, where @samp{b} stands for ``byte'';
10465 see @ref{Memory,,Examining Memory}.}
10466
10467 @item a
10468 @cindex unknown address, locating
10469 @cindex locate address
10470 Print as an address, both absolute in hexadecimal and as an offset from
10471 the nearest preceding symbol. You can use this format used to discover
10472 where (in what function) an unknown address is located:
10473
10474 @smallexample
10475 (@value{GDBP}) p/a 0x54320
10476 $3 = 0x54320 <_initialize_vx+396>
10477 @end smallexample
10478
10479 @noindent
10480 The command @code{info symbol 0x54320} yields similar results.
10481 @xref{Symbols, info symbol}.
10482
10483 @item c
10484 Regard as an integer and print it as a character constant. This
10485 prints both the numerical value and its character representation. The
10486 character representation is replaced with the octal escape @samp{\nnn}
10487 for characters outside the 7-bit @sc{ascii} range.
10488
10489 Without this format, @value{GDBN} displays @code{char},
10490 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10491 constants. Single-byte members of vectors are displayed as integer
10492 data.
10493
10494 @item f
10495 Regard the bits of the value as a floating point number and print
10496 using typical floating point syntax.
10497
10498 @item s
10499 @cindex printing strings
10500 @cindex printing byte arrays
10501 Regard as a string, if possible. With this format, pointers to single-byte
10502 data are displayed as null-terminated strings and arrays of single-byte data
10503 are displayed as fixed-length strings. Other values are displayed in their
10504 natural types.
10505
10506 Without this format, @value{GDBN} displays pointers to and arrays of
10507 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10508 strings. Single-byte members of a vector are displayed as an integer
10509 array.
10510
10511 @item z
10512 Like @samp{x} formatting, the value is treated as an integer and
10513 printed as hexadecimal, but leading zeros are printed to pad the value
10514 to the size of the integer type.
10515
10516 @item r
10517 @cindex raw printing
10518 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10519 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10520 Printing}). This typically results in a higher-level display of the
10521 value's contents. The @samp{r} format bypasses any Python
10522 pretty-printer which might exist.
10523 @end table
10524
10525 For example, to print the program counter in hex (@pxref{Registers}), type
10526
10527 @smallexample
10528 p/x $pc
10529 @end smallexample
10530
10531 @noindent
10532 Note that no space is required before the slash; this is because command
10533 names in @value{GDBN} cannot contain a slash.
10534
10535 To reprint the last value in the value history with a different format,
10536 you can use the @code{print} command with just a format and no
10537 expression. For example, @samp{p/x} reprints the last value in hex.
10538
10539 @node Memory
10540 @section Examining Memory
10541
10542 You can use the command @code{x} (for ``examine'') to examine memory in
10543 any of several formats, independently of your program's data types.
10544
10545 @cindex examining memory
10546 @table @code
10547 @kindex x @r{(examine memory)}
10548 @item x/@var{nfu} @var{addr}
10549 @itemx x @var{addr}
10550 @itemx x
10551 Use the @code{x} command to examine memory.
10552 @end table
10553
10554 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10555 much memory to display and how to format it; @var{addr} is an
10556 expression giving the address where you want to start displaying memory.
10557 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10558 Several commands set convenient defaults for @var{addr}.
10559
10560 @table @r
10561 @item @var{n}, the repeat count
10562 The repeat count is a decimal integer; the default is 1. It specifies
10563 how much memory (counting by units @var{u}) to display. If a negative
10564 number is specified, memory is examined backward from @var{addr}.
10565 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10566 @c 4.1.2.
10567
10568 @item @var{f}, the display format
10569 The display format is one of the formats used by @code{print}
10570 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10571 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10572 The default is @samp{x} (hexadecimal) initially. The default changes
10573 each time you use either @code{x} or @code{print}.
10574
10575 @item @var{u}, the unit size
10576 The unit size is any of
10577
10578 @table @code
10579 @item b
10580 Bytes.
10581 @item h
10582 Halfwords (two bytes).
10583 @item w
10584 Words (four bytes). This is the initial default.
10585 @item g
10586 Giant words (eight bytes).
10587 @end table
10588
10589 Each time you specify a unit size with @code{x}, that size becomes the
10590 default unit the next time you use @code{x}. For the @samp{i} format,
10591 the unit size is ignored and is normally not written. For the @samp{s} format,
10592 the unit size defaults to @samp{b}, unless it is explicitly given.
10593 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10594 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10595 Note that the results depend on the programming language of the
10596 current compilation unit. If the language is C, the @samp{s}
10597 modifier will use the UTF-16 encoding while @samp{w} will use
10598 UTF-32. The encoding is set by the programming language and cannot
10599 be altered.
10600
10601 @item @var{addr}, starting display address
10602 @var{addr} is the address where you want @value{GDBN} to begin displaying
10603 memory. The expression need not have a pointer value (though it may);
10604 it is always interpreted as an integer address of a byte of memory.
10605 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10606 @var{addr} is usually just after the last address examined---but several
10607 other commands also set the default address: @code{info breakpoints} (to
10608 the address of the last breakpoint listed), @code{info line} (to the
10609 starting address of a line), and @code{print} (if you use it to display
10610 a value from memory).
10611 @end table
10612
10613 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10614 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10615 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10616 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10617 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10618
10619 You can also specify a negative repeat count to examine memory backward
10620 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10621 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10622
10623 Since the letters indicating unit sizes are all distinct from the
10624 letters specifying output formats, you do not have to remember whether
10625 unit size or format comes first; either order works. The output
10626 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10627 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10628
10629 Even though the unit size @var{u} is ignored for the formats @samp{s}
10630 and @samp{i}, you might still want to use a count @var{n}; for example,
10631 @samp{3i} specifies that you want to see three machine instructions,
10632 including any operands. For convenience, especially when used with
10633 the @code{display} command, the @samp{i} format also prints branch delay
10634 slot instructions, if any, beyond the count specified, which immediately
10635 follow the last instruction that is within the count. The command
10636 @code{disassemble} gives an alternative way of inspecting machine
10637 instructions; see @ref{Machine Code,,Source and Machine Code}.
10638
10639 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10640 the command displays null-terminated strings or instructions before the given
10641 address as many as the absolute value of the given number. For the @samp{i}
10642 format, we use line number information in the debug info to accurately locate
10643 instruction boundaries while disassembling backward. If line info is not
10644 available, the command stops examining memory with an error message.
10645
10646 All the defaults for the arguments to @code{x} are designed to make it
10647 easy to continue scanning memory with minimal specifications each time
10648 you use @code{x}. For example, after you have inspected three machine
10649 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10650 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10651 the repeat count @var{n} is used again; the other arguments default as
10652 for successive uses of @code{x}.
10653
10654 When examining machine instructions, the instruction at current program
10655 counter is shown with a @code{=>} marker. For example:
10656
10657 @smallexample
10658 (@value{GDBP}) x/5i $pc-6
10659 0x804837f <main+11>: mov %esp,%ebp
10660 0x8048381 <main+13>: push %ecx
10661 0x8048382 <main+14>: sub $0x4,%esp
10662 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10663 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10664 @end smallexample
10665
10666 @cindex @code{$_}, @code{$__}, and value history
10667 The addresses and contents printed by the @code{x} command are not saved
10668 in the value history because there is often too much of them and they
10669 would get in the way. Instead, @value{GDBN} makes these values available for
10670 subsequent use in expressions as values of the convenience variables
10671 @code{$_} and @code{$__}. After an @code{x} command, the last address
10672 examined is available for use in expressions in the convenience variable
10673 @code{$_}. The contents of that address, as examined, are available in
10674 the convenience variable @code{$__}.
10675
10676 If the @code{x} command has a repeat count, the address and contents saved
10677 are from the last memory unit printed; this is not the same as the last
10678 address printed if several units were printed on the last line of output.
10679
10680 @anchor{addressable memory unit}
10681 @cindex addressable memory unit
10682 Most targets have an addressable memory unit size of 8 bits. This means
10683 that to each memory address are associated 8 bits of data. Some
10684 targets, however, have other addressable memory unit sizes.
10685 Within @value{GDBN} and this document, the term
10686 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10687 when explicitly referring to a chunk of data of that size. The word
10688 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10689 the addressable memory unit size of the target. For most systems,
10690 addressable memory unit is a synonym of byte.
10691
10692 @cindex remote memory comparison
10693 @cindex target memory comparison
10694 @cindex verify remote memory image
10695 @cindex verify target memory image
10696 When you are debugging a program running on a remote target machine
10697 (@pxref{Remote Debugging}), you may wish to verify the program's image
10698 in the remote machine's memory against the executable file you
10699 downloaded to the target. Or, on any target, you may want to check
10700 whether the program has corrupted its own read-only sections. The
10701 @code{compare-sections} command is provided for such situations.
10702
10703 @table @code
10704 @kindex compare-sections
10705 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10706 Compare the data of a loadable section @var{section-name} in the
10707 executable file of the program being debugged with the same section in
10708 the target machine's memory, and report any mismatches. With no
10709 arguments, compares all loadable sections. With an argument of
10710 @code{-r}, compares all loadable read-only sections.
10711
10712 Note: for remote targets, this command can be accelerated if the
10713 target supports computing the CRC checksum of a block of memory
10714 (@pxref{qCRC packet}).
10715 @end table
10716
10717 @node Auto Display
10718 @section Automatic Display
10719 @cindex automatic display
10720 @cindex display of expressions
10721
10722 If you find that you want to print the value of an expression frequently
10723 (to see how it changes), you might want to add it to the @dfn{automatic
10724 display list} so that @value{GDBN} prints its value each time your program stops.
10725 Each expression added to the list is given a number to identify it;
10726 to remove an expression from the list, you specify that number.
10727 The automatic display looks like this:
10728
10729 @smallexample
10730 2: foo = 38
10731 3: bar[5] = (struct hack *) 0x3804
10732 @end smallexample
10733
10734 @noindent
10735 This display shows item numbers, expressions and their current values. As with
10736 displays you request manually using @code{x} or @code{print}, you can
10737 specify the output format you prefer; in fact, @code{display} decides
10738 whether to use @code{print} or @code{x} depending your format
10739 specification---it uses @code{x} if you specify either the @samp{i}
10740 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
10741
10742 @table @code
10743 @kindex display
10744 @item display @var{expr}
10745 Add the expression @var{expr} to the list of expressions to display
10746 each time your program stops. @xref{Expressions, ,Expressions}.
10747
10748 @code{display} does not repeat if you press @key{RET} again after using it.
10749
10750 @item display/@var{fmt} @var{expr}
10751 For @var{fmt} specifying only a display format and not a size or
10752 count, add the expression @var{expr} to the auto-display list but
10753 arrange to display it each time in the specified format @var{fmt}.
10754 @xref{Output Formats,,Output Formats}.
10755
10756 @item display/@var{fmt} @var{addr}
10757 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10758 number of units, add the expression @var{addr} as a memory address to
10759 be examined each time your program stops. Examining means in effect
10760 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
10761 @end table
10762
10763 For example, @samp{display/i $pc} can be helpful, to see the machine
10764 instruction about to be executed each time execution stops (@samp{$pc}
10765 is a common name for the program counter; @pxref{Registers, ,Registers}).
10766
10767 @table @code
10768 @kindex delete display
10769 @kindex undisplay
10770 @item undisplay @var{dnums}@dots{}
10771 @itemx delete display @var{dnums}@dots{}
10772 Remove items from the list of expressions to display. Specify the
10773 numbers of the displays that you want affected with the command
10774 argument @var{dnums}. It can be a single display number, one of the
10775 numbers shown in the first field of the @samp{info display} display;
10776 or it could be a range of display numbers, as in @code{2-4}.
10777
10778 @code{undisplay} does not repeat if you press @key{RET} after using it.
10779 (Otherwise you would just get the error @samp{No display number @dots{}}.)
10780
10781 @kindex disable display
10782 @item disable display @var{dnums}@dots{}
10783 Disable the display of item numbers @var{dnums}. A disabled display
10784 item is not printed automatically, but is not forgotten. It may be
10785 enabled again later. Specify the numbers of the displays that you
10786 want affected with the command argument @var{dnums}. It can be a
10787 single display number, one of the numbers shown in the first field of
10788 the @samp{info display} display; or it could be a range of display
10789 numbers, as in @code{2-4}.
10790
10791 @kindex enable display
10792 @item enable display @var{dnums}@dots{}
10793 Enable display of item numbers @var{dnums}. It becomes effective once
10794 again in auto display of its expression, until you specify otherwise.
10795 Specify the numbers of the displays that you want affected with the
10796 command argument @var{dnums}. It can be a single display number, one
10797 of the numbers shown in the first field of the @samp{info display}
10798 display; or it could be a range of display numbers, as in @code{2-4}.
10799
10800 @item display
10801 Display the current values of the expressions on the list, just as is
10802 done when your program stops.
10803
10804 @kindex info display
10805 @item info display
10806 Print the list of expressions previously set up to display
10807 automatically, each one with its item number, but without showing the
10808 values. This includes disabled expressions, which are marked as such.
10809 It also includes expressions which would not be displayed right now
10810 because they refer to automatic variables not currently available.
10811 @end table
10812
10813 @cindex display disabled out of scope
10814 If a display expression refers to local variables, then it does not make
10815 sense outside the lexical context for which it was set up. Such an
10816 expression is disabled when execution enters a context where one of its
10817 variables is not defined. For example, if you give the command
10818 @code{display last_char} while inside a function with an argument
10819 @code{last_char}, @value{GDBN} displays this argument while your program
10820 continues to stop inside that function. When it stops elsewhere---where
10821 there is no variable @code{last_char}---the display is disabled
10822 automatically. The next time your program stops where @code{last_char}
10823 is meaningful, you can enable the display expression once again.
10824
10825 @node Print Settings
10826 @section Print Settings
10827
10828 @cindex format options
10829 @cindex print settings
10830 @value{GDBN} provides the following ways to control how arrays, structures,
10831 and symbols are printed.
10832
10833 @noindent
10834 These settings are useful for debugging programs in any language:
10835
10836 @table @code
10837 @kindex set print
10838 @anchor{set print address}
10839 @item set print address
10840 @itemx set print address on
10841 @cindex print/don't print memory addresses
10842 @value{GDBN} prints memory addresses showing the location of stack
10843 traces, structure values, pointer values, breakpoints, and so forth,
10844 even when it also displays the contents of those addresses. The default
10845 is @code{on}. For example, this is what a stack frame display looks like with
10846 @code{set print address on}:
10847
10848 @smallexample
10849 @group
10850 (@value{GDBP}) f
10851 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10852 at input.c:530
10853 530 if (lquote != def_lquote)
10854 @end group
10855 @end smallexample
10856
10857 @item set print address off
10858 Do not print addresses when displaying their contents. For example,
10859 this is the same stack frame displayed with @code{set print address off}:
10860
10861 @smallexample
10862 @group
10863 (@value{GDBP}) set print addr off
10864 (@value{GDBP}) f
10865 #0 set_quotes (lq="<<", rq=">>") at input.c:530
10866 530 if (lquote != def_lquote)
10867 @end group
10868 @end smallexample
10869
10870 You can use @samp{set print address off} to eliminate all machine
10871 dependent displays from the @value{GDBN} interface. For example, with
10872 @code{print address off}, you should get the same text for backtraces on
10873 all machines---whether or not they involve pointer arguments.
10874
10875 @kindex show print
10876 @item show print address
10877 Show whether or not addresses are to be printed.
10878 @end table
10879
10880 When @value{GDBN} prints a symbolic address, it normally prints the
10881 closest earlier symbol plus an offset. If that symbol does not uniquely
10882 identify the address (for example, it is a name whose scope is a single
10883 source file), you may need to clarify. One way to do this is with
10884 @code{info line}, for example @samp{info line *0x4537}. Alternately,
10885 you can set @value{GDBN} to print the source file and line number when
10886 it prints a symbolic address:
10887
10888 @table @code
10889 @item set print symbol-filename on
10890 @cindex source file and line of a symbol
10891 @cindex symbol, source file and line
10892 Tell @value{GDBN} to print the source file name and line number of a
10893 symbol in the symbolic form of an address.
10894
10895 @item set print symbol-filename off
10896 Do not print source file name and line number of a symbol. This is the
10897 default.
10898
10899 @item show print symbol-filename
10900 Show whether or not @value{GDBN} will print the source file name and
10901 line number of a symbol in the symbolic form of an address.
10902 @end table
10903
10904 Another situation where it is helpful to show symbol filenames and line
10905 numbers is when disassembling code; @value{GDBN} shows you the line
10906 number and source file that corresponds to each instruction.
10907
10908 Also, you may wish to see the symbolic form only if the address being
10909 printed is reasonably close to the closest earlier symbol:
10910
10911 @table @code
10912 @item set print max-symbolic-offset @var{max-offset}
10913 @itemx set print max-symbolic-offset unlimited
10914 @cindex maximum value for offset of closest symbol
10915 Tell @value{GDBN} to only display the symbolic form of an address if the
10916 offset between the closest earlier symbol and the address is less than
10917 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
10918 to always print the symbolic form of an address if any symbol precedes
10919 it. Zero is equivalent to @code{unlimited}.
10920
10921 @item show print max-symbolic-offset
10922 Ask how large the maximum offset is that @value{GDBN} prints in a
10923 symbolic address.
10924 @end table
10925
10926 @cindex wild pointer, interpreting
10927 @cindex pointer, finding referent
10928 If you have a pointer and you are not sure where it points, try
10929 @samp{set print symbol-filename on}. Then you can determine the name
10930 and source file location of the variable where it points, using
10931 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
10932 For example, here @value{GDBN} shows that a variable @code{ptt} points
10933 at another variable @code{t}, defined in @file{hi2.c}:
10934
10935 @smallexample
10936 (@value{GDBP}) set print symbol-filename on
10937 (@value{GDBP}) p/a ptt
10938 $4 = 0xe008 <t in hi2.c>
10939 @end smallexample
10940
10941 @quotation
10942 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
10943 does not show the symbol name and filename of the referent, even with
10944 the appropriate @code{set print} options turned on.
10945 @end quotation
10946
10947 You can also enable @samp{/a}-like formatting all the time using
10948 @samp{set print symbol on}:
10949
10950 @anchor{set print symbol}
10951 @table @code
10952 @item set print symbol on
10953 Tell @value{GDBN} to print the symbol corresponding to an address, if
10954 one exists.
10955
10956 @item set print symbol off
10957 Tell @value{GDBN} not to print the symbol corresponding to an
10958 address. In this mode, @value{GDBN} will still print the symbol
10959 corresponding to pointers to functions. This is the default.
10960
10961 @item show print symbol
10962 Show whether @value{GDBN} will display the symbol corresponding to an
10963 address.
10964 @end table
10965
10966 Other settings control how different kinds of objects are printed:
10967
10968 @table @code
10969 @anchor{set print array}
10970 @item set print array
10971 @itemx set print array on
10972 @cindex pretty print arrays
10973 Pretty print arrays. This format is more convenient to read,
10974 but uses more space. The default is off.
10975
10976 @item set print array off
10977 Return to compressed format for arrays.
10978
10979 @item show print array
10980 Show whether compressed or pretty format is selected for displaying
10981 arrays.
10982
10983 @cindex print array indexes
10984 @anchor{set print array-indexes}
10985 @item set print array-indexes
10986 @itemx set print array-indexes on
10987 Print the index of each element when displaying arrays. May be more
10988 convenient to locate a given element in the array or quickly find the
10989 index of a given element in that printed array. The default is off.
10990
10991 @item set print array-indexes off
10992 Stop printing element indexes when displaying arrays.
10993
10994 @item show print array-indexes
10995 Show whether the index of each element is printed when displaying
10996 arrays.
10997
10998 @anchor{set print elements}
10999 @item set print elements @var{number-of-elements}
11000 @itemx set print elements unlimited
11001 @cindex number of array elements to print
11002 @cindex limit on number of printed array elements
11003 Set a limit on how many elements of an array @value{GDBN} will print.
11004 If @value{GDBN} is printing a large array, it stops printing after it has
11005 printed the number of elements set by the @code{set print elements} command.
11006 This limit also applies to the display of strings.
11007 When @value{GDBN} starts, this limit is set to 200.
11008 Setting @var{number-of-elements} to @code{unlimited} or zero means
11009 that the number of elements to print is unlimited.
11010
11011 @item show print elements
11012 Display the number of elements of a large array that @value{GDBN} will print.
11013 If the number is 0, then the printing is unlimited.
11014
11015 @anchor{set print frame-arguments}
11016 @item set print frame-arguments @var{value}
11017 @kindex set print frame-arguments
11018 @cindex printing frame argument values
11019 @cindex print all frame argument values
11020 @cindex print frame argument values for scalars only
11021 @cindex do not print frame arguments
11022 This command allows to control how the values of arguments are printed
11023 when the debugger prints a frame (@pxref{Frames}). The possible
11024 values are:
11025
11026 @table @code
11027 @item all
11028 The values of all arguments are printed.
11029
11030 @item scalars
11031 Print the value of an argument only if it is a scalar. The value of more
11032 complex arguments such as arrays, structures, unions, etc, is replaced
11033 by @code{@dots{}}. This is the default. Here is an example where
11034 only scalar arguments are shown:
11035
11036 @smallexample
11037 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11038 at frame-args.c:23
11039 @end smallexample
11040
11041 @item none
11042 None of the argument values are printed. Instead, the value of each argument
11043 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11044
11045 @smallexample
11046 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11047 at frame-args.c:23
11048 @end smallexample
11049
11050 @item presence
11051 Only the presence of arguments is indicated by @code{@dots{}}.
11052 The @code{@dots{}} are not printed for function without any arguments.
11053 None of the argument names and values are printed.
11054 In this case, the example above now becomes:
11055
11056 @smallexample
11057 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11058 @end smallexample
11059
11060 @end table
11061
11062 By default, only scalar arguments are printed. This command can be used
11063 to configure the debugger to print the value of all arguments, regardless
11064 of their type. However, it is often advantageous to not print the value
11065 of more complex parameters. For instance, it reduces the amount of
11066 information printed in each frame, making the backtrace more readable.
11067 Also, it improves performance when displaying Ada frames, because
11068 the computation of large arguments can sometimes be CPU-intensive,
11069 especially in large applications. Setting @code{print frame-arguments}
11070 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11071 this computation, thus speeding up the display of each Ada frame.
11072
11073 @item show print frame-arguments
11074 Show how the value of arguments should be displayed when printing a frame.
11075
11076 @anchor{set print raw-frame-arguments}
11077 @item set print raw-frame-arguments on
11078 Print frame arguments in raw, non pretty-printed, form.
11079
11080 @item set print raw-frame-arguments off
11081 Print frame arguments in pretty-printed form, if there is a pretty-printer
11082 for the value (@pxref{Pretty Printing}),
11083 otherwise print the value in raw form.
11084 This is the default.
11085
11086 @item show print raw-frame-arguments
11087 Show whether to print frame arguments in raw form.
11088
11089 @anchor{set print entry-values}
11090 @item set print entry-values @var{value}
11091 @kindex set print entry-values
11092 Set printing of frame argument values at function entry. In some cases
11093 @value{GDBN} can determine the value of function argument which was passed by
11094 the function caller, even if the value was modified inside the called function
11095 and therefore is different. With optimized code, the current value could be
11096 unavailable, but the entry value may still be known.
11097
11098 The default value is @code{default} (see below for its description). Older
11099 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11100 this feature will behave in the @code{default} setting the same way as with the
11101 @code{no} setting.
11102
11103 This functionality is currently supported only by DWARF 2 debugging format and
11104 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11105 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11106 this information.
11107
11108 The @var{value} parameter can be one of the following:
11109
11110 @table @code
11111 @item no
11112 Print only actual parameter values, never print values from function entry
11113 point.
11114 @smallexample
11115 #0 equal (val=5)
11116 #0 different (val=6)
11117 #0 lost (val=<optimized out>)
11118 #0 born (val=10)
11119 #0 invalid (val=<optimized out>)
11120 @end smallexample
11121
11122 @item only
11123 Print only parameter values from function entry point. The actual parameter
11124 values are never printed.
11125 @smallexample
11126 #0 equal (val@@entry=5)
11127 #0 different (val@@entry=5)
11128 #0 lost (val@@entry=5)
11129 #0 born (val@@entry=<optimized out>)
11130 #0 invalid (val@@entry=<optimized out>)
11131 @end smallexample
11132
11133 @item preferred
11134 Print only parameter values from function entry point. If value from function
11135 entry point is not known while the actual value is known, print the actual
11136 value for such parameter.
11137 @smallexample
11138 #0 equal (val@@entry=5)
11139 #0 different (val@@entry=5)
11140 #0 lost (val@@entry=5)
11141 #0 born (val=10)
11142 #0 invalid (val@@entry=<optimized out>)
11143 @end smallexample
11144
11145 @item if-needed
11146 Print actual parameter values. If actual parameter value is not known while
11147 value from function entry point is known, print the entry point value for such
11148 parameter.
11149 @smallexample
11150 #0 equal (val=5)
11151 #0 different (val=6)
11152 #0 lost (val@@entry=5)
11153 #0 born (val=10)
11154 #0 invalid (val=<optimized out>)
11155 @end smallexample
11156
11157 @item both
11158 Always print both the actual parameter value and its value from function entry
11159 point, even if values of one or both are not available due to compiler
11160 optimizations.
11161 @smallexample
11162 #0 equal (val=5, val@@entry=5)
11163 #0 different (val=6, val@@entry=5)
11164 #0 lost (val=<optimized out>, val@@entry=5)
11165 #0 born (val=10, val@@entry=<optimized out>)
11166 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11167 @end smallexample
11168
11169 @item compact
11170 Print the actual parameter value if it is known and also its value from
11171 function entry point if it is known. If neither is known, print for the actual
11172 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11173 values are known and identical, print the shortened
11174 @code{param=param@@entry=VALUE} notation.
11175 @smallexample
11176 #0 equal (val=val@@entry=5)
11177 #0 different (val=6, val@@entry=5)
11178 #0 lost (val@@entry=5)
11179 #0 born (val=10)
11180 #0 invalid (val=<optimized out>)
11181 @end smallexample
11182
11183 @item default
11184 Always print the actual parameter value. Print also its value from function
11185 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11186 if both values are known and identical, print the shortened
11187 @code{param=param@@entry=VALUE} notation.
11188 @smallexample
11189 #0 equal (val=val@@entry=5)
11190 #0 different (val=6, val@@entry=5)
11191 #0 lost (val=<optimized out>, val@@entry=5)
11192 #0 born (val=10)
11193 #0 invalid (val=<optimized out>)
11194 @end smallexample
11195 @end table
11196
11197 For analysis messages on possible failures of frame argument values at function
11198 entry resolution see @ref{set debug entry-values}.
11199
11200 @item show print entry-values
11201 Show the method being used for printing of frame argument values at function
11202 entry.
11203
11204 @anchor{set print frame-info}
11205 @item set print frame-info @var{value}
11206 @kindex set print frame-info
11207 @cindex printing frame information
11208 @cindex frame information, printing
11209 This command allows to control the information printed when
11210 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11211 for a general explanation about frames and frame information.
11212 Note that some other settings (such as @code{set print frame-arguments}
11213 and @code{set print address}) are also influencing if and how some frame
11214 information is displayed. In particular, the frame program counter is never
11215 printed if @code{set print address} is off.
11216
11217 The possible values for @code{set print frame-info} are:
11218 @table @code
11219 @item short-location
11220 Print the frame level, the program counter (if not at the
11221 beginning of the location source line), the function, the function
11222 arguments.
11223 @item location
11224 Same as @code{short-location} but also print the source file and source line
11225 number.
11226 @item location-and-address
11227 Same as @code{location} but print the program counter even if located at the
11228 beginning of the location source line.
11229 @item source-line
11230 Print the program counter (if not at the beginning of the location
11231 source line), the line number and the source line.
11232 @item source-and-location
11233 Print what @code{location} and @code{source-line} are printing.
11234 @item auto
11235 The information printed for a frame is decided automatically
11236 by the @value{GDBN} command that prints a frame.
11237 For example, @code{frame} prints the information printed by
11238 @code{source-and-location} while @code{stepi} will switch between
11239 @code{source-line} and @code{source-and-location} depending on the program
11240 counter.
11241 The default value is @code{auto}.
11242 @end table
11243
11244 @anchor{set print repeats}
11245 @item set print repeats @var{number-of-repeats}
11246 @itemx set print repeats unlimited
11247 @cindex repeated array elements
11248 Set the threshold for suppressing display of repeated array
11249 elements. When the number of consecutive identical elements of an
11250 array exceeds the threshold, @value{GDBN} prints the string
11251 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11252 identical repetitions, instead of displaying the identical elements
11253 themselves. Setting the threshold to @code{unlimited} or zero will
11254 cause all elements to be individually printed. The default threshold
11255 is 10.
11256
11257 @item show print repeats
11258 Display the current threshold for printing repeated identical
11259 elements.
11260
11261 @anchor{set print max-depth}
11262 @item set print max-depth @var{depth}
11263 @item set print max-depth unlimited
11264 @cindex printing nested structures
11265 Set the threshold after which nested structures are replaced with
11266 ellipsis, this can make visualising deeply nested structures easier.
11267
11268 For example, given this C code
11269
11270 @smallexample
11271 typedef struct s1 @{ int a; @} s1;
11272 typedef struct s2 @{ s1 b; @} s2;
11273 typedef struct s3 @{ s2 c; @} s3;
11274 typedef struct s4 @{ s3 d; @} s4;
11275
11276 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11277 @end smallexample
11278
11279 The following table shows how different values of @var{depth} will
11280 effect how @code{var} is printed by @value{GDBN}:
11281
11282 @multitable @columnfractions .3 .7
11283 @headitem @var{depth} setting @tab Result of @samp{p var}
11284 @item unlimited
11285 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11286 @item @code{0}
11287 @tab @code{$1 = @{...@}}
11288 @item @code{1}
11289 @tab @code{$1 = @{d = @{...@}@}}
11290 @item @code{2}
11291 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11292 @item @code{3}
11293 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11294 @item @code{4}
11295 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11296 @end multitable
11297
11298 To see the contents of structures that have been hidden the user can
11299 either increase the print max-depth, or they can print the elements of
11300 the structure that are visible, for example
11301
11302 @smallexample
11303 (gdb) set print max-depth 2
11304 (gdb) p var
11305 $1 = @{d = @{c = @{...@}@}@}
11306 (gdb) p var.d
11307 $2 = @{c = @{b = @{...@}@}@}
11308 (gdb) p var.d.c
11309 $3 = @{b = @{a = 3@}@}
11310 @end smallexample
11311
11312 The pattern used to replace nested structures varies based on
11313 language, for most languages @code{@{...@}} is used, but Fortran uses
11314 @code{(...)}.
11315
11316 @item show print max-depth
11317 Display the current threshold after which nested structures are
11318 replaces with ellipsis.
11319
11320 @anchor{set print null-stop}
11321 @item set print null-stop
11322 @cindex @sc{null} elements in arrays
11323 Cause @value{GDBN} to stop printing the characters of an array when the first
11324 @sc{null} is encountered. This is useful when large arrays actually
11325 contain only short strings.
11326 The default is off.
11327
11328 @item show print null-stop
11329 Show whether @value{GDBN} stops printing an array on the first
11330 @sc{null} character.
11331
11332 @anchor{set print pretty}
11333 @item set print pretty on
11334 @cindex print structures in indented form
11335 @cindex indentation in structure display
11336 Cause @value{GDBN} to print structures in an indented format with one member
11337 per line, like this:
11338
11339 @smallexample
11340 @group
11341 $1 = @{
11342 next = 0x0,
11343 flags = @{
11344 sweet = 1,
11345 sour = 1
11346 @},
11347 meat = 0x54 "Pork"
11348 @}
11349 @end group
11350 @end smallexample
11351
11352 @item set print pretty off
11353 Cause @value{GDBN} to print structures in a compact format, like this:
11354
11355 @smallexample
11356 @group
11357 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11358 meat = 0x54 "Pork"@}
11359 @end group
11360 @end smallexample
11361
11362 @noindent
11363 This is the default format.
11364
11365 @item show print pretty
11366 Show which format @value{GDBN} is using to print structures.
11367
11368 @anchor{set print raw-values}
11369 @item set print raw-values on
11370 Print values in raw form, without applying the pretty
11371 printers for the value.
11372
11373 @item set print raw-values off
11374 Print values in pretty-printed form, if there is a pretty-printer
11375 for the value (@pxref{Pretty Printing}),
11376 otherwise print the value in raw form.
11377
11378 The default setting is ``off''.
11379
11380 @item show print raw-values
11381 Show whether to print values in raw form.
11382
11383 @item set print sevenbit-strings on
11384 @cindex eight-bit characters in strings
11385 @cindex octal escapes in strings
11386 Print using only seven-bit characters; if this option is set,
11387 @value{GDBN} displays any eight-bit characters (in strings or
11388 character values) using the notation @code{\}@var{nnn}. This setting is
11389 best if you are working in English (@sc{ascii}) and you use the
11390 high-order bit of characters as a marker or ``meta'' bit.
11391
11392 @item set print sevenbit-strings off
11393 Print full eight-bit characters. This allows the use of more
11394 international character sets, and is the default.
11395
11396 @item show print sevenbit-strings
11397 Show whether or not @value{GDBN} is printing only seven-bit characters.
11398
11399 @anchor{set print union}
11400 @item set print union on
11401 @cindex unions in structures, printing
11402 Tell @value{GDBN} to print unions which are contained in structures
11403 and other unions. This is the default setting.
11404
11405 @item set print union off
11406 Tell @value{GDBN} not to print unions which are contained in
11407 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11408 instead.
11409
11410 @item show print union
11411 Ask @value{GDBN} whether or not it will print unions which are contained in
11412 structures and other unions.
11413
11414 For example, given the declarations
11415
11416 @smallexample
11417 typedef enum @{Tree, Bug@} Species;
11418 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11419 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11420 Bug_forms;
11421
11422 struct thing @{
11423 Species it;
11424 union @{
11425 Tree_forms tree;
11426 Bug_forms bug;
11427 @} form;
11428 @};
11429
11430 struct thing foo = @{Tree, @{Acorn@}@};
11431 @end smallexample
11432
11433 @noindent
11434 with @code{set print union on} in effect @samp{p foo} would print
11435
11436 @smallexample
11437 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11438 @end smallexample
11439
11440 @noindent
11441 and with @code{set print union off} in effect it would print
11442
11443 @smallexample
11444 $1 = @{it = Tree, form = @{...@}@}
11445 @end smallexample
11446
11447 @noindent
11448 @code{set print union} affects programs written in C-like languages
11449 and in Pascal.
11450 @end table
11451
11452 @need 1000
11453 @noindent
11454 These settings are of interest when debugging C@t{++} programs:
11455
11456 @table @code
11457 @cindex demangling C@t{++} names
11458 @item set print demangle
11459 @itemx set print demangle on
11460 Print C@t{++} names in their source form rather than in the encoded
11461 (``mangled'') form passed to the assembler and linker for type-safe
11462 linkage. The default is on.
11463
11464 @item show print demangle
11465 Show whether C@t{++} names are printed in mangled or demangled form.
11466
11467 @item set print asm-demangle
11468 @itemx set print asm-demangle on
11469 Print C@t{++} names in their source form rather than their mangled form, even
11470 in assembler code printouts such as instruction disassemblies.
11471 The default is off.
11472
11473 @item show print asm-demangle
11474 Show whether C@t{++} names in assembly listings are printed in mangled
11475 or demangled form.
11476
11477 @cindex C@t{++} symbol decoding style
11478 @cindex symbol decoding style, C@t{++}
11479 @kindex set demangle-style
11480 @item set demangle-style @var{style}
11481 Choose among several encoding schemes used by different compilers to represent
11482 C@t{++} names. If you omit @var{style}, you will see a list of possible
11483 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11484 decoding style by inspecting your program.
11485
11486 @item show demangle-style
11487 Display the encoding style currently in use for decoding C@t{++} symbols.
11488
11489 @anchor{set print object}
11490 @item set print object
11491 @itemx set print object on
11492 @cindex derived type of an object, printing
11493 @cindex display derived types
11494 When displaying a pointer to an object, identify the @emph{actual}
11495 (derived) type of the object rather than the @emph{declared} type, using
11496 the virtual function table. Note that the virtual function table is
11497 required---this feature can only work for objects that have run-time
11498 type identification; a single virtual method in the object's declared
11499 type is sufficient. Note that this setting is also taken into account when
11500 working with variable objects via MI (@pxref{GDB/MI}).
11501
11502 @item set print object off
11503 Display only the declared type of objects, without reference to the
11504 virtual function table. This is the default setting.
11505
11506 @item show print object
11507 Show whether actual, or declared, object types are displayed.
11508
11509 @anchor{set print static-members}
11510 @item set print static-members
11511 @itemx set print static-members on
11512 @cindex static members of C@t{++} objects
11513 Print static members when displaying a C@t{++} object. The default is on.
11514
11515 @item set print static-members off
11516 Do not print static members when displaying a C@t{++} object.
11517
11518 @item show print static-members
11519 Show whether C@t{++} static members are printed or not.
11520
11521 @item set print pascal_static-members
11522 @itemx set print pascal_static-members on
11523 @cindex static members of Pascal objects
11524 @cindex Pascal objects, static members display
11525 Print static members when displaying a Pascal object. The default is on.
11526
11527 @item set print pascal_static-members off
11528 Do not print static members when displaying a Pascal object.
11529
11530 @item show print pascal_static-members
11531 Show whether Pascal static members are printed or not.
11532
11533 @c These don't work with HP ANSI C++ yet.
11534 @anchor{set print vtbl}
11535 @item set print vtbl
11536 @itemx set print vtbl on
11537 @cindex pretty print C@t{++} virtual function tables
11538 @cindex virtual functions (C@t{++}) display
11539 @cindex VTBL display
11540 Pretty print C@t{++} virtual function tables. The default is off.
11541 (The @code{vtbl} commands do not work on programs compiled with the HP
11542 ANSI C@t{++} compiler (@code{aCC}).)
11543
11544 @item set print vtbl off
11545 Do not pretty print C@t{++} virtual function tables.
11546
11547 @item show print vtbl
11548 Show whether C@t{++} virtual function tables are pretty printed, or not.
11549 @end table
11550
11551 @node Pretty Printing
11552 @section Pretty Printing
11553
11554 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11555 Python code. It greatly simplifies the display of complex objects. This
11556 mechanism works for both MI and the CLI.
11557
11558 @menu
11559 * Pretty-Printer Introduction:: Introduction to pretty-printers
11560 * Pretty-Printer Example:: An example pretty-printer
11561 * Pretty-Printer Commands:: Pretty-printer commands
11562 @end menu
11563
11564 @node Pretty-Printer Introduction
11565 @subsection Pretty-Printer Introduction
11566
11567 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11568 registered for the value. If there is then @value{GDBN} invokes the
11569 pretty-printer to print the value. Otherwise the value is printed normally.
11570
11571 Pretty-printers are normally named. This makes them easy to manage.
11572 The @samp{info pretty-printer} command will list all the installed
11573 pretty-printers with their names.
11574 If a pretty-printer can handle multiple data types, then its
11575 @dfn{subprinters} are the printers for the individual data types.
11576 Each such subprinter has its own name.
11577 The format of the name is @var{printer-name};@var{subprinter-name}.
11578
11579 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11580 Typically they are automatically loaded and registered when the corresponding
11581 debug information is loaded, thus making them available without having to
11582 do anything special.
11583
11584 There are three places where a pretty-printer can be registered.
11585
11586 @itemize @bullet
11587 @item
11588 Pretty-printers registered globally are available when debugging
11589 all inferiors.
11590
11591 @item
11592 Pretty-printers registered with a program space are available only
11593 when debugging that program.
11594 @xref{Progspaces In Python}, for more details on program spaces in Python.
11595
11596 @item
11597 Pretty-printers registered with an objfile are loaded and unloaded
11598 with the corresponding objfile (e.g., shared library).
11599 @xref{Objfiles In Python}, for more details on objfiles in Python.
11600 @end itemize
11601
11602 @xref{Selecting Pretty-Printers}, for further information on how
11603 pretty-printers are selected,
11604
11605 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11606 for new types.
11607
11608 @node Pretty-Printer Example
11609 @subsection Pretty-Printer Example
11610
11611 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11612
11613 @smallexample
11614 (@value{GDBP}) print s
11615 $1 = @{
11616 static npos = 4294967295,
11617 _M_dataplus = @{
11618 <std::allocator<char>> = @{
11619 <__gnu_cxx::new_allocator<char>> = @{
11620 <No data fields>@}, <No data fields>
11621 @},
11622 members of std::basic_string<char, std::char_traits<char>,
11623 std::allocator<char> >::_Alloc_hider:
11624 _M_p = 0x804a014 "abcd"
11625 @}
11626 @}
11627 @end smallexample
11628
11629 With a pretty-printer for @code{std::string} only the contents are printed:
11630
11631 @smallexample
11632 (@value{GDBP}) print s
11633 $2 = "abcd"
11634 @end smallexample
11635
11636 @node Pretty-Printer Commands
11637 @subsection Pretty-Printer Commands
11638 @cindex pretty-printer commands
11639
11640 @table @code
11641 @kindex info pretty-printer
11642 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11643 Print the list of installed pretty-printers.
11644 This includes disabled pretty-printers, which are marked as such.
11645
11646 @var{object-regexp} is a regular expression matching the objects
11647 whose pretty-printers to list.
11648 Objects can be @code{global}, the program space's file
11649 (@pxref{Progspaces In Python}),
11650 and the object files within that program space (@pxref{Objfiles In Python}).
11651 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11652 looks up a printer from these three objects.
11653
11654 @var{name-regexp} is a regular expression matching the name of the printers
11655 to list.
11656
11657 @kindex disable pretty-printer
11658 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11659 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11660 A disabled pretty-printer is not forgotten, it may be enabled again later.
11661
11662 @kindex enable pretty-printer
11663 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11664 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11665 @end table
11666
11667 Example:
11668
11669 Suppose we have three pretty-printers installed: one from library1.so
11670 named @code{foo} that prints objects of type @code{foo}, and
11671 another from library2.so named @code{bar} that prints two types of objects,
11672 @code{bar1} and @code{bar2}.
11673
11674 @smallexample
11675 (gdb) info pretty-printer
11676 library1.so:
11677 foo
11678 library2.so:
11679 bar
11680 bar1
11681 bar2
11682 (gdb) info pretty-printer library2
11683 library2.so:
11684 bar
11685 bar1
11686 bar2
11687 (gdb) disable pretty-printer library1
11688 1 printer disabled
11689 2 of 3 printers enabled
11690 (gdb) info pretty-printer
11691 library1.so:
11692 foo [disabled]
11693 library2.so:
11694 bar
11695 bar1
11696 bar2
11697 (gdb) disable pretty-printer library2 bar;bar1
11698 1 printer disabled
11699 1 of 3 printers enabled
11700 (gdb) info pretty-printer library2
11701 library1.so:
11702 foo [disabled]
11703 library2.so:
11704 bar
11705 bar1 [disabled]
11706 bar2
11707 (gdb) disable pretty-printer library2 bar
11708 1 printer disabled
11709 0 of 3 printers enabled
11710 (gdb) info pretty-printer library2
11711 library1.so:
11712 foo [disabled]
11713 library2.so:
11714 bar [disabled]
11715 bar1 [disabled]
11716 bar2
11717 @end smallexample
11718
11719 Note that for @code{bar} the entire printer can be disabled,
11720 as can each individual subprinter.
11721
11722 Printing values and frame arguments is done by default using
11723 the enabled pretty printers.
11724
11725 The print option @code{-raw-values} and @value{GDBN} setting
11726 @code{set print raw-values} (@pxref{set print raw-values}) can be
11727 used to print values without applying the enabled pretty printers.
11728
11729 Similarly, the backtrace option @code{-raw-frame-arguments} and
11730 @value{GDBN} setting @code{set print raw-frame-arguments}
11731 (@pxref{set print raw-frame-arguments}) can be used to ignore the
11732 enabled pretty printers when printing frame argument values.
11733
11734 @node Value History
11735 @section Value History
11736
11737 @cindex value history
11738 @cindex history of values printed by @value{GDBN}
11739 Values printed by the @code{print} command are saved in the @value{GDBN}
11740 @dfn{value history}. This allows you to refer to them in other expressions.
11741 Values are kept until the symbol table is re-read or discarded
11742 (for example with the @code{file} or @code{symbol-file} commands).
11743 When the symbol table changes, the value history is discarded,
11744 since the values may contain pointers back to the types defined in the
11745 symbol table.
11746
11747 @cindex @code{$}
11748 @cindex @code{$$}
11749 @cindex history number
11750 The values printed are given @dfn{history numbers} by which you can
11751 refer to them. These are successive integers starting with one.
11752 @code{print} shows you the history number assigned to a value by
11753 printing @samp{$@var{num} = } before the value; here @var{num} is the
11754 history number.
11755
11756 To refer to any previous value, use @samp{$} followed by the value's
11757 history number. The way @code{print} labels its output is designed to
11758 remind you of this. Just @code{$} refers to the most recent value in
11759 the history, and @code{$$} refers to the value before that.
11760 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11761 is the value just prior to @code{$$}, @code{$$1} is equivalent to
11762 @code{$$}, and @code{$$0} is equivalent to @code{$}.
11763
11764 For example, suppose you have just printed a pointer to a structure and
11765 want to see the contents of the structure. It suffices to type
11766
11767 @smallexample
11768 p *$
11769 @end smallexample
11770
11771 If you have a chain of structures where the component @code{next} points
11772 to the next one, you can print the contents of the next one with this:
11773
11774 @smallexample
11775 p *$.next
11776 @end smallexample
11777
11778 @noindent
11779 You can print successive links in the chain by repeating this
11780 command---which you can do by just typing @key{RET}.
11781
11782 Note that the history records values, not expressions. If the value of
11783 @code{x} is 4 and you type these commands:
11784
11785 @smallexample
11786 print x
11787 set x=5
11788 @end smallexample
11789
11790 @noindent
11791 then the value recorded in the value history by the @code{print} command
11792 remains 4 even though the value of @code{x} has changed.
11793
11794 @table @code
11795 @kindex show values
11796 @item show values
11797 Print the last ten values in the value history, with their item numbers.
11798 This is like @samp{p@ $$9} repeated ten times, except that @code{show
11799 values} does not change the history.
11800
11801 @item show values @var{n}
11802 Print ten history values centered on history item number @var{n}.
11803
11804 @item show values +
11805 Print ten history values just after the values last printed. If no more
11806 values are available, @code{show values +} produces no display.
11807 @end table
11808
11809 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11810 same effect as @samp{show values +}.
11811
11812 @node Convenience Vars
11813 @section Convenience Variables
11814
11815 @cindex convenience variables
11816 @cindex user-defined variables
11817 @value{GDBN} provides @dfn{convenience variables} that you can use within
11818 @value{GDBN} to hold on to a value and refer to it later. These variables
11819 exist entirely within @value{GDBN}; they are not part of your program, and
11820 setting a convenience variable has no direct effect on further execution
11821 of your program. That is why you can use them freely.
11822
11823 Convenience variables are prefixed with @samp{$}. Any name preceded by
11824 @samp{$} can be used for a convenience variable, unless it is one of
11825 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
11826 (Value history references, in contrast, are @emph{numbers} preceded
11827 by @samp{$}. @xref{Value History, ,Value History}.)
11828
11829 You can save a value in a convenience variable with an assignment
11830 expression, just as you would set a variable in your program.
11831 For example:
11832
11833 @smallexample
11834 set $foo = *object_ptr
11835 @end smallexample
11836
11837 @noindent
11838 would save in @code{$foo} the value contained in the object pointed to by
11839 @code{object_ptr}.
11840
11841 Using a convenience variable for the first time creates it, but its
11842 value is @code{void} until you assign a new value. You can alter the
11843 value with another assignment at any time.
11844
11845 Convenience variables have no fixed types. You can assign a convenience
11846 variable any type of value, including structures and arrays, even if
11847 that variable already has a value of a different type. The convenience
11848 variable, when used as an expression, has the type of its current value.
11849
11850 @table @code
11851 @kindex show convenience
11852 @cindex show all user variables and functions
11853 @item show convenience
11854 Print a list of convenience variables used so far, and their values,
11855 as well as a list of the convenience functions.
11856 Abbreviated @code{show conv}.
11857
11858 @kindex init-if-undefined
11859 @cindex convenience variables, initializing
11860 @item init-if-undefined $@var{variable} = @var{expression}
11861 Set a convenience variable if it has not already been set. This is useful
11862 for user-defined commands that keep some state. It is similar, in concept,
11863 to using local static variables with initializers in C (except that
11864 convenience variables are global). It can also be used to allow users to
11865 override default values used in a command script.
11866
11867 If the variable is already defined then the expression is not evaluated so
11868 any side-effects do not occur.
11869 @end table
11870
11871 One of the ways to use a convenience variable is as a counter to be
11872 incremented or a pointer to be advanced. For example, to print
11873 a field from successive elements of an array of structures:
11874
11875 @smallexample
11876 set $i = 0
11877 print bar[$i++]->contents
11878 @end smallexample
11879
11880 @noindent
11881 Repeat that command by typing @key{RET}.
11882
11883 Some convenience variables are created automatically by @value{GDBN} and given
11884 values likely to be useful.
11885
11886 @table @code
11887 @vindex $_@r{, convenience variable}
11888 @item $_
11889 The variable @code{$_} is automatically set by the @code{x} command to
11890 the last address examined (@pxref{Memory, ,Examining Memory}). Other
11891 commands which provide a default address for @code{x} to examine also
11892 set @code{$_} to that address; these commands include @code{info line}
11893 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11894 except when set by the @code{x} command, in which case it is a pointer
11895 to the type of @code{$__}.
11896
11897 @vindex $__@r{, convenience variable}
11898 @item $__
11899 The variable @code{$__} is automatically set by the @code{x} command
11900 to the value found in the last address examined. Its type is chosen
11901 to match the format in which the data was printed.
11902
11903 @item $_exitcode
11904 @vindex $_exitcode@r{, convenience variable}
11905 When the program being debugged terminates normally, @value{GDBN}
11906 automatically sets this variable to the exit code of the program, and
11907 resets @code{$_exitsignal} to @code{void}.
11908
11909 @item $_exitsignal
11910 @vindex $_exitsignal@r{, convenience variable}
11911 When the program being debugged dies due to an uncaught signal,
11912 @value{GDBN} automatically sets this variable to that signal's number,
11913 and resets @code{$_exitcode} to @code{void}.
11914
11915 To distinguish between whether the program being debugged has exited
11916 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
11917 @code{$_exitsignal} is not @code{void}), the convenience function
11918 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
11919 Functions}). For example, considering the following source code:
11920
11921 @smallexample
11922 #include <signal.h>
11923
11924 int
11925 main (int argc, char *argv[])
11926 @{
11927 raise (SIGALRM);
11928 return 0;
11929 @}
11930 @end smallexample
11931
11932 A valid way of telling whether the program being debugged has exited
11933 or signalled would be:
11934
11935 @smallexample
11936 (@value{GDBP}) define has_exited_or_signalled
11937 Type commands for definition of ``has_exited_or_signalled''.
11938 End with a line saying just ``end''.
11939 >if $_isvoid ($_exitsignal)
11940 >echo The program has exited\n
11941 >else
11942 >echo The program has signalled\n
11943 >end
11944 >end
11945 (@value{GDBP}) run
11946 Starting program:
11947
11948 Program terminated with signal SIGALRM, Alarm clock.
11949 The program no longer exists.
11950 (@value{GDBP}) has_exited_or_signalled
11951 The program has signalled
11952 @end smallexample
11953
11954 As can be seen, @value{GDBN} correctly informs that the program being
11955 debugged has signalled, since it calls @code{raise} and raises a
11956 @code{SIGALRM} signal. If the program being debugged had not called
11957 @code{raise}, then @value{GDBN} would report a normal exit:
11958
11959 @smallexample
11960 (@value{GDBP}) has_exited_or_signalled
11961 The program has exited
11962 @end smallexample
11963
11964 @item $_exception
11965 The variable @code{$_exception} is set to the exception object being
11966 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
11967
11968 @item $_ada_exception
11969 The variable @code{$_ada_exception} is set to the address of the
11970 exception being caught or thrown at an Ada exception-related
11971 catchpoint. @xref{Set Catchpoints}.
11972
11973 @item $_probe_argc
11974 @itemx $_probe_arg0@dots{}$_probe_arg11
11975 Arguments to a static probe. @xref{Static Probe Points}.
11976
11977 @item $_sdata
11978 @vindex $_sdata@r{, inspect, convenience variable}
11979 The variable @code{$_sdata} contains extra collected static tracepoint
11980 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
11981 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
11982 if extra static tracepoint data has not been collected.
11983
11984 @item $_siginfo
11985 @vindex $_siginfo@r{, convenience variable}
11986 The variable @code{$_siginfo} contains extra signal information
11987 (@pxref{extra signal information}). Note that @code{$_siginfo}
11988 could be empty, if the application has not yet received any signals.
11989 For example, it will be empty before you execute the @code{run} command.
11990
11991 @item $_tlb
11992 @vindex $_tlb@r{, convenience variable}
11993 The variable @code{$_tlb} is automatically set when debugging
11994 applications running on MS-Windows in native mode or connected to
11995 gdbserver that supports the @code{qGetTIBAddr} request.
11996 @xref{General Query Packets}.
11997 This variable contains the address of the thread information block.
11998
11999 @item $_inferior
12000 The number of the current inferior. @xref{Inferiors Connections and
12001 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12002
12003 @item $_thread
12004 The thread number of the current thread. @xref{thread numbers}.
12005
12006 @item $_gthread
12007 The global number of the current thread. @xref{global thread numbers}.
12008
12009 @item $_gdb_major
12010 @itemx $_gdb_minor
12011 @vindex $_gdb_major@r{, convenience variable}
12012 @vindex $_gdb_minor@r{, convenience variable}
12013 The major and minor version numbers of the running @value{GDBN}.
12014 Development snapshots and pretest versions have their minor version
12015 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12016 the value 12 for @code{$_gdb_minor}. These variables allow you to
12017 write scripts that work with different versions of @value{GDBN}
12018 without errors caused by features unavailable in some of those
12019 versions.
12020
12021 @item $_shell_exitcode
12022 @itemx $_shell_exitsignal
12023 @vindex $_shell_exitcode@r{, convenience variable}
12024 @vindex $_shell_exitsignal@r{, convenience variable}
12025 @cindex shell command, exit code
12026 @cindex shell command, exit signal
12027 @cindex exit status of shell commands
12028 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12029 shell commands. When a launched command terminates, @value{GDBN}
12030 automatically maintains the variables @code{$_shell_exitcode}
12031 and @code{$_shell_exitsignal} according to the exit status of the last
12032 launched command. These variables are set and used similarly to
12033 the variables @code{$_exitcode} and @code{$_exitsignal}.
12034
12035 @end table
12036
12037 @node Convenience Funs
12038 @section Convenience Functions
12039
12040 @cindex convenience functions
12041 @value{GDBN} also supplies some @dfn{convenience functions}. These
12042 have a syntax similar to convenience variables. A convenience
12043 function can be used in an expression just like an ordinary function;
12044 however, a convenience function is implemented internally to
12045 @value{GDBN}.
12046
12047 These functions do not require @value{GDBN} to be configured with
12048 @code{Python} support, which means that they are always available.
12049
12050 @table @code
12051
12052 @item $_isvoid (@var{expr})
12053 @findex $_isvoid@r{, convenience function}
12054 Return one if the expression @var{expr} is @code{void}. Otherwise it
12055 returns zero.
12056
12057 A @code{void} expression is an expression where the type of the result
12058 is @code{void}. For example, you can examine a convenience variable
12059 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12060 it is @code{void}:
12061
12062 @smallexample
12063 (@value{GDBP}) print $_exitcode
12064 $1 = void
12065 (@value{GDBP}) print $_isvoid ($_exitcode)
12066 $2 = 1
12067 (@value{GDBP}) run
12068 Starting program: ./a.out
12069 [Inferior 1 (process 29572) exited normally]
12070 (@value{GDBP}) print $_exitcode
12071 $3 = 0
12072 (@value{GDBP}) print $_isvoid ($_exitcode)
12073 $4 = 0
12074 @end smallexample
12075
12076 In the example above, we used @code{$_isvoid} to check whether
12077 @code{$_exitcode} is @code{void} before and after the execution of the
12078 program being debugged. Before the execution there is no exit code to
12079 be examined, therefore @code{$_exitcode} is @code{void}. After the
12080 execution the program being debugged returned zero, therefore
12081 @code{$_exitcode} is zero, which means that it is not @code{void}
12082 anymore.
12083
12084 The @code{void} expression can also be a call of a function from the
12085 program being debugged. For example, given the following function:
12086
12087 @smallexample
12088 void
12089 foo (void)
12090 @{
12091 @}
12092 @end smallexample
12093
12094 The result of calling it inside @value{GDBN} is @code{void}:
12095
12096 @smallexample
12097 (@value{GDBP}) print foo ()
12098 $1 = void
12099 (@value{GDBP}) print $_isvoid (foo ())
12100 $2 = 1
12101 (@value{GDBP}) set $v = foo ()
12102 (@value{GDBP}) print $v
12103 $3 = void
12104 (@value{GDBP}) print $_isvoid ($v)
12105 $4 = 1
12106 @end smallexample
12107
12108 @item $_gdb_setting_str (@var{setting})
12109 @findex $_gdb_setting_str@r{, convenience function}
12110 Return the value of the @value{GDBN} @var{setting} as a string.
12111 @var{setting} is any setting that can be used in a @code{set} or
12112 @code{show} command (@pxref{Controlling GDB}).
12113
12114 @smallexample
12115 (@value{GDBP}) show print frame-arguments
12116 Printing of non-scalar frame arguments is "scalars".
12117 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12118 $1 = "scalars"
12119 (@value{GDBP}) p $_gdb_setting_str("height")
12120 $2 = "30"
12121 (@value{GDBP})
12122 @end smallexample
12123
12124 @item $_gdb_setting (@var{setting})
12125 @findex $_gdb_setting@r{, convenience function}
12126 Return the value of the @value{GDBN} @var{setting}.
12127 The type of the returned value depends on the setting.
12128
12129 The value type for boolean and auto boolean settings is @code{int}.
12130 The boolean values @code{off} and @code{on} are converted to
12131 the integer values @code{0} and @code{1}. The value @code{auto} is
12132 converted to the value @code{-1}.
12133
12134 The value type for integer settings is either @code{unsigned int}
12135 or @code{int}, depending on the setting.
12136
12137 Some integer settings accept an @code{unlimited} value.
12138 Depending on the setting, the @code{set} command also accepts
12139 the value @code{0} or the value @code{@minus{}1} as a synonym for
12140 @code{unlimited}.
12141 For example, @code{set height unlimited} is equivalent to
12142 @code{set height 0}.
12143
12144 Some other settings that accept the @code{unlimited} value
12145 use the value @code{0} to literally mean zero.
12146 For example, @code{set history size 0} indicates to not
12147 record any @value{GDBN} commands in the command history.
12148 For such settings, @code{@minus{}1} is the synonym
12149 for @code{unlimited}.
12150
12151 See the documentation of the corresponding @code{set} command for
12152 the numerical value equivalent to @code{unlimited}.
12153
12154 The @code{$_gdb_setting} function converts the unlimited value
12155 to a @code{0} or a @code{@minus{}1} value according to what the
12156 @code{set} command uses.
12157
12158 @smallexample
12159 @group
12160 (@value{GDBP}) p $_gdb_setting_str("height")
12161 $1 = "30"
12162 (@value{GDBP}) p $_gdb_setting("height")
12163 $2 = 30
12164 (@value{GDBP}) set height unlimited
12165 (@value{GDBP}) p $_gdb_setting_str("height")
12166 $3 = "unlimited"
12167 (@value{GDBP}) p $_gdb_setting("height")
12168 $4 = 0
12169 @end group
12170 @group
12171 (@value{GDBP}) p $_gdb_setting_str("history size")
12172 $5 = "unlimited"
12173 (@value{GDBP}) p $_gdb_setting("history size")
12174 $6 = -1
12175 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12176 $7 = "auto"
12177 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12178 $8 = -1
12179 (@value{GDBP})
12180 @end group
12181 @end smallexample
12182
12183 Other setting types (enum, filename, optional filename, string, string noescape)
12184 are returned as string values.
12185
12186
12187 @item $_gdb_maint_setting_str (@var{setting})
12188 @findex $_gdb_maint_setting_str@r{, convenience function}
12189 Like the @code{$_gdb_setting_str} function, but works with
12190 @code{maintenance set} variables.
12191
12192 @item $_gdb_maint_setting (@var{setting})
12193 @findex $_gdb_maint_setting@r{, convenience function}
12194 Like the @code{$_gdb_setting} function, but works with
12195 @code{maintenance set} variables.
12196
12197 @end table
12198
12199 The following functions require @value{GDBN} to be configured with
12200 @code{Python} support.
12201
12202 @table @code
12203
12204 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12205 @findex $_memeq@r{, convenience function}
12206 Returns one if the @var{length} bytes at the addresses given by
12207 @var{buf1} and @var{buf2} are equal.
12208 Otherwise it returns zero.
12209
12210 @item $_regex(@var{str}, @var{regex})
12211 @findex $_regex@r{, convenience function}
12212 Returns one if the string @var{str} matches the regular expression
12213 @var{regex}. Otherwise it returns zero.
12214 The syntax of the regular expression is that specified by @code{Python}'s
12215 regular expression support.
12216
12217 @item $_streq(@var{str1}, @var{str2})
12218 @findex $_streq@r{, convenience function}
12219 Returns one if the strings @var{str1} and @var{str2} are equal.
12220 Otherwise it returns zero.
12221
12222 @item $_strlen(@var{str})
12223 @findex $_strlen@r{, convenience function}
12224 Returns the length of string @var{str}.
12225
12226 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12227 @findex $_caller_is@r{, convenience function}
12228 Returns one if the calling function's name is equal to @var{name}.
12229 Otherwise it returns zero.
12230
12231 If the optional argument @var{number_of_frames} is provided,
12232 it is the number of frames up in the stack to look.
12233 The default is 1.
12234
12235 Example:
12236
12237 @smallexample
12238 (gdb) backtrace
12239 #0 bottom_func ()
12240 at testsuite/gdb.python/py-caller-is.c:21
12241 #1 0x00000000004005a0 in middle_func ()
12242 at testsuite/gdb.python/py-caller-is.c:27
12243 #2 0x00000000004005ab in top_func ()
12244 at testsuite/gdb.python/py-caller-is.c:33
12245 #3 0x00000000004005b6 in main ()
12246 at testsuite/gdb.python/py-caller-is.c:39
12247 (gdb) print $_caller_is ("middle_func")
12248 $1 = 1
12249 (gdb) print $_caller_is ("top_func", 2)
12250 $1 = 1
12251 @end smallexample
12252
12253 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12254 @findex $_caller_matches@r{, convenience function}
12255 Returns one if the calling function's name matches the regular expression
12256 @var{regexp}. Otherwise it returns zero.
12257
12258 If the optional argument @var{number_of_frames} is provided,
12259 it is the number of frames up in the stack to look.
12260 The default is 1.
12261
12262 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12263 @findex $_any_caller_is@r{, convenience function}
12264 Returns one if any calling function's name is equal to @var{name}.
12265 Otherwise it returns zero.
12266
12267 If the optional argument @var{number_of_frames} is provided,
12268 it is the number of frames up in the stack to look.
12269 The default is 1.
12270
12271 This function differs from @code{$_caller_is} in that this function
12272 checks all stack frames from the immediate caller to the frame specified
12273 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12274 frame specified by @var{number_of_frames}.
12275
12276 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12277 @findex $_any_caller_matches@r{, convenience function}
12278 Returns one if any calling function's name matches the regular expression
12279 @var{regexp}. Otherwise it returns zero.
12280
12281 If the optional argument @var{number_of_frames} is provided,
12282 it is the number of frames up in the stack to look.
12283 The default is 1.
12284
12285 This function differs from @code{$_caller_matches} in that this function
12286 checks all stack frames from the immediate caller to the frame specified
12287 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12288 frame specified by @var{number_of_frames}.
12289
12290 @item $_as_string(@var{value})
12291 @findex $_as_string@r{, convenience function}
12292 Return the string representation of @var{value}.
12293
12294 This function is useful to obtain the textual label (enumerator) of an
12295 enumeration value. For example, assuming the variable @var{node} is of
12296 an enumerated type:
12297
12298 @smallexample
12299 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12300 Visiting node of type NODE_INTEGER
12301 @end smallexample
12302
12303 @item $_cimag(@var{value})
12304 @itemx $_creal(@var{value})
12305 @findex $_cimag@r{, convenience function}
12306 @findex $_creal@r{, convenience function}
12307 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12308 the complex number @var{value}.
12309
12310 The type of the imaginary or real part depends on the type of the
12311 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12312 will return an imaginary part of type @code{float}.
12313
12314 @end table
12315
12316 @value{GDBN} provides the ability to list and get help on
12317 convenience functions.
12318
12319 @table @code
12320 @item help function
12321 @kindex help function
12322 @cindex show all convenience functions
12323 Print a list of all convenience functions.
12324 @end table
12325
12326 @node Registers
12327 @section Registers
12328
12329 @cindex registers
12330 You can refer to machine register contents, in expressions, as variables
12331 with names starting with @samp{$}. The names of registers are different
12332 for each machine; use @code{info registers} to see the names used on
12333 your machine.
12334
12335 @table @code
12336 @kindex info registers
12337 @item info registers
12338 Print the names and values of all registers except floating-point
12339 and vector registers (in the selected stack frame).
12340
12341 @kindex info all-registers
12342 @cindex floating point registers
12343 @item info all-registers
12344 Print the names and values of all registers, including floating-point
12345 and vector registers (in the selected stack frame).
12346
12347 @item info registers @var{reggroup} @dots{}
12348 Print the name and value of the registers in each of the specified
12349 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12350 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12351
12352 @item info registers @var{regname} @dots{}
12353 Print the @dfn{relativized} value of each specified register @var{regname}.
12354 As discussed in detail below, register values are normally relative to
12355 the selected stack frame. The @var{regname} may be any register name valid on
12356 the machine you are using, with or without the initial @samp{$}.
12357 @end table
12358
12359 @anchor{standard registers}
12360 @cindex stack pointer register
12361 @cindex program counter register
12362 @cindex process status register
12363 @cindex frame pointer register
12364 @cindex standard registers
12365 @value{GDBN} has four ``standard'' register names that are available (in
12366 expressions) on most machines---whenever they do not conflict with an
12367 architecture's canonical mnemonics for registers. The register names
12368 @code{$pc} and @code{$sp} are used for the program counter register and
12369 the stack pointer. @code{$fp} is used for a register that contains a
12370 pointer to the current stack frame, and @code{$ps} is used for a
12371 register that contains the processor status. For example,
12372 you could print the program counter in hex with
12373
12374 @smallexample
12375 p/x $pc
12376 @end smallexample
12377
12378 @noindent
12379 or print the instruction to be executed next with
12380
12381 @smallexample
12382 x/i $pc
12383 @end smallexample
12384
12385 @noindent
12386 or add four to the stack pointer@footnote{This is a way of removing
12387 one word from the stack, on machines where stacks grow downward in
12388 memory (most machines, nowadays). This assumes that the innermost
12389 stack frame is selected; setting @code{$sp} is not allowed when other
12390 stack frames are selected. To pop entire frames off the stack,
12391 regardless of machine architecture, use @code{return};
12392 see @ref{Returning, ,Returning from a Function}.} with
12393
12394 @smallexample
12395 set $sp += 4
12396 @end smallexample
12397
12398 Whenever possible, these four standard register names are available on
12399 your machine even though the machine has different canonical mnemonics,
12400 so long as there is no conflict. The @code{info registers} command
12401 shows the canonical names. For example, on the SPARC, @code{info
12402 registers} displays the processor status register as @code{$psr} but you
12403 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12404 is an alias for the @sc{eflags} register.
12405
12406 @value{GDBN} always considers the contents of an ordinary register as an
12407 integer when the register is examined in this way. Some machines have
12408 special registers which can hold nothing but floating point; these
12409 registers are considered to have floating point values. There is no way
12410 to refer to the contents of an ordinary register as floating point value
12411 (although you can @emph{print} it as a floating point value with
12412 @samp{print/f $@var{regname}}).
12413
12414 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12415 means that the data format in which the register contents are saved by
12416 the operating system is not the same one that your program normally
12417 sees. For example, the registers of the 68881 floating point
12418 coprocessor are always saved in ``extended'' (raw) format, but all C
12419 programs expect to work with ``double'' (virtual) format. In such
12420 cases, @value{GDBN} normally works with the virtual format only (the format
12421 that makes sense for your program), but the @code{info registers} command
12422 prints the data in both formats.
12423
12424 @cindex SSE registers (x86)
12425 @cindex MMX registers (x86)
12426 Some machines have special registers whose contents can be interpreted
12427 in several different ways. For example, modern x86-based machines
12428 have SSE and MMX registers that can hold several values packed
12429 together in several different formats. @value{GDBN} refers to such
12430 registers in @code{struct} notation:
12431
12432 @smallexample
12433 (@value{GDBP}) print $xmm1
12434 $1 = @{
12435 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12436 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12437 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12438 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12439 v4_int32 = @{0, 20657912, 11, 13@},
12440 v2_int64 = @{88725056443645952, 55834574859@},
12441 uint128 = 0x0000000d0000000b013b36f800000000
12442 @}
12443 @end smallexample
12444
12445 @noindent
12446 To set values of such registers, you need to tell @value{GDBN} which
12447 view of the register you wish to change, as if you were assigning
12448 value to a @code{struct} member:
12449
12450 @smallexample
12451 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12452 @end smallexample
12453
12454 Normally, register values are relative to the selected stack frame
12455 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12456 value that the register would contain if all stack frames farther in
12457 were exited and their saved registers restored. In order to see the
12458 true contents of hardware registers, you must select the innermost
12459 frame (with @samp{frame 0}).
12460
12461 @cindex caller-saved registers
12462 @cindex call-clobbered registers
12463 @cindex volatile registers
12464 @cindex <not saved> values
12465 Usually ABIs reserve some registers as not needed to be saved by the
12466 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12467 registers). It may therefore not be possible for @value{GDBN} to know
12468 the value a register had before the call (in other words, in the outer
12469 frame), if the register value has since been changed by the callee.
12470 @value{GDBN} tries to deduce where the inner frame saved
12471 (``callee-saved'') registers, from the debug info, unwind info, or the
12472 machine code generated by your compiler. If some register is not
12473 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12474 its own knowledge of the ABI, or because the debug/unwind info
12475 explicitly says the register's value is undefined), @value{GDBN}
12476 displays @w{@samp{<not saved>}} as the register's value. With targets
12477 that @value{GDBN} has no knowledge of the register saving convention,
12478 if a register was not saved by the callee, then its value and location
12479 in the outer frame are assumed to be the same of the inner frame.
12480 This is usually harmless, because if the register is call-clobbered,
12481 the caller either does not care what is in the register after the
12482 call, or has code to restore the value that it does care about. Note,
12483 however, that if you change such a register in the outer frame, you
12484 may also be affecting the inner frame. Also, the more ``outer'' the
12485 frame is you're looking at, the more likely a call-clobbered
12486 register's value is to be wrong, in the sense that it doesn't actually
12487 represent the value the register had just before the call.
12488
12489 @node Floating Point Hardware
12490 @section Floating Point Hardware
12491 @cindex floating point
12492
12493 Depending on the configuration, @value{GDBN} may be able to give
12494 you more information about the status of the floating point hardware.
12495
12496 @table @code
12497 @kindex info float
12498 @item info float
12499 Display hardware-dependent information about the floating
12500 point unit. The exact contents and layout vary depending on the
12501 floating point chip. Currently, @samp{info float} is supported on
12502 the ARM and x86 machines.
12503 @end table
12504
12505 @node Vector Unit
12506 @section Vector Unit
12507 @cindex vector unit
12508
12509 Depending on the configuration, @value{GDBN} may be able to give you
12510 more information about the status of the vector unit.
12511
12512 @table @code
12513 @kindex info vector
12514 @item info vector
12515 Display information about the vector unit. The exact contents and
12516 layout vary depending on the hardware.
12517 @end table
12518
12519 @node OS Information
12520 @section Operating System Auxiliary Information
12521 @cindex OS information
12522
12523 @value{GDBN} provides interfaces to useful OS facilities that can help
12524 you debug your program.
12525
12526 @cindex auxiliary vector
12527 @cindex vector, auxiliary
12528 Some operating systems supply an @dfn{auxiliary vector} to programs at
12529 startup. This is akin to the arguments and environment that you
12530 specify for a program, but contains a system-dependent variety of
12531 binary values that tell system libraries important details about the
12532 hardware, operating system, and process. Each value's purpose is
12533 identified by an integer tag; the meanings are well-known but system-specific.
12534 Depending on the configuration and operating system facilities,
12535 @value{GDBN} may be able to show you this information. For remote
12536 targets, this functionality may further depend on the remote stub's
12537 support of the @samp{qXfer:auxv:read} packet, see
12538 @ref{qXfer auxiliary vector read}.
12539
12540 @table @code
12541 @kindex info auxv
12542 @item info auxv
12543 Display the auxiliary vector of the inferior, which can be either a
12544 live process or a core dump file. @value{GDBN} prints each tag value
12545 numerically, and also shows names and text descriptions for recognized
12546 tags. Some values in the vector are numbers, some bit masks, and some
12547 pointers to strings or other data. @value{GDBN} displays each value in the
12548 most appropriate form for a recognized tag, and in hexadecimal for
12549 an unrecognized tag.
12550 @end table
12551
12552 On some targets, @value{GDBN} can access operating system-specific
12553 information and show it to you. The types of information available
12554 will differ depending on the type of operating system running on the
12555 target. The mechanism used to fetch the data is described in
12556 @ref{Operating System Information}. For remote targets, this
12557 functionality depends on the remote stub's support of the
12558 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12559
12560 @table @code
12561 @kindex info os
12562 @item info os @var{infotype}
12563
12564 Display OS information of the requested type.
12565
12566 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12567
12568 @anchor{linux info os infotypes}
12569 @table @code
12570 @kindex info os cpus
12571 @item cpus
12572 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12573 the available fields from /proc/cpuinfo. For each supported architecture
12574 different fields are available. Two common entries are processor which gives
12575 CPU number and bogomips; a system constant that is calculated during
12576 kernel initialization.
12577
12578 @kindex info os files
12579 @item files
12580 Display the list of open file descriptors on the target. For each
12581 file descriptor, @value{GDBN} prints the identifier of the process
12582 owning the descriptor, the command of the owning process, the value
12583 of the descriptor, and the target of the descriptor.
12584
12585 @kindex info os modules
12586 @item modules
12587 Display the list of all loaded kernel modules on the target. For each
12588 module, @value{GDBN} prints the module name, the size of the module in
12589 bytes, the number of times the module is used, the dependencies of the
12590 module, the status of the module, and the address of the loaded module
12591 in memory.
12592
12593 @kindex info os msg
12594 @item msg
12595 Display the list of all System V message queues on the target. For each
12596 message queue, @value{GDBN} prints the message queue key, the message
12597 queue identifier, the access permissions, the current number of bytes
12598 on the queue, the current number of messages on the queue, the processes
12599 that last sent and received a message on the queue, the user and group
12600 of the owner and creator of the message queue, the times at which a
12601 message was last sent and received on the queue, and the time at which
12602 the message queue was last changed.
12603
12604 @kindex info os processes
12605 @item processes
12606 Display the list of processes on the target. For each process,
12607 @value{GDBN} prints the process identifier, the name of the user, the
12608 command corresponding to the process, and the list of processor cores
12609 that the process is currently running on. (To understand what these
12610 properties mean, for this and the following info types, please consult
12611 the general @sc{gnu}/Linux documentation.)
12612
12613 @kindex info os procgroups
12614 @item procgroups
12615 Display the list of process groups on the target. For each process,
12616 @value{GDBN} prints the identifier of the process group that it belongs
12617 to, the command corresponding to the process group leader, the process
12618 identifier, and the command line of the process. The list is sorted
12619 first by the process group identifier, then by the process identifier,
12620 so that processes belonging to the same process group are grouped together
12621 and the process group leader is listed first.
12622
12623 @kindex info os semaphores
12624 @item semaphores
12625 Display the list of all System V semaphore sets on the target. For each
12626 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12627 set identifier, the access permissions, the number of semaphores in the
12628 set, the user and group of the owner and creator of the semaphore set,
12629 and the times at which the semaphore set was operated upon and changed.
12630
12631 @kindex info os shm
12632 @item shm
12633 Display the list of all System V shared-memory regions on the target.
12634 For each shared-memory region, @value{GDBN} prints the region key,
12635 the shared-memory identifier, the access permissions, the size of the
12636 region, the process that created the region, the process that last
12637 attached to or detached from the region, the current number of live
12638 attaches to the region, and the times at which the region was last
12639 attached to, detach from, and changed.
12640
12641 @kindex info os sockets
12642 @item sockets
12643 Display the list of Internet-domain sockets on the target. For each
12644 socket, @value{GDBN} prints the address and port of the local and
12645 remote endpoints, the current state of the connection, the creator of
12646 the socket, the IP address family of the socket, and the type of the
12647 connection.
12648
12649 @kindex info os threads
12650 @item threads
12651 Display the list of threads running on the target. For each thread,
12652 @value{GDBN} prints the identifier of the process that the thread
12653 belongs to, the command of the process, the thread identifier, and the
12654 processor core that it is currently running on. The main thread of a
12655 process is not listed.
12656 @end table
12657
12658 @item info os
12659 If @var{infotype} is omitted, then list the possible values for
12660 @var{infotype} and the kind of OS information available for each
12661 @var{infotype}. If the target does not return a list of possible
12662 types, this command will report an error.
12663 @end table
12664
12665 @node Memory Region Attributes
12666 @section Memory Region Attributes
12667 @cindex memory region attributes
12668
12669 @dfn{Memory region attributes} allow you to describe special handling
12670 required by regions of your target's memory. @value{GDBN} uses
12671 attributes to determine whether to allow certain types of memory
12672 accesses; whether to use specific width accesses; and whether to cache
12673 target memory. By default the description of memory regions is
12674 fetched from the target (if the current target supports this), but the
12675 user can override the fetched regions.
12676
12677 Defined memory regions can be individually enabled and disabled. When a
12678 memory region is disabled, @value{GDBN} uses the default attributes when
12679 accessing memory in that region. Similarly, if no memory regions have
12680 been defined, @value{GDBN} uses the default attributes when accessing
12681 all memory.
12682
12683 When a memory region is defined, it is given a number to identify it;
12684 to enable, disable, or remove a memory region, you specify that number.
12685
12686 @table @code
12687 @kindex mem
12688 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
12689 Define a memory region bounded by @var{lower} and @var{upper} with
12690 attributes @var{attributes}@dots{}, and add it to the list of regions
12691 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
12692 case: it is treated as the target's maximum memory address.
12693 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
12694
12695 @item mem auto
12696 Discard any user changes to the memory regions and use target-supplied
12697 regions, if available, or no regions if the target does not support.
12698
12699 @kindex delete mem
12700 @item delete mem @var{nums}@dots{}
12701 Remove memory regions @var{nums}@dots{} from the list of regions
12702 monitored by @value{GDBN}.
12703
12704 @kindex disable mem
12705 @item disable mem @var{nums}@dots{}
12706 Disable monitoring of memory regions @var{nums}@dots{}.
12707 A disabled memory region is not forgotten.
12708 It may be enabled again later.
12709
12710 @kindex enable mem
12711 @item enable mem @var{nums}@dots{}
12712 Enable monitoring of memory regions @var{nums}@dots{}.
12713
12714 @kindex info mem
12715 @item info mem
12716 Print a table of all defined memory regions, with the following columns
12717 for each region:
12718
12719 @table @emph
12720 @item Memory Region Number
12721 @item Enabled or Disabled.
12722 Enabled memory regions are marked with @samp{y}.
12723 Disabled memory regions are marked with @samp{n}.
12724
12725 @item Lo Address
12726 The address defining the inclusive lower bound of the memory region.
12727
12728 @item Hi Address
12729 The address defining the exclusive upper bound of the memory region.
12730
12731 @item Attributes
12732 The list of attributes set for this memory region.
12733 @end table
12734 @end table
12735
12736
12737 @subsection Attributes
12738
12739 @subsubsection Memory Access Mode
12740 The access mode attributes set whether @value{GDBN} may make read or
12741 write accesses to a memory region.
12742
12743 While these attributes prevent @value{GDBN} from performing invalid
12744 memory accesses, they do nothing to prevent the target system, I/O DMA,
12745 etc.@: from accessing memory.
12746
12747 @table @code
12748 @item ro
12749 Memory is read only.
12750 @item wo
12751 Memory is write only.
12752 @item rw
12753 Memory is read/write. This is the default.
12754 @end table
12755
12756 @subsubsection Memory Access Size
12757 The access size attribute tells @value{GDBN} to use specific sized
12758 accesses in the memory region. Often memory mapped device registers
12759 require specific sized accesses. If no access size attribute is
12760 specified, @value{GDBN} may use accesses of any size.
12761
12762 @table @code
12763 @item 8
12764 Use 8 bit memory accesses.
12765 @item 16
12766 Use 16 bit memory accesses.
12767 @item 32
12768 Use 32 bit memory accesses.
12769 @item 64
12770 Use 64 bit memory accesses.
12771 @end table
12772
12773 @c @subsubsection Hardware/Software Breakpoints
12774 @c The hardware/software breakpoint attributes set whether @value{GDBN}
12775 @c will use hardware or software breakpoints for the internal breakpoints
12776 @c used by the step, next, finish, until, etc. commands.
12777 @c
12778 @c @table @code
12779 @c @item hwbreak
12780 @c Always use hardware breakpoints
12781 @c @item swbreak (default)
12782 @c @end table
12783
12784 @subsubsection Data Cache
12785 The data cache attributes set whether @value{GDBN} will cache target
12786 memory. While this generally improves performance by reducing debug
12787 protocol overhead, it can lead to incorrect results because @value{GDBN}
12788 does not know about volatile variables or memory mapped device
12789 registers.
12790
12791 @table @code
12792 @item cache
12793 Enable @value{GDBN} to cache target memory.
12794 @item nocache
12795 Disable @value{GDBN} from caching target memory. This is the default.
12796 @end table
12797
12798 @subsection Memory Access Checking
12799 @value{GDBN} can be instructed to refuse accesses to memory that is
12800 not explicitly described. This can be useful if accessing such
12801 regions has undesired effects for a specific target, or to provide
12802 better error checking. The following commands control this behaviour.
12803
12804 @table @code
12805 @kindex set mem inaccessible-by-default
12806 @item set mem inaccessible-by-default [on|off]
12807 If @code{on} is specified, make @value{GDBN} treat memory not
12808 explicitly described by the memory ranges as non-existent and refuse accesses
12809 to such memory. The checks are only performed if there's at least one
12810 memory range defined. If @code{off} is specified, make @value{GDBN}
12811 treat the memory not explicitly described by the memory ranges as RAM.
12812 The default value is @code{on}.
12813 @kindex show mem inaccessible-by-default
12814 @item show mem inaccessible-by-default
12815 Show the current handling of accesses to unknown memory.
12816 @end table
12817
12818
12819 @c @subsubsection Memory Write Verification
12820 @c The memory write verification attributes set whether @value{GDBN}
12821 @c will re-reads data after each write to verify the write was successful.
12822 @c
12823 @c @table @code
12824 @c @item verify
12825 @c @item noverify (default)
12826 @c @end table
12827
12828 @node Dump/Restore Files
12829 @section Copy Between Memory and a File
12830 @cindex dump/restore files
12831 @cindex append data to a file
12832 @cindex dump data to a file
12833 @cindex restore data from a file
12834
12835 You can use the commands @code{dump}, @code{append}, and
12836 @code{restore} to copy data between target memory and a file. The
12837 @code{dump} and @code{append} commands write data to a file, and the
12838 @code{restore} command reads data from a file back into the inferior's
12839 memory. Files may be in binary, Motorola S-record, Intel hex,
12840 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12841 append to binary files, and cannot read from Verilog Hex files.
12842
12843 @table @code
12844
12845 @kindex dump
12846 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12847 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12848 Dump the contents of memory from @var{start_addr} to @var{end_addr},
12849 or the value of @var{expr}, to @var{filename} in the given format.
12850
12851 The @var{format} parameter may be any one of:
12852 @table @code
12853 @item binary
12854 Raw binary form.
12855 @item ihex
12856 Intel hex format.
12857 @item srec
12858 Motorola S-record format.
12859 @item tekhex
12860 Tektronix Hex format.
12861 @item verilog
12862 Verilog Hex format.
12863 @end table
12864
12865 @value{GDBN} uses the same definitions of these formats as the
12866 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12867 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
12868 form.
12869
12870 @kindex append
12871 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12872 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12873 Append the contents of memory from @var{start_addr} to @var{end_addr},
12874 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
12875 (@value{GDBN} can only append data to files in raw binary form.)
12876
12877 @kindex restore
12878 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12879 Restore the contents of file @var{filename} into memory. The
12880 @code{restore} command can automatically recognize any known @sc{bfd}
12881 file format, except for raw binary. To restore a raw binary file you
12882 must specify the optional keyword @code{binary} after the filename.
12883
12884 If @var{bias} is non-zero, its value will be added to the addresses
12885 contained in the file. Binary files always start at address zero, so
12886 they will be restored at address @var{bias}. Other bfd files have
12887 a built-in location; they will be restored at offset @var{bias}
12888 from that location.
12889
12890 If @var{start} and/or @var{end} are non-zero, then only data between
12891 file offset @var{start} and file offset @var{end} will be restored.
12892 These offsets are relative to the addresses in the file, before
12893 the @var{bias} argument is applied.
12894
12895 @end table
12896
12897 @node Core File Generation
12898 @section How to Produce a Core File from Your Program
12899 @cindex dump core from inferior
12900
12901 A @dfn{core file} or @dfn{core dump} is a file that records the memory
12902 image of a running process and its process status (register values
12903 etc.). Its primary use is post-mortem debugging of a program that
12904 crashed while it ran outside a debugger. A program that crashes
12905 automatically produces a core file, unless this feature is disabled by
12906 the user. @xref{Files}, for information on invoking @value{GDBN} in
12907 the post-mortem debugging mode.
12908
12909 Occasionally, you may wish to produce a core file of the program you
12910 are debugging in order to preserve a snapshot of its state.
12911 @value{GDBN} has a special command for that.
12912
12913 @table @code
12914 @kindex gcore
12915 @kindex generate-core-file
12916 @item generate-core-file [@var{file}]
12917 @itemx gcore [@var{file}]
12918 Produce a core dump of the inferior process. The optional argument
12919 @var{file} specifies the file name where to put the core dump. If not
12920 specified, the file name defaults to @file{core.@var{pid}}, where
12921 @var{pid} is the inferior process ID.
12922
12923 Note that this command is implemented only for some systems (as of
12924 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
12925
12926 On @sc{gnu}/Linux, this command can take into account the value of the
12927 file @file{/proc/@var{pid}/coredump_filter} when generating the core
12928 dump (@pxref{set use-coredump-filter}), and by default honors the
12929 @code{VM_DONTDUMP} flag for mappings where it is present in the file
12930 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
12931
12932 @kindex set use-coredump-filter
12933 @anchor{set use-coredump-filter}
12934 @item set use-coredump-filter on
12935 @itemx set use-coredump-filter off
12936 Enable or disable the use of the file
12937 @file{/proc/@var{pid}/coredump_filter} when generating core dump
12938 files. This file is used by the Linux kernel to decide what types of
12939 memory mappings will be dumped or ignored when generating a core dump
12940 file. @var{pid} is the process ID of a currently running process.
12941
12942 To make use of this feature, you have to write in the
12943 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
12944 which is a bit mask representing the memory mapping types. If a bit
12945 is set in the bit mask, then the memory mappings of the corresponding
12946 types will be dumped; otherwise, they will be ignored. This
12947 configuration is inherited by child processes. For more information
12948 about the bits that can be set in the
12949 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
12950 manpage of @code{core(5)}.
12951
12952 By default, this option is @code{on}. If this option is turned
12953 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
12954 and instead uses the same default value as the Linux kernel in order
12955 to decide which pages will be dumped in the core dump file. This
12956 value is currently @code{0x33}, which means that bits @code{0}
12957 (anonymous private mappings), @code{1} (anonymous shared mappings),
12958 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
12959 This will cause these memory mappings to be dumped automatically.
12960
12961 @kindex set dump-excluded-mappings
12962 @anchor{set dump-excluded-mappings}
12963 @item set dump-excluded-mappings on
12964 @itemx set dump-excluded-mappings off
12965 If @code{on} is specified, @value{GDBN} will dump memory mappings
12966 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
12967 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
12968
12969 The default value is @code{off}.
12970 @end table
12971
12972 @node Character Sets
12973 @section Character Sets
12974 @cindex character sets
12975 @cindex charset
12976 @cindex translating between character sets
12977 @cindex host character set
12978 @cindex target character set
12979
12980 If the program you are debugging uses a different character set to
12981 represent characters and strings than the one @value{GDBN} uses itself,
12982 @value{GDBN} can automatically translate between the character sets for
12983 you. The character set @value{GDBN} uses we call the @dfn{host
12984 character set}; the one the inferior program uses we call the
12985 @dfn{target character set}.
12986
12987 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
12988 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
12989 remote protocol (@pxref{Remote Debugging}) to debug a program
12990 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
12991 then the host character set is Latin-1, and the target character set is
12992 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
12993 target-charset EBCDIC-US}, then @value{GDBN} translates between
12994 @sc{ebcdic} and Latin 1 as you print character or string values, or use
12995 character and string literals in expressions.
12996
12997 @value{GDBN} has no way to automatically recognize which character set
12998 the inferior program uses; you must tell it, using the @code{set
12999 target-charset} command, described below.
13000
13001 Here are the commands for controlling @value{GDBN}'s character set
13002 support:
13003
13004 @table @code
13005 @item set target-charset @var{charset}
13006 @kindex set target-charset
13007 Set the current target character set to @var{charset}. To display the
13008 list of supported target character sets, type
13009 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13010
13011 @item set host-charset @var{charset}
13012 @kindex set host-charset
13013 Set the current host character set to @var{charset}.
13014
13015 By default, @value{GDBN} uses a host character set appropriate to the
13016 system it is running on; you can override that default using the
13017 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13018 automatically determine the appropriate host character set. In this
13019 case, @value{GDBN} uses @samp{UTF-8}.
13020
13021 @value{GDBN} can only use certain character sets as its host character
13022 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13023 @value{GDBN} will list the host character sets it supports.
13024
13025 @item set charset @var{charset}
13026 @kindex set charset
13027 Set the current host and target character sets to @var{charset}. As
13028 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13029 @value{GDBN} will list the names of the character sets that can be used
13030 for both host and target.
13031
13032 @item show charset
13033 @kindex show charset
13034 Show the names of the current host and target character sets.
13035
13036 @item show host-charset
13037 @kindex show host-charset
13038 Show the name of the current host character set.
13039
13040 @item show target-charset
13041 @kindex show target-charset
13042 Show the name of the current target character set.
13043
13044 @item set target-wide-charset @var{charset}
13045 @kindex set target-wide-charset
13046 Set the current target's wide character set to @var{charset}. This is
13047 the character set used by the target's @code{wchar_t} type. To
13048 display the list of supported wide character sets, type
13049 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13050
13051 @item show target-wide-charset
13052 @kindex show target-wide-charset
13053 Show the name of the current target's wide character set.
13054 @end table
13055
13056 Here is an example of @value{GDBN}'s character set support in action.
13057 Assume that the following source code has been placed in the file
13058 @file{charset-test.c}:
13059
13060 @smallexample
13061 #include <stdio.h>
13062
13063 char ascii_hello[]
13064 = @{72, 101, 108, 108, 111, 44, 32, 119,
13065 111, 114, 108, 100, 33, 10, 0@};
13066 char ibm1047_hello[]
13067 = @{200, 133, 147, 147, 150, 107, 64, 166,
13068 150, 153, 147, 132, 90, 37, 0@};
13069
13070 main ()
13071 @{
13072 printf ("Hello, world!\n");
13073 @}
13074 @end smallexample
13075
13076 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13077 containing the string @samp{Hello, world!} followed by a newline,
13078 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13079
13080 We compile the program, and invoke the debugger on it:
13081
13082 @smallexample
13083 $ gcc -g charset-test.c -o charset-test
13084 $ gdb -nw charset-test
13085 GNU gdb 2001-12-19-cvs
13086 Copyright 2001 Free Software Foundation, Inc.
13087 @dots{}
13088 (@value{GDBP})
13089 @end smallexample
13090
13091 We can use the @code{show charset} command to see what character sets
13092 @value{GDBN} is currently using to interpret and display characters and
13093 strings:
13094
13095 @smallexample
13096 (@value{GDBP}) show charset
13097 The current host and target character set is `ISO-8859-1'.
13098 (@value{GDBP})
13099 @end smallexample
13100
13101 For the sake of printing this manual, let's use @sc{ascii} as our
13102 initial character set:
13103 @smallexample
13104 (@value{GDBP}) set charset ASCII
13105 (@value{GDBP}) show charset
13106 The current host and target character set is `ASCII'.
13107 (@value{GDBP})
13108 @end smallexample
13109
13110 Let's assume that @sc{ascii} is indeed the correct character set for our
13111 host system --- in other words, let's assume that if @value{GDBN} prints
13112 characters using the @sc{ascii} character set, our terminal will display
13113 them properly. Since our current target character set is also
13114 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13115
13116 @smallexample
13117 (@value{GDBP}) print ascii_hello
13118 $1 = 0x401698 "Hello, world!\n"
13119 (@value{GDBP}) print ascii_hello[0]
13120 $2 = 72 'H'
13121 (@value{GDBP})
13122 @end smallexample
13123
13124 @value{GDBN} uses the target character set for character and string
13125 literals you use in expressions:
13126
13127 @smallexample
13128 (@value{GDBP}) print '+'
13129 $3 = 43 '+'
13130 (@value{GDBP})
13131 @end smallexample
13132
13133 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13134 character.
13135
13136 @value{GDBN} relies on the user to tell it which character set the
13137 target program uses. If we print @code{ibm1047_hello} while our target
13138 character set is still @sc{ascii}, we get jibberish:
13139
13140 @smallexample
13141 (@value{GDBP}) print ibm1047_hello
13142 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13143 (@value{GDBP}) print ibm1047_hello[0]
13144 $5 = 200 '\310'
13145 (@value{GDBP})
13146 @end smallexample
13147
13148 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13149 @value{GDBN} tells us the character sets it supports:
13150
13151 @smallexample
13152 (@value{GDBP}) set target-charset
13153 ASCII EBCDIC-US IBM1047 ISO-8859-1
13154 (@value{GDBP}) set target-charset
13155 @end smallexample
13156
13157 We can select @sc{ibm1047} as our target character set, and examine the
13158 program's strings again. Now the @sc{ascii} string is wrong, but
13159 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13160 target character set, @sc{ibm1047}, to the host character set,
13161 @sc{ascii}, and they display correctly:
13162
13163 @smallexample
13164 (@value{GDBP}) set target-charset IBM1047
13165 (@value{GDBP}) show charset
13166 The current host character set is `ASCII'.
13167 The current target character set is `IBM1047'.
13168 (@value{GDBP}) print ascii_hello
13169 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13170 (@value{GDBP}) print ascii_hello[0]
13171 $7 = 72 '\110'
13172 (@value{GDBP}) print ibm1047_hello
13173 $8 = 0x4016a8 "Hello, world!\n"
13174 (@value{GDBP}) print ibm1047_hello[0]
13175 $9 = 200 'H'
13176 (@value{GDBP})
13177 @end smallexample
13178
13179 As above, @value{GDBN} uses the target character set for character and
13180 string literals you use in expressions:
13181
13182 @smallexample
13183 (@value{GDBP}) print '+'
13184 $10 = 78 '+'
13185 (@value{GDBP})
13186 @end smallexample
13187
13188 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13189 character.
13190
13191 @node Caching Target Data
13192 @section Caching Data of Targets
13193 @cindex caching data of targets
13194
13195 @value{GDBN} caches data exchanged between the debugger and a target.
13196 Each cache is associated with the address space of the inferior.
13197 @xref{Inferiors Connections and Programs}, about inferior and address space.
13198 Such caching generally improves performance in remote debugging
13199 (@pxref{Remote Debugging}), because it reduces the overhead of the
13200 remote protocol by bundling memory reads and writes into large chunks.
13201 Unfortunately, simply caching everything would lead to incorrect results,
13202 since @value{GDBN} does not necessarily know anything about volatile
13203 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13204 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13205 is executing.
13206 Therefore, by default, @value{GDBN} only caches data
13207 known to be on the stack@footnote{In non-stop mode, it is moderately
13208 rare for a running thread to modify the stack of a stopped thread
13209 in a way that would interfere with a backtrace, and caching of
13210 stack reads provides a significant speed up of remote backtraces.} or
13211 in the code segment.
13212 Other regions of memory can be explicitly marked as
13213 cacheable; @pxref{Memory Region Attributes}.
13214
13215 @table @code
13216 @kindex set remotecache
13217 @item set remotecache on
13218 @itemx set remotecache off
13219 This option no longer does anything; it exists for compatibility
13220 with old scripts.
13221
13222 @kindex show remotecache
13223 @item show remotecache
13224 Show the current state of the obsolete remotecache flag.
13225
13226 @kindex set stack-cache
13227 @item set stack-cache on
13228 @itemx set stack-cache off
13229 Enable or disable caching of stack accesses. When @code{on}, use
13230 caching. By default, this option is @code{on}.
13231
13232 @kindex show stack-cache
13233 @item show stack-cache
13234 Show the current state of data caching for memory accesses.
13235
13236 @kindex set code-cache
13237 @item set code-cache on
13238 @itemx set code-cache off
13239 Enable or disable caching of code segment accesses. When @code{on},
13240 use caching. By default, this option is @code{on}. This improves
13241 performance of disassembly in remote debugging.
13242
13243 @kindex show code-cache
13244 @item show code-cache
13245 Show the current state of target memory cache for code segment
13246 accesses.
13247
13248 @kindex info dcache
13249 @item info dcache @r{[}line@r{]}
13250 Print the information about the performance of data cache of the
13251 current inferior's address space. The information displayed
13252 includes the dcache width and depth, and for each cache line, its
13253 number, address, and how many times it was referenced. This
13254 command is useful for debugging the data cache operation.
13255
13256 If a line number is specified, the contents of that line will be
13257 printed in hex.
13258
13259 @item set dcache size @var{size}
13260 @cindex dcache size
13261 @kindex set dcache size
13262 Set maximum number of entries in dcache (dcache depth above).
13263
13264 @item set dcache line-size @var{line-size}
13265 @cindex dcache line-size
13266 @kindex set dcache line-size
13267 Set number of bytes each dcache entry caches (dcache width above).
13268 Must be a power of 2.
13269
13270 @item show dcache size
13271 @kindex show dcache size
13272 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13273
13274 @item show dcache line-size
13275 @kindex show dcache line-size
13276 Show default size of dcache lines.
13277
13278 @end table
13279
13280 @node Searching Memory
13281 @section Search Memory
13282 @cindex searching memory
13283
13284 Memory can be searched for a particular sequence of bytes with the
13285 @code{find} command.
13286
13287 @table @code
13288 @kindex find
13289 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13290 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13291 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13292 etc. The search begins at address @var{start_addr} and continues for either
13293 @var{len} bytes or through to @var{end_addr} inclusive.
13294 @end table
13295
13296 @var{s} and @var{n} are optional parameters.
13297 They may be specified in either order, apart or together.
13298
13299 @table @r
13300 @item @var{s}, search query size
13301 The size of each search query value.
13302
13303 @table @code
13304 @item b
13305 bytes
13306 @item h
13307 halfwords (two bytes)
13308 @item w
13309 words (four bytes)
13310 @item g
13311 giant words (eight bytes)
13312 @end table
13313
13314 All values are interpreted in the current language.
13315 This means, for example, that if the current source language is C/C@t{++}
13316 then searching for the string ``hello'' includes the trailing '\0'.
13317 The null terminator can be removed from searching by using casts,
13318 e.g.: @samp{@{char[5]@}"hello"}.
13319
13320 If the value size is not specified, it is taken from the
13321 value's type in the current language.
13322 This is useful when one wants to specify the search
13323 pattern as a mixture of types.
13324 Note that this means, for example, that in the case of C-like languages
13325 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13326 which is typically four bytes.
13327
13328 @item @var{n}, maximum number of finds
13329 The maximum number of matches to print. The default is to print all finds.
13330 @end table
13331
13332 You can use strings as search values. Quote them with double-quotes
13333 (@code{"}).
13334 The string value is copied into the search pattern byte by byte,
13335 regardless of the endianness of the target and the size specification.
13336
13337 The address of each match found is printed as well as a count of the
13338 number of matches found.
13339
13340 The address of the last value found is stored in convenience variable
13341 @samp{$_}.
13342 A count of the number of matches is stored in @samp{$numfound}.
13343
13344 For example, if stopped at the @code{printf} in this function:
13345
13346 @smallexample
13347 void
13348 hello ()
13349 @{
13350 static char hello[] = "hello-hello";
13351 static struct @{ char c; short s; int i; @}
13352 __attribute__ ((packed)) mixed
13353 = @{ 'c', 0x1234, 0x87654321 @};
13354 printf ("%s\n", hello);
13355 @}
13356 @end smallexample
13357
13358 @noindent
13359 you get during debugging:
13360
13361 @smallexample
13362 (gdb) find &hello[0], +sizeof(hello), "hello"
13363 0x804956d <hello.1620+6>
13364 1 pattern found
13365 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13366 0x8049567 <hello.1620>
13367 0x804956d <hello.1620+6>
13368 2 patterns found.
13369 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13370 0x8049567 <hello.1620>
13371 0x804956d <hello.1620+6>
13372 2 patterns found.
13373 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13374 0x8049567 <hello.1620>
13375 1 pattern found
13376 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13377 0x8049560 <mixed.1625>
13378 1 pattern found
13379 (gdb) print $numfound
13380 $1 = 1
13381 (gdb) print $_
13382 $2 = (void *) 0x8049560
13383 @end smallexample
13384
13385 @node Value Sizes
13386 @section Value Sizes
13387
13388 Whenever @value{GDBN} prints a value memory will be allocated within
13389 @value{GDBN} to hold the contents of the value. It is possible in
13390 some languages with dynamic typing systems, that an invalid program
13391 may indicate a value that is incorrectly large, this in turn may cause
13392 @value{GDBN} to try and allocate an overly large amount of memory.
13393
13394 @table @code
13395 @kindex set max-value-size
13396 @item set max-value-size @var{bytes}
13397 @itemx set max-value-size unlimited
13398 Set the maximum size of memory that @value{GDBN} will allocate for the
13399 contents of a value to @var{bytes}, trying to display a value that
13400 requires more memory than that will result in an error.
13401
13402 Setting this variable does not effect values that have already been
13403 allocated within @value{GDBN}, only future allocations.
13404
13405 There's a minimum size that @code{max-value-size} can be set to in
13406 order that @value{GDBN} can still operate correctly, this minimum is
13407 currently 16 bytes.
13408
13409 The limit applies to the results of some subexpressions as well as to
13410 complete expressions. For example, an expression denoting a simple
13411 integer component, such as @code{x.y.z}, may fail if the size of
13412 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13413 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13414 @var{A} is an array variable with non-constant size, will generally
13415 succeed regardless of the bounds on @var{A}, as long as the component
13416 size is less than @var{bytes}.
13417
13418 The default value of @code{max-value-size} is currently 64k.
13419
13420 @kindex show max-value-size
13421 @item show max-value-size
13422 Show the maximum size of memory, in bytes, that @value{GDBN} will
13423 allocate for the contents of a value.
13424 @end table
13425
13426 @node Optimized Code
13427 @chapter Debugging Optimized Code
13428 @cindex optimized code, debugging
13429 @cindex debugging optimized code
13430
13431 Almost all compilers support optimization. With optimization
13432 disabled, the compiler generates assembly code that corresponds
13433 directly to your source code, in a simplistic way. As the compiler
13434 applies more powerful optimizations, the generated assembly code
13435 diverges from your original source code. With help from debugging
13436 information generated by the compiler, @value{GDBN} can map from
13437 the running program back to constructs from your original source.
13438
13439 @value{GDBN} is more accurate with optimization disabled. If you
13440 can recompile without optimization, it is easier to follow the
13441 progress of your program during debugging. But, there are many cases
13442 where you may need to debug an optimized version.
13443
13444 When you debug a program compiled with @samp{-g -O}, remember that the
13445 optimizer has rearranged your code; the debugger shows you what is
13446 really there. Do not be too surprised when the execution path does not
13447 exactly match your source file! An extreme example: if you define a
13448 variable, but never use it, @value{GDBN} never sees that
13449 variable---because the compiler optimizes it out of existence.
13450
13451 Some things do not work as well with @samp{-g -O} as with just
13452 @samp{-g}, particularly on machines with instruction scheduling. If in
13453 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13454 please report it to us as a bug (including a test case!).
13455 @xref{Variables}, for more information about debugging optimized code.
13456
13457 @menu
13458 * Inline Functions:: How @value{GDBN} presents inlining
13459 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13460 @end menu
13461
13462 @node Inline Functions
13463 @section Inline Functions
13464 @cindex inline functions, debugging
13465
13466 @dfn{Inlining} is an optimization that inserts a copy of the function
13467 body directly at each call site, instead of jumping to a shared
13468 routine. @value{GDBN} displays inlined functions just like
13469 non-inlined functions. They appear in backtraces. You can view their
13470 arguments and local variables, step into them with @code{step}, skip
13471 them with @code{next}, and escape from them with @code{finish}.
13472 You can check whether a function was inlined by using the
13473 @code{info frame} command.
13474
13475 For @value{GDBN} to support inlined functions, the compiler must
13476 record information about inlining in the debug information ---
13477 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13478 other compilers do also. @value{GDBN} only supports inlined functions
13479 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13480 do not emit two required attributes (@samp{DW_AT_call_file} and
13481 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13482 function calls with earlier versions of @value{NGCC}. It instead
13483 displays the arguments and local variables of inlined functions as
13484 local variables in the caller.
13485
13486 The body of an inlined function is directly included at its call site;
13487 unlike a non-inlined function, there are no instructions devoted to
13488 the call. @value{GDBN} still pretends that the call site and the
13489 start of the inlined function are different instructions. Stepping to
13490 the call site shows the call site, and then stepping again shows
13491 the first line of the inlined function, even though no additional
13492 instructions are executed.
13493
13494 This makes source-level debugging much clearer; you can see both the
13495 context of the call and then the effect of the call. Only stepping by
13496 a single instruction using @code{stepi} or @code{nexti} does not do
13497 this; single instruction steps always show the inlined body.
13498
13499 There are some ways that @value{GDBN} does not pretend that inlined
13500 function calls are the same as normal calls:
13501
13502 @itemize @bullet
13503 @item
13504 Setting breakpoints at the call site of an inlined function may not
13505 work, because the call site does not contain any code. @value{GDBN}
13506 may incorrectly move the breakpoint to the next line of the enclosing
13507 function, after the call. This limitation will be removed in a future
13508 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13509 or inside the inlined function instead.
13510
13511 @item
13512 @value{GDBN} cannot locate the return value of inlined calls after
13513 using the @code{finish} command. This is a limitation of compiler-generated
13514 debugging information; after @code{finish}, you can step to the next line
13515 and print a variable where your program stored the return value.
13516
13517 @end itemize
13518
13519 @node Tail Call Frames
13520 @section Tail Call Frames
13521 @cindex tail call frames, debugging
13522
13523 Function @code{B} can call function @code{C} in its very last statement. In
13524 unoptimized compilation the call of @code{C} is immediately followed by return
13525 instruction at the end of @code{B} code. Optimizing compiler may replace the
13526 call and return in function @code{B} into one jump to function @code{C}
13527 instead. Such use of a jump instruction is called @dfn{tail call}.
13528
13529 During execution of function @code{C}, there will be no indication in the
13530 function call stack frames that it was tail-called from @code{B}. If function
13531 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13532 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13533 some cases @value{GDBN} can determine that @code{C} was tail-called from
13534 @code{B}, and it will then create fictitious call frame for that, with the
13535 return address set up as if @code{B} called @code{C} normally.
13536
13537 This functionality is currently supported only by DWARF 2 debugging format and
13538 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13539 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13540 this information.
13541
13542 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13543 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13544
13545 @smallexample
13546 (gdb) x/i $pc - 2
13547 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13548 (gdb) info frame
13549 Stack level 1, frame at 0x7fffffffda30:
13550 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13551 tail call frame, caller of frame at 0x7fffffffda30
13552 source language c++.
13553 Arglist at unknown address.
13554 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13555 @end smallexample
13556
13557 The detection of all the possible code path executions can find them ambiguous.
13558 There is no execution history stored (possible @ref{Reverse Execution} is never
13559 used for this purpose) and the last known caller could have reached the known
13560 callee by multiple different jump sequences. In such case @value{GDBN} still
13561 tries to show at least all the unambiguous top tail callers and all the
13562 unambiguous bottom tail calees, if any.
13563
13564 @table @code
13565 @anchor{set debug entry-values}
13566 @item set debug entry-values
13567 @kindex set debug entry-values
13568 When set to on, enables printing of analysis messages for both frame argument
13569 values at function entry and tail calls. It will show all the possible valid
13570 tail calls code paths it has considered. It will also print the intersection
13571 of them with the final unambiguous (possibly partial or even empty) code path
13572 result.
13573
13574 @item show debug entry-values
13575 @kindex show debug entry-values
13576 Show the current state of analysis messages printing for both frame argument
13577 values at function entry and tail calls.
13578 @end table
13579
13580 The analysis messages for tail calls can for example show why the virtual tail
13581 call frame for function @code{c} has not been recognized (due to the indirect
13582 reference by variable @code{x}):
13583
13584 @smallexample
13585 static void __attribute__((noinline, noclone)) c (void);
13586 void (*x) (void) = c;
13587 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13588 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13589 int main (void) @{ x (); return 0; @}
13590
13591 Breakpoint 1, DW_OP_entry_value resolving cannot find
13592 DW_TAG_call_site 0x40039a in main
13593 a () at t.c:3
13594 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13595 (gdb) bt
13596 #0 a () at t.c:3
13597 #1 0x000000000040039a in main () at t.c:5
13598 @end smallexample
13599
13600 Another possibility is an ambiguous virtual tail call frames resolution:
13601
13602 @smallexample
13603 int i;
13604 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13605 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13606 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13607 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13608 static void __attribute__((noinline, noclone)) b (void)
13609 @{ if (i) c (); else e (); @}
13610 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13611 int main (void) @{ a (); return 0; @}
13612
13613 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13614 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13615 tailcall: reduced: 0x4004d2(a) |
13616 (gdb) bt
13617 #0 f () at t.c:2
13618 #1 0x00000000004004d2 in a () at t.c:8
13619 #2 0x0000000000400395 in main () at t.c:9
13620 @end smallexample
13621
13622 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13623 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13624
13625 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13626 @ifset HAVE_MAKEINFO_CLICK
13627 @set ARROW @click{}
13628 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13629 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13630 @end ifset
13631 @ifclear HAVE_MAKEINFO_CLICK
13632 @set ARROW ->
13633 @set CALLSEQ1B @value{CALLSEQ1A}
13634 @set CALLSEQ2B @value{CALLSEQ2A}
13635 @end ifclear
13636
13637 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13638 The code can have possible execution paths @value{CALLSEQ1B} or
13639 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13640
13641 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13642 has found. It then finds another possible calling sequence - that one is
13643 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13644 printed as the @code{reduced:} calling sequence. That one could have many
13645 further @code{compare:} and @code{reduced:} statements as long as there remain
13646 any non-ambiguous sequence entries.
13647
13648 For the frame of function @code{b} in both cases there are different possible
13649 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
13650 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
13651 therefore this one is displayed to the user while the ambiguous frames are
13652 omitted.
13653
13654 There can be also reasons why printing of frame argument values at function
13655 entry may fail:
13656
13657 @smallexample
13658 int v;
13659 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13660 static void __attribute__((noinline, noclone)) a (int i);
13661 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13662 static void __attribute__((noinline, noclone)) a (int i)
13663 @{ if (i) b (i - 1); else c (0); @}
13664 int main (void) @{ a (5); return 0; @}
13665
13666 (gdb) bt
13667 #0 c (i=i@@entry=0) at t.c:2
13668 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
13669 function "a" at 0x400420 can call itself via tail calls
13670 i=<optimized out>) at t.c:6
13671 #2 0x000000000040036e in main () at t.c:7
13672 @end smallexample
13673
13674 @value{GDBN} cannot find out from the inferior state if and how many times did
13675 function @code{a} call itself (via function @code{b}) as these calls would be
13676 tail calls. Such tail calls would modify the @code{i} variable, therefore
13677 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13678 prints @code{<optimized out>} instead.
13679
13680 @node Macros
13681 @chapter C Preprocessor Macros
13682
13683 Some languages, such as C and C@t{++}, provide a way to define and invoke
13684 ``preprocessor macros'' which expand into strings of tokens.
13685 @value{GDBN} can evaluate expressions containing macro invocations, show
13686 the result of macro expansion, and show a macro's definition, including
13687 where it was defined.
13688
13689 You may need to compile your program specially to provide @value{GDBN}
13690 with information about preprocessor macros. Most compilers do not
13691 include macros in their debugging information, even when you compile
13692 with the @option{-g} flag. @xref{Compilation}.
13693
13694 A program may define a macro at one point, remove that definition later,
13695 and then provide a different definition after that. Thus, at different
13696 points in the program, a macro may have different definitions, or have
13697 no definition at all. If there is a current stack frame, @value{GDBN}
13698 uses the macros in scope at that frame's source code line. Otherwise,
13699 @value{GDBN} uses the macros in scope at the current listing location;
13700 see @ref{List}.
13701
13702 Whenever @value{GDBN} evaluates an expression, it always expands any
13703 macro invocations present in the expression. @value{GDBN} also provides
13704 the following commands for working with macros explicitly.
13705
13706 @table @code
13707
13708 @kindex macro expand
13709 @cindex macro expansion, showing the results of preprocessor
13710 @cindex preprocessor macro expansion, showing the results of
13711 @cindex expanding preprocessor macros
13712 @item macro expand @var{expression}
13713 @itemx macro exp @var{expression}
13714 Show the results of expanding all preprocessor macro invocations in
13715 @var{expression}. Since @value{GDBN} simply expands macros, but does
13716 not parse the result, @var{expression} need not be a valid expression;
13717 it can be any string of tokens.
13718
13719 @kindex macro exp1
13720 @item macro expand-once @var{expression}
13721 @itemx macro exp1 @var{expression}
13722 @cindex expand macro once
13723 @i{(This command is not yet implemented.)} Show the results of
13724 expanding those preprocessor macro invocations that appear explicitly in
13725 @var{expression}. Macro invocations appearing in that expansion are
13726 left unchanged. This command allows you to see the effect of a
13727 particular macro more clearly, without being confused by further
13728 expansions. Since @value{GDBN} simply expands macros, but does not
13729 parse the result, @var{expression} need not be a valid expression; it
13730 can be any string of tokens.
13731
13732 @kindex info macro
13733 @cindex macro definition, showing
13734 @cindex definition of a macro, showing
13735 @cindex macros, from debug info
13736 @item info macro [-a|-all] [--] @var{macro}
13737 Show the current definition or all definitions of the named @var{macro},
13738 and describe the source location or compiler command-line where that
13739 definition was established. The optional double dash is to signify the end of
13740 argument processing and the beginning of @var{macro} for non C-like macros where
13741 the macro may begin with a hyphen.
13742
13743 @kindex info macros
13744 @item info macros @var{location}
13745 Show all macro definitions that are in effect at the location specified
13746 by @var{location}, and describe the source location or compiler
13747 command-line where those definitions were established.
13748
13749 @kindex macro define
13750 @cindex user-defined macros
13751 @cindex defining macros interactively
13752 @cindex macros, user-defined
13753 @item macro define @var{macro} @var{replacement-list}
13754 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
13755 Introduce a definition for a preprocessor macro named @var{macro},
13756 invocations of which are replaced by the tokens given in
13757 @var{replacement-list}. The first form of this command defines an
13758 ``object-like'' macro, which takes no arguments; the second form
13759 defines a ``function-like'' macro, which takes the arguments given in
13760 @var{arglist}.
13761
13762 A definition introduced by this command is in scope in every
13763 expression evaluated in @value{GDBN}, until it is removed with the
13764 @code{macro undef} command, described below. The definition overrides
13765 all definitions for @var{macro} present in the program being debugged,
13766 as well as any previous user-supplied definition.
13767
13768 @kindex macro undef
13769 @item macro undef @var{macro}
13770 Remove any user-supplied definition for the macro named @var{macro}.
13771 This command only affects definitions provided with the @code{macro
13772 define} command, described above; it cannot remove definitions present
13773 in the program being debugged.
13774
13775 @kindex macro list
13776 @item macro list
13777 List all the macros defined using the @code{macro define} command.
13778 @end table
13779
13780 @cindex macros, example of debugging with
13781 Here is a transcript showing the above commands in action. First, we
13782 show our source files:
13783
13784 @smallexample
13785 $ cat sample.c
13786 #include <stdio.h>
13787 #include "sample.h"
13788
13789 #define M 42
13790 #define ADD(x) (M + x)
13791
13792 main ()
13793 @{
13794 #define N 28
13795 printf ("Hello, world!\n");
13796 #undef N
13797 printf ("We're so creative.\n");
13798 #define N 1729
13799 printf ("Goodbye, world!\n");
13800 @}
13801 $ cat sample.h
13802 #define Q <
13803 $
13804 @end smallexample
13805
13806 Now, we compile the program using the @sc{gnu} C compiler,
13807 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13808 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13809 and @option{-gdwarf-4}; we recommend always choosing the most recent
13810 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13811 includes information about preprocessor macros in the debugging
13812 information.
13813
13814 @smallexample
13815 $ gcc -gdwarf-2 -g3 sample.c -o sample
13816 $
13817 @end smallexample
13818
13819 Now, we start @value{GDBN} on our sample program:
13820
13821 @smallexample
13822 $ gdb -nw sample
13823 GNU gdb 2002-05-06-cvs
13824 Copyright 2002 Free Software Foundation, Inc.
13825 GDB is free software, @dots{}
13826 (@value{GDBP})
13827 @end smallexample
13828
13829 We can expand macros and examine their definitions, even when the
13830 program is not running. @value{GDBN} uses the current listing position
13831 to decide which macro definitions are in scope:
13832
13833 @smallexample
13834 (@value{GDBP}) list main
13835 3
13836 4 #define M 42
13837 5 #define ADD(x) (M + x)
13838 6
13839 7 main ()
13840 8 @{
13841 9 #define N 28
13842 10 printf ("Hello, world!\n");
13843 11 #undef N
13844 12 printf ("We're so creative.\n");
13845 (@value{GDBP}) info macro ADD
13846 Defined at /home/jimb/gdb/macros/play/sample.c:5
13847 #define ADD(x) (M + x)
13848 (@value{GDBP}) info macro Q
13849 Defined at /home/jimb/gdb/macros/play/sample.h:1
13850 included at /home/jimb/gdb/macros/play/sample.c:2
13851 #define Q <
13852 (@value{GDBP}) macro expand ADD(1)
13853 expands to: (42 + 1)
13854 (@value{GDBP}) macro expand-once ADD(1)
13855 expands to: once (M + 1)
13856 (@value{GDBP})
13857 @end smallexample
13858
13859 In the example above, note that @code{macro expand-once} expands only
13860 the macro invocation explicit in the original text --- the invocation of
13861 @code{ADD} --- but does not expand the invocation of the macro @code{M},
13862 which was introduced by @code{ADD}.
13863
13864 Once the program is running, @value{GDBN} uses the macro definitions in
13865 force at the source line of the current stack frame:
13866
13867 @smallexample
13868 (@value{GDBP}) break main
13869 Breakpoint 1 at 0x8048370: file sample.c, line 10.
13870 (@value{GDBP}) run
13871 Starting program: /home/jimb/gdb/macros/play/sample
13872
13873 Breakpoint 1, main () at sample.c:10
13874 10 printf ("Hello, world!\n");
13875 (@value{GDBP})
13876 @end smallexample
13877
13878 At line 10, the definition of the macro @code{N} at line 9 is in force:
13879
13880 @smallexample
13881 (@value{GDBP}) info macro N
13882 Defined at /home/jimb/gdb/macros/play/sample.c:9
13883 #define N 28
13884 (@value{GDBP}) macro expand N Q M
13885 expands to: 28 < 42
13886 (@value{GDBP}) print N Q M
13887 $1 = 1
13888 (@value{GDBP})
13889 @end smallexample
13890
13891 As we step over directives that remove @code{N}'s definition, and then
13892 give it a new definition, @value{GDBN} finds the definition (or lack
13893 thereof) in force at each point:
13894
13895 @smallexample
13896 (@value{GDBP}) next
13897 Hello, world!
13898 12 printf ("We're so creative.\n");
13899 (@value{GDBP}) info macro N
13900 The symbol `N' has no definition as a C/C++ preprocessor macro
13901 at /home/jimb/gdb/macros/play/sample.c:12
13902 (@value{GDBP}) next
13903 We're so creative.
13904 14 printf ("Goodbye, world!\n");
13905 (@value{GDBP}) info macro N
13906 Defined at /home/jimb/gdb/macros/play/sample.c:13
13907 #define N 1729
13908 (@value{GDBP}) macro expand N Q M
13909 expands to: 1729 < 42
13910 (@value{GDBP}) print N Q M
13911 $2 = 0
13912 (@value{GDBP})
13913 @end smallexample
13914
13915 In addition to source files, macros can be defined on the compilation command
13916 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
13917 such a way, @value{GDBN} displays the location of their definition as line zero
13918 of the source file submitted to the compiler.
13919
13920 @smallexample
13921 (@value{GDBP}) info macro __STDC__
13922 Defined at /home/jimb/gdb/macros/play/sample.c:0
13923 -D__STDC__=1
13924 (@value{GDBP})
13925 @end smallexample
13926
13927
13928 @node Tracepoints
13929 @chapter Tracepoints
13930 @c This chapter is based on the documentation written by Michael
13931 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
13932
13933 @cindex tracepoints
13934 In some applications, it is not feasible for the debugger to interrupt
13935 the program's execution long enough for the developer to learn
13936 anything helpful about its behavior. If the program's correctness
13937 depends on its real-time behavior, delays introduced by a debugger
13938 might cause the program to change its behavior drastically, or perhaps
13939 fail, even when the code itself is correct. It is useful to be able
13940 to observe the program's behavior without interrupting it.
13941
13942 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
13943 specify locations in the program, called @dfn{tracepoints}, and
13944 arbitrary expressions to evaluate when those tracepoints are reached.
13945 Later, using the @code{tfind} command, you can examine the values
13946 those expressions had when the program hit the tracepoints. The
13947 expressions may also denote objects in memory---structures or arrays,
13948 for example---whose values @value{GDBN} should record; while visiting
13949 a particular tracepoint, you may inspect those objects as if they were
13950 in memory at that moment. However, because @value{GDBN} records these
13951 values without interacting with you, it can do so quickly and
13952 unobtrusively, hopefully not disturbing the program's behavior.
13953
13954 The tracepoint facility is currently available only for remote
13955 targets. @xref{Targets}. In addition, your remote target must know
13956 how to collect trace data. This functionality is implemented in the
13957 remote stub; however, none of the stubs distributed with @value{GDBN}
13958 support tracepoints as of this writing. The format of the remote
13959 packets used to implement tracepoints are described in @ref{Tracepoint
13960 Packets}.
13961
13962 It is also possible to get trace data from a file, in a manner reminiscent
13963 of corefiles; you specify the filename, and use @code{tfind} to search
13964 through the file. @xref{Trace Files}, for more details.
13965
13966 This chapter describes the tracepoint commands and features.
13967
13968 @menu
13969 * Set Tracepoints::
13970 * Analyze Collected Data::
13971 * Tracepoint Variables::
13972 * Trace Files::
13973 @end menu
13974
13975 @node Set Tracepoints
13976 @section Commands to Set Tracepoints
13977
13978 Before running such a @dfn{trace experiment}, an arbitrary number of
13979 tracepoints can be set. A tracepoint is actually a special type of
13980 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
13981 standard breakpoint commands. For instance, as with breakpoints,
13982 tracepoint numbers are successive integers starting from one, and many
13983 of the commands associated with tracepoints take the tracepoint number
13984 as their argument, to identify which tracepoint to work on.
13985
13986 For each tracepoint, you can specify, in advance, some arbitrary set
13987 of data that you want the target to collect in the trace buffer when
13988 it hits that tracepoint. The collected data can include registers,
13989 local variables, or global data. Later, you can use @value{GDBN}
13990 commands to examine the values these data had at the time the
13991 tracepoint was hit.
13992
13993 Tracepoints do not support every breakpoint feature. Ignore counts on
13994 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
13995 commands when they are hit. Tracepoints may not be thread-specific
13996 either.
13997
13998 @cindex fast tracepoints
13999 Some targets may support @dfn{fast tracepoints}, which are inserted in
14000 a different way (such as with a jump instead of a trap), that is
14001 faster but possibly restricted in where they may be installed.
14002
14003 @cindex static tracepoints
14004 @cindex markers, static tracepoints
14005 @cindex probing markers, static tracepoints
14006 Regular and fast tracepoints are dynamic tracing facilities, meaning
14007 that they can be used to insert tracepoints at (almost) any location
14008 in the target. Some targets may also support controlling @dfn{static
14009 tracepoints} from @value{GDBN}. With static tracing, a set of
14010 instrumentation points, also known as @dfn{markers}, are embedded in
14011 the target program, and can be activated or deactivated by name or
14012 address. These are usually placed at locations which facilitate
14013 investigating what the target is actually doing. @value{GDBN}'s
14014 support for static tracing includes being able to list instrumentation
14015 points, and attach them with @value{GDBN} defined high level
14016 tracepoints that expose the whole range of convenience of
14017 @value{GDBN}'s tracepoints support. Namely, support for collecting
14018 registers values and values of global or local (to the instrumentation
14019 point) variables; tracepoint conditions and trace state variables.
14020 The act of installing a @value{GDBN} static tracepoint on an
14021 instrumentation point, or marker, is referred to as @dfn{probing} a
14022 static tracepoint marker.
14023
14024 @code{gdbserver} supports tracepoints on some target systems.
14025 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14026
14027 This section describes commands to set tracepoints and associated
14028 conditions and actions.
14029
14030 @menu
14031 * Create and Delete Tracepoints::
14032 * Enable and Disable Tracepoints::
14033 * Tracepoint Passcounts::
14034 * Tracepoint Conditions::
14035 * Trace State Variables::
14036 * Tracepoint Actions::
14037 * Listing Tracepoints::
14038 * Listing Static Tracepoint Markers::
14039 * Starting and Stopping Trace Experiments::
14040 * Tracepoint Restrictions::
14041 @end menu
14042
14043 @node Create and Delete Tracepoints
14044 @subsection Create and Delete Tracepoints
14045
14046 @table @code
14047 @cindex set tracepoint
14048 @kindex trace
14049 @item trace @var{location}
14050 The @code{trace} command is very similar to the @code{break} command.
14051 Its argument @var{location} can be any valid location.
14052 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14053 which is a point in the target program where the debugger will briefly stop,
14054 collect some data, and then allow the program to continue. Setting a tracepoint
14055 or changing its actions takes effect immediately if the remote stub
14056 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14057 in tracing}).
14058 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14059 these changes don't take effect until the next @code{tstart}
14060 command, and once a trace experiment is running, further changes will
14061 not have any effect until the next trace experiment starts. In addition,
14062 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14063 address is not yet resolved. (This is similar to pending breakpoints.)
14064 Pending tracepoints are not downloaded to the target and not installed
14065 until they are resolved. The resolution of pending tracepoints requires
14066 @value{GDBN} support---when debugging with the remote target, and
14067 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14068 tracing}), pending tracepoints can not be resolved (and downloaded to
14069 the remote stub) while @value{GDBN} is disconnected.
14070
14071 Here are some examples of using the @code{trace} command:
14072
14073 @smallexample
14074 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14075
14076 (@value{GDBP}) @b{trace +2} // 2 lines forward
14077
14078 (@value{GDBP}) @b{trace my_function} // first source line of function
14079
14080 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14081
14082 (@value{GDBP}) @b{trace *0x2117c4} // an address
14083 @end smallexample
14084
14085 @noindent
14086 You can abbreviate @code{trace} as @code{tr}.
14087
14088 @item trace @var{location} if @var{cond}
14089 Set a tracepoint with condition @var{cond}; evaluate the expression
14090 @var{cond} each time the tracepoint is reached, and collect data only
14091 if the value is nonzero---that is, if @var{cond} evaluates as true.
14092 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14093 information on tracepoint conditions.
14094
14095 @item ftrace @var{location} [ if @var{cond} ]
14096 @cindex set fast tracepoint
14097 @cindex fast tracepoints, setting
14098 @kindex ftrace
14099 The @code{ftrace} command sets a fast tracepoint. For targets that
14100 support them, fast tracepoints will use a more efficient but possibly
14101 less general technique to trigger data collection, such as a jump
14102 instruction instead of a trap, or some sort of hardware support. It
14103 may not be possible to create a fast tracepoint at the desired
14104 location, in which case the command will exit with an explanatory
14105 message.
14106
14107 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14108 @code{trace}.
14109
14110 On 32-bit x86-architecture systems, fast tracepoints normally need to
14111 be placed at an instruction that is 5 bytes or longer, but can be
14112 placed at 4-byte instructions if the low 64K of memory of the target
14113 program is available to install trampolines. Some Unix-type systems,
14114 such as @sc{gnu}/Linux, exclude low addresses from the program's
14115 address space; but for instance with the Linux kernel it is possible
14116 to let @value{GDBN} use this area by doing a @command{sysctl} command
14117 to set the @code{mmap_min_addr} kernel parameter, as in
14118
14119 @example
14120 sudo sysctl -w vm.mmap_min_addr=32768
14121 @end example
14122
14123 @noindent
14124 which sets the low address to 32K, which leaves plenty of room for
14125 trampolines. The minimum address should be set to a page boundary.
14126
14127 @item strace @var{location} [ if @var{cond} ]
14128 @cindex set static tracepoint
14129 @cindex static tracepoints, setting
14130 @cindex probe static tracepoint marker
14131 @kindex strace
14132 The @code{strace} command sets a static tracepoint. For targets that
14133 support it, setting a static tracepoint probes a static
14134 instrumentation point, or marker, found at @var{location}. It may not
14135 be possible to set a static tracepoint at the desired location, in
14136 which case the command will exit with an explanatory message.
14137
14138 @value{GDBN} handles arguments to @code{strace} exactly as for
14139 @code{trace}, with the addition that the user can also specify
14140 @code{-m @var{marker}} as @var{location}. This probes the marker
14141 identified by the @var{marker} string identifier. This identifier
14142 depends on the static tracepoint backend library your program is
14143 using. You can find all the marker identifiers in the @samp{ID} field
14144 of the @code{info static-tracepoint-markers} command output.
14145 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14146 Markers}. For example, in the following small program using the UST
14147 tracing engine:
14148
14149 @smallexample
14150 main ()
14151 @{
14152 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14153 @}
14154 @end smallexample
14155
14156 @noindent
14157 the marker id is composed of joining the first two arguments to the
14158 @code{trace_mark} call with a slash, which translates to:
14159
14160 @smallexample
14161 (@value{GDBP}) info static-tracepoint-markers
14162 Cnt Enb ID Address What
14163 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14164 Data: "str %s"
14165 [etc...]
14166 @end smallexample
14167
14168 @noindent
14169 so you may probe the marker above with:
14170
14171 @smallexample
14172 (@value{GDBP}) strace -m ust/bar33
14173 @end smallexample
14174
14175 Static tracepoints accept an extra collect action --- @code{collect
14176 $_sdata}. This collects arbitrary user data passed in the probe point
14177 call to the tracing library. In the UST example above, you'll see
14178 that the third argument to @code{trace_mark} is a printf-like format
14179 string. The user data is then the result of running that formatting
14180 string against the following arguments. Note that @code{info
14181 static-tracepoint-markers} command output lists that format string in
14182 the @samp{Data:} field.
14183
14184 You can inspect this data when analyzing the trace buffer, by printing
14185 the $_sdata variable like any other variable available to
14186 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14187
14188 @vindex $tpnum
14189 @cindex last tracepoint number
14190 @cindex recent tracepoint number
14191 @cindex tracepoint number
14192 The convenience variable @code{$tpnum} records the tracepoint number
14193 of the most recently set tracepoint.
14194
14195 @kindex delete tracepoint
14196 @cindex tracepoint deletion
14197 @item delete tracepoint @r{[}@var{num}@r{]}
14198 Permanently delete one or more tracepoints. With no argument, the
14199 default is to delete all tracepoints. Note that the regular
14200 @code{delete} command can remove tracepoints also.
14201
14202 Examples:
14203
14204 @smallexample
14205 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14206
14207 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14208 @end smallexample
14209
14210 @noindent
14211 You can abbreviate this command as @code{del tr}.
14212 @end table
14213
14214 @node Enable and Disable Tracepoints
14215 @subsection Enable and Disable Tracepoints
14216
14217 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14218
14219 @table @code
14220 @kindex disable tracepoint
14221 @item disable tracepoint @r{[}@var{num}@r{]}
14222 Disable tracepoint @var{num}, or all tracepoints if no argument
14223 @var{num} is given. A disabled tracepoint will have no effect during
14224 a trace experiment, but it is not forgotten. You can re-enable
14225 a disabled tracepoint using the @code{enable tracepoint} command.
14226 If the command is issued during a trace experiment and the debug target
14227 has support for disabling tracepoints during a trace experiment, then the
14228 change will be effective immediately. Otherwise, it will be applied to the
14229 next trace experiment.
14230
14231 @kindex enable tracepoint
14232 @item enable tracepoint @r{[}@var{num}@r{]}
14233 Enable tracepoint @var{num}, or all tracepoints. If this command is
14234 issued during a trace experiment and the debug target supports enabling
14235 tracepoints during a trace experiment, then the enabled tracepoints will
14236 become effective immediately. Otherwise, they will become effective the
14237 next time a trace experiment is run.
14238 @end table
14239
14240 @node Tracepoint Passcounts
14241 @subsection Tracepoint Passcounts
14242
14243 @table @code
14244 @kindex passcount
14245 @cindex tracepoint pass count
14246 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14247 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14248 automatically stop a trace experiment. If a tracepoint's passcount is
14249 @var{n}, then the trace experiment will be automatically stopped on
14250 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14251 @var{num} is not specified, the @code{passcount} command sets the
14252 passcount of the most recently defined tracepoint. If no passcount is
14253 given, the trace experiment will run until stopped explicitly by the
14254 user.
14255
14256 Examples:
14257
14258 @smallexample
14259 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14260 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14261
14262 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14263 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14264 (@value{GDBP}) @b{trace foo}
14265 (@value{GDBP}) @b{pass 3}
14266 (@value{GDBP}) @b{trace bar}
14267 (@value{GDBP}) @b{pass 2}
14268 (@value{GDBP}) @b{trace baz}
14269 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14270 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14271 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14272 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14273 @end smallexample
14274 @end table
14275
14276 @node Tracepoint Conditions
14277 @subsection Tracepoint Conditions
14278 @cindex conditional tracepoints
14279 @cindex tracepoint conditions
14280
14281 The simplest sort of tracepoint collects data every time your program
14282 reaches a specified place. You can also specify a @dfn{condition} for
14283 a tracepoint. A condition is just a Boolean expression in your
14284 programming language (@pxref{Expressions, ,Expressions}). A
14285 tracepoint with a condition evaluates the expression each time your
14286 program reaches it, and data collection happens only if the condition
14287 is true.
14288
14289 Tracepoint conditions can be specified when a tracepoint is set, by
14290 using @samp{if} in the arguments to the @code{trace} command.
14291 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14292 also be set or changed at any time with the @code{condition} command,
14293 just as with breakpoints.
14294
14295 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14296 the conditional expression itself. Instead, @value{GDBN} encodes the
14297 expression into an agent expression (@pxref{Agent Expressions})
14298 suitable for execution on the target, independently of @value{GDBN}.
14299 Global variables become raw memory locations, locals become stack
14300 accesses, and so forth.
14301
14302 For instance, suppose you have a function that is usually called
14303 frequently, but should not be called after an error has occurred. You
14304 could use the following tracepoint command to collect data about calls
14305 of that function that happen while the error code is propagating
14306 through the program; an unconditional tracepoint could end up
14307 collecting thousands of useless trace frames that you would have to
14308 search through.
14309
14310 @smallexample
14311 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14312 @end smallexample
14313
14314 @node Trace State Variables
14315 @subsection Trace State Variables
14316 @cindex trace state variables
14317
14318 A @dfn{trace state variable} is a special type of variable that is
14319 created and managed by target-side code. The syntax is the same as
14320 that for GDB's convenience variables (a string prefixed with ``$''),
14321 but they are stored on the target. They must be created explicitly,
14322 using a @code{tvariable} command. They are always 64-bit signed
14323 integers.
14324
14325 Trace state variables are remembered by @value{GDBN}, and downloaded
14326 to the target along with tracepoint information when the trace
14327 experiment starts. There are no intrinsic limits on the number of
14328 trace state variables, beyond memory limitations of the target.
14329
14330 @cindex convenience variables, and trace state variables
14331 Although trace state variables are managed by the target, you can use
14332 them in print commands and expressions as if they were convenience
14333 variables; @value{GDBN} will get the current value from the target
14334 while the trace experiment is running. Trace state variables share
14335 the same namespace as other ``$'' variables, which means that you
14336 cannot have trace state variables with names like @code{$23} or
14337 @code{$pc}, nor can you have a trace state variable and a convenience
14338 variable with the same name.
14339
14340 @table @code
14341
14342 @item tvariable $@var{name} [ = @var{expression} ]
14343 @kindex tvariable
14344 The @code{tvariable} command creates a new trace state variable named
14345 @code{$@var{name}}, and optionally gives it an initial value of
14346 @var{expression}. The @var{expression} is evaluated when this command is
14347 entered; the result will be converted to an integer if possible,
14348 otherwise @value{GDBN} will report an error. A subsequent
14349 @code{tvariable} command specifying the same name does not create a
14350 variable, but instead assigns the supplied initial value to the
14351 existing variable of that name, overwriting any previous initial
14352 value. The default initial value is 0.
14353
14354 @item info tvariables
14355 @kindex info tvariables
14356 List all the trace state variables along with their initial values.
14357 Their current values may also be displayed, if the trace experiment is
14358 currently running.
14359
14360 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14361 @kindex delete tvariable
14362 Delete the given trace state variables, or all of them if no arguments
14363 are specified.
14364
14365 @end table
14366
14367 @node Tracepoint Actions
14368 @subsection Tracepoint Action Lists
14369
14370 @table @code
14371 @kindex actions
14372 @cindex tracepoint actions
14373 @item actions @r{[}@var{num}@r{]}
14374 This command will prompt for a list of actions to be taken when the
14375 tracepoint is hit. If the tracepoint number @var{num} is not
14376 specified, this command sets the actions for the one that was most
14377 recently defined (so that you can define a tracepoint and then say
14378 @code{actions} without bothering about its number). You specify the
14379 actions themselves on the following lines, one action at a time, and
14380 terminate the actions list with a line containing just @code{end}. So
14381 far, the only defined actions are @code{collect}, @code{teval}, and
14382 @code{while-stepping}.
14383
14384 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14385 Commands, ,Breakpoint Command Lists}), except that only the defined
14386 actions are allowed; any other @value{GDBN} command is rejected.
14387
14388 @cindex remove actions from a tracepoint
14389 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14390 and follow it immediately with @samp{end}.
14391
14392 @smallexample
14393 (@value{GDBP}) @b{collect @var{data}} // collect some data
14394
14395 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14396
14397 (@value{GDBP}) @b{end} // signals the end of actions.
14398 @end smallexample
14399
14400 In the following example, the action list begins with @code{collect}
14401 commands indicating the things to be collected when the tracepoint is
14402 hit. Then, in order to single-step and collect additional data
14403 following the tracepoint, a @code{while-stepping} command is used,
14404 followed by the list of things to be collected after each step in a
14405 sequence of single steps. The @code{while-stepping} command is
14406 terminated by its own separate @code{end} command. Lastly, the action
14407 list is terminated by an @code{end} command.
14408
14409 @smallexample
14410 (@value{GDBP}) @b{trace foo}
14411 (@value{GDBP}) @b{actions}
14412 Enter actions for tracepoint 1, one per line:
14413 > collect bar,baz
14414 > collect $regs
14415 > while-stepping 12
14416 > collect $pc, arr[i]
14417 > end
14418 end
14419 @end smallexample
14420
14421 @kindex collect @r{(tracepoints)}
14422 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14423 Collect values of the given expressions when the tracepoint is hit.
14424 This command accepts a comma-separated list of any valid expressions.
14425 In addition to global, static, or local variables, the following
14426 special arguments are supported:
14427
14428 @table @code
14429 @item $regs
14430 Collect all registers.
14431
14432 @item $args
14433 Collect all function arguments.
14434
14435 @item $locals
14436 Collect all local variables.
14437
14438 @item $_ret
14439 Collect the return address. This is helpful if you want to see more
14440 of a backtrace.
14441
14442 @emph{Note:} The return address location can not always be reliably
14443 determined up front, and the wrong address / registers may end up
14444 collected instead. On some architectures the reliability is higher
14445 for tracepoints at function entry, while on others it's the opposite.
14446 When this happens, backtracing will stop because the return address is
14447 found unavailable (unless another collect rule happened to match it).
14448
14449 @item $_probe_argc
14450 Collects the number of arguments from the static probe at which the
14451 tracepoint is located.
14452 @xref{Static Probe Points}.
14453
14454 @item $_probe_arg@var{n}
14455 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14456 from the static probe at which the tracepoint is located.
14457 @xref{Static Probe Points}.
14458
14459 @item $_sdata
14460 @vindex $_sdata@r{, collect}
14461 Collect static tracepoint marker specific data. Only available for
14462 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14463 Lists}. On the UST static tracepoints library backend, an
14464 instrumentation point resembles a @code{printf} function call. The
14465 tracing library is able to collect user specified data formatted to a
14466 character string using the format provided by the programmer that
14467 instrumented the program. Other backends have similar mechanisms.
14468 Here's an example of a UST marker call:
14469
14470 @smallexample
14471 const char master_name[] = "$your_name";
14472 trace_mark(channel1, marker1, "hello %s", master_name)
14473 @end smallexample
14474
14475 In this case, collecting @code{$_sdata} collects the string
14476 @samp{hello $yourname}. When analyzing the trace buffer, you can
14477 inspect @samp{$_sdata} like any other variable available to
14478 @value{GDBN}.
14479 @end table
14480
14481 You can give several consecutive @code{collect} commands, each one
14482 with a single argument, or one @code{collect} command with several
14483 arguments separated by commas; the effect is the same.
14484
14485 The optional @var{mods} changes the usual handling of the arguments.
14486 @code{s} requests that pointers to chars be handled as strings, in
14487 particular collecting the contents of the memory being pointed at, up
14488 to the first zero. The upper bound is by default the value of the
14489 @code{print elements} variable; if @code{s} is followed by a decimal
14490 number, that is the upper bound instead. So for instance
14491 @samp{collect/s25 mystr} collects as many as 25 characters at
14492 @samp{mystr}.
14493
14494 The command @code{info scope} (@pxref{Symbols, info scope}) is
14495 particularly useful for figuring out what data to collect.
14496
14497 @kindex teval @r{(tracepoints)}
14498 @item teval @var{expr1}, @var{expr2}, @dots{}
14499 Evaluate the given expressions when the tracepoint is hit. This
14500 command accepts a comma-separated list of expressions. The results
14501 are discarded, so this is mainly useful for assigning values to trace
14502 state variables (@pxref{Trace State Variables}) without adding those
14503 values to the trace buffer, as would be the case if the @code{collect}
14504 action were used.
14505
14506 @kindex while-stepping @r{(tracepoints)}
14507 @item while-stepping @var{n}
14508 Perform @var{n} single-step instruction traces after the tracepoint,
14509 collecting new data after each step. The @code{while-stepping}
14510 command is followed by the list of what to collect while stepping
14511 (followed by its own @code{end} command):
14512
14513 @smallexample
14514 > while-stepping 12
14515 > collect $regs, myglobal
14516 > end
14517 >
14518 @end smallexample
14519
14520 @noindent
14521 Note that @code{$pc} is not automatically collected by
14522 @code{while-stepping}; you need to explicitly collect that register if
14523 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14524 @code{stepping}.
14525
14526 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14527 @kindex set default-collect
14528 @cindex default collection action
14529 This variable is a list of expressions to collect at each tracepoint
14530 hit. It is effectively an additional @code{collect} action prepended
14531 to every tracepoint action list. The expressions are parsed
14532 individually for each tracepoint, so for instance a variable named
14533 @code{xyz} may be interpreted as a global for one tracepoint, and a
14534 local for another, as appropriate to the tracepoint's location.
14535
14536 @item show default-collect
14537 @kindex show default-collect
14538 Show the list of expressions that are collected by default at each
14539 tracepoint hit.
14540
14541 @end table
14542
14543 @node Listing Tracepoints
14544 @subsection Listing Tracepoints
14545
14546 @table @code
14547 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14548 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14549 @cindex information about tracepoints
14550 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14551 Display information about the tracepoint @var{num}. If you don't
14552 specify a tracepoint number, displays information about all the
14553 tracepoints defined so far. The format is similar to that used for
14554 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14555 command, simply restricting itself to tracepoints.
14556
14557 A tracepoint's listing may include additional information specific to
14558 tracing:
14559
14560 @itemize @bullet
14561 @item
14562 its passcount as given by the @code{passcount @var{n}} command
14563
14564 @item
14565 the state about installed on target of each location
14566 @end itemize
14567
14568 @smallexample
14569 (@value{GDBP}) @b{info trace}
14570 Num Type Disp Enb Address What
14571 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14572 while-stepping 20
14573 collect globfoo, $regs
14574 end
14575 collect globfoo2
14576 end
14577 pass count 1200
14578 2 tracepoint keep y <MULTIPLE>
14579 collect $eip
14580 2.1 y 0x0804859c in func4 at change-loc.h:35
14581 installed on target
14582 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14583 installed on target
14584 2.3 y <PENDING> set_tracepoint
14585 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14586 not installed on target
14587 (@value{GDBP})
14588 @end smallexample
14589
14590 @noindent
14591 This command can be abbreviated @code{info tp}.
14592 @end table
14593
14594 @node Listing Static Tracepoint Markers
14595 @subsection Listing Static Tracepoint Markers
14596
14597 @table @code
14598 @kindex info static-tracepoint-markers
14599 @cindex information about static tracepoint markers
14600 @item info static-tracepoint-markers
14601 Display information about all static tracepoint markers defined in the
14602 program.
14603
14604 For each marker, the following columns are printed:
14605
14606 @table @emph
14607 @item Count
14608 An incrementing counter, output to help readability. This is not a
14609 stable identifier.
14610 @item ID
14611 The marker ID, as reported by the target.
14612 @item Enabled or Disabled
14613 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14614 that are not enabled.
14615 @item Address
14616 Where the marker is in your program, as a memory address.
14617 @item What
14618 Where the marker is in the source for your program, as a file and line
14619 number. If the debug information included in the program does not
14620 allow @value{GDBN} to locate the source of the marker, this column
14621 will be left blank.
14622 @end table
14623
14624 @noindent
14625 In addition, the following information may be printed for each marker:
14626
14627 @table @emph
14628 @item Data
14629 User data passed to the tracing library by the marker call. In the
14630 UST backend, this is the format string passed as argument to the
14631 marker call.
14632 @item Static tracepoints probing the marker
14633 The list of static tracepoints attached to the marker.
14634 @end table
14635
14636 @smallexample
14637 (@value{GDBP}) info static-tracepoint-markers
14638 Cnt ID Enb Address What
14639 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14640 Data: number1 %d number2 %d
14641 Probed by static tracepoints: #2
14642 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14643 Data: str %s
14644 (@value{GDBP})
14645 @end smallexample
14646 @end table
14647
14648 @node Starting and Stopping Trace Experiments
14649 @subsection Starting and Stopping Trace Experiments
14650
14651 @table @code
14652 @kindex tstart [ @var{notes} ]
14653 @cindex start a new trace experiment
14654 @cindex collected data discarded
14655 @item tstart
14656 This command starts the trace experiment, and begins collecting data.
14657 It has the side effect of discarding all the data collected in the
14658 trace buffer during the previous trace experiment. If any arguments
14659 are supplied, they are taken as a note and stored with the trace
14660 experiment's state. The notes may be arbitrary text, and are
14661 especially useful with disconnected tracing in a multi-user context;
14662 the notes can explain what the trace is doing, supply user contact
14663 information, and so forth.
14664
14665 @kindex tstop [ @var{notes} ]
14666 @cindex stop a running trace experiment
14667 @item tstop
14668 This command stops the trace experiment. If any arguments are
14669 supplied, they are recorded with the experiment as a note. This is
14670 useful if you are stopping a trace started by someone else, for
14671 instance if the trace is interfering with the system's behavior and
14672 needs to be stopped quickly.
14673
14674 @strong{Note}: a trace experiment and data collection may stop
14675 automatically if any tracepoint's passcount is reached
14676 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14677
14678 @kindex tstatus
14679 @cindex status of trace data collection
14680 @cindex trace experiment, status of
14681 @item tstatus
14682 This command displays the status of the current trace data
14683 collection.
14684 @end table
14685
14686 Here is an example of the commands we described so far:
14687
14688 @smallexample
14689 (@value{GDBP}) @b{trace gdb_c_test}
14690 (@value{GDBP}) @b{actions}
14691 Enter actions for tracepoint #1, one per line.
14692 > collect $regs,$locals,$args
14693 > while-stepping 11
14694 > collect $regs
14695 > end
14696 > end
14697 (@value{GDBP}) @b{tstart}
14698 [time passes @dots{}]
14699 (@value{GDBP}) @b{tstop}
14700 @end smallexample
14701
14702 @anchor{disconnected tracing}
14703 @cindex disconnected tracing
14704 You can choose to continue running the trace experiment even if
14705 @value{GDBN} disconnects from the target, voluntarily or
14706 involuntarily. For commands such as @code{detach}, the debugger will
14707 ask what you want to do with the trace. But for unexpected
14708 terminations (@value{GDBN} crash, network outage), it would be
14709 unfortunate to lose hard-won trace data, so the variable
14710 @code{disconnected-tracing} lets you decide whether the trace should
14711 continue running without @value{GDBN}.
14712
14713 @table @code
14714 @item set disconnected-tracing on
14715 @itemx set disconnected-tracing off
14716 @kindex set disconnected-tracing
14717 Choose whether a tracing run should continue to run if @value{GDBN}
14718 has disconnected from the target. Note that @code{detach} or
14719 @code{quit} will ask you directly what to do about a running trace no
14720 matter what this variable's setting, so the variable is mainly useful
14721 for handling unexpected situations, such as loss of the network.
14722
14723 @item show disconnected-tracing
14724 @kindex show disconnected-tracing
14725 Show the current choice for disconnected tracing.
14726
14727 @end table
14728
14729 When you reconnect to the target, the trace experiment may or may not
14730 still be running; it might have filled the trace buffer in the
14731 meantime, or stopped for one of the other reasons. If it is running,
14732 it will continue after reconnection.
14733
14734 Upon reconnection, the target will upload information about the
14735 tracepoints in effect. @value{GDBN} will then compare that
14736 information to the set of tracepoints currently defined, and attempt
14737 to match them up, allowing for the possibility that the numbers may
14738 have changed due to creation and deletion in the meantime. If one of
14739 the target's tracepoints does not match any in @value{GDBN}, the
14740 debugger will create a new tracepoint, so that you have a number with
14741 which to specify that tracepoint. This matching-up process is
14742 necessarily heuristic, and it may result in useless tracepoints being
14743 created; you may simply delete them if they are of no use.
14744
14745 @cindex circular trace buffer
14746 If your target agent supports a @dfn{circular trace buffer}, then you
14747 can run a trace experiment indefinitely without filling the trace
14748 buffer; when space runs out, the agent deletes already-collected trace
14749 frames, oldest first, until there is enough room to continue
14750 collecting. This is especially useful if your tracepoints are being
14751 hit too often, and your trace gets terminated prematurely because the
14752 buffer is full. To ask for a circular trace buffer, simply set
14753 @samp{circular-trace-buffer} to on. You can set this at any time,
14754 including during tracing; if the agent can do it, it will change
14755 buffer handling on the fly, otherwise it will not take effect until
14756 the next run.
14757
14758 @table @code
14759 @item set circular-trace-buffer on
14760 @itemx set circular-trace-buffer off
14761 @kindex set circular-trace-buffer
14762 Choose whether a tracing run should use a linear or circular buffer
14763 for trace data. A linear buffer will not lose any trace data, but may
14764 fill up prematurely, while a circular buffer will discard old trace
14765 data, but it will have always room for the latest tracepoint hits.
14766
14767 @item show circular-trace-buffer
14768 @kindex show circular-trace-buffer
14769 Show the current choice for the trace buffer. Note that this may not
14770 match the agent's current buffer handling, nor is it guaranteed to
14771 match the setting that might have been in effect during a past run,
14772 for instance if you are looking at frames from a trace file.
14773
14774 @end table
14775
14776 @table @code
14777 @item set trace-buffer-size @var{n}
14778 @itemx set trace-buffer-size unlimited
14779 @kindex set trace-buffer-size
14780 Request that the target use a trace buffer of @var{n} bytes. Not all
14781 targets will honor the request; they may have a compiled-in size for
14782 the trace buffer, or some other limitation. Set to a value of
14783 @code{unlimited} or @code{-1} to let the target use whatever size it
14784 likes. This is also the default.
14785
14786 @item show trace-buffer-size
14787 @kindex show trace-buffer-size
14788 Show the current requested size for the trace buffer. Note that this
14789 will only match the actual size if the target supports size-setting,
14790 and was able to handle the requested size. For instance, if the
14791 target can only change buffer size between runs, this variable will
14792 not reflect the change until the next run starts. Use @code{tstatus}
14793 to get a report of the actual buffer size.
14794 @end table
14795
14796 @table @code
14797 @item set trace-user @var{text}
14798 @kindex set trace-user
14799
14800 @item show trace-user
14801 @kindex show trace-user
14802
14803 @item set trace-notes @var{text}
14804 @kindex set trace-notes
14805 Set the trace run's notes.
14806
14807 @item show trace-notes
14808 @kindex show trace-notes
14809 Show the trace run's notes.
14810
14811 @item set trace-stop-notes @var{text}
14812 @kindex set trace-stop-notes
14813 Set the trace run's stop notes. The handling of the note is as for
14814 @code{tstop} arguments; the set command is convenient way to fix a
14815 stop note that is mistaken or incomplete.
14816
14817 @item show trace-stop-notes
14818 @kindex show trace-stop-notes
14819 Show the trace run's stop notes.
14820
14821 @end table
14822
14823 @node Tracepoint Restrictions
14824 @subsection Tracepoint Restrictions
14825
14826 @cindex tracepoint restrictions
14827 There are a number of restrictions on the use of tracepoints. As
14828 described above, tracepoint data gathering occurs on the target
14829 without interaction from @value{GDBN}. Thus the full capabilities of
14830 the debugger are not available during data gathering, and then at data
14831 examination time, you will be limited by only having what was
14832 collected. The following items describe some common problems, but it
14833 is not exhaustive, and you may run into additional difficulties not
14834 mentioned here.
14835
14836 @itemize @bullet
14837
14838 @item
14839 Tracepoint expressions are intended to gather objects (lvalues). Thus
14840 the full flexibility of GDB's expression evaluator is not available.
14841 You cannot call functions, cast objects to aggregate types, access
14842 convenience variables or modify values (except by assignment to trace
14843 state variables). Some language features may implicitly call
14844 functions (for instance Objective-C fields with accessors), and therefore
14845 cannot be collected either.
14846
14847 @item
14848 Collection of local variables, either individually or in bulk with
14849 @code{$locals} or @code{$args}, during @code{while-stepping} may
14850 behave erratically. The stepping action may enter a new scope (for
14851 instance by stepping into a function), or the location of the variable
14852 may change (for instance it is loaded into a register). The
14853 tracepoint data recorded uses the location information for the
14854 variables that is correct for the tracepoint location. When the
14855 tracepoint is created, it is not possible, in general, to determine
14856 where the steps of a @code{while-stepping} sequence will advance the
14857 program---particularly if a conditional branch is stepped.
14858
14859 @item
14860 Collection of an incompletely-initialized or partially-destroyed object
14861 may result in something that @value{GDBN} cannot display, or displays
14862 in a misleading way.
14863
14864 @item
14865 When @value{GDBN} displays a pointer to character it automatically
14866 dereferences the pointer to also display characters of the string
14867 being pointed to. However, collecting the pointer during tracing does
14868 not automatically collect the string. You need to explicitly
14869 dereference the pointer and provide size information if you want to
14870 collect not only the pointer, but the memory pointed to. For example,
14871 @code{*ptr@@50} can be used to collect the 50 element array pointed to
14872 by @code{ptr}.
14873
14874 @item
14875 It is not possible to collect a complete stack backtrace at a
14876 tracepoint. Instead, you may collect the registers and a few hundred
14877 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
14878 (adjust to use the name of the actual stack pointer register on your
14879 target architecture, and the amount of stack you wish to capture).
14880 Then the @code{backtrace} command will show a partial backtrace when
14881 using a trace frame. The number of stack frames that can be examined
14882 depends on the sizes of the frames in the collected stack. Note that
14883 if you ask for a block so large that it goes past the bottom of the
14884 stack, the target agent may report an error trying to read from an
14885 invalid address.
14886
14887 @item
14888 If you do not collect registers at a tracepoint, @value{GDBN} can
14889 infer that the value of @code{$pc} must be the same as the address of
14890 the tracepoint and use that when you are looking at a trace frame
14891 for that tracepoint. However, this cannot work if the tracepoint has
14892 multiple locations (for instance if it was set in a function that was
14893 inlined), or if it has a @code{while-stepping} loop. In those cases
14894 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
14895 it to zero.
14896
14897 @end itemize
14898
14899 @node Analyze Collected Data
14900 @section Using the Collected Data
14901
14902 After the tracepoint experiment ends, you use @value{GDBN} commands
14903 for examining the trace data. The basic idea is that each tracepoint
14904 collects a trace @dfn{snapshot} every time it is hit and another
14905 snapshot every time it single-steps. All these snapshots are
14906 consecutively numbered from zero and go into a buffer, and you can
14907 examine them later. The way you examine them is to @dfn{focus} on a
14908 specific trace snapshot. When the remote stub is focused on a trace
14909 snapshot, it will respond to all @value{GDBN} requests for memory and
14910 registers by reading from the buffer which belongs to that snapshot,
14911 rather than from @emph{real} memory or registers of the program being
14912 debugged. This means that @strong{all} @value{GDBN} commands
14913 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
14914 behave as if we were currently debugging the program state as it was
14915 when the tracepoint occurred. Any requests for data that are not in
14916 the buffer will fail.
14917
14918 @menu
14919 * tfind:: How to select a trace snapshot
14920 * tdump:: How to display all data for a snapshot
14921 * save tracepoints:: How to save tracepoints for a future run
14922 @end menu
14923
14924 @node tfind
14925 @subsection @code{tfind @var{n}}
14926
14927 @kindex tfind
14928 @cindex select trace snapshot
14929 @cindex find trace snapshot
14930 The basic command for selecting a trace snapshot from the buffer is
14931 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
14932 counting from zero. If no argument @var{n} is given, the next
14933 snapshot is selected.
14934
14935 Here are the various forms of using the @code{tfind} command.
14936
14937 @table @code
14938 @item tfind start
14939 Find the first snapshot in the buffer. This is a synonym for
14940 @code{tfind 0} (since 0 is the number of the first snapshot).
14941
14942 @item tfind none
14943 Stop debugging trace snapshots, resume @emph{live} debugging.
14944
14945 @item tfind end
14946 Same as @samp{tfind none}.
14947
14948 @item tfind
14949 No argument means find the next trace snapshot or find the first
14950 one if no trace snapshot is selected.
14951
14952 @item tfind -
14953 Find the previous trace snapshot before the current one. This permits
14954 retracing earlier steps.
14955
14956 @item tfind tracepoint @var{num}
14957 Find the next snapshot associated with tracepoint @var{num}. Search
14958 proceeds forward from the last examined trace snapshot. If no
14959 argument @var{num} is given, it means find the next snapshot collected
14960 for the same tracepoint as the current snapshot.
14961
14962 @item tfind pc @var{addr}
14963 Find the next snapshot associated with the value @var{addr} of the
14964 program counter. Search proceeds forward from the last examined trace
14965 snapshot. If no argument @var{addr} is given, it means find the next
14966 snapshot with the same value of PC as the current snapshot.
14967
14968 @item tfind outside @var{addr1}, @var{addr2}
14969 Find the next snapshot whose PC is outside the given range of
14970 addresses (exclusive).
14971
14972 @item tfind range @var{addr1}, @var{addr2}
14973 Find the next snapshot whose PC is between @var{addr1} and
14974 @var{addr2} (inclusive).
14975
14976 @item tfind line @r{[}@var{file}:@r{]}@var{n}
14977 Find the next snapshot associated with the source line @var{n}. If
14978 the optional argument @var{file} is given, refer to line @var{n} in
14979 that source file. Search proceeds forward from the last examined
14980 trace snapshot. If no argument @var{n} is given, it means find the
14981 next line other than the one currently being examined; thus saying
14982 @code{tfind line} repeatedly can appear to have the same effect as
14983 stepping from line to line in a @emph{live} debugging session.
14984 @end table
14985
14986 The default arguments for the @code{tfind} commands are specifically
14987 designed to make it easy to scan through the trace buffer. For
14988 instance, @code{tfind} with no argument selects the next trace
14989 snapshot, and @code{tfind -} with no argument selects the previous
14990 trace snapshot. So, by giving one @code{tfind} command, and then
14991 simply hitting @key{RET} repeatedly you can examine all the trace
14992 snapshots in order. Or, by saying @code{tfind -} and then hitting
14993 @key{RET} repeatedly you can examine the snapshots in reverse order.
14994 The @code{tfind line} command with no argument selects the snapshot
14995 for the next source line executed. The @code{tfind pc} command with
14996 no argument selects the next snapshot with the same program counter
14997 (PC) as the current frame. The @code{tfind tracepoint} command with
14998 no argument selects the next trace snapshot collected by the same
14999 tracepoint as the current one.
15000
15001 In addition to letting you scan through the trace buffer manually,
15002 these commands make it easy to construct @value{GDBN} scripts that
15003 scan through the trace buffer and print out whatever collected data
15004 you are interested in. Thus, if we want to examine the PC, FP, and SP
15005 registers from each trace frame in the buffer, we can say this:
15006
15007 @smallexample
15008 (@value{GDBP}) @b{tfind start}
15009 (@value{GDBP}) @b{while ($trace_frame != -1)}
15010 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15011 $trace_frame, $pc, $sp, $fp
15012 > tfind
15013 > end
15014
15015 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15016 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15017 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15018 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15019 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15020 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15021 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15022 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15023 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15024 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15025 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15026 @end smallexample
15027
15028 Or, if we want to examine the variable @code{X} at each source line in
15029 the buffer:
15030
15031 @smallexample
15032 (@value{GDBP}) @b{tfind start}
15033 (@value{GDBP}) @b{while ($trace_frame != -1)}
15034 > printf "Frame %d, X == %d\n", $trace_frame, X
15035 > tfind line
15036 > end
15037
15038 Frame 0, X = 1
15039 Frame 7, X = 2
15040 Frame 13, X = 255
15041 @end smallexample
15042
15043 @node tdump
15044 @subsection @code{tdump}
15045 @kindex tdump
15046 @cindex dump all data collected at tracepoint
15047 @cindex tracepoint data, display
15048
15049 This command takes no arguments. It prints all the data collected at
15050 the current trace snapshot.
15051
15052 @smallexample
15053 (@value{GDBP}) @b{trace 444}
15054 (@value{GDBP}) @b{actions}
15055 Enter actions for tracepoint #2, one per line:
15056 > collect $regs, $locals, $args, gdb_long_test
15057 > end
15058
15059 (@value{GDBP}) @b{tstart}
15060
15061 (@value{GDBP}) @b{tfind line 444}
15062 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15063 at gdb_test.c:444
15064 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15065
15066 (@value{GDBP}) @b{tdump}
15067 Data collected at tracepoint 2, trace frame 1:
15068 d0 0xc4aa0085 -995491707
15069 d1 0x18 24
15070 d2 0x80 128
15071 d3 0x33 51
15072 d4 0x71aea3d 119204413
15073 d5 0x22 34
15074 d6 0xe0 224
15075 d7 0x380035 3670069
15076 a0 0x19e24a 1696330
15077 a1 0x3000668 50333288
15078 a2 0x100 256
15079 a3 0x322000 3284992
15080 a4 0x3000698 50333336
15081 a5 0x1ad3cc 1758156
15082 fp 0x30bf3c 0x30bf3c
15083 sp 0x30bf34 0x30bf34
15084 ps 0x0 0
15085 pc 0x20b2c8 0x20b2c8
15086 fpcontrol 0x0 0
15087 fpstatus 0x0 0
15088 fpiaddr 0x0 0
15089 p = 0x20e5b4 "gdb-test"
15090 p1 = (void *) 0x11
15091 p2 = (void *) 0x22
15092 p3 = (void *) 0x33
15093 p4 = (void *) 0x44
15094 p5 = (void *) 0x55
15095 p6 = (void *) 0x66
15096 gdb_long_test = 17 '\021'
15097
15098 (@value{GDBP})
15099 @end smallexample
15100
15101 @code{tdump} works by scanning the tracepoint's current collection
15102 actions and printing the value of each expression listed. So
15103 @code{tdump} can fail, if after a run, you change the tracepoint's
15104 actions to mention variables that were not collected during the run.
15105
15106 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15107 uses the collected value of @code{$pc} to distinguish between trace
15108 frames that were collected at the tracepoint hit, and frames that were
15109 collected while stepping. This allows it to correctly choose whether
15110 to display the basic list of collections, or the collections from the
15111 body of the while-stepping loop. However, if @code{$pc} was not collected,
15112 then @code{tdump} will always attempt to dump using the basic collection
15113 list, and may fail if a while-stepping frame does not include all the
15114 same data that is collected at the tracepoint hit.
15115 @c This is getting pretty arcane, example would be good.
15116
15117 @node save tracepoints
15118 @subsection @code{save tracepoints @var{filename}}
15119 @kindex save tracepoints
15120 @kindex save-tracepoints
15121 @cindex save tracepoints for future sessions
15122
15123 This command saves all current tracepoint definitions together with
15124 their actions and passcounts, into a file @file{@var{filename}}
15125 suitable for use in a later debugging session. To read the saved
15126 tracepoint definitions, use the @code{source} command (@pxref{Command
15127 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15128 alias for @w{@code{save tracepoints}}
15129
15130 @node Tracepoint Variables
15131 @section Convenience Variables for Tracepoints
15132 @cindex tracepoint variables
15133 @cindex convenience variables for tracepoints
15134
15135 @table @code
15136 @vindex $trace_frame
15137 @item (int) $trace_frame
15138 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15139 snapshot is selected.
15140
15141 @vindex $tracepoint
15142 @item (int) $tracepoint
15143 The tracepoint for the current trace snapshot.
15144
15145 @vindex $trace_line
15146 @item (int) $trace_line
15147 The line number for the current trace snapshot.
15148
15149 @vindex $trace_file
15150 @item (char []) $trace_file
15151 The source file for the current trace snapshot.
15152
15153 @vindex $trace_func
15154 @item (char []) $trace_func
15155 The name of the function containing @code{$tracepoint}.
15156 @end table
15157
15158 Note: @code{$trace_file} is not suitable for use in @code{printf},
15159 use @code{output} instead.
15160
15161 Here's a simple example of using these convenience variables for
15162 stepping through all the trace snapshots and printing some of their
15163 data. Note that these are not the same as trace state variables,
15164 which are managed by the target.
15165
15166 @smallexample
15167 (@value{GDBP}) @b{tfind start}
15168
15169 (@value{GDBP}) @b{while $trace_frame != -1}
15170 > output $trace_file
15171 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15172 > tfind
15173 > end
15174 @end smallexample
15175
15176 @node Trace Files
15177 @section Using Trace Files
15178 @cindex trace files
15179
15180 In some situations, the target running a trace experiment may no
15181 longer be available; perhaps it crashed, or the hardware was needed
15182 for a different activity. To handle these cases, you can arrange to
15183 dump the trace data into a file, and later use that file as a source
15184 of trace data, via the @code{target tfile} command.
15185
15186 @table @code
15187
15188 @kindex tsave
15189 @item tsave [ -r ] @var{filename}
15190 @itemx tsave [-ctf] @var{dirname}
15191 Save the trace data to @var{filename}. By default, this command
15192 assumes that @var{filename} refers to the host filesystem, so if
15193 necessary @value{GDBN} will copy raw trace data up from the target and
15194 then save it. If the target supports it, you can also supply the
15195 optional argument @code{-r} (``remote'') to direct the target to save
15196 the data directly into @var{filename} in its own filesystem, which may be
15197 more efficient if the trace buffer is very large. (Note, however, that
15198 @code{target tfile} can only read from files accessible to the host.)
15199 By default, this command will save trace frame in tfile format.
15200 You can supply the optional argument @code{-ctf} to save data in CTF
15201 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15202 that can be shared by multiple debugging and tracing tools. Please go to
15203 @indicateurl{http://www.efficios.com/ctf} to get more information.
15204
15205 @kindex target tfile
15206 @kindex tfile
15207 @kindex target ctf
15208 @kindex ctf
15209 @item target tfile @var{filename}
15210 @itemx target ctf @var{dirname}
15211 Use the file named @var{filename} or directory named @var{dirname} as
15212 a source of trace data. Commands that examine data work as they do with
15213 a live target, but it is not possible to run any new trace experiments.
15214 @code{tstatus} will report the state of the trace run at the moment
15215 the data was saved, as well as the current trace frame you are examining.
15216 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15217 the host.
15218
15219 @smallexample
15220 (@value{GDBP}) target ctf ctf.ctf
15221 (@value{GDBP}) tfind
15222 Found trace frame 0, tracepoint 2
15223 39 ++a; /* set tracepoint 1 here */
15224 (@value{GDBP}) tdump
15225 Data collected at tracepoint 2, trace frame 0:
15226 i = 0
15227 a = 0
15228 b = 1 '\001'
15229 c = @{"123", "456", "789", "123", "456", "789"@}
15230 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15231 (@value{GDBP}) p b
15232 $1 = 1
15233 @end smallexample
15234
15235 @end table
15236
15237 @node Overlays
15238 @chapter Debugging Programs That Use Overlays
15239 @cindex overlays
15240
15241 If your program is too large to fit completely in your target system's
15242 memory, you can sometimes use @dfn{overlays} to work around this
15243 problem. @value{GDBN} provides some support for debugging programs that
15244 use overlays.
15245
15246 @menu
15247 * How Overlays Work:: A general explanation of overlays.
15248 * Overlay Commands:: Managing overlays in @value{GDBN}.
15249 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15250 mapped by asking the inferior.
15251 * Overlay Sample Program:: A sample program using overlays.
15252 @end menu
15253
15254 @node How Overlays Work
15255 @section How Overlays Work
15256 @cindex mapped overlays
15257 @cindex unmapped overlays
15258 @cindex load address, overlay's
15259 @cindex mapped address
15260 @cindex overlay area
15261
15262 Suppose you have a computer whose instruction address space is only 64
15263 kilobytes long, but which has much more memory which can be accessed by
15264 other means: special instructions, segment registers, or memory
15265 management hardware, for example. Suppose further that you want to
15266 adapt a program which is larger than 64 kilobytes to run on this system.
15267
15268 One solution is to identify modules of your program which are relatively
15269 independent, and need not call each other directly; call these modules
15270 @dfn{overlays}. Separate the overlays from the main program, and place
15271 their machine code in the larger memory. Place your main program in
15272 instruction memory, but leave at least enough space there to hold the
15273 largest overlay as well.
15274
15275 Now, to call a function located in an overlay, you must first copy that
15276 overlay's machine code from the large memory into the space set aside
15277 for it in the instruction memory, and then jump to its entry point
15278 there.
15279
15280 @c NB: In the below the mapped area's size is greater or equal to the
15281 @c size of all overlays. This is intentional to remind the developer
15282 @c that overlays don't necessarily need to be the same size.
15283
15284 @smallexample
15285 @group
15286 Data Instruction Larger
15287 Address Space Address Space Address Space
15288 +-----------+ +-----------+ +-----------+
15289 | | | | | |
15290 +-----------+ +-----------+ +-----------+<-- overlay 1
15291 | program | | main | .----| overlay 1 | load address
15292 | variables | | program | | +-----------+
15293 | and heap | | | | | |
15294 +-----------+ | | | +-----------+<-- overlay 2
15295 | | +-----------+ | | | load address
15296 +-----------+ | | | .-| overlay 2 |
15297 | | | | | |
15298 mapped --->+-----------+ | | +-----------+
15299 address | | | | | |
15300 | overlay | <-' | | |
15301 | area | <---' +-----------+<-- overlay 3
15302 | | <---. | | load address
15303 +-----------+ `--| overlay 3 |
15304 | | | |
15305 +-----------+ | |
15306 +-----------+
15307 | |
15308 +-----------+
15309
15310 @anchor{A code overlay}A code overlay
15311 @end group
15312 @end smallexample
15313
15314 The diagram (@pxref{A code overlay}) shows a system with separate data
15315 and instruction address spaces. To map an overlay, the program copies
15316 its code from the larger address space to the instruction address space.
15317 Since the overlays shown here all use the same mapped address, only one
15318 may be mapped at a time. For a system with a single address space for
15319 data and instructions, the diagram would be similar, except that the
15320 program variables and heap would share an address space with the main
15321 program and the overlay area.
15322
15323 An overlay loaded into instruction memory and ready for use is called a
15324 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15325 instruction memory. An overlay not present (or only partially present)
15326 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15327 is its address in the larger memory. The mapped address is also called
15328 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15329 called the @dfn{load memory address}, or @dfn{LMA}.
15330
15331 Unfortunately, overlays are not a completely transparent way to adapt a
15332 program to limited instruction memory. They introduce a new set of
15333 global constraints you must keep in mind as you design your program:
15334
15335 @itemize @bullet
15336
15337 @item
15338 Before calling or returning to a function in an overlay, your program
15339 must make sure that overlay is actually mapped. Otherwise, the call or
15340 return will transfer control to the right address, but in the wrong
15341 overlay, and your program will probably crash.
15342
15343 @item
15344 If the process of mapping an overlay is expensive on your system, you
15345 will need to choose your overlays carefully to minimize their effect on
15346 your program's performance.
15347
15348 @item
15349 The executable file you load onto your system must contain each
15350 overlay's instructions, appearing at the overlay's load address, not its
15351 mapped address. However, each overlay's instructions must be relocated
15352 and its symbols defined as if the overlay were at its mapped address.
15353 You can use GNU linker scripts to specify different load and relocation
15354 addresses for pieces of your program; see @ref{Overlay Description,,,
15355 ld.info, Using ld: the GNU linker}.
15356
15357 @item
15358 The procedure for loading executable files onto your system must be able
15359 to load their contents into the larger address space as well as the
15360 instruction and data spaces.
15361
15362 @end itemize
15363
15364 The overlay system described above is rather simple, and could be
15365 improved in many ways:
15366
15367 @itemize @bullet
15368
15369 @item
15370 If your system has suitable bank switch registers or memory management
15371 hardware, you could use those facilities to make an overlay's load area
15372 contents simply appear at their mapped address in instruction space.
15373 This would probably be faster than copying the overlay to its mapped
15374 area in the usual way.
15375
15376 @item
15377 If your overlays are small enough, you could set aside more than one
15378 overlay area, and have more than one overlay mapped at a time.
15379
15380 @item
15381 You can use overlays to manage data, as well as instructions. In
15382 general, data overlays are even less transparent to your design than
15383 code overlays: whereas code overlays only require care when you call or
15384 return to functions, data overlays require care every time you access
15385 the data. Also, if you change the contents of a data overlay, you
15386 must copy its contents back out to its load address before you can copy a
15387 different data overlay into the same mapped area.
15388
15389 @end itemize
15390
15391
15392 @node Overlay Commands
15393 @section Overlay Commands
15394
15395 To use @value{GDBN}'s overlay support, each overlay in your program must
15396 correspond to a separate section of the executable file. The section's
15397 virtual memory address and load memory address must be the overlay's
15398 mapped and load addresses. Identifying overlays with sections allows
15399 @value{GDBN} to determine the appropriate address of a function or
15400 variable, depending on whether the overlay is mapped or not.
15401
15402 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15403 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15404
15405 @table @code
15406 @item overlay off
15407 @kindex overlay
15408 Disable @value{GDBN}'s overlay support. When overlay support is
15409 disabled, @value{GDBN} assumes that all functions and variables are
15410 always present at their mapped addresses. By default, @value{GDBN}'s
15411 overlay support is disabled.
15412
15413 @item overlay manual
15414 @cindex manual overlay debugging
15415 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15416 relies on you to tell it which overlays are mapped, and which are not,
15417 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15418 commands described below.
15419
15420 @item overlay map-overlay @var{overlay}
15421 @itemx overlay map @var{overlay}
15422 @cindex map an overlay
15423 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15424 be the name of the object file section containing the overlay. When an
15425 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15426 functions and variables at their mapped addresses. @value{GDBN} assumes
15427 that any other overlays whose mapped ranges overlap that of
15428 @var{overlay} are now unmapped.
15429
15430 @item overlay unmap-overlay @var{overlay}
15431 @itemx overlay unmap @var{overlay}
15432 @cindex unmap an overlay
15433 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15434 must be the name of the object file section containing the overlay.
15435 When an overlay is unmapped, @value{GDBN} assumes it can find the
15436 overlay's functions and variables at their load addresses.
15437
15438 @item overlay auto
15439 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15440 consults a data structure the overlay manager maintains in the inferior
15441 to see which overlays are mapped. For details, see @ref{Automatic
15442 Overlay Debugging}.
15443
15444 @item overlay load-target
15445 @itemx overlay load
15446 @cindex reloading the overlay table
15447 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15448 re-reads the table @value{GDBN} automatically each time the inferior
15449 stops, so this command should only be necessary if you have changed the
15450 overlay mapping yourself using @value{GDBN}. This command is only
15451 useful when using automatic overlay debugging.
15452
15453 @item overlay list-overlays
15454 @itemx overlay list
15455 @cindex listing mapped overlays
15456 Display a list of the overlays currently mapped, along with their mapped
15457 addresses, load addresses, and sizes.
15458
15459 @end table
15460
15461 Normally, when @value{GDBN} prints a code address, it includes the name
15462 of the function the address falls in:
15463
15464 @smallexample
15465 (@value{GDBP}) print main
15466 $3 = @{int ()@} 0x11a0 <main>
15467 @end smallexample
15468 @noindent
15469 When overlay debugging is enabled, @value{GDBN} recognizes code in
15470 unmapped overlays, and prints the names of unmapped functions with
15471 asterisks around them. For example, if @code{foo} is a function in an
15472 unmapped overlay, @value{GDBN} prints it this way:
15473
15474 @smallexample
15475 (@value{GDBP}) overlay list
15476 No sections are mapped.
15477 (@value{GDBP}) print foo
15478 $5 = @{int (int)@} 0x100000 <*foo*>
15479 @end smallexample
15480 @noindent
15481 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15482 name normally:
15483
15484 @smallexample
15485 (@value{GDBP}) overlay list
15486 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15487 mapped at 0x1016 - 0x104a
15488 (@value{GDBP}) print foo
15489 $6 = @{int (int)@} 0x1016 <foo>
15490 @end smallexample
15491
15492 When overlay debugging is enabled, @value{GDBN} can find the correct
15493 address for functions and variables in an overlay, whether or not the
15494 overlay is mapped. This allows most @value{GDBN} commands, like
15495 @code{break} and @code{disassemble}, to work normally, even on unmapped
15496 code. However, @value{GDBN}'s breakpoint support has some limitations:
15497
15498 @itemize @bullet
15499 @item
15500 @cindex breakpoints in overlays
15501 @cindex overlays, setting breakpoints in
15502 You can set breakpoints in functions in unmapped overlays, as long as
15503 @value{GDBN} can write to the overlay at its load address.
15504 @item
15505 @value{GDBN} can not set hardware or simulator-based breakpoints in
15506 unmapped overlays. However, if you set a breakpoint at the end of your
15507 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15508 you are using manual overlay management), @value{GDBN} will re-set its
15509 breakpoints properly.
15510 @end itemize
15511
15512
15513 @node Automatic Overlay Debugging
15514 @section Automatic Overlay Debugging
15515 @cindex automatic overlay debugging
15516
15517 @value{GDBN} can automatically track which overlays are mapped and which
15518 are not, given some simple co-operation from the overlay manager in the
15519 inferior. If you enable automatic overlay debugging with the
15520 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15521 looks in the inferior's memory for certain variables describing the
15522 current state of the overlays.
15523
15524 Here are the variables your overlay manager must define to support
15525 @value{GDBN}'s automatic overlay debugging:
15526
15527 @table @asis
15528
15529 @item @code{_ovly_table}:
15530 This variable must be an array of the following structures:
15531
15532 @smallexample
15533 struct
15534 @{
15535 /* The overlay's mapped address. */
15536 unsigned long vma;
15537
15538 /* The size of the overlay, in bytes. */
15539 unsigned long size;
15540
15541 /* The overlay's load address. */
15542 unsigned long lma;
15543
15544 /* Non-zero if the overlay is currently mapped;
15545 zero otherwise. */
15546 unsigned long mapped;
15547 @}
15548 @end smallexample
15549
15550 @item @code{_novlys}:
15551 This variable must be a four-byte signed integer, holding the total
15552 number of elements in @code{_ovly_table}.
15553
15554 @end table
15555
15556 To decide whether a particular overlay is mapped or not, @value{GDBN}
15557 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15558 @code{lma} members equal the VMA and LMA of the overlay's section in the
15559 executable file. When @value{GDBN} finds a matching entry, it consults
15560 the entry's @code{mapped} member to determine whether the overlay is
15561 currently mapped.
15562
15563 In addition, your overlay manager may define a function called
15564 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15565 will silently set a breakpoint there. If the overlay manager then
15566 calls this function whenever it has changed the overlay table, this
15567 will enable @value{GDBN} to accurately keep track of which overlays
15568 are in program memory, and update any breakpoints that may be set
15569 in overlays. This will allow breakpoints to work even if the
15570 overlays are kept in ROM or other non-writable memory while they
15571 are not being executed.
15572
15573 @node Overlay Sample Program
15574 @section Overlay Sample Program
15575 @cindex overlay example program
15576
15577 When linking a program which uses overlays, you must place the overlays
15578 at their load addresses, while relocating them to run at their mapped
15579 addresses. To do this, you must write a linker script (@pxref{Overlay
15580 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15581 since linker scripts are specific to a particular host system, target
15582 architecture, and target memory layout, this manual cannot provide
15583 portable sample code demonstrating @value{GDBN}'s overlay support.
15584
15585 However, the @value{GDBN} source distribution does contain an overlaid
15586 program, with linker scripts for a few systems, as part of its test
15587 suite. The program consists of the following files from
15588 @file{gdb/testsuite/gdb.base}:
15589
15590 @table @file
15591 @item overlays.c
15592 The main program file.
15593 @item ovlymgr.c
15594 A simple overlay manager, used by @file{overlays.c}.
15595 @item foo.c
15596 @itemx bar.c
15597 @itemx baz.c
15598 @itemx grbx.c
15599 Overlay modules, loaded and used by @file{overlays.c}.
15600 @item d10v.ld
15601 @itemx m32r.ld
15602 Linker scripts for linking the test program on the @code{d10v-elf}
15603 and @code{m32r-elf} targets.
15604 @end table
15605
15606 You can build the test program using the @code{d10v-elf} GCC
15607 cross-compiler like this:
15608
15609 @smallexample
15610 $ d10v-elf-gcc -g -c overlays.c
15611 $ d10v-elf-gcc -g -c ovlymgr.c
15612 $ d10v-elf-gcc -g -c foo.c
15613 $ d10v-elf-gcc -g -c bar.c
15614 $ d10v-elf-gcc -g -c baz.c
15615 $ d10v-elf-gcc -g -c grbx.c
15616 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15617 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15618 @end smallexample
15619
15620 The build process is identical for any other architecture, except that
15621 you must substitute the appropriate compiler and linker script for the
15622 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15623
15624
15625 @node Languages
15626 @chapter Using @value{GDBN} with Different Languages
15627 @cindex languages
15628
15629 Although programming languages generally have common aspects, they are
15630 rarely expressed in the same manner. For instance, in ANSI C,
15631 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15632 Modula-2, it is accomplished by @code{p^}. Values can also be
15633 represented (and displayed) differently. Hex numbers in C appear as
15634 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15635
15636 @cindex working language
15637 Language-specific information is built into @value{GDBN} for some languages,
15638 allowing you to express operations like the above in your program's
15639 native language, and allowing @value{GDBN} to output values in a manner
15640 consistent with the syntax of your program's native language. The
15641 language you use to build expressions is called the @dfn{working
15642 language}.
15643
15644 @menu
15645 * Setting:: Switching between source languages
15646 * Show:: Displaying the language
15647 * Checks:: Type and range checks
15648 * Supported Languages:: Supported languages
15649 * Unsupported Languages:: Unsupported languages
15650 @end menu
15651
15652 @node Setting
15653 @section Switching Between Source Languages
15654
15655 There are two ways to control the working language---either have @value{GDBN}
15656 set it automatically, or select it manually yourself. You can use the
15657 @code{set language} command for either purpose. On startup, @value{GDBN}
15658 defaults to setting the language automatically. The working language is
15659 used to determine how expressions you type are interpreted, how values
15660 are printed, etc.
15661
15662 In addition to the working language, every source file that
15663 @value{GDBN} knows about has its own working language. For some object
15664 file formats, the compiler might indicate which language a particular
15665 source file is in. However, most of the time @value{GDBN} infers the
15666 language from the name of the file. The language of a source file
15667 controls whether C@t{++} names are demangled---this way @code{backtrace} can
15668 show each frame appropriately for its own language. There is no way to
15669 set the language of a source file from within @value{GDBN}, but you can
15670 set the language associated with a filename extension. @xref{Show, ,
15671 Displaying the Language}.
15672
15673 This is most commonly a problem when you use a program, such
15674 as @code{cfront} or @code{f2c}, that generates C but is written in
15675 another language. In that case, make the
15676 program use @code{#line} directives in its C output; that way
15677 @value{GDBN} will know the correct language of the source code of the original
15678 program, and will display that source code, not the generated C code.
15679
15680 @menu
15681 * Filenames:: Filename extensions and languages.
15682 * Manually:: Setting the working language manually
15683 * Automatically:: Having @value{GDBN} infer the source language
15684 @end menu
15685
15686 @node Filenames
15687 @subsection List of Filename Extensions and Languages
15688
15689 If a source file name ends in one of the following extensions, then
15690 @value{GDBN} infers that its language is the one indicated.
15691
15692 @table @file
15693 @item .ada
15694 @itemx .ads
15695 @itemx .adb
15696 @itemx .a
15697 Ada source file.
15698
15699 @item .c
15700 C source file
15701
15702 @item .C
15703 @itemx .cc
15704 @itemx .cp
15705 @itemx .cpp
15706 @itemx .cxx
15707 @itemx .c++
15708 C@t{++} source file
15709
15710 @item .d
15711 D source file
15712
15713 @item .m
15714 Objective-C source file
15715
15716 @item .f
15717 @itemx .F
15718 Fortran source file
15719
15720 @item .mod
15721 Modula-2 source file
15722
15723 @item .s
15724 @itemx .S
15725 Assembler source file. This actually behaves almost like C, but
15726 @value{GDBN} does not skip over function prologues when stepping.
15727 @end table
15728
15729 In addition, you may set the language associated with a filename
15730 extension. @xref{Show, , Displaying the Language}.
15731
15732 @node Manually
15733 @subsection Setting the Working Language
15734
15735 If you allow @value{GDBN} to set the language automatically,
15736 expressions are interpreted the same way in your debugging session and
15737 your program.
15738
15739 @kindex set language
15740 If you wish, you may set the language manually. To do this, issue the
15741 command @samp{set language @var{lang}}, where @var{lang} is the name of
15742 a language, such as
15743 @code{c} or @code{modula-2}.
15744 For a list of the supported languages, type @samp{set language}.
15745
15746 Setting the language manually prevents @value{GDBN} from updating the working
15747 language automatically. This can lead to confusion if you try
15748 to debug a program when the working language is not the same as the
15749 source language, when an expression is acceptable to both
15750 languages---but means different things. For instance, if the current
15751 source file were written in C, and @value{GDBN} was parsing Modula-2, a
15752 command such as:
15753
15754 @smallexample
15755 print a = b + c
15756 @end smallexample
15757
15758 @noindent
15759 might not have the effect you intended. In C, this means to add
15760 @code{b} and @code{c} and place the result in @code{a}. The result
15761 printed would be the value of @code{a}. In Modula-2, this means to compare
15762 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
15763
15764 @node Automatically
15765 @subsection Having @value{GDBN} Infer the Source Language
15766
15767 To have @value{GDBN} set the working language automatically, use
15768 @samp{set language local} or @samp{set language auto}. @value{GDBN}
15769 then infers the working language. That is, when your program stops in a
15770 frame (usually by encountering a breakpoint), @value{GDBN} sets the
15771 working language to the language recorded for the function in that
15772 frame. If the language for a frame is unknown (that is, if the function
15773 or block corresponding to the frame was defined in a source file that
15774 does not have a recognized extension), the current working language is
15775 not changed, and @value{GDBN} issues a warning.
15776
15777 This may not seem necessary for most programs, which are written
15778 entirely in one source language. However, program modules and libraries
15779 written in one source language can be used by a main program written in
15780 a different source language. Using @samp{set language auto} in this
15781 case frees you from having to set the working language manually.
15782
15783 @node Show
15784 @section Displaying the Language
15785
15786 The following commands help you find out which language is the
15787 working language, and also what language source files were written in.
15788
15789 @table @code
15790 @item show language
15791 @anchor{show language}
15792 @kindex show language
15793 Display the current working language. This is the
15794 language you can use with commands such as @code{print} to
15795 build and compute expressions that may involve variables in your program.
15796
15797 @item info frame
15798 @kindex info frame@r{, show the source language}
15799 Display the source language for this frame. This language becomes the
15800 working language if you use an identifier from this frame.
15801 @xref{Frame Info, ,Information about a Frame}, to identify the other
15802 information listed here.
15803
15804 @item info source
15805 @kindex info source@r{, show the source language}
15806 Display the source language of this source file.
15807 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
15808 information listed here.
15809 @end table
15810
15811 In unusual circumstances, you may have source files with extensions
15812 not in the standard list. You can then set the extension associated
15813 with a language explicitly:
15814
15815 @table @code
15816 @item set extension-language @var{ext} @var{language}
15817 @kindex set extension-language
15818 Tell @value{GDBN} that source files with extension @var{ext} are to be
15819 assumed as written in the source language @var{language}.
15820
15821 @item info extensions
15822 @kindex info extensions
15823 List all the filename extensions and the associated languages.
15824 @end table
15825
15826 @node Checks
15827 @section Type and Range Checking
15828
15829 Some languages are designed to guard you against making seemingly common
15830 errors through a series of compile- and run-time checks. These include
15831 checking the type of arguments to functions and operators and making
15832 sure mathematical overflows are caught at run time. Checks such as
15833 these help to ensure a program's correctness once it has been compiled
15834 by eliminating type mismatches and providing active checks for range
15835 errors when your program is running.
15836
15837 By default @value{GDBN} checks for these errors according to the
15838 rules of the current source language. Although @value{GDBN} does not check
15839 the statements in your program, it can check expressions entered directly
15840 into @value{GDBN} for evaluation via the @code{print} command, for example.
15841
15842 @menu
15843 * Type Checking:: An overview of type checking
15844 * Range Checking:: An overview of range checking
15845 @end menu
15846
15847 @cindex type checking
15848 @cindex checks, type
15849 @node Type Checking
15850 @subsection An Overview of Type Checking
15851
15852 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
15853 arguments to operators and functions have to be of the correct type,
15854 otherwise an error occurs. These checks prevent type mismatch
15855 errors from ever causing any run-time problems. For example,
15856
15857 @smallexample
15858 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15859
15860 (@value{GDBP}) print obj.my_method (0)
15861 $1 = 2
15862 @exdent but
15863 (@value{GDBP}) print obj.my_method (0x1234)
15864 Cannot resolve method klass::my_method to any overloaded instance
15865 @end smallexample
15866
15867 The second example fails because in C@t{++} the integer constant
15868 @samp{0x1234} is not type-compatible with the pointer parameter type.
15869
15870 For the expressions you use in @value{GDBN} commands, you can tell
15871 @value{GDBN} to not enforce strict type checking or
15872 to treat any mismatches as errors and abandon the expression;
15873 When type checking is disabled, @value{GDBN} successfully evaluates
15874 expressions like the second example above.
15875
15876 Even if type checking is off, there may be other reasons
15877 related to type that prevent @value{GDBN} from evaluating an expression.
15878 For instance, @value{GDBN} does not know how to add an @code{int} and
15879 a @code{struct foo}. These particular type errors have nothing to do
15880 with the language in use and usually arise from expressions which make
15881 little sense to evaluate anyway.
15882
15883 @value{GDBN} provides some additional commands for controlling type checking:
15884
15885 @kindex set check type
15886 @kindex show check type
15887 @table @code
15888 @item set check type on
15889 @itemx set check type off
15890 Set strict type checking on or off. If any type mismatches occur in
15891 evaluating an expression while type checking is on, @value{GDBN} prints a
15892 message and aborts evaluation of the expression.
15893
15894 @item show check type
15895 Show the current setting of type checking and whether @value{GDBN}
15896 is enforcing strict type checking rules.
15897 @end table
15898
15899 @cindex range checking
15900 @cindex checks, range
15901 @node Range Checking
15902 @subsection An Overview of Range Checking
15903
15904 In some languages (such as Modula-2), it is an error to exceed the
15905 bounds of a type; this is enforced with run-time checks. Such range
15906 checking is meant to ensure program correctness by making sure
15907 computations do not overflow, or indices on an array element access do
15908 not exceed the bounds of the array.
15909
15910 For expressions you use in @value{GDBN} commands, you can tell
15911 @value{GDBN} to treat range errors in one of three ways: ignore them,
15912 always treat them as errors and abandon the expression, or issue
15913 warnings but evaluate the expression anyway.
15914
15915 A range error can result from numerical overflow, from exceeding an
15916 array index bound, or when you type a constant that is not a member
15917 of any type. Some languages, however, do not treat overflows as an
15918 error. In many implementations of C, mathematical overflow causes the
15919 result to ``wrap around'' to lower values---for example, if @var{m} is
15920 the largest integer value, and @var{s} is the smallest, then
15921
15922 @smallexample
15923 @var{m} + 1 @result{} @var{s}
15924 @end smallexample
15925
15926 This, too, is specific to individual languages, and in some cases
15927 specific to individual compilers or machines. @xref{Supported Languages, ,
15928 Supported Languages}, for further details on specific languages.
15929
15930 @value{GDBN} provides some additional commands for controlling the range checker:
15931
15932 @kindex set check range
15933 @kindex show check range
15934 @table @code
15935 @item set check range auto
15936 Set range checking on or off based on the current working language.
15937 @xref{Supported Languages, ,Supported Languages}, for the default settings for
15938 each language.
15939
15940 @item set check range on
15941 @itemx set check range off
15942 Set range checking on or off, overriding the default setting for the
15943 current working language. A warning is issued if the setting does not
15944 match the language default. If a range error occurs and range checking is on,
15945 then a message is printed and evaluation of the expression is aborted.
15946
15947 @item set check range warn
15948 Output messages when the @value{GDBN} range checker detects a range error,
15949 but attempt to evaluate the expression anyway. Evaluating the
15950 expression may still be impossible for other reasons, such as accessing
15951 memory that the process does not own (a typical example from many Unix
15952 systems).
15953
15954 @item show range
15955 Show the current setting of the range checker, and whether or not it is
15956 being set automatically by @value{GDBN}.
15957 @end table
15958
15959 @node Supported Languages
15960 @section Supported Languages
15961
15962 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
15963 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
15964 @c This is false ...
15965 Some @value{GDBN} features may be used in expressions regardless of the
15966 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
15967 and the @samp{@{type@}addr} construct (@pxref{Expressions,
15968 ,Expressions}) can be used with the constructs of any supported
15969 language.
15970
15971 The following sections detail to what degree each source language is
15972 supported by @value{GDBN}. These sections are not meant to be language
15973 tutorials or references, but serve only as a reference guide to what the
15974 @value{GDBN} expression parser accepts, and what input and output
15975 formats should look like for different languages. There are many good
15976 books written on each of these languages; please look to these for a
15977 language reference or tutorial.
15978
15979 @menu
15980 * C:: C and C@t{++}
15981 * D:: D
15982 * Go:: Go
15983 * Objective-C:: Objective-C
15984 * OpenCL C:: OpenCL C
15985 * Fortran:: Fortran
15986 * Pascal:: Pascal
15987 * Rust:: Rust
15988 * Modula-2:: Modula-2
15989 * Ada:: Ada
15990 @end menu
15991
15992 @node C
15993 @subsection C and C@t{++}
15994
15995 @cindex C and C@t{++}
15996 @cindex expressions in C or C@t{++}
15997
15998 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
15999 to both languages. Whenever this is the case, we discuss those languages
16000 together.
16001
16002 @cindex C@t{++}
16003 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16004 @cindex @sc{gnu} C@t{++}
16005 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16006 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16007 effectively, you must compile your C@t{++} programs with a supported
16008 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16009 compiler (@code{aCC}).
16010
16011 @menu
16012 * C Operators:: C and C@t{++} operators
16013 * C Constants:: C and C@t{++} constants
16014 * C Plus Plus Expressions:: C@t{++} expressions
16015 * C Defaults:: Default settings for C and C@t{++}
16016 * C Checks:: C and C@t{++} type and range checks
16017 * Debugging C:: @value{GDBN} and C
16018 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16019 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16020 @end menu
16021
16022 @node C Operators
16023 @subsubsection C and C@t{++} Operators
16024
16025 @cindex C and C@t{++} operators
16026
16027 Operators must be defined on values of specific types. For instance,
16028 @code{+} is defined on numbers, but not on structures. Operators are
16029 often defined on groups of types.
16030
16031 For the purposes of C and C@t{++}, the following definitions hold:
16032
16033 @itemize @bullet
16034
16035 @item
16036 @emph{Integral types} include @code{int} with any of its storage-class
16037 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16038
16039 @item
16040 @emph{Floating-point types} include @code{float}, @code{double}, and
16041 @code{long double} (if supported by the target platform).
16042
16043 @item
16044 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16045
16046 @item
16047 @emph{Scalar types} include all of the above.
16048
16049 @end itemize
16050
16051 @noindent
16052 The following operators are supported. They are listed here
16053 in order of increasing precedence:
16054
16055 @table @code
16056 @item ,
16057 The comma or sequencing operator. Expressions in a comma-separated list
16058 are evaluated from left to right, with the result of the entire
16059 expression being the last expression evaluated.
16060
16061 @item =
16062 Assignment. The value of an assignment expression is the value
16063 assigned. Defined on scalar types.
16064
16065 @item @var{op}=
16066 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16067 and translated to @w{@code{@var{a} = @var{a op b}}}.
16068 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16069 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16070 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16071
16072 @item ?:
16073 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16074 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16075 should be of an integral type.
16076
16077 @item ||
16078 Logical @sc{or}. Defined on integral types.
16079
16080 @item &&
16081 Logical @sc{and}. Defined on integral types.
16082
16083 @item |
16084 Bitwise @sc{or}. Defined on integral types.
16085
16086 @item ^
16087 Bitwise exclusive-@sc{or}. Defined on integral types.
16088
16089 @item &
16090 Bitwise @sc{and}. Defined on integral types.
16091
16092 @item ==@r{, }!=
16093 Equality and inequality. Defined on scalar types. The value of these
16094 expressions is 0 for false and non-zero for true.
16095
16096 @item <@r{, }>@r{, }<=@r{, }>=
16097 Less than, greater than, less than or equal, greater than or equal.
16098 Defined on scalar types. The value of these expressions is 0 for false
16099 and non-zero for true.
16100
16101 @item <<@r{, }>>
16102 left shift, and right shift. Defined on integral types.
16103
16104 @item @@
16105 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16106
16107 @item +@r{, }-
16108 Addition and subtraction. Defined on integral types, floating-point types and
16109 pointer types.
16110
16111 @item *@r{, }/@r{, }%
16112 Multiplication, division, and modulus. Multiplication and division are
16113 defined on integral and floating-point types. Modulus is defined on
16114 integral types.
16115
16116 @item ++@r{, }--
16117 Increment and decrement. When appearing before a variable, the
16118 operation is performed before the variable is used in an expression;
16119 when appearing after it, the variable's value is used before the
16120 operation takes place.
16121
16122 @item *
16123 Pointer dereferencing. Defined on pointer types. Same precedence as
16124 @code{++}.
16125
16126 @item &
16127 Address operator. Defined on variables. Same precedence as @code{++}.
16128
16129 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16130 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16131 to examine the address
16132 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16133 stored.
16134
16135 @item -
16136 Negative. Defined on integral and floating-point types. Same
16137 precedence as @code{++}.
16138
16139 @item !
16140 Logical negation. Defined on integral types. Same precedence as
16141 @code{++}.
16142
16143 @item ~
16144 Bitwise complement operator. Defined on integral types. Same precedence as
16145 @code{++}.
16146
16147
16148 @item .@r{, }->
16149 Structure member, and pointer-to-structure member. For convenience,
16150 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16151 pointer based on the stored type information.
16152 Defined on @code{struct} and @code{union} data.
16153
16154 @item .*@r{, }->*
16155 Dereferences of pointers to members.
16156
16157 @item []
16158 Array indexing. @code{@var{a}[@var{i}]} is defined as
16159 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16160
16161 @item ()
16162 Function parameter list. Same precedence as @code{->}.
16163
16164 @item ::
16165 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16166 and @code{class} types.
16167
16168 @item ::
16169 Doubled colons also represent the @value{GDBN} scope operator
16170 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16171 above.
16172 @end table
16173
16174 If an operator is redefined in the user code, @value{GDBN} usually
16175 attempts to invoke the redefined version instead of using the operator's
16176 predefined meaning.
16177
16178 @node C Constants
16179 @subsubsection C and C@t{++} Constants
16180
16181 @cindex C and C@t{++} constants
16182
16183 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16184 following ways:
16185
16186 @itemize @bullet
16187 @item
16188 Integer constants are a sequence of digits. Octal constants are
16189 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16190 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16191 @samp{l}, specifying that the constant should be treated as a
16192 @code{long} value.
16193
16194 @item
16195 Floating point constants are a sequence of digits, followed by a decimal
16196 point, followed by a sequence of digits, and optionally followed by an
16197 exponent. An exponent is of the form:
16198 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16199 sequence of digits. The @samp{+} is optional for positive exponents.
16200 A floating-point constant may also end with a letter @samp{f} or
16201 @samp{F}, specifying that the constant should be treated as being of
16202 the @code{float} (as opposed to the default @code{double}) type; or with
16203 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16204 constant.
16205
16206 @item
16207 Enumerated constants consist of enumerated identifiers, or their
16208 integral equivalents.
16209
16210 @item
16211 Character constants are a single character surrounded by single quotes
16212 (@code{'}), or a number---the ordinal value of the corresponding character
16213 (usually its @sc{ascii} value). Within quotes, the single character may
16214 be represented by a letter or by @dfn{escape sequences}, which are of
16215 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16216 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16217 @samp{@var{x}} is a predefined special character---for example,
16218 @samp{\n} for newline.
16219
16220 Wide character constants can be written by prefixing a character
16221 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16222 form of @samp{x}. The target wide character set is used when
16223 computing the value of this constant (@pxref{Character Sets}).
16224
16225 @item
16226 String constants are a sequence of character constants surrounded by
16227 double quotes (@code{"}). Any valid character constant (as described
16228 above) may appear. Double quotes within the string must be preceded by
16229 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16230 characters.
16231
16232 Wide string constants can be written by prefixing a string constant
16233 with @samp{L}, as in C. The target wide character set is used when
16234 computing the value of this constant (@pxref{Character Sets}).
16235
16236 @item
16237 Pointer constants are an integral value. You can also write pointers
16238 to constants using the C operator @samp{&}.
16239
16240 @item
16241 Array constants are comma-separated lists surrounded by braces @samp{@{}
16242 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16243 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16244 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16245 @end itemize
16246
16247 @node C Plus Plus Expressions
16248 @subsubsection C@t{++} Expressions
16249
16250 @cindex expressions in C@t{++}
16251 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16252
16253 @cindex debugging C@t{++} programs
16254 @cindex C@t{++} compilers
16255 @cindex debug formats and C@t{++}
16256 @cindex @value{NGCC} and C@t{++}
16257 @quotation
16258 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16259 the proper compiler and the proper debug format. Currently,
16260 @value{GDBN} works best when debugging C@t{++} code that is compiled
16261 with the most recent version of @value{NGCC} possible. The DWARF
16262 debugging format is preferred; @value{NGCC} defaults to this on most
16263 popular platforms. Other compilers and/or debug formats are likely to
16264 work badly or not at all when using @value{GDBN} to debug C@t{++}
16265 code. @xref{Compilation}.
16266 @end quotation
16267
16268 @enumerate
16269
16270 @cindex member functions
16271 @item
16272 Member function calls are allowed; you can use expressions like
16273
16274 @smallexample
16275 count = aml->GetOriginal(x, y)
16276 @end smallexample
16277
16278 @vindex this@r{, inside C@t{++} member functions}
16279 @cindex namespace in C@t{++}
16280 @item
16281 While a member function is active (in the selected stack frame), your
16282 expressions have the same namespace available as the member function;
16283 that is, @value{GDBN} allows implicit references to the class instance
16284 pointer @code{this} following the same rules as C@t{++}. @code{using}
16285 declarations in the current scope are also respected by @value{GDBN}.
16286
16287 @cindex call overloaded functions
16288 @cindex overloaded functions, calling
16289 @cindex type conversions in C@t{++}
16290 @item
16291 You can call overloaded functions; @value{GDBN} resolves the function
16292 call to the right definition, with some restrictions. @value{GDBN} does not
16293 perform overload resolution involving user-defined type conversions,
16294 calls to constructors, or instantiations of templates that do not exist
16295 in the program. It also cannot handle ellipsis argument lists or
16296 default arguments.
16297
16298 It does perform integral conversions and promotions, floating-point
16299 promotions, arithmetic conversions, pointer conversions, conversions of
16300 class objects to base classes, and standard conversions such as those of
16301 functions or arrays to pointers; it requires an exact match on the
16302 number of function arguments.
16303
16304 Overload resolution is always performed, unless you have specified
16305 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16306 ,@value{GDBN} Features for C@t{++}}.
16307
16308 You must specify @code{set overload-resolution off} in order to use an
16309 explicit function signature to call an overloaded function, as in
16310 @smallexample
16311 p 'foo(char,int)'('x', 13)
16312 @end smallexample
16313
16314 The @value{GDBN} command-completion facility can simplify this;
16315 see @ref{Completion, ,Command Completion}.
16316
16317 @cindex reference declarations
16318 @item
16319 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16320 references; you can use them in expressions just as you do in C@t{++}
16321 source---they are automatically dereferenced.
16322
16323 In the parameter list shown when @value{GDBN} displays a frame, the values of
16324 reference variables are not displayed (unlike other variables); this
16325 avoids clutter, since references are often used for large structures.
16326 The @emph{address} of a reference variable is always shown, unless
16327 you have specified @samp{set print address off}.
16328
16329 @item
16330 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16331 expressions can use it just as expressions in your program do. Since
16332 one scope may be defined in another, you can use @code{::} repeatedly if
16333 necessary, for example in an expression like
16334 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16335 resolving name scope by reference to source files, in both C and C@t{++}
16336 debugging (@pxref{Variables, ,Program Variables}).
16337
16338 @item
16339 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16340 specification.
16341 @end enumerate
16342
16343 @node C Defaults
16344 @subsubsection C and C@t{++} Defaults
16345
16346 @cindex C and C@t{++} defaults
16347
16348 If you allow @value{GDBN} to set range checking automatically, it
16349 defaults to @code{off} whenever the working language changes to
16350 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16351 selects the working language.
16352
16353 If you allow @value{GDBN} to set the language automatically, it
16354 recognizes source files whose names end with @file{.c}, @file{.C}, or
16355 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16356 these files, it sets the working language to C or C@t{++}.
16357 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16358 for further details.
16359
16360 @node C Checks
16361 @subsubsection C and C@t{++} Type and Range Checks
16362
16363 @cindex C and C@t{++} checks
16364
16365 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16366 checking is used. However, if you turn type checking off, @value{GDBN}
16367 will allow certain non-standard conversions, such as promoting integer
16368 constants to pointers.
16369
16370 Range checking, if turned on, is done on mathematical operations. Array
16371 indices are not checked, since they are often used to index a pointer
16372 that is not itself an array.
16373
16374 @node Debugging C
16375 @subsubsection @value{GDBN} and C
16376
16377 The @code{set print union} and @code{show print union} commands apply to
16378 the @code{union} type. When set to @samp{on}, any @code{union} that is
16379 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16380 appears as @samp{@{...@}}.
16381
16382 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16383 with pointers and a memory allocation function. @xref{Expressions,
16384 ,Expressions}.
16385
16386 @node Debugging C Plus Plus
16387 @subsubsection @value{GDBN} Features for C@t{++}
16388
16389 @cindex commands for C@t{++}
16390
16391 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16392 designed specifically for use with C@t{++}. Here is a summary:
16393
16394 @table @code
16395 @cindex break in overloaded functions
16396 @item @r{breakpoint menus}
16397 When you want a breakpoint in a function whose name is overloaded,
16398 @value{GDBN} has the capability to display a menu of possible breakpoint
16399 locations to help you specify which function definition you want.
16400 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16401
16402 @cindex overloading in C@t{++}
16403 @item rbreak @var{regex}
16404 Setting breakpoints using regular expressions is helpful for setting
16405 breakpoints on overloaded functions that are not members of any special
16406 classes.
16407 @xref{Set Breaks, ,Setting Breakpoints}.
16408
16409 @cindex C@t{++} exception handling
16410 @item catch throw
16411 @itemx catch rethrow
16412 @itemx catch catch
16413 Debug C@t{++} exception handling using these commands. @xref{Set
16414 Catchpoints, , Setting Catchpoints}.
16415
16416 @cindex inheritance
16417 @item ptype @var{typename}
16418 Print inheritance relationships as well as other information for type
16419 @var{typename}.
16420 @xref{Symbols, ,Examining the Symbol Table}.
16421
16422 @item info vtbl @var{expression}.
16423 The @code{info vtbl} command can be used to display the virtual
16424 method tables of the object computed by @var{expression}. This shows
16425 one entry per virtual table; there may be multiple virtual tables when
16426 multiple inheritance is in use.
16427
16428 @cindex C@t{++} demangling
16429 @item demangle @var{name}
16430 Demangle @var{name}.
16431 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16432
16433 @cindex C@t{++} symbol display
16434 @item set print demangle
16435 @itemx show print demangle
16436 @itemx set print asm-demangle
16437 @itemx show print asm-demangle
16438 Control whether C@t{++} symbols display in their source form, both when
16439 displaying code as C@t{++} source and when displaying disassemblies.
16440 @xref{Print Settings, ,Print Settings}.
16441
16442 @item set print object
16443 @itemx show print object
16444 Choose whether to print derived (actual) or declared types of objects.
16445 @xref{Print Settings, ,Print Settings}.
16446
16447 @item set print vtbl
16448 @itemx show print vtbl
16449 Control the format for printing virtual function tables.
16450 @xref{Print Settings, ,Print Settings}.
16451 (The @code{vtbl} commands do not work on programs compiled with the HP
16452 ANSI C@t{++} compiler (@code{aCC}).)
16453
16454 @kindex set overload-resolution
16455 @cindex overloaded functions, overload resolution
16456 @item set overload-resolution on
16457 Enable overload resolution for C@t{++} expression evaluation. The default
16458 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16459 and searches for a function whose signature matches the argument types,
16460 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16461 Expressions, ,C@t{++} Expressions}, for details).
16462 If it cannot find a match, it emits a message.
16463
16464 @item set overload-resolution off
16465 Disable overload resolution for C@t{++} expression evaluation. For
16466 overloaded functions that are not class member functions, @value{GDBN}
16467 chooses the first function of the specified name that it finds in the
16468 symbol table, whether or not its arguments are of the correct type. For
16469 overloaded functions that are class member functions, @value{GDBN}
16470 searches for a function whose signature @emph{exactly} matches the
16471 argument types.
16472
16473 @kindex show overload-resolution
16474 @item show overload-resolution
16475 Show the current setting of overload resolution.
16476
16477 @item @r{Overloaded symbol names}
16478 You can specify a particular definition of an overloaded symbol, using
16479 the same notation that is used to declare such symbols in C@t{++}: type
16480 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16481 also use the @value{GDBN} command-line word completion facilities to list the
16482 available choices, or to finish the type list for you.
16483 @xref{Completion,, Command Completion}, for details on how to do this.
16484
16485 @item @r{Breakpoints in functions with ABI tags}
16486
16487 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16488 correspond to changes in the ABI of a type, function, or variable that
16489 would not otherwise be reflected in a mangled name. See
16490 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16491 for more detail.
16492
16493 The ABI tags are visible in C@t{++} demangled names. For example, a
16494 function that returns a std::string:
16495
16496 @smallexample
16497 std::string function(int);
16498 @end smallexample
16499
16500 @noindent
16501 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16502 tag, and @value{GDBN} displays the symbol like this:
16503
16504 @smallexample
16505 function[abi:cxx11](int)
16506 @end smallexample
16507
16508 You can set a breakpoint on such functions simply as if they had no
16509 tag. For example:
16510
16511 @smallexample
16512 (gdb) b function(int)
16513 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16514 (gdb) info breakpoints
16515 Num Type Disp Enb Address What
16516 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16517 at main.cc:10
16518 @end smallexample
16519
16520 On the rare occasion you need to disambiguate between different ABI
16521 tags, you can do so by simply including the ABI tag in the function
16522 name, like:
16523
16524 @smallexample
16525 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16526 @end smallexample
16527 @end table
16528
16529 @node Decimal Floating Point
16530 @subsubsection Decimal Floating Point format
16531 @cindex decimal floating point format
16532
16533 @value{GDBN} can examine, set and perform computations with numbers in
16534 decimal floating point format, which in the C language correspond to the
16535 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16536 specified by the extension to support decimal floating-point arithmetic.
16537
16538 There are two encodings in use, depending on the architecture: BID (Binary
16539 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16540 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16541 configured target.
16542
16543 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16544 to manipulate decimal floating point numbers, it is not possible to convert
16545 (using a cast, for example) integers wider than 32-bit to decimal float.
16546
16547 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16548 point computations, error checking in decimal float operations ignores
16549 underflow, overflow and divide by zero exceptions.
16550
16551 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16552 to inspect @code{_Decimal128} values stored in floating point registers.
16553 See @ref{PowerPC,,PowerPC} for more details.
16554
16555 @node D
16556 @subsection D
16557
16558 @cindex D
16559 @value{GDBN} can be used to debug programs written in D and compiled with
16560 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16561 specific feature --- dynamic arrays.
16562
16563 @node Go
16564 @subsection Go
16565
16566 @cindex Go (programming language)
16567 @value{GDBN} can be used to debug programs written in Go and compiled with
16568 @file{gccgo} or @file{6g} compilers.
16569
16570 Here is a summary of the Go-specific features and restrictions:
16571
16572 @table @code
16573 @cindex current Go package
16574 @item The current Go package
16575 The name of the current package does not need to be specified when
16576 specifying global variables and functions.
16577
16578 For example, given the program:
16579
16580 @example
16581 package main
16582 var myglob = "Shall we?"
16583 func main () @{
16584 // ...
16585 @}
16586 @end example
16587
16588 When stopped inside @code{main} either of these work:
16589
16590 @example
16591 (gdb) p myglob
16592 (gdb) p main.myglob
16593 @end example
16594
16595 @cindex builtin Go types
16596 @item Builtin Go types
16597 The @code{string} type is recognized by @value{GDBN} and is printed
16598 as a string.
16599
16600 @cindex builtin Go functions
16601 @item Builtin Go functions
16602 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16603 function and handles it internally.
16604
16605 @cindex restrictions on Go expressions
16606 @item Restrictions on Go expressions
16607 All Go operators are supported except @code{&^}.
16608 The Go @code{_} ``blank identifier'' is not supported.
16609 Automatic dereferencing of pointers is not supported.
16610 @end table
16611
16612 @node Objective-C
16613 @subsection Objective-C
16614
16615 @cindex Objective-C
16616 This section provides information about some commands and command
16617 options that are useful for debugging Objective-C code. See also
16618 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16619 few more commands specific to Objective-C support.
16620
16621 @menu
16622 * Method Names in Commands::
16623 * The Print Command with Objective-C::
16624 @end menu
16625
16626 @node Method Names in Commands
16627 @subsubsection Method Names in Commands
16628
16629 The following commands have been extended to accept Objective-C method
16630 names as line specifications:
16631
16632 @kindex clear@r{, and Objective-C}
16633 @kindex break@r{, and Objective-C}
16634 @kindex info line@r{, and Objective-C}
16635 @kindex jump@r{, and Objective-C}
16636 @kindex list@r{, and Objective-C}
16637 @itemize
16638 @item @code{clear}
16639 @item @code{break}
16640 @item @code{info line}
16641 @item @code{jump}
16642 @item @code{list}
16643 @end itemize
16644
16645 A fully qualified Objective-C method name is specified as
16646
16647 @smallexample
16648 -[@var{Class} @var{methodName}]
16649 @end smallexample
16650
16651 where the minus sign is used to indicate an instance method and a
16652 plus sign (not shown) is used to indicate a class method. The class
16653 name @var{Class} and method name @var{methodName} are enclosed in
16654 brackets, similar to the way messages are specified in Objective-C
16655 source code. For example, to set a breakpoint at the @code{create}
16656 instance method of class @code{Fruit} in the program currently being
16657 debugged, enter:
16658
16659 @smallexample
16660 break -[Fruit create]
16661 @end smallexample
16662
16663 To list ten program lines around the @code{initialize} class method,
16664 enter:
16665
16666 @smallexample
16667 list +[NSText initialize]
16668 @end smallexample
16669
16670 In the current version of @value{GDBN}, the plus or minus sign is
16671 required. In future versions of @value{GDBN}, the plus or minus
16672 sign will be optional, but you can use it to narrow the search. It
16673 is also possible to specify just a method name:
16674
16675 @smallexample
16676 break create
16677 @end smallexample
16678
16679 You must specify the complete method name, including any colons. If
16680 your program's source files contain more than one @code{create} method,
16681 you'll be presented with a numbered list of classes that implement that
16682 method. Indicate your choice by number, or type @samp{0} to exit if
16683 none apply.
16684
16685 As another example, to clear a breakpoint established at the
16686 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16687
16688 @smallexample
16689 clear -[NSWindow makeKeyAndOrderFront:]
16690 @end smallexample
16691
16692 @node The Print Command with Objective-C
16693 @subsubsection The Print Command With Objective-C
16694 @cindex Objective-C, print objects
16695 @kindex print-object
16696 @kindex po @r{(@code{print-object})}
16697
16698 The print command has also been extended to accept methods. For example:
16699
16700 @smallexample
16701 print -[@var{object} hash]
16702 @end smallexample
16703
16704 @cindex print an Objective-C object description
16705 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16706 @noindent
16707 will tell @value{GDBN} to send the @code{hash} message to @var{object}
16708 and print the result. Also, an additional command has been added,
16709 @code{print-object} or @code{po} for short, which is meant to print
16710 the description of an object. However, this command may only work
16711 with certain Objective-C libraries that have a particular hook
16712 function, @code{_NSPrintForDebugger}, defined.
16713
16714 @node OpenCL C
16715 @subsection OpenCL C
16716
16717 @cindex OpenCL C
16718 This section provides information about @value{GDBN}s OpenCL C support.
16719
16720 @menu
16721 * OpenCL C Datatypes::
16722 * OpenCL C Expressions::
16723 * OpenCL C Operators::
16724 @end menu
16725
16726 @node OpenCL C Datatypes
16727 @subsubsection OpenCL C Datatypes
16728
16729 @cindex OpenCL C Datatypes
16730 @value{GDBN} supports the builtin scalar and vector datatypes specified
16731 by OpenCL 1.1. In addition the half- and double-precision floating point
16732 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16733 extensions are also known to @value{GDBN}.
16734
16735 @node OpenCL C Expressions
16736 @subsubsection OpenCL C Expressions
16737
16738 @cindex OpenCL C Expressions
16739 @value{GDBN} supports accesses to vector components including the access as
16740 lvalue where possible. Since OpenCL C is based on C99 most C expressions
16741 supported by @value{GDBN} can be used as well.
16742
16743 @node OpenCL C Operators
16744 @subsubsection OpenCL C Operators
16745
16746 @cindex OpenCL C Operators
16747 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16748 vector data types.
16749
16750 @node Fortran
16751 @subsection Fortran
16752 @cindex Fortran-specific support in @value{GDBN}
16753
16754 @value{GDBN} can be used to debug programs written in Fortran, but it
16755 currently supports only the features of Fortran 77 language.
16756
16757 @cindex trailing underscore, in Fortran symbols
16758 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16759 among them) append an underscore to the names of variables and
16760 functions. When you debug programs compiled by those compilers, you
16761 will need to refer to variables and functions with a trailing
16762 underscore.
16763
16764 @menu
16765 * Fortran Operators:: Fortran operators and expressions
16766 * Fortran Defaults:: Default settings for Fortran
16767 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
16768 @end menu
16769
16770 @node Fortran Operators
16771 @subsubsection Fortran Operators and Expressions
16772
16773 @cindex Fortran operators and expressions
16774
16775 Operators must be defined on values of specific types. For instance,
16776 @code{+} is defined on numbers, but not on characters or other non-
16777 arithmetic types. Operators are often defined on groups of types.
16778
16779 @table @code
16780 @item **
16781 The exponentiation operator. It raises the first operand to the power
16782 of the second one.
16783
16784 @item :
16785 The range operator. Normally used in the form of array(low:high) to
16786 represent a section of array.
16787
16788 @item %
16789 The access component operator. Normally used to access elements in derived
16790 types. Also suitable for unions. As unions aren't part of regular Fortran,
16791 this can only happen when accessing a register that uses a gdbarch-defined
16792 union type.
16793 @item ::
16794 The scope operator. Normally used to access variables in modules or
16795 to set breakpoints on subroutines nested in modules or in other
16796 subroutines (internal subroutines).
16797 @end table
16798
16799 @node Fortran Defaults
16800 @subsubsection Fortran Defaults
16801
16802 @cindex Fortran Defaults
16803
16804 Fortran symbols are usually case-insensitive, so @value{GDBN} by
16805 default uses case-insensitive matches for Fortran symbols. You can
16806 change that with the @samp{set case-insensitive} command, see
16807 @ref{Symbols}, for the details.
16808
16809 @node Special Fortran Commands
16810 @subsubsection Special Fortran Commands
16811
16812 @cindex Special Fortran commands
16813
16814 @value{GDBN} has some commands to support Fortran-specific features,
16815 such as displaying common blocks.
16816
16817 @table @code
16818 @cindex @code{COMMON} blocks, Fortran
16819 @kindex info common
16820 @item info common @r{[}@var{common-name}@r{]}
16821 This command prints the values contained in the Fortran @code{COMMON}
16822 block whose name is @var{common-name}. With no argument, the names of
16823 all @code{COMMON} blocks visible at the current program location are
16824 printed.
16825 @end table
16826
16827 @node Pascal
16828 @subsection Pascal
16829
16830 @cindex Pascal support in @value{GDBN}, limitations
16831 Debugging Pascal programs which use sets, subranges, file variables, or
16832 nested functions does not currently work. @value{GDBN} does not support
16833 entering expressions, printing values, or similar features using Pascal
16834 syntax.
16835
16836 The Pascal-specific command @code{set print pascal_static-members}
16837 controls whether static members of Pascal objects are displayed.
16838 @xref{Print Settings, pascal_static-members}.
16839
16840 @node Rust
16841 @subsection Rust
16842
16843 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16844 Programming Language}. Type- and value-printing, and expression
16845 parsing, are reasonably complete. However, there are a few
16846 peculiarities and holes to be aware of.
16847
16848 @itemize @bullet
16849 @item
16850 Linespecs (@pxref{Specify Location}) are never relative to the current
16851 crate. Instead, they act as if there were a global namespace of
16852 crates, somewhat similar to the way @code{extern crate} behaves.
16853
16854 That is, if @value{GDBN} is stopped at a breakpoint in a function in
16855 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16856 to set a breakpoint in a function named @samp{f} in a crate named
16857 @samp{B}.
16858
16859 As a consequence of this approach, linespecs also cannot refer to
16860 items using @samp{self::} or @samp{super::}.
16861
16862 @item
16863 Because @value{GDBN} implements Rust name-lookup semantics in
16864 expressions, it will sometimes prepend the current crate to a name.
16865 For example, if @value{GDBN} is stopped at a breakpoint in the crate
16866 @samp{K}, then @code{print ::x::y} will try to find the symbol
16867 @samp{K::x::y}.
16868
16869 However, since it is useful to be able to refer to other crates when
16870 debugging, @value{GDBN} provides the @code{extern} extension to
16871 circumvent this. To use the extension, just put @code{extern} before
16872 a path expression to refer to the otherwise unavailable ``global''
16873 scope.
16874
16875 In the above example, if you wanted to refer to the symbol @samp{y} in
16876 the crate @samp{x}, you would use @code{print extern x::y}.
16877
16878 @item
16879 The Rust expression evaluator does not support ``statement-like''
16880 expressions such as @code{if} or @code{match}, or lambda expressions.
16881
16882 @item
16883 Tuple expressions are not implemented.
16884
16885 @item
16886 The Rust expression evaluator does not currently implement the
16887 @code{Drop} trait. Objects that may be created by the evaluator will
16888 never be destroyed.
16889
16890 @item
16891 @value{GDBN} does not implement type inference for generics. In order
16892 to call generic functions or otherwise refer to generic items, you
16893 will have to specify the type parameters manually.
16894
16895 @item
16896 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16897 cases this does not cause any problems. However, in an expression
16898 context, completing a generic function name will give syntactically
16899 invalid results. This happens because Rust requires the @samp{::}
16900 operator between the function name and its generic arguments. For
16901 example, @value{GDBN} might provide a completion like
16902 @code{crate::f<u32>}, where the parser would require
16903 @code{crate::f::<u32>}.
16904
16905 @item
16906 As of this writing, the Rust compiler (version 1.8) has a few holes in
16907 the debugging information it generates. These holes prevent certain
16908 features from being implemented by @value{GDBN}:
16909 @itemize @bullet
16910
16911 @item
16912 Method calls cannot be made via traits.
16913
16914 @item
16915 Operator overloading is not implemented.
16916
16917 @item
16918 When debugging in a monomorphized function, you cannot use the generic
16919 type names.
16920
16921 @item
16922 The type @code{Self} is not available.
16923
16924 @item
16925 @code{use} statements are not available, so some names may not be
16926 available in the crate.
16927 @end itemize
16928 @end itemize
16929
16930 @node Modula-2
16931 @subsection Modula-2
16932
16933 @cindex Modula-2, @value{GDBN} support
16934
16935 The extensions made to @value{GDBN} to support Modula-2 only support
16936 output from the @sc{gnu} Modula-2 compiler (which is currently being
16937 developed). Other Modula-2 compilers are not currently supported, and
16938 attempting to debug executables produced by them is most likely
16939 to give an error as @value{GDBN} reads in the executable's symbol
16940 table.
16941
16942 @cindex expressions in Modula-2
16943 @menu
16944 * M2 Operators:: Built-in operators
16945 * Built-In Func/Proc:: Built-in functions and procedures
16946 * M2 Constants:: Modula-2 constants
16947 * M2 Types:: Modula-2 types
16948 * M2 Defaults:: Default settings for Modula-2
16949 * Deviations:: Deviations from standard Modula-2
16950 * M2 Checks:: Modula-2 type and range checks
16951 * M2 Scope:: The scope operators @code{::} and @code{.}
16952 * GDB/M2:: @value{GDBN} and Modula-2
16953 @end menu
16954
16955 @node M2 Operators
16956 @subsubsection Operators
16957 @cindex Modula-2 operators
16958
16959 Operators must be defined on values of specific types. For instance,
16960 @code{+} is defined on numbers, but not on structures. Operators are
16961 often defined on groups of types. For the purposes of Modula-2, the
16962 following definitions hold:
16963
16964 @itemize @bullet
16965
16966 @item
16967 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
16968 their subranges.
16969
16970 @item
16971 @emph{Character types} consist of @code{CHAR} and its subranges.
16972
16973 @item
16974 @emph{Floating-point types} consist of @code{REAL}.
16975
16976 @item
16977 @emph{Pointer types} consist of anything declared as @code{POINTER TO
16978 @var{type}}.
16979
16980 @item
16981 @emph{Scalar types} consist of all of the above.
16982
16983 @item
16984 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
16985
16986 @item
16987 @emph{Boolean types} consist of @code{BOOLEAN}.
16988 @end itemize
16989
16990 @noindent
16991 The following operators are supported, and appear in order of
16992 increasing precedence:
16993
16994 @table @code
16995 @item ,
16996 Function argument or array index separator.
16997
16998 @item :=
16999 Assignment. The value of @var{var} @code{:=} @var{value} is
17000 @var{value}.
17001
17002 @item <@r{, }>
17003 Less than, greater than on integral, floating-point, or enumerated
17004 types.
17005
17006 @item <=@r{, }>=
17007 Less than or equal to, greater than or equal to
17008 on integral, floating-point and enumerated types, or set inclusion on
17009 set types. Same precedence as @code{<}.
17010
17011 @item =@r{, }<>@r{, }#
17012 Equality and two ways of expressing inequality, valid on scalar types.
17013 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17014 available for inequality, since @code{#} conflicts with the script
17015 comment character.
17016
17017 @item IN
17018 Set membership. Defined on set types and the types of their members.
17019 Same precedence as @code{<}.
17020
17021 @item OR
17022 Boolean disjunction. Defined on boolean types.
17023
17024 @item AND@r{, }&
17025 Boolean conjunction. Defined on boolean types.
17026
17027 @item @@
17028 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17029
17030 @item +@r{, }-
17031 Addition and subtraction on integral and floating-point types, or union
17032 and difference on set types.
17033
17034 @item *
17035 Multiplication on integral and floating-point types, or set intersection
17036 on set types.
17037
17038 @item /
17039 Division on floating-point types, or symmetric set difference on set
17040 types. Same precedence as @code{*}.
17041
17042 @item DIV@r{, }MOD
17043 Integer division and remainder. Defined on integral types. Same
17044 precedence as @code{*}.
17045
17046 @item -
17047 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17048
17049 @item ^
17050 Pointer dereferencing. Defined on pointer types.
17051
17052 @item NOT
17053 Boolean negation. Defined on boolean types. Same precedence as
17054 @code{^}.
17055
17056 @item .
17057 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17058 precedence as @code{^}.
17059
17060 @item []
17061 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17062
17063 @item ()
17064 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17065 as @code{^}.
17066
17067 @item ::@r{, }.
17068 @value{GDBN} and Modula-2 scope operators.
17069 @end table
17070
17071 @quotation
17072 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17073 treats the use of the operator @code{IN}, or the use of operators
17074 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17075 @code{<=}, and @code{>=} on sets as an error.
17076 @end quotation
17077
17078
17079 @node Built-In Func/Proc
17080 @subsubsection Built-in Functions and Procedures
17081 @cindex Modula-2 built-ins
17082
17083 Modula-2 also makes available several built-in procedures and functions.
17084 In describing these, the following metavariables are used:
17085
17086 @table @var
17087
17088 @item a
17089 represents an @code{ARRAY} variable.
17090
17091 @item c
17092 represents a @code{CHAR} constant or variable.
17093
17094 @item i
17095 represents a variable or constant of integral type.
17096
17097 @item m
17098 represents an identifier that belongs to a set. Generally used in the
17099 same function with the metavariable @var{s}. The type of @var{s} should
17100 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17101
17102 @item n
17103 represents a variable or constant of integral or floating-point type.
17104
17105 @item r
17106 represents a variable or constant of floating-point type.
17107
17108 @item t
17109 represents a type.
17110
17111 @item v
17112 represents a variable.
17113
17114 @item x
17115 represents a variable or constant of one of many types. See the
17116 explanation of the function for details.
17117 @end table
17118
17119 All Modula-2 built-in procedures also return a result, described below.
17120
17121 @table @code
17122 @item ABS(@var{n})
17123 Returns the absolute value of @var{n}.
17124
17125 @item CAP(@var{c})
17126 If @var{c} is a lower case letter, it returns its upper case
17127 equivalent, otherwise it returns its argument.
17128
17129 @item CHR(@var{i})
17130 Returns the character whose ordinal value is @var{i}.
17131
17132 @item DEC(@var{v})
17133 Decrements the value in the variable @var{v} by one. Returns the new value.
17134
17135 @item DEC(@var{v},@var{i})
17136 Decrements the value in the variable @var{v} by @var{i}. Returns the
17137 new value.
17138
17139 @item EXCL(@var{m},@var{s})
17140 Removes the element @var{m} from the set @var{s}. Returns the new
17141 set.
17142
17143 @item FLOAT(@var{i})
17144 Returns the floating point equivalent of the integer @var{i}.
17145
17146 @item HIGH(@var{a})
17147 Returns the index of the last member of @var{a}.
17148
17149 @item INC(@var{v})
17150 Increments the value in the variable @var{v} by one. Returns the new value.
17151
17152 @item INC(@var{v},@var{i})
17153 Increments the value in the variable @var{v} by @var{i}. Returns the
17154 new value.
17155
17156 @item INCL(@var{m},@var{s})
17157 Adds the element @var{m} to the set @var{s} if it is not already
17158 there. Returns the new set.
17159
17160 @item MAX(@var{t})
17161 Returns the maximum value of the type @var{t}.
17162
17163 @item MIN(@var{t})
17164 Returns the minimum value of the type @var{t}.
17165
17166 @item ODD(@var{i})
17167 Returns boolean TRUE if @var{i} is an odd number.
17168
17169 @item ORD(@var{x})
17170 Returns the ordinal value of its argument. For example, the ordinal
17171 value of a character is its @sc{ascii} value (on machines supporting
17172 the @sc{ascii} character set). The argument @var{x} must be of an
17173 ordered type, which include integral, character and enumerated types.
17174
17175 @item SIZE(@var{x})
17176 Returns the size of its argument. The argument @var{x} can be a
17177 variable or a type.
17178
17179 @item TRUNC(@var{r})
17180 Returns the integral part of @var{r}.
17181
17182 @item TSIZE(@var{x})
17183 Returns the size of its argument. The argument @var{x} can be a
17184 variable or a type.
17185
17186 @item VAL(@var{t},@var{i})
17187 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17188 @end table
17189
17190 @quotation
17191 @emph{Warning:} Sets and their operations are not yet supported, so
17192 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17193 an error.
17194 @end quotation
17195
17196 @cindex Modula-2 constants
17197 @node M2 Constants
17198 @subsubsection Constants
17199
17200 @value{GDBN} allows you to express the constants of Modula-2 in the following
17201 ways:
17202
17203 @itemize @bullet
17204
17205 @item
17206 Integer constants are simply a sequence of digits. When used in an
17207 expression, a constant is interpreted to be type-compatible with the
17208 rest of the expression. Hexadecimal integers are specified by a
17209 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17210
17211 @item
17212 Floating point constants appear as a sequence of digits, followed by a
17213 decimal point and another sequence of digits. An optional exponent can
17214 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17215 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17216 digits of the floating point constant must be valid decimal (base 10)
17217 digits.
17218
17219 @item
17220 Character constants consist of a single character enclosed by a pair of
17221 like quotes, either single (@code{'}) or double (@code{"}). They may
17222 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17223 followed by a @samp{C}.
17224
17225 @item
17226 String constants consist of a sequence of characters enclosed by a
17227 pair of like quotes, either single (@code{'}) or double (@code{"}).
17228 Escape sequences in the style of C are also allowed. @xref{C
17229 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17230 sequences.
17231
17232 @item
17233 Enumerated constants consist of an enumerated identifier.
17234
17235 @item
17236 Boolean constants consist of the identifiers @code{TRUE} and
17237 @code{FALSE}.
17238
17239 @item
17240 Pointer constants consist of integral values only.
17241
17242 @item
17243 Set constants are not yet supported.
17244 @end itemize
17245
17246 @node M2 Types
17247 @subsubsection Modula-2 Types
17248 @cindex Modula-2 types
17249
17250 Currently @value{GDBN} can print the following data types in Modula-2
17251 syntax: array types, record types, set types, pointer types, procedure
17252 types, enumerated types, subrange types and base types. You can also
17253 print the contents of variables declared using these type.
17254 This section gives a number of simple source code examples together with
17255 sample @value{GDBN} sessions.
17256
17257 The first example contains the following section of code:
17258
17259 @smallexample
17260 VAR
17261 s: SET OF CHAR ;
17262 r: [20..40] ;
17263 @end smallexample
17264
17265 @noindent
17266 and you can request @value{GDBN} to interrogate the type and value of
17267 @code{r} and @code{s}.
17268
17269 @smallexample
17270 (@value{GDBP}) print s
17271 @{'A'..'C', 'Z'@}
17272 (@value{GDBP}) ptype s
17273 SET OF CHAR
17274 (@value{GDBP}) print r
17275 21
17276 (@value{GDBP}) ptype r
17277 [20..40]
17278 @end smallexample
17279
17280 @noindent
17281 Likewise if your source code declares @code{s} as:
17282
17283 @smallexample
17284 VAR
17285 s: SET ['A'..'Z'] ;
17286 @end smallexample
17287
17288 @noindent
17289 then you may query the type of @code{s} by:
17290
17291 @smallexample
17292 (@value{GDBP}) ptype s
17293 type = SET ['A'..'Z']
17294 @end smallexample
17295
17296 @noindent
17297 Note that at present you cannot interactively manipulate set
17298 expressions using the debugger.
17299
17300 The following example shows how you might declare an array in Modula-2
17301 and how you can interact with @value{GDBN} to print its type and contents:
17302
17303 @smallexample
17304 VAR
17305 s: ARRAY [-10..10] OF CHAR ;
17306 @end smallexample
17307
17308 @smallexample
17309 (@value{GDBP}) ptype s
17310 ARRAY [-10..10] OF CHAR
17311 @end smallexample
17312
17313 Note that the array handling is not yet complete and although the type
17314 is printed correctly, expression handling still assumes that all
17315 arrays have a lower bound of zero and not @code{-10} as in the example
17316 above.
17317
17318 Here are some more type related Modula-2 examples:
17319
17320 @smallexample
17321 TYPE
17322 colour = (blue, red, yellow, green) ;
17323 t = [blue..yellow] ;
17324 VAR
17325 s: t ;
17326 BEGIN
17327 s := blue ;
17328 @end smallexample
17329
17330 @noindent
17331 The @value{GDBN} interaction shows how you can query the data type
17332 and value of a variable.
17333
17334 @smallexample
17335 (@value{GDBP}) print s
17336 $1 = blue
17337 (@value{GDBP}) ptype t
17338 type = [blue..yellow]
17339 @end smallexample
17340
17341 @noindent
17342 In this example a Modula-2 array is declared and its contents
17343 displayed. Observe that the contents are written in the same way as
17344 their @code{C} counterparts.
17345
17346 @smallexample
17347 VAR
17348 s: ARRAY [1..5] OF CARDINAL ;
17349 BEGIN
17350 s[1] := 1 ;
17351 @end smallexample
17352
17353 @smallexample
17354 (@value{GDBP}) print s
17355 $1 = @{1, 0, 0, 0, 0@}
17356 (@value{GDBP}) ptype s
17357 type = ARRAY [1..5] OF CARDINAL
17358 @end smallexample
17359
17360 The Modula-2 language interface to @value{GDBN} also understands
17361 pointer types as shown in this example:
17362
17363 @smallexample
17364 VAR
17365 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17366 BEGIN
17367 NEW(s) ;
17368 s^[1] := 1 ;
17369 @end smallexample
17370
17371 @noindent
17372 and you can request that @value{GDBN} describes the type of @code{s}.
17373
17374 @smallexample
17375 (@value{GDBP}) ptype s
17376 type = POINTER TO ARRAY [1..5] OF CARDINAL
17377 @end smallexample
17378
17379 @value{GDBN} handles compound types as we can see in this example.
17380 Here we combine array types, record types, pointer types and subrange
17381 types:
17382
17383 @smallexample
17384 TYPE
17385 foo = RECORD
17386 f1: CARDINAL ;
17387 f2: CHAR ;
17388 f3: myarray ;
17389 END ;
17390
17391 myarray = ARRAY myrange OF CARDINAL ;
17392 myrange = [-2..2] ;
17393 VAR
17394 s: POINTER TO ARRAY myrange OF foo ;
17395 @end smallexample
17396
17397 @noindent
17398 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17399 below.
17400
17401 @smallexample
17402 (@value{GDBP}) ptype s
17403 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17404 f1 : CARDINAL;
17405 f2 : CHAR;
17406 f3 : ARRAY [-2..2] OF CARDINAL;
17407 END
17408 @end smallexample
17409
17410 @node M2 Defaults
17411 @subsubsection Modula-2 Defaults
17412 @cindex Modula-2 defaults
17413
17414 If type and range checking are set automatically by @value{GDBN}, they
17415 both default to @code{on} whenever the working language changes to
17416 Modula-2. This happens regardless of whether you or @value{GDBN}
17417 selected the working language.
17418
17419 If you allow @value{GDBN} to set the language automatically, then entering
17420 code compiled from a file whose name ends with @file{.mod} sets the
17421 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17422 Infer the Source Language}, for further details.
17423
17424 @node Deviations
17425 @subsubsection Deviations from Standard Modula-2
17426 @cindex Modula-2, deviations from
17427
17428 A few changes have been made to make Modula-2 programs easier to debug.
17429 This is done primarily via loosening its type strictness:
17430
17431 @itemize @bullet
17432 @item
17433 Unlike in standard Modula-2, pointer constants can be formed by
17434 integers. This allows you to modify pointer variables during
17435 debugging. (In standard Modula-2, the actual address contained in a
17436 pointer variable is hidden from you; it can only be modified
17437 through direct assignment to another pointer variable or expression that
17438 returned a pointer.)
17439
17440 @item
17441 C escape sequences can be used in strings and characters to represent
17442 non-printable characters. @value{GDBN} prints out strings with these
17443 escape sequences embedded. Single non-printable characters are
17444 printed using the @samp{CHR(@var{nnn})} format.
17445
17446 @item
17447 The assignment operator (@code{:=}) returns the value of its right-hand
17448 argument.
17449
17450 @item
17451 All built-in procedures both modify @emph{and} return their argument.
17452 @end itemize
17453
17454 @node M2 Checks
17455 @subsubsection Modula-2 Type and Range Checks
17456 @cindex Modula-2 checks
17457
17458 @quotation
17459 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17460 range checking.
17461 @end quotation
17462 @c FIXME remove warning when type/range checks added
17463
17464 @value{GDBN} considers two Modula-2 variables type equivalent if:
17465
17466 @itemize @bullet
17467 @item
17468 They are of types that have been declared equivalent via a @code{TYPE
17469 @var{t1} = @var{t2}} statement
17470
17471 @item
17472 They have been declared on the same line. (Note: This is true of the
17473 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17474 @end itemize
17475
17476 As long as type checking is enabled, any attempt to combine variables
17477 whose types are not equivalent is an error.
17478
17479 Range checking is done on all mathematical operations, assignment, array
17480 index bounds, and all built-in functions and procedures.
17481
17482 @node M2 Scope
17483 @subsubsection The Scope Operators @code{::} and @code{.}
17484 @cindex scope
17485 @cindex @code{.}, Modula-2 scope operator
17486 @cindex colon, doubled as scope operator
17487 @ifinfo
17488 @vindex colon-colon@r{, in Modula-2}
17489 @c Info cannot handle :: but TeX can.
17490 @end ifinfo
17491 @ifnotinfo
17492 @vindex ::@r{, in Modula-2}
17493 @end ifnotinfo
17494
17495 There are a few subtle differences between the Modula-2 scope operator
17496 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17497 similar syntax:
17498
17499 @smallexample
17500
17501 @var{module} . @var{id}
17502 @var{scope} :: @var{id}
17503 @end smallexample
17504
17505 @noindent
17506 where @var{scope} is the name of a module or a procedure,
17507 @var{module} the name of a module, and @var{id} is any declared
17508 identifier within your program, except another module.
17509
17510 Using the @code{::} operator makes @value{GDBN} search the scope
17511 specified by @var{scope} for the identifier @var{id}. If it is not
17512 found in the specified scope, then @value{GDBN} searches all scopes
17513 enclosing the one specified by @var{scope}.
17514
17515 Using the @code{.} operator makes @value{GDBN} search the current scope for
17516 the identifier specified by @var{id} that was imported from the
17517 definition module specified by @var{module}. With this operator, it is
17518 an error if the identifier @var{id} was not imported from definition
17519 module @var{module}, or if @var{id} is not an identifier in
17520 @var{module}.
17521
17522 @node GDB/M2
17523 @subsubsection @value{GDBN} and Modula-2
17524
17525 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17526 Five subcommands of @code{set print} and @code{show print} apply
17527 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17528 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17529 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17530 analogue in Modula-2.
17531
17532 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17533 with any language, is not useful with Modula-2. Its
17534 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17535 created in Modula-2 as they can in C or C@t{++}. However, because an
17536 address can be specified by an integral constant, the construct
17537 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17538
17539 @cindex @code{#} in Modula-2
17540 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17541 interpreted as the beginning of a comment. Use @code{<>} instead.
17542
17543 @node Ada
17544 @subsection Ada
17545 @cindex Ada
17546
17547 The extensions made to @value{GDBN} for Ada only support
17548 output from the @sc{gnu} Ada (GNAT) compiler.
17549 Other Ada compilers are not currently supported, and
17550 attempting to debug executables produced by them is most likely
17551 to be difficult.
17552
17553
17554 @cindex expressions in Ada
17555 @menu
17556 * Ada Mode Intro:: General remarks on the Ada syntax
17557 and semantics supported by Ada mode
17558 in @value{GDBN}.
17559 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17560 * Additions to Ada:: Extensions of the Ada expression syntax.
17561 * Overloading support for Ada:: Support for expressions involving overloaded
17562 subprograms.
17563 * Stopping Before Main Program:: Debugging the program during elaboration.
17564 * Ada Exceptions:: Ada Exceptions
17565 * Ada Tasks:: Listing and setting breakpoints in tasks.
17566 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17567 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17568 Profile
17569 * Ada Settings:: New settable GDB parameters for Ada.
17570 * Ada Glitches:: Known peculiarities of Ada mode.
17571 @end menu
17572
17573 @node Ada Mode Intro
17574 @subsubsection Introduction
17575 @cindex Ada mode, general
17576
17577 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17578 syntax, with some extensions.
17579 The philosophy behind the design of this subset is
17580
17581 @itemize @bullet
17582 @item
17583 That @value{GDBN} should provide basic literals and access to operations for
17584 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17585 leaving more sophisticated computations to subprograms written into the
17586 program (which therefore may be called from @value{GDBN}).
17587
17588 @item
17589 That type safety and strict adherence to Ada language restrictions
17590 are not particularly important to the @value{GDBN} user.
17591
17592 @item
17593 That brevity is important to the @value{GDBN} user.
17594 @end itemize
17595
17596 Thus, for brevity, the debugger acts as if all names declared in
17597 user-written packages are directly visible, even if they are not visible
17598 according to Ada rules, thus making it unnecessary to fully qualify most
17599 names with their packages, regardless of context. Where this causes
17600 ambiguity, @value{GDBN} asks the user's intent.
17601
17602 The debugger will start in Ada mode if it detects an Ada main program.
17603 As for other languages, it will enter Ada mode when stopped in a program that
17604 was translated from an Ada source file.
17605
17606 While in Ada mode, you may use `@t{--}' for comments. This is useful
17607 mostly for documenting command files. The standard @value{GDBN} comment
17608 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17609 middle (to allow based literals).
17610
17611 @node Omissions from Ada
17612 @subsubsection Omissions from Ada
17613 @cindex Ada, omissions from
17614
17615 Here are the notable omissions from the subset:
17616
17617 @itemize @bullet
17618 @item
17619 Only a subset of the attributes are supported:
17620
17621 @itemize @minus
17622 @item
17623 @t{'First}, @t{'Last}, and @t{'Length}
17624 on array objects (not on types and subtypes).
17625
17626 @item
17627 @t{'Min} and @t{'Max}.
17628
17629 @item
17630 @t{'Pos} and @t{'Val}.
17631
17632 @item
17633 @t{'Tag}.
17634
17635 @item
17636 @t{'Range} on array objects (not subtypes), but only as the right
17637 operand of the membership (@code{in}) operator.
17638
17639 @item
17640 @t{'Access}, @t{'Unchecked_Access}, and
17641 @t{'Unrestricted_Access} (a GNAT extension).
17642
17643 @item
17644 @t{'Address}.
17645 @end itemize
17646
17647 @item
17648 The names in
17649 @code{Characters.Latin_1} are not available and
17650 concatenation is not implemented. Thus, escape characters in strings are
17651 not currently available.
17652
17653 @item
17654 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17655 equality of representations. They will generally work correctly
17656 for strings and arrays whose elements have integer or enumeration types.
17657 They may not work correctly for arrays whose element
17658 types have user-defined equality, for arrays of real values
17659 (in particular, IEEE-conformant floating point, because of negative
17660 zeroes and NaNs), and for arrays whose elements contain unused bits with
17661 indeterminate values.
17662
17663 @item
17664 The other component-by-component array operations (@code{and}, @code{or},
17665 @code{xor}, @code{not}, and relational tests other than equality)
17666 are not implemented.
17667
17668 @item
17669 @cindex array aggregates (Ada)
17670 @cindex record aggregates (Ada)
17671 @cindex aggregates (Ada)
17672 There is limited support for array and record aggregates. They are
17673 permitted only on the right sides of assignments, as in these examples:
17674
17675 @smallexample
17676 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17677 (@value{GDBP}) set An_Array := (1, others => 0)
17678 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17679 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17680 (@value{GDBP}) set A_Record := (1, "Peter", True);
17681 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
17682 @end smallexample
17683
17684 Changing a
17685 discriminant's value by assigning an aggregate has an
17686 undefined effect if that discriminant is used within the record.
17687 However, you can first modify discriminants by directly assigning to
17688 them (which normally would not be allowed in Ada), and then performing an
17689 aggregate assignment. For example, given a variable @code{A_Rec}
17690 declared to have a type such as:
17691
17692 @smallexample
17693 type Rec (Len : Small_Integer := 0) is record
17694 Id : Integer;
17695 Vals : IntArray (1 .. Len);
17696 end record;
17697 @end smallexample
17698
17699 you can assign a value with a different size of @code{Vals} with two
17700 assignments:
17701
17702 @smallexample
17703 (@value{GDBP}) set A_Rec.Len := 4
17704 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
17705 @end smallexample
17706
17707 As this example also illustrates, @value{GDBN} is very loose about the usual
17708 rules concerning aggregates. You may leave out some of the
17709 components of an array or record aggregate (such as the @code{Len}
17710 component in the assignment to @code{A_Rec} above); they will retain their
17711 original values upon assignment. You may freely use dynamic values as
17712 indices in component associations. You may even use overlapping or
17713 redundant component associations, although which component values are
17714 assigned in such cases is not defined.
17715
17716 @item
17717 Calls to dispatching subprograms are not implemented.
17718
17719 @item
17720 The overloading algorithm is much more limited (i.e., less selective)
17721 than that of real Ada. It makes only limited use of the context in
17722 which a subexpression appears to resolve its meaning, and it is much
17723 looser in its rules for allowing type matches. As a result, some
17724 function calls will be ambiguous, and the user will be asked to choose
17725 the proper resolution.
17726
17727 @item
17728 The @code{new} operator is not implemented.
17729
17730 @item
17731 Entry calls are not implemented.
17732
17733 @item
17734 Aside from printing, arithmetic operations on the native VAX floating-point
17735 formats are not supported.
17736
17737 @item
17738 It is not possible to slice a packed array.
17739
17740 @item
17741 The names @code{True} and @code{False}, when not part of a qualified name,
17742 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17743 context.
17744 Should your program
17745 redefine these names in a package or procedure (at best a dubious practice),
17746 you will have to use fully qualified names to access their new definitions.
17747 @end itemize
17748
17749 @node Additions to Ada
17750 @subsubsection Additions to Ada
17751 @cindex Ada, deviations from
17752
17753 As it does for other languages, @value{GDBN} makes certain generic
17754 extensions to Ada (@pxref{Expressions}):
17755
17756 @itemize @bullet
17757 @item
17758 If the expression @var{E} is a variable residing in memory (typically
17759 a local variable or array element) and @var{N} is a positive integer,
17760 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17761 @var{N}-1 adjacent variables following it in memory as an array. In
17762 Ada, this operator is generally not necessary, since its prime use is
17763 in displaying parts of an array, and slicing will usually do this in
17764 Ada. However, there are occasional uses when debugging programs in
17765 which certain debugging information has been optimized away.
17766
17767 @item
17768 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
17769 appears in function or file @var{B}.'' When @var{B} is a file name,
17770 you must typically surround it in single quotes.
17771
17772 @item
17773 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17774 @var{type} that appears at address @var{addr}.''
17775
17776 @item
17777 A name starting with @samp{$} is a convenience variable
17778 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17779 @end itemize
17780
17781 In addition, @value{GDBN} provides a few other shortcuts and outright
17782 additions specific to Ada:
17783
17784 @itemize @bullet
17785 @item
17786 The assignment statement is allowed as an expression, returning
17787 its right-hand operand as its value. Thus, you may enter
17788
17789 @smallexample
17790 (@value{GDBP}) set x := y + 3
17791 (@value{GDBP}) print A(tmp := y + 1)
17792 @end smallexample
17793
17794 @item
17795 The semicolon is allowed as an ``operator,'' returning as its value
17796 the value of its right-hand operand.
17797 This allows, for example,
17798 complex conditional breaks:
17799
17800 @smallexample
17801 (@value{GDBP}) break f
17802 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
17803 @end smallexample
17804
17805 @item
17806 Rather than use catenation and symbolic character names to introduce special
17807 characters into strings, one may instead use a special bracket notation,
17808 which is also used to print strings. A sequence of characters of the form
17809 @samp{["@var{XX}"]} within a string or character literal denotes the
17810 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
17811 sequence of characters @samp{["""]} also denotes a single quotation mark
17812 in strings. For example,
17813 @smallexample
17814 "One line.["0a"]Next line.["0a"]"
17815 @end smallexample
17816 @noindent
17817 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17818 after each period.
17819
17820 @item
17821 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17822 @t{'Max} is optional (and is ignored in any case). For example, it is valid
17823 to write
17824
17825 @smallexample
17826 (@value{GDBP}) print 'max(x, y)
17827 @end smallexample
17828
17829 @item
17830 When printing arrays, @value{GDBN} uses positional notation when the
17831 array has a lower bound of 1, and uses a modified named notation otherwise.
17832 For example, a one-dimensional array of three integers with a lower bound
17833 of 3 might print as
17834
17835 @smallexample
17836 (3 => 10, 17, 1)
17837 @end smallexample
17838
17839 @noindent
17840 That is, in contrast to valid Ada, only the first component has a @code{=>}
17841 clause.
17842
17843 @item
17844 You may abbreviate attributes in expressions with any unique,
17845 multi-character subsequence of
17846 their names (an exact match gets preference).
17847 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17848 in place of @t{a'length}.
17849
17850 @item
17851 @cindex quoting Ada internal identifiers
17852 Since Ada is case-insensitive, the debugger normally maps identifiers you type
17853 to lower case. The GNAT compiler uses upper-case characters for
17854 some of its internal identifiers, which are normally of no interest to users.
17855 For the rare occasions when you actually have to look at them,
17856 enclose them in angle brackets to avoid the lower-case mapping.
17857 For example,
17858 @smallexample
17859 (@value{GDBP}) print <JMPBUF_SAVE>[0]
17860 @end smallexample
17861
17862 @item
17863 Printing an object of class-wide type or dereferencing an
17864 access-to-class-wide value will display all the components of the object's
17865 specific type (as indicated by its run-time tag). Likewise, component
17866 selection on such a value will operate on the specific type of the
17867 object.
17868
17869 @end itemize
17870
17871 @node Overloading support for Ada
17872 @subsubsection Overloading support for Ada
17873 @cindex overloading, Ada
17874
17875 The debugger supports limited overloading. Given a subprogram call in which
17876 the function symbol has multiple definitions, it will use the number of
17877 actual parameters and some information about their types to attempt to narrow
17878 the set of definitions. It also makes very limited use of context, preferring
17879 procedures to functions in the context of the @code{call} command, and
17880 functions to procedures elsewhere.
17881
17882 If, after narrowing, the set of matching definitions still contains more than
17883 one definition, @value{GDBN} will display a menu to query which one it should
17884 use, for instance:
17885
17886 @smallexample
17887 (@value{GDBP}) print f(1)
17888 Multiple matches for f
17889 [0] cancel
17890 [1] foo.f (integer) return boolean at foo.adb:23
17891 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
17892 >
17893 @end smallexample
17894
17895 In this case, just select one menu entry either to cancel expression evaluation
17896 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17897 instance (type the corresponding number and press @key{RET}).
17898
17899 Here are a couple of commands to customize @value{GDBN}'s behavior in this
17900 case:
17901
17902 @table @code
17903
17904 @kindex set ada print-signatures
17905 @item set ada print-signatures
17906 Control whether parameter types and return types are displayed in overloads
17907 selection menus. It is @code{on} by default.
17908 @xref{Overloading support for Ada}.
17909
17910 @kindex show ada print-signatures
17911 @item show ada print-signatures
17912 Show the current setting for displaying parameter types and return types in
17913 overloads selection menu.
17914 @xref{Overloading support for Ada}.
17915
17916 @end table
17917
17918 @node Stopping Before Main Program
17919 @subsubsection Stopping at the Very Beginning
17920
17921 @cindex breakpointing Ada elaboration code
17922 It is sometimes necessary to debug the program during elaboration, and
17923 before reaching the main procedure.
17924 As defined in the Ada Reference
17925 Manual, the elaboration code is invoked from a procedure called
17926 @code{adainit}. To run your program up to the beginning of
17927 elaboration, simply use the following two commands:
17928 @code{tbreak adainit} and @code{run}.
17929
17930 @node Ada Exceptions
17931 @subsubsection Ada Exceptions
17932
17933 A command is provided to list all Ada exceptions:
17934
17935 @table @code
17936 @kindex info exceptions
17937 @item info exceptions
17938 @itemx info exceptions @var{regexp}
17939 The @code{info exceptions} command allows you to list all Ada exceptions
17940 defined within the program being debugged, as well as their addresses.
17941 With a regular expression, @var{regexp}, as argument, only those exceptions
17942 whose names match @var{regexp} are listed.
17943 @end table
17944
17945 Below is a small example, showing how the command can be used, first
17946 without argument, and next with a regular expression passed as an
17947 argument.
17948
17949 @smallexample
17950 (@value{GDBP}) info exceptions
17951 All defined Ada exceptions:
17952 constraint_error: 0x613da0
17953 program_error: 0x613d20
17954 storage_error: 0x613ce0
17955 tasking_error: 0x613ca0
17956 const.aint_global_e: 0x613b00
17957 (@value{GDBP}) info exceptions const.aint
17958 All Ada exceptions matching regular expression "const.aint":
17959 constraint_error: 0x613da0
17960 const.aint_global_e: 0x613b00
17961 @end smallexample
17962
17963 It is also possible to ask @value{GDBN} to stop your program's execution
17964 when an exception is raised. For more details, see @ref{Set Catchpoints}.
17965
17966 @node Ada Tasks
17967 @subsubsection Extensions for Ada Tasks
17968 @cindex Ada, tasking
17969
17970 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
17971 @value{GDBN} provides the following task-related commands:
17972
17973 @table @code
17974 @kindex info tasks
17975 @item info tasks
17976 This command shows a list of current Ada tasks, as in the following example:
17977
17978
17979 @smallexample
17980 @iftex
17981 @leftskip=0.5cm
17982 @end iftex
17983 (@value{GDBP}) info tasks
17984 ID TID P-ID Pri State Name
17985 1 8088000 0 15 Child Activation Wait main_task
17986 2 80a4000 1 15 Accept Statement b
17987 3 809a800 1 15 Child Activation Wait a
17988 * 4 80ae800 3 15 Runnable c
17989
17990 @end smallexample
17991
17992 @noindent
17993 In this listing, the asterisk before the last task indicates it to be the
17994 task currently being inspected.
17995
17996 @table @asis
17997 @item ID
17998 Represents @value{GDBN}'s internal task number.
17999
18000 @item TID
18001 The Ada task ID.
18002
18003 @item P-ID
18004 The parent's task ID (@value{GDBN}'s internal task number).
18005
18006 @item Pri
18007 The base priority of the task.
18008
18009 @item State
18010 Current state of the task.
18011
18012 @table @code
18013 @item Unactivated
18014 The task has been created but has not been activated. It cannot be
18015 executing.
18016
18017 @item Runnable
18018 The task is not blocked for any reason known to Ada. (It may be waiting
18019 for a mutex, though.) It is conceptually "executing" in normal mode.
18020
18021 @item Terminated
18022 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18023 that were waiting on terminate alternatives have been awakened and have
18024 terminated themselves.
18025
18026 @item Child Activation Wait
18027 The task is waiting for created tasks to complete activation.
18028
18029 @item Accept Statement
18030 The task is waiting on an accept or selective wait statement.
18031
18032 @item Waiting on entry call
18033 The task is waiting on an entry call.
18034
18035 @item Async Select Wait
18036 The task is waiting to start the abortable part of an asynchronous
18037 select statement.
18038
18039 @item Delay Sleep
18040 The task is waiting on a select statement with only a delay
18041 alternative open.
18042
18043 @item Child Termination Wait
18044 The task is sleeping having completed a master within itself, and is
18045 waiting for the tasks dependent on that master to become terminated or
18046 waiting on a terminate Phase.
18047
18048 @item Wait Child in Term Alt
18049 The task is sleeping waiting for tasks on terminate alternatives to
18050 finish terminating.
18051
18052 @item Accepting RV with @var{taskno}
18053 The task is accepting a rendez-vous with the task @var{taskno}.
18054 @end table
18055
18056 @item Name
18057 Name of the task in the program.
18058
18059 @end table
18060
18061 @kindex info task @var{taskno}
18062 @item info task @var{taskno}
18063 This command shows detailed informations on the specified task, as in
18064 the following example:
18065 @smallexample
18066 @iftex
18067 @leftskip=0.5cm
18068 @end iftex
18069 (@value{GDBP}) info tasks
18070 ID TID P-ID Pri State Name
18071 1 8077880 0 15 Child Activation Wait main_task
18072 * 2 807c468 1 15 Runnable task_1
18073 (@value{GDBP}) info task 2
18074 Ada Task: 0x807c468
18075 Name: "task_1"
18076 Thread: 0
18077 LWP: 0x1fac
18078 Parent: 1 ("main_task")
18079 Base Priority: 15
18080 State: Runnable
18081 @end smallexample
18082
18083 @item task
18084 @kindex task@r{ (Ada)}
18085 @cindex current Ada task ID
18086 This command prints the ID and name of the current task.
18087
18088 @smallexample
18089 @iftex
18090 @leftskip=0.5cm
18091 @end iftex
18092 (@value{GDBP}) info tasks
18093 ID TID P-ID Pri State Name
18094 1 8077870 0 15 Child Activation Wait main_task
18095 * 2 807c458 1 15 Runnable some_task
18096 (@value{GDBP}) task
18097 [Current task is 2 "some_task"]
18098 @end smallexample
18099
18100 @item task @var{taskno}
18101 @cindex Ada task switching
18102 This command is like the @code{thread @var{thread-id}}
18103 command (@pxref{Threads}). It switches the context of debugging
18104 from the current task to the given task.
18105
18106 @smallexample
18107 @iftex
18108 @leftskip=0.5cm
18109 @end iftex
18110 (@value{GDBP}) info tasks
18111 ID TID P-ID Pri State Name
18112 1 8077870 0 15 Child Activation Wait main_task
18113 * 2 807c458 1 15 Runnable some_task
18114 (@value{GDBP}) task 1
18115 [Switching to task 1 "main_task"]
18116 #0 0x8067726 in pthread_cond_wait ()
18117 (@value{GDBP}) bt
18118 #0 0x8067726 in pthread_cond_wait ()
18119 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18120 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18121 #3 0x806153e in system.tasking.stages.activate_tasks ()
18122 #4 0x804aacc in un () at un.adb:5
18123 @end smallexample
18124
18125 @item break @var{location} task @var{taskno}
18126 @itemx break @var{location} task @var{taskno} if @dots{}
18127 @cindex breakpoints and tasks, in Ada
18128 @cindex task breakpoints, in Ada
18129 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18130 These commands are like the @code{break @dots{} thread @dots{}}
18131 command (@pxref{Thread Stops}). The
18132 @var{location} argument specifies source lines, as described
18133 in @ref{Specify Location}.
18134
18135 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18136 to specify that you only want @value{GDBN} to stop the program when a
18137 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18138 numeric task identifiers assigned by @value{GDBN}, shown in the first
18139 column of the @samp{info tasks} display.
18140
18141 If you do not specify @samp{task @var{taskno}} when you set a
18142 breakpoint, the breakpoint applies to @emph{all} tasks of your
18143 program.
18144
18145 You can use the @code{task} qualifier on conditional breakpoints as
18146 well; in this case, place @samp{task @var{taskno}} before the
18147 breakpoint condition (before the @code{if}).
18148
18149 For example,
18150
18151 @smallexample
18152 @iftex
18153 @leftskip=0.5cm
18154 @end iftex
18155 (@value{GDBP}) info tasks
18156 ID TID P-ID Pri State Name
18157 1 140022020 0 15 Child Activation Wait main_task
18158 2 140045060 1 15 Accept/Select Wait t2
18159 3 140044840 1 15 Runnable t1
18160 * 4 140056040 1 15 Runnable t3
18161 (@value{GDBP}) b 15 task 2
18162 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18163 (@value{GDBP}) cont
18164 Continuing.
18165 task # 1 running
18166 task # 2 running
18167
18168 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18169 15 flush;
18170 (@value{GDBP}) info tasks
18171 ID TID P-ID Pri State Name
18172 1 140022020 0 15 Child Activation Wait main_task
18173 * 2 140045060 1 15 Runnable t2
18174 3 140044840 1 15 Runnable t1
18175 4 140056040 1 15 Delay Sleep t3
18176 @end smallexample
18177 @end table
18178
18179 @node Ada Tasks and Core Files
18180 @subsubsection Tasking Support when Debugging Core Files
18181 @cindex Ada tasking and core file debugging
18182
18183 When inspecting a core file, as opposed to debugging a live program,
18184 tasking support may be limited or even unavailable, depending on
18185 the platform being used.
18186 For instance, on x86-linux, the list of tasks is available, but task
18187 switching is not supported.
18188
18189 On certain platforms, the debugger needs to perform some
18190 memory writes in order to provide Ada tasking support. When inspecting
18191 a core file, this means that the core file must be opened with read-write
18192 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18193 Under these circumstances, you should make a backup copy of the core
18194 file before inspecting it with @value{GDBN}.
18195
18196 @node Ravenscar Profile
18197 @subsubsection Tasking Support when using the Ravenscar Profile
18198 @cindex Ravenscar Profile
18199
18200 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18201 specifically designed for systems with safety-critical real-time
18202 requirements.
18203
18204 @table @code
18205 @kindex set ravenscar task-switching on
18206 @cindex task switching with program using Ravenscar Profile
18207 @item set ravenscar task-switching on
18208 Allows task switching when debugging a program that uses the Ravenscar
18209 Profile. This is the default.
18210
18211 @kindex set ravenscar task-switching off
18212 @item set ravenscar task-switching off
18213 Turn off task switching when debugging a program that uses the Ravenscar
18214 Profile. This is mostly intended to disable the code that adds support
18215 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18216 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18217 To be effective, this command should be run before the program is started.
18218
18219 @kindex show ravenscar task-switching
18220 @item show ravenscar task-switching
18221 Show whether it is possible to switch from task to task in a program
18222 using the Ravenscar Profile.
18223
18224 @end table
18225
18226 @node Ada Settings
18227 @subsubsection Ada Settings
18228 @cindex Ada settings
18229
18230 @table @code
18231 @kindex set varsize-limit
18232 @item set varsize-limit @var{size}
18233 Prevent @value{GDBN} from attempting to evaluate objects whose size
18234 is above the given limit (@var{size}) when those sizes are computed
18235 from run-time quantities. This is typically the case when the object
18236 has a variable size, such as an array whose bounds are not known at
18237 compile time for example. Setting @var{size} to @code{unlimited}
18238 removes the size limitation. By default, the limit is about 65KB.
18239
18240 The purpose of having such a limit is to prevent @value{GDBN} from
18241 trying to grab enormous chunks of virtual memory when asked to evaluate
18242 a quantity whose bounds have been corrupted or have not yet been fully
18243 initialized. The limit applies to the results of some subexpressions
18244 as well as to complete expressions. For example, an expression denoting
18245 a simple integer component, such as @code{x.y.z}, may fail if the size of
18246 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18247 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18248 @code{A} is an array variable with non-constant size, will generally
18249 succeed regardless of the bounds on @code{A}, as long as the component
18250 size is less than @var{size}.
18251
18252 @kindex show varsize-limit
18253 @item show varsize-limit
18254 Show the limit on types whose size is determined by run-time quantities.
18255 @end table
18256
18257 @node Ada Glitches
18258 @subsubsection Known Peculiarities of Ada Mode
18259 @cindex Ada, problems
18260
18261 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18262 we know of several problems with and limitations of Ada mode in
18263 @value{GDBN},
18264 some of which will be fixed with planned future releases of the debugger
18265 and the GNU Ada compiler.
18266
18267 @itemize @bullet
18268 @item
18269 Static constants that the compiler chooses not to materialize as objects in
18270 storage are invisible to the debugger.
18271
18272 @item
18273 Named parameter associations in function argument lists are ignored (the
18274 argument lists are treated as positional).
18275
18276 @item
18277 Many useful library packages are currently invisible to the debugger.
18278
18279 @item
18280 Fixed-point arithmetic, conversions, input, and output is carried out using
18281 floating-point arithmetic, and may give results that only approximate those on
18282 the host machine.
18283
18284 @item
18285 The GNAT compiler never generates the prefix @code{Standard} for any of
18286 the standard symbols defined by the Ada language. @value{GDBN} knows about
18287 this: it will strip the prefix from names when you use it, and will never
18288 look for a name you have so qualified among local symbols, nor match against
18289 symbols in other packages or subprograms. If you have
18290 defined entities anywhere in your program other than parameters and
18291 local variables whose simple names match names in @code{Standard},
18292 GNAT's lack of qualification here can cause confusion. When this happens,
18293 you can usually resolve the confusion
18294 by qualifying the problematic names with package
18295 @code{Standard} explicitly.
18296 @end itemize
18297
18298 Older versions of the compiler sometimes generate erroneous debugging
18299 information, resulting in the debugger incorrectly printing the value
18300 of affected entities. In some cases, the debugger is able to work
18301 around an issue automatically. In other cases, the debugger is able
18302 to work around the issue, but the work-around has to be specifically
18303 enabled.
18304
18305 @kindex set ada trust-PAD-over-XVS
18306 @kindex show ada trust-PAD-over-XVS
18307 @table @code
18308
18309 @item set ada trust-PAD-over-XVS on
18310 Configure GDB to strictly follow the GNAT encoding when computing the
18311 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18312 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18313 a complete description of the encoding used by the GNAT compiler).
18314 This is the default.
18315
18316 @item set ada trust-PAD-over-XVS off
18317 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18318 sometimes prints the wrong value for certain entities, changing @code{ada
18319 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18320 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18321 @code{off}, but this incurs a slight performance penalty, so it is
18322 recommended to leave this setting to @code{on} unless necessary.
18323
18324 @end table
18325
18326 @cindex GNAT descriptive types
18327 @cindex GNAT encoding
18328 Internally, the debugger also relies on the compiler following a number
18329 of conventions known as the @samp{GNAT Encoding}, all documented in
18330 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18331 how the debugging information should be generated for certain types.
18332 In particular, this convention makes use of @dfn{descriptive types},
18333 which are artificial types generated purely to help the debugger.
18334
18335 These encodings were defined at a time when the debugging information
18336 format used was not powerful enough to describe some of the more complex
18337 types available in Ada. Since DWARF allows us to express nearly all
18338 Ada features, the long-term goal is to slowly replace these descriptive
18339 types by their pure DWARF equivalent. To facilitate that transition,
18340 a new maintenance option is available to force the debugger to ignore
18341 those descriptive types. It allows the user to quickly evaluate how
18342 well @value{GDBN} works without them.
18343
18344 @table @code
18345
18346 @kindex maint ada set ignore-descriptive-types
18347 @item maintenance ada set ignore-descriptive-types [on|off]
18348 Control whether the debugger should ignore descriptive types.
18349 The default is not to ignore descriptives types (@code{off}).
18350
18351 @kindex maint ada show ignore-descriptive-types
18352 @item maintenance ada show ignore-descriptive-types
18353 Show if descriptive types are ignored by @value{GDBN}.
18354
18355 @end table
18356
18357 @node Unsupported Languages
18358 @section Unsupported Languages
18359
18360 @cindex unsupported languages
18361 @cindex minimal language
18362 In addition to the other fully-supported programming languages,
18363 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18364 It does not represent a real programming language, but provides a set
18365 of capabilities close to what the C or assembly languages provide.
18366 This should allow most simple operations to be performed while debugging
18367 an application that uses a language currently not supported by @value{GDBN}.
18368
18369 If the language is set to @code{auto}, @value{GDBN} will automatically
18370 select this language if the current frame corresponds to an unsupported
18371 language.
18372
18373 @node Symbols
18374 @chapter Examining the Symbol Table
18375
18376 The commands described in this chapter allow you to inquire about the
18377 symbols (names of variables, functions and types) defined in your
18378 program. This information is inherent in the text of your program and
18379 does not change as your program executes. @value{GDBN} finds it in your
18380 program's symbol table, in the file indicated when you started @value{GDBN}
18381 (@pxref{File Options, ,Choosing Files}), or by one of the
18382 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18383
18384 @cindex symbol names
18385 @cindex names of symbols
18386 @cindex quoting names
18387 @anchor{quoting names}
18388 Occasionally, you may need to refer to symbols that contain unusual
18389 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18390 most frequent case is in referring to static variables in other
18391 source files (@pxref{Variables,,Program Variables}). File names
18392 are recorded in object files as debugging symbols, but @value{GDBN} would
18393 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18394 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18395 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18396
18397 @smallexample
18398 p 'foo.c'::x
18399 @end smallexample
18400
18401 @noindent
18402 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18403
18404 @table @code
18405 @cindex case-insensitive symbol names
18406 @cindex case sensitivity in symbol names
18407 @kindex set case-sensitive
18408 @item set case-sensitive on
18409 @itemx set case-sensitive off
18410 @itemx set case-sensitive auto
18411 Normally, when @value{GDBN} looks up symbols, it matches their names
18412 with case sensitivity determined by the current source language.
18413 Occasionally, you may wish to control that. The command @code{set
18414 case-sensitive} lets you do that by specifying @code{on} for
18415 case-sensitive matches or @code{off} for case-insensitive ones. If
18416 you specify @code{auto}, case sensitivity is reset to the default
18417 suitable for the source language. The default is case-sensitive
18418 matches for all languages except for Fortran, for which the default is
18419 case-insensitive matches.
18420
18421 @kindex show case-sensitive
18422 @item show case-sensitive
18423 This command shows the current setting of case sensitivity for symbols
18424 lookups.
18425
18426 @kindex set print type methods
18427 @item set print type methods
18428 @itemx set print type methods on
18429 @itemx set print type methods off
18430 Normally, when @value{GDBN} prints a class, it displays any methods
18431 declared in that class. You can control this behavior either by
18432 passing the appropriate flag to @code{ptype}, or using @command{set
18433 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18434 display the methods; this is the default. Specifying @code{off} will
18435 cause @value{GDBN} to omit the methods.
18436
18437 @kindex show print type methods
18438 @item show print type methods
18439 This command shows the current setting of method display when printing
18440 classes.
18441
18442 @kindex set print type nested-type-limit
18443 @item set print type nested-type-limit @var{limit}
18444 @itemx set print type nested-type-limit unlimited
18445 Set the limit of displayed nested types that the type printer will
18446 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18447 nested definitions. By default, the type printer will not show any nested
18448 types defined in classes.
18449
18450 @kindex show print type nested-type-limit
18451 @item show print type nested-type-limit
18452 This command shows the current display limit of nested types when
18453 printing classes.
18454
18455 @kindex set print type typedefs
18456 @item set print type typedefs
18457 @itemx set print type typedefs on
18458 @itemx set print type typedefs off
18459
18460 Normally, when @value{GDBN} prints a class, it displays any typedefs
18461 defined in that class. You can control this behavior either by
18462 passing the appropriate flag to @code{ptype}, or using @command{set
18463 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18464 display the typedef definitions; this is the default. Specifying
18465 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18466 Note that this controls whether the typedef definition itself is
18467 printed, not whether typedef names are substituted when printing other
18468 types.
18469
18470 @kindex show print type typedefs
18471 @item show print type typedefs
18472 This command shows the current setting of typedef display when
18473 printing classes.
18474
18475 @kindex info address
18476 @cindex address of a symbol
18477 @item info address @var{symbol}
18478 Describe where the data for @var{symbol} is stored. For a register
18479 variable, this says which register it is kept in. For a non-register
18480 local variable, this prints the stack-frame offset at which the variable
18481 is always stored.
18482
18483 Note the contrast with @samp{print &@var{symbol}}, which does not work
18484 at all for a register variable, and for a stack local variable prints
18485 the exact address of the current instantiation of the variable.
18486
18487 @kindex info symbol
18488 @cindex symbol from address
18489 @cindex closest symbol and offset for an address
18490 @item info symbol @var{addr}
18491 Print the name of a symbol which is stored at the address @var{addr}.
18492 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18493 nearest symbol and an offset from it:
18494
18495 @smallexample
18496 (@value{GDBP}) info symbol 0x54320
18497 _initialize_vx + 396 in section .text
18498 @end smallexample
18499
18500 @noindent
18501 This is the opposite of the @code{info address} command. You can use
18502 it to find out the name of a variable or a function given its address.
18503
18504 For dynamically linked executables, the name of executable or shared
18505 library containing the symbol is also printed:
18506
18507 @smallexample
18508 (@value{GDBP}) info symbol 0x400225
18509 _start + 5 in section .text of /tmp/a.out
18510 (@value{GDBP}) info symbol 0x2aaaac2811cf
18511 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18512 @end smallexample
18513
18514 @kindex demangle
18515 @cindex demangle
18516 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18517 Demangle @var{name}.
18518 If @var{language} is provided it is the name of the language to demangle
18519 @var{name} in. Otherwise @var{name} is demangled in the current language.
18520
18521 The @samp{--} option specifies the end of options,
18522 and is useful when @var{name} begins with a dash.
18523
18524 The parameter @code{demangle-style} specifies how to interpret the kind
18525 of mangling used. @xref{Print Settings}.
18526
18527 @kindex whatis
18528 @item whatis[/@var{flags}] [@var{arg}]
18529 Print the data type of @var{arg}, which can be either an expression
18530 or a name of a data type. With no argument, print the data type of
18531 @code{$}, the last value in the value history.
18532
18533 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18534 is not actually evaluated, and any side-effecting operations (such as
18535 assignments or function calls) inside it do not take place.
18536
18537 If @var{arg} is a variable or an expression, @code{whatis} prints its
18538 literal type as it is used in the source code. If the type was
18539 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18540 the data type underlying the @code{typedef}. If the type of the
18541 variable or the expression is a compound data type, such as
18542 @code{struct} or @code{class}, @code{whatis} never prints their
18543 fields or methods. It just prints the @code{struct}/@code{class}
18544 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18545 such a compound data type, use @code{ptype}.
18546
18547 If @var{arg} is a type name that was defined using @code{typedef},
18548 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18549 Unrolling means that @code{whatis} will show the underlying type used
18550 in the @code{typedef} declaration of @var{arg}. However, if that
18551 underlying type is also a @code{typedef}, @code{whatis} will not
18552 unroll it.
18553
18554 For C code, the type names may also have the form @samp{class
18555 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18556 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18557
18558 @var{flags} can be used to modify how the type is displayed.
18559 Available flags are:
18560
18561 @table @code
18562 @item r
18563 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18564 parameters and typedefs defined in a class when printing the class'
18565 members. The @code{/r} flag disables this.
18566
18567 @item m
18568 Do not print methods defined in the class.
18569
18570 @item M
18571 Print methods defined in the class. This is the default, but the flag
18572 exists in case you change the default with @command{set print type methods}.
18573
18574 @item t
18575 Do not print typedefs defined in the class. Note that this controls
18576 whether the typedef definition itself is printed, not whether typedef
18577 names are substituted when printing other types.
18578
18579 @item T
18580 Print typedefs defined in the class. This is the default, but the flag
18581 exists in case you change the default with @command{set print type typedefs}.
18582
18583 @item o
18584 Print the offsets and sizes of fields in a struct, similar to what the
18585 @command{pahole} tool does. This option implies the @code{/tm} flags.
18586
18587 For example, given the following declarations:
18588
18589 @smallexample
18590 struct tuv
18591 @{
18592 int a1;
18593 char *a2;
18594 int a3;
18595 @};
18596
18597 struct xyz
18598 @{
18599 int f1;
18600 char f2;
18601 void *f3;
18602 struct tuv f4;
18603 @};
18604
18605 union qwe
18606 @{
18607 struct tuv fff1;
18608 struct xyz fff2;
18609 @};
18610
18611 struct tyu
18612 @{
18613 int a1 : 1;
18614 int a2 : 3;
18615 int a3 : 23;
18616 char a4 : 2;
18617 int64_t a5;
18618 int a6 : 5;
18619 int64_t a7 : 3;
18620 @};
18621 @end smallexample
18622
18623 Issuing a @kbd{ptype /o struct tuv} command would print:
18624
18625 @smallexample
18626 (@value{GDBP}) ptype /o struct tuv
18627 /* offset | size */ type = struct tuv @{
18628 /* 0 | 4 */ int a1;
18629 /* XXX 4-byte hole */
18630 /* 8 | 8 */ char *a2;
18631 /* 16 | 4 */ int a3;
18632
18633 /* total size (bytes): 24 */
18634 @}
18635 @end smallexample
18636
18637 Notice the format of the first column of comments. There, you can
18638 find two parts separated by the @samp{|} character: the @emph{offset},
18639 which indicates where the field is located inside the struct, in
18640 bytes, and the @emph{size} of the field. Another interesting line is
18641 the marker of a @emph{hole} in the struct, indicating that it may be
18642 possible to pack the struct and make it use less space by reorganizing
18643 its fields.
18644
18645 It is also possible to print offsets inside an union:
18646
18647 @smallexample
18648 (@value{GDBP}) ptype /o union qwe
18649 /* offset | size */ type = union qwe @{
18650 /* 24 */ struct tuv @{
18651 /* 0 | 4 */ int a1;
18652 /* XXX 4-byte hole */
18653 /* 8 | 8 */ char *a2;
18654 /* 16 | 4 */ int a3;
18655
18656 /* total size (bytes): 24 */
18657 @} fff1;
18658 /* 40 */ struct xyz @{
18659 /* 0 | 4 */ int f1;
18660 /* 4 | 1 */ char f2;
18661 /* XXX 3-byte hole */
18662 /* 8 | 8 */ void *f3;
18663 /* 16 | 24 */ struct tuv @{
18664 /* 16 | 4 */ int a1;
18665 /* XXX 4-byte hole */
18666 /* 24 | 8 */ char *a2;
18667 /* 32 | 4 */ int a3;
18668
18669 /* total size (bytes): 24 */
18670 @} f4;
18671
18672 /* total size (bytes): 40 */
18673 @} fff2;
18674
18675 /* total size (bytes): 40 */
18676 @}
18677 @end smallexample
18678
18679 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18680 same space (because we are dealing with an union), the offset is not
18681 printed for them. However, you can still examine the offset of each
18682 of these structures' fields.
18683
18684 Another useful scenario is printing the offsets of a struct containing
18685 bitfields:
18686
18687 @smallexample
18688 (@value{GDBP}) ptype /o struct tyu
18689 /* offset | size */ type = struct tyu @{
18690 /* 0:31 | 4 */ int a1 : 1;
18691 /* 0:28 | 4 */ int a2 : 3;
18692 /* 0: 5 | 4 */ int a3 : 23;
18693 /* 3: 3 | 1 */ signed char a4 : 2;
18694 /* XXX 3-bit hole */
18695 /* XXX 4-byte hole */
18696 /* 8 | 8 */ int64_t a5;
18697 /* 16: 0 | 4 */ int a6 : 5;
18698 /* 16: 5 | 8 */ int64_t a7 : 3;
18699 "/* XXX 7-byte padding */
18700
18701 /* total size (bytes): 24 */
18702 @}
18703 @end smallexample
18704
18705 Note how the offset information is now extended to also include the
18706 first bit of the bitfield.
18707 @end table
18708
18709 @kindex ptype
18710 @item ptype[/@var{flags}] [@var{arg}]
18711 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
18712 detailed description of the type, instead of just the name of the type.
18713 @xref{Expressions, ,Expressions}.
18714
18715 Contrary to @code{whatis}, @code{ptype} always unrolls any
18716 @code{typedef}s in its argument declaration, whether the argument is
18717 a variable, expression, or a data type. This means that @code{ptype}
18718 of a variable or an expression will not print literally its type as
18719 present in the source code---use @code{whatis} for that. @code{typedef}s at
18720 the pointer or reference targets are also unrolled. Only @code{typedef}s of
18721 fields, methods and inner @code{class typedef}s of @code{struct}s,
18722 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18723
18724 For example, for this variable declaration:
18725
18726 @smallexample
18727 typedef double real_t;
18728 struct complex @{ real_t real; double imag; @};
18729 typedef struct complex complex_t;
18730 complex_t var;
18731 real_t *real_pointer_var;
18732 @end smallexample
18733
18734 @noindent
18735 the two commands give this output:
18736
18737 @smallexample
18738 @group
18739 (@value{GDBP}) whatis var
18740 type = complex_t
18741 (@value{GDBP}) ptype var
18742 type = struct complex @{
18743 real_t real;
18744 double imag;
18745 @}
18746 (@value{GDBP}) whatis complex_t
18747 type = struct complex
18748 (@value{GDBP}) whatis struct complex
18749 type = struct complex
18750 (@value{GDBP}) ptype struct complex
18751 type = struct complex @{
18752 real_t real;
18753 double imag;
18754 @}
18755 (@value{GDBP}) whatis real_pointer_var
18756 type = real_t *
18757 (@value{GDBP}) ptype real_pointer_var
18758 type = double *
18759 @end group
18760 @end smallexample
18761
18762 @noindent
18763 As with @code{whatis}, using @code{ptype} without an argument refers to
18764 the type of @code{$}, the last value in the value history.
18765
18766 @cindex incomplete type
18767 Sometimes, programs use opaque data types or incomplete specifications
18768 of complex data structure. If the debug information included in the
18769 program does not allow @value{GDBN} to display a full declaration of
18770 the data type, it will say @samp{<incomplete type>}. For example,
18771 given these declarations:
18772
18773 @smallexample
18774 struct foo;
18775 struct foo *fooptr;
18776 @end smallexample
18777
18778 @noindent
18779 but no definition for @code{struct foo} itself, @value{GDBN} will say:
18780
18781 @smallexample
18782 (@value{GDBP}) ptype foo
18783 $1 = <incomplete type>
18784 @end smallexample
18785
18786 @noindent
18787 ``Incomplete type'' is C terminology for data types that are not
18788 completely specified.
18789
18790 @cindex unknown type
18791 Othertimes, information about a variable's type is completely absent
18792 from the debug information included in the program. This most often
18793 happens when the program or library where the variable is defined
18794 includes no debug information at all. @value{GDBN} knows the variable
18795 exists from inspecting the linker/loader symbol table (e.g., the ELF
18796 dynamic symbol table), but such symbols do not contain type
18797 information. Inspecting the type of a (global) variable for which
18798 @value{GDBN} has no type information shows:
18799
18800 @smallexample
18801 (@value{GDBP}) ptype var
18802 type = <data variable, no debug info>
18803 @end smallexample
18804
18805 @xref{Variables, no debug info variables}, for how to print the values
18806 of such variables.
18807
18808 @kindex info types
18809 @item info types [-q] [@var{regexp}]
18810 Print a brief description of all types whose names match the regular
18811 expression @var{regexp} (or all types in your program, if you supply
18812 no argument). Each complete typename is matched as though it were a
18813 complete line; thus, @samp{i type value} gives information on all
18814 types in your program whose names include the string @code{value}, but
18815 @samp{i type ^value$} gives information only on types whose complete
18816 name is @code{value}.
18817
18818 In programs using different languages, @value{GDBN} chooses the syntax
18819 to print the type description according to the
18820 @samp{set language} value: using @samp{set language auto}
18821 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18822 language of the type, other values mean to use
18823 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18824
18825 This command differs from @code{ptype} in two ways: first, like
18826 @code{whatis}, it does not print a detailed description; second, it
18827 lists all source files and line numbers where a type is defined.
18828
18829 The output from @samp{into types} is proceeded with a header line
18830 describing what types are being listed. The optional flag @samp{-q},
18831 which stands for @samp{quiet}, disables printing this header
18832 information.
18833
18834 @kindex info type-printers
18835 @item info type-printers
18836 Versions of @value{GDBN} that ship with Python scripting enabled may
18837 have ``type printers'' available. When using @command{ptype} or
18838 @command{whatis}, these printers are consulted when the name of a type
18839 is needed. @xref{Type Printing API}, for more information on writing
18840 type printers.
18841
18842 @code{info type-printers} displays all the available type printers.
18843
18844 @kindex enable type-printer
18845 @kindex disable type-printer
18846 @item enable type-printer @var{name}@dots{}
18847 @item disable type-printer @var{name}@dots{}
18848 These commands can be used to enable or disable type printers.
18849
18850 @kindex info scope
18851 @cindex local variables
18852 @item info scope @var{location}
18853 List all the variables local to a particular scope. This command
18854 accepts a @var{location} argument---a function name, a source line, or
18855 an address preceded by a @samp{*}, and prints all the variables local
18856 to the scope defined by that location. (@xref{Specify Location}, for
18857 details about supported forms of @var{location}.) For example:
18858
18859 @smallexample
18860 (@value{GDBP}) @b{info scope command_line_handler}
18861 Scope for command_line_handler:
18862 Symbol rl is an argument at stack/frame offset 8, length 4.
18863 Symbol linebuffer is in static storage at address 0x150a18, length 4.
18864 Symbol linelength is in static storage at address 0x150a1c, length 4.
18865 Symbol p is a local variable in register $esi, length 4.
18866 Symbol p1 is a local variable in register $ebx, length 4.
18867 Symbol nline is a local variable in register $edx, length 4.
18868 Symbol repeat is a local variable at frame offset -8, length 4.
18869 @end smallexample
18870
18871 @noindent
18872 This command is especially useful for determining what data to collect
18873 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18874 collect}.
18875
18876 @kindex info source
18877 @item info source
18878 Show information about the current source file---that is, the source file for
18879 the function containing the current point of execution:
18880 @itemize @bullet
18881 @item
18882 the name of the source file, and the directory containing it,
18883 @item
18884 the directory it was compiled in,
18885 @item
18886 its length, in lines,
18887 @item
18888 which programming language it is written in,
18889 @item
18890 if the debug information provides it, the program that compiled the file
18891 (which may include, e.g., the compiler version and command line arguments),
18892 @item
18893 whether the executable includes debugging information for that file, and
18894 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18895 @item
18896 whether the debugging information includes information about
18897 preprocessor macros.
18898 @end itemize
18899
18900
18901 @kindex info sources
18902 @item info sources
18903 Print the names of all source files in your program for which there is
18904 debugging information, organized into two lists: files whose symbols
18905 have already been read, and files whose symbols will be read when needed.
18906
18907 @item info sources [-dirname | -basename] [--] [@var{regexp}]
18908 Like @samp{info sources}, but only print the names of the files
18909 matching the provided @var{regexp}.
18910 By default, the @var{regexp} is used to match anywhere in the filename.
18911 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
18912 If @code{-basename}, only files having a basename matching @var{regexp}
18913 are shown.
18914 The matching is case-sensitive, except on operating systems that
18915 have case-insensitive filesystem (e.g., MS-Windows).
18916
18917 @kindex info functions
18918 @item info functions [-q] [-n]
18919 Print the names and data types of all defined functions.
18920 Similarly to @samp{info types}, this command groups its output by source
18921 files and annotates each function definition with its source line
18922 number.
18923
18924 In programs using different languages, @value{GDBN} chooses the syntax
18925 to print the function name and type according to the
18926 @samp{set language} value: using @samp{set language auto}
18927 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18928 language of the function, other values mean to use
18929 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18930
18931 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
18932 results. A non-debugging symbol is a symbol that comes from the
18933 executable's symbol table, not from the debug information (for
18934 example, DWARF) associated with the executable.
18935
18936 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18937 printing header information and messages explaining why no functions
18938 have been printed.
18939
18940 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
18941 Like @samp{info functions}, but only print the names and data types
18942 of the functions selected with the provided regexp(s).
18943
18944 If @var{regexp} is provided, print only the functions whose names
18945 match the regular expression @var{regexp}.
18946 Thus, @samp{info fun step} finds all functions whose
18947 names include @code{step}; @samp{info fun ^step} finds those whose names
18948 start with @code{step}. If a function name contains characters that
18949 conflict with the regular expression language (e.g.@:
18950 @samp{operator*()}), they may be quoted with a backslash.
18951
18952 If @var{type_regexp} is provided, print only the functions whose
18953 types, as printed by the @code{whatis} command, match
18954 the regular expression @var{type_regexp}.
18955 If @var{type_regexp} contains space(s), it should be enclosed in
18956 quote characters. If needed, use backslash to escape the meaning
18957 of special characters or quotes.
18958 Thus, @samp{info fun -t '^int ('} finds the functions that return
18959 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
18960 have an argument type containing int; @samp{info fun -t '^int (' ^step}
18961 finds the functions whose names start with @code{step} and that return
18962 int.
18963
18964 If both @var{regexp} and @var{type_regexp} are provided, a function
18965 is printed only if its name matches @var{regexp} and its type matches
18966 @var{type_regexp}.
18967
18968
18969 @kindex info variables
18970 @item info variables [-q] [-n]
18971 Print the names and data types of all variables that are defined
18972 outside of functions (i.e.@: excluding local variables).
18973 The printed variables are grouped by source files and annotated with
18974 their respective source line numbers.
18975
18976 In programs using different languages, @value{GDBN} chooses the syntax
18977 to print the variable name and type according to the
18978 @samp{set language} value: using @samp{set language auto}
18979 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18980 language of the variable, other values mean to use
18981 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18982
18983 The @samp{-n} flag excludes non-debugging symbols from the results.
18984
18985 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18986 printing header information and messages explaining why no variables
18987 have been printed.
18988
18989 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
18990 Like @kbd{info variables}, but only print the variables selected
18991 with the provided regexp(s).
18992
18993 If @var{regexp} is provided, print only the variables whose names
18994 match the regular expression @var{regexp}.
18995
18996 If @var{type_regexp} is provided, print only the variables whose
18997 types, as printed by the @code{whatis} command, match
18998 the regular expression @var{type_regexp}.
18999 If @var{type_regexp} contains space(s), it should be enclosed in
19000 quote characters. If needed, use backslash to escape the meaning
19001 of special characters or quotes.
19002
19003 If both @var{regexp} and @var{type_regexp} are provided, an argument
19004 is printed only if its name matches @var{regexp} and its type matches
19005 @var{type_regexp}.
19006
19007 @kindex info modules
19008 @cindex modules
19009 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19010 List all Fortran modules in the program, or all modules matching the
19011 optional regular expression @var{regexp}.
19012
19013 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19014 printing header information and messages explaining why no modules
19015 have been printed.
19016
19017 @kindex info module
19018 @cindex Fortran modules, information about
19019 @cindex functions and variables by Fortran module
19020 @cindex module functions and variables
19021 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19022 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19023 List all functions or variables within all Fortran modules. The set
19024 of functions or variables listed can be limited by providing some or
19025 all of the optional regular expressions. If @var{module-regexp} is
19026 provided, then only Fortran modules matching @var{module-regexp} will
19027 be searched. Only functions or variables whose type matches the
19028 optional regular expression @var{type-regexp} will be listed. And
19029 only functions or variables whose name matches the optional regular
19030 expression @var{regexp} will be listed.
19031
19032 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19033 printing header information and messages explaining why no functions
19034 or variables have been printed.
19035
19036 @kindex info classes
19037 @cindex Objective-C, classes and selectors
19038 @item info classes
19039 @itemx info classes @var{regexp}
19040 Display all Objective-C classes in your program, or
19041 (with the @var{regexp} argument) all those matching a particular regular
19042 expression.
19043
19044 @kindex info selectors
19045 @item info selectors
19046 @itemx info selectors @var{regexp}
19047 Display all Objective-C selectors in your program, or
19048 (with the @var{regexp} argument) all those matching a particular regular
19049 expression.
19050
19051 @ignore
19052 This was never implemented.
19053 @kindex info methods
19054 @item info methods
19055 @itemx info methods @var{regexp}
19056 The @code{info methods} command permits the user to examine all defined
19057 methods within C@t{++} program, or (with the @var{regexp} argument) a
19058 specific set of methods found in the various C@t{++} classes. Many
19059 C@t{++} classes provide a large number of methods. Thus, the output
19060 from the @code{ptype} command can be overwhelming and hard to use. The
19061 @code{info-methods} command filters the methods, printing only those
19062 which match the regular-expression @var{regexp}.
19063 @end ignore
19064
19065 @cindex opaque data types
19066 @kindex set opaque-type-resolution
19067 @item set opaque-type-resolution on
19068 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19069 declared as a pointer to a @code{struct}, @code{class}, or
19070 @code{union}---for example, @code{struct MyType *}---that is used in one
19071 source file although the full declaration of @code{struct MyType} is in
19072 another source file. The default is on.
19073
19074 A change in the setting of this subcommand will not take effect until
19075 the next time symbols for a file are loaded.
19076
19077 @item set opaque-type-resolution off
19078 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19079 is printed as follows:
19080 @smallexample
19081 @{<no data fields>@}
19082 @end smallexample
19083
19084 @kindex show opaque-type-resolution
19085 @item show opaque-type-resolution
19086 Show whether opaque types are resolved or not.
19087
19088 @kindex set print symbol-loading
19089 @cindex print messages when symbols are loaded
19090 @item set print symbol-loading
19091 @itemx set print symbol-loading full
19092 @itemx set print symbol-loading brief
19093 @itemx set print symbol-loading off
19094 The @code{set print symbol-loading} command allows you to control the
19095 printing of messages when @value{GDBN} loads symbol information.
19096 By default a message is printed for the executable and one for each
19097 shared library, and normally this is what you want. However, when
19098 debugging apps with large numbers of shared libraries these messages
19099 can be annoying.
19100 When set to @code{brief} a message is printed for each executable,
19101 and when @value{GDBN} loads a collection of shared libraries at once
19102 it will only print one message regardless of the number of shared
19103 libraries. When set to @code{off} no messages are printed.
19104
19105 @kindex show print symbol-loading
19106 @item show print symbol-loading
19107 Show whether messages will be printed when a @value{GDBN} command
19108 entered from the keyboard causes symbol information to be loaded.
19109
19110 @kindex maint print symbols
19111 @cindex symbol dump
19112 @kindex maint print psymbols
19113 @cindex partial symbol dump
19114 @kindex maint print msymbols
19115 @cindex minimal symbol dump
19116 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19117 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19118 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19119 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19120 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19121 Write a dump of debugging symbol data into the file @var{filename} or
19122 the terminal if @var{filename} is unspecified.
19123 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19124 that objfile.
19125 If @code{-pc @var{address}} is specified, only dump symbols for the file
19126 with code at that address. Note that @var{address} may be a symbol like
19127 @code{main}.
19128 If @code{-source @var{source}} is specified, only dump symbols for that
19129 source file.
19130
19131 These commands are used to debug the @value{GDBN} symbol-reading code.
19132 These commands do not modify internal @value{GDBN} state, therefore
19133 @samp{maint print symbols} will only print symbols for already expanded symbol
19134 tables.
19135 You can use the command @code{info sources} to find out which files these are.
19136 If you use @samp{maint print psymbols} instead, the dump shows information
19137 about symbols that @value{GDBN} only knows partially---that is, symbols
19138 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19139 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19140 ``ELF symbols''.
19141
19142 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19143 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19144
19145 @kindex maint info symtabs
19146 @kindex maint info psymtabs
19147 @cindex listing @value{GDBN}'s internal symbol tables
19148 @cindex symbol tables, listing @value{GDBN}'s internal
19149 @cindex full symbol tables, listing @value{GDBN}'s internal
19150 @cindex partial symbol tables, listing @value{GDBN}'s internal
19151 @item maint info symtabs @r{[} @var{regexp} @r{]}
19152 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19153
19154 List the @code{struct symtab} or @code{struct partial_symtab}
19155 structures whose names match @var{regexp}. If @var{regexp} is not
19156 given, list them all. The output includes expressions which you can
19157 copy into a @value{GDBN} debugging this one to examine a particular
19158 structure in more detail. For example:
19159
19160 @smallexample
19161 (@value{GDBP}) maint info psymtabs dwarf2read
19162 @{ objfile /home/gnu/build/gdb/gdb
19163 ((struct objfile *) 0x82e69d0)
19164 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19165 ((struct partial_symtab *) 0x8474b10)
19166 readin no
19167 fullname (null)
19168 text addresses 0x814d3c8 -- 0x8158074
19169 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19170 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19171 dependencies (none)
19172 @}
19173 @}
19174 (@value{GDBP}) maint info symtabs
19175 (@value{GDBP})
19176 @end smallexample
19177 @noindent
19178 We see that there is one partial symbol table whose filename contains
19179 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19180 and we see that @value{GDBN} has not read in any symtabs yet at all.
19181 If we set a breakpoint on a function, that will cause @value{GDBN} to
19182 read the symtab for the compilation unit containing that function:
19183
19184 @smallexample
19185 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19186 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19187 line 1574.
19188 (@value{GDBP}) maint info symtabs
19189 @{ objfile /home/gnu/build/gdb/gdb
19190 ((struct objfile *) 0x82e69d0)
19191 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19192 ((struct symtab *) 0x86c1f38)
19193 dirname (null)
19194 fullname (null)
19195 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19196 linetable ((struct linetable *) 0x8370fa0)
19197 debugformat DWARF 2
19198 @}
19199 @}
19200 (@value{GDBP})
19201 @end smallexample
19202
19203 @kindex maint info line-table
19204 @cindex listing @value{GDBN}'s internal line tables
19205 @cindex line tables, listing @value{GDBN}'s internal
19206 @item maint info line-table @r{[} @var{regexp} @r{]}
19207
19208 List the @code{struct linetable} from all @code{struct symtab}
19209 instances whose name matches @var{regexp}. If @var{regexp} is not
19210 given, list the @code{struct linetable} from all @code{struct symtab}.
19211
19212 @kindex maint set symbol-cache-size
19213 @cindex symbol cache size
19214 @item maint set symbol-cache-size @var{size}
19215 Set the size of the symbol cache to @var{size}.
19216 The default size is intended to be good enough for debugging
19217 most applications. This option exists to allow for experimenting
19218 with different sizes.
19219
19220 @kindex maint show symbol-cache-size
19221 @item maint show symbol-cache-size
19222 Show the size of the symbol cache.
19223
19224 @kindex maint print symbol-cache
19225 @cindex symbol cache, printing its contents
19226 @item maint print symbol-cache
19227 Print the contents of the symbol cache.
19228 This is useful when debugging symbol cache issues.
19229
19230 @kindex maint print symbol-cache-statistics
19231 @cindex symbol cache, printing usage statistics
19232 @item maint print symbol-cache-statistics
19233 Print symbol cache usage statistics.
19234 This helps determine how well the cache is being utilized.
19235
19236 @kindex maint flush-symbol-cache
19237 @cindex symbol cache, flushing
19238 @item maint flush-symbol-cache
19239 Flush the contents of the symbol cache, all entries are removed.
19240 This command is useful when debugging the symbol cache.
19241 It is also useful when collecting performance data.
19242
19243 @end table
19244
19245 @node Altering
19246 @chapter Altering Execution
19247
19248 Once you think you have found an error in your program, you might want to
19249 find out for certain whether correcting the apparent error would lead to
19250 correct results in the rest of the run. You can find the answer by
19251 experiment, using the @value{GDBN} features for altering execution of the
19252 program.
19253
19254 For example, you can store new values into variables or memory
19255 locations, give your program a signal, restart it at a different
19256 address, or even return prematurely from a function.
19257
19258 @menu
19259 * Assignment:: Assignment to variables
19260 * Jumping:: Continuing at a different address
19261 * Signaling:: Giving your program a signal
19262 * Returning:: Returning from a function
19263 * Calling:: Calling your program's functions
19264 * Patching:: Patching your program
19265 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19266 @end menu
19267
19268 @node Assignment
19269 @section Assignment to Variables
19270
19271 @cindex assignment
19272 @cindex setting variables
19273 To alter the value of a variable, evaluate an assignment expression.
19274 @xref{Expressions, ,Expressions}. For example,
19275
19276 @smallexample
19277 print x=4
19278 @end smallexample
19279
19280 @noindent
19281 stores the value 4 into the variable @code{x}, and then prints the
19282 value of the assignment expression (which is 4).
19283 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19284 information on operators in supported languages.
19285
19286 @kindex set variable
19287 @cindex variables, setting
19288 If you are not interested in seeing the value of the assignment, use the
19289 @code{set} command instead of the @code{print} command. @code{set} is
19290 really the same as @code{print} except that the expression's value is
19291 not printed and is not put in the value history (@pxref{Value History,
19292 ,Value History}). The expression is evaluated only for its effects.
19293
19294 If the beginning of the argument string of the @code{set} command
19295 appears identical to a @code{set} subcommand, use the @code{set
19296 variable} command instead of just @code{set}. This command is identical
19297 to @code{set} except for its lack of subcommands. For example, if your
19298 program has a variable @code{width}, you get an error if you try to set
19299 a new value with just @samp{set width=13}, because @value{GDBN} has the
19300 command @code{set width}:
19301
19302 @smallexample
19303 (@value{GDBP}) whatis width
19304 type = double
19305 (@value{GDBP}) p width
19306 $4 = 13
19307 (@value{GDBP}) set width=47
19308 Invalid syntax in expression.
19309 @end smallexample
19310
19311 @noindent
19312 The invalid expression, of course, is @samp{=47}. In
19313 order to actually set the program's variable @code{width}, use
19314
19315 @smallexample
19316 (@value{GDBP}) set var width=47
19317 @end smallexample
19318
19319 Because the @code{set} command has many subcommands that can conflict
19320 with the names of program variables, it is a good idea to use the
19321 @code{set variable} command instead of just @code{set}. For example, if
19322 your program has a variable @code{g}, you run into problems if you try
19323 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19324 the command @code{set gnutarget}, abbreviated @code{set g}:
19325
19326 @smallexample
19327 @group
19328 (@value{GDBP}) whatis g
19329 type = double
19330 (@value{GDBP}) p g
19331 $1 = 1
19332 (@value{GDBP}) set g=4
19333 (@value{GDBP}) p g
19334 $2 = 1
19335 (@value{GDBP}) r
19336 The program being debugged has been started already.
19337 Start it from the beginning? (y or n) y
19338 Starting program: /home/smith/cc_progs/a.out
19339 "/home/smith/cc_progs/a.out": can't open to read symbols:
19340 Invalid bfd target.
19341 (@value{GDBP}) show g
19342 The current BFD target is "=4".
19343 @end group
19344 @end smallexample
19345
19346 @noindent
19347 The program variable @code{g} did not change, and you silently set the
19348 @code{gnutarget} to an invalid value. In order to set the variable
19349 @code{g}, use
19350
19351 @smallexample
19352 (@value{GDBP}) set var g=4
19353 @end smallexample
19354
19355 @value{GDBN} allows more implicit conversions in assignments than C; you can
19356 freely store an integer value into a pointer variable or vice versa,
19357 and you can convert any structure to any other structure that is the
19358 same length or shorter.
19359 @comment FIXME: how do structs align/pad in these conversions?
19360 @comment /doc@cygnus.com 18dec1990
19361
19362 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19363 construct to generate a value of specified type at a specified address
19364 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19365 to memory location @code{0x83040} as an integer (which implies a certain size
19366 and representation in memory), and
19367
19368 @smallexample
19369 set @{int@}0x83040 = 4
19370 @end smallexample
19371
19372 @noindent
19373 stores the value 4 into that memory location.
19374
19375 @node Jumping
19376 @section Continuing at a Different Address
19377
19378 Ordinarily, when you continue your program, you do so at the place where
19379 it stopped, with the @code{continue} command. You can instead continue at
19380 an address of your own choosing, with the following commands:
19381
19382 @table @code
19383 @kindex jump
19384 @kindex j @r{(@code{jump})}
19385 @item jump @var{location}
19386 @itemx j @var{location}
19387 Resume execution at @var{location}. Execution stops again immediately
19388 if there is a breakpoint there. @xref{Specify Location}, for a description
19389 of the different forms of @var{location}. It is common
19390 practice to use the @code{tbreak} command in conjunction with
19391 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19392
19393 The @code{jump} command does not change the current stack frame, or
19394 the stack pointer, or the contents of any memory location or any
19395 register other than the program counter. If @var{location} is in
19396 a different function from the one currently executing, the results may
19397 be bizarre if the two functions expect different patterns of arguments or
19398 of local variables. For this reason, the @code{jump} command requests
19399 confirmation if the specified line is not in the function currently
19400 executing. However, even bizarre results are predictable if you are
19401 well acquainted with the machine-language code of your program.
19402 @end table
19403
19404 On many systems, you can get much the same effect as the @code{jump}
19405 command by storing a new value into the register @code{$pc}. The
19406 difference is that this does not start your program running; it only
19407 changes the address of where it @emph{will} run when you continue. For
19408 example,
19409
19410 @smallexample
19411 set $pc = 0x485
19412 @end smallexample
19413
19414 @noindent
19415 makes the next @code{continue} command or stepping command execute at
19416 address @code{0x485}, rather than at the address where your program stopped.
19417 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19418
19419 The most common occasion to use the @code{jump} command is to back
19420 up---perhaps with more breakpoints set---over a portion of a program
19421 that has already executed, in order to examine its execution in more
19422 detail.
19423
19424 @c @group
19425 @node Signaling
19426 @section Giving your Program a Signal
19427 @cindex deliver a signal to a program
19428
19429 @table @code
19430 @kindex signal
19431 @item signal @var{signal}
19432 Resume execution where your program is stopped, but immediately give it the
19433 signal @var{signal}. The @var{signal} can be the name or the number of a
19434 signal. For example, on many systems @code{signal 2} and @code{signal
19435 SIGINT} are both ways of sending an interrupt signal.
19436
19437 Alternatively, if @var{signal} is zero, continue execution without
19438 giving a signal. This is useful when your program stopped on account of
19439 a signal and would ordinarily see the signal when resumed with the
19440 @code{continue} command; @samp{signal 0} causes it to resume without a
19441 signal.
19442
19443 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19444 delivered to the currently selected thread, not the thread that last
19445 reported a stop. This includes the situation where a thread was
19446 stopped due to a signal. So if you want to continue execution
19447 suppressing the signal that stopped a thread, you should select that
19448 same thread before issuing the @samp{signal 0} command. If you issue
19449 the @samp{signal 0} command with another thread as the selected one,
19450 @value{GDBN} detects that and asks for confirmation.
19451
19452 Invoking the @code{signal} command is not the same as invoking the
19453 @code{kill} utility from the shell. Sending a signal with @code{kill}
19454 causes @value{GDBN} to decide what to do with the signal depending on
19455 the signal handling tables (@pxref{Signals}). The @code{signal} command
19456 passes the signal directly to your program.
19457
19458 @code{signal} does not repeat when you press @key{RET} a second time
19459 after executing the command.
19460
19461 @kindex queue-signal
19462 @item queue-signal @var{signal}
19463 Queue @var{signal} to be delivered immediately to the current thread
19464 when execution of the thread resumes. The @var{signal} can be the name or
19465 the number of a signal. For example, on many systems @code{signal 2} and
19466 @code{signal SIGINT} are both ways of sending an interrupt signal.
19467 The handling of the signal must be set to pass the signal to the program,
19468 otherwise @value{GDBN} will report an error.
19469 You can control the handling of signals from @value{GDBN} with the
19470 @code{handle} command (@pxref{Signals}).
19471
19472 Alternatively, if @var{signal} is zero, any currently queued signal
19473 for the current thread is discarded and when execution resumes no signal
19474 will be delivered. This is useful when your program stopped on account
19475 of a signal and would ordinarily see the signal when resumed with the
19476 @code{continue} command.
19477
19478 This command differs from the @code{signal} command in that the signal
19479 is just queued, execution is not resumed. And @code{queue-signal} cannot
19480 be used to pass a signal whose handling state has been set to @code{nopass}
19481 (@pxref{Signals}).
19482 @end table
19483 @c @end group
19484
19485 @xref{stepping into signal handlers}, for information on how stepping
19486 commands behave when the thread has a signal queued.
19487
19488 @node Returning
19489 @section Returning from a Function
19490
19491 @table @code
19492 @cindex returning from a function
19493 @kindex return
19494 @item return
19495 @itemx return @var{expression}
19496 You can cancel execution of a function call with the @code{return}
19497 command. If you give an
19498 @var{expression} argument, its value is used as the function's return
19499 value.
19500 @end table
19501
19502 When you use @code{return}, @value{GDBN} discards the selected stack frame
19503 (and all frames within it). You can think of this as making the
19504 discarded frame return prematurely. If you wish to specify a value to
19505 be returned, give that value as the argument to @code{return}.
19506
19507 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19508 Frame}), and any other frames inside of it, leaving its caller as the
19509 innermost remaining frame. That frame becomes selected. The
19510 specified value is stored in the registers used for returning values
19511 of functions.
19512
19513 The @code{return} command does not resume execution; it leaves the
19514 program stopped in the state that would exist if the function had just
19515 returned. In contrast, the @code{finish} command (@pxref{Continuing
19516 and Stepping, ,Continuing and Stepping}) resumes execution until the
19517 selected stack frame returns naturally.
19518
19519 @value{GDBN} needs to know how the @var{expression} argument should be set for
19520 the inferior. The concrete registers assignment depends on the OS ABI and the
19521 type being returned by the selected stack frame. For example it is common for
19522 OS ABI to return floating point values in FPU registers while integer values in
19523 CPU registers. Still some ABIs return even floating point values in CPU
19524 registers. Larger integer widths (such as @code{long long int}) also have
19525 specific placement rules. @value{GDBN} already knows the OS ABI from its
19526 current target so it needs to find out also the type being returned to make the
19527 assignment into the right register(s).
19528
19529 Normally, the selected stack frame has debug info. @value{GDBN} will always
19530 use the debug info instead of the implicit type of @var{expression} when the
19531 debug info is available. For example, if you type @kbd{return -1}, and the
19532 function in the current stack frame is declared to return a @code{long long
19533 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19534 into a @code{long long int}:
19535
19536 @smallexample
19537 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19538 29 return 31;
19539 (@value{GDBP}) return -1
19540 Make func return now? (y or n) y
19541 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19542 43 printf ("result=%lld\n", func ());
19543 (@value{GDBP})
19544 @end smallexample
19545
19546 However, if the selected stack frame does not have a debug info, e.g., if the
19547 function was compiled without debug info, @value{GDBN} has to find out the type
19548 to return from user. Specifying a different type by mistake may set the value
19549 in different inferior registers than the caller code expects. For example,
19550 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19551 of a @code{long long int} result for a debug info less function (on 32-bit
19552 architectures). Therefore the user is required to specify the return type by
19553 an appropriate cast explicitly:
19554
19555 @smallexample
19556 Breakpoint 2, 0x0040050b in func ()
19557 (@value{GDBP}) return -1
19558 Return value type not available for selected stack frame.
19559 Please use an explicit cast of the value to return.
19560 (@value{GDBP}) return (long long int) -1
19561 Make selected stack frame return now? (y or n) y
19562 #0 0x00400526 in main ()
19563 (@value{GDBP})
19564 @end smallexample
19565
19566 @node Calling
19567 @section Calling Program Functions
19568
19569 @table @code
19570 @cindex calling functions
19571 @cindex inferior functions, calling
19572 @item print @var{expr}
19573 Evaluate the expression @var{expr} and display the resulting value.
19574 The expression may include calls to functions in the program being
19575 debugged.
19576
19577 @kindex call
19578 @item call @var{expr}
19579 Evaluate the expression @var{expr} without displaying @code{void}
19580 returned values.
19581
19582 You can use this variant of the @code{print} command if you want to
19583 execute a function from your program that does not return anything
19584 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19585 with @code{void} returned values that @value{GDBN} will otherwise
19586 print. If the result is not void, it is printed and saved in the
19587 value history.
19588 @end table
19589
19590 It is possible for the function you call via the @code{print} or
19591 @code{call} command to generate a signal (e.g., if there's a bug in
19592 the function, or if you passed it incorrect arguments). What happens
19593 in that case is controlled by the @code{set unwindonsignal} command.
19594
19595 Similarly, with a C@t{++} program it is possible for the function you
19596 call via the @code{print} or @code{call} command to generate an
19597 exception that is not handled due to the constraints of the dummy
19598 frame. In this case, any exception that is raised in the frame, but has
19599 an out-of-frame exception handler will not be found. GDB builds a
19600 dummy-frame for the inferior function call, and the unwinder cannot
19601 seek for exception handlers outside of this dummy-frame. What happens
19602 in that case is controlled by the
19603 @code{set unwind-on-terminating-exception} command.
19604
19605 @table @code
19606 @item set unwindonsignal
19607 @kindex set unwindonsignal
19608 @cindex unwind stack in called functions
19609 @cindex call dummy stack unwinding
19610 Set unwinding of the stack if a signal is received while in a function
19611 that @value{GDBN} called in the program being debugged. If set to on,
19612 @value{GDBN} unwinds the stack it created for the call and restores
19613 the context to what it was before the call. If set to off (the
19614 default), @value{GDBN} stops in the frame where the signal was
19615 received.
19616
19617 @item show unwindonsignal
19618 @kindex show unwindonsignal
19619 Show the current setting of stack unwinding in the functions called by
19620 @value{GDBN}.
19621
19622 @item set unwind-on-terminating-exception
19623 @kindex set unwind-on-terminating-exception
19624 @cindex unwind stack in called functions with unhandled exceptions
19625 @cindex call dummy stack unwinding on unhandled exception.
19626 Set unwinding of the stack if a C@t{++} exception is raised, but left
19627 unhandled while in a function that @value{GDBN} called in the program being
19628 debugged. If set to on (the default), @value{GDBN} unwinds the stack
19629 it created for the call and restores the context to what it was before
19630 the call. If set to off, @value{GDBN} the exception is delivered to
19631 the default C@t{++} exception handler and the inferior terminated.
19632
19633 @item show unwind-on-terminating-exception
19634 @kindex show unwind-on-terminating-exception
19635 Show the current setting of stack unwinding in the functions called by
19636 @value{GDBN}.
19637
19638 @item set may-call-functions
19639 @kindex set may-call-functions
19640 @cindex disabling calling functions in the program
19641 @cindex calling functions in the program, disabling
19642 Set permission to call functions in the program.
19643 This controls whether @value{GDBN} will attempt to call functions in
19644 the program, such as with expressions in the @code{print} command. It
19645 defaults to @code{on}.
19646
19647 To call a function in the program, @value{GDBN} has to temporarily
19648 modify the state of the inferior. This has potentially undesired side
19649 effects. Also, having @value{GDBN} call nested functions is likely to
19650 be erroneous and may even crash the program being debugged. You can
19651 avoid such hazards by forbidding @value{GDBN} from calling functions
19652 in the program being debugged. If calling functions in the program
19653 is forbidden, GDB will throw an error when a command (such as printing
19654 an expression) starts a function call in the program.
19655
19656 @item show may-call-functions
19657 @kindex show may-call-functions
19658 Show permission to call functions in the program.
19659
19660 @end table
19661
19662 @subsection Calling functions with no debug info
19663
19664 @cindex no debug info functions
19665 Sometimes, a function you wish to call is missing debug information.
19666 In such case, @value{GDBN} does not know the type of the function,
19667 including the types of the function's parameters. To avoid calling
19668 the inferior function incorrectly, which could result in the called
19669 function functioning erroneously and even crash, @value{GDBN} refuses
19670 to call the function unless you tell it the type of the function.
19671
19672 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19673 to do that. The simplest is to cast the call to the function's
19674 declared return type. For example:
19675
19676 @smallexample
19677 (@value{GDBP}) p getenv ("PATH")
19678 'getenv' has unknown return type; cast the call to its declared return type
19679 (@value{GDBP}) p (char *) getenv ("PATH")
19680 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19681 @end smallexample
19682
19683 Casting the return type of a no-debug function is equivalent to
19684 casting the function to a pointer to a prototyped function that has a
19685 prototype that matches the types of the passed-in arguments, and
19686 calling that. I.e., the call above is equivalent to:
19687
19688 @smallexample
19689 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19690 @end smallexample
19691
19692 @noindent
19693 and given this prototyped C or C++ function with float parameters:
19694
19695 @smallexample
19696 float multiply (float v1, float v2) @{ return v1 * v2; @}
19697 @end smallexample
19698
19699 @noindent
19700 these calls are equivalent:
19701
19702 @smallexample
19703 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19704 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19705 @end smallexample
19706
19707 If the function you wish to call is declared as unprototyped (i.e.@:
19708 old K&R style), you must use the cast-to-function-pointer syntax, so
19709 that @value{GDBN} knows that it needs to apply default argument
19710 promotions (promote float arguments to double). @xref{ABI, float
19711 promotion}. For example, given this unprototyped C function with
19712 float parameters, and no debug info:
19713
19714 @smallexample
19715 float
19716 multiply_noproto (v1, v2)
19717 float v1, v2;
19718 @{
19719 return v1 * v2;
19720 @}
19721 @end smallexample
19722
19723 @noindent
19724 you call it like this:
19725
19726 @smallexample
19727 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19728 @end smallexample
19729
19730 @node Patching
19731 @section Patching Programs
19732
19733 @cindex patching binaries
19734 @cindex writing into executables
19735 @cindex writing into corefiles
19736
19737 By default, @value{GDBN} opens the file containing your program's
19738 executable code (or the corefile) read-only. This prevents accidental
19739 alterations to machine code; but it also prevents you from intentionally
19740 patching your program's binary.
19741
19742 If you'd like to be able to patch the binary, you can specify that
19743 explicitly with the @code{set write} command. For example, you might
19744 want to turn on internal debugging flags, or even to make emergency
19745 repairs.
19746
19747 @table @code
19748 @kindex set write
19749 @item set write on
19750 @itemx set write off
19751 If you specify @samp{set write on}, @value{GDBN} opens executable and
19752 core files for both reading and writing; if you specify @kbd{set write
19753 off} (the default), @value{GDBN} opens them read-only.
19754
19755 If you have already loaded a file, you must load it again (using the
19756 @code{exec-file} or @code{core-file} command) after changing @code{set
19757 write}, for your new setting to take effect.
19758
19759 @item show write
19760 @kindex show write
19761 Display whether executable files and core files are opened for writing
19762 as well as reading.
19763 @end table
19764
19765 @node Compiling and Injecting Code
19766 @section Compiling and injecting code in @value{GDBN}
19767 @cindex injecting code
19768 @cindex writing into executables
19769 @cindex compiling code
19770
19771 @value{GDBN} supports on-demand compilation and code injection into
19772 programs running under @value{GDBN}. GCC 5.0 or higher built with
19773 @file{libcc1.so} must be installed for this functionality to be enabled.
19774 This functionality is implemented with the following commands.
19775
19776 @table @code
19777 @kindex compile code
19778 @item compile code @var{source-code}
19779 @itemx compile code -raw @var{--} @var{source-code}
19780 Compile @var{source-code} with the compiler language found as the current
19781 language in @value{GDBN} (@pxref{Languages}). If compilation and
19782 injection is not supported with the current language specified in
19783 @value{GDBN}, or the compiler does not support this feature, an error
19784 message will be printed. If @var{source-code} compiles and links
19785 successfully, @value{GDBN} will load the object-code emitted,
19786 and execute it within the context of the currently selected inferior.
19787 It is important to note that the compiled code is executed immediately.
19788 After execution, the compiled code is removed from @value{GDBN} and any
19789 new types or variables you have defined will be deleted.
19790
19791 The command allows you to specify @var{source-code} in two ways.
19792 The simplest method is to provide a single line of code to the command.
19793 E.g.:
19794
19795 @smallexample
19796 compile code printf ("hello world\n");
19797 @end smallexample
19798
19799 If you specify options on the command line as well as source code, they
19800 may conflict. The @samp{--} delimiter can be used to separate options
19801 from actual source code. E.g.:
19802
19803 @smallexample
19804 compile code -r -- printf ("hello world\n");
19805 @end smallexample
19806
19807 Alternatively you can enter source code as multiple lines of text. To
19808 enter this mode, invoke the @samp{compile code} command without any text
19809 following the command. This will start the multiple-line editor and
19810 allow you to type as many lines of source code as required. When you
19811 have completed typing, enter @samp{end} on its own line to exit the
19812 editor.
19813
19814 @smallexample
19815 compile code
19816 >printf ("hello\n");
19817 >printf ("world\n");
19818 >end
19819 @end smallexample
19820
19821 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19822 provided @var{source-code} in a callable scope. In this case, you must
19823 specify the entry point of the code by defining a function named
19824 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19825 inferior. Using @samp{-raw} option may be needed for example when
19826 @var{source-code} requires @samp{#include} lines which may conflict with
19827 inferior symbols otherwise.
19828
19829 @kindex compile file
19830 @item compile file @var{filename}
19831 @itemx compile file -raw @var{filename}
19832 Like @code{compile code}, but take the source code from @var{filename}.
19833
19834 @smallexample
19835 compile file /home/user/example.c
19836 @end smallexample
19837 @end table
19838
19839 @table @code
19840 @item compile print [[@var{options}] --] @var{expr}
19841 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
19842 Compile and execute @var{expr} with the compiler language found as the
19843 current language in @value{GDBN} (@pxref{Languages}). By default the
19844 value of @var{expr} is printed in a format appropriate to its data type;
19845 you can choose a different format by specifying @samp{/@var{f}}, where
19846 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
19847 Formats}. The @code{compile print} command accepts the same options
19848 as the @code{print} command; see @ref{print options}.
19849
19850 @item compile print [[@var{options}] --]
19851 @itemx compile print [[@var{options}] --] /@var{f}
19852 @cindex reprint the last value
19853 Alternatively you can enter the expression (source code producing it) as
19854 multiple lines of text. To enter this mode, invoke the @samp{compile print}
19855 command without any text following the command. This will start the
19856 multiple-line editor.
19857 @end table
19858
19859 @noindent
19860 The process of compiling and injecting the code can be inspected using:
19861
19862 @table @code
19863 @anchor{set debug compile}
19864 @item set debug compile
19865 @cindex compile command debugging info
19866 Turns on or off display of @value{GDBN} process of compiling and
19867 injecting the code. The default is off.
19868
19869 @item show debug compile
19870 Displays the current state of displaying @value{GDBN} process of
19871 compiling and injecting the code.
19872
19873 @anchor{set debug compile-cplus-types}
19874 @item set debug compile-cplus-types
19875 @cindex compile C@t{++} type conversion
19876 Turns on or off the display of C@t{++} type conversion debugging information.
19877 The default is off.
19878
19879 @item show debug compile-cplus-types
19880 Displays the current state of displaying debugging information for
19881 C@t{++} type conversion.
19882 @end table
19883
19884 @subsection Compilation options for the @code{compile} command
19885
19886 @value{GDBN} needs to specify the right compilation options for the code
19887 to be injected, in part to make its ABI compatible with the inferior
19888 and in part to make the injected code compatible with @value{GDBN}'s
19889 injecting process.
19890
19891 @noindent
19892 The options used, in increasing precedence:
19893
19894 @table @asis
19895 @item target architecture and OS options (@code{gdbarch})
19896 These options depend on target processor type and target operating
19897 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19898 (@code{-m64}) compilation option.
19899
19900 @item compilation options recorded in the target
19901 @value{NGCC} (since version 4.7) stores the options used for compilation
19902 into @code{DW_AT_producer} part of DWARF debugging information according
19903 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19904 explicitly specify @code{-g} during inferior compilation otherwise
19905 @value{NGCC} produces no DWARF. This feature is only relevant for
19906 platforms where @code{-g} produces DWARF by default, otherwise one may
19907 try to enforce DWARF by using @code{-gdwarf-4}.
19908
19909 @item compilation options set by @code{set compile-args}
19910 @end table
19911
19912 @noindent
19913 You can override compilation options using the following command:
19914
19915 @table @code
19916 @item set compile-args
19917 @cindex compile command options override
19918 Set compilation options used for compiling and injecting code with the
19919 @code{compile} commands. These options override any conflicting ones
19920 from the target architecture and/or options stored during inferior
19921 compilation.
19922
19923 @item show compile-args
19924 Displays the current state of compilation options override.
19925 This does not show all the options actually used during compilation,
19926 use @ref{set debug compile} for that.
19927 @end table
19928
19929 @subsection Caveats when using the @code{compile} command
19930
19931 There are a few caveats to keep in mind when using the @code{compile}
19932 command. As the caveats are different per language, the table below
19933 highlights specific issues on a per language basis.
19934
19935 @table @asis
19936 @item C code examples and caveats
19937 When the language in @value{GDBN} is set to @samp{C}, the compiler will
19938 attempt to compile the source code with a @samp{C} compiler. The source
19939 code provided to the @code{compile} command will have much the same
19940 access to variables and types as it normally would if it were part of
19941 the program currently being debugged in @value{GDBN}.
19942
19943 Below is a sample program that forms the basis of the examples that
19944 follow. This program has been compiled and loaded into @value{GDBN},
19945 much like any other normal debugging session.
19946
19947 @smallexample
19948 void function1 (void)
19949 @{
19950 int i = 42;
19951 printf ("function 1\n");
19952 @}
19953
19954 void function2 (void)
19955 @{
19956 int j = 12;
19957 function1 ();
19958 @}
19959
19960 int main(void)
19961 @{
19962 int k = 6;
19963 int *p;
19964 function2 ();
19965 return 0;
19966 @}
19967 @end smallexample
19968
19969 For the purposes of the examples in this section, the program above has
19970 been compiled, loaded into @value{GDBN}, stopped at the function
19971 @code{main}, and @value{GDBN} is awaiting input from the user.
19972
19973 To access variables and types for any program in @value{GDBN}, the
19974 program must be compiled and packaged with debug information. The
19975 @code{compile} command is not an exception to this rule. Without debug
19976 information, you can still use the @code{compile} command, but you will
19977 be very limited in what variables and types you can access.
19978
19979 So with that in mind, the example above has been compiled with debug
19980 information enabled. The @code{compile} command will have access to
19981 all variables and types (except those that may have been optimized
19982 out). Currently, as @value{GDBN} has stopped the program in the
19983 @code{main} function, the @code{compile} command would have access to
19984 the variable @code{k}. You could invoke the @code{compile} command
19985 and type some source code to set the value of @code{k}. You can also
19986 read it, or do anything with that variable you would normally do in
19987 @code{C}. Be aware that changes to inferior variables in the
19988 @code{compile} command are persistent. In the following example:
19989
19990 @smallexample
19991 compile code k = 3;
19992 @end smallexample
19993
19994 @noindent
19995 the variable @code{k} is now 3. It will retain that value until
19996 something else in the example program changes it, or another
19997 @code{compile} command changes it.
19998
19999 Normal scope and access rules apply to source code compiled and
20000 injected by the @code{compile} command. In the example, the variables
20001 @code{j} and @code{k} are not accessible yet, because the program is
20002 currently stopped in the @code{main} function, where these variables
20003 are not in scope. Therefore, the following command
20004
20005 @smallexample
20006 compile code j = 3;
20007 @end smallexample
20008
20009 @noindent
20010 will result in a compilation error message.
20011
20012 Once the program is continued, execution will bring these variables in
20013 scope, and they will become accessible; then the code you specify via
20014 the @code{compile} command will be able to access them.
20015
20016 You can create variables and types with the @code{compile} command as
20017 part of your source code. Variables and types that are created as part
20018 of the @code{compile} command are not visible to the rest of the program for
20019 the duration of its run. This example is valid:
20020
20021 @smallexample
20022 compile code int ff = 5; printf ("ff is %d\n", ff);
20023 @end smallexample
20024
20025 However, if you were to type the following into @value{GDBN} after that
20026 command has completed:
20027
20028 @smallexample
20029 compile code printf ("ff is %d\n'', ff);
20030 @end smallexample
20031
20032 @noindent
20033 a compiler error would be raised as the variable @code{ff} no longer
20034 exists. Object code generated and injected by the @code{compile}
20035 command is removed when its execution ends. Caution is advised
20036 when assigning to program variables values of variables created by the
20037 code submitted to the @code{compile} command. This example is valid:
20038
20039 @smallexample
20040 compile code int ff = 5; k = ff;
20041 @end smallexample
20042
20043 The value of the variable @code{ff} is assigned to @code{k}. The variable
20044 @code{k} does not require the existence of @code{ff} to maintain the value
20045 it has been assigned. However, pointers require particular care in
20046 assignment. If the source code compiled with the @code{compile} command
20047 changed the address of a pointer in the example program, perhaps to a
20048 variable created in the @code{compile} command, that pointer would point
20049 to an invalid location when the command exits. The following example
20050 would likely cause issues with your debugged program:
20051
20052 @smallexample
20053 compile code int ff = 5; p = &ff;
20054 @end smallexample
20055
20056 In this example, @code{p} would point to @code{ff} when the
20057 @code{compile} command is executing the source code provided to it.
20058 However, as variables in the (example) program persist with their
20059 assigned values, the variable @code{p} would point to an invalid
20060 location when the command exists. A general rule should be followed
20061 in that you should either assign @code{NULL} to any assigned pointers,
20062 or restore a valid location to the pointer before the command exits.
20063
20064 Similar caution must be exercised with any structs, unions, and typedefs
20065 defined in @code{compile} command. Types defined in the @code{compile}
20066 command will no longer be available in the next @code{compile} command.
20067 Therefore, if you cast a variable to a type defined in the
20068 @code{compile} command, care must be taken to ensure that any future
20069 need to resolve the type can be achieved.
20070
20071 @smallexample
20072 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20073 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20074 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20075 Compilation failed.
20076 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20077 42
20078 @end smallexample
20079
20080 Variables that have been optimized away by the compiler are not
20081 accessible to the code submitted to the @code{compile} command.
20082 Access to those variables will generate a compiler error which @value{GDBN}
20083 will print to the console.
20084 @end table
20085
20086 @subsection Compiler search for the @code{compile} command
20087
20088 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20089 which may not be obvious for remote targets of different architecture
20090 than where @value{GDBN} is running. Environment variable @code{PATH} on
20091 @value{GDBN} host is searched for @value{NGCC} binary matching the
20092 target architecture and operating system. This search can be overriden
20093 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20094 taken from shell that executed @value{GDBN}, it is not the value set by
20095 @value{GDBN} command @code{set environment}). @xref{Environment}.
20096
20097
20098 Specifically @code{PATH} is searched for binaries matching regular expression
20099 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20100 debugged. @var{arch} is processor name --- multiarch is supported, so for
20101 example both @code{i386} and @code{x86_64} targets look for pattern
20102 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20103 for pattern @code{s390x?}. @var{os} is currently supported only for
20104 pattern @code{linux(-gnu)?}.
20105
20106 On Posix hosts the compiler driver @value{GDBN} needs to find also
20107 shared library @file{libcc1.so} from the compiler. It is searched in
20108 default shared library search path (overridable with usual environment
20109 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20110 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20111 according to the installation of the found compiler --- as possibly
20112 specified by the @code{set compile-gcc} command.
20113
20114 @table @code
20115 @item set compile-gcc
20116 @cindex compile command driver filename override
20117 Set compilation command used for compiling and injecting code with the
20118 @code{compile} commands. If this option is not set (it is set to
20119 an empty string), the search described above will occur --- that is the
20120 default.
20121
20122 @item show compile-gcc
20123 Displays the current compile command @value{NGCC} driver filename.
20124 If set, it is the main command @command{gcc}, found usually for example
20125 under name @file{x86_64-linux-gnu-gcc}.
20126 @end table
20127
20128 @node GDB Files
20129 @chapter @value{GDBN} Files
20130
20131 @value{GDBN} needs to know the file name of the program to be debugged,
20132 both in order to read its symbol table and in order to start your
20133 program. To debug a core dump of a previous run, you must also tell
20134 @value{GDBN} the name of the core dump file.
20135
20136 @menu
20137 * Files:: Commands to specify files
20138 * File Caching:: Information about @value{GDBN}'s file caching
20139 * Separate Debug Files:: Debugging information in separate files
20140 * MiniDebugInfo:: Debugging information in a special section
20141 * Index Files:: Index files speed up GDB
20142 * Symbol Errors:: Errors reading symbol files
20143 * Data Files:: GDB data files
20144 @end menu
20145
20146 @node Files
20147 @section Commands to Specify Files
20148
20149 @cindex symbol table
20150 @cindex core dump file
20151
20152 You may want to specify executable and core dump file names. The usual
20153 way to do this is at start-up time, using the arguments to
20154 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20155 Out of @value{GDBN}}).
20156
20157 Occasionally it is necessary to change to a different file during a
20158 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20159 specify a file you want to use. Or you are debugging a remote target
20160 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20161 Program}). In these situations the @value{GDBN} commands to specify
20162 new files are useful.
20163
20164 @table @code
20165 @cindex executable file
20166 @kindex file
20167 @item file @var{filename}
20168 Use @var{filename} as the program to be debugged. It is read for its
20169 symbols and for the contents of pure memory. It is also the program
20170 executed when you use the @code{run} command. If you do not specify a
20171 directory and the file is not found in the @value{GDBN} working directory,
20172 @value{GDBN} uses the environment variable @code{PATH} as a list of
20173 directories to search, just as the shell does when looking for a program
20174 to run. You can change the value of this variable, for both @value{GDBN}
20175 and your program, using the @code{path} command.
20176
20177 @cindex unlinked object files
20178 @cindex patching object files
20179 You can load unlinked object @file{.o} files into @value{GDBN} using
20180 the @code{file} command. You will not be able to ``run'' an object
20181 file, but you can disassemble functions and inspect variables. Also,
20182 if the underlying BFD functionality supports it, you could use
20183 @kbd{gdb -write} to patch object files using this technique. Note
20184 that @value{GDBN} can neither interpret nor modify relocations in this
20185 case, so branches and some initialized variables will appear to go to
20186 the wrong place. But this feature is still handy from time to time.
20187
20188 @item file
20189 @code{file} with no argument makes @value{GDBN} discard any information it
20190 has on both executable file and the symbol table.
20191
20192 @kindex exec-file
20193 @item exec-file @r{[} @var{filename} @r{]}
20194 Specify that the program to be run (but not the symbol table) is found
20195 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20196 if necessary to locate your program. Omitting @var{filename} means to
20197 discard information on the executable file.
20198
20199 @kindex symbol-file
20200 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20201 Read symbol table information from file @var{filename}. @code{PATH} is
20202 searched when necessary. Use the @code{file} command to get both symbol
20203 table and program to run from the same file.
20204
20205 If an optional @var{offset} is specified, it is added to the start
20206 address of each section in the symbol file. This is useful if the
20207 program is relocated at runtime, such as the Linux kernel with kASLR
20208 enabled.
20209
20210 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20211 program's symbol table.
20212
20213 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20214 some breakpoints and auto-display expressions. This is because they may
20215 contain pointers to the internal data recording symbols and data types,
20216 which are part of the old symbol table data being discarded inside
20217 @value{GDBN}.
20218
20219 @code{symbol-file} does not repeat if you press @key{RET} again after
20220 executing it once.
20221
20222 When @value{GDBN} is configured for a particular environment, it
20223 understands debugging information in whatever format is the standard
20224 generated for that environment; you may use either a @sc{gnu} compiler, or
20225 other compilers that adhere to the local conventions.
20226 Best results are usually obtained from @sc{gnu} compilers; for example,
20227 using @code{@value{NGCC}} you can generate debugging information for
20228 optimized code.
20229
20230 For most kinds of object files, with the exception of old SVR3 systems
20231 using COFF, the @code{symbol-file} command does not normally read the
20232 symbol table in full right away. Instead, it scans the symbol table
20233 quickly to find which source files and which symbols are present. The
20234 details are read later, one source file at a time, as they are needed.
20235
20236 The purpose of this two-stage reading strategy is to make @value{GDBN}
20237 start up faster. For the most part, it is invisible except for
20238 occasional pauses while the symbol table details for a particular source
20239 file are being read. (The @code{set verbose} command can turn these
20240 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20241 Warnings and Messages}.)
20242
20243 We have not implemented the two-stage strategy for COFF yet. When the
20244 symbol table is stored in COFF format, @code{symbol-file} reads the
20245 symbol table data in full right away. Note that ``stabs-in-COFF''
20246 still does the two-stage strategy, since the debug info is actually
20247 in stabs format.
20248
20249 @kindex readnow
20250 @cindex reading symbols immediately
20251 @cindex symbols, reading immediately
20252 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20253 @itemx file @r{[} -readnow @r{]} @var{filename}
20254 You can override the @value{GDBN} two-stage strategy for reading symbol
20255 tables by using the @samp{-readnow} option with any of the commands that
20256 load symbol table information, if you want to be sure @value{GDBN} has the
20257 entire symbol table available.
20258
20259 @cindex @code{-readnever}, option for symbol-file command
20260 @cindex never read symbols
20261 @cindex symbols, never read
20262 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20263 @itemx file @r{[} -readnever @r{]} @var{filename}
20264 You can instruct @value{GDBN} to never read the symbolic information
20265 contained in @var{filename} by using the @samp{-readnever} option.
20266 @xref{--readnever}.
20267
20268 @c FIXME: for now no mention of directories, since this seems to be in
20269 @c flux. 13mar1992 status is that in theory GDB would look either in
20270 @c current dir or in same dir as myprog; but issues like competing
20271 @c GDB's, or clutter in system dirs, mean that in practice right now
20272 @c only current dir is used. FFish says maybe a special GDB hierarchy
20273 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20274 @c files.
20275
20276 @kindex core-file
20277 @item core-file @r{[}@var{filename}@r{]}
20278 @itemx core
20279 Specify the whereabouts of a core dump file to be used as the ``contents
20280 of memory''. Traditionally, core files contain only some parts of the
20281 address space of the process that generated them; @value{GDBN} can access the
20282 executable file itself for other parts.
20283
20284 @code{core-file} with no argument specifies that no core file is
20285 to be used.
20286
20287 Note that the core file is ignored when your program is actually running
20288 under @value{GDBN}. So, if you have been running your program and you
20289 wish to debug a core file instead, you must kill the subprocess in which
20290 the program is running. To do this, use the @code{kill} command
20291 (@pxref{Kill Process, ,Killing the Child Process}).
20292
20293 @kindex add-symbol-file
20294 @cindex dynamic linking
20295 @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{]}
20296 The @code{add-symbol-file} command reads additional symbol table
20297 information from the file @var{filename}. You would use this command
20298 when @var{filename} has been dynamically loaded (by some other means)
20299 into the program that is running. The @var{textaddress} parameter gives
20300 the memory address at which the file's text section has been loaded.
20301 You can additionally specify the base address of other sections using
20302 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20303 If a section is omitted, @value{GDBN} will use its default addresses
20304 as found in @var{filename}. Any @var{address} or @var{textaddress}
20305 can be given as an expression.
20306
20307 If an optional @var{offset} is specified, it is added to the start
20308 address of each section, except those for which the address was
20309 specified explicitly.
20310
20311 The symbol table of the file @var{filename} is added to the symbol table
20312 originally read with the @code{symbol-file} command. You can use the
20313 @code{add-symbol-file} command any number of times; the new symbol data
20314 thus read is kept in addition to the old.
20315
20316 Changes can be reverted using the command @code{remove-symbol-file}.
20317
20318 @cindex relocatable object files, reading symbols from
20319 @cindex object files, relocatable, reading symbols from
20320 @cindex reading symbols from relocatable object files
20321 @cindex symbols, reading from relocatable object files
20322 @cindex @file{.o} files, reading symbols from
20323 Although @var{filename} is typically a shared library file, an
20324 executable file, or some other object file which has been fully
20325 relocated for loading into a process, you can also load symbolic
20326 information from relocatable @file{.o} files, as long as:
20327
20328 @itemize @bullet
20329 @item
20330 the file's symbolic information refers only to linker symbols defined in
20331 that file, not to symbols defined by other object files,
20332 @item
20333 every section the file's symbolic information refers to has actually
20334 been loaded into the inferior, as it appears in the file, and
20335 @item
20336 you can determine the address at which every section was loaded, and
20337 provide these to the @code{add-symbol-file} command.
20338 @end itemize
20339
20340 @noindent
20341 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20342 relocatable files into an already running program; such systems
20343 typically make the requirements above easy to meet. However, it's
20344 important to recognize that many native systems use complex link
20345 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20346 assembly, for example) that make the requirements difficult to meet. In
20347 general, one cannot assume that using @code{add-symbol-file} to read a
20348 relocatable object file's symbolic information will have the same effect
20349 as linking the relocatable object file into the program in the normal
20350 way.
20351
20352 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20353
20354 @kindex remove-symbol-file
20355 @item remove-symbol-file @var{filename}
20356 @item remove-symbol-file -a @var{address}
20357 Remove a symbol file added via the @code{add-symbol-file} command. The
20358 file to remove can be identified by its @var{filename} or by an @var{address}
20359 that lies within the boundaries of this symbol file in memory. Example:
20360
20361 @smallexample
20362 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20363 add symbol table from file "/home/user/gdb/mylib.so" at
20364 .text_addr = 0x7ffff7ff9480
20365 (y or n) y
20366 Reading symbols from /home/user/gdb/mylib.so...
20367 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20368 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20369 (gdb)
20370 @end smallexample
20371
20372
20373 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20374
20375 @kindex add-symbol-file-from-memory
20376 @cindex @code{syscall DSO}
20377 @cindex load symbols from memory
20378 @item add-symbol-file-from-memory @var{address}
20379 Load symbols from the given @var{address} in a dynamically loaded
20380 object file whose image is mapped directly into the inferior's memory.
20381 For example, the Linux kernel maps a @code{syscall DSO} into each
20382 process's address space; this DSO provides kernel-specific code for
20383 some system calls. The argument can be any expression whose
20384 evaluation yields the address of the file's shared object file header.
20385 For this command to work, you must have used @code{symbol-file} or
20386 @code{exec-file} commands in advance.
20387
20388 @kindex section
20389 @item section @var{section} @var{addr}
20390 The @code{section} command changes the base address of the named
20391 @var{section} of the exec file to @var{addr}. This can be used if the
20392 exec file does not contain section addresses, (such as in the
20393 @code{a.out} format), or when the addresses specified in the file
20394 itself are wrong. Each section must be changed separately. The
20395 @code{info files} command, described below, lists all the sections and
20396 their addresses.
20397
20398 @kindex info files
20399 @kindex info target
20400 @item info files
20401 @itemx info target
20402 @code{info files} and @code{info target} are synonymous; both print the
20403 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20404 including the names of the executable and core dump files currently in
20405 use by @value{GDBN}, and the files from which symbols were loaded. The
20406 command @code{help target} lists all possible targets rather than
20407 current ones.
20408
20409 @kindex maint info sections
20410 @item maint info sections
20411 Another command that can give you extra information about program sections
20412 is @code{maint info sections}. In addition to the section information
20413 displayed by @code{info files}, this command displays the flags and file
20414 offset of each section in the executable and core dump files. In addition,
20415 @code{maint info sections} provides the following command options (which
20416 may be arbitrarily combined):
20417
20418 @table @code
20419 @item ALLOBJ
20420 Display sections for all loaded object files, including shared libraries.
20421 @item @var{sections}
20422 Display info only for named @var{sections}.
20423 @item @var{section-flags}
20424 Display info only for sections for which @var{section-flags} are true.
20425 The section flags that @value{GDBN} currently knows about are:
20426 @table @code
20427 @item ALLOC
20428 Section will have space allocated in the process when loaded.
20429 Set for all sections except those containing debug information.
20430 @item LOAD
20431 Section will be loaded from the file into the child process memory.
20432 Set for pre-initialized code and data, clear for @code{.bss} sections.
20433 @item RELOC
20434 Section needs to be relocated before loading.
20435 @item READONLY
20436 Section cannot be modified by the child process.
20437 @item CODE
20438 Section contains executable code only.
20439 @item DATA
20440 Section contains data only (no executable code).
20441 @item ROM
20442 Section will reside in ROM.
20443 @item CONSTRUCTOR
20444 Section contains data for constructor/destructor lists.
20445 @item HAS_CONTENTS
20446 Section is not empty.
20447 @item NEVER_LOAD
20448 An instruction to the linker to not output the section.
20449 @item COFF_SHARED_LIBRARY
20450 A notification to the linker that the section contains
20451 COFF shared library information.
20452 @item IS_COMMON
20453 Section contains common symbols.
20454 @end table
20455 @end table
20456 @kindex set trust-readonly-sections
20457 @cindex read-only sections
20458 @item set trust-readonly-sections on
20459 Tell @value{GDBN} that readonly sections in your object file
20460 really are read-only (i.e.@: that their contents will not change).
20461 In that case, @value{GDBN} can fetch values from these sections
20462 out of the object file, rather than from the target program.
20463 For some targets (notably embedded ones), this can be a significant
20464 enhancement to debugging performance.
20465
20466 The default is off.
20467
20468 @item set trust-readonly-sections off
20469 Tell @value{GDBN} not to trust readonly sections. This means that
20470 the contents of the section might change while the program is running,
20471 and must therefore be fetched from the target when needed.
20472
20473 @item show trust-readonly-sections
20474 Show the current setting of trusting readonly sections.
20475 @end table
20476
20477 All file-specifying commands allow both absolute and relative file names
20478 as arguments. @value{GDBN} always converts the file name to an absolute file
20479 name and remembers it that way.
20480
20481 @cindex shared libraries
20482 @anchor{Shared Libraries}
20483 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20484 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20485 DSBT (TIC6X) shared libraries.
20486
20487 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20488 shared libraries. @xref{Expat}.
20489
20490 @value{GDBN} automatically loads symbol definitions from shared libraries
20491 when you use the @code{run} command, or when you examine a core file.
20492 (Before you issue the @code{run} command, @value{GDBN} does not understand
20493 references to a function in a shared library, however---unless you are
20494 debugging a core file).
20495
20496 @c FIXME: some @value{GDBN} release may permit some refs to undef
20497 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20498 @c FIXME...lib; check this from time to time when updating manual
20499
20500 There are times, however, when you may wish to not automatically load
20501 symbol definitions from shared libraries, such as when they are
20502 particularly large or there are many of them.
20503
20504 To control the automatic loading of shared library symbols, use the
20505 commands:
20506
20507 @table @code
20508 @kindex set auto-solib-add
20509 @item set auto-solib-add @var{mode}
20510 If @var{mode} is @code{on}, symbols from all shared object libraries
20511 will be loaded automatically when the inferior begins execution, you
20512 attach to an independently started inferior, or when the dynamic linker
20513 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20514 is @code{off}, symbols must be loaded manually, using the
20515 @code{sharedlibrary} command. The default value is @code{on}.
20516
20517 @cindex memory used for symbol tables
20518 If your program uses lots of shared libraries with debug info that
20519 takes large amounts of memory, you can decrease the @value{GDBN}
20520 memory footprint by preventing it from automatically loading the
20521 symbols from shared libraries. To that end, type @kbd{set
20522 auto-solib-add off} before running the inferior, then load each
20523 library whose debug symbols you do need with @kbd{sharedlibrary
20524 @var{regexp}}, where @var{regexp} is a regular expression that matches
20525 the libraries whose symbols you want to be loaded.
20526
20527 @kindex show auto-solib-add
20528 @item show auto-solib-add
20529 Display the current autoloading mode.
20530 @end table
20531
20532 @cindex load shared library
20533 To explicitly load shared library symbols, use the @code{sharedlibrary}
20534 command:
20535
20536 @table @code
20537 @kindex info sharedlibrary
20538 @kindex info share
20539 @item info share @var{regex}
20540 @itemx info sharedlibrary @var{regex}
20541 Print the names of the shared libraries which are currently loaded
20542 that match @var{regex}. If @var{regex} is omitted then print
20543 all shared libraries that are loaded.
20544
20545 @kindex info dll
20546 @item info dll @var{regex}
20547 This is an alias of @code{info sharedlibrary}.
20548
20549 @kindex sharedlibrary
20550 @kindex share
20551 @item sharedlibrary @var{regex}
20552 @itemx share @var{regex}
20553 Load shared object library symbols for files matching a
20554 Unix regular expression.
20555 As with files loaded automatically, it only loads shared libraries
20556 required by your program for a core file or after typing @code{run}. If
20557 @var{regex} is omitted all shared libraries required by your program are
20558 loaded.
20559
20560 @item nosharedlibrary
20561 @kindex nosharedlibrary
20562 @cindex unload symbols from shared libraries
20563 Unload all shared object library symbols. This discards all symbols
20564 that have been loaded from all shared libraries. Symbols from shared
20565 libraries that were loaded by explicit user requests are not
20566 discarded.
20567 @end table
20568
20569 Sometimes you may wish that @value{GDBN} stops and gives you control
20570 when any of shared library events happen. The best way to do this is
20571 to use @code{catch load} and @code{catch unload} (@pxref{Set
20572 Catchpoints}).
20573
20574 @value{GDBN} also supports the @code{set stop-on-solib-events}
20575 command for this. This command exists for historical reasons. It is
20576 less useful than setting a catchpoint, because it does not allow for
20577 conditions or commands as a catchpoint does.
20578
20579 @table @code
20580 @item set stop-on-solib-events
20581 @kindex set stop-on-solib-events
20582 This command controls whether @value{GDBN} should give you control
20583 when the dynamic linker notifies it about some shared library event.
20584 The most common event of interest is loading or unloading of a new
20585 shared library.
20586
20587 @item show stop-on-solib-events
20588 @kindex show stop-on-solib-events
20589 Show whether @value{GDBN} stops and gives you control when shared
20590 library events happen.
20591 @end table
20592
20593 Shared libraries are also supported in many cross or remote debugging
20594 configurations. @value{GDBN} needs to have access to the target's libraries;
20595 this can be accomplished either by providing copies of the libraries
20596 on the host system, or by asking @value{GDBN} to automatically retrieve the
20597 libraries from the target. If copies of the target libraries are
20598 provided, they need to be the same as the target libraries, although the
20599 copies on the target can be stripped as long as the copies on the host are
20600 not.
20601
20602 @cindex where to look for shared libraries
20603 For remote debugging, you need to tell @value{GDBN} where the target
20604 libraries are, so that it can load the correct copies---otherwise, it
20605 may try to load the host's libraries. @value{GDBN} has two variables
20606 to specify the search directories for target libraries.
20607
20608 @table @code
20609 @cindex prefix for executable and shared library file names
20610 @cindex system root, alternate
20611 @kindex set solib-absolute-prefix
20612 @kindex set sysroot
20613 @item set sysroot @var{path}
20614 Use @var{path} as the system root for the program being debugged. Any
20615 absolute shared library paths will be prefixed with @var{path}; many
20616 runtime loaders store the absolute paths to the shared library in the
20617 target program's memory. When starting processes remotely, and when
20618 attaching to already-running processes (local or remote), their
20619 executable filenames will be prefixed with @var{path} if reported to
20620 @value{GDBN} as absolute by the operating system. If you use
20621 @code{set sysroot} to find executables and shared libraries, they need
20622 to be laid out in the same way that they are on the target, with
20623 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20624 @var{path}.
20625
20626 If @var{path} starts with the sequence @file{target:} and the target
20627 system is remote then @value{GDBN} will retrieve the target binaries
20628 from the remote system. This is only supported when using a remote
20629 target that supports the @code{remote get} command (@pxref{File
20630 Transfer,,Sending files to a remote system}). The part of @var{path}
20631 following the initial @file{target:} (if present) is used as system
20632 root prefix on the remote file system. If @var{path} starts with the
20633 sequence @file{remote:} this is converted to the sequence
20634 @file{target:} by @code{set sysroot}@footnote{Historically the
20635 functionality to retrieve binaries from the remote system was
20636 provided by prefixing @var{path} with @file{remote:}}. If you want
20637 to specify a local system root using a directory that happens to be
20638 named @file{target:} or @file{remote:}, you need to use some
20639 equivalent variant of the name like @file{./target:}.
20640
20641 For targets with an MS-DOS based filesystem, such as MS-Windows and
20642 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20643 absolute file name with @var{path}. But first, on Unix hosts,
20644 @value{GDBN} converts all backslash directory separators into forward
20645 slashes, because the backslash is not a directory separator on Unix:
20646
20647 @smallexample
20648 c:\foo\bar.dll @result{} c:/foo/bar.dll
20649 @end smallexample
20650
20651 Then, @value{GDBN} attempts prefixing the target file name with
20652 @var{path}, and looks for the resulting file name in the host file
20653 system:
20654
20655 @smallexample
20656 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20657 @end smallexample
20658
20659 If that does not find the binary, @value{GDBN} tries removing
20660 the @samp{:} character from the drive spec, both for convenience, and,
20661 for the case of the host file system not supporting file names with
20662 colons:
20663
20664 @smallexample
20665 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20666 @end smallexample
20667
20668 This makes it possible to have a system root that mirrors a target
20669 with more than one drive. E.g., you may want to setup your local
20670 copies of the target system shared libraries like so (note @samp{c} vs
20671 @samp{z}):
20672
20673 @smallexample
20674 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20675 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20676 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20677 @end smallexample
20678
20679 @noindent
20680 and point the system root at @file{/path/to/sysroot}, so that
20681 @value{GDBN} can find the correct copies of both
20682 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20683
20684 If that still does not find the binary, @value{GDBN} tries
20685 removing the whole drive spec from the target file name:
20686
20687 @smallexample
20688 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20689 @end smallexample
20690
20691 This last lookup makes it possible to not care about the drive name,
20692 if you don't want or need to.
20693
20694 The @code{set solib-absolute-prefix} command is an alias for @code{set
20695 sysroot}.
20696
20697 @cindex default system root
20698 @cindex @samp{--with-sysroot}
20699 You can set the default system root by using the configure-time
20700 @samp{--with-sysroot} option. If the system root is inside
20701 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20702 @samp{--exec-prefix}), then the default system root will be updated
20703 automatically if the installed @value{GDBN} is moved to a new
20704 location.
20705
20706 @kindex show sysroot
20707 @item show sysroot
20708 Display the current executable and shared library prefix.
20709
20710 @kindex set solib-search-path
20711 @item set solib-search-path @var{path}
20712 If this variable is set, @var{path} is a colon-separated list of
20713 directories to search for shared libraries. @samp{solib-search-path}
20714 is used after @samp{sysroot} fails to locate the library, or if the
20715 path to the library is relative instead of absolute. If you want to
20716 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
20717 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
20718 finding your host's libraries. @samp{sysroot} is preferred; setting
20719 it to a nonexistent directory may interfere with automatic loading
20720 of shared library symbols.
20721
20722 @kindex show solib-search-path
20723 @item show solib-search-path
20724 Display the current shared library search path.
20725
20726 @cindex DOS file-name semantics of file names.
20727 @kindex set target-file-system-kind (unix|dos-based|auto)
20728 @kindex show target-file-system-kind
20729 @item set target-file-system-kind @var{kind}
20730 Set assumed file system kind for target reported file names.
20731
20732 Shared library file names as reported by the target system may not
20733 make sense as is on the system @value{GDBN} is running on. For
20734 example, when remote debugging a target that has MS-DOS based file
20735 system semantics, from a Unix host, the target may be reporting to
20736 @value{GDBN} a list of loaded shared libraries with file names such as
20737 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20738 drive letters, so the @samp{c:\} prefix is not normally understood as
20739 indicating an absolute file name, and neither is the backslash
20740 normally considered a directory separator character. In that case,
20741 the native file system would interpret this whole absolute file name
20742 as a relative file name with no directory components. This would make
20743 it impossible to point @value{GDBN} at a copy of the remote target's
20744 shared libraries on the host using @code{set sysroot}, and impractical
20745 with @code{set solib-search-path}. Setting
20746 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20747 to interpret such file names similarly to how the target would, and to
20748 map them to file names valid on @value{GDBN}'s native file system
20749 semantics. The value of @var{kind} can be @code{"auto"}, in addition
20750 to one of the supported file system kinds. In that case, @value{GDBN}
20751 tries to determine the appropriate file system variant based on the
20752 current target's operating system (@pxref{ABI, ,Configuring the
20753 Current ABI}). The supported file system settings are:
20754
20755 @table @code
20756 @item unix
20757 Instruct @value{GDBN} to assume the target file system is of Unix
20758 kind. Only file names starting the forward slash (@samp{/}) character
20759 are considered absolute, and the directory separator character is also
20760 the forward slash.
20761
20762 @item dos-based
20763 Instruct @value{GDBN} to assume the target file system is DOS based.
20764 File names starting with either a forward slash, or a drive letter
20765 followed by a colon (e.g., @samp{c:}), are considered absolute, and
20766 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20767 considered directory separators.
20768
20769 @item auto
20770 Instruct @value{GDBN} to use the file system kind associated with the
20771 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20772 This is the default.
20773 @end table
20774 @end table
20775
20776 @cindex file name canonicalization
20777 @cindex base name differences
20778 When processing file names provided by the user, @value{GDBN}
20779 frequently needs to compare them to the file names recorded in the
20780 program's debug info. Normally, @value{GDBN} compares just the
20781 @dfn{base names} of the files as strings, which is reasonably fast
20782 even for very large programs. (The base name of a file is the last
20783 portion of its name, after stripping all the leading directories.)
20784 This shortcut in comparison is based upon the assumption that files
20785 cannot have more than one base name. This is usually true, but
20786 references to files that use symlinks or similar filesystem
20787 facilities violate that assumption. If your program records files
20788 using such facilities, or if you provide file names to @value{GDBN}
20789 using symlinks etc., you can set @code{basenames-may-differ} to
20790 @code{true} to instruct @value{GDBN} to completely canonicalize each
20791 pair of file names it needs to compare. This will make file-name
20792 comparisons accurate, but at a price of a significant slowdown.
20793
20794 @table @code
20795 @item set basenames-may-differ
20796 @kindex set basenames-may-differ
20797 Set whether a source file may have multiple base names.
20798
20799 @item show basenames-may-differ
20800 @kindex show basenames-may-differ
20801 Show whether a source file may have multiple base names.
20802 @end table
20803
20804 @node File Caching
20805 @section File Caching
20806 @cindex caching of opened files
20807 @cindex caching of bfd objects
20808
20809 To speed up file loading, and reduce memory usage, @value{GDBN} will
20810 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20811 BFD, bfd, The Binary File Descriptor Library}. The following commands
20812 allow visibility and control of the caching behavior.
20813
20814 @table @code
20815 @kindex maint info bfds
20816 @item maint info bfds
20817 This prints information about each @code{bfd} object that is known to
20818 @value{GDBN}.
20819
20820 @kindex maint set bfd-sharing
20821 @kindex maint show bfd-sharing
20822 @kindex bfd caching
20823 @item maint set bfd-sharing
20824 @item maint show bfd-sharing
20825 Control whether @code{bfd} objects can be shared. When sharing is
20826 enabled @value{GDBN} reuses already open @code{bfd} objects rather
20827 than reopening the same file. Turning sharing off does not cause
20828 already shared @code{bfd} objects to be unshared, but all future files
20829 that are opened will create a new @code{bfd} object. Similarly,
20830 re-enabling sharing does not cause multiple existing @code{bfd}
20831 objects to be collapsed into a single shared @code{bfd} object.
20832
20833 @kindex set debug bfd-cache @var{level}
20834 @kindex bfd caching
20835 @item set debug bfd-cache @var{level}
20836 Turns on debugging of the bfd cache, setting the level to @var{level}.
20837
20838 @kindex show debug bfd-cache
20839 @kindex bfd caching
20840 @item show debug bfd-cache
20841 Show the current debugging level of the bfd cache.
20842 @end table
20843
20844 @node Separate Debug Files
20845 @section Debugging Information in Separate Files
20846 @cindex separate debugging information files
20847 @cindex debugging information in separate files
20848 @cindex @file{.debug} subdirectories
20849 @cindex debugging information directory, global
20850 @cindex global debugging information directories
20851 @cindex build ID, and separate debugging files
20852 @cindex @file{.build-id} directory
20853
20854 @value{GDBN} allows you to put a program's debugging information in a
20855 file separate from the executable itself, in a way that allows
20856 @value{GDBN} to find and load the debugging information automatically.
20857 Since debugging information can be very large---sometimes larger
20858 than the executable code itself---some systems distribute debugging
20859 information for their executables in separate files, which users can
20860 install only when they need to debug a problem.
20861
20862 @value{GDBN} supports two ways of specifying the separate debug info
20863 file:
20864
20865 @itemize @bullet
20866 @item
20867 The executable contains a @dfn{debug link} that specifies the name of
20868 the separate debug info file. The separate debug file's name is
20869 usually @file{@var{executable}.debug}, where @var{executable} is the
20870 name of the corresponding executable file without leading directories
20871 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
20872 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20873 checksum for the debug file, which @value{GDBN} uses to validate that
20874 the executable and the debug file came from the same build.
20875
20876 @item
20877 The executable contains a @dfn{build ID}, a unique bit string that is
20878 also present in the corresponding debug info file. (This is supported
20879 only on some operating systems, when using the ELF or PE file formats
20880 for binary files and the @sc{gnu} Binutils.) For more details about
20881 this feature, see the description of the @option{--build-id}
20882 command-line option in @ref{Options, , Command Line Options, ld,
20883 The GNU Linker}. The debug info file's name is not specified
20884 explicitly by the build ID, but can be computed from the build ID, see
20885 below.
20886 @end itemize
20887
20888 Depending on the way the debug info file is specified, @value{GDBN}
20889 uses two different methods of looking for the debug file:
20890
20891 @itemize @bullet
20892 @item
20893 For the ``debug link'' method, @value{GDBN} looks up the named file in
20894 the directory of the executable file, then in a subdirectory of that
20895 directory named @file{.debug}, and finally under each one of the
20896 global debug directories, in a subdirectory whose name is identical to
20897 the leading directories of the executable's absolute file name. (On
20898 MS-Windows/MS-DOS, the drive letter of the executable's leading
20899 directories is converted to a one-letter subdirectory, i.e.@:
20900 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20901 filesystems disallow colons in file names.)
20902
20903 @item
20904 For the ``build ID'' method, @value{GDBN} looks in the
20905 @file{.build-id} subdirectory of each one of the global debug directories for
20906 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
20907 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
20908 are the rest of the bit string. (Real build ID strings are 32 or more
20909 hex characters, not 10.)
20910 @end itemize
20911
20912 So, for example, suppose you ask @value{GDBN} to debug
20913 @file{/usr/bin/ls}, which has a debug link that specifies the
20914 file @file{ls.debug}, and a build ID whose value in hex is
20915 @code{abcdef1234}. If the list of the global debug directories includes
20916 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
20917 debug information files, in the indicated order:
20918
20919 @itemize @minus
20920 @item
20921 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
20922 @item
20923 @file{/usr/bin/ls.debug}
20924 @item
20925 @file{/usr/bin/.debug/ls.debug}
20926 @item
20927 @file{/usr/lib/debug/usr/bin/ls.debug}.
20928 @end itemize
20929
20930 @anchor{debug-file-directory}
20931 Global debugging info directories default to what is set by @value{GDBN}
20932 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
20933 you can also set the global debugging info directories, and view the list
20934 @value{GDBN} is currently using.
20935
20936 @table @code
20937
20938 @kindex set debug-file-directory
20939 @item set debug-file-directory @var{directories}
20940 Set the directories which @value{GDBN} searches for separate debugging
20941 information files to @var{directory}. Multiple path components can be set
20942 concatenating them by a path separator.
20943
20944 @kindex show debug-file-directory
20945 @item show debug-file-directory
20946 Show the directories @value{GDBN} searches for separate debugging
20947 information files.
20948
20949 @end table
20950
20951 @cindex @code{.gnu_debuglink} sections
20952 @cindex debug link sections
20953 A debug link is a special section of the executable file named
20954 @code{.gnu_debuglink}. The section must contain:
20955
20956 @itemize
20957 @item
20958 A filename, with any leading directory components removed, followed by
20959 a zero byte,
20960 @item
20961 zero to three bytes of padding, as needed to reach the next four-byte
20962 boundary within the section, and
20963 @item
20964 a four-byte CRC checksum, stored in the same endianness used for the
20965 executable file itself. The checksum is computed on the debugging
20966 information file's full contents by the function given below, passing
20967 zero as the @var{crc} argument.
20968 @end itemize
20969
20970 Any executable file format can carry a debug link, as long as it can
20971 contain a section named @code{.gnu_debuglink} with the contents
20972 described above.
20973
20974 @cindex @code{.note.gnu.build-id} sections
20975 @cindex build ID sections
20976 The build ID is a special section in the executable file (and in other
20977 ELF binary files that @value{GDBN} may consider). This section is
20978 often named @code{.note.gnu.build-id}, but that name is not mandatory.
20979 It contains unique identification for the built files---the ID remains
20980 the same across multiple builds of the same build tree. The default
20981 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
20982 content for the build ID string. The same section with an identical
20983 value is present in the original built binary with symbols, in its
20984 stripped variant, and in the separate debugging information file.
20985
20986 The debugging information file itself should be an ordinary
20987 executable, containing a full set of linker symbols, sections, and
20988 debugging information. The sections of the debugging information file
20989 should have the same names, addresses, and sizes as the original file,
20990 but they need not contain any data---much like a @code{.bss} section
20991 in an ordinary executable.
20992
20993 The @sc{gnu} binary utilities (Binutils) package includes the
20994 @samp{objcopy} utility that can produce
20995 the separated executable / debugging information file pairs using the
20996 following commands:
20997
20998 @smallexample
20999 @kbd{objcopy --only-keep-debug foo foo.debug}
21000 @kbd{strip -g foo}
21001 @end smallexample
21002
21003 @noindent
21004 These commands remove the debugging
21005 information from the executable file @file{foo} and place it in the file
21006 @file{foo.debug}. You can use the first, second or both methods to link the
21007 two files:
21008
21009 @itemize @bullet
21010 @item
21011 The debug link method needs the following additional command to also leave
21012 behind a debug link in @file{foo}:
21013
21014 @smallexample
21015 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21016 @end smallexample
21017
21018 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21019 a version of the @code{strip} command such that the command @kbd{strip foo -f
21020 foo.debug} has the same functionality as the two @code{objcopy} commands and
21021 the @code{ln -s} command above, together.
21022
21023 @item
21024 Build ID gets embedded into the main executable using @code{ld --build-id} or
21025 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21026 compatibility fixes for debug files separation are present in @sc{gnu} binary
21027 utilities (Binutils) package since version 2.18.
21028 @end itemize
21029
21030 @noindent
21031
21032 @cindex CRC algorithm definition
21033 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21034 IEEE 802.3 using the polynomial:
21035
21036 @c TexInfo requires naked braces for multi-digit exponents for Tex
21037 @c output, but this causes HTML output to barf. HTML has to be set using
21038 @c raw commands. So we end up having to specify this equation in 2
21039 @c different ways!
21040 @ifhtml
21041 @display
21042 @html
21043 <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>
21044 + <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
21045 @end html
21046 @end display
21047 @end ifhtml
21048 @ifnothtml
21049 @display
21050 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21051 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21052 @end display
21053 @end ifnothtml
21054
21055 The function is computed byte at a time, taking the least
21056 significant bit of each byte first. The initial pattern
21057 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21058 the final result is inverted to ensure trailing zeros also affect the
21059 CRC.
21060
21061 @emph{Note:} This is the same CRC polynomial as used in handling the
21062 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21063 However in the case of the Remote Serial Protocol, the CRC is computed
21064 @emph{most} significant bit first, and the result is not inverted, so
21065 trailing zeros have no effect on the CRC value.
21066
21067 To complete the description, we show below the code of the function
21068 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21069 initially supplied @code{crc} argument means that an initial call to
21070 this function passing in zero will start computing the CRC using
21071 @code{0xffffffff}.
21072
21073 @kindex gnu_debuglink_crc32
21074 @smallexample
21075 unsigned long
21076 gnu_debuglink_crc32 (unsigned long crc,
21077 unsigned char *buf, size_t len)
21078 @{
21079 static const unsigned long crc32_table[256] =
21080 @{
21081 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21082 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21083 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21084 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21085 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21086 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21087 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21088 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21089 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21090 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21091 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21092 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21093 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21094 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21095 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21096 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21097 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21098 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21099 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21100 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21101 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21102 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21103 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21104 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21105 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21106 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21107 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21108 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21109 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21110 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21111 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21112 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21113 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21114 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21115 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21116 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21117 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21118 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21119 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21120 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21121 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21122 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21123 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21124 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21125 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21126 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21127 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21128 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21129 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21130 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21131 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21132 0x2d02ef8d
21133 @};
21134 unsigned char *end;
21135
21136 crc = ~crc & 0xffffffff;
21137 for (end = buf + len; buf < end; ++buf)
21138 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21139 return ~crc & 0xffffffff;
21140 @}
21141 @end smallexample
21142
21143 @noindent
21144 This computation does not apply to the ``build ID'' method.
21145
21146 @node MiniDebugInfo
21147 @section Debugging information in a special section
21148 @cindex separate debug sections
21149 @cindex @samp{.gnu_debugdata} section
21150
21151 Some systems ship pre-built executables and libraries that have a
21152 special @samp{.gnu_debugdata} section. This feature is called
21153 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21154 is used to supply extra symbols for backtraces.
21155
21156 The intent of this section is to provide extra minimal debugging
21157 information for use in simple backtraces. It is not intended to be a
21158 replacement for full separate debugging information (@pxref{Separate
21159 Debug Files}). The example below shows the intended use; however,
21160 @value{GDBN} does not currently put restrictions on what sort of
21161 debugging information might be included in the section.
21162
21163 @value{GDBN} has support for this extension. If the section exists,
21164 then it is used provided that no other source of debugging information
21165 can be found, and that @value{GDBN} was configured with LZMA support.
21166
21167 This section can be easily created using @command{objcopy} and other
21168 standard utilities:
21169
21170 @smallexample
21171 # Extract the dynamic symbols from the main binary, there is no need
21172 # to also have these in the normal symbol table.
21173 nm -D @var{binary} --format=posix --defined-only \
21174 | awk '@{ print $1 @}' | sort > dynsyms
21175
21176 # Extract all the text (i.e. function) symbols from the debuginfo.
21177 # (Note that we actually also accept "D" symbols, for the benefit
21178 # of platforms like PowerPC64 that use function descriptors.)
21179 nm @var{binary} --format=posix --defined-only \
21180 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21181 | sort > funcsyms
21182
21183 # Keep all the function symbols not already in the dynamic symbol
21184 # table.
21185 comm -13 dynsyms funcsyms > keep_symbols
21186
21187 # Separate full debug info into debug binary.
21188 objcopy --only-keep-debug @var{binary} debug
21189
21190 # Copy the full debuginfo, keeping only a minimal set of symbols and
21191 # removing some unnecessary sections.
21192 objcopy -S --remove-section .gdb_index --remove-section .comment \
21193 --keep-symbols=keep_symbols debug mini_debuginfo
21194
21195 # Drop the full debug info from the original binary.
21196 strip --strip-all -R .comment @var{binary}
21197
21198 # Inject the compressed data into the .gnu_debugdata section of the
21199 # original binary.
21200 xz mini_debuginfo
21201 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21202 @end smallexample
21203
21204 @node Index Files
21205 @section Index Files Speed Up @value{GDBN}
21206 @cindex index files
21207 @cindex @samp{.gdb_index} section
21208
21209 When @value{GDBN} finds a symbol file, it scans the symbols in the
21210 file in order to construct an internal symbol table. This lets most
21211 @value{GDBN} operations work quickly---at the cost of a delay early
21212 on. For large programs, this delay can be quite lengthy, so
21213 @value{GDBN} provides a way to build an index, which speeds up
21214 startup.
21215
21216 For convenience, @value{GDBN} comes with a program,
21217 @command{gdb-add-index}, which can be used to add the index to a
21218 symbol file. It takes the symbol file as its only argument:
21219
21220 @smallexample
21221 $ gdb-add-index symfile
21222 @end smallexample
21223
21224 @xref{gdb-add-index}.
21225
21226 It is also possible to do the work manually. Here is what
21227 @command{gdb-add-index} does behind the curtains.
21228
21229 The index is stored as a section in the symbol file. @value{GDBN} can
21230 write the index to a file, then you can put it into the symbol file
21231 using @command{objcopy}.
21232
21233 To create an index file, use the @code{save gdb-index} command:
21234
21235 @table @code
21236 @item save gdb-index [-dwarf-5] @var{directory}
21237 @kindex save gdb-index
21238 Create index files for all symbol files currently known by
21239 @value{GDBN}. For each known @var{symbol-file}, this command by
21240 default creates it produces a single file
21241 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21242 the @option{-dwarf-5} option, it produces 2 files:
21243 @file{@var{symbol-file}.debug_names} and
21244 @file{@var{symbol-file}.debug_str}. The files are created in the
21245 given @var{directory}.
21246 @end table
21247
21248 Once you have created an index file you can merge it into your symbol
21249 file, here named @file{symfile}, using @command{objcopy}:
21250
21251 @smallexample
21252 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21253 --set-section-flags .gdb_index=readonly symfile symfile
21254 @end smallexample
21255
21256 Or for @code{-dwarf-5}:
21257
21258 @smallexample
21259 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21260 $ cat symfile.debug_str >>symfile.debug_str.new
21261 $ objcopy --add-section .debug_names=symfile.gdb-index \
21262 --set-section-flags .debug_names=readonly \
21263 --update-section .debug_str=symfile.debug_str.new symfile symfile
21264 @end smallexample
21265
21266 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21267 sections that have been deprecated. Usually they are deprecated because
21268 they are missing a new feature or have performance issues.
21269 To tell @value{GDBN} to use a deprecated index section anyway
21270 specify @code{set use-deprecated-index-sections on}.
21271 The default is @code{off}.
21272 This can speed up startup, but may result in some functionality being lost.
21273 @xref{Index Section Format}.
21274
21275 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21276 must be done before gdb reads the file. The following will not work:
21277
21278 @smallexample
21279 $ gdb -ex "set use-deprecated-index-sections on" <program>
21280 @end smallexample
21281
21282 Instead you must do, for example,
21283
21284 @smallexample
21285 $ gdb -iex "set use-deprecated-index-sections on" <program>
21286 @end smallexample
21287
21288 There are currently some limitation on indices. They only work when
21289 using DWARF debugging information, not stabs. And, only the
21290 @code{-dwarf-5} index works for programs using Ada.
21291
21292 @subsection Automatic symbol index cache
21293
21294 @cindex automatic symbol index cache
21295 It is possible for @value{GDBN} to automatically save a copy of this index in a
21296 cache on disk and retrieve it from there when loading the same binary in the
21297 future. This feature can be turned on with @kbd{set index-cache on}. The
21298 following commands can be used to tweak the behavior of the index cache.
21299
21300 @table @code
21301
21302 @kindex set index-cache
21303 @item set index-cache on
21304 @itemx set index-cache off
21305 Enable or disable the use of the symbol index cache.
21306
21307 @item set index-cache directory @var{directory}
21308 @kindex show index-cache
21309 @itemx show index-cache directory
21310 Set/show the directory where index files will be saved.
21311
21312 The default value for this directory depends on the host platform. On
21313 most systems, the index is cached in the @file{gdb} subdirectory of
21314 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21315 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21316 of your home directory. However, on some systems, the default may
21317 differ according to local convention.
21318
21319 There is no limit on the disk space used by index cache. It is perfectly safe
21320 to delete the content of that directory to free up disk space.
21321
21322 @item show index-cache stats
21323 Print the number of cache hits and misses since the launch of @value{GDBN}.
21324
21325 @end table
21326
21327 @node Symbol Errors
21328 @section Errors Reading Symbol Files
21329
21330 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21331 such as symbol types it does not recognize, or known bugs in compiler
21332 output. By default, @value{GDBN} does not notify you of such problems, since
21333 they are relatively common and primarily of interest to people
21334 debugging compilers. If you are interested in seeing information
21335 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21336 only one message about each such type of problem, no matter how many
21337 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21338 to see how many times the problems occur, with the @code{set
21339 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21340 Messages}).
21341
21342 The messages currently printed, and their meanings, include:
21343
21344 @table @code
21345 @item inner block not inside outer block in @var{symbol}
21346
21347 The symbol information shows where symbol scopes begin and end
21348 (such as at the start of a function or a block of statements). This
21349 error indicates that an inner scope block is not fully contained
21350 in its outer scope blocks.
21351
21352 @value{GDBN} circumvents the problem by treating the inner block as if it had
21353 the same scope as the outer block. In the error message, @var{symbol}
21354 may be shown as ``@code{(don't know)}'' if the outer block is not a
21355 function.
21356
21357 @item block at @var{address} out of order
21358
21359 The symbol information for symbol scope blocks should occur in
21360 order of increasing addresses. This error indicates that it does not
21361 do so.
21362
21363 @value{GDBN} does not circumvent this problem, and has trouble
21364 locating symbols in the source file whose symbols it is reading. (You
21365 can often determine what source file is affected by specifying
21366 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21367 Messages}.)
21368
21369 @item bad block start address patched
21370
21371 The symbol information for a symbol scope block has a start address
21372 smaller than the address of the preceding source line. This is known
21373 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21374
21375 @value{GDBN} circumvents the problem by treating the symbol scope block as
21376 starting on the previous source line.
21377
21378 @item bad string table offset in symbol @var{n}
21379
21380 @cindex foo
21381 Symbol number @var{n} contains a pointer into the string table which is
21382 larger than the size of the string table.
21383
21384 @value{GDBN} circumvents the problem by considering the symbol to have the
21385 name @code{foo}, which may cause other problems if many symbols end up
21386 with this name.
21387
21388 @item unknown symbol type @code{0x@var{nn}}
21389
21390 The symbol information contains new data types that @value{GDBN} does
21391 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21392 uncomprehended information, in hexadecimal.
21393
21394 @value{GDBN} circumvents the error by ignoring this symbol information.
21395 This usually allows you to debug your program, though certain symbols
21396 are not accessible. If you encounter such a problem and feel like
21397 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21398 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21399 and examine @code{*bufp} to see the symbol.
21400
21401 @item stub type has NULL name
21402
21403 @value{GDBN} could not find the full definition for a struct or class.
21404
21405 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21406 The symbol information for a C@t{++} member function is missing some
21407 information that recent versions of the compiler should have output for
21408 it.
21409
21410 @item info mismatch between compiler and debugger
21411
21412 @value{GDBN} could not parse a type specification output by the compiler.
21413
21414 @end table
21415
21416 @node Data Files
21417 @section GDB Data Files
21418
21419 @cindex prefix for data files
21420 @value{GDBN} will sometimes read an auxiliary data file. These files
21421 are kept in a directory known as the @dfn{data directory}.
21422
21423 You can set the data directory's name, and view the name @value{GDBN}
21424 is currently using.
21425
21426 @table @code
21427 @kindex set data-directory
21428 @item set data-directory @var{directory}
21429 Set the directory which @value{GDBN} searches for auxiliary data files
21430 to @var{directory}.
21431
21432 @kindex show data-directory
21433 @item show data-directory
21434 Show the directory @value{GDBN} searches for auxiliary data files.
21435 @end table
21436
21437 @cindex default data directory
21438 @cindex @samp{--with-gdb-datadir}
21439 You can set the default data directory by using the configure-time
21440 @samp{--with-gdb-datadir} option. If the data directory is inside
21441 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21442 @samp{--exec-prefix}), then the default data directory will be updated
21443 automatically if the installed @value{GDBN} is moved to a new
21444 location.
21445
21446 The data directory may also be specified with the
21447 @code{--data-directory} command line option.
21448 @xref{Mode Options}.
21449
21450 @node Targets
21451 @chapter Specifying a Debugging Target
21452
21453 @cindex debugging target
21454 A @dfn{target} is the execution environment occupied by your program.
21455
21456 Often, @value{GDBN} runs in the same host environment as your program;
21457 in that case, the debugging target is specified as a side effect when
21458 you use the @code{file} or @code{core} commands. When you need more
21459 flexibility---for example, running @value{GDBN} on a physically separate
21460 host, or controlling a standalone system over a serial port or a
21461 realtime system over a TCP/IP connection---you can use the @code{target}
21462 command to specify one of the target types configured for @value{GDBN}
21463 (@pxref{Target Commands, ,Commands for Managing Targets}).
21464
21465 @cindex target architecture
21466 It is possible to build @value{GDBN} for several different @dfn{target
21467 architectures}. When @value{GDBN} is built like that, you can choose
21468 one of the available architectures with the @kbd{set architecture}
21469 command.
21470
21471 @table @code
21472 @kindex set architecture
21473 @kindex show architecture
21474 @item set architecture @var{arch}
21475 This command sets the current target architecture to @var{arch}. The
21476 value of @var{arch} can be @code{"auto"}, in addition to one of the
21477 supported architectures.
21478
21479 @item show architecture
21480 Show the current target architecture.
21481
21482 @item set processor
21483 @itemx processor
21484 @kindex set processor
21485 @kindex show processor
21486 These are alias commands for, respectively, @code{set architecture}
21487 and @code{show architecture}.
21488 @end table
21489
21490 @menu
21491 * Active Targets:: Active targets
21492 * Target Commands:: Commands for managing targets
21493 * Byte Order:: Choosing target byte order
21494 @end menu
21495
21496 @node Active Targets
21497 @section Active Targets
21498
21499 @cindex stacking targets
21500 @cindex active targets
21501 @cindex multiple targets
21502
21503 There are multiple classes of targets such as: processes, executable files or
21504 recording sessions. Core files belong to the process class, making core file
21505 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21506 on multiple active targets, one in each class. This allows you to (for
21507 example) start a process and inspect its activity, while still having access to
21508 the executable file after the process finishes. Or if you start process
21509 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21510 presented a virtual layer of the recording target, while the process target
21511 remains stopped at the chronologically last point of the process execution.
21512
21513 Use the @code{core-file} and @code{exec-file} commands to select a new core
21514 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21515 specify as a target a process that is already running, use the @code{attach}
21516 command (@pxref{Attach, ,Debugging an Already-running Process}).
21517
21518 @node Target Commands
21519 @section Commands for Managing Targets
21520
21521 @table @code
21522 @item target @var{type} @var{parameters}
21523 Connects the @value{GDBN} host environment to a target machine or
21524 process. A target is typically a protocol for talking to debugging
21525 facilities. You use the argument @var{type} to specify the type or
21526 protocol of the target machine.
21527
21528 Further @var{parameters} are interpreted by the target protocol, but
21529 typically include things like device names or host names to connect
21530 with, process numbers, and baud rates.
21531
21532 The @code{target} command does not repeat if you press @key{RET} again
21533 after executing the command.
21534
21535 @kindex help target
21536 @item help target
21537 Displays the names of all targets available. To display targets
21538 currently selected, use either @code{info target} or @code{info files}
21539 (@pxref{Files, ,Commands to Specify Files}).
21540
21541 @item help target @var{name}
21542 Describe a particular target, including any parameters necessary to
21543 select it.
21544
21545 @kindex set gnutarget
21546 @item set gnutarget @var{args}
21547 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21548 knows whether it is reading an @dfn{executable},
21549 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21550 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21551 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21552
21553 @quotation
21554 @emph{Warning:} To specify a file format with @code{set gnutarget},
21555 you must know the actual BFD name.
21556 @end quotation
21557
21558 @noindent
21559 @xref{Files, , Commands to Specify Files}.
21560
21561 @kindex show gnutarget
21562 @item show gnutarget
21563 Use the @code{show gnutarget} command to display what file format
21564 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21565 @value{GDBN} will determine the file format for each file automatically,
21566 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21567 @end table
21568
21569 @cindex common targets
21570 Here are some common targets (available, or not, depending on the GDB
21571 configuration):
21572
21573 @table @code
21574 @kindex target
21575 @item target exec @var{program}
21576 @cindex executable file target
21577 An executable file. @samp{target exec @var{program}} is the same as
21578 @samp{exec-file @var{program}}.
21579
21580 @item target core @var{filename}
21581 @cindex core dump file target
21582 A core dump file. @samp{target core @var{filename}} is the same as
21583 @samp{core-file @var{filename}}.
21584
21585 @item target remote @var{medium}
21586 @cindex remote target
21587 A remote system connected to @value{GDBN} via a serial line or network
21588 connection. This command tells @value{GDBN} to use its own remote
21589 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21590
21591 For example, if you have a board connected to @file{/dev/ttya} on the
21592 machine running @value{GDBN}, you could say:
21593
21594 @smallexample
21595 target remote /dev/ttya
21596 @end smallexample
21597
21598 @code{target remote} supports the @code{load} command. This is only
21599 useful if you have some other way of getting the stub to the target
21600 system, and you can put it somewhere in memory where it won't get
21601 clobbered by the download.
21602
21603 @item target sim @r{[}@var{simargs}@r{]} @dots{}
21604 @cindex built-in simulator target
21605 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
21606 In general,
21607 @smallexample
21608 target sim
21609 load
21610 run
21611 @end smallexample
21612 @noindent
21613 works; however, you cannot assume that a specific memory map, device
21614 drivers, or even basic I/O is available, although some simulators do
21615 provide these. For info about any processor-specific simulator details,
21616 see the appropriate section in @ref{Embedded Processors, ,Embedded
21617 Processors}.
21618
21619 @item target native
21620 @cindex native target
21621 Setup for local/native process debugging. Useful to make the
21622 @code{run} command spawn native processes (likewise @code{attach},
21623 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21624 (@pxref{set auto-connect-native-target}).
21625
21626 @end table
21627
21628 Different targets are available on different configurations of @value{GDBN};
21629 your configuration may have more or fewer targets.
21630
21631 Many remote targets require you to download the executable's code once
21632 you've successfully established a connection. You may wish to control
21633 various aspects of this process.
21634
21635 @table @code
21636
21637 @item set hash
21638 @kindex set hash@r{, for remote monitors}
21639 @cindex hash mark while downloading
21640 This command controls whether a hash mark @samp{#} is displayed while
21641 downloading a file to the remote monitor. If on, a hash mark is
21642 displayed after each S-record is successfully downloaded to the
21643 monitor.
21644
21645 @item show hash
21646 @kindex show hash@r{, for remote monitors}
21647 Show the current status of displaying the hash mark.
21648
21649 @item set debug monitor
21650 @kindex set debug monitor
21651 @cindex display remote monitor communications
21652 Enable or disable display of communications messages between
21653 @value{GDBN} and the remote monitor.
21654
21655 @item show debug monitor
21656 @kindex show debug monitor
21657 Show the current status of displaying communications between
21658 @value{GDBN} and the remote monitor.
21659 @end table
21660
21661 @table @code
21662
21663 @kindex load @var{filename} @var{offset}
21664 @item load @var{filename} @var{offset}
21665 @anchor{load}
21666 Depending on what remote debugging facilities are configured into
21667 @value{GDBN}, the @code{load} command may be available. Where it exists, it
21668 is meant to make @var{filename} (an executable) available for debugging
21669 on the remote system---by downloading, or dynamic linking, for example.
21670 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21671 the @code{add-symbol-file} command.
21672
21673 If your @value{GDBN} does not have a @code{load} command, attempting to
21674 execute it gets the error message ``@code{You can't do that when your
21675 target is @dots{}}''
21676
21677 The file is loaded at whatever address is specified in the executable.
21678 For some object file formats, you can specify the load address when you
21679 link the program; for other formats, like a.out, the object file format
21680 specifies a fixed address.
21681 @c FIXME! This would be a good place for an xref to the GNU linker doc.
21682
21683 It is also possible to tell @value{GDBN} to load the executable file at a
21684 specific offset described by the optional argument @var{offset}. When
21685 @var{offset} is provided, @var{filename} must also be provided.
21686
21687 Depending on the remote side capabilities, @value{GDBN} may be able to
21688 load programs into flash memory.
21689
21690 @code{load} does not repeat if you press @key{RET} again after using it.
21691 @end table
21692
21693 @table @code
21694
21695 @kindex flash-erase
21696 @item flash-erase
21697 @anchor{flash-erase}
21698
21699 Erases all known flash memory regions on the target.
21700
21701 @end table
21702
21703 @node Byte Order
21704 @section Choosing Target Byte Order
21705
21706 @cindex choosing target byte order
21707 @cindex target byte order
21708
21709 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
21710 offer the ability to run either big-endian or little-endian byte
21711 orders. Usually the executable or symbol will include a bit to
21712 designate the endian-ness, and you will not need to worry about
21713 which to use. However, you may still find it useful to adjust
21714 @value{GDBN}'s idea of processor endian-ness manually.
21715
21716 @table @code
21717 @kindex set endian
21718 @item set endian big
21719 Instruct @value{GDBN} to assume the target is big-endian.
21720
21721 @item set endian little
21722 Instruct @value{GDBN} to assume the target is little-endian.
21723
21724 @item set endian auto
21725 Instruct @value{GDBN} to use the byte order associated with the
21726 executable.
21727
21728 @item show endian
21729 Display @value{GDBN}'s current idea of the target byte order.
21730
21731 @end table
21732
21733 If the @code{set endian auto} mode is in effect and no executable has
21734 been selected, then the endianness used is the last one chosen either
21735 by one of the @code{set endian big} and @code{set endian little}
21736 commands or by inferring from the last executable used. If no
21737 endianness has been previously chosen, then the default for this mode
21738 is inferred from the target @value{GDBN} has been built for, and is
21739 @code{little} if the name of the target CPU has an @code{el} suffix
21740 and @code{big} otherwise.
21741
21742 Note that these commands merely adjust interpretation of symbolic
21743 data on the host, and that they have absolutely no effect on the
21744 target system.
21745
21746
21747 @node Remote Debugging
21748 @chapter Debugging Remote Programs
21749 @cindex remote debugging
21750
21751 If you are trying to debug a program running on a machine that cannot run
21752 @value{GDBN} in the usual way, it is often useful to use remote debugging.
21753 For example, you might use remote debugging on an operating system kernel,
21754 or on a small system which does not have a general purpose operating system
21755 powerful enough to run a full-featured debugger.
21756
21757 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21758 to make this work with particular debugging targets. In addition,
21759 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
21760 but not specific to any particular target system) which you can use if you
21761 write the remote stubs---the code that runs on the remote system to
21762 communicate with @value{GDBN}.
21763
21764 Other remote targets may be available in your
21765 configuration of @value{GDBN}; use @code{help target} to list them.
21766
21767 @menu
21768 * Connecting:: Connecting to a remote target
21769 * File Transfer:: Sending files to a remote system
21770 * Server:: Using the gdbserver program
21771 * Remote Configuration:: Remote configuration
21772 * Remote Stub:: Implementing a remote stub
21773 @end menu
21774
21775 @node Connecting
21776 @section Connecting to a Remote Target
21777 @cindex remote debugging, connecting
21778 @cindex @code{gdbserver}, connecting
21779 @cindex remote debugging, types of connections
21780 @cindex @code{gdbserver}, types of connections
21781 @cindex @code{gdbserver}, @code{target remote} mode
21782 @cindex @code{gdbserver}, @code{target extended-remote} mode
21783
21784 This section describes how to connect to a remote target, including the
21785 types of connections and their differences, how to set up executable and
21786 symbol files on the host and target, and the commands used for
21787 connecting to and disconnecting from the remote target.
21788
21789 @subsection Types of Remote Connections
21790
21791 @value{GDBN} supports two types of remote connections, @code{target remote}
21792 mode and @code{target extended-remote} mode. Note that many remote targets
21793 support only @code{target remote} mode. There are several major
21794 differences between the two types of connections, enumerated here:
21795
21796 @table @asis
21797
21798 @cindex remote debugging, detach and program exit
21799 @item Result of detach or program exit
21800 @strong{With target remote mode:} When the debugged program exits or you
21801 detach from it, @value{GDBN} disconnects from the target. When using
21802 @code{gdbserver}, @code{gdbserver} will exit.
21803
21804 @strong{With target extended-remote mode:} When the debugged program exits or
21805 you detach from it, @value{GDBN} remains connected to the target, even
21806 though no program is running. You can rerun the program, attach to a
21807 running program, or use @code{monitor} commands specific to the target.
21808
21809 When using @code{gdbserver} in this case, it does not exit unless it was
21810 invoked using the @option{--once} option. If the @option{--once} option
21811 was not used, you can ask @code{gdbserver} to exit using the
21812 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21813
21814 @item Specifying the program to debug
21815 For both connection types you use the @code{file} command to specify the
21816 program on the host system. If you are using @code{gdbserver} there are
21817 some differences in how to specify the location of the program on the
21818 target.
21819
21820 @strong{With target remote mode:} You must either specify the program to debug
21821 on the @code{gdbserver} command line or use the @option{--attach} option
21822 (@pxref{Attaching to a program,,Attaching to a Running Program}).
21823
21824 @cindex @option{--multi}, @code{gdbserver} option
21825 @strong{With target extended-remote mode:} You may specify the program to debug
21826 on the @code{gdbserver} command line, or you can load the program or attach
21827 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21828
21829 @anchor{--multi Option in Types of Remote Connnections}
21830 You can start @code{gdbserver} without supplying an initial command to run
21831 or process ID to attach. To do this, use the @option{--multi} command line
21832 option. Then you can connect using @code{target extended-remote} and start
21833 the program you want to debug (see below for details on using the
21834 @code{run} command in this scenario). Note that the conditions under which
21835 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
21836 (@code{target remote} or @code{target extended-remote}). The
21837 @option{--multi} option to @code{gdbserver} has no influence on that.
21838
21839 @item The @code{run} command
21840 @strong{With target remote mode:} The @code{run} command is not
21841 supported. Once a connection has been established, you can use all
21842 the usual @value{GDBN} commands to examine and change data. The
21843 remote program is already running, so you can use commands like
21844 @kbd{step} and @kbd{continue}.
21845
21846 @strong{With target extended-remote mode:} The @code{run} command is
21847 supported. The @code{run} command uses the value set by
21848 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
21849 the program to run. Command line arguments are supported, except for
21850 wildcard expansion and I/O redirection (@pxref{Arguments}).
21851
21852 If you specify the program to debug on the command line, then the
21853 @code{run} command is not required to start execution, and you can
21854 resume using commands like @kbd{step} and @kbd{continue} as with
21855 @code{target remote} mode.
21856
21857 @anchor{Attaching in Types of Remote Connections}
21858 @item Attaching
21859 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21860 not supported. To attach to a running program using @code{gdbserver}, you
21861 must use the @option{--attach} option (@pxref{Running gdbserver}).
21862
21863 @strong{With target extended-remote mode:} To attach to a running program,
21864 you may use the @code{attach} command after the connection has been
21865 established. If you are using @code{gdbserver}, you may also invoke
21866 @code{gdbserver} using the @option{--attach} option
21867 (@pxref{Running gdbserver}).
21868
21869 Some remote targets allow @value{GDBN} to determine the executable file running
21870 in the process the debugger is attaching to. In such a case, @value{GDBN}
21871 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21872 between the executable file name running in the process and the name of the
21873 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21874
21875 @end table
21876
21877 @anchor{Host and target files}
21878 @subsection Host and Target Files
21879 @cindex remote debugging, symbol files
21880 @cindex symbol files, remote debugging
21881
21882 @value{GDBN}, running on the host, needs access to symbol and debugging
21883 information for your program running on the target. This requires
21884 access to an unstripped copy of your program, and possibly any associated
21885 symbol files. Note that this section applies equally to both @code{target
21886 remote} mode and @code{target extended-remote} mode.
21887
21888 Some remote targets (@pxref{qXfer executable filename read}, and
21889 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21890 the same connection used to communicate with @value{GDBN}. With such a
21891 target, if the remote program is unstripped, the only command you need is
21892 @code{target remote} (or @code{target extended-remote}).
21893
21894 If the remote program is stripped, or the target does not support remote
21895 program file access, start up @value{GDBN} using the name of the local
21896 unstripped copy of your program as the first argument, or use the
21897 @code{file} command. Use @code{set sysroot} to specify the location (on
21898 the host) of target libraries (unless your @value{GDBN} was compiled with
21899 the correct sysroot using @code{--with-sysroot}). Alternatively, you
21900 may use @code{set solib-search-path} to specify how @value{GDBN} locates
21901 target libraries.
21902
21903 The symbol file and target libraries must exactly match the executable
21904 and libraries on the target, with one exception: the files on the host
21905 system should not be stripped, even if the files on the target system
21906 are. Mismatched or missing files will lead to confusing results
21907 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21908 files may also prevent @code{gdbserver} from debugging multi-threaded
21909 programs.
21910
21911 @subsection Remote Connection Commands
21912 @cindex remote connection commands
21913 @value{GDBN} can communicate with the target over a serial line, a
21914 local Unix domain socket, or
21915 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
21916 each case, @value{GDBN} uses the same protocol for debugging your
21917 program; only the medium carrying the debugging packets varies. The
21918 @code{target remote} and @code{target extended-remote} commands
21919 establish a connection to the target. Both commands accept the same
21920 arguments, which indicate the medium to use:
21921
21922 @table @code
21923
21924 @item target remote @var{serial-device}
21925 @itemx target extended-remote @var{serial-device}
21926 @cindex serial line, @code{target remote}
21927 Use @var{serial-device} to communicate with the target. For example,
21928 to use a serial line connected to the device named @file{/dev/ttyb}:
21929
21930 @smallexample
21931 target remote /dev/ttyb
21932 @end smallexample
21933
21934 If you're using a serial line, you may want to give @value{GDBN} the
21935 @samp{--baud} option, or use the @code{set serial baud} command
21936 (@pxref{Remote Configuration, set serial baud}) before the
21937 @code{target} command.
21938
21939 @item target remote @var{local-socket}
21940 @itemx target extended-remote @var{local-socket}
21941 @cindex local socket, @code{target remote}
21942 @cindex Unix domain socket
21943 Use @var{local-socket} to communicate with the target. For example,
21944 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
21945
21946 @smallexample
21947 target remote /tmp/gdb-socket0
21948 @end smallexample
21949
21950 Note that this command has the same form as the command to connect
21951 to a serial line. @value{GDBN} will automatically determine which
21952 kind of file you have specified and will make the appropriate kind
21953 of connection.
21954 This feature is not available if the host system does not support
21955 Unix domain sockets.
21956
21957 @item target remote @code{@var{host}:@var{port}}
21958 @itemx target remote @code{[@var{host}]:@var{port}}
21959 @itemx target remote @code{tcp:@var{host}:@var{port}}
21960 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
21961 @itemx target remote @code{tcp4:@var{host}:@var{port}}
21962 @itemx target remote @code{tcp6:@var{host}:@var{port}}
21963 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
21964 @itemx target extended-remote @code{@var{host}:@var{port}}
21965 @itemx target extended-remote @code{[@var{host}]:@var{port}}
21966 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
21967 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
21968 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
21969 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
21970 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
21971 @cindex @acronym{TCP} port, @code{target remote}
21972 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
21973 The @var{host} may be either a host name, a numeric @acronym{IPv4}
21974 address, or a numeric @acronym{IPv6} address (with or without the
21975 square brackets to separate the address from the port); @var{port}
21976 must be a decimal number. The @var{host} could be the target machine
21977 itself, if it is directly connected to the net, or it might be a
21978 terminal server which in turn has a serial line to the target.
21979
21980 For example, to connect to port 2828 on a terminal server named
21981 @code{manyfarms}:
21982
21983 @smallexample
21984 target remote manyfarms:2828
21985 @end smallexample
21986
21987 To connect to port 2828 on a terminal server whose address is
21988 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
21989 square bracket syntax:
21990
21991 @smallexample
21992 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
21993 @end smallexample
21994
21995 @noindent
21996 or explicitly specify the @acronym{IPv6} protocol:
21997
21998 @smallexample
21999 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22000 @end smallexample
22001
22002 This last example may be confusing to the reader, because there is no
22003 visible separation between the hostname and the port number.
22004 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22005 using square brackets for clarity. However, it is important to
22006 mention that for @value{GDBN} there is no ambiguity: the number after
22007 the last colon is considered to be the port number.
22008
22009 If your remote target is actually running on the same machine as your
22010 debugger session (e.g.@: a simulator for your target running on the
22011 same host), you can omit the hostname. For example, to connect to
22012 port 1234 on your local machine:
22013
22014 @smallexample
22015 target remote :1234
22016 @end smallexample
22017 @noindent
22018
22019 Note that the colon is still required here.
22020
22021 @item target remote @code{udp:@var{host}:@var{port}}
22022 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22023 @itemx target remote @code{udp4:@var{host}:@var{port}}
22024 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22025 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22026 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22027 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22028 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22029 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22030 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22031 @cindex @acronym{UDP} port, @code{target remote}
22032 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22033 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22034
22035 @smallexample
22036 target remote udp:manyfarms:2828
22037 @end smallexample
22038
22039 When using a @acronym{UDP} connection for remote debugging, you should
22040 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22041 can silently drop packets on busy or unreliable networks, which will
22042 cause havoc with your debugging session.
22043
22044 @item target remote | @var{command}
22045 @itemx target extended-remote | @var{command}
22046 @cindex pipe, @code{target remote} to
22047 Run @var{command} in the background and communicate with it using a
22048 pipe. The @var{command} is a shell command, to be parsed and expanded
22049 by the system's command shell, @code{/bin/sh}; it should expect remote
22050 protocol packets on its standard input, and send replies on its
22051 standard output. You could use this to run a stand-alone simulator
22052 that speaks the remote debugging protocol, to make net connections
22053 using programs like @code{ssh}, or for other similar tricks.
22054
22055 If @var{command} closes its standard output (perhaps by exiting),
22056 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22057 program has already exited, this will have no effect.)
22058
22059 @end table
22060
22061 @cindex interrupting remote programs
22062 @cindex remote programs, interrupting
22063 Whenever @value{GDBN} is waiting for the remote program, if you type the
22064 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22065 program. This may or may not succeed, depending in part on the hardware
22066 and the serial drivers the remote system uses. If you type the
22067 interrupt character once again, @value{GDBN} displays this prompt:
22068
22069 @smallexample
22070 Interrupted while waiting for the program.
22071 Give up (and stop debugging it)? (y or n)
22072 @end smallexample
22073
22074 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22075 the remote debugging session. (If you decide you want to try again later,
22076 you can use @kbd{target remote} again to connect once more.) If you type
22077 @kbd{n}, @value{GDBN} goes back to waiting.
22078
22079 In @code{target extended-remote} mode, typing @kbd{n} will leave
22080 @value{GDBN} connected to the target.
22081
22082 @table @code
22083 @kindex detach (remote)
22084 @item detach
22085 When you have finished debugging the remote program, you can use the
22086 @code{detach} command to release it from @value{GDBN} control.
22087 Detaching from the target normally resumes its execution, but the results
22088 will depend on your particular remote stub. After the @code{detach}
22089 command in @code{target remote} mode, @value{GDBN} is free to connect to
22090 another target. In @code{target extended-remote} mode, @value{GDBN} is
22091 still connected to the target.
22092
22093 @kindex disconnect
22094 @item disconnect
22095 The @code{disconnect} command closes the connection to the target, and
22096 the target is generally not resumed. It will wait for @value{GDBN}
22097 (this instance or another one) to connect and continue debugging. After
22098 the @code{disconnect} command, @value{GDBN} is again free to connect to
22099 another target.
22100
22101 @cindex send command to remote monitor
22102 @cindex extend @value{GDBN} for remote targets
22103 @cindex add new commands for external monitor
22104 @kindex monitor
22105 @item monitor @var{cmd}
22106 This command allows you to send arbitrary commands directly to the
22107 remote monitor. Since @value{GDBN} doesn't care about the commands it
22108 sends like this, this command is the way to extend @value{GDBN}---you
22109 can add new commands that only the external monitor will understand
22110 and implement.
22111 @end table
22112
22113 @node File Transfer
22114 @section Sending files to a remote system
22115 @cindex remote target, file transfer
22116 @cindex file transfer
22117 @cindex sending files to remote systems
22118
22119 Some remote targets offer the ability to transfer files over the same
22120 connection used to communicate with @value{GDBN}. This is convenient
22121 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22122 running @code{gdbserver} over a network interface. For other targets,
22123 e.g.@: embedded devices with only a single serial port, this may be
22124 the only way to upload or download files.
22125
22126 Not all remote targets support these commands.
22127
22128 @table @code
22129 @kindex remote put
22130 @item remote put @var{hostfile} @var{targetfile}
22131 Copy file @var{hostfile} from the host system (the machine running
22132 @value{GDBN}) to @var{targetfile} on the target system.
22133
22134 @kindex remote get
22135 @item remote get @var{targetfile} @var{hostfile}
22136 Copy file @var{targetfile} from the target system to @var{hostfile}
22137 on the host system.
22138
22139 @kindex remote delete
22140 @item remote delete @var{targetfile}
22141 Delete @var{targetfile} from the target system.
22142
22143 @end table
22144
22145 @node Server
22146 @section Using the @code{gdbserver} Program
22147
22148 @kindex gdbserver
22149 @cindex remote connection without stubs
22150 @code{gdbserver} is a control program for Unix-like systems, which
22151 allows you to connect your program with a remote @value{GDBN} via
22152 @code{target remote} or @code{target extended-remote}---but without
22153 linking in the usual debugging stub.
22154
22155 @code{gdbserver} is not a complete replacement for the debugging stubs,
22156 because it requires essentially the same operating-system facilities
22157 that @value{GDBN} itself does. In fact, a system that can run
22158 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22159 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22160 because it is a much smaller program than @value{GDBN} itself. It is
22161 also easier to port than all of @value{GDBN}, so you may be able to get
22162 started more quickly on a new system by using @code{gdbserver}.
22163 Finally, if you develop code for real-time systems, you may find that
22164 the tradeoffs involved in real-time operation make it more convenient to
22165 do as much development work as possible on another system, for example
22166 by cross-compiling. You can use @code{gdbserver} to make a similar
22167 choice for debugging.
22168
22169 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22170 or a TCP connection, using the standard @value{GDBN} remote serial
22171 protocol.
22172
22173 @quotation
22174 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22175 Do not run @code{gdbserver} connected to any public network; a
22176 @value{GDBN} connection to @code{gdbserver} provides access to the
22177 target system with the same privileges as the user running
22178 @code{gdbserver}.
22179 @end quotation
22180
22181 @anchor{Running gdbserver}
22182 @subsection Running @code{gdbserver}
22183 @cindex arguments, to @code{gdbserver}
22184 @cindex @code{gdbserver}, command-line arguments
22185
22186 Run @code{gdbserver} on the target system. You need a copy of the
22187 program you want to debug, including any libraries it requires.
22188 @code{gdbserver} does not need your program's symbol table, so you can
22189 strip the program if necessary to save space. @value{GDBN} on the host
22190 system does all the symbol handling.
22191
22192 To use the server, you must tell it how to communicate with @value{GDBN};
22193 the name of your program; and the arguments for your program. The usual
22194 syntax is:
22195
22196 @smallexample
22197 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22198 @end smallexample
22199
22200 @var{comm} is either a device name (to use a serial line), or a TCP
22201 hostname and portnumber, or @code{-} or @code{stdio} to use
22202 stdin/stdout of @code{gdbserver}.
22203 For example, to debug Emacs with the argument
22204 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22205 @file{/dev/com1}:
22206
22207 @smallexample
22208 target> gdbserver /dev/com1 emacs foo.txt
22209 @end smallexample
22210
22211 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22212 with it.
22213
22214 To use a TCP connection instead of a serial line:
22215
22216 @smallexample
22217 target> gdbserver host:2345 emacs foo.txt
22218 @end smallexample
22219
22220 The only difference from the previous example is the first argument,
22221 specifying that you are communicating with the host @value{GDBN} via
22222 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22223 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22224 (Currently, the @samp{host} part is ignored.) You can choose any number
22225 you want for the port number as long as it does not conflict with any
22226 TCP ports already in use on the target system (for example, @code{23} is
22227 reserved for @code{telnet}).@footnote{If you choose a port number that
22228 conflicts with another service, @code{gdbserver} prints an error message
22229 and exits.} You must use the same port number with the host @value{GDBN}
22230 @code{target remote} command.
22231
22232 The @code{stdio} connection is useful when starting @code{gdbserver}
22233 with ssh:
22234
22235 @smallexample
22236 (gdb) target remote | ssh -T hostname gdbserver - hello
22237 @end smallexample
22238
22239 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22240 and we don't want escape-character handling. Ssh does this by default when
22241 a command is provided, the flag is provided to make it explicit.
22242 You could elide it if you want to.
22243
22244 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22245 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22246 display through a pipe connected to gdbserver.
22247 Both @code{stdout} and @code{stderr} use the same pipe.
22248
22249 @anchor{Attaching to a program}
22250 @subsubsection Attaching to a Running Program
22251 @cindex attach to a program, @code{gdbserver}
22252 @cindex @option{--attach}, @code{gdbserver} option
22253
22254 On some targets, @code{gdbserver} can also attach to running programs.
22255 This is accomplished via the @code{--attach} argument. The syntax is:
22256
22257 @smallexample
22258 target> gdbserver --attach @var{comm} @var{pid}
22259 @end smallexample
22260
22261 @var{pid} is the process ID of a currently running process. It isn't
22262 necessary to point @code{gdbserver} at a binary for the running process.
22263
22264 In @code{target extended-remote} mode, you can also attach using the
22265 @value{GDBN} attach command
22266 (@pxref{Attaching in Types of Remote Connections}).
22267
22268 @pindex pidof
22269 You can debug processes by name instead of process ID if your target has the
22270 @code{pidof} utility:
22271
22272 @smallexample
22273 target> gdbserver --attach @var{comm} `pidof @var{program}`
22274 @end smallexample
22275
22276 In case more than one copy of @var{program} is running, or @var{program}
22277 has multiple threads, most versions of @code{pidof} support the
22278 @code{-s} option to only return the first process ID.
22279
22280 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22281
22282 This section applies only when @code{gdbserver} is run to listen on a TCP
22283 port.
22284
22285 @code{gdbserver} normally terminates after all of its debugged processes have
22286 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22287 extended-remote}, @code{gdbserver} stays running even with no processes left.
22288 @value{GDBN} normally terminates the spawned debugged process on its exit,
22289 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22290 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22291 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22292 stays running even in the @kbd{target remote} mode.
22293
22294 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22295 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22296 completeness, at most one @value{GDBN} can be connected at a time.
22297
22298 @cindex @option{--once}, @code{gdbserver} option
22299 By default, @code{gdbserver} keeps the listening TCP port open, so that
22300 subsequent connections are possible. However, if you start @code{gdbserver}
22301 with the @option{--once} option, it will stop listening for any further
22302 connection attempts after connecting to the first @value{GDBN} session. This
22303 means no further connections to @code{gdbserver} will be possible after the
22304 first one. It also means @code{gdbserver} will terminate after the first
22305 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22306 connections and even in the @kbd{target extended-remote} mode. The
22307 @option{--once} option allows reusing the same port number for connecting to
22308 multiple instances of @code{gdbserver} running on the same host, since each
22309 instance closes its port after the first connection.
22310
22311 @anchor{Other Command-Line Arguments for gdbserver}
22312 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22313
22314 You can use the @option{--multi} option to start @code{gdbserver} without
22315 specifying a program to debug or a process to attach to. Then you can
22316 attach in @code{target extended-remote} mode and run or attach to a
22317 program. For more information,
22318 @pxref{--multi Option in Types of Remote Connnections}.
22319
22320 @cindex @option{--debug}, @code{gdbserver} option
22321 The @option{--debug} option tells @code{gdbserver} to display extra
22322 status information about the debugging process.
22323 @cindex @option{--remote-debug}, @code{gdbserver} option
22324 The @option{--remote-debug} option tells @code{gdbserver} to display
22325 remote protocol debug output.
22326 @cindex @option{--debug-file}, @code{gdbserver} option
22327 @cindex @code{gdbserver}, send all debug output to a single file
22328 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22329 write any debug output to the given @var{filename}. These options are intended
22330 for @code{gdbserver} development and for bug reports to the developers.
22331
22332 @cindex @option{--debug-format}, @code{gdbserver} option
22333 The @option{--debug-format=option1[,option2,...]} option tells
22334 @code{gdbserver} to include additional information in each output.
22335 Possible options are:
22336
22337 @table @code
22338 @item none
22339 Turn off all extra information in debugging output.
22340 @item all
22341 Turn on all extra information in debugging output.
22342 @item timestamps
22343 Include a timestamp in each line of debugging output.
22344 @end table
22345
22346 Options are processed in order. Thus, for example, if @option{none}
22347 appears last then no additional information is added to debugging output.
22348
22349 @cindex @option{--wrapper}, @code{gdbserver} option
22350 The @option{--wrapper} option specifies a wrapper to launch programs
22351 for debugging. The option should be followed by the name of the
22352 wrapper, then any command-line arguments to pass to the wrapper, then
22353 @kbd{--} indicating the end of the wrapper arguments.
22354
22355 @code{gdbserver} runs the specified wrapper program with a combined
22356 command line including the wrapper arguments, then the name of the
22357 program to debug, then any arguments to the program. The wrapper
22358 runs until it executes your program, and then @value{GDBN} gains control.
22359
22360 You can use any program that eventually calls @code{execve} with
22361 its arguments as a wrapper. Several standard Unix utilities do
22362 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22363 with @code{exec "$@@"} will also work.
22364
22365 For example, you can use @code{env} to pass an environment variable to
22366 the debugged program, without setting the variable in @code{gdbserver}'s
22367 environment:
22368
22369 @smallexample
22370 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22371 @end smallexample
22372
22373 @cindex @option{--selftest}
22374 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22375
22376 @smallexample
22377 $ gdbserver --selftest
22378 Ran 2 unit tests, 0 failed
22379 @end smallexample
22380
22381 These tests are disabled in release.
22382 @subsection Connecting to @code{gdbserver}
22383
22384 The basic procedure for connecting to the remote target is:
22385 @itemize
22386
22387 @item
22388 Run @value{GDBN} on the host system.
22389
22390 @item
22391 Make sure you have the necessary symbol files
22392 (@pxref{Host and target files}).
22393 Load symbols for your application using the @code{file} command before you
22394 connect. Use @code{set sysroot} to locate target libraries (unless your
22395 @value{GDBN} was compiled with the correct sysroot using
22396 @code{--with-sysroot}).
22397
22398 @item
22399 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22400 For TCP connections, you must start up @code{gdbserver} prior to using
22401 the @code{target} command. Otherwise you may get an error whose
22402 text depends on the host system, but which usually looks something like
22403 @samp{Connection refused}. Don't use the @code{load}
22404 command in @value{GDBN} when using @code{target remote} mode, since the
22405 program is already on the target.
22406
22407 @end itemize
22408
22409 @anchor{Monitor Commands for gdbserver}
22410 @subsection Monitor Commands for @code{gdbserver}
22411 @cindex monitor commands, for @code{gdbserver}
22412
22413 During a @value{GDBN} session using @code{gdbserver}, you can use the
22414 @code{monitor} command to send special requests to @code{gdbserver}.
22415 Here are the available commands.
22416
22417 @table @code
22418 @item monitor help
22419 List the available monitor commands.
22420
22421 @item monitor set debug 0
22422 @itemx monitor set debug 1
22423 Disable or enable general debugging messages.
22424
22425 @item monitor set remote-debug 0
22426 @itemx monitor set remote-debug 1
22427 Disable or enable specific debugging messages associated with the remote
22428 protocol (@pxref{Remote Protocol}).
22429
22430 @item monitor set debug-file filename
22431 @itemx monitor set debug-file
22432 Send any debug output to the given file, or to stderr.
22433
22434 @item monitor set debug-format option1@r{[},option2,...@r{]}
22435 Specify additional text to add to debugging messages.
22436 Possible options are:
22437
22438 @table @code
22439 @item none
22440 Turn off all extra information in debugging output.
22441 @item all
22442 Turn on all extra information in debugging output.
22443 @item timestamps
22444 Include a timestamp in each line of debugging output.
22445 @end table
22446
22447 Options are processed in order. Thus, for example, if @option{none}
22448 appears last then no additional information is added to debugging output.
22449
22450 @item monitor set libthread-db-search-path [PATH]
22451 @cindex gdbserver, search path for @code{libthread_db}
22452 When this command is issued, @var{path} is a colon-separated list of
22453 directories to search for @code{libthread_db} (@pxref{Threads,,set
22454 libthread-db-search-path}). If you omit @var{path},
22455 @samp{libthread-db-search-path} will be reset to its default value.
22456
22457 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22458 not supported in @code{gdbserver}.
22459
22460 @item monitor exit
22461 Tell gdbserver to exit immediately. This command should be followed by
22462 @code{disconnect} to close the debugging session. @code{gdbserver} will
22463 detach from any attached processes and kill any processes it created.
22464 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22465 of a multi-process mode debug session.
22466
22467 @end table
22468
22469 @subsection Tracepoints support in @code{gdbserver}
22470 @cindex tracepoints support in @code{gdbserver}
22471
22472 On some targets, @code{gdbserver} supports tracepoints, fast
22473 tracepoints and static tracepoints.
22474
22475 For fast or static tracepoints to work, a special library called the
22476 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22477 This library is built and distributed as an integral part of
22478 @code{gdbserver}. In addition, support for static tracepoints
22479 requires building the in-process agent library with static tracepoints
22480 support. At present, the UST (LTTng Userspace Tracer,
22481 @url{http://lttng.org/ust}) tracing engine is supported. This support
22482 is automatically available if UST development headers are found in the
22483 standard include path when @code{gdbserver} is built, or if
22484 @code{gdbserver} was explicitly configured using @option{--with-ust}
22485 to point at such headers. You can explicitly disable the support
22486 using @option{--with-ust=no}.
22487
22488 There are several ways to load the in-process agent in your program:
22489
22490 @table @code
22491 @item Specifying it as dependency at link time
22492
22493 You can link your program dynamically with the in-process agent
22494 library. On most systems, this is accomplished by adding
22495 @code{-linproctrace} to the link command.
22496
22497 @item Using the system's preloading mechanisms
22498
22499 You can force loading the in-process agent at startup time by using
22500 your system's support for preloading shared libraries. Many Unixes
22501 support the concept of preloading user defined libraries. In most
22502 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22503 in the environment. See also the description of @code{gdbserver}'s
22504 @option{--wrapper} command line option.
22505
22506 @item Using @value{GDBN} to force loading the agent at run time
22507
22508 On some systems, you can force the inferior to load a shared library,
22509 by calling a dynamic loader function in the inferior that takes care
22510 of dynamically looking up and loading a shared library. On most Unix
22511 systems, the function is @code{dlopen}. You'll use the @code{call}
22512 command for that. For example:
22513
22514 @smallexample
22515 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22516 @end smallexample
22517
22518 Note that on most Unix systems, for the @code{dlopen} function to be
22519 available, the program needs to be linked with @code{-ldl}.
22520 @end table
22521
22522 On systems that have a userspace dynamic loader, like most Unix
22523 systems, when you connect to @code{gdbserver} using @code{target
22524 remote}, you'll find that the program is stopped at the dynamic
22525 loader's entry point, and no shared library has been loaded in the
22526 program's address space yet, including the in-process agent. In that
22527 case, before being able to use any of the fast or static tracepoints
22528 features, you need to let the loader run and load the shared
22529 libraries. The simplest way to do that is to run the program to the
22530 main procedure. E.g., if debugging a C or C@t{++} program, start
22531 @code{gdbserver} like so:
22532
22533 @smallexample
22534 $ gdbserver :9999 myprogram
22535 @end smallexample
22536
22537 Start GDB and connect to @code{gdbserver} like so, and run to main:
22538
22539 @smallexample
22540 $ gdb myprogram
22541 (@value{GDBP}) target remote myhost:9999
22542 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22543 (@value{GDBP}) b main
22544 (@value{GDBP}) continue
22545 @end smallexample
22546
22547 The in-process tracing agent library should now be loaded into the
22548 process; you can confirm it with the @code{info sharedlibrary}
22549 command, which will list @file{libinproctrace.so} as loaded in the
22550 process. You are now ready to install fast tracepoints, list static
22551 tracepoint markers, probe static tracepoints markers, and start
22552 tracing.
22553
22554 @node Remote Configuration
22555 @section Remote Configuration
22556
22557 @kindex set remote
22558 @kindex show remote
22559 This section documents the configuration options available when
22560 debugging remote programs. For the options related to the File I/O
22561 extensions of the remote protocol, see @ref{system,
22562 system-call-allowed}.
22563
22564 @table @code
22565 @item set remoteaddresssize @var{bits}
22566 @cindex address size for remote targets
22567 @cindex bits in remote address
22568 Set the maximum size of address in a memory packet to the specified
22569 number of bits. @value{GDBN} will mask off the address bits above
22570 that number, when it passes addresses to the remote target. The
22571 default value is the number of bits in the target's address.
22572
22573 @item show remoteaddresssize
22574 Show the current value of remote address size in bits.
22575
22576 @item set serial baud @var{n}
22577 @cindex baud rate for remote targets
22578 Set the baud rate for the remote serial I/O to @var{n} baud. The
22579 value is used to set the speed of the serial port used for debugging
22580 remote targets.
22581
22582 @item show serial baud
22583 Show the current speed of the remote connection.
22584
22585 @item set serial parity @var{parity}
22586 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22587 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22588
22589 @item show serial parity
22590 Show the current parity of the serial port.
22591
22592 @item set remotebreak
22593 @cindex interrupt remote programs
22594 @cindex BREAK signal instead of Ctrl-C
22595 @anchor{set remotebreak}
22596 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
22597 when you type @kbd{Ctrl-c} to interrupt the program running
22598 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
22599 character instead. The default is off, since most remote systems
22600 expect to see @samp{Ctrl-C} as the interrupt signal.
22601
22602 @item show remotebreak
22603 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22604 interrupt the remote program.
22605
22606 @item set remoteflow on
22607 @itemx set remoteflow off
22608 @kindex set remoteflow
22609 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22610 on the serial port used to communicate to the remote target.
22611
22612 @item show remoteflow
22613 @kindex show remoteflow
22614 Show the current setting of hardware flow control.
22615
22616 @item set remotelogbase @var{base}
22617 Set the base (a.k.a.@: radix) of logging serial protocol
22618 communications to @var{base}. Supported values of @var{base} are:
22619 @code{ascii}, @code{octal}, and @code{hex}. The default is
22620 @code{ascii}.
22621
22622 @item show remotelogbase
22623 Show the current setting of the radix for logging remote serial
22624 protocol.
22625
22626 @item set remotelogfile @var{file}
22627 @cindex record serial communications on file
22628 Record remote serial communications on the named @var{file}. The
22629 default is not to record at all.
22630
22631 @item show remotelogfile
22632 Show the current setting of the file name on which to record the
22633 serial communications.
22634
22635 @item set remotetimeout @var{num}
22636 @cindex timeout for serial communications
22637 @cindex remote timeout
22638 Set the timeout limit to wait for the remote target to respond to
22639 @var{num} seconds. The default is 2 seconds.
22640
22641 @item show remotetimeout
22642 Show the current number of seconds to wait for the remote target
22643 responses.
22644
22645 @cindex limit hardware breakpoints and watchpoints
22646 @cindex remote target, limit break- and watchpoints
22647 @anchor{set remote hardware-watchpoint-limit}
22648 @anchor{set remote hardware-breakpoint-limit}
22649 @item set remote hardware-watchpoint-limit @var{limit}
22650 @itemx set remote hardware-breakpoint-limit @var{limit}
22651 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22652 or breakpoints. The @var{limit} can be set to 0 to disable hardware
22653 watchpoints or breakpoints, and @code{unlimited} for unlimited
22654 watchpoints or breakpoints.
22655
22656 @item show remote hardware-watchpoint-limit
22657 @itemx show remote hardware-breakpoint-limit
22658 Show the current limit for the number of hardware watchpoints or
22659 breakpoints that @value{GDBN} can use.
22660
22661 @cindex limit hardware watchpoints length
22662 @cindex remote target, limit watchpoints length
22663 @anchor{set remote hardware-watchpoint-length-limit}
22664 @item set remote hardware-watchpoint-length-limit @var{limit}
22665 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22666 length of a remote hardware watchpoint. A @var{limit} of 0 disables
22667 hardware watchpoints and @code{unlimited} allows watchpoints of any
22668 length.
22669
22670 @item show remote hardware-watchpoint-length-limit
22671 Show the current limit (in bytes) of the maximum length of
22672 a remote hardware watchpoint.
22673
22674 @item set remote exec-file @var{filename}
22675 @itemx show remote exec-file
22676 @anchor{set remote exec-file}
22677 @cindex executable file, for remote target
22678 Select the file used for @code{run} with @code{target
22679 extended-remote}. This should be set to a filename valid on the
22680 target system. If it is not set, the target will use a default
22681 filename (e.g.@: the last program run).
22682
22683 @item set remote interrupt-sequence
22684 @cindex interrupt remote programs
22685 @cindex select Ctrl-C, BREAK or BREAK-g
22686 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22687 @samp{BREAK-g} as the
22688 sequence to the remote target in order to interrupt the execution.
22689 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22690 is high level of serial line for some certain time.
22691 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22692 It is @code{BREAK} signal followed by character @code{g}.
22693
22694 @item show interrupt-sequence
22695 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22696 is sent by @value{GDBN} to interrupt the remote program.
22697 @code{BREAK-g} is BREAK signal followed by @code{g} and
22698 also known as Magic SysRq g.
22699
22700 @item set remote interrupt-on-connect
22701 @cindex send interrupt-sequence on start
22702 Specify whether interrupt-sequence is sent to remote target when
22703 @value{GDBN} connects to it. This is mostly needed when you debug
22704 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22705 which is known as Magic SysRq g in order to connect @value{GDBN}.
22706
22707 @item show interrupt-on-connect
22708 Show whether interrupt-sequence is sent
22709 to remote target when @value{GDBN} connects to it.
22710
22711 @kindex set tcp
22712 @kindex show tcp
22713 @item set tcp auto-retry on
22714 @cindex auto-retry, for remote TCP target
22715 Enable auto-retry for remote TCP connections. This is useful if the remote
22716 debugging agent is launched in parallel with @value{GDBN}; there is a race
22717 condition because the agent may not become ready to accept the connection
22718 before @value{GDBN} attempts to connect. When auto-retry is
22719 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22720 to establish the connection using the timeout specified by
22721 @code{set tcp connect-timeout}.
22722
22723 @item set tcp auto-retry off
22724 Do not auto-retry failed TCP connections.
22725
22726 @item show tcp auto-retry
22727 Show the current auto-retry setting.
22728
22729 @item set tcp connect-timeout @var{seconds}
22730 @itemx set tcp connect-timeout unlimited
22731 @cindex connection timeout, for remote TCP target
22732 @cindex timeout, for remote target connection
22733 Set the timeout for establishing a TCP connection to the remote target to
22734 @var{seconds}. The timeout affects both polling to retry failed connections
22735 (enabled by @code{set tcp auto-retry on}) and waiting for connections
22736 that are merely slow to complete, and represents an approximate cumulative
22737 value. If @var{seconds} is @code{unlimited}, there is no timeout and
22738 @value{GDBN} will keep attempting to establish a connection forever,
22739 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
22740
22741 @item show tcp connect-timeout
22742 Show the current connection timeout setting.
22743 @end table
22744
22745 @cindex remote packets, enabling and disabling
22746 The @value{GDBN} remote protocol autodetects the packets supported by
22747 your debugging stub. If you need to override the autodetection, you
22748 can use these commands to enable or disable individual packets. Each
22749 packet can be set to @samp{on} (the remote target supports this
22750 packet), @samp{off} (the remote target does not support this packet),
22751 or @samp{auto} (detect remote target support for this packet). They
22752 all default to @samp{auto}. For more information about each packet,
22753 see @ref{Remote Protocol}.
22754
22755 During normal use, you should not have to use any of these commands.
22756 If you do, that may be a bug in your remote debugging stub, or a bug
22757 in @value{GDBN}. You may want to report the problem to the
22758 @value{GDBN} developers.
22759
22760 For each packet @var{name}, the command to enable or disable the
22761 packet is @code{set remote @var{name}-packet}. The available settings
22762 are:
22763
22764 @multitable @columnfractions 0.28 0.32 0.25
22765 @item Command Name
22766 @tab Remote Packet
22767 @tab Related Features
22768
22769 @item @code{fetch-register}
22770 @tab @code{p}
22771 @tab @code{info registers}
22772
22773 @item @code{set-register}
22774 @tab @code{P}
22775 @tab @code{set}
22776
22777 @item @code{binary-download}
22778 @tab @code{X}
22779 @tab @code{load}, @code{set}
22780
22781 @item @code{read-aux-vector}
22782 @tab @code{qXfer:auxv:read}
22783 @tab @code{info auxv}
22784
22785 @item @code{symbol-lookup}
22786 @tab @code{qSymbol}
22787 @tab Detecting multiple threads
22788
22789 @item @code{attach}
22790 @tab @code{vAttach}
22791 @tab @code{attach}
22792
22793 @item @code{verbose-resume}
22794 @tab @code{vCont}
22795 @tab Stepping or resuming multiple threads
22796
22797 @item @code{run}
22798 @tab @code{vRun}
22799 @tab @code{run}
22800
22801 @item @code{software-breakpoint}
22802 @tab @code{Z0}
22803 @tab @code{break}
22804
22805 @item @code{hardware-breakpoint}
22806 @tab @code{Z1}
22807 @tab @code{hbreak}
22808
22809 @item @code{write-watchpoint}
22810 @tab @code{Z2}
22811 @tab @code{watch}
22812
22813 @item @code{read-watchpoint}
22814 @tab @code{Z3}
22815 @tab @code{rwatch}
22816
22817 @item @code{access-watchpoint}
22818 @tab @code{Z4}
22819 @tab @code{awatch}
22820
22821 @item @code{pid-to-exec-file}
22822 @tab @code{qXfer:exec-file:read}
22823 @tab @code{attach}, @code{run}
22824
22825 @item @code{target-features}
22826 @tab @code{qXfer:features:read}
22827 @tab @code{set architecture}
22828
22829 @item @code{library-info}
22830 @tab @code{qXfer:libraries:read}
22831 @tab @code{info sharedlibrary}
22832
22833 @item @code{memory-map}
22834 @tab @code{qXfer:memory-map:read}
22835 @tab @code{info mem}
22836
22837 @item @code{read-sdata-object}
22838 @tab @code{qXfer:sdata:read}
22839 @tab @code{print $_sdata}
22840
22841 @item @code{read-siginfo-object}
22842 @tab @code{qXfer:siginfo:read}
22843 @tab @code{print $_siginfo}
22844
22845 @item @code{write-siginfo-object}
22846 @tab @code{qXfer:siginfo:write}
22847 @tab @code{set $_siginfo}
22848
22849 @item @code{threads}
22850 @tab @code{qXfer:threads:read}
22851 @tab @code{info threads}
22852
22853 @item @code{get-thread-local-@*storage-address}
22854 @tab @code{qGetTLSAddr}
22855 @tab Displaying @code{__thread} variables
22856
22857 @item @code{get-thread-information-block-address}
22858 @tab @code{qGetTIBAddr}
22859 @tab Display MS-Windows Thread Information Block.
22860
22861 @item @code{search-memory}
22862 @tab @code{qSearch:memory}
22863 @tab @code{find}
22864
22865 @item @code{supported-packets}
22866 @tab @code{qSupported}
22867 @tab Remote communications parameters
22868
22869 @item @code{catch-syscalls}
22870 @tab @code{QCatchSyscalls}
22871 @tab @code{catch syscall}
22872
22873 @item @code{pass-signals}
22874 @tab @code{QPassSignals}
22875 @tab @code{handle @var{signal}}
22876
22877 @item @code{program-signals}
22878 @tab @code{QProgramSignals}
22879 @tab @code{handle @var{signal}}
22880
22881 @item @code{hostio-close-packet}
22882 @tab @code{vFile:close}
22883 @tab @code{remote get}, @code{remote put}
22884
22885 @item @code{hostio-open-packet}
22886 @tab @code{vFile:open}
22887 @tab @code{remote get}, @code{remote put}
22888
22889 @item @code{hostio-pread-packet}
22890 @tab @code{vFile:pread}
22891 @tab @code{remote get}, @code{remote put}
22892
22893 @item @code{hostio-pwrite-packet}
22894 @tab @code{vFile:pwrite}
22895 @tab @code{remote get}, @code{remote put}
22896
22897 @item @code{hostio-unlink-packet}
22898 @tab @code{vFile:unlink}
22899 @tab @code{remote delete}
22900
22901 @item @code{hostio-readlink-packet}
22902 @tab @code{vFile:readlink}
22903 @tab Host I/O
22904
22905 @item @code{hostio-fstat-packet}
22906 @tab @code{vFile:fstat}
22907 @tab Host I/O
22908
22909 @item @code{hostio-setfs-packet}
22910 @tab @code{vFile:setfs}
22911 @tab Host I/O
22912
22913 @item @code{noack-packet}
22914 @tab @code{QStartNoAckMode}
22915 @tab Packet acknowledgment
22916
22917 @item @code{osdata}
22918 @tab @code{qXfer:osdata:read}
22919 @tab @code{info os}
22920
22921 @item @code{query-attached}
22922 @tab @code{qAttached}
22923 @tab Querying remote process attach state.
22924
22925 @item @code{trace-buffer-size}
22926 @tab @code{QTBuffer:size}
22927 @tab @code{set trace-buffer-size}
22928
22929 @item @code{trace-status}
22930 @tab @code{qTStatus}
22931 @tab @code{tstatus}
22932
22933 @item @code{traceframe-info}
22934 @tab @code{qXfer:traceframe-info:read}
22935 @tab Traceframe info
22936
22937 @item @code{install-in-trace}
22938 @tab @code{InstallInTrace}
22939 @tab Install tracepoint in tracing
22940
22941 @item @code{disable-randomization}
22942 @tab @code{QDisableRandomization}
22943 @tab @code{set disable-randomization}
22944
22945 @item @code{startup-with-shell}
22946 @tab @code{QStartupWithShell}
22947 @tab @code{set startup-with-shell}
22948
22949 @item @code{environment-hex-encoded}
22950 @tab @code{QEnvironmentHexEncoded}
22951 @tab @code{set environment}
22952
22953 @item @code{environment-unset}
22954 @tab @code{QEnvironmentUnset}
22955 @tab @code{unset environment}
22956
22957 @item @code{environment-reset}
22958 @tab @code{QEnvironmentReset}
22959 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
22960
22961 @item @code{set-working-dir}
22962 @tab @code{QSetWorkingDir}
22963 @tab @code{set cwd}
22964
22965 @item @code{conditional-breakpoints-packet}
22966 @tab @code{Z0 and Z1}
22967 @tab @code{Support for target-side breakpoint condition evaluation}
22968
22969 @item @code{multiprocess-extensions}
22970 @tab @code{multiprocess extensions}
22971 @tab Debug multiple processes and remote process PID awareness
22972
22973 @item @code{swbreak-feature}
22974 @tab @code{swbreak stop reason}
22975 @tab @code{break}
22976
22977 @item @code{hwbreak-feature}
22978 @tab @code{hwbreak stop reason}
22979 @tab @code{hbreak}
22980
22981 @item @code{fork-event-feature}
22982 @tab @code{fork stop reason}
22983 @tab @code{fork}
22984
22985 @item @code{vfork-event-feature}
22986 @tab @code{vfork stop reason}
22987 @tab @code{vfork}
22988
22989 @item @code{exec-event-feature}
22990 @tab @code{exec stop reason}
22991 @tab @code{exec}
22992
22993 @item @code{thread-events}
22994 @tab @code{QThreadEvents}
22995 @tab Tracking thread lifetime.
22996
22997 @item @code{no-resumed-stop-reply}
22998 @tab @code{no resumed thread left stop reply}
22999 @tab Tracking thread lifetime.
23000
23001 @end multitable
23002
23003 @node Remote Stub
23004 @section Implementing a Remote Stub
23005
23006 @cindex debugging stub, example
23007 @cindex remote stub, example
23008 @cindex stub example, remote debugging
23009 The stub files provided with @value{GDBN} implement the target side of the
23010 communication protocol, and the @value{GDBN} side is implemented in the
23011 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23012 these subroutines to communicate, and ignore the details. (If you're
23013 implementing your own stub file, you can still ignore the details: start
23014 with one of the existing stub files. @file{sparc-stub.c} is the best
23015 organized, and therefore the easiest to read.)
23016
23017 @cindex remote serial debugging, overview
23018 To debug a program running on another machine (the debugging
23019 @dfn{target} machine), you must first arrange for all the usual
23020 prerequisites for the program to run by itself. For example, for a C
23021 program, you need:
23022
23023 @enumerate
23024 @item
23025 A startup routine to set up the C runtime environment; these usually
23026 have a name like @file{crt0}. The startup routine may be supplied by
23027 your hardware supplier, or you may have to write your own.
23028
23029 @item
23030 A C subroutine library to support your program's
23031 subroutine calls, notably managing input and output.
23032
23033 @item
23034 A way of getting your program to the other machine---for example, a
23035 download program. These are often supplied by the hardware
23036 manufacturer, but you may have to write your own from hardware
23037 documentation.
23038 @end enumerate
23039
23040 The next step is to arrange for your program to use a serial port to
23041 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23042 machine). In general terms, the scheme looks like this:
23043
23044 @table @emph
23045 @item On the host,
23046 @value{GDBN} already understands how to use this protocol; when everything
23047 else is set up, you can simply use the @samp{target remote} command
23048 (@pxref{Targets,,Specifying a Debugging Target}).
23049
23050 @item On the target,
23051 you must link with your program a few special-purpose subroutines that
23052 implement the @value{GDBN} remote serial protocol. The file containing these
23053 subroutines is called a @dfn{debugging stub}.
23054
23055 On certain remote targets, you can use an auxiliary program
23056 @code{gdbserver} instead of linking a stub into your program.
23057 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23058 @end table
23059
23060 The debugging stub is specific to the architecture of the remote
23061 machine; for example, use @file{sparc-stub.c} to debug programs on
23062 @sc{sparc} boards.
23063
23064 @cindex remote serial stub list
23065 These working remote stubs are distributed with @value{GDBN}:
23066
23067 @table @code
23068
23069 @item i386-stub.c
23070 @cindex @file{i386-stub.c}
23071 @cindex Intel
23072 @cindex i386
23073 For Intel 386 and compatible architectures.
23074
23075 @item m68k-stub.c
23076 @cindex @file{m68k-stub.c}
23077 @cindex Motorola 680x0
23078 @cindex m680x0
23079 For Motorola 680x0 architectures.
23080
23081 @item sh-stub.c
23082 @cindex @file{sh-stub.c}
23083 @cindex Renesas
23084 @cindex SH
23085 For Renesas SH architectures.
23086
23087 @item sparc-stub.c
23088 @cindex @file{sparc-stub.c}
23089 @cindex Sparc
23090 For @sc{sparc} architectures.
23091
23092 @item sparcl-stub.c
23093 @cindex @file{sparcl-stub.c}
23094 @cindex Fujitsu
23095 @cindex SparcLite
23096 For Fujitsu @sc{sparclite} architectures.
23097
23098 @end table
23099
23100 The @file{README} file in the @value{GDBN} distribution may list other
23101 recently added stubs.
23102
23103 @menu
23104 * Stub Contents:: What the stub can do for you
23105 * Bootstrapping:: What you must do for the stub
23106 * Debug Session:: Putting it all together
23107 @end menu
23108
23109 @node Stub Contents
23110 @subsection What the Stub Can Do for You
23111
23112 @cindex remote serial stub
23113 The debugging stub for your architecture supplies these three
23114 subroutines:
23115
23116 @table @code
23117 @item set_debug_traps
23118 @findex set_debug_traps
23119 @cindex remote serial stub, initialization
23120 This routine arranges for @code{handle_exception} to run when your
23121 program stops. You must call this subroutine explicitly in your
23122 program's startup code.
23123
23124 @item handle_exception
23125 @findex handle_exception
23126 @cindex remote serial stub, main routine
23127 This is the central workhorse, but your program never calls it
23128 explicitly---the setup code arranges for @code{handle_exception} to
23129 run when a trap is triggered.
23130
23131 @code{handle_exception} takes control when your program stops during
23132 execution (for example, on a breakpoint), and mediates communications
23133 with @value{GDBN} on the host machine. This is where the communications
23134 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23135 representative on the target machine. It begins by sending summary
23136 information on the state of your program, then continues to execute,
23137 retrieving and transmitting any information @value{GDBN} needs, until you
23138 execute a @value{GDBN} command that makes your program resume; at that point,
23139 @code{handle_exception} returns control to your own code on the target
23140 machine.
23141
23142 @item breakpoint
23143 @cindex @code{breakpoint} subroutine, remote
23144 Use this auxiliary subroutine to make your program contain a
23145 breakpoint. Depending on the particular situation, this may be the only
23146 way for @value{GDBN} to get control. For instance, if your target
23147 machine has some sort of interrupt button, you won't need to call this;
23148 pressing the interrupt button transfers control to
23149 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23150 simply receiving characters on the serial port may also trigger a trap;
23151 again, in that situation, you don't need to call @code{breakpoint} from
23152 your own program---simply running @samp{target remote} from the host
23153 @value{GDBN} session gets control.
23154
23155 Call @code{breakpoint} if none of these is true, or if you simply want
23156 to make certain your program stops at a predetermined point for the
23157 start of your debugging session.
23158 @end table
23159
23160 @node Bootstrapping
23161 @subsection What You Must Do for the Stub
23162
23163 @cindex remote stub, support routines
23164 The debugging stubs that come with @value{GDBN} are set up for a particular
23165 chip architecture, but they have no information about the rest of your
23166 debugging target machine.
23167
23168 First of all you need to tell the stub how to communicate with the
23169 serial port.
23170
23171 @table @code
23172 @item int getDebugChar()
23173 @findex getDebugChar
23174 Write this subroutine to read a single character from the serial port.
23175 It may be identical to @code{getchar} for your target system; a
23176 different name is used to allow you to distinguish the two if you wish.
23177
23178 @item void putDebugChar(int)
23179 @findex putDebugChar
23180 Write this subroutine to write a single character to the serial port.
23181 It may be identical to @code{putchar} for your target system; a
23182 different name is used to allow you to distinguish the two if you wish.
23183 @end table
23184
23185 @cindex control C, and remote debugging
23186 @cindex interrupting remote targets
23187 If you want @value{GDBN} to be able to stop your program while it is
23188 running, you need to use an interrupt-driven serial driver, and arrange
23189 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23190 character). That is the character which @value{GDBN} uses to tell the
23191 remote system to stop.
23192
23193 Getting the debugging target to return the proper status to @value{GDBN}
23194 probably requires changes to the standard stub; one quick and dirty way
23195 is to just execute a breakpoint instruction (the ``dirty'' part is that
23196 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23197
23198 Other routines you need to supply are:
23199
23200 @table @code
23201 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23202 @findex exceptionHandler
23203 Write this function to install @var{exception_address} in the exception
23204 handling tables. You need to do this because the stub does not have any
23205 way of knowing what the exception handling tables on your target system
23206 are like (for example, the processor's table might be in @sc{rom},
23207 containing entries which point to a table in @sc{ram}).
23208 The @var{exception_number} specifies the exception which should be changed;
23209 its meaning is architecture-dependent (for example, different numbers
23210 might represent divide by zero, misaligned access, etc). When this
23211 exception occurs, control should be transferred directly to
23212 @var{exception_address}, and the processor state (stack, registers,
23213 and so on) should be just as it is when a processor exception occurs. So if
23214 you want to use a jump instruction to reach @var{exception_address}, it
23215 should be a simple jump, not a jump to subroutine.
23216
23217 For the 386, @var{exception_address} should be installed as an interrupt
23218 gate so that interrupts are masked while the handler runs. The gate
23219 should be at privilege level 0 (the most privileged level). The
23220 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23221 help from @code{exceptionHandler}.
23222
23223 @item void flush_i_cache()
23224 @findex flush_i_cache
23225 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23226 instruction cache, if any, on your target machine. If there is no
23227 instruction cache, this subroutine may be a no-op.
23228
23229 On target machines that have instruction caches, @value{GDBN} requires this
23230 function to make certain that the state of your program is stable.
23231 @end table
23232
23233 @noindent
23234 You must also make sure this library routine is available:
23235
23236 @table @code
23237 @item void *memset(void *, int, int)
23238 @findex memset
23239 This is the standard library function @code{memset} that sets an area of
23240 memory to a known value. If you have one of the free versions of
23241 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23242 either obtain it from your hardware manufacturer, or write your own.
23243 @end table
23244
23245 If you do not use the GNU C compiler, you may need other standard
23246 library subroutines as well; this varies from one stub to another,
23247 but in general the stubs are likely to use any of the common library
23248 subroutines which @code{@value{NGCC}} generates as inline code.
23249
23250
23251 @node Debug Session
23252 @subsection Putting it All Together
23253
23254 @cindex remote serial debugging summary
23255 In summary, when your program is ready to debug, you must follow these
23256 steps.
23257
23258 @enumerate
23259 @item
23260 Make sure you have defined the supporting low-level routines
23261 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23262 @display
23263 @code{getDebugChar}, @code{putDebugChar},
23264 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23265 @end display
23266
23267 @item
23268 Insert these lines in your program's startup code, before the main
23269 procedure is called:
23270
23271 @smallexample
23272 set_debug_traps();
23273 breakpoint();
23274 @end smallexample
23275
23276 On some machines, when a breakpoint trap is raised, the hardware
23277 automatically makes the PC point to the instruction after the
23278 breakpoint. If your machine doesn't do that, you may need to adjust
23279 @code{handle_exception} to arrange for it to return to the instruction
23280 after the breakpoint on this first invocation, so that your program
23281 doesn't keep hitting the initial breakpoint instead of making
23282 progress.
23283
23284 @item
23285 For the 680x0 stub only, you need to provide a variable called
23286 @code{exceptionHook}. Normally you just use:
23287
23288 @smallexample
23289 void (*exceptionHook)() = 0;
23290 @end smallexample
23291
23292 @noindent
23293 but if before calling @code{set_debug_traps}, you set it to point to a
23294 function in your program, that function is called when
23295 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23296 error). The function indicated by @code{exceptionHook} is called with
23297 one parameter: an @code{int} which is the exception number.
23298
23299 @item
23300 Compile and link together: your program, the @value{GDBN} debugging stub for
23301 your target architecture, and the supporting subroutines.
23302
23303 @item
23304 Make sure you have a serial connection between your target machine and
23305 the @value{GDBN} host, and identify the serial port on the host.
23306
23307 @item
23308 @c The "remote" target now provides a `load' command, so we should
23309 @c document that. FIXME.
23310 Download your program to your target machine (or get it there by
23311 whatever means the manufacturer provides), and start it.
23312
23313 @item
23314 Start @value{GDBN} on the host, and connect to the target
23315 (@pxref{Connecting,,Connecting to a Remote Target}).
23316
23317 @end enumerate
23318
23319 @node Configurations
23320 @chapter Configuration-Specific Information
23321
23322 While nearly all @value{GDBN} commands are available for all native and
23323 cross versions of the debugger, there are some exceptions. This chapter
23324 describes things that are only available in certain configurations.
23325
23326 There are three major categories of configurations: native
23327 configurations, where the host and target are the same, embedded
23328 operating system configurations, which are usually the same for several
23329 different processor architectures, and bare embedded processors, which
23330 are quite different from each other.
23331
23332 @menu
23333 * Native::
23334 * Embedded OS::
23335 * Embedded Processors::
23336 * Architectures::
23337 @end menu
23338
23339 @node Native
23340 @section Native
23341
23342 This section describes details specific to particular native
23343 configurations.
23344
23345 @menu
23346 * BSD libkvm Interface:: Debugging BSD kernel memory images
23347 * Process Information:: Process information
23348 * DJGPP Native:: Features specific to the DJGPP port
23349 * Cygwin Native:: Features specific to the Cygwin port
23350 * Hurd Native:: Features specific to @sc{gnu} Hurd
23351 * Darwin:: Features specific to Darwin
23352 * FreeBSD:: Features specific to FreeBSD
23353 @end menu
23354
23355 @node BSD libkvm Interface
23356 @subsection BSD libkvm Interface
23357
23358 @cindex libkvm
23359 @cindex kernel memory image
23360 @cindex kernel crash dump
23361
23362 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23363 interface that provides a uniform interface for accessing kernel virtual
23364 memory images, including live systems and crash dumps. @value{GDBN}
23365 uses this interface to allow you to debug live kernels and kernel crash
23366 dumps on many native BSD configurations. This is implemented as a
23367 special @code{kvm} debugging target. For debugging a live system, load
23368 the currently running kernel into @value{GDBN} and connect to the
23369 @code{kvm} target:
23370
23371 @smallexample
23372 (@value{GDBP}) @b{target kvm}
23373 @end smallexample
23374
23375 For debugging crash dumps, provide the file name of the crash dump as an
23376 argument:
23377
23378 @smallexample
23379 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23380 @end smallexample
23381
23382 Once connected to the @code{kvm} target, the following commands are
23383 available:
23384
23385 @table @code
23386 @kindex kvm
23387 @item kvm pcb
23388 Set current context from the @dfn{Process Control Block} (PCB) address.
23389
23390 @item kvm proc
23391 Set current context from proc address. This command isn't available on
23392 modern FreeBSD systems.
23393 @end table
23394
23395 @node Process Information
23396 @subsection Process Information
23397 @cindex /proc
23398 @cindex examine process image
23399 @cindex process info via @file{/proc}
23400
23401 Some operating systems provide interfaces to fetch additional
23402 information about running processes beyond memory and per-thread
23403 register state. If @value{GDBN} is configured for an operating system
23404 with a supported interface, the command @code{info proc} is available
23405 to report information about the process running your program, or about
23406 any process running on your system.
23407
23408 One supported interface is a facility called @samp{/proc} that can be
23409 used to examine the image of a running process using file-system
23410 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23411 systems.
23412
23413 On FreeBSD and NetBSD systems, system control nodes are used to query
23414 process information.
23415
23416 In addition, some systems may provide additional process information
23417 in core files. Note that a core file may include a subset of the
23418 information available from a live process. Process information is
23419 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23420 systems.
23421
23422 @table @code
23423 @kindex info proc
23424 @cindex process ID
23425 @item info proc
23426 @itemx info proc @var{process-id}
23427 Summarize available information about a process. If a
23428 process ID is specified by @var{process-id}, display information about
23429 that process; otherwise display information about the program being
23430 debugged. The summary includes the debugged process ID, the command
23431 line used to invoke it, its current working directory, and its
23432 executable file's absolute file name.
23433
23434 On some systems, @var{process-id} can be of the form
23435 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23436 within a process. If the optional @var{pid} part is missing, it means
23437 a thread from the process being debugged (the leading @samp{/} still
23438 needs to be present, or else @value{GDBN} will interpret the number as
23439 a process ID rather than a thread ID).
23440
23441 @item info proc cmdline
23442 @cindex info proc cmdline
23443 Show the original command line of the process. This command is
23444 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23445
23446 @item info proc cwd
23447 @cindex info proc cwd
23448 Show the current working directory of the process. This command is
23449 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23450
23451 @item info proc exe
23452 @cindex info proc exe
23453 Show the name of executable of the process. This command is supported
23454 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23455
23456 @item info proc files
23457 @cindex info proc files
23458 Show the file descriptors open by the process. For each open file
23459 descriptor, @value{GDBN} shows its number, type (file, directory,
23460 character device, socket), file pointer offset, and the name of the
23461 resource open on the descriptor. The resource name can be a file name
23462 (for files, directories, and devices) or a protocol followed by socket
23463 address (for network connections). This command is supported on
23464 FreeBSD.
23465
23466 This example shows the open file descriptors for a process using a
23467 tty for standard input and output as well as two network sockets:
23468
23469 @smallexample
23470 (gdb) info proc files 22136
23471 process 22136
23472 Open files:
23473
23474 FD Type Offset Flags Name
23475 text file - r-------- /usr/bin/ssh
23476 ctty chr - rw------- /dev/pts/20
23477 cwd dir - r-------- /usr/home/john
23478 root dir - r-------- /
23479 0 chr 0x32933a4 rw------- /dev/pts/20
23480 1 chr 0x32933a4 rw------- /dev/pts/20
23481 2 chr 0x32933a4 rw------- /dev/pts/20
23482 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23483 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23484 @end smallexample
23485
23486 @item info proc mappings
23487 @cindex memory address space mappings
23488 Report the memory address space ranges accessible in a process. On
23489 Solaris, FreeBSD and NetBSD systems, each memory range includes information
23490 on whether the process has read, write, or execute access rights to each
23491 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23492 includes the object file which is mapped to that range.
23493
23494 @item info proc stat
23495 @itemx info proc status
23496 @cindex process detailed status information
23497 Show additional process-related information, including the user ID and
23498 group ID; virtual memory usage; the signals that are pending, blocked,
23499 and ignored; its TTY; its consumption of system and user time; its
23500 stack size; its @samp{nice} value; etc. These commands are supported
23501 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23502
23503 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23504 information (type @kbd{man 5 proc} from your shell prompt).
23505
23506 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23507 @code{info proc status}.
23508
23509 @item info proc all
23510 Show all the information about the process described under all of the
23511 above @code{info proc} subcommands.
23512
23513 @ignore
23514 @comment These sub-options of 'info proc' were not included when
23515 @comment procfs.c was re-written. Keep their descriptions around
23516 @comment against the day when someone finds the time to put them back in.
23517 @kindex info proc times
23518 @item info proc times
23519 Starting time, user CPU time, and system CPU time for your program and
23520 its children.
23521
23522 @kindex info proc id
23523 @item info proc id
23524 Report on the process IDs related to your program: its own process ID,
23525 the ID of its parent, the process group ID, and the session ID.
23526 @end ignore
23527
23528 @item set procfs-trace
23529 @kindex set procfs-trace
23530 @cindex @code{procfs} API calls
23531 This command enables and disables tracing of @code{procfs} API calls.
23532
23533 @item show procfs-trace
23534 @kindex show procfs-trace
23535 Show the current state of @code{procfs} API call tracing.
23536
23537 @item set procfs-file @var{file}
23538 @kindex set procfs-file
23539 Tell @value{GDBN} to write @code{procfs} API trace to the named
23540 @var{file}. @value{GDBN} appends the trace info to the previous
23541 contents of the file. The default is to display the trace on the
23542 standard output.
23543
23544 @item show procfs-file
23545 @kindex show procfs-file
23546 Show the file to which @code{procfs} API trace is written.
23547
23548 @item proc-trace-entry
23549 @itemx proc-trace-exit
23550 @itemx proc-untrace-entry
23551 @itemx proc-untrace-exit
23552 @kindex proc-trace-entry
23553 @kindex proc-trace-exit
23554 @kindex proc-untrace-entry
23555 @kindex proc-untrace-exit
23556 These commands enable and disable tracing of entries into and exits
23557 from the @code{syscall} interface.
23558
23559 @item info pidlist
23560 @kindex info pidlist
23561 @cindex process list, QNX Neutrino
23562 For QNX Neutrino only, this command displays the list of all the
23563 processes and all the threads within each process.
23564
23565 @item info meminfo
23566 @kindex info meminfo
23567 @cindex mapinfo list, QNX Neutrino
23568 For QNX Neutrino only, this command displays the list of all mapinfos.
23569 @end table
23570
23571 @node DJGPP Native
23572 @subsection Features for Debugging @sc{djgpp} Programs
23573 @cindex @sc{djgpp} debugging
23574 @cindex native @sc{djgpp} debugging
23575 @cindex MS-DOS-specific commands
23576
23577 @cindex DPMI
23578 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23579 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23580 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23581 top of real-mode DOS systems and their emulations.
23582
23583 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
23584 defines a few commands specific to the @sc{djgpp} port. This
23585 subsection describes those commands.
23586
23587 @table @code
23588 @kindex info dos
23589 @item info dos
23590 This is a prefix of @sc{djgpp}-specific commands which print
23591 information about the target system and important OS structures.
23592
23593 @kindex sysinfo
23594 @cindex MS-DOS system info
23595 @cindex free memory information (MS-DOS)
23596 @item info dos sysinfo
23597 This command displays assorted information about the underlying
23598 platform: the CPU type and features, the OS version and flavor, the
23599 DPMI version, and the available conventional and DPMI memory.
23600
23601 @cindex GDT
23602 @cindex LDT
23603 @cindex IDT
23604 @cindex segment descriptor tables
23605 @cindex descriptor tables display
23606 @item info dos gdt
23607 @itemx info dos ldt
23608 @itemx info dos idt
23609 These 3 commands display entries from, respectively, Global, Local,
23610 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23611 tables are data structures which store a descriptor for each segment
23612 that is currently in use. The segment's selector is an index into a
23613 descriptor table; the table entry for that index holds the
23614 descriptor's base address and limit, and its attributes and access
23615 rights.
23616
23617 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23618 segment (used for both data and the stack), and a DOS segment (which
23619 allows access to DOS/BIOS data structures and absolute addresses in
23620 conventional memory). However, the DPMI host will usually define
23621 additional segments in order to support the DPMI environment.
23622
23623 @cindex garbled pointers
23624 These commands allow to display entries from the descriptor tables.
23625 Without an argument, all entries from the specified table are
23626 displayed. An argument, which should be an integer expression, means
23627 display a single entry whose index is given by the argument. For
23628 example, here's a convenient way to display information about the
23629 debugged program's data segment:
23630
23631 @smallexample
23632 @exdent @code{(@value{GDBP}) info dos ldt $ds}
23633 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23634 @end smallexample
23635
23636 @noindent
23637 This comes in handy when you want to see whether a pointer is outside
23638 the data segment's limit (i.e.@: @dfn{garbled}).
23639
23640 @cindex page tables display (MS-DOS)
23641 @item info dos pde
23642 @itemx info dos pte
23643 These two commands display entries from, respectively, the Page
23644 Directory and the Page Tables. Page Directories and Page Tables are
23645 data structures which control how virtual memory addresses are mapped
23646 into physical addresses. A Page Table includes an entry for every
23647 page of memory that is mapped into the program's address space; there
23648 may be several Page Tables, each one holding up to 4096 entries. A
23649 Page Directory has up to 4096 entries, one each for every Page Table
23650 that is currently in use.
23651
23652 Without an argument, @kbd{info dos pde} displays the entire Page
23653 Directory, and @kbd{info dos pte} displays all the entries in all of
23654 the Page Tables. An argument, an integer expression, given to the
23655 @kbd{info dos pde} command means display only that entry from the Page
23656 Directory table. An argument given to the @kbd{info dos pte} command
23657 means display entries from a single Page Table, the one pointed to by
23658 the specified entry in the Page Directory.
23659
23660 @cindex direct memory access (DMA) on MS-DOS
23661 These commands are useful when your program uses @dfn{DMA} (Direct
23662 Memory Access), which needs physical addresses to program the DMA
23663 controller.
23664
23665 These commands are supported only with some DPMI servers.
23666
23667 @cindex physical address from linear address
23668 @item info dos address-pte @var{addr}
23669 This command displays the Page Table entry for a specified linear
23670 address. The argument @var{addr} is a linear address which should
23671 already have the appropriate segment's base address added to it,
23672 because this command accepts addresses which may belong to @emph{any}
23673 segment. For example, here's how to display the Page Table entry for
23674 the page where a variable @code{i} is stored:
23675
23676 @smallexample
23677 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23678 @exdent @code{Page Table entry for address 0x11a00d30:}
23679 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
23680 @end smallexample
23681
23682 @noindent
23683 This says that @code{i} is stored at offset @code{0xd30} from the page
23684 whose physical base address is @code{0x02698000}, and shows all the
23685 attributes of that page.
23686
23687 Note that you must cast the addresses of variables to a @code{char *},
23688 since otherwise the value of @code{__djgpp_base_address}, the base
23689 address of all variables and functions in a @sc{djgpp} program, will
23690 be added using the rules of C pointer arithmetics: if @code{i} is
23691 declared an @code{int}, @value{GDBN} will add 4 times the value of
23692 @code{__djgpp_base_address} to the address of @code{i}.
23693
23694 Here's another example, it displays the Page Table entry for the
23695 transfer buffer:
23696
23697 @smallexample
23698 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23699 @exdent @code{Page Table entry for address 0x29110:}
23700 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23701 @end smallexample
23702
23703 @noindent
23704 (The @code{+ 3} offset is because the transfer buffer's address is the
23705 3rd member of the @code{_go32_info_block} structure.) The output
23706 clearly shows that this DPMI server maps the addresses in conventional
23707 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23708 linear (@code{0x29110}) addresses are identical.
23709
23710 This command is supported only with some DPMI servers.
23711 @end table
23712
23713 @cindex DOS serial data link, remote debugging
23714 In addition to native debugging, the DJGPP port supports remote
23715 debugging via a serial data link. The following commands are specific
23716 to remote serial debugging in the DJGPP port of @value{GDBN}.
23717
23718 @table @code
23719 @kindex set com1base
23720 @kindex set com1irq
23721 @kindex set com2base
23722 @kindex set com2irq
23723 @kindex set com3base
23724 @kindex set com3irq
23725 @kindex set com4base
23726 @kindex set com4irq
23727 @item set com1base @var{addr}
23728 This command sets the base I/O port address of the @file{COM1} serial
23729 port.
23730
23731 @item set com1irq @var{irq}
23732 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23733 for the @file{COM1} serial port.
23734
23735 There are similar commands @samp{set com2base}, @samp{set com3irq},
23736 etc.@: for setting the port address and the @code{IRQ} lines for the
23737 other 3 COM ports.
23738
23739 @kindex show com1base
23740 @kindex show com1irq
23741 @kindex show com2base
23742 @kindex show com2irq
23743 @kindex show com3base
23744 @kindex show com3irq
23745 @kindex show com4base
23746 @kindex show com4irq
23747 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23748 display the current settings of the base address and the @code{IRQ}
23749 lines used by the COM ports.
23750
23751 @item info serial
23752 @kindex info serial
23753 @cindex DOS serial port status
23754 This command prints the status of the 4 DOS serial ports. For each
23755 port, it prints whether it's active or not, its I/O base address and
23756 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23757 counts of various errors encountered so far.
23758 @end table
23759
23760
23761 @node Cygwin Native
23762 @subsection Features for Debugging MS Windows PE Executables
23763 @cindex MS Windows debugging
23764 @cindex native Cygwin debugging
23765 @cindex Cygwin-specific commands
23766
23767 @value{GDBN} supports native debugging of MS Windows programs, including
23768 DLLs with and without symbolic debugging information.
23769
23770 @cindex Ctrl-BREAK, MS-Windows
23771 @cindex interrupt debuggee on MS-Windows
23772 MS-Windows programs that call @code{SetConsoleMode} to switch off the
23773 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23774 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23775 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23776 sequence, which can be used to interrupt the debuggee even if it
23777 ignores @kbd{C-c}.
23778
23779 There are various additional Cygwin-specific commands, described in
23780 this section. Working with DLLs that have no debugging symbols is
23781 described in @ref{Non-debug DLL Symbols}.
23782
23783 @table @code
23784 @kindex info w32
23785 @item info w32
23786 This is a prefix of MS Windows-specific commands which print
23787 information about the target system and important OS structures.
23788
23789 @item info w32 selector
23790 This command displays information returned by
23791 the Win32 API @code{GetThreadSelectorEntry} function.
23792 It takes an optional argument that is evaluated to
23793 a long value to give the information about this given selector.
23794 Without argument, this command displays information
23795 about the six segment registers.
23796
23797 @item info w32 thread-information-block
23798 This command displays thread specific information stored in the
23799 Thread Information Block (readable on the X86 CPU family using @code{$fs}
23800 selector for 32-bit programs and @code{$gs} for 64-bit programs).
23801
23802 @kindex signal-event
23803 @item signal-event @var{id}
23804 This command signals an event with user-provided @var{id}. Used to resume
23805 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23806
23807 To use it, create or edit the following keys in
23808 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23809 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23810 (for x86_64 versions):
23811
23812 @itemize @minus
23813 @item
23814 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
23815 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23816 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
23817
23818 The first @code{%ld} will be replaced by the process ID of the
23819 crashing process, the second @code{%ld} will be replaced by the ID of
23820 the event that blocks the crashing process, waiting for @value{GDBN}
23821 to attach.
23822
23823 @item
23824 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23825 make the system run debugger specified by the Debugger key
23826 automatically, @code{0} will cause a dialog box with ``OK'' and
23827 ``Cancel'' buttons to appear, which allows the user to either
23828 terminate the crashing process (OK) or debug it (Cancel).
23829 @end itemize
23830
23831 @kindex set cygwin-exceptions
23832 @cindex debugging the Cygwin DLL
23833 @cindex Cygwin DLL, debugging
23834 @item set cygwin-exceptions @var{mode}
23835 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23836 happen inside the Cygwin DLL. If @var{mode} is @code{off},
23837 @value{GDBN} will delay recognition of exceptions, and may ignore some
23838 exceptions which seem to be caused by internal Cygwin DLL
23839 ``bookkeeping''. This option is meant primarily for debugging the
23840 Cygwin DLL itself; the default value is @code{off} to avoid annoying
23841 @value{GDBN} users with false @code{SIGSEGV} signals.
23842
23843 @kindex show cygwin-exceptions
23844 @item show cygwin-exceptions
23845 Displays whether @value{GDBN} will break on exceptions that happen
23846 inside the Cygwin DLL itself.
23847
23848 @kindex set new-console
23849 @item set new-console @var{mode}
23850 If @var{mode} is @code{on} the debuggee will
23851 be started in a new console on next start.
23852 If @var{mode} is @code{off}, the debuggee will
23853 be started in the same console as the debugger.
23854
23855 @kindex show new-console
23856 @item show new-console
23857 Displays whether a new console is used
23858 when the debuggee is started.
23859
23860 @kindex set new-group
23861 @item set new-group @var{mode}
23862 This boolean value controls whether the debuggee should
23863 start a new group or stay in the same group as the debugger.
23864 This affects the way the Windows OS handles
23865 @samp{Ctrl-C}.
23866
23867 @kindex show new-group
23868 @item show new-group
23869 Displays current value of new-group boolean.
23870
23871 @kindex set debugevents
23872 @item set debugevents
23873 This boolean value adds debug output concerning kernel events related
23874 to the debuggee seen by the debugger. This includes events that
23875 signal thread and process creation and exit, DLL loading and
23876 unloading, console interrupts, and debugging messages produced by the
23877 Windows @code{OutputDebugString} API call.
23878
23879 @kindex set debugexec
23880 @item set debugexec
23881 This boolean value adds debug output concerning execute events
23882 (such as resume thread) seen by the debugger.
23883
23884 @kindex set debugexceptions
23885 @item set debugexceptions
23886 This boolean value adds debug output concerning exceptions in the
23887 debuggee seen by the debugger.
23888
23889 @kindex set debugmemory
23890 @item set debugmemory
23891 This boolean value adds debug output concerning debuggee memory reads
23892 and writes by the debugger.
23893
23894 @kindex set shell
23895 @item set shell
23896 This boolean values specifies whether the debuggee is called
23897 via a shell or directly (default value is on).
23898
23899 @kindex show shell
23900 @item show shell
23901 Displays if the debuggee will be started with a shell.
23902
23903 @end table
23904
23905 @menu
23906 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
23907 @end menu
23908
23909 @node Non-debug DLL Symbols
23910 @subsubsection Support for DLLs without Debugging Symbols
23911 @cindex DLLs with no debugging symbols
23912 @cindex Minimal symbols and DLLs
23913
23914 Very often on windows, some of the DLLs that your program relies on do
23915 not include symbolic debugging information (for example,
23916 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
23917 symbols in a DLL, it relies on the minimal amount of symbolic
23918 information contained in the DLL's export table. This section
23919 describes working with such symbols, known internally to @value{GDBN} as
23920 ``minimal symbols''.
23921
23922 Note that before the debugged program has started execution, no DLLs
23923 will have been loaded. The easiest way around this problem is simply to
23924 start the program --- either by setting a breakpoint or letting the
23925 program run once to completion.
23926
23927 @subsubsection DLL Name Prefixes
23928
23929 In keeping with the naming conventions used by the Microsoft debugging
23930 tools, DLL export symbols are made available with a prefix based on the
23931 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
23932 also entered into the symbol table, so @code{CreateFileA} is often
23933 sufficient. In some cases there will be name clashes within a program
23934 (particularly if the executable itself includes full debugging symbols)
23935 necessitating the use of the fully qualified name when referring to the
23936 contents of the DLL. Use single-quotes around the name to avoid the
23937 exclamation mark (``!'') being interpreted as a language operator.
23938
23939 Note that the internal name of the DLL may be all upper-case, even
23940 though the file name of the DLL is lower-case, or vice-versa. Since
23941 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
23942 some confusion. If in doubt, try the @code{info functions} and
23943 @code{info variables} commands or even @code{maint print msymbols}
23944 (@pxref{Symbols}). Here's an example:
23945
23946 @smallexample
23947 (@value{GDBP}) info function CreateFileA
23948 All functions matching regular expression "CreateFileA":
23949
23950 Non-debugging symbols:
23951 0x77e885f4 CreateFileA
23952 0x77e885f4 KERNEL32!CreateFileA
23953 @end smallexample
23954
23955 @smallexample
23956 (@value{GDBP}) info function !
23957 All functions matching regular expression "!":
23958
23959 Non-debugging symbols:
23960 0x6100114c cygwin1!__assert
23961 0x61004034 cygwin1!_dll_crt0@@0
23962 0x61004240 cygwin1!dll_crt0(per_process *)
23963 [etc...]
23964 @end smallexample
23965
23966 @subsubsection Working with Minimal Symbols
23967
23968 Symbols extracted from a DLL's export table do not contain very much
23969 type information. All that @value{GDBN} can do is guess whether a symbol
23970 refers to a function or variable depending on the linker section that
23971 contains the symbol. Also note that the actual contents of the memory
23972 contained in a DLL are not available unless the program is running. This
23973 means that you cannot examine the contents of a variable or disassemble
23974 a function within a DLL without a running program.
23975
23976 Variables are generally treated as pointers and dereferenced
23977 automatically. For this reason, it is often necessary to prefix a
23978 variable name with the address-of operator (``&'') and provide explicit
23979 type information in the command. Here's an example of the type of
23980 problem:
23981
23982 @smallexample
23983 (@value{GDBP}) print 'cygwin1!__argv'
23984 'cygwin1!__argv' has unknown type; cast it to its declared type
23985 @end smallexample
23986
23987 @smallexample
23988 (@value{GDBP}) x 'cygwin1!__argv'
23989 'cygwin1!__argv' has unknown type; cast it to its declared type
23990 @end smallexample
23991
23992 And two possible solutions:
23993
23994 @smallexample
23995 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
23996 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
23997 @end smallexample
23998
23999 @smallexample
24000 (@value{GDBP}) x/2x &'cygwin1!__argv'
24001 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24002 (@value{GDBP}) x/x 0x10021608
24003 0x10021608: 0x0022fd98
24004 (@value{GDBP}) x/s 0x0022fd98
24005 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24006 @end smallexample
24007
24008 Setting a break point within a DLL is possible even before the program
24009 starts execution. However, under these circumstances, @value{GDBN} can't
24010 examine the initial instructions of the function in order to skip the
24011 function's frame set-up code. You can work around this by using ``*&''
24012 to set the breakpoint at a raw memory address:
24013
24014 @smallexample
24015 (@value{GDBP}) break *&'python22!PyOS_Readline'
24016 Breakpoint 1 at 0x1e04eff0
24017 @end smallexample
24018
24019 The author of these extensions is not entirely convinced that setting a
24020 break point within a shared DLL like @file{kernel32.dll} is completely
24021 safe.
24022
24023 @node Hurd Native
24024 @subsection Commands Specific to @sc{gnu} Hurd Systems
24025 @cindex @sc{gnu} Hurd debugging
24026
24027 This subsection describes @value{GDBN} commands specific to the
24028 @sc{gnu} Hurd native debugging.
24029
24030 @table @code
24031 @item set signals
24032 @itemx set sigs
24033 @kindex set signals@r{, Hurd command}
24034 @kindex set sigs@r{, Hurd command}
24035 This command toggles the state of inferior signal interception by
24036 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24037 affected by this command. @code{sigs} is a shorthand alias for
24038 @code{signals}.
24039
24040 @item show signals
24041 @itemx show sigs
24042 @kindex show signals@r{, Hurd command}
24043 @kindex show sigs@r{, Hurd command}
24044 Show the current state of intercepting inferior's signals.
24045
24046 @item set signal-thread
24047 @itemx set sigthread
24048 @kindex set signal-thread
24049 @kindex set sigthread
24050 This command tells @value{GDBN} which thread is the @code{libc} signal
24051 thread. That thread is run when a signal is delivered to a running
24052 process. @code{set sigthread} is the shorthand alias of @code{set
24053 signal-thread}.
24054
24055 @item show signal-thread
24056 @itemx show sigthread
24057 @kindex show signal-thread
24058 @kindex show sigthread
24059 These two commands show which thread will run when the inferior is
24060 delivered a signal.
24061
24062 @item set stopped
24063 @kindex set stopped@r{, Hurd command}
24064 This commands tells @value{GDBN} that the inferior process is stopped,
24065 as with the @code{SIGSTOP} signal. The stopped process can be
24066 continued by delivering a signal to it.
24067
24068 @item show stopped
24069 @kindex show stopped@r{, Hurd command}
24070 This command shows whether @value{GDBN} thinks the debuggee is
24071 stopped.
24072
24073 @item set exceptions
24074 @kindex set exceptions@r{, Hurd command}
24075 Use this command to turn off trapping of exceptions in the inferior.
24076 When exception trapping is off, neither breakpoints nor
24077 single-stepping will work. To restore the default, set exception
24078 trapping on.
24079
24080 @item show exceptions
24081 @kindex show exceptions@r{, Hurd command}
24082 Show the current state of trapping exceptions in the inferior.
24083
24084 @item set task pause
24085 @kindex set task@r{, Hurd commands}
24086 @cindex task attributes (@sc{gnu} Hurd)
24087 @cindex pause current task (@sc{gnu} Hurd)
24088 This command toggles task suspension when @value{GDBN} has control.
24089 Setting it to on takes effect immediately, and the task is suspended
24090 whenever @value{GDBN} gets control. Setting it to off will take
24091 effect the next time the inferior is continued. If this option is set
24092 to off, you can use @code{set thread default pause on} or @code{set
24093 thread pause on} (see below) to pause individual threads.
24094
24095 @item show task pause
24096 @kindex show task@r{, Hurd commands}
24097 Show the current state of task suspension.
24098
24099 @item set task detach-suspend-count
24100 @cindex task suspend count
24101 @cindex detach from task, @sc{gnu} Hurd
24102 This command sets the suspend count the task will be left with when
24103 @value{GDBN} detaches from it.
24104
24105 @item show task detach-suspend-count
24106 Show the suspend count the task will be left with when detaching.
24107
24108 @item set task exception-port
24109 @itemx set task excp
24110 @cindex task exception port, @sc{gnu} Hurd
24111 This command sets the task exception port to which @value{GDBN} will
24112 forward exceptions. The argument should be the value of the @dfn{send
24113 rights} of the task. @code{set task excp} is a shorthand alias.
24114
24115 @item set noninvasive
24116 @cindex noninvasive task options
24117 This command switches @value{GDBN} to a mode that is the least
24118 invasive as far as interfering with the inferior is concerned. This
24119 is the same as using @code{set task pause}, @code{set exceptions}, and
24120 @code{set signals} to values opposite to the defaults.
24121
24122 @item info send-rights
24123 @itemx info receive-rights
24124 @itemx info port-rights
24125 @itemx info port-sets
24126 @itemx info dead-names
24127 @itemx info ports
24128 @itemx info psets
24129 @cindex send rights, @sc{gnu} Hurd
24130 @cindex receive rights, @sc{gnu} Hurd
24131 @cindex port rights, @sc{gnu} Hurd
24132 @cindex port sets, @sc{gnu} Hurd
24133 @cindex dead names, @sc{gnu} Hurd
24134 These commands display information about, respectively, send rights,
24135 receive rights, port rights, port sets, and dead names of a task.
24136 There are also shorthand aliases: @code{info ports} for @code{info
24137 port-rights} and @code{info psets} for @code{info port-sets}.
24138
24139 @item set thread pause
24140 @kindex set thread@r{, Hurd command}
24141 @cindex thread properties, @sc{gnu} Hurd
24142 @cindex pause current thread (@sc{gnu} Hurd)
24143 This command toggles current thread suspension when @value{GDBN} has
24144 control. Setting it to on takes effect immediately, and the current
24145 thread is suspended whenever @value{GDBN} gets control. Setting it to
24146 off will take effect the next time the inferior is continued.
24147 Normally, this command has no effect, since when @value{GDBN} has
24148 control, the whole task is suspended. However, if you used @code{set
24149 task pause off} (see above), this command comes in handy to suspend
24150 only the current thread.
24151
24152 @item show thread pause
24153 @kindex show thread@r{, Hurd command}
24154 This command shows the state of current thread suspension.
24155
24156 @item set thread run
24157 This command sets whether the current thread is allowed to run.
24158
24159 @item show thread run
24160 Show whether the current thread is allowed to run.
24161
24162 @item set thread detach-suspend-count
24163 @cindex thread suspend count, @sc{gnu} Hurd
24164 @cindex detach from thread, @sc{gnu} Hurd
24165 This command sets the suspend count @value{GDBN} will leave on a
24166 thread when detaching. This number is relative to the suspend count
24167 found by @value{GDBN} when it notices the thread; use @code{set thread
24168 takeover-suspend-count} to force it to an absolute value.
24169
24170 @item show thread detach-suspend-count
24171 Show the suspend count @value{GDBN} will leave on the thread when
24172 detaching.
24173
24174 @item set thread exception-port
24175 @itemx set thread excp
24176 Set the thread exception port to which to forward exceptions. This
24177 overrides the port set by @code{set task exception-port} (see above).
24178 @code{set thread excp} is the shorthand alias.
24179
24180 @item set thread takeover-suspend-count
24181 Normally, @value{GDBN}'s thread suspend counts are relative to the
24182 value @value{GDBN} finds when it notices each thread. This command
24183 changes the suspend counts to be absolute instead.
24184
24185 @item set thread default
24186 @itemx show thread default
24187 @cindex thread default settings, @sc{gnu} Hurd
24188 Each of the above @code{set thread} commands has a @code{set thread
24189 default} counterpart (e.g., @code{set thread default pause}, @code{set
24190 thread default exception-port}, etc.). The @code{thread default}
24191 variety of commands sets the default thread properties for all
24192 threads; you can then change the properties of individual threads with
24193 the non-default commands.
24194 @end table
24195
24196 @node Darwin
24197 @subsection Darwin
24198 @cindex Darwin
24199
24200 @value{GDBN} provides the following commands specific to the Darwin target:
24201
24202 @table @code
24203 @item set debug darwin @var{num}
24204 @kindex set debug darwin
24205 When set to a non zero value, enables debugging messages specific to
24206 the Darwin support. Higher values produce more verbose output.
24207
24208 @item show debug darwin
24209 @kindex show debug darwin
24210 Show the current state of Darwin messages.
24211
24212 @item set debug mach-o @var{num}
24213 @kindex set debug mach-o
24214 When set to a non zero value, enables debugging messages while
24215 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24216 file format used on Darwin for object and executable files.) Higher
24217 values produce more verbose output. This is a command to diagnose
24218 problems internal to @value{GDBN} and should not be needed in normal
24219 usage.
24220
24221 @item show debug mach-o
24222 @kindex show debug mach-o
24223 Show the current state of Mach-O file messages.
24224
24225 @item set mach-exceptions on
24226 @itemx set mach-exceptions off
24227 @kindex set mach-exceptions
24228 On Darwin, faults are first reported as a Mach exception and are then
24229 mapped to a Posix signal. Use this command to turn on trapping of
24230 Mach exceptions in the inferior. This might be sometimes useful to
24231 better understand the cause of a fault. The default is off.
24232
24233 @item show mach-exceptions
24234 @kindex show mach-exceptions
24235 Show the current state of exceptions trapping.
24236 @end table
24237
24238 @node FreeBSD
24239 @subsection FreeBSD
24240 @cindex FreeBSD
24241
24242 When the ABI of a system call is changed in the FreeBSD kernel, this
24243 is implemented by leaving a compatibility system call using the old
24244 ABI at the existing number and allocating a new system call number for
24245 the version using the new ABI. As a convenience, when a system call
24246 is caught by name (@pxref{catch syscall}), compatibility system calls
24247 are also caught.
24248
24249 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24250 system call and catching the @code{kevent} system call by name catches
24251 both variants:
24252
24253 @smallexample
24254 (@value{GDBP}) catch syscall kevent
24255 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24256 (@value{GDBP})
24257 @end smallexample
24258
24259
24260 @node Embedded OS
24261 @section Embedded Operating Systems
24262
24263 This section describes configurations involving the debugging of
24264 embedded operating systems that are available for several different
24265 architectures.
24266
24267 @value{GDBN} includes the ability to debug programs running on
24268 various real-time operating systems.
24269
24270 @node Embedded Processors
24271 @section Embedded Processors
24272
24273 This section goes into details specific to particular embedded
24274 configurations.
24275
24276 @cindex send command to simulator
24277 Whenever a specific embedded processor has a simulator, @value{GDBN}
24278 allows to send an arbitrary command to the simulator.
24279
24280 @table @code
24281 @item sim @var{command}
24282 @kindex sim@r{, a command}
24283 Send an arbitrary @var{command} string to the simulator. Consult the
24284 documentation for the specific simulator in use for information about
24285 acceptable commands.
24286 @end table
24287
24288
24289 @menu
24290 * ARC:: Synopsys ARC
24291 * ARM:: ARM
24292 * M68K:: Motorola M68K
24293 * MicroBlaze:: Xilinx MicroBlaze
24294 * MIPS Embedded:: MIPS Embedded
24295 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24296 * PowerPC Embedded:: PowerPC Embedded
24297 * AVR:: Atmel AVR
24298 * CRIS:: CRIS
24299 * Super-H:: Renesas Super-H
24300 @end menu
24301
24302 @node ARC
24303 @subsection Synopsys ARC
24304 @cindex Synopsys ARC
24305 @cindex ARC specific commands
24306 @cindex ARC600
24307 @cindex ARC700
24308 @cindex ARC EM
24309 @cindex ARC HS
24310
24311 @value{GDBN} provides the following ARC-specific commands:
24312
24313 @table @code
24314 @item set debug arc
24315 @kindex set debug arc
24316 Control the level of ARC specific debug messages. Use 0 for no messages (the
24317 default), 1 for debug messages, and 2 for even more debug messages.
24318
24319 @item show debug arc
24320 @kindex show debug arc
24321 Show the level of ARC specific debugging in operation.
24322
24323 @item maint print arc arc-instruction @var{address}
24324 @kindex maint print arc arc-instruction
24325 Print internal disassembler information about instruction at a given address.
24326
24327 @end table
24328
24329 @node ARM
24330 @subsection ARM
24331
24332 @value{GDBN} provides the following ARM-specific commands:
24333
24334 @table @code
24335 @item set arm disassembler
24336 @kindex set arm
24337 This commands selects from a list of disassembly styles. The
24338 @code{"std"} style is the standard style.
24339
24340 @item show arm disassembler
24341 @kindex show arm
24342 Show the current disassembly style.
24343
24344 @item set arm apcs32
24345 @cindex ARM 32-bit mode
24346 This command toggles ARM operation mode between 32-bit and 26-bit.
24347
24348 @item show arm apcs32
24349 Display the current usage of the ARM 32-bit mode.
24350
24351 @item set arm fpu @var{fputype}
24352 This command sets the ARM floating-point unit (FPU) type. The
24353 argument @var{fputype} can be one of these:
24354
24355 @table @code
24356 @item auto
24357 Determine the FPU type by querying the OS ABI.
24358 @item softfpa
24359 Software FPU, with mixed-endian doubles on little-endian ARM
24360 processors.
24361 @item fpa
24362 GCC-compiled FPA co-processor.
24363 @item softvfp
24364 Software FPU with pure-endian doubles.
24365 @item vfp
24366 VFP co-processor.
24367 @end table
24368
24369 @item show arm fpu
24370 Show the current type of the FPU.
24371
24372 @item set arm abi
24373 This command forces @value{GDBN} to use the specified ABI.
24374
24375 @item show arm abi
24376 Show the currently used ABI.
24377
24378 @item set arm fallback-mode (arm|thumb|auto)
24379 @value{GDBN} uses the symbol table, when available, to determine
24380 whether instructions are ARM or Thumb. This command controls
24381 @value{GDBN}'s default behavior when the symbol table is not
24382 available. The default is @samp{auto}, which causes @value{GDBN} to
24383 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24384 register).
24385
24386 @item show arm fallback-mode
24387 Show the current fallback instruction mode.
24388
24389 @item set arm force-mode (arm|thumb|auto)
24390 This command overrides use of the symbol table to determine whether
24391 instructions are ARM or Thumb. The default is @samp{auto}, which
24392 causes @value{GDBN} to use the symbol table and then the setting
24393 of @samp{set arm fallback-mode}.
24394
24395 @item show arm force-mode
24396 Show the current forced instruction mode.
24397
24398 @item set debug arm
24399 Toggle whether to display ARM-specific debugging messages from the ARM
24400 target support subsystem.
24401
24402 @item show debug arm
24403 Show whether ARM-specific debugging messages are enabled.
24404 @end table
24405
24406 @table @code
24407 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24408 The @value{GDBN} ARM simulator accepts the following optional arguments.
24409
24410 @table @code
24411 @item --swi-support=@var{type}
24412 Tell the simulator which SWI interfaces to support. The argument
24413 @var{type} may be a comma separated list of the following values.
24414 The default value is @code{all}.
24415
24416 @table @code
24417 @item none
24418 @item demon
24419 @item angel
24420 @item redboot
24421 @item all
24422 @end table
24423 @end table
24424 @end table
24425
24426 @node M68K
24427 @subsection M68k
24428
24429 The Motorola m68k configuration includes ColdFire support.
24430
24431 @node MicroBlaze
24432 @subsection MicroBlaze
24433 @cindex Xilinx MicroBlaze
24434 @cindex XMD, Xilinx Microprocessor Debugger
24435
24436 The MicroBlaze is a soft-core processor supported on various Xilinx
24437 FPGAs, such as Spartan or Virtex series. Boards with these processors
24438 usually have JTAG ports which connect to a host system running the Xilinx
24439 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24440 This host system is used to download the configuration bitstream to
24441 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24442 communicates with the target board using the JTAG interface and
24443 presents a @code{gdbserver} interface to the board. By default
24444 @code{xmd} uses port @code{1234}. (While it is possible to change
24445 this default port, it requires the use of undocumented @code{xmd}
24446 commands. Contact Xilinx support if you need to do this.)
24447
24448 Use these GDB commands to connect to the MicroBlaze target processor.
24449
24450 @table @code
24451 @item target remote :1234
24452 Use this command to connect to the target if you are running @value{GDBN}
24453 on the same system as @code{xmd}.
24454
24455 @item target remote @var{xmd-host}:1234
24456 Use this command to connect to the target if it is connected to @code{xmd}
24457 running on a different system named @var{xmd-host}.
24458
24459 @item load
24460 Use this command to download a program to the MicroBlaze target.
24461
24462 @item set debug microblaze @var{n}
24463 Enable MicroBlaze-specific debugging messages if non-zero.
24464
24465 @item show debug microblaze @var{n}
24466 Show MicroBlaze-specific debugging level.
24467 @end table
24468
24469 @node MIPS Embedded
24470 @subsection @acronym{MIPS} Embedded
24471
24472 @noindent
24473 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24474
24475 @table @code
24476 @item set mipsfpu double
24477 @itemx set mipsfpu single
24478 @itemx set mipsfpu none
24479 @itemx set mipsfpu auto
24480 @itemx show mipsfpu
24481 @kindex set mipsfpu
24482 @kindex show mipsfpu
24483 @cindex @acronym{MIPS} remote floating point
24484 @cindex floating point, @acronym{MIPS} remote
24485 If your target board does not support the @acronym{MIPS} floating point
24486 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24487 need this, you may wish to put the command in your @value{GDBN} init
24488 file). This tells @value{GDBN} how to find the return value of
24489 functions which return floating point values. It also allows
24490 @value{GDBN} to avoid saving the floating point registers when calling
24491 functions on the board. If you are using a floating point coprocessor
24492 with only single precision floating point support, as on the @sc{r4650}
24493 processor, use the command @samp{set mipsfpu single}. The default
24494 double precision floating point coprocessor may be selected using
24495 @samp{set mipsfpu double}.
24496
24497 In previous versions the only choices were double precision or no
24498 floating point, so @samp{set mipsfpu on} will select double precision
24499 and @samp{set mipsfpu off} will select no floating point.
24500
24501 As usual, you can inquire about the @code{mipsfpu} variable with
24502 @samp{show mipsfpu}.
24503 @end table
24504
24505 @node OpenRISC 1000
24506 @subsection OpenRISC 1000
24507 @cindex OpenRISC 1000
24508
24509 @noindent
24510 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24511 mainly provided as a soft-core which can run on Xilinx, Altera and other
24512 FPGA's.
24513
24514 @value{GDBN} for OpenRISC supports the below commands when connecting to
24515 a target:
24516
24517 @table @code
24518
24519 @kindex target sim
24520 @item target sim
24521
24522 Runs the builtin CPU simulator which can run very basic
24523 programs but does not support most hardware functions like MMU.
24524 For more complex use cases the user is advised to run an external
24525 target, and connect using @samp{target remote}.
24526
24527 Example: @code{target sim}
24528
24529 @item set debug or1k
24530 Toggle whether to display OpenRISC-specific debugging messages from the
24531 OpenRISC target support subsystem.
24532
24533 @item show debug or1k
24534 Show whether OpenRISC-specific debugging messages are enabled.
24535 @end table
24536
24537 @node PowerPC Embedded
24538 @subsection PowerPC Embedded
24539
24540 @cindex DVC register
24541 @value{GDBN} supports using the DVC (Data Value Compare) register to
24542 implement in hardware simple hardware watchpoint conditions of the form:
24543
24544 @smallexample
24545 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24546 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24547 @end smallexample
24548
24549 The DVC register will be automatically used when @value{GDBN} detects
24550 such pattern in a condition expression, and the created watchpoint uses one
24551 debug register (either the @code{exact-watchpoints} option is on and the
24552 variable is scalar, or the variable has a length of one byte). This feature
24553 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24554 or newer.
24555
24556 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24557 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24558 in which case watchpoints using only one debug register are created when
24559 watching variables of scalar types.
24560
24561 You can create an artificial array to watch an arbitrary memory
24562 region using one of the following commands (@pxref{Expressions}):
24563
24564 @smallexample
24565 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24566 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24567 @end smallexample
24568
24569 PowerPC embedded processors support masked watchpoints. See the discussion
24570 about the @code{mask} argument in @ref{Set Watchpoints}.
24571
24572 @cindex ranged breakpoint
24573 PowerPC embedded processors support hardware accelerated
24574 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24575 the inferior whenever it executes an instruction at any address within
24576 the range it specifies. To set a ranged breakpoint in @value{GDBN},
24577 use the @code{break-range} command.
24578
24579 @value{GDBN} provides the following PowerPC-specific commands:
24580
24581 @table @code
24582 @kindex break-range
24583 @item break-range @var{start-location}, @var{end-location}
24584 Set a breakpoint for an address range given by
24585 @var{start-location} and @var{end-location}, which can specify a function name,
24586 a line number, an offset of lines from the current line or from the start
24587 location, or an address of an instruction (see @ref{Specify Location},
24588 for a list of all the possible ways to specify a @var{location}.)
24589 The breakpoint will stop execution of the inferior whenever it
24590 executes an instruction at any address within the specified range,
24591 (including @var{start-location} and @var{end-location}.)
24592
24593 @kindex set powerpc
24594 @item set powerpc soft-float
24595 @itemx show powerpc soft-float
24596 Force @value{GDBN} to use (or not use) a software floating point calling
24597 convention. By default, @value{GDBN} selects the calling convention based
24598 on the selected architecture and the provided executable file.
24599
24600 @item set powerpc vector-abi
24601 @itemx show powerpc vector-abi
24602 Force @value{GDBN} to use the specified calling convention for vector
24603 arguments and return values. The valid options are @samp{auto};
24604 @samp{generic}, to avoid vector registers even if they are present;
24605 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24606 registers. By default, @value{GDBN} selects the calling convention
24607 based on the selected architecture and the provided executable file.
24608
24609 @item set powerpc exact-watchpoints
24610 @itemx show powerpc exact-watchpoints
24611 Allow @value{GDBN} to use only one debug register when watching a variable
24612 of scalar type, thus assuming that the variable is accessed through the
24613 address of its first byte.
24614
24615 @end table
24616
24617 @node AVR
24618 @subsection Atmel AVR
24619 @cindex AVR
24620
24621 When configured for debugging the Atmel AVR, @value{GDBN} supports the
24622 following AVR-specific commands:
24623
24624 @table @code
24625 @item info io_registers
24626 @kindex info io_registers@r{, AVR}
24627 @cindex I/O registers (Atmel AVR)
24628 This command displays information about the AVR I/O registers. For
24629 each register, @value{GDBN} prints its number and value.
24630 @end table
24631
24632 @node CRIS
24633 @subsection CRIS
24634 @cindex CRIS
24635
24636 When configured for debugging CRIS, @value{GDBN} provides the
24637 following CRIS-specific commands:
24638
24639 @table @code
24640 @item set cris-version @var{ver}
24641 @cindex CRIS version
24642 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24643 The CRIS version affects register names and sizes. This command is useful in
24644 case autodetection of the CRIS version fails.
24645
24646 @item show cris-version
24647 Show the current CRIS version.
24648
24649 @item set cris-dwarf2-cfi
24650 @cindex DWARF-2 CFI and CRIS
24651 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24652 Change to @samp{off} when using @code{gcc-cris} whose version is below
24653 @code{R59}.
24654
24655 @item show cris-dwarf2-cfi
24656 Show the current state of using DWARF-2 CFI.
24657
24658 @item set cris-mode @var{mode}
24659 @cindex CRIS mode
24660 Set the current CRIS mode to @var{mode}. It should only be changed when
24661 debugging in guru mode, in which case it should be set to
24662 @samp{guru} (the default is @samp{normal}).
24663
24664 @item show cris-mode
24665 Show the current CRIS mode.
24666 @end table
24667
24668 @node Super-H
24669 @subsection Renesas Super-H
24670 @cindex Super-H
24671
24672 For the Renesas Super-H processor, @value{GDBN} provides these
24673 commands:
24674
24675 @table @code
24676 @item set sh calling-convention @var{convention}
24677 @kindex set sh calling-convention
24678 Set the calling-convention used when calling functions from @value{GDBN}.
24679 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24680 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24681 convention. If the DWARF-2 information of the called function specifies
24682 that the function follows the Renesas calling convention, the function
24683 is called using the Renesas calling convention. If the calling convention
24684 is set to @samp{renesas}, the Renesas calling convention is always used,
24685 regardless of the DWARF-2 information. This can be used to override the
24686 default of @samp{gcc} if debug information is missing, or the compiler
24687 does not emit the DWARF-2 calling convention entry for a function.
24688
24689 @item show sh calling-convention
24690 @kindex show sh calling-convention
24691 Show the current calling convention setting.
24692
24693 @end table
24694
24695
24696 @node Architectures
24697 @section Architectures
24698
24699 This section describes characteristics of architectures that affect
24700 all uses of @value{GDBN} with the architecture, both native and cross.
24701
24702 @menu
24703 * AArch64::
24704 * i386::
24705 * Alpha::
24706 * MIPS::
24707 * HPPA:: HP PA architecture
24708 * PowerPC::
24709 * Nios II::
24710 * Sparc64::
24711 * S12Z::
24712 @end menu
24713
24714 @node AArch64
24715 @subsection AArch64
24716 @cindex AArch64 support
24717
24718 When @value{GDBN} is debugging the AArch64 architecture, it provides the
24719 following special commands:
24720
24721 @table @code
24722 @item set debug aarch64
24723 @kindex set debug aarch64
24724 This command determines whether AArch64 architecture-specific debugging
24725 messages are to be displayed.
24726
24727 @item show debug aarch64
24728 Show whether AArch64 debugging messages are displayed.
24729
24730 @end table
24731
24732 @subsubsection AArch64 SVE.
24733 @cindex AArch64 SVE.
24734
24735 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24736 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24737 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24738 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24739 @code{$vg} will be provided. This is the vector granule for the current thread
24740 and represents the number of 64-bit chunks in an SVE @code{z} register.
24741
24742 If the vector length changes, then the @code{$vg} register will be updated,
24743 but the lengths of the @code{z} and @code{p} registers will not change. This
24744 is a known limitation of @value{GDBN} and does not affect the execution of the
24745 target process.
24746
24747 @subsubsection AArch64 Pointer Authentication.
24748 @cindex AArch64 Pointer Authentication.
24749
24750 When @value{GDBN} is debugging the AArch64 architecture, and the program is
24751 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
24752 register @code{$lr} is pointing to an PAC function its value will be masked.
24753 When GDB prints a backtrace, any addresses that required unmasking will be
24754 postfixed with the marker [PAC]. When using the MI, this is printed as part
24755 of the @code{addr_flags} field.
24756
24757 @node i386
24758 @subsection x86 Architecture-specific Issues
24759
24760 @table @code
24761 @item set struct-convention @var{mode}
24762 @kindex set struct-convention
24763 @cindex struct return convention
24764 @cindex struct/union returned in registers
24765 Set the convention used by the inferior to return @code{struct}s and
24766 @code{union}s from functions to @var{mode}. Possible values of
24767 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24768 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24769 are returned on the stack, while @code{"reg"} means that a
24770 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24771 be returned in a register.
24772
24773 @item show struct-convention
24774 @kindex show struct-convention
24775 Show the current setting of the convention to return @code{struct}s
24776 from functions.
24777 @end table
24778
24779
24780 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24781 @cindex Intel Memory Protection Extensions (MPX).
24782
24783 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24784 @footnote{The register named with capital letters represent the architecture
24785 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24786 which are the lower bound and upper bound. Bounds are effective addresses or
24787 memory locations. The upper bounds are architecturally represented in 1's
24788 complement form. A bound having lower bound = 0, and upper bound = 0
24789 (1's complement of all bits set) will allow access to the entire address space.
24790
24791 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24792 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24793 display the upper bound performing the complement of one operation on the
24794 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24795 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24796 can also be noted that the upper bounds are inclusive.
24797
24798 As an example, assume that the register BND0 holds bounds for a pointer having
24799 access allowed for the range between 0x32 and 0x71. The values present on
24800 bnd0raw and bnd registers are presented as follows:
24801
24802 @smallexample
24803 bnd0raw = @{0x32, 0xffffffff8e@}
24804 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24805 @end smallexample
24806
24807 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24808 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24809 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24810 Python, the display includes the memory size, in bits, accessible to
24811 the pointer.
24812
24813 Bounds can also be stored in bounds tables, which are stored in
24814 application memory. These tables store bounds for pointers by specifying
24815 the bounds pointer's value along with its bounds. Evaluating and changing
24816 bounds located in bound tables is therefore interesting while investigating
24817 bugs on MPX context. @value{GDBN} provides commands for this purpose:
24818
24819 @table @code
24820 @item show mpx bound @var{pointer}
24821 @kindex show mpx bound
24822 Display bounds of the given @var{pointer}.
24823
24824 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24825 @kindex set mpx bound
24826 Set the bounds of a pointer in the bound table.
24827 This command takes three parameters: @var{pointer} is the pointers
24828 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24829 for lower and upper bounds respectively.
24830 @end table
24831
24832 When you call an inferior function on an Intel MPX enabled program,
24833 GDB sets the inferior's bound registers to the init (disabled) state
24834 before calling the function. As a consequence, bounds checks for the
24835 pointer arguments passed to the function will always pass.
24836
24837 This is necessary because when you call an inferior function, the
24838 program is usually in the middle of the execution of other function.
24839 Since at that point bound registers are in an arbitrary state, not
24840 clearing them would lead to random bound violations in the called
24841 function.
24842
24843 You can still examine the influence of the bound registers on the
24844 execution of the called function by stopping the execution of the
24845 called function at its prologue, setting bound registers, and
24846 continuing the execution. For example:
24847
24848 @smallexample
24849 $ break *upper
24850 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24851 $ print upper (a, b, c, d, 1)
24852 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24853 $ print $bnd0
24854 @{lbound = 0x0, ubound = ffffffff@} : size -1
24855 @end smallexample
24856
24857 At this last step the value of bnd0 can be changed for investigation of bound
24858 violations caused along the execution of the call. In order to know how to
24859 set the bound registers or bound table for the call consult the ABI.
24860
24861 @node Alpha
24862 @subsection Alpha
24863
24864 See the following section.
24865
24866 @node MIPS
24867 @subsection @acronym{MIPS}
24868
24869 @cindex stack on Alpha
24870 @cindex stack on @acronym{MIPS}
24871 @cindex Alpha stack
24872 @cindex @acronym{MIPS} stack
24873 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
24874 sometimes requires @value{GDBN} to search backward in the object code to
24875 find the beginning of a function.
24876
24877 @cindex response time, @acronym{MIPS} debugging
24878 To improve response time (especially for embedded applications, where
24879 @value{GDBN} may be restricted to a slow serial line for this search)
24880 you may want to limit the size of this search, using one of these
24881 commands:
24882
24883 @table @code
24884 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
24885 @item set heuristic-fence-post @var{limit}
24886 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24887 search for the beginning of a function. A value of @var{0} (the
24888 default) means there is no limit. However, except for @var{0}, the
24889 larger the limit the more bytes @code{heuristic-fence-post} must search
24890 and therefore the longer it takes to run. You should only need to use
24891 this command when debugging a stripped executable.
24892
24893 @item show heuristic-fence-post
24894 Display the current limit.
24895 @end table
24896
24897 @noindent
24898 These commands are available @emph{only} when @value{GDBN} is configured
24899 for debugging programs on Alpha or @acronym{MIPS} processors.
24900
24901 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
24902 programs:
24903
24904 @table @code
24905 @item set mips abi @var{arg}
24906 @kindex set mips abi
24907 @cindex set ABI for @acronym{MIPS}
24908 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
24909 values of @var{arg} are:
24910
24911 @table @samp
24912 @item auto
24913 The default ABI associated with the current binary (this is the
24914 default).
24915 @item o32
24916 @item o64
24917 @item n32
24918 @item n64
24919 @item eabi32
24920 @item eabi64
24921 @end table
24922
24923 @item show mips abi
24924 @kindex show mips abi
24925 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
24926
24927 @item set mips compression @var{arg}
24928 @kindex set mips compression
24929 @cindex code compression, @acronym{MIPS}
24930 Tell @value{GDBN} which @acronym{MIPS} compressed
24931 @acronym{ISA, Instruction Set Architecture} encoding is used by the
24932 inferior. @value{GDBN} uses this for code disassembly and other
24933 internal interpretation purposes. This setting is only referred to
24934 when no executable has been associated with the debugging session or
24935 the executable does not provide information about the encoding it uses.
24936 Otherwise this setting is automatically updated from information
24937 provided by the executable.
24938
24939 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
24940 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
24941 executables containing @acronym{MIPS16} code frequently are not
24942 identified as such.
24943
24944 This setting is ``sticky''; that is, it retains its value across
24945 debugging sessions until reset either explicitly with this command or
24946 implicitly from an executable.
24947
24948 The compiler and/or assembler typically add symbol table annotations to
24949 identify functions compiled for the @acronym{MIPS16} or
24950 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
24951 are present, @value{GDBN} uses them in preference to the global
24952 compressed @acronym{ISA} encoding setting.
24953
24954 @item show mips compression
24955 @kindex show mips compression
24956 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
24957 @value{GDBN} to debug the inferior.
24958
24959 @item set mipsfpu
24960 @itemx show mipsfpu
24961 @xref{MIPS Embedded, set mipsfpu}.
24962
24963 @item set mips mask-address @var{arg}
24964 @kindex set mips mask-address
24965 @cindex @acronym{MIPS} addresses, masking
24966 This command determines whether the most-significant 32 bits of 64-bit
24967 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
24968 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
24969 setting, which lets @value{GDBN} determine the correct value.
24970
24971 @item show mips mask-address
24972 @kindex show mips mask-address
24973 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
24974 not.
24975
24976 @item set remote-mips64-transfers-32bit-regs
24977 @kindex set remote-mips64-transfers-32bit-regs
24978 This command controls compatibility with 64-bit @acronym{MIPS} targets that
24979 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
24980 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
24981 and 64 bits for other registers, set this option to @samp{on}.
24982
24983 @item show remote-mips64-transfers-32bit-regs
24984 @kindex show remote-mips64-transfers-32bit-regs
24985 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
24986
24987 @item set debug mips
24988 @kindex set debug mips
24989 This command turns on and off debugging messages for the @acronym{MIPS}-specific
24990 target code in @value{GDBN}.
24991
24992 @item show debug mips
24993 @kindex show debug mips
24994 Show the current setting of @acronym{MIPS} debugging messages.
24995 @end table
24996
24997
24998 @node HPPA
24999 @subsection HPPA
25000 @cindex HPPA support
25001
25002 When @value{GDBN} is debugging the HP PA architecture, it provides the
25003 following special commands:
25004
25005 @table @code
25006 @item set debug hppa
25007 @kindex set debug hppa
25008 This command determines whether HPPA architecture-specific debugging
25009 messages are to be displayed.
25010
25011 @item show debug hppa
25012 Show whether HPPA debugging messages are displayed.
25013
25014 @item maint print unwind @var{address}
25015 @kindex maint print unwind@r{, HPPA}
25016 This command displays the contents of the unwind table entry at the
25017 given @var{address}.
25018
25019 @end table
25020
25021
25022 @node PowerPC
25023 @subsection PowerPC
25024 @cindex PowerPC architecture
25025
25026 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25027 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25028 numbers stored in the floating point registers. These values must be stored
25029 in two consecutive registers, always starting at an even register like
25030 @code{f0} or @code{f2}.
25031
25032 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25033 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25034 @code{f2} and @code{f3} for @code{$dl1} and so on.
25035
25036 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25037 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25038
25039 @node Nios II
25040 @subsection Nios II
25041 @cindex Nios II architecture
25042
25043 When @value{GDBN} is debugging the Nios II architecture,
25044 it provides the following special commands:
25045
25046 @table @code
25047
25048 @item set debug nios2
25049 @kindex set debug nios2
25050 This command turns on and off debugging messages for the Nios II
25051 target code in @value{GDBN}.
25052
25053 @item show debug nios2
25054 @kindex show debug nios2
25055 Show the current setting of Nios II debugging messages.
25056 @end table
25057
25058 @node Sparc64
25059 @subsection Sparc64
25060 @cindex Sparc64 support
25061 @cindex Application Data Integrity
25062 @subsubsection ADI Support
25063
25064 The M7 processor supports an Application Data Integrity (ADI) feature that
25065 detects invalid data accesses. When software allocates memory and enables
25066 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25067 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25068 the 4-bit version in every cacheline of that data. Hardware saves the latter
25069 in spare bits in the cache and memory hierarchy. On each load and store,
25070 the processor compares the upper 4 VA (virtual address) bits to the
25071 cacheline's version. If there is a mismatch, the processor generates a
25072 version mismatch trap which can be either precise or disrupting. The trap
25073 is an error condition which the kernel delivers to the process as a SIGSEGV
25074 signal.
25075
25076 Note that only 64-bit applications can use ADI and need to be built with
25077 ADI-enabled.
25078
25079 Values of the ADI version tags, which are in granularity of a
25080 cacheline (64 bytes), can be viewed or modified.
25081
25082
25083 @table @code
25084 @kindex adi examine
25085 @item adi (examine | x) [ / @var{n} ] @var{addr}
25086
25087 The @code{adi examine} command displays the value of one ADI version tag per
25088 cacheline.
25089
25090 @var{n} is a decimal integer specifying the number in bytes; the default
25091 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25092 block size, to display.
25093
25094 @var{addr} is the address in user address space where you want @value{GDBN}
25095 to begin displaying the ADI version tags.
25096
25097 Below is an example of displaying ADI versions of variable "shmaddr".
25098
25099 @smallexample
25100 (@value{GDBP}) adi x/100 shmaddr
25101 0xfff800010002c000: 0 0
25102 @end smallexample
25103
25104 @kindex adi assign
25105 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25106
25107 The @code{adi assign} command is used to assign new ADI version tag
25108 to an address.
25109
25110 @var{n} is a decimal integer specifying the number in bytes;
25111 the default is 1. It specifies how much ADI version information, at the
25112 ratio of 1:ADI block size, to modify.
25113
25114 @var{addr} is the address in user address space where you want @value{GDBN}
25115 to begin modifying the ADI version tags.
25116
25117 @var{tag} is the new ADI version tag.
25118
25119 For example, do the following to modify then verify ADI versions of
25120 variable "shmaddr":
25121
25122 @smallexample
25123 (@value{GDBP}) adi a/100 shmaddr = 7
25124 (@value{GDBP}) adi x/100 shmaddr
25125 0xfff800010002c000: 7 7
25126 @end smallexample
25127
25128 @end table
25129
25130 @node S12Z
25131 @subsection S12Z
25132 @cindex S12Z support
25133
25134 When @value{GDBN} is debugging the S12Z architecture,
25135 it provides the following special command:
25136
25137 @table @code
25138 @item maint info bdccsr
25139 @kindex maint info bdccsr@r{, S12Z}
25140 This command displays the current value of the microprocessor's
25141 BDCCSR register.
25142 @end table
25143
25144
25145 @node Controlling GDB
25146 @chapter Controlling @value{GDBN}
25147
25148 You can alter the way @value{GDBN} interacts with you by using the
25149 @code{set} command. For commands controlling how @value{GDBN} displays
25150 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25151 described here.
25152
25153 @menu
25154 * Prompt:: Prompt
25155 * Editing:: Command editing
25156 * Command History:: Command history
25157 * Screen Size:: Screen size
25158 * Output Styling:: Output styling
25159 * Numbers:: Numbers
25160 * ABI:: Configuring the current ABI
25161 * Auto-loading:: Automatically loading associated files
25162 * Messages/Warnings:: Optional warnings and messages
25163 * Debugging Output:: Optional messages about internal happenings
25164 * Other Misc Settings:: Other Miscellaneous Settings
25165 @end menu
25166
25167 @node Prompt
25168 @section Prompt
25169
25170 @cindex prompt
25171
25172 @value{GDBN} indicates its readiness to read a command by printing a string
25173 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25174 can change the prompt string with the @code{set prompt} command. For
25175 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25176 the prompt in one of the @value{GDBN} sessions so that you can always tell
25177 which one you are talking to.
25178
25179 @emph{Note:} @code{set prompt} does not add a space for you after the
25180 prompt you set. This allows you to set a prompt which ends in a space
25181 or a prompt that does not.
25182
25183 @table @code
25184 @kindex set prompt
25185 @item set prompt @var{newprompt}
25186 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25187
25188 @kindex show prompt
25189 @item show prompt
25190 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25191 @end table
25192
25193 Versions of @value{GDBN} that ship with Python scripting enabled have
25194 prompt extensions. The commands for interacting with these extensions
25195 are:
25196
25197 @table @code
25198 @kindex set extended-prompt
25199 @item set extended-prompt @var{prompt}
25200 Set an extended prompt that allows for substitutions.
25201 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25202 substitution. Any escape sequences specified as part of the prompt
25203 string are replaced with the corresponding strings each time the prompt
25204 is displayed.
25205
25206 For example:
25207
25208 @smallexample
25209 set extended-prompt Current working directory: \w (gdb)
25210 @end smallexample
25211
25212 Note that when an extended-prompt is set, it takes control of the
25213 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25214
25215 @kindex show extended-prompt
25216 @item show extended-prompt
25217 Prints the extended prompt. Any escape sequences specified as part of
25218 the prompt string with @code{set extended-prompt}, are replaced with the
25219 corresponding strings each time the prompt is displayed.
25220 @end table
25221
25222 @node Editing
25223 @section Command Editing
25224 @cindex readline
25225 @cindex command line editing
25226
25227 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25228 @sc{gnu} library provides consistent behavior for programs which provide a
25229 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25230 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25231 substitution, and a storage and recall of command history across
25232 debugging sessions.
25233
25234 You may control the behavior of command line editing in @value{GDBN} with the
25235 command @code{set}.
25236
25237 @table @code
25238 @kindex set editing
25239 @cindex editing
25240 @item set editing
25241 @itemx set editing on
25242 Enable command line editing (enabled by default).
25243
25244 @item set editing off
25245 Disable command line editing.
25246
25247 @kindex show editing
25248 @item show editing
25249 Show whether command line editing is enabled.
25250 @end table
25251
25252 @ifset SYSTEM_READLINE
25253 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25254 @end ifset
25255 @ifclear SYSTEM_READLINE
25256 @xref{Command Line Editing},
25257 @end ifclear
25258 for more details about the Readline
25259 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25260 encouraged to read that chapter.
25261
25262 @cindex Readline application name
25263 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25264 is useful for conditions in @file{.inputrc}.
25265
25266 @cindex operate-and-get-next
25267 @value{GDBN} defines a bindable Readline command,
25268 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25269 This command accepts the current line for execution and fetches the
25270 next line relative to the current line from the history for editing.
25271 Any argument is ignored.
25272
25273 @node Command History
25274 @section Command History
25275 @cindex command history
25276
25277 @value{GDBN} can keep track of the commands you type during your
25278 debugging sessions, so that you can be certain of precisely what
25279 happened. Use these commands to manage the @value{GDBN} command
25280 history facility.
25281
25282 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25283 package, to provide the history facility.
25284 @ifset SYSTEM_READLINE
25285 @xref{Using History Interactively, , , history, GNU History Library},
25286 @end ifset
25287 @ifclear SYSTEM_READLINE
25288 @xref{Using History Interactively},
25289 @end ifclear
25290 for the detailed description of the History library.
25291
25292 To issue a command to @value{GDBN} without affecting certain aspects of
25293 the state which is seen by users, prefix it with @samp{server }
25294 (@pxref{Server Prefix}). This
25295 means that this command will not affect the command history, nor will it
25296 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25297 pressed on a line by itself.
25298
25299 @cindex @code{server}, command prefix
25300 The server prefix does not affect the recording of values into the value
25301 history; to print a value without recording it into the value history,
25302 use the @code{output} command instead of the @code{print} command.
25303
25304 Here is the description of @value{GDBN} commands related to command
25305 history.
25306
25307 @table @code
25308 @cindex history substitution
25309 @cindex history file
25310 @kindex set history filename
25311 @cindex @env{GDBHISTFILE}, environment variable
25312 @item set history filename @r{[}@var{fname}@r{]}
25313 Set the name of the @value{GDBN} command history file to @var{fname}.
25314 This is the file where @value{GDBN} reads an initial command history
25315 list, and where it writes the command history from this session when it
25316 exits. You can access this list through history expansion or through
25317 the history command editing characters listed below. This file defaults
25318 to the value of the environment variable @code{GDBHISTFILE}, or to
25319 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25320 is not set.
25321
25322 The @code{GDBHISTFILE} environment variable is read after processing
25323 any @value{GDBN} initialization files (@pxref{Startup}) and after
25324 processing any commands passed using command line options (for
25325 example, @code{-ex}).
25326
25327 If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25328 is the empty string then @value{GDBN} will neither try to load an
25329 existing history file, nor will it try to save the history on exit.
25330
25331 @cindex save command history
25332 @kindex set history save
25333 @item set history save
25334 @itemx set history save on
25335 Record command history in a file, whose name may be specified with the
25336 @code{set history filename} command. By default, this option is
25337 disabled. The command history will be recorded when @value{GDBN}
25338 exits. If @code{set history filename} is set to the empty string then
25339 history saving is disabled, even when @code{set history save} is
25340 @code{on}.
25341
25342 @item set history save off
25343 Don't record the command history into the file specified by @code{set
25344 history filename} when @value{GDBN} exits.
25345
25346 @cindex history size
25347 @kindex set history size
25348 @cindex @env{GDBHISTSIZE}, environment variable
25349 @item set history size @var{size}
25350 @itemx set history size unlimited
25351 Set the number of commands which @value{GDBN} keeps in its history list.
25352 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25353 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25354 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25355 either a negative number or the empty string, then the number of commands
25356 @value{GDBN} keeps in the history list is unlimited.
25357
25358 The @code{GDBHISTSIZE} environment variable is read after processing
25359 any @value{GDBN} initialization files (@pxref{Startup}) and after
25360 processing any commands passed using command line options (for
25361 example, @code{-ex}).
25362
25363 @cindex remove duplicate history
25364 @kindex set history remove-duplicates
25365 @item set history remove-duplicates @var{count}
25366 @itemx set history remove-duplicates unlimited
25367 Control the removal of duplicate history entries in the command history list.
25368 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25369 history entries and remove the first entry that is a duplicate of the current
25370 entry being added to the command history list. If @var{count} is
25371 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25372 removal of duplicate history entries is disabled.
25373
25374 Only history entries added during the current session are considered for
25375 removal. This option is set to 0 by default.
25376
25377 @end table
25378
25379 History expansion assigns special meaning to the character @kbd{!}.
25380 @ifset SYSTEM_READLINE
25381 @xref{Event Designators, , , history, GNU History Library},
25382 @end ifset
25383 @ifclear SYSTEM_READLINE
25384 @xref{Event Designators},
25385 @end ifclear
25386 for more details.
25387
25388 @cindex history expansion, turn on/off
25389 Since @kbd{!} is also the logical not operator in C, history expansion
25390 is off by default. If you decide to enable history expansion with the
25391 @code{set history expansion on} command, you may sometimes need to
25392 follow @kbd{!} (when it is used as logical not, in an expression) with
25393 a space or a tab to prevent it from being expanded. The readline
25394 history facilities do not attempt substitution on the strings
25395 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25396
25397 The commands to control history expansion are:
25398
25399 @table @code
25400 @item set history expansion on
25401 @itemx set history expansion
25402 @kindex set history expansion
25403 Enable history expansion. History expansion is off by default.
25404
25405 @item set history expansion off
25406 Disable history expansion.
25407
25408 @c @group
25409 @kindex show history
25410 @item show history
25411 @itemx show history filename
25412 @itemx show history save
25413 @itemx show history size
25414 @itemx show history expansion
25415 These commands display the state of the @value{GDBN} history parameters.
25416 @code{show history} by itself displays all four states.
25417 @c @end group
25418 @end table
25419
25420 @table @code
25421 @kindex show commands
25422 @cindex show last commands
25423 @cindex display command history
25424 @item show commands
25425 Display the last ten commands in the command history.
25426
25427 @item show commands @var{n}
25428 Print ten commands centered on command number @var{n}.
25429
25430 @item show commands +
25431 Print ten commands just after the commands last printed.
25432 @end table
25433
25434 @node Screen Size
25435 @section Screen Size
25436 @cindex size of screen
25437 @cindex screen size
25438 @cindex pagination
25439 @cindex page size
25440 @cindex pauses in output
25441
25442 Certain commands to @value{GDBN} may produce large amounts of
25443 information output to the screen. To help you read all of it,
25444 @value{GDBN} pauses and asks you for input at the end of each page of
25445 output. Type @key{RET} when you want to see one more page of output,
25446 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25447 without paging for the rest of the current command. Also, the screen
25448 width setting determines when to wrap lines of output. Depending on
25449 what is being printed, @value{GDBN} tries to break the line at a
25450 readable place, rather than simply letting it overflow onto the
25451 following line.
25452
25453 Normally @value{GDBN} knows the size of the screen from the terminal
25454 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25455 together with the value of the @code{TERM} environment variable and the
25456 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25457 you can override it with the @code{set height} and @code{set
25458 width} commands:
25459
25460 @table @code
25461 @kindex set height
25462 @kindex set width
25463 @kindex show width
25464 @kindex show height
25465 @item set height @var{lpp}
25466 @itemx set height unlimited
25467 @itemx show height
25468 @itemx set width @var{cpl}
25469 @itemx set width unlimited
25470 @itemx show width
25471 These @code{set} commands specify a screen height of @var{lpp} lines and
25472 a screen width of @var{cpl} characters. The associated @code{show}
25473 commands display the current settings.
25474
25475 If you specify a height of either @code{unlimited} or zero lines,
25476 @value{GDBN} does not pause during output no matter how long the
25477 output is. This is useful if output is to a file or to an editor
25478 buffer.
25479
25480 Likewise, you can specify @samp{set width unlimited} or @samp{set
25481 width 0} to prevent @value{GDBN} from wrapping its output.
25482
25483 @item set pagination on
25484 @itemx set pagination off
25485 @kindex set pagination
25486 Turn the output pagination on or off; the default is on. Turning
25487 pagination off is the alternative to @code{set height unlimited}. Note that
25488 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25489 Options, -batch}) also automatically disables pagination.
25490
25491 @item show pagination
25492 @kindex show pagination
25493 Show the current pagination mode.
25494 @end table
25495
25496 @node Output Styling
25497 @section Output Styling
25498 @cindex styling
25499 @cindex colors
25500
25501 @kindex set style
25502 @kindex show style
25503 @value{GDBN} can style its output on a capable terminal. This is
25504 enabled by default on most systems, but disabled by default when in
25505 batch mode (@pxref{Mode Options}). Various style settings are available;
25506 and styles can also be disabled entirely.
25507
25508 @table @code
25509 @item set style enabled @samp{on|off}
25510 Enable or disable all styling. The default is host-dependent, with
25511 most hosts defaulting to @samp{on}.
25512
25513 @item show style enabled
25514 Show the current state of styling.
25515
25516 @item set style sources @samp{on|off}
25517 Enable or disable source code styling. This affects whether source
25518 code, such as the output of the @code{list} command, is styled. Note
25519 that source styling only works if styling in general is enabled, and
25520 if @value{GDBN} was linked with the GNU Source Highlight library. The
25521 default is @samp{on}.
25522
25523 @item show style sources
25524 Show the current state of source code styling.
25525 @end table
25526
25527 Subcommands of @code{set style} control specific forms of styling.
25528 These subcommands all follow the same pattern: each style-able object
25529 can be styled with a foreground color, a background color, and an
25530 intensity.
25531
25532 For example, the style of file names can be controlled using the
25533 @code{set style filename} group of commands:
25534
25535 @table @code
25536 @item set style filename background @var{color}
25537 Set the background to @var{color}. Valid colors are @samp{none}
25538 (meaning the terminal's default color), @samp{black}, @samp{red},
25539 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25540 and@samp{white}.
25541
25542 @item set style filename foreground @var{color}
25543 Set the foreground to @var{color}. Valid colors are @samp{none}
25544 (meaning the terminal's default color), @samp{black}, @samp{red},
25545 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25546 and@samp{white}.
25547
25548 @item set style filename intensity @var{value}
25549 Set the intensity to @var{value}. Valid intensities are @samp{normal}
25550 (the default), @samp{bold}, and @samp{dim}.
25551 @end table
25552
25553 The @code{show style} command and its subcommands are styling
25554 a style name in their output using its own style.
25555 So, use @command{show style} to see the complete list of styles,
25556 their characteristics and the visual aspect of each style.
25557
25558 The style-able objects are:
25559 @table @code
25560 @item filename
25561 Control the styling of file names. By default, this style's
25562 foreground color is green.
25563
25564 @item function
25565 Control the styling of function names. These are managed with the
25566 @code{set style function} family of commands. By default, this
25567 style's foreground color is yellow.
25568
25569 @item variable
25570 Control the styling of variable names. These are managed with the
25571 @code{set style variable} family of commands. By default, this style's
25572 foreground color is cyan.
25573
25574 @item address
25575 Control the styling of addresses. These are managed with the
25576 @code{set style address} family of commands. By default, this style's
25577 foreground color is blue.
25578
25579 @item title
25580 Control the styling of titles. These are managed with the
25581 @code{set style title} family of commands. By default, this style's
25582 intensity is bold. Commands are using the title style to improve
25583 the readability of large output. For example, the commands
25584 @command{apropos} and @command{help} are using the title style
25585 for the command names.
25586
25587 @item highlight
25588 Control the styling of highlightings. These are managed with the
25589 @code{set style highlight} family of commands. By default, this style's
25590 foreground color is red. Commands are using the highlight style to draw
25591 the user attention to some specific parts of their output. For example,
25592 the command @command{apropos -v REGEXP} uses the highlight style to
25593 mark the documentation parts matching @var{regexp}.
25594
25595 @item tui-border
25596 Control the styling of the TUI border. Note that, unlike other
25597 styling options, only the color of the border can be controlled via
25598 @code{set style}. This was done for compatibility reasons, as TUI
25599 controls to set the border's intensity predated the addition of
25600 general styling to @value{GDBN}. @xref{TUI Configuration}.
25601
25602 @item tui-active-border
25603 Control the styling of the active TUI border; that is, the TUI window
25604 that has the focus.
25605
25606 @end table
25607
25608 @node Numbers
25609 @section Numbers
25610 @cindex number representation
25611 @cindex entering numbers
25612
25613 You can always enter numbers in octal, decimal, or hexadecimal in
25614 @value{GDBN} by the usual conventions: octal numbers begin with
25615 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
25616 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25617 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
25618 10; likewise, the default display for numbers---when no particular
25619 format is specified---is base 10. You can change the default base for
25620 both input and output with the commands described below.
25621
25622 @table @code
25623 @kindex set input-radix
25624 @item set input-radix @var{base}
25625 Set the default base for numeric input. Supported choices
25626 for @var{base} are decimal 8, 10, or 16. The base must itself be
25627 specified either unambiguously or using the current input radix; for
25628 example, any of
25629
25630 @smallexample
25631 set input-radix 012
25632 set input-radix 10.
25633 set input-radix 0xa
25634 @end smallexample
25635
25636 @noindent
25637 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
25638 leaves the input radix unchanged, no matter what it was, since
25639 @samp{10}, being without any leading or trailing signs of its base, is
25640 interpreted in the current radix. Thus, if the current radix is 16,
25641 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25642 change the radix.
25643
25644 @kindex set output-radix
25645 @item set output-radix @var{base}
25646 Set the default base for numeric display. Supported choices
25647 for @var{base} are decimal 8, 10, or 16. The base must itself be
25648 specified either unambiguously or using the current input radix.
25649
25650 @kindex show input-radix
25651 @item show input-radix
25652 Display the current default base for numeric input.
25653
25654 @kindex show output-radix
25655 @item show output-radix
25656 Display the current default base for numeric display.
25657
25658 @item set radix @r{[}@var{base}@r{]}
25659 @itemx show radix
25660 @kindex set radix
25661 @kindex show radix
25662 These commands set and show the default base for both input and output
25663 of numbers. @code{set radix} sets the radix of input and output to
25664 the same base; without an argument, it resets the radix back to its
25665 default value of 10.
25666
25667 @end table
25668
25669 @node ABI
25670 @section Configuring the Current ABI
25671
25672 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25673 application automatically. However, sometimes you need to override its
25674 conclusions. Use these commands to manage @value{GDBN}'s view of the
25675 current ABI.
25676
25677 @cindex OS ABI
25678 @kindex set osabi
25679 @kindex show osabi
25680 @cindex Newlib OS ABI and its influence on the longjmp handling
25681
25682 One @value{GDBN} configuration can debug binaries for multiple operating
25683 system targets, either via remote debugging or native emulation.
25684 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25685 but you can override its conclusion using the @code{set osabi} command.
25686 One example where this is useful is in debugging of binaries which use
25687 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25688 not have the same identifying marks that the standard C library for your
25689 platform provides.
25690
25691 When @value{GDBN} is debugging the AArch64 architecture, it provides a
25692 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25693 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25694 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25695
25696 @table @code
25697 @item show osabi
25698 Show the OS ABI currently in use.
25699
25700 @item set osabi
25701 With no argument, show the list of registered available OS ABI's.
25702
25703 @item set osabi @var{abi}
25704 Set the current OS ABI to @var{abi}.
25705 @end table
25706
25707 @cindex float promotion
25708
25709 Generally, the way that an argument of type @code{float} is passed to a
25710 function depends on whether the function is prototyped. For a prototyped
25711 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25712 according to the architecture's convention for @code{float}. For unprototyped
25713 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25714 @code{double} and then passed.
25715
25716 Unfortunately, some forms of debug information do not reliably indicate whether
25717 a function is prototyped. If @value{GDBN} calls a function that is not marked
25718 as prototyped, it consults @kbd{set coerce-float-to-double}.
25719
25720 @table @code
25721 @kindex set coerce-float-to-double
25722 @item set coerce-float-to-double
25723 @itemx set coerce-float-to-double on
25724 Arguments of type @code{float} will be promoted to @code{double} when passed
25725 to an unprototyped function. This is the default setting.
25726
25727 @item set coerce-float-to-double off
25728 Arguments of type @code{float} will be passed directly to unprototyped
25729 functions.
25730
25731 @kindex show coerce-float-to-double
25732 @item show coerce-float-to-double
25733 Show the current setting of promoting @code{float} to @code{double}.
25734 @end table
25735
25736 @kindex set cp-abi
25737 @kindex show cp-abi
25738 @value{GDBN} needs to know the ABI used for your program's C@t{++}
25739 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25740 used to build your application. @value{GDBN} only fully supports
25741 programs with a single C@t{++} ABI; if your program contains code using
25742 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25743 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25744 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25745 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25746 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25747 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25748 ``auto''.
25749
25750 @table @code
25751 @item show cp-abi
25752 Show the C@t{++} ABI currently in use.
25753
25754 @item set cp-abi
25755 With no argument, show the list of supported C@t{++} ABI's.
25756
25757 @item set cp-abi @var{abi}
25758 @itemx set cp-abi auto
25759 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25760 @end table
25761
25762 @node Auto-loading
25763 @section Automatically loading associated files
25764 @cindex auto-loading
25765
25766 @value{GDBN} sometimes reads files with commands and settings automatically,
25767 without being explicitly told so by the user. We call this feature
25768 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
25769 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
25770 results or introduce security risks (e.g., if the file comes from untrusted
25771 sources).
25772
25773 @menu
25774 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25775 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25776
25777 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25778 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
25779 @end menu
25780
25781 There are various kinds of files @value{GDBN} can automatically load.
25782 In addition to these files, @value{GDBN} supports auto-loading code written
25783 in various extension languages. @xref{Auto-loading extensions}.
25784
25785 Note that loading of these associated files (including the local @file{.gdbinit}
25786 file) requires accordingly configured @code{auto-load safe-path}
25787 (@pxref{Auto-loading safe path}).
25788
25789 For these reasons, @value{GDBN} includes commands and options to let you
25790 control when to auto-load files and which files should be auto-loaded.
25791
25792 @table @code
25793 @anchor{set auto-load off}
25794 @kindex set auto-load off
25795 @item set auto-load off
25796 Globally disable loading of all auto-loaded files.
25797 You may want to use this command with the @samp{-iex} option
25798 (@pxref{Option -init-eval-command}) such as:
25799 @smallexample
25800 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25801 @end smallexample
25802
25803 Be aware that system init file (@pxref{System-wide configuration})
25804 and init files from your home directory (@pxref{Home Directory Init File})
25805 still get read (as they come from generally trusted directories).
25806 To prevent @value{GDBN} from auto-loading even those init files, use the
25807 @option{-nx} option (@pxref{Mode Options}), in addition to
25808 @code{set auto-load no}.
25809
25810 @anchor{show auto-load}
25811 @kindex show auto-load
25812 @item show auto-load
25813 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25814 or disabled.
25815
25816 @smallexample
25817 (gdb) show auto-load
25818 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25819 libthread-db: Auto-loading of inferior specific libthread_db is on.
25820 local-gdbinit: Auto-loading of .gdbinit script from current directory
25821 is on.
25822 python-scripts: Auto-loading of Python scripts is on.
25823 safe-path: List of directories from which it is safe to auto-load files
25824 is $debugdir:$datadir/auto-load.
25825 scripts-directory: List of directories from which to load auto-loaded scripts
25826 is $debugdir:$datadir/auto-load.
25827 @end smallexample
25828
25829 @anchor{info auto-load}
25830 @kindex info auto-load
25831 @item info auto-load
25832 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25833 not.
25834
25835 @smallexample
25836 (gdb) info auto-load
25837 gdb-scripts:
25838 Loaded Script
25839 Yes /home/user/gdb/gdb-gdb.gdb
25840 libthread-db: No auto-loaded libthread-db.
25841 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25842 loaded.
25843 python-scripts:
25844 Loaded Script
25845 Yes /home/user/gdb/gdb-gdb.py
25846 @end smallexample
25847 @end table
25848
25849 These are @value{GDBN} control commands for the auto-loading:
25850
25851 @multitable @columnfractions .5 .5
25852 @item @xref{set auto-load off}.
25853 @tab Disable auto-loading globally.
25854 @item @xref{show auto-load}.
25855 @tab Show setting of all kinds of files.
25856 @item @xref{info auto-load}.
25857 @tab Show state of all kinds of files.
25858 @item @xref{set auto-load gdb-scripts}.
25859 @tab Control for @value{GDBN} command scripts.
25860 @item @xref{show auto-load gdb-scripts}.
25861 @tab Show setting of @value{GDBN} command scripts.
25862 @item @xref{info auto-load gdb-scripts}.
25863 @tab Show state of @value{GDBN} command scripts.
25864 @item @xref{set auto-load python-scripts}.
25865 @tab Control for @value{GDBN} Python scripts.
25866 @item @xref{show auto-load python-scripts}.
25867 @tab Show setting of @value{GDBN} Python scripts.
25868 @item @xref{info auto-load python-scripts}.
25869 @tab Show state of @value{GDBN} Python scripts.
25870 @item @xref{set auto-load guile-scripts}.
25871 @tab Control for @value{GDBN} Guile scripts.
25872 @item @xref{show auto-load guile-scripts}.
25873 @tab Show setting of @value{GDBN} Guile scripts.
25874 @item @xref{info auto-load guile-scripts}.
25875 @tab Show state of @value{GDBN} Guile scripts.
25876 @item @xref{set auto-load scripts-directory}.
25877 @tab Control for @value{GDBN} auto-loaded scripts location.
25878 @item @xref{show auto-load scripts-directory}.
25879 @tab Show @value{GDBN} auto-loaded scripts location.
25880 @item @xref{add-auto-load-scripts-directory}.
25881 @tab Add directory for auto-loaded scripts location list.
25882 @item @xref{set auto-load local-gdbinit}.
25883 @tab Control for init file in the current directory.
25884 @item @xref{show auto-load local-gdbinit}.
25885 @tab Show setting of init file in the current directory.
25886 @item @xref{info auto-load local-gdbinit}.
25887 @tab Show state of init file in the current directory.
25888 @item @xref{set auto-load libthread-db}.
25889 @tab Control for thread debugging library.
25890 @item @xref{show auto-load libthread-db}.
25891 @tab Show setting of thread debugging library.
25892 @item @xref{info auto-load libthread-db}.
25893 @tab Show state of thread debugging library.
25894 @item @xref{set auto-load safe-path}.
25895 @tab Control directories trusted for automatic loading.
25896 @item @xref{show auto-load safe-path}.
25897 @tab Show directories trusted for automatic loading.
25898 @item @xref{add-auto-load-safe-path}.
25899 @tab Add directory trusted for automatic loading.
25900 @end multitable
25901
25902 @node Init File in the Current Directory
25903 @subsection Automatically loading init file in the current directory
25904 @cindex auto-loading init file in the current directory
25905
25906 By default, @value{GDBN} reads and executes the canned sequences of commands
25907 from init file (if any) in the current working directory,
25908 see @ref{Init File in the Current Directory during Startup}.
25909
25910 Note that loading of this local @file{.gdbinit} file also requires accordingly
25911 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25912
25913 @table @code
25914 @anchor{set auto-load local-gdbinit}
25915 @kindex set auto-load local-gdbinit
25916 @item set auto-load local-gdbinit [on|off]
25917 Enable or disable the auto-loading of canned sequences of commands
25918 (@pxref{Sequences}) found in init file in the current directory.
25919
25920 @anchor{show auto-load local-gdbinit}
25921 @kindex show auto-load local-gdbinit
25922 @item show auto-load local-gdbinit
25923 Show whether auto-loading of canned sequences of commands from init file in the
25924 current directory is enabled or disabled.
25925
25926 @anchor{info auto-load local-gdbinit}
25927 @kindex info auto-load local-gdbinit
25928 @item info auto-load local-gdbinit
25929 Print whether canned sequences of commands from init file in the
25930 current directory have been auto-loaded.
25931 @end table
25932
25933 @node libthread_db.so.1 file
25934 @subsection Automatically loading thread debugging library
25935 @cindex auto-loading libthread_db.so.1
25936
25937 This feature is currently present only on @sc{gnu}/Linux native hosts.
25938
25939 @value{GDBN} reads in some cases thread debugging library from places specific
25940 to the inferior (@pxref{set libthread-db-search-path}).
25941
25942 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
25943 without checking this @samp{set auto-load libthread-db} switch as system
25944 libraries have to be trusted in general. In all other cases of
25945 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
25946 auto-load libthread-db} is enabled before trying to open such thread debugging
25947 library.
25948
25949 Note that loading of this debugging library also requires accordingly configured
25950 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25951
25952 @table @code
25953 @anchor{set auto-load libthread-db}
25954 @kindex set auto-load libthread-db
25955 @item set auto-load libthread-db [on|off]
25956 Enable or disable the auto-loading of inferior specific thread debugging library.
25957
25958 @anchor{show auto-load libthread-db}
25959 @kindex show auto-load libthread-db
25960 @item show auto-load libthread-db
25961 Show whether auto-loading of inferior specific thread debugging library is
25962 enabled or disabled.
25963
25964 @anchor{info auto-load libthread-db}
25965 @kindex info auto-load libthread-db
25966 @item info auto-load libthread-db
25967 Print the list of all loaded inferior specific thread debugging libraries and
25968 for each such library print list of inferior @var{pid}s using it.
25969 @end table
25970
25971 @node Auto-loading safe path
25972 @subsection Security restriction for auto-loading
25973 @cindex auto-loading safe-path
25974
25975 As the files of inferior can come from untrusted source (such as submitted by
25976 an application user) @value{GDBN} does not always load any files automatically.
25977 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
25978 directories trusted for loading files not explicitly requested by user.
25979 Each directory can also be a shell wildcard pattern.
25980
25981 If the path is not set properly you will see a warning and the file will not
25982 get loaded:
25983
25984 @smallexample
25985 $ ./gdb -q ./gdb
25986 Reading symbols from /home/user/gdb/gdb...
25987 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
25988 declined by your `auto-load safe-path' set
25989 to "$debugdir:$datadir/auto-load".
25990 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
25991 declined by your `auto-load safe-path' set
25992 to "$debugdir:$datadir/auto-load".
25993 @end smallexample
25994
25995 @noindent
25996 To instruct @value{GDBN} to go ahead and use the init files anyway,
25997 invoke @value{GDBN} like this:
25998
25999 @smallexample
26000 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26001 @end smallexample
26002
26003 The list of trusted directories is controlled by the following commands:
26004
26005 @table @code
26006 @anchor{set auto-load safe-path}
26007 @kindex set auto-load safe-path
26008 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26009 Set the list of directories (and their subdirectories) trusted for automatic
26010 loading and execution of scripts. You can also enter a specific trusted file.
26011 Each directory can also be a shell wildcard pattern; wildcards do not match
26012 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26013 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26014 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26015 its default value as specified during @value{GDBN} compilation.
26016
26017 The list of directories uses path separator (@samp{:} on GNU and Unix
26018 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26019 to the @env{PATH} environment variable.
26020
26021 @anchor{show auto-load safe-path}
26022 @kindex show auto-load safe-path
26023 @item show auto-load safe-path
26024 Show the list of directories trusted for automatic loading and execution of
26025 scripts.
26026
26027 @anchor{add-auto-load-safe-path}
26028 @kindex add-auto-load-safe-path
26029 @item add-auto-load-safe-path
26030 Add an entry (or list of entries) to the list of directories trusted for
26031 automatic loading and execution of scripts. Multiple entries may be delimited
26032 by the host platform path separator in use.
26033 @end table
26034
26035 This variable defaults to what @code{--with-auto-load-dir} has been configured
26036 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26037 substitution applies the same as for @ref{set auto-load scripts-directory}.
26038 The default @code{set auto-load safe-path} value can be also overriden by
26039 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26040
26041 Setting this variable to @file{/} disables this security protection,
26042 corresponding @value{GDBN} configuration option is
26043 @option{--without-auto-load-safe-path}.
26044 This variable is supposed to be set to the system directories writable by the
26045 system superuser only. Users can add their source directories in init files in
26046 their home directories (@pxref{Home Directory Init File}). See also deprecated
26047 init file in the current directory
26048 (@pxref{Init File in the Current Directory during Startup}).
26049
26050 To force @value{GDBN} to load the files it declined to load in the previous
26051 example, you could use one of the following ways:
26052
26053 @table @asis
26054 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26055 Specify this trusted directory (or a file) as additional component of the list.
26056 You have to specify also any existing directories displayed by
26057 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26058
26059 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26060 Specify this directory as in the previous case but just for a single
26061 @value{GDBN} session.
26062
26063 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26064 Disable auto-loading safety for a single @value{GDBN} session.
26065 This assumes all the files you debug during this @value{GDBN} session will come
26066 from trusted sources.
26067
26068 @item @kbd{./configure --without-auto-load-safe-path}
26069 During compilation of @value{GDBN} you may disable any auto-loading safety.
26070 This assumes all the files you will ever debug with this @value{GDBN} come from
26071 trusted sources.
26072 @end table
26073
26074 On the other hand you can also explicitly forbid automatic files loading which
26075 also suppresses any such warning messages:
26076
26077 @table @asis
26078 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26079 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26080
26081 @item @file{~/.gdbinit}: @samp{set auto-load no}
26082 Disable auto-loading globally for the user
26083 (@pxref{Home Directory Init File}). While it is improbable, you could also
26084 use system init file instead (@pxref{System-wide configuration}).
26085 @end table
26086
26087 This setting applies to the file names as entered by user. If no entry matches
26088 @value{GDBN} tries as a last resort to also resolve all the file names into
26089 their canonical form (typically resolving symbolic links) and compare the
26090 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26091 own before starting the comparison so a canonical form of directories is
26092 recommended to be entered.
26093
26094 @node Auto-loading verbose mode
26095 @subsection Displaying files tried for auto-load
26096 @cindex auto-loading verbose mode
26097
26098 For better visibility of all the file locations where you can place scripts to
26099 be auto-loaded with inferior --- or to protect yourself against accidental
26100 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26101 all the files attempted to be loaded. Both existing and non-existing files may
26102 be printed.
26103
26104 For example the list of directories from which it is safe to auto-load files
26105 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26106 may not be too obvious while setting it up.
26107
26108 @smallexample
26109 (gdb) set debug auto-load on
26110 (gdb) file ~/src/t/true
26111 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26112 for objfile "/tmp/true".
26113 auto-load: Updating directories of "/usr:/opt".
26114 auto-load: Using directory "/usr".
26115 auto-load: Using directory "/opt".
26116 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26117 by your `auto-load safe-path' set to "/usr:/opt".
26118 @end smallexample
26119
26120 @table @code
26121 @anchor{set debug auto-load}
26122 @kindex set debug auto-load
26123 @item set debug auto-load [on|off]
26124 Set whether to print the filenames attempted to be auto-loaded.
26125
26126 @anchor{show debug auto-load}
26127 @kindex show debug auto-load
26128 @item show debug auto-load
26129 Show whether printing of the filenames attempted to be auto-loaded is turned
26130 on or off.
26131 @end table
26132
26133 @node Messages/Warnings
26134 @section Optional Warnings and Messages
26135
26136 @cindex verbose operation
26137 @cindex optional warnings
26138 By default, @value{GDBN} is silent about its inner workings. If you are
26139 running on a slow machine, you may want to use the @code{set verbose}
26140 command. This makes @value{GDBN} tell you when it does a lengthy
26141 internal operation, so you will not think it has crashed.
26142
26143 Currently, the messages controlled by @code{set verbose} are those
26144 which announce that the symbol table for a source file is being read;
26145 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26146
26147 @table @code
26148 @kindex set verbose
26149 @item set verbose on
26150 Enables @value{GDBN} output of certain informational messages.
26151
26152 @item set verbose off
26153 Disables @value{GDBN} output of certain informational messages.
26154
26155 @kindex show verbose
26156 @item show verbose
26157 Displays whether @code{set verbose} is on or off.
26158 @end table
26159
26160 By default, if @value{GDBN} encounters bugs in the symbol table of an
26161 object file, it is silent; but if you are debugging a compiler, you may
26162 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26163 Symbol Files}).
26164
26165 @table @code
26166
26167 @kindex set complaints
26168 @item set complaints @var{limit}
26169 Permits @value{GDBN} to output @var{limit} complaints about each type of
26170 unusual symbols before becoming silent about the problem. Set
26171 @var{limit} to zero to suppress all complaints; set it to a large number
26172 to prevent complaints from being suppressed.
26173
26174 @kindex show complaints
26175 @item show complaints
26176 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26177
26178 @end table
26179
26180 @anchor{confirmation requests}
26181 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26182 lot of stupid questions to confirm certain commands. For example, if
26183 you try to run a program which is already running:
26184
26185 @smallexample
26186 (@value{GDBP}) run
26187 The program being debugged has been started already.
26188 Start it from the beginning? (y or n)
26189 @end smallexample
26190
26191 If you are willing to unflinchingly face the consequences of your own
26192 commands, you can disable this ``feature'':
26193
26194 @table @code
26195
26196 @kindex set confirm
26197 @cindex flinching
26198 @cindex confirmation
26199 @cindex stupid questions
26200 @item set confirm off
26201 Disables confirmation requests. Note that running @value{GDBN} with
26202 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26203 automatically disables confirmation requests.
26204
26205 @item set confirm on
26206 Enables confirmation requests (the default).
26207
26208 @kindex show confirm
26209 @item show confirm
26210 Displays state of confirmation requests.
26211
26212 @end table
26213
26214 @cindex command tracing
26215 If you need to debug user-defined commands or sourced files you may find it
26216 useful to enable @dfn{command tracing}. In this mode each command will be
26217 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26218 quantity denoting the call depth of each command.
26219
26220 @table @code
26221 @kindex set trace-commands
26222 @cindex command scripts, debugging
26223 @item set trace-commands on
26224 Enable command tracing.
26225 @item set trace-commands off
26226 Disable command tracing.
26227 @item show trace-commands
26228 Display the current state of command tracing.
26229 @end table
26230
26231 @node Debugging Output
26232 @section Optional Messages about Internal Happenings
26233 @cindex optional debugging messages
26234
26235 @value{GDBN} has commands that enable optional debugging messages from
26236 various @value{GDBN} subsystems; normally these commands are of
26237 interest to @value{GDBN} maintainers, or when reporting a bug. This
26238 section documents those commands.
26239
26240 @table @code
26241 @kindex set exec-done-display
26242 @item set exec-done-display
26243 Turns on or off the notification of asynchronous commands'
26244 completion. When on, @value{GDBN} will print a message when an
26245 asynchronous command finishes its execution. The default is off.
26246 @kindex show exec-done-display
26247 @item show exec-done-display
26248 Displays the current setting of asynchronous command completion
26249 notification.
26250 @kindex set debug
26251 @cindex ARM AArch64
26252 @item set debug aarch64
26253 Turns on or off display of debugging messages related to ARM AArch64.
26254 The default is off.
26255 @kindex show debug
26256 @item show debug aarch64
26257 Displays the current state of displaying debugging messages related to
26258 ARM AArch64.
26259 @cindex gdbarch debugging info
26260 @cindex architecture debugging info
26261 @item set debug arch
26262 Turns on or off display of gdbarch debugging info. The default is off
26263 @item show debug arch
26264 Displays the current state of displaying gdbarch debugging info.
26265 @item set debug aix-solib
26266 @cindex AIX shared library debugging
26267 Control display of debugging messages from the AIX shared library
26268 support module. The default is off.
26269 @item show debug aix-thread
26270 Show the current state of displaying AIX shared library debugging messages.
26271 @item set debug aix-thread
26272 @cindex AIX threads
26273 Display debugging messages about inner workings of the AIX thread
26274 module.
26275 @item show debug aix-thread
26276 Show the current state of AIX thread debugging info display.
26277 @item set debug check-physname
26278 @cindex physname
26279 Check the results of the ``physname'' computation. When reading DWARF
26280 debugging information for C@t{++}, @value{GDBN} attempts to compute
26281 each entity's name. @value{GDBN} can do this computation in two
26282 different ways, depending on exactly what information is present.
26283 When enabled, this setting causes @value{GDBN} to compute the names
26284 both ways and display any discrepancies.
26285 @item show debug check-physname
26286 Show the current state of ``physname'' checking.
26287 @item set debug coff-pe-read
26288 @cindex COFF/PE exported symbols
26289 Control display of debugging messages related to reading of COFF/PE
26290 exported symbols. The default is off.
26291 @item show debug coff-pe-read
26292 Displays the current state of displaying debugging messages related to
26293 reading of COFF/PE exported symbols.
26294 @item set debug dwarf-die
26295 @cindex DWARF DIEs
26296 Dump DWARF DIEs after they are read in.
26297 The value is the number of nesting levels to print.
26298 A value of zero turns off the display.
26299 @item show debug dwarf-die
26300 Show the current state of DWARF DIE debugging.
26301 @item set debug dwarf-line
26302 @cindex DWARF Line Tables
26303 Turns on or off display of debugging messages related to reading
26304 DWARF line tables. The default is 0 (off).
26305 A value of 1 provides basic information.
26306 A value greater than 1 provides more verbose information.
26307 @item show debug dwarf-line
26308 Show the current state of DWARF line table debugging.
26309 @item set debug dwarf-read
26310 @cindex DWARF Reading
26311 Turns on or off display of debugging messages related to reading
26312 DWARF debug info. The default is 0 (off).
26313 A value of 1 provides basic information.
26314 A value greater than 1 provides more verbose information.
26315 @item show debug dwarf-read
26316 Show the current state of DWARF reader debugging.
26317 @item set debug displaced
26318 @cindex displaced stepping debugging info
26319 Turns on or off display of @value{GDBN} debugging info for the
26320 displaced stepping support. The default is off.
26321 @item show debug displaced
26322 Displays the current state of displaying @value{GDBN} debugging info
26323 related to displaced stepping.
26324 @item set debug event
26325 @cindex event debugging info
26326 Turns on or off display of @value{GDBN} event debugging info. The
26327 default is off.
26328 @item show debug event
26329 Displays the current state of displaying @value{GDBN} event debugging
26330 info.
26331 @item set debug expression
26332 @cindex expression debugging info
26333 Turns on or off display of debugging info about @value{GDBN}
26334 expression parsing. The default is off.
26335 @item show debug expression
26336 Displays the current state of displaying debugging info about
26337 @value{GDBN} expression parsing.
26338 @item set debug fbsd-lwp
26339 @cindex FreeBSD LWP debug messages
26340 Turns on or off debugging messages from the FreeBSD LWP debug support.
26341 @item show debug fbsd-lwp
26342 Show the current state of FreeBSD LWP debugging messages.
26343 @item set debug fbsd-nat
26344 @cindex FreeBSD native target debug messages
26345 Turns on or off debugging messages from the FreeBSD native target.
26346 @item show debug fbsd-nat
26347 Show the current state of FreeBSD native target debugging messages.
26348 @item set debug frame
26349 @cindex frame debugging info
26350 Turns on or off display of @value{GDBN} frame debugging info. The
26351 default is off.
26352 @item show debug frame
26353 Displays the current state of displaying @value{GDBN} frame debugging
26354 info.
26355 @item set debug gnu-nat
26356 @cindex @sc{gnu}/Hurd debug messages
26357 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26358 @item show debug gnu-nat
26359 Show the current state of @sc{gnu}/Hurd debugging messages.
26360 @item set debug infrun
26361 @cindex inferior debugging info
26362 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26363 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26364 for implementing operations such as single-stepping the inferior.
26365 @item show debug infrun
26366 Displays the current state of @value{GDBN} inferior debugging.
26367 @item set debug jit
26368 @cindex just-in-time compilation, debugging messages
26369 Turn on or off debugging messages from JIT debug support.
26370 @item show debug jit
26371 Displays the current state of @value{GDBN} JIT debugging.
26372 @item set debug lin-lwp
26373 @cindex @sc{gnu}/Linux LWP debug messages
26374 @cindex Linux lightweight processes
26375 Turn on or off debugging messages from the Linux LWP debug support.
26376 @item show debug lin-lwp
26377 Show the current state of Linux LWP debugging messages.
26378 @item set debug linux-namespaces
26379 @cindex @sc{gnu}/Linux namespaces debug messages
26380 Turn on or off debugging messages from the Linux namespaces debug support.
26381 @item show debug linux-namespaces
26382 Show the current state of Linux namespaces debugging messages.
26383 @item set debug mach-o
26384 @cindex Mach-O symbols processing
26385 Control display of debugging messages related to Mach-O symbols
26386 processing. The default is off.
26387 @item show debug mach-o
26388 Displays the current state of displaying debugging messages related to
26389 reading of COFF/PE exported symbols.
26390 @item set debug notification
26391 @cindex remote async notification debugging info
26392 Turn on or off debugging messages about remote async notification.
26393 The default is off.
26394 @item show debug notification
26395 Displays the current state of remote async notification debugging messages.
26396 @item set debug observer
26397 @cindex observer debugging info
26398 Turns on or off display of @value{GDBN} observer debugging. This
26399 includes info such as the notification of observable events.
26400 @item show debug observer
26401 Displays the current state of observer debugging.
26402 @item set debug overload
26403 @cindex C@t{++} overload debugging info
26404 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26405 info. This includes info such as ranking of functions, etc. The default
26406 is off.
26407 @item show debug overload
26408 Displays the current state of displaying @value{GDBN} C@t{++} overload
26409 debugging info.
26410 @cindex expression parser, debugging info
26411 @cindex debug expression parser
26412 @item set debug parser
26413 Turns on or off the display of expression parser debugging output.
26414 Internally, this sets the @code{yydebug} variable in the expression
26415 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26416 details. The default is off.
26417 @item show debug parser
26418 Show the current state of expression parser debugging.
26419 @cindex packets, reporting on stdout
26420 @cindex serial connections, debugging
26421 @cindex debug remote protocol
26422 @cindex remote protocol debugging
26423 @cindex display remote packets
26424 @item set debug remote
26425 Turns on or off display of reports on all packets sent back and forth across
26426 the serial line to the remote machine. The info is printed on the
26427 @value{GDBN} standard output stream. The default is off.
26428 @item show debug remote
26429 Displays the state of display of remote packets.
26430
26431 @item set debug remote-packet-max-chars
26432 Sets the maximum number of characters to display for each remote packet when
26433 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26434 displaying lengthy remote packets and polluting the console.
26435
26436 The default value is @code{512}, which means @value{GDBN} will truncate each
26437 remote packet after 512 bytes.
26438
26439 Setting this option to @code{unlimited} will disable truncation and will output
26440 the full length of the remote packets.
26441 @item show debug remote-packet-max-chars
26442 Displays the number of bytes to output for remote packet debugging.
26443
26444 @item set debug separate-debug-file
26445 Turns on or off display of debug output about separate debug file search.
26446 @item show debug separate-debug-file
26447 Displays the state of separate debug file search debug output.
26448
26449 @item set debug serial
26450 Turns on or off display of @value{GDBN} serial debugging info. The
26451 default is off.
26452 @item show debug serial
26453 Displays the current state of displaying @value{GDBN} serial debugging
26454 info.
26455 @item set debug solib-frv
26456 @cindex FR-V shared-library debugging
26457 Turn on or off debugging messages for FR-V shared-library code.
26458 @item show debug solib-frv
26459 Display the current state of FR-V shared-library code debugging
26460 messages.
26461 @item set debug symbol-lookup
26462 @cindex symbol lookup
26463 Turns on or off display of debugging messages related to symbol lookup.
26464 The default is 0 (off).
26465 A value of 1 provides basic information.
26466 A value greater than 1 provides more verbose information.
26467 @item show debug symbol-lookup
26468 Show the current state of symbol lookup debugging messages.
26469 @item set debug symfile
26470 @cindex symbol file functions
26471 Turns on or off display of debugging messages related to symbol file functions.
26472 The default is off. @xref{Files}.
26473 @item show debug symfile
26474 Show the current state of symbol file debugging messages.
26475 @item set debug symtab-create
26476 @cindex symbol table creation
26477 Turns on or off display of debugging messages related to symbol table creation.
26478 The default is 0 (off).
26479 A value of 1 provides basic information.
26480 A value greater than 1 provides more verbose information.
26481 @item show debug symtab-create
26482 Show the current state of symbol table creation debugging.
26483 @item set debug target
26484 @cindex target debugging info
26485 Turns on or off display of @value{GDBN} target debugging info. This info
26486 includes what is going on at the target level of GDB, as it happens. The
26487 default is 0. Set it to 1 to track events, and to 2 to also track the
26488 value of large memory transfers.
26489 @item show debug target
26490 Displays the current state of displaying @value{GDBN} target debugging
26491 info.
26492 @item set debug timestamp
26493 @cindex timestamping debugging info
26494 Turns on or off display of timestamps with @value{GDBN} debugging info.
26495 When enabled, seconds and microseconds are displayed before each debugging
26496 message.
26497 @item show debug timestamp
26498 Displays the current state of displaying timestamps with @value{GDBN}
26499 debugging info.
26500 @item set debug varobj
26501 @cindex variable object debugging info
26502 Turns on or off display of @value{GDBN} variable object debugging
26503 info. The default is off.
26504 @item show debug varobj
26505 Displays the current state of displaying @value{GDBN} variable object
26506 debugging info.
26507 @item set debug xml
26508 @cindex XML parser debugging
26509 Turn on or off debugging messages for built-in XML parsers.
26510 @item show debug xml
26511 Displays the current state of XML debugging messages.
26512 @end table
26513
26514 @node Other Misc Settings
26515 @section Other Miscellaneous Settings
26516 @cindex miscellaneous settings
26517
26518 @table @code
26519 @kindex set interactive-mode
26520 @item set interactive-mode
26521 If @code{on}, forces @value{GDBN} to assume that GDB was started
26522 in a terminal. In practice, this means that @value{GDBN} should wait
26523 for the user to answer queries generated by commands entered at
26524 the command prompt. If @code{off}, forces @value{GDBN} to operate
26525 in the opposite mode, and it uses the default answers to all queries.
26526 If @code{auto} (the default), @value{GDBN} tries to determine whether
26527 its standard input is a terminal, and works in interactive-mode if it
26528 is, non-interactively otherwise.
26529
26530 In the vast majority of cases, the debugger should be able to guess
26531 correctly which mode should be used. But this setting can be useful
26532 in certain specific cases, such as running a MinGW @value{GDBN}
26533 inside a cygwin window.
26534
26535 @kindex show interactive-mode
26536 @item show interactive-mode
26537 Displays whether the debugger is operating in interactive mode or not.
26538 @end table
26539
26540 @node Extending GDB
26541 @chapter Extending @value{GDBN}
26542 @cindex extending GDB
26543
26544 @value{GDBN} provides several mechanisms for extension.
26545 @value{GDBN} also provides the ability to automatically load
26546 extensions when it reads a file for debugging. This allows the
26547 user to automatically customize @value{GDBN} for the program
26548 being debugged.
26549
26550 @menu
26551 * Sequences:: Canned Sequences of @value{GDBN} Commands
26552 * Python:: Extending @value{GDBN} using Python
26553 * Guile:: Extending @value{GDBN} using Guile
26554 * Auto-loading extensions:: Automatically loading extensions
26555 * Multiple Extension Languages:: Working with multiple extension languages
26556 * Aliases:: Creating new spellings of existing commands
26557 @end menu
26558
26559 To facilitate the use of extension languages, @value{GDBN} is capable
26560 of evaluating the contents of a file. When doing so, @value{GDBN}
26561 can recognize which extension language is being used by looking at
26562 the filename extension. Files with an unrecognized filename extension
26563 are always treated as a @value{GDBN} Command Files.
26564 @xref{Command Files,, Command files}.
26565
26566 You can control how @value{GDBN} evaluates these files with the following
26567 setting:
26568
26569 @table @code
26570 @kindex set script-extension
26571 @kindex show script-extension
26572 @item set script-extension off
26573 All scripts are always evaluated as @value{GDBN} Command Files.
26574
26575 @item set script-extension soft
26576 The debugger determines the scripting language based on filename
26577 extension. If this scripting language is supported, @value{GDBN}
26578 evaluates the script using that language. Otherwise, it evaluates
26579 the file as a @value{GDBN} Command File.
26580
26581 @item set script-extension strict
26582 The debugger determines the scripting language based on filename
26583 extension, and evaluates the script using that language. If the
26584 language is not supported, then the evaluation fails.
26585
26586 @item show script-extension
26587 Display the current value of the @code{script-extension} option.
26588
26589 @end table
26590
26591 @ifset SYSTEM_GDBINIT_DIR
26592 This setting is not used for files in the system-wide gdbinit directory.
26593 Files in that directory must have an extension matching their language,
26594 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26595 commands. @xref{Startup}.
26596 @end ifset
26597
26598 @node Sequences
26599 @section Canned Sequences of Commands
26600
26601 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
26602 Command Lists}), @value{GDBN} provides two ways to store sequences of
26603 commands for execution as a unit: user-defined commands and command
26604 files.
26605
26606 @menu
26607 * Define:: How to define your own commands
26608 * Hooks:: Hooks for user-defined commands
26609 * Command Files:: How to write scripts of commands to be stored in a file
26610 * Output:: Commands for controlled output
26611 * Auto-loading sequences:: Controlling auto-loaded command files
26612 @end menu
26613
26614 @node Define
26615 @subsection User-defined Commands
26616
26617 @cindex user-defined command
26618 @cindex arguments, to user-defined commands
26619 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26620 which you assign a new name as a command. This is done with the
26621 @code{define} command. User commands may accept an unlimited number of arguments
26622 separated by whitespace. Arguments are accessed within the user command
26623 via @code{$arg0@dots{}$argN}. A trivial example:
26624
26625 @smallexample
26626 define adder
26627 print $arg0 + $arg1 + $arg2
26628 end
26629 @end smallexample
26630
26631 @noindent
26632 To execute the command use:
26633
26634 @smallexample
26635 adder 1 2 3
26636 @end smallexample
26637
26638 @noindent
26639 This defines the command @code{adder}, which prints the sum of
26640 its three arguments. Note the arguments are text substitutions, so they may
26641 reference variables, use complex expressions, or even perform inferior
26642 functions calls.
26643
26644 @cindex argument count in user-defined commands
26645 @cindex how many arguments (user-defined commands)
26646 In addition, @code{$argc} may be used to find out how many arguments have
26647 been passed.
26648
26649 @smallexample
26650 define adder
26651 if $argc == 2
26652 print $arg0 + $arg1
26653 end
26654 if $argc == 3
26655 print $arg0 + $arg1 + $arg2
26656 end
26657 end
26658 @end smallexample
26659
26660 Combining with the @code{eval} command (@pxref{eval}) makes it easier
26661 to process a variable number of arguments:
26662
26663 @smallexample
26664 define adder
26665 set $i = 0
26666 set $sum = 0
26667 while $i < $argc
26668 eval "set $sum = $sum + $arg%d", $i
26669 set $i = $i + 1
26670 end
26671 print $sum
26672 end
26673 @end smallexample
26674
26675 @table @code
26676
26677 @kindex define
26678 @item define @var{commandname}
26679 Define a command named @var{commandname}. If there is already a command
26680 by that name, you are asked to confirm that you want to redefine it.
26681 The argument @var{commandname} may be a bare command name consisting of letters,
26682 numbers, dashes, dots, and underscores. It may also start with any
26683 predefined or user-defined prefix command.
26684 For example, @samp{define target my-target} creates
26685 a user-defined @samp{target my-target} command.
26686
26687 The definition of the command is made up of other @value{GDBN} command lines,
26688 which are given following the @code{define} command. The end of these
26689 commands is marked by a line containing @code{end}.
26690
26691 @kindex document
26692 @kindex end@r{ (user-defined commands)}
26693 @item document @var{commandname}
26694 Document the user-defined command @var{commandname}, so that it can be
26695 accessed by @code{help}. The command @var{commandname} must already be
26696 defined. This command reads lines of documentation just as @code{define}
26697 reads the lines of the command definition, ending with @code{end}.
26698 After the @code{document} command is finished, @code{help} on command
26699 @var{commandname} displays the documentation you have written.
26700
26701 You may use the @code{document} command again to change the
26702 documentation of a command. Redefining the command with @code{define}
26703 does not change the documentation.
26704
26705 @kindex define-prefix
26706 @item define-prefix @var{commandname}
26707 Define or mark the command @var{commandname} as a user-defined prefix
26708 command. Once marked, @var{commandname} can be used as prefix command
26709 by the @code{define} command.
26710 Note that @code{define-prefix} can be used with a not yet defined
26711 @var{commandname}. In such a case, @var{commandname} is defined as
26712 an empty user-defined command.
26713 In case you redefine a command that was marked as a user-defined
26714 prefix command, the subcommands of the redefined command are kept
26715 (and @value{GDBN} indicates so to the user).
26716
26717 Example:
26718 @example
26719 (gdb) define-prefix abc
26720 (gdb) define-prefix abc def
26721 (gdb) define abc def
26722 Type commands for definition of "abc def".
26723 End with a line saying just "end".
26724 >echo command initial def\n
26725 >end
26726 (gdb) define abc def ghi
26727 Type commands for definition of "abc def ghi".
26728 End with a line saying just "end".
26729 >echo command ghi\n
26730 >end
26731 (gdb) define abc def
26732 Keeping subcommands of prefix command "def".
26733 Redefine command "def"? (y or n) y
26734 Type commands for definition of "abc def".
26735 End with a line saying just "end".
26736 >echo command def\n
26737 >end
26738 (gdb) abc def ghi
26739 command ghi
26740 (gdb) abc def
26741 command def
26742 (gdb)
26743 @end example
26744
26745 @kindex dont-repeat
26746 @cindex don't repeat command
26747 @item dont-repeat
26748 Used inside a user-defined command, this tells @value{GDBN} that this
26749 command should not be repeated when the user hits @key{RET}
26750 (@pxref{Command Syntax, repeat last command}).
26751
26752 @kindex help user-defined
26753 @item help user-defined
26754 List all user-defined commands and all python commands defined in class
26755 COMMAND_USER. The first line of the documentation or docstring is
26756 included (if any).
26757
26758 @kindex show user
26759 @item show user
26760 @itemx show user @var{commandname}
26761 Display the @value{GDBN} commands used to define @var{commandname} (but
26762 not its documentation). If no @var{commandname} is given, display the
26763 definitions for all user-defined commands.
26764 This does not work for user-defined python commands.
26765
26766 @cindex infinite recursion in user-defined commands
26767 @kindex show max-user-call-depth
26768 @kindex set max-user-call-depth
26769 @item show max-user-call-depth
26770 @itemx set max-user-call-depth
26771 The value of @code{max-user-call-depth} controls how many recursion
26772 levels are allowed in user-defined commands before @value{GDBN} suspects an
26773 infinite recursion and aborts the command.
26774 This does not apply to user-defined python commands.
26775 @end table
26776
26777 In addition to the above commands, user-defined commands frequently
26778 use control flow commands, described in @ref{Command Files}.
26779
26780 When user-defined commands are executed, the
26781 commands of the definition are not printed. An error in any command
26782 stops execution of the user-defined command.
26783
26784 If used interactively, commands that would ask for confirmation proceed
26785 without asking when used inside a user-defined command. Many @value{GDBN}
26786 commands that normally print messages to say what they are doing omit the
26787 messages when used in a user-defined command.
26788
26789 @node Hooks
26790 @subsection User-defined Command Hooks
26791 @cindex command hooks
26792 @cindex hooks, for commands
26793 @cindex hooks, pre-command
26794
26795 @kindex hook
26796 You may define @dfn{hooks}, which are a special kind of user-defined
26797 command. Whenever you run the command @samp{foo}, if the user-defined
26798 command @samp{hook-foo} exists, it is executed (with no arguments)
26799 before that command.
26800
26801 @cindex hooks, post-command
26802 @kindex hookpost
26803 A hook may also be defined which is run after the command you executed.
26804 Whenever you run the command @samp{foo}, if the user-defined command
26805 @samp{hookpost-foo} exists, it is executed (with no arguments) after
26806 that command. Post-execution hooks may exist simultaneously with
26807 pre-execution hooks, for the same command.
26808
26809 It is valid for a hook to call the command which it hooks. If this
26810 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
26811
26812 @c It would be nice if hookpost could be passed a parameter indicating
26813 @c if the command it hooks executed properly or not. FIXME!
26814
26815 @kindex stop@r{, a pseudo-command}
26816 In addition, a pseudo-command, @samp{stop} exists. Defining
26817 (@samp{hook-stop}) makes the associated commands execute every time
26818 execution stops in your program: before breakpoint commands are run,
26819 displays are printed, or the stack frame is printed.
26820
26821 For example, to ignore @code{SIGALRM} signals while
26822 single-stepping, but treat them normally during normal execution,
26823 you could define:
26824
26825 @smallexample
26826 define hook-stop
26827 handle SIGALRM nopass
26828 end
26829
26830 define hook-run
26831 handle SIGALRM pass
26832 end
26833
26834 define hook-continue
26835 handle SIGALRM pass
26836 end
26837 @end smallexample
26838
26839 As a further example, to hook at the beginning and end of the @code{echo}
26840 command, and to add extra text to the beginning and end of the message,
26841 you could define:
26842
26843 @smallexample
26844 define hook-echo
26845 echo <<<---
26846 end
26847
26848 define hookpost-echo
26849 echo --->>>\n
26850 end
26851
26852 (@value{GDBP}) echo Hello World
26853 <<<---Hello World--->>>
26854 (@value{GDBP})
26855
26856 @end smallexample
26857
26858 You can define a hook for any single-word command in @value{GDBN}, but
26859 not for command aliases; you should define a hook for the basic command
26860 name, e.g.@: @code{backtrace} rather than @code{bt}.
26861 @c FIXME! So how does Joe User discover whether a command is an alias
26862 @c or not?
26863 You can hook a multi-word command by adding @code{hook-} or
26864 @code{hookpost-} to the last word of the command, e.g.@:
26865 @samp{define target hook-remote} to add a hook to @samp{target remote}.
26866
26867 If an error occurs during the execution of your hook, execution of
26868 @value{GDBN} commands stops and @value{GDBN} issues a prompt
26869 (before the command that you actually typed had a chance to run).
26870
26871 If you try to define a hook which does not match any known command, you
26872 get a warning from the @code{define} command.
26873
26874 @node Command Files
26875 @subsection Command Files
26876
26877 @cindex command files
26878 @cindex scripting commands
26879 A command file for @value{GDBN} is a text file made of lines that are
26880 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26881 also be included. An empty line in a command file does nothing; it
26882 does not mean to repeat the last command, as it would from the
26883 terminal.
26884
26885 You can request the execution of a command file with the @code{source}
26886 command. Note that the @code{source} command is also used to evaluate
26887 scripts that are not Command Files. The exact behavior can be configured
26888 using the @code{script-extension} setting.
26889 @xref{Extending GDB,, Extending GDB}.
26890
26891 @table @code
26892 @kindex source
26893 @cindex execute commands from a file
26894 @item source [-s] [-v] @var{filename}
26895 Execute the command file @var{filename}.
26896 @end table
26897
26898 The lines in a command file are generally executed sequentially,
26899 unless the order of execution is changed by one of the
26900 @emph{flow-control commands} described below. The commands are not
26901 printed as they are executed. An error in any command terminates
26902 execution of the command file and control is returned to the console.
26903
26904 @value{GDBN} first searches for @var{filename} in the current directory.
26905 If the file is not found there, and @var{filename} does not specify a
26906 directory, then @value{GDBN} also looks for the file on the source search path
26907 (specified with the @samp{directory} command);
26908 except that @file{$cdir} is not searched because the compilation directory
26909 is not relevant to scripts.
26910
26911 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
26912 on the search path even if @var{filename} specifies a directory.
26913 The search is done by appending @var{filename} to each element of the
26914 search path. So, for example, if @var{filename} is @file{mylib/myscript}
26915 and the search path contains @file{/home/user} then @value{GDBN} will
26916 look for the script @file{/home/user/mylib/myscript}.
26917 The search is also done if @var{filename} is an absolute path.
26918 For example, if @var{filename} is @file{/tmp/myscript} and
26919 the search path contains @file{/home/user} then @value{GDBN} will
26920 look for the script @file{/home/user/tmp/myscript}.
26921 For DOS-like systems, if @var{filename} contains a drive specification,
26922 it is stripped before concatenation. For example, if @var{filename} is
26923 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
26924 will look for the script @file{c:/tmp/myscript}.
26925
26926 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
26927 each command as it is executed. The option must be given before
26928 @var{filename}, and is interpreted as part of the filename anywhere else.
26929
26930 Commands that would ask for confirmation if used interactively proceed
26931 without asking when used in a command file. Many @value{GDBN} commands that
26932 normally print messages to say what they are doing omit the messages
26933 when called from command files.
26934
26935 @value{GDBN} also accepts command input from standard input. In this
26936 mode, normal output goes to standard output and error output goes to
26937 standard error. Errors in a command file supplied on standard input do
26938 not terminate execution of the command file---execution continues with
26939 the next command.
26940
26941 @smallexample
26942 gdb < cmds > log 2>&1
26943 @end smallexample
26944
26945 (The syntax above will vary depending on the shell used.) This example
26946 will execute commands from the file @file{cmds}. All output and errors
26947 would be directed to @file{log}.
26948
26949 Since commands stored on command files tend to be more general than
26950 commands typed interactively, they frequently need to deal with
26951 complicated situations, such as different or unexpected values of
26952 variables and symbols, changes in how the program being debugged is
26953 built, etc. @value{GDBN} provides a set of flow-control commands to
26954 deal with these complexities. Using these commands, you can write
26955 complex scripts that loop over data structures, execute commands
26956 conditionally, etc.
26957
26958 @table @code
26959 @kindex if
26960 @kindex else
26961 @item if
26962 @itemx else
26963 This command allows to include in your script conditionally executed
26964 commands. The @code{if} command takes a single argument, which is an
26965 expression to evaluate. It is followed by a series of commands that
26966 are executed only if the expression is true (its value is nonzero).
26967 There can then optionally be an @code{else} line, followed by a series
26968 of commands that are only executed if the expression was false. The
26969 end of the list is marked by a line containing @code{end}.
26970
26971 @kindex while
26972 @item while
26973 This command allows to write loops. Its syntax is similar to
26974 @code{if}: the command takes a single argument, which is an expression
26975 to evaluate, and must be followed by the commands to execute, one per
26976 line, terminated by an @code{end}. These commands are called the
26977 @dfn{body} of the loop. The commands in the body of @code{while} are
26978 executed repeatedly as long as the expression evaluates to true.
26979
26980 @kindex loop_break
26981 @item loop_break
26982 This command exits the @code{while} loop in whose body it is included.
26983 Execution of the script continues after that @code{while}s @code{end}
26984 line.
26985
26986 @kindex loop_continue
26987 @item loop_continue
26988 This command skips the execution of the rest of the body of commands
26989 in the @code{while} loop in whose body it is included. Execution
26990 branches to the beginning of the @code{while} loop, where it evaluates
26991 the controlling expression.
26992
26993 @kindex end@r{ (if/else/while commands)}
26994 @item end
26995 Terminate the block of commands that are the body of @code{if},
26996 @code{else}, or @code{while} flow-control commands.
26997 @end table
26998
26999
27000 @node Output
27001 @subsection Commands for Controlled Output
27002
27003 During the execution of a command file or a user-defined command, normal
27004 @value{GDBN} output is suppressed; the only output that appears is what is
27005 explicitly printed by the commands in the definition. This section
27006 describes three commands useful for generating exactly the output you
27007 want.
27008
27009 @table @code
27010 @kindex echo
27011 @item echo @var{text}
27012 @c I do not consider backslash-space a standard C escape sequence
27013 @c because it is not in ANSI.
27014 Print @var{text}. Nonprinting characters can be included in
27015 @var{text} using C escape sequences, such as @samp{\n} to print a
27016 newline. @strong{No newline is printed unless you specify one.}
27017 In addition to the standard C escape sequences, a backslash followed
27018 by a space stands for a space. This is useful for displaying a
27019 string with spaces at the beginning or the end, since leading and
27020 trailing spaces are otherwise trimmed from all arguments.
27021 To print @samp{@w{ }and foo =@w{ }}, use the command
27022 @samp{echo \@w{ }and foo = \@w{ }}.
27023
27024 A backslash at the end of @var{text} can be used, as in C, to continue
27025 the command onto subsequent lines. For example,
27026
27027 @smallexample
27028 echo This is some text\n\
27029 which is continued\n\
27030 onto several lines.\n
27031 @end smallexample
27032
27033 produces the same output as
27034
27035 @smallexample
27036 echo This is some text\n
27037 echo which is continued\n
27038 echo onto several lines.\n
27039 @end smallexample
27040
27041 @kindex output
27042 @item output @var{expression}
27043 Print the value of @var{expression} and nothing but that value: no
27044 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27045 value history either. @xref{Expressions, ,Expressions}, for more information
27046 on expressions.
27047
27048 @item output/@var{fmt} @var{expression}
27049 Print the value of @var{expression} in format @var{fmt}. You can use
27050 the same formats as for @code{print}. @xref{Output Formats,,Output
27051 Formats}, for more information.
27052
27053 @kindex printf
27054 @item printf @var{template}, @var{expressions}@dots{}
27055 Print the values of one or more @var{expressions} under the control of
27056 the string @var{template}. To print several values, make
27057 @var{expressions} be a comma-separated list of individual expressions,
27058 which may be either numbers or pointers. Their values are printed as
27059 specified by @var{template}, exactly as a C program would do by
27060 executing the code below:
27061
27062 @smallexample
27063 printf (@var{template}, @var{expressions}@dots{});
27064 @end smallexample
27065
27066 As in @code{C} @code{printf}, ordinary characters in @var{template}
27067 are printed verbatim, while @dfn{conversion specification} introduced
27068 by the @samp{%} character cause subsequent @var{expressions} to be
27069 evaluated, their values converted and formatted according to type and
27070 style information encoded in the conversion specifications, and then
27071 printed.
27072
27073 For example, you can print two values in hex like this:
27074
27075 @smallexample
27076 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27077 @end smallexample
27078
27079 @code{printf} supports all the standard @code{C} conversion
27080 specifications, including the flags and modifiers between the @samp{%}
27081 character and the conversion letter, with the following exceptions:
27082
27083 @itemize @bullet
27084 @item
27085 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27086
27087 @item
27088 The modifier @samp{*} is not supported for specifying precision or
27089 width.
27090
27091 @item
27092 The @samp{'} flag (for separation of digits into groups according to
27093 @code{LC_NUMERIC'}) is not supported.
27094
27095 @item
27096 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27097 supported.
27098
27099 @item
27100 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27101
27102 @item
27103 The conversion letters @samp{a} and @samp{A} are not supported.
27104 @end itemize
27105
27106 @noindent
27107 Note that the @samp{ll} type modifier is supported only if the
27108 underlying @code{C} implementation used to build @value{GDBN} supports
27109 the @code{long long int} type, and the @samp{L} type modifier is
27110 supported only if @code{long double} type is available.
27111
27112 As in @code{C}, @code{printf} supports simple backslash-escape
27113 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27114 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27115 single character. Octal and hexadecimal escape sequences are not
27116 supported.
27117
27118 Additionally, @code{printf} supports conversion specifications for DFP
27119 (@dfn{Decimal Floating Point}) types using the following length modifiers
27120 together with a floating point specifier.
27121 letters:
27122
27123 @itemize @bullet
27124 @item
27125 @samp{H} for printing @code{Decimal32} types.
27126
27127 @item
27128 @samp{D} for printing @code{Decimal64} types.
27129
27130 @item
27131 @samp{DD} for printing @code{Decimal128} types.
27132 @end itemize
27133
27134 If the underlying @code{C} implementation used to build @value{GDBN} has
27135 support for the three length modifiers for DFP types, other modifiers
27136 such as width and precision will also be available for @value{GDBN} to use.
27137
27138 In case there is no such @code{C} support, no additional modifiers will be
27139 available and the value will be printed in the standard way.
27140
27141 Here's an example of printing DFP types using the above conversion letters:
27142 @smallexample
27143 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27144 @end smallexample
27145
27146 @anchor{eval}
27147 @kindex eval
27148 @item eval @var{template}, @var{expressions}@dots{}
27149 Convert the values of one or more @var{expressions} under the control of
27150 the string @var{template} to a command line, and call it.
27151
27152 @end table
27153
27154 @node Auto-loading sequences
27155 @subsection Controlling auto-loading native @value{GDBN} scripts
27156 @cindex native script auto-loading
27157
27158 When a new object file is read (for example, due to the @code{file}
27159 command, or because the inferior has loaded a shared library),
27160 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27161 @xref{Auto-loading extensions}.
27162
27163 Auto-loading can be enabled or disabled,
27164 and the list of auto-loaded scripts can be printed.
27165
27166 @table @code
27167 @anchor{set auto-load gdb-scripts}
27168 @kindex set auto-load gdb-scripts
27169 @item set auto-load gdb-scripts [on|off]
27170 Enable or disable the auto-loading of canned sequences of commands scripts.
27171
27172 @anchor{show auto-load gdb-scripts}
27173 @kindex show auto-load gdb-scripts
27174 @item show auto-load gdb-scripts
27175 Show whether auto-loading of canned sequences of commands scripts is enabled or
27176 disabled.
27177
27178 @anchor{info auto-load gdb-scripts}
27179 @kindex info auto-load gdb-scripts
27180 @cindex print list of auto-loaded canned sequences of commands scripts
27181 @item info auto-load gdb-scripts [@var{regexp}]
27182 Print the list of all canned sequences of commands scripts that @value{GDBN}
27183 auto-loaded.
27184 @end table
27185
27186 If @var{regexp} is supplied only canned sequences of commands scripts with
27187 matching names are printed.
27188
27189 @c Python docs live in a separate file.
27190 @include python.texi
27191
27192 @c Guile docs live in a separate file.
27193 @include guile.texi
27194
27195 @node Auto-loading extensions
27196 @section Auto-loading extensions
27197 @cindex auto-loading extensions
27198
27199 @value{GDBN} provides two mechanisms for automatically loading extensions
27200 when a new object file is read (for example, due to the @code{file}
27201 command, or because the inferior has loaded a shared library):
27202 @file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27203 section of modern file formats like ELF.
27204
27205 @menu
27206 * objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27207 * .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27208 * Which flavor to choose?::
27209 @end menu
27210
27211 The auto-loading feature is useful for supplying application-specific
27212 debugging commands and features.
27213
27214 Auto-loading can be enabled or disabled,
27215 and the list of auto-loaded scripts can be printed.
27216 See the @samp{auto-loading} section of each extension language
27217 for more information.
27218 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27219 For Python files see @ref{Python Auto-loading}.
27220
27221 Note that loading of this script file also requires accordingly configured
27222 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27223
27224 @node objfile-gdbdotext file
27225 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27226 @cindex @file{@var{objfile}-gdb.gdb}
27227 @cindex @file{@var{objfile}-gdb.py}
27228 @cindex @file{@var{objfile}-gdb.scm}
27229
27230 When a new object file is read, @value{GDBN} looks for a file named
27231 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27232 where @var{objfile} is the object file's name and
27233 where @var{ext} is the file extension for the extension language:
27234
27235 @table @code
27236 @item @file{@var{objfile}-gdb.gdb}
27237 GDB's own command language
27238 @item @file{@var{objfile}-gdb.py}
27239 Python
27240 @item @file{@var{objfile}-gdb.scm}
27241 Guile
27242 @end table
27243
27244 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27245 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27246 components, and appending the @file{-gdb.@var{ext}} suffix.
27247 If this file exists and is readable, @value{GDBN} will evaluate it as a
27248 script in the specified extension language.
27249
27250 If this file does not exist, then @value{GDBN} will look for
27251 @var{script-name} file in all of the directories as specified below.
27252
27253 Note that loading of these files requires an accordingly configured
27254 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27255
27256 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27257 scripts normally according to its @file{.exe} filename. But if no scripts are
27258 found @value{GDBN} also tries script filenames matching the object file without
27259 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27260 is attempted on any platform. This makes the script filenames compatible
27261 between Unix and MS-Windows hosts.
27262
27263 @table @code
27264 @anchor{set auto-load scripts-directory}
27265 @kindex set auto-load scripts-directory
27266 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27267 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27268 may be delimited by the host platform path separator in use
27269 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27270
27271 Each entry here needs to be covered also by the security setting
27272 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27273
27274 @anchor{with-auto-load-dir}
27275 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27276 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27277 configuration option @option{--with-auto-load-dir}.
27278
27279 Any reference to @file{$debugdir} will get replaced by
27280 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27281 reference to @file{$datadir} will get replaced by @var{data-directory} which is
27282 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27283 @file{$datadir} must be placed as a directory component --- either alone or
27284 delimited by @file{/} or @file{\} directory separators, depending on the host
27285 platform.
27286
27287 The list of directories uses path separator (@samp{:} on GNU and Unix
27288 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27289 to the @env{PATH} environment variable.
27290
27291 @anchor{show auto-load scripts-directory}
27292 @kindex show auto-load scripts-directory
27293 @item show auto-load scripts-directory
27294 Show @value{GDBN} auto-loaded scripts location.
27295
27296 @anchor{add-auto-load-scripts-directory}
27297 @kindex add-auto-load-scripts-directory
27298 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27299 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27300 Multiple entries may be delimited by the host platform path separator in use.
27301 @end table
27302
27303 @value{GDBN} does not track which files it has already auto-loaded this way.
27304 @value{GDBN} will load the associated script every time the corresponding
27305 @var{objfile} is opened.
27306 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27307 is evaluated more than once.
27308
27309 @node dotdebug_gdb_scripts section
27310 @subsection The @code{.debug_gdb_scripts} section
27311 @cindex @code{.debug_gdb_scripts} section
27312
27313 For systems using file formats like ELF and COFF,
27314 when @value{GDBN} loads a new object file
27315 it will look for a special section named @code{.debug_gdb_scripts}.
27316 If this section exists, its contents is a list of null-terminated entries
27317 specifying scripts to load. Each entry begins with a non-null prefix byte that
27318 specifies the kind of entry, typically the extension language and whether the
27319 script is in a file or inlined in @code{.debug_gdb_scripts}.
27320
27321 The following entries are supported:
27322
27323 @table @code
27324 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27325 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27326 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27327 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27328 @end table
27329
27330 @subsubsection Script File Entries
27331
27332 If the entry specifies a file, @value{GDBN} will look for the file first
27333 in the current directory and then along the source search path
27334 (@pxref{Source Path, ,Specifying Source Directories}),
27335 except that @file{$cdir} is not searched, since the compilation
27336 directory is not relevant to scripts.
27337
27338 File entries can be placed in section @code{.debug_gdb_scripts} with,
27339 for example, this GCC macro for Python scripts.
27340
27341 @example
27342 /* Note: The "MS" section flags are to remove duplicates. */
27343 #define DEFINE_GDB_PY_SCRIPT(script_name) \
27344 asm("\
27345 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27346 .byte 1 /* Python */\n\
27347 .asciz \"" script_name "\"\n\
27348 .popsection \n\
27349 ");
27350 @end example
27351
27352 @noindent
27353 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
27354 Then one can reference the macro in a header or source file like this:
27355
27356 @example
27357 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27358 @end example
27359
27360 The script name may include directories if desired.
27361
27362 Note that loading of this script file also requires accordingly configured
27363 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27364
27365 If the macro invocation is put in a header, any application or library
27366 using this header will get a reference to the specified script,
27367 and with the use of @code{"MS"} attributes on the section, the linker
27368 will remove duplicates.
27369
27370 @subsubsection Script Text Entries
27371
27372 Script text entries allow to put the executable script in the entry
27373 itself instead of loading it from a file.
27374 The first line of the entry, everything after the prefix byte and up to
27375 the first newline (@code{0xa}) character, is the script name, and must not
27376 contain any kind of space character, e.g., spaces or tabs.
27377 The rest of the entry, up to the trailing null byte, is the script to
27378 execute in the specified language. The name needs to be unique among
27379 all script names, as @value{GDBN} executes each script only once based
27380 on its name.
27381
27382 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27383 testsuite.
27384
27385 @example
27386 #include "symcat.h"
27387 #include "gdb/section-scripts.h"
27388 asm(
27389 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27390 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27391 ".ascii \"gdb.inlined-script\\n\"\n"
27392 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27393 ".ascii \" def __init__ (self):\\n\"\n"
27394 ".ascii \" super (test_cmd, self).__init__ ("
27395 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27396 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27397 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27398 ".ascii \"test_cmd ()\\n\"\n"
27399 ".byte 0\n"
27400 ".popsection\n"
27401 );
27402 @end example
27403
27404 Loading of inlined scripts requires a properly configured
27405 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27406 The path to specify in @code{auto-load safe-path} is the path of the file
27407 containing the @code{.debug_gdb_scripts} section.
27408
27409 @node Which flavor to choose?
27410 @subsection Which flavor to choose?
27411
27412 Given the multiple ways of auto-loading extensions, it might not always
27413 be clear which one to choose. This section provides some guidance.
27414
27415 @noindent
27416 Benefits of the @file{-gdb.@var{ext}} way:
27417
27418 @itemize @bullet
27419 @item
27420 Can be used with file formats that don't support multiple sections.
27421
27422 @item
27423 Ease of finding scripts for public libraries.
27424
27425 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27426 in the source search path.
27427 For publicly installed libraries, e.g., @file{libstdc++}, there typically
27428 isn't a source directory in which to find the script.
27429
27430 @item
27431 Doesn't require source code additions.
27432 @end itemize
27433
27434 @noindent
27435 Benefits of the @code{.debug_gdb_scripts} way:
27436
27437 @itemize @bullet
27438 @item
27439 Works with static linking.
27440
27441 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27442 trigger their loading. When an application is statically linked the only
27443 objfile available is the executable, and it is cumbersome to attach all the
27444 scripts from all the input libraries to the executable's
27445 @file{-gdb.@var{ext}} script.
27446
27447 @item
27448 Works with classes that are entirely inlined.
27449
27450 Some classes can be entirely inlined, and thus there may not be an associated
27451 shared library to attach a @file{-gdb.@var{ext}} script to.
27452
27453 @item
27454 Scripts needn't be copied out of the source tree.
27455
27456 In some circumstances, apps can be built out of large collections of internal
27457 libraries, and the build infrastructure necessary to install the
27458 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27459 cumbersome. It may be easier to specify the scripts in the
27460 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
27461 top of the source tree to the source search path.
27462 @end itemize
27463
27464 @node Multiple Extension Languages
27465 @section Multiple Extension Languages
27466
27467 The Guile and Python extension languages do not share any state,
27468 and generally do not interfere with each other.
27469 There are some things to be aware of, however.
27470
27471 @subsection Python comes first
27472
27473 Python was @value{GDBN}'s first extension language, and to avoid breaking
27474 existing behaviour Python comes first. This is generally solved by the
27475 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
27476 extension languages, and when it makes a call to an extension language,
27477 (say to pretty-print a value), it tries each in turn until an extension
27478 language indicates it has performed the request (e.g., has returned the
27479 pretty-printed form of a value).
27480 This extends to errors while performing such requests: If an error happens
27481 while, for example, trying to pretty-print an object then the error is
27482 reported and any following extension languages are not tried.
27483
27484 @node Aliases
27485 @section Creating new spellings of existing commands
27486 @cindex aliases for commands
27487
27488 It is often useful to define alternate spellings of existing commands.
27489 For example, if a new @value{GDBN} command defined in Python has
27490 a long name to type, it is handy to have an abbreviated version of it
27491 that involves less typing.
27492
27493 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27494 of the @samp{step} command even though it is otherwise an ambiguous
27495 abbreviation of other commands like @samp{set} and @samp{show}.
27496
27497 Aliases are also used to provide shortened or more common versions
27498 of multi-word commands. For example, @value{GDBN} provides the
27499 @samp{tty} alias of the @samp{set inferior-tty} command.
27500
27501 You can define a new alias with the @samp{alias} command.
27502
27503 @table @code
27504
27505 @kindex alias
27506 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
27507
27508 @end table
27509
27510 @var{ALIAS} specifies the name of the new alias.
27511 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27512 underscores.
27513
27514 @var{COMMAND} specifies the name of an existing command
27515 that is being aliased.
27516
27517 The @samp{-a} option specifies that the new alias is an abbreviation
27518 of the command. Abbreviations are not used in command completion.
27519
27520 The @samp{--} option specifies the end of options,
27521 and is useful when @var{ALIAS} begins with a dash.
27522
27523 Here is a simple example showing how to make an abbreviation
27524 of a command so that there is less to type.
27525 Suppose you were tired of typing @samp{disas}, the current
27526 shortest unambiguous abbreviation of the @samp{disassemble} command
27527 and you wanted an even shorter version named @samp{di}.
27528 The following will accomplish this.
27529
27530 @smallexample
27531 (gdb) alias -a di = disas
27532 @end smallexample
27533
27534 Note that aliases are different from user-defined commands.
27535 With a user-defined command, you also need to write documentation
27536 for it with the @samp{document} command.
27537 An alias automatically picks up the documentation of the existing command.
27538
27539 Here is an example where we make @samp{elms} an abbreviation of
27540 @samp{elements} in the @samp{set print elements} command.
27541 This is to show that you can make an abbreviation of any part
27542 of a command.
27543
27544 @smallexample
27545 (gdb) alias -a set print elms = set print elements
27546 (gdb) alias -a show print elms = show print elements
27547 (gdb) set p elms 20
27548 (gdb) show p elms
27549 Limit on string chars or array elements to print is 200.
27550 @end smallexample
27551
27552 Note that if you are defining an alias of a @samp{set} command,
27553 and you want to have an alias for the corresponding @samp{show}
27554 command, then you need to define the latter separately.
27555
27556 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27557 @var{ALIAS}, just as they are normally.
27558
27559 @smallexample
27560 (gdb) alias -a set pr elms = set p ele
27561 @end smallexample
27562
27563 Finally, here is an example showing the creation of a one word
27564 alias for a more complex command.
27565 This creates alias @samp{spe} of the command @samp{set print elements}.
27566
27567 @smallexample
27568 (gdb) alias spe = set print elements
27569 (gdb) spe 20
27570 @end smallexample
27571
27572 @node Interpreters
27573 @chapter Command Interpreters
27574 @cindex command interpreters
27575
27576 @value{GDBN} supports multiple command interpreters, and some command
27577 infrastructure to allow users or user interface writers to switch
27578 between interpreters or run commands in other interpreters.
27579
27580 @value{GDBN} currently supports two command interpreters, the console
27581 interpreter (sometimes called the command-line interpreter or @sc{cli})
27582 and the machine interface interpreter (or @sc{gdb/mi}). This manual
27583 describes both of these interfaces in great detail.
27584
27585 By default, @value{GDBN} will start with the console interpreter.
27586 However, the user may choose to start @value{GDBN} with another
27587 interpreter by specifying the @option{-i} or @option{--interpreter}
27588 startup options. Defined interpreters include:
27589
27590 @table @code
27591 @item console
27592 @cindex console interpreter
27593 The traditional console or command-line interpreter. This is the most often
27594 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27595 @value{GDBN} will use this interpreter.
27596
27597 @item mi
27598 @cindex mi interpreter
27599 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
27600 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27601 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27602 Interface}.
27603
27604 @item mi3
27605 @cindex mi3 interpreter
27606 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27607
27608 @item mi2
27609 @cindex mi2 interpreter
27610 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
27611
27612 @item mi1
27613 @cindex mi1 interpreter
27614 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
27615
27616 @end table
27617
27618 @cindex invoke another interpreter
27619
27620 @kindex interpreter-exec
27621 You may execute commands in any interpreter from the current
27622 interpreter using the appropriate command. If you are running the
27623 console interpreter, simply use the @code{interpreter-exec} command:
27624
27625 @smallexample
27626 interpreter-exec mi "-data-list-register-names"
27627 @end smallexample
27628
27629 @sc{gdb/mi} has a similar command, although it is only available in versions of
27630 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27631
27632 Note that @code{interpreter-exec} only changes the interpreter for the
27633 duration of the specified command. It does not change the interpreter
27634 permanently.
27635
27636 @cindex start a new independent interpreter
27637
27638 Although you may only choose a single interpreter at startup, it is
27639 possible to run an independent interpreter on a specified input/output
27640 device (usually a tty).
27641
27642 For example, consider a debugger GUI or IDE that wants to provide a
27643 @value{GDBN} console view. It may do so by embedding a terminal
27644 emulator widget in its GUI, starting @value{GDBN} in the traditional
27645 command-line mode with stdin/stdout/stderr redirected to that
27646 terminal, and then creating an MI interpreter running on a specified
27647 input/output device. The console interpreter created by @value{GDBN}
27648 at startup handles commands the user types in the terminal widget,
27649 while the GUI controls and synchronizes state with @value{GDBN} using
27650 the separate MI interpreter.
27651
27652 To start a new secondary @dfn{user interface} running MI, use the
27653 @code{new-ui} command:
27654
27655 @kindex new-ui
27656 @cindex new user interface
27657 @smallexample
27658 new-ui @var{interpreter} @var{tty}
27659 @end smallexample
27660
27661 The @var{interpreter} parameter specifies the interpreter to run.
27662 This accepts the same values as the @code{interpreter-exec} command.
27663 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27664 @var{tty} parameter specifies the name of the bidirectional file the
27665 interpreter uses for input/output, usually the name of a
27666 pseudoterminal slave on Unix systems. For example:
27667
27668 @smallexample
27669 (@value{GDBP}) new-ui mi /dev/pts/9
27670 @end smallexample
27671
27672 @noindent
27673 runs an MI interpreter on @file{/dev/pts/9}.
27674
27675 @node TUI
27676 @chapter @value{GDBN} Text User Interface
27677 @cindex TUI
27678 @cindex Text User Interface
27679
27680 @menu
27681 * TUI Overview:: TUI overview
27682 * TUI Keys:: TUI key bindings
27683 * TUI Single Key Mode:: TUI single key mode
27684 * TUI Commands:: TUI-specific commands
27685 * TUI Configuration:: TUI configuration variables
27686 @end menu
27687
27688 The @value{GDBN} Text User Interface (TUI) is a terminal
27689 interface which uses the @code{curses} library to show the source
27690 file, the assembly output, the program registers and @value{GDBN}
27691 commands in separate text windows. The TUI mode is supported only
27692 on platforms where a suitable version of the @code{curses} library
27693 is available.
27694
27695 The TUI mode is enabled by default when you invoke @value{GDBN} as
27696 @samp{@value{GDBP} -tui}.
27697 You can also switch in and out of TUI mode while @value{GDBN} runs by
27698 using various TUI commands and key bindings, such as @command{tui
27699 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
27700 @ref{TUI Keys, ,TUI Key Bindings}.
27701
27702 @node TUI Overview
27703 @section TUI Overview
27704
27705 In TUI mode, @value{GDBN} can display several text windows:
27706
27707 @table @emph
27708 @item command
27709 This window is the @value{GDBN} command window with the @value{GDBN}
27710 prompt and the @value{GDBN} output. The @value{GDBN} input is still
27711 managed using readline.
27712
27713 @item source
27714 The source window shows the source file of the program. The current
27715 line and active breakpoints are displayed in this window.
27716
27717 @item assembly
27718 The assembly window shows the disassembly output of the program.
27719
27720 @item register
27721 This window shows the processor registers. Registers are highlighted
27722 when their values change.
27723 @end table
27724
27725 The source and assembly windows show the current program position
27726 by highlighting the current line and marking it with a @samp{>} marker.
27727 Breakpoints are indicated with two markers. The first marker
27728 indicates the breakpoint type:
27729
27730 @table @code
27731 @item B
27732 Breakpoint which was hit at least once.
27733
27734 @item b
27735 Breakpoint which was never hit.
27736
27737 @item H
27738 Hardware breakpoint which was hit at least once.
27739
27740 @item h
27741 Hardware breakpoint which was never hit.
27742 @end table
27743
27744 The second marker indicates whether the breakpoint is enabled or not:
27745
27746 @table @code
27747 @item +
27748 Breakpoint is enabled.
27749
27750 @item -
27751 Breakpoint is disabled.
27752 @end table
27753
27754 The source, assembly and register windows are updated when the current
27755 thread changes, when the frame changes, or when the program counter
27756 changes.
27757
27758 These windows are not all visible at the same time. The command
27759 window is always visible. The others can be arranged in several
27760 layouts:
27761
27762 @itemize @bullet
27763 @item
27764 source only,
27765
27766 @item
27767 assembly only,
27768
27769 @item
27770 source and assembly,
27771
27772 @item
27773 source and registers, or
27774
27775 @item
27776 assembly and registers.
27777 @end itemize
27778
27779 These are the standard layouts, but other layouts can be defined.
27780
27781 A status line above the command window shows the following information:
27782
27783 @table @emph
27784 @item target
27785 Indicates the current @value{GDBN} target.
27786 (@pxref{Targets, ,Specifying a Debugging Target}).
27787
27788 @item process
27789 Gives the current process or thread number.
27790 When no process is being debugged, this field is set to @code{No process}.
27791
27792 @item function
27793 Gives the current function name for the selected frame.
27794 The name is demangled if demangling is turned on (@pxref{Print Settings}).
27795 When there is no symbol corresponding to the current program counter,
27796 the string @code{??} is displayed.
27797
27798 @item line
27799 Indicates the current line number for the selected frame.
27800 When the current line number is not known, the string @code{??} is displayed.
27801
27802 @item pc
27803 Indicates the current program counter address.
27804 @end table
27805
27806 @node TUI Keys
27807 @section TUI Key Bindings
27808 @cindex TUI key bindings
27809
27810 The TUI installs several key bindings in the readline keymaps
27811 @ifset SYSTEM_READLINE
27812 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27813 @end ifset
27814 @ifclear SYSTEM_READLINE
27815 (@pxref{Command Line Editing}).
27816 @end ifclear
27817 The following key bindings are installed for both TUI mode and the
27818 @value{GDBN} standard mode.
27819
27820 @table @kbd
27821 @kindex C-x C-a
27822 @item C-x C-a
27823 @kindex C-x a
27824 @itemx C-x a
27825 @kindex C-x A
27826 @itemx C-x A
27827 Enter or leave the TUI mode. When leaving the TUI mode,
27828 the curses window management stops and @value{GDBN} operates using
27829 its standard mode, writing on the terminal directly. When reentering
27830 the TUI mode, control is given back to the curses windows.
27831 The screen is then refreshed.
27832
27833 This key binding uses the bindable Readline function
27834 @code{tui-switch-mode}.
27835
27836 @kindex C-x 1
27837 @item C-x 1
27838 Use a TUI layout with only one window. The layout will
27839 either be @samp{source} or @samp{assembly}. When the TUI mode
27840 is not active, it will switch to the TUI mode.
27841
27842 Think of this key binding as the Emacs @kbd{C-x 1} binding.
27843
27844 This key binding uses the bindable Readline function
27845 @code{tui-delete-other-windows}.
27846
27847 @kindex C-x 2
27848 @item C-x 2
27849 Use a TUI layout with at least two windows. When the current
27850 layout already has two windows, the next layout with two windows is used.
27851 When a new layout is chosen, one window will always be common to the
27852 previous layout and the new one.
27853
27854 Think of it as the Emacs @kbd{C-x 2} binding.
27855
27856 This key binding uses the bindable Readline function
27857 @code{tui-change-windows}.
27858
27859 @kindex C-x o
27860 @item C-x o
27861 Change the active window. The TUI associates several key bindings
27862 (like scrolling and arrow keys) with the active window. This command
27863 gives the focus to the next TUI window.
27864
27865 Think of it as the Emacs @kbd{C-x o} binding.
27866
27867 This key binding uses the bindable Readline function
27868 @code{tui-other-window}.
27869
27870 @kindex C-x s
27871 @item C-x s
27872 Switch in and out of the TUI SingleKey mode that binds single
27873 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
27874
27875 This key binding uses the bindable Readline function
27876 @code{next-keymap}.
27877 @end table
27878
27879 The following key bindings only work in the TUI mode:
27880
27881 @table @asis
27882 @kindex PgUp
27883 @item @key{PgUp}
27884 Scroll the active window one page up.
27885
27886 @kindex PgDn
27887 @item @key{PgDn}
27888 Scroll the active window one page down.
27889
27890 @kindex Up
27891 @item @key{Up}
27892 Scroll the active window one line up.
27893
27894 @kindex Down
27895 @item @key{Down}
27896 Scroll the active window one line down.
27897
27898 @kindex Left
27899 @item @key{Left}
27900 Scroll the active window one column left.
27901
27902 @kindex Right
27903 @item @key{Right}
27904 Scroll the active window one column right.
27905
27906 @kindex C-L
27907 @item @kbd{C-L}
27908 Refresh the screen.
27909 @end table
27910
27911 Because the arrow keys scroll the active window in the TUI mode, they
27912 are not available for their normal use by readline unless the command
27913 window has the focus. When another window is active, you must use
27914 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
27915 and @kbd{C-f} to control the command window.
27916
27917 @node TUI Single Key Mode
27918 @section TUI Single Key Mode
27919 @cindex TUI single key mode
27920
27921 The TUI also provides a @dfn{SingleKey} mode, which binds several
27922 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
27923 switch into this mode, where the following key bindings are used:
27924
27925 @table @kbd
27926 @kindex c @r{(SingleKey TUI key)}
27927 @item c
27928 continue
27929
27930 @kindex d @r{(SingleKey TUI key)}
27931 @item d
27932 down
27933
27934 @kindex f @r{(SingleKey TUI key)}
27935 @item f
27936 finish
27937
27938 @kindex n @r{(SingleKey TUI key)}
27939 @item n
27940 next
27941
27942 @kindex o @r{(SingleKey TUI key)}
27943 @item o
27944 nexti. The shortcut letter @samp{o} stands for ``step Over''.
27945
27946 @kindex q @r{(SingleKey TUI key)}
27947 @item q
27948 exit the SingleKey mode.
27949
27950 @kindex r @r{(SingleKey TUI key)}
27951 @item r
27952 run
27953
27954 @kindex s @r{(SingleKey TUI key)}
27955 @item s
27956 step
27957
27958 @kindex i @r{(SingleKey TUI key)}
27959 @item i
27960 stepi. The shortcut letter @samp{i} stands for ``step Into''.
27961
27962 @kindex u @r{(SingleKey TUI key)}
27963 @item u
27964 up
27965
27966 @kindex v @r{(SingleKey TUI key)}
27967 @item v
27968 info locals
27969
27970 @kindex w @r{(SingleKey TUI key)}
27971 @item w
27972 where
27973 @end table
27974
27975 Other keys temporarily switch to the @value{GDBN} command prompt.
27976 The key that was pressed is inserted in the editing buffer so that
27977 it is possible to type most @value{GDBN} commands without interaction
27978 with the TUI SingleKey mode. Once the command is entered the TUI
27979 SingleKey mode is restored. The only way to permanently leave
27980 this mode is by typing @kbd{q} or @kbd{C-x s}.
27981
27982 @cindex SingleKey keymap name
27983 If @value{GDBN} was built with Readline 8.0 or later, the TUI
27984 SingleKey keymap will be named @samp{SingleKey}. This can be used in
27985 @file{.inputrc} to add additional bindings to this keymap.
27986
27987 @node TUI Commands
27988 @section TUI-specific Commands
27989 @cindex TUI commands
27990
27991 The TUI has specific commands to control the text windows.
27992 These commands are always available, even when @value{GDBN} is not in
27993 the TUI mode. When @value{GDBN} is in the standard mode, most
27994 of these commands will automatically switch to the TUI mode.
27995
27996 Note that if @value{GDBN}'s @code{stdout} is not connected to a
27997 terminal, or @value{GDBN} has been started with the machine interface
27998 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27999 these commands will fail with an error, because it would not be
28000 possible or desirable to enable curses window management.
28001
28002 @table @code
28003 @item tui enable
28004 @kindex tui enable
28005 Activate TUI mode. The last active TUI window layout will be used if
28006 TUI mode has previously been used in the current debugging session,
28007 otherwise a default layout is used.
28008
28009 @item tui disable
28010 @kindex tui disable
28011 Disable TUI mode, returning to the console interpreter.
28012
28013 @item info win
28014 @kindex info win
28015 List and give the size of all displayed windows.
28016
28017 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28018 @kindex tui new-layout
28019 Create a new TUI layout. The new layout will be named @var{name}, and
28020 can be accessed using the @code{layout} command (see below).
28021
28022 Each @var{window} parameter is either the name of a window to display,
28023 or a window description. The windows will be displayed from top to
28024 bottom in the order listed.
28025
28026 The names of the windows are the same as the ones given to the
28027 @code{focus} command (see below); additional, the @code{status}
28028 window can be specified. Note that, because it is of fixed height,
28029 the weight assigned to the status window is of no importance. It is
28030 conventional to use @samp{0} here.
28031
28032 A window description looks a bit like an invocation of @code{tui
28033 new-layout}, and is of the form
28034 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28035
28036 This specifies a sub-layout. If @code{-horizontal} is given, the
28037 windows in this description will be arranged side-by-side, rather than
28038 top-to-bottom.
28039
28040 Each @var{weight} is an integer. It is the weight of this window
28041 relative to all the other windows in the layout. These numbers are
28042 used to calculate how much of the screen is given to each window.
28043
28044 For example:
28045
28046 @example
28047 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28048 @end example
28049
28050 Here, the new layout is called @samp{example}. It shows the source
28051 and register windows, followed by the status window, and then finally
28052 the command window. The non-status windows all have the same weight,
28053 so the terminal will be split into three roughly equal sections.
28054
28055 Here is a more complex example, showing a horizontal layout:
28056
28057 @example
28058 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28059 @end example
28060
28061 This will result in side-by-side source and assembly windows; with the
28062 status and command window being beneath these, filling the entire
28063 width of the terminal. Because they have weight 2, the source and
28064 assembly windows will be twice the height of the command window.
28065
28066 @item layout @var{name}
28067 @kindex layout
28068 Changes which TUI windows are displayed. The @var{name} parameter
28069 controls which layout is shown. It can be either one of the built-in
28070 layout names, or the name of a layout defined by the user using
28071 @code{tui new-layout}.
28072
28073 The built-in layouts are as follows:
28074
28075 @table @code
28076 @item next
28077 Display the next layout.
28078
28079 @item prev
28080 Display the previous layout.
28081
28082 @item src
28083 Display the source and command windows.
28084
28085 @item asm
28086 Display the assembly and command windows.
28087
28088 @item split
28089 Display the source, assembly, and command windows.
28090
28091 @item regs
28092 When in @code{src} layout display the register, source, and command
28093 windows. When in @code{asm} or @code{split} layout display the
28094 register, assembler, and command windows.
28095 @end table
28096
28097 @item focus @var{name}
28098 @kindex focus
28099 Changes which TUI window is currently active for scrolling. The
28100 @var{name} parameter can be any of the following:
28101
28102 @table @code
28103 @item next
28104 Make the next window active for scrolling.
28105
28106 @item prev
28107 Make the previous window active for scrolling.
28108
28109 @item src
28110 Make the source window active for scrolling.
28111
28112 @item asm
28113 Make the assembly window active for scrolling.
28114
28115 @item regs
28116 Make the register window active for scrolling.
28117
28118 @item cmd
28119 Make the command window active for scrolling.
28120 @end table
28121
28122 @item refresh
28123 @kindex refresh
28124 Refresh the screen. This is similar to typing @kbd{C-L}.
28125
28126 @item tui reg @var{group}
28127 @kindex tui reg
28128 Changes the register group displayed in the tui register window to
28129 @var{group}. If the register window is not currently displayed this
28130 command will cause the register window to be displayed. The list of
28131 register groups, as well as their order is target specific. The
28132 following groups are available on most targets:
28133 @table @code
28134 @item next
28135 Repeatedly selecting this group will cause the display to cycle
28136 through all of the available register groups.
28137
28138 @item prev
28139 Repeatedly selecting this group will cause the display to cycle
28140 through all of the available register groups in the reverse order to
28141 @var{next}.
28142
28143 @item general
28144 Display the general registers.
28145 @item float
28146 Display the floating point registers.
28147 @item system
28148 Display the system registers.
28149 @item vector
28150 Display the vector registers.
28151 @item all
28152 Display all registers.
28153 @end table
28154
28155 @item update
28156 @kindex update
28157 Update the source window and the current execution point.
28158
28159 @item winheight @var{name} +@var{count}
28160 @itemx winheight @var{name} -@var{count}
28161 @kindex winheight
28162 Change the height of the window @var{name} by @var{count}
28163 lines. Positive counts increase the height, while negative counts
28164 decrease it. The @var{name} parameter can be one of @code{src} (the
28165 source window), @code{cmd} (the command window), @code{asm} (the
28166 disassembly window), or @code{regs} (the register display window).
28167 @end table
28168
28169 @node TUI Configuration
28170 @section TUI Configuration Variables
28171 @cindex TUI configuration variables
28172
28173 Several configuration variables control the appearance of TUI windows.
28174
28175 @table @code
28176 @item set tui border-kind @var{kind}
28177 @kindex set tui border-kind
28178 Select the border appearance for the source, assembly and register windows.
28179 The possible values are the following:
28180 @table @code
28181 @item space
28182 Use a space character to draw the border.
28183
28184 @item ascii
28185 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28186
28187 @item acs
28188 Use the Alternate Character Set to draw the border. The border is
28189 drawn using character line graphics if the terminal supports them.
28190 @end table
28191
28192 @item set tui border-mode @var{mode}
28193 @kindex set tui border-mode
28194 @itemx set tui active-border-mode @var{mode}
28195 @kindex set tui active-border-mode
28196 Select the display attributes for the borders of the inactive windows
28197 or the active window. The @var{mode} can be one of the following:
28198 @table @code
28199 @item normal
28200 Use normal attributes to display the border.
28201
28202 @item standout
28203 Use standout mode.
28204
28205 @item reverse
28206 Use reverse video mode.
28207
28208 @item half
28209 Use half bright mode.
28210
28211 @item half-standout
28212 Use half bright and standout mode.
28213
28214 @item bold
28215 Use extra bright or bold mode.
28216
28217 @item bold-standout
28218 Use extra bright or bold and standout mode.
28219 @end table
28220
28221 @item set tui tab-width @var{nchars}
28222 @kindex set tui tab-width
28223 @kindex tabset
28224 Set the width of tab stops to be @var{nchars} characters. This
28225 setting affects the display of TAB characters in the source and
28226 assembly windows.
28227
28228 @item set tui compact-source @r{[}on@r{|}off@r{]}
28229 @kindex set tui compact-source
28230 Set whether the TUI source window is displayed in ``compact'' form.
28231 The default display uses more space for line numbers and starts the
28232 source text at the next tab stop; the compact display uses only as
28233 much space as is needed for the line numbers in the current file, and
28234 only a single space to separate the line numbers from the source.
28235 @end table
28236
28237 Note that the colors of the TUI borders can be controlled using the
28238 appropriate @code{set style} commands. @xref{Output Styling}.
28239
28240 @node Emacs
28241 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28242
28243 @cindex Emacs
28244 @cindex @sc{gnu} Emacs
28245 A special interface allows you to use @sc{gnu} Emacs to view (and
28246 edit) the source files for the program you are debugging with
28247 @value{GDBN}.
28248
28249 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28250 executable file you want to debug as an argument. This command starts
28251 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28252 created Emacs buffer.
28253 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28254
28255 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28256 things:
28257
28258 @itemize @bullet
28259 @item
28260 All ``terminal'' input and output goes through an Emacs buffer, called
28261 the GUD buffer.
28262
28263 This applies both to @value{GDBN} commands and their output, and to the input
28264 and output done by the program you are debugging.
28265
28266 This is useful because it means that you can copy the text of previous
28267 commands and input them again; you can even use parts of the output
28268 in this way.
28269
28270 All the facilities of Emacs' Shell mode are available for interacting
28271 with your program. In particular, you can send signals the usual
28272 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28273 stop.
28274
28275 @item
28276 @value{GDBN} displays source code through Emacs.
28277
28278 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28279 source file for that frame and puts an arrow (@samp{=>}) at the
28280 left margin of the current line. Emacs uses a separate buffer for
28281 source display, and splits the screen to show both your @value{GDBN} session
28282 and the source.
28283
28284 Explicit @value{GDBN} @code{list} or search commands still produce output as
28285 usual, but you probably have no reason to use them from Emacs.
28286 @end itemize
28287
28288 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28289 a graphical mode, enabled by default, which provides further buffers
28290 that can control the execution and describe the state of your program.
28291 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28292
28293 If you specify an absolute file name when prompted for the @kbd{M-x
28294 gdb} argument, then Emacs sets your current working directory to where
28295 your program resides. If you only specify the file name, then Emacs
28296 sets your current working directory to the directory associated
28297 with the previous buffer. In this case, @value{GDBN} may find your
28298 program by searching your environment's @code{PATH} variable, but on
28299 some operating systems it might not find the source. So, although the
28300 @value{GDBN} input and output session proceeds normally, the auxiliary
28301 buffer does not display the current source and line of execution.
28302
28303 The initial working directory of @value{GDBN} is printed on the top
28304 line of the GUD buffer and this serves as a default for the commands
28305 that specify files for @value{GDBN} to operate on. @xref{Files,
28306 ,Commands to Specify Files}.
28307
28308 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28309 need to call @value{GDBN} by a different name (for example, if you
28310 keep several configurations around, with different names) you can
28311 customize the Emacs variable @code{gud-gdb-command-name} to run the
28312 one you want.
28313
28314 In the GUD buffer, you can use these special Emacs commands in
28315 addition to the standard Shell mode commands:
28316
28317 @table @kbd
28318 @item C-h m
28319 Describe the features of Emacs' GUD Mode.
28320
28321 @item C-c C-s
28322 Execute to another source line, like the @value{GDBN} @code{step} command; also
28323 update the display window to show the current file and location.
28324
28325 @item C-c C-n
28326 Execute to next source line in this function, skipping all function
28327 calls, like the @value{GDBN} @code{next} command. Then update the display window
28328 to show the current file and location.
28329
28330 @item C-c C-i
28331 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28332 display window accordingly.
28333
28334 @item C-c C-f
28335 Execute until exit from the selected stack frame, like the @value{GDBN}
28336 @code{finish} command.
28337
28338 @item C-c C-r
28339 Continue execution of your program, like the @value{GDBN} @code{continue}
28340 command.
28341
28342 @item C-c <
28343 Go up the number of frames indicated by the numeric argument
28344 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28345 like the @value{GDBN} @code{up} command.
28346
28347 @item C-c >
28348 Go down the number of frames indicated by the numeric argument, like the
28349 @value{GDBN} @code{down} command.
28350 @end table
28351
28352 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28353 tells @value{GDBN} to set a breakpoint on the source line point is on.
28354
28355 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28356 separate frame which shows a backtrace when the GUD buffer is current.
28357 Move point to any frame in the stack and type @key{RET} to make it
28358 become the current frame and display the associated source in the
28359 source buffer. Alternatively, click @kbd{Mouse-2} to make the
28360 selected frame become the current one. In graphical mode, the
28361 speedbar displays watch expressions.
28362
28363 If you accidentally delete the source-display buffer, an easy way to get
28364 it back is to type the command @code{f} in the @value{GDBN} buffer, to
28365 request a frame display; when you run under Emacs, this recreates
28366 the source buffer if necessary to show you the context of the current
28367 frame.
28368
28369 The source files displayed in Emacs are in ordinary Emacs buffers
28370 which are visiting the source files in the usual way. You can edit
28371 the files with these buffers if you wish; but keep in mind that @value{GDBN}
28372 communicates with Emacs in terms of line numbers. If you add or
28373 delete lines from the text, the line numbers that @value{GDBN} knows cease
28374 to correspond properly with the code.
28375
28376 A more detailed description of Emacs' interaction with @value{GDBN} is
28377 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28378 Emacs Manual}).
28379
28380 @node GDB/MI
28381 @chapter The @sc{gdb/mi} Interface
28382
28383 @unnumberedsec Function and Purpose
28384
28385 @cindex @sc{gdb/mi}, its purpose
28386 @sc{gdb/mi} is a line based machine oriented text interface to
28387 @value{GDBN} and is activated by specifying using the
28388 @option{--interpreter} command line option (@pxref{Mode Options}). It
28389 is specifically intended to support the development of systems which
28390 use the debugger as just one small component of a larger system.
28391
28392 This chapter is a specification of the @sc{gdb/mi} interface. It is written
28393 in the form of a reference manual.
28394
28395 Note that @sc{gdb/mi} is still under construction, so some of the
28396 features described below are incomplete and subject to change
28397 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28398
28399 @unnumberedsec Notation and Terminology
28400
28401 @cindex notational conventions, for @sc{gdb/mi}
28402 This chapter uses the following notation:
28403
28404 @itemize @bullet
28405 @item
28406 @code{|} separates two alternatives.
28407
28408 @item
28409 @code{[ @var{something} ]} indicates that @var{something} is optional:
28410 it may or may not be given.
28411
28412 @item
28413 @code{( @var{group} )*} means that @var{group} inside the parentheses
28414 may repeat zero or more times.
28415
28416 @item
28417 @code{( @var{group} )+} means that @var{group} inside the parentheses
28418 may repeat one or more times.
28419
28420 @item
28421 @code{"@var{string}"} means a literal @var{string}.
28422 @end itemize
28423
28424 @ignore
28425 @heading Dependencies
28426 @end ignore
28427
28428 @menu
28429 * GDB/MI General Design::
28430 * GDB/MI Command Syntax::
28431 * GDB/MI Compatibility with CLI::
28432 * GDB/MI Development and Front Ends::
28433 * GDB/MI Output Records::
28434 * GDB/MI Simple Examples::
28435 * GDB/MI Command Description Format::
28436 * GDB/MI Breakpoint Commands::
28437 * GDB/MI Catchpoint Commands::
28438 * GDB/MI Program Context::
28439 * GDB/MI Thread Commands::
28440 * GDB/MI Ada Tasking Commands::
28441 * GDB/MI Program Execution::
28442 * GDB/MI Stack Manipulation::
28443 * GDB/MI Variable Objects::
28444 * GDB/MI Data Manipulation::
28445 * GDB/MI Tracepoint Commands::
28446 * GDB/MI Symbol Query::
28447 * GDB/MI File Commands::
28448 @ignore
28449 * GDB/MI Kod Commands::
28450 * GDB/MI Memory Overlay Commands::
28451 * GDB/MI Signal Handling Commands::
28452 @end ignore
28453 * GDB/MI Target Manipulation::
28454 * GDB/MI File Transfer Commands::
28455 * GDB/MI Ada Exceptions Commands::
28456 * GDB/MI Support Commands::
28457 * GDB/MI Miscellaneous Commands::
28458 @end menu
28459
28460 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28461 @node GDB/MI General Design
28462 @section @sc{gdb/mi} General Design
28463 @cindex GDB/MI General Design
28464
28465 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28466 parts---commands sent to @value{GDBN}, responses to those commands
28467 and notifications. Each command results in exactly one response,
28468 indicating either successful completion of the command, or an error.
28469 For the commands that do not resume the target, the response contains the
28470 requested information. For the commands that resume the target, the
28471 response only indicates whether the target was successfully resumed.
28472 Notifications is the mechanism for reporting changes in the state of the
28473 target, or in @value{GDBN} state, that cannot conveniently be associated with
28474 a command and reported as part of that command response.
28475
28476 The important examples of notifications are:
28477 @itemize @bullet
28478
28479 @item
28480 Exec notifications. These are used to report changes in
28481 target state---when a target is resumed, or stopped. It would not
28482 be feasible to include this information in response of resuming
28483 commands, because one resume commands can result in multiple events in
28484 different threads. Also, quite some time may pass before any event
28485 happens in the target, while a frontend needs to know whether the resuming
28486 command itself was successfully executed.
28487
28488 @item
28489 Console output, and status notifications. Console output
28490 notifications are used to report output of CLI commands, as well as
28491 diagnostics for other commands. Status notifications are used to
28492 report the progress of a long-running operation. Naturally, including
28493 this information in command response would mean no output is produced
28494 until the command is finished, which is undesirable.
28495
28496 @item
28497 General notifications. Commands may have various side effects on
28498 the @value{GDBN} or target state beyond their official purpose. For example,
28499 a command may change the selected thread. Although such changes can
28500 be included in command response, using notification allows for more
28501 orthogonal frontend design.
28502
28503 @end itemize
28504
28505 There's no guarantee that whenever an MI command reports an error,
28506 @value{GDBN} or the target are in any specific state, and especially,
28507 the state is not reverted to the state before the MI command was
28508 processed. Therefore, whenever an MI command results in an error,
28509 we recommend that the frontend refreshes all the information shown in
28510 the user interface.
28511
28512
28513 @menu
28514 * Context management::
28515 * Asynchronous and non-stop modes::
28516 * Thread groups::
28517 @end menu
28518
28519 @node Context management
28520 @subsection Context management
28521
28522 @subsubsection Threads and Frames
28523
28524 In most cases when @value{GDBN} accesses the target, this access is
28525 done in context of a specific thread and frame (@pxref{Frames}).
28526 Often, even when accessing global data, the target requires that a thread
28527 be specified. The CLI interface maintains the selected thread and frame,
28528 and supplies them to target on each command. This is convenient,
28529 because a command line user would not want to specify that information
28530 explicitly on each command, and because user interacts with
28531 @value{GDBN} via a single terminal, so no confusion is possible as
28532 to what thread and frame are the current ones.
28533
28534 In the case of MI, the concept of selected thread and frame is less
28535 useful. First, a frontend can easily remember this information
28536 itself. Second, a graphical frontend can have more than one window,
28537 each one used for debugging a different thread, and the frontend might
28538 want to access additional threads for internal purposes. This
28539 increases the risk that by relying on implicitly selected thread, the
28540 frontend may be operating on a wrong one. Therefore, each MI command
28541 should explicitly specify which thread and frame to operate on. To
28542 make it possible, each MI command accepts the @samp{--thread} and
28543 @samp{--frame} options, the value to each is @value{GDBN} global
28544 identifier for thread and frame to operate on.
28545
28546 Usually, each top-level window in a frontend allows the user to select
28547 a thread and a frame, and remembers the user selection for further
28548 operations. However, in some cases @value{GDBN} may suggest that the
28549 current thread or frame be changed. For example, when stopping on a
28550 breakpoint it is reasonable to switch to the thread where breakpoint is
28551 hit. For another example, if the user issues the CLI @samp{thread} or
28552 @samp{frame} commands via the frontend, it is desirable to change the
28553 frontend's selection to the one specified by user. @value{GDBN}
28554 communicates the suggestion to change current thread and frame using the
28555 @samp{=thread-selected} notification.
28556
28557 Note that historically, MI shares the selected thread with CLI, so
28558 frontends used the @code{-thread-select} to execute commands in the
28559 right context. However, getting this to work right is cumbersome. The
28560 simplest way is for frontend to emit @code{-thread-select} command
28561 before every command. This doubles the number of commands that need
28562 to be sent. The alternative approach is to suppress @code{-thread-select}
28563 if the selected thread in @value{GDBN} is supposed to be identical to the
28564 thread the frontend wants to operate on. However, getting this
28565 optimization right can be tricky. In particular, if the frontend
28566 sends several commands to @value{GDBN}, and one of the commands changes the
28567 selected thread, then the behaviour of subsequent commands will
28568 change. So, a frontend should either wait for response from such
28569 problematic commands, or explicitly add @code{-thread-select} for
28570 all subsequent commands. No frontend is known to do this exactly
28571 right, so it is suggested to just always pass the @samp{--thread} and
28572 @samp{--frame} options.
28573
28574 @subsubsection Language
28575
28576 The execution of several commands depends on which language is selected.
28577 By default, the current language (@pxref{show language}) is used.
28578 But for commands known to be language-sensitive, it is recommended
28579 to use the @samp{--language} option. This option takes one argument,
28580 which is the name of the language to use while executing the command.
28581 For instance:
28582
28583 @smallexample
28584 -data-evaluate-expression --language c "sizeof (void*)"
28585 ^done,value="4"
28586 (gdb)
28587 @end smallexample
28588
28589 The valid language names are the same names accepted by the
28590 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28591 @samp{local} or @samp{unknown}.
28592
28593 @node Asynchronous and non-stop modes
28594 @subsection Asynchronous command execution and non-stop mode
28595
28596 On some targets, @value{GDBN} is capable of processing MI commands
28597 even while the target is running. This is called @dfn{asynchronous
28598 command execution} (@pxref{Background Execution}). The frontend may
28599 specify a preference for asynchronous execution using the
28600 @code{-gdb-set mi-async 1} command, which should be emitted before
28601 either running the executable or attaching to the target. After the
28602 frontend has started the executable or attached to the target, it can
28603 find if asynchronous execution is enabled using the
28604 @code{-list-target-features} command.
28605
28606 @table @code
28607 @item -gdb-set mi-async on
28608 @item -gdb-set mi-async off
28609 Set whether MI is in asynchronous mode.
28610
28611 When @code{off}, which is the default, MI execution commands (e.g.,
28612 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28613 for the program to stop before processing further commands.
28614
28615 When @code{on}, MI execution commands are background execution
28616 commands (e.g., @code{-exec-continue} becomes the equivalent of the
28617 @code{c&} CLI command), and so @value{GDBN} is capable of processing
28618 MI commands even while the target is running.
28619
28620 @item -gdb-show mi-async
28621 Show whether MI asynchronous mode is enabled.
28622 @end table
28623
28624 Note: In @value{GDBN} version 7.7 and earlier, this option was called
28625 @code{target-async} instead of @code{mi-async}, and it had the effect
28626 of both putting MI in asynchronous mode and making CLI background
28627 commands possible. CLI background commands are now always possible
28628 ``out of the box'' if the target supports them. The old spelling is
28629 kept as a deprecated alias for backwards compatibility.
28630
28631 Even if @value{GDBN} can accept a command while target is running,
28632 many commands that access the target do not work when the target is
28633 running. Therefore, asynchronous command execution is most useful
28634 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28635 it is possible to examine the state of one thread, while other threads
28636 are running.
28637
28638 When a given thread is running, MI commands that try to access the
28639 target in the context of that thread may not work, or may work only on
28640 some targets. In particular, commands that try to operate on thread's
28641 stack will not work, on any target. Commands that read memory, or
28642 modify breakpoints, may work or not work, depending on the target. Note
28643 that even commands that operate on global state, such as @code{print},
28644 @code{set}, and breakpoint commands, still access the target in the
28645 context of a specific thread, so frontend should try to find a
28646 stopped thread and perform the operation on that thread (using the
28647 @samp{--thread} option).
28648
28649 Which commands will work in the context of a running thread is
28650 highly target dependent. However, the two commands
28651 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28652 to find the state of a thread, will always work.
28653
28654 @node Thread groups
28655 @subsection Thread groups
28656 @value{GDBN} may be used to debug several processes at the same time.
28657 On some platforms, @value{GDBN} may support debugging of several
28658 hardware systems, each one having several cores with several different
28659 processes running on each core. This section describes the MI
28660 mechanism to support such debugging scenarios.
28661
28662 The key observation is that regardless of the structure of the
28663 target, MI can have a global list of threads, because most commands that
28664 accept the @samp{--thread} option do not need to know what process that
28665 thread belongs to. Therefore, it is not necessary to introduce
28666 neither additional @samp{--process} option, nor an notion of the
28667 current process in the MI interface. The only strictly new feature
28668 that is required is the ability to find how the threads are grouped
28669 into processes.
28670
28671 To allow the user to discover such grouping, and to support arbitrary
28672 hierarchy of machines/cores/processes, MI introduces the concept of a
28673 @dfn{thread group}. Thread group is a collection of threads and other
28674 thread groups. A thread group always has a string identifier, a type,
28675 and may have additional attributes specific to the type. A new
28676 command, @code{-list-thread-groups}, returns the list of top-level
28677 thread groups, which correspond to processes that @value{GDBN} is
28678 debugging at the moment. By passing an identifier of a thread group
28679 to the @code{-list-thread-groups} command, it is possible to obtain
28680 the members of specific thread group.
28681
28682 To allow the user to easily discover processes, and other objects, he
28683 wishes to debug, a concept of @dfn{available thread group} is
28684 introduced. Available thread group is an thread group that
28685 @value{GDBN} is not debugging, but that can be attached to, using the
28686 @code{-target-attach} command. The list of available top-level thread
28687 groups can be obtained using @samp{-list-thread-groups --available}.
28688 In general, the content of a thread group may be only retrieved only
28689 after attaching to that thread group.
28690
28691 Thread groups are related to inferiors (@pxref{Inferiors Connections and
28692 Programs}). Each inferior corresponds to a thread group of a special
28693 type @samp{process}, and some additional operations are permitted on
28694 such thread groups.
28695
28696 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28697 @node GDB/MI Command Syntax
28698 @section @sc{gdb/mi} Command Syntax
28699
28700 @menu
28701 * GDB/MI Input Syntax::
28702 * GDB/MI Output Syntax::
28703 @end menu
28704
28705 @node GDB/MI Input Syntax
28706 @subsection @sc{gdb/mi} Input Syntax
28707
28708 @cindex input syntax for @sc{gdb/mi}
28709 @cindex @sc{gdb/mi}, input syntax
28710 @table @code
28711 @item @var{command} @expansion{}
28712 @code{@var{cli-command} | @var{mi-command}}
28713
28714 @item @var{cli-command} @expansion{}
28715 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28716 @var{cli-command} is any existing @value{GDBN} CLI command.
28717
28718 @item @var{mi-command} @expansion{}
28719 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28720 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28721
28722 @item @var{token} @expansion{}
28723 "any sequence of digits"
28724
28725 @item @var{option} @expansion{}
28726 @code{"-" @var{parameter} [ " " @var{parameter} ]}
28727
28728 @item @var{parameter} @expansion{}
28729 @code{@var{non-blank-sequence} | @var{c-string}}
28730
28731 @item @var{operation} @expansion{}
28732 @emph{any of the operations described in this chapter}
28733
28734 @item @var{non-blank-sequence} @expansion{}
28735 @emph{anything, provided it doesn't contain special characters such as
28736 "-", @var{nl}, """ and of course " "}
28737
28738 @item @var{c-string} @expansion{}
28739 @code{""" @var{seven-bit-iso-c-string-content} """}
28740
28741 @item @var{nl} @expansion{}
28742 @code{CR | CR-LF}
28743 @end table
28744
28745 @noindent
28746 Notes:
28747
28748 @itemize @bullet
28749 @item
28750 The CLI commands are still handled by the @sc{mi} interpreter; their
28751 output is described below.
28752
28753 @item
28754 The @code{@var{token}}, when present, is passed back when the command
28755 finishes.
28756
28757 @item
28758 Some @sc{mi} commands accept optional arguments as part of the parameter
28759 list. Each option is identified by a leading @samp{-} (dash) and may be
28760 followed by an optional argument parameter. Options occur first in the
28761 parameter list and can be delimited from normal parameters using
28762 @samp{--} (this is useful when some parameters begin with a dash).
28763 @end itemize
28764
28765 Pragmatics:
28766
28767 @itemize @bullet
28768 @item
28769 We want easy access to the existing CLI syntax (for debugging).
28770
28771 @item
28772 We want it to be easy to spot a @sc{mi} operation.
28773 @end itemize
28774
28775 @node GDB/MI Output Syntax
28776 @subsection @sc{gdb/mi} Output Syntax
28777
28778 @cindex output syntax of @sc{gdb/mi}
28779 @cindex @sc{gdb/mi}, output syntax
28780 The output from @sc{gdb/mi} consists of zero or more out-of-band records
28781 followed, optionally, by a single result record. This result record
28782 is for the most recent command. The sequence of output records is
28783 terminated by @samp{(gdb)}.
28784
28785 If an input command was prefixed with a @code{@var{token}} then the
28786 corresponding output for that command will also be prefixed by that same
28787 @var{token}.
28788
28789 @table @code
28790 @item @var{output} @expansion{}
28791 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
28792
28793 @item @var{result-record} @expansion{}
28794 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28795
28796 @item @var{out-of-band-record} @expansion{}
28797 @code{@var{async-record} | @var{stream-record}}
28798
28799 @item @var{async-record} @expansion{}
28800 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28801
28802 @item @var{exec-async-output} @expansion{}
28803 @code{[ @var{token} ] "*" @var{async-output nl}}
28804
28805 @item @var{status-async-output} @expansion{}
28806 @code{[ @var{token} ] "+" @var{async-output nl}}
28807
28808 @item @var{notify-async-output} @expansion{}
28809 @code{[ @var{token} ] "=" @var{async-output nl}}
28810
28811 @item @var{async-output} @expansion{}
28812 @code{@var{async-class} ( "," @var{result} )*}
28813
28814 @item @var{result-class} @expansion{}
28815 @code{"done" | "running" | "connected" | "error" | "exit"}
28816
28817 @item @var{async-class} @expansion{}
28818 @code{"stopped" | @var{others}} (where @var{others} will be added
28819 depending on the needs---this is still in development).
28820
28821 @item @var{result} @expansion{}
28822 @code{ @var{variable} "=" @var{value}}
28823
28824 @item @var{variable} @expansion{}
28825 @code{ @var{string} }
28826
28827 @item @var{value} @expansion{}
28828 @code{ @var{const} | @var{tuple} | @var{list} }
28829
28830 @item @var{const} @expansion{}
28831 @code{@var{c-string}}
28832
28833 @item @var{tuple} @expansion{}
28834 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28835
28836 @item @var{list} @expansion{}
28837 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28838 @var{result} ( "," @var{result} )* "]" }
28839
28840 @item @var{stream-record} @expansion{}
28841 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28842
28843 @item @var{console-stream-output} @expansion{}
28844 @code{"~" @var{c-string nl}}
28845
28846 @item @var{target-stream-output} @expansion{}
28847 @code{"@@" @var{c-string nl}}
28848
28849 @item @var{log-stream-output} @expansion{}
28850 @code{"&" @var{c-string nl}}
28851
28852 @item @var{nl} @expansion{}
28853 @code{CR | CR-LF}
28854
28855 @item @var{token} @expansion{}
28856 @emph{any sequence of digits}.
28857 @end table
28858
28859 @noindent
28860 Notes:
28861
28862 @itemize @bullet
28863 @item
28864 All output sequences end in a single line containing a period.
28865
28866 @item
28867 The @code{@var{token}} is from the corresponding request. Note that
28868 for all async output, while the token is allowed by the grammar and
28869 may be output by future versions of @value{GDBN} for select async
28870 output messages, it is generally omitted. Frontends should treat
28871 all async output as reporting general changes in the state of the
28872 target and there should be no need to associate async output to any
28873 prior command.
28874
28875 @item
28876 @cindex status output in @sc{gdb/mi}
28877 @var{status-async-output} contains on-going status information about the
28878 progress of a slow operation. It can be discarded. All status output is
28879 prefixed by @samp{+}.
28880
28881 @item
28882 @cindex async output in @sc{gdb/mi}
28883 @var{exec-async-output} contains asynchronous state change on the target
28884 (stopped, started, disappeared). All async output is prefixed by
28885 @samp{*}.
28886
28887 @item
28888 @cindex notify output in @sc{gdb/mi}
28889 @var{notify-async-output} contains supplementary information that the
28890 client should handle (e.g., a new breakpoint information). All notify
28891 output is prefixed by @samp{=}.
28892
28893 @item
28894 @cindex console output in @sc{gdb/mi}
28895 @var{console-stream-output} is output that should be displayed as is in the
28896 console. It is the textual response to a CLI command. All the console
28897 output is prefixed by @samp{~}.
28898
28899 @item
28900 @cindex target output in @sc{gdb/mi}
28901 @var{target-stream-output} is the output produced by the target program.
28902 All the target output is prefixed by @samp{@@}.
28903
28904 @item
28905 @cindex log output in @sc{gdb/mi}
28906 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
28907 instance messages that should be displayed as part of an error log. All
28908 the log output is prefixed by @samp{&}.
28909
28910 @item
28911 @cindex list output in @sc{gdb/mi}
28912 New @sc{gdb/mi} commands should only output @var{lists} containing
28913 @var{values}.
28914
28915
28916 @end itemize
28917
28918 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
28919 details about the various output records.
28920
28921 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28922 @node GDB/MI Compatibility with CLI
28923 @section @sc{gdb/mi} Compatibility with CLI
28924
28925 @cindex compatibility, @sc{gdb/mi} and CLI
28926 @cindex @sc{gdb/mi}, compatibility with CLI
28927
28928 For the developers convenience CLI commands can be entered directly,
28929 but there may be some unexpected behaviour. For example, commands
28930 that query the user will behave as if the user replied yes, breakpoint
28931 command lists are not executed and some CLI commands, such as
28932 @code{if}, @code{when} and @code{define}, prompt for further input with
28933 @samp{>}, which is not valid MI output.
28934
28935 This feature may be removed at some stage in the future and it is
28936 recommended that front ends use the @code{-interpreter-exec} command
28937 (@pxref{-interpreter-exec}).
28938
28939 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28940 @node GDB/MI Development and Front Ends
28941 @section @sc{gdb/mi} Development and Front Ends
28942 @cindex @sc{gdb/mi} development
28943
28944 The application which takes the MI output and presents the state of the
28945 program being debugged to the user is called a @dfn{front end}.
28946
28947 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
28948 to the MI interface may break existing usage. This section describes how the
28949 protocol changes and how to request previous version of the protocol when it
28950 does.
28951
28952 Some changes in MI need not break a carefully designed front end, and
28953 for these the MI version will remain unchanged. The following is a
28954 list of changes that may occur within one level, so front ends should
28955 parse MI output in a way that can handle them:
28956
28957 @itemize @bullet
28958 @item
28959 New MI commands may be added.
28960
28961 @item
28962 New fields may be added to the output of any MI command.
28963
28964 @item
28965 The range of values for fields with specified values, e.g.,
28966 @code{in_scope} (@pxref{-var-update}) may be extended.
28967
28968 @c The format of field's content e.g type prefix, may change so parse it
28969 @c at your own risk. Yes, in general?
28970
28971 @c The order of fields may change? Shouldn't really matter but it might
28972 @c resolve inconsistencies.
28973 @end itemize
28974
28975 If the changes are likely to break front ends, the MI version level
28976 will be increased by one. The new versions of the MI protocol are not compatible
28977 with the old versions. Old versions of MI remain available, allowing front ends
28978 to keep using them until they are modified to use the latest MI version.
28979
28980 Since @code{--interpreter=mi} always points to the latest MI version, it is
28981 recommended that front ends request a specific version of MI when launching
28982 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
28983 interpreter with the MI version they expect.
28984
28985 The following table gives a summary of the released versions of the MI
28986 interface: the version number, the version of GDB in which it first appeared
28987 and the breaking changes compared to the previous version.
28988
28989 @multitable @columnfractions .05 .05 .9
28990 @headitem MI version @tab GDB version @tab Breaking changes
28991
28992 @item
28993 @center 1
28994 @tab
28995 @center 5.1
28996 @tab
28997 None
28998
28999 @item
29000 @center 2
29001 @tab
29002 @center 6.0
29003 @tab
29004
29005 @itemize
29006 @item
29007 The @code{-environment-pwd}, @code{-environment-directory} and
29008 @code{-environment-path} commands now returns values using the MI output
29009 syntax, rather than CLI output syntax.
29010
29011 @item
29012 @code{-var-list-children}'s @code{children} result field is now a list, rather
29013 than a tuple.
29014
29015 @item
29016 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29017 a tuple.
29018 @end itemize
29019
29020 @item
29021 @center 3
29022 @tab
29023 @center 9.1
29024 @tab
29025
29026 @itemize
29027 @item
29028 The output of information about multi-location breakpoints has changed in the
29029 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29030 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29031 The multiple locations are now placed in a @code{locations} field, whose value
29032 is a list.
29033 @end itemize
29034
29035 @end multitable
29036
29037 If your front end cannot yet migrate to a more recent version of the
29038 MI protocol, you can nevertheless selectively enable specific features
29039 available in those recent MI versions, using the following commands:
29040
29041 @table @code
29042
29043 @item -fix-multi-location-breakpoint-output
29044 Use the output for multi-location breakpoints which was introduced by
29045 MI 3, even when using MI versions 2 or 1. This command has no
29046 effect when using MI version 3 or later.
29047
29048 @end table
29049
29050 The best way to avoid unexpected changes in MI that might break your front
29051 end is to make your project known to @value{GDBN} developers and
29052 follow development on @email{gdb@@sourceware.org} and
29053 @email{gdb-patches@@sourceware.org}.
29054 @cindex mailing lists
29055
29056 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29057 @node GDB/MI Output Records
29058 @section @sc{gdb/mi} Output Records
29059
29060 @menu
29061 * GDB/MI Result Records::
29062 * GDB/MI Stream Records::
29063 * GDB/MI Async Records::
29064 * GDB/MI Breakpoint Information::
29065 * GDB/MI Frame Information::
29066 * GDB/MI Thread Information::
29067 * GDB/MI Ada Exception Information::
29068 @end menu
29069
29070 @node GDB/MI Result Records
29071 @subsection @sc{gdb/mi} Result Records
29072
29073 @cindex result records in @sc{gdb/mi}
29074 @cindex @sc{gdb/mi}, result records
29075 In addition to a number of out-of-band notifications, the response to a
29076 @sc{gdb/mi} command includes one of the following result indications:
29077
29078 @table @code
29079 @findex ^done
29080 @item "^done" [ "," @var{results} ]
29081 The synchronous operation was successful, @code{@var{results}} are the return
29082 values.
29083
29084 @item "^running"
29085 @findex ^running
29086 This result record is equivalent to @samp{^done}. Historically, it
29087 was output instead of @samp{^done} if the command has resumed the
29088 target. This behaviour is maintained for backward compatibility, but
29089 all frontends should treat @samp{^done} and @samp{^running}
29090 identically and rely on the @samp{*running} output record to determine
29091 which threads are resumed.
29092
29093 @item "^connected"
29094 @findex ^connected
29095 @value{GDBN} has connected to a remote target.
29096
29097 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29098 @findex ^error
29099 The operation failed. The @code{msg=@var{c-string}} variable contains
29100 the corresponding error message.
29101
29102 If present, the @code{code=@var{c-string}} variable provides an error
29103 code on which consumers can rely on to detect the corresponding
29104 error condition. At present, only one error code is defined:
29105
29106 @table @samp
29107 @item "undefined-command"
29108 Indicates that the command causing the error does not exist.
29109 @end table
29110
29111 @item "^exit"
29112 @findex ^exit
29113 @value{GDBN} has terminated.
29114
29115 @end table
29116
29117 @node GDB/MI Stream Records
29118 @subsection @sc{gdb/mi} Stream Records
29119
29120 @cindex @sc{gdb/mi}, stream records
29121 @cindex stream records in @sc{gdb/mi}
29122 @value{GDBN} internally maintains a number of output streams: the console, the
29123 target, and the log. The output intended for each of these streams is
29124 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29125
29126 Each stream record begins with a unique @dfn{prefix character} which
29127 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29128 Syntax}). In addition to the prefix, each stream record contains a
29129 @code{@var{string-output}}. This is either raw text (with an implicit new
29130 line) or a quoted C string (which does not contain an implicit newline).
29131
29132 @table @code
29133 @item "~" @var{string-output}
29134 The console output stream contains text that should be displayed in the
29135 CLI console window. It contains the textual responses to CLI commands.
29136
29137 @item "@@" @var{string-output}
29138 The target output stream contains any textual output from the running
29139 target. This is only present when GDB's event loop is truly
29140 asynchronous, which is currently only the case for remote targets.
29141
29142 @item "&" @var{string-output}
29143 The log stream contains debugging messages being produced by @value{GDBN}'s
29144 internals.
29145 @end table
29146
29147 @node GDB/MI Async Records
29148 @subsection @sc{gdb/mi} Async Records
29149
29150 @cindex async records in @sc{gdb/mi}
29151 @cindex @sc{gdb/mi}, async records
29152 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29153 additional changes that have occurred. Those changes can either be a
29154 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29155 target activity (e.g., target stopped).
29156
29157 The following is the list of possible async records:
29158
29159 @table @code
29160
29161 @item *running,thread-id="@var{thread}"
29162 The target is now running. The @var{thread} field can be the global
29163 thread ID of the thread that is now running, and it can be
29164 @samp{all} if all threads are running. The frontend should assume
29165 that no interaction with a running thread is possible after this
29166 notification is produced. The frontend should not assume that this
29167 notification is output only once for any command. @value{GDBN} may
29168 emit this notification several times, either for different threads,
29169 because it cannot resume all threads together, or even for a single
29170 thread, if the thread must be stepped though some code before letting
29171 it run freely.
29172
29173 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29174 The target has stopped. The @var{reason} field can have one of the
29175 following values:
29176
29177 @table @code
29178 @item breakpoint-hit
29179 A breakpoint was reached.
29180 @item watchpoint-trigger
29181 A watchpoint was triggered.
29182 @item read-watchpoint-trigger
29183 A read watchpoint was triggered.
29184 @item access-watchpoint-trigger
29185 An access watchpoint was triggered.
29186 @item function-finished
29187 An -exec-finish or similar CLI command was accomplished.
29188 @item location-reached
29189 An -exec-until or similar CLI command was accomplished.
29190 @item watchpoint-scope
29191 A watchpoint has gone out of scope.
29192 @item end-stepping-range
29193 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29194 similar CLI command was accomplished.
29195 @item exited-signalled
29196 The inferior exited because of a signal.
29197 @item exited
29198 The inferior exited.
29199 @item exited-normally
29200 The inferior exited normally.
29201 @item signal-received
29202 A signal was received by the inferior.
29203 @item solib-event
29204 The inferior has stopped due to a library being loaded or unloaded.
29205 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29206 set or when a @code{catch load} or @code{catch unload} catchpoint is
29207 in use (@pxref{Set Catchpoints}).
29208 @item fork
29209 The inferior has forked. This is reported when @code{catch fork}
29210 (@pxref{Set Catchpoints}) has been used.
29211 @item vfork
29212 The inferior has vforked. This is reported in when @code{catch vfork}
29213 (@pxref{Set Catchpoints}) has been used.
29214 @item syscall-entry
29215 The inferior entered a system call. This is reported when @code{catch
29216 syscall} (@pxref{Set Catchpoints}) has been used.
29217 @item syscall-return
29218 The inferior returned from a system call. This is reported when
29219 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29220 @item exec
29221 The inferior called @code{exec}. This is reported when @code{catch exec}
29222 (@pxref{Set Catchpoints}) has been used.
29223 @end table
29224
29225 The @var{id} field identifies the global thread ID of the thread
29226 that directly caused the stop -- for example by hitting a breakpoint.
29227 Depending on whether all-stop
29228 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29229 stop all threads, or only the thread that directly triggered the stop.
29230 If all threads are stopped, the @var{stopped} field will have the
29231 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29232 field will be a list of thread identifiers. Presently, this list will
29233 always include a single thread, but frontend should be prepared to see
29234 several threads in the list. The @var{core} field reports the
29235 processor core on which the stop event has happened. This field may be absent
29236 if such information is not available.
29237
29238 @item =thread-group-added,id="@var{id}"
29239 @itemx =thread-group-removed,id="@var{id}"
29240 A thread group was either added or removed. The @var{id} field
29241 contains the @value{GDBN} identifier of the thread group. When a thread
29242 group is added, it generally might not be associated with a running
29243 process. When a thread group is removed, its id becomes invalid and
29244 cannot be used in any way.
29245
29246 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29247 A thread group became associated with a running program,
29248 either because the program was just started or the thread group
29249 was attached to a program. The @var{id} field contains the
29250 @value{GDBN} identifier of the thread group. The @var{pid} field
29251 contains process identifier, specific to the operating system.
29252
29253 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29254 A thread group is no longer associated with a running program,
29255 either because the program has exited, or because it was detached
29256 from. The @var{id} field contains the @value{GDBN} identifier of the
29257 thread group. The @var{code} field is the exit code of the inferior; it exists
29258 only when the inferior exited with some code.
29259
29260 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29261 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29262 A thread either was created, or has exited. The @var{id} field
29263 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29264 field identifies the thread group this thread belongs to.
29265
29266 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29267 Informs that the selected thread or frame were changed. This notification
29268 is not emitted as result of the @code{-thread-select} or
29269 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29270 that is not documented to change the selected thread and frame actually
29271 changes them. In particular, invoking, directly or indirectly
29272 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29273 will generate this notification. Changing the thread or frame from another
29274 user interface (see @ref{Interpreters}) will also generate this notification.
29275
29276 The @var{frame} field is only present if the newly selected thread is
29277 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29278
29279 We suggest that in response to this notification, front ends
29280 highlight the selected thread and cause subsequent commands to apply to
29281 that thread.
29282
29283 @item =library-loaded,...
29284 Reports that a new library file was loaded by the program. This
29285 notification has 5 fields---@var{id}, @var{target-name},
29286 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29287 opaque identifier of the library. For remote debugging case,
29288 @var{target-name} and @var{host-name} fields give the name of the
29289 library file on the target, and on the host respectively. For native
29290 debugging, both those fields have the same value. The
29291 @var{symbols-loaded} field is emitted only for backward compatibility
29292 and should not be relied on to convey any useful information. The
29293 @var{thread-group} field, if present, specifies the id of the thread
29294 group in whose context the library was loaded. If the field is
29295 absent, it means the library was loaded in the context of all present
29296 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29297 to this library.
29298
29299 @item =library-unloaded,...
29300 Reports that a library was unloaded by the program. This notification
29301 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29302 the same meaning as for the @code{=library-loaded} notification.
29303 The @var{thread-group} field, if present, specifies the id of the
29304 thread group in whose context the library was unloaded. If the field is
29305 absent, it means the library was unloaded in the context of all present
29306 thread groups.
29307
29308 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29309 @itemx =traceframe-changed,end
29310 Reports that the trace frame was changed and its new number is
29311 @var{tfnum}. The number of the tracepoint associated with this trace
29312 frame is @var{tpnum}.
29313
29314 @item =tsv-created,name=@var{name},initial=@var{initial}
29315 Reports that the new trace state variable @var{name} is created with
29316 initial value @var{initial}.
29317
29318 @item =tsv-deleted,name=@var{name}
29319 @itemx =tsv-deleted
29320 Reports that the trace state variable @var{name} is deleted or all
29321 trace state variables are deleted.
29322
29323 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29324 Reports that the trace state variable @var{name} is modified with
29325 the initial value @var{initial}. The current value @var{current} of
29326 trace state variable is optional and is reported if the current
29327 value of trace state variable is known.
29328
29329 @item =breakpoint-created,bkpt=@{...@}
29330 @itemx =breakpoint-modified,bkpt=@{...@}
29331 @itemx =breakpoint-deleted,id=@var{number}
29332 Reports that a breakpoint was created, modified, or deleted,
29333 respectively. Only user-visible breakpoints are reported to the MI
29334 user.
29335
29336 The @var{bkpt} argument is of the same form as returned by the various
29337 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29338 @var{number} is the ordinal number of the breakpoint.
29339
29340 Note that if a breakpoint is emitted in the result record of a
29341 command, then it will not also be emitted in an async record.
29342
29343 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29344 @itemx =record-stopped,thread-group="@var{id}"
29345 Execution log recording was either started or stopped on an
29346 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29347 group corresponding to the affected inferior.
29348
29349 The @var{method} field indicates the method used to record execution. If the
29350 method in use supports multiple recording formats, @var{format} will be present
29351 and contain the currently used format. @xref{Process Record and Replay},
29352 for existing method and format values.
29353
29354 @item =cmd-param-changed,param=@var{param},value=@var{value}
29355 Reports that a parameter of the command @code{set @var{param}} is
29356 changed to @var{value}. In the multi-word @code{set} command,
29357 the @var{param} is the whole parameter list to @code{set} command.
29358 For example, In command @code{set check type on}, @var{param}
29359 is @code{check type} and @var{value} is @code{on}.
29360
29361 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29362 Reports that bytes from @var{addr} to @var{data} + @var{len} were
29363 written in an inferior. The @var{id} is the identifier of the
29364 thread group corresponding to the affected inferior. The optional
29365 @code{type="code"} part is reported if the memory written to holds
29366 executable code.
29367 @end table
29368
29369 @node GDB/MI Breakpoint Information
29370 @subsection @sc{gdb/mi} Breakpoint Information
29371
29372 When @value{GDBN} reports information about a breakpoint, a
29373 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29374 following fields:
29375
29376 @table @code
29377 @item number
29378 The breakpoint number.
29379
29380 @item type
29381 The type of the breakpoint. For ordinary breakpoints this will be
29382 @samp{breakpoint}, but many values are possible.
29383
29384 @item catch-type
29385 If the type of the breakpoint is @samp{catchpoint}, then this
29386 indicates the exact type of catchpoint.
29387
29388 @item disp
29389 This is the breakpoint disposition---either @samp{del}, meaning that
29390 the breakpoint will be deleted at the next stop, or @samp{keep},
29391 meaning that the breakpoint will not be deleted.
29392
29393 @item enabled
29394 This indicates whether the breakpoint is enabled, in which case the
29395 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29396 Note that this is not the same as the field @code{enable}.
29397
29398 @item addr
29399 The address of the breakpoint. This may be a hexidecimal number,
29400 giving the address; or the string @samp{<PENDING>}, for a pending
29401 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29402 multiple locations. This field will not be present if no address can
29403 be determined. For example, a watchpoint does not have an address.
29404
29405 @item addr_flags
29406 Optional field containing any flags related to the address. These flags are
29407 architecture-dependent; see @ref{Architectures} for their meaning for a
29408 particular CPU.
29409
29410 @item func
29411 If known, the function in which the breakpoint appears.
29412 If not known, this field is not present.
29413
29414 @item filename
29415 The name of the source file which contains this function, if known.
29416 If not known, this field is not present.
29417
29418 @item fullname
29419 The full file name of the source file which contains this function, if
29420 known. If not known, this field is not present.
29421
29422 @item line
29423 The line number at which this breakpoint appears, if known.
29424 If not known, this field is not present.
29425
29426 @item at
29427 If the source file is not known, this field may be provided. If
29428 provided, this holds the address of the breakpoint, possibly followed
29429 by a symbol name.
29430
29431 @item pending
29432 If this breakpoint is pending, this field is present and holds the
29433 text used to set the breakpoint, as entered by the user.
29434
29435 @item evaluated-by
29436 Where this breakpoint's condition is evaluated, either @samp{host} or
29437 @samp{target}.
29438
29439 @item thread
29440 If this is a thread-specific breakpoint, then this identifies the
29441 thread in which the breakpoint can trigger.
29442
29443 @item task
29444 If this breakpoint is restricted to a particular Ada task, then this
29445 field will hold the task identifier.
29446
29447 @item cond
29448 If the breakpoint is conditional, this is the condition expression.
29449
29450 @item ignore
29451 The ignore count of the breakpoint.
29452
29453 @item enable
29454 The enable count of the breakpoint.
29455
29456 @item traceframe-usage
29457 FIXME.
29458
29459 @item static-tracepoint-marker-string-id
29460 For a static tracepoint, the name of the static tracepoint marker.
29461
29462 @item mask
29463 For a masked watchpoint, this is the mask.
29464
29465 @item pass
29466 A tracepoint's pass count.
29467
29468 @item original-location
29469 The location of the breakpoint as originally specified by the user.
29470 This field is optional.
29471
29472 @item times
29473 The number of times the breakpoint has been hit.
29474
29475 @item installed
29476 This field is only given for tracepoints. This is either @samp{y},
29477 meaning that the tracepoint is installed, or @samp{n}, meaning that it
29478 is not.
29479
29480 @item what
29481 Some extra data, the exact contents of which are type-dependent.
29482
29483 @item locations
29484 This field is present if the breakpoint has multiple locations. It is also
29485 exceptionally present if the breakpoint is enabled and has a single, disabled
29486 location.
29487
29488 The value is a list of locations. The format of a location is described below.
29489
29490 @end table
29491
29492 A location in a multi-location breakpoint is represented as a tuple with the
29493 following fields:
29494
29495 @table @code
29496
29497 @item number
29498 The location number as a dotted pair, like @samp{1.2}. The first digit is the
29499 number of the parent breakpoint. The second digit is the number of the
29500 location within that breakpoint.
29501
29502 @item enabled
29503 This indicates whether the location is enabled, in which case the
29504 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29505 Note that this is not the same as the field @code{enable}.
29506
29507 @item addr
29508 The address of this location as an hexidecimal number.
29509
29510 @item addr_flags
29511 Optional field containing any flags related to the address. These flags are
29512 architecture-dependent; see @ref{Architectures} for their meaning for a
29513 particular CPU.
29514
29515 @item func
29516 If known, the function in which the location appears.
29517 If not known, this field is not present.
29518
29519 @item file
29520 The name of the source file which contains this location, if known.
29521 If not known, this field is not present.
29522
29523 @item fullname
29524 The full file name of the source file which contains this location, if
29525 known. If not known, this field is not present.
29526
29527 @item line
29528 The line number at which this location appears, if known.
29529 If not known, this field is not present.
29530
29531 @item thread-groups
29532 The thread groups this location is in.
29533
29534 @end table
29535
29536 For example, here is what the output of @code{-break-insert}
29537 (@pxref{GDB/MI Breakpoint Commands}) might be:
29538
29539 @smallexample
29540 -> -break-insert main
29541 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29542 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29543 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29544 times="0"@}
29545 <- (gdb)
29546 @end smallexample
29547
29548 @node GDB/MI Frame Information
29549 @subsection @sc{gdb/mi} Frame Information
29550
29551 Response from many MI commands includes an information about stack
29552 frame. This information is a tuple that may have the following
29553 fields:
29554
29555 @table @code
29556 @item level
29557 The level of the stack frame. The innermost frame has the level of
29558 zero. This field is always present.
29559
29560 @item func
29561 The name of the function corresponding to the frame. This field may
29562 be absent if @value{GDBN} is unable to determine the function name.
29563
29564 @item addr
29565 The code address for the frame. This field is always present.
29566
29567 @item addr_flags
29568 Optional field containing any flags related to the address. These flags are
29569 architecture-dependent; see @ref{Architectures} for their meaning for a
29570 particular CPU.
29571
29572 @item file
29573 The name of the source files that correspond to the frame's code
29574 address. This field may be absent.
29575
29576 @item line
29577 The source line corresponding to the frames' code address. This field
29578 may be absent.
29579
29580 @item from
29581 The name of the binary file (either executable or shared library) the
29582 corresponds to the frame's code address. This field may be absent.
29583
29584 @end table
29585
29586 @node GDB/MI Thread Information
29587 @subsection @sc{gdb/mi} Thread Information
29588
29589 Whenever @value{GDBN} has to report an information about a thread, it
29590 uses a tuple with the following fields. The fields are always present unless
29591 stated otherwise.
29592
29593 @table @code
29594 @item id
29595 The global numeric id assigned to the thread by @value{GDBN}.
29596
29597 @item target-id
29598 The target-specific string identifying the thread.
29599
29600 @item details
29601 Additional information about the thread provided by the target.
29602 It is supposed to be human-readable and not interpreted by the
29603 frontend. This field is optional.
29604
29605 @item name
29606 The name of the thread. If the user specified a name using the
29607 @code{thread name} command, then this name is given. Otherwise, if
29608 @value{GDBN} can extract the thread name from the target, then that
29609 name is given. If @value{GDBN} cannot find the thread name, then this
29610 field is omitted.
29611
29612 @item state
29613 The execution state of the thread, either @samp{stopped} or @samp{running},
29614 depending on whether the thread is presently running.
29615
29616 @item frame
29617 The stack frame currently executing in the thread. This field is only present
29618 if the thread is stopped. Its format is documented in
29619 @ref{GDB/MI Frame Information}.
29620
29621 @item core
29622 The value of this field is an integer number of the processor core the
29623 thread was last seen on. This field is optional.
29624 @end table
29625
29626 @node GDB/MI Ada Exception Information
29627 @subsection @sc{gdb/mi} Ada Exception Information
29628
29629 Whenever a @code{*stopped} record is emitted because the program
29630 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29631 @value{GDBN} provides the name of the exception that was raised via
29632 the @code{exception-name} field. Also, for exceptions that were raised
29633 with an exception message, @value{GDBN} provides that message via
29634 the @code{exception-message} field.
29635
29636 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29637 @node GDB/MI Simple Examples
29638 @section Simple Examples of @sc{gdb/mi} Interaction
29639 @cindex @sc{gdb/mi}, simple examples
29640
29641 This subsection presents several simple examples of interaction using
29642 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29643 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29644 the output received from @sc{gdb/mi}.
29645
29646 Note the line breaks shown in the examples are here only for
29647 readability, they don't appear in the real output.
29648
29649 @subheading Setting a Breakpoint
29650
29651 Setting a breakpoint generates synchronous output which contains detailed
29652 information of the breakpoint.
29653
29654 @smallexample
29655 -> -break-insert main
29656 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29657 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29658 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29659 times="0"@}
29660 <- (gdb)
29661 @end smallexample
29662
29663 @subheading Program Execution
29664
29665 Program execution generates asynchronous records and MI gives the
29666 reason that execution stopped.
29667
29668 @smallexample
29669 -> -exec-run
29670 <- ^running
29671 <- (gdb)
29672 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
29673 frame=@{addr="0x08048564",func="main",
29674 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
29675 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29676 arch="i386:x86_64"@}
29677 <- (gdb)
29678 -> -exec-continue
29679 <- ^running
29680 <- (gdb)
29681 <- *stopped,reason="exited-normally"
29682 <- (gdb)
29683 @end smallexample
29684
29685 @subheading Quitting @value{GDBN}
29686
29687 Quitting @value{GDBN} just prints the result class @samp{^exit}.
29688
29689 @smallexample
29690 -> (gdb)
29691 <- -gdb-exit
29692 <- ^exit
29693 @end smallexample
29694
29695 Please note that @samp{^exit} is printed immediately, but it might
29696 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29697 performs necessary cleanups, including killing programs being debugged
29698 or disconnecting from debug hardware, so the frontend should wait till
29699 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29700 fails to exit in reasonable time.
29701
29702 @subheading A Bad Command
29703
29704 Here's what happens if you pass a non-existent command:
29705
29706 @smallexample
29707 -> -rubbish
29708 <- ^error,msg="Undefined MI command: rubbish"
29709 <- (gdb)
29710 @end smallexample
29711
29712
29713 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29714 @node GDB/MI Command Description Format
29715 @section @sc{gdb/mi} Command Description Format
29716
29717 The remaining sections describe blocks of commands. Each block of
29718 commands is laid out in a fashion similar to this section.
29719
29720 @subheading Motivation
29721
29722 The motivation for this collection of commands.
29723
29724 @subheading Introduction
29725
29726 A brief introduction to this collection of commands as a whole.
29727
29728 @subheading Commands
29729
29730 For each command in the block, the following is described:
29731
29732 @subsubheading Synopsis
29733
29734 @smallexample
29735 -command @var{args}@dots{}
29736 @end smallexample
29737
29738 @subsubheading Result
29739
29740 @subsubheading @value{GDBN} Command
29741
29742 The corresponding @value{GDBN} CLI command(s), if any.
29743
29744 @subsubheading Example
29745
29746 Example(s) formatted for readability. Some of the described commands have
29747 not been implemented yet and these are labeled N.A.@: (not available).
29748
29749
29750 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29751 @node GDB/MI Breakpoint Commands
29752 @section @sc{gdb/mi} Breakpoint Commands
29753
29754 @cindex breakpoint commands for @sc{gdb/mi}
29755 @cindex @sc{gdb/mi}, breakpoint commands
29756 This section documents @sc{gdb/mi} commands for manipulating
29757 breakpoints.
29758
29759 @subheading The @code{-break-after} Command
29760 @findex -break-after
29761
29762 @subsubheading Synopsis
29763
29764 @smallexample
29765 -break-after @var{number} @var{count}
29766 @end smallexample
29767
29768 The breakpoint number @var{number} is not in effect until it has been
29769 hit @var{count} times. To see how this is reflected in the output of
29770 the @samp{-break-list} command, see the description of the
29771 @samp{-break-list} command below.
29772
29773 @subsubheading @value{GDBN} Command
29774
29775 The corresponding @value{GDBN} command is @samp{ignore}.
29776
29777 @subsubheading Example
29778
29779 @smallexample
29780 (gdb)
29781 -break-insert main
29782 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29783 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29784 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29785 times="0"@}
29786 (gdb)
29787 -break-after 1 3
29788 ~
29789 ^done
29790 (gdb)
29791 -break-list
29792 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29793 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29794 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29795 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29796 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29797 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29798 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29799 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29800 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29801 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
29802 (gdb)
29803 @end smallexample
29804
29805 @ignore
29806 @subheading The @code{-break-catch} Command
29807 @findex -break-catch
29808 @end ignore
29809
29810 @subheading The @code{-break-commands} Command
29811 @findex -break-commands
29812
29813 @subsubheading Synopsis
29814
29815 @smallexample
29816 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29817 @end smallexample
29818
29819 Specifies the CLI commands that should be executed when breakpoint
29820 @var{number} is hit. The parameters @var{command1} to @var{commandN}
29821 are the commands. If no command is specified, any previously-set
29822 commands are cleared. @xref{Break Commands}. Typical use of this
29823 functionality is tracing a program, that is, printing of values of
29824 some variables whenever breakpoint is hit and then continuing.
29825
29826 @subsubheading @value{GDBN} Command
29827
29828 The corresponding @value{GDBN} command is @samp{commands}.
29829
29830 @subsubheading Example
29831
29832 @smallexample
29833 (gdb)
29834 -break-insert main
29835 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29836 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29837 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29838 times="0"@}
29839 (gdb)
29840 -break-commands 1 "print v" "continue"
29841 ^done
29842 (gdb)
29843 @end smallexample
29844
29845 @subheading The @code{-break-condition} Command
29846 @findex -break-condition
29847
29848 @subsubheading Synopsis
29849
29850 @smallexample
29851 -break-condition @var{number} @var{expr}
29852 @end smallexample
29853
29854 Breakpoint @var{number} will stop the program only if the condition in
29855 @var{expr} is true. The condition becomes part of the
29856 @samp{-break-list} output (see the description of the @samp{-break-list}
29857 command below).
29858
29859 @subsubheading @value{GDBN} Command
29860
29861 The corresponding @value{GDBN} command is @samp{condition}.
29862
29863 @subsubheading Example
29864
29865 @smallexample
29866 (gdb)
29867 -break-condition 1 1
29868 ^done
29869 (gdb)
29870 -break-list
29871 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29872 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29873 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29874 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29875 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29876 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29877 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29878 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29879 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29880 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
29881 (gdb)
29882 @end smallexample
29883
29884 @subheading The @code{-break-delete} Command
29885 @findex -break-delete
29886
29887 @subsubheading Synopsis
29888
29889 @smallexample
29890 -break-delete ( @var{breakpoint} )+
29891 @end smallexample
29892
29893 Delete the breakpoint(s) whose number(s) are specified in the argument
29894 list. This is obviously reflected in the breakpoint list.
29895
29896 @subsubheading @value{GDBN} Command
29897
29898 The corresponding @value{GDBN} command is @samp{delete}.
29899
29900 @subsubheading Example
29901
29902 @smallexample
29903 (gdb)
29904 -break-delete 1
29905 ^done
29906 (gdb)
29907 -break-list
29908 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29909 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29910 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29911 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29912 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29913 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29914 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29915 body=[]@}
29916 (gdb)
29917 @end smallexample
29918
29919 @subheading The @code{-break-disable} Command
29920 @findex -break-disable
29921
29922 @subsubheading Synopsis
29923
29924 @smallexample
29925 -break-disable ( @var{breakpoint} )+
29926 @end smallexample
29927
29928 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
29929 break list is now set to @samp{n} for the named @var{breakpoint}(s).
29930
29931 @subsubheading @value{GDBN} Command
29932
29933 The corresponding @value{GDBN} command is @samp{disable}.
29934
29935 @subsubheading Example
29936
29937 @smallexample
29938 (gdb)
29939 -break-disable 2
29940 ^done
29941 (gdb)
29942 -break-list
29943 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29944 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29945 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29946 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29947 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29948 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29949 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29950 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
29951 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29952 line="5",thread-groups=["i1"],times="0"@}]@}
29953 (gdb)
29954 @end smallexample
29955
29956 @subheading The @code{-break-enable} Command
29957 @findex -break-enable
29958
29959 @subsubheading Synopsis
29960
29961 @smallexample
29962 -break-enable ( @var{breakpoint} )+
29963 @end smallexample
29964
29965 Enable (previously disabled) @var{breakpoint}(s).
29966
29967 @subsubheading @value{GDBN} Command
29968
29969 The corresponding @value{GDBN} command is @samp{enable}.
29970
29971 @subsubheading Example
29972
29973 @smallexample
29974 (gdb)
29975 -break-enable 2
29976 ^done
29977 (gdb)
29978 -break-list
29979 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29980 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29981 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29982 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29983 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29984 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29985 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29986 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
29987 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29988 line="5",thread-groups=["i1"],times="0"@}]@}
29989 (gdb)
29990 @end smallexample
29991
29992 @subheading The @code{-break-info} Command
29993 @findex -break-info
29994
29995 @subsubheading Synopsis
29996
29997 @smallexample
29998 -break-info @var{breakpoint}
29999 @end smallexample
30000
30001 @c REDUNDANT???
30002 Get information about a single breakpoint.
30003
30004 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30005 Information}, for details on the format of each breakpoint in the
30006 table.
30007
30008 @subsubheading @value{GDBN} Command
30009
30010 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30011
30012 @subsubheading Example
30013 N.A.
30014
30015 @subheading The @code{-break-insert} Command
30016 @findex -break-insert
30017 @anchor{-break-insert}
30018
30019 @subsubheading Synopsis
30020
30021 @smallexample
30022 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
30023 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30024 [ -p @var{thread-id} ] [ @var{location} ]
30025 @end smallexample
30026
30027 @noindent
30028 If specified, @var{location}, can be one of:
30029
30030 @table @var
30031 @item linespec location
30032 A linespec location. @xref{Linespec Locations}.
30033
30034 @item explicit location
30035 An explicit location. @sc{gdb/mi} explicit locations are
30036 analogous to the CLI's explicit locations using the option names
30037 listed below. @xref{Explicit Locations}.
30038
30039 @table @samp
30040 @item --source @var{filename}
30041 The source file name of the location. This option requires the use
30042 of either @samp{--function} or @samp{--line}.
30043
30044 @item --function @var{function}
30045 The name of a function or method.
30046
30047 @item --label @var{label}
30048 The name of a label.
30049
30050 @item --line @var{lineoffset}
30051 An absolute or relative line offset from the start of the location.
30052 @end table
30053
30054 @item address location
30055 An address location, *@var{address}. @xref{Address Locations}.
30056 @end table
30057
30058 @noindent
30059 The possible optional parameters of this command are:
30060
30061 @table @samp
30062 @item -t
30063 Insert a temporary breakpoint.
30064 @item -h
30065 Insert a hardware breakpoint.
30066 @item -f
30067 If @var{location} cannot be parsed (for example if it
30068 refers to unknown files or functions), create a pending
30069 breakpoint. Without this flag, @value{GDBN} will report
30070 an error, and won't create a breakpoint, if @var{location}
30071 cannot be parsed.
30072 @item -d
30073 Create a disabled breakpoint.
30074 @item -a
30075 Create a tracepoint. @xref{Tracepoints}. When this parameter
30076 is used together with @samp{-h}, a fast tracepoint is created.
30077 @item -c @var{condition}
30078 Make the breakpoint conditional on @var{condition}.
30079 @item -i @var{ignore-count}
30080 Initialize the @var{ignore-count}.
30081 @item -p @var{thread-id}
30082 Restrict the breakpoint to the thread with the specified global
30083 @var{thread-id}.
30084 @end table
30085
30086 @subsubheading Result
30087
30088 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30089 resulting breakpoint.
30090
30091 Note: this format is open to change.
30092 @c An out-of-band breakpoint instead of part of the result?
30093
30094 @subsubheading @value{GDBN} Command
30095
30096 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30097 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30098
30099 @subsubheading Example
30100
30101 @smallexample
30102 (gdb)
30103 -break-insert main
30104 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30105 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30106 times="0"@}
30107 (gdb)
30108 -break-insert -t foo
30109 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30110 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30111 times="0"@}
30112 (gdb)
30113 -break-list
30114 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30115 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30116 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30117 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30118 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30119 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30120 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30121 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30122 addr="0x0001072c", func="main",file="recursive2.c",
30123 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30124 times="0"@},
30125 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30126 addr="0x00010774",func="foo",file="recursive2.c",
30127 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30128 times="0"@}]@}
30129 (gdb)
30130 @c -break-insert -r foo.*
30131 @c ~int foo(int, int);
30132 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30133 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30134 @c times="0"@}
30135 @c (gdb)
30136 @end smallexample
30137
30138 @subheading The @code{-dprintf-insert} Command
30139 @findex -dprintf-insert
30140
30141 @subsubheading Synopsis
30142
30143 @smallexample
30144 -dprintf-insert [ -t ] [ -f ] [ -d ]
30145 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30146 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30147 [ @var{argument} ]
30148 @end smallexample
30149
30150 @noindent
30151 If supplied, @var{location} may be specified the same way as for
30152 the @code{-break-insert} command. @xref{-break-insert}.
30153
30154 The possible optional parameters of this command are:
30155
30156 @table @samp
30157 @item -t
30158 Insert a temporary breakpoint.
30159 @item -f
30160 If @var{location} cannot be parsed (for example, if it
30161 refers to unknown files or functions), create a pending
30162 breakpoint. Without this flag, @value{GDBN} will report
30163 an error, and won't create a breakpoint, if @var{location}
30164 cannot be parsed.
30165 @item -d
30166 Create a disabled breakpoint.
30167 @item -c @var{condition}
30168 Make the breakpoint conditional on @var{condition}.
30169 @item -i @var{ignore-count}
30170 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30171 to @var{ignore-count}.
30172 @item -p @var{thread-id}
30173 Restrict the breakpoint to the thread with the specified global
30174 @var{thread-id}.
30175 @end table
30176
30177 @subsubheading Result
30178
30179 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30180 resulting breakpoint.
30181
30182 @c An out-of-band breakpoint instead of part of the result?
30183
30184 @subsubheading @value{GDBN} Command
30185
30186 The corresponding @value{GDBN} command is @samp{dprintf}.
30187
30188 @subsubheading Example
30189
30190 @smallexample
30191 (gdb)
30192 4-dprintf-insert foo "At foo entry\n"
30193 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30194 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30195 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30196 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30197 original-location="foo"@}
30198 (gdb)
30199 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30200 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30201 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30202 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30203 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30204 original-location="mi-dprintf.c:26"@}
30205 (gdb)
30206 @end smallexample
30207
30208 @subheading The @code{-break-list} Command
30209 @findex -break-list
30210
30211 @subsubheading Synopsis
30212
30213 @smallexample
30214 -break-list
30215 @end smallexample
30216
30217 Displays the list of inserted breakpoints, showing the following fields:
30218
30219 @table @samp
30220 @item Number
30221 number of the breakpoint
30222 @item Type
30223 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30224 @item Disposition
30225 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30226 or @samp{nokeep}
30227 @item Enabled
30228 is the breakpoint enabled or no: @samp{y} or @samp{n}
30229 @item Address
30230 memory location at which the breakpoint is set
30231 @item What
30232 logical location of the breakpoint, expressed by function name, file
30233 name, line number
30234 @item Thread-groups
30235 list of thread groups to which this breakpoint applies
30236 @item Times
30237 number of times the breakpoint has been hit
30238 @end table
30239
30240 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30241 @code{body} field is an empty list.
30242
30243 @subsubheading @value{GDBN} Command
30244
30245 The corresponding @value{GDBN} command is @samp{info break}.
30246
30247 @subsubheading Example
30248
30249 @smallexample
30250 (gdb)
30251 -break-list
30252 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30253 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30254 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30255 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30256 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30257 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30258 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30259 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30260 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30261 times="0"@},
30262 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30263 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30264 line="13",thread-groups=["i1"],times="0"@}]@}
30265 (gdb)
30266 @end smallexample
30267
30268 Here's an example of the result when there are no breakpoints:
30269
30270 @smallexample
30271 (gdb)
30272 -break-list
30273 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30274 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30275 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30276 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30277 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30278 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30279 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30280 body=[]@}
30281 (gdb)
30282 @end smallexample
30283
30284 @subheading The @code{-break-passcount} Command
30285 @findex -break-passcount
30286
30287 @subsubheading Synopsis
30288
30289 @smallexample
30290 -break-passcount @var{tracepoint-number} @var{passcount}
30291 @end smallexample
30292
30293 Set the passcount for tracepoint @var{tracepoint-number} to
30294 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30295 is not a tracepoint, error is emitted. This corresponds to CLI
30296 command @samp{passcount}.
30297
30298 @subheading The @code{-break-watch} Command
30299 @findex -break-watch
30300
30301 @subsubheading Synopsis
30302
30303 @smallexample
30304 -break-watch [ -a | -r ]
30305 @end smallexample
30306
30307 Create a watchpoint. With the @samp{-a} option it will create an
30308 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30309 read from or on a write to the memory location. With the @samp{-r}
30310 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30311 trigger only when the memory location is accessed for reading. Without
30312 either of the options, the watchpoint created is a regular watchpoint,
30313 i.e., it will trigger when the memory location is accessed for writing.
30314 @xref{Set Watchpoints, , Setting Watchpoints}.
30315
30316 Note that @samp{-break-list} will report a single list of watchpoints and
30317 breakpoints inserted.
30318
30319 @subsubheading @value{GDBN} Command
30320
30321 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30322 @samp{rwatch}.
30323
30324 @subsubheading Example
30325
30326 Setting a watchpoint on a variable in the @code{main} function:
30327
30328 @smallexample
30329 (gdb)
30330 -break-watch x
30331 ^done,wpt=@{number="2",exp="x"@}
30332 (gdb)
30333 -exec-continue
30334 ^running
30335 (gdb)
30336 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30337 value=@{old="-268439212",new="55"@},
30338 frame=@{func="main",args=[],file="recursive2.c",
30339 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30340 (gdb)
30341 @end smallexample
30342
30343 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30344 the program execution twice: first for the variable changing value, then
30345 for the watchpoint going out of scope.
30346
30347 @smallexample
30348 (gdb)
30349 -break-watch C
30350 ^done,wpt=@{number="5",exp="C"@}
30351 (gdb)
30352 -exec-continue
30353 ^running
30354 (gdb)
30355 *stopped,reason="watchpoint-trigger",
30356 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30357 frame=@{func="callee4",args=[],
30358 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30359 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30360 arch="i386:x86_64"@}
30361 (gdb)
30362 -exec-continue
30363 ^running
30364 (gdb)
30365 *stopped,reason="watchpoint-scope",wpnum="5",
30366 frame=@{func="callee3",args=[@{name="strarg",
30367 value="0x11940 \"A string argument.\""@}],
30368 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30369 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30370 arch="i386:x86_64"@}
30371 (gdb)
30372 @end smallexample
30373
30374 Listing breakpoints and watchpoints, at different points in the program
30375 execution. Note that once the watchpoint goes out of scope, it is
30376 deleted.
30377
30378 @smallexample
30379 (gdb)
30380 -break-watch C
30381 ^done,wpt=@{number="2",exp="C"@}
30382 (gdb)
30383 -break-list
30384 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30385 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30386 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30387 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30388 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30389 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30390 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30391 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30392 addr="0x00010734",func="callee4",
30393 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30394 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30395 times="1"@},
30396 bkpt=@{number="2",type="watchpoint",disp="keep",
30397 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30398 (gdb)
30399 -exec-continue
30400 ^running
30401 (gdb)
30402 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30403 value=@{old="-276895068",new="3"@},
30404 frame=@{func="callee4",args=[],
30405 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30406 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30407 arch="i386:x86_64"@}
30408 (gdb)
30409 -break-list
30410 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30411 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30412 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30413 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30414 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30415 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30416 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30417 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30418 addr="0x00010734",func="callee4",
30419 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30420 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30421 times="1"@},
30422 bkpt=@{number="2",type="watchpoint",disp="keep",
30423 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30424 (gdb)
30425 -exec-continue
30426 ^running
30427 ^done,reason="watchpoint-scope",wpnum="2",
30428 frame=@{func="callee3",args=[@{name="strarg",
30429 value="0x11940 \"A string argument.\""@}],
30430 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30431 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30432 arch="i386:x86_64"@}
30433 (gdb)
30434 -break-list
30435 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30436 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30437 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30438 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30439 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30440 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30441 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30442 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30443 addr="0x00010734",func="callee4",
30444 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30445 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30446 thread-groups=["i1"],times="1"@}]@}
30447 (gdb)
30448 @end smallexample
30449
30450
30451 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30452 @node GDB/MI Catchpoint Commands
30453 @section @sc{gdb/mi} Catchpoint Commands
30454
30455 This section documents @sc{gdb/mi} commands for manipulating
30456 catchpoints.
30457
30458 @menu
30459 * Shared Library GDB/MI Catchpoint Commands::
30460 * Ada Exception GDB/MI Catchpoint Commands::
30461 * C++ Exception GDB/MI Catchpoint Commands::
30462 @end menu
30463
30464 @node Shared Library GDB/MI Catchpoint Commands
30465 @subsection Shared Library @sc{gdb/mi} Catchpoints
30466
30467 @subheading The @code{-catch-load} Command
30468 @findex -catch-load
30469
30470 @subsubheading Synopsis
30471
30472 @smallexample
30473 -catch-load [ -t ] [ -d ] @var{regexp}
30474 @end smallexample
30475
30476 Add a catchpoint for library load events. If the @samp{-t} option is used,
30477 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30478 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30479 in a disabled state. The @samp{regexp} argument is a regular
30480 expression used to match the name of the loaded library.
30481
30482
30483 @subsubheading @value{GDBN} Command
30484
30485 The corresponding @value{GDBN} command is @samp{catch load}.
30486
30487 @subsubheading Example
30488
30489 @smallexample
30490 -catch-load -t foo.so
30491 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30492 what="load of library matching foo.so",catch-type="load",times="0"@}
30493 (gdb)
30494 @end smallexample
30495
30496
30497 @subheading The @code{-catch-unload} Command
30498 @findex -catch-unload
30499
30500 @subsubheading Synopsis
30501
30502 @smallexample
30503 -catch-unload [ -t ] [ -d ] @var{regexp}
30504 @end smallexample
30505
30506 Add a catchpoint for library unload events. If the @samp{-t} option is
30507 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30508 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30509 created in a disabled state. The @samp{regexp} argument is a regular
30510 expression used to match the name of the unloaded library.
30511
30512 @subsubheading @value{GDBN} Command
30513
30514 The corresponding @value{GDBN} command is @samp{catch unload}.
30515
30516 @subsubheading Example
30517
30518 @smallexample
30519 -catch-unload -d bar.so
30520 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30521 what="load of library matching bar.so",catch-type="unload",times="0"@}
30522 (gdb)
30523 @end smallexample
30524
30525 @node Ada Exception GDB/MI Catchpoint Commands
30526 @subsection Ada Exception @sc{gdb/mi} Catchpoints
30527
30528 The following @sc{gdb/mi} commands can be used to create catchpoints
30529 that stop the execution when Ada exceptions are being raised.
30530
30531 @subheading The @code{-catch-assert} Command
30532 @findex -catch-assert
30533
30534 @subsubheading Synopsis
30535
30536 @smallexample
30537 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30538 @end smallexample
30539
30540 Add a catchpoint for failed Ada assertions.
30541
30542 The possible optional parameters for this command are:
30543
30544 @table @samp
30545 @item -c @var{condition}
30546 Make the catchpoint conditional on @var{condition}.
30547 @item -d
30548 Create a disabled catchpoint.
30549 @item -t
30550 Create a temporary catchpoint.
30551 @end table
30552
30553 @subsubheading @value{GDBN} Command
30554
30555 The corresponding @value{GDBN} command is @samp{catch assert}.
30556
30557 @subsubheading Example
30558
30559 @smallexample
30560 -catch-assert
30561 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30562 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30563 thread-groups=["i1"],times="0",
30564 original-location="__gnat_debug_raise_assert_failure"@}
30565 (gdb)
30566 @end smallexample
30567
30568 @subheading The @code{-catch-exception} Command
30569 @findex -catch-exception
30570
30571 @subsubheading Synopsis
30572
30573 @smallexample
30574 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30575 [ -t ] [ -u ]
30576 @end smallexample
30577
30578 Add a catchpoint stopping when Ada exceptions are raised.
30579 By default, the command stops the program when any Ada exception
30580 gets raised. But it is also possible, by using some of the
30581 optional parameters described below, to create more selective
30582 catchpoints.
30583
30584 The possible optional parameters for this command are:
30585
30586 @table @samp
30587 @item -c @var{condition}
30588 Make the catchpoint conditional on @var{condition}.
30589 @item -d
30590 Create a disabled catchpoint.
30591 @item -e @var{exception-name}
30592 Only stop when @var{exception-name} is raised. This option cannot
30593 be used combined with @samp{-u}.
30594 @item -t
30595 Create a temporary catchpoint.
30596 @item -u
30597 Stop only when an unhandled exception gets raised. This option
30598 cannot be used combined with @samp{-e}.
30599 @end table
30600
30601 @subsubheading @value{GDBN} Command
30602
30603 The corresponding @value{GDBN} commands are @samp{catch exception}
30604 and @samp{catch exception unhandled}.
30605
30606 @subsubheading Example
30607
30608 @smallexample
30609 -catch-exception -e Program_Error
30610 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30611 enabled="y",addr="0x0000000000404874",
30612 what="`Program_Error' Ada exception", thread-groups=["i1"],
30613 times="0",original-location="__gnat_debug_raise_exception"@}
30614 (gdb)
30615 @end smallexample
30616
30617 @subheading The @code{-catch-handlers} Command
30618 @findex -catch-handlers
30619
30620 @subsubheading Synopsis
30621
30622 @smallexample
30623 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30624 [ -t ]
30625 @end smallexample
30626
30627 Add a catchpoint stopping when Ada exceptions are handled.
30628 By default, the command stops the program when any Ada exception
30629 gets handled. But it is also possible, by using some of the
30630 optional parameters described below, to create more selective
30631 catchpoints.
30632
30633 The possible optional parameters for this command are:
30634
30635 @table @samp
30636 @item -c @var{condition}
30637 Make the catchpoint conditional on @var{condition}.
30638 @item -d
30639 Create a disabled catchpoint.
30640 @item -e @var{exception-name}
30641 Only stop when @var{exception-name} is handled.
30642 @item -t
30643 Create a temporary catchpoint.
30644 @end table
30645
30646 @subsubheading @value{GDBN} Command
30647
30648 The corresponding @value{GDBN} command is @samp{catch handlers}.
30649
30650 @subsubheading Example
30651
30652 @smallexample
30653 -catch-handlers -e Constraint_Error
30654 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30655 enabled="y",addr="0x0000000000402f68",
30656 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30657 times="0",original-location="__gnat_begin_handler"@}
30658 (gdb)
30659 @end smallexample
30660
30661 @node C++ Exception GDB/MI Catchpoint Commands
30662 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30663
30664 The following @sc{gdb/mi} commands can be used to create catchpoints
30665 that stop the execution when C@t{++} exceptions are being throw, rethrown,
30666 or caught.
30667
30668 @subheading The @code{-catch-throw} Command
30669 @findex -catch-throw
30670
30671 @subsubheading Synopsis
30672
30673 @smallexample
30674 -catch-throw [ -t ] [ -r @var{regexp}]
30675 @end smallexample
30676
30677 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30678 given, then only exceptions whose type matches the regular expression
30679 will be caught.
30680
30681 If @samp{-t} is given, then the catchpoint is enabled only for one
30682 stop, the catchpoint is automatically deleted after stopping once for
30683 the event.
30684
30685 @subsubheading @value{GDBN} Command
30686
30687 The corresponding @value{GDBN} commands are @samp{catch throw}
30688 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30689
30690 @subsubheading Example
30691
30692 @smallexample
30693 -catch-throw -r exception_type
30694 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30695 what="exception throw",catch-type="throw",
30696 thread-groups=["i1"],
30697 regexp="exception_type",times="0"@}
30698 (gdb)
30699 -exec-run
30700 ^running
30701 (gdb)
30702 ~"\n"
30703 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30704 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30705 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30706 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30707 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30708 thread-id="1",stopped-threads="all",core="6"
30709 (gdb)
30710 @end smallexample
30711
30712 @subheading The @code{-catch-rethrow} Command
30713 @findex -catch-rethrow
30714
30715 @subsubheading Synopsis
30716
30717 @smallexample
30718 -catch-rethrow [ -t ] [ -r @var{regexp}]
30719 @end smallexample
30720
30721 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30722 then only exceptions whose type matches the regular expression will be
30723 caught.
30724
30725 If @samp{-t} is given, then the catchpoint is enabled only for one
30726 stop, the catchpoint is automatically deleted after the first event is
30727 caught.
30728
30729 @subsubheading @value{GDBN} Command
30730
30731 The corresponding @value{GDBN} commands are @samp{catch rethrow}
30732 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30733
30734 @subsubheading Example
30735
30736 @smallexample
30737 -catch-rethrow -r exception_type
30738 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30739 what="exception rethrow",catch-type="rethrow",
30740 thread-groups=["i1"],
30741 regexp="exception_type",times="0"@}
30742 (gdb)
30743 -exec-run
30744 ^running
30745 (gdb)
30746 ~"\n"
30747 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30748 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30749 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30750 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30751 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30752 thread-id="1",stopped-threads="all",core="6"
30753 (gdb)
30754 @end smallexample
30755
30756 @subheading The @code{-catch-catch} Command
30757 @findex -catch-catch
30758
30759 @subsubheading Synopsis
30760
30761 @smallexample
30762 -catch-catch [ -t ] [ -r @var{regexp}]
30763 @end smallexample
30764
30765 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30766 is given, then only exceptions whose type matches the regular
30767 expression will be caught.
30768
30769 If @samp{-t} is given, then the catchpoint is enabled only for one
30770 stop, the catchpoint is automatically deleted after the first event is
30771 caught.
30772
30773 @subsubheading @value{GDBN} Command
30774
30775 The corresponding @value{GDBN} commands are @samp{catch catch}
30776 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30777
30778 @subsubheading Example
30779
30780 @smallexample
30781 -catch-catch -r exception_type
30782 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30783 what="exception catch",catch-type="catch",
30784 thread-groups=["i1"],
30785 regexp="exception_type",times="0"@}
30786 (gdb)
30787 -exec-run
30788 ^running
30789 (gdb)
30790 ~"\n"
30791 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30792 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30793 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30794 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30795 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30796 thread-id="1",stopped-threads="all",core="6"
30797 (gdb)
30798 @end smallexample
30799
30800 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30801 @node GDB/MI Program Context
30802 @section @sc{gdb/mi} Program Context
30803
30804 @subheading The @code{-exec-arguments} Command
30805 @findex -exec-arguments
30806
30807
30808 @subsubheading Synopsis
30809
30810 @smallexample
30811 -exec-arguments @var{args}
30812 @end smallexample
30813
30814 Set the inferior program arguments, to be used in the next
30815 @samp{-exec-run}.
30816
30817 @subsubheading @value{GDBN} Command
30818
30819 The corresponding @value{GDBN} command is @samp{set args}.
30820
30821 @subsubheading Example
30822
30823 @smallexample
30824 (gdb)
30825 -exec-arguments -v word
30826 ^done
30827 (gdb)
30828 @end smallexample
30829
30830
30831 @ignore
30832 @subheading The @code{-exec-show-arguments} Command
30833 @findex -exec-show-arguments
30834
30835 @subsubheading Synopsis
30836
30837 @smallexample
30838 -exec-show-arguments
30839 @end smallexample
30840
30841 Print the arguments of the program.
30842
30843 @subsubheading @value{GDBN} Command
30844
30845 The corresponding @value{GDBN} command is @samp{show args}.
30846
30847 @subsubheading Example
30848 N.A.
30849 @end ignore
30850
30851
30852 @subheading The @code{-environment-cd} Command
30853 @findex -environment-cd
30854
30855 @subsubheading Synopsis
30856
30857 @smallexample
30858 -environment-cd @var{pathdir}
30859 @end smallexample
30860
30861 Set @value{GDBN}'s working directory.
30862
30863 @subsubheading @value{GDBN} Command
30864
30865 The corresponding @value{GDBN} command is @samp{cd}.
30866
30867 @subsubheading Example
30868
30869 @smallexample
30870 (gdb)
30871 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30872 ^done
30873 (gdb)
30874 @end smallexample
30875
30876
30877 @subheading The @code{-environment-directory} Command
30878 @findex -environment-directory
30879
30880 @subsubheading Synopsis
30881
30882 @smallexample
30883 -environment-directory [ -r ] [ @var{pathdir} ]+
30884 @end smallexample
30885
30886 Add directories @var{pathdir} to beginning of search path for source files.
30887 If the @samp{-r} option is used, the search path is reset to the default
30888 search path. If directories @var{pathdir} are supplied in addition to the
30889 @samp{-r} option, the search path is first reset and then addition
30890 occurs as normal.
30891 Multiple directories may be specified, separated by blanks. Specifying
30892 multiple directories in a single command
30893 results in the directories added to the beginning of the
30894 search path in the same order they were presented in the command.
30895 If blanks are needed as
30896 part of a directory name, double-quotes should be used around
30897 the name. In the command output, the path will show up separated
30898 by the system directory-separator character. The directory-separator
30899 character must not be used
30900 in any directory name.
30901 If no directories are specified, the current search path is displayed.
30902
30903 @subsubheading @value{GDBN} Command
30904
30905 The corresponding @value{GDBN} command is @samp{dir}.
30906
30907 @subsubheading Example
30908
30909 @smallexample
30910 (gdb)
30911 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30912 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30913 (gdb)
30914 -environment-directory ""
30915 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30916 (gdb)
30917 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
30918 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
30919 (gdb)
30920 -environment-directory -r
30921 ^done,source-path="$cdir:$cwd"
30922 (gdb)
30923 @end smallexample
30924
30925
30926 @subheading The @code{-environment-path} Command
30927 @findex -environment-path
30928
30929 @subsubheading Synopsis
30930
30931 @smallexample
30932 -environment-path [ -r ] [ @var{pathdir} ]+
30933 @end smallexample
30934
30935 Add directories @var{pathdir} to beginning of search path for object files.
30936 If the @samp{-r} option is used, the search path is reset to the original
30937 search path that existed at gdb start-up. If directories @var{pathdir} are
30938 supplied in addition to the
30939 @samp{-r} option, the search path is first reset and then addition
30940 occurs as normal.
30941 Multiple directories may be specified, separated by blanks. Specifying
30942 multiple directories in a single command
30943 results in the directories added to the beginning of the
30944 search path in the same order they were presented in the command.
30945 If blanks are needed as
30946 part of a directory name, double-quotes should be used around
30947 the name. In the command output, the path will show up separated
30948 by the system directory-separator character. The directory-separator
30949 character must not be used
30950 in any directory name.
30951 If no directories are specified, the current path is displayed.
30952
30953
30954 @subsubheading @value{GDBN} Command
30955
30956 The corresponding @value{GDBN} command is @samp{path}.
30957
30958 @subsubheading Example
30959
30960 @smallexample
30961 (gdb)
30962 -environment-path
30963 ^done,path="/usr/bin"
30964 (gdb)
30965 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
30966 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
30967 (gdb)
30968 -environment-path -r /usr/local/bin
30969 ^done,path="/usr/local/bin:/usr/bin"
30970 (gdb)
30971 @end smallexample
30972
30973
30974 @subheading The @code{-environment-pwd} Command
30975 @findex -environment-pwd
30976
30977 @subsubheading Synopsis
30978
30979 @smallexample
30980 -environment-pwd
30981 @end smallexample
30982
30983 Show the current working directory.
30984
30985 @subsubheading @value{GDBN} Command
30986
30987 The corresponding @value{GDBN} command is @samp{pwd}.
30988
30989 @subsubheading Example
30990
30991 @smallexample
30992 (gdb)
30993 -environment-pwd
30994 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
30995 (gdb)
30996 @end smallexample
30997
30998 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30999 @node GDB/MI Thread Commands
31000 @section @sc{gdb/mi} Thread Commands
31001
31002
31003 @subheading The @code{-thread-info} Command
31004 @findex -thread-info
31005
31006 @subsubheading Synopsis
31007
31008 @smallexample
31009 -thread-info [ @var{thread-id} ]
31010 @end smallexample
31011
31012 Reports information about either a specific thread, if the
31013 @var{thread-id} parameter is present, or about all threads.
31014 @var{thread-id} is the thread's global thread ID. When printing
31015 information about all threads, also reports the global ID of the
31016 current thread.
31017
31018 @subsubheading @value{GDBN} Command
31019
31020 The @samp{info thread} command prints the same information
31021 about all threads.
31022
31023 @subsubheading Result
31024
31025 The result contains the following attributes:
31026
31027 @table @samp
31028 @item threads
31029 A list of threads. The format of the elements of the list is described in
31030 @ref{GDB/MI Thread Information}.
31031
31032 @item current-thread-id
31033 The global id of the currently selected thread. This field is omitted if there
31034 is no selected thread (for example, when the selected inferior is not running,
31035 and therefore has no threads) or if a @var{thread-id} argument was passed to
31036 the command.
31037
31038 @end table
31039
31040 @subsubheading Example
31041
31042 @smallexample
31043 -thread-info
31044 ^done,threads=[
31045 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31046 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31047 args=[]@},state="running"@},
31048 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31049 frame=@{level="0",addr="0x0804891f",func="foo",
31050 args=[@{name="i",value="10"@}],
31051 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31052 state="running"@}],
31053 current-thread-id="1"
31054 (gdb)
31055 @end smallexample
31056
31057 @subheading The @code{-thread-list-ids} Command
31058 @findex -thread-list-ids
31059
31060 @subsubheading Synopsis
31061
31062 @smallexample
31063 -thread-list-ids
31064 @end smallexample
31065
31066 Produces a list of the currently known global @value{GDBN} thread ids.
31067 At the end of the list it also prints the total number of such
31068 threads.
31069
31070 This command is retained for historical reasons, the
31071 @code{-thread-info} command should be used instead.
31072
31073 @subsubheading @value{GDBN} Command
31074
31075 Part of @samp{info threads} supplies the same information.
31076
31077 @subsubheading Example
31078
31079 @smallexample
31080 (gdb)
31081 -thread-list-ids
31082 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31083 current-thread-id="1",number-of-threads="3"
31084 (gdb)
31085 @end smallexample
31086
31087
31088 @subheading The @code{-thread-select} Command
31089 @findex -thread-select
31090
31091 @subsubheading Synopsis
31092
31093 @smallexample
31094 -thread-select @var{thread-id}
31095 @end smallexample
31096
31097 Make thread with global thread number @var{thread-id} the current
31098 thread. It prints the number of the new current thread, and the
31099 topmost frame for that thread.
31100
31101 This command is deprecated in favor of explicitly using the
31102 @samp{--thread} option to each command.
31103
31104 @subsubheading @value{GDBN} Command
31105
31106 The corresponding @value{GDBN} command is @samp{thread}.
31107
31108 @subsubheading Example
31109
31110 @smallexample
31111 (gdb)
31112 -exec-next
31113 ^running
31114 (gdb)
31115 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31116 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31117 (gdb)
31118 -thread-list-ids
31119 ^done,
31120 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31121 number-of-threads="3"
31122 (gdb)
31123 -thread-select 3
31124 ^done,new-thread-id="3",
31125 frame=@{level="0",func="vprintf",
31126 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31127 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31128 (gdb)
31129 @end smallexample
31130
31131 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31132 @node GDB/MI Ada Tasking Commands
31133 @section @sc{gdb/mi} Ada Tasking Commands
31134
31135 @subheading The @code{-ada-task-info} Command
31136 @findex -ada-task-info
31137
31138 @subsubheading Synopsis
31139
31140 @smallexample
31141 -ada-task-info [ @var{task-id} ]
31142 @end smallexample
31143
31144 Reports information about either a specific Ada task, if the
31145 @var{task-id} parameter is present, or about all Ada tasks.
31146
31147 @subsubheading @value{GDBN} Command
31148
31149 The @samp{info tasks} command prints the same information
31150 about all Ada tasks (@pxref{Ada Tasks}).
31151
31152 @subsubheading Result
31153
31154 The result is a table of Ada tasks. The following columns are
31155 defined for each Ada task:
31156
31157 @table @samp
31158 @item current
31159 This field exists only for the current thread. It has the value @samp{*}.
31160
31161 @item id
31162 The identifier that @value{GDBN} uses to refer to the Ada task.
31163
31164 @item task-id
31165 The identifier that the target uses to refer to the Ada task.
31166
31167 @item thread-id
31168 The global thread identifier of the thread corresponding to the Ada
31169 task.
31170
31171 This field should always exist, as Ada tasks are always implemented
31172 on top of a thread. But if @value{GDBN} cannot find this corresponding
31173 thread for any reason, the field is omitted.
31174
31175 @item parent-id
31176 This field exists only when the task was created by another task.
31177 In this case, it provides the ID of the parent task.
31178
31179 @item priority
31180 The base priority of the task.
31181
31182 @item state
31183 The current state of the task. For a detailed description of the
31184 possible states, see @ref{Ada Tasks}.
31185
31186 @item name
31187 The name of the task.
31188
31189 @end table
31190
31191 @subsubheading Example
31192
31193 @smallexample
31194 -ada-task-info
31195 ^done,tasks=@{nr_rows="3",nr_cols="8",
31196 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31197 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31198 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31199 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31200 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31201 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31202 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31203 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31204 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31205 state="Child Termination Wait",name="main_task"@}]@}
31206 (gdb)
31207 @end smallexample
31208
31209 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31210 @node GDB/MI Program Execution
31211 @section @sc{gdb/mi} Program Execution
31212
31213 These are the asynchronous commands which generate the out-of-band
31214 record @samp{*stopped}. Currently @value{GDBN} only really executes
31215 asynchronously with remote targets and this interaction is mimicked in
31216 other cases.
31217
31218 @subheading The @code{-exec-continue} Command
31219 @findex -exec-continue
31220
31221 @subsubheading Synopsis
31222
31223 @smallexample
31224 -exec-continue [--reverse] [--all|--thread-group N]
31225 @end smallexample
31226
31227 Resumes the execution of the inferior program, which will continue
31228 to execute until it reaches a debugger stop event. If the
31229 @samp{--reverse} option is specified, execution resumes in reverse until
31230 it reaches a stop event. Stop events may include
31231 @itemize @bullet
31232 @item
31233 breakpoints or watchpoints
31234 @item
31235 signals or exceptions
31236 @item
31237 the end of the process (or its beginning under @samp{--reverse})
31238 @item
31239 the end or beginning of a replay log if one is being used.
31240 @end itemize
31241 In all-stop mode (@pxref{All-Stop
31242 Mode}), may resume only one thread, or all threads, depending on the
31243 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31244 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31245 ignored in all-stop mode. If the @samp{--thread-group} options is
31246 specified, then all threads in that thread group are resumed.
31247
31248 @subsubheading @value{GDBN} Command
31249
31250 The corresponding @value{GDBN} corresponding is @samp{continue}.
31251
31252 @subsubheading Example
31253
31254 @smallexample
31255 -exec-continue
31256 ^running
31257 (gdb)
31258 @@Hello world
31259 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31260 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31261 line="13",arch="i386:x86_64"@}
31262 (gdb)
31263 @end smallexample
31264
31265
31266 @subheading The @code{-exec-finish} Command
31267 @findex -exec-finish
31268
31269 @subsubheading Synopsis
31270
31271 @smallexample
31272 -exec-finish [--reverse]
31273 @end smallexample
31274
31275 Resumes the execution of the inferior program until the current
31276 function is exited. Displays the results returned by the function.
31277 If the @samp{--reverse} option is specified, resumes the reverse
31278 execution of the inferior program until the point where current
31279 function was called.
31280
31281 @subsubheading @value{GDBN} Command
31282
31283 The corresponding @value{GDBN} command is @samp{finish}.
31284
31285 @subsubheading Example
31286
31287 Function returning @code{void}.
31288
31289 @smallexample
31290 -exec-finish
31291 ^running
31292 (gdb)
31293 @@hello from foo
31294 *stopped,reason="function-finished",frame=@{func="main",args=[],
31295 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31296 (gdb)
31297 @end smallexample
31298
31299 Function returning other than @code{void}. The name of the internal
31300 @value{GDBN} variable storing the result is printed, together with the
31301 value itself.
31302
31303 @smallexample
31304 -exec-finish
31305 ^running
31306 (gdb)
31307 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31308 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31309 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31310 arch="i386:x86_64"@},
31311 gdb-result-var="$1",return-value="0"
31312 (gdb)
31313 @end smallexample
31314
31315
31316 @subheading The @code{-exec-interrupt} Command
31317 @findex -exec-interrupt
31318
31319 @subsubheading Synopsis
31320
31321 @smallexample
31322 -exec-interrupt [--all|--thread-group N]
31323 @end smallexample
31324
31325 Interrupts the background execution of the target. Note how the token
31326 associated with the stop message is the one for the execution command
31327 that has been interrupted. The token for the interrupt itself only
31328 appears in the @samp{^done} output. If the user is trying to
31329 interrupt a non-running program, an error message will be printed.
31330
31331 Note that when asynchronous execution is enabled, this command is
31332 asynchronous just like other execution commands. That is, first the
31333 @samp{^done} response will be printed, and the target stop will be
31334 reported after that using the @samp{*stopped} notification.
31335
31336 In non-stop mode, only the context thread is interrupted by default.
31337 All threads (in all inferiors) will be interrupted if the
31338 @samp{--all} option is specified. If the @samp{--thread-group}
31339 option is specified, all threads in that group will be interrupted.
31340
31341 @subsubheading @value{GDBN} Command
31342
31343 The corresponding @value{GDBN} command is @samp{interrupt}.
31344
31345 @subsubheading Example
31346
31347 @smallexample
31348 (gdb)
31349 111-exec-continue
31350 111^running
31351
31352 (gdb)
31353 222-exec-interrupt
31354 222^done
31355 (gdb)
31356 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
31357 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
31358 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
31359 (gdb)
31360
31361 (gdb)
31362 -exec-interrupt
31363 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
31364 (gdb)
31365 @end smallexample
31366
31367 @subheading The @code{-exec-jump} Command
31368 @findex -exec-jump
31369
31370 @subsubheading Synopsis
31371
31372 @smallexample
31373 -exec-jump @var{location}
31374 @end smallexample
31375
31376 Resumes execution of the inferior program at the location specified by
31377 parameter. @xref{Specify Location}, for a description of the
31378 different forms of @var{location}.
31379
31380 @subsubheading @value{GDBN} Command
31381
31382 The corresponding @value{GDBN} command is @samp{jump}.
31383
31384 @subsubheading Example
31385
31386 @smallexample
31387 -exec-jump foo.c:10
31388 *running,thread-id="all"
31389 ^running
31390 @end smallexample
31391
31392
31393 @subheading The @code{-exec-next} Command
31394 @findex -exec-next
31395
31396 @subsubheading Synopsis
31397
31398 @smallexample
31399 -exec-next [--reverse]
31400 @end smallexample
31401
31402 Resumes execution of the inferior program, stopping when the beginning
31403 of the next source line is reached.
31404
31405 If the @samp{--reverse} option is specified, resumes reverse execution
31406 of the inferior program, stopping at the beginning of the previous
31407 source line. If you issue this command on the first line of a
31408 function, it will take you back to the caller of that function, to the
31409 source line where the function was called.
31410
31411
31412 @subsubheading @value{GDBN} Command
31413
31414 The corresponding @value{GDBN} command is @samp{next}.
31415
31416 @subsubheading Example
31417
31418 @smallexample
31419 -exec-next
31420 ^running
31421 (gdb)
31422 *stopped,reason="end-stepping-range",line="8",file="hello.c"
31423 (gdb)
31424 @end smallexample
31425
31426
31427 @subheading The @code{-exec-next-instruction} Command
31428 @findex -exec-next-instruction
31429
31430 @subsubheading Synopsis
31431
31432 @smallexample
31433 -exec-next-instruction [--reverse]
31434 @end smallexample
31435
31436 Executes one machine instruction. If the instruction is a function
31437 call, continues until the function returns. If the program stops at an
31438 instruction in the middle of a source line, the address will be
31439 printed as well.
31440
31441 If the @samp{--reverse} option is specified, resumes reverse execution
31442 of the inferior program, stopping at the previous instruction. If the
31443 previously executed instruction was a return from another function,
31444 it will continue to execute in reverse until the call to that function
31445 (from the current stack frame) is reached.
31446
31447 @subsubheading @value{GDBN} Command
31448
31449 The corresponding @value{GDBN} command is @samp{nexti}.
31450
31451 @subsubheading Example
31452
31453 @smallexample
31454 (gdb)
31455 -exec-next-instruction
31456 ^running
31457
31458 (gdb)
31459 *stopped,reason="end-stepping-range",
31460 addr="0x000100d4",line="5",file="hello.c"
31461 (gdb)
31462 @end smallexample
31463
31464
31465 @subheading The @code{-exec-return} Command
31466 @findex -exec-return
31467
31468 @subsubheading Synopsis
31469
31470 @smallexample
31471 -exec-return
31472 @end smallexample
31473
31474 Makes current function return immediately. Doesn't execute the inferior.
31475 Displays the new current frame.
31476
31477 @subsubheading @value{GDBN} Command
31478
31479 The corresponding @value{GDBN} command is @samp{return}.
31480
31481 @subsubheading Example
31482
31483 @smallexample
31484 (gdb)
31485 200-break-insert callee4
31486 200^done,bkpt=@{number="1",addr="0x00010734",
31487 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31488 (gdb)
31489 000-exec-run
31490 000^running
31491 (gdb)
31492 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31493 frame=@{func="callee4",args=[],
31494 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31495 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31496 arch="i386:x86_64"@}
31497 (gdb)
31498 205-break-delete
31499 205^done
31500 (gdb)
31501 111-exec-return
31502 111^done,frame=@{level="0",func="callee3",
31503 args=[@{name="strarg",
31504 value="0x11940 \"A string argument.\""@}],
31505 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31506 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31507 arch="i386:x86_64"@}
31508 (gdb)
31509 @end smallexample
31510
31511
31512 @subheading The @code{-exec-run} Command
31513 @findex -exec-run
31514
31515 @subsubheading Synopsis
31516
31517 @smallexample
31518 -exec-run [ --all | --thread-group N ] [ --start ]
31519 @end smallexample
31520
31521 Starts execution of the inferior from the beginning. The inferior
31522 executes until either a breakpoint is encountered or the program
31523 exits. In the latter case the output will include an exit code, if
31524 the program has exited exceptionally.
31525
31526 When neither the @samp{--all} nor the @samp{--thread-group} option
31527 is specified, the current inferior is started. If the
31528 @samp{--thread-group} option is specified, it should refer to a thread
31529 group of type @samp{process}, and that thread group will be started.
31530 If the @samp{--all} option is specified, then all inferiors will be started.
31531
31532 Using the @samp{--start} option instructs the debugger to stop
31533 the execution at the start of the inferior's main subprogram,
31534 following the same behavior as the @code{start} command
31535 (@pxref{Starting}).
31536
31537 @subsubheading @value{GDBN} Command
31538
31539 The corresponding @value{GDBN} command is @samp{run}.
31540
31541 @subsubheading Examples
31542
31543 @smallexample
31544 (gdb)
31545 -break-insert main
31546 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31547 (gdb)
31548 -exec-run
31549 ^running
31550 (gdb)
31551 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31552 frame=@{func="main",args=[],file="recursive2.c",
31553 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
31554 (gdb)
31555 @end smallexample
31556
31557 @noindent
31558 Program exited normally:
31559
31560 @smallexample
31561 (gdb)
31562 -exec-run
31563 ^running
31564 (gdb)
31565 x = 55
31566 *stopped,reason="exited-normally"
31567 (gdb)
31568 @end smallexample
31569
31570 @noindent
31571 Program exited exceptionally:
31572
31573 @smallexample
31574 (gdb)
31575 -exec-run
31576 ^running
31577 (gdb)
31578 x = 55
31579 *stopped,reason="exited",exit-code="01"
31580 (gdb)
31581 @end smallexample
31582
31583 Another way the program can terminate is if it receives a signal such as
31584 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31585
31586 @smallexample
31587 (gdb)
31588 *stopped,reason="exited-signalled",signal-name="SIGINT",
31589 signal-meaning="Interrupt"
31590 @end smallexample
31591
31592
31593 @c @subheading -exec-signal
31594
31595
31596 @subheading The @code{-exec-step} Command
31597 @findex -exec-step
31598
31599 @subsubheading Synopsis
31600
31601 @smallexample
31602 -exec-step [--reverse]
31603 @end smallexample
31604
31605 Resumes execution of the inferior program, stopping when the beginning
31606 of the next source line is reached, if the next source line is not a
31607 function call. If it is, stop at the first instruction of the called
31608 function. If the @samp{--reverse} option is specified, resumes reverse
31609 execution of the inferior program, stopping at the beginning of the
31610 previously executed source line.
31611
31612 @subsubheading @value{GDBN} Command
31613
31614 The corresponding @value{GDBN} command is @samp{step}.
31615
31616 @subsubheading Example
31617
31618 Stepping into a function:
31619
31620 @smallexample
31621 -exec-step
31622 ^running
31623 (gdb)
31624 *stopped,reason="end-stepping-range",
31625 frame=@{func="foo",args=[@{name="a",value="10"@},
31626 @{name="b",value="0"@}],file="recursive2.c",
31627 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
31628 (gdb)
31629 @end smallexample
31630
31631 Regular stepping:
31632
31633 @smallexample
31634 -exec-step
31635 ^running
31636 (gdb)
31637 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
31638 (gdb)
31639 @end smallexample
31640
31641
31642 @subheading The @code{-exec-step-instruction} Command
31643 @findex -exec-step-instruction
31644
31645 @subsubheading Synopsis
31646
31647 @smallexample
31648 -exec-step-instruction [--reverse]
31649 @end smallexample
31650
31651 Resumes the inferior which executes one machine instruction. If the
31652 @samp{--reverse} option is specified, resumes reverse execution of the
31653 inferior program, stopping at the previously executed instruction.
31654 The output, once @value{GDBN} has stopped, will vary depending on
31655 whether we have stopped in the middle of a source line or not. In the
31656 former case, the address at which the program stopped will be printed
31657 as well.
31658
31659 @subsubheading @value{GDBN} Command
31660
31661 The corresponding @value{GDBN} command is @samp{stepi}.
31662
31663 @subsubheading Example
31664
31665 @smallexample
31666 (gdb)
31667 -exec-step-instruction
31668 ^running
31669
31670 (gdb)
31671 *stopped,reason="end-stepping-range",
31672 frame=@{func="foo",args=[],file="try.c",
31673 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31674 (gdb)
31675 -exec-step-instruction
31676 ^running
31677
31678 (gdb)
31679 *stopped,reason="end-stepping-range",
31680 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
31681 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31682 (gdb)
31683 @end smallexample
31684
31685
31686 @subheading The @code{-exec-until} Command
31687 @findex -exec-until
31688
31689 @subsubheading Synopsis
31690
31691 @smallexample
31692 -exec-until [ @var{location} ]
31693 @end smallexample
31694
31695 Executes the inferior until the @var{location} specified in the
31696 argument is reached. If there is no argument, the inferior executes
31697 until a source line greater than the current one is reached. The
31698 reason for stopping in this case will be @samp{location-reached}.
31699
31700 @subsubheading @value{GDBN} Command
31701
31702 The corresponding @value{GDBN} command is @samp{until}.
31703
31704 @subsubheading Example
31705
31706 @smallexample
31707 (gdb)
31708 -exec-until recursive2.c:6
31709 ^running
31710 (gdb)
31711 x = 55
31712 *stopped,reason="location-reached",frame=@{func="main",args=[],
31713 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31714 arch="i386:x86_64"@}
31715 (gdb)
31716 @end smallexample
31717
31718 @ignore
31719 @subheading -file-clear
31720 Is this going away????
31721 @end ignore
31722
31723 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31724 @node GDB/MI Stack Manipulation
31725 @section @sc{gdb/mi} Stack Manipulation Commands
31726
31727 @subheading The @code{-enable-frame-filters} Command
31728 @findex -enable-frame-filters
31729
31730 @smallexample
31731 -enable-frame-filters
31732 @end smallexample
31733
31734 @value{GDBN} allows Python-based frame filters to affect the output of
31735 the MI commands relating to stack traces. As there is no way to
31736 implement this in a fully backward-compatible way, a front end must
31737 request that this functionality be enabled.
31738
31739 Once enabled, this feature cannot be disabled.
31740
31741 Note that if Python support has not been compiled into @value{GDBN},
31742 this command will still succeed (and do nothing).
31743
31744 @subheading The @code{-stack-info-frame} Command
31745 @findex -stack-info-frame
31746
31747 @subsubheading Synopsis
31748
31749 @smallexample
31750 -stack-info-frame
31751 @end smallexample
31752
31753 Get info on the selected frame.
31754
31755 @subsubheading @value{GDBN} Command
31756
31757 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31758 (without arguments).
31759
31760 @subsubheading Example
31761
31762 @smallexample
31763 (gdb)
31764 -stack-info-frame
31765 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31766 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31767 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31768 arch="i386:x86_64"@}
31769 (gdb)
31770 @end smallexample
31771
31772 @subheading The @code{-stack-info-depth} Command
31773 @findex -stack-info-depth
31774
31775 @subsubheading Synopsis
31776
31777 @smallexample
31778 -stack-info-depth [ @var{max-depth} ]
31779 @end smallexample
31780
31781 Return the depth of the stack. If the integer argument @var{max-depth}
31782 is specified, do not count beyond @var{max-depth} frames.
31783
31784 @subsubheading @value{GDBN} Command
31785
31786 There's no equivalent @value{GDBN} command.
31787
31788 @subsubheading Example
31789
31790 For a stack with frame levels 0 through 11:
31791
31792 @smallexample
31793 (gdb)
31794 -stack-info-depth
31795 ^done,depth="12"
31796 (gdb)
31797 -stack-info-depth 4
31798 ^done,depth="4"
31799 (gdb)
31800 -stack-info-depth 12
31801 ^done,depth="12"
31802 (gdb)
31803 -stack-info-depth 11
31804 ^done,depth="11"
31805 (gdb)
31806 -stack-info-depth 13
31807 ^done,depth="12"
31808 (gdb)
31809 @end smallexample
31810
31811 @anchor{-stack-list-arguments}
31812 @subheading The @code{-stack-list-arguments} Command
31813 @findex -stack-list-arguments
31814
31815 @subsubheading Synopsis
31816
31817 @smallexample
31818 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31819 [ @var{low-frame} @var{high-frame} ]
31820 @end smallexample
31821
31822 Display a list of the arguments for the frames between @var{low-frame}
31823 and @var{high-frame} (inclusive). If @var{low-frame} and
31824 @var{high-frame} are not provided, list the arguments for the whole
31825 call stack. If the two arguments are equal, show the single frame
31826 at the corresponding level. It is an error if @var{low-frame} is
31827 larger than the actual number of frames. On the other hand,
31828 @var{high-frame} may be larger than the actual number of frames, in
31829 which case only existing frames will be returned.
31830
31831 If @var{print-values} is 0 or @code{--no-values}, print only the names of
31832 the variables; if it is 1 or @code{--all-values}, print also their
31833 values; and if it is 2 or @code{--simple-values}, print the name,
31834 type and value for simple data types, and the name and type for arrays,
31835 structures and unions. If the option @code{--no-frame-filters} is
31836 supplied, then Python frame filters will not be executed.
31837
31838 If the @code{--skip-unavailable} option is specified, arguments that
31839 are not available are not listed. Partially available arguments
31840 are still displayed, however.
31841
31842 Use of this command to obtain arguments in a single frame is
31843 deprecated in favor of the @samp{-stack-list-variables} command.
31844
31845 @subsubheading @value{GDBN} Command
31846
31847 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31848 @samp{gdb_get_args} command which partially overlaps with the
31849 functionality of @samp{-stack-list-arguments}.
31850
31851 @subsubheading Example
31852
31853 @smallexample
31854 (gdb)
31855 -stack-list-frames
31856 ^done,
31857 stack=[
31858 frame=@{level="0",addr="0x00010734",func="callee4",
31859 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31860 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31861 arch="i386:x86_64"@},
31862 frame=@{level="1",addr="0x0001076c",func="callee3",
31863 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31864 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31865 arch="i386:x86_64"@},
31866 frame=@{level="2",addr="0x0001078c",func="callee2",
31867 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31868 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31869 arch="i386:x86_64"@},
31870 frame=@{level="3",addr="0x000107b4",func="callee1",
31871 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31872 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31873 arch="i386:x86_64"@},
31874 frame=@{level="4",addr="0x000107e0",func="main",
31875 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31876 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31877 arch="i386:x86_64"@}]
31878 (gdb)
31879 -stack-list-arguments 0
31880 ^done,
31881 stack-args=[
31882 frame=@{level="0",args=[]@},
31883 frame=@{level="1",args=[name="strarg"]@},
31884 frame=@{level="2",args=[name="intarg",name="strarg"]@},
31885 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31886 frame=@{level="4",args=[]@}]
31887 (gdb)
31888 -stack-list-arguments 1
31889 ^done,
31890 stack-args=[
31891 frame=@{level="0",args=[]@},
31892 frame=@{level="1",
31893 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31894 frame=@{level="2",args=[
31895 @{name="intarg",value="2"@},
31896 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31897 @{frame=@{level="3",args=[
31898 @{name="intarg",value="2"@},
31899 @{name="strarg",value="0x11940 \"A string argument.\""@},
31900 @{name="fltarg",value="3.5"@}]@},
31901 frame=@{level="4",args=[]@}]
31902 (gdb)
31903 -stack-list-arguments 0 2 2
31904 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
31905 (gdb)
31906 -stack-list-arguments 1 2 2
31907 ^done,stack-args=[frame=@{level="2",
31908 args=[@{name="intarg",value="2"@},
31909 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
31910 (gdb)
31911 @end smallexample
31912
31913 @c @subheading -stack-list-exception-handlers
31914
31915
31916 @anchor{-stack-list-frames}
31917 @subheading The @code{-stack-list-frames} Command
31918 @findex -stack-list-frames
31919
31920 @subsubheading Synopsis
31921
31922 @smallexample
31923 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
31924 @end smallexample
31925
31926 List the frames currently on the stack. For each frame it displays the
31927 following info:
31928
31929 @table @samp
31930 @item @var{level}
31931 The frame number, 0 being the topmost frame, i.e., the innermost function.
31932 @item @var{addr}
31933 The @code{$pc} value for that frame.
31934 @item @var{func}
31935 Function name.
31936 @item @var{file}
31937 File name of the source file where the function lives.
31938 @item @var{fullname}
31939 The full file name of the source file where the function lives.
31940 @item @var{line}
31941 Line number corresponding to the @code{$pc}.
31942 @item @var{from}
31943 The shared library where this function is defined. This is only given
31944 if the frame's function is not known.
31945 @item @var{arch}
31946 Frame's architecture.
31947 @end table
31948
31949 If invoked without arguments, this command prints a backtrace for the
31950 whole stack. If given two integer arguments, it shows the frames whose
31951 levels are between the two arguments (inclusive). If the two arguments
31952 are equal, it shows the single frame at the corresponding level. It is
31953 an error if @var{low-frame} is larger than the actual number of
31954 frames. On the other hand, @var{high-frame} may be larger than the
31955 actual number of frames, in which case only existing frames will be
31956 returned. If the option @code{--no-frame-filters} is supplied, then
31957 Python frame filters will not be executed.
31958
31959 @subsubheading @value{GDBN} Command
31960
31961 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
31962
31963 @subsubheading Example
31964
31965 Full stack backtrace:
31966
31967 @smallexample
31968 (gdb)
31969 -stack-list-frames
31970 ^done,stack=
31971 [frame=@{level="0",addr="0x0001076c",func="foo",
31972 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
31973 arch="i386:x86_64"@},
31974 frame=@{level="1",addr="0x000107a4",func="foo",
31975 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31976 arch="i386:x86_64"@},
31977 frame=@{level="2",addr="0x000107a4",func="foo",
31978 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31979 arch="i386:x86_64"@},
31980 frame=@{level="3",addr="0x000107a4",func="foo",
31981 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31982 arch="i386:x86_64"@},
31983 frame=@{level="4",addr="0x000107a4",func="foo",
31984 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31985 arch="i386:x86_64"@},
31986 frame=@{level="5",addr="0x000107a4",func="foo",
31987 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31988 arch="i386:x86_64"@},
31989 frame=@{level="6",addr="0x000107a4",func="foo",
31990 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31991 arch="i386:x86_64"@},
31992 frame=@{level="7",addr="0x000107a4",func="foo",
31993 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31994 arch="i386:x86_64"@},
31995 frame=@{level="8",addr="0x000107a4",func="foo",
31996 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31997 arch="i386:x86_64"@},
31998 frame=@{level="9",addr="0x000107a4",func="foo",
31999 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32000 arch="i386:x86_64"@},
32001 frame=@{level="10",addr="0x000107a4",func="foo",
32002 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32003 arch="i386:x86_64"@},
32004 frame=@{level="11",addr="0x00010738",func="main",
32005 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32006 arch="i386:x86_64"@}]
32007 (gdb)
32008 @end smallexample
32009
32010 Show frames between @var{low_frame} and @var{high_frame}:
32011
32012 @smallexample
32013 (gdb)
32014 -stack-list-frames 3 5
32015 ^done,stack=
32016 [frame=@{level="3",addr="0x000107a4",func="foo",
32017 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32018 arch="i386:x86_64"@},
32019 frame=@{level="4",addr="0x000107a4",func="foo",
32020 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32021 arch="i386:x86_64"@},
32022 frame=@{level="5",addr="0x000107a4",func="foo",
32023 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32024 arch="i386:x86_64"@}]
32025 (gdb)
32026 @end smallexample
32027
32028 Show a single frame:
32029
32030 @smallexample
32031 (gdb)
32032 -stack-list-frames 3 3
32033 ^done,stack=
32034 [frame=@{level="3",addr="0x000107a4",func="foo",
32035 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32036 arch="i386:x86_64"@}]
32037 (gdb)
32038 @end smallexample
32039
32040
32041 @subheading The @code{-stack-list-locals} Command
32042 @findex -stack-list-locals
32043 @anchor{-stack-list-locals}
32044
32045 @subsubheading Synopsis
32046
32047 @smallexample
32048 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32049 @end smallexample
32050
32051 Display the local variable names for the selected frame. If
32052 @var{print-values} is 0 or @code{--no-values}, print only the names of
32053 the variables; if it is 1 or @code{--all-values}, print also their
32054 values; and if it is 2 or @code{--simple-values}, print the name,
32055 type and value for simple data types, and the name and type for arrays,
32056 structures and unions. In this last case, a frontend can immediately
32057 display the value of simple data types and create variable objects for
32058 other data types when the user wishes to explore their values in
32059 more detail. If the option @code{--no-frame-filters} is supplied, then
32060 Python frame filters will not be executed.
32061
32062 If the @code{--skip-unavailable} option is specified, local variables
32063 that are not available are not listed. Partially available local
32064 variables are still displayed, however.
32065
32066 This command is deprecated in favor of the
32067 @samp{-stack-list-variables} command.
32068
32069 @subsubheading @value{GDBN} Command
32070
32071 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32072
32073 @subsubheading Example
32074
32075 @smallexample
32076 (gdb)
32077 -stack-list-locals 0
32078 ^done,locals=[name="A",name="B",name="C"]
32079 (gdb)
32080 -stack-list-locals --all-values
32081 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32082 @{name="C",value="@{1, 2, 3@}"@}]
32083 -stack-list-locals --simple-values
32084 ^done,locals=[@{name="A",type="int",value="1"@},
32085 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32086 (gdb)
32087 @end smallexample
32088
32089 @anchor{-stack-list-variables}
32090 @subheading The @code{-stack-list-variables} Command
32091 @findex -stack-list-variables
32092
32093 @subsubheading Synopsis
32094
32095 @smallexample
32096 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32097 @end smallexample
32098
32099 Display the names of local variables and function arguments for the selected frame. If
32100 @var{print-values} is 0 or @code{--no-values}, print only the names of
32101 the variables; if it is 1 or @code{--all-values}, print also their
32102 values; and if it is 2 or @code{--simple-values}, print the name,
32103 type and value for simple data types, and the name and type for arrays,
32104 structures and unions. If the option @code{--no-frame-filters} is
32105 supplied, then Python frame filters will not be executed.
32106
32107 If the @code{--skip-unavailable} option is specified, local variables
32108 and arguments that are not available are not listed. Partially
32109 available arguments and local variables are still displayed, however.
32110
32111 @subsubheading Example
32112
32113 @smallexample
32114 (gdb)
32115 -stack-list-variables --thread 1 --frame 0 --all-values
32116 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32117 (gdb)
32118 @end smallexample
32119
32120
32121 @subheading The @code{-stack-select-frame} Command
32122 @findex -stack-select-frame
32123
32124 @subsubheading Synopsis
32125
32126 @smallexample
32127 -stack-select-frame @var{framenum}
32128 @end smallexample
32129
32130 Change the selected frame. Select a different frame @var{framenum} on
32131 the stack.
32132
32133 This command in deprecated in favor of passing the @samp{--frame}
32134 option to every command.
32135
32136 @subsubheading @value{GDBN} Command
32137
32138 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32139 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32140
32141 @subsubheading Example
32142
32143 @smallexample
32144 (gdb)
32145 -stack-select-frame 2
32146 ^done
32147 (gdb)
32148 @end smallexample
32149
32150 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32151 @node GDB/MI Variable Objects
32152 @section @sc{gdb/mi} Variable Objects
32153
32154 @ignore
32155
32156 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32157
32158 For the implementation of a variable debugger window (locals, watched
32159 expressions, etc.), we are proposing the adaptation of the existing code
32160 used by @code{Insight}.
32161
32162 The two main reasons for that are:
32163
32164 @enumerate 1
32165 @item
32166 It has been proven in practice (it is already on its second generation).
32167
32168 @item
32169 It will shorten development time (needless to say how important it is
32170 now).
32171 @end enumerate
32172
32173 The original interface was designed to be used by Tcl code, so it was
32174 slightly changed so it could be used through @sc{gdb/mi}. This section
32175 describes the @sc{gdb/mi} operations that will be available and gives some
32176 hints about their use.
32177
32178 @emph{Note}: In addition to the set of operations described here, we
32179 expect the @sc{gui} implementation of a variable window to require, at
32180 least, the following operations:
32181
32182 @itemize @bullet
32183 @item @code{-gdb-show} @code{output-radix}
32184 @item @code{-stack-list-arguments}
32185 @item @code{-stack-list-locals}
32186 @item @code{-stack-select-frame}
32187 @end itemize
32188
32189 @end ignore
32190
32191 @subheading Introduction to Variable Objects
32192
32193 @cindex variable objects in @sc{gdb/mi}
32194
32195 Variable objects are "object-oriented" MI interface for examining and
32196 changing values of expressions. Unlike some other MI interfaces that
32197 work with expressions, variable objects are specifically designed for
32198 simple and efficient presentation in the frontend. A variable object
32199 is identified by string name. When a variable object is created, the
32200 frontend specifies the expression for that variable object. The
32201 expression can be a simple variable, or it can be an arbitrary complex
32202 expression, and can even involve CPU registers. After creating a
32203 variable object, the frontend can invoke other variable object
32204 operations---for example to obtain or change the value of a variable
32205 object, or to change display format.
32206
32207 Variable objects have hierarchical tree structure. Any variable object
32208 that corresponds to a composite type, such as structure in C, has
32209 a number of child variable objects, for example corresponding to each
32210 element of a structure. A child variable object can itself have
32211 children, recursively. Recursion ends when we reach
32212 leaf variable objects, which always have built-in types. Child variable
32213 objects are created only by explicit request, so if a frontend
32214 is not interested in the children of a particular variable object, no
32215 child will be created.
32216
32217 For a leaf variable object it is possible to obtain its value as a
32218 string, or set the value from a string. String value can be also
32219 obtained for a non-leaf variable object, but it's generally a string
32220 that only indicates the type of the object, and does not list its
32221 contents. Assignment to a non-leaf variable object is not allowed.
32222
32223 A frontend does not need to read the values of all variable objects each time
32224 the program stops. Instead, MI provides an update command that lists all
32225 variable objects whose values has changed since the last update
32226 operation. This considerably reduces the amount of data that must
32227 be transferred to the frontend. As noted above, children variable
32228 objects are created on demand, and only leaf variable objects have a
32229 real value. As result, gdb will read target memory only for leaf
32230 variables that frontend has created.
32231
32232 The automatic update is not always desirable. For example, a frontend
32233 might want to keep a value of some expression for future reference,
32234 and never update it. For another example, fetching memory is
32235 relatively slow for embedded targets, so a frontend might want
32236 to disable automatic update for the variables that are either not
32237 visible on the screen, or ``closed''. This is possible using so
32238 called ``frozen variable objects''. Such variable objects are never
32239 implicitly updated.
32240
32241 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32242 fixed variable object, the expression is parsed when the variable
32243 object is created, including associating identifiers to specific
32244 variables. The meaning of expression never changes. For a floating
32245 variable object the values of variables whose names appear in the
32246 expressions are re-evaluated every time in the context of the current
32247 frame. Consider this example:
32248
32249 @smallexample
32250 void do_work(...)
32251 @{
32252 struct work_state state;
32253
32254 if (...)
32255 do_work(...);
32256 @}
32257 @end smallexample
32258
32259 If a fixed variable object for the @code{state} variable is created in
32260 this function, and we enter the recursive call, the variable
32261 object will report the value of @code{state} in the top-level
32262 @code{do_work} invocation. On the other hand, a floating variable
32263 object will report the value of @code{state} in the current frame.
32264
32265 If an expression specified when creating a fixed variable object
32266 refers to a local variable, the variable object becomes bound to the
32267 thread and frame in which the variable object is created. When such
32268 variable object is updated, @value{GDBN} makes sure that the
32269 thread/frame combination the variable object is bound to still exists,
32270 and re-evaluates the variable object in context of that thread/frame.
32271
32272 The following is the complete set of @sc{gdb/mi} operations defined to
32273 access this functionality:
32274
32275 @multitable @columnfractions .4 .6
32276 @item @strong{Operation}
32277 @tab @strong{Description}
32278
32279 @item @code{-enable-pretty-printing}
32280 @tab enable Python-based pretty-printing
32281 @item @code{-var-create}
32282 @tab create a variable object
32283 @item @code{-var-delete}
32284 @tab delete the variable object and/or its children
32285 @item @code{-var-set-format}
32286 @tab set the display format of this variable
32287 @item @code{-var-show-format}
32288 @tab show the display format of this variable
32289 @item @code{-var-info-num-children}
32290 @tab tells how many children this object has
32291 @item @code{-var-list-children}
32292 @tab return a list of the object's children
32293 @item @code{-var-info-type}
32294 @tab show the type of this variable object
32295 @item @code{-var-info-expression}
32296 @tab print parent-relative expression that this variable object represents
32297 @item @code{-var-info-path-expression}
32298 @tab print full expression that this variable object represents
32299 @item @code{-var-show-attributes}
32300 @tab is this variable editable? does it exist here?
32301 @item @code{-var-evaluate-expression}
32302 @tab get the value of this variable
32303 @item @code{-var-assign}
32304 @tab set the value of this variable
32305 @item @code{-var-update}
32306 @tab update the variable and its children
32307 @item @code{-var-set-frozen}
32308 @tab set frozenness attribute
32309 @item @code{-var-set-update-range}
32310 @tab set range of children to display on update
32311 @end multitable
32312
32313 In the next subsection we describe each operation in detail and suggest
32314 how it can be used.
32315
32316 @subheading Description And Use of Operations on Variable Objects
32317
32318 @subheading The @code{-enable-pretty-printing} Command
32319 @findex -enable-pretty-printing
32320
32321 @smallexample
32322 -enable-pretty-printing
32323 @end smallexample
32324
32325 @value{GDBN} allows Python-based visualizers to affect the output of the
32326 MI variable object commands. However, because there was no way to
32327 implement this in a fully backward-compatible way, a front end must
32328 request that this functionality be enabled.
32329
32330 Once enabled, this feature cannot be disabled.
32331
32332 Note that if Python support has not been compiled into @value{GDBN},
32333 this command will still succeed (and do nothing).
32334
32335 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32336 may work differently in future versions of @value{GDBN}.
32337
32338 @subheading The @code{-var-create} Command
32339 @findex -var-create
32340
32341 @subsubheading Synopsis
32342
32343 @smallexample
32344 -var-create @{@var{name} | "-"@}
32345 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32346 @end smallexample
32347
32348 This operation creates a variable object, which allows the monitoring of
32349 a variable, the result of an expression, a memory cell or a CPU
32350 register.
32351
32352 The @var{name} parameter is the string by which the object can be
32353 referenced. It must be unique. If @samp{-} is specified, the varobj
32354 system will generate a string ``varNNNNNN'' automatically. It will be
32355 unique provided that one does not specify @var{name} of that format.
32356 The command fails if a duplicate name is found.
32357
32358 The frame under which the expression should be evaluated can be
32359 specified by @var{frame-addr}. A @samp{*} indicates that the current
32360 frame should be used. A @samp{@@} indicates that a floating variable
32361 object must be created.
32362
32363 @var{expression} is any expression valid on the current language set (must not
32364 begin with a @samp{*}), or one of the following:
32365
32366 @itemize @bullet
32367 @item
32368 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
32369
32370 @item
32371 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
32372
32373 @item
32374 @samp{$@var{regname}} --- a CPU register name
32375 @end itemize
32376
32377 @cindex dynamic varobj
32378 A varobj's contents may be provided by a Python-based pretty-printer. In this
32379 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32380 have slightly different semantics in some cases. If the
32381 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32382 will never create a dynamic varobj. This ensures backward
32383 compatibility for existing clients.
32384
32385 @subsubheading Result
32386
32387 This operation returns attributes of the newly-created varobj. These
32388 are:
32389
32390 @table @samp
32391 @item name
32392 The name of the varobj.
32393
32394 @item numchild
32395 The number of children of the varobj. This number is not necessarily
32396 reliable for a dynamic varobj. Instead, you must examine the
32397 @samp{has_more} attribute.
32398
32399 @item value
32400 The varobj's scalar value. For a varobj whose type is some sort of
32401 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32402 will not be interesting.
32403
32404 @item type
32405 The varobj's type. This is a string representation of the type, as
32406 would be printed by the @value{GDBN} CLI. If @samp{print object}
32407 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32408 @emph{actual} (derived) type of the object is shown rather than the
32409 @emph{declared} one.
32410
32411 @item thread-id
32412 If a variable object is bound to a specific thread, then this is the
32413 thread's global identifier.
32414
32415 @item has_more
32416 For a dynamic varobj, this indicates whether there appear to be any
32417 children available. For a non-dynamic varobj, this will be 0.
32418
32419 @item dynamic
32420 This attribute will be present and have the value @samp{1} if the
32421 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32422 then this attribute will not be present.
32423
32424 @item displayhint
32425 A dynamic varobj can supply a display hint to the front end. The
32426 value comes directly from the Python pretty-printer object's
32427 @code{display_hint} method. @xref{Pretty Printing API}.
32428 @end table
32429
32430 Typical output will look like this:
32431
32432 @smallexample
32433 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32434 has_more="@var{has_more}"
32435 @end smallexample
32436
32437
32438 @subheading The @code{-var-delete} Command
32439 @findex -var-delete
32440
32441 @subsubheading Synopsis
32442
32443 @smallexample
32444 -var-delete [ -c ] @var{name}
32445 @end smallexample
32446
32447 Deletes a previously created variable object and all of its children.
32448 With the @samp{-c} option, just deletes the children.
32449
32450 Returns an error if the object @var{name} is not found.
32451
32452
32453 @subheading The @code{-var-set-format} Command
32454 @findex -var-set-format
32455
32456 @subsubheading Synopsis
32457
32458 @smallexample
32459 -var-set-format @var{name} @var{format-spec}
32460 @end smallexample
32461
32462 Sets the output format for the value of the object @var{name} to be
32463 @var{format-spec}.
32464
32465 @anchor{-var-set-format}
32466 The syntax for the @var{format-spec} is as follows:
32467
32468 @smallexample
32469 @var{format-spec} @expansion{}
32470 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
32471 @end smallexample
32472
32473 The natural format is the default format choosen automatically
32474 based on the variable type (like decimal for an @code{int}, hex
32475 for pointers, etc.).
32476
32477 The zero-hexadecimal format has a representation similar to hexadecimal
32478 but with padding zeroes to the left of the value. For example, a 32-bit
32479 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32480 zero-hexadecimal format.
32481
32482 For a variable with children, the format is set only on the
32483 variable itself, and the children are not affected.
32484
32485 @subheading The @code{-var-show-format} Command
32486 @findex -var-show-format
32487
32488 @subsubheading Synopsis
32489
32490 @smallexample
32491 -var-show-format @var{name}
32492 @end smallexample
32493
32494 Returns the format used to display the value of the object @var{name}.
32495
32496 @smallexample
32497 @var{format} @expansion{}
32498 @var{format-spec}
32499 @end smallexample
32500
32501
32502 @subheading The @code{-var-info-num-children} Command
32503 @findex -var-info-num-children
32504
32505 @subsubheading Synopsis
32506
32507 @smallexample
32508 -var-info-num-children @var{name}
32509 @end smallexample
32510
32511 Returns the number of children of a variable object @var{name}:
32512
32513 @smallexample
32514 numchild=@var{n}
32515 @end smallexample
32516
32517 Note that this number is not completely reliable for a dynamic varobj.
32518 It will return the current number of children, but more children may
32519 be available.
32520
32521
32522 @subheading The @code{-var-list-children} Command
32523 @findex -var-list-children
32524
32525 @subsubheading Synopsis
32526
32527 @smallexample
32528 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32529 @end smallexample
32530 @anchor{-var-list-children}
32531
32532 Return a list of the children of the specified variable object and
32533 create variable objects for them, if they do not already exist. With
32534 a single argument or if @var{print-values} has a value of 0 or
32535 @code{--no-values}, print only the names of the variables; if
32536 @var{print-values} is 1 or @code{--all-values}, also print their
32537 values; and if it is 2 or @code{--simple-values} print the name and
32538 value for simple data types and just the name for arrays, structures
32539 and unions.
32540
32541 @var{from} and @var{to}, if specified, indicate the range of children
32542 to report. If @var{from} or @var{to} is less than zero, the range is
32543 reset and all children will be reported. Otherwise, children starting
32544 at @var{from} (zero-based) and up to and excluding @var{to} will be
32545 reported.
32546
32547 If a child range is requested, it will only affect the current call to
32548 @code{-var-list-children}, but not future calls to @code{-var-update}.
32549 For this, you must instead use @code{-var-set-update-range}. The
32550 intent of this approach is to enable a front end to implement any
32551 update approach it likes; for example, scrolling a view may cause the
32552 front end to request more children with @code{-var-list-children}, and
32553 then the front end could call @code{-var-set-update-range} with a
32554 different range to ensure that future updates are restricted to just
32555 the visible items.
32556
32557 For each child the following results are returned:
32558
32559 @table @var
32560
32561 @item name
32562 Name of the variable object created for this child.
32563
32564 @item exp
32565 The expression to be shown to the user by the front end to designate this child.
32566 For example this may be the name of a structure member.
32567
32568 For a dynamic varobj, this value cannot be used to form an
32569 expression. There is no way to do this at all with a dynamic varobj.
32570
32571 For C/C@t{++} structures there are several pseudo children returned to
32572 designate access qualifiers. For these pseudo children @var{exp} is
32573 @samp{public}, @samp{private}, or @samp{protected}. In this case the
32574 type and value are not present.
32575
32576 A dynamic varobj will not report the access qualifying
32577 pseudo-children, regardless of the language. This information is not
32578 available at all with a dynamic varobj.
32579
32580 @item numchild
32581 Number of children this child has. For a dynamic varobj, this will be
32582 0.
32583
32584 @item type
32585 The type of the child. If @samp{print object}
32586 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32587 @emph{actual} (derived) type of the object is shown rather than the
32588 @emph{declared} one.
32589
32590 @item value
32591 If values were requested, this is the value.
32592
32593 @item thread-id
32594 If this variable object is associated with a thread, this is the
32595 thread's global thread id. Otherwise this result is not present.
32596
32597 @item frozen
32598 If the variable object is frozen, this variable will be present with a value of 1.
32599
32600 @item displayhint
32601 A dynamic varobj can supply a display hint to the front end. The
32602 value comes directly from the Python pretty-printer object's
32603 @code{display_hint} method. @xref{Pretty Printing API}.
32604
32605 @item dynamic
32606 This attribute will be present and have the value @samp{1} if the
32607 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32608 then this attribute will not be present.
32609
32610 @end table
32611
32612 The result may have its own attributes:
32613
32614 @table @samp
32615 @item displayhint
32616 A dynamic varobj can supply a display hint to the front end. The
32617 value comes directly from the Python pretty-printer object's
32618 @code{display_hint} method. @xref{Pretty Printing API}.
32619
32620 @item has_more
32621 This is an integer attribute which is nonzero if there are children
32622 remaining after the end of the selected range.
32623 @end table
32624
32625 @subsubheading Example
32626
32627 @smallexample
32628 (gdb)
32629 -var-list-children n
32630 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32631 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
32632 (gdb)
32633 -var-list-children --all-values n
32634 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32635 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
32636 @end smallexample
32637
32638
32639 @subheading The @code{-var-info-type} Command
32640 @findex -var-info-type
32641
32642 @subsubheading Synopsis
32643
32644 @smallexample
32645 -var-info-type @var{name}
32646 @end smallexample
32647
32648 Returns the type of the specified variable @var{name}. The type is
32649 returned as a string in the same format as it is output by the
32650 @value{GDBN} CLI:
32651
32652 @smallexample
32653 type=@var{typename}
32654 @end smallexample
32655
32656
32657 @subheading The @code{-var-info-expression} Command
32658 @findex -var-info-expression
32659
32660 @subsubheading Synopsis
32661
32662 @smallexample
32663 -var-info-expression @var{name}
32664 @end smallexample
32665
32666 Returns a string that is suitable for presenting this
32667 variable object in user interface. The string is generally
32668 not valid expression in the current language, and cannot be evaluated.
32669
32670 For example, if @code{a} is an array, and variable object
32671 @code{A} was created for @code{a}, then we'll get this output:
32672
32673 @smallexample
32674 (gdb) -var-info-expression A.1
32675 ^done,lang="C",exp="1"
32676 @end smallexample
32677
32678 @noindent
32679 Here, the value of @code{lang} is the language name, which can be
32680 found in @ref{Supported Languages}.
32681
32682 Note that the output of the @code{-var-list-children} command also
32683 includes those expressions, so the @code{-var-info-expression} command
32684 is of limited use.
32685
32686 @subheading The @code{-var-info-path-expression} Command
32687 @findex -var-info-path-expression
32688
32689 @subsubheading Synopsis
32690
32691 @smallexample
32692 -var-info-path-expression @var{name}
32693 @end smallexample
32694
32695 Returns an expression that can be evaluated in the current
32696 context and will yield the same value that a variable object has.
32697 Compare this with the @code{-var-info-expression} command, which
32698 result can be used only for UI presentation. Typical use of
32699 the @code{-var-info-path-expression} command is creating a
32700 watchpoint from a variable object.
32701
32702 This command is currently not valid for children of a dynamic varobj,
32703 and will give an error when invoked on one.
32704
32705 For example, suppose @code{C} is a C@t{++} class, derived from class
32706 @code{Base}, and that the @code{Base} class has a member called
32707 @code{m_size}. Assume a variable @code{c} is has the type of
32708 @code{C} and a variable object @code{C} was created for variable
32709 @code{c}. Then, we'll get this output:
32710 @smallexample
32711 (gdb) -var-info-path-expression C.Base.public.m_size
32712 ^done,path_expr=((Base)c).m_size)
32713 @end smallexample
32714
32715 @subheading The @code{-var-show-attributes} Command
32716 @findex -var-show-attributes
32717
32718 @subsubheading Synopsis
32719
32720 @smallexample
32721 -var-show-attributes @var{name}
32722 @end smallexample
32723
32724 List attributes of the specified variable object @var{name}:
32725
32726 @smallexample
32727 status=@var{attr} [ ( ,@var{attr} )* ]
32728 @end smallexample
32729
32730 @noindent
32731 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32732
32733 @subheading The @code{-var-evaluate-expression} Command
32734 @findex -var-evaluate-expression
32735
32736 @subsubheading Synopsis
32737
32738 @smallexample
32739 -var-evaluate-expression [-f @var{format-spec}] @var{name}
32740 @end smallexample
32741
32742 Evaluates the expression that is represented by the specified variable
32743 object and returns its value as a string. The format of the string
32744 can be specified with the @samp{-f} option. The possible values of
32745 this option are the same as for @code{-var-set-format}
32746 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32747 the current display format will be used. The current display format
32748 can be changed using the @code{-var-set-format} command.
32749
32750 @smallexample
32751 value=@var{value}
32752 @end smallexample
32753
32754 Note that one must invoke @code{-var-list-children} for a variable
32755 before the value of a child variable can be evaluated.
32756
32757 @subheading The @code{-var-assign} Command
32758 @findex -var-assign
32759
32760 @subsubheading Synopsis
32761
32762 @smallexample
32763 -var-assign @var{name} @var{expression}
32764 @end smallexample
32765
32766 Assigns the value of @var{expression} to the variable object specified
32767 by @var{name}. The object must be @samp{editable}. If the variable's
32768 value is altered by the assign, the variable will show up in any
32769 subsequent @code{-var-update} list.
32770
32771 @subsubheading Example
32772
32773 @smallexample
32774 (gdb)
32775 -var-assign var1 3
32776 ^done,value="3"
32777 (gdb)
32778 -var-update *
32779 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
32780 (gdb)
32781 @end smallexample
32782
32783 @subheading The @code{-var-update} Command
32784 @findex -var-update
32785
32786 @subsubheading Synopsis
32787
32788 @smallexample
32789 -var-update [@var{print-values}] @{@var{name} | "*"@}
32790 @end smallexample
32791
32792 Reevaluate the expressions corresponding to the variable object
32793 @var{name} and all its direct and indirect children, and return the
32794 list of variable objects whose values have changed; @var{name} must
32795 be a root variable object. Here, ``changed'' means that the result of
32796 @code{-var-evaluate-expression} before and after the
32797 @code{-var-update} is different. If @samp{*} is used as the variable
32798 object names, all existing variable objects are updated, except
32799 for frozen ones (@pxref{-var-set-frozen}). The option
32800 @var{print-values} determines whether both names and values, or just
32801 names are printed. The possible values of this option are the same
32802 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32803 recommended to use the @samp{--all-values} option, to reduce the
32804 number of MI commands needed on each program stop.
32805
32806 With the @samp{*} parameter, if a variable object is bound to a
32807 currently running thread, it will not be updated, without any
32808 diagnostic.
32809
32810 If @code{-var-set-update-range} was previously used on a varobj, then
32811 only the selected range of children will be reported.
32812
32813 @code{-var-update} reports all the changed varobjs in a tuple named
32814 @samp{changelist}.
32815
32816 Each item in the change list is itself a tuple holding:
32817
32818 @table @samp
32819 @item name
32820 The name of the varobj.
32821
32822 @item value
32823 If values were requested for this update, then this field will be
32824 present and will hold the value of the varobj.
32825
32826 @item in_scope
32827 @anchor{-var-update}
32828 This field is a string which may take one of three values:
32829
32830 @table @code
32831 @item "true"
32832 The variable object's current value is valid.
32833
32834 @item "false"
32835 The variable object does not currently hold a valid value but it may
32836 hold one in the future if its associated expression comes back into
32837 scope.
32838
32839 @item "invalid"
32840 The variable object no longer holds a valid value.
32841 This can occur when the executable file being debugged has changed,
32842 either through recompilation or by using the @value{GDBN} @code{file}
32843 command. The front end should normally choose to delete these variable
32844 objects.
32845 @end table
32846
32847 In the future new values may be added to this list so the front should
32848 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32849
32850 @item type_changed
32851 This is only present if the varobj is still valid. If the type
32852 changed, then this will be the string @samp{true}; otherwise it will
32853 be @samp{false}.
32854
32855 When a varobj's type changes, its children are also likely to have
32856 become incorrect. Therefore, the varobj's children are automatically
32857 deleted when this attribute is @samp{true}. Also, the varobj's update
32858 range, when set using the @code{-var-set-update-range} command, is
32859 unset.
32860
32861 @item new_type
32862 If the varobj's type changed, then this field will be present and will
32863 hold the new type.
32864
32865 @item new_num_children
32866 For a dynamic varobj, if the number of children changed, or if the
32867 type changed, this will be the new number of children.
32868
32869 The @samp{numchild} field in other varobj responses is generally not
32870 valid for a dynamic varobj -- it will show the number of children that
32871 @value{GDBN} knows about, but because dynamic varobjs lazily
32872 instantiate their children, this will not reflect the number of
32873 children which may be available.
32874
32875 The @samp{new_num_children} attribute only reports changes to the
32876 number of children known by @value{GDBN}. This is the only way to
32877 detect whether an update has removed children (which necessarily can
32878 only happen at the end of the update range).
32879
32880 @item displayhint
32881 The display hint, if any.
32882
32883 @item has_more
32884 This is an integer value, which will be 1 if there are more children
32885 available outside the varobj's update range.
32886
32887 @item dynamic
32888 This attribute will be present and have the value @samp{1} if the
32889 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32890 then this attribute will not be present.
32891
32892 @item new_children
32893 If new children were added to a dynamic varobj within the selected
32894 update range (as set by @code{-var-set-update-range}), then they will
32895 be listed in this attribute.
32896 @end table
32897
32898 @subsubheading Example
32899
32900 @smallexample
32901 (gdb)
32902 -var-assign var1 3
32903 ^done,value="3"
32904 (gdb)
32905 -var-update --all-values var1
32906 ^done,changelist=[@{name="var1",value="3",in_scope="true",
32907 type_changed="false"@}]
32908 (gdb)
32909 @end smallexample
32910
32911 @subheading The @code{-var-set-frozen} Command
32912 @findex -var-set-frozen
32913 @anchor{-var-set-frozen}
32914
32915 @subsubheading Synopsis
32916
32917 @smallexample
32918 -var-set-frozen @var{name} @var{flag}
32919 @end smallexample
32920
32921 Set the frozenness flag on the variable object @var{name}. The
32922 @var{flag} parameter should be either @samp{1} to make the variable
32923 frozen or @samp{0} to make it unfrozen. If a variable object is
32924 frozen, then neither itself, nor any of its children, are
32925 implicitly updated by @code{-var-update} of
32926 a parent variable or by @code{-var-update *}. Only
32927 @code{-var-update} of the variable itself will update its value and
32928 values of its children. After a variable object is unfrozen, it is
32929 implicitly updated by all subsequent @code{-var-update} operations.
32930 Unfreezing a variable does not update it, only subsequent
32931 @code{-var-update} does.
32932
32933 @subsubheading Example
32934
32935 @smallexample
32936 (gdb)
32937 -var-set-frozen V 1
32938 ^done
32939 (gdb)
32940 @end smallexample
32941
32942 @subheading The @code{-var-set-update-range} command
32943 @findex -var-set-update-range
32944 @anchor{-var-set-update-range}
32945
32946 @subsubheading Synopsis
32947
32948 @smallexample
32949 -var-set-update-range @var{name} @var{from} @var{to}
32950 @end smallexample
32951
32952 Set the range of children to be returned by future invocations of
32953 @code{-var-update}.
32954
32955 @var{from} and @var{to} indicate the range of children to report. If
32956 @var{from} or @var{to} is less than zero, the range is reset and all
32957 children will be reported. Otherwise, children starting at @var{from}
32958 (zero-based) and up to and excluding @var{to} will be reported.
32959
32960 @subsubheading Example
32961
32962 @smallexample
32963 (gdb)
32964 -var-set-update-range V 1 2
32965 ^done
32966 @end smallexample
32967
32968 @subheading The @code{-var-set-visualizer} command
32969 @findex -var-set-visualizer
32970 @anchor{-var-set-visualizer}
32971
32972 @subsubheading Synopsis
32973
32974 @smallexample
32975 -var-set-visualizer @var{name} @var{visualizer}
32976 @end smallexample
32977
32978 Set a visualizer for the variable object @var{name}.
32979
32980 @var{visualizer} is the visualizer to use. The special value
32981 @samp{None} means to disable any visualizer in use.
32982
32983 If not @samp{None}, @var{visualizer} must be a Python expression.
32984 This expression must evaluate to a callable object which accepts a
32985 single argument. @value{GDBN} will call this object with the value of
32986 the varobj @var{name} as an argument (this is done so that the same
32987 Python pretty-printing code can be used for both the CLI and MI).
32988 When called, this object must return an object which conforms to the
32989 pretty-printing interface (@pxref{Pretty Printing API}).
32990
32991 The pre-defined function @code{gdb.default_visualizer} may be used to
32992 select a visualizer by following the built-in process
32993 (@pxref{Selecting Pretty-Printers}). This is done automatically when
32994 a varobj is created, and so ordinarily is not needed.
32995
32996 This feature is only available if Python support is enabled. The MI
32997 command @code{-list-features} (@pxref{GDB/MI Support Commands})
32998 can be used to check this.
32999
33000 @subsubheading Example
33001
33002 Resetting the visualizer:
33003
33004 @smallexample
33005 (gdb)
33006 -var-set-visualizer V None
33007 ^done
33008 @end smallexample
33009
33010 Reselecting the default (type-based) visualizer:
33011
33012 @smallexample
33013 (gdb)
33014 -var-set-visualizer V gdb.default_visualizer
33015 ^done
33016 @end smallexample
33017
33018 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33019 can be used to instantiate this class for a varobj:
33020
33021 @smallexample
33022 (gdb)
33023 -var-set-visualizer V "lambda val: SomeClass()"
33024 ^done
33025 @end smallexample
33026
33027 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33028 @node GDB/MI Data Manipulation
33029 @section @sc{gdb/mi} Data Manipulation
33030
33031 @cindex data manipulation, in @sc{gdb/mi}
33032 @cindex @sc{gdb/mi}, data manipulation
33033 This section describes the @sc{gdb/mi} commands that manipulate data:
33034 examine memory and registers, evaluate expressions, etc.
33035
33036 For details about what an addressable memory unit is,
33037 @pxref{addressable memory unit}.
33038
33039 @c REMOVED FROM THE INTERFACE.
33040 @c @subheading -data-assign
33041 @c Change the value of a program variable. Plenty of side effects.
33042 @c @subsubheading GDB Command
33043 @c set variable
33044 @c @subsubheading Example
33045 @c N.A.
33046
33047 @subheading The @code{-data-disassemble} Command
33048 @findex -data-disassemble
33049
33050 @subsubheading Synopsis
33051
33052 @smallexample
33053 -data-disassemble
33054 [ -s @var{start-addr} -e @var{end-addr} ]
33055 | [ -a @var{addr} ]
33056 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33057 -- @var{mode}
33058 @end smallexample
33059
33060 @noindent
33061 Where:
33062
33063 @table @samp
33064 @item @var{start-addr}
33065 is the beginning address (or @code{$pc})
33066 @item @var{end-addr}
33067 is the end address
33068 @item @var{addr}
33069 is an address anywhere within (or the name of) the function to
33070 disassemble. If an address is specified, the whole function
33071 surrounding that address will be disassembled. If a name is
33072 specified, the whole function with that name will be disassembled.
33073 @item @var{filename}
33074 is the name of the file to disassemble
33075 @item @var{linenum}
33076 is the line number to disassemble around
33077 @item @var{lines}
33078 is the number of disassembly lines to be produced. If it is -1,
33079 the whole function will be disassembled, in case no @var{end-addr} is
33080 specified. If @var{end-addr} is specified as a non-zero value, and
33081 @var{lines} is lower than the number of disassembly lines between
33082 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
33083 displayed; if @var{lines} is higher than the number of lines between
33084 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33085 are displayed.
33086 @item @var{mode}
33087 is one of:
33088 @itemize @bullet
33089 @item 0 disassembly only
33090 @item 1 mixed source and disassembly (deprecated)
33091 @item 2 disassembly with raw opcodes
33092 @item 3 mixed source and disassembly with raw opcodes (deprecated)
33093 @item 4 mixed source and disassembly
33094 @item 5 mixed source and disassembly with raw opcodes
33095 @end itemize
33096
33097 Modes 1 and 3 are deprecated. The output is ``source centric''
33098 which hasn't proved useful in practice.
33099 @xref{Machine Code}, for a discussion of the difference between
33100 @code{/m} and @code{/s} output of the @code{disassemble} command.
33101 @end table
33102
33103 @subsubheading Result
33104
33105 The result of the @code{-data-disassemble} command will be a list named
33106 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33107 used with the @code{-data-disassemble} command.
33108
33109 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33110 following fields:
33111
33112 @table @code
33113 @item address
33114 The address at which this instruction was disassembled.
33115
33116 @item func-name
33117 The name of the function this instruction is within.
33118
33119 @item offset
33120 The decimal offset in bytes from the start of @samp{func-name}.
33121
33122 @item inst
33123 The text disassembly for this @samp{address}.
33124
33125 @item opcodes
33126 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33127 bytes for the @samp{inst} field.
33128
33129 @end table
33130
33131 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33132 @samp{src_and_asm_line}, each of which has the following fields:
33133
33134 @table @code
33135 @item line
33136 The line number within @samp{file}.
33137
33138 @item file
33139 The file name from the compilation unit. This might be an absolute
33140 file name or a relative file name depending on the compile command
33141 used.
33142
33143 @item fullname
33144 Absolute file name of @samp{file}. It is converted to a canonical form
33145 using the source file search path
33146 (@pxref{Source Path, ,Specifying Source Directories})
33147 and after resolving all the symbolic links.
33148
33149 If the source file is not found this field will contain the path as
33150 present in the debug information.
33151
33152 @item line_asm_insn
33153 This is a list of tuples containing the disassembly for @samp{line} in
33154 @samp{file}. The fields of each tuple are the same as for
33155 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33156 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33157 @samp{opcodes}.
33158
33159 @end table
33160
33161 Note that whatever included in the @samp{inst} field, is not
33162 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33163 adjust its format.
33164
33165 @subsubheading @value{GDBN} Command
33166
33167 The corresponding @value{GDBN} command is @samp{disassemble}.
33168
33169 @subsubheading Example
33170
33171 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33172
33173 @smallexample
33174 (gdb)
33175 -data-disassemble -s $pc -e "$pc + 20" -- 0
33176 ^done,
33177 asm_insns=[
33178 @{address="0x000107c0",func-name="main",offset="4",
33179 inst="mov 2, %o0"@},
33180 @{address="0x000107c4",func-name="main",offset="8",
33181 inst="sethi %hi(0x11800), %o2"@},
33182 @{address="0x000107c8",func-name="main",offset="12",
33183 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33184 @{address="0x000107cc",func-name="main",offset="16",
33185 inst="sethi %hi(0x11800), %o2"@},
33186 @{address="0x000107d0",func-name="main",offset="20",
33187 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33188 (gdb)
33189 @end smallexample
33190
33191 Disassemble the whole @code{main} function. Line 32 is part of
33192 @code{main}.
33193
33194 @smallexample
33195 -data-disassemble -f basics.c -l 32 -- 0
33196 ^done,asm_insns=[
33197 @{address="0x000107bc",func-name="main",offset="0",
33198 inst="save %sp, -112, %sp"@},
33199 @{address="0x000107c0",func-name="main",offset="4",
33200 inst="mov 2, %o0"@},
33201 @{address="0x000107c4",func-name="main",offset="8",
33202 inst="sethi %hi(0x11800), %o2"@},
33203 [@dots{}]
33204 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33205 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33206 (gdb)
33207 @end smallexample
33208
33209 Disassemble 3 instructions from the start of @code{main}:
33210
33211 @smallexample
33212 (gdb)
33213 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33214 ^done,asm_insns=[
33215 @{address="0x000107bc",func-name="main",offset="0",
33216 inst="save %sp, -112, %sp"@},
33217 @{address="0x000107c0",func-name="main",offset="4",
33218 inst="mov 2, %o0"@},
33219 @{address="0x000107c4",func-name="main",offset="8",
33220 inst="sethi %hi(0x11800), %o2"@}]
33221 (gdb)
33222 @end smallexample
33223
33224 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33225
33226 @smallexample
33227 (gdb)
33228 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33229 ^done,asm_insns=[
33230 src_and_asm_line=@{line="31",
33231 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33232 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33233 line_asm_insn=[@{address="0x000107bc",
33234 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33235 src_and_asm_line=@{line="32",
33236 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33237 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33238 line_asm_insn=[@{address="0x000107c0",
33239 func-name="main",offset="4",inst="mov 2, %o0"@},
33240 @{address="0x000107c4",func-name="main",offset="8",
33241 inst="sethi %hi(0x11800), %o2"@}]@}]
33242 (gdb)
33243 @end smallexample
33244
33245
33246 @subheading The @code{-data-evaluate-expression} Command
33247 @findex -data-evaluate-expression
33248
33249 @subsubheading Synopsis
33250
33251 @smallexample
33252 -data-evaluate-expression @var{expr}
33253 @end smallexample
33254
33255 Evaluate @var{expr} as an expression. The expression could contain an
33256 inferior function call. The function call will execute synchronously.
33257 If the expression contains spaces, it must be enclosed in double quotes.
33258
33259 @subsubheading @value{GDBN} Command
33260
33261 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33262 @samp{call}. In @code{gdbtk} only, there's a corresponding
33263 @samp{gdb_eval} command.
33264
33265 @subsubheading Example
33266
33267 In the following example, the numbers that precede the commands are the
33268 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33269 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33270 output.
33271
33272 @smallexample
33273 211-data-evaluate-expression A
33274 211^done,value="1"
33275 (gdb)
33276 311-data-evaluate-expression &A
33277 311^done,value="0xefffeb7c"
33278 (gdb)
33279 411-data-evaluate-expression A+3
33280 411^done,value="4"
33281 (gdb)
33282 511-data-evaluate-expression "A + 3"
33283 511^done,value="4"
33284 (gdb)
33285 @end smallexample
33286
33287
33288 @subheading The @code{-data-list-changed-registers} Command
33289 @findex -data-list-changed-registers
33290
33291 @subsubheading Synopsis
33292
33293 @smallexample
33294 -data-list-changed-registers
33295 @end smallexample
33296
33297 Display a list of the registers that have changed.
33298
33299 @subsubheading @value{GDBN} Command
33300
33301 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33302 has the corresponding command @samp{gdb_changed_register_list}.
33303
33304 @subsubheading Example
33305
33306 On a PPC MBX board:
33307
33308 @smallexample
33309 (gdb)
33310 -exec-continue
33311 ^running
33312
33313 (gdb)
33314 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33315 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33316 line="5",arch="powerpc"@}
33317 (gdb)
33318 -data-list-changed-registers
33319 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33320 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33321 "24","25","26","27","28","30","31","64","65","66","67","69"]
33322 (gdb)
33323 @end smallexample
33324
33325
33326 @subheading The @code{-data-list-register-names} Command
33327 @findex -data-list-register-names
33328
33329 @subsubheading Synopsis
33330
33331 @smallexample
33332 -data-list-register-names [ ( @var{regno} )+ ]
33333 @end smallexample
33334
33335 Show a list of register names for the current target. If no arguments
33336 are given, it shows a list of the names of all the registers. If
33337 integer numbers are given as arguments, it will print a list of the
33338 names of the registers corresponding to the arguments. To ensure
33339 consistency between a register name and its number, the output list may
33340 include empty register names.
33341
33342 @subsubheading @value{GDBN} Command
33343
33344 @value{GDBN} does not have a command which corresponds to
33345 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33346 corresponding command @samp{gdb_regnames}.
33347
33348 @subsubheading Example
33349
33350 For the PPC MBX board:
33351 @smallexample
33352 (gdb)
33353 -data-list-register-names
33354 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33355 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33356 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33357 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33358 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33359 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33360 "", "pc","ps","cr","lr","ctr","xer"]
33361 (gdb)
33362 -data-list-register-names 1 2 3
33363 ^done,register-names=["r1","r2","r3"]
33364 (gdb)
33365 @end smallexample
33366
33367 @subheading The @code{-data-list-register-values} Command
33368 @findex -data-list-register-values
33369
33370 @subsubheading Synopsis
33371
33372 @smallexample
33373 -data-list-register-values
33374 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
33375 @end smallexample
33376
33377 Display the registers' contents. The format according to which the
33378 registers' contents are to be returned is given by @var{fmt}, followed
33379 by an optional list of numbers specifying the registers to display. A
33380 missing list of numbers indicates that the contents of all the
33381 registers must be returned. The @code{--skip-unavailable} option
33382 indicates that only the available registers are to be returned.
33383
33384 Allowed formats for @var{fmt} are:
33385
33386 @table @code
33387 @item x
33388 Hexadecimal
33389 @item o
33390 Octal
33391 @item t
33392 Binary
33393 @item d
33394 Decimal
33395 @item r
33396 Raw
33397 @item N
33398 Natural
33399 @end table
33400
33401 @subsubheading @value{GDBN} Command
33402
33403 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33404 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
33405
33406 @subsubheading Example
33407
33408 For a PPC MBX board (note: line breaks are for readability only, they
33409 don't appear in the actual output):
33410
33411 @smallexample
33412 (gdb)
33413 -data-list-register-values r 64 65
33414 ^done,register-values=[@{number="64",value="0xfe00a300"@},
33415 @{number="65",value="0x00029002"@}]
33416 (gdb)
33417 -data-list-register-values x
33418 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
33419 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33420 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
33421 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33422 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33423 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33424 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
33425 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33426 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33427 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33428 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33429 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33430 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33431 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33432 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33433 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33434 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
33435 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
33436 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
33437 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
33438 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
33439 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
33440 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
33441 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
33442 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
33443 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
33444 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
33445 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
33446 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
33447 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
33448 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
33449 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
33450 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33451 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33452 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33453 @{number="69",value="0x20002b03"@}]
33454 (gdb)
33455 @end smallexample
33456
33457
33458 @subheading The @code{-data-read-memory} Command
33459 @findex -data-read-memory
33460
33461 This command is deprecated, use @code{-data-read-memory-bytes} instead.
33462
33463 @subsubheading Synopsis
33464
33465 @smallexample
33466 -data-read-memory [ -o @var{byte-offset} ]
33467 @var{address} @var{word-format} @var{word-size}
33468 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
33469 @end smallexample
33470
33471 @noindent
33472 where:
33473
33474 @table @samp
33475 @item @var{address}
33476 An expression specifying the address of the first memory word to be
33477 read. Complex expressions containing embedded white space should be
33478 quoted using the C convention.
33479
33480 @item @var{word-format}
33481 The format to be used to print the memory words. The notation is the
33482 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
33483 ,Output Formats}).
33484
33485 @item @var{word-size}
33486 The size of each memory word in bytes.
33487
33488 @item @var{nr-rows}
33489 The number of rows in the output table.
33490
33491 @item @var{nr-cols}
33492 The number of columns in the output table.
33493
33494 @item @var{aschar}
33495 If present, indicates that each row should include an @sc{ascii} dump. The
33496 value of @var{aschar} is used as a padding character when a byte is not a
33497 member of the printable @sc{ascii} character set (printable @sc{ascii}
33498 characters are those whose code is between 32 and 126, inclusively).
33499
33500 @item @var{byte-offset}
33501 An offset to add to the @var{address} before fetching memory.
33502 @end table
33503
33504 This command displays memory contents as a table of @var{nr-rows} by
33505 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
33506 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33507 (returned as @samp{total-bytes}). Should less than the requested number
33508 of bytes be returned by the target, the missing words are identified
33509 using @samp{N/A}. The number of bytes read from the target is returned
33510 in @samp{nr-bytes} and the starting address used to read memory in
33511 @samp{addr}.
33512
33513 The address of the next/previous row or page is available in
33514 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
33515 @samp{prev-page}.
33516
33517 @subsubheading @value{GDBN} Command
33518
33519 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33520 @samp{gdb_get_mem} memory read command.
33521
33522 @subsubheading Example
33523
33524 Read six bytes of memory starting at @code{bytes+6} but then offset by
33525 @code{-6} bytes. Format as three rows of two columns. One byte per
33526 word. Display each word in hex.
33527
33528 @smallexample
33529 (gdb)
33530 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
33531 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33532 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33533 prev-page="0x0000138a",memory=[
33534 @{addr="0x00001390",data=["0x00","0x01"]@},
33535 @{addr="0x00001392",data=["0x02","0x03"]@},
33536 @{addr="0x00001394",data=["0x04","0x05"]@}]
33537 (gdb)
33538 @end smallexample
33539
33540 Read two bytes of memory starting at address @code{shorts + 64} and
33541 display as a single word formatted in decimal.
33542
33543 @smallexample
33544 (gdb)
33545 5-data-read-memory shorts+64 d 2 1 1
33546 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33547 next-row="0x00001512",prev-row="0x0000150e",
33548 next-page="0x00001512",prev-page="0x0000150e",memory=[
33549 @{addr="0x00001510",data=["128"]@}]
33550 (gdb)
33551 @end smallexample
33552
33553 Read thirty two bytes of memory starting at @code{bytes+16} and format
33554 as eight rows of four columns. Include a string encoding with @samp{x}
33555 used as the non-printable character.
33556
33557 @smallexample
33558 (gdb)
33559 4-data-read-memory bytes+16 x 1 8 4 x
33560 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33561 next-row="0x000013c0",prev-row="0x0000139c",
33562 next-page="0x000013c0",prev-page="0x00001380",memory=[
33563 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33564 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33565 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33566 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33567 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33568 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33569 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33570 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33571 (gdb)
33572 @end smallexample
33573
33574 @subheading The @code{-data-read-memory-bytes} Command
33575 @findex -data-read-memory-bytes
33576
33577 @subsubheading Synopsis
33578
33579 @smallexample
33580 -data-read-memory-bytes [ -o @var{offset} ]
33581 @var{address} @var{count}
33582 @end smallexample
33583
33584 @noindent
33585 where:
33586
33587 @table @samp
33588 @item @var{address}
33589 An expression specifying the address of the first addressable memory unit
33590 to be read. Complex expressions containing embedded white space should be
33591 quoted using the C convention.
33592
33593 @item @var{count}
33594 The number of addressable memory units to read. This should be an integer
33595 literal.
33596
33597 @item @var{offset}
33598 The offset relative to @var{address} at which to start reading. This
33599 should be an integer literal. This option is provided so that a frontend
33600 is not required to first evaluate address and then perform address
33601 arithmetics itself.
33602
33603 @end table
33604
33605 This command attempts to read all accessible memory regions in the
33606 specified range. First, all regions marked as unreadable in the memory
33607 map (if one is defined) will be skipped. @xref{Memory Region
33608 Attributes}. Second, @value{GDBN} will attempt to read the remaining
33609 regions. For each one, if reading full region results in an errors,
33610 @value{GDBN} will try to read a subset of the region.
33611
33612 In general, every single memory unit in the region may be readable or not,
33613 and the only way to read every readable unit is to try a read at
33614 every address, which is not practical. Therefore, @value{GDBN} will
33615 attempt to read all accessible memory units at either beginning or the end
33616 of the region, using a binary division scheme. This heuristic works
33617 well for reading across a memory map boundary. Note that if a region
33618 has a readable range that is neither at the beginning or the end,
33619 @value{GDBN} will not read it.
33620
33621 The result record (@pxref{GDB/MI Result Records}) that is output of
33622 the command includes a field named @samp{memory} whose content is a
33623 list of tuples. Each tuple represent a successfully read memory block
33624 and has the following fields:
33625
33626 @table @code
33627 @item begin
33628 The start address of the memory block, as hexadecimal literal.
33629
33630 @item end
33631 The end address of the memory block, as hexadecimal literal.
33632
33633 @item offset
33634 The offset of the memory block, as hexadecimal literal, relative to
33635 the start address passed to @code{-data-read-memory-bytes}.
33636
33637 @item contents
33638 The contents of the memory block, in hex.
33639
33640 @end table
33641
33642
33643
33644 @subsubheading @value{GDBN} Command
33645
33646 The corresponding @value{GDBN} command is @samp{x}.
33647
33648 @subsubheading Example
33649
33650 @smallexample
33651 (gdb)
33652 -data-read-memory-bytes &a 10
33653 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33654 end="0xbffff15e",
33655 contents="01000000020000000300"@}]
33656 (gdb)
33657 @end smallexample
33658
33659
33660 @subheading The @code{-data-write-memory-bytes} Command
33661 @findex -data-write-memory-bytes
33662
33663 @subsubheading Synopsis
33664
33665 @smallexample
33666 -data-write-memory-bytes @var{address} @var{contents}
33667 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
33668 @end smallexample
33669
33670 @noindent
33671 where:
33672
33673 @table @samp
33674 @item @var{address}
33675 An expression specifying the address of the first addressable memory unit
33676 to be written. Complex expressions containing embedded white space should
33677 be quoted using the C convention.
33678
33679 @item @var{contents}
33680 The hex-encoded data to write. It is an error if @var{contents} does
33681 not represent an integral number of addressable memory units.
33682
33683 @item @var{count}
33684 Optional argument indicating the number of addressable memory units to be
33685 written. If @var{count} is greater than @var{contents}' length,
33686 @value{GDBN} will repeatedly write @var{contents} until it fills
33687 @var{count} memory units.
33688
33689 @end table
33690
33691 @subsubheading @value{GDBN} Command
33692
33693 There's no corresponding @value{GDBN} command.
33694
33695 @subsubheading Example
33696
33697 @smallexample
33698 (gdb)
33699 -data-write-memory-bytes &a "aabbccdd"
33700 ^done
33701 (gdb)
33702 @end smallexample
33703
33704 @smallexample
33705 (gdb)
33706 -data-write-memory-bytes &a "aabbccdd" 16e
33707 ^done
33708 (gdb)
33709 @end smallexample
33710
33711 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33712 @node GDB/MI Tracepoint Commands
33713 @section @sc{gdb/mi} Tracepoint Commands
33714
33715 The commands defined in this section implement MI support for
33716 tracepoints. For detailed introduction, see @ref{Tracepoints}.
33717
33718 @subheading The @code{-trace-find} Command
33719 @findex -trace-find
33720
33721 @subsubheading Synopsis
33722
33723 @smallexample
33724 -trace-find @var{mode} [@var{parameters}@dots{}]
33725 @end smallexample
33726
33727 Find a trace frame using criteria defined by @var{mode} and
33728 @var{parameters}. The following table lists permissible
33729 modes and their parameters. For details of operation, see @ref{tfind}.
33730
33731 @table @samp
33732
33733 @item none
33734 No parameters are required. Stops examining trace frames.
33735
33736 @item frame-number
33737 An integer is required as parameter. Selects tracepoint frame with
33738 that index.
33739
33740 @item tracepoint-number
33741 An integer is required as parameter. Finds next
33742 trace frame that corresponds to tracepoint with the specified number.
33743
33744 @item pc
33745 An address is required as parameter. Finds
33746 next trace frame that corresponds to any tracepoint at the specified
33747 address.
33748
33749 @item pc-inside-range
33750 Two addresses are required as parameters. Finds next trace
33751 frame that corresponds to a tracepoint at an address inside the
33752 specified range. Both bounds are considered to be inside the range.
33753
33754 @item pc-outside-range
33755 Two addresses are required as parameters. Finds
33756 next trace frame that corresponds to a tracepoint at an address outside
33757 the specified range. Both bounds are considered to be inside the range.
33758
33759 @item line
33760 Line specification is required as parameter. @xref{Specify Location}.
33761 Finds next trace frame that corresponds to a tracepoint at
33762 the specified location.
33763
33764 @end table
33765
33766 If @samp{none} was passed as @var{mode}, the response does not
33767 have fields. Otherwise, the response may have the following fields:
33768
33769 @table @samp
33770 @item found
33771 This field has either @samp{0} or @samp{1} as the value, depending
33772 on whether a matching tracepoint was found.
33773
33774 @item traceframe
33775 The index of the found traceframe. This field is present iff
33776 the @samp{found} field has value of @samp{1}.
33777
33778 @item tracepoint
33779 The index of the found tracepoint. This field is present iff
33780 the @samp{found} field has value of @samp{1}.
33781
33782 @item frame
33783 The information about the frame corresponding to the found trace
33784 frame. This field is present only if a trace frame was found.
33785 @xref{GDB/MI Frame Information}, for description of this field.
33786
33787 @end table
33788
33789 @subsubheading @value{GDBN} Command
33790
33791 The corresponding @value{GDBN} command is @samp{tfind}.
33792
33793 @subheading -trace-define-variable
33794 @findex -trace-define-variable
33795
33796 @subsubheading Synopsis
33797
33798 @smallexample
33799 -trace-define-variable @var{name} [ @var{value} ]
33800 @end smallexample
33801
33802 Create trace variable @var{name} if it does not exist. If
33803 @var{value} is specified, sets the initial value of the specified
33804 trace variable to that value. Note that the @var{name} should start
33805 with the @samp{$} character.
33806
33807 @subsubheading @value{GDBN} Command
33808
33809 The corresponding @value{GDBN} command is @samp{tvariable}.
33810
33811 @subheading The @code{-trace-frame-collected} Command
33812 @findex -trace-frame-collected
33813
33814 @subsubheading Synopsis
33815
33816 @smallexample
33817 -trace-frame-collected
33818 [--var-print-values @var{var_pval}]
33819 [--comp-print-values @var{comp_pval}]
33820 [--registers-format @var{regformat}]
33821 [--memory-contents]
33822 @end smallexample
33823
33824 This command returns the set of collected objects, register names,
33825 trace state variable names, memory ranges and computed expressions
33826 that have been collected at a particular trace frame. The optional
33827 parameters to the command affect the output format in different ways.
33828 See the output description table below for more details.
33829
33830 The reported names can be used in the normal manner to create
33831 varobjs and inspect the objects themselves. The items returned by
33832 this command are categorized so that it is clear which is a variable,
33833 which is a register, which is a trace state variable, which is a
33834 memory range and which is a computed expression.
33835
33836 For instance, if the actions were
33837 @smallexample
33838 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33839 collect *(int*)0xaf02bef0@@40
33840 @end smallexample
33841
33842 @noindent
33843 the object collected in its entirety would be @code{myVar}. The
33844 object @code{myArray} would be partially collected, because only the
33845 element at index @code{myIndex} would be collected. The remaining
33846 objects would be computed expressions.
33847
33848 An example output would be:
33849
33850 @smallexample
33851 (gdb)
33852 -trace-frame-collected
33853 ^done,
33854 explicit-variables=[@{name="myVar",value="1"@}],
33855 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33856 @{name="myObj.field",value="0"@},
33857 @{name="myPtr->field",value="1"@},
33858 @{name="myCount + 2",value="3"@},
33859 @{name="$tvar1 + 1",value="43970027"@}],
33860 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33861 @{number="1",value="0x0"@},
33862 @{number="2",value="0x4"@},
33863 ...
33864 @{number="125",value="0x0"@}],
33865 tvars=[@{name="$tvar1",current="43970026"@}],
33866 memory=[@{address="0x0000000000602264",length="4"@},
33867 @{address="0x0000000000615bc0",length="4"@}]
33868 (gdb)
33869 @end smallexample
33870
33871 Where:
33872
33873 @table @code
33874 @item explicit-variables
33875 The set of objects that have been collected in their entirety (as
33876 opposed to collecting just a few elements of an array or a few struct
33877 members). For each object, its name and value are printed.
33878 The @code{--var-print-values} option affects how or whether the value
33879 field is output. If @var{var_pval} is 0, then print only the names;
33880 if it is 1, print also their values; and if it is 2, print the name,
33881 type and value for simple data types, and the name and type for
33882 arrays, structures and unions.
33883
33884 @item computed-expressions
33885 The set of computed expressions that have been collected at the
33886 current trace frame. The @code{--comp-print-values} option affects
33887 this set like the @code{--var-print-values} option affects the
33888 @code{explicit-variables} set. See above.
33889
33890 @item registers
33891 The registers that have been collected at the current trace frame.
33892 For each register collected, the name and current value are returned.
33893 The value is formatted according to the @code{--registers-format}
33894 option. See the @command{-data-list-register-values} command for a
33895 list of the allowed formats. The default is @samp{x}.
33896
33897 @item tvars
33898 The trace state variables that have been collected at the current
33899 trace frame. For each trace state variable collected, the name and
33900 current value are returned.
33901
33902 @item memory
33903 The set of memory ranges that have been collected at the current trace
33904 frame. Its content is a list of tuples. Each tuple represents a
33905 collected memory range and has the following fields:
33906
33907 @table @code
33908 @item address
33909 The start address of the memory range, as hexadecimal literal.
33910
33911 @item length
33912 The length of the memory range, as decimal literal.
33913
33914 @item contents
33915 The contents of the memory block, in hex. This field is only present
33916 if the @code{--memory-contents} option is specified.
33917
33918 @end table
33919
33920 @end table
33921
33922 @subsubheading @value{GDBN} Command
33923
33924 There is no corresponding @value{GDBN} command.
33925
33926 @subsubheading Example
33927
33928 @subheading -trace-list-variables
33929 @findex -trace-list-variables
33930
33931 @subsubheading Synopsis
33932
33933 @smallexample
33934 -trace-list-variables
33935 @end smallexample
33936
33937 Return a table of all defined trace variables. Each element of the
33938 table has the following fields:
33939
33940 @table @samp
33941 @item name
33942 The name of the trace variable. This field is always present.
33943
33944 @item initial
33945 The initial value. This is a 64-bit signed integer. This
33946 field is always present.
33947
33948 @item current
33949 The value the trace variable has at the moment. This is a 64-bit
33950 signed integer. This field is absent iff current value is
33951 not defined, for example if the trace was never run, or is
33952 presently running.
33953
33954 @end table
33955
33956 @subsubheading @value{GDBN} Command
33957
33958 The corresponding @value{GDBN} command is @samp{tvariables}.
33959
33960 @subsubheading Example
33961
33962 @smallexample
33963 (gdb)
33964 -trace-list-variables
33965 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
33966 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
33967 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
33968 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
33969 body=[variable=@{name="$trace_timestamp",initial="0"@}
33970 variable=@{name="$foo",initial="10",current="15"@}]@}
33971 (gdb)
33972 @end smallexample
33973
33974 @subheading -trace-save
33975 @findex -trace-save
33976
33977 @subsubheading Synopsis
33978
33979 @smallexample
33980 -trace-save [ -r ] [ -ctf ] @var{filename}
33981 @end smallexample
33982
33983 Saves the collected trace data to @var{filename}. Without the
33984 @samp{-r} option, the data is downloaded from the target and saved
33985 in a local file. With the @samp{-r} option the target is asked
33986 to perform the save.
33987
33988 By default, this command will save the trace in the tfile format. You can
33989 supply the optional @samp{-ctf} argument to save it the CTF format. See
33990 @ref{Trace Files} for more information about CTF.
33991
33992 @subsubheading @value{GDBN} Command
33993
33994 The corresponding @value{GDBN} command is @samp{tsave}.
33995
33996
33997 @subheading -trace-start
33998 @findex -trace-start
33999
34000 @subsubheading Synopsis
34001
34002 @smallexample
34003 -trace-start
34004 @end smallexample
34005
34006 Starts a tracing experiment. The result of this command does not
34007 have any fields.
34008
34009 @subsubheading @value{GDBN} Command
34010
34011 The corresponding @value{GDBN} command is @samp{tstart}.
34012
34013 @subheading -trace-status
34014 @findex -trace-status
34015
34016 @subsubheading Synopsis
34017
34018 @smallexample
34019 -trace-status
34020 @end smallexample
34021
34022 Obtains the status of a tracing experiment. The result may include
34023 the following fields:
34024
34025 @table @samp
34026
34027 @item supported
34028 May have a value of either @samp{0}, when no tracing operations are
34029 supported, @samp{1}, when all tracing operations are supported, or
34030 @samp{file} when examining trace file. In the latter case, examining
34031 of trace frame is possible but new tracing experiement cannot be
34032 started. This field is always present.
34033
34034 @item running
34035 May have a value of either @samp{0} or @samp{1} depending on whether
34036 tracing experiement is in progress on target. This field is present
34037 if @samp{supported} field is not @samp{0}.
34038
34039 @item stop-reason
34040 Report the reason why the tracing was stopped last time. This field
34041 may be absent iff tracing was never stopped on target yet. The
34042 value of @samp{request} means the tracing was stopped as result of
34043 the @code{-trace-stop} command. The value of @samp{overflow} means
34044 the tracing buffer is full. The value of @samp{disconnection} means
34045 tracing was automatically stopped when @value{GDBN} has disconnected.
34046 The value of @samp{passcount} means tracing was stopped when a
34047 tracepoint was passed a maximal number of times for that tracepoint.
34048 This field is present if @samp{supported} field is not @samp{0}.
34049
34050 @item stopping-tracepoint
34051 The number of tracepoint whose passcount as exceeded. This field is
34052 present iff the @samp{stop-reason} field has the value of
34053 @samp{passcount}.
34054
34055 @item frames
34056 @itemx frames-created
34057 The @samp{frames} field is a count of the total number of trace frames
34058 in the trace buffer, while @samp{frames-created} is the total created
34059 during the run, including ones that were discarded, such as when a
34060 circular trace buffer filled up. Both fields are optional.
34061
34062 @item buffer-size
34063 @itemx buffer-free
34064 These fields tell the current size of the tracing buffer and the
34065 remaining space. These fields are optional.
34066
34067 @item circular
34068 The value of the circular trace buffer flag. @code{1} means that the
34069 trace buffer is circular and old trace frames will be discarded if
34070 necessary to make room, @code{0} means that the trace buffer is linear
34071 and may fill up.
34072
34073 @item disconnected
34074 The value of the disconnected tracing flag. @code{1} means that
34075 tracing will continue after @value{GDBN} disconnects, @code{0} means
34076 that the trace run will stop.
34077
34078 @item trace-file
34079 The filename of the trace file being examined. This field is
34080 optional, and only present when examining a trace file.
34081
34082 @end table
34083
34084 @subsubheading @value{GDBN} Command
34085
34086 The corresponding @value{GDBN} command is @samp{tstatus}.
34087
34088 @subheading -trace-stop
34089 @findex -trace-stop
34090
34091 @subsubheading Synopsis
34092
34093 @smallexample
34094 -trace-stop
34095 @end smallexample
34096
34097 Stops a tracing experiment. The result of this command has the same
34098 fields as @code{-trace-status}, except that the @samp{supported} and
34099 @samp{running} fields are not output.
34100
34101 @subsubheading @value{GDBN} Command
34102
34103 The corresponding @value{GDBN} command is @samp{tstop}.
34104
34105
34106 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34107 @node GDB/MI Symbol Query
34108 @section @sc{gdb/mi} Symbol Query Commands
34109
34110
34111 @ignore
34112 @subheading The @code{-symbol-info-address} Command
34113 @findex -symbol-info-address
34114
34115 @subsubheading Synopsis
34116
34117 @smallexample
34118 -symbol-info-address @var{symbol}
34119 @end smallexample
34120
34121 Describe where @var{symbol} is stored.
34122
34123 @subsubheading @value{GDBN} Command
34124
34125 The corresponding @value{GDBN} command is @samp{info address}.
34126
34127 @subsubheading Example
34128 N.A.
34129
34130
34131 @subheading The @code{-symbol-info-file} Command
34132 @findex -symbol-info-file
34133
34134 @subsubheading Synopsis
34135
34136 @smallexample
34137 -symbol-info-file
34138 @end smallexample
34139
34140 Show the file for the symbol.
34141
34142 @subsubheading @value{GDBN} Command
34143
34144 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34145 @samp{gdb_find_file}.
34146
34147 @subsubheading Example
34148 N.A.
34149 @end ignore
34150
34151 @subheading The @code{-symbol-info-functions} Command
34152 @findex -symbol-info-functions
34153 @anchor{-symbol-info-functions}
34154
34155 @subsubheading Synopsis
34156
34157 @smallexample
34158 -symbol-info-functions [--include-nondebug]
34159 [--type @var{type_regexp}]
34160 [--name @var{name_regexp}]
34161 [--max-results @var{limit}]
34162 @end smallexample
34163
34164 @noindent
34165 Return a list containing the names and types for all global functions
34166 taken from the debug information. The functions are grouped by source
34167 file, and shown with the line number on which each function is
34168 defined.
34169
34170 The @code{--include-nondebug} option causes the output to include
34171 code symbols from the symbol table.
34172
34173 The options @code{--type} and @code{--name} allow the symbols returned
34174 to be filtered based on either the name of the function, or the type
34175 signature of the function.
34176
34177 The option @code{--max-results} restricts the command to return no
34178 more than @var{limit} results. If exactly @var{limit} results are
34179 returned then there might be additional results available if a higher
34180 limit is used.
34181
34182 @subsubheading @value{GDBN} Command
34183
34184 The corresponding @value{GDBN} command is @samp{info functions}.
34185
34186 @subsubheading Example
34187 @smallexample
34188 @group
34189 (gdb)
34190 -symbol-info-functions
34191 ^done,symbols=
34192 @{debug=
34193 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34194 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34195 symbols=[@{line="36", name="f4", type="void (int *)",
34196 description="void f4(int *);"@},
34197 @{line="42", name="main", type="int ()",
34198 description="int main();"@},
34199 @{line="30", name="f1", type="my_int_t (int, int)",
34200 description="static my_int_t f1(int, int);"@}]@},
34201 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34202 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34203 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34204 description="float f2(another_float_t);"@},
34205 @{line="39", name="f3", type="int (another_int_t)",
34206 description="int f3(another_int_t);"@},
34207 @{line="27", name="f1", type="another_float_t (int)",
34208 description="static another_float_t f1(int);"@}]@}]@}
34209 @end group
34210 @group
34211 (gdb)
34212 -symbol-info-functions --name f1
34213 ^done,symbols=
34214 @{debug=
34215 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34216 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34217 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34218 description="static my_int_t f1(int, int);"@}]@},
34219 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34220 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34221 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34222 description="static another_float_t f1(int);"@}]@}]@}
34223 @end group
34224 @group
34225 (gdb)
34226 -symbol-info-functions --type void
34227 ^done,symbols=
34228 @{debug=
34229 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34230 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34231 symbols=[@{line="36", name="f4", type="void (int *)",
34232 description="void f4(int *);"@}]@}]@}
34233 @end group
34234 @group
34235 (gdb)
34236 -symbol-info-functions --include-nondebug
34237 ^done,symbols=
34238 @{debug=
34239 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34240 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34241 symbols=[@{line="36", name="f4", type="void (int *)",
34242 description="void f4(int *);"@},
34243 @{line="42", name="main", type="int ()",
34244 description="int main();"@},
34245 @{line="30", name="f1", type="my_int_t (int, int)",
34246 description="static my_int_t f1(int, int);"@}]@},
34247 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34248 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34249 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34250 description="float f2(another_float_t);"@},
34251 @{line="39", name="f3", type="int (another_int_t)",
34252 description="int f3(another_int_t);"@},
34253 @{line="27", name="f1", type="another_float_t (int)",
34254 description="static another_float_t f1(int);"@}]@}],
34255 nondebug=
34256 [@{address="0x0000000000400398",name="_init"@},
34257 @{address="0x00000000004003b0",name="_start"@},
34258 ...
34259 ]@}
34260 @end group
34261 @end smallexample
34262
34263 @subheading The @code{-symbol-info-module-functions} Command
34264 @findex -symbol-info-module-functions
34265 @anchor{-symbol-info-module-functions}
34266
34267 @subsubheading Synopsis
34268
34269 @smallexample
34270 -symbol-info-module-functions [--module @var{module_regexp}]
34271 [--name @var{name_regexp}]
34272 [--type @var{type_regexp}]
34273 @end smallexample
34274
34275 @noindent
34276 Return a list containing the names of all known functions within all
34277 know Fortran modules. The functions are grouped by source file and
34278 containing module, and shown with the line number on which each
34279 function is defined.
34280
34281 The option @code{--module} only returns results for modules matching
34282 @var{module_regexp}. The option @code{--name} only returns functions
34283 whose name matches @var{name_regexp}, and @code{--type} only returns
34284 functions whose type matches @var{type_regexp}.
34285
34286 @subsubheading @value{GDBN} Command
34287
34288 The corresponding @value{GDBN} command is @samp{info module functions}.
34289
34290 @subsubheading Example
34291
34292 @smallexample
34293 @group
34294 (gdb)
34295 -symbol-info-module-functions
34296 ^done,symbols=
34297 [@{module="mod1",
34298 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34299 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34300 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34301 description="void mod1::check_all(void);"@}]@}]@},
34302 @{module="mod2",
34303 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34304 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34305 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34306 description="void mod2::check_var_i(void);"@}]@}]@},
34307 @{module="mod3",
34308 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34309 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34310 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34311 description="void mod3::check_all(void);"@},
34312 @{line="27",name="mod3::check_mod2",type="void (void)",
34313 description="void mod3::check_mod2(void);"@}]@}]@},
34314 @{module="modmany",
34315 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34316 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34317 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34318 description="void modmany::check_some(void);"@}]@}]@},
34319 @{module="moduse",
34320 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34321 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34322 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34323 description="void moduse::check_all(void);"@},
34324 @{line="49",name="moduse::check_var_x",type="void (void)",
34325 description="void moduse::check_var_x(void);"@}]@}]@}]
34326 @end group
34327 @end smallexample
34328
34329 @subheading The @code{-symbol-info-module-variables} Command
34330 @findex -symbol-info-module-variables
34331 @anchor{-symbol-info-module-variables}
34332
34333 @subsubheading Synopsis
34334
34335 @smallexample
34336 -symbol-info-module-variables [--module @var{module_regexp}]
34337 [--name @var{name_regexp}]
34338 [--type @var{type_regexp}]
34339 @end smallexample
34340
34341 @noindent
34342 Return a list containing the names of all known variables within all
34343 know Fortran modules. The variables are grouped by source file and
34344 containing module, and shown with the line number on which each
34345 variable is defined.
34346
34347 The option @code{--module} only returns results for modules matching
34348 @var{module_regexp}. The option @code{--name} only returns variables
34349 whose name matches @var{name_regexp}, and @code{--type} only returns
34350 variables whose type matches @var{type_regexp}.
34351
34352 @subsubheading @value{GDBN} Command
34353
34354 The corresponding @value{GDBN} command is @samp{info module variables}.
34355
34356 @subsubheading Example
34357
34358 @smallexample
34359 @group
34360 (gdb)
34361 -symbol-info-module-variables
34362 ^done,symbols=
34363 [@{module="mod1",
34364 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34365 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34366 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34367 description="integer(kind=4) mod1::var_const;"@},
34368 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34369 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34370 @{module="mod2",
34371 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34372 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34373 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34374 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34375 @{module="mod3",
34376 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34377 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34378 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34379 description="integer(kind=4) mod3::mod1;"@},
34380 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34381 description="integer(kind=4) mod3::mod2;"@},
34382 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34383 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34384 @{module="modmany",
34385 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34386 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34387 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34388 description="integer(kind=4) modmany::var_a;"@},
34389 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34390 description="integer(kind=4) modmany::var_b;"@},
34391 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34392 description="integer(kind=4) modmany::var_c;"@},
34393 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34394 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34395 @{module="moduse",
34396 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34397 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34398 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34399 description="integer(kind=4) moduse::var_x;"@},
34400 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34401 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34402 @end group
34403 @end smallexample
34404
34405 @subheading The @code{-symbol-info-modules} Command
34406 @findex -symbol-info-modules
34407 @anchor{-symbol-info-modules}
34408
34409 @subsubheading Synopsis
34410
34411 @smallexample
34412 -symbol-info-modules [--name @var{name_regexp}]
34413 [--max-results @var{limit}]
34414
34415 @end smallexample
34416
34417 @noindent
34418 Return a list containing the names of all known Fortran modules. The
34419 modules are grouped by source file, and shown with the line number on
34420 which each modules is defined.
34421
34422 The option @code{--name} allows the modules returned to be filtered
34423 based the name of the module.
34424
34425 The option @code{--max-results} restricts the command to return no
34426 more than @var{limit} results. If exactly @var{limit} results are
34427 returned then there might be additional results available if a higher
34428 limit is used.
34429
34430 @subsubheading @value{GDBN} Command
34431
34432 The corresponding @value{GDBN} command is @samp{info modules}.
34433
34434 @subsubheading Example
34435 @smallexample
34436 @group
34437 (gdb)
34438 -symbol-info-modules
34439 ^done,symbols=
34440 @{debug=
34441 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34442 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34443 symbols=[@{line="16",name="mod1"@},
34444 @{line="22",name="mod2"@}]@},
34445 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34446 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34447 symbols=[@{line="16",name="mod3"@},
34448 @{line="22",name="modmany"@},
34449 @{line="26",name="moduse"@}]@}]@}
34450 @end group
34451 @group
34452 (gdb)
34453 -symbol-info-modules --name mod[123]
34454 ^done,symbols=
34455 @{debug=
34456 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34457 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34458 symbols=[@{line="16",name="mod1"@},
34459 @{line="22",name="mod2"@}]@},
34460 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34461 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34462 symbols=[@{line="16",name="mod3"@}]@}]@}
34463 @end group
34464 @end smallexample
34465
34466 @subheading The @code{-symbol-info-types} Command
34467 @findex -symbol-info-types
34468 @anchor{-symbol-info-types}
34469
34470 @subsubheading Synopsis
34471
34472 @smallexample
34473 -symbol-info-types [--name @var{name_regexp}]
34474 [--max-results @var{limit}]
34475
34476 @end smallexample
34477
34478 @noindent
34479 Return a list of all defined types. The types are grouped by source
34480 file, and shown with the line number on which each user defined type
34481 is defined. Some base types are not defined in the source code but
34482 are added to the debug information by the compiler, for example
34483 @code{int}, @code{float}, etc.; these types do not have an associated
34484 line number.
34485
34486 The option @code{--name} allows the list of types returned to be
34487 filtered by name.
34488
34489 The option @code{--max-results} restricts the command to return no
34490 more than @var{limit} results. If exactly @var{limit} results are
34491 returned then there might be additional results available if a higher
34492 limit is used.
34493
34494 @subsubheading @value{GDBN} Command
34495
34496 The corresponding @value{GDBN} command is @samp{info types}.
34497
34498 @subsubheading Example
34499 @smallexample
34500 @group
34501 (gdb)
34502 -symbol-info-types
34503 ^done,symbols=
34504 @{debug=
34505 [@{filename="gdb.mi/mi-sym-info-1.c",
34506 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34507 symbols=[@{name="float"@},
34508 @{name="int"@},
34509 @{line="27",name="typedef int my_int_t;"@}]@},
34510 @{filename="gdb.mi/mi-sym-info-2.c",
34511 fullname="/project/gdb.mi/mi-sym-info-2.c",
34512 symbols=[@{line="24",name="typedef float another_float_t;"@},
34513 @{line="23",name="typedef int another_int_t;"@},
34514 @{name="float"@},
34515 @{name="int"@}]@}]@}
34516 @end group
34517 @group
34518 (gdb)
34519 -symbol-info-types --name _int_
34520 ^done,symbols=
34521 @{debug=
34522 [@{filename="gdb.mi/mi-sym-info-1.c",
34523 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34524 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34525 @{filename="gdb.mi/mi-sym-info-2.c",
34526 fullname="/project/gdb.mi/mi-sym-info-2.c",
34527 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34528 @end group
34529 @end smallexample
34530
34531 @subheading The @code{-symbol-info-variables} Command
34532 @findex -symbol-info-variables
34533 @anchor{-symbol-info-variables}
34534
34535 @subsubheading Synopsis
34536
34537 @smallexample
34538 -symbol-info-variables [--include-nondebug]
34539 [--type @var{type_regexp}]
34540 [--name @var{name_regexp}]
34541 [--max-results @var{limit}]
34542
34543 @end smallexample
34544
34545 @noindent
34546 Return a list containing the names and types for all global variables
34547 taken from the debug information. The variables are grouped by source
34548 file, and shown with the line number on which each variable is
34549 defined.
34550
34551 The @code{--include-nondebug} option causes the output to include
34552 data symbols from the symbol table.
34553
34554 The options @code{--type} and @code{--name} allow the symbols returned
34555 to be filtered based on either the name of the variable, or the type
34556 of the variable.
34557
34558 The option @code{--max-results} restricts the command to return no
34559 more than @var{limit} results. If exactly @var{limit} results are
34560 returned then there might be additional results available if a higher
34561 limit is used.
34562
34563 @subsubheading @value{GDBN} Command
34564
34565 The corresponding @value{GDBN} command is @samp{info variables}.
34566
34567 @subsubheading Example
34568 @smallexample
34569 @group
34570 (gdb)
34571 -symbol-info-variables
34572 ^done,symbols=
34573 @{debug=
34574 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34575 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34576 symbols=[@{line="25",name="global_f1",type="float",
34577 description="static float global_f1;"@},
34578 @{line="24",name="global_i1",type="int",
34579 description="static int global_i1;"@}]@},
34580 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34581 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34582 symbols=[@{line="21",name="global_f2",type="int",
34583 description="int global_f2;"@},
34584 @{line="20",name="global_i2",type="int",
34585 description="int global_i2;"@},
34586 @{line="19",name="global_f1",type="float",
34587 description="static float global_f1;"@},
34588 @{line="18",name="global_i1",type="int",
34589 description="static int global_i1;"@}]@}]@}
34590 @end group
34591 @group
34592 (gdb)
34593 -symbol-info-variables --name f1
34594 ^done,symbols=
34595 @{debug=
34596 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34597 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34598 symbols=[@{line="25",name="global_f1",type="float",
34599 description="static float global_f1;"@}]@},
34600 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34601 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34602 symbols=[@{line="19",name="global_f1",type="float",
34603 description="static float global_f1;"@}]@}]@}
34604 @end group
34605 @group
34606 (gdb)
34607 -symbol-info-variables --type float
34608 ^done,symbols=
34609 @{debug=
34610 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34611 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34612 symbols=[@{line="25",name="global_f1",type="float",
34613 description="static float global_f1;"@}]@},
34614 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34615 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34616 symbols=[@{line="19",name="global_f1",type="float",
34617 description="static float global_f1;"@}]@}]@}
34618 @end group
34619 @group
34620 (gdb)
34621 -symbol-info-variables --include-nondebug
34622 ^done,symbols=
34623 @{debug=
34624 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34625 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34626 symbols=[@{line="25",name="global_f1",type="float",
34627 description="static float global_f1;"@},
34628 @{line="24",name="global_i1",type="int",
34629 description="static int global_i1;"@}]@},
34630 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34631 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34632 symbols=[@{line="21",name="global_f2",type="int",
34633 description="int global_f2;"@},
34634 @{line="20",name="global_i2",type="int",
34635 description="int global_i2;"@},
34636 @{line="19",name="global_f1",type="float",
34637 description="static float global_f1;"@},
34638 @{line="18",name="global_i1",type="int",
34639 description="static int global_i1;"@}]@}],
34640 nondebug=
34641 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34642 @{address="0x00000000004005d8",name="__dso_handle"@}
34643 ...
34644 ]@}
34645 @end group
34646 @end smallexample
34647
34648 @ignore
34649 @subheading The @code{-symbol-info-line} Command
34650 @findex -symbol-info-line
34651
34652 @subsubheading Synopsis
34653
34654 @smallexample
34655 -symbol-info-line
34656 @end smallexample
34657
34658 Show the core addresses of the code for a source line.
34659
34660 @subsubheading @value{GDBN} Command
34661
34662 The corresponding @value{GDBN} command is @samp{info line}.
34663 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
34664
34665 @subsubheading Example
34666 N.A.
34667
34668
34669 @subheading The @code{-symbol-info-symbol} Command
34670 @findex -symbol-info-symbol
34671
34672 @subsubheading Synopsis
34673
34674 @smallexample
34675 -symbol-info-symbol @var{addr}
34676 @end smallexample
34677
34678 Describe what symbol is at location @var{addr}.
34679
34680 @subsubheading @value{GDBN} Command
34681
34682 The corresponding @value{GDBN} command is @samp{info symbol}.
34683
34684 @subsubheading Example
34685 N.A.
34686
34687
34688 @subheading The @code{-symbol-list-functions} Command
34689 @findex -symbol-list-functions
34690
34691 @subsubheading Synopsis
34692
34693 @smallexample
34694 -symbol-list-functions
34695 @end smallexample
34696
34697 List the functions in the executable.
34698
34699 @subsubheading @value{GDBN} Command
34700
34701 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34702 @samp{gdb_search} in @code{gdbtk}.
34703
34704 @subsubheading Example
34705 N.A.
34706 @end ignore
34707
34708
34709 @subheading The @code{-symbol-list-lines} Command
34710 @findex -symbol-list-lines
34711
34712 @subsubheading Synopsis
34713
34714 @smallexample
34715 -symbol-list-lines @var{filename}
34716 @end smallexample
34717
34718 Print the list of lines that contain code and their associated program
34719 addresses for the given source filename. The entries are sorted in
34720 ascending PC order.
34721
34722 @subsubheading @value{GDBN} Command
34723
34724 There is no corresponding @value{GDBN} command.
34725
34726 @subsubheading Example
34727 @smallexample
34728 (gdb)
34729 -symbol-list-lines basics.c
34730 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
34731 (gdb)
34732 @end smallexample
34733
34734
34735 @ignore
34736 @subheading The @code{-symbol-list-types} Command
34737 @findex -symbol-list-types
34738
34739 @subsubheading Synopsis
34740
34741 @smallexample
34742 -symbol-list-types
34743 @end smallexample
34744
34745 List all the type names.
34746
34747 @subsubheading @value{GDBN} Command
34748
34749 The corresponding commands are @samp{info types} in @value{GDBN},
34750 @samp{gdb_search} in @code{gdbtk}.
34751
34752 @subsubheading Example
34753 N.A.
34754
34755
34756 @subheading The @code{-symbol-list-variables} Command
34757 @findex -symbol-list-variables
34758
34759 @subsubheading Synopsis
34760
34761 @smallexample
34762 -symbol-list-variables
34763 @end smallexample
34764
34765 List all the global and static variable names.
34766
34767 @subsubheading @value{GDBN} Command
34768
34769 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
34770
34771 @subsubheading Example
34772 N.A.
34773
34774
34775 @subheading The @code{-symbol-locate} Command
34776 @findex -symbol-locate
34777
34778 @subsubheading Synopsis
34779
34780 @smallexample
34781 -symbol-locate
34782 @end smallexample
34783
34784 @subsubheading @value{GDBN} Command
34785
34786 @samp{gdb_loc} in @code{gdbtk}.
34787
34788 @subsubheading Example
34789 N.A.
34790
34791
34792 @subheading The @code{-symbol-type} Command
34793 @findex -symbol-type
34794
34795 @subsubheading Synopsis
34796
34797 @smallexample
34798 -symbol-type @var{variable}
34799 @end smallexample
34800
34801 Show type of @var{variable}.
34802
34803 @subsubheading @value{GDBN} Command
34804
34805 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34806 @samp{gdb_obj_variable}.
34807
34808 @subsubheading Example
34809 N.A.
34810 @end ignore
34811
34812
34813 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34814 @node GDB/MI File Commands
34815 @section @sc{gdb/mi} File Commands
34816
34817 This section describes the GDB/MI commands to specify executable file names
34818 and to read in and obtain symbol table information.
34819
34820 @subheading The @code{-file-exec-and-symbols} Command
34821 @findex -file-exec-and-symbols
34822
34823 @subsubheading Synopsis
34824
34825 @smallexample
34826 -file-exec-and-symbols @var{file}
34827 @end smallexample
34828
34829 Specify the executable file to be debugged. This file is the one from
34830 which the symbol table is also read. If no file is specified, the
34831 command clears the executable and symbol information. If breakpoints
34832 are set when using this command with no arguments, @value{GDBN} will produce
34833 error messages. Otherwise, no output is produced, except a completion
34834 notification.
34835
34836 @subsubheading @value{GDBN} Command
34837
34838 The corresponding @value{GDBN} command is @samp{file}.
34839
34840 @subsubheading Example
34841
34842 @smallexample
34843 (gdb)
34844 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34845 ^done
34846 (gdb)
34847 @end smallexample
34848
34849
34850 @subheading The @code{-file-exec-file} Command
34851 @findex -file-exec-file
34852
34853 @subsubheading Synopsis
34854
34855 @smallexample
34856 -file-exec-file @var{file}
34857 @end smallexample
34858
34859 Specify the executable file to be debugged. Unlike
34860 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34861 from this file. If used without argument, @value{GDBN} clears the information
34862 about the executable file. No output is produced, except a completion
34863 notification.
34864
34865 @subsubheading @value{GDBN} Command
34866
34867 The corresponding @value{GDBN} command is @samp{exec-file}.
34868
34869 @subsubheading Example
34870
34871 @smallexample
34872 (gdb)
34873 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34874 ^done
34875 (gdb)
34876 @end smallexample
34877
34878
34879 @ignore
34880 @subheading The @code{-file-list-exec-sections} Command
34881 @findex -file-list-exec-sections
34882
34883 @subsubheading Synopsis
34884
34885 @smallexample
34886 -file-list-exec-sections
34887 @end smallexample
34888
34889 List the sections of the current executable file.
34890
34891 @subsubheading @value{GDBN} Command
34892
34893 The @value{GDBN} command @samp{info file} shows, among the rest, the same
34894 information as this command. @code{gdbtk} has a corresponding command
34895 @samp{gdb_load_info}.
34896
34897 @subsubheading Example
34898 N.A.
34899 @end ignore
34900
34901
34902 @subheading The @code{-file-list-exec-source-file} Command
34903 @findex -file-list-exec-source-file
34904
34905 @subsubheading Synopsis
34906
34907 @smallexample
34908 -file-list-exec-source-file
34909 @end smallexample
34910
34911 List the line number, the current source file, and the absolute path
34912 to the current source file for the current executable. The macro
34913 information field has a value of @samp{1} or @samp{0} depending on
34914 whether or not the file includes preprocessor macro information.
34915
34916 @subsubheading @value{GDBN} Command
34917
34918 The @value{GDBN} equivalent is @samp{info source}
34919
34920 @subsubheading Example
34921
34922 @smallexample
34923 (gdb)
34924 123-file-list-exec-source-file
34925 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
34926 (gdb)
34927 @end smallexample
34928
34929
34930 @subheading The @code{-file-list-exec-source-files} Command
34931 @findex -file-list-exec-source-files
34932
34933 @subsubheading Synopsis
34934
34935 @smallexample
34936 -file-list-exec-source-files
34937 @end smallexample
34938
34939 List the source files for the current executable.
34940
34941 It will always output both the filename and fullname (absolute file
34942 name) of a source file.
34943
34944 @subsubheading @value{GDBN} Command
34945
34946 The @value{GDBN} equivalent is @samp{info sources}.
34947 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
34948
34949 @subsubheading Example
34950 @smallexample
34951 (gdb)
34952 -file-list-exec-source-files
34953 ^done,files=[
34954 @{file=foo.c,fullname=/home/foo.c@},
34955 @{file=/home/bar.c,fullname=/home/bar.c@},
34956 @{file=gdb_could_not_find_fullpath.c@}]
34957 (gdb)
34958 @end smallexample
34959
34960 @subheading The @code{-file-list-shared-libraries} Command
34961 @findex -file-list-shared-libraries
34962
34963 @subsubheading Synopsis
34964
34965 @smallexample
34966 -file-list-shared-libraries [ @var{regexp} ]
34967 @end smallexample
34968
34969 List the shared libraries in the program.
34970 With a regular expression @var{regexp}, only those libraries whose
34971 names match @var{regexp} are listed.
34972
34973 @subsubheading @value{GDBN} Command
34974
34975 The corresponding @value{GDBN} command is @samp{info shared}. The fields
34976 have a similar meaning to the @code{=library-loaded} notification.
34977 The @code{ranges} field specifies the multiple segments belonging to this
34978 library. Each range has the following fields:
34979
34980 @table @samp
34981 @item from
34982 The address defining the inclusive lower bound of the segment.
34983 @item to
34984 The address defining the exclusive upper bound of the segment.
34985 @end table
34986
34987 @subsubheading Example
34988 @smallexample
34989 (gdb)
34990 -file-list-exec-source-files
34991 ^done,shared-libraries=[
34992 @{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"@}]@},
34993 @{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"@}]@}]
34994 (gdb)
34995 @end smallexample
34996
34997
34998 @ignore
34999 @subheading The @code{-file-list-symbol-files} Command
35000 @findex -file-list-symbol-files
35001
35002 @subsubheading Synopsis
35003
35004 @smallexample
35005 -file-list-symbol-files
35006 @end smallexample
35007
35008 List symbol files.
35009
35010 @subsubheading @value{GDBN} Command
35011
35012 The corresponding @value{GDBN} command is @samp{info file} (part of it).
35013
35014 @subsubheading Example
35015 N.A.
35016 @end ignore
35017
35018
35019 @subheading The @code{-file-symbol-file} Command
35020 @findex -file-symbol-file
35021
35022 @subsubheading Synopsis
35023
35024 @smallexample
35025 -file-symbol-file @var{file}
35026 @end smallexample
35027
35028 Read symbol table info from the specified @var{file} argument. When
35029 used without arguments, clears @value{GDBN}'s symbol table info. No output is
35030 produced, except for a completion notification.
35031
35032 @subsubheading @value{GDBN} Command
35033
35034 The corresponding @value{GDBN} command is @samp{symbol-file}.
35035
35036 @subsubheading Example
35037
35038 @smallexample
35039 (gdb)
35040 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35041 ^done
35042 (gdb)
35043 @end smallexample
35044
35045 @ignore
35046 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35047 @node GDB/MI Memory Overlay Commands
35048 @section @sc{gdb/mi} Memory Overlay Commands
35049
35050 The memory overlay commands are not implemented.
35051
35052 @c @subheading -overlay-auto
35053
35054 @c @subheading -overlay-list-mapping-state
35055
35056 @c @subheading -overlay-list-overlays
35057
35058 @c @subheading -overlay-map
35059
35060 @c @subheading -overlay-off
35061
35062 @c @subheading -overlay-on
35063
35064 @c @subheading -overlay-unmap
35065
35066 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35067 @node GDB/MI Signal Handling Commands
35068 @section @sc{gdb/mi} Signal Handling Commands
35069
35070 Signal handling commands are not implemented.
35071
35072 @c @subheading -signal-handle
35073
35074 @c @subheading -signal-list-handle-actions
35075
35076 @c @subheading -signal-list-signal-types
35077 @end ignore
35078
35079
35080 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35081 @node GDB/MI Target Manipulation
35082 @section @sc{gdb/mi} Target Manipulation Commands
35083
35084
35085 @subheading The @code{-target-attach} Command
35086 @findex -target-attach
35087
35088 @subsubheading Synopsis
35089
35090 @smallexample
35091 -target-attach @var{pid} | @var{gid} | @var{file}
35092 @end smallexample
35093
35094 Attach to a process @var{pid} or a file @var{file} outside of
35095 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35096 group, the id previously returned by
35097 @samp{-list-thread-groups --available} must be used.
35098
35099 @subsubheading @value{GDBN} Command
35100
35101 The corresponding @value{GDBN} command is @samp{attach}.
35102
35103 @subsubheading Example
35104 @smallexample
35105 (gdb)
35106 -target-attach 34
35107 =thread-created,id="1"
35108 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35109 ^done
35110 (gdb)
35111 @end smallexample
35112
35113 @ignore
35114 @subheading The @code{-target-compare-sections} Command
35115 @findex -target-compare-sections
35116
35117 @subsubheading Synopsis
35118
35119 @smallexample
35120 -target-compare-sections [ @var{section} ]
35121 @end smallexample
35122
35123 Compare data of section @var{section} on target to the exec file.
35124 Without the argument, all sections are compared.
35125
35126 @subsubheading @value{GDBN} Command
35127
35128 The @value{GDBN} equivalent is @samp{compare-sections}.
35129
35130 @subsubheading Example
35131 N.A.
35132 @end ignore
35133
35134
35135 @subheading The @code{-target-detach} Command
35136 @findex -target-detach
35137
35138 @subsubheading Synopsis
35139
35140 @smallexample
35141 -target-detach [ @var{pid} | @var{gid} ]
35142 @end smallexample
35143
35144 Detach from the remote target which normally resumes its execution.
35145 If either @var{pid} or @var{gid} is specified, detaches from either
35146 the specified process, or specified thread group. There's no output.
35147
35148 @subsubheading @value{GDBN} Command
35149
35150 The corresponding @value{GDBN} command is @samp{detach}.
35151
35152 @subsubheading Example
35153
35154 @smallexample
35155 (gdb)
35156 -target-detach
35157 ^done
35158 (gdb)
35159 @end smallexample
35160
35161
35162 @subheading The @code{-target-disconnect} Command
35163 @findex -target-disconnect
35164
35165 @subsubheading Synopsis
35166
35167 @smallexample
35168 -target-disconnect
35169 @end smallexample
35170
35171 Disconnect from the remote target. There's no output and the target is
35172 generally not resumed.
35173
35174 @subsubheading @value{GDBN} Command
35175
35176 The corresponding @value{GDBN} command is @samp{disconnect}.
35177
35178 @subsubheading Example
35179
35180 @smallexample
35181 (gdb)
35182 -target-disconnect
35183 ^done
35184 (gdb)
35185 @end smallexample
35186
35187
35188 @subheading The @code{-target-download} Command
35189 @findex -target-download
35190
35191 @subsubheading Synopsis
35192
35193 @smallexample
35194 -target-download
35195 @end smallexample
35196
35197 Loads the executable onto the remote target.
35198 It prints out an update message every half second, which includes the fields:
35199
35200 @table @samp
35201 @item section
35202 The name of the section.
35203 @item section-sent
35204 The size of what has been sent so far for that section.
35205 @item section-size
35206 The size of the section.
35207 @item total-sent
35208 The total size of what was sent so far (the current and the previous sections).
35209 @item total-size
35210 The size of the overall executable to download.
35211 @end table
35212
35213 @noindent
35214 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35215 @sc{gdb/mi} Output Syntax}).
35216
35217 In addition, it prints the name and size of the sections, as they are
35218 downloaded. These messages include the following fields:
35219
35220 @table @samp
35221 @item section
35222 The name of the section.
35223 @item section-size
35224 The size of the section.
35225 @item total-size
35226 The size of the overall executable to download.
35227 @end table
35228
35229 @noindent
35230 At the end, a summary is printed.
35231
35232 @subsubheading @value{GDBN} Command
35233
35234 The corresponding @value{GDBN} command is @samp{load}.
35235
35236 @subsubheading Example
35237
35238 Note: each status message appears on a single line. Here the messages
35239 have been broken down so that they can fit onto a page.
35240
35241 @smallexample
35242 (gdb)
35243 -target-download
35244 +download,@{section=".text",section-size="6668",total-size="9880"@}
35245 +download,@{section=".text",section-sent="512",section-size="6668",
35246 total-sent="512",total-size="9880"@}
35247 +download,@{section=".text",section-sent="1024",section-size="6668",
35248 total-sent="1024",total-size="9880"@}
35249 +download,@{section=".text",section-sent="1536",section-size="6668",
35250 total-sent="1536",total-size="9880"@}
35251 +download,@{section=".text",section-sent="2048",section-size="6668",
35252 total-sent="2048",total-size="9880"@}
35253 +download,@{section=".text",section-sent="2560",section-size="6668",
35254 total-sent="2560",total-size="9880"@}
35255 +download,@{section=".text",section-sent="3072",section-size="6668",
35256 total-sent="3072",total-size="9880"@}
35257 +download,@{section=".text",section-sent="3584",section-size="6668",
35258 total-sent="3584",total-size="9880"@}
35259 +download,@{section=".text",section-sent="4096",section-size="6668",
35260 total-sent="4096",total-size="9880"@}
35261 +download,@{section=".text",section-sent="4608",section-size="6668",
35262 total-sent="4608",total-size="9880"@}
35263 +download,@{section=".text",section-sent="5120",section-size="6668",
35264 total-sent="5120",total-size="9880"@}
35265 +download,@{section=".text",section-sent="5632",section-size="6668",
35266 total-sent="5632",total-size="9880"@}
35267 +download,@{section=".text",section-sent="6144",section-size="6668",
35268 total-sent="6144",total-size="9880"@}
35269 +download,@{section=".text",section-sent="6656",section-size="6668",
35270 total-sent="6656",total-size="9880"@}
35271 +download,@{section=".init",section-size="28",total-size="9880"@}
35272 +download,@{section=".fini",section-size="28",total-size="9880"@}
35273 +download,@{section=".data",section-size="3156",total-size="9880"@}
35274 +download,@{section=".data",section-sent="512",section-size="3156",
35275 total-sent="7236",total-size="9880"@}
35276 +download,@{section=".data",section-sent="1024",section-size="3156",
35277 total-sent="7748",total-size="9880"@}
35278 +download,@{section=".data",section-sent="1536",section-size="3156",
35279 total-sent="8260",total-size="9880"@}
35280 +download,@{section=".data",section-sent="2048",section-size="3156",
35281 total-sent="8772",total-size="9880"@}
35282 +download,@{section=".data",section-sent="2560",section-size="3156",
35283 total-sent="9284",total-size="9880"@}
35284 +download,@{section=".data",section-sent="3072",section-size="3156",
35285 total-sent="9796",total-size="9880"@}
35286 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35287 write-rate="429"
35288 (gdb)
35289 @end smallexample
35290
35291
35292 @ignore
35293 @subheading The @code{-target-exec-status} Command
35294 @findex -target-exec-status
35295
35296 @subsubheading Synopsis
35297
35298 @smallexample
35299 -target-exec-status
35300 @end smallexample
35301
35302 Provide information on the state of the target (whether it is running or
35303 not, for instance).
35304
35305 @subsubheading @value{GDBN} Command
35306
35307 There's no equivalent @value{GDBN} command.
35308
35309 @subsubheading Example
35310 N.A.
35311
35312
35313 @subheading The @code{-target-list-available-targets} Command
35314 @findex -target-list-available-targets
35315
35316 @subsubheading Synopsis
35317
35318 @smallexample
35319 -target-list-available-targets
35320 @end smallexample
35321
35322 List the possible targets to connect to.
35323
35324 @subsubheading @value{GDBN} Command
35325
35326 The corresponding @value{GDBN} command is @samp{help target}.
35327
35328 @subsubheading Example
35329 N.A.
35330
35331
35332 @subheading The @code{-target-list-current-targets} Command
35333 @findex -target-list-current-targets
35334
35335 @subsubheading Synopsis
35336
35337 @smallexample
35338 -target-list-current-targets
35339 @end smallexample
35340
35341 Describe the current target.
35342
35343 @subsubheading @value{GDBN} Command
35344
35345 The corresponding information is printed by @samp{info file} (among
35346 other things).
35347
35348 @subsubheading Example
35349 N.A.
35350
35351
35352 @subheading The @code{-target-list-parameters} Command
35353 @findex -target-list-parameters
35354
35355 @subsubheading Synopsis
35356
35357 @smallexample
35358 -target-list-parameters
35359 @end smallexample
35360
35361 @c ????
35362 @end ignore
35363
35364 @subsubheading @value{GDBN} Command
35365
35366 No equivalent.
35367
35368 @subsubheading Example
35369 N.A.
35370
35371 @subheading The @code{-target-flash-erase} Command
35372 @findex -target-flash-erase
35373
35374 @subsubheading Synopsis
35375
35376 @smallexample
35377 -target-flash-erase
35378 @end smallexample
35379
35380 Erases all known flash memory regions on the target.
35381
35382 The corresponding @value{GDBN} command is @samp{flash-erase}.
35383
35384 The output is a list of flash regions that have been erased, with starting
35385 addresses and memory region sizes.
35386
35387 @smallexample
35388 (gdb)
35389 -target-flash-erase
35390 ^done,erased-regions=@{address="0x0",size="0x40000"@}
35391 (gdb)
35392 @end smallexample
35393
35394 @subheading The @code{-target-select} Command
35395 @findex -target-select
35396
35397 @subsubheading Synopsis
35398
35399 @smallexample
35400 -target-select @var{type} @var{parameters @dots{}}
35401 @end smallexample
35402
35403 Connect @value{GDBN} to the remote target. This command takes two args:
35404
35405 @table @samp
35406 @item @var{type}
35407 The type of target, for instance @samp{remote}, etc.
35408 @item @var{parameters}
35409 Device names, host names and the like. @xref{Target Commands, ,
35410 Commands for Managing Targets}, for more details.
35411 @end table
35412
35413 The output is a connection notification, followed by the address at
35414 which the target program is, in the following form:
35415
35416 @smallexample
35417 ^connected,addr="@var{address}",func="@var{function name}",
35418 args=[@var{arg list}]
35419 @end smallexample
35420
35421 @subsubheading @value{GDBN} Command
35422
35423 The corresponding @value{GDBN} command is @samp{target}.
35424
35425 @subsubheading Example
35426
35427 @smallexample
35428 (gdb)
35429 -target-select remote /dev/ttya
35430 ^connected,addr="0xfe00a300",func="??",args=[]
35431 (gdb)
35432 @end smallexample
35433
35434 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35435 @node GDB/MI File Transfer Commands
35436 @section @sc{gdb/mi} File Transfer Commands
35437
35438
35439 @subheading The @code{-target-file-put} Command
35440 @findex -target-file-put
35441
35442 @subsubheading Synopsis
35443
35444 @smallexample
35445 -target-file-put @var{hostfile} @var{targetfile}
35446 @end smallexample
35447
35448 Copy file @var{hostfile} from the host system (the machine running
35449 @value{GDBN}) to @var{targetfile} on the target system.
35450
35451 @subsubheading @value{GDBN} Command
35452
35453 The corresponding @value{GDBN} command is @samp{remote put}.
35454
35455 @subsubheading Example
35456
35457 @smallexample
35458 (gdb)
35459 -target-file-put localfile remotefile
35460 ^done
35461 (gdb)
35462 @end smallexample
35463
35464
35465 @subheading The @code{-target-file-get} Command
35466 @findex -target-file-get
35467
35468 @subsubheading Synopsis
35469
35470 @smallexample
35471 -target-file-get @var{targetfile} @var{hostfile}
35472 @end smallexample
35473
35474 Copy file @var{targetfile} from the target system to @var{hostfile}
35475 on the host system.
35476
35477 @subsubheading @value{GDBN} Command
35478
35479 The corresponding @value{GDBN} command is @samp{remote get}.
35480
35481 @subsubheading Example
35482
35483 @smallexample
35484 (gdb)
35485 -target-file-get remotefile localfile
35486 ^done
35487 (gdb)
35488 @end smallexample
35489
35490
35491 @subheading The @code{-target-file-delete} Command
35492 @findex -target-file-delete
35493
35494 @subsubheading Synopsis
35495
35496 @smallexample
35497 -target-file-delete @var{targetfile}
35498 @end smallexample
35499
35500 Delete @var{targetfile} from the target system.
35501
35502 @subsubheading @value{GDBN} Command
35503
35504 The corresponding @value{GDBN} command is @samp{remote delete}.
35505
35506 @subsubheading Example
35507
35508 @smallexample
35509 (gdb)
35510 -target-file-delete remotefile
35511 ^done
35512 (gdb)
35513 @end smallexample
35514
35515
35516 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35517 @node GDB/MI Ada Exceptions Commands
35518 @section Ada Exceptions @sc{gdb/mi} Commands
35519
35520 @subheading The @code{-info-ada-exceptions} Command
35521 @findex -info-ada-exceptions
35522
35523 @subsubheading Synopsis
35524
35525 @smallexample
35526 -info-ada-exceptions [ @var{regexp}]
35527 @end smallexample
35528
35529 List all Ada exceptions defined within the program being debugged.
35530 With a regular expression @var{regexp}, only those exceptions whose
35531 names match @var{regexp} are listed.
35532
35533 @subsubheading @value{GDBN} Command
35534
35535 The corresponding @value{GDBN} command is @samp{info exceptions}.
35536
35537 @subsubheading Result
35538
35539 The result is a table of Ada exceptions. The following columns are
35540 defined for each exception:
35541
35542 @table @samp
35543 @item name
35544 The name of the exception.
35545
35546 @item address
35547 The address of the exception.
35548
35549 @end table
35550
35551 @subsubheading Example
35552
35553 @smallexample
35554 -info-ada-exceptions aint
35555 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35556 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35557 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35558 body=[@{name="constraint_error",address="0x0000000000613da0"@},
35559 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35560 @end smallexample
35561
35562 @subheading Catching Ada Exceptions
35563
35564 The commands describing how to ask @value{GDBN} to stop when a program
35565 raises an exception are described at @ref{Ada Exception GDB/MI
35566 Catchpoint Commands}.
35567
35568
35569 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35570 @node GDB/MI Support Commands
35571 @section @sc{gdb/mi} Support Commands
35572
35573 Since new commands and features get regularly added to @sc{gdb/mi},
35574 some commands are available to help front-ends query the debugger
35575 about support for these capabilities. Similarly, it is also possible
35576 to query @value{GDBN} about target support of certain features.
35577
35578 @subheading The @code{-info-gdb-mi-command} Command
35579 @cindex @code{-info-gdb-mi-command}
35580 @findex -info-gdb-mi-command
35581
35582 @subsubheading Synopsis
35583
35584 @smallexample
35585 -info-gdb-mi-command @var{cmd_name}
35586 @end smallexample
35587
35588 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35589
35590 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35591 is technically not part of the command name (@pxref{GDB/MI Input
35592 Syntax}), and thus should be omitted in @var{cmd_name}. However,
35593 for ease of use, this command also accepts the form with the leading
35594 dash.
35595
35596 @subsubheading @value{GDBN} Command
35597
35598 There is no corresponding @value{GDBN} command.
35599
35600 @subsubheading Result
35601
35602 The result is a tuple. There is currently only one field:
35603
35604 @table @samp
35605 @item exists
35606 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35607 @code{"false"} otherwise.
35608
35609 @end table
35610
35611 @subsubheading Example
35612
35613 Here is an example where the @sc{gdb/mi} command does not exist:
35614
35615 @smallexample
35616 -info-gdb-mi-command unsupported-command
35617 ^done,command=@{exists="false"@}
35618 @end smallexample
35619
35620 @noindent
35621 And here is an example where the @sc{gdb/mi} command is known
35622 to the debugger:
35623
35624 @smallexample
35625 -info-gdb-mi-command symbol-list-lines
35626 ^done,command=@{exists="true"@}
35627 @end smallexample
35628
35629 @subheading The @code{-list-features} Command
35630 @findex -list-features
35631 @cindex supported @sc{gdb/mi} features, list
35632
35633 Returns a list of particular features of the MI protocol that
35634 this version of gdb implements. A feature can be a command,
35635 or a new field in an output of some command, or even an
35636 important bugfix. While a frontend can sometimes detect presence
35637 of a feature at runtime, it is easier to perform detection at debugger
35638 startup.
35639
35640 The command returns a list of strings, with each string naming an
35641 available feature. Each returned string is just a name, it does not
35642 have any internal structure. The list of possible feature names
35643 is given below.
35644
35645 Example output:
35646
35647 @smallexample
35648 (gdb) -list-features
35649 ^done,result=["feature1","feature2"]
35650 @end smallexample
35651
35652 The current list of features is:
35653
35654 @ftable @samp
35655 @item frozen-varobjs
35656 Indicates support for the @code{-var-set-frozen} command, as well
35657 as possible presence of the @code{frozen} field in the output
35658 of @code{-varobj-create}.
35659 @item pending-breakpoints
35660 Indicates support for the @option{-f} option to the @code{-break-insert}
35661 command.
35662 @item python
35663 Indicates Python scripting support, Python-based
35664 pretty-printing commands, and possible presence of the
35665 @samp{display_hint} field in the output of @code{-var-list-children}
35666 @item thread-info
35667 Indicates support for the @code{-thread-info} command.
35668 @item data-read-memory-bytes
35669 Indicates support for the @code{-data-read-memory-bytes} and the
35670 @code{-data-write-memory-bytes} commands.
35671 @item breakpoint-notifications
35672 Indicates that changes to breakpoints and breakpoints created via the
35673 CLI will be announced via async records.
35674 @item ada-task-info
35675 Indicates support for the @code{-ada-task-info} command.
35676 @item language-option
35677 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35678 option (@pxref{Context management}).
35679 @item info-gdb-mi-command
35680 Indicates support for the @code{-info-gdb-mi-command} command.
35681 @item undefined-command-error-code
35682 Indicates support for the "undefined-command" error code in error result
35683 records, produced when trying to execute an undefined @sc{gdb/mi} command
35684 (@pxref{GDB/MI Result Records}).
35685 @item exec-run-start-option
35686 Indicates that the @code{-exec-run} command supports the @option{--start}
35687 option (@pxref{GDB/MI Program Execution}).
35688 @item data-disassemble-a-option
35689 Indicates that the @code{-data-disassemble} command supports the @option{-a}
35690 option (@pxref{GDB/MI Data Manipulation}).
35691 @end ftable
35692
35693 @subheading The @code{-list-target-features} Command
35694 @findex -list-target-features
35695
35696 Returns a list of particular features that are supported by the
35697 target. Those features affect the permitted MI commands, but
35698 unlike the features reported by the @code{-list-features} command, the
35699 features depend on which target GDB is using at the moment. Whenever
35700 a target can change, due to commands such as @code{-target-select},
35701 @code{-target-attach} or @code{-exec-run}, the list of target features
35702 may change, and the frontend should obtain it again.
35703 Example output:
35704
35705 @smallexample
35706 (gdb) -list-target-features
35707 ^done,result=["async"]
35708 @end smallexample
35709
35710 The current list of features is:
35711
35712 @table @samp
35713 @item async
35714 Indicates that the target is capable of asynchronous command
35715 execution, which means that @value{GDBN} will accept further commands
35716 while the target is running.
35717
35718 @item reverse
35719 Indicates that the target is capable of reverse execution.
35720 @xref{Reverse Execution}, for more information.
35721
35722 @end table
35723
35724 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35725 @node GDB/MI Miscellaneous Commands
35726 @section Miscellaneous @sc{gdb/mi} Commands
35727
35728 @c @subheading -gdb-complete
35729
35730 @subheading The @code{-gdb-exit} Command
35731 @findex -gdb-exit
35732
35733 @subsubheading Synopsis
35734
35735 @smallexample
35736 -gdb-exit
35737 @end smallexample
35738
35739 Exit @value{GDBN} immediately.
35740
35741 @subsubheading @value{GDBN} Command
35742
35743 Approximately corresponds to @samp{quit}.
35744
35745 @subsubheading Example
35746
35747 @smallexample
35748 (gdb)
35749 -gdb-exit
35750 ^exit
35751 @end smallexample
35752
35753
35754 @ignore
35755 @subheading The @code{-exec-abort} Command
35756 @findex -exec-abort
35757
35758 @subsubheading Synopsis
35759
35760 @smallexample
35761 -exec-abort
35762 @end smallexample
35763
35764 Kill the inferior running program.
35765
35766 @subsubheading @value{GDBN} Command
35767
35768 The corresponding @value{GDBN} command is @samp{kill}.
35769
35770 @subsubheading Example
35771 N.A.
35772 @end ignore
35773
35774
35775 @subheading The @code{-gdb-set} Command
35776 @findex -gdb-set
35777
35778 @subsubheading Synopsis
35779
35780 @smallexample
35781 -gdb-set
35782 @end smallexample
35783
35784 Set an internal @value{GDBN} variable.
35785 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35786
35787 @subsubheading @value{GDBN} Command
35788
35789 The corresponding @value{GDBN} command is @samp{set}.
35790
35791 @subsubheading Example
35792
35793 @smallexample
35794 (gdb)
35795 -gdb-set $foo=3
35796 ^done
35797 (gdb)
35798 @end smallexample
35799
35800
35801 @subheading The @code{-gdb-show} Command
35802 @findex -gdb-show
35803
35804 @subsubheading Synopsis
35805
35806 @smallexample
35807 -gdb-show
35808 @end smallexample
35809
35810 Show the current value of a @value{GDBN} variable.
35811
35812 @subsubheading @value{GDBN} Command
35813
35814 The corresponding @value{GDBN} command is @samp{show}.
35815
35816 @subsubheading Example
35817
35818 @smallexample
35819 (gdb)
35820 -gdb-show annotate
35821 ^done,value="0"
35822 (gdb)
35823 @end smallexample
35824
35825 @c @subheading -gdb-source
35826
35827
35828 @subheading The @code{-gdb-version} Command
35829 @findex -gdb-version
35830
35831 @subsubheading Synopsis
35832
35833 @smallexample
35834 -gdb-version
35835 @end smallexample
35836
35837 Show version information for @value{GDBN}. Used mostly in testing.
35838
35839 @subsubheading @value{GDBN} Command
35840
35841 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35842 default shows this information when you start an interactive session.
35843
35844 @subsubheading Example
35845
35846 @c This example modifies the actual output from GDB to avoid overfull
35847 @c box in TeX.
35848 @smallexample
35849 (gdb)
35850 -gdb-version
35851 ~GNU gdb 5.2.1
35852 ~Copyright 2000 Free Software Foundation, Inc.
35853 ~GDB is free software, covered by the GNU General Public License, and
35854 ~you are welcome to change it and/or distribute copies of it under
35855 ~ certain conditions.
35856 ~Type "show copying" to see the conditions.
35857 ~There is absolutely no warranty for GDB. Type "show warranty" for
35858 ~ details.
35859 ~This GDB was configured as
35860 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35861 ^done
35862 (gdb)
35863 @end smallexample
35864
35865 @subheading The @code{-list-thread-groups} Command
35866 @findex -list-thread-groups
35867
35868 @subheading Synopsis
35869
35870 @smallexample
35871 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
35872 @end smallexample
35873
35874 Lists thread groups (@pxref{Thread groups}). When a single thread
35875 group is passed as the argument, lists the children of that group.
35876 When several thread group are passed, lists information about those
35877 thread groups. Without any parameters, lists information about all
35878 top-level thread groups.
35879
35880 Normally, thread groups that are being debugged are reported.
35881 With the @samp{--available} option, @value{GDBN} reports thread groups
35882 available on the target.
35883
35884 The output of this command may have either a @samp{threads} result or
35885 a @samp{groups} result. The @samp{thread} result has a list of tuples
35886 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35887 Information}). The @samp{groups} result has a list of tuples as value,
35888 each tuple describing a thread group. If top-level groups are
35889 requested (that is, no parameter is passed), or when several groups
35890 are passed, the output always has a @samp{groups} result. The format
35891 of the @samp{group} result is described below.
35892
35893 To reduce the number of roundtrips it's possible to list thread groups
35894 together with their children, by passing the @samp{--recurse} option
35895 and the recursion depth. Presently, only recursion depth of 1 is
35896 permitted. If this option is present, then every reported thread group
35897 will also include its children, either as @samp{group} or
35898 @samp{threads} field.
35899
35900 In general, any combination of option and parameters is permitted, with
35901 the following caveats:
35902
35903 @itemize @bullet
35904 @item
35905 When a single thread group is passed, the output will typically
35906 be the @samp{threads} result. Because threads may not contain
35907 anything, the @samp{recurse} option will be ignored.
35908
35909 @item
35910 When the @samp{--available} option is passed, limited information may
35911 be available. In particular, the list of threads of a process might
35912 be inaccessible. Further, specifying specific thread groups might
35913 not give any performance advantage over listing all thread groups.
35914 The frontend should assume that @samp{-list-thread-groups --available}
35915 is always an expensive operation and cache the results.
35916
35917 @end itemize
35918
35919 The @samp{groups} result is a list of tuples, where each tuple may
35920 have the following fields:
35921
35922 @table @code
35923 @item id
35924 Identifier of the thread group. This field is always present.
35925 The identifier is an opaque string; frontends should not try to
35926 convert it to an integer, even though it might look like one.
35927
35928 @item type
35929 The type of the thread group. At present, only @samp{process} is a
35930 valid type.
35931
35932 @item pid
35933 The target-specific process identifier. This field is only present
35934 for thread groups of type @samp{process} and only if the process exists.
35935
35936 @item exit-code
35937 The exit code of this group's last exited thread, formatted in octal.
35938 This field is only present for thread groups of type @samp{process} and
35939 only if the process is not running.
35940
35941 @item num_children
35942 The number of children this thread group has. This field may be
35943 absent for an available thread group.
35944
35945 @item threads
35946 This field has a list of tuples as value, each tuple describing a
35947 thread. It may be present if the @samp{--recurse} option is
35948 specified, and it's actually possible to obtain the threads.
35949
35950 @item cores
35951 This field is a list of integers, each identifying a core that one
35952 thread of the group is running on. This field may be absent if
35953 such information is not available.
35954
35955 @item executable
35956 The name of the executable file that corresponds to this thread group.
35957 The field is only present for thread groups of type @samp{process},
35958 and only if there is a corresponding executable file.
35959
35960 @end table
35961
35962 @subheading Example
35963
35964 @smallexample
35965 @value{GDBP}
35966 -list-thread-groups
35967 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
35968 -list-thread-groups 17
35969 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
35970 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
35971 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
35972 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
35973 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
35974 -list-thread-groups --available
35975 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
35976 -list-thread-groups --available --recurse 1
35977 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35978 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35979 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
35980 -list-thread-groups --available --recurse 1 17 18
35981 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35982 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35983 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
35984 @end smallexample
35985
35986 @subheading The @code{-info-os} Command
35987 @findex -info-os
35988
35989 @subsubheading Synopsis
35990
35991 @smallexample
35992 -info-os [ @var{type} ]
35993 @end smallexample
35994
35995 If no argument is supplied, the command returns a table of available
35996 operating-system-specific information types. If one of these types is
35997 supplied as an argument @var{type}, then the command returns a table
35998 of data of that type.
35999
36000 The types of information available depend on the target operating
36001 system.
36002
36003 @subsubheading @value{GDBN} Command
36004
36005 The corresponding @value{GDBN} command is @samp{info os}.
36006
36007 @subsubheading Example
36008
36009 When run on a @sc{gnu}/Linux system, the output will look something
36010 like this:
36011
36012 @smallexample
36013 @value{GDBP}
36014 -info-os
36015 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36016 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36017 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36018 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36019 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36020 col2="CPUs"@},
36021 item=@{col0="files",col1="Listing of all file descriptors",
36022 col2="File descriptors"@},
36023 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36024 col2="Kernel modules"@},
36025 item=@{col0="msg",col1="Listing of all message queues",
36026 col2="Message queues"@},
36027 item=@{col0="processes",col1="Listing of all processes",
36028 col2="Processes"@},
36029 item=@{col0="procgroups",col1="Listing of all process groups",
36030 col2="Process groups"@},
36031 item=@{col0="semaphores",col1="Listing of all semaphores",
36032 col2="Semaphores"@},
36033 item=@{col0="shm",col1="Listing of all shared-memory regions",
36034 col2="Shared-memory regions"@},
36035 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36036 col2="Sockets"@},
36037 item=@{col0="threads",col1="Listing of all threads",
36038 col2="Threads"@}]
36039 @value{GDBP}
36040 -info-os processes
36041 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36042 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36043 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36044 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36045 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36046 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36047 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36048 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36049 ...
36050 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36051 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36052 (gdb)
36053 @end smallexample
36054
36055 (Note that the MI output here includes a @code{"Title"} column that
36056 does not appear in command-line @code{info os}; this column is useful
36057 for MI clients that want to enumerate the types of data, such as in a
36058 popup menu, but is needless clutter on the command line, and
36059 @code{info os} omits it.)
36060
36061 @subheading The @code{-add-inferior} Command
36062 @findex -add-inferior
36063
36064 @subheading Synopsis
36065
36066 @smallexample
36067 -add-inferior
36068 @end smallexample
36069
36070 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
36071 inferior is not associated with any executable. Such association may
36072 be established with the @samp{-file-exec-and-symbols} command
36073 (@pxref{GDB/MI File Commands}). The command response has a single
36074 field, @samp{inferior}, whose value is the identifier of the
36075 thread group corresponding to the new inferior.
36076
36077 @subheading Example
36078
36079 @smallexample
36080 @value{GDBP}
36081 -add-inferior
36082 ^done,inferior="i3"
36083 @end smallexample
36084
36085 @subheading The @code{-interpreter-exec} Command
36086 @findex -interpreter-exec
36087
36088 @subheading Synopsis
36089
36090 @smallexample
36091 -interpreter-exec @var{interpreter} @var{command}
36092 @end smallexample
36093 @anchor{-interpreter-exec}
36094
36095 Execute the specified @var{command} in the given @var{interpreter}.
36096
36097 @subheading @value{GDBN} Command
36098
36099 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36100
36101 @subheading Example
36102
36103 @smallexample
36104 (gdb)
36105 -interpreter-exec console "break main"
36106 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36107 &"During symbol reading, bad structure-type format.\n"
36108 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36109 ^done
36110 (gdb)
36111 @end smallexample
36112
36113 @subheading The @code{-inferior-tty-set} Command
36114 @findex -inferior-tty-set
36115
36116 @subheading Synopsis
36117
36118 @smallexample
36119 -inferior-tty-set /dev/pts/1
36120 @end smallexample
36121
36122 Set terminal for future runs of the program being debugged.
36123
36124 @subheading @value{GDBN} Command
36125
36126 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36127
36128 @subheading Example
36129
36130 @smallexample
36131 (gdb)
36132 -inferior-tty-set /dev/pts/1
36133 ^done
36134 (gdb)
36135 @end smallexample
36136
36137 @subheading The @code{-inferior-tty-show} Command
36138 @findex -inferior-tty-show
36139
36140 @subheading Synopsis
36141
36142 @smallexample
36143 -inferior-tty-show
36144 @end smallexample
36145
36146 Show terminal for future runs of program being debugged.
36147
36148 @subheading @value{GDBN} Command
36149
36150 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36151
36152 @subheading Example
36153
36154 @smallexample
36155 (gdb)
36156 -inferior-tty-set /dev/pts/1
36157 ^done
36158 (gdb)
36159 -inferior-tty-show
36160 ^done,inferior_tty_terminal="/dev/pts/1"
36161 (gdb)
36162 @end smallexample
36163
36164 @subheading The @code{-enable-timings} Command
36165 @findex -enable-timings
36166
36167 @subheading Synopsis
36168
36169 @smallexample
36170 -enable-timings [yes | no]
36171 @end smallexample
36172
36173 Toggle the printing of the wallclock, user and system times for an MI
36174 command as a field in its output. This command is to help frontend
36175 developers optimize the performance of their code. No argument is
36176 equivalent to @samp{yes}.
36177
36178 @subheading @value{GDBN} Command
36179
36180 No equivalent.
36181
36182 @subheading Example
36183
36184 @smallexample
36185 (gdb)
36186 -enable-timings
36187 ^done
36188 (gdb)
36189 -break-insert main
36190 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36191 addr="0x080484ed",func="main",file="myprog.c",
36192 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36193 times="0"@},
36194 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36195 (gdb)
36196 -enable-timings no
36197 ^done
36198 (gdb)
36199 -exec-run
36200 ^running
36201 (gdb)
36202 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36203 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36204 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36205 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36206 (gdb)
36207 @end smallexample
36208
36209 @subheading The @code{-complete} Command
36210 @findex -complete
36211
36212 @subheading Synopsis
36213
36214 @smallexample
36215 -complete @var{command}
36216 @end smallexample
36217
36218 Show a list of completions for partially typed CLI @var{command}.
36219
36220 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36221 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36222 because @value{GDBN} is used remotely via a SSH connection.
36223
36224 @subheading Result
36225
36226 The result consists of two or three fields:
36227
36228 @table @samp
36229 @item completion
36230 This field contains the completed @var{command}. If @var{command}
36231 has no known completions, this field is omitted.
36232
36233 @item matches
36234 This field contains a (possibly empty) array of matches. It is always present.
36235
36236 @item max_completions_reached
36237 This field contains @code{1} if number of known completions is above
36238 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36239 @code{0}. It is always present.
36240
36241 @end table
36242
36243 @subheading @value{GDBN} Command
36244
36245 The corresponding @value{GDBN} command is @samp{complete}.
36246
36247 @subheading Example
36248
36249 @smallexample
36250 (gdb)
36251 -complete br
36252 ^done,completion="break",
36253 matches=["break","break-range"],
36254 max_completions_reached="0"
36255 (gdb)
36256 -complete "b ma"
36257 ^done,completion="b ma",
36258 matches=["b madvise","b main"],max_completions_reached="0"
36259 (gdb)
36260 -complete "b push_b"
36261 ^done,completion="b push_back(",
36262 matches=[
36263 "b A::push_back(void*)",
36264 "b std::string::push_back(char)",
36265 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36266 max_completions_reached="0"
36267 (gdb)
36268 -complete "nonexist"
36269 ^done,matches=[],max_completions_reached="0"
36270 (gdb)
36271
36272 @end smallexample
36273
36274 @node Annotations
36275 @chapter @value{GDBN} Annotations
36276
36277 This chapter describes annotations in @value{GDBN}. Annotations were
36278 designed to interface @value{GDBN} to graphical user interfaces or other
36279 similar programs which want to interact with @value{GDBN} at a
36280 relatively high level.
36281
36282 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36283 (@pxref{GDB/MI}).
36284
36285 @ignore
36286 This is Edition @value{EDITION}, @value{DATE}.
36287 @end ignore
36288
36289 @menu
36290 * Annotations Overview:: What annotations are; the general syntax.
36291 * Server Prefix:: Issuing a command without affecting user state.
36292 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36293 * Errors:: Annotations for error messages.
36294 * Invalidation:: Some annotations describe things now invalid.
36295 * Annotations for Running::
36296 Whether the program is running, how it stopped, etc.
36297 * Source Annotations:: Annotations describing source code.
36298 @end menu
36299
36300 @node Annotations Overview
36301 @section What is an Annotation?
36302 @cindex annotations
36303
36304 Annotations start with a newline character, two @samp{control-z}
36305 characters, and the name of the annotation. If there is no additional
36306 information associated with this annotation, the name of the annotation
36307 is followed immediately by a newline. If there is additional
36308 information, the name of the annotation is followed by a space, the
36309 additional information, and a newline. The additional information
36310 cannot contain newline characters.
36311
36312 Any output not beginning with a newline and two @samp{control-z}
36313 characters denotes literal output from @value{GDBN}. Currently there is
36314 no need for @value{GDBN} to output a newline followed by two
36315 @samp{control-z} characters, but if there was such a need, the
36316 annotations could be extended with an @samp{escape} annotation which
36317 means those three characters as output.
36318
36319 The annotation @var{level}, which is specified using the
36320 @option{--annotate} command line option (@pxref{Mode Options}), controls
36321 how much information @value{GDBN} prints together with its prompt,
36322 values of expressions, source lines, and other types of output. Level 0
36323 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36324 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36325 for programs that control @value{GDBN}, and level 2 annotations have
36326 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36327 Interface, annotate, GDB's Obsolete Annotations}).
36328
36329 @table @code
36330 @kindex set annotate
36331 @item set annotate @var{level}
36332 The @value{GDBN} command @code{set annotate} sets the level of
36333 annotations to the specified @var{level}.
36334
36335 @item show annotate
36336 @kindex show annotate
36337 Show the current annotation level.
36338 @end table
36339
36340 This chapter describes level 3 annotations.
36341
36342 A simple example of starting up @value{GDBN} with annotations is:
36343
36344 @smallexample
36345 $ @kbd{gdb --annotate=3}
36346 GNU gdb 6.0
36347 Copyright 2003 Free Software Foundation, Inc.
36348 GDB is free software, covered by the GNU General Public License,
36349 and you are welcome to change it and/or distribute copies of it
36350 under certain conditions.
36351 Type "show copying" to see the conditions.
36352 There is absolutely no warranty for GDB. Type "show warranty"
36353 for details.
36354 This GDB was configured as "i386-pc-linux-gnu"
36355
36356 ^Z^Zpre-prompt
36357 (@value{GDBP})
36358 ^Z^Zprompt
36359 @kbd{quit}
36360
36361 ^Z^Zpost-prompt
36362 $
36363 @end smallexample
36364
36365 Here @samp{quit} is input to @value{GDBN}; the rest is output from
36366 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36367 denotes a @samp{control-z} character) are annotations; the rest is
36368 output from @value{GDBN}.
36369
36370 @node Server Prefix
36371 @section The Server Prefix
36372 @cindex server prefix
36373
36374 If you prefix a command with @samp{server } then it will not affect
36375 the command history, nor will it affect @value{GDBN}'s notion of which
36376 command to repeat if @key{RET} is pressed on a line by itself. This
36377 means that commands can be run behind a user's back by a front-end in
36378 a transparent manner.
36379
36380 The @code{server } prefix does not affect the recording of values into
36381 the value history; to print a value without recording it into the
36382 value history, use the @code{output} command instead of the
36383 @code{print} command.
36384
36385 Using this prefix also disables confirmation requests
36386 (@pxref{confirmation requests}).
36387
36388 @node Prompting
36389 @section Annotation for @value{GDBN} Input
36390
36391 @cindex annotations for prompts
36392 When @value{GDBN} prompts for input, it annotates this fact so it is possible
36393 to know when to send output, when the output from a given command is
36394 over, etc.
36395
36396 Different kinds of input each have a different @dfn{input type}. Each
36397 input type has three annotations: a @code{pre-} annotation, which
36398 denotes the beginning of any prompt which is being output, a plain
36399 annotation, which denotes the end of the prompt, and then a @code{post-}
36400 annotation which denotes the end of any echo which may (or may not) be
36401 associated with the input. For example, the @code{prompt} input type
36402 features the following annotations:
36403
36404 @smallexample
36405 ^Z^Zpre-prompt
36406 ^Z^Zprompt
36407 ^Z^Zpost-prompt
36408 @end smallexample
36409
36410 The input types are
36411
36412 @table @code
36413 @findex pre-prompt annotation
36414 @findex prompt annotation
36415 @findex post-prompt annotation
36416 @item prompt
36417 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36418
36419 @findex pre-commands annotation
36420 @findex commands annotation
36421 @findex post-commands annotation
36422 @item commands
36423 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36424 command. The annotations are repeated for each command which is input.
36425
36426 @findex pre-overload-choice annotation
36427 @findex overload-choice annotation
36428 @findex post-overload-choice annotation
36429 @item overload-choice
36430 When @value{GDBN} wants the user to select between various overloaded functions.
36431
36432 @findex pre-query annotation
36433 @findex query annotation
36434 @findex post-query annotation
36435 @item query
36436 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36437
36438 @findex pre-prompt-for-continue annotation
36439 @findex prompt-for-continue annotation
36440 @findex post-prompt-for-continue annotation
36441 @item prompt-for-continue
36442 When @value{GDBN} is asking the user to press return to continue. Note: Don't
36443 expect this to work well; instead use @code{set height 0} to disable
36444 prompting. This is because the counting of lines is buggy in the
36445 presence of annotations.
36446 @end table
36447
36448 @node Errors
36449 @section Errors
36450 @cindex annotations for errors, warnings and interrupts
36451
36452 @findex quit annotation
36453 @smallexample
36454 ^Z^Zquit
36455 @end smallexample
36456
36457 This annotation occurs right before @value{GDBN} responds to an interrupt.
36458
36459 @findex error annotation
36460 @smallexample
36461 ^Z^Zerror
36462 @end smallexample
36463
36464 This annotation occurs right before @value{GDBN} responds to an error.
36465
36466 Quit and error annotations indicate that any annotations which @value{GDBN} was
36467 in the middle of may end abruptly. For example, if a
36468 @code{value-history-begin} annotation is followed by a @code{error}, one
36469 cannot expect to receive the matching @code{value-history-end}. One
36470 cannot expect not to receive it either, however; an error annotation
36471 does not necessarily mean that @value{GDBN} is immediately returning all the way
36472 to the top level.
36473
36474 @findex error-begin annotation
36475 A quit or error annotation may be preceded by
36476
36477 @smallexample
36478 ^Z^Zerror-begin
36479 @end smallexample
36480
36481 Any output between that and the quit or error annotation is the error
36482 message.
36483
36484 Warning messages are not yet annotated.
36485 @c If we want to change that, need to fix warning(), type_error(),
36486 @c range_error(), and possibly other places.
36487
36488 @node Invalidation
36489 @section Invalidation Notices
36490
36491 @cindex annotations for invalidation messages
36492 The following annotations say that certain pieces of state may have
36493 changed.
36494
36495 @table @code
36496 @findex frames-invalid annotation
36497 @item ^Z^Zframes-invalid
36498
36499 The frames (for example, output from the @code{backtrace} command) may
36500 have changed.
36501
36502 @findex breakpoints-invalid annotation
36503 @item ^Z^Zbreakpoints-invalid
36504
36505 The breakpoints may have changed. For example, the user just added or
36506 deleted a breakpoint.
36507 @end table
36508
36509 @node Annotations for Running
36510 @section Running the Program
36511 @cindex annotations for running programs
36512
36513 @findex starting annotation
36514 @findex stopping annotation
36515 When the program starts executing due to a @value{GDBN} command such as
36516 @code{step} or @code{continue},
36517
36518 @smallexample
36519 ^Z^Zstarting
36520 @end smallexample
36521
36522 is output. When the program stops,
36523
36524 @smallexample
36525 ^Z^Zstopped
36526 @end smallexample
36527
36528 is output. Before the @code{stopped} annotation, a variety of
36529 annotations describe how the program stopped.
36530
36531 @table @code
36532 @findex exited annotation
36533 @item ^Z^Zexited @var{exit-status}
36534 The program exited, and @var{exit-status} is the exit status (zero for
36535 successful exit, otherwise nonzero).
36536
36537 @findex signalled annotation
36538 @findex signal-name annotation
36539 @findex signal-name-end annotation
36540 @findex signal-string annotation
36541 @findex signal-string-end annotation
36542 @item ^Z^Zsignalled
36543 The program exited with a signal. After the @code{^Z^Zsignalled}, the
36544 annotation continues:
36545
36546 @smallexample
36547 @var{intro-text}
36548 ^Z^Zsignal-name
36549 @var{name}
36550 ^Z^Zsignal-name-end
36551 @var{middle-text}
36552 ^Z^Zsignal-string
36553 @var{string}
36554 ^Z^Zsignal-string-end
36555 @var{end-text}
36556 @end smallexample
36557
36558 @noindent
36559 where @var{name} is the name of the signal, such as @code{SIGILL} or
36560 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
36561 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
36562 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36563 user's benefit and have no particular format.
36564
36565 @findex signal annotation
36566 @item ^Z^Zsignal
36567 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36568 just saying that the program received the signal, not that it was
36569 terminated with it.
36570
36571 @findex breakpoint annotation
36572 @item ^Z^Zbreakpoint @var{number}
36573 The program hit breakpoint number @var{number}.
36574
36575 @findex watchpoint annotation
36576 @item ^Z^Zwatchpoint @var{number}
36577 The program hit watchpoint number @var{number}.
36578 @end table
36579
36580 @node Source Annotations
36581 @section Displaying Source
36582 @cindex annotations for source display
36583
36584 @findex source annotation
36585 The following annotation is used instead of displaying source code:
36586
36587 @smallexample
36588 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36589 @end smallexample
36590
36591 where @var{filename} is an absolute file name indicating which source
36592 file, @var{line} is the line number within that file (where 1 is the
36593 first line in the file), @var{character} is the character position
36594 within the file (where 0 is the first character in the file) (for most
36595 debug formats this will necessarily point to the beginning of a line),
36596 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
36597 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36598 @var{addr} is the address in the target program associated with the
36599 source which is being displayed. The @var{addr} is in the form @samp{0x}
36600 followed by one or more lowercase hex digits (note that this does not
36601 depend on the language).
36602
36603 @node JIT Interface
36604 @chapter JIT Compilation Interface
36605 @cindex just-in-time compilation
36606 @cindex JIT compilation interface
36607
36608 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36609 interface. A JIT compiler is a program or library that generates native
36610 executable code at runtime and executes it, usually in order to achieve good
36611 performance while maintaining platform independence.
36612
36613 Programs that use JIT compilation are normally difficult to debug because
36614 portions of their code are generated at runtime, instead of being loaded from
36615 object files, which is where @value{GDBN} normally finds the program's symbols
36616 and debug information. In order to debug programs that use JIT compilation,
36617 @value{GDBN} has an interface that allows the program to register in-memory
36618 symbol files with @value{GDBN} at runtime.
36619
36620 If you are using @value{GDBN} to debug a program that uses this interface, then
36621 it should work transparently so long as you have not stripped the binary. If
36622 you are developing a JIT compiler, then the interface is documented in the rest
36623 of this chapter. At this time, the only known client of this interface is the
36624 LLVM JIT.
36625
36626 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36627 JIT compiler communicates with @value{GDBN} by writing data into a global
36628 variable and calling a function at a well-known symbol. When @value{GDBN}
36629 attaches, it reads a linked list of symbol files from the global variable to
36630 find existing code, and puts a breakpoint in the function so that it can find
36631 out about additional code.
36632
36633 @menu
36634 * Declarations:: Relevant C struct declarations
36635 * Registering Code:: Steps to register code
36636 * Unregistering Code:: Steps to unregister code
36637 * Custom Debug Info:: Emit debug information in a custom format
36638 @end menu
36639
36640 @node Declarations
36641 @section JIT Declarations
36642
36643 These are the relevant struct declarations that a C program should include to
36644 implement the interface:
36645
36646 @smallexample
36647 typedef enum
36648 @{
36649 JIT_NOACTION = 0,
36650 JIT_REGISTER_FN,
36651 JIT_UNREGISTER_FN
36652 @} jit_actions_t;
36653
36654 struct jit_code_entry
36655 @{
36656 struct jit_code_entry *next_entry;
36657 struct jit_code_entry *prev_entry;
36658 const char *symfile_addr;
36659 uint64_t symfile_size;
36660 @};
36661
36662 struct jit_descriptor
36663 @{
36664 uint32_t version;
36665 /* This type should be jit_actions_t, but we use uint32_t
36666 to be explicit about the bitwidth. */
36667 uint32_t action_flag;
36668 struct jit_code_entry *relevant_entry;
36669 struct jit_code_entry *first_entry;
36670 @};
36671
36672 /* GDB puts a breakpoint in this function. */
36673 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36674
36675 /* Make sure to specify the version statically, because the
36676 debugger may check the version before we can set it. */
36677 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36678 @end smallexample
36679
36680 If the JIT is multi-threaded, then it is important that the JIT synchronize any
36681 modifications to this global data properly, which can easily be done by putting
36682 a global mutex around modifications to these structures.
36683
36684 @node Registering Code
36685 @section Registering Code
36686
36687 To register code with @value{GDBN}, the JIT should follow this protocol:
36688
36689 @itemize @bullet
36690 @item
36691 Generate an object file in memory with symbols and other desired debug
36692 information. The file must include the virtual addresses of the sections.
36693
36694 @item
36695 Create a code entry for the file, which gives the start and size of the symbol
36696 file.
36697
36698 @item
36699 Add it to the linked list in the JIT descriptor.
36700
36701 @item
36702 Point the relevant_entry field of the descriptor at the entry.
36703
36704 @item
36705 Set @code{action_flag} to @code{JIT_REGISTER} and call
36706 @code{__jit_debug_register_code}.
36707 @end itemize
36708
36709 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36710 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
36711 new code. However, the linked list must still be maintained in order to allow
36712 @value{GDBN} to attach to a running process and still find the symbol files.
36713
36714 @node Unregistering Code
36715 @section Unregistering Code
36716
36717 If code is freed, then the JIT should use the following protocol:
36718
36719 @itemize @bullet
36720 @item
36721 Remove the code entry corresponding to the code from the linked list.
36722
36723 @item
36724 Point the @code{relevant_entry} field of the descriptor at the code entry.
36725
36726 @item
36727 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36728 @code{__jit_debug_register_code}.
36729 @end itemize
36730
36731 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36732 and the JIT will leak the memory used for the associated symbol files.
36733
36734 @node Custom Debug Info
36735 @section Custom Debug Info
36736 @cindex custom JIT debug info
36737 @cindex JIT debug info reader
36738
36739 Generating debug information in platform-native file formats (like ELF
36740 or COFF) may be an overkill for JIT compilers; especially if all the
36741 debug info is used for is displaying a meaningful backtrace. The
36742 issue can be resolved by having the JIT writers decide on a debug info
36743 format and also provide a reader that parses the debug info generated
36744 by the JIT compiler. This section gives a brief overview on writing
36745 such a parser. More specific details can be found in the source file
36746 @file{gdb/jit-reader.in}, which is also installed as a header at
36747 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36748
36749 The reader is implemented as a shared object (so this functionality is
36750 not available on platforms which don't allow loading shared objects at
36751 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36752 @code{jit-reader-unload} are provided, to be used to load and unload
36753 the readers from a preconfigured directory. Once loaded, the shared
36754 object is used the parse the debug information emitted by the JIT
36755 compiler.
36756
36757 @menu
36758 * Using JIT Debug Info Readers:: How to use supplied readers correctly
36759 * Writing JIT Debug Info Readers:: Creating a debug-info reader
36760 @end menu
36761
36762 @node Using JIT Debug Info Readers
36763 @subsection Using JIT Debug Info Readers
36764 @kindex jit-reader-load
36765 @kindex jit-reader-unload
36766
36767 Readers can be loaded and unloaded using the @code{jit-reader-load}
36768 and @code{jit-reader-unload} commands.
36769
36770 @table @code
36771 @item jit-reader-load @var{reader}
36772 Load the JIT reader named @var{reader}, which is a shared
36773 object specified as either an absolute or a relative file name. In
36774 the latter case, @value{GDBN} will try to load the reader from a
36775 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36776 system (here @var{libdir} is the system library directory, often
36777 @file{/usr/local/lib}).
36778
36779 Only one reader can be active at a time; trying to load a second
36780 reader when one is already loaded will result in @value{GDBN}
36781 reporting an error. A new JIT reader can be loaded by first unloading
36782 the current one using @code{jit-reader-unload} and then invoking
36783 @code{jit-reader-load}.
36784
36785 @item jit-reader-unload
36786 Unload the currently loaded JIT reader.
36787
36788 @end table
36789
36790 @node Writing JIT Debug Info Readers
36791 @subsection Writing JIT Debug Info Readers
36792 @cindex writing JIT debug info readers
36793
36794 As mentioned, a reader is essentially a shared object conforming to a
36795 certain ABI. This ABI is described in @file{jit-reader.h}.
36796
36797 @file{jit-reader.h} defines the structures, macros and functions
36798 required to write a reader. It is installed (along with
36799 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36800 the system include directory.
36801
36802 Readers need to be released under a GPL compatible license. A reader
36803 can be declared as released under such a license by placing the macro
36804 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36805
36806 The entry point for readers is the symbol @code{gdb_init_reader},
36807 which is expected to be a function with the prototype
36808
36809 @findex gdb_init_reader
36810 @smallexample
36811 extern struct gdb_reader_funcs *gdb_init_reader (void);
36812 @end smallexample
36813
36814 @cindex @code{struct gdb_reader_funcs}
36815
36816 @code{struct gdb_reader_funcs} contains a set of pointers to callback
36817 functions. These functions are executed to read the debug info
36818 generated by the JIT compiler (@code{read}), to unwind stack frames
36819 (@code{unwind}) and to create canonical frame IDs
36820 (@code{get_frame_id}). It also has a callback that is called when the
36821 reader is being unloaded (@code{destroy}). The struct looks like this
36822
36823 @smallexample
36824 struct gdb_reader_funcs
36825 @{
36826 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36827 int reader_version;
36828
36829 /* For use by the reader. */
36830 void *priv_data;
36831
36832 gdb_read_debug_info *read;
36833 gdb_unwind_frame *unwind;
36834 gdb_get_frame_id *get_frame_id;
36835 gdb_destroy_reader *destroy;
36836 @};
36837 @end smallexample
36838
36839 @cindex @code{struct gdb_symbol_callbacks}
36840 @cindex @code{struct gdb_unwind_callbacks}
36841
36842 The callbacks are provided with another set of callbacks by
36843 @value{GDBN} to do their job. For @code{read}, these callbacks are
36844 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36845 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36846 @code{struct gdb_symbol_callbacks} has callbacks to create new object
36847 files and new symbol tables inside those object files. @code{struct
36848 gdb_unwind_callbacks} has callbacks to read registers off the current
36849 frame and to write out the values of the registers in the previous
36850 frame. Both have a callback (@code{target_read}) to read bytes off the
36851 target's address space.
36852
36853 @node In-Process Agent
36854 @chapter In-Process Agent
36855 @cindex debugging agent
36856 The traditional debugging model is conceptually low-speed, but works fine,
36857 because most bugs can be reproduced in debugging-mode execution. However,
36858 as multi-core or many-core processors are becoming mainstream, and
36859 multi-threaded programs become more and more popular, there should be more
36860 and more bugs that only manifest themselves at normal-mode execution, for
36861 example, thread races, because debugger's interference with the program's
36862 timing may conceal the bugs. On the other hand, in some applications,
36863 it is not feasible for the debugger to interrupt the program's execution
36864 long enough for the developer to learn anything helpful about its behavior.
36865 If the program's correctness depends on its real-time behavior, delays
36866 introduced by a debugger might cause the program to fail, even when the
36867 code itself is correct. It is useful to be able to observe the program's
36868 behavior without interrupting it.
36869
36870 Therefore, traditional debugging model is too intrusive to reproduce
36871 some bugs. In order to reduce the interference with the program, we can
36872 reduce the number of operations performed by debugger. The
36873 @dfn{In-Process Agent}, a shared library, is running within the same
36874 process with inferior, and is able to perform some debugging operations
36875 itself. As a result, debugger is only involved when necessary, and
36876 performance of debugging can be improved accordingly. Note that
36877 interference with program can be reduced but can't be removed completely,
36878 because the in-process agent will still stop or slow down the program.
36879
36880 The in-process agent can interpret and execute Agent Expressions
36881 (@pxref{Agent Expressions}) during performing debugging operations. The
36882 agent expressions can be used for different purposes, such as collecting
36883 data in tracepoints, and condition evaluation in breakpoints.
36884
36885 @anchor{Control Agent}
36886 You can control whether the in-process agent is used as an aid for
36887 debugging with the following commands:
36888
36889 @table @code
36890 @kindex set agent on
36891 @item set agent on
36892 Causes the in-process agent to perform some operations on behalf of the
36893 debugger. Just which operations requested by the user will be done
36894 by the in-process agent depends on the its capabilities. For example,
36895 if you request to evaluate breakpoint conditions in the in-process agent,
36896 and the in-process agent has such capability as well, then breakpoint
36897 conditions will be evaluated in the in-process agent.
36898
36899 @kindex set agent off
36900 @item set agent off
36901 Disables execution of debugging operations by the in-process agent. All
36902 of the operations will be performed by @value{GDBN}.
36903
36904 @kindex show agent
36905 @item show agent
36906 Display the current setting of execution of debugging operations by
36907 the in-process agent.
36908 @end table
36909
36910 @menu
36911 * In-Process Agent Protocol::
36912 @end menu
36913
36914 @node In-Process Agent Protocol
36915 @section In-Process Agent Protocol
36916 @cindex in-process agent protocol
36917
36918 The in-process agent is able to communicate with both @value{GDBN} and
36919 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
36920 used for communications between @value{GDBN} or GDBserver and the IPA.
36921 In general, @value{GDBN} or GDBserver sends commands
36922 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
36923 in-process agent replies back with the return result of the command, or
36924 some other information. The data sent to in-process agent is composed
36925 of primitive data types, such as 4-byte or 8-byte type, and composite
36926 types, which are called objects (@pxref{IPA Protocol Objects}).
36927
36928 @menu
36929 * IPA Protocol Objects::
36930 * IPA Protocol Commands::
36931 @end menu
36932
36933 @node IPA Protocol Objects
36934 @subsection IPA Protocol Objects
36935 @cindex ipa protocol objects
36936
36937 The commands sent to and results received from agent may contain some
36938 complex data types called @dfn{objects}.
36939
36940 The in-process agent is running on the same machine with @value{GDBN}
36941 or GDBserver, so it doesn't have to handle as much differences between
36942 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
36943 However, there are still some differences of two ends in two processes:
36944
36945 @enumerate
36946 @item
36947 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
36948 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
36949 @item
36950 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
36951 GDBserver is compiled with one, and in-process agent is compiled with
36952 the other one.
36953 @end enumerate
36954
36955 Here are the IPA Protocol Objects:
36956
36957 @enumerate
36958 @item
36959 agent expression object. It represents an agent expression
36960 (@pxref{Agent Expressions}).
36961 @anchor{agent expression object}
36962 @item
36963 tracepoint action object. It represents a tracepoint action
36964 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
36965 memory, static trace data and to evaluate expression.
36966 @anchor{tracepoint action object}
36967 @item
36968 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
36969 @anchor{tracepoint object}
36970
36971 @end enumerate
36972
36973 The following table describes important attributes of each IPA protocol
36974 object:
36975
36976 @multitable @columnfractions .30 .20 .50
36977 @headitem Name @tab Size @tab Description
36978 @item @emph{agent expression object} @tab @tab
36979 @item length @tab 4 @tab length of bytes code
36980 @item byte code @tab @var{length} @tab contents of byte code
36981 @item @emph{tracepoint action for collecting memory} @tab @tab
36982 @item 'M' @tab 1 @tab type of tracepoint action
36983 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
36984 address of the lowest byte to collect, otherwise @var{addr} is the offset
36985 of @var{basereg} for memory collecting.
36986 @item len @tab 8 @tab length of memory for collecting
36987 @item basereg @tab 4 @tab the register number containing the starting
36988 memory address for collecting.
36989 @item @emph{tracepoint action for collecting registers} @tab @tab
36990 @item 'R' @tab 1 @tab type of tracepoint action
36991 @item @emph{tracepoint action for collecting static trace data} @tab @tab
36992 @item 'L' @tab 1 @tab type of tracepoint action
36993 @item @emph{tracepoint action for expression evaluation} @tab @tab
36994 @item 'X' @tab 1 @tab type of tracepoint action
36995 @item agent expression @tab length of @tab @ref{agent expression object}
36996 @item @emph{tracepoint object} @tab @tab
36997 @item number @tab 4 @tab number of tracepoint
36998 @item address @tab 8 @tab address of tracepoint inserted on
36999 @item type @tab 4 @tab type of tracepoint
37000 @item enabled @tab 1 @tab enable or disable of tracepoint
37001 @item step_count @tab 8 @tab step
37002 @item pass_count @tab 8 @tab pass
37003 @item numactions @tab 4 @tab number of tracepoint actions
37004 @item hit count @tab 8 @tab hit count
37005 @item trace frame usage @tab 8 @tab trace frame usage
37006 @item compiled_cond @tab 8 @tab compiled condition
37007 @item orig_size @tab 8 @tab orig size
37008 @item condition @tab 4 if condition is NULL otherwise length of
37009 @ref{agent expression object}
37010 @tab zero if condition is NULL, otherwise is
37011 @ref{agent expression object}
37012 @item actions @tab variable
37013 @tab numactions number of @ref{tracepoint action object}
37014 @end multitable
37015
37016 @node IPA Protocol Commands
37017 @subsection IPA Protocol Commands
37018 @cindex ipa protocol commands
37019
37020 The spaces in each command are delimiters to ease reading this commands
37021 specification. They don't exist in real commands.
37022
37023 @table @samp
37024
37025 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37026 Installs a new fast tracepoint described by @var{tracepoint_object}
37027 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
37028 head of @dfn{jumppad}, which is used to jump to data collection routine
37029 in IPA finally.
37030
37031 Replies:
37032 @table @samp
37033 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37034 @var{target_address} is address of tracepoint in the inferior.
37035 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
37036 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37037 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37038 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37039 @item E @var{NN}
37040 for an error
37041
37042 @end table
37043
37044 @item close
37045 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37046 is about to kill inferiors.
37047
37048 @item qTfSTM
37049 @xref{qTfSTM}.
37050 @item qTsSTM
37051 @xref{qTsSTM}.
37052 @item qTSTMat
37053 @xref{qTSTMat}.
37054 @item probe_marker_at:@var{address}
37055 Asks in-process agent to probe the marker at @var{address}.
37056
37057 Replies:
37058 @table @samp
37059 @item E @var{NN}
37060 for an error
37061 @end table
37062 @item unprobe_marker_at:@var{address}
37063 Asks in-process agent to unprobe the marker at @var{address}.
37064 @end table
37065
37066 @node GDB Bugs
37067 @chapter Reporting Bugs in @value{GDBN}
37068 @cindex bugs in @value{GDBN}
37069 @cindex reporting bugs in @value{GDBN}
37070
37071 Your bug reports play an essential role in making @value{GDBN} reliable.
37072
37073 Reporting a bug may help you by bringing a solution to your problem, or it
37074 may not. But in any case the principal function of a bug report is to help
37075 the entire community by making the next version of @value{GDBN} work better. Bug
37076 reports are your contribution to the maintenance of @value{GDBN}.
37077
37078 In order for a bug report to serve its purpose, you must include the
37079 information that enables us to fix the bug.
37080
37081 @menu
37082 * Bug Criteria:: Have you found a bug?
37083 * Bug Reporting:: How to report bugs
37084 @end menu
37085
37086 @node Bug Criteria
37087 @section Have You Found a Bug?
37088 @cindex bug criteria
37089
37090 If you are not sure whether you have found a bug, here are some guidelines:
37091
37092 @itemize @bullet
37093 @cindex fatal signal
37094 @cindex debugger crash
37095 @cindex crash of debugger
37096 @item
37097 If the debugger gets a fatal signal, for any input whatever, that is a
37098 @value{GDBN} bug. Reliable debuggers never crash.
37099
37100 @cindex error on valid input
37101 @item
37102 If @value{GDBN} produces an error message for valid input, that is a
37103 bug. (Note that if you're cross debugging, the problem may also be
37104 somewhere in the connection to the target.)
37105
37106 @cindex invalid input
37107 @item
37108 If @value{GDBN} does not produce an error message for invalid input,
37109 that is a bug. However, you should note that your idea of
37110 ``invalid input'' might be our idea of ``an extension'' or ``support
37111 for traditional practice''.
37112
37113 @item
37114 If you are an experienced user of debugging tools, your suggestions
37115 for improvement of @value{GDBN} are welcome in any case.
37116 @end itemize
37117
37118 @node Bug Reporting
37119 @section How to Report Bugs
37120 @cindex bug reports
37121 @cindex @value{GDBN} bugs, reporting
37122
37123 A number of companies and individuals offer support for @sc{gnu} products.
37124 If you obtained @value{GDBN} from a support organization, we recommend you
37125 contact that organization first.
37126
37127 You can find contact information for many support companies and
37128 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37129 distribution.
37130 @c should add a web page ref...
37131
37132 @ifset BUGURL
37133 @ifset BUGURL_DEFAULT
37134 In any event, we also recommend that you submit bug reports for
37135 @value{GDBN}. The preferred method is to submit them directly using
37136 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37137 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37138 be used.
37139
37140 @strong{Do not send bug reports to @samp{info-gdb}, or to
37141 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37142 not want to receive bug reports. Those that do have arranged to receive
37143 @samp{bug-gdb}.
37144
37145 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37146 serves as a repeater. The mailing list and the newsgroup carry exactly
37147 the same messages. Often people think of posting bug reports to the
37148 newsgroup instead of mailing them. This appears to work, but it has one
37149 problem which can be crucial: a newsgroup posting often lacks a mail
37150 path back to the sender. Thus, if we need to ask for more information,
37151 we may be unable to reach you. For this reason, it is better to send
37152 bug reports to the mailing list.
37153 @end ifset
37154 @ifclear BUGURL_DEFAULT
37155 In any event, we also recommend that you submit bug reports for
37156 @value{GDBN} to @value{BUGURL}.
37157 @end ifclear
37158 @end ifset
37159
37160 The fundamental principle of reporting bugs usefully is this:
37161 @strong{report all the facts}. If you are not sure whether to state a
37162 fact or leave it out, state it!
37163
37164 Often people omit facts because they think they know what causes the
37165 problem and assume that some details do not matter. Thus, you might
37166 assume that the name of the variable you use in an example does not matter.
37167 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37168 stray memory reference which happens to fetch from the location where that
37169 name is stored in memory; perhaps, if the name were different, the contents
37170 of that location would fool the debugger into doing the right thing despite
37171 the bug. Play it safe and give a specific, complete example. That is the
37172 easiest thing for you to do, and the most helpful.
37173
37174 Keep in mind that the purpose of a bug report is to enable us to fix the
37175 bug. It may be that the bug has been reported previously, but neither
37176 you nor we can know that unless your bug report is complete and
37177 self-contained.
37178
37179 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37180 bell?'' Those bug reports are useless, and we urge everyone to
37181 @emph{refuse to respond to them} except to chide the sender to report
37182 bugs properly.
37183
37184 To enable us to fix the bug, you should include all these things:
37185
37186 @itemize @bullet
37187 @item
37188 The version of @value{GDBN}. @value{GDBN} announces it if you start
37189 with no arguments; you can also print it at any time using @code{show
37190 version}.
37191
37192 Without this, we will not know whether there is any point in looking for
37193 the bug in the current version of @value{GDBN}.
37194
37195 @item
37196 The type of machine you are using, and the operating system name and
37197 version number.
37198
37199 @item
37200 The details of the @value{GDBN} build-time configuration.
37201 @value{GDBN} shows these details if you invoke it with the
37202 @option{--configuration} command-line option, or if you type
37203 @code{show configuration} at @value{GDBN}'s prompt.
37204
37205 @item
37206 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37207 ``@value{GCC}--2.8.1''.
37208
37209 @item
37210 What compiler (and its version) was used to compile the program you are
37211 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37212 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37213 to get this information; for other compilers, see the documentation for
37214 those compilers.
37215
37216 @item
37217 The command arguments you gave the compiler to compile your example and
37218 observe the bug. For example, did you use @samp{-O}? To guarantee
37219 you will not omit something important, list them all. A copy of the
37220 Makefile (or the output from make) is sufficient.
37221
37222 If we were to try to guess the arguments, we would probably guess wrong
37223 and then we might not encounter the bug.
37224
37225 @item
37226 A complete input script, and all necessary source files, that will
37227 reproduce the bug.
37228
37229 @item
37230 A description of what behavior you observe that you believe is
37231 incorrect. For example, ``It gets a fatal signal.''
37232
37233 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37234 will certainly notice it. But if the bug is incorrect output, we might
37235 not notice unless it is glaringly wrong. You might as well not give us
37236 a chance to make a mistake.
37237
37238 Even if the problem you experience is a fatal signal, you should still
37239 say so explicitly. Suppose something strange is going on, such as, your
37240 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37241 the C library on your system. (This has happened!) Your copy might
37242 crash and ours would not. If you told us to expect a crash, then when
37243 ours fails to crash, we would know that the bug was not happening for
37244 us. If you had not told us to expect a crash, then we would not be able
37245 to draw any conclusion from our observations.
37246
37247 @pindex script
37248 @cindex recording a session script
37249 To collect all this information, you can use a session recording program
37250 such as @command{script}, which is available on many Unix systems.
37251 Just run your @value{GDBN} session inside @command{script} and then
37252 include the @file{typescript} file with your bug report.
37253
37254 Another way to record a @value{GDBN} session is to run @value{GDBN}
37255 inside Emacs and then save the entire buffer to a file.
37256
37257 @item
37258 If you wish to suggest changes to the @value{GDBN} source, send us context
37259 diffs. If you even discuss something in the @value{GDBN} source, refer to
37260 it by context, not by line number.
37261
37262 The line numbers in our development sources will not match those in your
37263 sources. Your line numbers would convey no useful information to us.
37264
37265 @end itemize
37266
37267 Here are some things that are not necessary:
37268
37269 @itemize @bullet
37270 @item
37271 A description of the envelope of the bug.
37272
37273 Often people who encounter a bug spend a lot of time investigating
37274 which changes to the input file will make the bug go away and which
37275 changes will not affect it.
37276
37277 This is often time consuming and not very useful, because the way we
37278 will find the bug is by running a single example under the debugger
37279 with breakpoints, not by pure deduction from a series of examples.
37280 We recommend that you save your time for something else.
37281
37282 Of course, if you can find a simpler example to report @emph{instead}
37283 of the original one, that is a convenience for us. Errors in the
37284 output will be easier to spot, running under the debugger will take
37285 less time, and so on.
37286
37287 However, simplification is not vital; if you do not want to do this,
37288 report the bug anyway and send us the entire test case you used.
37289
37290 @item
37291 A patch for the bug.
37292
37293 A patch for the bug does help us if it is a good one. But do not omit
37294 the necessary information, such as the test case, on the assumption that
37295 a patch is all we need. We might see problems with your patch and decide
37296 to fix the problem another way, or we might not understand it at all.
37297
37298 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37299 construct an example that will make the program follow a certain path
37300 through the code. If you do not send us the example, we will not be able
37301 to construct one, so we will not be able to verify that the bug is fixed.
37302
37303 And if we cannot understand what bug you are trying to fix, or why your
37304 patch should be an improvement, we will not install it. A test case will
37305 help us to understand.
37306
37307 @item
37308 A guess about what the bug is or what it depends on.
37309
37310 Such guesses are usually wrong. Even we cannot guess right about such
37311 things without first using the debugger to find the facts.
37312 @end itemize
37313
37314 @c The readline documentation is distributed with the readline code
37315 @c and consists of the two following files:
37316 @c rluser.texi
37317 @c hsuser.texi
37318 @c Use -I with makeinfo to point to the appropriate directory,
37319 @c environment var TEXINPUTS with TeX.
37320 @ifclear SYSTEM_READLINE
37321 @include rluser.texi
37322 @include hsuser.texi
37323 @end ifclear
37324
37325 @node In Memoriam
37326 @appendix In Memoriam
37327
37328 The @value{GDBN} project mourns the loss of the following long-time
37329 contributors:
37330
37331 @table @code
37332 @item Fred Fish
37333 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37334 to Free Software in general. Outside of @value{GDBN}, he was known in
37335 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37336
37337 @item Michael Snyder
37338 Michael was one of the Global Maintainers of the @value{GDBN} project,
37339 with contributions recorded as early as 1996, until 2011. In addition
37340 to his day to day participation, he was a large driving force behind
37341 adding Reverse Debugging to @value{GDBN}.
37342 @end table
37343
37344 Beyond their technical contributions to the project, they were also
37345 enjoyable members of the Free Software Community. We will miss them.
37346
37347 @node Formatting Documentation
37348 @appendix Formatting Documentation
37349
37350 @cindex @value{GDBN} reference card
37351 @cindex reference card
37352 The @value{GDBN} 4 release includes an already-formatted reference card, ready
37353 for printing with PostScript or Ghostscript, in the @file{gdb}
37354 subdirectory of the main source directory@footnote{In
37355 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37356 release.}. If you can use PostScript or Ghostscript with your printer,
37357 you can print the reference card immediately with @file{refcard.ps}.
37358
37359 The release also includes the source for the reference card. You
37360 can format it, using @TeX{}, by typing:
37361
37362 @smallexample
37363 make refcard.dvi
37364 @end smallexample
37365
37366 The @value{GDBN} reference card is designed to print in @dfn{landscape}
37367 mode on US ``letter'' size paper;
37368 that is, on a sheet 11 inches wide by 8.5 inches
37369 high. You will need to specify this form of printing as an option to
37370 your @sc{dvi} output program.
37371
37372 @cindex documentation
37373
37374 All the documentation for @value{GDBN} comes as part of the machine-readable
37375 distribution. The documentation is written in Texinfo format, which is
37376 a documentation system that uses a single source file to produce both
37377 on-line information and a printed manual. You can use one of the Info
37378 formatting commands to create the on-line version of the documentation
37379 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
37380
37381 @value{GDBN} includes an already formatted copy of the on-line Info
37382 version of this manual in the @file{gdb} subdirectory. The main Info
37383 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37384 subordinate files matching @samp{gdb.info*} in the same directory. If
37385 necessary, you can print out these files, or read them with any editor;
37386 but they are easier to read using the @code{info} subsystem in @sc{gnu}
37387 Emacs or the standalone @code{info} program, available as part of the
37388 @sc{gnu} Texinfo distribution.
37389
37390 If you want to format these Info files yourself, you need one of the
37391 Info formatting programs, such as @code{texinfo-format-buffer} or
37392 @code{makeinfo}.
37393
37394 If you have @code{makeinfo} installed, and are in the top level
37395 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37396 version @value{GDBVN}), you can make the Info file by typing:
37397
37398 @smallexample
37399 cd gdb
37400 make gdb.info
37401 @end smallexample
37402
37403 If you want to typeset and print copies of this manual, you need @TeX{},
37404 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37405 Texinfo definitions file.
37406
37407 @TeX{} is a typesetting program; it does not print files directly, but
37408 produces output files called @sc{dvi} files. To print a typeset
37409 document, you need a program to print @sc{dvi} files. If your system
37410 has @TeX{} installed, chances are it has such a program. The precise
37411 command to use depends on your system; @kbd{lpr -d} is common; another
37412 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37413 require a file name without any extension or a @samp{.dvi} extension.
37414
37415 @TeX{} also requires a macro definitions file called
37416 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37417 written in Texinfo format. On its own, @TeX{} cannot either read or
37418 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37419 and is located in the @file{gdb-@var{version-number}/texinfo}
37420 directory.
37421
37422 If you have @TeX{} and a @sc{dvi} printer program installed, you can
37423 typeset and print this manual. First switch to the @file{gdb}
37424 subdirectory of the main source directory (for example, to
37425 @file{gdb-@value{GDBVN}/gdb}) and type:
37426
37427 @smallexample
37428 make gdb.dvi
37429 @end smallexample
37430
37431 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
37432
37433 @node Installing GDB
37434 @appendix Installing @value{GDBN}
37435 @cindex installation
37436
37437 @menu
37438 * Requirements:: Requirements for building @value{GDBN}
37439 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
37440 * Separate Objdir:: Compiling @value{GDBN} in another directory
37441 * Config Names:: Specifying names for hosts and targets
37442 * Configure Options:: Summary of options for configure
37443 * System-wide configuration:: Having a system-wide init file
37444 @end menu
37445
37446 @node Requirements
37447 @section Requirements for Building @value{GDBN}
37448 @cindex building @value{GDBN}, requirements for
37449
37450 Building @value{GDBN} requires various tools and packages to be available.
37451 Other packages will be used only if they are found.
37452
37453 @heading Tools/Packages Necessary for Building @value{GDBN}
37454 @table @asis
37455 @item C@t{++}11 compiler
37456 @value{GDBN} is written in C@t{++}11. It should be buildable with any
37457 recent C@t{++}11 compiler, e.g.@: GCC.
37458
37459 @item GNU make
37460 @value{GDBN}'s build system relies on features only found in the GNU
37461 make program. Other variants of @code{make} will not work.
37462 @end table
37463
37464 @heading Tools/Packages Optional for Building @value{GDBN}
37465 @table @asis
37466 @item Expat
37467 @anchor{Expat}
37468 @value{GDBN} can use the Expat XML parsing library. This library may be
37469 included with your operating system distribution; if it is not, you
37470 can get the latest version from @url{http://expat.sourceforge.net}.
37471 The @file{configure} script will search for this library in several
37472 standard locations; if it is installed in an unusual path, you can
37473 use the @option{--with-libexpat-prefix} option to specify its location.
37474
37475 Expat is used for:
37476
37477 @itemize @bullet
37478 @item
37479 Remote protocol memory maps (@pxref{Memory Map Format})
37480 @item
37481 Target descriptions (@pxref{Target Descriptions})
37482 @item
37483 Remote shared library lists (@xref{Library List Format},
37484 or alternatively @pxref{Library List Format for SVR4 Targets})
37485 @item
37486 MS-Windows shared libraries (@pxref{Shared Libraries})
37487 @item
37488 Traceframe info (@pxref{Traceframe Info Format})
37489 @item
37490 Branch trace (@pxref{Branch Trace Format},
37491 @pxref{Branch Trace Configuration Format})
37492 @end itemize
37493
37494 @item Guile
37495 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37496 default, @value{GDBN} will be compiled if the Guile libraries are
37497 installed and are found by @file{configure}. You can use the
37498 @code{--with-guile} option to request Guile, and pass either the Guile
37499 version number or the file name of the relevant @code{pkg-config}
37500 program to choose a particular version of Guile.
37501
37502 @item iconv
37503 @value{GDBN}'s features related to character sets (@pxref{Character
37504 Sets}) require a functioning @code{iconv} implementation. If you are
37505 on a GNU system, then this is provided by the GNU C Library. Some
37506 other systems also provide a working @code{iconv}.
37507
37508 If @value{GDBN} is using the @code{iconv} program which is installed
37509 in a non-standard place, you will need to tell @value{GDBN} where to
37510 find it. This is done with @option{--with-iconv-bin} which specifies
37511 the directory that contains the @code{iconv} program. This program is
37512 run in order to make a list of the available character sets.
37513
37514 On systems without @code{iconv}, you can install GNU Libiconv. If
37515 Libiconv is installed in a standard place, @value{GDBN} will
37516 automatically use it if it is needed. If you have previously
37517 installed Libiconv in a non-standard place, you can use the
37518 @option{--with-libiconv-prefix} option to @file{configure}.
37519
37520 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37521 arrange to build Libiconv if a directory named @file{libiconv} appears
37522 in the top-most source directory. If Libiconv is built this way, and
37523 if the operating system does not provide a suitable @code{iconv}
37524 implementation, then the just-built library will automatically be used
37525 by @value{GDBN}. One easy way to set this up is to download GNU
37526 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37527 source tree, and then rename the directory holding the Libiconv source
37528 code to @samp{libiconv}.
37529
37530 @item lzma
37531 @value{GDBN} can support debugging sections that are compressed with
37532 the LZMA library. @xref{MiniDebugInfo}. If this library is not
37533 included with your operating system, you can find it in the xz package
37534 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37535 the usual place, then the @file{configure} script will use it
37536 automatically. If it is installed in an unusual path, you can use the
37537 @option{--with-lzma-prefix} option to specify its location.
37538
37539 @item MPFR
37540 @anchor{MPFR}
37541 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
37542 library. This library may be included with your operating system
37543 distribution; if it is not, you can get the latest version from
37544 @url{http://www.mpfr.org}. The @file{configure} script will search
37545 for this library in several standard locations; if it is installed
37546 in an unusual path, you can use the @option{--with-libmpfr-prefix}
37547 option to specify its location.
37548
37549 GNU MPFR is used to emulate target floating-point arithmetic during
37550 expression evaluation when the target uses different floating-point
37551 formats than the host. If GNU MPFR it is not available, @value{GDBN}
37552 will fall back to using host floating-point arithmetic.
37553
37554 @item Python
37555 @value{GDBN} can be scripted using Python language. @xref{Python}.
37556 By default, @value{GDBN} will be compiled if the Python libraries are
37557 installed and are found by @file{configure}. You can use the
37558 @code{--with-python} option to request Python, and pass either the
37559 file name of the relevant @code{python} executable, or the name of the
37560 directory in which Python is installed, to choose a particular
37561 installation of Python.
37562
37563 @item zlib
37564 @cindex compressed debug sections
37565 @value{GDBN} will use the @samp{zlib} library, if available, to read
37566 compressed debug sections. Some linkers, such as GNU gold, are capable
37567 of producing binaries with compressed debug sections. If @value{GDBN}
37568 is compiled with @samp{zlib}, it will be able to read the debug
37569 information in such binaries.
37570
37571 The @samp{zlib} library is likely included with your operating system
37572 distribution; if it is not, you can get the latest version from
37573 @url{http://zlib.net}.
37574 @end table
37575
37576 @node Running Configure
37577 @section Invoking the @value{GDBN} @file{configure} Script
37578 @cindex configuring @value{GDBN}
37579 @value{GDBN} comes with a @file{configure} script that automates the process
37580 of preparing @value{GDBN} for installation; you can then use @code{make} to
37581 build the @code{gdb} program.
37582 @iftex
37583 @c irrelevant in info file; it's as current as the code it lives with.
37584 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37585 look at the @file{README} file in the sources; we may have improved the
37586 installation procedures since publishing this manual.}
37587 @end iftex
37588
37589 The @value{GDBN} distribution includes all the source code you need for
37590 @value{GDBN} in a single directory, whose name is usually composed by
37591 appending the version number to @samp{gdb}.
37592
37593 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37594 @file{gdb-@value{GDBVN}} directory. That directory contains:
37595
37596 @table @code
37597 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37598 script for configuring @value{GDBN} and all its supporting libraries
37599
37600 @item gdb-@value{GDBVN}/gdb
37601 the source specific to @value{GDBN} itself
37602
37603 @item gdb-@value{GDBVN}/bfd
37604 source for the Binary File Descriptor library
37605
37606 @item gdb-@value{GDBVN}/include
37607 @sc{gnu} include files
37608
37609 @item gdb-@value{GDBVN}/libiberty
37610 source for the @samp{-liberty} free software library
37611
37612 @item gdb-@value{GDBVN}/opcodes
37613 source for the library of opcode tables and disassemblers
37614
37615 @item gdb-@value{GDBVN}/readline
37616 source for the @sc{gnu} command-line interface
37617 @end table
37618
37619 There may be other subdirectories as well.
37620
37621 The simplest way to configure and build @value{GDBN} is to run @file{configure}
37622 from the @file{gdb-@var{version-number}} source directory, which in
37623 this example is the @file{gdb-@value{GDBVN}} directory.
37624
37625 First switch to the @file{gdb-@var{version-number}} source directory
37626 if you are not already in it; then run @file{configure}. Pass the
37627 identifier for the platform on which @value{GDBN} will run as an
37628 argument.
37629
37630 For example:
37631
37632 @smallexample
37633 cd gdb-@value{GDBVN}
37634 ./configure
37635 make
37636 @end smallexample
37637
37638 Running @samp{configure} and then running @code{make} builds the
37639 included supporting libraries, then @code{gdb} itself. The configured
37640 source files, and the binaries, are left in the corresponding source
37641 directories.
37642
37643 @need 750
37644 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
37645 system does not recognize this automatically when you run a different
37646 shell, you may need to run @code{sh} on it explicitly:
37647
37648 @smallexample
37649 sh configure
37650 @end smallexample
37651
37652 You should run the @file{configure} script from the top directory in the
37653 source tree, the @file{gdb-@var{version-number}} directory. If you run
37654 @file{configure} from one of the subdirectories, you will configure only
37655 that subdirectory. That is usually not what you want. In particular,
37656 if you run the first @file{configure} from the @file{gdb} subdirectory
37657 of the @file{gdb-@var{version-number}} directory, you will omit the
37658 configuration of @file{bfd}, @file{readline}, and other sibling
37659 directories of the @file{gdb} subdirectory. This leads to build errors
37660 about missing include files such as @file{bfd/bfd.h}.
37661
37662 You can install @code{@value{GDBN}} anywhere. The best way to do this
37663 is to pass the @code{--prefix} option to @code{configure}, and then
37664 install it with @code{make install}.
37665
37666 @node Separate Objdir
37667 @section Compiling @value{GDBN} in Another Directory
37668
37669 If you want to run @value{GDBN} versions for several host or target machines,
37670 you need a different @code{gdb} compiled for each combination of
37671 host and target. @file{configure} is designed to make this easy by
37672 allowing you to generate each configuration in a separate subdirectory,
37673 rather than in the source directory. If your @code{make} program
37674 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37675 @code{make} in each of these directories builds the @code{gdb}
37676 program specified there.
37677
37678 To build @code{gdb} in a separate directory, run @file{configure}
37679 with the @samp{--srcdir} option to specify where to find the source.
37680 (You also need to specify a path to find @file{configure}
37681 itself from your working directory. If the path to @file{configure}
37682 would be the same as the argument to @samp{--srcdir}, you can leave out
37683 the @samp{--srcdir} option; it is assumed.)
37684
37685 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37686 separate directory for a Sun 4 like this:
37687
37688 @smallexample
37689 @group
37690 cd gdb-@value{GDBVN}
37691 mkdir ../gdb-sun4
37692 cd ../gdb-sun4
37693 ../gdb-@value{GDBVN}/configure
37694 make
37695 @end group
37696 @end smallexample
37697
37698 When @file{configure} builds a configuration using a remote source
37699 directory, it creates a tree for the binaries with the same structure
37700 (and using the same names) as the tree under the source directory. In
37701 the example, you'd find the Sun 4 library @file{libiberty.a} in the
37702 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37703 @file{gdb-sun4/gdb}.
37704
37705 Make sure that your path to the @file{configure} script has just one
37706 instance of @file{gdb} in it. If your path to @file{configure} looks
37707 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37708 one subdirectory of @value{GDBN}, not the whole package. This leads to
37709 build errors about missing include files such as @file{bfd/bfd.h}.
37710
37711 One popular reason to build several @value{GDBN} configurations in separate
37712 directories is to configure @value{GDBN} for cross-compiling (where
37713 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
37714 programs that run on another machine---the @dfn{target}).
37715 You specify a cross-debugging target by
37716 giving the @samp{--target=@var{target}} option to @file{configure}.
37717
37718 When you run @code{make} to build a program or library, you must run
37719 it in a configured directory---whatever directory you were in when you
37720 called @file{configure} (or one of its subdirectories).
37721
37722 The @code{Makefile} that @file{configure} generates in each source
37723 directory also runs recursively. If you type @code{make} in a source
37724 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37725 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37726 will build all the required libraries, and then build GDB.
37727
37728 When you have multiple hosts or targets configured in separate
37729 directories, you can run @code{make} on them in parallel (for example,
37730 if they are NFS-mounted on each of the hosts); they will not interfere
37731 with each other.
37732
37733 @node Config Names
37734 @section Specifying Names for Hosts and Targets
37735
37736 The specifications used for hosts and targets in the @file{configure}
37737 script are based on a three-part naming scheme, but some short predefined
37738 aliases are also supported. The full naming scheme encodes three pieces
37739 of information in the following pattern:
37740
37741 @smallexample
37742 @var{architecture}-@var{vendor}-@var{os}
37743 @end smallexample
37744
37745 For example, you can use the alias @code{sun4} as a @var{host} argument,
37746 or as the value for @var{target} in a @code{--target=@var{target}}
37747 option. The equivalent full name is @samp{sparc-sun-sunos4}.
37748
37749 The @file{configure} script accompanying @value{GDBN} does not provide
37750 any query facility to list all supported host and target names or
37751 aliases. @file{configure} calls the Bourne shell script
37752 @code{config.sub} to map abbreviations to full names; you can read the
37753 script, if you wish, or you can use it to test your guesses on
37754 abbreviations---for example:
37755
37756 @smallexample
37757 % sh config.sub i386-linux
37758 i386-pc-linux-gnu
37759 % sh config.sub alpha-linux
37760 alpha-unknown-linux-gnu
37761 % sh config.sub hp9k700
37762 hppa1.1-hp-hpux
37763 % sh config.sub sun4
37764 sparc-sun-sunos4.1.1
37765 % sh config.sub sun3
37766 m68k-sun-sunos4.1.1
37767 % sh config.sub i986v
37768 Invalid configuration `i986v': machine `i986v' not recognized
37769 @end smallexample
37770
37771 @noindent
37772 @code{config.sub} is also distributed in the @value{GDBN} source
37773 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
37774
37775 @node Configure Options
37776 @section @file{configure} Options
37777
37778 Here is a summary of the @file{configure} options and arguments that
37779 are most often useful for building @value{GDBN}. @file{configure}
37780 also has several other options not listed here. @inforef{Running
37781 configure scripts,,autoconf.info}, for a full
37782 explanation of @file{configure}.
37783
37784 @smallexample
37785 configure @r{[}--help@r{]}
37786 @r{[}--prefix=@var{dir}@r{]}
37787 @r{[}--exec-prefix=@var{dir}@r{]}
37788 @r{[}--srcdir=@var{dirname}@r{]}
37789 @r{[}--target=@var{target}@r{]}
37790 @end smallexample
37791
37792 @noindent
37793 You may introduce options with a single @samp{-} rather than
37794 @samp{--} if you prefer; but you may abbreviate option names if you use
37795 @samp{--}.
37796
37797 @table @code
37798 @item --help
37799 Display a quick summary of how to invoke @file{configure}.
37800
37801 @item --prefix=@var{dir}
37802 Configure the source to install programs and files under directory
37803 @file{@var{dir}}.
37804
37805 @item --exec-prefix=@var{dir}
37806 Configure the source to install programs under directory
37807 @file{@var{dir}}.
37808
37809 @c avoid splitting the warning from the explanation:
37810 @need 2000
37811 @item --srcdir=@var{dirname}
37812 Use this option to make configurations in directories separate from the
37813 @value{GDBN} source directories. Among other things, you can use this to
37814 build (or maintain) several configurations simultaneously, in separate
37815 directories. @file{configure} writes configuration-specific files in
37816 the current directory, but arranges for them to use the source in the
37817 directory @var{dirname}. @file{configure} creates directories under
37818 the working directory in parallel to the source directories below
37819 @var{dirname}.
37820
37821 @item --target=@var{target}
37822 Configure @value{GDBN} for cross-debugging programs running on the specified
37823 @var{target}. Without this option, @value{GDBN} is configured to debug
37824 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
37825
37826 There is no convenient way to generate a list of all available
37827 targets. Also see the @code{--enable-targets} option, below.
37828 @end table
37829
37830 There are many other options that are specific to @value{GDBN}. This
37831 lists just the most common ones; there are some very specialized
37832 options not described here.
37833
37834 @table @code
37835 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37836 @itemx --enable-targets=all
37837 Configure @value{GDBN} for cross-debugging programs running on the
37838 specified list of targets. The special value @samp{all} configures
37839 @value{GDBN} for debugging programs running on any target it supports.
37840
37841 @item --with-gdb-datadir=@var{path}
37842 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37843 here for certain supporting files or scripts. This defaults to the
37844 @file{gdb} subdirectory of @samp{datadir} (which can be set using
37845 @code{--datadir}).
37846
37847 @item --with-relocated-sources=@var{dir}
37848 Sets up the default source path substitution rule so that directory
37849 names recorded in debug information will be automatically adjusted for
37850 any directory under @var{dir}. @var{dir} should be a subdirectory of
37851 @value{GDBN}'s configured prefix, the one mentioned in the
37852 @code{--prefix} or @code{--exec-prefix} options to configure. This
37853 option is useful if GDB is supposed to be moved to a different place
37854 after it is built.
37855
37856 @item --enable-64-bit-bfd
37857 Enable 64-bit support in BFD on 32-bit hosts.
37858
37859 @item --disable-gdbmi
37860 Build @value{GDBN} without the GDB/MI machine interface
37861 (@pxref{GDB/MI}).
37862
37863 @item --enable-tui
37864 Build @value{GDBN} with the text-mode full-screen user interface
37865 (TUI). Requires a curses library (ncurses and cursesX are also
37866 supported).
37867
37868 @item --with-curses
37869 Use the curses library instead of the termcap library, for text-mode
37870 terminal operations.
37871
37872 @item --with-debuginfod
37873 Build @value{GDBN} with libdebuginfod, the debuginfod client library.
37874 Used to automatically fetch source files and separate debug files from
37875 debuginfod servers using the associated executable's build ID. Enabled
37876 by default if libdebuginfod is installed and found at configure time.
37877 debuginfod is packaged with elfutils, starting with version 0.178. You
37878 can get the latest version from `https://sourceware.org/elfutils/'.
37879
37880 @item --with-libunwind-ia64
37881 Use the libunwind library for unwinding function call stack on ia64
37882 target platforms. See http://www.nongnu.org/libunwind/index.html for
37883 details.
37884
37885 @item --with-system-readline
37886 Use the readline library installed on the host, rather than the
37887 library supplied as part of @value{GDBN}. Readline 7 or newer is
37888 required; this is enforced by the build system.
37889
37890 @item --with-system-zlib
37891 Use the zlib library installed on the host, rather than the library
37892 supplied as part of @value{GDBN}.
37893
37894 @item --with-expat
37895 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
37896 default if libexpat is installed and found at configure time.) This
37897 library is used to read XML files supplied with @value{GDBN}. If it
37898 is unavailable, some features, such as remote protocol memory maps,
37899 target descriptions, and shared library lists, that are based on XML
37900 files, will not be available in @value{GDBN}. If your host does not
37901 have libexpat installed, you can get the latest version from
37902 `http://expat.sourceforge.net'.
37903
37904 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
37905
37906 Build @value{GDBN} with GNU libiconv, a character set encoding
37907 conversion library. This is not done by default, as on GNU systems
37908 the @code{iconv} that is built in to the C library is sufficient. If
37909 your host does not have a working @code{iconv}, you can get the latest
37910 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
37911
37912 @value{GDBN}'s build system also supports building GNU libiconv as
37913 part of the overall build. @xref{Requirements}.
37914
37915 @item --with-lzma
37916 Build @value{GDBN} with LZMA, a compression library. (Done by default
37917 if liblzma is installed and found at configure time.) LZMA is used by
37918 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
37919 platforms using the ELF object file format. If your host does not
37920 have liblzma installed, you can get the latest version from
37921 `https://tukaani.org/xz/'.
37922
37923 @item --with-mpfr
37924 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
37925 floating-point computation with correct rounding. (Done by default if
37926 GNU MPFR is installed and found at configure time.) This library is
37927 used to emulate target floating-point arithmetic during expression
37928 evaluation when the target uses different floating-point formats than
37929 the host. If GNU MPFR is not available, @value{GDBN} will fall back
37930 to using host floating-point arithmetic. If your host does not have
37931 GNU MPFR installed, you can get the latest version from
37932 `http://www.mpfr.org'.
37933
37934 @item --with-python@r{[}=@var{python}@r{]}
37935 Build @value{GDBN} with Python scripting support. (Done by default if
37936 libpython is present and found at configure time.) Python makes
37937 @value{GDBN} scripting much more powerful than the restricted CLI
37938 scripting language. If your host does not have Python installed, you
37939 can find it on `http://www.python.org/download/'. The oldest version
37940 of Python supported by GDB is 2.6. The optional argument @var{python}
37941 is used to find the Python headers and libraries. It can be either
37942 the name of a Python executable, or the name of the directory in which
37943 Python is installed.
37944
37945 @item --with-guile[=GUILE]'
37946 Build @value{GDBN} with GNU Guile scripting support. (Done by default
37947 if libguile is present and found at configure time.) If your host
37948 does not have Guile installed, you can find it at
37949 `https://www.gnu.org/software/guile/'. The optional argument GUILE
37950 can be a version number, which will cause @code{configure} to try to
37951 use that version of Guile; or the file name of a @code{pkg-config}
37952 executable, which will be queried to find the information needed to
37953 compile and link against Guile.
37954
37955 @item --without-included-regex
37956 Don't use the regex library included with @value{GDBN} (as part of the
37957 libiberty library). This is the default on hosts with version 2 of
37958 the GNU C library.
37959
37960 @item --with-sysroot=@var{dir}
37961 Use @var{dir} as the default system root directory for libraries whose
37962 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
37963 @var{dir} can be modified at run time by using the @command{set
37964 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
37965 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
37966 default system root will be automatically adjusted if and when
37967 @value{GDBN} is moved to a different location.
37968
37969 @item --with-system-gdbinit=@var{file}
37970 Configure @value{GDBN} to automatically load a system-wide init file.
37971 @var{file} should be an absolute file name. If @var{file} is in a
37972 directory under the configured prefix, and @value{GDBN} is moved to
37973 another location after being built, the location of the system-wide
37974 init file will be adjusted accordingly.
37975
37976 @item --with-system-gdbinit-dir=@var{directory}
37977 Configure @value{GDBN} to automatically load init files from a
37978 system-wide directory. @var{directory} should be an absolute directory
37979 name. If @var{directory} is in a directory under the configured
37980 prefix, and @value{GDBN} is moved to another location after being
37981 built, the location of the system-wide init directory will be
37982 adjusted accordingly.
37983
37984 @item --enable-build-warnings
37985 When building the @value{GDBN} sources, ask the compiler to warn about
37986 any code which looks even vaguely suspicious. It passes many
37987 different warning flags, depending on the exact version of the
37988 compiler you are using.
37989
37990 @item --enable-werror
37991 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
37992 to the compiler, which will fail the compilation if the compiler
37993 outputs any warning messages.
37994
37995 @item --enable-ubsan
37996 Enable the GCC undefined behavior sanitizer. This is disabled by
37997 default, but passing @code{--enable-ubsan=yes} or
37998 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
37999 undefined behavior sanitizer checks for C@t{++} undefined behavior.
38000 It has a performance cost, so if you are looking at @value{GDBN}'s
38001 performance, you should disable it. The undefined behavior sanitizer
38002 was first introduced in GCC 4.9.
38003 @end table
38004
38005 @node System-wide configuration
38006 @section System-wide configuration and settings
38007 @cindex system-wide init file
38008
38009 @value{GDBN} can be configured to have a system-wide init file and a
38010 system-wide init file directory; this file and files in that directory
38011 (if they have a recognized file extension) will be read and executed at
38012 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38013
38014 Here are the corresponding configure options:
38015
38016 @table @code
38017 @item --with-system-gdbinit=@var{file}
38018 Specify that the default location of the system-wide init file is
38019 @var{file}.
38020 @item --with-system-gdbinit-dir=@var{directory}
38021 Specify that the default location of the system-wide init file directory
38022 is @var{directory}.
38023 @end table
38024
38025 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38026 they may be subject to relocation. Two possible cases:
38027
38028 @itemize @bullet
38029 @item
38030 If the default location of this init file/directory contains @file{$prefix},
38031 it will be subject to relocation. Suppose that the configure options
38032 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38033 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38034 init file is looked for as @file{$install/etc/gdbinit} instead of
38035 @file{$prefix/etc/gdbinit}.
38036
38037 @item
38038 By contrast, if the default location does not contain the prefix,
38039 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38040 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38041 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38042 wherever @value{GDBN} is installed.
38043 @end itemize
38044
38045 If the configured location of the system-wide init file (as given by the
38046 @option{--with-system-gdbinit} option at configure time) is in the
38047 data-directory (as specified by @option{--with-gdb-datadir} at configure
38048 time) or in one of its subdirectories, then @value{GDBN} will look for the
38049 system-wide init file in the directory specified by the
38050 @option{--data-directory} command-line option.
38051 Note that the system-wide init file is only read once, during @value{GDBN}
38052 initialization. If the data-directory is changed after @value{GDBN} has
38053 started with the @code{set data-directory} command, the file will not be
38054 reread.
38055
38056 This applies similarly to the system-wide directory specified in
38057 @option{--with-system-gdbinit-dir}.
38058
38059 Any supported scripting language can be used for these init files, as long
38060 as the file extension matches the scripting language. To be interpreted
38061 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38062 extension.
38063
38064 @menu
38065 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38066 @end menu
38067
38068 @node System-wide Configuration Scripts
38069 @subsection Installed System-wide Configuration Scripts
38070 @cindex system-wide configuration scripts
38071
38072 The @file{system-gdbinit} directory, located inside the data-directory
38073 (as specified by @option{--with-gdb-datadir} at configure time) contains
38074 a number of scripts which can be used as system-wide init files. To
38075 automatically source those scripts at startup, @value{GDBN} should be
38076 configured with @option{--with-system-gdbinit}. Otherwise, any user
38077 should be able to source them by hand as needed.
38078
38079 The following scripts are currently available:
38080 @itemize @bullet
38081
38082 @item @file{elinos.py}
38083 @pindex elinos.py
38084 @cindex ELinOS system-wide configuration script
38085 This script is useful when debugging a program on an ELinOS target.
38086 It takes advantage of the environment variables defined in a standard
38087 ELinOS environment in order to determine the location of the system
38088 shared libraries, and then sets the @samp{solib-absolute-prefix}
38089 and @samp{solib-search-path} variables appropriately.
38090
38091 @item @file{wrs-linux.py}
38092 @pindex wrs-linux.py
38093 @cindex Wind River Linux system-wide configuration script
38094 This script is useful when debugging a program on a target running
38095 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38096 the host-side sysroot used by the target system.
38097
38098 @end itemize
38099
38100 @node Maintenance Commands
38101 @appendix Maintenance Commands
38102 @cindex maintenance commands
38103 @cindex internal commands
38104
38105 In addition to commands intended for @value{GDBN} users, @value{GDBN}
38106 includes a number of commands intended for @value{GDBN} developers,
38107 that are not documented elsewhere in this manual. These commands are
38108 provided here for reference. (For commands that turn on debugging
38109 messages, see @ref{Debugging Output}.)
38110
38111 @table @code
38112 @kindex maint agent
38113 @kindex maint agent-eval
38114 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38115 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38116 Translate the given @var{expression} into remote agent bytecodes.
38117 This command is useful for debugging the Agent Expression mechanism
38118 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38119 expression useful for data collection, such as by tracepoints, while
38120 @samp{maint agent-eval} produces an expression that evaluates directly
38121 to a result. For instance, a collection expression for @code{globa +
38122 globb} will include bytecodes to record four bytes of memory at each
38123 of the addresses of @code{globa} and @code{globb}, while discarding
38124 the result of the addition, while an evaluation expression will do the
38125 addition and return the sum.
38126 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38127 If not, generate remote agent bytecode for current frame PC address.
38128
38129 @kindex maint agent-printf
38130 @item maint agent-printf @var{format},@var{expr},...
38131 Translate the given format string and list of argument expressions
38132 into remote agent bytecodes and display them as a disassembled list.
38133 This command is useful for debugging the agent version of dynamic
38134 printf (@pxref{Dynamic Printf}).
38135
38136 @kindex maint info breakpoints
38137 @item @anchor{maint info breakpoints}maint info breakpoints
38138 Using the same format as @samp{info breakpoints}, display both the
38139 breakpoints you've set explicitly, and those @value{GDBN} is using for
38140 internal purposes. Internal breakpoints are shown with negative
38141 breakpoint numbers. The type column identifies what kind of breakpoint
38142 is shown:
38143
38144 @table @code
38145 @item breakpoint
38146 Normal, explicitly set breakpoint.
38147
38148 @item watchpoint
38149 Normal, explicitly set watchpoint.
38150
38151 @item longjmp
38152 Internal breakpoint, used to handle correctly stepping through
38153 @code{longjmp} calls.
38154
38155 @item longjmp resume
38156 Internal breakpoint at the target of a @code{longjmp}.
38157
38158 @item until
38159 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38160
38161 @item finish
38162 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38163
38164 @item shlib events
38165 Shared library events.
38166
38167 @end table
38168
38169 @kindex maint info btrace
38170 @item maint info btrace
38171 Pint information about raw branch tracing data.
38172
38173 @kindex maint btrace packet-history
38174 @item maint btrace packet-history
38175 Print the raw branch trace packets that are used to compute the
38176 execution history for the @samp{record btrace} command. Both the
38177 information and the format in which it is printed depend on the btrace
38178 recording format.
38179
38180 @table @code
38181 @item bts
38182 For the BTS recording format, print a list of blocks of sequential
38183 code. For each block, the following information is printed:
38184
38185 @table @asis
38186 @item Block number
38187 Newer blocks have higher numbers. The oldest block has number zero.
38188 @item Lowest @samp{PC}
38189 @item Highest @samp{PC}
38190 @end table
38191
38192 @item pt
38193 For the Intel Processor Trace recording format, print a list of
38194 Intel Processor Trace packets. For each packet, the following
38195 information is printed:
38196
38197 @table @asis
38198 @item Packet number
38199 Newer packets have higher numbers. The oldest packet has number zero.
38200 @item Trace offset
38201 The packet's offset in the trace stream.
38202 @item Packet opcode and payload
38203 @end table
38204 @end table
38205
38206 @kindex maint btrace clear-packet-history
38207 @item maint btrace clear-packet-history
38208 Discards the cached packet history printed by the @samp{maint btrace
38209 packet-history} command. The history will be computed again when
38210 needed.
38211
38212 @kindex maint btrace clear
38213 @item maint btrace clear
38214 Discard the branch trace data. The data will be fetched anew and the
38215 branch trace will be recomputed when needed.
38216
38217 This implicitly truncates the branch trace to a single branch trace
38218 buffer. When updating branch trace incrementally, the branch trace
38219 available to @value{GDBN} may be bigger than a single branch trace
38220 buffer.
38221
38222 @kindex maint set btrace pt skip-pad
38223 @item maint set btrace pt skip-pad
38224 @kindex maint show btrace pt skip-pad
38225 @item maint show btrace pt skip-pad
38226 Control whether @value{GDBN} will skip PAD packets when computing the
38227 packet history.
38228
38229 @kindex set displaced-stepping
38230 @kindex show displaced-stepping
38231 @cindex displaced stepping support
38232 @cindex out-of-line single-stepping
38233 @item set displaced-stepping
38234 @itemx show displaced-stepping
38235 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38236 if the target supports it. Displaced stepping is a way to single-step
38237 over breakpoints without removing them from the inferior, by executing
38238 an out-of-line copy of the instruction that was originally at the
38239 breakpoint location. It is also known as out-of-line single-stepping.
38240
38241 @table @code
38242 @item set displaced-stepping on
38243 If the target architecture supports it, @value{GDBN} will use
38244 displaced stepping to step over breakpoints.
38245
38246 @item set displaced-stepping off
38247 @value{GDBN} will not use displaced stepping to step over breakpoints,
38248 even if such is supported by the target architecture.
38249
38250 @cindex non-stop mode, and @samp{set displaced-stepping}
38251 @item set displaced-stepping auto
38252 This is the default mode. @value{GDBN} will use displaced stepping
38253 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38254 architecture supports displaced stepping.
38255 @end table
38256
38257 @kindex maint check-psymtabs
38258 @item maint check-psymtabs
38259 Check the consistency of currently expanded psymtabs versus symtabs.
38260 Use this to check, for example, whether a symbol is in one but not the other.
38261
38262 @kindex maint check-symtabs
38263 @item maint check-symtabs
38264 Check the consistency of currently expanded symtabs.
38265
38266 @kindex maint expand-symtabs
38267 @item maint expand-symtabs [@var{regexp}]
38268 Expand symbol tables.
38269 If @var{regexp} is specified, only expand symbol tables for file
38270 names matching @var{regexp}.
38271
38272 @kindex maint set catch-demangler-crashes
38273 @kindex maint show catch-demangler-crashes
38274 @cindex demangler crashes
38275 @item maint set catch-demangler-crashes [on|off]
38276 @itemx maint show catch-demangler-crashes
38277 Control whether @value{GDBN} should attempt to catch crashes in the
38278 symbol name demangler. The default is to attempt to catch crashes.
38279 If enabled, the first time a crash is caught, a core file is created,
38280 the offending symbol is displayed and the user is presented with the
38281 option to terminate the current session.
38282
38283 @kindex maint cplus first_component
38284 @item maint cplus first_component @var{name}
38285 Print the first C@t{++} class/namespace component of @var{name}.
38286
38287 @kindex maint cplus namespace
38288 @item maint cplus namespace
38289 Print the list of possible C@t{++} namespaces.
38290
38291 @kindex maint deprecate
38292 @kindex maint undeprecate
38293 @cindex deprecated commands
38294 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38295 @itemx maint undeprecate @var{command}
38296 Deprecate or undeprecate the named @var{command}. Deprecated commands
38297 cause @value{GDBN} to issue a warning when you use them. The optional
38298 argument @var{replacement} says which newer command should be used in
38299 favor of the deprecated one; if it is given, @value{GDBN} will mention
38300 the replacement as part of the warning.
38301
38302 @kindex maint dump-me
38303 @item maint dump-me
38304 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38305 Cause a fatal signal in the debugger and force it to dump its core.
38306 This is supported only on systems which support aborting a program
38307 with the @code{SIGQUIT} signal.
38308
38309 @kindex maint internal-error
38310 @kindex maint internal-warning
38311 @kindex maint demangler-warning
38312 @cindex demangler crashes
38313 @item maint internal-error @r{[}@var{message-text}@r{]}
38314 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38315 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38316
38317 Cause @value{GDBN} to call the internal function @code{internal_error},
38318 @code{internal_warning} or @code{demangler_warning} and hence behave
38319 as though an internal problem has been detected. In addition to
38320 reporting the internal problem, these functions give the user the
38321 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38322 and @code{internal_warning}) create a core file of the current
38323 @value{GDBN} session.
38324
38325 These commands take an optional parameter @var{message-text} that is
38326 used as the text of the error or warning message.
38327
38328 Here's an example of using @code{internal-error}:
38329
38330 @smallexample
38331 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38332 @dots{}/maint.c:121: internal-error: testing, 1, 2
38333 A problem internal to GDB has been detected. Further
38334 debugging may prove unreliable.
38335 Quit this debugging session? (y or n) @kbd{n}
38336 Create a core file? (y or n) @kbd{n}
38337 (@value{GDBP})
38338 @end smallexample
38339
38340 @cindex @value{GDBN} internal error
38341 @cindex internal errors, control of @value{GDBN} behavior
38342 @cindex demangler crashes
38343
38344 @kindex maint set internal-error
38345 @kindex maint show internal-error
38346 @kindex maint set internal-warning
38347 @kindex maint show internal-warning
38348 @kindex maint set demangler-warning
38349 @kindex maint show demangler-warning
38350 @item maint set internal-error @var{action} [ask|yes|no]
38351 @itemx maint show internal-error @var{action}
38352 @itemx maint set internal-warning @var{action} [ask|yes|no]
38353 @itemx maint show internal-warning @var{action}
38354 @itemx maint set demangler-warning @var{action} [ask|yes|no]
38355 @itemx maint show demangler-warning @var{action}
38356 When @value{GDBN} reports an internal problem (error or warning) it
38357 gives the user the opportunity to both quit @value{GDBN} and create a
38358 core file of the current @value{GDBN} session. These commands let you
38359 override the default behaviour for each particular @var{action},
38360 described in the table below.
38361
38362 @table @samp
38363 @item quit
38364 You can specify that @value{GDBN} should always (yes) or never (no)
38365 quit. The default is to ask the user what to do.
38366
38367 @item corefile
38368 You can specify that @value{GDBN} should always (yes) or never (no)
38369 create a core file. The default is to ask the user what to do. Note
38370 that there is no @code{corefile} option for @code{demangler-warning}:
38371 demangler warnings always create a core file and this cannot be
38372 disabled.
38373 @end table
38374
38375 @kindex maint packet
38376 @item maint packet @var{text}
38377 If @value{GDBN} is talking to an inferior via the serial protocol,
38378 then this command sends the string @var{text} to the inferior, and
38379 displays the response packet. @value{GDBN} supplies the initial
38380 @samp{$} character, the terminating @samp{#} character, and the
38381 checksum.
38382
38383 @kindex maint print architecture
38384 @item maint print architecture @r{[}@var{file}@r{]}
38385 Print the entire architecture configuration. The optional argument
38386 @var{file} names the file where the output goes.
38387
38388 @kindex maint print c-tdesc @r{[}@var{file}@r{]}
38389 @item maint print c-tdesc
38390 Print the target description (@pxref{Target Descriptions}) as
38391 a C source file. By default, the target description is for the current
38392 target, but if the optional argument @var{file} is provided, that file
38393 is used to produce the description. The @var{file} should be an XML
38394 document, of the form described in @ref{Target Description Format}.
38395 The created source file is built into @value{GDBN} when @value{GDBN} is
38396 built again. This command is used by developers after they add or
38397 modify XML target descriptions.
38398
38399 @kindex maint check xml-descriptions
38400 @item maint check xml-descriptions @var{dir}
38401 Check that the target descriptions dynamically created by @value{GDBN}
38402 equal the descriptions created from XML files found in @var{dir}.
38403
38404 @anchor{maint check libthread-db}
38405 @kindex maint check libthread-db
38406 @item maint check libthread-db
38407 Run integrity checks on the current inferior's thread debugging
38408 library. This exercises all @code{libthread_db} functionality used by
38409 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
38410 @code{proc_service} functions provided by @value{GDBN} that
38411 @code{libthread_db} uses. Note that parts of the test may be skipped
38412 on some platforms when debugging core files.
38413
38414 @kindex maint print dummy-frames
38415 @item maint print dummy-frames
38416 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38417
38418 @smallexample
38419 (@value{GDBP}) @kbd{b add}
38420 @dots{}
38421 (@value{GDBP}) @kbd{print add(2,3)}
38422 Breakpoint 2, add (a=2, b=3) at @dots{}
38423 58 return (a + b);
38424 The program being debugged stopped while in a function called from GDB.
38425 @dots{}
38426 (@value{GDBP}) @kbd{maint print dummy-frames}
38427 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
38428 (@value{GDBP})
38429 @end smallexample
38430
38431 Takes an optional file parameter.
38432
38433 @kindex maint print registers
38434 @kindex maint print raw-registers
38435 @kindex maint print cooked-registers
38436 @kindex maint print register-groups
38437 @kindex maint print remote-registers
38438 @item maint print registers @r{[}@var{file}@r{]}
38439 @itemx maint print raw-registers @r{[}@var{file}@r{]}
38440 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
38441 @itemx maint print register-groups @r{[}@var{file}@r{]}
38442 @itemx maint print remote-registers @r{[}@var{file}@r{]}
38443 Print @value{GDBN}'s internal register data structures.
38444
38445 The command @code{maint print raw-registers} includes the contents of
38446 the raw register cache; the command @code{maint print
38447 cooked-registers} includes the (cooked) value of all registers,
38448 including registers which aren't available on the target nor visible
38449 to user; the command @code{maint print register-groups} includes the
38450 groups that each register is a member of; and the command @code{maint
38451 print remote-registers} includes the remote target's register numbers
38452 and offsets in the `G' packets.
38453
38454 These commands take an optional parameter, a file name to which to
38455 write the information.
38456
38457 @kindex maint print reggroups
38458 @item maint print reggroups @r{[}@var{file}@r{]}
38459 Print @value{GDBN}'s internal register group data structures. The
38460 optional argument @var{file} tells to what file to write the
38461 information.
38462
38463 The register groups info looks like this:
38464
38465 @smallexample
38466 (@value{GDBP}) @kbd{maint print reggroups}
38467 Group Type
38468 general user
38469 float user
38470 all user
38471 vector user
38472 system user
38473 save internal
38474 restore internal
38475 @end smallexample
38476
38477 @kindex flushregs
38478 @item flushregs
38479 This command forces @value{GDBN} to flush its internal register cache.
38480
38481 @kindex maint print objfiles
38482 @cindex info for known object files
38483 @item maint print objfiles @r{[}@var{regexp}@r{]}
38484 Print a dump of all known object files.
38485 If @var{regexp} is specified, only print object files whose names
38486 match @var{regexp}. For each object file, this command prints its name,
38487 address in memory, and all of its psymtabs and symtabs.
38488
38489 @kindex maint print user-registers
38490 @cindex user registers
38491 @item maint print user-registers
38492 List all currently available @dfn{user registers}. User registers
38493 typically provide alternate names for actual hardware registers. They
38494 include the four ``standard'' registers @code{$fp}, @code{$pc},
38495 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
38496 registers can be used in expressions in the same way as the canonical
38497 register names, but only the latter are listed by the @code{info
38498 registers} and @code{maint print registers} commands.
38499
38500 @kindex maint print section-scripts
38501 @cindex info for known .debug_gdb_scripts-loaded scripts
38502 @item maint print section-scripts [@var{regexp}]
38503 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38504 If @var{regexp} is specified, only print scripts loaded by object files
38505 matching @var{regexp}.
38506 For each script, this command prints its name as specified in the objfile,
38507 and the full path if known.
38508 @xref{dotdebug_gdb_scripts section}.
38509
38510 @kindex maint print statistics
38511 @cindex bcache statistics
38512 @item maint print statistics
38513 This command prints, for each object file in the program, various data
38514 about that object file followed by the byte cache (@dfn{bcache})
38515 statistics for the object file. The objfile data includes the number
38516 of minimal, partial, full, and stabs symbols, the number of types
38517 defined by the objfile, the number of as yet unexpanded psym tables,
38518 the number of line tables and string tables, and the amount of memory
38519 used by the various tables. The bcache statistics include the counts,
38520 sizes, and counts of duplicates of all and unique objects, max,
38521 average, and median entry size, total memory used and its overhead and
38522 savings, and various measures of the hash table size and chain
38523 lengths.
38524
38525 @kindex maint print target-stack
38526 @cindex target stack description
38527 @item maint print target-stack
38528 A @dfn{target} is an interface between the debugger and a particular
38529 kind of file or process. Targets can be stacked in @dfn{strata},
38530 so that more than one target can potentially respond to a request.
38531 In particular, memory accesses will walk down the stack of targets
38532 until they find a target that is interested in handling that particular
38533 address.
38534
38535 This command prints a short description of each layer that was pushed on
38536 the @dfn{target stack}, starting from the top layer down to the bottom one.
38537
38538 @kindex maint print type
38539 @cindex type chain of a data type
38540 @item maint print type @var{expr}
38541 Print the type chain for a type specified by @var{expr}. The argument
38542 can be either a type name or a symbol. If it is a symbol, the type of
38543 that symbol is described. The type chain produced by this command is
38544 a recursive definition of the data type as stored in @value{GDBN}'s
38545 data structures, including its flags and contained types.
38546
38547 @kindex maint selftest
38548 @cindex self tests
38549 @item maint selftest @r{[}@var{filter}@r{]}
38550 Run any self tests that were compiled in to @value{GDBN}. This will
38551 print a message showing how many tests were run, and how many failed.
38552 If a @var{filter} is passed, only the tests with @var{filter} in their
38553 name will by ran.
38554
38555 @kindex maint info selftests
38556 @cindex self tests
38557 @item maint info selftests
38558 List the selftests compiled in to @value{GDBN}.
38559
38560 @kindex maint set dwarf always-disassemble
38561 @kindex maint show dwarf always-disassemble
38562 @item maint set dwarf always-disassemble
38563 @item maint show dwarf always-disassemble
38564 Control the behavior of @code{info address} when using DWARF debugging
38565 information.
38566
38567 The default is @code{off}, which means that @value{GDBN} should try to
38568 describe a variable's location in an easily readable format. When
38569 @code{on}, @value{GDBN} will instead display the DWARF location
38570 expression in an assembly-like format. Note that some locations are
38571 too complex for @value{GDBN} to describe simply; in this case you will
38572 always see the disassembly form.
38573
38574 Here is an example of the resulting disassembly:
38575
38576 @smallexample
38577 (gdb) info addr argc
38578 Symbol "argc" is a complex DWARF expression:
38579 1: DW_OP_fbreg 0
38580 @end smallexample
38581
38582 For more information on these expressions, see
38583 @uref{http://www.dwarfstd.org/, the DWARF standard}.
38584
38585 @kindex maint set dwarf max-cache-age
38586 @kindex maint show dwarf max-cache-age
38587 @item maint set dwarf max-cache-age
38588 @itemx maint show dwarf max-cache-age
38589 Control the DWARF compilation unit cache.
38590
38591 @cindex DWARF compilation units cache
38592 In object files with inter-compilation-unit references, such as those
38593 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
38594 reader needs to frequently refer to previously read compilation units.
38595 This setting controls how long a compilation unit will remain in the
38596 cache if it is not referenced. A higher limit means that cached
38597 compilation units will be stored in memory longer, and more total
38598 memory will be used. Setting it to zero disables caching, which will
38599 slow down @value{GDBN} startup, but reduce memory consumption.
38600
38601 @kindex maint set dwarf unwinders
38602 @kindex maint show dwarf unwinders
38603 @item maint set dwarf unwinders
38604 @itemx maint show dwarf unwinders
38605 Control use of the DWARF frame unwinders.
38606
38607 @cindex DWARF frame unwinders
38608 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38609 frame unwinders to build the backtrace. Many of these targets will
38610 also have a second mechanism for building the backtrace for use in
38611 cases where DWARF information is not available, this second mechanism
38612 is often an analysis of a function's prologue.
38613
38614 In order to extend testing coverage of the second level stack
38615 unwinding mechanisms it is helpful to be able to disable the DWARF
38616 stack unwinders, this can be done with this switch.
38617
38618 In normal use of @value{GDBN} disabling the DWARF unwinders is not
38619 advisable, there are cases that are better handled through DWARF than
38620 prologue analysis, and the debug experience is likely to be better
38621 with the DWARF frame unwinders enabled.
38622
38623 If DWARF frame unwinders are not supported for a particular target
38624 architecture, then enabling this flag does not cause them to be used.
38625
38626 @kindex maint set worker-threads
38627 @kindex maint show worker-threads
38628 @item maint set worker-threads
38629 @item maint show worker-threads
38630 Control the number of worker threads that may be used by @value{GDBN}.
38631 On capable hosts, @value{GDBN} may use multiple threads to speed up
38632 certain CPU-intensive operations, such as demangling symbol names.
38633 While the number of threads used by @value{GDBN} may vary, this
38634 command can be used to set an upper bound on this number. The default
38635 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38636 number. Note that this only controls worker threads started by
38637 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
38638 of their own.
38639
38640 @kindex maint set profile
38641 @kindex maint show profile
38642 @cindex profiling GDB
38643 @item maint set profile
38644 @itemx maint show profile
38645 Control profiling of @value{GDBN}.
38646
38647 Profiling will be disabled until you use the @samp{maint set profile}
38648 command to enable it. When you enable profiling, the system will begin
38649 collecting timing and execution count data; when you disable profiling or
38650 exit @value{GDBN}, the results will be written to a log file. Remember that
38651 if you use profiling, @value{GDBN} will overwrite the profiling log file
38652 (often called @file{gmon.out}). If you have a record of important profiling
38653 data in a @file{gmon.out} file, be sure to move it to a safe location.
38654
38655 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
38656 compiled with the @samp{-pg} compiler option.
38657
38658 @kindex maint set show-debug-regs
38659 @kindex maint show show-debug-regs
38660 @cindex hardware debug registers
38661 @item maint set show-debug-regs
38662 @itemx maint show show-debug-regs
38663 Control whether to show variables that mirror the hardware debug
38664 registers. Use @code{on} to enable, @code{off} to disable. If
38665 enabled, the debug registers values are shown when @value{GDBN} inserts or
38666 removes a hardware breakpoint or watchpoint, and when the inferior
38667 triggers a hardware-assisted breakpoint or watchpoint.
38668
38669 @kindex maint set show-all-tib
38670 @kindex maint show show-all-tib
38671 @item maint set show-all-tib
38672 @itemx maint show show-all-tib
38673 Control whether to show all non zero areas within a 1k block starting
38674 at thread local base, when using the @samp{info w32 thread-information-block}
38675 command.
38676
38677 @kindex maint set target-async
38678 @kindex maint show target-async
38679 @item maint set target-async
38680 @itemx maint show target-async
38681 This controls whether @value{GDBN} targets operate in synchronous or
38682 asynchronous mode (@pxref{Background Execution}). Normally the
38683 default is asynchronous, if it is available; but this can be changed
38684 to more easily debug problems occurring only in synchronous mode.
38685
38686 @kindex maint set target-non-stop @var{mode} [on|off|auto]
38687 @kindex maint show target-non-stop
38688 @item maint set target-non-stop
38689 @itemx maint show target-non-stop
38690
38691 This controls whether @value{GDBN} targets always operate in non-stop
38692 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38693 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38694 if supported by the target.
38695
38696 @table @code
38697 @item maint set target-non-stop auto
38698 This is the default mode. @value{GDBN} controls the target in
38699 non-stop mode if the target supports it.
38700
38701 @item maint set target-non-stop on
38702 @value{GDBN} controls the target in non-stop mode even if the target
38703 does not indicate support.
38704
38705 @item maint set target-non-stop off
38706 @value{GDBN} does not control the target in non-stop mode even if the
38707 target supports it.
38708 @end table
38709
38710 @kindex maint set tui-resize-message
38711 @kindex maint show tui-resize-message
38712 @item maint set tui-resize-message
38713 @item maint show tui-resize-message
38714 Control whether @value{GDBN} displays a message each time the terminal
38715 is resized when in TUI mode. The default is @code{off}, which means
38716 that @value{GDBN} is silent during resizes. When @code{on},
38717 @value{GDBN} will display a message after a resize is completed; the
38718 message will include a number indicating how many times the terminal
38719 has been resized. This setting is intended for use by the test suite,
38720 where it would otherwise be difficult to determine when a resize and
38721 refresh has been completed.
38722
38723 @kindex maint set per-command
38724 @kindex maint show per-command
38725 @item maint set per-command
38726 @itemx maint show per-command
38727 @cindex resources used by commands
38728
38729 @value{GDBN} can display the resources used by each command.
38730 This is useful in debugging performance problems.
38731
38732 @table @code
38733 @item maint set per-command space [on|off]
38734 @itemx maint show per-command space
38735 Enable or disable the printing of the memory used by GDB for each command.
38736 If enabled, @value{GDBN} will display how much memory each command
38737 took, following the command's own output.
38738 This can also be requested by invoking @value{GDBN} with the
38739 @option{--statistics} command-line switch (@pxref{Mode Options}).
38740
38741 @item maint set per-command time [on|off]
38742 @itemx maint show per-command time
38743 Enable or disable the printing of the execution time of @value{GDBN}
38744 for each command.
38745 If enabled, @value{GDBN} will display how much time it
38746 took to execute each command, following the command's own output.
38747 Both CPU time and wallclock time are printed.
38748 Printing both is useful when trying to determine whether the cost is
38749 CPU or, e.g., disk/network latency.
38750 Note that the CPU time printed is for @value{GDBN} only, it does not include
38751 the execution time of the inferior because there's no mechanism currently
38752 to compute how much time was spent by @value{GDBN} and how much time was
38753 spent by the program been debugged.
38754 This can also be requested by invoking @value{GDBN} with the
38755 @option{--statistics} command-line switch (@pxref{Mode Options}).
38756
38757 @item maint set per-command symtab [on|off]
38758 @itemx maint show per-command symtab
38759 Enable or disable the printing of basic symbol table statistics
38760 for each command.
38761 If enabled, @value{GDBN} will display the following information:
38762
38763 @enumerate a
38764 @item
38765 number of symbol tables
38766 @item
38767 number of primary symbol tables
38768 @item
38769 number of blocks in the blockvector
38770 @end enumerate
38771 @end table
38772
38773 @kindex maint set check-libthread-db
38774 @kindex maint show check-libthread-db
38775 @item maint set check-libthread-db [on|off]
38776 @itemx maint show check-libthread-db
38777 Control whether @value{GDBN} should run integrity checks on inferior
38778 specific thread debugging libraries as they are loaded. The default
38779 is not to perform such checks. If any check fails @value{GDBN} will
38780 unload the library and continue searching for a suitable candidate as
38781 described in @ref{set libthread-db-search-path}. For more information
38782 about the tests, see @ref{maint check libthread-db}.
38783
38784 @kindex maint space
38785 @cindex memory used by commands
38786 @item maint space @var{value}
38787 An alias for @code{maint set per-command space}.
38788 A non-zero value enables it, zero disables it.
38789
38790 @kindex maint time
38791 @cindex time of command execution
38792 @item maint time @var{value}
38793 An alias for @code{maint set per-command time}.
38794 A non-zero value enables it, zero disables it.
38795
38796 @kindex maint translate-address
38797 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38798 Find the symbol stored at the location specified by the address
38799 @var{addr} and an optional section name @var{section}. If found,
38800 @value{GDBN} prints the name of the closest symbol and an offset from
38801 the symbol's location to the specified address. This is similar to
38802 the @code{info address} command (@pxref{Symbols}), except that this
38803 command also allows to find symbols in other sections.
38804
38805 If section was not specified, the section in which the symbol was found
38806 is also printed. For dynamically linked executables, the name of
38807 executable or shared library containing the symbol is printed as well.
38808
38809 @kindex maint test-options
38810 @item maint test-options require-delimiter
38811 @itemx maint test-options unknown-is-error
38812 @itemx maint test-options unknown-is-operand
38813 These commands are used by the testsuite to validate the command
38814 options framework. The @code{require-delimiter} variant requires a
38815 double-dash delimiter to indicate end of options. The
38816 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
38817 @code{unknown-is-error} variant throws an error on unknown option,
38818 while @code{unknown-is-operand} treats unknown options as the start of
38819 the command's operands. When run, the commands output the result of
38820 the processed options. When completed, the commands store the
38821 internal result of completion in a variable exposed by the @code{maint
38822 show test-options-completion-result} command.
38823
38824 @kindex maint show test-options-completion-result
38825 @item maint show test-options-completion-result
38826 Shows the result of completing the @code{maint test-options}
38827 subcommands. This is used by the testsuite to validate completion
38828 support in the command options framework.
38829
38830 @kindex maint set test-settings
38831 @kindex maint show test-settings
38832 @item maint set test-settings @var{kind}
38833 @itemx maint show test-settings @var{kind}
38834 These are representative commands for each @var{kind} of setting type
38835 @value{GDBN} supports. They are used by the testsuite for exercising
38836 the settings infrastructure.
38837
38838 @kindex maint with
38839 @item maint with @var{setting} [@var{value}] [-- @var{command}]
38840 Like the @code{with} command, but works with @code{maintenance set}
38841 variables. This is used by the testsuite to exercise the @code{with}
38842 command's infrastructure.
38843
38844 @end table
38845
38846 The following command is useful for non-interactive invocations of
38847 @value{GDBN}, such as in the test suite.
38848
38849 @table @code
38850 @item set watchdog @var{nsec}
38851 @kindex set watchdog
38852 @cindex watchdog timer
38853 @cindex timeout for commands
38854 Set the maximum number of seconds @value{GDBN} will wait for the
38855 target operation to finish. If this time expires, @value{GDBN}
38856 reports and error and the command is aborted.
38857
38858 @item show watchdog
38859 Show the current setting of the target wait timeout.
38860 @end table
38861
38862 @node Remote Protocol
38863 @appendix @value{GDBN} Remote Serial Protocol
38864
38865 @menu
38866 * Overview::
38867 * Packets::
38868 * Stop Reply Packets::
38869 * General Query Packets::
38870 * Architecture-Specific Protocol Details::
38871 * Tracepoint Packets::
38872 * Host I/O Packets::
38873 * Interrupts::
38874 * Notification Packets::
38875 * Remote Non-Stop::
38876 * Packet Acknowledgment::
38877 * Examples::
38878 * File-I/O Remote Protocol Extension::
38879 * Library List Format::
38880 * Library List Format for SVR4 Targets::
38881 * Memory Map Format::
38882 * Thread List Format::
38883 * Traceframe Info Format::
38884 * Branch Trace Format::
38885 * Branch Trace Configuration Format::
38886 @end menu
38887
38888 @node Overview
38889 @section Overview
38890
38891 There may be occasions when you need to know something about the
38892 protocol---for example, if there is only one serial port to your target
38893 machine, you might want your program to do something special if it
38894 recognizes a packet meant for @value{GDBN}.
38895
38896 In the examples below, @samp{->} and @samp{<-} are used to indicate
38897 transmitted and received data, respectively.
38898
38899 @cindex protocol, @value{GDBN} remote serial
38900 @cindex serial protocol, @value{GDBN} remote
38901 @cindex remote serial protocol
38902 All @value{GDBN} commands and responses (other than acknowledgments
38903 and notifications, see @ref{Notification Packets}) are sent as a
38904 @var{packet}. A @var{packet} is introduced with the character
38905 @samp{$}, the actual @var{packet-data}, and the terminating character
38906 @samp{#} followed by a two-digit @var{checksum}:
38907
38908 @smallexample
38909 @code{$}@var{packet-data}@code{#}@var{checksum}
38910 @end smallexample
38911 @noindent
38912
38913 @cindex checksum, for @value{GDBN} remote
38914 @noindent
38915 The two-digit @var{checksum} is computed as the modulo 256 sum of all
38916 characters between the leading @samp{$} and the trailing @samp{#} (an
38917 eight bit unsigned checksum).
38918
38919 Implementors should note that prior to @value{GDBN} 5.0 the protocol
38920 specification also included an optional two-digit @var{sequence-id}:
38921
38922 @smallexample
38923 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
38924 @end smallexample
38925
38926 @cindex sequence-id, for @value{GDBN} remote
38927 @noindent
38928 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
38929 has never output @var{sequence-id}s. Stubs that handle packets added
38930 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
38931
38932 When either the host or the target machine receives a packet, the first
38933 response expected is an acknowledgment: either @samp{+} (to indicate
38934 the package was received correctly) or @samp{-} (to request
38935 retransmission):
38936
38937 @smallexample
38938 -> @code{$}@var{packet-data}@code{#}@var{checksum}
38939 <- @code{+}
38940 @end smallexample
38941 @noindent
38942
38943 The @samp{+}/@samp{-} acknowledgments can be disabled
38944 once a connection is established.
38945 @xref{Packet Acknowledgment}, for details.
38946
38947 The host (@value{GDBN}) sends @var{command}s, and the target (the
38948 debugging stub incorporated in your program) sends a @var{response}. In
38949 the case of step and continue @var{command}s, the response is only sent
38950 when the operation has completed, and the target has again stopped all
38951 threads in all attached processes. This is the default all-stop mode
38952 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
38953 execution mode; see @ref{Remote Non-Stop}, for details.
38954
38955 @var{packet-data} consists of a sequence of characters with the
38956 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
38957 exceptions).
38958
38959 @cindex remote protocol, field separator
38960 Fields within the packet should be separated using @samp{,} @samp{;} or
38961 @samp{:}. Except where otherwise noted all numbers are represented in
38962 @sc{hex} with leading zeros suppressed.
38963
38964 Implementors should note that prior to @value{GDBN} 5.0, the character
38965 @samp{:} could not appear as the third character in a packet (as it
38966 would potentially conflict with the @var{sequence-id}).
38967
38968 @cindex remote protocol, binary data
38969 @anchor{Binary Data}
38970 Binary data in most packets is encoded either as two hexadecimal
38971 digits per byte of binary data. This allowed the traditional remote
38972 protocol to work over connections which were only seven-bit clean.
38973 Some packets designed more recently assume an eight-bit clean
38974 connection, and use a more efficient encoding to send and receive
38975 binary data.
38976
38977 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
38978 as an escape character. Any escaped byte is transmitted as the escape
38979 character followed by the original character XORed with @code{0x20}.
38980 For example, the byte @code{0x7d} would be transmitted as the two
38981 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
38982 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
38983 @samp{@}}) must always be escaped. Responses sent by the stub
38984 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
38985 is not interpreted as the start of a run-length encoded sequence
38986 (described next).
38987
38988 Response @var{data} can be run-length encoded to save space.
38989 Run-length encoding replaces runs of identical characters with one
38990 instance of the repeated character, followed by a @samp{*} and a
38991 repeat count. The repeat count is itself sent encoded, to avoid
38992 binary characters in @var{data}: a value of @var{n} is sent as
38993 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
38994 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
38995 code 32) for a repeat count of 3. (This is because run-length
38996 encoding starts to win for counts 3 or more.) Thus, for example,
38997 @samp{0* } is a run-length encoding of ``0000'': the space character
38998 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
38999 3}} more times.
39000
39001 The printable characters @samp{#} and @samp{$} or with a numeric value
39002 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39003 seven repeats (@samp{$}) can be expanded using a repeat count of only
39004 five (@samp{"}). For example, @samp{00000000} can be encoded as
39005 @samp{0*"00}.
39006
39007 The error response returned for some packets includes a two character
39008 error number. That number is not well defined.
39009
39010 @cindex empty response, for unsupported packets
39011 For any @var{command} not supported by the stub, an empty response
39012 (@samp{$#00}) should be returned. That way it is possible to extend the
39013 protocol. A newer @value{GDBN} can tell if a packet is supported based
39014 on that response.
39015
39016 At a minimum, a stub is required to support the @samp{g} and @samp{G}
39017 commands for register access, and the @samp{m} and @samp{M} commands
39018 for memory access. Stubs that only control single-threaded targets
39019 can implement run control with the @samp{c} (continue), and @samp{s}
39020 (step) commands. Stubs that support multi-threading targets should
39021 support the @samp{vCont} command. All other commands are optional.
39022
39023 @node Packets
39024 @section Packets
39025
39026 The following table provides a complete list of all currently defined
39027 @var{command}s and their corresponding response @var{data}.
39028 @xref{File-I/O Remote Protocol Extension}, for details about the File
39029 I/O extension of the remote protocol.
39030
39031 Each packet's description has a template showing the packet's overall
39032 syntax, followed by an explanation of the packet's meaning. We
39033 include spaces in some of the templates for clarity; these are not
39034 part of the packet's syntax. No @value{GDBN} packet uses spaces to
39035 separate its components. For example, a template like @samp{foo
39036 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
39037 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39038 @var{baz}. @value{GDBN} does not transmit a space character between the
39039 @samp{foo} and the @var{bar}, or between the @var{bar} and the
39040 @var{baz}.
39041
39042 @cindex @var{thread-id}, in remote protocol
39043 @anchor{thread-id syntax}
39044 Several packets and replies include a @var{thread-id} field to identify
39045 a thread. Normally these are positive numbers with a target-specific
39046 interpretation, formatted as big-endian hex strings. A @var{thread-id}
39047 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39048 pick any thread.
39049
39050 In addition, the remote protocol supports a multiprocess feature in
39051 which the @var{thread-id} syntax is extended to optionally include both
39052 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39053 The @var{pid} (process) and @var{tid} (thread) components each have the
39054 format described above: a positive number with target-specific
39055 interpretation formatted as a big-endian hex string, literal @samp{-1}
39056 to indicate all processes or threads (respectively), or @samp{0} to
39057 indicate an arbitrary process or thread. Specifying just a process, as
39058 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39059 error to specify all processes but a specific thread, such as
39060 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39061 for those packets and replies explicitly documented to include a process
39062 ID, rather than a @var{thread-id}.
39063
39064 The multiprocess @var{thread-id} syntax extensions are only used if both
39065 @value{GDBN} and the stub report support for the @samp{multiprocess}
39066 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39067 more information.
39068
39069 Note that all packet forms beginning with an upper- or lower-case
39070 letter, other than those described here, are reserved for future use.
39071
39072 Here are the packet descriptions.
39073
39074 @table @samp
39075
39076 @item !
39077 @cindex @samp{!} packet
39078 @anchor{extended mode}
39079 Enable extended mode. In extended mode, the remote server is made
39080 persistent. The @samp{R} packet is used to restart the program being
39081 debugged.
39082
39083 Reply:
39084 @table @samp
39085 @item OK
39086 The remote target both supports and has enabled extended mode.
39087 @end table
39088
39089 @item ?
39090 @cindex @samp{?} packet
39091 @anchor{? packet}
39092 Indicate the reason the target halted. The reply is the same as for
39093 step and continue. This packet has a special interpretation when the
39094 target is in non-stop mode; see @ref{Remote Non-Stop}.
39095
39096 Reply:
39097 @xref{Stop Reply Packets}, for the reply specifications.
39098
39099 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
39100 @cindex @samp{A} packet
39101 Initialized @code{argv[]} array passed into program. @var{arglen}
39102 specifies the number of bytes in the hex encoded byte stream
39103 @var{arg}. See @code{gdbserver} for more details.
39104
39105 Reply:
39106 @table @samp
39107 @item OK
39108 The arguments were set.
39109 @item E @var{NN}
39110 An error occurred.
39111 @end table
39112
39113 @item b @var{baud}
39114 @cindex @samp{b} packet
39115 (Don't use this packet; its behavior is not well-defined.)
39116 Change the serial line speed to @var{baud}.
39117
39118 JTC: @emph{When does the transport layer state change? When it's
39119 received, or after the ACK is transmitted. In either case, there are
39120 problems if the command or the acknowledgment packet is dropped.}
39121
39122 Stan: @emph{If people really wanted to add something like this, and get
39123 it working for the first time, they ought to modify ser-unix.c to send
39124 some kind of out-of-band message to a specially-setup stub and have the
39125 switch happen "in between" packets, so that from remote protocol's point
39126 of view, nothing actually happened.}
39127
39128 @item B @var{addr},@var{mode}
39129 @cindex @samp{B} packet
39130 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39131 breakpoint at @var{addr}.
39132
39133 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39134 (@pxref{insert breakpoint or watchpoint packet}).
39135
39136 @cindex @samp{bc} packet
39137 @anchor{bc}
39138 @item bc
39139 Backward continue. Execute the target system in reverse. No parameter.
39140 @xref{Reverse Execution}, for more information.
39141
39142 Reply:
39143 @xref{Stop Reply Packets}, for the reply specifications.
39144
39145 @cindex @samp{bs} packet
39146 @anchor{bs}
39147 @item bs
39148 Backward single step. Execute one instruction in reverse. No parameter.
39149 @xref{Reverse Execution}, for more information.
39150
39151 Reply:
39152 @xref{Stop Reply Packets}, for the reply specifications.
39153
39154 @item c @r{[}@var{addr}@r{]}
39155 @cindex @samp{c} packet
39156 Continue at @var{addr}, which is the address to resume. If @var{addr}
39157 is omitted, resume at current address.
39158
39159 This packet is deprecated for multi-threading support. @xref{vCont
39160 packet}.
39161
39162 Reply:
39163 @xref{Stop Reply Packets}, for the reply specifications.
39164
39165 @item C @var{sig}@r{[};@var{addr}@r{]}
39166 @cindex @samp{C} packet
39167 Continue with signal @var{sig} (hex signal number). If
39168 @samp{;@var{addr}} is omitted, resume at same address.
39169
39170 This packet is deprecated for multi-threading support. @xref{vCont
39171 packet}.
39172
39173 Reply:
39174 @xref{Stop Reply Packets}, for the reply specifications.
39175
39176 @item d
39177 @cindex @samp{d} packet
39178 Toggle debug flag.
39179
39180 Don't use this packet; instead, define a general set packet
39181 (@pxref{General Query Packets}).
39182
39183 @item D
39184 @itemx D;@var{pid}
39185 @cindex @samp{D} packet
39186 The first form of the packet is used to detach @value{GDBN} from the
39187 remote system. It is sent to the remote target
39188 before @value{GDBN} disconnects via the @code{detach} command.
39189
39190 The second form, including a process ID, is used when multiprocess
39191 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39192 detach only a specific process. The @var{pid} is specified as a
39193 big-endian hex string.
39194
39195 Reply:
39196 @table @samp
39197 @item OK
39198 for success
39199 @item E @var{NN}
39200 for an error
39201 @end table
39202
39203 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39204 @cindex @samp{F} packet
39205 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39206 This is part of the File-I/O protocol extension. @xref{File-I/O
39207 Remote Protocol Extension}, for the specification.
39208
39209 @item g
39210 @anchor{read registers packet}
39211 @cindex @samp{g} packet
39212 Read general registers.
39213
39214 Reply:
39215 @table @samp
39216 @item @var{XX@dots{}}
39217 Each byte of register data is described by two hex digits. The bytes
39218 with the register are transmitted in target byte order. The size of
39219 each register and their position within the @samp{g} packet are
39220 determined by the @value{GDBN} internal gdbarch functions
39221 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39222
39223 When reading registers from a trace frame (@pxref{Analyze Collected
39224 Data,,Using the Collected Data}), the stub may also return a string of
39225 literal @samp{x}'s in place of the register data digits, to indicate
39226 that the corresponding register has not been collected, thus its value
39227 is unavailable. For example, for an architecture with 4 registers of
39228 4 bytes each, the following reply indicates to @value{GDBN} that
39229 registers 0 and 2 have not been collected, while registers 1 and 3
39230 have been collected, and both have zero value:
39231
39232 @smallexample
39233 -> @code{g}
39234 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39235 @end smallexample
39236
39237 @item E @var{NN}
39238 for an error.
39239 @end table
39240
39241 @item G @var{XX@dots{}}
39242 @cindex @samp{G} packet
39243 Write general registers. @xref{read registers packet}, for a
39244 description of the @var{XX@dots{}} data.
39245
39246 Reply:
39247 @table @samp
39248 @item OK
39249 for success
39250 @item E @var{NN}
39251 for an error
39252 @end table
39253
39254 @item H @var{op} @var{thread-id}
39255 @cindex @samp{H} packet
39256 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39257 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39258 should be @samp{c} for step and continue operations (note that this
39259 is deprecated, supporting the @samp{vCont} command is a better
39260 option), and @samp{g} for other operations. The thread designator
39261 @var{thread-id} has the format and interpretation described in
39262 @ref{thread-id syntax}.
39263
39264 Reply:
39265 @table @samp
39266 @item OK
39267 for success
39268 @item E @var{NN}
39269 for an error
39270 @end table
39271
39272 @c FIXME: JTC:
39273 @c 'H': How restrictive (or permissive) is the thread model. If a
39274 @c thread is selected and stopped, are other threads allowed
39275 @c to continue to execute? As I mentioned above, I think the
39276 @c semantics of each command when a thread is selected must be
39277 @c described. For example:
39278 @c
39279 @c 'g': If the stub supports threads and a specific thread is
39280 @c selected, returns the register block from that thread;
39281 @c otherwise returns current registers.
39282 @c
39283 @c 'G' If the stub supports threads and a specific thread is
39284 @c selected, sets the registers of the register block of
39285 @c that thread; otherwise sets current registers.
39286
39287 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39288 @anchor{cycle step packet}
39289 @cindex @samp{i} packet
39290 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39291 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39292 step starting at that address.
39293
39294 @item I
39295 @cindex @samp{I} packet
39296 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39297 step packet}.
39298
39299 @item k
39300 @cindex @samp{k} packet
39301 Kill request.
39302
39303 The exact effect of this packet is not specified.
39304
39305 For a bare-metal target, it may power cycle or reset the target
39306 system. For that reason, the @samp{k} packet has no reply.
39307
39308 For a single-process target, it may kill that process if possible.
39309
39310 A multiple-process target may choose to kill just one process, or all
39311 that are under @value{GDBN}'s control. For more precise control, use
39312 the vKill packet (@pxref{vKill packet}).
39313
39314 If the target system immediately closes the connection in response to
39315 @samp{k}, @value{GDBN} does not consider the lack of packet
39316 acknowledgment to be an error, and assumes the kill was successful.
39317
39318 If connected using @kbd{target extended-remote}, and the target does
39319 not close the connection in response to a kill request, @value{GDBN}
39320 probes the target state as if a new connection was opened
39321 (@pxref{? packet}).
39322
39323 @item m @var{addr},@var{length}
39324 @cindex @samp{m} packet
39325 Read @var{length} addressable memory units starting at address @var{addr}
39326 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39327 any particular boundary.
39328
39329 The stub need not use any particular size or alignment when gathering
39330 data from memory for the response; even if @var{addr} is word-aligned
39331 and @var{length} is a multiple of the word size, the stub is free to
39332 use byte accesses, or not. For this reason, this packet may not be
39333 suitable for accessing memory-mapped I/O devices.
39334 @cindex alignment of remote memory accesses
39335 @cindex size of remote memory accesses
39336 @cindex memory, alignment and size of remote accesses
39337
39338 Reply:
39339 @table @samp
39340 @item @var{XX@dots{}}
39341 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39342 The reply may contain fewer addressable memory units than requested if the
39343 server was able to read only part of the region of memory.
39344 @item E @var{NN}
39345 @var{NN} is errno
39346 @end table
39347
39348 @item M @var{addr},@var{length}:@var{XX@dots{}}
39349 @cindex @samp{M} packet
39350 Write @var{length} addressable memory units starting at address @var{addr}
39351 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39352 byte is transmitted as a two-digit hexadecimal number.
39353
39354 Reply:
39355 @table @samp
39356 @item OK
39357 for success
39358 @item E @var{NN}
39359 for an error (this includes the case where only part of the data was
39360 written).
39361 @end table
39362
39363 @item p @var{n}
39364 @cindex @samp{p} packet
39365 Read the value of register @var{n}; @var{n} is in hex.
39366 @xref{read registers packet}, for a description of how the returned
39367 register value is encoded.
39368
39369 Reply:
39370 @table @samp
39371 @item @var{XX@dots{}}
39372 the register's value
39373 @item E @var{NN}
39374 for an error
39375 @item @w{}
39376 Indicating an unrecognized @var{query}.
39377 @end table
39378
39379 @item P @var{n@dots{}}=@var{r@dots{}}
39380 @anchor{write register packet}
39381 @cindex @samp{P} packet
39382 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
39383 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
39384 digits for each byte in the register (target byte order).
39385
39386 Reply:
39387 @table @samp
39388 @item OK
39389 for success
39390 @item E @var{NN}
39391 for an error
39392 @end table
39393
39394 @item q @var{name} @var{params}@dots{}
39395 @itemx Q @var{name} @var{params}@dots{}
39396 @cindex @samp{q} packet
39397 @cindex @samp{Q} packet
39398 General query (@samp{q}) and set (@samp{Q}). These packets are
39399 described fully in @ref{General Query Packets}.
39400
39401 @item r
39402 @cindex @samp{r} packet
39403 Reset the entire system.
39404
39405 Don't use this packet; use the @samp{R} packet instead.
39406
39407 @item R @var{XX}
39408 @cindex @samp{R} packet
39409 Restart the program being debugged. The @var{XX}, while needed, is ignored.
39410 This packet is only available in extended mode (@pxref{extended mode}).
39411
39412 The @samp{R} packet has no reply.
39413
39414 @item s @r{[}@var{addr}@r{]}
39415 @cindex @samp{s} packet
39416 Single step, resuming at @var{addr}. If
39417 @var{addr} is omitted, resume at same address.
39418
39419 This packet is deprecated for multi-threading support. @xref{vCont
39420 packet}.
39421
39422 Reply:
39423 @xref{Stop Reply Packets}, for the reply specifications.
39424
39425 @item S @var{sig}@r{[};@var{addr}@r{]}
39426 @anchor{step with signal packet}
39427 @cindex @samp{S} packet
39428 Step with signal. This is analogous to the @samp{C} packet, but
39429 requests a single-step, rather than a normal resumption of execution.
39430
39431 This packet is deprecated for multi-threading support. @xref{vCont
39432 packet}.
39433
39434 Reply:
39435 @xref{Stop Reply Packets}, for the reply specifications.
39436
39437 @item t @var{addr}:@var{PP},@var{MM}
39438 @cindex @samp{t} packet
39439 Search backwards starting at address @var{addr} for a match with pattern
39440 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
39441 There must be at least 3 digits in @var{addr}.
39442
39443 @item T @var{thread-id}
39444 @cindex @samp{T} packet
39445 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
39446
39447 Reply:
39448 @table @samp
39449 @item OK
39450 thread is still alive
39451 @item E @var{NN}
39452 thread is dead
39453 @end table
39454
39455 @item v
39456 Packets starting with @samp{v} are identified by a multi-letter name,
39457 up to the first @samp{;} or @samp{?} (or the end of the packet).
39458
39459 @item vAttach;@var{pid}
39460 @cindex @samp{vAttach} packet
39461 Attach to a new process with the specified process ID @var{pid}.
39462 The process ID is a
39463 hexadecimal integer identifying the process. In all-stop mode, all
39464 threads in the attached process are stopped; in non-stop mode, it may be
39465 attached without being stopped if that is supported by the target.
39466
39467 @c In non-stop mode, on a successful vAttach, the stub should set the
39468 @c current thread to a thread of the newly-attached process. After
39469 @c attaching, GDB queries for the attached process's thread ID with qC.
39470 @c Also note that, from a user perspective, whether or not the
39471 @c target is stopped on attach in non-stop mode depends on whether you
39472 @c use the foreground or background version of the attach command, not
39473 @c on what vAttach does; GDB does the right thing with respect to either
39474 @c stopping or restarting threads.
39475
39476 This packet is only available in extended mode (@pxref{extended mode}).
39477
39478 Reply:
39479 @table @samp
39480 @item E @var{nn}
39481 for an error
39482 @item @r{Any stop packet}
39483 for success in all-stop mode (@pxref{Stop Reply Packets})
39484 @item OK
39485 for success in non-stop mode (@pxref{Remote Non-Stop})
39486 @end table
39487
39488 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
39489 @cindex @samp{vCont} packet
39490 @anchor{vCont packet}
39491 Resume the inferior, specifying different actions for each thread.
39492
39493 For each inferior thread, the leftmost action with a matching
39494 @var{thread-id} is applied. Threads that don't match any action
39495 remain in their current state. Thread IDs are specified using the
39496 syntax described in @ref{thread-id syntax}. If multiprocess
39497 extensions (@pxref{multiprocess extensions}) are supported, actions
39498 can be specified to match all threads in a process by using the
39499 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39500 @var{thread-id} matches all threads. Specifying no actions is an
39501 error.
39502
39503 Currently supported actions are:
39504
39505 @table @samp
39506 @item c
39507 Continue.
39508 @item C @var{sig}
39509 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
39510 @item s
39511 Step.
39512 @item S @var{sig}
39513 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39514 @item t
39515 Stop.
39516 @item r @var{start},@var{end}
39517 Step once, and then keep stepping as long as the thread stops at
39518 addresses between @var{start} (inclusive) and @var{end} (exclusive).
39519 The remote stub reports a stop reply when either the thread goes out
39520 of the range or is stopped due to an unrelated reason, such as hitting
39521 a breakpoint. @xref{range stepping}.
39522
39523 If the range is empty (@var{start} == @var{end}), then the action
39524 becomes equivalent to the @samp{s} action. In other words,
39525 single-step once, and report the stop (even if the stepped instruction
39526 jumps to @var{start}).
39527
39528 (A stop reply may be sent at any point even if the PC is still within
39529 the stepping range; for example, it is valid to implement this packet
39530 in a degenerate way as a single instruction step operation.)
39531
39532 @end table
39533
39534 The optional argument @var{addr} normally associated with the
39535 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
39536 not supported in @samp{vCont}.
39537
39538 The @samp{t} action is only relevant in non-stop mode
39539 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
39540 A stop reply should be generated for any affected thread not already stopped.
39541 When a thread is stopped by means of a @samp{t} action,
39542 the corresponding stop reply should indicate that the thread has stopped with
39543 signal @samp{0}, regardless of whether the target uses some other signal
39544 as an implementation detail.
39545
39546 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39547 @samp{r} actions for threads that are already running. Conversely,
39548 the server must ignore @samp{t} actions for threads that are already
39549 stopped.
39550
39551 @emph{Note:} In non-stop mode, a thread is considered running until
39552 @value{GDBN} acknowledges an asynchronous stop notification for it with
39553 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39554
39555 The stub must support @samp{vCont} if it reports support for
39556 multiprocess extensions (@pxref{multiprocess extensions}).
39557
39558 Reply:
39559 @xref{Stop Reply Packets}, for the reply specifications.
39560
39561 @item vCont?
39562 @cindex @samp{vCont?} packet
39563 Request a list of actions supported by the @samp{vCont} packet.
39564
39565 Reply:
39566 @table @samp
39567 @item vCont@r{[};@var{action}@dots{}@r{]}
39568 The @samp{vCont} packet is supported. Each @var{action} is a supported
39569 command in the @samp{vCont} packet.
39570 @item @w{}
39571 The @samp{vCont} packet is not supported.
39572 @end table
39573
39574 @anchor{vCtrlC packet}
39575 @item vCtrlC
39576 @cindex @samp{vCtrlC} packet
39577 Interrupt remote target as if a control-C was pressed on the remote
39578 terminal. This is the equivalent to reacting to the @code{^C}
39579 (@samp{\003}, the control-C character) character in all-stop mode
39580 while the target is running, except this works in non-stop mode.
39581 @xref{interrupting remote targets}, for more info on the all-stop
39582 variant.
39583
39584 Reply:
39585 @table @samp
39586 @item E @var{nn}
39587 for an error
39588 @item OK
39589 for success
39590 @end table
39591
39592 @item vFile:@var{operation}:@var{parameter}@dots{}
39593 @cindex @samp{vFile} packet
39594 Perform a file operation on the target system. For details,
39595 see @ref{Host I/O Packets}.
39596
39597 @item vFlashErase:@var{addr},@var{length}
39598 @cindex @samp{vFlashErase} packet
39599 Direct the stub to erase @var{length} bytes of flash starting at
39600 @var{addr}. The region may enclose any number of flash blocks, but
39601 its start and end must fall on block boundaries, as indicated by the
39602 flash block size appearing in the memory map (@pxref{Memory Map
39603 Format}). @value{GDBN} groups flash memory programming operations
39604 together, and sends a @samp{vFlashDone} request after each group; the
39605 stub is allowed to delay erase operation until the @samp{vFlashDone}
39606 packet is received.
39607
39608 Reply:
39609 @table @samp
39610 @item OK
39611 for success
39612 @item E @var{NN}
39613 for an error
39614 @end table
39615
39616 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
39617 @cindex @samp{vFlashWrite} packet
39618 Direct the stub to write data to flash address @var{addr}. The data
39619 is passed in binary form using the same encoding as for the @samp{X}
39620 packet (@pxref{Binary Data}). The memory ranges specified by
39621 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39622 not overlap, and must appear in order of increasing addresses
39623 (although @samp{vFlashErase} packets for higher addresses may already
39624 have been received; the ordering is guaranteed only between
39625 @samp{vFlashWrite} packets). If a packet writes to an address that was
39626 neither erased by a preceding @samp{vFlashErase} packet nor by some other
39627 target-specific method, the results are unpredictable.
39628
39629
39630 Reply:
39631 @table @samp
39632 @item OK
39633 for success
39634 @item E.memtype
39635 for vFlashWrite addressing non-flash memory
39636 @item E @var{NN}
39637 for an error
39638 @end table
39639
39640 @item vFlashDone
39641 @cindex @samp{vFlashDone} packet
39642 Indicate to the stub that flash programming operation is finished.
39643 The stub is permitted to delay or batch the effects of a group of
39644 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
39645 @samp{vFlashDone} packet is received. The contents of the affected
39646 regions of flash memory are unpredictable until the @samp{vFlashDone}
39647 request is completed.
39648
39649 @item vKill;@var{pid}
39650 @cindex @samp{vKill} packet
39651 @anchor{vKill packet}
39652 Kill the process with the specified process ID @var{pid}, which is a
39653 hexadecimal integer identifying the process. This packet is used in
39654 preference to @samp{k} when multiprocess protocol extensions are
39655 supported; see @ref{multiprocess extensions}.
39656
39657 Reply:
39658 @table @samp
39659 @item E @var{nn}
39660 for an error
39661 @item OK
39662 for success
39663 @end table
39664
39665 @item vMustReplyEmpty
39666 @cindex @samp{vMustReplyEmpty} packet
39667 The correct reply to an unknown @samp{v} packet is to return the empty
39668 string, however, some older versions of @command{gdbserver} would
39669 incorrectly return @samp{OK} for unknown @samp{v} packets.
39670
39671 The @samp{vMustReplyEmpty} is used as a feature test to check how
39672 @command{gdbserver} handles unknown packets, it is important that this
39673 packet be handled in the same way as other unknown @samp{v} packets.
39674 If this packet is handled differently to other unknown @samp{v}
39675 packets then it is possible that @value{GDBN} may run into problems in
39676 other areas, specifically around use of @samp{vFile:setfs:}.
39677
39678 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39679 @cindex @samp{vRun} packet
39680 Run the program @var{filename}, passing it each @var{argument} on its
39681 command line. The file and arguments are hex-encoded strings. If
39682 @var{filename} is an empty string, the stub may use a default program
39683 (e.g.@: the last program run). The program is created in the stopped
39684 state.
39685
39686 @c FIXME: What about non-stop mode?
39687
39688 This packet is only available in extended mode (@pxref{extended mode}).
39689
39690 Reply:
39691 @table @samp
39692 @item E @var{nn}
39693 for an error
39694 @item @r{Any stop packet}
39695 for success (@pxref{Stop Reply Packets})
39696 @end table
39697
39698 @item vStopped
39699 @cindex @samp{vStopped} packet
39700 @xref{Notification Packets}.
39701
39702 @item X @var{addr},@var{length}:@var{XX@dots{}}
39703 @anchor{X packet}
39704 @cindex @samp{X} packet
39705 Write data to memory, where the data is transmitted in binary.
39706 Memory is specified by its address @var{addr} and number of addressable memory
39707 units @var{length} (@pxref{addressable memory unit});
39708 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
39709
39710 Reply:
39711 @table @samp
39712 @item OK
39713 for success
39714 @item E @var{NN}
39715 for an error
39716 @end table
39717
39718 @item z @var{type},@var{addr},@var{kind}
39719 @itemx Z @var{type},@var{addr},@var{kind}
39720 @anchor{insert breakpoint or watchpoint packet}
39721 @cindex @samp{z} packet
39722 @cindex @samp{Z} packets
39723 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
39724 watchpoint starting at address @var{address} of kind @var{kind}.
39725
39726 Each breakpoint and watchpoint packet @var{type} is documented
39727 separately.
39728
39729 @emph{Implementation notes: A remote target shall return an empty string
39730 for an unrecognized breakpoint or watchpoint packet @var{type}. A
39731 remote target shall support either both or neither of a given
39732 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
39733 avoid potential problems with duplicate packets, the operations should
39734 be implemented in an idempotent way.}
39735
39736 @item z0,@var{addr},@var{kind}
39737 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39738 @cindex @samp{z0} packet
39739 @cindex @samp{Z0} packet
39740 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
39741 @var{addr} of type @var{kind}.
39742
39743 A software breakpoint is implemented by replacing the instruction at
39744 @var{addr} with a software breakpoint or trap instruction. The
39745 @var{kind} is target-specific and typically indicates the size of the
39746 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39747 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39748 architectures have additional meanings for @var{kind}
39749 (@pxref{Architecture-Specific Protocol Details}); if no
39750 architecture-specific value is being used, it should be @samp{0}.
39751 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
39752 conditional expressions in bytecode form that should be evaluated on
39753 the target's side. These are the conditions that should be taken into
39754 consideration when deciding if the breakpoint trigger should be
39755 reported back to @value{GDBN}.
39756
39757 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
39758 for how to best report a software breakpoint event to @value{GDBN}.
39759
39760 The @var{cond_list} parameter is comprised of a series of expressions,
39761 concatenated without separators. Each expression has the following form:
39762
39763 @table @samp
39764
39765 @item X @var{len},@var{expr}
39766 @var{len} is the length of the bytecode expression and @var{expr} is the
39767 actual conditional expression in bytecode form.
39768
39769 @end table
39770
39771 The optional @var{cmd_list} parameter introduces commands that may be
39772 run on the target, rather than being reported back to @value{GDBN}.
39773 The parameter starts with a numeric flag @var{persist}; if the flag is
39774 nonzero, then the breakpoint may remain active and the commands
39775 continue to be run even when @value{GDBN} disconnects from the target.
39776 Following this flag is a series of expressions concatenated with no
39777 separators. Each expression has the following form:
39778
39779 @table @samp
39780
39781 @item X @var{len},@var{expr}
39782 @var{len} is the length of the bytecode expression and @var{expr} is the
39783 actual commands expression in bytecode form.
39784
39785 @end table
39786
39787 @emph{Implementation note: It is possible for a target to copy or move
39788 code that contains software breakpoints (e.g., when implementing
39789 overlays). The behavior of this packet, in the presence of such a
39790 target, is not defined.}
39791
39792 Reply:
39793 @table @samp
39794 @item OK
39795 success
39796 @item @w{}
39797 not supported
39798 @item E @var{NN}
39799 for an error
39800 @end table
39801
39802 @item z1,@var{addr},@var{kind}
39803 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39804 @cindex @samp{z1} packet
39805 @cindex @samp{Z1} packet
39806 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
39807 address @var{addr}.
39808
39809 A hardware breakpoint is implemented using a mechanism that is not
39810 dependent on being able to modify the target's memory. The
39811 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39812 same meaning as in @samp{Z0} packets.
39813
39814 @emph{Implementation note: A hardware breakpoint is not affected by code
39815 movement.}
39816
39817 Reply:
39818 @table @samp
39819 @item OK
39820 success
39821 @item @w{}
39822 not supported
39823 @item E @var{NN}
39824 for an error
39825 @end table
39826
39827 @item z2,@var{addr},@var{kind}
39828 @itemx Z2,@var{addr},@var{kind}
39829 @cindex @samp{z2} packet
39830 @cindex @samp{Z2} packet
39831 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
39832 The number of bytes to watch is specified by @var{kind}.
39833
39834 Reply:
39835 @table @samp
39836 @item OK
39837 success
39838 @item @w{}
39839 not supported
39840 @item E @var{NN}
39841 for an error
39842 @end table
39843
39844 @item z3,@var{addr},@var{kind}
39845 @itemx Z3,@var{addr},@var{kind}
39846 @cindex @samp{z3} packet
39847 @cindex @samp{Z3} packet
39848 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
39849 The number of bytes to watch is specified by @var{kind}.
39850
39851 Reply:
39852 @table @samp
39853 @item OK
39854 success
39855 @item @w{}
39856 not supported
39857 @item E @var{NN}
39858 for an error
39859 @end table
39860
39861 @item z4,@var{addr},@var{kind}
39862 @itemx Z4,@var{addr},@var{kind}
39863 @cindex @samp{z4} packet
39864 @cindex @samp{Z4} packet
39865 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
39866 The number of bytes to watch is specified by @var{kind}.
39867
39868 Reply:
39869 @table @samp
39870 @item OK
39871 success
39872 @item @w{}
39873 not supported
39874 @item E @var{NN}
39875 for an error
39876 @end table
39877
39878 @end table
39879
39880 @node Stop Reply Packets
39881 @section Stop Reply Packets
39882 @cindex stop reply packets
39883
39884 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
39885 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
39886 receive any of the below as a reply. Except for @samp{?}
39887 and @samp{vStopped}, that reply is only returned
39888 when the target halts. In the below the exact meaning of @dfn{signal
39889 number} is defined by the header @file{include/gdb/signals.h} in the
39890 @value{GDBN} source code.
39891
39892 In non-stop mode, the server will simply reply @samp{OK} to commands
39893 such as @samp{vCont}; any stop will be the subject of a future
39894 notification. @xref{Remote Non-Stop}.
39895
39896 As in the description of request packets, we include spaces in the
39897 reply templates for clarity; these are not part of the reply packet's
39898 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
39899 components.
39900
39901 @table @samp
39902
39903 @item S @var{AA}
39904 The program received signal number @var{AA} (a two-digit hexadecimal
39905 number). This is equivalent to a @samp{T} response with no
39906 @var{n}:@var{r} pairs.
39907
39908 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
39909 @cindex @samp{T} packet reply
39910 The program received signal number @var{AA} (a two-digit hexadecimal
39911 number). This is equivalent to an @samp{S} response, except that the
39912 @samp{@var{n}:@var{r}} pairs can carry values of important registers
39913 and other information directly in the stop reply packet, reducing
39914 round-trip latency. Single-step and breakpoint traps are reported
39915 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
39916
39917 @itemize @bullet
39918 @item
39919 If @var{n} is a hexadecimal number, it is a register number, and the
39920 corresponding @var{r} gives that register's value. The data @var{r} is a
39921 series of bytes in target byte order, with each byte given by a
39922 two-digit hex number.
39923
39924 @item
39925 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
39926 the stopped thread, as specified in @ref{thread-id syntax}.
39927
39928 @item
39929 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
39930 the core on which the stop event was detected.
39931
39932 @item
39933 If @var{n} is a recognized @dfn{stop reason}, it describes a more
39934 specific event that stopped the target. The currently defined stop
39935 reasons are listed below. The @var{aa} should be @samp{05}, the trap
39936 signal. At most one stop reason should be present.
39937
39938 @item
39939 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
39940 and go on to the next; this allows us to extend the protocol in the
39941 future.
39942 @end itemize
39943
39944 The currently defined stop reasons are:
39945
39946 @table @samp
39947 @item watch
39948 @itemx rwatch
39949 @itemx awatch
39950 The packet indicates a watchpoint hit, and @var{r} is the data address, in
39951 hex.
39952
39953 @item syscall_entry
39954 @itemx syscall_return
39955 The packet indicates a syscall entry or return, and @var{r} is the
39956 syscall number, in hex.
39957
39958 @cindex shared library events, remote reply
39959 @item library
39960 The packet indicates that the loaded libraries have changed.
39961 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
39962 list of loaded libraries. The @var{r} part is ignored.
39963
39964 @cindex replay log events, remote reply
39965 @item replaylog
39966 The packet indicates that the target cannot continue replaying
39967 logged execution events, because it has reached the end (or the
39968 beginning when executing backward) of the log. The value of @var{r}
39969 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
39970 for more information.
39971
39972 @item swbreak
39973 @anchor{swbreak stop reason}
39974 The packet indicates a software breakpoint instruction was executed,
39975 irrespective of whether it was @value{GDBN} that planted the
39976 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
39977 part must be left empty.
39978
39979 On some architectures, such as x86, at the architecture level, when a
39980 breakpoint instruction executes the program counter points at the
39981 breakpoint address plus an offset. On such targets, the stub is
39982 responsible for adjusting the PC to point back at the breakpoint
39983 address.
39984
39985 This packet should not be sent by default; older @value{GDBN} versions
39986 did not support it. @value{GDBN} requests it, by supplying an
39987 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39988 remote stub must also supply the appropriate @samp{qSupported} feature
39989 indicating support.
39990
39991 This packet is required for correct non-stop mode operation.
39992
39993 @item hwbreak
39994 The packet indicates the target stopped for a hardware breakpoint.
39995 The @var{r} part must be left empty.
39996
39997 The same remarks about @samp{qSupported} and non-stop mode above
39998 apply.
39999
40000 @cindex fork events, remote reply
40001 @item fork
40002 The packet indicates that @code{fork} was called, and @var{r}
40003 is the thread ID of the new child process. Refer to
40004 @ref{thread-id syntax} for the format of the @var{thread-id}
40005 field. This packet is only applicable to targets that support
40006 fork events.
40007
40008 This packet should not be sent by default; older @value{GDBN} versions
40009 did not support it. @value{GDBN} requests it, by supplying an
40010 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40011 remote stub must also supply the appropriate @samp{qSupported} feature
40012 indicating support.
40013
40014 @cindex vfork events, remote reply
40015 @item vfork
40016 The packet indicates that @code{vfork} was called, and @var{r}
40017 is the thread ID of the new child process. Refer to
40018 @ref{thread-id syntax} for the format of the @var{thread-id}
40019 field. This packet is only applicable to targets that support
40020 vfork events.
40021
40022 This packet should not be sent by default; older @value{GDBN} versions
40023 did not support it. @value{GDBN} requests it, by supplying an
40024 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40025 remote stub must also supply the appropriate @samp{qSupported} feature
40026 indicating support.
40027
40028 @cindex vforkdone events, remote reply
40029 @item vforkdone
40030 The packet indicates that a child process created by a vfork
40031 has either called @code{exec} or terminated, so that the
40032 address spaces of the parent and child process are no longer
40033 shared. The @var{r} part is ignored. This packet is only
40034 applicable to targets that support vforkdone events.
40035
40036 This packet should not be sent by default; older @value{GDBN} versions
40037 did not support it. @value{GDBN} requests it, by supplying an
40038 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40039 remote stub must also supply the appropriate @samp{qSupported} feature
40040 indicating support.
40041
40042 @cindex exec events, remote reply
40043 @item exec
40044 The packet indicates that @code{execve} was called, and @var{r}
40045 is the absolute pathname of the file that was executed, in hex.
40046 This packet is only applicable to targets that support exec events.
40047
40048 This packet should not be sent by default; older @value{GDBN} versions
40049 did not support it. @value{GDBN} requests it, by supplying an
40050 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40051 remote stub must also supply the appropriate @samp{qSupported} feature
40052 indicating support.
40053
40054 @cindex thread create event, remote reply
40055 @anchor{thread create event}
40056 @item create
40057 The packet indicates that the thread was just created. The new thread
40058 is stopped until @value{GDBN} sets it running with a resumption packet
40059 (@pxref{vCont packet}). This packet should not be sent by default;
40060 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
40061 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40062 @var{r} part is ignored.
40063
40064 @end table
40065
40066 @item W @var{AA}
40067 @itemx W @var{AA} ; process:@var{pid}
40068 The process exited, and @var{AA} is the exit status. This is only
40069 applicable to certain targets.
40070
40071 The second form of the response, including the process ID of the
40072 exited process, can be used only when @value{GDBN} has reported
40073 support for multiprocess protocol extensions; see @ref{multiprocess
40074 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40075 hex strings.
40076
40077 @item X @var{AA}
40078 @itemx X @var{AA} ; process:@var{pid}
40079 The process terminated with signal @var{AA}.
40080
40081 The second form of the response, including the process ID of the
40082 terminated process, can be used only when @value{GDBN} has reported
40083 support for multiprocess protocol extensions; see @ref{multiprocess
40084 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40085 hex strings.
40086
40087 @anchor{thread exit event}
40088 @cindex thread exit event, remote reply
40089 @item w @var{AA} ; @var{tid}
40090
40091 The thread exited, and @var{AA} is the exit status. This response
40092 should not be sent by default; @value{GDBN} requests it with the
40093 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
40094 @var{AA} is formatted as a big-endian hex string.
40095
40096 @item N
40097 There are no resumed threads left in the target. In other words, even
40098 though the process is alive, the last resumed thread has exited. For
40099 example, say the target process has two threads: thread 1 and thread
40100 2. The client leaves thread 1 stopped, and resumes thread 2, which
40101 subsequently exits. At this point, even though the process is still
40102 alive, and thus no @samp{W} stop reply is sent, no thread is actually
40103 executing either. The @samp{N} stop reply thus informs the client
40104 that it can stop waiting for stop replies. This packet should not be
40105 sent by default; older @value{GDBN} versions did not support it.
40106 @value{GDBN} requests it, by supplying an appropriate
40107 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40108 also supply the appropriate @samp{qSupported} feature indicating
40109 support.
40110
40111 @item O @var{XX}@dots{}
40112 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40113 written as the program's console output. This can happen at any time
40114 while the program is running and the debugger should continue to wait
40115 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40116
40117 @item F @var{call-id},@var{parameter}@dots{}
40118 @var{call-id} is the identifier which says which host system call should
40119 be called. This is just the name of the function. Translation into the
40120 correct system call is only applicable as it's defined in @value{GDBN}.
40121 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40122 system calls.
40123
40124 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40125 this very system call.
40126
40127 The target replies with this packet when it expects @value{GDBN} to
40128 call a host system call on behalf of the target. @value{GDBN} replies
40129 with an appropriate @samp{F} packet and keeps up waiting for the next
40130 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40131 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40132 Protocol Extension}, for more details.
40133
40134 @end table
40135
40136 @node General Query Packets
40137 @section General Query Packets
40138 @cindex remote query requests
40139
40140 Packets starting with @samp{q} are @dfn{general query packets};
40141 packets starting with @samp{Q} are @dfn{general set packets}. General
40142 query and set packets are a semi-unified form for retrieving and
40143 sending information to and from the stub.
40144
40145 The initial letter of a query or set packet is followed by a name
40146 indicating what sort of thing the packet applies to. For example,
40147 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40148 definitions with the stub. These packet names follow some
40149 conventions:
40150
40151 @itemize @bullet
40152 @item
40153 The name must not contain commas, colons or semicolons.
40154 @item
40155 Most @value{GDBN} query and set packets have a leading upper case
40156 letter.
40157 @item
40158 The names of custom vendor packets should use a company prefix, in
40159 lower case, followed by a period. For example, packets designed at
40160 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40161 foos) or @samp{Qacme.bar} (for setting bars).
40162 @end itemize
40163
40164 The name of a query or set packet should be separated from any
40165 parameters by a @samp{:}; the parameters themselves should be
40166 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40167 full packet name, and check for a separator or the end of the packet,
40168 in case two packet names share a common prefix. New packets should not begin
40169 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40170 packets predate these conventions, and have arguments without any terminator
40171 for the packet name; we suspect they are in widespread use in places that
40172 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40173 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40174 packet.}.
40175
40176 Like the descriptions of the other packets, each description here
40177 has a template showing the packet's overall syntax, followed by an
40178 explanation of the packet's meaning. We include spaces in some of the
40179 templates for clarity; these are not part of the packet's syntax. No
40180 @value{GDBN} packet uses spaces to separate its components.
40181
40182 Here are the currently defined query and set packets:
40183
40184 @table @samp
40185
40186 @item QAgent:1
40187 @itemx QAgent:0
40188 Turn on or off the agent as a helper to perform some debugging operations
40189 delegated from @value{GDBN} (@pxref{Control Agent}).
40190
40191 @item QAllow:@var{op}:@var{val}@dots{}
40192 @cindex @samp{QAllow} packet
40193 Specify which operations @value{GDBN} expects to request of the
40194 target, as a semicolon-separated list of operation name and value
40195 pairs. Possible values for @var{op} include @samp{WriteReg},
40196 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40197 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40198 indicating that @value{GDBN} will not request the operation, or 1,
40199 indicating that it may. (The target can then use this to set up its
40200 own internals optimally, for instance if the debugger never expects to
40201 insert breakpoints, it may not need to install its own trap handler.)
40202
40203 @item qC
40204 @cindex current thread, remote request
40205 @cindex @samp{qC} packet
40206 Return the current thread ID.
40207
40208 Reply:
40209 @table @samp
40210 @item QC @var{thread-id}
40211 Where @var{thread-id} is a thread ID as documented in
40212 @ref{thread-id syntax}.
40213 @item @r{(anything else)}
40214 Any other reply implies the old thread ID.
40215 @end table
40216
40217 @item qCRC:@var{addr},@var{length}
40218 @cindex CRC of memory block, remote request
40219 @cindex @samp{qCRC} packet
40220 @anchor{qCRC packet}
40221 Compute the CRC checksum of a block of memory using CRC-32 defined in
40222 IEEE 802.3. The CRC is computed byte at a time, taking the most
40223 significant bit of each byte first. The initial pattern code
40224 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40225
40226 @emph{Note:} This is the same CRC used in validating separate debug
40227 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40228 Files}). However the algorithm is slightly different. When validating
40229 separate debug files, the CRC is computed taking the @emph{least}
40230 significant bit of each byte first, and the final result is inverted to
40231 detect trailing zeros.
40232
40233 Reply:
40234 @table @samp
40235 @item E @var{NN}
40236 An error (such as memory fault)
40237 @item C @var{crc32}
40238 The specified memory region's checksum is @var{crc32}.
40239 @end table
40240
40241 @item QDisableRandomization:@var{value}
40242 @cindex disable address space randomization, remote request
40243 @cindex @samp{QDisableRandomization} packet
40244 Some target operating systems will randomize the virtual address space
40245 of the inferior process as a security feature, but provide a feature
40246 to disable such randomization, e.g.@: to allow for a more deterministic
40247 debugging experience. On such systems, this packet with a @var{value}
40248 of 1 directs the target to disable address space randomization for
40249 processes subsequently started via @samp{vRun} packets, while a packet
40250 with a @var{value} of 0 tells the target to enable address space
40251 randomization.
40252
40253 This packet is only available in extended mode (@pxref{extended mode}).
40254
40255 Reply:
40256 @table @samp
40257 @item OK
40258 The request succeeded.
40259
40260 @item E @var{nn}
40261 An error occurred. The error number @var{nn} is given as hex digits.
40262
40263 @item @w{}
40264 An empty reply indicates that @samp{QDisableRandomization} is not supported
40265 by the stub.
40266 @end table
40267
40268 This packet is not probed by default; the remote stub must request it,
40269 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40270 This should only be done on targets that actually support disabling
40271 address space randomization.
40272
40273 @item QStartupWithShell:@var{value}
40274 @cindex startup with shell, remote request
40275 @cindex @samp{QStartupWithShell} packet
40276 On UNIX-like targets, it is possible to start the inferior using a
40277 shell program. This is the default behavior on both @value{GDBN} and
40278 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40279 used to inform @command{gdbserver} whether it should start the
40280 inferior using a shell or not.
40281
40282 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40283 to start the inferior. If @var{value} is @samp{1},
40284 @command{gdbserver} will use a shell to start the inferior. All other
40285 values are considered an error.
40286
40287 This packet is only available in extended mode (@pxref{extended
40288 mode}).
40289
40290 Reply:
40291 @table @samp
40292 @item OK
40293 The request succeeded.
40294
40295 @item E @var{nn}
40296 An error occurred. The error number @var{nn} is given as hex digits.
40297 @end table
40298
40299 This packet is not probed by default; the remote stub must request it,
40300 by supplying an appropriate @samp{qSupported} response
40301 (@pxref{qSupported}). This should only be done on targets that
40302 actually support starting the inferior using a shell.
40303
40304 Use of this packet is controlled by the @code{set startup-with-shell}
40305 command; @pxref{set startup-with-shell}.
40306
40307 @item QEnvironmentHexEncoded:@var{hex-value}
40308 @anchor{QEnvironmentHexEncoded}
40309 @cindex set environment variable, remote request
40310 @cindex @samp{QEnvironmentHexEncoded} packet
40311 On UNIX-like targets, it is possible to set environment variables that
40312 will be passed to the inferior during the startup process. This
40313 packet is used to inform @command{gdbserver} of an environment
40314 variable that has been defined by the user on @value{GDBN} (@pxref{set
40315 environment}).
40316
40317 The packet is composed by @var{hex-value}, an hex encoded
40318 representation of the @var{name=value} format representing an
40319 environment variable. The name of the environment variable is
40320 represented by @var{name}, and the value to be assigned to the
40321 environment variable is represented by @var{value}. If the variable
40322 has no value (i.e., the value is @code{null}), then @var{value} will
40323 not be present.
40324
40325 This packet is only available in extended mode (@pxref{extended
40326 mode}).
40327
40328 Reply:
40329 @table @samp
40330 @item OK
40331 The request succeeded.
40332 @end table
40333
40334 This packet is not probed by default; the remote stub must request it,
40335 by supplying an appropriate @samp{qSupported} response
40336 (@pxref{qSupported}). This should only be done on targets that
40337 actually support passing environment variables to the starting
40338 inferior.
40339
40340 This packet is related to the @code{set environment} command;
40341 @pxref{set environment}.
40342
40343 @item QEnvironmentUnset:@var{hex-value}
40344 @anchor{QEnvironmentUnset}
40345 @cindex unset environment variable, remote request
40346 @cindex @samp{QEnvironmentUnset} packet
40347 On UNIX-like targets, it is possible to unset environment variables
40348 before starting the inferior in the remote target. This packet is
40349 used to inform @command{gdbserver} of an environment variable that has
40350 been unset by the user on @value{GDBN} (@pxref{unset environment}).
40351
40352 The packet is composed by @var{hex-value}, an hex encoded
40353 representation of the name of the environment variable to be unset.
40354
40355 This packet is only available in extended mode (@pxref{extended
40356 mode}).
40357
40358 Reply:
40359 @table @samp
40360 @item OK
40361 The request succeeded.
40362 @end table
40363
40364 This packet is not probed by default; the remote stub must request it,
40365 by supplying an appropriate @samp{qSupported} response
40366 (@pxref{qSupported}). This should only be done on targets that
40367 actually support passing environment variables to the starting
40368 inferior.
40369
40370 This packet is related to the @code{unset environment} command;
40371 @pxref{unset environment}.
40372
40373 @item QEnvironmentReset
40374 @anchor{QEnvironmentReset}
40375 @cindex reset environment, remote request
40376 @cindex @samp{QEnvironmentReset} packet
40377 On UNIX-like targets, this packet is used to reset the state of
40378 environment variables in the remote target before starting the
40379 inferior. In this context, reset means unsetting all environment
40380 variables that were previously set by the user (i.e., were not
40381 initially present in the environment). It is sent to
40382 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40383 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40384 (@pxref{QEnvironmentUnset}) packets.
40385
40386 This packet is only available in extended mode (@pxref{extended
40387 mode}).
40388
40389 Reply:
40390 @table @samp
40391 @item OK
40392 The request succeeded.
40393 @end table
40394
40395 This packet is not probed by default; the remote stub must request it,
40396 by supplying an appropriate @samp{qSupported} response
40397 (@pxref{qSupported}). This should only be done on targets that
40398 actually support passing environment variables to the starting
40399 inferior.
40400
40401 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
40402 @anchor{QSetWorkingDir packet}
40403 @cindex set working directory, remote request
40404 @cindex @samp{QSetWorkingDir} packet
40405 This packet is used to inform the remote server of the intended
40406 current working directory for programs that are going to be executed.
40407
40408 The packet is composed by @var{directory}, an hex encoded
40409 representation of the directory that the remote inferior will use as
40410 its current working directory. If @var{directory} is an empty string,
40411 the remote server should reset the inferior's current working
40412 directory to its original, empty value.
40413
40414 This packet is only available in extended mode (@pxref{extended
40415 mode}).
40416
40417 Reply:
40418 @table @samp
40419 @item OK
40420 The request succeeded.
40421 @end table
40422
40423 @item qfThreadInfo
40424 @itemx qsThreadInfo
40425 @cindex list active threads, remote request
40426 @cindex @samp{qfThreadInfo} packet
40427 @cindex @samp{qsThreadInfo} packet
40428 Obtain a list of all active thread IDs from the target (OS). Since there
40429 may be too many active threads to fit into one reply packet, this query
40430 works iteratively: it may require more than one query/reply sequence to
40431 obtain the entire list of threads. The first query of the sequence will
40432 be the @samp{qfThreadInfo} query; subsequent queries in the
40433 sequence will be the @samp{qsThreadInfo} query.
40434
40435 NOTE: This packet replaces the @samp{qL} query (see below).
40436
40437 Reply:
40438 @table @samp
40439 @item m @var{thread-id}
40440 A single thread ID
40441 @item m @var{thread-id},@var{thread-id}@dots{}
40442 a comma-separated list of thread IDs
40443 @item l
40444 (lower case letter @samp{L}) denotes end of list.
40445 @end table
40446
40447 In response to each query, the target will reply with a list of one or
40448 more thread IDs, separated by commas.
40449 @value{GDBN} will respond to each reply with a request for more thread
40450 ids (using the @samp{qs} form of the query), until the target responds
40451 with @samp{l} (lower-case ell, for @dfn{last}).
40452 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40453 fields.
40454
40455 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40456 initial connection with the remote target, and the very first thread ID
40457 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40458 message. Therefore, the stub should ensure that the first thread ID in
40459 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40460
40461 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
40462 @cindex get thread-local storage address, remote request
40463 @cindex @samp{qGetTLSAddr} packet
40464 Fetch the address associated with thread local storage specified
40465 by @var{thread-id}, @var{offset}, and @var{lm}.
40466
40467 @var{thread-id} is the thread ID associated with the
40468 thread for which to fetch the TLS address. @xref{thread-id syntax}.
40469
40470 @var{offset} is the (big endian, hex encoded) offset associated with the
40471 thread local variable. (This offset is obtained from the debug
40472 information associated with the variable.)
40473
40474 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
40475 load module associated with the thread local storage. For example,
40476 a @sc{gnu}/Linux system will pass the link map address of the shared
40477 object associated with the thread local storage under consideration.
40478 Other operating environments may choose to represent the load module
40479 differently, so the precise meaning of this parameter will vary.
40480
40481 Reply:
40482 @table @samp
40483 @item @var{XX}@dots{}
40484 Hex encoded (big endian) bytes representing the address of the thread
40485 local storage requested.
40486
40487 @item E @var{nn}
40488 An error occurred. The error number @var{nn} is given as hex digits.
40489
40490 @item @w{}
40491 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
40492 @end table
40493
40494 @item qGetTIBAddr:@var{thread-id}
40495 @cindex get thread information block address
40496 @cindex @samp{qGetTIBAddr} packet
40497 Fetch address of the Windows OS specific Thread Information Block.
40498
40499 @var{thread-id} is the thread ID associated with the thread.
40500
40501 Reply:
40502 @table @samp
40503 @item @var{XX}@dots{}
40504 Hex encoded (big endian) bytes representing the linear address of the
40505 thread information block.
40506
40507 @item E @var{nn}
40508 An error occured. This means that either the thread was not found, or the
40509 address could not be retrieved.
40510
40511 @item @w{}
40512 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40513 @end table
40514
40515 @item qL @var{startflag} @var{threadcount} @var{nextthread}
40516 Obtain thread information from RTOS. Where: @var{startflag} (one hex
40517 digit) is one to indicate the first query and zero to indicate a
40518 subsequent query; @var{threadcount} (two hex digits) is the maximum
40519 number of threads the response packet can contain; and @var{nextthread}
40520 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
40521 returned in the response as @var{argthread}.
40522
40523 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
40524
40525 Reply:
40526 @table @samp
40527 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
40528 Where: @var{count} (two hex digits) is the number of threads being
40529 returned; @var{done} (one hex digit) is zero to indicate more threads
40530 and one indicates no further threads; @var{argthreadid} (eight hex
40531 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
40532 is a sequence of thread IDs, @var{threadid} (eight hex
40533 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
40534 @end table
40535
40536 @item qOffsets
40537 @cindex section offsets, remote request
40538 @cindex @samp{qOffsets} packet
40539 Get section offsets that the target used when relocating the downloaded
40540 image.
40541
40542 Reply:
40543 @table @samp
40544 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40545 Relocate the @code{Text} section by @var{xxx} from its original address.
40546 Relocate the @code{Data} section by @var{yyy} from its original address.
40547 If the object file format provides segment information (e.g.@: @sc{elf}
40548 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40549 segments by the supplied offsets.
40550
40551 @emph{Note: while a @code{Bss} offset may be included in the response,
40552 @value{GDBN} ignores this and instead applies the @code{Data} offset
40553 to the @code{Bss} section.}
40554
40555 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40556 Relocate the first segment of the object file, which conventionally
40557 contains program code, to a starting address of @var{xxx}. If
40558 @samp{DataSeg} is specified, relocate the second segment, which
40559 conventionally contains modifiable data, to a starting address of
40560 @var{yyy}. @value{GDBN} will report an error if the object file
40561 does not contain segment information, or does not contain at least
40562 as many segments as mentioned in the reply. Extra segments are
40563 kept at fixed offsets relative to the last relocated segment.
40564 @end table
40565
40566 @item qP @var{mode} @var{thread-id}
40567 @cindex thread information, remote request
40568 @cindex @samp{qP} packet
40569 Returns information on @var{thread-id}. Where: @var{mode} is a hex
40570 encoded 32 bit mode; @var{thread-id} is a thread ID
40571 (@pxref{thread-id syntax}).
40572
40573 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40574 (see below).
40575
40576 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
40577
40578 @item QNonStop:1
40579 @itemx QNonStop:0
40580 @cindex non-stop mode, remote request
40581 @cindex @samp{QNonStop} packet
40582 @anchor{QNonStop}
40583 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40584 @xref{Remote Non-Stop}, for more information.
40585
40586 Reply:
40587 @table @samp
40588 @item OK
40589 The request succeeded.
40590
40591 @item E @var{nn}
40592 An error occurred. The error number @var{nn} is given as hex digits.
40593
40594 @item @w{}
40595 An empty reply indicates that @samp{QNonStop} is not supported by
40596 the stub.
40597 @end table
40598
40599 This packet is not probed by default; the remote stub must request it,
40600 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40601 Use of this packet is controlled by the @code{set non-stop} command;
40602 @pxref{Non-Stop Mode}.
40603
40604 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40605 @itemx QCatchSyscalls:0
40606 @cindex catch syscalls from inferior, remote request
40607 @cindex @samp{QCatchSyscalls} packet
40608 @anchor{QCatchSyscalls}
40609 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40610 catching syscalls from the inferior process.
40611
40612 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40613 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40614 is listed, every system call should be reported.
40615
40616 Note that if a syscall not in the list is reported, @value{GDBN} will
40617 still filter the event according to its own list from all corresponding
40618 @code{catch syscall} commands. However, it is more efficient to only
40619 report the requested syscalls.
40620
40621 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40622 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
40623
40624 If the inferior process execs, the state of @samp{QCatchSyscalls} is
40625 kept for the new process too. On targets where exec may affect syscall
40626 numbers, for example with exec between 32 and 64-bit processes, the
40627 client should send a new packet with the new syscall list.
40628
40629 Reply:
40630 @table @samp
40631 @item OK
40632 The request succeeded.
40633
40634 @item E @var{nn}
40635 An error occurred. @var{nn} are hex digits.
40636
40637 @item @w{}
40638 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40639 the stub.
40640 @end table
40641
40642 Use of this packet is controlled by the @code{set remote catch-syscalls}
40643 command (@pxref{Remote Configuration, set remote catch-syscalls}).
40644 This packet is not probed by default; the remote stub must request it,
40645 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40646
40647 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40648 @cindex pass signals to inferior, remote request
40649 @cindex @samp{QPassSignals} packet
40650 @anchor{QPassSignals}
40651 Each listed @var{signal} should be passed directly to the inferior process.
40652 Signals are numbered identically to continue packets and stop replies
40653 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40654 strictly greater than the previous item. These signals do not need to stop
40655 the inferior, or be reported to @value{GDBN}. All other signals should be
40656 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40657 combine; any earlier @samp{QPassSignals} list is completely replaced by the
40658 new list. This packet improves performance when using @samp{handle
40659 @var{signal} nostop noprint pass}.
40660
40661 Reply:
40662 @table @samp
40663 @item OK
40664 The request succeeded.
40665
40666 @item E @var{nn}
40667 An error occurred. The error number @var{nn} is given as hex digits.
40668
40669 @item @w{}
40670 An empty reply indicates that @samp{QPassSignals} is not supported by
40671 the stub.
40672 @end table
40673
40674 Use of this packet is controlled by the @code{set remote pass-signals}
40675 command (@pxref{Remote Configuration, set remote pass-signals}).
40676 This packet is not probed by default; the remote stub must request it,
40677 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40678
40679 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40680 @cindex signals the inferior may see, remote request
40681 @cindex @samp{QProgramSignals} packet
40682 @anchor{QProgramSignals}
40683 Each listed @var{signal} may be delivered to the inferior process.
40684 Others should be silently discarded.
40685
40686 In some cases, the remote stub may need to decide whether to deliver a
40687 signal to the program or not without @value{GDBN} involvement. One
40688 example of that is while detaching --- the program's threads may have
40689 stopped for signals that haven't yet had a chance of being reported to
40690 @value{GDBN}, and so the remote stub can use the signal list specified
40691 by this packet to know whether to deliver or ignore those pending
40692 signals.
40693
40694 This does not influence whether to deliver a signal as requested by a
40695 resumption packet (@pxref{vCont packet}).
40696
40697 Signals are numbered identically to continue packets and stop replies
40698 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40699 strictly greater than the previous item. Multiple
40700 @samp{QProgramSignals} packets do not combine; any earlier
40701 @samp{QProgramSignals} list is completely replaced by the new list.
40702
40703 Reply:
40704 @table @samp
40705 @item OK
40706 The request succeeded.
40707
40708 @item E @var{nn}
40709 An error occurred. The error number @var{nn} is given as hex digits.
40710
40711 @item @w{}
40712 An empty reply indicates that @samp{QProgramSignals} is not supported
40713 by the stub.
40714 @end table
40715
40716 Use of this packet is controlled by the @code{set remote program-signals}
40717 command (@pxref{Remote Configuration, set remote program-signals}).
40718 This packet is not probed by default; the remote stub must request it,
40719 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40720
40721 @anchor{QThreadEvents}
40722 @item QThreadEvents:1
40723 @itemx QThreadEvents:0
40724 @cindex thread create/exit events, remote request
40725 @cindex @samp{QThreadEvents} packet
40726
40727 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40728 reporting of thread create and exit events. @xref{thread create
40729 event}, for the reply specifications. For example, this is used in
40730 non-stop mode when @value{GDBN} stops a set of threads and
40731 synchronously waits for the their corresponding stop replies. Without
40732 exit events, if one of the threads exits, @value{GDBN} would hang
40733 forever not knowing that it should no longer expect a stop for that
40734 same thread. @value{GDBN} does not enable this feature unless the
40735 stub reports that it supports it by including @samp{QThreadEvents+} in
40736 its @samp{qSupported} reply.
40737
40738 Reply:
40739 @table @samp
40740 @item OK
40741 The request succeeded.
40742
40743 @item E @var{nn}
40744 An error occurred. The error number @var{nn} is given as hex digits.
40745
40746 @item @w{}
40747 An empty reply indicates that @samp{QThreadEvents} is not supported by
40748 the stub.
40749 @end table
40750
40751 Use of this packet is controlled by the @code{set remote thread-events}
40752 command (@pxref{Remote Configuration, set remote thread-events}).
40753
40754 @item qRcmd,@var{command}
40755 @cindex execute remote command, remote request
40756 @cindex @samp{qRcmd} packet
40757 @var{command} (hex encoded) is passed to the local interpreter for
40758 execution. Invalid commands should be reported using the output
40759 string. Before the final result packet, the target may also respond
40760 with a number of intermediate @samp{O@var{output}} console output
40761 packets. @emph{Implementors should note that providing access to a
40762 stubs's interpreter may have security implications}.
40763
40764 Reply:
40765 @table @samp
40766 @item OK
40767 A command response with no output.
40768 @item @var{OUTPUT}
40769 A command response with the hex encoded output string @var{OUTPUT}.
40770 @item E @var{NN}
40771 Indicate a badly formed request.
40772 @item @w{}
40773 An empty reply indicates that @samp{qRcmd} is not recognized.
40774 @end table
40775
40776 (Note that the @code{qRcmd} packet's name is separated from the
40777 command by a @samp{,}, not a @samp{:}, contrary to the naming
40778 conventions above. Please don't use this packet as a model for new
40779 packets.)
40780
40781 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40782 @cindex searching memory, in remote debugging
40783 @ifnotinfo
40784 @cindex @samp{qSearch:memory} packet
40785 @end ifnotinfo
40786 @cindex @samp{qSearch memory} packet
40787 @anchor{qSearch memory}
40788 Search @var{length} bytes at @var{address} for @var{search-pattern}.
40789 Both @var{address} and @var{length} are encoded in hex;
40790 @var{search-pattern} is a sequence of bytes, also hex encoded.
40791
40792 Reply:
40793 @table @samp
40794 @item 0
40795 The pattern was not found.
40796 @item 1,address
40797 The pattern was found at @var{address}.
40798 @item E @var{NN}
40799 A badly formed request or an error was encountered while searching memory.
40800 @item @w{}
40801 An empty reply indicates that @samp{qSearch:memory} is not recognized.
40802 @end table
40803
40804 @item QStartNoAckMode
40805 @cindex @samp{QStartNoAckMode} packet
40806 @anchor{QStartNoAckMode}
40807 Request that the remote stub disable the normal @samp{+}/@samp{-}
40808 protocol acknowledgments (@pxref{Packet Acknowledgment}).
40809
40810 Reply:
40811 @table @samp
40812 @item OK
40813 The stub has switched to no-acknowledgment mode.
40814 @value{GDBN} acknowledges this response,
40815 but neither the stub nor @value{GDBN} shall send or expect further
40816 @samp{+}/@samp{-} acknowledgments in the current connection.
40817 @item @w{}
40818 An empty reply indicates that the stub does not support no-acknowledgment mode.
40819 @end table
40820
40821 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40822 @cindex supported packets, remote query
40823 @cindex features of the remote protocol
40824 @cindex @samp{qSupported} packet
40825 @anchor{qSupported}
40826 Tell the remote stub about features supported by @value{GDBN}, and
40827 query the stub for features it supports. This packet allows
40828 @value{GDBN} and the remote stub to take advantage of each others'
40829 features. @samp{qSupported} also consolidates multiple feature probes
40830 at startup, to improve @value{GDBN} performance---a single larger
40831 packet performs better than multiple smaller probe packets on
40832 high-latency links. Some features may enable behavior which must not
40833 be on by default, e.g.@: because it would confuse older clients or
40834 stubs. Other features may describe packets which could be
40835 automatically probed for, but are not. These features must be
40836 reported before @value{GDBN} will use them. This ``default
40837 unsupported'' behavior is not appropriate for all packets, but it
40838 helps to keep the initial connection time under control with new
40839 versions of @value{GDBN} which support increasing numbers of packets.
40840
40841 Reply:
40842 @table @samp
40843 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40844 The stub supports or does not support each returned @var{stubfeature},
40845 depending on the form of each @var{stubfeature} (see below for the
40846 possible forms).
40847 @item @w{}
40848 An empty reply indicates that @samp{qSupported} is not recognized,
40849 or that no features needed to be reported to @value{GDBN}.
40850 @end table
40851
40852 The allowed forms for each feature (either a @var{gdbfeature} in the
40853 @samp{qSupported} packet, or a @var{stubfeature} in the response)
40854 are:
40855
40856 @table @samp
40857 @item @var{name}=@var{value}
40858 The remote protocol feature @var{name} is supported, and associated
40859 with the specified @var{value}. The format of @var{value} depends
40860 on the feature, but it must not include a semicolon.
40861 @item @var{name}+
40862 The remote protocol feature @var{name} is supported, and does not
40863 need an associated value.
40864 @item @var{name}-
40865 The remote protocol feature @var{name} is not supported.
40866 @item @var{name}?
40867 The remote protocol feature @var{name} may be supported, and
40868 @value{GDBN} should auto-detect support in some other way when it is
40869 needed. This form will not be used for @var{gdbfeature} notifications,
40870 but may be used for @var{stubfeature} responses.
40871 @end table
40872
40873 Whenever the stub receives a @samp{qSupported} request, the
40874 supplied set of @value{GDBN} features should override any previous
40875 request. This allows @value{GDBN} to put the stub in a known
40876 state, even if the stub had previously been communicating with
40877 a different version of @value{GDBN}.
40878
40879 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
40880 are defined:
40881
40882 @table @samp
40883 @item multiprocess
40884 This feature indicates whether @value{GDBN} supports multiprocess
40885 extensions to the remote protocol. @value{GDBN} does not use such
40886 extensions unless the stub also reports that it supports them by
40887 including @samp{multiprocess+} in its @samp{qSupported} reply.
40888 @xref{multiprocess extensions}, for details.
40889
40890 @item xmlRegisters
40891 This feature indicates that @value{GDBN} supports the XML target
40892 description. If the stub sees @samp{xmlRegisters=} with target
40893 specific strings separated by a comma, it will report register
40894 description.
40895
40896 @item qRelocInsn
40897 This feature indicates whether @value{GDBN} supports the
40898 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
40899 instruction reply packet}).
40900
40901 @item swbreak
40902 This feature indicates whether @value{GDBN} supports the swbreak stop
40903 reason in stop replies. @xref{swbreak stop reason}, for details.
40904
40905 @item hwbreak
40906 This feature indicates whether @value{GDBN} supports the hwbreak stop
40907 reason in stop replies. @xref{swbreak stop reason}, for details.
40908
40909 @item fork-events
40910 This feature indicates whether @value{GDBN} supports fork event
40911 extensions to the remote protocol. @value{GDBN} does not use such
40912 extensions unless the stub also reports that it supports them by
40913 including @samp{fork-events+} in its @samp{qSupported} reply.
40914
40915 @item vfork-events
40916 This feature indicates whether @value{GDBN} supports vfork event
40917 extensions to the remote protocol. @value{GDBN} does not use such
40918 extensions unless the stub also reports that it supports them by
40919 including @samp{vfork-events+} in its @samp{qSupported} reply.
40920
40921 @item exec-events
40922 This feature indicates whether @value{GDBN} supports exec event
40923 extensions to the remote protocol. @value{GDBN} does not use such
40924 extensions unless the stub also reports that it supports them by
40925 including @samp{exec-events+} in its @samp{qSupported} reply.
40926
40927 @item vContSupported
40928 This feature indicates whether @value{GDBN} wants to know the
40929 supported actions in the reply to @samp{vCont?} packet.
40930 @end table
40931
40932 Stubs should ignore any unknown values for
40933 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
40934 packet supports receiving packets of unlimited length (earlier
40935 versions of @value{GDBN} may reject overly long responses). Additional values
40936 for @var{gdbfeature} may be defined in the future to let the stub take
40937 advantage of new features in @value{GDBN}, e.g.@: incompatible
40938 improvements in the remote protocol---the @samp{multiprocess} feature is
40939 an example of such a feature. The stub's reply should be independent
40940 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
40941 describes all the features it supports, and then the stub replies with
40942 all the features it supports.
40943
40944 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
40945 responses, as long as each response uses one of the standard forms.
40946
40947 Some features are flags. A stub which supports a flag feature
40948 should respond with a @samp{+} form response. Other features
40949 require values, and the stub should respond with an @samp{=}
40950 form response.
40951
40952 Each feature has a default value, which @value{GDBN} will use if
40953 @samp{qSupported} is not available or if the feature is not mentioned
40954 in the @samp{qSupported} response. The default values are fixed; a
40955 stub is free to omit any feature responses that match the defaults.
40956
40957 Not all features can be probed, but for those which can, the probing
40958 mechanism is useful: in some cases, a stub's internal
40959 architecture may not allow the protocol layer to know some information
40960 about the underlying target in advance. This is especially common in
40961 stubs which may be configured for multiple targets.
40962
40963 These are the currently defined stub features and their properties:
40964
40965 @multitable @columnfractions 0.35 0.2 0.12 0.2
40966 @c NOTE: The first row should be @headitem, but we do not yet require
40967 @c a new enough version of Texinfo (4.7) to use @headitem.
40968 @item Feature Name
40969 @tab Value Required
40970 @tab Default
40971 @tab Probe Allowed
40972
40973 @item @samp{PacketSize}
40974 @tab Yes
40975 @tab @samp{-}
40976 @tab No
40977
40978 @item @samp{qXfer:auxv:read}
40979 @tab No
40980 @tab @samp{-}
40981 @tab Yes
40982
40983 @item @samp{qXfer:btrace:read}
40984 @tab No
40985 @tab @samp{-}
40986 @tab Yes
40987
40988 @item @samp{qXfer:btrace-conf:read}
40989 @tab No
40990 @tab @samp{-}
40991 @tab Yes
40992
40993 @item @samp{qXfer:exec-file:read}
40994 @tab No
40995 @tab @samp{-}
40996 @tab Yes
40997
40998 @item @samp{qXfer:features:read}
40999 @tab No
41000 @tab @samp{-}
41001 @tab Yes
41002
41003 @item @samp{qXfer:libraries:read}
41004 @tab No
41005 @tab @samp{-}
41006 @tab Yes
41007
41008 @item @samp{qXfer:libraries-svr4:read}
41009 @tab No
41010 @tab @samp{-}
41011 @tab Yes
41012
41013 @item @samp{augmented-libraries-svr4-read}
41014 @tab No
41015 @tab @samp{-}
41016 @tab No
41017
41018 @item @samp{qXfer:memory-map:read}
41019 @tab No
41020 @tab @samp{-}
41021 @tab Yes
41022
41023 @item @samp{qXfer:sdata:read}
41024 @tab No
41025 @tab @samp{-}
41026 @tab Yes
41027
41028 @item @samp{qXfer:siginfo:read}
41029 @tab No
41030 @tab @samp{-}
41031 @tab Yes
41032
41033 @item @samp{qXfer:siginfo:write}
41034 @tab No
41035 @tab @samp{-}
41036 @tab Yes
41037
41038 @item @samp{qXfer:threads:read}
41039 @tab No
41040 @tab @samp{-}
41041 @tab Yes
41042
41043 @item @samp{qXfer:traceframe-info:read}
41044 @tab No
41045 @tab @samp{-}
41046 @tab Yes
41047
41048 @item @samp{qXfer:uib:read}
41049 @tab No
41050 @tab @samp{-}
41051 @tab Yes
41052
41053 @item @samp{qXfer:fdpic:read}
41054 @tab No
41055 @tab @samp{-}
41056 @tab Yes
41057
41058 @item @samp{Qbtrace:off}
41059 @tab Yes
41060 @tab @samp{-}
41061 @tab Yes
41062
41063 @item @samp{Qbtrace:bts}
41064 @tab Yes
41065 @tab @samp{-}
41066 @tab Yes
41067
41068 @item @samp{Qbtrace:pt}
41069 @tab Yes
41070 @tab @samp{-}
41071 @tab Yes
41072
41073 @item @samp{Qbtrace-conf:bts:size}
41074 @tab Yes
41075 @tab @samp{-}
41076 @tab Yes
41077
41078 @item @samp{Qbtrace-conf:pt:size}
41079 @tab Yes
41080 @tab @samp{-}
41081 @tab Yes
41082
41083 @item @samp{QNonStop}
41084 @tab No
41085 @tab @samp{-}
41086 @tab Yes
41087
41088 @item @samp{QCatchSyscalls}
41089 @tab No
41090 @tab @samp{-}
41091 @tab Yes
41092
41093 @item @samp{QPassSignals}
41094 @tab No
41095 @tab @samp{-}
41096 @tab Yes
41097
41098 @item @samp{QStartNoAckMode}
41099 @tab No
41100 @tab @samp{-}
41101 @tab Yes
41102
41103 @item @samp{multiprocess}
41104 @tab No
41105 @tab @samp{-}
41106 @tab No
41107
41108 @item @samp{ConditionalBreakpoints}
41109 @tab No
41110 @tab @samp{-}
41111 @tab No
41112
41113 @item @samp{ConditionalTracepoints}
41114 @tab No
41115 @tab @samp{-}
41116 @tab No
41117
41118 @item @samp{ReverseContinue}
41119 @tab No
41120 @tab @samp{-}
41121 @tab No
41122
41123 @item @samp{ReverseStep}
41124 @tab No
41125 @tab @samp{-}
41126 @tab No
41127
41128 @item @samp{TracepointSource}
41129 @tab No
41130 @tab @samp{-}
41131 @tab No
41132
41133 @item @samp{QAgent}
41134 @tab No
41135 @tab @samp{-}
41136 @tab No
41137
41138 @item @samp{QAllow}
41139 @tab No
41140 @tab @samp{-}
41141 @tab No
41142
41143 @item @samp{QDisableRandomization}
41144 @tab No
41145 @tab @samp{-}
41146 @tab No
41147
41148 @item @samp{EnableDisableTracepoints}
41149 @tab No
41150 @tab @samp{-}
41151 @tab No
41152
41153 @item @samp{QTBuffer:size}
41154 @tab No
41155 @tab @samp{-}
41156 @tab No
41157
41158 @item @samp{tracenz}
41159 @tab No
41160 @tab @samp{-}
41161 @tab No
41162
41163 @item @samp{BreakpointCommands}
41164 @tab No
41165 @tab @samp{-}
41166 @tab No
41167
41168 @item @samp{swbreak}
41169 @tab No
41170 @tab @samp{-}
41171 @tab No
41172
41173 @item @samp{hwbreak}
41174 @tab No
41175 @tab @samp{-}
41176 @tab No
41177
41178 @item @samp{fork-events}
41179 @tab No
41180 @tab @samp{-}
41181 @tab No
41182
41183 @item @samp{vfork-events}
41184 @tab No
41185 @tab @samp{-}
41186 @tab No
41187
41188 @item @samp{exec-events}
41189 @tab No
41190 @tab @samp{-}
41191 @tab No
41192
41193 @item @samp{QThreadEvents}
41194 @tab No
41195 @tab @samp{-}
41196 @tab No
41197
41198 @item @samp{no-resumed}
41199 @tab No
41200 @tab @samp{-}
41201 @tab No
41202
41203 @end multitable
41204
41205 These are the currently defined stub features, in more detail:
41206
41207 @table @samp
41208 @cindex packet size, remote protocol
41209 @item PacketSize=@var{bytes}
41210 The remote stub can accept packets up to at least @var{bytes} in
41211 length. @value{GDBN} will send packets up to this size for bulk
41212 transfers, and will never send larger packets. This is a limit on the
41213 data characters in the packet, including the frame and checksum.
41214 There is no trailing NUL byte in a remote protocol packet; if the stub
41215 stores packets in a NUL-terminated format, it should allow an extra
41216 byte in its buffer for the NUL. If this stub feature is not supported,
41217 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41218
41219 @item qXfer:auxv:read
41220 The remote stub understands the @samp{qXfer:auxv:read} packet
41221 (@pxref{qXfer auxiliary vector read}).
41222
41223 @item qXfer:btrace:read
41224 The remote stub understands the @samp{qXfer:btrace:read}
41225 packet (@pxref{qXfer btrace read}).
41226
41227 @item qXfer:btrace-conf:read
41228 The remote stub understands the @samp{qXfer:btrace-conf:read}
41229 packet (@pxref{qXfer btrace-conf read}).
41230
41231 @item qXfer:exec-file:read
41232 The remote stub understands the @samp{qXfer:exec-file:read} packet
41233 (@pxref{qXfer executable filename read}).
41234
41235 @item qXfer:features:read
41236 The remote stub understands the @samp{qXfer:features:read} packet
41237 (@pxref{qXfer target description read}).
41238
41239 @item qXfer:libraries:read
41240 The remote stub understands the @samp{qXfer:libraries:read} packet
41241 (@pxref{qXfer library list read}).
41242
41243 @item qXfer:libraries-svr4:read
41244 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41245 (@pxref{qXfer svr4 library list read}).
41246
41247 @item augmented-libraries-svr4-read
41248 The remote stub understands the augmented form of the
41249 @samp{qXfer:libraries-svr4:read} packet
41250 (@pxref{qXfer svr4 library list read}).
41251
41252 @item qXfer:memory-map:read
41253 The remote stub understands the @samp{qXfer:memory-map:read} packet
41254 (@pxref{qXfer memory map read}).
41255
41256 @item qXfer:sdata:read
41257 The remote stub understands the @samp{qXfer:sdata:read} packet
41258 (@pxref{qXfer sdata read}).
41259
41260 @item qXfer:siginfo:read
41261 The remote stub understands the @samp{qXfer:siginfo:read} packet
41262 (@pxref{qXfer siginfo read}).
41263
41264 @item qXfer:siginfo:write
41265 The remote stub understands the @samp{qXfer:siginfo:write} packet
41266 (@pxref{qXfer siginfo write}).
41267
41268 @item qXfer:threads:read
41269 The remote stub understands the @samp{qXfer:threads:read} packet
41270 (@pxref{qXfer threads read}).
41271
41272 @item qXfer:traceframe-info:read
41273 The remote stub understands the @samp{qXfer:traceframe-info:read}
41274 packet (@pxref{qXfer traceframe info read}).
41275
41276 @item qXfer:uib:read
41277 The remote stub understands the @samp{qXfer:uib:read}
41278 packet (@pxref{qXfer unwind info block}).
41279
41280 @item qXfer:fdpic:read
41281 The remote stub understands the @samp{qXfer:fdpic:read}
41282 packet (@pxref{qXfer fdpic loadmap read}).
41283
41284 @item QNonStop
41285 The remote stub understands the @samp{QNonStop} packet
41286 (@pxref{QNonStop}).
41287
41288 @item QCatchSyscalls
41289 The remote stub understands the @samp{QCatchSyscalls} packet
41290 (@pxref{QCatchSyscalls}).
41291
41292 @item QPassSignals
41293 The remote stub understands the @samp{QPassSignals} packet
41294 (@pxref{QPassSignals}).
41295
41296 @item QStartNoAckMode
41297 The remote stub understands the @samp{QStartNoAckMode} packet and
41298 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41299
41300 @item multiprocess
41301 @anchor{multiprocess extensions}
41302 @cindex multiprocess extensions, in remote protocol
41303 The remote stub understands the multiprocess extensions to the remote
41304 protocol syntax. The multiprocess extensions affect the syntax of
41305 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41306 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41307 replies. Note that reporting this feature indicates support for the
41308 syntactic extensions only, not that the stub necessarily supports
41309 debugging of more than one process at a time. The stub must not use
41310 multiprocess extensions in packet replies unless @value{GDBN} has also
41311 indicated it supports them in its @samp{qSupported} request.
41312
41313 @item qXfer:osdata:read
41314 The remote stub understands the @samp{qXfer:osdata:read} packet
41315 ((@pxref{qXfer osdata read}).
41316
41317 @item ConditionalBreakpoints
41318 The target accepts and implements evaluation of conditional expressions
41319 defined for breakpoints. The target will only report breakpoint triggers
41320 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41321
41322 @item ConditionalTracepoints
41323 The remote stub accepts and implements conditional expressions defined
41324 for tracepoints (@pxref{Tracepoint Conditions}).
41325
41326 @item ReverseContinue
41327 The remote stub accepts and implements the reverse continue packet
41328 (@pxref{bc}).
41329
41330 @item ReverseStep
41331 The remote stub accepts and implements the reverse step packet
41332 (@pxref{bs}).
41333
41334 @item TracepointSource
41335 The remote stub understands the @samp{QTDPsrc} packet that supplies
41336 the source form of tracepoint definitions.
41337
41338 @item QAgent
41339 The remote stub understands the @samp{QAgent} packet.
41340
41341 @item QAllow
41342 The remote stub understands the @samp{QAllow} packet.
41343
41344 @item QDisableRandomization
41345 The remote stub understands the @samp{QDisableRandomization} packet.
41346
41347 @item StaticTracepoint
41348 @cindex static tracepoints, in remote protocol
41349 The remote stub supports static tracepoints.
41350
41351 @item InstallInTrace
41352 @anchor{install tracepoint in tracing}
41353 The remote stub supports installing tracepoint in tracing.
41354
41355 @item EnableDisableTracepoints
41356 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41357 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41358 to be enabled and disabled while a trace experiment is running.
41359
41360 @item QTBuffer:size
41361 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
41362 packet that allows to change the size of the trace buffer.
41363
41364 @item tracenz
41365 @cindex string tracing, in remote protocol
41366 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41367 See @ref{Bytecode Descriptions} for details about the bytecode.
41368
41369 @item BreakpointCommands
41370 @cindex breakpoint commands, in remote protocol
41371 The remote stub supports running a breakpoint's command list itself,
41372 rather than reporting the hit to @value{GDBN}.
41373
41374 @item Qbtrace:off
41375 The remote stub understands the @samp{Qbtrace:off} packet.
41376
41377 @item Qbtrace:bts
41378 The remote stub understands the @samp{Qbtrace:bts} packet.
41379
41380 @item Qbtrace:pt
41381 The remote stub understands the @samp{Qbtrace:pt} packet.
41382
41383 @item Qbtrace-conf:bts:size
41384 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41385
41386 @item Qbtrace-conf:pt:size
41387 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41388
41389 @item swbreak
41390 The remote stub reports the @samp{swbreak} stop reason for memory
41391 breakpoints.
41392
41393 @item hwbreak
41394 The remote stub reports the @samp{hwbreak} stop reason for hardware
41395 breakpoints.
41396
41397 @item fork-events
41398 The remote stub reports the @samp{fork} stop reason for fork events.
41399
41400 @item vfork-events
41401 The remote stub reports the @samp{vfork} stop reason for vfork events
41402 and vforkdone events.
41403
41404 @item exec-events
41405 The remote stub reports the @samp{exec} stop reason for exec events.
41406
41407 @item vContSupported
41408 The remote stub reports the supported actions in the reply to
41409 @samp{vCont?} packet.
41410
41411 @item QThreadEvents
41412 The remote stub understands the @samp{QThreadEvents} packet.
41413
41414 @item no-resumed
41415 The remote stub reports the @samp{N} stop reply.
41416
41417 @end table
41418
41419 @item qSymbol::
41420 @cindex symbol lookup, remote request
41421 @cindex @samp{qSymbol} packet
41422 Notify the target that @value{GDBN} is prepared to serve symbol lookup
41423 requests. Accept requests from the target for the values of symbols.
41424
41425 Reply:
41426 @table @samp
41427 @item OK
41428 The target does not need to look up any (more) symbols.
41429 @item qSymbol:@var{sym_name}
41430 The target requests the value of symbol @var{sym_name} (hex encoded).
41431 @value{GDBN} may provide the value by using the
41432 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41433 below.
41434 @end table
41435
41436 @item qSymbol:@var{sym_value}:@var{sym_name}
41437 Set the value of @var{sym_name} to @var{sym_value}.
41438
41439 @var{sym_name} (hex encoded) is the name of a symbol whose value the
41440 target has previously requested.
41441
41442 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41443 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
41444 will be empty.
41445
41446 Reply:
41447 @table @samp
41448 @item OK
41449 The target does not need to look up any (more) symbols.
41450 @item qSymbol:@var{sym_name}
41451 The target requests the value of a new symbol @var{sym_name} (hex
41452 encoded). @value{GDBN} will continue to supply the values of symbols
41453 (if available), until the target ceases to request them.
41454 @end table
41455
41456 @item qTBuffer
41457 @itemx QTBuffer
41458 @itemx QTDisconnected
41459 @itemx QTDP
41460 @itemx QTDPsrc
41461 @itemx QTDV
41462 @itemx qTfP
41463 @itemx qTfV
41464 @itemx QTFrame
41465 @itemx qTMinFTPILen
41466
41467 @xref{Tracepoint Packets}.
41468
41469 @item qThreadExtraInfo,@var{thread-id}
41470 @cindex thread attributes info, remote request
41471 @cindex @samp{qThreadExtraInfo} packet
41472 Obtain from the target OS a printable string description of thread
41473 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41474 for the forms of @var{thread-id}. This
41475 string may contain anything that the target OS thinks is interesting
41476 for @value{GDBN} to tell the user about the thread. The string is
41477 displayed in @value{GDBN}'s @code{info threads} display. Some
41478 examples of possible thread extra info strings are @samp{Runnable}, or
41479 @samp{Blocked on Mutex}.
41480
41481 Reply:
41482 @table @samp
41483 @item @var{XX}@dots{}
41484 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41485 comprising the printable string containing the extra information about
41486 the thread's attributes.
41487 @end table
41488
41489 (Note that the @code{qThreadExtraInfo} packet's name is separated from
41490 the command by a @samp{,}, not a @samp{:}, contrary to the naming
41491 conventions above. Please don't use this packet as a model for new
41492 packets.)
41493
41494 @item QTNotes
41495 @itemx qTP
41496 @itemx QTSave
41497 @itemx qTsP
41498 @itemx qTsV
41499 @itemx QTStart
41500 @itemx QTStop
41501 @itemx QTEnable
41502 @itemx QTDisable
41503 @itemx QTinit
41504 @itemx QTro
41505 @itemx qTStatus
41506 @itemx qTV
41507 @itemx qTfSTM
41508 @itemx qTsSTM
41509 @itemx qTSTMat
41510 @xref{Tracepoint Packets}.
41511
41512 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41513 @cindex read special object, remote request
41514 @cindex @samp{qXfer} packet
41515 @anchor{qXfer read}
41516 Read uninterpreted bytes from the target's special data area
41517 identified by the keyword @var{object}. Request @var{length} bytes
41518 starting at @var{offset} bytes into the data. The content and
41519 encoding of @var{annex} is specific to @var{object}; it can supply
41520 additional details about what data to access.
41521
41522 Reply:
41523 @table @samp
41524 @item m @var{data}
41525 Data @var{data} (@pxref{Binary Data}) has been read from the
41526 target. There may be more data at a higher address (although
41527 it is permitted to return @samp{m} even for the last valid
41528 block of data, as long as at least one byte of data was read).
41529 It is possible for @var{data} to have fewer bytes than the @var{length} in the
41530 request.
41531
41532 @item l @var{data}
41533 Data @var{data} (@pxref{Binary Data}) has been read from the target.
41534 There is no more data to be read. It is possible for @var{data} to
41535 have fewer bytes than the @var{length} in the request.
41536
41537 @item l
41538 The @var{offset} in the request is at the end of the data.
41539 There is no more data to be read.
41540
41541 @item E00
41542 The request was malformed, or @var{annex} was invalid.
41543
41544 @item E @var{nn}
41545 The offset was invalid, or there was an error encountered reading the data.
41546 The @var{nn} part is a hex-encoded @code{errno} value.
41547
41548 @item @w{}
41549 An empty reply indicates the @var{object} string was not recognized by
41550 the stub, or that the object does not support reading.
41551 @end table
41552
41553 Here are the specific requests of this form defined so far. All the
41554 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
41555 formats, listed above.
41556
41557 @table @samp
41558 @item qXfer:auxv:read::@var{offset},@var{length}
41559 @anchor{qXfer auxiliary vector read}
41560 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
41561 auxiliary vector}. Note @var{annex} must be empty.
41562
41563 This packet is not probed by default; the remote stub must request it,
41564 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41565
41566 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41567 @anchor{qXfer btrace read}
41568
41569 Return a description of the current branch trace.
41570 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41571 packet may have one of the following values:
41572
41573 @table @code
41574 @item all
41575 Returns all available branch trace.
41576
41577 @item new
41578 Returns all available branch trace if the branch trace changed since
41579 the last read request.
41580
41581 @item delta
41582 Returns the new branch trace since the last read request. Adds a new
41583 block to the end of the trace that begins at zero and ends at the source
41584 location of the first branch in the trace buffer. This extra block is
41585 used to stitch traces together.
41586
41587 If the trace buffer overflowed, returns an error indicating the overflow.
41588 @end table
41589
41590 This packet is not probed by default; the remote stub must request it
41591 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41592
41593 @item qXfer:btrace-conf:read::@var{offset},@var{length}
41594 @anchor{qXfer btrace-conf read}
41595
41596 Return a description of the current branch trace configuration.
41597 @xref{Branch Trace Configuration Format}.
41598
41599 This packet is not probed by default; the remote stub must request it
41600 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41601
41602 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41603 @anchor{qXfer executable filename read}
41604 Return the full absolute name of the file that was executed to create
41605 a process running on the remote system. The annex specifies the
41606 numeric process ID of the process to query, encoded as a hexadecimal
41607 number. If the annex part is empty the remote stub should return the
41608 filename corresponding to the currently executing process.
41609
41610 This packet is not probed by default; the remote stub must request it,
41611 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41612
41613 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41614 @anchor{qXfer target description read}
41615 Access the @dfn{target description}. @xref{Target Descriptions}. The
41616 annex specifies which XML document to access. The main description is
41617 always loaded from the @samp{target.xml} annex.
41618
41619 This packet is not probed by default; the remote stub must request it,
41620 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41621
41622 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41623 @anchor{qXfer library list read}
41624 Access the target's list of loaded libraries. @xref{Library List Format}.
41625 The annex part of the generic @samp{qXfer} packet must be empty
41626 (@pxref{qXfer read}).
41627
41628 Targets which maintain a list of libraries in the program's memory do
41629 not need to implement this packet; it is designed for platforms where
41630 the operating system manages the list of loaded libraries.
41631
41632 This packet is not probed by default; the remote stub must request it,
41633 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41634
41635 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41636 @anchor{qXfer svr4 library list read}
41637 Access the target's list of loaded libraries when the target is an SVR4
41638 platform. @xref{Library List Format for SVR4 Targets}. The annex part
41639 of the generic @samp{qXfer} packet must be empty unless the remote
41640 stub indicated it supports the augmented form of this packet
41641 by supplying an appropriate @samp{qSupported} response
41642 (@pxref{qXfer read}, @ref{qSupported}).
41643
41644 This packet is optional for better performance on SVR4 targets.
41645 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41646
41647 This packet is not probed by default; the remote stub must request it,
41648 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41649
41650 If the remote stub indicates it supports the augmented form of this
41651 packet then the annex part of the generic @samp{qXfer} packet may
41652 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41653 arguments. The currently supported arguments are:
41654
41655 @table @code
41656 @item start=@var{address}
41657 A hexadecimal number specifying the address of the @samp{struct
41658 link_map} to start reading the library list from. If unset or zero
41659 then the first @samp{struct link_map} in the library list will be
41660 chosen as the starting point.
41661
41662 @item prev=@var{address}
41663 A hexadecimal number specifying the address of the @samp{struct
41664 link_map} immediately preceding the @samp{struct link_map}
41665 specified by the @samp{start} argument. If unset or zero then
41666 the remote stub will expect that no @samp{struct link_map}
41667 exists prior to the starting point.
41668
41669 @end table
41670
41671 Arguments that are not understood by the remote stub will be silently
41672 ignored.
41673
41674 @item qXfer:memory-map:read::@var{offset},@var{length}
41675 @anchor{qXfer memory map read}
41676 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
41677 annex part of the generic @samp{qXfer} packet must be empty
41678 (@pxref{qXfer read}).
41679
41680 This packet is not probed by default; the remote stub must request it,
41681 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41682
41683 @item qXfer:sdata:read::@var{offset},@var{length}
41684 @anchor{qXfer sdata read}
41685
41686 Read contents of the extra collected static tracepoint marker
41687 information. The annex part of the generic @samp{qXfer} packet must
41688 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41689 Action Lists}.
41690
41691 This packet is not probed by default; the remote stub must request it,
41692 by supplying an appropriate @samp{qSupported} response
41693 (@pxref{qSupported}).
41694
41695 @item qXfer:siginfo:read::@var{offset},@var{length}
41696 @anchor{qXfer siginfo read}
41697 Read contents of the extra signal information on the target
41698 system. The annex part of the generic @samp{qXfer} packet must be
41699 empty (@pxref{qXfer read}).
41700
41701 This packet is not probed by default; the remote stub must request it,
41702 by supplying an appropriate @samp{qSupported} response
41703 (@pxref{qSupported}).
41704
41705 @item qXfer:threads:read::@var{offset},@var{length}
41706 @anchor{qXfer threads read}
41707 Access the list of threads on target. @xref{Thread List Format}. The
41708 annex part of the generic @samp{qXfer} packet must be empty
41709 (@pxref{qXfer read}).
41710
41711 This packet is not probed by default; the remote stub must request it,
41712 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41713
41714 @item qXfer:traceframe-info:read::@var{offset},@var{length}
41715 @anchor{qXfer traceframe info read}
41716
41717 Return a description of the current traceframe's contents.
41718 @xref{Traceframe Info Format}. The annex part of the generic
41719 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
41720
41721 This packet is not probed by default; the remote stub must request it,
41722 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41723
41724 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41725 @anchor{qXfer unwind info block}
41726
41727 Return the unwind information block for @var{pc}. This packet is used
41728 on OpenVMS/ia64 to ask the kernel unwind information.
41729
41730 This packet is not probed by default.
41731
41732 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41733 @anchor{qXfer fdpic loadmap read}
41734 Read contents of @code{loadmap}s on the target system. The
41735 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41736 executable @code{loadmap} or interpreter @code{loadmap} to read.
41737
41738 This packet is not probed by default; the remote stub must request it,
41739 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41740
41741 @item qXfer:osdata:read::@var{offset},@var{length}
41742 @anchor{qXfer osdata read}
41743 Access the target's @dfn{operating system information}.
41744 @xref{Operating System Information}.
41745
41746 @end table
41747
41748 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41749 @cindex write data into object, remote request
41750 @anchor{qXfer write}
41751 Write uninterpreted bytes into the target's special data area
41752 identified by the keyword @var{object}, starting at @var{offset} bytes
41753 into the data. The binary-encoded data (@pxref{Binary Data}) to be
41754 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41755 is specific to @var{object}; it can supply additional details about what data
41756 to access.
41757
41758 Reply:
41759 @table @samp
41760 @item @var{nn}
41761 @var{nn} (hex encoded) is the number of bytes written.
41762 This may be fewer bytes than supplied in the request.
41763
41764 @item E00
41765 The request was malformed, or @var{annex} was invalid.
41766
41767 @item E @var{nn}
41768 The offset was invalid, or there was an error encountered writing the data.
41769 The @var{nn} part is a hex-encoded @code{errno} value.
41770
41771 @item @w{}
41772 An empty reply indicates the @var{object} string was not
41773 recognized by the stub, or that the object does not support writing.
41774 @end table
41775
41776 Here are the specific requests of this form defined so far. All the
41777 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
41778 formats, listed above.
41779
41780 @table @samp
41781 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41782 @anchor{qXfer siginfo write}
41783 Write @var{data} to the extra signal information on the target system.
41784 The annex part of the generic @samp{qXfer} packet must be
41785 empty (@pxref{qXfer write}).
41786
41787 This packet is not probed by default; the remote stub must request it,
41788 by supplying an appropriate @samp{qSupported} response
41789 (@pxref{qSupported}).
41790 @end table
41791
41792 @item qXfer:@var{object}:@var{operation}:@dots{}
41793 Requests of this form may be added in the future. When a stub does
41794 not recognize the @var{object} keyword, or its support for
41795 @var{object} does not recognize the @var{operation} keyword, the stub
41796 must respond with an empty packet.
41797
41798 @item qAttached:@var{pid}
41799 @cindex query attached, remote request
41800 @cindex @samp{qAttached} packet
41801 Return an indication of whether the remote server attached to an
41802 existing process or created a new process. When the multiprocess
41803 protocol extensions are supported (@pxref{multiprocess extensions}),
41804 @var{pid} is an integer in hexadecimal format identifying the target
41805 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41806 the query packet will be simplified as @samp{qAttached}.
41807
41808 This query is used, for example, to know whether the remote process
41809 should be detached or killed when a @value{GDBN} session is ended with
41810 the @code{quit} command.
41811
41812 Reply:
41813 @table @samp
41814 @item 1
41815 The remote server attached to an existing process.
41816 @item 0
41817 The remote server created a new process.
41818 @item E @var{NN}
41819 A badly formed request or an error was encountered.
41820 @end table
41821
41822 @item Qbtrace:bts
41823 Enable branch tracing for the current thread using Branch Trace Store.
41824
41825 Reply:
41826 @table @samp
41827 @item OK
41828 Branch tracing has been enabled.
41829 @item E.errtext
41830 A badly formed request or an error was encountered.
41831 @end table
41832
41833 @item Qbtrace:pt
41834 Enable branch tracing for the current thread using Intel Processor Trace.
41835
41836 Reply:
41837 @table @samp
41838 @item OK
41839 Branch tracing has been enabled.
41840 @item E.errtext
41841 A badly formed request or an error was encountered.
41842 @end table
41843
41844 @item Qbtrace:off
41845 Disable branch tracing for the current thread.
41846
41847 Reply:
41848 @table @samp
41849 @item OK
41850 Branch tracing has been disabled.
41851 @item E.errtext
41852 A badly formed request or an error was encountered.
41853 @end table
41854
41855 @item Qbtrace-conf:bts:size=@var{value}
41856 Set the requested ring buffer size for new threads that use the
41857 btrace recording method in bts format.
41858
41859 Reply:
41860 @table @samp
41861 @item OK
41862 The ring buffer size has been set.
41863 @item E.errtext
41864 A badly formed request or an error was encountered.
41865 @end table
41866
41867 @item Qbtrace-conf:pt:size=@var{value}
41868 Set the requested ring buffer size for new threads that use the
41869 btrace recording method in pt format.
41870
41871 Reply:
41872 @table @samp
41873 @item OK
41874 The ring buffer size has been set.
41875 @item E.errtext
41876 A badly formed request or an error was encountered.
41877 @end table
41878
41879 @end table
41880
41881 @node Architecture-Specific Protocol Details
41882 @section Architecture-Specific Protocol Details
41883
41884 This section describes how the remote protocol is applied to specific
41885 target architectures. Also see @ref{Standard Target Features}, for
41886 details of XML target descriptions for each architecture.
41887
41888 @menu
41889 * ARM-Specific Protocol Details::
41890 * MIPS-Specific Protocol Details::
41891 @end menu
41892
41893 @node ARM-Specific Protocol Details
41894 @subsection @acronym{ARM}-specific Protocol Details
41895
41896 @menu
41897 * ARM Breakpoint Kinds::
41898 @end menu
41899
41900 @node ARM Breakpoint Kinds
41901 @subsubsection @acronym{ARM} Breakpoint Kinds
41902 @cindex breakpoint kinds, @acronym{ARM}
41903
41904 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41905
41906 @table @r
41907
41908 @item 2
41909 16-bit Thumb mode breakpoint.
41910
41911 @item 3
41912 32-bit Thumb mode (Thumb-2) breakpoint.
41913
41914 @item 4
41915 32-bit @acronym{ARM} mode breakpoint.
41916
41917 @end table
41918
41919 @node MIPS-Specific Protocol Details
41920 @subsection @acronym{MIPS}-specific Protocol Details
41921
41922 @menu
41923 * MIPS Register packet Format::
41924 * MIPS Breakpoint Kinds::
41925 @end menu
41926
41927 @node MIPS Register packet Format
41928 @subsubsection @acronym{MIPS} Register Packet Format
41929 @cindex register packet format, @acronym{MIPS}
41930
41931 The following @code{g}/@code{G} packets have previously been defined.
41932 In the below, some thirty-two bit registers are transferred as
41933 sixty-four bits. Those registers should be zero/sign extended (which?)
41934 to fill the space allocated. Register bytes are transferred in target
41935 byte order. The two nibbles within a register byte are transferred
41936 most-significant -- least-significant.
41937
41938 @table @r
41939
41940 @item MIPS32
41941 All registers are transferred as thirty-two bit quantities in the order:
41942 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
41943 registers; fsr; fir; fp.
41944
41945 @item MIPS64
41946 All registers are transferred as sixty-four bit quantities (including
41947 thirty-two bit registers such as @code{sr}). The ordering is the same
41948 as @code{MIPS32}.
41949
41950 @end table
41951
41952 @node MIPS Breakpoint Kinds
41953 @subsubsection @acronym{MIPS} Breakpoint Kinds
41954 @cindex breakpoint kinds, @acronym{MIPS}
41955
41956 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41957
41958 @table @r
41959
41960 @item 2
41961 16-bit @acronym{MIPS16} mode breakpoint.
41962
41963 @item 3
41964 16-bit @acronym{microMIPS} mode breakpoint.
41965
41966 @item 4
41967 32-bit standard @acronym{MIPS} mode breakpoint.
41968
41969 @item 5
41970 32-bit @acronym{microMIPS} mode breakpoint.
41971
41972 @end table
41973
41974 @node Tracepoint Packets
41975 @section Tracepoint Packets
41976 @cindex tracepoint packets
41977 @cindex packets, tracepoint
41978
41979 Here we describe the packets @value{GDBN} uses to implement
41980 tracepoints (@pxref{Tracepoints}).
41981
41982 @table @samp
41983
41984 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
41985 @cindex @samp{QTDP} packet
41986 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
41987 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
41988 the tracepoint is disabled. The @var{step} gives the tracepoint's step
41989 count, and @var{pass} gives its pass count. If an @samp{F} is present,
41990 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
41991 the number of bytes that the target should copy elsewhere to make room
41992 for the tracepoint. If an @samp{X} is present, it introduces a
41993 tracepoint condition, which consists of a hexadecimal length, followed
41994 by a comma and hex-encoded bytes, in a manner similar to action
41995 encodings as described below. If the trailing @samp{-} is present,
41996 further @samp{QTDP} packets will follow to specify this tracepoint's
41997 actions.
41998
41999 Replies:
42000 @table @samp
42001 @item OK
42002 The packet was understood and carried out.
42003 @item qRelocInsn
42004 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42005 @item @w{}
42006 The packet was not recognized.
42007 @end table
42008
42009 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42010 Define actions to be taken when a tracepoint is hit. The @var{n} and
42011 @var{addr} must be the same as in the initial @samp{QTDP} packet for
42012 this tracepoint. This packet may only be sent immediately after
42013 another @samp{QTDP} packet that ended with a @samp{-}. If the
42014 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42015 specifying more actions for this tracepoint.
42016
42017 In the series of action packets for a given tracepoint, at most one
42018 can have an @samp{S} before its first @var{action}. If such a packet
42019 is sent, it and the following packets define ``while-stepping''
42020 actions. Any prior packets define ordinary actions --- that is, those
42021 taken when the tracepoint is first hit. If no action packet has an
42022 @samp{S}, then all the packets in the series specify ordinary
42023 tracepoint actions.
42024
42025 The @samp{@var{action}@dots{}} portion of the packet is a series of
42026 actions, concatenated without separators. Each action has one of the
42027 following forms:
42028
42029 @table @samp
42030
42031 @item R @var{mask}
42032 Collect the registers whose bits are set in @var{mask},
42033 a hexadecimal number whose @var{i}'th bit is set if register number
42034 @var{i} should be collected. (The least significant bit is numbered
42035 zero.) Note that @var{mask} may be any number of digits long; it may
42036 not fit in a 32-bit word.
42037
42038 @item M @var{basereg},@var{offset},@var{len}
42039 Collect @var{len} bytes of memory starting at the address in register
42040 number @var{basereg}, plus @var{offset}. If @var{basereg} is
42041 @samp{-1}, then the range has a fixed address: @var{offset} is the
42042 address of the lowest byte to collect. The @var{basereg},
42043 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
42044 values (the @samp{-1} value for @var{basereg} is a special case).
42045
42046 @item X @var{len},@var{expr}
42047 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42048 it directs. The agent expression @var{expr} is as described in
42049 @ref{Agent Expressions}. Each byte of the expression is encoded as a
42050 two-digit hex number in the packet; @var{len} is the number of bytes
42051 in the expression (and thus one-half the number of hex digits in the
42052 packet).
42053
42054 @end table
42055
42056 Any number of actions may be packed together in a single @samp{QTDP}
42057 packet, as long as the packet does not exceed the maximum packet
42058 length (400 bytes, for many stubs). There may be only one @samp{R}
42059 action per tracepoint, and it must precede any @samp{M} or @samp{X}
42060 actions. Any registers referred to by @samp{M} and @samp{X} actions
42061 must be collected by a preceding @samp{R} action. (The
42062 ``while-stepping'' actions are treated as if they were attached to a
42063 separate tracepoint, as far as these restrictions are concerned.)
42064
42065 Replies:
42066 @table @samp
42067 @item OK
42068 The packet was understood and carried out.
42069 @item qRelocInsn
42070 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42071 @item @w{}
42072 The packet was not recognized.
42073 @end table
42074
42075 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42076 @cindex @samp{QTDPsrc} packet
42077 Specify a source string of tracepoint @var{n} at address @var{addr}.
42078 This is useful to get accurate reproduction of the tracepoints
42079 originally downloaded at the beginning of the trace run. The @var{type}
42080 is the name of the tracepoint part, such as @samp{cond} for the
42081 tracepoint's conditional expression (see below for a list of types), while
42082 @var{bytes} is the string, encoded in hexadecimal.
42083
42084 @var{start} is the offset of the @var{bytes} within the overall source
42085 string, while @var{slen} is the total length of the source string.
42086 This is intended for handling source strings that are longer than will
42087 fit in a single packet.
42088 @c Add detailed example when this info is moved into a dedicated
42089 @c tracepoint descriptions section.
42090
42091 The available string types are @samp{at} for the location,
42092 @samp{cond} for the conditional, and @samp{cmd} for an action command.
42093 @value{GDBN} sends a separate packet for each command in the action
42094 list, in the same order in which the commands are stored in the list.
42095
42096 The target does not need to do anything with source strings except
42097 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42098 query packets.
42099
42100 Although this packet is optional, and @value{GDBN} will only send it
42101 if the target replies with @samp{TracepointSource} @xref{General
42102 Query Packets}, it makes both disconnected tracing and trace files
42103 much easier to use. Otherwise the user must be careful that the
42104 tracepoints in effect while looking at trace frames are identical to
42105 the ones in effect during the trace run; even a small discrepancy
42106 could cause @samp{tdump} not to work, or a particular trace frame not
42107 be found.
42108
42109 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42110 @cindex define trace state variable, remote request
42111 @cindex @samp{QTDV} packet
42112 Create a new trace state variable, number @var{n}, with an initial
42113 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42114 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42115 the option of not using this packet for initial values of zero; the
42116 target should simply create the trace state variables as they are
42117 mentioned in expressions. The value @var{builtin} should be 1 (one)
42118 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42119 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42120 @samp{qTsV} packet had it set. The contents of @var{name} is the
42121 hex-encoded name (without the leading @samp{$}) of the trace state
42122 variable.
42123
42124 @item QTFrame:@var{n}
42125 @cindex @samp{QTFrame} packet
42126 Select the @var{n}'th tracepoint frame from the buffer, and use the
42127 register and memory contents recorded there to answer subsequent
42128 request packets from @value{GDBN}.
42129
42130 A successful reply from the stub indicates that the stub has found the
42131 requested frame. The response is a series of parts, concatenated
42132 without separators, describing the frame we selected. Each part has
42133 one of the following forms:
42134
42135 @table @samp
42136 @item F @var{f}
42137 The selected frame is number @var{n} in the trace frame buffer;
42138 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42139 was no frame matching the criteria in the request packet.
42140
42141 @item T @var{t}
42142 The selected trace frame records a hit of tracepoint number @var{t};
42143 @var{t} is a hexadecimal number.
42144
42145 @end table
42146
42147 @item QTFrame:pc:@var{addr}
42148 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42149 currently selected frame whose PC is @var{addr};
42150 @var{addr} is a hexadecimal number.
42151
42152 @item QTFrame:tdp:@var{t}
42153 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42154 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42155 is a hexadecimal number.
42156
42157 @item QTFrame:range:@var{start}:@var{end}
42158 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42159 currently selected frame whose PC is between @var{start} (inclusive)
42160 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42161 numbers.
42162
42163 @item QTFrame:outside:@var{start}:@var{end}
42164 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42165 frame @emph{outside} the given range of addresses (exclusive).
42166
42167 @item qTMinFTPILen
42168 @cindex @samp{qTMinFTPILen} packet
42169 This packet requests the minimum length of instruction at which a fast
42170 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42171 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42172 it depends on the target system being able to create trampolines in
42173 the first 64K of memory, which might or might not be possible for that
42174 system. So the reply to this packet will be 4 if it is able to
42175 arrange for that.
42176
42177 Replies:
42178
42179 @table @samp
42180 @item 0
42181 The minimum instruction length is currently unknown.
42182 @item @var{length}
42183 The minimum instruction length is @var{length}, where @var{length}
42184 is a hexadecimal number greater or equal to 1. A reply
42185 of 1 means that a fast tracepoint may be placed on any instruction
42186 regardless of size.
42187 @item E
42188 An error has occurred.
42189 @item @w{}
42190 An empty reply indicates that the request is not supported by the stub.
42191 @end table
42192
42193 @item QTStart
42194 @cindex @samp{QTStart} packet
42195 Begin the tracepoint experiment. Begin collecting data from
42196 tracepoint hits in the trace frame buffer. This packet supports the
42197 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42198 instruction reply packet}).
42199
42200 @item QTStop
42201 @cindex @samp{QTStop} packet
42202 End the tracepoint experiment. Stop collecting trace frames.
42203
42204 @item QTEnable:@var{n}:@var{addr}
42205 @anchor{QTEnable}
42206 @cindex @samp{QTEnable} packet
42207 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42208 experiment. If the tracepoint was previously disabled, then collection
42209 of data from it will resume.
42210
42211 @item QTDisable:@var{n}:@var{addr}
42212 @anchor{QTDisable}
42213 @cindex @samp{QTDisable} packet
42214 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42215 experiment. No more data will be collected from the tracepoint unless
42216 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42217
42218 @item QTinit
42219 @cindex @samp{QTinit} packet
42220 Clear the table of tracepoints, and empty the trace frame buffer.
42221
42222 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
42223 @cindex @samp{QTro} packet
42224 Establish the given ranges of memory as ``transparent''. The stub
42225 will answer requests for these ranges from memory's current contents,
42226 if they were not collected as part of the tracepoint hit.
42227
42228 @value{GDBN} uses this to mark read-only regions of memory, like those
42229 containing program code. Since these areas never change, they should
42230 still have the same contents they did when the tracepoint was hit, so
42231 there's no reason for the stub to refuse to provide their contents.
42232
42233 @item QTDisconnected:@var{value}
42234 @cindex @samp{QTDisconnected} packet
42235 Set the choice to what to do with the tracing run when @value{GDBN}
42236 disconnects from the target. A @var{value} of 1 directs the target to
42237 continue the tracing run, while 0 tells the target to stop tracing if
42238 @value{GDBN} is no longer in the picture.
42239
42240 @item qTStatus
42241 @cindex @samp{qTStatus} packet
42242 Ask the stub if there is a trace experiment running right now.
42243
42244 The reply has the form:
42245
42246 @table @samp
42247
42248 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
42249 @var{running} is a single digit @code{1} if the trace is presently
42250 running, or @code{0} if not. It is followed by semicolon-separated
42251 optional fields that an agent may use to report additional status.
42252
42253 @end table
42254
42255 If the trace is not running, the agent may report any of several
42256 explanations as one of the optional fields:
42257
42258 @table @samp
42259
42260 @item tnotrun:0
42261 No trace has been run yet.
42262
42263 @item tstop[:@var{text}]:0
42264 The trace was stopped by a user-originated stop command. The optional
42265 @var{text} field is a user-supplied string supplied as part of the
42266 stop command (for instance, an explanation of why the trace was
42267 stopped manually). It is hex-encoded.
42268
42269 @item tfull:0
42270 The trace stopped because the trace buffer filled up.
42271
42272 @item tdisconnected:0
42273 The trace stopped because @value{GDBN} disconnected from the target.
42274
42275 @item tpasscount:@var{tpnum}
42276 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42277
42278 @item terror:@var{text}:@var{tpnum}
42279 The trace stopped because tracepoint @var{tpnum} had an error. The
42280 string @var{text} is available to describe the nature of the error
42281 (for instance, a divide by zero in the condition expression); it
42282 is hex encoded.
42283
42284 @item tunknown:0
42285 The trace stopped for some other reason.
42286
42287 @end table
42288
42289 Additional optional fields supply statistical and other information.
42290 Although not required, they are extremely useful for users monitoring
42291 the progress of a trace run. If a trace has stopped, and these
42292 numbers are reported, they must reflect the state of the just-stopped
42293 trace.
42294
42295 @table @samp
42296
42297 @item tframes:@var{n}
42298 The number of trace frames in the buffer.
42299
42300 @item tcreated:@var{n}
42301 The total number of trace frames created during the run. This may
42302 be larger than the trace frame count, if the buffer is circular.
42303
42304 @item tsize:@var{n}
42305 The total size of the trace buffer, in bytes.
42306
42307 @item tfree:@var{n}
42308 The number of bytes still unused in the buffer.
42309
42310 @item circular:@var{n}
42311 The value of the circular trace buffer flag. @code{1} means that the
42312 trace buffer is circular and old trace frames will be discarded if
42313 necessary to make room, @code{0} means that the trace buffer is linear
42314 and may fill up.
42315
42316 @item disconn:@var{n}
42317 The value of the disconnected tracing flag. @code{1} means that
42318 tracing will continue after @value{GDBN} disconnects, @code{0} means
42319 that the trace run will stop.
42320
42321 @end table
42322
42323 @item qTP:@var{tp}:@var{addr}
42324 @cindex tracepoint status, remote request
42325 @cindex @samp{qTP} packet
42326 Ask the stub for the current state of tracepoint number @var{tp} at
42327 address @var{addr}.
42328
42329 Replies:
42330 @table @samp
42331 @item V@var{hits}:@var{usage}
42332 The tracepoint has been hit @var{hits} times so far during the trace
42333 run, and accounts for @var{usage} in the trace buffer. Note that
42334 @code{while-stepping} steps are not counted as separate hits, but the
42335 steps' space consumption is added into the usage number.
42336
42337 @end table
42338
42339 @item qTV:@var{var}
42340 @cindex trace state variable value, remote request
42341 @cindex @samp{qTV} packet
42342 Ask the stub for the value of the trace state variable number @var{var}.
42343
42344 Replies:
42345 @table @samp
42346 @item V@var{value}
42347 The value of the variable is @var{value}. This will be the current
42348 value of the variable if the user is examining a running target, or a
42349 saved value if the variable was collected in the trace frame that the
42350 user is looking at. Note that multiple requests may result in
42351 different reply values, such as when requesting values while the
42352 program is running.
42353
42354 @item U
42355 The value of the variable is unknown. This would occur, for example,
42356 if the user is examining a trace frame in which the requested variable
42357 was not collected.
42358 @end table
42359
42360 @item qTfP
42361 @cindex @samp{qTfP} packet
42362 @itemx qTsP
42363 @cindex @samp{qTsP} packet
42364 These packets request data about tracepoints that are being used by
42365 the target. @value{GDBN} sends @code{qTfP} to get the first piece
42366 of data, and multiple @code{qTsP} to get additional pieces. Replies
42367 to these packets generally take the form of the @code{QTDP} packets
42368 that define tracepoints. (FIXME add detailed syntax)
42369
42370 @item qTfV
42371 @cindex @samp{qTfV} packet
42372 @itemx qTsV
42373 @cindex @samp{qTsV} packet
42374 These packets request data about trace state variables that are on the
42375 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42376 and multiple @code{qTsV} to get additional variables. Replies to
42377 these packets follow the syntax of the @code{QTDV} packets that define
42378 trace state variables.
42379
42380 @item qTfSTM
42381 @itemx qTsSTM
42382 @anchor{qTfSTM}
42383 @anchor{qTsSTM}
42384 @cindex @samp{qTfSTM} packet
42385 @cindex @samp{qTsSTM} packet
42386 These packets request data about static tracepoint markers that exist
42387 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42388 first piece of data, and multiple @code{qTsSTM} to get additional
42389 pieces. Replies to these packets take the following form:
42390
42391 Reply:
42392 @table @samp
42393 @item m @var{address}:@var{id}:@var{extra}
42394 A single marker
42395 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42396 a comma-separated list of markers
42397 @item l
42398 (lower case letter @samp{L}) denotes end of list.
42399 @item E @var{nn}
42400 An error occurred. The error number @var{nn} is given as hex digits.
42401 @item @w{}
42402 An empty reply indicates that the request is not supported by the
42403 stub.
42404 @end table
42405
42406 The @var{address} is encoded in hex;
42407 @var{id} and @var{extra} are strings encoded in hex.
42408
42409 In response to each query, the target will reply with a list of one or
42410 more markers, separated by commas. @value{GDBN} will respond to each
42411 reply with a request for more markers (using the @samp{qs} form of the
42412 query), until the target responds with @samp{l} (lower-case ell, for
42413 @dfn{last}).
42414
42415 @item qTSTMat:@var{address}
42416 @anchor{qTSTMat}
42417 @cindex @samp{qTSTMat} packet
42418 This packets requests data about static tracepoint markers in the
42419 target program at @var{address}. Replies to this packet follow the
42420 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42421 tracepoint markers.
42422
42423 @item QTSave:@var{filename}
42424 @cindex @samp{QTSave} packet
42425 This packet directs the target to save trace data to the file name
42426 @var{filename} in the target's filesystem. The @var{filename} is encoded
42427 as a hex string; the interpretation of the file name (relative vs
42428 absolute, wild cards, etc) is up to the target.
42429
42430 @item qTBuffer:@var{offset},@var{len}
42431 @cindex @samp{qTBuffer} packet
42432 Return up to @var{len} bytes of the current contents of trace buffer,
42433 starting at @var{offset}. The trace buffer is treated as if it were
42434 a contiguous collection of traceframes, as per the trace file format.
42435 The reply consists as many hex-encoded bytes as the target can deliver
42436 in a packet; it is not an error to return fewer than were asked for.
42437 A reply consisting of just @code{l} indicates that no bytes are
42438 available.
42439
42440 @item QTBuffer:circular:@var{value}
42441 This packet directs the target to use a circular trace buffer if
42442 @var{value} is 1, or a linear buffer if the value is 0.
42443
42444 @item QTBuffer:size:@var{size}
42445 @anchor{QTBuffer-size}
42446 @cindex @samp{QTBuffer size} packet
42447 This packet directs the target to make the trace buffer be of size
42448 @var{size} if possible. A value of @code{-1} tells the target to
42449 use whatever size it prefers.
42450
42451 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
42452 @cindex @samp{QTNotes} packet
42453 This packet adds optional textual notes to the trace run. Allowable
42454 types include @code{user}, @code{notes}, and @code{tstop}, the
42455 @var{text} fields are arbitrary strings, hex-encoded.
42456
42457 @end table
42458
42459 @subsection Relocate instruction reply packet
42460 When installing fast tracepoints in memory, the target may need to
42461 relocate the instruction currently at the tracepoint address to a
42462 different address in memory. For most instructions, a simple copy is
42463 enough, but, for example, call instructions that implicitly push the
42464 return address on the stack, and relative branches or other
42465 PC-relative instructions require offset adjustment, so that the effect
42466 of executing the instruction at a different address is the same as if
42467 it had executed in the original location.
42468
42469 In response to several of the tracepoint packets, the target may also
42470 respond with a number of intermediate @samp{qRelocInsn} request
42471 packets before the final result packet, to have @value{GDBN} handle
42472 this relocation operation. If a packet supports this mechanism, its
42473 documentation will explicitly say so. See for example the above
42474 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42475 format of the request is:
42476
42477 @table @samp
42478 @item qRelocInsn:@var{from};@var{to}
42479
42480 This requests @value{GDBN} to copy instruction at address @var{from}
42481 to address @var{to}, possibly adjusted so that executing the
42482 instruction at @var{to} has the same effect as executing it at
42483 @var{from}. @value{GDBN} writes the adjusted instruction to target
42484 memory starting at @var{to}.
42485 @end table
42486
42487 Replies:
42488 @table @samp
42489 @item qRelocInsn:@var{adjusted_size}
42490 Informs the stub the relocation is complete. The @var{adjusted_size} is
42491 the length in bytes of resulting relocated instruction sequence.
42492 @item E @var{NN}
42493 A badly formed request was detected, or an error was encountered while
42494 relocating the instruction.
42495 @end table
42496
42497 @node Host I/O Packets
42498 @section Host I/O Packets
42499 @cindex Host I/O, remote protocol
42500 @cindex file transfer, remote protocol
42501
42502 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42503 operations on the far side of a remote link. For example, Host I/O is
42504 used to upload and download files to a remote target with its own
42505 filesystem. Host I/O uses the same constant values and data structure
42506 layout as the target-initiated File-I/O protocol. However, the
42507 Host I/O packets are structured differently. The target-initiated
42508 protocol relies on target memory to store parameters and buffers.
42509 Host I/O requests are initiated by @value{GDBN}, and the
42510 target's memory is not involved. @xref{File-I/O Remote Protocol
42511 Extension}, for more details on the target-initiated protocol.
42512
42513 The Host I/O request packets all encode a single operation along with
42514 its arguments. They have this format:
42515
42516 @table @samp
42517
42518 @item vFile:@var{operation}: @var{parameter}@dots{}
42519 @var{operation} is the name of the particular request; the target
42520 should compare the entire packet name up to the second colon when checking
42521 for a supported operation. The format of @var{parameter} depends on
42522 the operation. Numbers are always passed in hexadecimal. Negative
42523 numbers have an explicit minus sign (i.e.@: two's complement is not
42524 used). Strings (e.g.@: filenames) are encoded as a series of
42525 hexadecimal bytes. The last argument to a system call may be a
42526 buffer of escaped binary data (@pxref{Binary Data}).
42527
42528 @end table
42529
42530 The valid responses to Host I/O packets are:
42531
42532 @table @samp
42533
42534 @item F @var{result} [, @var{errno}] [; @var{attachment}]
42535 @var{result} is the integer value returned by this operation, usually
42536 non-negative for success and -1 for errors. If an error has occured,
42537 @var{errno} will be included in the result specifying a
42538 value defined by the File-I/O protocol (@pxref{Errno Values}). For
42539 operations which return data, @var{attachment} supplies the data as a
42540 binary buffer. Binary buffers in response packets are escaped in the
42541 normal way (@pxref{Binary Data}). See the individual packet
42542 documentation for the interpretation of @var{result} and
42543 @var{attachment}.
42544
42545 @item @w{}
42546 An empty response indicates that this operation is not recognized.
42547
42548 @end table
42549
42550 These are the supported Host I/O operations:
42551
42552 @table @samp
42553 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
42554 Open a file at @var{filename} and return a file descriptor for it, or
42555 return -1 if an error occurs. The @var{filename} is a string,
42556 @var{flags} is an integer indicating a mask of open flags
42557 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42558 of mode bits to use if the file is created (@pxref{mode_t Values}).
42559 @xref{open}, for details of the open flags and mode values.
42560
42561 @item vFile:close: @var{fd}
42562 Close the open file corresponding to @var{fd} and return 0, or
42563 -1 if an error occurs.
42564
42565 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
42566 Read data from the open file corresponding to @var{fd}. Up to
42567 @var{count} bytes will be read from the file, starting at @var{offset}
42568 relative to the start of the file. The target may read fewer bytes;
42569 common reasons include packet size limits and an end-of-file
42570 condition. The number of bytes read is returned. Zero should only be
42571 returned for a successful read at the end of the file, or if
42572 @var{count} was zero.
42573
42574 The data read should be returned as a binary attachment on success.
42575 If zero bytes were read, the response should include an empty binary
42576 attachment (i.e.@: a trailing semicolon). The return value is the
42577 number of target bytes read; the binary attachment may be longer if
42578 some characters were escaped.
42579
42580 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42581 Write @var{data} (a binary buffer) to the open file corresponding
42582 to @var{fd}. Start the write at @var{offset} from the start of the
42583 file. Unlike many @code{write} system calls, there is no
42584 separate @var{count} argument; the length of @var{data} in the
42585 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
42586 which may be shorter than the length of @var{data}, or -1 if an
42587 error occurred.
42588
42589 @item vFile:fstat: @var{fd}
42590 Get information about the open file corresponding to @var{fd}.
42591 On success the information is returned as a binary attachment
42592 and the return value is the size of this attachment in bytes.
42593 If an error occurs the return value is -1. The format of the
42594 returned binary attachment is as described in @ref{struct stat}.
42595
42596 @item vFile:unlink: @var{filename}
42597 Delete the file at @var{filename} on the target. Return 0,
42598 or -1 if an error occurs. The @var{filename} is a string.
42599
42600 @item vFile:readlink: @var{filename}
42601 Read value of symbolic link @var{filename} on the target. Return
42602 the number of bytes read, or -1 if an error occurs.
42603
42604 The data read should be returned as a binary attachment on success.
42605 If zero bytes were read, the response should include an empty binary
42606 attachment (i.e.@: a trailing semicolon). The return value is the
42607 number of target bytes read; the binary attachment may be longer if
42608 some characters were escaped.
42609
42610 @item vFile:setfs: @var{pid}
42611 Select the filesystem on which @code{vFile} operations with
42612 @var{filename} arguments will operate. This is required for
42613 @value{GDBN} to be able to access files on remote targets where
42614 the remote stub does not share a common filesystem with the
42615 inferior(s).
42616
42617 If @var{pid} is nonzero, select the filesystem as seen by process
42618 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
42619 the remote stub. Return 0 on success, or -1 if an error occurs.
42620 If @code{vFile:setfs:} indicates success, the selected filesystem
42621 remains selected until the next successful @code{vFile:setfs:}
42622 operation.
42623
42624 @end table
42625
42626 @node Interrupts
42627 @section Interrupts
42628 @cindex interrupts (remote protocol)
42629 @anchor{interrupting remote targets}
42630
42631 In all-stop mode, when a program on the remote target is running,
42632 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42633 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42634 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
42635
42636 The precise meaning of @code{BREAK} is defined by the transport
42637 mechanism and may, in fact, be undefined. @value{GDBN} does not
42638 currently define a @code{BREAK} mechanism for any of the network
42639 interfaces except for TCP, in which case @value{GDBN} sends the
42640 @code{telnet} BREAK sequence.
42641
42642 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
42643 transport mechanisms. It is represented by sending the single byte
42644 @code{0x03} without any of the usual packet overhead described in
42645 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42646 transmitted as part of a packet, it is considered to be packet data
42647 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
42648 (@pxref{X packet}), used for binary downloads, may include an unescaped
42649 @code{0x03} as part of its packet.
42650
42651 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42652 When Linux kernel receives this sequence from serial port,
42653 it stops execution and connects to gdb.
42654
42655 In non-stop mode, because packet resumptions are asynchronous
42656 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42657 command to the remote stub, even when the target is running. For that
42658 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42659 packet}) with the usual packet framing instead of the single byte
42660 @code{0x03}.
42661
42662 Stubs are not required to recognize these interrupt mechanisms and the
42663 precise meaning associated with receipt of the interrupt is
42664 implementation defined. If the target supports debugging of multiple
42665 threads and/or processes, it should attempt to interrupt all
42666 currently-executing threads and processes.
42667 If the stub is successful at interrupting the
42668 running program, it should send one of the stop
42669 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42670 of successfully stopping the program in all-stop mode, and a stop reply
42671 for each stopped thread in non-stop mode.
42672 Interrupts received while the
42673 program is stopped are queued and the program will be interrupted when
42674 it is resumed next time.
42675
42676 @node Notification Packets
42677 @section Notification Packets
42678 @cindex notification packets
42679 @cindex packets, notification
42680
42681 The @value{GDBN} remote serial protocol includes @dfn{notifications},
42682 packets that require no acknowledgment. Both the GDB and the stub
42683 may send notifications (although the only notifications defined at
42684 present are sent by the stub). Notifications carry information
42685 without incurring the round-trip latency of an acknowledgment, and so
42686 are useful for low-impact communications where occasional packet loss
42687 is not a problem.
42688
42689 A notification packet has the form @samp{% @var{data} #
42690 @var{checksum}}, where @var{data} is the content of the notification,
42691 and @var{checksum} is a checksum of @var{data}, computed and formatted
42692 as for ordinary @value{GDBN} packets. A notification's @var{data}
42693 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42694 receiving a notification, the recipient sends no @samp{+} or @samp{-}
42695 to acknowledge the notification's receipt or to report its corruption.
42696
42697 Every notification's @var{data} begins with a name, which contains no
42698 colon characters, followed by a colon character.
42699
42700 Recipients should silently ignore corrupted notifications and
42701 notifications they do not understand. Recipients should restart
42702 timeout periods on receipt of a well-formed notification, whether or
42703 not they understand it.
42704
42705 Senders should only send the notifications described here when this
42706 protocol description specifies that they are permitted. In the
42707 future, we may extend the protocol to permit existing notifications in
42708 new contexts; this rule helps older senders avoid confusing newer
42709 recipients.
42710
42711 (Older versions of @value{GDBN} ignore bytes received until they see
42712 the @samp{$} byte that begins an ordinary packet, so new stubs may
42713 transmit notifications without fear of confusing older clients. There
42714 are no notifications defined for @value{GDBN} to send at the moment, but we
42715 assume that most older stubs would ignore them, as well.)
42716
42717 Each notification is comprised of three parts:
42718 @table @samp
42719 @item @var{name}:@var{event}
42720 The notification packet is sent by the side that initiates the
42721 exchange (currently, only the stub does that), with @var{event}
42722 carrying the specific information about the notification, and
42723 @var{name} specifying the name of the notification.
42724 @item @var{ack}
42725 The acknowledge sent by the other side, usually @value{GDBN}, to
42726 acknowledge the exchange and request the event.
42727 @end table
42728
42729 The purpose of an asynchronous notification mechanism is to report to
42730 @value{GDBN} that something interesting happened in the remote stub.
42731
42732 The remote stub may send notification @var{name}:@var{event}
42733 at any time, but @value{GDBN} acknowledges the notification when
42734 appropriate. The notification event is pending before @value{GDBN}
42735 acknowledges. Only one notification at a time may be pending; if
42736 additional events occur before @value{GDBN} has acknowledged the
42737 previous notification, they must be queued by the stub for later
42738 synchronous transmission in response to @var{ack} packets from
42739 @value{GDBN}. Because the notification mechanism is unreliable,
42740 the stub is permitted to resend a notification if it believes
42741 @value{GDBN} may not have received it.
42742
42743 Specifically, notifications may appear when @value{GDBN} is not
42744 otherwise reading input from the stub, or when @value{GDBN} is
42745 expecting to read a normal synchronous response or a
42746 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
42747 Notification packets are distinct from any other communication from
42748 the stub so there is no ambiguity.
42749
42750 After receiving a notification, @value{GDBN} shall acknowledge it by
42751 sending a @var{ack} packet as a regular, synchronous request to the
42752 stub. Such acknowledgment is not required to happen immediately, as
42753 @value{GDBN} is permitted to send other, unrelated packets to the
42754 stub first, which the stub should process normally.
42755
42756 Upon receiving a @var{ack} packet, if the stub has other queued
42757 events to report to @value{GDBN}, it shall respond by sending a
42758 normal @var{event}. @value{GDBN} shall then send another @var{ack}
42759 packet to solicit further responses; again, it is permitted to send
42760 other, unrelated packets as well which the stub should process
42761 normally.
42762
42763 If the stub receives a @var{ack} packet and there are no additional
42764 @var{event} to report, the stub shall return an @samp{OK} response.
42765 At this point, @value{GDBN} has finished processing a notification
42766 and the stub has completed sending any queued events. @value{GDBN}
42767 won't accept any new notifications until the final @samp{OK} is
42768 received . If further notification events occur, the stub shall send
42769 a new notification, @value{GDBN} shall accept the notification, and
42770 the process shall be repeated.
42771
42772 The process of asynchronous notification can be illustrated by the
42773 following example:
42774 @smallexample
42775 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
42776 @code{...}
42777 -> @code{vStopped}
42778 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42779 -> @code{vStopped}
42780 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42781 -> @code{vStopped}
42782 <- @code{OK}
42783 @end smallexample
42784
42785 The following notifications are defined:
42786 @multitable @columnfractions 0.12 0.12 0.38 0.38
42787
42788 @item Notification
42789 @tab Ack
42790 @tab Event
42791 @tab Description
42792
42793 @item Stop
42794 @tab vStopped
42795 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
42796 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42797 for information on how these notifications are acknowledged by
42798 @value{GDBN}.
42799 @tab Report an asynchronous stop event in non-stop mode.
42800
42801 @end multitable
42802
42803 @node Remote Non-Stop
42804 @section Remote Protocol Support for Non-Stop Mode
42805
42806 @value{GDBN}'s remote protocol supports non-stop debugging of
42807 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42808 supports non-stop mode, it should report that to @value{GDBN} by including
42809 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42810
42811 @value{GDBN} typically sends a @samp{QNonStop} packet only when
42812 establishing a new connection with the stub. Entering non-stop mode
42813 does not alter the state of any currently-running threads, but targets
42814 must stop all threads in any already-attached processes when entering
42815 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42816 probe the target state after a mode change.
42817
42818 In non-stop mode, when an attached process encounters an event that
42819 would otherwise be reported with a stop reply, it uses the
42820 asynchronous notification mechanism (@pxref{Notification Packets}) to
42821 inform @value{GDBN}. In contrast to all-stop mode, where all threads
42822 in all processes are stopped when a stop reply is sent, in non-stop
42823 mode only the thread reporting the stop event is stopped. That is,
42824 when reporting a @samp{S} or @samp{T} response to indicate completion
42825 of a step operation, hitting a breakpoint, or a fault, only the
42826 affected thread is stopped; any other still-running threads continue
42827 to run. When reporting a @samp{W} or @samp{X} response, all running
42828 threads belonging to other attached processes continue to run.
42829
42830 In non-stop mode, the target shall respond to the @samp{?} packet as
42831 follows. First, any incomplete stop reply notification/@samp{vStopped}
42832 sequence in progress is abandoned. The target must begin a new
42833 sequence reporting stop events for all stopped threads, whether or not
42834 it has previously reported those events to @value{GDBN}. The first
42835 stop reply is sent as a synchronous reply to the @samp{?} packet, and
42836 subsequent stop replies are sent as responses to @samp{vStopped} packets
42837 using the mechanism described above. The target must not send
42838 asynchronous stop reply notifications until the sequence is complete.
42839 If all threads are running when the target receives the @samp{?} packet,
42840 or if the target is not attached to any process, it shall respond
42841 @samp{OK}.
42842
42843 If the stub supports non-stop mode, it should also support the
42844 @samp{swbreak} stop reason if software breakpoints are supported, and
42845 the @samp{hwbreak} stop reason if hardware breakpoints are supported
42846 (@pxref{swbreak stop reason}). This is because given the asynchronous
42847 nature of non-stop mode, between the time a thread hits a breakpoint
42848 and the time the event is finally processed by @value{GDBN}, the
42849 breakpoint may have already been removed from the target. Due to
42850 this, @value{GDBN} needs to be able to tell whether a trap stop was
42851 caused by a delayed breakpoint event, which should be ignored, as
42852 opposed to a random trap signal, which should be reported to the user.
42853 Note the @samp{swbreak} feature implies that the target is responsible
42854 for adjusting the PC when a software breakpoint triggers, if
42855 necessary, such as on the x86 architecture.
42856
42857 @node Packet Acknowledgment
42858 @section Packet Acknowledgment
42859
42860 @cindex acknowledgment, for @value{GDBN} remote
42861 @cindex packet acknowledgment, for @value{GDBN} remote
42862 By default, when either the host or the target machine receives a packet,
42863 the first response expected is an acknowledgment: either @samp{+} (to indicate
42864 the package was received correctly) or @samp{-} (to request retransmission).
42865 This mechanism allows the @value{GDBN} remote protocol to operate over
42866 unreliable transport mechanisms, such as a serial line.
42867
42868 In cases where the transport mechanism is itself reliable (such as a pipe or
42869 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42870 It may be desirable to disable them in that case to reduce communication
42871 overhead, or for other reasons. This can be accomplished by means of the
42872 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42873
42874 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42875 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
42876 and response format still includes the normal checksum, as described in
42877 @ref{Overview}, but the checksum may be ignored by the receiver.
42878
42879 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
42880 no-acknowledgment mode, it should report that to @value{GDBN}
42881 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
42882 @pxref{qSupported}.
42883 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
42884 disabled via the @code{set remote noack-packet off} command
42885 (@pxref{Remote Configuration}),
42886 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
42887 Only then may the stub actually turn off packet acknowledgments.
42888 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
42889 response, which can be safely ignored by the stub.
42890
42891 Note that @code{set remote noack-packet} command only affects negotiation
42892 between @value{GDBN} and the stub when subsequent connections are made;
42893 it does not affect the protocol acknowledgment state for any current
42894 connection.
42895 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
42896 new connection is established,
42897 there is also no protocol request to re-enable the acknowledgments
42898 for the current connection, once disabled.
42899
42900 @node Examples
42901 @section Examples
42902
42903 Example sequence of a target being re-started. Notice how the restart
42904 does not get any direct output:
42905
42906 @smallexample
42907 -> @code{R00}
42908 <- @code{+}
42909 @emph{target restarts}
42910 -> @code{?}
42911 <- @code{+}
42912 <- @code{T001:1234123412341234}
42913 -> @code{+}
42914 @end smallexample
42915
42916 Example sequence of a target being stepped by a single instruction:
42917
42918 @smallexample
42919 -> @code{G1445@dots{}}
42920 <- @code{+}
42921 -> @code{s}
42922 <- @code{+}
42923 @emph{time passes}
42924 <- @code{T001:1234123412341234}
42925 -> @code{+}
42926 -> @code{g}
42927 <- @code{+}
42928 <- @code{1455@dots{}}
42929 -> @code{+}
42930 @end smallexample
42931
42932 @node File-I/O Remote Protocol Extension
42933 @section File-I/O Remote Protocol Extension
42934 @cindex File-I/O remote protocol extension
42935
42936 @menu
42937 * File-I/O Overview::
42938 * Protocol Basics::
42939 * The F Request Packet::
42940 * The F Reply Packet::
42941 * The Ctrl-C Message::
42942 * Console I/O::
42943 * List of Supported Calls::
42944 * Protocol-specific Representation of Datatypes::
42945 * Constants::
42946 * File-I/O Examples::
42947 @end menu
42948
42949 @node File-I/O Overview
42950 @subsection File-I/O Overview
42951 @cindex file-i/o overview
42952
42953 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
42954 target to use the host's file system and console I/O to perform various
42955 system calls. System calls on the target system are translated into a
42956 remote protocol packet to the host system, which then performs the needed
42957 actions and returns a response packet to the target system.
42958 This simulates file system operations even on targets that lack file systems.
42959
42960 The protocol is defined to be independent of both the host and target systems.
42961 It uses its own internal representation of datatypes and values. Both
42962 @value{GDBN} and the target's @value{GDBN} stub are responsible for
42963 translating the system-dependent value representations into the internal
42964 protocol representations when data is transmitted.
42965
42966 The communication is synchronous. A system call is possible only when
42967 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
42968 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
42969 the target is stopped to allow deterministic access to the target's
42970 memory. Therefore File-I/O is not interruptible by target signals. On
42971 the other hand, it is possible to interrupt File-I/O by a user interrupt
42972 (@samp{Ctrl-C}) within @value{GDBN}.
42973
42974 The target's request to perform a host system call does not finish
42975 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
42976 after finishing the system call, the target returns to continuing the
42977 previous activity (continue, step). No additional continue or step
42978 request from @value{GDBN} is required.
42979
42980 @smallexample
42981 (@value{GDBP}) continue
42982 <- target requests 'system call X'
42983 target is stopped, @value{GDBN} executes system call
42984 -> @value{GDBN} returns result
42985 ... target continues, @value{GDBN} returns to wait for the target
42986 <- target hits breakpoint and sends a Txx packet
42987 @end smallexample
42988
42989 The protocol only supports I/O on the console and to regular files on
42990 the host file system. Character or block special devices, pipes,
42991 named pipes, sockets or any other communication method on the host
42992 system are not supported by this protocol.
42993
42994 File I/O is not supported in non-stop mode.
42995
42996 @node Protocol Basics
42997 @subsection Protocol Basics
42998 @cindex protocol basics, file-i/o
42999
43000 The File-I/O protocol uses the @code{F} packet as the request as well
43001 as reply packet. Since a File-I/O system call can only occur when
43002 @value{GDBN} is waiting for a response from the continuing or stepping target,
43003 the File-I/O request is a reply that @value{GDBN} has to expect as a result
43004 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43005 This @code{F} packet contains all information needed to allow @value{GDBN}
43006 to call the appropriate host system call:
43007
43008 @itemize @bullet
43009 @item
43010 A unique identifier for the requested system call.
43011
43012 @item
43013 All parameters to the system call. Pointers are given as addresses
43014 in the target memory address space. Pointers to strings are given as
43015 pointer/length pair. Numerical values are given as they are.
43016 Numerical control flags are given in a protocol-specific representation.
43017
43018 @end itemize
43019
43020 At this point, @value{GDBN} has to perform the following actions.
43021
43022 @itemize @bullet
43023 @item
43024 If the parameters include pointer values to data needed as input to a
43025 system call, @value{GDBN} requests this data from the target with a
43026 standard @code{m} packet request. This additional communication has to be
43027 expected by the target implementation and is handled as any other @code{m}
43028 packet.
43029
43030 @item
43031 @value{GDBN} translates all value from protocol representation to host
43032 representation as needed. Datatypes are coerced into the host types.
43033
43034 @item
43035 @value{GDBN} calls the system call.
43036
43037 @item
43038 It then coerces datatypes back to protocol representation.
43039
43040 @item
43041 If the system call is expected to return data in buffer space specified
43042 by pointer parameters to the call, the data is transmitted to the
43043 target using a @code{M} or @code{X} packet. This packet has to be expected
43044 by the target implementation and is handled as any other @code{M} or @code{X}
43045 packet.
43046
43047 @end itemize
43048
43049 Eventually @value{GDBN} replies with another @code{F} packet which contains all
43050 necessary information for the target to continue. This at least contains
43051
43052 @itemize @bullet
43053 @item
43054 Return value.
43055
43056 @item
43057 @code{errno}, if has been changed by the system call.
43058
43059 @item
43060 ``Ctrl-C'' flag.
43061
43062 @end itemize
43063
43064 After having done the needed type and value coercion, the target continues
43065 the latest continue or step action.
43066
43067 @node The F Request Packet
43068 @subsection The @code{F} Request Packet
43069 @cindex file-i/o request packet
43070 @cindex @code{F} request packet
43071
43072 The @code{F} request packet has the following format:
43073
43074 @table @samp
43075 @item F@var{call-id},@var{parameter@dots{}}
43076
43077 @var{call-id} is the identifier to indicate the host system call to be called.
43078 This is just the name of the function.
43079
43080 @var{parameter@dots{}} are the parameters to the system call.
43081 Parameters are hexadecimal integer values, either the actual values in case
43082 of scalar datatypes, pointers to target buffer space in case of compound
43083 datatypes and unspecified memory areas, or pointer/length pairs in case
43084 of string parameters. These are appended to the @var{call-id} as a
43085 comma-delimited list. All values are transmitted in ASCII
43086 string representation, pointer/length pairs separated by a slash.
43087
43088 @end table
43089
43090
43091
43092 @node The F Reply Packet
43093 @subsection The @code{F} Reply Packet
43094 @cindex file-i/o reply packet
43095 @cindex @code{F} reply packet
43096
43097 The @code{F} reply packet has the following format:
43098
43099 @table @samp
43100
43101 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43102
43103 @var{retcode} is the return code of the system call as hexadecimal value.
43104
43105 @var{errno} is the @code{errno} set by the call, in protocol-specific
43106 representation.
43107 This parameter can be omitted if the call was successful.
43108
43109 @var{Ctrl-C flag} is only sent if the user requested a break. In this
43110 case, @var{errno} must be sent as well, even if the call was successful.
43111 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43112
43113 @smallexample
43114 F0,0,C
43115 @end smallexample
43116
43117 @noindent
43118 or, if the call was interrupted before the host call has been performed:
43119
43120 @smallexample
43121 F-1,4,C
43122 @end smallexample
43123
43124 @noindent
43125 assuming 4 is the protocol-specific representation of @code{EINTR}.
43126
43127 @end table
43128
43129
43130 @node The Ctrl-C Message
43131 @subsection The @samp{Ctrl-C} Message
43132 @cindex ctrl-c message, in file-i/o protocol
43133
43134 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43135 reply packet (@pxref{The F Reply Packet}),
43136 the target should behave as if it had
43137 gotten a break message. The meaning for the target is ``system call
43138 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43139 (as with a break message) and return to @value{GDBN} with a @code{T02}
43140 packet.
43141
43142 It's important for the target to know in which
43143 state the system call was interrupted. There are two possible cases:
43144
43145 @itemize @bullet
43146 @item
43147 The system call hasn't been performed on the host yet.
43148
43149 @item
43150 The system call on the host has been finished.
43151
43152 @end itemize
43153
43154 These two states can be distinguished by the target by the value of the
43155 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43156 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43157 on POSIX systems. In any other case, the target may presume that the
43158 system call has been finished --- successfully or not --- and should behave
43159 as if the break message arrived right after the system call.
43160
43161 @value{GDBN} must behave reliably. If the system call has not been called
43162 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43163 @code{errno} in the packet. If the system call on the host has been finished
43164 before the user requests a break, the full action must be finished by
43165 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43166 The @code{F} packet may only be sent when either nothing has happened
43167 or the full action has been completed.
43168
43169 @node Console I/O
43170 @subsection Console I/O
43171 @cindex console i/o as part of file-i/o
43172
43173 By default and if not explicitly closed by the target system, the file
43174 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43175 on the @value{GDBN} console is handled as any other file output operation
43176 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43177 by @value{GDBN} so that after the target read request from file descriptor
43178 0 all following typing is buffered until either one of the following
43179 conditions is met:
43180
43181 @itemize @bullet
43182 @item
43183 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43184 @code{read}
43185 system call is treated as finished.
43186
43187 @item
43188 The user presses @key{RET}. This is treated as end of input with a trailing
43189 newline.
43190
43191 @item
43192 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43193 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43194
43195 @end itemize
43196
43197 If the user has typed more characters than fit in the buffer given to
43198 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43199 either another @code{read(0, @dots{})} is requested by the target, or debugging
43200 is stopped at the user's request.
43201
43202
43203 @node List of Supported Calls
43204 @subsection List of Supported Calls
43205 @cindex list of supported file-i/o calls
43206
43207 @menu
43208 * open::
43209 * close::
43210 * read::
43211 * write::
43212 * lseek::
43213 * rename::
43214 * unlink::
43215 * stat/fstat::
43216 * gettimeofday::
43217 * isatty::
43218 * system::
43219 @end menu
43220
43221 @node open
43222 @unnumberedsubsubsec open
43223 @cindex open, file-i/o system call
43224
43225 @table @asis
43226 @item Synopsis:
43227 @smallexample
43228 int open(const char *pathname, int flags);
43229 int open(const char *pathname, int flags, mode_t mode);
43230 @end smallexample
43231
43232 @item Request:
43233 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43234
43235 @noindent
43236 @var{flags} is the bitwise @code{OR} of the following values:
43237
43238 @table @code
43239 @item O_CREAT
43240 If the file does not exist it will be created. The host
43241 rules apply as far as file ownership and time stamps
43242 are concerned.
43243
43244 @item O_EXCL
43245 When used with @code{O_CREAT}, if the file already exists it is
43246 an error and open() fails.
43247
43248 @item O_TRUNC
43249 If the file already exists and the open mode allows
43250 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43251 truncated to zero length.
43252
43253 @item O_APPEND
43254 The file is opened in append mode.
43255
43256 @item O_RDONLY
43257 The file is opened for reading only.
43258
43259 @item O_WRONLY
43260 The file is opened for writing only.
43261
43262 @item O_RDWR
43263 The file is opened for reading and writing.
43264 @end table
43265
43266 @noindent
43267 Other bits are silently ignored.
43268
43269
43270 @noindent
43271 @var{mode} is the bitwise @code{OR} of the following values:
43272
43273 @table @code
43274 @item S_IRUSR
43275 User has read permission.
43276
43277 @item S_IWUSR
43278 User has write permission.
43279
43280 @item S_IRGRP
43281 Group has read permission.
43282
43283 @item S_IWGRP
43284 Group has write permission.
43285
43286 @item S_IROTH
43287 Others have read permission.
43288
43289 @item S_IWOTH
43290 Others have write permission.
43291 @end table
43292
43293 @noindent
43294 Other bits are silently ignored.
43295
43296
43297 @item Return value:
43298 @code{open} returns the new file descriptor or -1 if an error
43299 occurred.
43300
43301 @item Errors:
43302
43303 @table @code
43304 @item EEXIST
43305 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
43306
43307 @item EISDIR
43308 @var{pathname} refers to a directory.
43309
43310 @item EACCES
43311 The requested access is not allowed.
43312
43313 @item ENAMETOOLONG
43314 @var{pathname} was too long.
43315
43316 @item ENOENT
43317 A directory component in @var{pathname} does not exist.
43318
43319 @item ENODEV
43320 @var{pathname} refers to a device, pipe, named pipe or socket.
43321
43322 @item EROFS
43323 @var{pathname} refers to a file on a read-only filesystem and
43324 write access was requested.
43325
43326 @item EFAULT
43327 @var{pathname} is an invalid pointer value.
43328
43329 @item ENOSPC
43330 No space on device to create the file.
43331
43332 @item EMFILE
43333 The process already has the maximum number of files open.
43334
43335 @item ENFILE
43336 The limit on the total number of files open on the system
43337 has been reached.
43338
43339 @item EINTR
43340 The call was interrupted by the user.
43341 @end table
43342
43343 @end table
43344
43345 @node close
43346 @unnumberedsubsubsec close
43347 @cindex close, file-i/o system call
43348
43349 @table @asis
43350 @item Synopsis:
43351 @smallexample
43352 int close(int fd);
43353 @end smallexample
43354
43355 @item Request:
43356 @samp{Fclose,@var{fd}}
43357
43358 @item Return value:
43359 @code{close} returns zero on success, or -1 if an error occurred.
43360
43361 @item Errors:
43362
43363 @table @code
43364 @item EBADF
43365 @var{fd} isn't a valid open file descriptor.
43366
43367 @item EINTR
43368 The call was interrupted by the user.
43369 @end table
43370
43371 @end table
43372
43373 @node read
43374 @unnumberedsubsubsec read
43375 @cindex read, file-i/o system call
43376
43377 @table @asis
43378 @item Synopsis:
43379 @smallexample
43380 int read(int fd, void *buf, unsigned int count);
43381 @end smallexample
43382
43383 @item Request:
43384 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
43385
43386 @item Return value:
43387 On success, the number of bytes read is returned.
43388 Zero indicates end of file. If count is zero, read
43389 returns zero as well. On error, -1 is returned.
43390
43391 @item Errors:
43392
43393 @table @code
43394 @item EBADF
43395 @var{fd} is not a valid file descriptor or is not open for
43396 reading.
43397
43398 @item EFAULT
43399 @var{bufptr} is an invalid pointer value.
43400
43401 @item EINTR
43402 The call was interrupted by the user.
43403 @end table
43404
43405 @end table
43406
43407 @node write
43408 @unnumberedsubsubsec write
43409 @cindex write, file-i/o system call
43410
43411 @table @asis
43412 @item Synopsis:
43413 @smallexample
43414 int write(int fd, const void *buf, unsigned int count);
43415 @end smallexample
43416
43417 @item Request:
43418 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
43419
43420 @item Return value:
43421 On success, the number of bytes written are returned.
43422 Zero indicates nothing was written. On error, -1
43423 is returned.
43424
43425 @item Errors:
43426
43427 @table @code
43428 @item EBADF
43429 @var{fd} is not a valid file descriptor or is not open for
43430 writing.
43431
43432 @item EFAULT
43433 @var{bufptr} is an invalid pointer value.
43434
43435 @item EFBIG
43436 An attempt was made to write a file that exceeds the
43437 host-specific maximum file size allowed.
43438
43439 @item ENOSPC
43440 No space on device to write the data.
43441
43442 @item EINTR
43443 The call was interrupted by the user.
43444 @end table
43445
43446 @end table
43447
43448 @node lseek
43449 @unnumberedsubsubsec lseek
43450 @cindex lseek, file-i/o system call
43451
43452 @table @asis
43453 @item Synopsis:
43454 @smallexample
43455 long lseek (int fd, long offset, int flag);
43456 @end smallexample
43457
43458 @item Request:
43459 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
43460
43461 @var{flag} is one of:
43462
43463 @table @code
43464 @item SEEK_SET
43465 The offset is set to @var{offset} bytes.
43466
43467 @item SEEK_CUR
43468 The offset is set to its current location plus @var{offset}
43469 bytes.
43470
43471 @item SEEK_END
43472 The offset is set to the size of the file plus @var{offset}
43473 bytes.
43474 @end table
43475
43476 @item Return value:
43477 On success, the resulting unsigned offset in bytes from
43478 the beginning of the file is returned. Otherwise, a
43479 value of -1 is returned.
43480
43481 @item Errors:
43482
43483 @table @code
43484 @item EBADF
43485 @var{fd} is not a valid open file descriptor.
43486
43487 @item ESPIPE
43488 @var{fd} is associated with the @value{GDBN} console.
43489
43490 @item EINVAL
43491 @var{flag} is not a proper value.
43492
43493 @item EINTR
43494 The call was interrupted by the user.
43495 @end table
43496
43497 @end table
43498
43499 @node rename
43500 @unnumberedsubsubsec rename
43501 @cindex rename, file-i/o system call
43502
43503 @table @asis
43504 @item Synopsis:
43505 @smallexample
43506 int rename(const char *oldpath, const char *newpath);
43507 @end smallexample
43508
43509 @item Request:
43510 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
43511
43512 @item Return value:
43513 On success, zero is returned. On error, -1 is returned.
43514
43515 @item Errors:
43516
43517 @table @code
43518 @item EISDIR
43519 @var{newpath} is an existing directory, but @var{oldpath} is not a
43520 directory.
43521
43522 @item EEXIST
43523 @var{newpath} is a non-empty directory.
43524
43525 @item EBUSY
43526 @var{oldpath} or @var{newpath} is a directory that is in use by some
43527 process.
43528
43529 @item EINVAL
43530 An attempt was made to make a directory a subdirectory
43531 of itself.
43532
43533 @item ENOTDIR
43534 A component used as a directory in @var{oldpath} or new
43535 path is not a directory. Or @var{oldpath} is a directory
43536 and @var{newpath} exists but is not a directory.
43537
43538 @item EFAULT
43539 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
43540
43541 @item EACCES
43542 No access to the file or the path of the file.
43543
43544 @item ENAMETOOLONG
43545
43546 @var{oldpath} or @var{newpath} was too long.
43547
43548 @item ENOENT
43549 A directory component in @var{oldpath} or @var{newpath} does not exist.
43550
43551 @item EROFS
43552 The file is on a read-only filesystem.
43553
43554 @item ENOSPC
43555 The device containing the file has no room for the new
43556 directory entry.
43557
43558 @item EINTR
43559 The call was interrupted by the user.
43560 @end table
43561
43562 @end table
43563
43564 @node unlink
43565 @unnumberedsubsubsec unlink
43566 @cindex unlink, file-i/o system call
43567
43568 @table @asis
43569 @item Synopsis:
43570 @smallexample
43571 int unlink(const char *pathname);
43572 @end smallexample
43573
43574 @item Request:
43575 @samp{Funlink,@var{pathnameptr}/@var{len}}
43576
43577 @item Return value:
43578 On success, zero is returned. On error, -1 is returned.
43579
43580 @item Errors:
43581
43582 @table @code
43583 @item EACCES
43584 No access to the file or the path of the file.
43585
43586 @item EPERM
43587 The system does not allow unlinking of directories.
43588
43589 @item EBUSY
43590 The file @var{pathname} cannot be unlinked because it's
43591 being used by another process.
43592
43593 @item EFAULT
43594 @var{pathnameptr} is an invalid pointer value.
43595
43596 @item ENAMETOOLONG
43597 @var{pathname} was too long.
43598
43599 @item ENOENT
43600 A directory component in @var{pathname} does not exist.
43601
43602 @item ENOTDIR
43603 A component of the path is not a directory.
43604
43605 @item EROFS
43606 The file is on a read-only filesystem.
43607
43608 @item EINTR
43609 The call was interrupted by the user.
43610 @end table
43611
43612 @end table
43613
43614 @node stat/fstat
43615 @unnumberedsubsubsec stat/fstat
43616 @cindex fstat, file-i/o system call
43617 @cindex stat, file-i/o system call
43618
43619 @table @asis
43620 @item Synopsis:
43621 @smallexample
43622 int stat(const char *pathname, struct stat *buf);
43623 int fstat(int fd, struct stat *buf);
43624 @end smallexample
43625
43626 @item Request:
43627 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43628 @samp{Ffstat,@var{fd},@var{bufptr}}
43629
43630 @item Return value:
43631 On success, zero is returned. On error, -1 is returned.
43632
43633 @item Errors:
43634
43635 @table @code
43636 @item EBADF
43637 @var{fd} is not a valid open file.
43638
43639 @item ENOENT
43640 A directory component in @var{pathname} does not exist or the
43641 path is an empty string.
43642
43643 @item ENOTDIR
43644 A component of the path is not a directory.
43645
43646 @item EFAULT
43647 @var{pathnameptr} is an invalid pointer value.
43648
43649 @item EACCES
43650 No access to the file or the path of the file.
43651
43652 @item ENAMETOOLONG
43653 @var{pathname} was too long.
43654
43655 @item EINTR
43656 The call was interrupted by the user.
43657 @end table
43658
43659 @end table
43660
43661 @node gettimeofday
43662 @unnumberedsubsubsec gettimeofday
43663 @cindex gettimeofday, file-i/o system call
43664
43665 @table @asis
43666 @item Synopsis:
43667 @smallexample
43668 int gettimeofday(struct timeval *tv, void *tz);
43669 @end smallexample
43670
43671 @item Request:
43672 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
43673
43674 @item Return value:
43675 On success, 0 is returned, -1 otherwise.
43676
43677 @item Errors:
43678
43679 @table @code
43680 @item EINVAL
43681 @var{tz} is a non-NULL pointer.
43682
43683 @item EFAULT
43684 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43685 @end table
43686
43687 @end table
43688
43689 @node isatty
43690 @unnumberedsubsubsec isatty
43691 @cindex isatty, file-i/o system call
43692
43693 @table @asis
43694 @item Synopsis:
43695 @smallexample
43696 int isatty(int fd);
43697 @end smallexample
43698
43699 @item Request:
43700 @samp{Fisatty,@var{fd}}
43701
43702 @item Return value:
43703 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
43704
43705 @item Errors:
43706
43707 @table @code
43708 @item EINTR
43709 The call was interrupted by the user.
43710 @end table
43711
43712 @end table
43713
43714 Note that the @code{isatty} call is treated as a special case: it returns
43715 1 to the target if the file descriptor is attached
43716 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43717 would require implementing @code{ioctl} and would be more complex than
43718 needed.
43719
43720
43721 @node system
43722 @unnumberedsubsubsec system
43723 @cindex system, file-i/o system call
43724
43725 @table @asis
43726 @item Synopsis:
43727 @smallexample
43728 int system(const char *command);
43729 @end smallexample
43730
43731 @item Request:
43732 @samp{Fsystem,@var{commandptr}/@var{len}}
43733
43734 @item Return value:
43735 If @var{len} is zero, the return value indicates whether a shell is
43736 available. A zero return value indicates a shell is not available.
43737 For non-zero @var{len}, the value returned is -1 on error and the
43738 return status of the command otherwise. Only the exit status of the
43739 command is returned, which is extracted from the host's @code{system}
43740 return value by calling @code{WEXITSTATUS(retval)}. In case
43741 @file{/bin/sh} could not be executed, 127 is returned.
43742
43743 @item Errors:
43744
43745 @table @code
43746 @item EINTR
43747 The call was interrupted by the user.
43748 @end table
43749
43750 @end table
43751
43752 @value{GDBN} takes over the full task of calling the necessary host calls
43753 to perform the @code{system} call. The return value of @code{system} on
43754 the host is simplified before it's returned
43755 to the target. Any termination signal information from the child process
43756 is discarded, and the return value consists
43757 entirely of the exit status of the called command.
43758
43759 Due to security concerns, the @code{system} call is by default refused
43760 by @value{GDBN}. The user has to allow this call explicitly with the
43761 @code{set remote system-call-allowed 1} command.
43762
43763 @table @code
43764 @item set remote system-call-allowed
43765 @kindex set remote system-call-allowed
43766 Control whether to allow the @code{system} calls in the File I/O
43767 protocol for the remote target. The default is zero (disabled).
43768
43769 @item show remote system-call-allowed
43770 @kindex show remote system-call-allowed
43771 Show whether the @code{system} calls are allowed in the File I/O
43772 protocol.
43773 @end table
43774
43775 @node Protocol-specific Representation of Datatypes
43776 @subsection Protocol-specific Representation of Datatypes
43777 @cindex protocol-specific representation of datatypes, in file-i/o protocol
43778
43779 @menu
43780 * Integral Datatypes::
43781 * Pointer Values::
43782 * Memory Transfer::
43783 * struct stat::
43784 * struct timeval::
43785 @end menu
43786
43787 @node Integral Datatypes
43788 @unnumberedsubsubsec Integral Datatypes
43789 @cindex integral datatypes, in file-i/o protocol
43790
43791 The integral datatypes used in the system calls are @code{int},
43792 @code{unsigned int}, @code{long}, @code{unsigned long},
43793 @code{mode_t}, and @code{time_t}.
43794
43795 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
43796 implemented as 32 bit values in this protocol.
43797
43798 @code{long} and @code{unsigned long} are implemented as 64 bit types.
43799
43800 @xref{Limits}, for corresponding MIN and MAX values (similar to those
43801 in @file{limits.h}) to allow range checking on host and target.
43802
43803 @code{time_t} datatypes are defined as seconds since the Epoch.
43804
43805 All integral datatypes transferred as part of a memory read or write of a
43806 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43807 byte order.
43808
43809 @node Pointer Values
43810 @unnumberedsubsubsec Pointer Values
43811 @cindex pointer values, in file-i/o protocol
43812
43813 Pointers to target data are transmitted as they are. An exception
43814 is made for pointers to buffers for which the length isn't
43815 transmitted as part of the function call, namely strings. Strings
43816 are transmitted as a pointer/length pair, both as hex values, e.g.@:
43817
43818 @smallexample
43819 @code{1aaf/12}
43820 @end smallexample
43821
43822 @noindent
43823 which is a pointer to data of length 18 bytes at position 0x1aaf.
43824 The length is defined as the full string length in bytes, including
43825 the trailing null byte. For example, the string @code{"hello world"}
43826 at address 0x123456 is transmitted as
43827
43828 @smallexample
43829 @code{123456/d}
43830 @end smallexample
43831
43832 @node Memory Transfer
43833 @unnumberedsubsubsec Memory Transfer
43834 @cindex memory transfer, in file-i/o protocol
43835
43836 Structured data which is transferred using a memory read or write (for
43837 example, a @code{struct stat}) is expected to be in a protocol-specific format
43838 with all scalar multibyte datatypes being big endian. Translation to
43839 this representation needs to be done both by the target before the @code{F}
43840 packet is sent, and by @value{GDBN} before
43841 it transfers memory to the target. Transferred pointers to structured
43842 data should point to the already-coerced data at any time.
43843
43844
43845 @node struct stat
43846 @unnumberedsubsubsec struct stat
43847 @cindex struct stat, in file-i/o protocol
43848
43849 The buffer of type @code{struct stat} used by the target and @value{GDBN}
43850 is defined as follows:
43851
43852 @smallexample
43853 struct stat @{
43854 unsigned int st_dev; /* device */
43855 unsigned int st_ino; /* inode */
43856 mode_t st_mode; /* protection */
43857 unsigned int st_nlink; /* number of hard links */
43858 unsigned int st_uid; /* user ID of owner */
43859 unsigned int st_gid; /* group ID of owner */
43860 unsigned int st_rdev; /* device type (if inode device) */
43861 unsigned long st_size; /* total size, in bytes */
43862 unsigned long st_blksize; /* blocksize for filesystem I/O */
43863 unsigned long st_blocks; /* number of blocks allocated */
43864 time_t st_atime; /* time of last access */
43865 time_t st_mtime; /* time of last modification */
43866 time_t st_ctime; /* time of last change */
43867 @};
43868 @end smallexample
43869
43870 The integral datatypes conform to the definitions given in the
43871 appropriate section (see @ref{Integral Datatypes}, for details) so this
43872 structure is of size 64 bytes.
43873
43874 The values of several fields have a restricted meaning and/or
43875 range of values.
43876
43877 @table @code
43878
43879 @item st_dev
43880 A value of 0 represents a file, 1 the console.
43881
43882 @item st_ino
43883 No valid meaning for the target. Transmitted unchanged.
43884
43885 @item st_mode
43886 Valid mode bits are described in @ref{Constants}. Any other
43887 bits have currently no meaning for the target.
43888
43889 @item st_uid
43890 @itemx st_gid
43891 @itemx st_rdev
43892 No valid meaning for the target. Transmitted unchanged.
43893
43894 @item st_atime
43895 @itemx st_mtime
43896 @itemx st_ctime
43897 These values have a host and file system dependent
43898 accuracy. Especially on Windows hosts, the file system may not
43899 support exact timing values.
43900 @end table
43901
43902 The target gets a @code{struct stat} of the above representation and is
43903 responsible for coercing it to the target representation before
43904 continuing.
43905
43906 Note that due to size differences between the host, target, and protocol
43907 representations of @code{struct stat} members, these members could eventually
43908 get truncated on the target.
43909
43910 @node struct timeval
43911 @unnumberedsubsubsec struct timeval
43912 @cindex struct timeval, in file-i/o protocol
43913
43914 The buffer of type @code{struct timeval} used by the File-I/O protocol
43915 is defined as follows:
43916
43917 @smallexample
43918 struct timeval @{
43919 time_t tv_sec; /* second */
43920 long tv_usec; /* microsecond */
43921 @};
43922 @end smallexample
43923
43924 The integral datatypes conform to the definitions given in the
43925 appropriate section (see @ref{Integral Datatypes}, for details) so this
43926 structure is of size 8 bytes.
43927
43928 @node Constants
43929 @subsection Constants
43930 @cindex constants, in file-i/o protocol
43931
43932 The following values are used for the constants inside of the
43933 protocol. @value{GDBN} and target are responsible for translating these
43934 values before and after the call as needed.
43935
43936 @menu
43937 * Open Flags::
43938 * mode_t Values::
43939 * Errno Values::
43940 * Lseek Flags::
43941 * Limits::
43942 @end menu
43943
43944 @node Open Flags
43945 @unnumberedsubsubsec Open Flags
43946 @cindex open flags, in file-i/o protocol
43947
43948 All values are given in hexadecimal representation.
43949
43950 @smallexample
43951 O_RDONLY 0x0
43952 O_WRONLY 0x1
43953 O_RDWR 0x2
43954 O_APPEND 0x8
43955 O_CREAT 0x200
43956 O_TRUNC 0x400
43957 O_EXCL 0x800
43958 @end smallexample
43959
43960 @node mode_t Values
43961 @unnumberedsubsubsec mode_t Values
43962 @cindex mode_t values, in file-i/o protocol
43963
43964 All values are given in octal representation.
43965
43966 @smallexample
43967 S_IFREG 0100000
43968 S_IFDIR 040000
43969 S_IRUSR 0400
43970 S_IWUSR 0200
43971 S_IXUSR 0100
43972 S_IRGRP 040
43973 S_IWGRP 020
43974 S_IXGRP 010
43975 S_IROTH 04
43976 S_IWOTH 02
43977 S_IXOTH 01
43978 @end smallexample
43979
43980 @node Errno Values
43981 @unnumberedsubsubsec Errno Values
43982 @cindex errno values, in file-i/o protocol
43983
43984 All values are given in decimal representation.
43985
43986 @smallexample
43987 EPERM 1
43988 ENOENT 2
43989 EINTR 4
43990 EBADF 9
43991 EACCES 13
43992 EFAULT 14
43993 EBUSY 16
43994 EEXIST 17
43995 ENODEV 19
43996 ENOTDIR 20
43997 EISDIR 21
43998 EINVAL 22
43999 ENFILE 23
44000 EMFILE 24
44001 EFBIG 27
44002 ENOSPC 28
44003 ESPIPE 29
44004 EROFS 30
44005 ENAMETOOLONG 91
44006 EUNKNOWN 9999
44007 @end smallexample
44008
44009 @code{EUNKNOWN} is used as a fallback error value if a host system returns
44010 any error value not in the list of supported error numbers.
44011
44012 @node Lseek Flags
44013 @unnumberedsubsubsec Lseek Flags
44014 @cindex lseek flags, in file-i/o protocol
44015
44016 @smallexample
44017 SEEK_SET 0
44018 SEEK_CUR 1
44019 SEEK_END 2
44020 @end smallexample
44021
44022 @node Limits
44023 @unnumberedsubsubsec Limits
44024 @cindex limits, in file-i/o protocol
44025
44026 All values are given in decimal representation.
44027
44028 @smallexample
44029 INT_MIN -2147483648
44030 INT_MAX 2147483647
44031 UINT_MAX 4294967295
44032 LONG_MIN -9223372036854775808
44033 LONG_MAX 9223372036854775807
44034 ULONG_MAX 18446744073709551615
44035 @end smallexample
44036
44037 @node File-I/O Examples
44038 @subsection File-I/O Examples
44039 @cindex file-i/o examples
44040
44041 Example sequence of a write call, file descriptor 3, buffer is at target
44042 address 0x1234, 6 bytes should be written:
44043
44044 @smallexample
44045 <- @code{Fwrite,3,1234,6}
44046 @emph{request memory read from target}
44047 -> @code{m1234,6}
44048 <- XXXXXX
44049 @emph{return "6 bytes written"}
44050 -> @code{F6}
44051 @end smallexample
44052
44053 Example sequence of a read call, file descriptor 3, buffer is at target
44054 address 0x1234, 6 bytes should be read:
44055
44056 @smallexample
44057 <- @code{Fread,3,1234,6}
44058 @emph{request memory write to target}
44059 -> @code{X1234,6:XXXXXX}
44060 @emph{return "6 bytes read"}
44061 -> @code{F6}
44062 @end smallexample
44063
44064 Example sequence of a read call, call fails on the host due to invalid
44065 file descriptor (@code{EBADF}):
44066
44067 @smallexample
44068 <- @code{Fread,3,1234,6}
44069 -> @code{F-1,9}
44070 @end smallexample
44071
44072 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44073 host is called:
44074
44075 @smallexample
44076 <- @code{Fread,3,1234,6}
44077 -> @code{F-1,4,C}
44078 <- @code{T02}
44079 @end smallexample
44080
44081 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44082 host is called:
44083
44084 @smallexample
44085 <- @code{Fread,3,1234,6}
44086 -> @code{X1234,6:XXXXXX}
44087 <- @code{T02}
44088 @end smallexample
44089
44090 @node Library List Format
44091 @section Library List Format
44092 @cindex library list format, remote protocol
44093
44094 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44095 same process as your application to manage libraries. In this case,
44096 @value{GDBN} can use the loader's symbol table and normal memory
44097 operations to maintain a list of shared libraries. On other
44098 platforms, the operating system manages loaded libraries.
44099 @value{GDBN} can not retrieve the list of currently loaded libraries
44100 through memory operations, so it uses the @samp{qXfer:libraries:read}
44101 packet (@pxref{qXfer library list read}) instead. The remote stub
44102 queries the target's operating system and reports which libraries
44103 are loaded.
44104
44105 The @samp{qXfer:libraries:read} packet returns an XML document which
44106 lists loaded libraries and their offsets. Each library has an
44107 associated name and one or more segment or section base addresses,
44108 which report where the library was loaded in memory.
44109
44110 For the common case of libraries that are fully linked binaries, the
44111 library should have a list of segments. If the target supports
44112 dynamic linking of a relocatable object file, its library XML element
44113 should instead include a list of allocated sections. The segment or
44114 section bases are start addresses, not relocation offsets; they do not
44115 depend on the library's link-time base addresses.
44116
44117 @value{GDBN} must be linked with the Expat library to support XML
44118 library lists. @xref{Expat}.
44119
44120 A simple memory map, with one loaded library relocated by a single
44121 offset, looks like this:
44122
44123 @smallexample
44124 <library-list>
44125 <library name="/lib/libc.so.6">
44126 <segment address="0x10000000"/>
44127 </library>
44128 </library-list>
44129 @end smallexample
44130
44131 Another simple memory map, with one loaded library with three
44132 allocated sections (.text, .data, .bss), looks like this:
44133
44134 @smallexample
44135 <library-list>
44136 <library name="sharedlib.o">
44137 <section address="0x10000000"/>
44138 <section address="0x20000000"/>
44139 <section address="0x30000000"/>
44140 </library>
44141 </library-list>
44142 @end smallexample
44143
44144 The format of a library list is described by this DTD:
44145
44146 @smallexample
44147 <!-- library-list: Root element with versioning -->
44148 <!ELEMENT library-list (library)*>
44149 <!ATTLIST library-list version CDATA #FIXED "1.0">
44150 <!ELEMENT library (segment*, section*)>
44151 <!ATTLIST library name CDATA #REQUIRED>
44152 <!ELEMENT segment EMPTY>
44153 <!ATTLIST segment address CDATA #REQUIRED>
44154 <!ELEMENT section EMPTY>
44155 <!ATTLIST section address CDATA #REQUIRED>
44156 @end smallexample
44157
44158 In addition, segments and section descriptors cannot be mixed within a
44159 single library element, and you must supply at least one segment or
44160 section for each library.
44161
44162 @node Library List Format for SVR4 Targets
44163 @section Library List Format for SVR4 Targets
44164 @cindex library list format, remote protocol
44165
44166 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44167 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44168 shared libraries. Still a special library list provided by this packet is
44169 more efficient for the @value{GDBN} remote protocol.
44170
44171 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44172 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44173 target, the following parameters are reported:
44174
44175 @itemize @minus
44176 @item
44177 @code{name}, the absolute file name from the @code{l_name} field of
44178 @code{struct link_map}.
44179 @item
44180 @code{lm} with address of @code{struct link_map} used for TLS
44181 (Thread Local Storage) access.
44182 @item
44183 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44184 @code{struct link_map}. For prelinked libraries this is not an absolute
44185 memory address. It is a displacement of absolute memory address against
44186 address the file was prelinked to during the library load.
44187 @item
44188 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44189 @end itemize
44190
44191 Additionally the single @code{main-lm} attribute specifies address of
44192 @code{struct link_map} used for the main executable. This parameter is used
44193 for TLS access and its presence is optional.
44194
44195 @value{GDBN} must be linked with the Expat library to support XML
44196 SVR4 library lists. @xref{Expat}.
44197
44198 A simple memory map, with two loaded libraries (which do not use prelink),
44199 looks like this:
44200
44201 @smallexample
44202 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44203 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44204 l_ld="0xe4eefc"/>
44205 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
44206 l_ld="0x152350"/>
44207 </library-list-svr>
44208 @end smallexample
44209
44210 The format of an SVR4 library list is described by this DTD:
44211
44212 @smallexample
44213 <!-- library-list-svr4: Root element with versioning -->
44214 <!ELEMENT library-list-svr4 (library)*>
44215 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44216 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
44217 <!ELEMENT library EMPTY>
44218 <!ATTLIST library name CDATA #REQUIRED>
44219 <!ATTLIST library lm CDATA #REQUIRED>
44220 <!ATTLIST library l_addr CDATA #REQUIRED>
44221 <!ATTLIST library l_ld CDATA #REQUIRED>
44222 @end smallexample
44223
44224 @node Memory Map Format
44225 @section Memory Map Format
44226 @cindex memory map format
44227
44228 To be able to write into flash memory, @value{GDBN} needs to obtain a
44229 memory map from the target. This section describes the format of the
44230 memory map.
44231
44232 The memory map is obtained using the @samp{qXfer:memory-map:read}
44233 (@pxref{qXfer memory map read}) packet and is an XML document that
44234 lists memory regions.
44235
44236 @value{GDBN} must be linked with the Expat library to support XML
44237 memory maps. @xref{Expat}.
44238
44239 The top-level structure of the document is shown below:
44240
44241 @smallexample
44242 <?xml version="1.0"?>
44243 <!DOCTYPE memory-map
44244 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44245 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44246 <memory-map>
44247 region...
44248 </memory-map>
44249 @end smallexample
44250
44251 Each region can be either:
44252
44253 @itemize
44254
44255 @item
44256 A region of RAM starting at @var{addr} and extending for @var{length}
44257 bytes from there:
44258
44259 @smallexample
44260 <memory type="ram" start="@var{addr}" length="@var{length}"/>
44261 @end smallexample
44262
44263
44264 @item
44265 A region of read-only memory:
44266
44267 @smallexample
44268 <memory type="rom" start="@var{addr}" length="@var{length}"/>
44269 @end smallexample
44270
44271
44272 @item
44273 A region of flash memory, with erasure blocks @var{blocksize}
44274 bytes in length:
44275
44276 @smallexample
44277 <memory type="flash" start="@var{addr}" length="@var{length}">
44278 <property name="blocksize">@var{blocksize}</property>
44279 </memory>
44280 @end smallexample
44281
44282 @end itemize
44283
44284 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44285 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44286 packets to write to addresses in such ranges.
44287
44288 The formal DTD for memory map format is given below:
44289
44290 @smallexample
44291 <!-- ................................................... -->
44292 <!-- Memory Map XML DTD ................................ -->
44293 <!-- File: memory-map.dtd .............................. -->
44294 <!-- .................................... .............. -->
44295 <!-- memory-map.dtd -->
44296 <!-- memory-map: Root element with versioning -->
44297 <!ELEMENT memory-map (memory)*>
44298 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
44299 <!ELEMENT memory (property)*>
44300 <!-- memory: Specifies a memory region,
44301 and its type, or device. -->
44302 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
44303 start CDATA #REQUIRED
44304 length CDATA #REQUIRED>
44305 <!-- property: Generic attribute tag -->
44306 <!ELEMENT property (#PCDATA | property)*>
44307 <!ATTLIST property name (blocksize) #REQUIRED>
44308 @end smallexample
44309
44310 @node Thread List Format
44311 @section Thread List Format
44312 @cindex thread list format
44313
44314 To efficiently update the list of threads and their attributes,
44315 @value{GDBN} issues the @samp{qXfer:threads:read} packet
44316 (@pxref{qXfer threads read}) and obtains the XML document with
44317 the following structure:
44318
44319 @smallexample
44320 <?xml version="1.0"?>
44321 <threads>
44322 <thread id="id" core="0" name="name">
44323 ... description ...
44324 </thread>
44325 </threads>
44326 @end smallexample
44327
44328 Each @samp{thread} element must have the @samp{id} attribute that
44329 identifies the thread (@pxref{thread-id syntax}). The
44330 @samp{core} attribute, if present, specifies which processor core
44331 the thread was last executing on. The @samp{name} attribute, if
44332 present, specifies the human-readable name of the thread. The content
44333 of the of @samp{thread} element is interpreted as human-readable
44334 auxiliary information. The @samp{handle} attribute, if present,
44335 is a hex encoded representation of the thread handle.
44336
44337
44338 @node Traceframe Info Format
44339 @section Traceframe Info Format
44340 @cindex traceframe info format
44341
44342 To be able to know which objects in the inferior can be examined when
44343 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44344 memory ranges, registers and trace state variables that have been
44345 collected in a traceframe.
44346
44347 This list is obtained using the @samp{qXfer:traceframe-info:read}
44348 (@pxref{qXfer traceframe info read}) packet and is an XML document.
44349
44350 @value{GDBN} must be linked with the Expat library to support XML
44351 traceframe info discovery. @xref{Expat}.
44352
44353 The top-level structure of the document is shown below:
44354
44355 @smallexample
44356 <?xml version="1.0"?>
44357 <!DOCTYPE traceframe-info
44358 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44359 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44360 <traceframe-info>
44361 block...
44362 </traceframe-info>
44363 @end smallexample
44364
44365 Each traceframe block can be either:
44366
44367 @itemize
44368
44369 @item
44370 A region of collected memory starting at @var{addr} and extending for
44371 @var{length} bytes from there:
44372
44373 @smallexample
44374 <memory start="@var{addr}" length="@var{length}"/>
44375 @end smallexample
44376
44377 @item
44378 A block indicating trace state variable numbered @var{number} has been
44379 collected:
44380
44381 @smallexample
44382 <tvar id="@var{number}"/>
44383 @end smallexample
44384
44385 @end itemize
44386
44387 The formal DTD for the traceframe info format is given below:
44388
44389 @smallexample
44390 <!ELEMENT traceframe-info (memory | tvar)* >
44391 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44392
44393 <!ELEMENT memory EMPTY>
44394 <!ATTLIST memory start CDATA #REQUIRED
44395 length CDATA #REQUIRED>
44396 <!ELEMENT tvar>
44397 <!ATTLIST tvar id CDATA #REQUIRED>
44398 @end smallexample
44399
44400 @node Branch Trace Format
44401 @section Branch Trace Format
44402 @cindex branch trace format
44403
44404 In order to display the branch trace of an inferior thread,
44405 @value{GDBN} needs to obtain the list of branches. This list is
44406 represented as list of sequential code blocks that are connected via
44407 branches. The code in each block has been executed sequentially.
44408
44409 This list is obtained using the @samp{qXfer:btrace:read}
44410 (@pxref{qXfer btrace read}) packet and is an XML document.
44411
44412 @value{GDBN} must be linked with the Expat library to support XML
44413 traceframe info discovery. @xref{Expat}.
44414
44415 The top-level structure of the document is shown below:
44416
44417 @smallexample
44418 <?xml version="1.0"?>
44419 <!DOCTYPE btrace
44420 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44421 "http://sourceware.org/gdb/gdb-btrace.dtd">
44422 <btrace>
44423 block...
44424 </btrace>
44425 @end smallexample
44426
44427 @itemize
44428
44429 @item
44430 A block of sequentially executed instructions starting at @var{begin}
44431 and ending at @var{end}:
44432
44433 @smallexample
44434 <block begin="@var{begin}" end="@var{end}"/>
44435 @end smallexample
44436
44437 @end itemize
44438
44439 The formal DTD for the branch trace format is given below:
44440
44441 @smallexample
44442 <!ELEMENT btrace (block* | pt) >
44443 <!ATTLIST btrace version CDATA #FIXED "1.0">
44444
44445 <!ELEMENT block EMPTY>
44446 <!ATTLIST block begin CDATA #REQUIRED
44447 end CDATA #REQUIRED>
44448
44449 <!ELEMENT pt (pt-config?, raw?)>
44450
44451 <!ELEMENT pt-config (cpu?)>
44452
44453 <!ELEMENT cpu EMPTY>
44454 <!ATTLIST cpu vendor CDATA #REQUIRED
44455 family CDATA #REQUIRED
44456 model CDATA #REQUIRED
44457 stepping CDATA #REQUIRED>
44458
44459 <!ELEMENT raw (#PCDATA)>
44460 @end smallexample
44461
44462 @node Branch Trace Configuration Format
44463 @section Branch Trace Configuration Format
44464 @cindex branch trace configuration format
44465
44466 For each inferior thread, @value{GDBN} can obtain the branch trace
44467 configuration using the @samp{qXfer:btrace-conf:read}
44468 (@pxref{qXfer btrace-conf read}) packet.
44469
44470 The configuration describes the branch trace format and configuration
44471 settings for that format. The following information is described:
44472
44473 @table @code
44474 @item bts
44475 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44476 @table @code
44477 @item size
44478 The size of the @acronym{BTS} ring buffer in bytes.
44479 @end table
44480 @item pt
44481 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
44482 PT}) format.
44483 @table @code
44484 @item size
44485 The size of the @acronym{Intel PT} ring buffer in bytes.
44486 @end table
44487 @end table
44488
44489 @value{GDBN} must be linked with the Expat library to support XML
44490 branch trace configuration discovery. @xref{Expat}.
44491
44492 The formal DTD for the branch trace configuration format is given below:
44493
44494 @smallexample
44495 <!ELEMENT btrace-conf (bts?, pt?)>
44496 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44497
44498 <!ELEMENT bts EMPTY>
44499 <!ATTLIST bts size CDATA #IMPLIED>
44500
44501 <!ELEMENT pt EMPTY>
44502 <!ATTLIST pt size CDATA #IMPLIED>
44503 @end smallexample
44504
44505 @include agentexpr.texi
44506
44507 @node Target Descriptions
44508 @appendix Target Descriptions
44509 @cindex target descriptions
44510
44511 One of the challenges of using @value{GDBN} to debug embedded systems
44512 is that there are so many minor variants of each processor
44513 architecture in use. It is common practice for vendors to start with
44514 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
44515 and then make changes to adapt it to a particular market niche. Some
44516 architectures have hundreds of variants, available from dozens of
44517 vendors. This leads to a number of problems:
44518
44519 @itemize @bullet
44520 @item
44521 With so many different customized processors, it is difficult for
44522 the @value{GDBN} maintainers to keep up with the changes.
44523 @item
44524 Since individual variants may have short lifetimes or limited
44525 audiences, it may not be worthwhile to carry information about every
44526 variant in the @value{GDBN} source tree.
44527 @item
44528 When @value{GDBN} does support the architecture of the embedded system
44529 at hand, the task of finding the correct architecture name to give the
44530 @command{set architecture} command can be error-prone.
44531 @end itemize
44532
44533 To address these problems, the @value{GDBN} remote protocol allows a
44534 target system to not only identify itself to @value{GDBN}, but to
44535 actually describe its own features. This lets @value{GDBN} support
44536 processor variants it has never seen before --- to the extent that the
44537 descriptions are accurate, and that @value{GDBN} understands them.
44538
44539 @value{GDBN} must be linked with the Expat library to support XML
44540 target descriptions. @xref{Expat}.
44541
44542 @menu
44543 * Retrieving Descriptions:: How descriptions are fetched from a target.
44544 * Target Description Format:: The contents of a target description.
44545 * Predefined Target Types:: Standard types available for target
44546 descriptions.
44547 * Enum Target Types:: How to define enum target types.
44548 * Standard Target Features:: Features @value{GDBN} knows about.
44549 @end menu
44550
44551 @node Retrieving Descriptions
44552 @section Retrieving Descriptions
44553
44554 Target descriptions can be read from the target automatically, or
44555 specified by the user manually. The default behavior is to read the
44556 description from the target. @value{GDBN} retrieves it via the remote
44557 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44558 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44559 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
44560 XML document, of the form described in @ref{Target Description
44561 Format}.
44562
44563 Alternatively, you can specify a file to read for the target description.
44564 If a file is set, the target will not be queried. The commands to
44565 specify a file are:
44566
44567 @table @code
44568 @cindex set tdesc filename
44569 @item set tdesc filename @var{path}
44570 Read the target description from @var{path}.
44571
44572 @cindex unset tdesc filename
44573 @item unset tdesc filename
44574 Do not read the XML target description from a file. @value{GDBN}
44575 will use the description supplied by the current target.
44576
44577 @cindex show tdesc filename
44578 @item show tdesc filename
44579 Show the filename to read for a target description, if any.
44580 @end table
44581
44582
44583 @node Target Description Format
44584 @section Target Description Format
44585 @cindex target descriptions, XML format
44586
44587 A target description annex is an @uref{http://www.w3.org/XML/, XML}
44588 document which complies with the Document Type Definition provided in
44589 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44590 means you can use generally available tools like @command{xmllint} to
44591 check that your feature descriptions are well-formed and valid.
44592 However, to help people unfamiliar with XML write descriptions for
44593 their targets, we also describe the grammar here.
44594
44595 Target descriptions can identify the architecture of the remote target
44596 and (for some architectures) provide information about custom register
44597 sets. They can also identify the OS ABI of the remote target.
44598 @value{GDBN} can use this information to autoconfigure for your
44599 target, or to warn you if you connect to an unsupported target.
44600
44601 Here is a simple target description:
44602
44603 @smallexample
44604 <target version="1.0">
44605 <architecture>i386:x86-64</architecture>
44606 </target>
44607 @end smallexample
44608
44609 @noindent
44610 This minimal description only says that the target uses
44611 the x86-64 architecture.
44612
44613 A target description has the following overall form, with [ ] marking
44614 optional elements and @dots{} marking repeatable elements. The elements
44615 are explained further below.
44616
44617 @smallexample
44618 <?xml version="1.0"?>
44619 <!DOCTYPE target SYSTEM "gdb-target.dtd">
44620 <target version="1.0">
44621 @r{[}@var{architecture}@r{]}
44622 @r{[}@var{osabi}@r{]}
44623 @r{[}@var{compatible}@r{]}
44624 @r{[}@var{feature}@dots{}@r{]}
44625 </target>
44626 @end smallexample
44627
44628 @noindent
44629 The description is generally insensitive to whitespace and line
44630 breaks, under the usual common-sense rules. The XML version
44631 declaration and document type declaration can generally be omitted
44632 (@value{GDBN} does not require them), but specifying them may be
44633 useful for XML validation tools. The @samp{version} attribute for
44634 @samp{<target>} may also be omitted, but we recommend
44635 including it; if future versions of @value{GDBN} use an incompatible
44636 revision of @file{gdb-target.dtd}, they will detect and report
44637 the version mismatch.
44638
44639 @subsection Inclusion
44640 @cindex target descriptions, inclusion
44641 @cindex XInclude
44642 @ifnotinfo
44643 @cindex <xi:include>
44644 @end ifnotinfo
44645
44646 It can sometimes be valuable to split a target description up into
44647 several different annexes, either for organizational purposes, or to
44648 share files between different possible target descriptions. You can
44649 divide a description into multiple files by replacing any element of
44650 the target description with an inclusion directive of the form:
44651
44652 @smallexample
44653 <xi:include href="@var{document}"/>
44654 @end smallexample
44655
44656 @noindent
44657 When @value{GDBN} encounters an element of this form, it will retrieve
44658 the named XML @var{document}, and replace the inclusion directive with
44659 the contents of that document. If the current description was read
44660 using @samp{qXfer}, then so will be the included document;
44661 @var{document} will be interpreted as the name of an annex. If the
44662 current description was read from a file, @value{GDBN} will look for
44663 @var{document} as a file in the same directory where it found the
44664 original description.
44665
44666 @subsection Architecture
44667 @cindex <architecture>
44668
44669 An @samp{<architecture>} element has this form:
44670
44671 @smallexample
44672 <architecture>@var{arch}</architecture>
44673 @end smallexample
44674
44675 @var{arch} is one of the architectures from the set accepted by
44676 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44677
44678 @subsection OS ABI
44679 @cindex @code{<osabi>}
44680
44681 This optional field was introduced in @value{GDBN} version 7.0.
44682 Previous versions of @value{GDBN} ignore it.
44683
44684 An @samp{<osabi>} element has this form:
44685
44686 @smallexample
44687 <osabi>@var{abi-name}</osabi>
44688 @end smallexample
44689
44690 @var{abi-name} is an OS ABI name from the same selection accepted by
44691 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44692
44693 @subsection Compatible Architecture
44694 @cindex @code{<compatible>}
44695
44696 This optional field was introduced in @value{GDBN} version 7.0.
44697 Previous versions of @value{GDBN} ignore it.
44698
44699 A @samp{<compatible>} element has this form:
44700
44701 @smallexample
44702 <compatible>@var{arch}</compatible>
44703 @end smallexample
44704
44705 @var{arch} is one of the architectures from the set accepted by
44706 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44707
44708 A @samp{<compatible>} element is used to specify that the target
44709 is able to run binaries in some other than the main target architecture
44710 given by the @samp{<architecture>} element. For example, on the
44711 Cell Broadband Engine, the main architecture is @code{powerpc:common}
44712 or @code{powerpc:common64}, but the system is able to run binaries
44713 in the @code{spu} architecture as well. The way to describe this
44714 capability with @samp{<compatible>} is as follows:
44715
44716 @smallexample
44717 <architecture>powerpc:common</architecture>
44718 <compatible>spu</compatible>
44719 @end smallexample
44720
44721 @subsection Features
44722 @cindex <feature>
44723
44724 Each @samp{<feature>} describes some logical portion of the target
44725 system. Features are currently used to describe available CPU
44726 registers and the types of their contents. A @samp{<feature>} element
44727 has this form:
44728
44729 @smallexample
44730 <feature name="@var{name}">
44731 @r{[}@var{type}@dots{}@r{]}
44732 @var{reg}@dots{}
44733 </feature>
44734 @end smallexample
44735
44736 @noindent
44737 Each feature's name should be unique within the description. The name
44738 of a feature does not matter unless @value{GDBN} has some special
44739 knowledge of the contents of that feature; if it does, the feature
44740 should have its standard name. @xref{Standard Target Features}.
44741
44742 @subsection Types
44743
44744 Any register's value is a collection of bits which @value{GDBN} must
44745 interpret. The default interpretation is a two's complement integer,
44746 but other types can be requested by name in the register description.
44747 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
44748 Target Types}), and the description can define additional composite
44749 and enum types.
44750
44751 Each type element must have an @samp{id} attribute, which gives
44752 a unique (within the containing @samp{<feature>}) name to the type.
44753 Types must be defined before they are used.
44754
44755 @cindex <vector>
44756 Some targets offer vector registers, which can be treated as arrays
44757 of scalar elements. These types are written as @samp{<vector>} elements,
44758 specifying the array element type, @var{type}, and the number of elements,
44759 @var{count}:
44760
44761 @smallexample
44762 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44763 @end smallexample
44764
44765 @cindex <union>
44766 If a register's value is usefully viewed in multiple ways, define it
44767 with a union type containing the useful representations. The
44768 @samp{<union>} element contains one or more @samp{<field>} elements,
44769 each of which has a @var{name} and a @var{type}:
44770
44771 @smallexample
44772 <union id="@var{id}">
44773 <field name="@var{name}" type="@var{type}"/>
44774 @dots{}
44775 </union>
44776 @end smallexample
44777
44778 @cindex <struct>
44779 @cindex <flags>
44780 If a register's value is composed from several separate values, define
44781 it with either a structure type or a flags type.
44782 A flags type may only contain bitfields.
44783 A structure type may either contain only bitfields or contain no bitfields.
44784 If the value contains only bitfields, its total size in bytes must be
44785 specified.
44786
44787 Non-bitfield values have a @var{name} and @var{type}.
44788
44789 @smallexample
44790 <struct id="@var{id}">
44791 <field name="@var{name}" type="@var{type}"/>
44792 @dots{}
44793 </struct>
44794 @end smallexample
44795
44796 Both @var{name} and @var{type} values are required.
44797 No implicit padding is added.
44798
44799 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
44800
44801 @smallexample
44802 <struct id="@var{id}" size="@var{size}">
44803 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44804 @dots{}
44805 </struct>
44806 @end smallexample
44807
44808 @smallexample
44809 <flags id="@var{id}" size="@var{size}">
44810 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44811 @dots{}
44812 </flags>
44813 @end smallexample
44814
44815 The @var{name} value is required.
44816 Bitfield values may be named with the empty string, @samp{""},
44817 in which case the field is ``filler'' and its value is not printed.
44818 Not all bits need to be specified, so ``filler'' fields are optional.
44819
44820 The @var{start} and @var{end} values are required, and @var{type}
44821 is optional.
44822 The field's @var{start} must be less than or equal to its @var{end},
44823 and zero represents the least significant bit.
44824
44825 The default value of @var{type} is @code{bool} for single bit fields,
44826 and an unsigned integer otherwise.
44827
44828 Which to choose? Structures or flags?
44829
44830 Registers defined with @samp{flags} have these advantages over
44831 defining them with @samp{struct}:
44832
44833 @itemize @bullet
44834 @item
44835 Arithmetic may be performed on them as if they were integers.
44836 @item
44837 They are printed in a more readable fashion.
44838 @end itemize
44839
44840 Registers defined with @samp{struct} have one advantage over
44841 defining them with @samp{flags}:
44842
44843 @itemize @bullet
44844 @item
44845 One can fetch individual fields like in @samp{C}.
44846
44847 @smallexample
44848 (gdb) print $my_struct_reg.field3
44849 $1 = 42
44850 @end smallexample
44851
44852 @end itemize
44853
44854 @subsection Registers
44855 @cindex <reg>
44856
44857 Each register is represented as an element with this form:
44858
44859 @smallexample
44860 <reg name="@var{name}"
44861 bitsize="@var{size}"
44862 @r{[}regnum="@var{num}"@r{]}
44863 @r{[}save-restore="@var{save-restore}"@r{]}
44864 @r{[}type="@var{type}"@r{]}
44865 @r{[}group="@var{group}"@r{]}/>
44866 @end smallexample
44867
44868 @noindent
44869 The components are as follows:
44870
44871 @table @var
44872
44873 @item name
44874 The register's name; it must be unique within the target description.
44875
44876 @item bitsize
44877 The register's size, in bits.
44878
44879 @item regnum
44880 The register's number. If omitted, a register's number is one greater
44881 than that of the previous register (either in the current feature or in
44882 a preceding feature); the first register in the target description
44883 defaults to zero. This register number is used to read or write
44884 the register; e.g.@: it is used in the remote @code{p} and @code{P}
44885 packets, and registers appear in the @code{g} and @code{G} packets
44886 in order of increasing register number.
44887
44888 @item save-restore
44889 Whether the register should be preserved across inferior function
44890 calls; this must be either @code{yes} or @code{no}. The default is
44891 @code{yes}, which is appropriate for most registers except for
44892 some system control registers; this is not related to the target's
44893 ABI.
44894
44895 @item type
44896 The type of the register. It may be a predefined type, a type
44897 defined in the current feature, or one of the special types @code{int}
44898 and @code{float}. @code{int} is an integer type of the correct size
44899 for @var{bitsize}, and @code{float} is a floating point type (in the
44900 architecture's normal floating point format) of the correct size for
44901 @var{bitsize}. The default is @code{int}.
44902
44903 @item group
44904 The register group to which this register belongs. It can be one of the
44905 standard register groups @code{general}, @code{float}, @code{vector} or an
44906 arbitrary string. Group names should be limited to alphanumeric characters.
44907 If a group name is made up of multiple words the words may be separated by
44908 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
44909 @var{group} is specified, @value{GDBN} will not display the register in
44910 @code{info registers}.
44911
44912 @end table
44913
44914 @node Predefined Target Types
44915 @section Predefined Target Types
44916 @cindex target descriptions, predefined types
44917
44918 Type definitions in the self-description can build up composite types
44919 from basic building blocks, but can not define fundamental types. Instead,
44920 standard identifiers are provided by @value{GDBN} for the fundamental
44921 types. The currently supported types are:
44922
44923 @table @code
44924
44925 @item bool
44926 Boolean type, occupying a single bit.
44927
44928 @item int8
44929 @itemx int16
44930 @itemx int24
44931 @itemx int32
44932 @itemx int64
44933 @itemx int128
44934 Signed integer types holding the specified number of bits.
44935
44936 @item uint8
44937 @itemx uint16
44938 @itemx uint24
44939 @itemx uint32
44940 @itemx uint64
44941 @itemx uint128
44942 Unsigned integer types holding the specified number of bits.
44943
44944 @item code_ptr
44945 @itemx data_ptr
44946 Pointers to unspecified code and data. The program counter and
44947 any dedicated return address register may be marked as code
44948 pointers; printing a code pointer converts it into a symbolic
44949 address. The stack pointer and any dedicated address registers
44950 may be marked as data pointers.
44951
44952 @item ieee_single
44953 Single precision IEEE floating point.
44954
44955 @item ieee_double
44956 Double precision IEEE floating point.
44957
44958 @item arm_fpa_ext
44959 The 12-byte extended precision format used by ARM FPA registers.
44960
44961 @item i387_ext
44962 The 10-byte extended precision format used by x87 registers.
44963
44964 @item i386_eflags
44965 32bit @sc{eflags} register used by x86.
44966
44967 @item i386_mxcsr
44968 32bit @sc{mxcsr} register used by x86.
44969
44970 @end table
44971
44972 @node Enum Target Types
44973 @section Enum Target Types
44974 @cindex target descriptions, enum types
44975
44976 Enum target types are useful in @samp{struct} and @samp{flags}
44977 register descriptions. @xref{Target Description Format}.
44978
44979 Enum types have a name, size and a list of name/value pairs.
44980
44981 @smallexample
44982 <enum id="@var{id}" size="@var{size}">
44983 <evalue name="@var{name}" value="@var{value}"/>
44984 @dots{}
44985 </enum>
44986 @end smallexample
44987
44988 Enums must be defined before they are used.
44989
44990 @smallexample
44991 <enum id="levels_type" size="4">
44992 <evalue name="low" value="0"/>
44993 <evalue name="high" value="1"/>
44994 </enum>
44995 <flags id="flags_type" size="4">
44996 <field name="X" start="0"/>
44997 <field name="LEVEL" start="1" end="1" type="levels_type"/>
44998 </flags>
44999 <reg name="flags" bitsize="32" type="flags_type"/>
45000 @end smallexample
45001
45002 Given that description, a value of 3 for the @samp{flags} register
45003 would be printed as:
45004
45005 @smallexample
45006 (gdb) info register flags
45007 flags 0x3 [ X LEVEL=high ]
45008 @end smallexample
45009
45010 @node Standard Target Features
45011 @section Standard Target Features
45012 @cindex target descriptions, standard features
45013
45014 A target description must contain either no registers or all the
45015 target's registers. If the description contains no registers, then
45016 @value{GDBN} will assume a default register layout, selected based on
45017 the architecture. If the description contains any registers, the
45018 default layout will not be used; the standard registers must be
45019 described in the target description, in such a way that @value{GDBN}
45020 can recognize them.
45021
45022 This is accomplished by giving specific names to feature elements
45023 which contain standard registers. @value{GDBN} will look for features
45024 with those names and verify that they contain the expected registers;
45025 if any known feature is missing required registers, or if any required
45026 feature is missing, @value{GDBN} will reject the target
45027 description. You can add additional registers to any of the
45028 standard features --- @value{GDBN} will display them just as if
45029 they were added to an unrecognized feature.
45030
45031 This section lists the known features and their expected contents.
45032 Sample XML documents for these features are included in the
45033 @value{GDBN} source tree, in the directory @file{gdb/features}.
45034
45035 Names recognized by @value{GDBN} should include the name of the
45036 company or organization which selected the name, and the overall
45037 architecture to which the feature applies; so e.g.@: the feature
45038 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45039
45040 The names of registers are not case sensitive for the purpose
45041 of recognizing standard features, but @value{GDBN} will only display
45042 registers using the capitalization used in the description.
45043
45044 @menu
45045 * AArch64 Features::
45046 * ARC Features::
45047 * ARM Features::
45048 * i386 Features::
45049 * MicroBlaze Features::
45050 * MIPS Features::
45051 * M68K Features::
45052 * NDS32 Features::
45053 * Nios II Features::
45054 * OpenRISC 1000 Features::
45055 * PowerPC Features::
45056 * RISC-V Features::
45057 * RX Features::
45058 * S/390 and System z Features::
45059 * Sparc Features::
45060 * TIC6x Features::
45061 @end menu
45062
45063
45064 @node AArch64 Features
45065 @subsection AArch64 Features
45066 @cindex target descriptions, AArch64 features
45067
45068 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45069 targets. It should contain registers @samp{x0} through @samp{x30},
45070 @samp{sp}, @samp{pc}, and @samp{cpsr}.
45071
45072 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45073 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45074 and @samp{fpcr}.
45075
45076 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45077 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45078 through @samp{p15}, @samp{ffr} and @samp{vg}.
45079
45080 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45081 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45082
45083 @node ARC Features
45084 @subsection ARC Features
45085 @cindex target descriptions, ARC Features
45086
45087 ARC processors are highly configurable, so even core registers and their number
45088 are not completely predetermined. In addition flags and PC registers which are
45089 important to @value{GDBN} are not ``core'' registers in ARC. It is required
45090 that one of the core registers features is present.
45091 @samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
45092
45093 The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
45094 targets with a normal register file. It should contain registers @samp{r0}
45095 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45096 @samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
45097 and any of extension core registers @samp{r32} through @samp{r59/acch}.
45098 @samp{ilink} and extension core registers are not available to read/write, when
45099 debugging GNU/Linux applications, thus @samp{ilink} is made optional.
45100
45101 The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
45102 ARC HS targets with a reduced register file. It should contain registers
45103 @samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
45104 @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
45105 This feature may contain register @samp{ilink} and any of extension core
45106 registers @samp{r32} through @samp{r59/acch}.
45107
45108 The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
45109 targets with a normal register file. It should contain registers @samp{r0}
45110 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45111 @samp{lp_count} and @samp{pcl}. This feature may contain registers
45112 @samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45113 through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45114 registers are not available when debugging GNU/Linux applications. The only
45115 difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45116 @samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45117 ARC v2, but @samp{ilink2} is optional on ARCompact.
45118
45119 The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45120 targets. It should contain registers @samp{pc} and @samp{status32}.
45121
45122 @node ARM Features
45123 @subsection ARM Features
45124 @cindex target descriptions, ARM features
45125
45126 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45127 ARM targets.
45128 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45129 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45130
45131 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45132 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45133 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45134 and @samp{xpsr}.
45135
45136 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45137 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45138
45139 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45140 it should contain at least registers @samp{wR0} through @samp{wR15} and
45141 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45142 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45143
45144 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45145 should contain at least registers @samp{d0} through @samp{d15}. If
45146 they are present, @samp{d16} through @samp{d31} should also be included.
45147 @value{GDBN} will synthesize the single-precision registers from
45148 halves of the double-precision registers.
45149
45150 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45151 need to contain registers; it instructs @value{GDBN} to display the
45152 VFP double-precision registers as vectors and to synthesize the
45153 quad-precision registers from pairs of double-precision registers.
45154 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45155 be present and include 32 double-precision registers.
45156
45157 @node i386 Features
45158 @subsection i386 Features
45159 @cindex target descriptions, i386 features
45160
45161 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45162 targets. It should describe the following registers:
45163
45164 @itemize @minus
45165 @item
45166 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45167 @item
45168 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45169 @item
45170 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45171 @samp{fs}, @samp{gs}
45172 @item
45173 @samp{st0} through @samp{st7}
45174 @item
45175 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45176 @samp{foseg}, @samp{fooff} and @samp{fop}
45177 @end itemize
45178
45179 The register sets may be different, depending on the target.
45180
45181 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45182 describe registers:
45183
45184 @itemize @minus
45185 @item
45186 @samp{xmm0} through @samp{xmm7} for i386
45187 @item
45188 @samp{xmm0} through @samp{xmm15} for amd64
45189 @item
45190 @samp{mxcsr}
45191 @end itemize
45192
45193 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45194 @samp{org.gnu.gdb.i386.sse} feature. It should
45195 describe the upper 128 bits of @sc{ymm} registers:
45196
45197 @itemize @minus
45198 @item
45199 @samp{ymm0h} through @samp{ymm7h} for i386
45200 @item
45201 @samp{ymm0h} through @samp{ymm15h} for amd64
45202 @end itemize
45203
45204 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
45205 Memory Protection Extension (MPX). It should describe the following registers:
45206
45207 @itemize @minus
45208 @item
45209 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45210 @item
45211 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45212 @end itemize
45213
45214 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45215 describe a single register, @samp{orig_eax}.
45216
45217 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45218 describe two system registers: @samp{fs_base} and @samp{gs_base}.
45219
45220 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45221 @samp{org.gnu.gdb.i386.avx} feature. It should
45222 describe additional @sc{xmm} registers:
45223
45224 @itemize @minus
45225 @item
45226 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45227 @end itemize
45228
45229 It should describe the upper 128 bits of additional @sc{ymm} registers:
45230
45231 @itemize @minus
45232 @item
45233 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45234 @end itemize
45235
45236 It should
45237 describe the upper 256 bits of @sc{zmm} registers:
45238
45239 @itemize @minus
45240 @item
45241 @samp{zmm0h} through @samp{zmm7h} for i386.
45242 @item
45243 @samp{zmm0h} through @samp{zmm15h} for amd64.
45244 @end itemize
45245
45246 It should
45247 describe the additional @sc{zmm} registers:
45248
45249 @itemize @minus
45250 @item
45251 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45252 @end itemize
45253
45254 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45255 describe a single register, @samp{pkru}. It is a 32-bit register
45256 valid for i386 and amd64.
45257
45258 @node MicroBlaze Features
45259 @subsection MicroBlaze Features
45260 @cindex target descriptions, MicroBlaze features
45261
45262 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45263 targets. It should contain registers @samp{r0} through @samp{r31},
45264 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45265 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45266 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45267
45268 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45269 If present, it should contain registers @samp{rshr} and @samp{rslr}
45270
45271 @node MIPS Features
45272 @subsection @acronym{MIPS} Features
45273 @cindex target descriptions, @acronym{MIPS} features
45274
45275 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
45276 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45277 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45278 on the target.
45279
45280 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45281 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45282 registers. They may be 32-bit or 64-bit depending on the target.
45283
45284 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45285 it may be optional in a future version of @value{GDBN}. It should
45286 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45287 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
45288
45289 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45290 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45291 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45292 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45293
45294 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45295 contain a single register, @samp{restart}, which is used by the
45296 Linux kernel to control restartable syscalls.
45297
45298 @node M68K Features
45299 @subsection M68K Features
45300 @cindex target descriptions, M68K features
45301
45302 @table @code
45303 @item @samp{org.gnu.gdb.m68k.core}
45304 @itemx @samp{org.gnu.gdb.coldfire.core}
45305 @itemx @samp{org.gnu.gdb.fido.core}
45306 One of those features must be always present.
45307 The feature that is present determines which flavor of m68k is
45308 used. The feature that is present should contain registers
45309 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45310 @samp{sp}, @samp{ps} and @samp{pc}.
45311
45312 @item @samp{org.gnu.gdb.coldfire.fp}
45313 This feature is optional. If present, it should contain registers
45314 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45315 @samp{fpiaddr}.
45316
45317 Note that, despite the fact that this feature's name says
45318 @samp{coldfire}, it is used to describe any floating point registers.
45319 The size of the registers must match the main m68k flavor; so, for
45320 example, if the primary feature is reported as @samp{coldfire}, then
45321 64-bit floating point registers are required.
45322 @end table
45323
45324 @node NDS32 Features
45325 @subsection NDS32 Features
45326 @cindex target descriptions, NDS32 features
45327
45328 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45329 targets. It should contain at least registers @samp{r0} through
45330 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45331 and @samp{pc}.
45332
45333 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45334 it should contain 64-bit double-precision floating-point registers
45335 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45336 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45337
45338 @emph{Note:} The first sixteen 64-bit double-precision floating-point
45339 registers are overlapped with the thirty-two 32-bit single-precision
45340 floating-point registers. The 32-bit single-precision registers, if
45341 not being listed explicitly, will be synthesized from halves of the
45342 overlapping 64-bit double-precision registers. Listing 32-bit
45343 single-precision registers explicitly is deprecated, and the
45344 support to it could be totally removed some day.
45345
45346 @node Nios II Features
45347 @subsection Nios II Features
45348 @cindex target descriptions, Nios II features
45349
45350 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45351 targets. It should contain the 32 core registers (@samp{zero},
45352 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45353 @samp{pc}, and the 16 control registers (@samp{status} through
45354 @samp{mpuacc}).
45355
45356 @node OpenRISC 1000 Features
45357 @subsection Openrisc 1000 Features
45358 @cindex target descriptions, OpenRISC 1000 features
45359
45360 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45361 targets. It should contain the 32 general purpose registers (@samp{r0}
45362 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45363
45364 @node PowerPC Features
45365 @subsection PowerPC Features
45366 @cindex target descriptions, PowerPC features
45367
45368 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45369 targets. It should contain registers @samp{r0} through @samp{r31},
45370 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45371 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
45372
45373 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45374 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45375
45376 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
45377 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45378 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45379 through @samp{v31} as aliases for the corresponding @samp{vrX}
45380 registers.
45381
45382 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
45383 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45384 combine these registers with the floating point registers (@samp{f0}
45385 through @samp{f31}) and the altivec registers (@samp{vr0} through
45386 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45387 @samp{vs63}, the set of vector-scalar registers for POWER7.
45388 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45389 @samp{org.gnu.gdb.power.altivec}.
45390
45391 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45392 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45393 @samp{spefscr}. SPE targets should provide 32-bit registers in
45394 @samp{org.gnu.gdb.power.core} and provide the upper halves in
45395 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45396 these to present registers @samp{ev0} through @samp{ev31} to the
45397 user.
45398
45399 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45400 contain the 64-bit register @samp{ppr}.
45401
45402 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45403 contain the 64-bit register @samp{dscr}.
45404
45405 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45406 contain the 64-bit register @samp{tar}.
45407
45408 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45409 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
45410 64-bit wide.
45411
45412 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45413 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45414 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45415 server PMU registers provided by @sc{gnu}/Linux.
45416
45417 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45418 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
45419 64-bit wide.
45420
45421 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45422 contain the checkpointed general-purpose registers @samp{cr0} through
45423 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
45424 @samp{cctr}. These registers may all be either 32-bit or 64-bit
45425 depending on the target. It should also contain the checkpointed
45426 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45427 wide.
45428
45429 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45430 contain the checkpointed 64-bit floating-point registers @samp{cf0}
45431 through @samp{cf31}, as well as the checkpointed 64-bit register
45432 @samp{cfpscr}.
45433
45434 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45435 should contain the checkpointed altivec registers @samp{cvr0} through
45436 @samp{cvr31}, all 128-bit wide. It should also contain the
45437 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45438 wide.
45439
45440 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45441 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45442 will combine these registers with the checkpointed floating point
45443 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45444 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45445 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45446 @samp{cvs63}. Therefore, this feature requires both
45447 @samp{org.gnu.gdb.power.htm.altivec} and
45448 @samp{org.gnu.gdb.power.htm.fpu}.
45449
45450 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45451 contain the 64-bit checkpointed register @samp{cppr}.
45452
45453 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45454 contain the 64-bit checkpointed register @samp{cdscr}.
45455
45456 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45457 contain the 64-bit checkpointed register @samp{ctar}.
45458
45459
45460 @node RISC-V Features
45461 @subsection RISC-V Features
45462 @cindex target descriptions, RISC-V Features
45463
45464 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45465 targets. It should contain the registers @samp{x0} through
45466 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45467 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45468 etc).
45469
45470 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45471 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45472 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45473 architectural register names, or the ABI names can be used.
45474
45475 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45476 it should contain registers that are not backed by real registers on
45477 the target, but are instead virtual, where the register value is
45478 derived from other target state. In many ways these are like
45479 @value{GDBN}s pseudo-registers, except implemented by the target.
45480 Currently the only register expected in this set is the one byte
45481 @samp{priv} register that contains the target's privilege level in the
45482 least significant two bits.
45483
45484 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45485 should contain all of the target's standard CSRs. Standard CSRs are
45486 those defined in the RISC-V specification documents. There is some
45487 overlap between this feature and the fpu feature; the @samp{fflags},
45488 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
45489 expectation is that these registers will be in the fpu feature if the
45490 target has floating point hardware, but can be moved into the csr
45491 feature if the target has the floating point control registers, but no
45492 other floating point hardware.
45493
45494 @node RX Features
45495 @subsection RX Features
45496 @cindex target descriptions, RX Features
45497
45498 The @samp{org.gnu.gdb.rx.core} feature is required for RX
45499 targets. It should contain the registers @samp{r0} through
45500 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45501 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45502
45503 @node S/390 and System z Features
45504 @subsection S/390 and System z Features
45505 @cindex target descriptions, S/390 features
45506 @cindex target descriptions, System z features
45507
45508 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45509 System z targets. It should contain the PSW and the 16 general
45510 registers. In particular, System z targets should provide the 64-bit
45511 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45512 S/390 targets should provide the 32-bit versions of these registers.
45513 A System z target that runs in 31-bit addressing mode should provide
45514 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45515 register's upper halves @samp{r0h} through @samp{r15h}, and their
45516 lower halves @samp{r0l} through @samp{r15l}.
45517
45518 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45519 contain the 64-bit registers @samp{f0} through @samp{f15}, and
45520 @samp{fpc}.
45521
45522 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45523 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45524
45525 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45526 contain the register @samp{orig_r2}, which is 64-bit wide on System z
45527 targets and 32-bit otherwise. In addition, the feature may contain
45528 the @samp{last_break} register, whose width depends on the addressing
45529 mode, as well as the @samp{system_call} register, which is always
45530 32-bit wide.
45531
45532 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45533 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45534 @samp{atia}, and @samp{tr0} through @samp{tr15}.
45535
45536 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
45537 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45538 combined by @value{GDBN} with the floating point registers @samp{f0}
45539 through @samp{f15} to present the 128-bit wide vector registers
45540 @samp{v0} through @samp{v15}. In addition, this feature should
45541 contain the 128-bit wide vector registers @samp{v16} through
45542 @samp{v31}.
45543
45544 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45545 the 64-bit wide guarded-storage-control registers @samp{gsd},
45546 @samp{gssm}, and @samp{gsepla}.
45547
45548 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45549 the 64-bit wide guarded-storage broadcast control registers
45550 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45551
45552 @node Sparc Features
45553 @subsection Sparc Features
45554 @cindex target descriptions, sparc32 features
45555 @cindex target descriptions, sparc64 features
45556 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45557 targets. It should describe the following registers:
45558
45559 @itemize @minus
45560 @item
45561 @samp{g0} through @samp{g7}
45562 @item
45563 @samp{o0} through @samp{o7}
45564 @item
45565 @samp{l0} through @samp{l7}
45566 @item
45567 @samp{i0} through @samp{i7}
45568 @end itemize
45569
45570 They may be 32-bit or 64-bit depending on the target.
45571
45572 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45573 targets. It should describe the following registers:
45574
45575 @itemize @minus
45576 @item
45577 @samp{f0} through @samp{f31}
45578 @item
45579 @samp{f32} through @samp{f62} for sparc64
45580 @end itemize
45581
45582 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45583 targets. It should describe the following registers:
45584
45585 @itemize @minus
45586 @item
45587 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45588 @samp{fsr}, and @samp{csr} for sparc32
45589 @item
45590 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45591 for sparc64
45592 @end itemize
45593
45594 @node TIC6x Features
45595 @subsection TMS320C6x Features
45596 @cindex target descriptions, TIC6x features
45597 @cindex target descriptions, TMS320C6x features
45598 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45599 targets. It should contain registers @samp{A0} through @samp{A15},
45600 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45601
45602 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45603 contain registers @samp{A16} through @samp{A31} and @samp{B16}
45604 through @samp{B31}.
45605
45606 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45607 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45608
45609 @node Operating System Information
45610 @appendix Operating System Information
45611 @cindex operating system information
45612
45613 @menu
45614 * Process list::
45615 @end menu
45616
45617 Users of @value{GDBN} often wish to obtain information about the state of
45618 the operating system running on the target---for example the list of
45619 processes, or the list of open files. This section describes the
45620 mechanism that makes it possible. This mechanism is similar to the
45621 target features mechanism (@pxref{Target Descriptions}), but focuses
45622 on a different aspect of target.
45623
45624 Operating system information is retrieved from the target via the
45625 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45626 read}). The object name in the request should be @samp{osdata}, and
45627 the @var{annex} identifies the data to be fetched.
45628
45629 @node Process list
45630 @appendixsection Process list
45631 @cindex operating system information, process list
45632
45633 When requesting the process list, the @var{annex} field in the
45634 @samp{qXfer} request should be @samp{processes}. The returned data is
45635 an XML document. The formal syntax of this document is defined in
45636 @file{gdb/features/osdata.dtd}.
45637
45638 An example document is:
45639
45640 @smallexample
45641 <?xml version="1.0"?>
45642 <!DOCTYPE target SYSTEM "osdata.dtd">
45643 <osdata type="processes">
45644 <item>
45645 <column name="pid">1</column>
45646 <column name="user">root</column>
45647 <column name="command">/sbin/init</column>
45648 <column name="cores">1,2,3</column>
45649 </item>
45650 </osdata>
45651 @end smallexample
45652
45653 Each item should include a column whose name is @samp{pid}. The value
45654 of that column should identify the process on the target. The
45655 @samp{user} and @samp{command} columns are optional, and will be
45656 displayed by @value{GDBN}. The @samp{cores} column, if present,
45657 should contain a comma-separated list of cores that this process
45658 is running on. Target may provide additional columns,
45659 which @value{GDBN} currently ignores.
45660
45661 @node Trace File Format
45662 @appendix Trace File Format
45663 @cindex trace file format
45664
45665 The trace file comes in three parts: a header, a textual description
45666 section, and a trace frame section with binary data.
45667
45668 The header has the form @code{\x7fTRACE0\n}. The first byte is
45669 @code{0x7f} so as to indicate that the file contains binary data,
45670 while the @code{0} is a version number that may have different values
45671 in the future.
45672
45673 The description section consists of multiple lines of @sc{ascii} text
45674 separated by newline characters (@code{0xa}). The lines may include a
45675 variety of optional descriptive or context-setting information, such
45676 as tracepoint definitions or register set size. @value{GDBN} will
45677 ignore any line that it does not recognize. An empty line marks the end
45678 of this section.
45679
45680 @table @code
45681 @item R @var{size}
45682 Specifies the size of a register block in bytes. This is equal to the
45683 size of a @code{g} packet payload in the remote protocol. @var{size}
45684 is an ascii decimal number. There should be only one such line in
45685 a single trace file.
45686
45687 @item status @var{status}
45688 Trace status. @var{status} has the same format as a @code{qTStatus}
45689 remote packet reply. There should be only one such line in a single trace
45690 file.
45691
45692 @item tp @var{payload}
45693 Tracepoint definition. The @var{payload} has the same format as
45694 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45695 may take multiple lines of definition, corresponding to the multiple
45696 reply packets.
45697
45698 @item tsv @var{payload}
45699 Trace state variable definition. The @var{payload} has the same format as
45700 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45701 may take multiple lines of definition, corresponding to the multiple
45702 reply packets.
45703
45704 @item tdesc @var{payload}
45705 Target description in XML format. The @var{payload} is a single line of
45706 the XML file. All such lines should be concatenated together to get
45707 the original XML file. This file is in the same format as @code{qXfer}
45708 @code{features} payload, and corresponds to the main @code{target.xml}
45709 file. Includes are not allowed.
45710
45711 @end table
45712
45713 The trace frame section consists of a number of consecutive frames.
45714 Each frame begins with a two-byte tracepoint number, followed by a
45715 four-byte size giving the amount of data in the frame. The data in
45716 the frame consists of a number of blocks, each introduced by a
45717 character indicating its type (at least register, memory, and trace
45718 state variable). The data in this section is raw binary, not a
45719 hexadecimal or other encoding; its endianness matches the target's
45720 endianness.
45721
45722 @c FIXME bi-arch may require endianness/arch info in description section
45723
45724 @table @code
45725 @item R @var{bytes}
45726 Register block. The number and ordering of bytes matches that of a
45727 @code{g} packet in the remote protocol. Note that these are the
45728 actual bytes, in target order, not a hexadecimal encoding.
45729
45730 @item M @var{address} @var{length} @var{bytes}...
45731 Memory block. This is a contiguous block of memory, at the 8-byte
45732 address @var{address}, with a 2-byte length @var{length}, followed by
45733 @var{length} bytes.
45734
45735 @item V @var{number} @var{value}
45736 Trace state variable block. This records the 8-byte signed value
45737 @var{value} of trace state variable numbered @var{number}.
45738
45739 @end table
45740
45741 Future enhancements of the trace file format may include additional types
45742 of blocks.
45743
45744 @node Index Section Format
45745 @appendix @code{.gdb_index} section format
45746 @cindex .gdb_index section format
45747 @cindex index section format
45748
45749 This section documents the index section that is created by @code{save
45750 gdb-index} (@pxref{Index Files}). The index section is
45751 DWARF-specific; some knowledge of DWARF is assumed in this
45752 description.
45753
45754 The mapped index file format is designed to be directly
45755 @code{mmap}able on any architecture. In most cases, a datum is
45756 represented using a little-endian 32-bit integer value, called an
45757 @code{offset_type}. Big endian machines must byte-swap the values
45758 before using them. Exceptions to this rule are noted. The data is
45759 laid out such that alignment is always respected.
45760
45761 A mapped index consists of several areas, laid out in order.
45762
45763 @enumerate
45764 @item
45765 The file header. This is a sequence of values, of @code{offset_type}
45766 unless otherwise noted:
45767
45768 @enumerate
45769 @item
45770 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
45771 Version 4 uses a different hashing function from versions 5 and 6.
45772 Version 6 includes symbols for inlined functions, whereas versions 4
45773 and 5 do not. Version 7 adds attributes to the CU indices in the
45774 symbol table. Version 8 specifies that symbols from DWARF type units
45775 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45776 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45777
45778 @value{GDBN} will only read version 4, 5, or 6 indices
45779 by specifying @code{set use-deprecated-index-sections on}.
45780 GDB has a workaround for potentially broken version 7 indices so it is
45781 currently not flagged as deprecated.
45782
45783 @item
45784 The offset, from the start of the file, of the CU list.
45785
45786 @item
45787 The offset, from the start of the file, of the types CU list. Note
45788 that this area can be empty, in which case this offset will be equal
45789 to the next offset.
45790
45791 @item
45792 The offset, from the start of the file, of the address area.
45793
45794 @item
45795 The offset, from the start of the file, of the symbol table.
45796
45797 @item
45798 The offset, from the start of the file, of the constant pool.
45799 @end enumerate
45800
45801 @item
45802 The CU list. This is a sequence of pairs of 64-bit little-endian
45803 values, sorted by the CU offset. The first element in each pair is
45804 the offset of a CU in the @code{.debug_info} section. The second
45805 element in each pair is the length of that CU. References to a CU
45806 elsewhere in the map are done using a CU index, which is just the
45807 0-based index into this table. Note that if there are type CUs, then
45808 conceptually CUs and type CUs form a single list for the purposes of
45809 CU indices.
45810
45811 @item
45812 The types CU list. This is a sequence of triplets of 64-bit
45813 little-endian values. In a triplet, the first value is the CU offset,
45814 the second value is the type offset in the CU, and the third value is
45815 the type signature. The types CU list is not sorted.
45816
45817 @item
45818 The address area. The address area consists of a sequence of address
45819 entries. Each address entry has three elements:
45820
45821 @enumerate
45822 @item
45823 The low address. This is a 64-bit little-endian value.
45824
45825 @item
45826 The high address. This is a 64-bit little-endian value. Like
45827 @code{DW_AT_high_pc}, the value is one byte beyond the end.
45828
45829 @item
45830 The CU index. This is an @code{offset_type} value.
45831 @end enumerate
45832
45833 @item
45834 The symbol table. This is an open-addressed hash table. The size of
45835 the hash table is always a power of 2.
45836
45837 Each slot in the hash table consists of a pair of @code{offset_type}
45838 values. The first value is the offset of the symbol's name in the
45839 constant pool. The second value is the offset of the CU vector in the
45840 constant pool.
45841
45842 If both values are 0, then this slot in the hash table is empty. This
45843 is ok because while 0 is a valid constant pool index, it cannot be a
45844 valid index for both a string and a CU vector.
45845
45846 The hash value for a table entry is computed by applying an
45847 iterative hash function to the symbol's name. Starting with an
45848 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
45849 the string is incorporated into the hash using the formula depending on the
45850 index version:
45851
45852 @table @asis
45853 @item Version 4
45854 The formula is @code{r = r * 67 + c - 113}.
45855
45856 @item Versions 5 to 7
45857 The formula is @code{r = r * 67 + tolower (c) - 113}.
45858 @end table
45859
45860 The terminating @samp{\0} is not incorporated into the hash.
45861
45862 The step size used in the hash table is computed via
45863 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45864 value, and @samp{size} is the size of the hash table. The step size
45865 is used to find the next candidate slot when handling a hash
45866 collision.
45867
45868 The names of C@t{++} symbols in the hash table are canonicalized. We
45869 don't currently have a simple description of the canonicalization
45870 algorithm; if you intend to create new index sections, you must read
45871 the code.
45872
45873 @item
45874 The constant pool. This is simply a bunch of bytes. It is organized
45875 so that alignment is correct: CU vectors are stored first, followed by
45876 strings.
45877
45878 A CU vector in the constant pool is a sequence of @code{offset_type}
45879 values. The first value is the number of CU indices in the vector.
45880 Each subsequent value is the index and symbol attributes of a CU in
45881 the CU list. This element in the hash table is used to indicate which
45882 CUs define the symbol and how the symbol is used.
45883 See below for the format of each CU index+attributes entry.
45884
45885 A string in the constant pool is zero-terminated.
45886 @end enumerate
45887
45888 Attributes were added to CU index values in @code{.gdb_index} version 7.
45889 If a symbol has multiple uses within a CU then there is one
45890 CU index+attributes value for each use.
45891
45892 The format of each CU index+attributes entry is as follows
45893 (bit 0 = LSB):
45894
45895 @table @asis
45896
45897 @item Bits 0-23
45898 This is the index of the CU in the CU list.
45899 @item Bits 24-27
45900 These bits are reserved for future purposes and must be zero.
45901 @item Bits 28-30
45902 The kind of the symbol in the CU.
45903
45904 @table @asis
45905 @item 0
45906 This value is reserved and should not be used.
45907 By reserving zero the full @code{offset_type} value is backwards compatible
45908 with previous versions of the index.
45909 @item 1
45910 The symbol is a type.
45911 @item 2
45912 The symbol is a variable or an enum value.
45913 @item 3
45914 The symbol is a function.
45915 @item 4
45916 Any other kind of symbol.
45917 @item 5,6,7
45918 These values are reserved.
45919 @end table
45920
45921 @item Bit 31
45922 This bit is zero if the value is global and one if it is static.
45923
45924 The determination of whether a symbol is global or static is complicated.
45925 The authorative reference is the file @file{dwarf2read.c} in
45926 @value{GDBN} sources.
45927
45928 @end table
45929
45930 This pseudo-code describes the computation of a symbol's kind and
45931 global/static attributes in the index.
45932
45933 @smallexample
45934 is_external = get_attribute (die, DW_AT_external);
45935 language = get_attribute (cu_die, DW_AT_language);
45936 switch (die->tag)
45937 @{
45938 case DW_TAG_typedef:
45939 case DW_TAG_base_type:
45940 case DW_TAG_subrange_type:
45941 kind = TYPE;
45942 is_static = 1;
45943 break;
45944 case DW_TAG_enumerator:
45945 kind = VARIABLE;
45946 is_static = language != CPLUS;
45947 break;
45948 case DW_TAG_subprogram:
45949 kind = FUNCTION;
45950 is_static = ! (is_external || language == ADA);
45951 break;
45952 case DW_TAG_constant:
45953 kind = VARIABLE;
45954 is_static = ! is_external;
45955 break;
45956 case DW_TAG_variable:
45957 kind = VARIABLE;
45958 is_static = ! is_external;
45959 break;
45960 case DW_TAG_namespace:
45961 kind = TYPE;
45962 is_static = 0;
45963 break;
45964 case DW_TAG_class_type:
45965 case DW_TAG_interface_type:
45966 case DW_TAG_structure_type:
45967 case DW_TAG_union_type:
45968 case DW_TAG_enumeration_type:
45969 kind = TYPE;
45970 is_static = language != CPLUS;
45971 break;
45972 default:
45973 assert (0);
45974 @}
45975 @end smallexample
45976
45977 @node Man Pages
45978 @appendix Manual pages
45979 @cindex Man pages
45980
45981 @menu
45982 * gdb man:: The GNU Debugger man page
45983 * gdbserver man:: Remote Server for the GNU Debugger man page
45984 * gcore man:: Generate a core file of a running program
45985 * gdbinit man:: gdbinit scripts
45986 * gdb-add-index man:: Add index files to speed up GDB
45987 @end menu
45988
45989 @node gdb man
45990 @heading gdb man
45991
45992 @c man title gdb The GNU Debugger
45993
45994 @c man begin SYNOPSIS gdb
45995 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
45996 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
45997 [@option{-b}@w{ }@var{bps}]
45998 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
45999 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46000 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46001 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46002 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46003 @c man end
46004
46005 @c man begin DESCRIPTION gdb
46006 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46007 going on ``inside'' another program while it executes -- or what another
46008 program was doing at the moment it crashed.
46009
46010 @value{GDBN} can do four main kinds of things (plus other things in support of
46011 these) to help you catch bugs in the act:
46012
46013 @itemize @bullet
46014 @item
46015 Start your program, specifying anything that might affect its behavior.
46016
46017 @item
46018 Make your program stop on specified conditions.
46019
46020 @item
46021 Examine what has happened, when your program has stopped.
46022
46023 @item
46024 Change things in your program, so you can experiment with correcting the
46025 effects of one bug and go on to learn about another.
46026 @end itemize
46027
46028 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46029 Modula-2.
46030
46031 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46032 commands from the terminal until you tell it to exit with the @value{GDBN}
46033 command @code{quit}. You can get online help from @value{GDBN} itself
46034 by using the command @code{help}.
46035
46036 You can run @code{gdb} with no arguments or options; but the most
46037 usual way to start @value{GDBN} is with one argument or two, specifying an
46038 executable program as the argument:
46039
46040 @smallexample
46041 gdb program
46042 @end smallexample
46043
46044 You can also start with both an executable program and a core file specified:
46045
46046 @smallexample
46047 gdb program core
46048 @end smallexample
46049
46050 You can, instead, specify a process ID as a second argument or use option
46051 @code{-p}, if you want to debug a running process:
46052
46053 @smallexample
46054 gdb program 1234
46055 gdb -p 1234
46056 @end smallexample
46057
46058 @noindent
46059 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46060 can omit the @var{program} filename.
46061
46062 Here are some of the most frequently needed @value{GDBN} commands:
46063
46064 @c pod2man highlights the right hand side of the @item lines.
46065 @table @env
46066 @item break [@var{file}:]@var{function}
46067 Set a breakpoint at @var{function} (in @var{file}).
46068
46069 @item run [@var{arglist}]
46070 Start your program (with @var{arglist}, if specified).
46071
46072 @item bt
46073 Backtrace: display the program stack.
46074
46075 @item print @var{expr}
46076 Display the value of an expression.
46077
46078 @item c
46079 Continue running your program (after stopping, e.g. at a breakpoint).
46080
46081 @item next
46082 Execute next program line (after stopping); step @emph{over} any
46083 function calls in the line.
46084
46085 @item edit [@var{file}:]@var{function}
46086 look at the program line where it is presently stopped.
46087
46088 @item list [@var{file}:]@var{function}
46089 type the text of the program in the vicinity of where it is presently stopped.
46090
46091 @item step
46092 Execute next program line (after stopping); step @emph{into} any
46093 function calls in the line.
46094
46095 @item help [@var{name}]
46096 Show information about @value{GDBN} command @var{name}, or general information
46097 about using @value{GDBN}.
46098
46099 @item quit
46100 Exit from @value{GDBN}.
46101 @end table
46102
46103 @ifset man
46104 For full details on @value{GDBN},
46105 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46106 by Richard M. Stallman and Roland H. Pesch. The same text is available online
46107 as the @code{gdb} entry in the @code{info} program.
46108 @end ifset
46109 @c man end
46110
46111 @c man begin OPTIONS gdb
46112 Any arguments other than options specify an executable
46113 file and core file (or process ID); that is, the first argument
46114 encountered with no
46115 associated option flag is equivalent to a @option{-se} option, and the second,
46116 if any, is equivalent to a @option{-c} option if it's the name of a file.
46117 Many options have
46118 both long and short forms; both are shown here. The long forms are also
46119 recognized if you truncate them, so long as enough of the option is
46120 present to be unambiguous. (If you prefer, you can flag option
46121 arguments with @option{+} rather than @option{-}, though we illustrate the
46122 more usual convention.)
46123
46124 All the options and command line arguments you give are processed
46125 in sequential order. The order makes a difference when the @option{-x}
46126 option is used.
46127
46128 @table @env
46129 @item -help
46130 @itemx -h
46131 List all options, with brief explanations.
46132
46133 @item -symbols=@var{file}
46134 @itemx -s @var{file}
46135 Read symbol table from file @var{file}.
46136
46137 @item -write
46138 Enable writing into executable and core files.
46139
46140 @item -exec=@var{file}
46141 @itemx -e @var{file}
46142 Use file @var{file} as the executable file to execute when
46143 appropriate, and for examining pure data in conjunction with a core
46144 dump.
46145
46146 @item -se=@var{file}
46147 Read symbol table from file @var{file} and use it as the executable
46148 file.
46149
46150 @item -core=@var{file}
46151 @itemx -c @var{file}
46152 Use file @var{file} as a core dump to examine.
46153
46154 @item -command=@var{file}
46155 @itemx -x @var{file}
46156 Execute @value{GDBN} commands from file @var{file}.
46157
46158 @item -ex @var{command}
46159 Execute given @value{GDBN} @var{command}.
46160
46161 @item -directory=@var{directory}
46162 @itemx -d @var{directory}
46163 Add @var{directory} to the path to search for source files.
46164
46165 @item -nh
46166 Do not execute commands from @file{~/.gdbinit}.
46167
46168 @item -nx
46169 @itemx -n
46170 Do not execute commands from any @file{.gdbinit} initialization files.
46171
46172 @item -quiet
46173 @itemx -q
46174 ``Quiet''. Do not print the introductory and copyright messages. These
46175 messages are also suppressed in batch mode.
46176
46177 @item -batch
46178 Run in batch mode. Exit with status @code{0} after processing all the command
46179 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46180 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46181 commands in the command files.
46182
46183 Batch mode may be useful for running @value{GDBN} as a filter, for example to
46184 download and run a program on another computer; in order to make this
46185 more useful, the message
46186
46187 @smallexample
46188 Program exited normally.
46189 @end smallexample
46190
46191 @noindent
46192 (which is ordinarily issued whenever a program running under @value{GDBN} control
46193 terminates) is not issued when running in batch mode.
46194
46195 @item -cd=@var{directory}
46196 Run @value{GDBN} using @var{directory} as its working directory,
46197 instead of the current directory.
46198
46199 @item -fullname
46200 @itemx -f
46201 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46202 @value{GDBN} to output the full file name and line number in a standard,
46203 recognizable fashion each time a stack frame is displayed (which
46204 includes each time the program stops). This recognizable format looks
46205 like two @samp{\032} characters, followed by the file name, line number
46206 and character position separated by colons, and a newline. The
46207 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46208 characters as a signal to display the source code for the frame.
46209
46210 @item -b @var{bps}
46211 Set the line speed (baud rate or bits per second) of any serial
46212 interface used by @value{GDBN} for remote debugging.
46213
46214 @item -tty=@var{device}
46215 Run using @var{device} for your program's standard input and output.
46216 @end table
46217 @c man end
46218
46219 @c man begin SEEALSO gdb
46220 @ifset man
46221 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46222 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46223 documentation are properly installed at your site, the command
46224
46225 @smallexample
46226 info gdb
46227 @end smallexample
46228
46229 @noindent
46230 should give you access to the complete manual.
46231
46232 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46233 Richard M. Stallman and Roland H. Pesch, July 1991.
46234 @end ifset
46235 @c man end
46236
46237 @node gdbserver man
46238 @heading gdbserver man
46239
46240 @c man title gdbserver Remote Server for the GNU Debugger
46241 @format
46242 @c man begin SYNOPSIS gdbserver
46243 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46244
46245 gdbserver --attach @var{comm} @var{pid}
46246
46247 gdbserver --multi @var{comm}
46248 @c man end
46249 @end format
46250
46251 @c man begin DESCRIPTION gdbserver
46252 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46253 than the one which is running the program being debugged.
46254
46255 @ifclear man
46256 @subheading Usage (server (target) side)
46257 @end ifclear
46258 @ifset man
46259 Usage (server (target) side):
46260 @end ifset
46261
46262 First, you need to have a copy of the program you want to debug put onto
46263 the target system. The program can be stripped to save space if needed, as
46264 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46265 the @value{GDBN} running on the host system.
46266
46267 To use the server, you log on to the target system, and run the @command{gdbserver}
46268 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46269 your program, and (c) its arguments. The general syntax is:
46270
46271 @smallexample
46272 target> gdbserver @var{comm} @var{program} [@var{args} ...]
46273 @end smallexample
46274
46275 For example, using a serial port, you might say:
46276
46277 @smallexample
46278 @ifset man
46279 @c @file would wrap it as F</dev/com1>.
46280 target> gdbserver /dev/com1 emacs foo.txt
46281 @end ifset
46282 @ifclear man
46283 target> gdbserver @file{/dev/com1} emacs foo.txt
46284 @end ifclear
46285 @end smallexample
46286
46287 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46288 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46289 waits patiently for the host @value{GDBN} to communicate with it.
46290
46291 To use a TCP connection, you could say:
46292
46293 @smallexample
46294 target> gdbserver host:2345 emacs foo.txt
46295 @end smallexample
46296
46297 This says pretty much the same thing as the last example, except that we are
46298 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46299 that we are expecting to see a TCP connection from @code{host} to local TCP port
46300 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
46301 want for the port number as long as it does not conflict with any existing TCP
46302 ports on the target system. This same port number must be used in the host
46303 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46304 you chose a port number that conflicts with another service, @command{gdbserver} will
46305 print an error message and exit.
46306
46307 @command{gdbserver} can also attach to running programs.
46308 This is accomplished via the @option{--attach} argument. The syntax is:
46309
46310 @smallexample
46311 target> gdbserver --attach @var{comm} @var{pid}
46312 @end smallexample
46313
46314 @var{pid} is the process ID of a currently running process. It isn't
46315 necessary to point @command{gdbserver} at a binary for the running process.
46316
46317 To start @code{gdbserver} without supplying an initial command to run
46318 or process ID to attach, use the @option{--multi} command line option.
46319 In such case you should connect using @kbd{target extended-remote} to start
46320 the program you want to debug.
46321
46322 @smallexample
46323 target> gdbserver --multi @var{comm}
46324 @end smallexample
46325
46326 @ifclear man
46327 @subheading Usage (host side)
46328 @end ifclear
46329 @ifset man
46330 Usage (host side):
46331 @end ifset
46332
46333 You need an unstripped copy of the target program on your host system, since
46334 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
46335 would, with the target program as the first argument. (You may need to use the
46336 @option{--baud} option if the serial line is running at anything except 9600 baud.)
46337 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
46338 new command you need to know about is @code{target remote}
46339 (or @code{target extended-remote}). Its argument is either
46340 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46341 descriptor. For example:
46342
46343 @smallexample
46344 @ifset man
46345 @c @file would wrap it as F</dev/ttyb>.
46346 (gdb) target remote /dev/ttyb
46347 @end ifset
46348 @ifclear man
46349 (gdb) target remote @file{/dev/ttyb}
46350 @end ifclear
46351 @end smallexample
46352
46353 @noindent
46354 communicates with the server via serial line @file{/dev/ttyb}, and:
46355
46356 @smallexample
46357 (gdb) target remote the-target:2345
46358 @end smallexample
46359
46360 @noindent
46361 communicates via a TCP connection to port 2345 on host `the-target', where
46362 you previously started up @command{gdbserver} with the same port number. Note that for
46363 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46364 command, otherwise you may get an error that looks something like
46365 `Connection refused'.
46366
46367 @command{gdbserver} can also debug multiple inferiors at once,
46368 described in
46369 @ifset man
46370 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46371 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
46372 @end ifset
46373 @ifclear man
46374 @ref{Inferiors Connections and Programs}.
46375 @end ifclear
46376 In such case use the @code{extended-remote} @value{GDBN} command variant:
46377
46378 @smallexample
46379 (gdb) target extended-remote the-target:2345
46380 @end smallexample
46381
46382 The @command{gdbserver} option @option{--multi} may or may not be used in such
46383 case.
46384 @c man end
46385
46386 @c man begin OPTIONS gdbserver
46387 There are three different modes for invoking @command{gdbserver}:
46388
46389 @itemize @bullet
46390
46391 @item
46392 Debug a specific program specified by its program name:
46393
46394 @smallexample
46395 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46396 @end smallexample
46397
46398 The @var{comm} parameter specifies how should the server communicate
46399 with @value{GDBN}; it is either a device name (to use a serial line),
46400 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46401 stdin/stdout of @code{gdbserver}. Specify the name of the program to
46402 debug in @var{prog}. Any remaining arguments will be passed to the
46403 program verbatim. When the program exits, @value{GDBN} will close the
46404 connection, and @code{gdbserver} will exit.
46405
46406 @item
46407 Debug a specific program by specifying the process ID of a running
46408 program:
46409
46410 @smallexample
46411 gdbserver --attach @var{comm} @var{pid}
46412 @end smallexample
46413
46414 The @var{comm} parameter is as described above. Supply the process ID
46415 of a running program in @var{pid}; @value{GDBN} will do everything
46416 else. Like with the previous mode, when the process @var{pid} exits,
46417 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
46418
46419 @item
46420 Multi-process mode -- debug more than one program/process:
46421
46422 @smallexample
46423 gdbserver --multi @var{comm}
46424 @end smallexample
46425
46426 In this mode, @value{GDBN} can instruct @command{gdbserver} which
46427 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46428 close the connection when a process being debugged exits, so you can
46429 debug several processes in the same session.
46430 @end itemize
46431
46432 In each of the modes you may specify these options:
46433
46434 @table @env
46435
46436 @item --help
46437 List all options, with brief explanations.
46438
46439 @item --version
46440 This option causes @command{gdbserver} to print its version number and exit.
46441
46442 @item --attach
46443 @command{gdbserver} will attach to a running program. The syntax is:
46444
46445 @smallexample
46446 target> gdbserver --attach @var{comm} @var{pid}
46447 @end smallexample
46448
46449 @var{pid} is the process ID of a currently running process. It isn't
46450 necessary to point @command{gdbserver} at a binary for the running process.
46451
46452 @item --multi
46453 To start @code{gdbserver} without supplying an initial command to run
46454 or process ID to attach, use this command line option.
46455 Then you can connect using @kbd{target extended-remote} and start
46456 the program you want to debug. The syntax is:
46457
46458 @smallexample
46459 target> gdbserver --multi @var{comm}
46460 @end smallexample
46461
46462 @item --debug
46463 Instruct @code{gdbserver} to display extra status information about the debugging
46464 process.
46465 This option is intended for @code{gdbserver} development and for bug reports to
46466 the developers.
46467
46468 @item --remote-debug
46469 Instruct @code{gdbserver} to display remote protocol debug output.
46470 This option is intended for @code{gdbserver} development and for bug reports to
46471 the developers.
46472
46473 @item --debug-file=@var{filename}
46474 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46475 This option is intended for @code{gdbserver} development and for bug reports to
46476 the developers.
46477
46478 @item --debug-format=option1@r{[},option2,...@r{]}
46479 Instruct @code{gdbserver} to include extra information in each line
46480 of debugging output.
46481 @xref{Other Command-Line Arguments for gdbserver}.
46482
46483 @item --wrapper
46484 Specify a wrapper to launch programs
46485 for debugging. The option should be followed by the name of the
46486 wrapper, then any command-line arguments to pass to the wrapper, then
46487 @kbd{--} indicating the end of the wrapper arguments.
46488
46489 @item --once
46490 By default, @command{gdbserver} keeps the listening TCP port open, so that
46491 additional connections are possible. However, if you start @code{gdbserver}
46492 with the @option{--once} option, it will stop listening for any further
46493 connection attempts after connecting to the first @value{GDBN} session.
46494
46495 @c --disable-packet is not documented for users.
46496
46497 @c --disable-randomization and --no-disable-randomization are superseded by
46498 @c QDisableRandomization.
46499
46500 @end table
46501 @c man end
46502
46503 @c man begin SEEALSO gdbserver
46504 @ifset man
46505 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46506 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46507 documentation are properly installed at your site, the command
46508
46509 @smallexample
46510 info gdb
46511 @end smallexample
46512
46513 should give you access to the complete manual.
46514
46515 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46516 Richard M. Stallman and Roland H. Pesch, July 1991.
46517 @end ifset
46518 @c man end
46519
46520 @node gcore man
46521 @heading gcore
46522
46523 @c man title gcore Generate a core file of a running program
46524
46525 @format
46526 @c man begin SYNOPSIS gcore
46527 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
46528 @c man end
46529 @end format
46530
46531 @c man begin DESCRIPTION gcore
46532 Generate core dumps of one or more running programs with process IDs
46533 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46534 is equivalent to one produced by the kernel when the process crashes
46535 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
46536 limit). However, unlike after a crash, after @command{gcore} finishes
46537 its job the program remains running without any change.
46538 @c man end
46539
46540 @c man begin OPTIONS gcore
46541 @table @env
46542 @item -a
46543 Dump all memory mappings. The actual effect of this option depends on
46544 the Operating System. On @sc{gnu}/Linux, it will disable
46545 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46546 enable @code{dump-excluded-mappings} (@pxref{set
46547 dump-excluded-mappings}).
46548
46549 @item -o @var{prefix}
46550 The optional argument @var{prefix} specifies the prefix to be used
46551 when composing the file names of the core dumps. The file name is
46552 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46553 process ID of the running program being analyzed by @command{gcore}.
46554 If not specified, @var{prefix} defaults to @var{gcore}.
46555 @end table
46556 @c man end
46557
46558 @c man begin SEEALSO gcore
46559 @ifset man
46560 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46561 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46562 documentation are properly installed at your site, the command
46563
46564 @smallexample
46565 info gdb
46566 @end smallexample
46567
46568 @noindent
46569 should give you access to the complete manual.
46570
46571 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46572 Richard M. Stallman and Roland H. Pesch, July 1991.
46573 @end ifset
46574 @c man end
46575
46576 @node gdbinit man
46577 @heading gdbinit
46578
46579 @c man title gdbinit GDB initialization scripts
46580
46581 @format
46582 @c man begin SYNOPSIS gdbinit
46583 @ifset SYSTEM_GDBINIT
46584 @value{SYSTEM_GDBINIT}
46585 @end ifset
46586
46587 @ifset SYSTEM_GDBINIT_DIR
46588 @value{SYSTEM_GDBINIT_DIR}/*
46589 @end ifset
46590
46591 ~/.gdbinit
46592
46593 ./.gdbinit
46594 @c man end
46595 @end format
46596
46597 @c man begin DESCRIPTION gdbinit
46598 These files contain @value{GDBN} commands to automatically execute during
46599 @value{GDBN} startup. The lines of contents are canned sequences of commands,
46600 described in
46601 @ifset man
46602 the @value{GDBN} manual in node @code{Sequences}
46603 -- shell command @code{info -f gdb -n Sequences}.
46604 @end ifset
46605 @ifclear man
46606 @ref{Sequences}.
46607 @end ifclear
46608
46609 Please read more in
46610 @ifset man
46611 the @value{GDBN} manual in node @code{Startup}
46612 -- shell command @code{info -f gdb -n Startup}.
46613 @end ifset
46614 @ifclear man
46615 @ref{Startup}.
46616 @end ifclear
46617
46618 @table @env
46619 @ifset SYSTEM_GDBINIT
46620 @item @value{SYSTEM_GDBINIT}
46621 @end ifset
46622 @ifclear SYSTEM_GDBINIT
46623 @item (not enabled with @code{--with-system-gdbinit} during compilation)
46624 @end ifclear
46625 System-wide initialization file. It is executed unless user specified
46626 @value{GDBN} option @code{-nx} or @code{-n}.
46627 See more in
46628 @ifset man
46629 the @value{GDBN} manual in node @code{System-wide configuration}
46630 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46631 @end ifset
46632 @ifset SYSTEM_GDBINIT_DIR
46633 @item @value{SYSTEM_GDBINIT_DIR}
46634 @end ifset
46635 @ifclear SYSTEM_GDBINIT_DIR
46636 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46637 @end ifclear
46638 System-wide initialization directory. All files in this directory are
46639 executed on startup unless user specified @value{GDBN} option @code{-nx} or
46640 @code{-n}, as long as they have a recognized file extension.
46641 See more in
46642 @ifset man
46643 the @value{GDBN} manual in node @code{System-wide configuration}
46644 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46645 @end ifset
46646 @ifclear man
46647 @ref{System-wide configuration}.
46648 @end ifclear
46649
46650 @item ~/.gdbinit
46651 User initialization file. It is executed unless user specified
46652 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46653
46654 @item ./.gdbinit
46655 Initialization file for current directory. It may need to be enabled with
46656 @value{GDBN} security command @code{set auto-load local-gdbinit}.
46657 See more in
46658 @ifset man
46659 the @value{GDBN} manual in node @code{Init File in the Current Directory}
46660 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46661 @end ifset
46662 @ifclear man
46663 @ref{Init File in the Current Directory}.
46664 @end ifclear
46665 @end table
46666 @c man end
46667
46668 @c man begin SEEALSO gdbinit
46669 @ifset man
46670 gdb(1), @code{info -f gdb -n Startup}
46671
46672 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46673 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46674 documentation are properly installed at your site, the command
46675
46676 @smallexample
46677 info gdb
46678 @end smallexample
46679
46680 should give you access to the complete manual.
46681
46682 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46683 Richard M. Stallman and Roland H. Pesch, July 1991.
46684 @end ifset
46685 @c man end
46686
46687 @node gdb-add-index man
46688 @heading gdb-add-index
46689 @pindex gdb-add-index
46690 @anchor{gdb-add-index}
46691
46692 @c man title gdb-add-index Add index files to speed up GDB
46693
46694 @c man begin SYNOPSIS gdb-add-index
46695 gdb-add-index @var{filename}
46696 @c man end
46697
46698 @c man begin DESCRIPTION gdb-add-index
46699 When @value{GDBN} finds a symbol file, it scans the symbols in the
46700 file in order to construct an internal symbol table. This lets most
46701 @value{GDBN} operations work quickly--at the cost of a delay early on.
46702 For large programs, this delay can be quite lengthy, so @value{GDBN}
46703 provides a way to build an index, which speeds up startup.
46704
46705 To determine whether a file contains such an index, use the command
46706 @kbd{readelf -S filename}: the index is stored in a section named
46707 @code{.gdb_index}. The index file can only be produced on systems
46708 which use ELF binaries and DWARF debug information (i.e., sections
46709 named @code{.debug_*}).
46710
46711 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46712 in the @env{PATH} environment variable. If you want to use different
46713 versions of these programs, you can specify them through the
46714 @env{GDB} and @env{OBJDUMP} environment variables.
46715
46716 See more in
46717 @ifset man
46718 the @value{GDBN} manual in node @code{Index Files}
46719 -- shell command @kbd{info -f gdb -n "Index Files"}.
46720 @end ifset
46721 @ifclear man
46722 @ref{Index Files}.
46723 @end ifclear
46724 @c man end
46725
46726 @c man begin SEEALSO gdb-add-index
46727 @ifset man
46728 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46729 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46730 documentation are properly installed at your site, the command
46731
46732 @smallexample
46733 info gdb
46734 @end smallexample
46735
46736 should give you access to the complete manual.
46737
46738 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46739 Richard M. Stallman and Roland H. Pesch, July 1991.
46740 @end ifset
46741 @c man end
46742
46743 @include gpl.texi
46744
46745 @node GNU Free Documentation License
46746 @appendix GNU Free Documentation License
46747 @include fdl.texi
46748
46749 @node Concept Index
46750 @unnumbered Concept Index
46751
46752 @printindex cp
46753
46754 @node Command and Variable Index
46755 @unnumbered Command, Variable, and Function Index
46756
46757 @printindex fn
46758
46759 @tex
46760 % I think something like @@colophon should be in texinfo. In the
46761 % meantime:
46762 \long\def\colophon{\hbox to0pt{}\vfill
46763 \centerline{The body of this manual is set in}
46764 \centerline{\fontname\tenrm,}
46765 \centerline{with headings in {\bf\fontname\tenbf}}
46766 \centerline{and examples in {\tt\fontname\tentt}.}
46767 \centerline{{\it\fontname\tenit\/},}
46768 \centerline{{\bf\fontname\tenbf}, and}
46769 \centerline{{\sl\fontname\tensl\/}}
46770 \centerline{are used for emphasis.}\vfill}
46771 \page\colophon
46772 % Blame: doc@@cygnus.com, 1991.
46773 @end tex
46774
46775 @bye
This page took 0.972207 seconds and 3 git commands to generate.